From 4fbd372d57183700f8c89852b6160937ebdd4521 Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 21 Sep 2017 17:43:32 +0200 Subject: [PATCH] Don't patch moonphases if skygfx already does that --- SilentPatchSA/SilentPatchSA.cpp | 44 ++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 97191c1..68f13b4 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -1362,6 +1362,32 @@ static void CdStreamInitThread() } +// ============= Mod compatibility stuff ============= + +namespace ModCompat +{ + bool SkygfxPatchesMoonphases( HMODULE module ) + { + if ( module == nullptr ) return false; // SkyGfx not installed + + struct Config + { + uint32_t version; + // The rest isn't relevant at the moment + }; + + auto func = (Config*(*)())GetProcAddress( module, "GetConfig" ); + if ( func == nullptr ) return false; // Old version? + + const Config* config = func(); + if ( config == nullptr ) return false; // Old version/error? + + constexpr uint32_t SKYGFX_VERSION_WITH_MOONPHASES = 0x360; + return config->version >= SKYGFX_VERSION_WITH_MOONPHASES; + } + +} + #if MEM_VALIDATORS #include @@ -2514,12 +2540,14 @@ BOOL InjectDelayedPatches_10() GetModuleFileNameW(hDLLModule, wcModulePath, _countof(wcModulePath) - 3); // Minus max required space for extension PathRenameExtensionW(wcModulePath, L".ini"); - bool bHasImVehFt = GetASIModuleHandleW(L"ImVehFt") != nullptr; - bool bSAMP = GetModuleHandleW(L"samp") != nullptr; - bool bSARender = GetASIModuleHandleW(L"SARender") != nullptr; + const bool bHasImVehFt = GetASIModuleHandleW(L"ImVehFt") != nullptr; + const bool bSAMP = GetModuleHandleW(L"samp") != nullptr; + const bool bSARender = GetASIModuleHandleW(L"SARender") != nullptr; + + const HMODULE skygfxModule = GetASIModuleHandle( TEXT("skygfx") ); ReadRotorFixExceptions(wcModulePath); - bool bHookDoubleRwheels = ReadDoubleRearWheels(wcModulePath); + const bool bHookDoubleRwheels = ReadDoubleRearWheels(wcModulePath); #ifndef NDEBUG const bool bHasDebugMenu = DebugMenuLoad(); @@ -2797,6 +2825,12 @@ BOOL InjectDelayedPatches_10() } #endif + // Moonphases + // Not taking effect with new skygfx since aap has it too now + if ( !ModCompat::SkygfxPatchesMoonphases( skygfxModule ) ) + { + InjectHook(0x713ACB, HandleMoonStuffStub, PATCH_JUMP); + } FLAUtils::Init(); @@ -3356,8 +3390,6 @@ void Patch_SA_10() // Only 1.0 and Steam Nop(0x57DC55, 2); - // Moonphases - InjectHook(0x713ACB, HandleMoonStuffStub, PATCH_JUMP); // TEMP //Patch(0x733B05, 40);