mirror of
https://github.com/CookiePLMonster/SilentPatch.git
synced 2024-12-29 15:23:02 +05:00
XP-friendly CVs
This commit is contained in:
parent
bda0c717a6
commit
a3bbfd2cd3
1 changed files with 31 additions and 12 deletions
|
@ -1284,10 +1284,30 @@ namespace Sema
|
||||||
|
|
||||||
namespace CV
|
namespace CV
|
||||||
{
|
{
|
||||||
|
namespace Funcs
|
||||||
|
{
|
||||||
|
static decltype(InitializeConditionVariable)* pInitializeConditionVariable = nullptr;
|
||||||
|
static decltype(SleepConditionVariableCS)* pSleepConditionVariableCS = nullptr;
|
||||||
|
static decltype(WakeConditionVariable)* pWakeConditionVariable = nullptr;
|
||||||
|
|
||||||
|
static bool TryInit()
|
||||||
|
{
|
||||||
|
const HMODULE kernelDLL = GetModuleHandle( TEXT("kernel32") );
|
||||||
|
assert( kernelDLL != nullptr );
|
||||||
|
pInitializeConditionVariable = (decltype(pInitializeConditionVariable))GetProcAddress( kernelDLL, "InitializeConditionVariable" );
|
||||||
|
pSleepConditionVariableCS = (decltype(pSleepConditionVariableCS))GetProcAddress( kernelDLL, "SleepConditionVariableCS" );
|
||||||
|
pWakeConditionVariable = (decltype(pWakeConditionVariable))GetProcAddress( kernelDLL, "WakeConditionVariable" );
|
||||||
|
|
||||||
|
return pInitializeConditionVariable != nullptr && pSleepConditionVariableCS != nullptr && pWakeConditionVariable != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
CdStream::Sync __stdcall InitializeSyncObject()
|
CdStream::Sync __stdcall InitializeSyncObject()
|
||||||
{
|
{
|
||||||
CdStream::Sync object;
|
CdStream::Sync object;
|
||||||
InitializeConditionVariable( &object.cv );
|
Funcs::pInitializeConditionVariable( &object.cv );
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1300,7 +1320,7 @@ namespace CV
|
||||||
EnterCriticalSection( &CdStreamCritSec );
|
EnterCriticalSection( &CdStreamCritSec );
|
||||||
while ( stream->nSectorsToRead != 0 )
|
while ( stream->nSectorsToRead != 0 )
|
||||||
{
|
{
|
||||||
SleepConditionVariableCS( &stream->sync.cv, &CdStreamCritSec, INFINITE );
|
Funcs::pSleepConditionVariableCS( &stream->sync.cv, &CdStreamCritSec, INFINITE );
|
||||||
}
|
}
|
||||||
stream->bInUse = 0;
|
stream->bInUse = 0;
|
||||||
LeaveCriticalSection( &CdStreamCritSec );
|
LeaveCriticalSection( &CdStreamCritSec );
|
||||||
|
@ -1311,7 +1331,7 @@ namespace CV
|
||||||
{
|
{
|
||||||
EnterCriticalSection( &CdStreamCritSec );
|
EnterCriticalSection( &CdStreamCritSec );
|
||||||
stream->nSectorsToRead = 0;
|
stream->nSectorsToRead = 0;
|
||||||
WakeConditionVariable( &stream->sync.cv );
|
Funcs::pWakeConditionVariable( &stream->sync.cv );
|
||||||
stream->bInUse = 0;
|
stream->bInUse = 0;
|
||||||
LeaveCriticalSection( &CdStreamCritSec );
|
LeaveCriticalSection( &CdStreamCritSec );
|
||||||
}
|
}
|
||||||
|
@ -1320,21 +1340,20 @@ namespace CV
|
||||||
static void (*orgCdStreamInitThread)();
|
static void (*orgCdStreamInitThread)();
|
||||||
static void CdStreamInitThread()
|
static void CdStreamInitThread()
|
||||||
{
|
{
|
||||||
// TODO: Branch for XP
|
if ( GetASIModuleHandle( L"modloader" ) == nullptr && CV::Funcs::TryInit() )
|
||||||
if ( GetASIModuleHandle( L"modloader" ) != nullptr )
|
|
||||||
{
|
|
||||||
CdStreamInitializeSyncObject = Sema::InitializeSyncObject;
|
|
||||||
CdStreamShutdownSyncObject = Sema::ShutdownSyncObject;
|
|
||||||
CdStreamSyncOnObject = Sema::CdStreamSync;
|
|
||||||
CdStreamThreadOnObject = Sema::CdStreamThread;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
CdStreamInitializeSyncObject = CV::InitializeSyncObject;
|
CdStreamInitializeSyncObject = CV::InitializeSyncObject;
|
||||||
CdStreamShutdownSyncObject = CV::ShutdownSyncObject;
|
CdStreamShutdownSyncObject = CV::ShutdownSyncObject;
|
||||||
CdStreamSyncOnObject = CV::CdStreamSync;
|
CdStreamSyncOnObject = CV::CdStreamSync;
|
||||||
CdStreamThreadOnObject = CV::CdStreamThread;
|
CdStreamThreadOnObject = CV::CdStreamThread;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CdStreamInitializeSyncObject = Sema::InitializeSyncObject;
|
||||||
|
CdStreamShutdownSyncObject = Sema::ShutdownSyncObject;
|
||||||
|
CdStreamSyncOnObject = Sema::CdStreamSync;
|
||||||
|
CdStreamThreadOnObject = Sema::CdStreamThread;
|
||||||
|
}
|
||||||
|
|
||||||
InitializeCriticalSectionAndSpinCount( &CdStreamCritSec, 10 );
|
InitializeCriticalSectionAndSpinCount( &CdStreamCritSec, 10 );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue