@@ -74,20 +74,52 @@ void InitImGui() // Initializes ImGui, alongside the needed fonts.
74
74
{
75
75
CreateContext ();
76
76
ImGuiIO& io = GetIO ();
77
+ // TODO: Figure out how to disable gamepad input to the game when the interface is open, and also make sure gamepad input is consistent.
78
+ // TODO: Find a way to add a gamepad hotkey to open the menu.
77
79
io.ConfigFlags = ImGuiConfigFlags_NoMouseCursorChange | ImGuiConfigFlags_NavEnableGamepad | ImGuiConfigFlags_NavEnableKeyboard;
78
80
LocalizationRm.InitFont (PlayerSettingsRm.INS .dpiScale / 100 .0f * PlayerSettingsRm.INS .dpiScaleMultiplier );
79
81
80
82
ImGui_ImplWin32_Init (window);
81
83
ImGui_ImplDX11_Init (pDevice, pContext);
82
84
}
83
85
84
- // Another function relating to imgui functionality .
86
+ // TODO: Figure out why this isn't disabling input from gameplay .
85
87
LRESULT __stdcall WndProc (const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
86
88
{
87
- if (true && ImGui_ImplWin32_WndProcHandler (hWnd, uMsg, wParam, lParam)) {
88
- return true ;
89
+ if (InitHook) {
90
+ // Toggle UI visibility with key presses
91
+ if (uMsg == WM_KEYUP) {
92
+ if (wParam == VK_DELETE)
93
+ PlayerSettingsRm.ShowEFUI = !PlayerSettingsRm.ShowEFUI ;
94
+ else if (wParam == VK_OEM_3)
95
+ PlayerSettingsRm.ShowDevConsole = !PlayerSettingsRm.ShowDevConsole ;
96
+ }
97
+ // If UI is active, block input from the game, but allow ImGui to handle it
98
+ if (PlayerSettingsRm.ShowEFUI ) {
99
+ // Pass input to ImGui first
100
+ if (ImGui_ImplWin32_WndProcHandler (hWnd, uMsg, wParam, lParam)) {
101
+ return true ; // ImGui handled the input, return early
102
+ }
103
+ // If ImGui didn't handle the input, block it from reaching the game
104
+ switch (uMsg)
105
+ {
106
+ case WM_MOUSEMOVE:
107
+ case WM_LBUTTONDOWN: case WM_LBUTTONUP:
108
+ case WM_RBUTTONDOWN: case WM_RBUTTONUP:
109
+ case WM_MBUTTONDOWN: case WM_MBUTTONUP:
110
+ case WM_MOUSEWHEEL:
111
+ case WM_KEYDOWN: case WM_KEYUP:
112
+ case WM_CHAR:
113
+ case WM_INPUT: // Block Raw Input if game uses DirectInput
114
+ return 0 ; // Absorb the event (block the game)
115
+ }
116
+ }
89
117
}
90
- return CallWindowProc (oWndProc, hWnd, uMsg, wParam, lParam);
118
+ // If UI is not active, pass input to the original window procedure (game)
119
+ if (oWndProc)
120
+ return CallWindowProc (oWndProc, hWnd, uMsg, wParam, lParam);
121
+ else
122
+ return DefWindowProc (hWnd, uMsg, wParam, lParam); // Fallback if oWndProc is invalid
91
123
}
92
124
93
125
// An easily callable function to make the CreateTexture2D hook a little cleaner.
@@ -360,8 +392,8 @@ namespace EnigmaFix {
360
392
// A hook that contains the needed logic for adding the imgui interface, and forcing flip model presentation.
361
393
HRESULT __stdcall RenderManager::hkPresent (IDXGISwapChain *pSwapChain, UINT SyncInterval, UINT Flags) // Here's what happens when the swapchain is ready to be presented.
362
394
{
363
- if (!InitHook) { // Checks if the hook hasn't been initalized , and if not, does the needed deeds to hook ImGui.
364
- HRESULT hr = pSwapChain->GetDevice (__uuidof (ID3D11Device), ( void **) &pDevice);
395
+ if (!InitHook) { // Checks if the hook hasn't been initialized , and if not, does the needed deeds to hook ImGui.
396
+ HRESULT hr = pSwapChain->GetDevice (__uuidof (ID3D11Device), reinterpret_cast < void **>( &pDevice) );
365
397
if (SUCCEEDED (hr))
366
398
{
367
399
pDevice->GetImmediateContext (&pContext);
@@ -371,27 +403,19 @@ namespace EnigmaFix {
371
403
PlayerSettingsRm.INS .dpiScale = Util::GetDPIScaleForWindow (window) * 100 .0f ;
372
404
spdlog::info (" RenderManager: Current DPI Scale is {}%." , PlayerSettingsRm.INS .dpiScale );
373
405
ID3D11Texture2D* pBackBuffer;
374
- hr = pSwapChain->GetBuffer (0 , __uuidof (ID3D11Texture2D), ( LPVOID*) &pBackBuffer);
406
+ hr = pSwapChain->GetBuffer (0 , __uuidof (ID3D11Texture2D), reinterpret_cast < LPVOID*>( &pBackBuffer) );
375
407
if (SUCCEEDED (hr)) {
376
408
pDevice->CreateRenderTargetView (pBackBuffer, NULL , &mainRenderTargetView);
377
409
pBackBuffer->Release ();
378
410
}
379
411
else { throw std::runtime_error (" Failed to get swapchain back buffer." ); } // Throw a standard C++ exception with an error message.
380
- oWndProc = ( WNDPROC) SetWindowLongPtr (window, GWLP_WNDPROC, ( LONG_PTR) WndProc);
412
+ oWndProc = reinterpret_cast < WNDPROC>( SetWindowLongPtr (window, GWLP_WNDPROC, reinterpret_cast < LONG_PTR>( WndProc)) );
381
413
InitImGui ();
382
414
InitHook = true ;
383
415
}
384
416
else { throw std::runtime_error (" Failed to get swapchain device." ); }
385
417
}
386
418
387
- if (GetAsyncKeyState (VK_DELETE) & 1 ) { // Checks if "DEL" key was pressed, and toggles the boolean that shows the UI.
388
- PlayerSettingsRm.ShowEFUI = !PlayerSettingsRm.ShowEFUI ;
389
- }
390
-
391
- if (GetAsyncKeyState (VK_OEM_3) & 1 ) { // Checks if "~/`/Tilde" key was pressed, and toggles the developer console UI.
392
- PlayerSettingsRm.ShowDevConsole = !PlayerSettingsRm.ShowDevConsole ;
393
- }
394
-
395
419
// TODO: Implement developer console and find a way to pipe SpdLog and standard logging to it.
396
420
PlayerSettingsRm.ShowUI = PlayerSettingsRm.ShowEFUI || PlayerSettingsRm.ShowDevConsole ; // Checks if either EFUI or the dev console are enabled, and if so, enable the showUI flag.
397
421
0 commit comments