mirror of
https://github.com/CookiePLMonster/SilentPatch.git
synced 2024-12-28 23:03:01 +05:00
Set up facilities for delayed patching in III/VC
This commit is contained in:
parent
f9a77d2ddd
commit
da5b5b1e12
4 changed files with 55 additions and 6 deletions
|
@ -19,6 +19,42 @@ namespace HandlingNameLoadFix
|
|||
}
|
||||
};
|
||||
|
||||
// ============= Delayed patches =============
|
||||
namespace DelayedPatches
|
||||
{
|
||||
static bool delayedPatchesDone = false;
|
||||
void (*Func)();
|
||||
|
||||
static BOOL (*RsEventHandler)(int, void*);
|
||||
static void (WINAPI **OldSetPreference)(int a, int b);
|
||||
void WINAPI Inject_MSS(int a, int b)
|
||||
{
|
||||
(*OldSetPreference)(a, b);
|
||||
if ( !std::exchange(delayedPatchesDone, true) )
|
||||
{
|
||||
if ( Func != nullptr ) Func();
|
||||
// So we don't have to revert patches
|
||||
HMODULE hDummyHandle;
|
||||
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN, (LPCTSTR)&Inject_MSS, &hDummyHandle);
|
||||
}
|
||||
}
|
||||
const auto pInjectMSS = Inject_MSS;
|
||||
|
||||
BOOL Inject_UAL(int a, void* b)
|
||||
{
|
||||
if ( RsEventHandler(a, b) )
|
||||
{
|
||||
if ( !std::exchange(delayedPatchesDone, true) && Func != nullptr )
|
||||
{
|
||||
Func();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Common {
|
||||
namespace Patches {
|
||||
void III_VC_Common()
|
||||
|
@ -26,6 +62,19 @@ namespace Common {
|
|||
using namespace Memory;
|
||||
using namespace hook;
|
||||
|
||||
// Delayed patching
|
||||
{
|
||||
using namespace DelayedPatches;
|
||||
|
||||
auto addr_mssHook = get_pattern( "6A 00 6A 02 6A 10 68 00 7D 00 00", -6 + 2 );
|
||||
OldSetPreference = *static_cast<decltype(OldSetPreference)*>(addr_mssHook);
|
||||
Patch( addr_mssHook, &pInjectMSS );
|
||||
|
||||
auto addr_ualHook = get_pattern( "FF 15 ? ? ? ? 6A 00 6A 18", 0xA );
|
||||
ReadCall( addr_ualHook, RsEventHandler );
|
||||
InjectHook( addr_ualHook, Inject_UAL );
|
||||
}
|
||||
|
||||
// Fixed bomb ownership/bombs saving for bikes
|
||||
{
|
||||
auto addr = get_pattern( "83 3C 33 00 74 19 89 F9 E8", 8 );
|
||||
|
@ -44,5 +93,10 @@ namespace Common {
|
|||
InjectHook( findExactWord.get<void>( 0xD ), strncmp_Fix );
|
||||
}
|
||||
}
|
||||
|
||||
void III_VC_SetDelayedPatchesFunc( void(*func)() )
|
||||
{
|
||||
DelayedPatches::Func = std::move(func);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,5 +5,6 @@ namespace Common
|
|||
namespace Patches
|
||||
{
|
||||
void III_VC_Common();
|
||||
void III_VC_SetDelayedPatchesFunc( void(*func)() );
|
||||
}
|
||||
};
|
|
@ -981,9 +981,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|||
}
|
||||
|
||||
Common::Patches::FixRwcseg_Patterns();
|
||||
|
||||
HMODULE hDummyHandle;
|
||||
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)&DllMain, &hDummyHandle);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -810,9 +810,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|||
}
|
||||
|
||||
Common::Patches::FixRwcseg_Patterns();
|
||||
|
||||
HMODULE hDummyHandle;
|
||||
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)&DllMain, &hDummyHandle);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue