Skip to content

Commit

Permalink
Update ImGUI and use docking branch (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pirulax authored Jul 10, 2023
1 parent 8691a46 commit 8b09631
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 138 deletions.
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
[submodule "libs/imgui"]
path = libs/imgui
url = ../../ocornut/imgui.git
branch = docking
2 changes: 1 addition & 1 deletion libs/imgui
Submodule imgui updated 155 files
12 changes: 8 additions & 4 deletions source/app/app_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ void AppGameInjectHooks() {
RH_ScopedGlobalInstall(RenderEffects, 0x53E170);
RH_ScopedGlobalInstall(RenderScene, 0x53DF40);
RH_ScopedGlobalInstall(RenderMenus, 0x53E530);
RH_ScopedGlobalInstall(Render2dStuff, 0x53E230, {.locked = true});
RH_ScopedGlobalInstall(Render2dStuff, 0x53E230);
RH_ScopedGlobalInstall(RenderDebugShit, 0x53E160);

RH_ScopedGlobalInstall(Idle, 0x53E920);
RH_ScopedGlobalInstall(FrontendIdle, 0x53E770);
RH_ScopedGlobalInstall(FrontendIdle, 0x53E770, { .locked = true }); // Must be hooked at all times otherwise imgui stops working!
}

// 0x5BF3B0
Expand Down Expand Up @@ -310,8 +310,11 @@ void Idle(void* param) {
}

if (!FrontEndMenuManager.m_bMenuActive && TheCamera.GetScreenFadeStatus() != eNameState::NAME_FADE_IN) {
CVector2D mousePos{SCREEN_WIDTH / 2.0f, SCREEN_HEIGHT / 2.0f};
RsMouseSetPos(&mousePos);
if (!notsa::ui::UIRenderer::GetSingleton().GetImIO()->NavActive) { // If imgui nav is active don't center the cursor
CVector2D mousePos{SCREEN_WIDTH / 2.0f, SCREEN_HEIGHT / 2.0f};
RsMouseSetPos(&mousePos);
}

CRenderer::ConstructRenderList();
CRenderer::PreRender();
CWorld::ProcessPedsAfterPreRender();
Expand Down Expand Up @@ -348,6 +351,7 @@ void Idle(void* param) {
}

RenderMenus();
notsa::ui::UIRenderer::GetSingleton().DrawLoop(); // NOTSA: ImGui menu draw loop
RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RWRSTATE(NULL));
DoFade();
CHud::DrawAfterFade();
Expand Down
107 changes: 64 additions & 43 deletions source/app/platform/win/win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Dbt.h>

#include "win.h"
#include "imgui_impl_win32.h"
#include "dshow.h"

#include "VideoPlayer.h"
Expand All @@ -30,6 +31,9 @@ static LPSTR AppClassName = LPSTR(APP_CLASS);

constexpr auto NO_FOREGROUND_PAUSE = true;

// Dear ImGui said I have to copy this here
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

// Custom enum, generated by ChatGPT, thank you
enum class WinVer {
WIN_95, //< Windows 95
Expand Down Expand Up @@ -244,6 +248,11 @@ BOOL GTATranslateShiftKey(RsKeyCodes*) { // The in keycode is ignored, so we won

// 0x747EB0
LRESULT CALLBACK __MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
const auto imio = ImGui::GetCurrentContext() ? &ImGui::GetIO() : nullptr;
if (ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam)) {
return true;
}

switch (uMsg) {
case WM_SETCURSOR: {
ShowCursor(false);
Expand All @@ -253,7 +262,11 @@ LRESULT CALLBACK __MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP: { //< 0x74823B - wParam is a `VK_` (virtual key), lParam are the flags (See https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-keyup)
case WM_SYSKEYUP: { //< 0x74823B - wParam is a `VK_` (virtual key), lParam are the flags (See https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-keyup)]
if (imio && imio->WantCaptureKeyboard) {
return 0;
}

if (RsKeyCodes ck; GTATranslateKey(&ck, lParam, wParam)) {
RsKeyboardEventHandler(
(uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN)
Expand All @@ -268,6 +281,54 @@ LRESULT CALLBACK __MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
}
return 0;
}
case WM_MOUSEMOVE: { //< 0x748323
if (imio && imio->WantCaptureMouse) {
return 0;
}
FrontEndMenuManager.m_nMousePosWinX = GET_X_LPARAM(lParam);
FrontEndMenuManager.m_nMousePosWinY = GET_Y_LPARAM(lParam);
break;
}
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN: {
if (imio && imio->WantCaptureMouse) {
return 0;
}
SetCapture(hWnd);
return 0;
}
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP: {
if (imio && imio->WantCaptureMouse) {
return 0;
}
ReleaseCapture();
return 0;
}
case WM_MOUSEWHEEL:
return 0;
case WM_SIZING: { // 0x74829E
if (RwInitialized) {
if (gGameState == GAME_STATE_IDLE) {
RsEventHandler(rsIDLE, (void*)TRUE);
}
}

const auto wndrect = reinterpret_cast<PRECT>(lParam);
VERIFY(SetWindowPos(
hWnd,
HWND_TOP,
0, 0,
wndrect->right - wndrect->left, wndrect->bottom - wndrect->top,
SWP_NOSIZE | SWP_NOMOVE
));

CPostEffects::SetupBackBufferVertex();

return 0;
}
case WM_ACTIVATEAPP: { // 0x748087
const auto wndBeingActivated = !!wParam;

Expand Down Expand Up @@ -317,7 +378,7 @@ LRESULT CALLBACK __MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara

return 0;
}
case WA_CLICKACTIVE:
case WM_DESTROY:
case WM_CLOSE: { // 0x747EF3
VERIFY(ClipCursor(nullptr));
VERIFY(SUCCEEDED(WinInput::Shutdown()));
Expand Down Expand Up @@ -447,46 +508,6 @@ LRESULT CALLBACK __MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
CTimer::SetCodePause(false);
break;
}
case WM_MOUSEFIRST: { //< 0x748323
FrontEndMenuManager.m_nMousePosWinX = GET_X_LPARAM(lParam);
FrontEndMenuManager.m_nMousePosWinY = GET_Y_LPARAM(lParam);
return 0;
}
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN: {
SetCapture(hWnd);
return 0;
}
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP: {
ReleaseCapture();
return 0;
}
case WM_MOUSEWHEEL: {
return 0;
}
case WM_SIZING: { // 0x74829E
if (RwInitialized) {
if (gGameState == GAME_STATE_IDLE) {
RsEventHandler(rsIDLE, (void*)TRUE);
}
}

const auto wndrect = reinterpret_cast<PRECT>(lParam);
VERIFY(SetWindowPos(
hWnd,
HWND_TOP,
0, 0,
wndrect->right - wndrect->left, wndrect->bottom - wndrect->top,
SWP_NOSIZE | SWP_NOMOVE
));

CPostEffects::SetupBackBufferVertex();

return 0;
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
Expand Down Expand Up @@ -822,7 +843,7 @@ void Win32InjectHooks() {

RH_ScopedGlobalInstall(GTATranslateShiftKey, 0x747CD0);
RH_ScopedGlobalInstall(GTATranslateKey, 0x747820);
RH_ScopedGlobalInstall(__MainWndProc, 0x747EB0);
RH_ScopedGlobalInstall(__MainWndProc, 0x747EB0, { .locked = true });

// Unhooking these 2 after the game has started will do nothing
RH_ScopedGlobalInstall(__WinMain, 0x748710);
Expand Down
4 changes: 4 additions & 0 deletions source/game_sa/Frontend/MenuManager_Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ void CMenuManager::CheckForMenuClosing() {

if (IsVideoModeExclusive()) {
DIReleaseMouse();
#ifdef FIX_BUGS // Causes the retarded fucktard code to not dispatch mouse input to WndProc => ImGUI mouse not working. Amazing piece of technology.
InitialiseMouse(false);
#else
InitialiseMouse(true);
#endif // !FIX_BUGS
}

m_fStatsScrollSpeed = 150.0f;
Expand Down
2 changes: 1 addition & 1 deletion source/game_sa/MenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void CMenuManager::InjectHooks() {
RH_ScopedInstall(CheckFrontEndDownInput, 0x5738B0);
RH_ScopedInstall(CheckFrontEndLeftInput, 0x573920);
RH_ScopedInstall(CheckFrontEndRightInput, 0x573990);
RH_ScopedInstall(CheckForMenuClosing, 0x576B70);
RH_ScopedInstall(CheckForMenuClosing, 0x576B70, { .locked = true }); // Must be hooked at all times otherwise imgui stops working! [The input at least does]
RH_ScopedInstall(CheckHover, 0x57C4F0);
RH_ScopedInstall(CheckMissionPackValidMenu, 0x57D720);
RH_ScopedInstall(CheckCodesForControls, 0x57DB20, { .reversed = false });
Expand Down
19 changes: 11 additions & 8 deletions source/game_sa/Pad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "StdInc.h"

#include "Pad.h"

#include "platform/win/Input.h"
#include "UIRenderer.h"
#include "ControllerConfigManager.h"
#include "app.h"
Expand Down Expand Up @@ -212,11 +212,16 @@ void CPad::Update(int32 pad) {

// 0x541DD0
void CPad::UpdatePads() {
GetPad(0)->UpdateMouse();
ProcessPad(false);
const auto& ImIONavActive = notsa::ui::UIRenderer::GetSingleton().GetImIO()->NavActive;

if (!ImIONavActive) {
GetPad(0)->UpdateMouse();
}

ProcessPad(false);
ControlsManager.ClearSimButtonPressCheckers();
if (!notsa::ui::UIRenderer::GetSingleton().Visible()) { // NOTSA: Don't handle updates if the menu is open, so we don't affect gameplay inputting text

if (!ImIONavActive) {
ControlsManager.AffectPadFromKeyBoard();
ControlsManager.AffectPadFromMouse();
GetPad(0)->Update(0);
Expand All @@ -225,8 +230,6 @@ void CPad::UpdatePads() {

OldKeyState = NewKeyState;
NewKeyState = TempKeyState;

notsa::ui::UIRenderer::GetSingleton().UpdateInput();
}

// 0x53F3C0
Expand Down Expand Up @@ -1190,10 +1193,10 @@ int GetCurrentKeyPressed(RsKeyCodes& keys) {
return plugin::CallAndReturn<int, 0x541490, RsKeyCodes&>(keys);
}

IDirectInputDevice8* DIReleaseMouse() {
IDirectInputDevice8* DIReleaseMouse() { // todo: wininput
return plugin::CallAndReturn<IDirectInputDevice8*, 0x746F70>();
}

void InitialiseMouse(bool exclusive) {
plugin::Call<0x7469A0, bool>(exclusive);
WinInput::InitialiseMouse(exclusive);
}
Loading

0 comments on commit 8b09631

Please sign in to comment.