Skip to content

Commit

Permalink
Fix game not focussing after F7, add version check
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Jul 13, 2022
1 parent 08fbaab commit 9749229
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
9 changes: 0 additions & 9 deletions Hooking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,15 +758,6 @@ LRESULT hooked_RegularWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
// set menu focus
menu->SetFocus(!focus);
menu->SetVisibility(!focus);

// disable game input
#if TRAE
*(bool*)0x8551A9 = Hooking::GetInstance().GetMenu()->IsFocus();
#elif TR8
*(bool*)0xA02B79 = Hooking::GetInstance().GetMenu()->IsFocus();
#elif TR7
*(bool*)ADDR(0x110AF09, 0x1101689) = Hooking::GetInstance().GetMenu()->IsFocus();
#endif
}

// pass input to menu
Expand Down
11 changes: 10 additions & 1 deletion Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void Menu::Process(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
// if menu is focussed and being hidden also stop focus
if (m_focus && !m_visible)
{
m_focus = false;
SetFocus(false);
}
}

Expand Down Expand Up @@ -1121,6 +1121,15 @@ FreeCameraMode Menu::GetFreeCamMode() const noexcept
void Menu::SetFocus(bool value) noexcept
{
m_focus = value;

// enable/disable game input
#if TRAE
* (bool*)0x8551A9 = m_focus;
#elif TR8
* (bool*)0xA02B79 = m_focus;
#elif TR7
* (bool*)ADDR(0x110AF09, 0x1101689) = m_focus;
#endif
}

bool Menu::IsVisible() const noexcept
Expand Down
2 changes: 1 addition & 1 deletion data/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
// Removes the ~5 seconds legal screen while starting the game.
// Removes the ~5 seconds legal screen while starting the game (Legend, Anniversary).
"remove_legal_screen": true
}
23 changes: 23 additions & 0 deletions dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ BOOL WINAPI hGetVersionExA(LPOSVERSIONINFOA lpStartupInfo)
return dGetVersionExA(lpStartupInfo);
}

bool CheckVersion()
{
auto hModule = GetModuleHandleA(nullptr);
auto header = (PIMAGE_NT_HEADERS)((DWORD_PTR)hModule + ((PIMAGE_DOS_HEADER)hModule)->e_lfanew);

#if RETAIL_VERSION
// if retail check if not debug exe timestamp
return header->FileHeader.TimeDateStamp != 0x446DCF16;
#else
// if debug check for debug exe timestamp
return header->FileHeader.TimeDateStamp == 0x446DCF16;
#endif
}

DWORD WINAPI Hook(LPVOID lpParam)
{
MH_Initialize();
Expand All @@ -35,6 +49,15 @@ DWORD WINAPI Hook(LPVOID lpParam)

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
// since there could be retail and debug asi in same folder
// unload early if exe timestamp is wrong one
#if TR7
if (!CheckVersion())
{
return FALSE;
}
#endif

switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
Expand Down

0 comments on commit 9749229

Please sign in to comment.