diff --git a/crashes/crashes/crashes.cpp b/crashes/crashes/crashes.cpp index 93e128d..94f4396 100644 --- a/crashes/crashes/crashes.cpp +++ b/crashes/crashes/crashes.cpp @@ -1125,187 +1125,6 @@ int getGameVersion() { return -1; } -// -// Volumetric shadow hooks -// - -#define HOOKPOS_GetFxQuality 0x49EA50 -void HOOK_GetFxQuality (); - -#define HOOKPOS_StoreShadowForVehicle 0x70BDA0 -DWORD RETURN_StoreShadowForVehicle = 0x70BDA9; -void HOOK_StoreShadowForVehicle (); - -DWORD dwFxQualityValue = 0; -WORD usCallingForVehicleModel = 0; -bool volumetricShadows = false; - -void setVolumetricShadows(bool value) { - volumetricShadows = value; -} - -void _cdecl MaybeAlterFxQualityValue ( DWORD dwAddrCalledFrom ) -{ - // Handle all calls from CVolumetricShadowMgr - if ( dwAddrCalledFrom > 0x70F990 && dwAddrCalledFrom < 0x711EB0 ) - { - // Force blob shadows if volumetric shadows are not enabled - if ( !volumetricShadows ) - dwFxQualityValue = 0; - - // These vehicles seem to have problems with volumetric shadows, so force blob shadows - switch ( usCallingForVehicleModel ) - { - case 460: // Skimmer - case 511: // Beagle - case 572: // Mower - case 590: // Box Freight - case 592: // Andromada - dwFxQualityValue = 0; - } - usCallingForVehicleModel = 0; - } - else - // Handle all calls from CPed::PreRenderAfterTest - if ( dwAddrCalledFrom > 0x5E65A0 && dwAddrCalledFrom < 0x5E7680 ) - { - // Always use blob shadows for peds as realtime shadows are disabled in MTA (context switching issues) - dwFxQualityValue = 0; - } -} - -// Hooked from 0x49EA50 -void _declspec(naked) HOOK_GetFxQuality () -{ - _asm - { - pushad - mov eax, [ecx+054h] // Current FxQuality setting - mov dwFxQualityValue, eax - - mov eax, [esp+32] // Address GetFxQuality was called from - push eax - call MaybeAlterFxQualityValue - add esp, 4 - } - - _asm - { - popad - } - - _asm - { - mov eax, dwFxQualityValue - retn - } -} - -// Hook to discover what vehicle will be calling GetFxQuality -void _declspec(naked) HOOK_StoreShadowForVehicle () -{ - _asm - { - // Hooked from 0x70BDA0 5 bytes - mov eax, [esp+4] // Get vehicle - mov ax, [eax+34] // pEntity->m_nModelIndex - mov usCallingForVehicleModel, ax - sub esp, 44h - push ebx - mov eax, 0x70F9B0 // CVolumetricShadowMgr::IsAvailable - call eax - jmp RETURN_StoreShadowForVehicle - } -} - -//#define HOOKPOS_FixClimbBug 0x04B5AE5 -#define HOOKPOS_FixClimbBug 0x05E3054 -#define SECOND_HOOKPOS_FixClimbBug 0x05E2F8F -#define HOOKSIZE_FixClimbBug 5 -DWORD RETURN_FixClimbBug = 0x5E3059; -DWORD calltakedmg = 0x04b5ac0; -DWORD ignoretakedmg = 0x04b5ac6; -DWORD dmg = 0x04B5CDC; -//DWORD fixClimbBugAlt_DWORD = 005E3054; - -DWORD g_iPlayer = 0; - -DWORD dwTmp = 0; -DWORD dwTmpEcx = 0; -DWORD dwTmpEax = 0; -void _declspec(naked) HOOK_FixClimbBug () { - - _asm mov [dwTmp],edx - _asm mov [dwTmpEcx],ecx - _asm mov [dwTmpEax],eax - - g_iPlayer = *(int*)0xB6F5F0; - - if(*(BYTE*)(g_iPlayer + 0x46D) == 34 || *(BYTE*)(g_iPlayer + 0x15C) != 0) { - _asm { - mov edx,[dwTmp] - mov eax,[dwTmpEax] - mov ecx,[dwTmpEcx] - call ignoretakedmg - jmp RETURN_FixClimbBug - } - } - - - _asm { - mov edx,[dwTmp] - mov eax,[dwTmpEax] - mov ecx,[dwTmpEcx] - call calltakedmg - jmp RETURN_FixClimbBug - } -} - -#define HOOKPOS_FixClimbBug2 0x04B5AE5 -#define HOOKSIZE_FixClimbBug2 6 -#define FixClimbBug_alt 0x04B5CDC -#define RETURN_FixClimbBug2 0x04B5AEB -DWORD dwRETURN_FixClimbBug2 = 0x04B5AEB; -DWORD fixClimbBugAlt_DWORD = 0x04B5CDC; - -void _declspec(naked) HOOK_FixClimbBug2 () { - - /*asm { - jnz FixClimbBug_alt - cmp edi,1 - jne RETURN_FixClimbBug2 - }*/ - - _asm { - jnz FixClimbBug_alt - mov [dwTmp],edi - mov [dwTmpEcx],ecx - mov [dwTmpEax],eax - } - - if(dwTmp != 1) { - _asm { - mov ecx,[dwTmpEcx] - mov eax,[dwTmpEax] - jmp dwRETURN_FixClimbBug2 - } - } - - - g_iPlayer = *(int*)0xB6F5F0; - - if(*(BYTE*)(g_iPlayer + 0x46D) == 34 || *(BYTE*)(g_iPlayer + 0x15C) != 0) { - _asm { - jmp fixClimbBugAlt_DWORD - } - } - - _asm { - mov ecx,[dwTmpEcx] - mov eax,[dwTmpEax] - jmp dwRETURN_FixClimbBug2 - } -} void InitHooks_CrashFixHacks () { @@ -1338,11 +1157,6 @@ void InitHooks_CrashFixHacks () EZHookInstall ( CrashFix_Misc27 ); EZHookInstall ( CrashFix_Misc28 ); EZHookInstall ( CrashFix_Misc29 ); - HookInstall ( HOOKPOS_GetFxQuality, (DWORD)HOOK_GetFxQuality, 5 ); - HookInstall ( HOOKPOS_StoreShadowForVehicle, (DWORD)HOOK_StoreShadowForVehicle, 9 ); EZHookInstall ( CClumpModelInfo_GetFrameFromId ); EZHookInstall ( Rtl_fopen ); - EZHookInstall ( FixClimbBug ); - EZHookInstall ( FixClimbBug2 ); - HookInstall( SECOND_HOOKPOS_FixClimbBug, (DWORD)HOOK_FixClimbBug, 5); } \ No newline at end of file diff --git a/crashes/crashes/crashes.vcxproj b/crashes/crashes/crashes.vcxproj index 2d60bd2..20461c7 100644 --- a/crashes/crashes/crashes.vcxproj +++ b/crashes/crashes/crashes.vcxproj @@ -82,6 +82,7 @@ + @@ -107,6 +108,7 @@ + diff --git a/crashes/crashes/crashes.vcxproj.filters b/crashes/crashes/crashes.vcxproj.filters index 70423ab..b2061f2 100644 --- a/crashes/crashes/crashes.vcxproj.filters +++ b/crashes/crashes/crashes.vcxproj.filters @@ -63,6 +63,9 @@ Header Files + + Header Files + @@ -89,5 +92,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/crashes/crashes/dllmain.cpp b/crashes/crashes/dllmain.cpp index d2b5d69..67abbdb 100644 --- a/crashes/crashes/dllmain.cpp +++ b/crashes/crashes/dllmain.cpp @@ -11,6 +11,7 @@ #include "patcher.h" #include "quickload.h" #include "main.h" +#include "fixes.h" #include #include #include @@ -379,6 +380,7 @@ static void WINAPI Load() { } InitHooks_CrashFixHacks ( ); + InitHooks_Fixes( ); CGammaRamp GammaRamp; diff --git a/crashes/crashes/fixes.cpp b/crashes/crashes/fixes.cpp new file mode 100644 index 0000000..05cdc9d --- /dev/null +++ b/crashes/crashes/fixes.cpp @@ -0,0 +1,195 @@ +#include +#include "fixes.h" +#include "multiplayer_hooksystem.h" + + +#define HOOKPOS_GetFxQuality 0x49EA50 +void HOOK_GetFxQuality (); + +#define HOOKPOS_StoreShadowForVehicle 0x70BDA0 +DWORD RETURN_StoreShadowForVehicle = 0x70BDA9; +void HOOK_StoreShadowForVehicle (); + +DWORD dwFxQualityValue = 0; +WORD usCallingForVehicleModel = 0; +bool volumetricShadows = false; + +void setVolumetricShadows(bool value) { + volumetricShadows = value; +} + +// +// Volumetric shadow hooks +// + +void _cdecl MaybeAlterFxQualityValue ( DWORD dwAddrCalledFrom ) +{ + // Handle all calls from CVolumetricShadowMgr + if ( dwAddrCalledFrom > 0x70F990 && dwAddrCalledFrom < 0x711EB0 ) + { + // Force blob shadows if volumetric shadows are not enabled + if ( !volumetricShadows ) + dwFxQualityValue = 0; + + // These vehicles seem to have problems with volumetric shadows, so force blob shadows + switch ( usCallingForVehicleModel ) + { + case 460: // Skimmer + case 511: // Beagle + case 572: // Mower + case 590: // Box Freight + case 592: // Andromada + dwFxQualityValue = 0; + } + usCallingForVehicleModel = 0; + } + else + // Handle all calls from CPed::PreRenderAfterTest + if ( dwAddrCalledFrom > 0x5E65A0 && dwAddrCalledFrom < 0x5E7680 ) + { + // Always use blob shadows for peds as realtime shadows are disabled in MTA (context switching issues) + dwFxQualityValue = 0; + } +} + +// Hooked from 0x49EA50 +void _declspec(naked) HOOK_GetFxQuality () +{ + _asm + { + pushad + mov eax, [ecx+054h] // Current FxQuality setting + mov dwFxQualityValue, eax + + mov eax, [esp+32] // Address GetFxQuality was called from + push eax + call MaybeAlterFxQualityValue + add esp, 4 + } + + _asm + { + popad + } + + _asm + { + mov eax, dwFxQualityValue + retn + } +} + +// Hook to discover what vehicle will be calling GetFxQuality +void _declspec(naked) HOOK_StoreShadowForVehicle () +{ + _asm + { + // Hooked from 0x70BDA0 5 bytes + mov eax, [esp+4] // Get vehicle + mov ax, [eax+34] // pEntity->m_nModelIndex + mov usCallingForVehicleModel, ax + sub esp, 44h + push ebx + mov eax, 0x70F9B0 // CVolumetricShadowMgr::IsAvailable + call eax + jmp RETURN_StoreShadowForVehicle + } +} + +#define HOOKPOS_FixClimbBug 0x05E3054 +#define SECOND_HOOKPOS_FixClimbBug 0x05E2F8F +#define HOOKSIZE_FixClimbBug 5 + +DWORD RETURN_FixClimbBug = 0x5E3059; +DWORD dwSendDmgToServer = 0x04b5ac0; +DWORD dwDontSendDmgToServer = dwSendDmgToServer + 0x6; + +DWORD g_dwPlayer = 0; + +DWORD dwTmp = 0; +DWORD dwTmpEcx = 0; +DWORD dwTmpEax = 0; + +void _declspec(naked) HOOK_FixClimbBug () { + + _asm mov [dwTmp],edx + _asm mov [dwTmpEcx],ecx + _asm mov [dwTmpEax],eax + + g_dwPlayer = *(int*)0xB6F5F0; + + if(*(BYTE*)(g_dwPlayer + 0x46D) == 34 || *(BYTE*)(g_dwPlayer + 0x15C) != 0) { + _asm { + mov edx,[dwTmp] + mov eax,[dwTmpEax] + mov ecx,[dwTmpEcx] + call dwDontSendDmgToServer + jmp RETURN_FixClimbBug + } + } + + + _asm { + mov edx,[dwTmp] + mov eax,[dwTmpEax] + mov ecx,[dwTmpEcx] + call dwSendDmgToServer + jmp RETURN_FixClimbBug + } +} + +#define HOOKPOS_FixClimbBug2 0x04B5AE5 +#define HOOKSIZE_FixClimbBug2 6 +#define FixClimbBug_alt 0x04B5CDC +#define RETURN_FixClimbBug2 0x04B5AEB +DWORD dwRETURN_FixClimbBug2 = 0x04B5AEB; +DWORD dwfixClimbBugAlt = 0x04B5CDC; + +void _declspec(naked) HOOK_FixClimbBug2 () { + + /*asm { + jnz FixClimbBug_alt + cmp edi,1 + jne RETURN_FixClimbBug2 + }*/ + + _asm { + jnz FixClimbBug_alt + mov [dwTmp],edi + mov [dwTmpEcx],ecx + mov [dwTmpEax],eax + } + + if(dwTmp != 1) { + _asm { + mov ecx,[dwTmpEcx] + mov eax,[dwTmpEax] + jmp dwRETURN_FixClimbBug2 + } + } + + + g_dwPlayer = *(int*)0xB6F5F0; + + if(*(BYTE*)(g_dwPlayer + 0x46D) == 34 || *(BYTE*)(g_dwPlayer + 0x15C) != 0) { + _asm { + jmp dwfixClimbBugAlt + } + } + + _asm { + mov ecx,[dwTmpEcx] + mov eax,[dwTmpEax] + jmp dwRETURN_FixClimbBug2 + } +} + +void InitHooks_Fixes () +{ + HookInstall ( HOOKPOS_GetFxQuality, (DWORD)HOOK_GetFxQuality, 5 ); + HookInstall ( HOOKPOS_StoreShadowForVehicle, (DWORD)HOOK_StoreShadowForVehicle, 9 ); + + EZHookInstall ( FixClimbBug ); + EZHookInstall ( FixClimbBug2 ); + HookInstall( SECOND_HOOKPOS_FixClimbBug, (DWORD)HOOK_FixClimbBug, 5); +} \ No newline at end of file diff --git a/crashes/crashes/fixes.h b/crashes/crashes/fixes.h new file mode 100644 index 0000000..958c587 --- /dev/null +++ b/crashes/crashes/fixes.h @@ -0,0 +1,4 @@ +#pragma once + +void setVolumetricShadows(bool value); +void InitHooks_Fixes(); \ No newline at end of file