Logging bug fix and error handling improvements

* Replaced the boolean 'fatal' parameter with a error code parameter, anything non-null will prompt a message (fatal) and terminate the process with given error code.
* Fixed bug where the global ostreamsink for spdlog did NOT get cleared in 'SQVM_PrintFunc' when cvar 'sq_showvmoutput' was < 3. Moved to global scope.
* Added error message for when detouring the process has failed, with the error code.
* Only call 'Plat_GetProcessUpTime()' once per log, (improves performance and fixes bug where the error message box would show a different time stamp than what is logged into the console or file).
* All TIER0 loggers only log to notify and console when the SDK engine has fully initialized and detoured all functions.
This commit is contained in:
Kawe Mazidjatari 2022-09-14 00:39:38 +02:00
parent d65bee5ffe
commit 3d6d6644bd
29 changed files with 151 additions and 114 deletions

View File

@ -226,10 +226,10 @@ void Systems_Init()
RuntimePtc_Init(); RuntimePtc_Init();
// Commit the transaction // Commit the transaction
if (DetourTransactionCommit() != NO_ERROR) if (LONG hr = DetourTransactionCommit() != NO_ERROR)
{ {
// Failed to hook into the process, terminate // Failed to hook into the process, terminate
TerminateProcess(GetCurrentProcess(), 0xBAD0C0DE); Error(eDLL_T::COMMON, 0xBAD0C0DE, "Failed to detour process: error code = %08x\n", hr);
} }
initTimer.End(); initTimer.End();
@ -422,7 +422,7 @@ void QuerySystemInfo()
{ {
if (MessageBoxA(NULL, "SSE and SSE2 are required.", "Unsupported CPU", MB_ICONERROR | MB_OK)) if (MessageBoxA(NULL, "SSE and SSE2 are required.", "Unsupported CPU", MB_ICONERROR | MB_OK))
{ {
TerminateProcess(GetCurrentProcess(), 1); TerminateProcess(GetCurrentProcess(), EXIT_FAILURE);
} }
} }
} }

View File

@ -77,4 +77,5 @@ void SpdLog_PostInit()
g_bSpdLog_UseAnsiClr = true; g_bSpdLog_UseAnsiClr = true;
} }
else { wconsole->set_pattern("%v"); } else { wconsole->set_pattern("%v"); }
g_bSpdLog_PostInit = true;
} }

View File

@ -4,6 +4,7 @@ constexpr int SPDLOG_MAX_SIZE = 10 * 1024 * 1024; // Sets number of bytes before
constexpr int SPDLOG_NUM_FILE = 0; // Sets number of files to rotate to. constexpr int SPDLOG_NUM_FILE = 0; // Sets number of files to rotate to.
inline bool g_bSpdLog_UseAnsiClr = false; inline bool g_bSpdLog_UseAnsiClr = false;
inline bool g_bSpdLog_PostInit = false;
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// IMGUI CONSOLE SINK | // IMGUI CONSOLE SINK |

View File

@ -60,9 +60,9 @@ studiohdr_t* CMDLCache::FindMDL(CMDLCache* cache, MDLHandle_t handle, void* a3)
if (!IsKnownBadModel(handle)) if (!IsKnownBadModel(handle))
{ {
if (!pStudioHdr) if (!pStudioHdr)
Error(eDLL_T::ENGINE, true, "Model with handle \"%hu\" not found and \"%s\" couldn't be loaded.\n", handle, ERROR_MODEL); Error(eDLL_T::ENGINE, EXIT_FAILURE, "Model with handle \"%hu\" not found and \"%s\" couldn't be loaded.\n", handle, ERROR_MODEL);
else else
Error(eDLL_T::ENGINE, false, "Model with handle \"%hu\" not found; replacing with \"%s\".\n", handle, ERROR_MODEL); Error(eDLL_T::ENGINE, NULL, "Model with handle \"%hu\" not found; replacing with \"%s\".\n", handle, ERROR_MODEL);
g_vBadMDLHandles.push_back(handle); g_vBadMDLHandles.push_back(handle);
} }
@ -143,9 +143,9 @@ studiohdr_t* CMDLCache::FindUncachedMDL(CMDLCache* cache, MDLHandle_t handle, st
if (!IsKnownBadModel(handle)) if (!IsKnownBadModel(handle))
{ {
if (!pStudioHdr) if (!pStudioHdr)
Error(eDLL_T::ENGINE, true, "Model with handle \"%hu\" not found and \"%s\" couldn't be loaded.\n", handle, ERROR_MODEL); Error(eDLL_T::ENGINE, EXIT_FAILURE, "Model with handle \"%hu\" not found and \"%s\" couldn't be loaded.\n", handle, ERROR_MODEL);
else else
Error(eDLL_T::ENGINE, false, "Model with handle \"%hu\" not found; replacing with \"%s\".\n", handle, ERROR_MODEL); Error(eDLL_T::ENGINE, NULL, "Model with handle \"%hu\" not found; replacing with \"%s\".\n", handle, ERROR_MODEL);
g_vBadMDLHandles.push_back(handle); g_vBadMDLHandles.push_back(handle);
} }
@ -165,9 +165,9 @@ studiohdr_t* CMDLCache::FindUncachedMDL(CMDLCache* cache, MDLHandle_t handle, st
if (!IsKnownBadModel(handle)) if (!IsKnownBadModel(handle))
{ {
if (!pStudioHdr) if (!pStudioHdr)
Error(eDLL_T::ENGINE, true, "Attempted to load old model \"%s\" and \"%s\" couldn't be loaded.\n", szModelName, ERROR_MODEL); Error(eDLL_T::ENGINE, EXIT_FAILURE, "Attempted to load old model \"%s\" and \"%s\" couldn't be loaded.\n", szModelName, ERROR_MODEL);
else else
Error(eDLL_T::ENGINE, false, "Attempted to load old model \"%s\"; replacing with \"%s\".\n", szModelName, ERROR_MODEL); Error(eDLL_T::ENGINE, NULL, "Attempted to load old model \"%s\"; replacing with \"%s\".\n", szModelName, ERROR_MODEL);
g_vBadMDLHandles.push_back(handle); g_vBadMDLHandles.push_back(handle);
} }
@ -193,9 +193,9 @@ studiohdr_t* CMDLCache::FindUncachedMDL(CMDLCache* cache, MDLHandle_t handle, st
if (!IsKnownBadModel(handle)) if (!IsKnownBadModel(handle))
{ {
if (!pStudioHdr) if (!pStudioHdr)
Error(eDLL_T::ENGINE, true, "Model \"%s\" not found and \"%s\" couldn't be loaded.\n", szModelName, ERROR_MODEL); Error(eDLL_T::ENGINE, EXIT_FAILURE, "Model \"%s\" not found and \"%s\" couldn't be loaded.\n", szModelName, ERROR_MODEL);
else else
Error(eDLL_T::ENGINE, false, "Model \"%s\" not found; replacing with \"%s\".\n", szModelName, ERROR_MODEL); Error(eDLL_T::ENGINE, NULL, "Model \"%s\" not found; replacing with \"%s\".\n", szModelName, ERROR_MODEL);
g_vBadMDLHandles.push_back(handle); g_vBadMDLHandles.push_back(handle);
} }
@ -215,9 +215,9 @@ studiohdr_t* CMDLCache::FindUncachedMDL(CMDLCache* cache, MDLHandle_t handle, st
if (!IsKnownBadModel(handle)) if (!IsKnownBadModel(handle))
{ {
if (!pStudioHdr) if (!pStudioHdr)
Error(eDLL_T::ENGINE, true, "Model \"%s\" has bad studio data and \"%s\" couldn't be loaded.\n", szModelName, ERROR_MODEL); Error(eDLL_T::ENGINE, EXIT_FAILURE, "Model \"%s\" has bad studio data and \"%s\" couldn't be loaded.\n", szModelName, ERROR_MODEL);
else else
Error(eDLL_T::ENGINE, false, "Model \"%s\" has bad studio data; replacing with \"%s\".\n", szModelName, ERROR_MODEL); Error(eDLL_T::ENGINE, NULL, "Model \"%s\" has bad studio data; replacing with \"%s\".\n", szModelName, ERROR_MODEL);
g_vBadMDLHandles.push_back(handle); g_vBadMDLHandles.push_back(handle);
} }
@ -231,9 +231,9 @@ studiohdr_t* CMDLCache::FindUncachedMDL(CMDLCache* cache, MDLHandle_t handle, st
if (!IsKnownBadModel(handle)) if (!IsKnownBadModel(handle))
{ {
if (!pStudioHdr) if (!pStudioHdr)
Error(eDLL_T::ENGINE, true, "Model \"%s\" has no studio data and \"%s\" couldn't be loaded.\n", szModelName, ERROR_MODEL); Error(eDLL_T::ENGINE, EXIT_FAILURE, "Model \"%s\" has no studio data and \"%s\" couldn't be loaded.\n", szModelName, ERROR_MODEL);
else else
Error(eDLL_T::ENGINE, false, "Model \"%s\" has no studio data; replacing with \"%s\".\n", szModelName, ERROR_MODEL); Error(eDLL_T::ENGINE, NULL, "Model \"%s\" has no studio data; replacing with \"%s\".\n", szModelName, ERROR_MODEL);
g_vBadMDLHandles.push_back(handle); g_vBadMDLHandles.push_back(handle);
} }
@ -257,7 +257,7 @@ studiohdr_t* CMDLCache::GetStudioHDR(CMDLCache* pMDLCache, MDLHandle_t handle)
{ {
pStudioHdr = GetErrorModel(); pStudioHdr = GetErrorModel();
if (!pStudioHdr) if (!pStudioHdr)
Error(eDLL_T::ENGINE, true, "Attempted to load model with no handle and \"%s\" couldn't be loaded.\n", ERROR_MODEL); Error(eDLL_T::ENGINE, EXIT_FAILURE, "Attempted to load model with no handle and \"%s\" couldn't be loaded.\n", ERROR_MODEL);
return pStudioHdr; return pStudioHdr;
} }
@ -293,7 +293,7 @@ studiohwdata_t* CMDLCache::GetHardwareData(CMDLCache* cache, MDLHandle_t handle)
{ {
if (!g_pMDLFallback->m_hErrorMDL) if (!g_pMDLFallback->m_hErrorMDL)
{ {
Error(eDLL_T::ENGINE, true, "Studio hardware with handle \"%hu\" not found and \"%s\" couldn't be loaded.\n", handle, ERROR_MODEL); Error(eDLL_T::ENGINE, EXIT_FAILURE, "Studio hardware with handle \"%hu\" not found and \"%s\" couldn't be loaded.\n", handle, ERROR_MODEL);
return nullptr; return nullptr;
} }
pStudioData = m_MDLDict->Find(g_pMDLFallback->m_hErrorMDL); pStudioData = m_MDLDict->Find(g_pMDLFallback->m_hErrorMDL);

View File

@ -204,7 +204,7 @@ void CRConClient::Recv(void)
} }
if (nRecvLen < 0 && !m_pSocket->IsSocketBlocking()) if (nRecvLen < 0 && !m_pSocket->IsSocketBlocking())
{ {
Error(eDLL_T::CLIENT, false, "RCON Cmd: recv error (%s)\n", NET_ErrorString(WSAGetLastError())); Error(eDLL_T::CLIENT, NULL, "RCON Cmd: recv error (%s)\n", NET_ErrorString(WSAGetLastError()));
break; break;
} }
@ -260,7 +260,7 @@ void CRConClient::ProcessBuffer(const char* pRecvBuf, int nRecvLen, CConnectedNe
if (pData->m_nPayloadLen < 0 || if (pData->m_nPayloadLen < 0 ||
pData->m_nPayloadLen > pData->m_RecvBuffer.max_size()) pData->m_nPayloadLen > pData->m_RecvBuffer.max_size())
{ {
Error(eDLL_T::CLIENT, false, "RCON Cmd: sync error (%d)\n", pData->m_nPayloadLen); Error(eDLL_T::CLIENT, NULL, "RCON Cmd: sync error (%d)\n", pData->m_nPayloadLen);
this->Disconnect(); // Out of sync (irrecoverable). this->Disconnect(); // Out of sync (irrecoverable).
break; break;

View File

@ -367,7 +367,7 @@ void MOD_PreloadPakFile(const string& svLevelName)
RPakHandle_t nPakId = g_pakLoadApi->LoadAsync(svToLoad.c_str(), g_pMallocPool.GetPtr(), 4, 0); RPakHandle_t nPakId = g_pakLoadApi->LoadAsync(svToLoad.c_str(), g_pMallocPool.GetPtr(), 4, 0);
if (nPakId == INVALID_PAK_HANDLE) if (nPakId == INVALID_PAK_HANDLE)
Error(eDLL_T::ENGINE, false, "%s: unable to load pak '%s' results '%d'\n", __FUNCTION__, svToLoad.c_str(), nPakId); Error(eDLL_T::ENGINE, NULL, "%s: unable to load pak '%s' results '%d'\n", __FUNCTION__, svToLoad.c_str(), nPakId);
else else
g_vLoadedPakHandle.push_back(nPakId); g_vLoadedPakHandle.push_back(nPakId);
} }

View File

@ -334,7 +334,7 @@ FORCEINLINE void CHostState::State_NewGame(void)
if (!CModelLoader__Map_IsValid(g_pModelLoader, m_levelName) // Check if map is valid and if we can start a new game. if (!CModelLoader__Map_IsValid(g_pModelLoader, m_levelName) // Check if map is valid and if we can start a new game.
|| !Host_NewGame(m_levelName, nullptr, m_bBackgroundLevel, nSplitScreenPlayers, time) || !g_pServerGameClients) || !Host_NewGame(m_levelName, nullptr, m_bBackgroundLevel, nSplitScreenPlayers, time) || !g_pServerGameClients)
{ {
Error(eDLL_T::ENGINE, false, "%s - Error: Map not valid\n", "CHostState::State_NewGame"); Error(eDLL_T::ENGINE, NULL, "%s - Error: Map not valid\n", "CHostState::State_NewGame");
#ifndef DEDICATED #ifndef DEDICATED
SCR_EndLoadingPlaque(); SCR_EndLoadingPlaque();
#endif // !DEDICATED #endif // !DEDICATED
@ -365,7 +365,7 @@ FORCEINLINE void CHostState::State_ChangeLevelSP(void)
} }
else else
{ {
Error(eDLL_T::ENGINE, false, "%s - Error: Unable to find map: '%s'\n", "CHostState::State_ChangeLevelSP", m_levelName); Error(eDLL_T::ENGINE, NULL, "%s - Error: Unable to find map: '%s'\n", "CHostState::State_ChangeLevelSP", m_levelName);
} }
m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run. m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run.
@ -397,7 +397,7 @@ FORCEINLINE void CHostState::State_ChangeLevelMP(void)
} }
else else
{ {
Error(eDLL_T::ENGINE, false, "%s - Error: Unable to find map: '%s'\n", "CHostState::State_ChangeLevelMP", m_levelName); Error(eDLL_T::ENGINE, NULL, "%s - Error: Unable to find map: '%s'\n", "CHostState::State_ChangeLevelMP", m_levelName);
} }
m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run. m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run.

View File

@ -78,7 +78,7 @@ void NET_SetKey(string svNetKey)
} }
else else
{ {
Error(eDLL_T::ENGINE, false, "AES-128 key not encoded or invalid\n"); Error(eDLL_T::ENGINE, NULL, "AES-128 key not encoded or invalid\n");
} }
} }
@ -96,14 +96,14 @@ void NET_GenerateKey()
BCRYPT_ALG_HANDLE hAlgorithm; BCRYPT_ALG_HANDLE hAlgorithm;
if (BCryptOpenAlgorithmProvider(&hAlgorithm, L"RNG", 0, 0) < 0) if (BCryptOpenAlgorithmProvider(&hAlgorithm, L"RNG", 0, 0) < 0)
{ {
Error(eDLL_T::ENGINE, false, "Failed to open rng algorithm\n"); Error(eDLL_T::ENGINE, NULL, "Failed to open rng algorithm\n");
return; return;
} }
uint8_t pBuffer[AES_128_KEY_SIZE]; uint8_t pBuffer[AES_128_KEY_SIZE];
if (BCryptGenRandom(hAlgorithm, pBuffer, AES_128_KEY_SIZE, 0) < 0) if (BCryptGenRandom(hAlgorithm, pBuffer, AES_128_KEY_SIZE, 0) < 0)
{ {
Error(eDLL_T::ENGINE, false, "Failed to generate random data\n"); Error(eDLL_T::ENGINE, NULL, "Failed to generate random data\n");
return; return;
} }

View File

@ -275,7 +275,7 @@ void CRConServer::Recv(void)
} }
if (nRecvLen < 0 && !m_pSocket->IsSocketBlocking()) if (nRecvLen < 0 && !m_pSocket->IsSocketBlocking())
{ {
Error(eDLL_T::SERVER, false, "RCON Cmd: recv error (%s)\n", NET_ErrorString(WSAGetLastError())); Error(eDLL_T::SERVER, NULL, "RCON Cmd: recv error (%s)\n", NET_ErrorString(WSAGetLastError()));
break; break;
} }
@ -450,7 +450,7 @@ void CRConServer::ProcessBuffer(const char* pRecvBuf, int nRecvLen, CConnectedNe
if (pData->m_nPayloadLen < 0 || if (pData->m_nPayloadLen < 0 ||
pData->m_nPayloadLen > pData->m_RecvBuffer.max_size()) pData->m_nPayloadLen > pData->m_RecvBuffer.max_size())
{ {
Error(eDLL_T::SERVER, false, "RCON Cmd: sync error (%d)\n", pData->m_nPayloadLen); Error(eDLL_T::SERVER, NULL, "RCON Cmd: sync error (%d)\n", pData->m_nPayloadLen);
this->CloseConnection(); // Out of sync (irrecoverable). this->CloseConnection(); // Out of sync (irrecoverable).
break; break;

View File

@ -8,10 +8,10 @@
int HSys_Error_Internal(char* fmt, va_list args) int HSys_Error_Internal(char* fmt, va_list args)
{ {
char buffer[2048]{}; char buffer[2048]{};
Error(eDLL_T::COMMON, false, "_______________________________________________________________\n"); Error(eDLL_T::COMMON, NULL, "_______________________________________________________________\n");
Error(eDLL_T::COMMON, false, "] ENGINE ERROR ################################################\n"); Error(eDLL_T::COMMON, NULL, "] ENGINE ERROR ################################################\n");
vsprintf(buffer, fmt, args); vsprintf(buffer, fmt, args);
Error(eDLL_T::COMMON, false, "%s\n", buffer); Error(eDLL_T::COMMON, NULL, "%s\n", buffer);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
return Sys_Error_Internal(fmt, args); return Sys_Error_Internal(fmt, args);

View File

@ -34,7 +34,7 @@ void HSys_Error(char* fmt, ...)
buf[sizeof(buf) -1] = 0; buf[sizeof(buf) -1] = 0;
va_end(args); va_end(args);
Error(eDLL_T::ENGINE, false, "%s", buf); Error(eDLL_T::ENGINE, NULL, "%s", buf);
return v_Sys_Error(buf); return v_Sys_Error(buf);
} }

View File

@ -52,7 +52,7 @@ void CAI_NetworkBuilder::SaveNetworkGraph(CAI_Network* pNetwork)
FileHandle_t pAIGraph = FileSystem()->Open(fsGraphPath.relative_path().u8string().c_str(), "wb", "GAME"); FileHandle_t pAIGraph = FileSystem()->Open(fsGraphPath.relative_path().u8string().c_str(), "wb", "GAME");
if (!pAIGraph) if (!pAIGraph)
{ {
Error(eDLL_T::SERVER, false, "%s - Unable to write to '%s' (read-only?)\n", __FUNCTION__, fsGraphPath.relative_path().u8string().c_str()); Error(eDLL_T::SERVER, NULL, "%s - Unable to write to '%s' (read-only?)\n", __FUNCTION__, fsGraphPath.relative_path().u8string().c_str());
return; return;
} }
@ -339,7 +339,7 @@ void CAI_NetworkManager::LoadNetworkGraph(CAI_NetworkManager* pAINetworkManager,
FileHandle_t pAIGraph = FileSystem()->Open(fsGraphPath.relative_path().u8string().c_str(), "rb", "GAME"); FileHandle_t pAIGraph = FileSystem()->Open(fsGraphPath.relative_path().u8string().c_str(), "rb", "GAME");
if (!pAIGraph) if (!pAIGraph)
{ {
Error(eDLL_T::SERVER, false, "%s - Unable to open '%s' (insufficient rights?)\n", __FUNCTION__, Error(eDLL_T::SERVER, NULL, "%s - Unable to open '%s' (insufficient rights?)\n", __FUNCTION__,
fsGraphPath.relative_path().u8string().c_str()); fsGraphPath.relative_path().u8string().c_str());
LoadNetworkGraphEx(pAINetworkManager, pBuffer, szAIGraphFile); LoadNetworkGraphEx(pAINetworkManager, pBuffer, szAIGraphFile);
@ -376,7 +376,7 @@ void CAI_NetworkManager::LoadNetworkGraph(CAI_NetworkManager* pAINetworkManager,
} }
else else
{ {
Error(eDLL_T::SERVER, false, "%s - AI node graph '%s' is corrupt\n", __FUNCTION__, Error(eDLL_T::SERVER, NULL, "%s - AI node graph '%s' is corrupt\n", __FUNCTION__,
fsGraphPath.relative_path().u8string().c_str()); fsGraphPath.relative_path().u8string().c_str());
} }

View File

@ -4058,7 +4058,7 @@ void MathLib_Init(float gamma, float texGamma, float brightness, int overbright,
Assert(0); Assert(0);
if (MessageBoxA(NULL, "SSE and SSE2 are required.", "Unsupported CPU", MB_ICONERROR | MB_OK)) if (MessageBoxA(NULL, "SSE and SSE2 are required.", "Unsupported CPU", MB_ICONERROR | MB_OK))
{ {
TerminateProcess(GetCurrentProcess(), 1); TerminateProcess(GetCurrentProcess(), EXIT_FAILURE);
} }
} }
#endif //!360 #endif //!360

View File

@ -76,7 +76,7 @@ void CBanSystem::Save(void) const
FileHandle_t pFile = FileSystem()->Open("banlist.json", "wt", "PLATFORM"); FileHandle_t pFile = FileSystem()->Open("banlist.json", "wt", "PLATFORM");
if (!pFile) if (!pFile)
{ {
Error(eDLL_T::SERVER, false, "%s - Unable to write to '%s' (read-only?)\n", __FUNCTION__, "banlist.json"); Error(eDLL_T::SERVER, NULL, "%s - Unable to write to '%s' (read-only?)\n", __FUNCTION__, "banlist.json");
return; return;
} }

View File

@ -51,12 +51,12 @@ RPakHandle_t CPakFile::LoadAsync(const char* szPakFileName, uintptr_t pMalloc, i
if (pakHandle == INVALID_PAK_HANDLE) if (pakHandle == INVALID_PAK_HANDLE)
{ {
Error(eDLL_T::RTECH, false, "%s: Failed read '%s' results '%u'\n", __FUNCTION__, szPakFileName, pakHandle); Error(eDLL_T::RTECH, NULL, "%s: Failed read '%s' results '%u'\n", __FUNCTION__, szPakFileName, pakHandle);
} }
} }
else else
{ {
Error(eDLL_T::RTECH, false, "%s: Failed. File '%s' doesn't exist\n", __FUNCTION__, szPakFileName); Error(eDLL_T::RTECH, NULL, "%s: Failed. File '%s' doesn't exist\n", __FUNCTION__, szPakFileName);
} }
return pakHandle; return pakHandle;

View File

@ -579,7 +579,7 @@ void RTech::CreateDXTexture(RTechTextureInfo_t* textureHeader, int64_t imageData
const D3D11_SUBRESOURCE_DATA* subResData = (D3D11_SUBRESOURCE_DATA*)((uint8_t*)initialData + offsetStartResourceData); const D3D11_SUBRESOURCE_DATA* subResData = (D3D11_SUBRESOURCE_DATA*)((uint8_t*)initialData + offsetStartResourceData);
const HRESULT createTextureRes = (*g_ppGameDevice)->CreateTexture2D(&textureDesc, subResData, &textureHeader->m_ppTexture); const HRESULT createTextureRes = (*g_ppGameDevice)->CreateTexture2D(&textureDesc, subResData, &textureHeader->m_ppTexture);
if (createTextureRes < S_OK) if (createTextureRes < S_OK)
Error(eDLL_T::RTECH, true, "Couldn't create texture \"%s\": error code %08x\n", textureHeader->m_nDebugName, createTextureRes); Error(eDLL_T::RTECH, EXIT_FAILURE, "Couldn't create texture \"%s\": error code %08x\n", textureHeader->m_nDebugName, createTextureRes);
D3D11_SHADER_RESOURCE_VIEW_DESC shaderResource{}; D3D11_SHADER_RESOURCE_VIEW_DESC shaderResource{};
shaderResource.Format = dxgiFormat; shaderResource.Format = dxgiFormat;
@ -597,7 +597,7 @@ void RTech::CreateDXTexture(RTechTextureInfo_t* textureHeader, int64_t imageData
const HRESULT createShaderResourceRes = (*g_ppGameDevice)->CreateShaderResourceView(textureHeader->m_ppTexture, &shaderResource, &textureHeader->m_ppShaderResourceView); const HRESULT createShaderResourceRes = (*g_ppGameDevice)->CreateShaderResourceView(textureHeader->m_ppTexture, &shaderResource, &textureHeader->m_ppShaderResourceView);
if (createShaderResourceRes < S_OK) if (createShaderResourceRes < S_OK)
Error(eDLL_T::RTECH, true, "Couldn't create shader resource view for texture \"%s\": error code %08x\n", textureHeader->m_nDebugName, createShaderResourceRes); Error(eDLL_T::RTECH, EXIT_FAILURE, "Couldn't create shader resource view for texture \"%s\": error code %08x\n", textureHeader->m_nDebugName, createShaderResourceRes);
} }
#pragma warning( pop ) #pragma warning( pop )
#endif #endif

View File

@ -146,7 +146,7 @@ SQBool Script_CreateServerVM()
if (results) if (results)
DevMsg(eDLL_T::SERVER, "Created SERVER VM: '%p'\n", g_pServerScript.GetValue<CSquirrelVM*>()); DevMsg(eDLL_T::SERVER, "Created SERVER VM: '%p'\n", g_pServerScript.GetValue<CSquirrelVM*>());
else else
Error(eDLL_T::SERVER, true, "Failed to create SERVER VM\n"); Error(eDLL_T::SERVER, EXIT_FAILURE, "Failed to create SERVER VM\n");
return results; return results;
} }
#endif // !CLIENT_DLL #endif // !CLIENT_DLL
@ -163,7 +163,7 @@ SQBool Script_CreateClientVM(CHLClient* pHlClient)
if (results) if (results)
DevMsg(eDLL_T::CLIENT, "Created CLIENT VM: '%p'\n", g_pClientScript.GetValue<CSquirrelVM*>()); DevMsg(eDLL_T::CLIENT, "Created CLIENT VM: '%p'\n", g_pClientScript.GetValue<CSquirrelVM*>());
else else
Error(eDLL_T::CLIENT, true, "Failed to create CLIENT VM\n"); Error(eDLL_T::CLIENT, EXIT_FAILURE, "Failed to create CLIENT VM\n");
return results; return results;
} }
@ -177,7 +177,7 @@ SQBool Script_CreateUIVM()
if (results) if (results)
DevMsg(eDLL_T::UI, "Created UI VM: '%p'\n", g_pUIScript.GetValue<CSquirrelVM*>()); DevMsg(eDLL_T::UI, "Created UI VM: '%p'\n", g_pUIScript.GetValue<CSquirrelVM*>());
else else
Error(eDLL_T::UI, true, "Failed to create UI VM\n"); Error(eDLL_T::UI, EXIT_FAILURE, "Failed to create UI VM\n");
return results; return results;
} }
#endif // !DEDICATED #endif // !DEDICATED
@ -258,14 +258,14 @@ void Script_Execute(const SQChar* code, SQCONTEXT context)
CSquirrelVM* script = Script_GetContextObject(context); CSquirrelVM* script = Script_GetContextObject(context);
if (!script) if (!script)
{ {
Error(eDLL_T::ENGINE, false, "Attempted to run %s script with no handle to script context\n", SQVM_GetContextName(context)); Error(eDLL_T::ENGINE, NULL, "Attempted to run %s script with no handle to script context\n", SQVM_GetContextName(context));
return; return;
} }
HSQUIRRELVM v = script->GetVM(); HSQUIRRELVM v = script->GetVM();
if (!v) if (!v)
{ {
Error(eDLL_T::ENGINE, false, "Attempted to run %s script while VM isn't initialized\n", SQVM_GetContextName(context)); Error(eDLL_T::ENGINE, NULL, "Attempted to run %s script while VM isn't initialized\n", SQVM_GetContextName(context));
return; return;
} }

View File

@ -85,6 +85,8 @@ SQRESULT SQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...)
static std::shared_ptr<spdlog::logger> sqlogger = spdlog::get("sqvm_info"); static std::shared_ptr<spdlog::logger> sqlogger = spdlog::get("sqvm_info");
s_LogMutex.lock(); s_LogMutex.lock();
const char* pszUpTime = Plat_GetProcessUpTime();
{///////////////////////////// {/////////////////////////////
va_list args{}; va_list args{};
va_start(args, fmt); va_start(args, fmt);
@ -95,7 +97,7 @@ SQRESULT SQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...)
va_end(args); va_end(args);
}///////////////////////////// }/////////////////////////////
vmStr = Plat_GetProcessUpTime(); vmStr = pszUpTime;
vmStr.append(SQVM_LOG_T[static_cast<SQInteger>(context)]); vmStr.append(SQVM_LOG_T[static_cast<SQInteger>(context)]);
vmStr.append(buf); vmStr.append(buf);
@ -118,7 +120,7 @@ SQRESULT SQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...)
bError = true; bError = true;
} }
} }
else if (g_bSQAuxBadLogic) if (g_bSQAuxBadLogic)
{ {
if (strstr(buf, "There was a problem processing game logic.")) if (strstr(buf, "There was a problem processing game logic."))
{ {
@ -138,22 +140,17 @@ SQRESULT SQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...)
else // Use ANSI escape codes for the external console. else // Use ANSI escape codes for the external console.
{ {
static std::string vmStrAnsi; static std::string vmStrAnsi;
vmStrAnsi = pszUpTime;
if (bColorOverride) if (bColorOverride)
{ {
if (bError) if (bError) {
{
vmStrAnsi = Plat_GetProcessUpTime();
vmStrAnsi.append(SQVM_ERROR_ANSI_LOG_T[static_cast<SQInteger>(context)]); vmStrAnsi.append(SQVM_ERROR_ANSI_LOG_T[static_cast<SQInteger>(context)]);
} }
else else {
{
vmStrAnsi = Plat_GetProcessUpTime();
vmStrAnsi.append(SQVM_WARNING_ANSI_LOG_T[static_cast<SQInteger>(context)]); vmStrAnsi.append(SQVM_WARNING_ANSI_LOG_T[static_cast<SQInteger>(context)]);
} }
} }
else else {
{
vmStrAnsi = Plat_GetProcessUpTime();
vmStrAnsi.append(SQVM_ANSI_LOG_T[static_cast<SQInteger>(context)]); vmStrAnsi.append(SQVM_ANSI_LOG_T[static_cast<SQInteger>(context)]);
} }
vmStrAnsi.append(buf); vmStrAnsi.append(buf);
@ -200,13 +197,13 @@ SQRESULT SQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...)
g_pConsole->AddLog(ConLog_t(g_spd_sys_w_oss.str(), color)); g_pConsole->AddLog(ConLog_t(g_spd_sys_w_oss.str(), color));
g_pLogSystem.AddLog(static_cast<EGlobalContext_t>(nResponseId), g_spd_sys_w_oss.str()); g_pLogSystem.AddLog(static_cast<EGlobalContext_t>(nResponseId), g_spd_sys_w_oss.str());
g_spd_sys_w_oss.str("");
g_spd_sys_w_oss.clear();
} }
#endif // !DEDICATED #endif // !DEDICATED
} }
g_spd_sys_w_oss.str("");
g_spd_sys_w_oss.clear();
s_LogMutex.unlock(); s_LogMutex.unlock();
return SQ_OK; return SQ_OK;
} }
@ -232,6 +229,7 @@ SQRESULT SQVM_WarningFunc(HSQUIRRELVM v, SQInteger a2, SQInteger a3, SQInteger*
} }
s_LogMutex.lock(); s_LogMutex.lock();
const char* pszUpTime = Plat_GetProcessUpTime();
#ifdef GAMEDLL_S3 #ifdef GAMEDLL_S3
context = v->GetContext(); context = v->GetContext();
#else // Nothing equal to 'rdx + 18h' exist in the vm structs for anything below S3. #else // Nothing equal to 'rdx + 18h' exist in the vm structs for anything below S3.
@ -261,7 +259,7 @@ SQRESULT SQVM_WarningFunc(HSQUIRRELVM v, SQInteger a2, SQInteger a3, SQInteger*
static std::shared_ptr<spdlog::logger> wconsole = spdlog::get("win_console"); static std::shared_ptr<spdlog::logger> wconsole = spdlog::get("win_console");
static std::shared_ptr<spdlog::logger> sqlogger = spdlog::get("sqvm_warn"); static std::shared_ptr<spdlog::logger> sqlogger = spdlog::get("sqvm_warn");
std::string vmStr = Plat_GetProcessUpTime(); std::string vmStr = pszUpTime;
vmStr.append(SQVM_LOG_T[static_cast<int>(context)]); vmStr.append(SQVM_LOG_T[static_cast<int>(context)]);
std::string svConstructor(*ppString, *nStringSize); // Get string from memory via std::string constructor. std::string svConstructor(*ppString, *nStringSize); // Get string from memory via std::string constructor.
vmStr.append(svConstructor); vmStr.append(svConstructor);
@ -278,7 +276,7 @@ SQRESULT SQVM_WarningFunc(HSQUIRRELVM v, SQInteger a2, SQInteger a3, SQInteger*
} }
else else
{ {
std::string vmStrAnsi = Plat_GetProcessUpTime(); std::string vmStrAnsi = pszUpTime;
vmStrAnsi.append(SQVM_WARNING_ANSI_LOG_T[static_cast<int>(context)]); vmStrAnsi.append(SQVM_WARNING_ANSI_LOG_T[static_cast<int>(context)]);
vmStrAnsi.append(svConstructor); vmStrAnsi.append(svConstructor);
wconsole->debug(vmStrAnsi); wconsole->debug(vmStrAnsi);
@ -292,12 +290,12 @@ SQRESULT SQVM_WarningFunc(HSQUIRRELVM v, SQInteger a2, SQInteger a3, SQInteger*
g_pConsole->AddLog(ConLog_t(g_spd_sys_w_oss.str(), ImVec4(1.00f, 1.00f, 0.00f, 0.80f))); g_pConsole->AddLog(ConLog_t(g_spd_sys_w_oss.str(), ImVec4(1.00f, 1.00f, 0.00f, 0.80f)));
g_pLogSystem.AddLog(EGlobalContext_t::WARNING_C, g_spd_sys_w_oss.str()); g_pLogSystem.AddLog(EGlobalContext_t::WARNING_C, g_spd_sys_w_oss.str());
g_spd_sys_w_oss.str("");
g_spd_sys_w_oss.clear();
#endif // !DEDICATED #endif // !DEDICATED
} }
g_spd_sys_w_oss.str("");
g_spd_sys_w_oss.clear();
s_LogMutex.unlock(); s_LogMutex.unlock();
return result; return result;
} }
@ -323,9 +321,9 @@ void SQVM_CompileError(HSQUIRRELVM v, const SQChar* pszError, const SQChar* pszF
v_SQVM_GetErrorLine(pszFile, nLine, szContextBuf, sizeof(szContextBuf)); v_SQVM_GetErrorLine(pszFile, nLine, szContextBuf, sizeof(szContextBuf));
Error(static_cast<eDLL_T>(context), false, "%s SCRIPT COMPILE ERROR: %s\n", SQVM_GetContextName(context), pszError); Error(static_cast<eDLL_T>(context), NULL, "%s SCRIPT COMPILE ERROR: %s\n", SQVM_GetContextName(context), pszError);
Error(static_cast<eDLL_T>(context), false, " -> %s\n\n", szContextBuf); Error(static_cast<eDLL_T>(context), NULL, " -> %s\n\n", szContextBuf);
Error(static_cast<eDLL_T>(context), false, "%s line [%d] column [%d]\n", pszFile, nLine, nColumn); Error(static_cast<eDLL_T>(context), NULL, "%s line [%d] column [%d]\n", pszFile, nLine, nColumn);
} }
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------

View File

@ -301,6 +301,8 @@ void DevMsg(eDLL_T context, const char* fmt, ...)
static std::shared_ptr<spdlog::logger> sqlogger = spdlog::get("sdk_info"); static std::shared_ptr<spdlog::logger> sqlogger = spdlog::get("sdk_info");
s_LogMutex.lock(); s_LogMutex.lock();
const char* pszUpTime = Plat_GetProcessUpTime();
{///////////////////////////// {/////////////////////////////
va_list args{}; va_list args{};
va_start(args, fmt); va_start(args, fmt);
@ -311,7 +313,7 @@ void DevMsg(eDLL_T context, const char* fmt, ...)
va_end(args); va_end(args);
}///////////////////////////// }/////////////////////////////
svOut = Plat_GetProcessUpTime(); svOut = g_bSpdLog_PostInit ? pszUpTime : "";
svOut.append(sDLL_T[static_cast<int>(context)]); svOut.append(sDLL_T[static_cast<int>(context)]);
svOut.append(szBuf); svOut.append(szBuf);
svOut = std::regex_replace(svOut, rxAnsiExp, ""); svOut = std::regex_replace(svOut, rxAnsiExp, "");
@ -330,7 +332,7 @@ void DevMsg(eDLL_T context, const char* fmt, ...)
} }
else else
{ {
svAnsiOut = Plat_GetProcessUpTime(); svAnsiOut = g_bSpdLog_PostInit ? pszUpTime : "";
svAnsiOut.append(sANSI_DLL_T[static_cast<int>(context)]); svAnsiOut.append(sANSI_DLL_T[static_cast<int>(context)]);
svAnsiOut.append(szBuf); svAnsiOut.append(szBuf);
@ -386,8 +388,11 @@ void DevMsg(eDLL_T context, const char* fmt, ...)
break; break;
} }
g_pConsole->AddLog(ConLog_t(g_spd_sys_w_oss.str(), color)); if (g_bSpdLog_PostInit)
g_pLogSystem.AddLog(tLog, g_spd_sys_w_oss.str()); {
g_pConsole->AddLog(ConLog_t(g_spd_sys_w_oss.str(), color));
g_pLogSystem.AddLog(tLog, g_spd_sys_w_oss.str());
}
g_spd_sys_w_oss.str(""); g_spd_sys_w_oss.str("");
g_spd_sys_w_oss.clear(); g_spd_sys_w_oss.clear();
@ -414,6 +419,8 @@ void Warning(eDLL_T context, const char* fmt, ...)
static std::shared_ptr<spdlog::logger> sqlogger = spdlog::get("sdk_warn"); static std::shared_ptr<spdlog::logger> sqlogger = spdlog::get("sdk_warn");
s_LogMutex.lock(); s_LogMutex.lock();
const char* pszUpTime = Plat_GetProcessUpTime();
{///////////////////////////// {/////////////////////////////
va_list args{}; va_list args{};
va_start(args, fmt); va_start(args, fmt);
@ -424,7 +431,7 @@ void Warning(eDLL_T context, const char* fmt, ...)
va_end(args); va_end(args);
}///////////////////////////// }/////////////////////////////
svOut = Plat_GetProcessUpTime(); svOut = g_bSpdLog_PostInit ? pszUpTime : "";
svOut.append(sDLL_T[static_cast<int>(context)]); svOut.append(sDLL_T[static_cast<int>(context)]);
svOut.append(szBuf); svOut.append(szBuf);
svOut = std::regex_replace(svOut, rxAnsiExp, ""); svOut = std::regex_replace(svOut, rxAnsiExp, "");
@ -443,7 +450,7 @@ void Warning(eDLL_T context, const char* fmt, ...)
} }
else else
{ {
svAnsiOut = Plat_GetProcessUpTime(); svAnsiOut = g_bSpdLog_PostInit ? pszUpTime : "";
svAnsiOut.append(sANSI_DLL_T[static_cast<int>(context)]); svAnsiOut.append(sANSI_DLL_T[static_cast<int>(context)]);
svAnsiOut.append(g_svYellowF); svAnsiOut.append(g_svYellowF);
svAnsiOut.append(szBuf); svAnsiOut.append(szBuf);
@ -459,12 +466,14 @@ void Warning(eDLL_T context, const char* fmt, ...)
} }
sqlogger->debug(svOut); sqlogger->debug(svOut);
#ifndef DEDICATED #ifndef DEDICATED
iconsole->info(svOut); iconsole->info(svOut);
g_pConsole->AddLog(ConLog_t(g_spd_sys_w_oss.str(), ImVec4(1.00f, 1.00f, 0.00f, 0.80f))); if (g_bSpdLog_PostInit)
g_pLogSystem.AddLog(EGlobalContext_t::WARNING_C, g_spd_sys_w_oss.str()); {
g_pConsole->AddLog(ConLog_t(g_spd_sys_w_oss.str(), ImVec4(1.00f, 1.00f, 0.00f, 0.80f)));
g_pLogSystem.AddLog(EGlobalContext_t::WARNING_C, g_spd_sys_w_oss.str());
}
g_spd_sys_w_oss.str(""); g_spd_sys_w_oss.str("");
g_spd_sys_w_oss.clear(); g_spd_sys_w_oss.clear();
@ -475,10 +484,10 @@ void Warning(eDLL_T context, const char* fmt, ...)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: Print engine and SDK errors // Purpose: Print engine and SDK errors
// Input : context - // Input : context -
// fatal - // code -
// *fmt - ... - // *fmt - ... -
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Error(eDLL_T context, bool fatal, const char* fmt, ...) void Error(eDLL_T context, UINT code, const char* fmt, ...)
{ {
static char szBuf[4096] = {}; static char szBuf[4096] = {};
@ -492,6 +501,8 @@ void Error(eDLL_T context, bool fatal, const char* fmt, ...)
static std::shared_ptr<spdlog::logger> sqlogger = spdlog::get("sdk_error"); static std::shared_ptr<spdlog::logger> sqlogger = spdlog::get("sdk_error");
s_LogMutex.lock(); s_LogMutex.lock();
const char* pszUpTime = Plat_GetProcessUpTime();
{///////////////////////////// {/////////////////////////////
va_list args{}; va_list args{};
va_start(args, fmt); va_start(args, fmt);
@ -502,7 +513,7 @@ void Error(eDLL_T context, bool fatal, const char* fmt, ...)
va_end(args); va_end(args);
}///////////////////////////// }/////////////////////////////
svOut = Plat_GetProcessUpTime(); svOut = g_bSpdLog_PostInit ? pszUpTime : "";
svOut.append(sDLL_T[static_cast<int>(context)]); svOut.append(sDLL_T[static_cast<int>(context)]);
svOut.append(szBuf); svOut.append(szBuf);
svOut = std::regex_replace(svOut, rxAnsiExp, ""); svOut = std::regex_replace(svOut, rxAnsiExp, "");
@ -521,7 +532,7 @@ void Error(eDLL_T context, bool fatal, const char* fmt, ...)
} }
else else
{ {
svAnsiOut = Plat_GetProcessUpTime(); svAnsiOut = g_bSpdLog_PostInit ? pszUpTime : "";
svAnsiOut.append(sANSI_DLL_T[static_cast<int>(context)]); svAnsiOut.append(sANSI_DLL_T[static_cast<int>(context)]);
svAnsiOut.append(g_svRedF); svAnsiOut.append(g_svRedF);
svAnsiOut.append(szBuf); svAnsiOut.append(szBuf);
@ -541,17 +552,20 @@ void Error(eDLL_T context, bool fatal, const char* fmt, ...)
#ifndef DEDICATED #ifndef DEDICATED
iconsole->info(svOut); iconsole->info(svOut);
g_pConsole->AddLog(ConLog_t(g_spd_sys_w_oss.str(), ImVec4(1.00f, 0.00f, 0.00f, 1.00f))); if (g_bSpdLog_PostInit)
g_pLogSystem.AddLog(EGlobalContext_t::ERROR_C, g_spd_sys_w_oss.str()); {
g_pConsole->AddLog(ConLog_t(g_spd_sys_w_oss.str(), ImVec4(1.00f, 0.00f, 0.00f, 1.00f)));
g_pLogSystem.AddLog(EGlobalContext_t::ERROR_C, g_spd_sys_w_oss.str());
}
g_spd_sys_w_oss.str(""); g_spd_sys_w_oss.str("");
g_spd_sys_w_oss.clear(); g_spd_sys_w_oss.clear();
#endif // !DEDICATED #endif // !DEDICATED
if (fatal) if (code) // Terminate the process if an exit code was passed.
{ {
if (MessageBoxA(NULL, fmt::format("{:s}- {:s}", Plat_GetProcessUpTime(), szBuf).c_str(), "SDK Error", MB_ICONERROR | MB_OK)) if (MessageBoxA(NULL, fmt::format("{:s}- {:s}", pszUpTime, szBuf).c_str(), "SDK Error", MB_ICONERROR | MB_OK))
{ {
TerminateProcess(GetCurrentProcess(), 1); TerminateProcess(GetCurrentProcess(), code);
} }
} }
s_LogMutex.unlock(); s_LogMutex.unlock();

View File

@ -81,7 +81,7 @@ extern std::mutex s_LogMutex;
PLATFORM_INTERFACE void NetMsg(EGlobalContext_t context, const char* fmt, ...) FMTFUNCTION(2, 3); PLATFORM_INTERFACE void NetMsg(EGlobalContext_t context, const char* fmt, ...) FMTFUNCTION(2, 3);
PLATFORM_INTERFACE void DevMsg(eDLL_T context, const char* fmt, ...) FMTFUNCTION(2, 3); PLATFORM_INTERFACE void DevMsg(eDLL_T context, const char* fmt, ...) FMTFUNCTION(2, 3);
PLATFORM_INTERFACE void Warning(eDLL_T context, const char* fmt, ...) FMTFUNCTION(1, 2); PLATFORM_INTERFACE void Warning(eDLL_T context, const char* fmt, ...) FMTFUNCTION(1, 2);
PLATFORM_INTERFACE void Error(eDLL_T context, bool fatal, const char* fmt, ...) FMTFUNCTION(1, 2); PLATFORM_INTERFACE void Error(eDLL_T context, UINT code, const char* fmt, ...) FMTFUNCTION(1, 2);
// You can use this macro like a runtime assert macro. // You can use this macro like a runtime assert macro.
// If the condition fails, then Error is called with the message. This macro is called // If the condition fails, then Error is called with the message. This macro is called

View File

@ -1,20 +1,42 @@
#include "core/stdafx.h" #include "core/stdafx.h"
#include "tier0/platform_internal.h" #include "tier0/platform_internal.h"
//-----------------------------------------------------------------------------
// Purpose: gets the process up time in seconds
// Output : double
//-----------------------------------------------------------------------------
double Plat_FloatTime() double Plat_FloatTime()
{ {
return v_Plat_FloatTime(); return v_Plat_FloatTime();
} }
//-----------------------------------------------------------------------------
// Purpose: gets the process up time in milliseconds
// Output : uint64_t
//-----------------------------------------------------------------------------
uint64_t Plat_MSTime() uint64_t Plat_MSTime()
{ {
return v_Plat_MSTime(); return v_Plat_MSTime();
} }
//-----------------------------------------------------------------------------
// Purpose: gets the process up time ( !! INTERNAL ONLY !! DO NOT USE !! ).
// Output : const char*
//-----------------------------------------------------------------------------
const char* Plat_GetProcessUpTime() const char* Plat_GetProcessUpTime()
{ {
static char szBuf[4096]; static char szBuf[4096];
sprintf_s(szBuf, sizeof(szBuf), "[%.3f] ", Plat_FloatTime()); sprintf_s(szBuf, sizeof(szBuf), "[%.3f] ", Plat_FloatTime());
return szBuf; return szBuf;
}
//-----------------------------------------------------------------------------
// Purpose: gets the process up time.
// Input : *szBuf -
// nSize -
//-----------------------------------------------------------------------------
void Plat_GetProcessUpTime(char* szBuf, size_t nSize)
{
sprintf_s(szBuf, nSize, "[%.3f] ", Plat_FloatTime());
} }

View File

@ -397,6 +397,7 @@ inline uint64_t Plat_Rdtsc()
double Plat_FloatTime(); double Plat_FloatTime();
uint64_t Plat_MSTime(); uint64_t Plat_MSTime();
const char* Plat_GetProcessUpTime(); const char* Plat_GetProcessUpTime();
void Plat_GetProcessUpTime(char* szBuf, size_t nSize);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Silences a number of warnings on 360 compiles // Silences a number of warnings on 360 compiles

View File

@ -269,7 +269,7 @@ void CUtlBlockMemory<T, I>::ChangeSize(int nBlocks)
if (!m_pMemory) if (!m_pMemory)
{ {
Error(eDLL_T::COMMON, true, "CUtlBlockMemory overflow!\n"); Error(eDLL_T::COMMON, EXIT_FAILURE, "CUtlBlockMemory overflow!\n");
} }
// allocate new blocks if growing // allocate new blocks if growing

View File

@ -296,7 +296,7 @@ void CUtlFixedMemory<T>::Grow(ssize_t num)
BlockHeader_t* RESTRICT pBlockHeader = (BlockHeader_t*)malloc(sizeof(BlockHeader_t) + nBlockSize * sizeof(T)); BlockHeader_t* RESTRICT pBlockHeader = (BlockHeader_t*)malloc(sizeof(BlockHeader_t) + nBlockSize * sizeof(T));
if (!pBlockHeader) if (!pBlockHeader)
{ {
Error(eDLL_T::ENGINE, true, "CUtlFixedMemory overflow!\n"); Error(eDLL_T::ENGINE, EXIT_FAILURE, "CUtlFixedMemory overflow!\n");
} }
pBlockHeader->m_pNext = NULL; pBlockHeader->m_pNext = NULL;
pBlockHeader->m_nBlockSize = nBlockSize; pBlockHeader->m_nBlockSize = nBlockSize;

View File

@ -683,7 +683,7 @@ I CUtlRBTree<T, I, L, M>::NewNode()
Assert(m_Elements.IsValidIterator(it)); Assert(m_Elements.IsValidIterator(it));
if (!m_Elements.IsValidIterator(it)) if (!m_Elements.IsValidIterator(it))
{ {
Error(eDLL_T::ENGINE, true, "CUtlRBTree overflow!\n"); Error(eDLL_T::ENGINE, EXIT_FAILURE, "CUtlRBTree overflow!\n");
} }
} }
m_LastAlloc = it; m_LastAlloc = it;

View File

@ -53,7 +53,7 @@ void CSocketCreator::ProcessAccept(void)
if (!IsSocketBlocking()) if (!IsSocketBlocking())
{ {
#ifndef NETCONSOLE #ifndef NETCONSOLE
Error(eDLL_T::ENGINE, false, "Socket ProcessAccept Error: %s\n", NET_ErrorString(WSAGetLastError())); Error(eDLL_T::ENGINE, NULL, "Socket ProcessAccept Error: %s\n", NET_ErrorString(WSAGetLastError()));
#else #else
printf("Socket ProcessAccept Error: %s\n", NET_ErrorString(WSAGetLastError())); printf("Socket ProcessAccept Error: %s\n", NET_ErrorString(WSAGetLastError()));
#endif // !NETCONSOLE #endif // !NETCONSOLE

View File

@ -576,7 +576,7 @@ void CPackedStore::UnpackAll(const VPKDir_t& vDir, const string& svPathOut)
vDir.m_vHeader.m_nMajorVersion != VPK_MAJOR_VERSION || vDir.m_vHeader.m_nMajorVersion != VPK_MAJOR_VERSION ||
vDir.m_vHeader.m_nMinorVersion != VPK_MINOR_VERSION) vDir.m_vHeader.m_nMinorVersion != VPK_MINOR_VERSION)
{ {
Error(eDLL_T::FS, false, "Unsupported VPK directory file (invalid header criteria)\n"); Error(eDLL_T::FS, NULL, "Unsupported VPK directory file (invalid header criteria)\n");
return; return;
} }
BuildManifest(vDir.m_vEntryBlocks, svPathOut, GetSourceName(vDir.m_svDirPath)); BuildManifest(vDir.m_vEntryBlocks, svPathOut, GetSourceName(vDir.m_svDirPath));
@ -600,7 +600,7 @@ void CPackedStore::UnpackAll(const VPKDir_t& vDir, const string& svPathOut)
if (!oStream.IsWritable()) if (!oStream.IsWritable())
{ {
Error(eDLL_T::FS, false, "Unable to write file '%s'\n", svFilePath.c_str()); Error(eDLL_T::FS, NULL, "Unable to write file '%s'\n", svFilePath.c_str());
continue; continue;
} }
DevMsg(eDLL_T::FS, "Unpacking entry '%zu' from block '%zu' ('%s')\n", j, i, vDir.m_vEntryBlocks[j].m_svEntryPath.c_str()); DevMsg(eDLL_T::FS, "Unpacking entry '%zu' from block '%zu' ('%s')\n", j, i, vDir.m_vEntryBlocks[j].m_svEntryPath.c_str());
@ -623,7 +623,7 @@ void CPackedStore::UnpackAll(const VPKDir_t& vDir, const string& svPathOut)
if (m_lzDecompStatus != lzham_decompress_status_t::LZHAM_DECOMP_STATUS_SUCCESS) if (m_lzDecompStatus != lzham_decompress_status_t::LZHAM_DECOMP_STATUS_SUCCESS)
{ {
Error(eDLL_T::FS, false, "Status '%d' for chunk '%zu' within entry '%zu' in block '%hu' (chunk not decompressed)\n", Error(eDLL_T::FS, NULL, "Status '%d' for chunk '%zu' within entry '%zu' in block '%hu' (chunk not decompressed)\n",
m_lzDecompStatus, m_nChunkCount, i, vDir.m_vEntryBlocks[j].m_iPackFileIndex); m_lzDecompStatus, m_nChunkCount, i, vDir.m_vEntryBlocks[j].m_iPackFileIndex);
} }
else // If successfully decompressed, write to file. else // If successfully decompressed, write to file.

View File

@ -185,9 +185,9 @@ void Host_KickID_f(const CCommand& args)
} }
} }
} }
catch (std::exception& e) catch (const std::exception& e)
{ {
Error(eDLL_T::SERVER, false, "%s - %s", __FUNCTION__, e.what()); Error(eDLL_T::SERVER, NULL, "%s - %s", __FUNCTION__, e.what());
return; return;
} }
} }
@ -296,9 +296,9 @@ void Host_BanID_f(const CCommand& args)
if (bSave) if (bSave)
g_pBanSystem->Save(); g_pBanSystem->Save();
} }
catch (std::exception& e) catch (const std::exception& e)
{ {
Error(eDLL_T::SERVER, false, "%s - %s", __FUNCTION__, e.what()); Error(eDLL_T::SERVER, NULL, "%s - %s", __FUNCTION__, e.what());
return; return;
} }
} }
@ -332,9 +332,9 @@ void Host_Unban_f(const CCommand& args)
} }
} }
} }
catch (std::exception& e) catch (const std::exception& e)
{ {
Error(eDLL_T::SERVER, false, "%s - %s", __FUNCTION__, e.what()); Error(eDLL_T::SERVER, NULL, "%s - %s", __FUNCTION__, e.what());
return; return;
} }
} }
@ -453,9 +453,9 @@ void Pak_RequestUnload_f(const CCommand& args)
g_pakLoadApi->UnloadPak(pakInfo->m_nHandle); g_pakLoadApi->UnloadPak(pakInfo->m_nHandle);
} }
} }
catch (std::exception& e) catch (const std::exception& e)
{ {
Error(eDLL_T::RTECH, false, "%s - %s", __FUNCTION__, e.what()); Error(eDLL_T::RTECH, NULL, "%s - %s", __FUNCTION__, e.what());
return; return;
} }
} }
@ -516,9 +516,9 @@ void Pak_Swap_f(const CCommand& args)
g_pakLoadApi->LoadAsync(pakName.c_str()); g_pakLoadApi->LoadAsync(pakName.c_str());
} }
catch (std::exception& e) catch (const std::exception& e)
{ {
Error(eDLL_T::RTECH, false, "%s - %s", __FUNCTION__, e.what()); Error(eDLL_T::RTECH, NULL, "%s - %s", __FUNCTION__, e.what());
return; return;
} }
} }
@ -570,7 +570,7 @@ void RTech_Decompress_f(const CCommand& args)
if (!FileExists(pakNameIn)) if (!FileExists(pakNameIn))
{ {
Error(eDLL_T::RTECH, false, "%s - pak file '%s' does not exist!\n", __FUNCTION__, pakNameIn.c_str()); Error(eDLL_T::RTECH, NULL, "%s - pak file '%s' does not exist!\n", __FUNCTION__, pakNameIn.c_str());
return; return;
} }
@ -594,17 +594,17 @@ void RTech_Decompress_f(const CCommand& args)
if (rheader.m_nMagic != RPAKHEADER) if (rheader.m_nMagic != RPAKHEADER)
{ {
Error(eDLL_T::RTECH, false, "%s - pak file '%s' has invalid magic!\n", __FUNCTION__, pakNameIn.c_str()); Error(eDLL_T::RTECH, NULL, "%s - pak file '%s' has invalid magic!\n", __FUNCTION__, pakNameIn.c_str());
return; return;
} }
if ((rheader.m_nFlags[1] & 1) != 1) if ((rheader.m_nFlags[1] & 1) != 1)
{ {
Error(eDLL_T::RTECH, false, "%s - pak file '%s' already decompressed!\n", __FUNCTION__, pakNameIn.c_str()); Error(eDLL_T::RTECH, NULL, "%s - pak file '%s' already decompressed!\n", __FUNCTION__, pakNameIn.c_str());
return; return;
} }
if (rheader.m_nSizeDisk != reader.GetSize()) if (rheader.m_nSizeDisk != reader.GetSize())
{ {
Error(eDLL_T::RTECH, false, "%s - pak file '%s' decompressed size '%zu' doesn't match expected value '%llu'!\n", __FUNCTION__, pakNameIn.c_str(), reader.GetSize(), rheader.m_nSizeMemory); Error(eDLL_T::RTECH, NULL, "%s - pak file '%s' decompressed size '%zu' doesn't match expected value '%llu'!\n", __FUNCTION__, pakNameIn.c_str(), reader.GetSize(), rheader.m_nSizeMemory);
return; return;
} }
@ -613,7 +613,7 @@ void RTech_Decompress_f(const CCommand& args)
if (decompSize == rheader.m_nSizeDisk) if (decompSize == rheader.m_nSizeDisk)
{ {
Error(eDLL_T::RTECH, false, "%s - calculated size: '%llu' expected: '%llu'!\n", __FUNCTION__, decompSize, rheader.m_nSizeMemory); Error(eDLL_T::RTECH, NULL, "%s - calculated size: '%llu' expected: '%llu'!\n", __FUNCTION__, decompSize, rheader.m_nSizeMemory);
return; return;
} }
else else
@ -629,7 +629,7 @@ void RTech_Decompress_f(const CCommand& args)
uint8_t decompResult = g_pRTech->DecompressPakFile(&state, reader.GetSize(), pakBuf.size()); uint8_t decompResult = g_pRTech->DecompressPakFile(&state, reader.GetSize(), pakBuf.size());
if (decompResult != 1) if (decompResult != 1)
{ {
Error(eDLL_T::RTECH, false, "%s - decompression failed for '%s' return value: '%hu'!\n", __FUNCTION__, pakNameIn.c_str(), decompResult); Error(eDLL_T::RTECH, NULL, "%s - decompression failed for '%s' return value: '%hu'!\n", __FUNCTION__, pakNameIn.c_str(), decompResult);
return; return;
} }

View File

@ -194,7 +194,7 @@ void GetPresent()
&nFeatureLevelsSupported, &nFeatureLevelsSupported,
&pContext))) &pContext)))
{ {
Error(eDLL_T::MS, true, "Failed to create device and swap chain: error code = %08x\n", hr); Error(eDLL_T::MS, EXIT_FAILURE, "Failed to create device and swap chain: error code = %08x\n", hr);
return; return;
} }
@ -372,7 +372,7 @@ HRESULT __stdcall Present(IDXGISwapChain* pSwapChain, UINT nSyncInterval, UINT n
HRESULT hr = 0; HRESULT hr = 0;
if (FAILED(hr = GetDeviceAndCtxFromSwapchain(pSwapChain, &g_pDevice, &g_pDeviceContext))) if (FAILED(hr = GetDeviceAndCtxFromSwapchain(pSwapChain, &g_pDevice, &g_pDeviceContext)))
{ {
Error(eDLL_T::MS, true, "Failed to get device and context from swap chain: error code = %08x\n", hr); Error(eDLL_T::MS, EXIT_FAILURE, "Failed to get device and context from swap chain: error code = %08x\n", hr);
return g_fnIDXGISwapChainPresent(pSwapChain, nSyncInterval, nFlags); return g_fnIDXGISwapChainPresent(pSwapChain, nSyncInterval, nFlags);
} }
@ -474,10 +474,10 @@ void InstallDXHooks()
DetourAttach(&(LPVOID&)g_oResizeBuffers, (PBYTE)GetResizeBuffers); DetourAttach(&(LPVOID&)g_oResizeBuffers, (PBYTE)GetResizeBuffers);
// Commit the transaction // Commit the transaction
if (DetourTransactionCommit() != NO_ERROR) if (LONG hr = DetourTransactionCommit() != NO_ERROR)
{ {
// Failed to hook into the process, terminate // Failed to hook into the process, terminate
TerminateProcess(GetCurrentProcess(), 0xBAD0C0DE); Error(eDLL_T::COMMON, 0xBAD0C0DE, "Failed to detour process: error code = %08x\n", hr);
} }
} }