III: Backport one more fix from VC to fix the timer initialize lingering the audio entities on New Game

Fixes #123
This commit is contained in:
Silent 2024-11-28 20:41:17 +01:00
parent 50c3a47cd3
commit 2a597da1bc
No known key found for this signature in database
GPG key ID: AE53149BB0C45AF1
6 changed files with 39 additions and 11 deletions

View file

@ -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;
}

View file

@ -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 />

@ -1 +1 @@
Subproject commit 95e523fa7494c0353b7ecfab408024a9d7b7e161
Subproject commit 70cab494523e76d56063b5044c34345c14803c96

View file

@ -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;
@ -736,8 +736,6 @@ namespace VariableResets
}, var );
}
// Functions that should have been called by the game but aren't...
TimerInitialise();
PurpleNinesGlitchFix();
}
@ -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);
}
@ -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

View file

@ -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;
@ -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>
@ -1167,6 +1164,7 @@ namespace VariableResets
void GameInitialise(const char* path)
{
ReInitOurVariables();
TimerInitialise();
orgGameInitialise(path);
}
}
@ -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);

View file

@ -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 />