mirror of
https://github.com/CookiePLMonster/SilentPatch.git
synced 2024-12-29 15:23:02 +05:00
CdStream fix future proof for new FLA
This commit is contained in:
parent
d6e0f3e74f
commit
d596ec7d1e
3 changed files with 72 additions and 38 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
int32_t (*FLAUtils::GetExtendedID8Func)(const uint8_t* ptr) = FLAUtils::GetExtendedID8_Stock;
|
||||
int32_t (*FLAUtils::GetExtendedID16Func)(const uint16_t* ptr) = FLAUtils::GetExtendedID16_Stock;
|
||||
void (*FLAUtils::SetCdStreamWakeFunc)(CdStreamWakeFunc func) = nullptr;
|
||||
|
||||
static HMODULE flaModule = nullptr;
|
||||
|
||||
|
@ -26,6 +27,8 @@ void FLAUtils::Init()
|
|||
{
|
||||
GetExtendedID16Func = function16;
|
||||
}
|
||||
|
||||
SetCdStreamWakeFunc = reinterpret_cast<decltype(SetCdStreamWakeFunc)>(GetProcAddress( flaModule, "SetCdStreamReleaseChannelfUsedByTheFLA" ));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,9 +35,24 @@ public:
|
|||
uint16_t value;
|
||||
};
|
||||
|
||||
typedef void(*CdStreamWakeFunc)( struct CdStream* );
|
||||
|
||||
static void Init();
|
||||
static bool UsesEnhancedIMGs();
|
||||
|
||||
static void SetCdStreamWakeFunction( CdStreamWakeFunc func )
|
||||
{
|
||||
if ( SetCdStreamWakeFunc != nullptr )
|
||||
{
|
||||
SetCdStreamWakeFunc( func );
|
||||
}
|
||||
}
|
||||
|
||||
static bool CdStreamRaceConditionAware()
|
||||
{
|
||||
return SetCdStreamWakeFunc != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr int32_t MAX_UINT8_ID = 0xFF;
|
||||
static constexpr int32_t MAX_UINT16_ID = 0xFFFD;
|
||||
|
@ -56,6 +71,7 @@ private:
|
|||
|
||||
static int32_t (*GetExtendedID8Func)(const uint8_t* ptr);
|
||||
static int32_t (*GetExtendedID16Func)(const uint16_t* ptr);
|
||||
static void (*SetCdStreamWakeFunc)(CdStreamWakeFunc func);
|
||||
|
||||
static_assert( sizeof(int8) == sizeof(uint8_t) );
|
||||
static_assert( sizeof(int16) == sizeof(uint16_t) );
|
||||
|
|
|
@ -1412,6 +1412,10 @@ static void CdStreamInitThread()
|
|||
|
||||
InitializeCriticalSectionAndSpinCount( &CdStreamCritSec, 10 );
|
||||
|
||||
FLAUtils::SetCdStreamWakeFunction( []( CdStream* pStream ) {
|
||||
CdStreamThreadOnObject( pStream );
|
||||
} );
|
||||
|
||||
orgCdStreamInitThread();
|
||||
}
|
||||
|
||||
|
@ -2916,7 +2920,14 @@ BOOL InjectDelayedPatches_10()
|
|||
|
||||
// Race condition in CdStream fixed
|
||||
// Not taking effect with modloader
|
||||
if ( !ModCompat::ModloaderCdStreamRaceConditionAware( modloaderModule ) && !FLAUtils::UsesEnhancedIMGs() )
|
||||
if ( !ModCompat::ModloaderCdStreamRaceConditionAware( modloaderModule ) )
|
||||
{
|
||||
// Don't patch if old FLA and enhanced IMGs are in place
|
||||
// For new FLA, we patch everything except CdStreamThread and then interop with FLA
|
||||
const bool flaBugAware = FLAUtils::CdStreamRaceConditionAware();
|
||||
const bool usesEnhancedImages = FLAUtils::UsesEnhancedIMGs();
|
||||
|
||||
if ( !usesEnhancedImages || flaBugAware )
|
||||
{
|
||||
ReadCall( 0x406C78, CdStreamSync::orgCdStreamInitThread );
|
||||
InjectHook( 0x406C78, CdStreamSync::CdStreamInitThread );
|
||||
|
@ -2954,9 +2965,12 @@ BOOL InjectDelayedPatches_10()
|
|||
}
|
||||
}
|
||||
|
||||
if ( !usesEnhancedImages )
|
||||
{
|
||||
Patch( 0x406669, { 0x56, 0xFF, 0x15 } );
|
||||
Patch( 0x406669 + 3, &CdStreamSync::CdStreamThreadOnObject );
|
||||
Patch( 0x406669 + 3 + 4, { 0xEB, 0x0F } );
|
||||
}
|
||||
|
||||
Patch( 0x406910, { 0xFF, 0x15 } );
|
||||
Patch( 0x406910 + 2, &CdStreamSync::CdStreamInitializeSyncObject );
|
||||
|
@ -2966,6 +2980,7 @@ BOOL InjectDelayedPatches_10()
|
|||
Patch( 0x4063B5, { 0x56, 0x50 } );
|
||||
InjectHook( 0x4063B5 + 2, CdStreamSync::CdStreamShutdownSyncObject_Stub, PATCH_CALL );
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue