psychonauts widescreen hud fix
@@ -178,10 +178,17 @@ DWORD WINAPI Init(LPVOID bDelay)
{
if (bWidescreenHud)
{
+ static auto idx = 0;
static void* stack[6];
CaptureStackBackTrace(0, 6, stack, NULL);
- if (stack[4] == dw_61F2EF || stack[5] == dw_61F2EF || stack[4] == dw_61F2FE || stack[5] == dw_61F2FE)
+ auto it = std::find_if(std::begin(stack), std::end(stack), [](void* n) { return n == dw_61F2EF || n == dw_61F2FE; });
+ if (!idx && it != std::end(stack))
+ idx = std::distance(std::begin(stack), it);
+
+ if (idx)
+ {
+ if (stack[idx] == dw_61F2EF || stack[idx + 1] == dw_61F2EF || stack[idx] == dw_61F2FE || stack[idx + 1] == dw_61F2FE)
{
flt_7933E0.a13 += Screen.fHudOffsetWide;
}
@@ -193,13 +200,13 @@ DWORD WINAPI Init(LPVOID bDelay)
<< "0x" << std::hex << std::setw(8) << std::setfill('0') << stack[4] << std::endl;
#endif
- if (stack[4] == dw_61EA8F || stack[4] == dw_616FB7 || stack[4] == dw_4FD37D)
+ if (stack[idx] == dw_61EA8F || stack[idx] == dw_616FB7 || stack[idx] == dw_4FD37D)
{
flt_7933E0.a13 -= Screen.fHudOffsetWide;
}
else
{
- if (stack[4] == dw_61EAC4 || stack[4] == dw_61EAF6 || stack[4] == dw_61EADD)
+ if (stack[idx] == dw_61EAC4 || stack[idx] == dw_61EAF6 || stack[idx] == dw_61EADD)
{
flt_7933E0.a13 += Screen.fHudOffsetWide;
}
@@ -209,6 +216,7 @@ DWORD WINAPI Init(LPVOID bDelay)
}
}
}
+ }
}; injector::MakeInline<HudHook2>(pattern.get_first(0), pattern.get_first(7)); //0x47C7CE, 0x47C7CE+7
//FMVs
