Skip to content

Commit

Permalink
Add window focus state capture.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyall committed Feb 22, 2024
1 parent 846bbd4 commit c74d75e
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ int iHasPassedIntro = 0;
int iRTCapX = 1920;
int iRTCapY = 1080;
float fRenTexResMulti = 1.0f;
BYTE iWindowFocusStatus = 0;

SafetyHookInline RenTexPostLoad{};
void* RenTexPostLoad_Hooked(uint8_t* thisptr)
Expand Down Expand Up @@ -703,22 +704,38 @@ void Framerate()

void Miscellaneous()
{
if (!bPauseOnFocusLoss)
// Window focus
uint8_t* WindowFocusScanResult = Memory::PatternScan(baseModule, "83 ?? ?? ?? 00 48 ?? ?? ?? 48 ?? ?? 0F ?? ?? FF ?? 38 ?? 00 00");
if (WindowFocusScanResult)
{
// Pause on focus loss
uint8_t* WindowFocusScanResult = Memory::PatternScan(baseModule, "83 ?? ?? ?? 00 48 ?? ?? ?? 48 ?? ?? 0F ?? ?? FF ?? 38 ?? 00 00");
if (WindowFocusScanResult)
{
spdlog::info("Window Focus: Address is {:s}+{:x}", sExeName.c_str(), (uintptr_t)WindowFocusScanResult - (uintptr_t)baseModule);
Memory::PatchBytes((uintptr_t)WindowFocusScanResult + 0x4, "\x7F", 1);
spdlog::info("Window Focus: Patched instruction.");
spdlog::info("Window Focus: Address is {:s}+{:x}", sExeName.c_str(), (uintptr_t)WindowFocusScanResult - (uintptr_t)baseModule);

}
else if (!WindowFocusScanResult)
{
spdlog::error("Window Focus: Pattern scan failed.");
}
static SafetyHookMid WindowFocusMidHook{};
WindowFocusMidHook = safetyhook::create_mid(WindowFocusScanResult + 0xC,
[](SafetyHookContext& ctx)
{
if (!bPauseOnFocusLoss)
{
// or ZF rflag
ctx.rflags &= 0x40;
}

if ((uint8_t)ctx.rflags + 0x40 == (uint8_t)66)
{
iWindowFocusStatus = 1;
}
else if ((uint8_t)ctx.rflags + 0x40 == (uint8_t)134)
{
iWindowFocusStatus = 0;
}
});

}
else if (!WindowFocusScanResult)
{
spdlog::error("Window Focus: Pattern scan failed.");
}

}

DWORD __stdcall Main(void*)
Expand Down

0 comments on commit c74d75e

Please sign in to comment.