Skip to content

Commit

Permalink
III: Backport one more fix from VC to fix the timer initialize linger…
Browse files Browse the repository at this point in the history
…ing the audio entities on New Game

Fixes #123
  • Loading branch information
CookiePLMonster committed Nov 28, 2024
1 parent 50c3a47 commit 2a597da
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
4 changes: 3 additions & 1 deletion DDraw/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ static bool PatchIAT()

static bool PatchIAT_ByPointers()
{
using namespace Memory::VP;

pOrgSystemParametersInfoA = SystemParametersInfoA;
memcpy( orgCode, pOrgSystemParametersInfoA, sizeof(orgCode) );
Memory::VP::InjectHook( pOrgSystemParametersInfoA, SystemParametersInfoA_OverwritingHook, Memory::HookType::Jump );
InjectHook( pOrgSystemParametersInfoA, SystemParametersInfoA_OverwritingHook, HookType::Jump );
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion DDraw/versionmeta.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<SILENTPATCH_EXT>.dll</SILENTPATCH_EXT>
<SILENTPATCH_FULL_NAME>SilentPatch DDraw Component</SILENTPATCH_FULL_NAME>
<SILENTPATCH_REVISION_ID>6</SILENTPATCH_REVISION_ID>
<SILENTPATCH_BUILD_ID>0</SILENTPATCH_BUILD_ID>
<SILENTPATCH_BUILD_ID>1</SILENTPATCH_BUILD_ID>
<SILENTPATCH_COPYRIGHT>2014-2024</SILENTPATCH_COPYRIGHT>
</PropertyGroup>
<PropertyGroup />
Expand Down
2 changes: 1 addition & 1 deletion SilentPatch/Utils
Submodule Utils updated 2 files
+4 −2 HookInit.hpp
+14 −2 MemoryMgr.h
32 changes: 29 additions & 3 deletions SilentPatchIII/SilentPatchIII.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ namespace DodoKeyboardControls
// ============= Resetting stats and variables on New Game =============
namespace VariableResets
{
static auto TimerInitialise = reinterpret_cast<void(*)()>(hook::get_pattern("83 E4 F8 68 ? ? ? ? E8", -6));
static void (*TimerInitialise)();

using VarVariant = std::variant< bool*, int* >;
std::vector<VarVariant> GameVariablesToReset;
Expand All @@ -736,8 +736,6 @@ namespace VariableResets
}, var );
}

// Functions that should have been called by the game but aren't...
TimerInitialise();
PurpleNinesGlitchFix();
}

Expand All @@ -757,8 +755,22 @@ namespace VariableResets
void GameInitialise(const char* path)
{
ReInitOurVariables();
TimerInitialise();
orgGameInitialise(path);
}

static void (__fastcall* DestroyAllGameCreatedEntities)(void* DMAudio);

template<std::size_t Index>
static void (__fastcall* orgService)(void* DMAudio);

template<std::size_t Index>
static void __fastcall Service_AndDestroyEntities(void* DMAudio)
{
DestroyAllGameCreatedEntities(DMAudio);
orgService<Index>(DMAudio);
}
HOOK_EACH_INIT(Service, orgService, Service_AndDestroyEntities);
}


Expand Down Expand Up @@ -2354,8 +2366,22 @@ void Patch_III_Common()
get_pattern("C6 05 ? ? ? ? ? E8 ? ? ? ? C7 05", 7)
};

TimerInitialise = reinterpret_cast<decltype(TimerInitialise)>(get_pattern("83 E4 F8 68 ? ? ? ? E8", -6));

// In GTA III, we also need to backport one more fix from VC to avoid issues with looping audio entities:
// CMenuManager::DoSettingsBeforeStartingAGame needs to call cDMAudio::DestroyAllGameCreatedEntities
DestroyAllGameCreatedEntities = reinterpret_cast<decltype(DestroyAllGameCreatedEntities)>(ReadCallFrom(
get_pattern("B9 ? ? ? ? E8 ? ? ? ? 31 DB BD ? ? ? ? 8D 40 00", 5)));

auto audio_service = pattern("B9 ? ? ? ? E8 ? ? ? ? B9 ? ? ? ? C6 05 ? ? ? ? ? E8").count(2);
std::array<void*, 2> audio_service_instances = {
audio_service.get(0).get<void>(5),
audio_service.get(1).get<void>(5),
};

InterceptCall(game_initialise, orgGameInitialise, GameInitialise);
HookEach_ReInitGameObjectVariables(reinit_game_object_variables, InterceptCall);
HookEach_Service(audio_service_instances, InterceptCall);

// Variables to reset
GameVariablesToReset.emplace_back(*get_pattern<bool*>("80 3D ? ? ? ? ? 74 2A", 2)); // Free resprays
Expand Down
8 changes: 4 additions & 4 deletions SilentPatchVC/SilentPatchVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ namespace IsPlayerTargettingCharFix
// ============= Resetting stats and variables on New Game =============
namespace VariableResets
{
static auto TimerInitialise = reinterpret_cast<void(*)()>(hook::get_pattern("83 E4 F8 68 ? ? ? ? E8", -6));
static void (*TimerInitialise)();

using VarVariant = std::variant< bool*, int* >;
std::vector<VarVariant> GameVariablesToReset;
Expand All @@ -1146,9 +1146,6 @@ namespace VariableResets
*v = {};
}, var );
}

// Functions that should have been called by the game but aren't...
TimerInitialise();
}

template<std::size_t Index>
Expand All @@ -1167,6 +1164,7 @@ namespace VariableResets
void GameInitialise(const char* path)
{
ReInitOurVariables();
TimerInitialise();
orgGameInitialise(path);
}
}
Expand Down Expand Up @@ -2798,6 +2796,8 @@ void Patch_VC_Common()
get_pattern("C6 05 ? ? ? ? ? E8 ? ? ? ? C7 05", 7)
};

TimerInitialise = reinterpret_cast<decltype(TimerInitialise)>(get_pattern("83 E4 F8 68 ? ? ? ? E8", -6));

InterceptCall(game_initialise, orgGameInitialise, GameInitialise);
HookEach_ReInitGameObjectVariables(reinit_game_object_variables, InterceptCall);

Expand Down
2 changes: 1 addition & 1 deletion SilentPatchVC/versionmeta.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<SILENTPATCH_EXT>.asi</SILENTPATCH_EXT>
<SILENTPATCH_FULL_NAME>SilentPatch for Vice City</SILENTPATCH_FULL_NAME>
<SILENTPATCH_REVISION_ID>11</SILENTPATCH_REVISION_ID>
<SILENTPATCH_BUILD_ID>1</SILENTPATCH_BUILD_ID>
<SILENTPATCH_BUILD_ID>2</SILENTPATCH_BUILD_ID>
<SILENTPATCH_COPYRIGHT>2013-2024</SILENTPATCH_COPYRIGHT>
</PropertyGroup>
<PropertyGroup />
Expand Down

0 comments on commit 2a597da

Please sign in to comment.