From bc5ef7e0b1150b987070909d174061c18090d127 Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Mon, 19 Feb 2024 21:20:00 +0800 Subject: [PATCH] [saco] Implement `HookRwRenderStateSet()` Implements: * `HookRwRenderStateSet()` * `RwRenderStateSetHook()` --- saco/main.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/saco/main.cpp b/saco/main.cpp index 206b778..e20fb86 100644 --- a/saco/main.cpp +++ b/saco/main.cpp @@ -47,6 +47,12 @@ void TheGraphicsLoop(); LONG WINAPI exc_handler(_EXCEPTION_POINTERS* exc_inf); void sub_1009DD50(); +DWORD dwOrgRwSetState=0; +DWORD dwSetStateCaller=0; +DWORD dwSetStateOption=0; +DWORD dwSetStateParam=0; +char dbgstr[256]; + // polls the game until it's able to run. void LaunchMonitor(PVOID v) { @@ -221,6 +227,51 @@ void SetupD3DFog(BOOL bEnable) //---------------------------------------------------- +void _declspec(naked) RwRenderStateSetHook() +{ + _asm mov eax, [esp] + _asm mov dwSetStateCaller, eax + _asm mov eax, [esp+4] + _asm mov dwSetStateOption, eax + _asm mov eax, [esp+8] + _asm mov dwSetStateParam, eax + + if(dwSetStateOption == 14) { + if(dwSetStateParam) { + SetupD3DFog(TRUE); + dwFogEnabled = 1; + } else { + SetupD3DFog(FALSE); + dwFogEnabled = 0; + } + _asm mov [esp+8], 0 ; no fog + } + + _asm mov eax, dwOrgRwSetState + _asm jmp eax +} + +//---------------------------------------------------- + +void HookRwRenderStateSet() +{ + DWORD dwNewRwSetState = (DWORD)RwRenderStateSetHook; + + _asm mov ebx, 0xC97B24 + _asm mov eax, [ebx] + _asm mov edx, [eax+32] + _asm mov dwOrgRwSetState, edx + _asm mov edx, dwNewRwSetState + _asm mov [eax+32], edx + +#ifdef _DEBUG + sprintf(dbgstr,"HookRwRenderStateSet(0x%X)",dwOrgRwSetState); + OutputDebugString(dbgstr); +#endif +} + +//---------------------------------------------------- + void CallRwRenderStateSet(int state, int option) { _asm push option