Skip to content

Commit

Permalink
Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Whitetiger committed Apr 9, 2014
1 parent 71e9252 commit 992996e
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 186 deletions.
186 changes: 0 additions & 186 deletions crashes/crashes/crashes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
Expand Down Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions crashes/crashes/crashes.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="crashes.h" />
<ClInclude Include="fixes.h" />
<ClInclude Include="gammaramp.h" />
<ClInclude Include="main.h" />
<ClInclude Include="memory.h" />
Expand All @@ -107,6 +108,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="fixes.cpp" />
<ClCompile Include="gammaramp.cpp" />
<ClCompile Include="log.cpp" />
<ClCompile Include="memory.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions crashes/crashes/crashes.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<ClInclude Include="main.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="fixes.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="crashes.cpp">
Expand All @@ -89,5 +92,8 @@
<ClCompile Include="quickload.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="fixes.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions crashes/crashes/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "patcher.h"
#include "quickload.h"
#include "main.h"
#include "fixes.h"
#include <iostream>
#include <fstream>
#include <Wininet.h>
Expand Down Expand Up @@ -379,6 +380,7 @@ static void WINAPI Load() {
}

InitHooks_CrashFixHacks ( );
InitHooks_Fixes( );

CGammaRamp GammaRamp;

Expand Down
Loading

0 comments on commit 992996e

Please sign in to comment.