Skip to content

Commit

Permalink
fixed a crash when a gang attacks your turf
Browse files Browse the repository at this point in the history
  • Loading branch information
dkluin committed Mar 22, 2017
1 parent 30fd4c3 commit b1b0283
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
9 changes: 5 additions & 4 deletions ExGangWars/ExGangWars.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -19,12 +19,14 @@
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -75,10 +77,9 @@
<SubSystem>Windows</SubSystem>
<MinimumRequiredVersion>5.0</MinimumRequiredVersion>
<AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
<PostBuildEvent>
<Command>copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\ExGangWars.asi"</Command>
</PostBuildEvent>
<PostBuildEvent />
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="General.h" />
Expand Down
46 changes: 37 additions & 9 deletions ExGangWars/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,53 @@ bool __stdcall CanNotPedtypeBeProvoked(int32_t nPedType)
return true;
}

// Silent: you should get rid of this, or change my code a bit or something...
int32_t GetRivalGangsTotalDensity(uint32_t nZoneExtraInfoID)
{
// We need to get a total strength of all gangs player can fight with
// so the game can decide whether to start a defensive gang war there
int32_t nTotalStrength = 0;

for ( int32_t i = 0; i < 10; i++ )
for (int32_t i = 0; i < 10; i++)
{
if ( CustomGangInfo[i].bCanFightWith )
if (CustomGangInfo[i].bCanFightWith)
nTotalStrength += ZoneInfoArray[nZoneExtraInfoID].GangDensity[i];
}
return nTotalStrength;
}

static DWORD FixGangWarInvalidZoneCrash_RET = 0x443B58;

static int32_t nTotalStrength;
static uint32_t nZoneExtraInfoID = 0;
static int32_t i;

__declspec(naked) void FixGangWarInvalidZoneCrash()
{
_asm pushad;
_asm movzx ebx, ax;
_asm mov nZoneExtraInfoID, ebx;

// Gets the total gang density
for (i = 0; i < 10; i++)
{
if (i != 8)
{
nTotalStrength += ZoneInfoArray[nZoneExtraInfoID].GangDensity[i];
}
}

// Compiler might generate code which uses some registers which are in use, so revert the register values to the ones before the code was executed.
_asm popad;

_asm
{
mov ebx, nTotalStrength
imul ebx, 0x11
jmp FixGangWarInvalidZoneCrash_RET
}
}

void FillZonesWithGangColours(bool bDontColour)
{
if ( TotalNumberOfZoneInfos )
Expand Down Expand Up @@ -212,13 +245,8 @@ void Patch_SA_10()
// Allow defensive gang wars in entire state
Patch<uint16_t>(0x443B9D, 0x65EB);

// push ebx \ call GetRivalGangsTotalDensity \ add esp, 4 \ imul ebx, 11h \ cmp eax, 14h
Patch<uint8_t>(0x443B55, 0x53);
Patch<uint32_t>(0x443B5B, 0x6B04C483);
Patch<uint32_t>(0x443B5F, 0xF88311DB);
Patch<uint32_t>(0x443B63, 0x90909014);
Nop(0x443B67, 4);
InjectHook(0x443B56, GetRivalGangsTotalDensity, PATCH_CALL);
// Calls fixed crash function
InjectHook(0x443B52, FixGangWarInvalidZoneCrash, PATCH_JUMP);

// lea edx, CTheZones::ZoneInfoArray[ebx] \ push edx \ call PickDefensiveGang
Patch<uint16_t>(0x443C3B, 0x938D);
Expand Down

0 comments on commit b1b0283

Please sign in to comment.