[System]: Correct one function (#660)

This commit is contained in:
Edo 2022-12-19 18:57:13 +01:00 committed by GitHub
parent 64c64cf9df
commit a4a622be52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 19 deletions

View File

@ -246,7 +246,7 @@ namespace Components
if (ent->client->sess.sessionState != Game::SESS_STATE_PLAYING || !CheatsOk(ent))
return;
auto** bgs = Game::Sys::GetTls<Game::bgs_t*>(Game::Sys::ThreadOffset::LEVEL_BGS);
auto** bgs = Game::Sys::GetTls<Game::bgs_t*>(Game::Sys::TLS_OFFSET::LEVEL_BGS);
assert(*bgs == nullptr);

View File

@ -77,16 +77,16 @@ namespace Game
extern const char* Com_LoadInfoString_FastFile(const char* fileName, const char* fileDesc, const char* ident, char* loadBuffer);
}
#define Com_InitThreadData() \
{ \
static Game::ProfileStack profile_stack{}; \
static Game::va_info_t va_info{}; \
static jmp_buf g_com_error{}; \
static Game::TraceThreadInfo g_trace_thread_info{}; \
static void* g_thread_values[Game::THREAD_VALUE_COUNT]{}; \
*(Game::Sys::GetTls<void*>(Game::Sys::THREAD_VALUES)) = g_thread_values; \
Game::Sys_SetValue(Game::THREAD_VALUE_PROF_STACK, &profile_stack); \
Game::Sys_SetValue(Game::THREAD_VALUE_VA, &va_info); \
Game::Sys_SetValue(Game::THREAD_VALUE_COM_ERROR, &g_com_error); \
Game::Sys_SetValue(Game::THREAD_VALUE_TRACE, &g_trace_thread_info); \
#define Com_InitThreadData() \
{ \
static Game::ProfileStack profile_stack{}; \
static Game::va_info_t va_info{}; \
static jmp_buf g_com_error{}; \
static Game::TraceThreadInfo g_trace_thread_info{}; \
static void* g_thread_values[Game::THREAD_VALUE_COUNT]{}; \
*(Game::Sys::GetTls<void*>(Game::Sys::TLS_OFFSET::THREAD_VALUES)) = g_thread_values; \
Game::Sys_SetValue(Game::THREAD_VALUE_PROF_STACK, &profile_stack); \
Game::Sys_SetValue(Game::THREAD_VALUE_VA, &va_info); \
Game::Sys_SetValue(Game::THREAD_VALUE_COM_ERROR, &g_com_error); \
Game::Sys_SetValue(Game::THREAD_VALUE_TRACE, &g_trace_thread_info); \
}

View File

@ -12,6 +12,7 @@ namespace Game
Sys_ListFiles_t Sys_ListFiles = Sys_ListFiles_t(0x45A660);
Sys_Milliseconds_t Sys_Milliseconds = Sys_Milliseconds_t(0x42A660);
Sys_Error_t Sys_Error = Sys_Error_t(0x43D570);
Sys_Sleep_t Sys_Sleep = Sys_Sleep_t(0x4169C0);
Sys_LockWrite_t Sys_LockWrite = Sys_LockWrite_t(0x435880);
Sys_TempPriorityAtLeastNormalBegin_t Sys_TempPriorityAtLeastNormalBegin = Sys_TempPriorityAtLeastNormalBegin_t(0x478680);
Sys_TempPriorityEnd_t Sys_TempPriorityEnd = Sys_TempPriorityEnd_t(0x4DCF00);
@ -30,7 +31,7 @@ namespace Game
void Sys_LockRead(FastCriticalSection* critSect)
{
InterlockedIncrement(&critSect->readCount);
while (critSect->writeCount) std::this_thread::sleep_for(1ms);
while (critSect->writeCount) Sys_Sleep(1);
}
void Sys_UnlockRead(FastCriticalSection* critSect)
@ -39,10 +40,16 @@ namespace Game
InterlockedDecrement(&critSect->readCount);
}
void Sys_UnlockWrite(FastCriticalSection* critSect)
{
assert(critSect->writeCount > 0);
InterlockedDecrement(&critSect->writeCount);
Sys_TempPriorityEnd(&critSect->tempPriority);
}
bool Sys_TryEnterCriticalSection(CriticalSection critSect)
{
assert(static_cast<unsigned int>(critSect) <
static_cast<unsigned int>(CRITSECT_COUNT));
AssertIn(critSect, CRITSECT_COUNT);
return TryEnterCriticalSection(&s_criticalSection[critSect]) != FALSE;
}

View File

@ -32,6 +32,9 @@ namespace Game
typedef int(*Sys_Milliseconds_t)();
extern Sys_Milliseconds_t Sys_Milliseconds;
typedef void(*Sys_Sleep_t)(int msec);
extern Sys_Sleep_t Sys_Sleep;
typedef void(*Sys_LockWrite_t)(FastCriticalSection* critSect);
extern Sys_LockWrite_t Sys_LockWrite;
@ -68,13 +71,14 @@ namespace Game
extern void Sys_LockRead(FastCriticalSection* critSect);
extern void Sys_UnlockRead(FastCriticalSection* critSect);
extern void Sys_UnlockWrite(FastCriticalSection* critSect);
extern bool Sys_TryEnterCriticalSection(CriticalSection critSect);
class Sys
{
public:
enum ThreadOffset : unsigned int
enum class TLS_OFFSET : unsigned int
{
LEVEL_BGS = 0xC,
THREAD_VALUES = 0x14,
@ -85,10 +89,10 @@ namespace Game
};
template <typename T>
static T* GetTls(ThreadOffset offset)
static T* GetTls(TLS_OFFSET offset)
{
const auto* tls = reinterpret_cast<std::uintptr_t*>(__readfsdword(0x2C));
return reinterpret_cast<T*>(tls[*g_dwTlsIndex] + offset);
return reinterpret_cast<T*>(tls[*g_dwTlsIndex] + static_cast<std::underlying_type_t<TLS_OFFSET>>(offset));
}
};
}