From d6e0f3e74f1e18dd281d82b221efb13c45faf6eb Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 26 Sep 2017 16:36:49 +0200 Subject: [PATCH] Skip cdstream fix if FLA uses enhanced IMGs --- SilentPatch/TheFLAUtils.cpp | 19 +++++++++++++++---- SilentPatch/TheFLAUtils.h | 1 + SilentPatchSA/SilentPatchSA.cpp | 7 +++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/SilentPatch/TheFLAUtils.cpp b/SilentPatch/TheFLAUtils.cpp index 9fc9072..d51a0af 100644 --- a/SilentPatch/TheFLAUtils.cpp +++ b/SilentPatch/TheFLAUtils.cpp @@ -8,21 +8,32 @@ int32_t (*FLAUtils::GetExtendedID8Func)(const uint8_t* ptr) = FLAUtils::GetExtendedID8_Stock; int32_t (*FLAUtils::GetExtendedID16Func)(const uint16_t* ptr) = FLAUtils::GetExtendedID16_Stock; +static HMODULE flaModule = nullptr; + void FLAUtils::Init() { - const HMODULE hFLA = GetASIModuleHandle(TEXT("$fastman92limitAdjuster")); - if ( hFLA != nullptr ) + flaModule = GetASIModuleHandle(TEXT("$fastman92limitAdjuster")); + if ( flaModule != nullptr ) { - const auto function8 = reinterpret_cast(GetProcAddress( hFLA, "GetExtendedIDfrom8bitBefore" )); + const auto function8 = reinterpret_cast(GetProcAddress( flaModule, "GetExtendedIDfrom8bitBefore" )); if ( function8 != nullptr ) { GetExtendedID8Func = function8; } - const auto function16 = reinterpret_cast(GetProcAddress( hFLA, "GetExtendedIDfrom16bitBefore" )); + const auto function16 = reinterpret_cast(GetProcAddress( flaModule, "GetExtendedIDfrom16bitBefore" )); if ( function16 != nullptr ) { GetExtendedID16Func = function16; } } +} + +bool FLAUtils::UsesEnhancedIMGs() +{ + if ( flaModule == nullptr ) return false; + + const auto func = reinterpret_cast(GetProcAddress( flaModule, "IsHandlingOfEnhancedIMGarchivesEnabled" )); + if ( func == nullptr ) return false; + return func(); } \ No newline at end of file diff --git a/SilentPatch/TheFLAUtils.h b/SilentPatch/TheFLAUtils.h index fc3eaa5..8bd8d3e 100644 --- a/SilentPatch/TheFLAUtils.h +++ b/SilentPatch/TheFLAUtils.h @@ -36,6 +36,7 @@ public: }; static void Init(); + static bool UsesEnhancedIMGs(); private: static constexpr int32_t MAX_UINT8_ID = 0xFF; diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index ffbfea6..5d13dff 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -2912,9 +2912,11 @@ BOOL InjectDelayedPatches_10() InjectHook(0x713ACB, HandleMoonStuffStub, PATCH_JUMP); } + FLAUtils::Init(); + // Race condition in CdStream fixed // Not taking effect with modloader - if ( !ModCompat::ModloaderCdStreamRaceConditionAware( modloaderModule ) ) + if ( !ModCompat::ModloaderCdStreamRaceConditionAware( modloaderModule ) && !FLAUtils::UsesEnhancedIMGs() ) { ReadCall( 0x406C78, CdStreamSync::orgCdStreamInitThread ); InjectHook( 0x406C78, CdStreamSync::CdStreamInitThread ); @@ -2980,9 +2982,6 @@ BOOL InjectDelayedPatches_10() } } #endif - - - FLAUtils::Init(); return FALSE; }