From 4d49b809f078530430827faafe52b8ceb510974e Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:22:40 +0300 Subject: [PATCH 01/19] Main --- Client/ceflauncher/premake5.lua | 2 ++ Client/ceflauncher_DLL/premake5.lua | 2 ++ Client/cefweb/premake5.lua | 2 ++ .../core/CAdditionalVertexStreamManager.cpp | 4 +-- Client/core/CCommands.cpp | 4 +-- Client/core/CCore.cpp | 4 +-- Client/core/CEntryHistory.h | 2 +- Client/core/CFilePathTranslator.cpp | 2 +- Client/core/CKeyBinds.cpp | 4 +-- Client/core/CVersionUpdater.Util.hpp | 4 +-- .../Graphics/CRenderItem.EffectTemplate.cpp | 8 +++--- Client/core/ServerBrowser/CServerBrowser.cpp | 16 ++++++------ Client/core/premake5.lua | 2 ++ Client/game_sa/CModelInfoSA.cpp | 2 +- Client/game_sa/CModelInfoSA.h | 2 +- Client/game_sa/CWeaponSA.cpp | 5 +++- Client/game_sa/CWeaponSA.h | 2 +- Client/gui/premake5.lua | 2 ++ Client/launch/premake5.lua | 2 ++ Client/loader-proxy/premake5.lua | 2 ++ Client/loader/CInstallManager.cpp | 16 ++++++------ Client/loader/Install.Manifest.cpp | 2 +- Client/loader/MainFunctions.cpp | 2 +- Client/loader/Utils.cpp | 2 +- Client/loader/premake5.lua | 2 ++ Client/mods/deathmatch/logic/CAntiCheat.cpp | 4 +-- Client/mods/deathmatch/logic/CClientGame.cpp | 2 +- Client/mods/deathmatch/logic/CClientIFP.cpp | 8 ++++++ Client/mods/deathmatch/logic/CClientIFP.h | 7 +---- .../deathmatch/logic/CClientModelManager.h | 2 +- .../logic/CClientPerfStat.LuaMemory.cpp | 26 +++++++++---------- .../logic/CClientPerfStat.LuaTiming.cpp | 6 ++--- .../deathmatch/logic/CClientStreamSector.cpp | 4 +-- .../deathmatch/logic/CClientStreamSector.h | 2 +- .../mods/deathmatch/logic/CClientStreamer.cpp | 2 +- .../mods/deathmatch/logic/CClientStreamer.h | 2 +- .../mods/deathmatch/logic/CClientWeapon.cpp | 2 +- .../deathmatch/logic/CServerIdManager.cpp | 2 +- .../deathmatch/logic/lua/CLuaTimerManager.cpp | 4 +-- .../logic/luadefs/CLuaBuildingDefs.cpp | 2 +- .../mods/deathmatch/logic/luadefs/CLuaDefs.h | 4 +++ .../logic/luadefs/CLuaDrawingDefs.cpp | 2 +- .../logic/luadefs/CLuaEngineDefs.cpp | 18 ++++++------- Client/mods/deathmatch/premake5.lua | 2 ++ Client/sdk/game/CModelInfo.h | 2 +- Client/sdk/game/CWeapon.h | 2 +- Server/core/premake5.lua | 2 ++ Server/launcher/premake5.lua | 2 ++ Server/mods/deathmatch/premake5.lua | 2 ++ .../deathmatch/logic/luadefs/CLuaUtilDefs.cpp | 2 +- Shared/sdk/SString.h | 6 ++--- Shared/sdk/SharedUtil.Logging.hpp | 4 +-- Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp | 2 +- .../sparsehash/internal/hashtable-common.h | 6 ++--- 54 files changed, 131 insertions(+), 97 deletions(-) diff --git a/Client/ceflauncher/premake5.lua b/Client/ceflauncher/premake5.lua index 1fd73bd1fa..85a99b14bc 100644 --- a/Client/ceflauncher/premake5.lua +++ b/Client/ceflauncher/premake5.lua @@ -4,6 +4,8 @@ project "CEFLauncher" targetname "CEFLauncher" targetdir(buildpath("mta/cef")) + cppdialect "C++20" + includedirs { "../sdk" } links { "CEFLauncher DLL"} diff --git a/Client/ceflauncher_DLL/premake5.lua b/Client/ceflauncher_DLL/premake5.lua index a7276942b0..630e38e764 100644 --- a/Client/ceflauncher_DLL/premake5.lua +++ b/Client/ceflauncher_DLL/premake5.lua @@ -4,6 +4,8 @@ project "CEFLauncher DLL" targetname "CEFLauncher_DLL" targetdir(buildpath("mta/cef")) + cppdialect "C++20" + includedirs { "../../vendor/cef3/cef" } libdirs { "../../vendor/cef3/cef/Release" } diff --git a/Client/cefweb/premake5.lua b/Client/cefweb/premake5.lua index da81e609de..2f868c6565 100644 --- a/Client/cefweb/premake5.lua +++ b/Client/cefweb/premake5.lua @@ -4,6 +4,8 @@ project "Client Webbrowser" targetname "cefweb" targetdir(buildpath("mta")) + cppdialect "C++20" + filter "system:windows" includedirs { "../../vendor/sparsehash/src/windows" } linkoptions { "/SAFESEH:NO" } diff --git a/Client/core/CAdditionalVertexStreamManager.cpp b/Client/core/CAdditionalVertexStreamManager.cpp index 027d4894a7..7fda15c252 100644 --- a/Client/core/CAdditionalVertexStreamManager.cpp +++ b/Client/core/CAdditionalVertexStreamManager.cpp @@ -466,13 +466,13 @@ SAdditionalStreamInfo* CAdditionalVertexStreamManager::CreateAdditionalStreamInf declNew->Usage = D3DDECLUSAGE_NORMAL; declNew->UsageIndex = 0; if (FAILED(m_pDevice->CreateVertexDeclaration(elements, &info.pVertexDeclaration))) - return false; + return nullptr; // Create new stream info.Stride = sizeof(float) * 3; UINT Size2 = ConvertPTSize(state.decl.VertexBufferDesc1.Size); if (FAILED(m_pDevice->CreateVertexBuffer(Size2, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &info.pStreamData, NULL))) - return false; + return nullptr; // Save info MapSet(m_AdditionalStreamInfoMap, state.stream1.pStreamData, info); diff --git a/Client/core/CCommands.cpp b/Client/core/CCommands.cpp index 1dfc8e0328..c729a41c14 100644 --- a/Client/core/CCommands.cpp +++ b/Client/core/CCommands.cpp @@ -84,12 +84,12 @@ bool CCommands::Execute(const char* szCommandLine) bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool bHandleRemotely, bool bIsScriptedBind) { // Copy szParametersIn so the contents can be changed - char* szParameters = NULL; + const char* szParameters = NULL; if (szParametersIn) { size_t sizeParameters = strlen(szParametersIn) + 1; szParameters = static_cast(alloca(sizeParameters)); - memcpy(szParameters, szParametersIn, sizeParameters); + memcpy(const_cast(szParameters), szParametersIn, sizeParameters); } // HACK: if its a 'chatboxsay' command, use the next parameter diff --git a/Client/core/CCore.cpp b/Client/core/CCore.cpp index 849eee0afc..6132cf7f69 100644 --- a/Client/core/CCore.cpp +++ b/Client/core/CCore.cpp @@ -60,13 +60,13 @@ static HMODULE WINAPI SkipDirectPlay_LoadLibraryA(LPCSTR fileName) const fs::path inLaunchDir = fs::path{FromUTF8(GetLaunchPath())} / "enbseries" / "enbhelper.dll"; if (fs::is_regular_file(inLaunchDir, ec)) - return Win32LoadLibraryA(inLaunchDir.u8string().c_str()); + return Win32LoadLibraryA(inLaunchDir.string().c_str()); // Try to load enbhelper.dll from the GTA install directory second. const fs::path inGTADir = g_gtaDirectory / "enbseries" / "enbhelper.dll"; if (fs::is_regular_file(inGTADir, ec)) - return Win32LoadLibraryA(inGTADir.u8string().c_str()); + return Win32LoadLibraryA(inGTADir.string().c_str()); return nullptr; } diff --git a/Client/core/CEntryHistory.h b/Client/core/CEntryHistory.h index c47fea1de0..0231c4fff3 100644 --- a/Client/core/CEntryHistory.h +++ b/Client/core/CEntryHistory.h @@ -66,7 +66,7 @@ class CEntryHistory // Return a specific entry from history CEntryHistoryItem* Get(unsigned int index) { - auto& iter = std::next(m_entries.begin(), index); + auto iter = std::next(m_entries.begin(), index); if (iter != m_entries.end()) return &(*iter); return nullptr; diff --git a/Client/core/CFilePathTranslator.cpp b/Client/core/CFilePathTranslator.cpp index 20b93f2f64..ce1bb420b6 100644 --- a/Client/core/CFilePathTranslator.cpp +++ b/Client/core/CFilePathTranslator.cpp @@ -80,7 +80,7 @@ void CFilePathTranslator::GetCurrentWorkingDirectory(std::string& WorkingDirecto void CFilePathTranslator::GetGTARootDirectory(std::string& ModuleRootDirOut) { - ModuleRootDirOut = g_gtaDirectory.u8string(); + ModuleRootDirOut = g_gtaDirectory.string(); } void CFilePathTranslator::GetMTASARootDirectory(std::string& InstallRootDirOut) diff --git a/Client/core/CKeyBinds.cpp b/Client/core/CKeyBinds.cpp index 78b354bd00..04e673936e 100644 --- a/Client/core/CKeyBinds.cpp +++ b/Client/core/CKeyBinds.cpp @@ -2300,7 +2300,7 @@ void CKeyBinds::BindCommand(const char* szCmdLine) { CConsoleInterface* pConsole = m_pCore->GetConsole(); - char* szError = "* Syntax: bind [] []"; + const char* szError = "* Syntax: bind [] []"; if (szCmdLine == NULL) { pConsole->Print(szError); @@ -2383,7 +2383,7 @@ void CKeyBinds::UnbindCommand(const char* szCmdLine) { CConsoleInterface* pConsole = m_pCore->GetConsole(); - char* szError = "* Syntax: unbind [ ]"; + const char* szError = "* Syntax: unbind [ ]"; if (szCmdLine == NULL) { pConsole->Print(szError); diff --git a/Client/core/CVersionUpdater.Util.hpp b/Client/core/CVersionUpdater.Util.hpp index d6f7677c9a..38976e2830 100644 --- a/Client/core/CVersionUpdater.Util.hpp +++ b/Client/core/CVersionUpdater.Util.hpp @@ -391,7 +391,7 @@ namespace SString GetAttribute(const SString& strName) const { const SString* pValue = MapFind(attributeMap, strName); - return pValue ? *pValue : ""; + return pValue ? (*pValue).c_str() : ""; } void SetAttribute(const SString& strName, const SString& strValue) { MapSet(attributeMap, strName, strValue); } }; @@ -606,7 +606,7 @@ namespace SaveReportSettings(); } - SString GetFilter() const { return strFilter != "" ? strFilter : "+all"; } + SString GetFilter() const { return strFilter != "" ? strFilter.c_str() : "+all"; } int GetMinSize() const { return iMinSize; } diff --git a/Client/core/Graphics/CRenderItem.EffectTemplate.cpp b/Client/core/Graphics/CRenderItem.EffectTemplate.cpp index 618b890e9f..9bf35abe19 100644 --- a/Client/core/Graphics/CRenderItem.EffectTemplate.cpp +++ b/Client/core/Graphics/CRenderItem.EffectTemplate.cpp @@ -47,7 +47,7 @@ namespace SString m_strReport; std::map m_FileMD5Map; - CIncludeManager::CIncludeManager(const SString& strRootPath, const SString& strCurrentPath) + CIncludeManager(const SString& strRootPath, const SString& strCurrentPath) { m_strRootPath = strRootPath; m_strCurrentPath = strCurrentPath; @@ -228,15 +228,15 @@ void CEffectTemplate::CreateUnderlyingData(const SString& strFile, const SString if (bDebug) dwFlags |= D3DXSHADER_DEBUG; - SString strMetaPath = bIsRawData ? "" : strFile.Right(strFile.length() - strRootPath.length()); - CIncludeManager IncludeManager(strRootPath, ExtractPath(strMetaPath)); + const char* szMetaPath = bIsRawData ? "" : strFile.Right(strFile.length() - strRootPath.length()).c_str(); + CIncludeManager IncludeManager(strRootPath, ExtractPath(szMetaPath)); LPD3DXBUFFER pBufferErrors = NULL; if (bIsRawData) m_CreateHResult = MyD3DXCreateEffect(m_pDevice, strFile, strFile.length(), ¯oList[0], &IncludeManager, dwFlags, NULL, &m_pD3DEffect, &pBufferErrors); else m_CreateHResult = - MyD3DXCreateEffectFromFile(m_pDevice, ExtractFilename(strMetaPath), ¯oList[0], &IncludeManager, dwFlags, NULL, &m_pD3DEffect, &pBufferErrors); + MyD3DXCreateEffectFromFile(m_pDevice, ExtractFilename(szMetaPath), ¯oList[0], &IncludeManager, dwFlags, NULL, &m_pD3DEffect, &pBufferErrors); // Handle compile errors strOutStatus = ""; diff --git a/Client/core/ServerBrowser/CServerBrowser.cpp b/Client/core/ServerBrowser/CServerBrowser.cpp index 764078e563..978b9811bd 100644 --- a/Client/core/ServerBrowser/CServerBrowser.cpp +++ b/Client/core/ServerBrowser/CServerBrowser.cpp @@ -1078,21 +1078,21 @@ void CServerBrowser::AddServerToList(CServerListItem* pServer, const ServerBrows pServer->iRowIndex = iIndex; } - const SString strVersion = !bIncludeOtherVersions ? "" : pServer->strVersion; + const char* szVersion = !bIncludeOtherVersions ? "" : pServer->strVersion.c_str(); const SString strVersionSortKey = pServer->strVersionSortKey + pServer->strTieBreakSortKey; - const SString strPlayers = pServer->nMaxPlayers == 0 ? "" : SString("%d / %d", pServer->nPlayers, pServer->nMaxPlayers); + const char* szPlayers = pServer->nMaxPlayers == 0 ? "" : SString("%d / %d", pServer->nPlayers, pServer->nMaxPlayers).c_str(); const SString strPlayersSortKey = SString("%04d-", pServer->nMaxPlayers ? pServer->nPlayers + 1 : 0) + pServer->strTieBreakSortKey; - const SString strPing = pServer->nPing == 9999 ? "" : SString("%d", pServer->nPing); + const char* szPing = pServer->nPing == 9999 ? "" : SString("%d", pServer->nPing).c_str(); const SString strPingSortKey = SString("%04d-", pServer->nPing) + pServer->strTieBreakSortKey; // The row index could change at any point here if list sorting is enabled - iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hVersion[Type], strVersion, false, false, true, strVersionSortKey); - iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hName[Type], pServer->strName, false, false, true, pServer->strNameSortKey); - iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hGame[Type], pServer->strGameMode, false, false, true); - iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hPlayers[Type], strPlayers, false, false, true, strPlayersSortKey); - iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hPing[Type], strPing, false, false, true, strPingSortKey); + iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hVersion[Type], szVersion, false, false, true, strVersionSortKey); + iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hName[Type], pServer->strName.c_str(), false, false, true, pServer->strNameSortKey); + iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hGame[Type], pServer->strGameMode.c_str(), false, false, true); + iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hPlayers[Type], szPlayers, false, false, true, strPlayersSortKey); + iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hPing[Type], szPing, false, false, true, strPingSortKey); // Locked icon m_pServerList[Type]->SetItemImage(iIndex, m_hLocked[Type], pServer->bPassworded ? m_pLockedIcon : NULL); diff --git a/Client/core/premake5.lua b/Client/core/premake5.lua index 0573dd6c05..afb43c5228 100644 --- a/Client/core/premake5.lua +++ b/Client/core/premake5.lua @@ -4,6 +4,8 @@ project "Client Core" targetname "core" targetdir(buildpath("mta")) + cppdialect "C++20" + filter "system:windows" includedirs { "../../vendor/sparsehash/src/windows" } linkoptions { "/SAFESEH:NO" } diff --git a/Client/game_sa/CModelInfoSA.cpp b/Client/game_sa/CModelInfoSA.cpp index 5dc00712da..a11a5d7be4 100644 --- a/Client/game_sa/CModelInfoSA.cpp +++ b/Client/game_sa/CModelInfoSA.cpp @@ -1708,7 +1708,7 @@ void CModelInfoSA::CopyStreamingInfoFromModel(ushort usBaseModelID) pTargetModelStreamingInfo->sizeInBlocks = pBaseModelStreamingInfo->sizeInBlocks; } -void CModelInfoSA::MakePedModel(char* szTexture) +void CModelInfoSA::MakePedModel(const char* szTexture) { // Create a new CPedModelInfo CPedModelInfoSA pedModelInfo; diff --git a/Client/game_sa/CModelInfoSA.h b/Client/game_sa/CModelInfoSA.h index 329d2e3e50..f808ed5755 100644 --- a/Client/game_sa/CModelInfoSA.h +++ b/Client/game_sa/CModelInfoSA.h @@ -444,7 +444,7 @@ class CModelInfoSA : public CModelInfo RwObject* GetRwObject() { return m_pInterface ? m_pInterface->pRwObject : NULL; } // CModelInfoSA methods - void MakePedModel(char* szTexture); + void MakePedModel(const char* szTexture); void MakeObjectModel(ushort usBaseModelID); void MakeVehicleAutomobile(ushort usBaseModelID); void MakeTimedObjectModel(ushort usBaseModelID); diff --git a/Client/game_sa/CWeaponSA.cpp b/Client/game_sa/CWeaponSA.cpp index d419734b8e..7edace7953 100644 --- a/Client/game_sa/CWeaponSA.cpp +++ b/Client/game_sa/CWeaponSA.cpp @@ -175,8 +175,11 @@ bool CWeaponSA::Fire(CEntity* pFiringEntity, CVector* pvecOrigin, CVector* pvecT return bReturn; } -void CWeaponSA::AddGunshell(CEntity* pFiringEntity, CVector* pvecOrigin, CVector2D* pvecDirection, float fSize) +void CWeaponSA::AddGunshell(CEntity* pFiringEntity, const CVector& vecOrigin, const CVector2D& vecDirection, float fSize) { + const CVector* pvecOrigin = &vecOrigin; + const CVector2D* pvecDirection = &vecDirection; + DWORD dwEntityInterface = 0; if (pFiringEntity) dwEntityInterface = (DWORD)pFiringEntity->GetInterface(); diff --git a/Client/game_sa/CWeaponSA.h b/Client/game_sa/CWeaponSA.h index 147f9017d9..d0d3fc976b 100644 --- a/Client/game_sa/CWeaponSA.h +++ b/Client/game_sa/CWeaponSA.h @@ -67,7 +67,7 @@ class CWeaponSA : public CWeapon void Initialize(eWeaponType type, unsigned int uiAmmo, CPed* pPed); void Update(CPed* pPed); bool Fire(CEntity* pFiringEntity, CVector* pvecOrigin, CVector* pvecOffset, CEntity* pTargetEntity, CVector* pvec_1, CVector* pvec_2); - void AddGunshell(CEntity* pFiringEntity, CVector* pvecOrigin, CVector2D* pvecDirection, float fSize); + void AddGunshell(CEntity* pFiringEntity, const CVector& vecOrigin, const CVector2D& vecDirection, float fSize); void DoBulletImpact(CEntity* pFiringEntity, CEntitySAInterface* pEntityInterface, CVector* pvecOrigin, CVector* pvecTarget, CColPoint* pColPoint, int i_1); unsigned char GenerateDamageEvent(CPed* pPed, CEntity* pResponsible, eWeaponType weaponType, int iDamagePerHit, ePedPieceTypes hitZone, int i_2); bool ProcessLineOfSight(const CVector* vecStart, const CVector* vecEnd, CColPoint** colCollision, CEntity** CollisionEntity, const SLineOfSightFlags flags, diff --git a/Client/gui/premake5.lua b/Client/gui/premake5.lua index 9fa53ab4f6..1a6ef70ec7 100644 --- a/Client/gui/premake5.lua +++ b/Client/gui/premake5.lua @@ -4,6 +4,8 @@ project "GUI" targetname "cgui" targetdir(buildpath("mta")) + cppdialect "C++20" + filter "system:windows" includedirs { "../../vendor/sparsehash/src/windows" } diff --git a/Client/launch/premake5.lua b/Client/launch/premake5.lua index 4a8fed34f6..9e0e480bbd 100644 --- a/Client/launch/premake5.lua +++ b/Client/launch/premake5.lua @@ -5,6 +5,8 @@ project "Client Launcher" targetdir(buildpath(".")) debugdir(buildpath(".")) + cppdialect "C++20" + includedirs { "../../Shared/sdk", "../sdk", diff --git a/Client/loader-proxy/premake5.lua b/Client/loader-proxy/premake5.lua index 36ad798f54..811d5383be 100644 --- a/Client/loader-proxy/premake5.lua +++ b/Client/loader-proxy/premake5.lua @@ -5,6 +5,8 @@ project "Loader Proxy" targetdir(buildpath("mta")) targetsuffix "" + cppdialect "C++20" + vpaths { ["Headers/*"] = "**.h", ["Sources"] = { "*.cpp" }, diff --git a/Client/loader/CInstallManager.cpp b/Client/loader/CInstallManager.cpp index 0f1b9f9728..f0168ea5f4 100644 --- a/Client/loader/CInstallManager.cpp +++ b/Client/loader/CInstallManager.cpp @@ -655,13 +655,13 @@ SString CInstallManager::_PrepareLaunchLocation() if (fs::is_regular_file(sourcePath, ec)) { SString strMessage(_("MTA:SA cannot launch because copying a file failed:")); - strMessage += "\n\n" + targetPath.u8string(); + strMessage += "\n\n" + targetPath.string(); BrowseToSolution("copy-files", ASK_GO_ONLINE, strMessage); } else { SString strMessage(_("MTA:SA cannot launch because an MTA:SA file is incorrect or missing:")); - strMessage += "\n\n" + sourcePath.u8string(); + strMessage += "\n\n" + sourcePath.string(); BrowseToSolution("mta-datafiles-missing", ASK_GO_ONLINE, strMessage); } @@ -693,7 +693,7 @@ SString CInstallManager::_ProcessGtaPatchCheck() if (!FileGenerator::IsPatchBase(patchBasePath)) { SString strMessage(_("MTA:SA cannot launch because a GTA:SA file is incorrect or missing:")); - strMessage += "\n\n" + patchBasePath.u8string(); + strMessage += "\n\n" + patchBasePath.string(); BrowseToSolution("gengta_pakfiles", ASK_GO_ONLINE, strMessage); return "quit"; } @@ -701,7 +701,7 @@ SString CInstallManager::_ProcessGtaPatchCheck() if (!FileGenerator::IsPatchDiff(patchDiffPath)) { SString strMessage(_("MTA:SA cannot launch because an MTA:SA file is incorrect or missing:")); - strMessage += "\n\n" + patchDiffPath.u8string(); + strMessage += "\n\n" + patchDiffPath.string(); BrowseToSolution("mta-datafiles-missing", ASK_GO_ONLINE, strMessage); return "quit"; } @@ -771,7 +771,7 @@ SString CInstallManager::_ProcessGtaDllCheck() if (isAdmin) { SString strMessage(_("MTA:SA cannot launch because a GTA:SA file is incorrect or missing:")); - strMessage += "\n\n" + dependecyPath.u8string(); + strMessage += "\n\n" + dependecyPath.string(); BrowseToSolution(SString("gendep_error&name=%s", dependency.fileName), ASK_GO_ONLINE, strMessage); return "quit"; } @@ -826,7 +826,7 @@ SString CInstallManager::_ProcessGtaVersionCheck() if (isAdmin) { SString strMessage(_("MTA:SA cannot launch because the GTA:SA executable is incorrect or missing:")); - strMessage += "\n\n" + gtaExePath.u8string(); + strMessage += "\n\n" + gtaExePath.string(); strMessage += "\n\n" + _("Please check your anti-virus for a false-positive detection, try to add an exception for the GTA:SA executable and restart MTA:SA."); @@ -851,7 +851,7 @@ SString CInstallManager::_ProcessGtaVersionCheck() if (isAdmin) { SString strMessage(_("MTA:SA cannot launch because the GTA:SA executable is not loadable:")); - strMessage += "\n\n" + gtaExePath.u8string(); + strMessage += "\n\n" + gtaExePath.string(); BrowseToSolution(SString("gengta_error&code=%d", ec.value()), ASK_GO_ONLINE, strMessage); return "quit"; } @@ -874,7 +874,7 @@ SString CInstallManager::_ProcessGtaVersionCheck() if (isAdmin) { SString strMessage(_("MTA:SA cannot launch because patching GTA:SA has failed:")); - strMessage += "\n\n" + gtaExePath.u8string(); + strMessage += "\n\n" + gtaExePath.string(); BrowseToSolution(SString("patchgta_error&code=%d", ec.value()), ASK_GO_ONLINE, strMessage); return "quit"; } diff --git a/Client/loader/Install.Manifest.cpp b/Client/loader/Install.Manifest.cpp index 9f3e264d02..ada7dc4421 100644 --- a/Client/loader/Install.Manifest.cpp +++ b/Client/loader/Install.Manifest.cpp @@ -63,7 +63,7 @@ static void ParseManifestVersion1(std::ifstream& manifest, std::vector 0) + if (reinterpret_cast(strchr(pathList[0].c_str(), '?')) > 0) return GAME_PATH_UNICODE_CHARS; } diff --git a/Client/loader/premake5.lua b/Client/loader/premake5.lua index 712d517ed2..b52bb63ae4 100644 --- a/Client/loader/premake5.lua +++ b/Client/loader/premake5.lua @@ -4,6 +4,8 @@ project "Loader" targetname "loader" targetdir(buildpath("mta")) + cppdialect "C++20" + filter "system:windows" linkoptions { "/SAFESEH:NO" } diff --git a/Client/mods/deathmatch/logic/CAntiCheat.cpp b/Client/mods/deathmatch/logic/CAntiCheat.cpp index dc2effaff6..bc3f80a2d3 100644 --- a/Client/mods/deathmatch/logic/CAntiCheat.cpp +++ b/Client/mods/deathmatch/logic/CAntiCheat.cpp @@ -100,9 +100,9 @@ SString CAntiCheat::GetInfo(const SString& acInfo, const SString& sdInfo) SString strAllowedFiles = "None"; SString strVerifyFiles = acInfo.SplitLeft(","); - SString strEnabledSD = sdInfo == "" ? "None" : sdInfo; + SString strEnabledSD = sdInfo == "" ? "None" : sdInfo.c_str(); SString strDisabledAC = acInfo.SplitRight(","); - strDisabledAC = strDisabledAC == "" ? "None" : strDisabledAC; + strDisabledAC = strDisabledAC == "" ? "None" : strDisabledAC.c_str(); int iVerifyFiles = atoi(strVerifyFiles); if (iVerifyFiles == 0) diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index 0bad60ecf2..7c536e94d6 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -1019,7 +1019,7 @@ void CClientGame::DoPulsePostFrame() bool useZoneName = true; const eClientVehicleType vehicleType = (pVehicle) ? CClientVehicleManager::GetVehicleType(pVehicle->GetModel()) : CLIENTVEHICLE_NONE; - std::string discordState = (pVehicle) ? g_vehicleTypePrefixes.at(vehicleType).c_str() : _("Walking around "); + std::string discordState = (pVehicle) ? g_vehicleTypePrefixes.at(vehicleType).c_str() : _("Walking around ").c_str(); if (task && task->IsValid()) { diff --git a/Client/mods/deathmatch/logic/CClientIFP.cpp b/Client/mods/deathmatch/logic/CClientIFP.cpp index 4fd3c31242..b313747310 100644 --- a/Client/mods/deathmatch/logic/CClientIFP.cpp +++ b/Client/mods/deathmatch/logic/CClientIFP.cpp @@ -1109,3 +1109,11 @@ CAnimBlendHierarchySAInterface* CClientIFP::GetAnimationHierarchy(const SString& } return nullptr; } + +template +void CClientIFP::ReadCompressedFrames(std::unique_ptr& pAnimationSequence, std::int32_t iFrames) +{ + BYTE* pKeyFrames = pAnimationSequence->GetKeyFrames(); + size_t iSizeInBytes = sizeof(T) * iFrames; + ReadBytes(pKeyFrames, iSizeInBytes); +} diff --git a/Client/mods/deathmatch/logic/CClientIFP.h b/Client/mods/deathmatch/logic/CClientIFP.h index 8b3283dc8d..cefbd17a21 100644 --- a/Client/mods/deathmatch/logic/CClientIFP.h +++ b/Client/mods/deathmatch/logic/CClientIFP.h @@ -242,12 +242,7 @@ class CClientIFP final : public CClientEntity, CFileReader void ReadKr00FramesAsCompressed(std::unique_ptr& pAnimationSequence, const std::int32_t& cFrames); template - void ReadCompressedFrames(std::unique_ptr& pAnimationSequence, std::int32_t iFrames) - { - BYTE* pKeyFrames = pAnimationSequence->GetKeyFrames(); - size_t iSizeInBytes = sizeof(T) * iFrames; - ReadBytes(pKeyFrames, iSizeInBytes); - } + void ReadCompressedFrames(std::unique_ptr& pAnimationSequence, std::int32_t iFrames); void InitializeAnimationHierarchy(std::unique_ptr& pAnimationHierarchy, const SString& strAnimationName, const std::int32_t& iSequences); diff --git a/Client/mods/deathmatch/logic/CClientModelManager.h b/Client/mods/deathmatch/logic/CClientModelManager.h index add0053a1e..15fff298ca 100644 --- a/Client/mods/deathmatch/logic/CClientModelManager.h +++ b/Client/mods/deathmatch/logic/CClientModelManager.h @@ -26,7 +26,7 @@ class CClientModelManager friend class CClientModel; public: - CClientModelManager::CClientModelManager(); + CClientModelManager(); ~CClientModelManager(void); void RemoveAll(void); diff --git a/Client/mods/deathmatch/logic/CClientPerfStat.LuaMemory.cpp b/Client/mods/deathmatch/logic/CClientPerfStat.LuaMemory.cpp index 18e134f2dd..32c64f3abc 100644 --- a/Client/mods/deathmatch/logic/CClientPerfStat.LuaMemory.cpp +++ b/Client/mods/deathmatch/logic/CClientPerfStat.LuaMemory.cpp @@ -297,15 +297,15 @@ void CClientPerfStatLuaMemoryImpl::GetLuaMemoryStats(CClientPerfStatResult* pRes int WebBrowserCount = g_pClientGame->GetManager()->GetRenderElementManager()->GetWebBrowserCount(); int VectorGraphicCount = g_pClientGame->GetManager()->GetRenderElementManager()->GetVectorGraphicCount(); TextItemCount = std::max(TextItemCount - 4, 0); // Remove count for radar items - row[c++] = !TextItemCount ? "-" : SString("%d", TextItemCount); - row[c++] = !DxFontCount ? "-" : SString("%d", DxFontCount); - row[c++] = !GuiFontCount ? "-" : SString("%d", GuiFontCount); - row[c++] = !TextureCount ? "-" : SString("%d", TextureCount); - row[c++] = !ShaderCount ? "-" : SString("%d", ShaderCount); - row[c++] = !RenderTargetCount ? "-" : SString("%d", RenderTargetCount); - row[c++] = !ScreenSourceCount ? "-" : SString("%d", ScreenSourceCount); - row[c++] = !WebBrowserCount ? "-" : SString("%d", WebBrowserCount); - row[c++] = !VectorGraphicCount ? "-" : SString("%d", VectorGraphicCount); + row[c++] = !TextItemCount ? "-" : SString("%d", TextItemCount).c_str(); + row[c++] = !DxFontCount ? "-" : SString("%d", DxFontCount).c_str(); + row[c++] = !GuiFontCount ? "-" : SString("%d", GuiFontCount).c_str(); + row[c++] = !TextureCount ? "-" : SString("%d", TextureCount).c_str(); + row[c++] = !ShaderCount ? "-" : SString("%d", ShaderCount).c_str(); + row[c++] = !RenderTargetCount ? "-" : SString("%d", RenderTargetCount).c_str(); + row[c++] = !ScreenSourceCount ? "-" : SString("%d", ScreenSourceCount).c_str(); + row[c++] = !WebBrowserCount ? "-" : SString("%d", WebBrowserCount).c_str(); + row[c++] = !VectorGraphicCount ? "-" : SString("%d", VectorGraphicCount).c_str(); } // For each VM @@ -333,9 +333,9 @@ void CClientPerfStatLuaMemoryImpl::GetLuaMemoryStats(CClientPerfStatResult* pRes row[c++] = SString("%d KB", LuaMainMemory.Current); row[c++] = SString("%d KB", LuaMainMemory.Max); - row[c++] = !LuaMainMemory.OpenXMLFiles ? "-" : SString("%d", LuaMainMemory.OpenXMLFiles); - row[c++] = !LuaMainMemory.Refs ? "-" : SString("%d", LuaMainMemory.Refs); - row[c++] = !LuaMainMemory.TimerCount ? "-" : SString("%d", LuaMainMemory.TimerCount); - row[c++] = !LuaMainMemory.ElementCount ? "-" : SString("%d", LuaMainMemory.ElementCount); + row[c++] = !LuaMainMemory.OpenXMLFiles ? "-" : SString("%d", LuaMainMemory.OpenXMLFiles).c_str(); + row[c++] = !LuaMainMemory.Refs ? "-" : SString("%d", LuaMainMemory.Refs).c_str(); + row[c++] = !LuaMainMemory.TimerCount ? "-" : SString("%d", LuaMainMemory.TimerCount).c_str(); + row[c++] = !LuaMainMemory.ElementCount ? "-" : SString("%d", LuaMainMemory.ElementCount).c_str(); } } diff --git a/Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp b/Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp index e89923a5f8..e46bced15a 100644 --- a/Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp +++ b/Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp @@ -430,9 +430,9 @@ void CClientPerfStatLuaTimingImpl::OutputTimingBlock(CClientPerfStatResult* pRes double total_p = total_s / double(threshList[i]) * 100; - row[c++] = total_p > 0.005 ? SString("%2.2f%%", total_p) : "-"; - row[c++] = total_s > 0.0005 ? SString("%2.3f", total_s) : "-"; - row[c++] = p->prev.calls > 0 ? SString("%d", p->prev.calls) : ""; + row[c++] = total_p > 0.005 ? SString("%2.2f%%", total_p).c_str() : "-"; + row[c++] = total_s > 0.0005 ? SString("%2.3f", total_s).c_str() : "-"; + row[c++] = p->prev.calls > 0 ? SString("%d", p->prev.calls).c_str() : ""; row[c++] = avg_s > 0.0005 ? SString("%2.3f", avg_s).c_str() : bSubBlock ? "-" : ""; row[c++] = max_s > 0.0005 ? SString("%2.3f", max_s).c_str() : bSubBlock ? "-" : ""; } diff --git a/Client/mods/deathmatch/logic/CClientStreamSector.cpp b/Client/mods/deathmatch/logic/CClientStreamSector.cpp index 39a2f38c7b..41bf225b3c 100644 --- a/Client/mods/deathmatch/logic/CClientStreamSector.cpp +++ b/Client/mods/deathmatch/logic/CClientStreamSector.cpp @@ -12,7 +12,7 @@ using std::list; -CClientStreamSector::CClientStreamSector(CClientStreamSectorRow* pRow, CVector2D& vecBottomLeft, CVector2D& vecTopRight) +CClientStreamSector::CClientStreamSector(CClientStreamSectorRow* pRow, const CVector2D& vecBottomLeft, const CVector2D& vecTopRight) { m_pRow = pRow; m_vecBottomLeft = vecBottomLeft; @@ -157,4 +157,4 @@ void CClientStreamSector::RemoveElements(list* pList) { pList->remove(*iter); } -} \ No newline at end of file +} diff --git a/Client/mods/deathmatch/logic/CClientStreamSector.h b/Client/mods/deathmatch/logic/CClientStreamSector.h index 10bd3db2f3..89c4b98dce 100644 --- a/Client/mods/deathmatch/logic/CClientStreamSector.h +++ b/Client/mods/deathmatch/logic/CClientStreamSector.h @@ -23,7 +23,7 @@ class CClientStreamSector friend class CClientStreamSectorRow; public: - CClientStreamSector(CClientStreamSectorRow* pRow, CVector2D& vecBottomLeft, CVector2D& vecTopRight); + CClientStreamSector(CClientStreamSectorRow* pRow, const CVector2D& vecBottomLeft, const CVector2D& vecTopRight); ~CClientStreamSector(); bool DoesContain(CVector& vecPosition); diff --git a/Client/mods/deathmatch/logic/CClientStreamer.cpp b/Client/mods/deathmatch/logic/CClientStreamer.cpp index e0aff6d352..3890bf544a 100644 --- a/Client/mods/deathmatch/logic/CClientStreamer.cpp +++ b/Client/mods/deathmatch/logic/CClientStreamer.cpp @@ -53,7 +53,7 @@ CClientStreamer::~CClientStreamer() m_ExtraRows.clear(); } -void CClientStreamer::CreateSectors(list* pList, CVector2D& vecSize, CVector2D& vecBottomLeft, CVector2D& vecTopRight) +void CClientStreamer::CreateSectors(list* pList, const CVector2D& vecSize, const CVector2D& vecBottomLeft, const CVector2D& vecTopRight) { // Creates our sectors within rows, filling up our rectangle, connecting each sector and row CClientStreamSector * pCurrent = NULL, *pPrevious = NULL, *pPreviousRowSector = NULL; diff --git a/Client/mods/deathmatch/logic/CClientStreamer.h b/Client/mods/deathmatch/logic/CClientStreamer.h index da69029387..27fd0fc706 100644 --- a/Client/mods/deathmatch/logic/CClientStreamer.h +++ b/Client/mods/deathmatch/logic/CClientStreamer.h @@ -36,7 +36,7 @@ class CClientStreamer std::list::iterator ActiveElementsEnd() { return m_ActiveElements.end(); } private: - void CreateSectors(std::list* pList, CVector2D& vecSize, CVector2D& vecBottomLeft, CVector2D& vecTopRight); + void CreateSectors(std::list* pList, const CVector2D& vecSize, const CVector2D& vecBottomLeft, const CVector2D& vecTopRight); void ConnectSector(CClientStreamSector* pSector); void ConnectRow(CClientStreamSectorRow* pRow); diff --git a/Client/mods/deathmatch/logic/CClientWeapon.cpp b/Client/mods/deathmatch/logic/CClientWeapon.cpp index af068f5e01..92fb7422a5 100644 --- a/Client/mods/deathmatch/logic/CClientWeapon.cpp +++ b/Client/mods/deathmatch/logic/CClientWeapon.cpp @@ -680,7 +680,7 @@ void CClientWeapon::DoGunShells(CVector vecOrigin, CVector vecDirection) // Note: Nozzle flare lags behind attached object if it is moving, but we can't set attached entity here as it will crash if not a ped g_pGame->GetFx()->TriggerGunshot(NULL, vecOrigin, vecDirection, true); - m_pWeapon->AddGunshell(m_pObject, &vecOrigin, &CVector2D(0, -1), fShellSize); + m_pWeapon->AddGunshell(m_pObject, vecOrigin, CVector2D(0, -1), fShellSize); } if (m_Type != WEAPONTYPE_MINIGUN) { diff --git a/Client/mods/deathmatch/logic/CServerIdManager.cpp b/Client/mods/deathmatch/logic/CServerIdManager.cpp index d8fc1d0ba8..2c7349b99b 100644 --- a/Client/mods/deathmatch/logic/CServerIdManager.cpp +++ b/Client/mods/deathmatch/logic/CServerIdManager.cpp @@ -266,7 +266,7 @@ SString CServerIdManagerImpl::GetConnectionPrivateDirectory(bool bPreviousVer) // If ServerId is invalid, use the temp dir if (strServerId.length() < 10) - return bPreviousVer ? "" : m_strTempErrorDir; + return bPreviousVer ? "" : m_strTempErrorDir.c_str(); // Otherwise fetch the server unique dir const CServerIdInfo& info = GetServerIdInfo(strServerId); diff --git a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp index 317de7f16d..3f48d1b29a 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp @@ -131,7 +131,7 @@ CLuaTimer* CLuaTimerManager::AddTimer(const CLuaFunctionRef& iLuaFunction, CTick { // Check for the minimum interval if (llTimeDelay.ToLongLong() < LUA_TIMER_MIN_INTERVAL) - return NULL; + return nullptr; if (VERIFY_FUNCTION(iLuaFunction)) { @@ -144,5 +144,5 @@ CLuaTimer* CLuaTimerManager::AddTimer(const CLuaFunctionRef& iLuaFunction, CTick return pLuaTimer; } - return false; + return nullptr; } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp index f45efbf09c..b00be47073 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp @@ -40,7 +40,7 @@ CClientBuilding* CLuaBuildingDefs::CreateBuilding(lua_State* const luaVM, uint16 // Get the resource we belong to CResource* pResource = pLuaMain->GetResource(); if (!pResource) - return false; + return nullptr; if (!CClientBuildingManager::IsValidModel(modelId)) throw std::invalid_argument("Invalid building model id"); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaDefs.h index 3f3c18386f..f6882eefea 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDefs.h @@ -9,6 +9,10 @@ *****************************************************************************/ #pragma once + +#include "SharedUtil.Template.h" +#include "lua/CLuaOverloadParser.h" + #define LUA_DECLARE(x) static int x ( lua_State * luaVM ); #define LUA_DECLARE_OOP(x) LUA_DECLARE(x) LUA_DECLARE(OOP_##x) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp index e30b7f3ba2..e0d6b5c798 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp @@ -1195,7 +1195,7 @@ int CLuaDrawingDefs::DxCreateShader(lua_State* luaVM) // Replace any path in the error message with our own one SString strRootPathWithoutResource = strRootPath.Left(strRootPath.TrimEnd("\\").length() - SStringX(pFileResource->GetName()).length()); strStatus = strStatus.ReplaceI(strRootPathWithoutResource, ""); - argStream.SetCustomError(bIsRawData ? "raw data" : strFile, strStatus); + argStream.SetCustomError(bIsRawData ? "raw data" : strFile.c_str(), strStatus); m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); lua_pushboolean(luaVM, false); return 1; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index db3a25f4c3..9270524460 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -320,12 +320,12 @@ int CLuaEngineDefs::EngineLoadCOL(lua_State* luaVM) { // Delete it again. We failed delete pCol; - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Error loading COL"); + argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Error loading COL"); } } else { - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Bad file path"); + argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Bad file path"); } } } @@ -392,12 +392,12 @@ int CLuaEngineDefs::EngineLoadDFF(lua_State* luaVM) { // Delete it again delete pDFF; - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Error loading DFF"); + argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Error loading DFF"); } } else { - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Bad file path"); + argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Bad file path"); } } } @@ -466,11 +466,11 @@ int CLuaEngineDefs::EngineLoadTXD(lua_State* luaVM) { // Delete it again delete pTXD; - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Error loading TXD"); + argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Error loading TXD"); } } else - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Bad file path"); + argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Bad file path"); } } } @@ -531,12 +531,12 @@ int CLuaEngineDefs::EngineLoadIFP(lua_State* luaVM) } else { - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Error loading IFP"); + argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Error loading IFP"); } } else { - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Bad file path"); + argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Bad file path"); } } } @@ -650,7 +650,7 @@ CClientIMG* CLuaEngineDefs::EngineLoadIMG(lua_State* const luaVM, std::string st // Get the resource we belong to CResource* pResource = pLuaMain->GetResource(); if (!pResource) - return false; + return nullptr; std::string strFullPath; diff --git a/Client/mods/deathmatch/premake5.lua b/Client/mods/deathmatch/premake5.lua index c8fdfd2ed8..f3aa19d151 100644 --- a/Client/mods/deathmatch/premake5.lua +++ b/Client/mods/deathmatch/premake5.lua @@ -4,6 +4,8 @@ project "Client Deathmatch" targetname "client" targetdir(buildpath("mods/deathmatch")) + cppdialect "C++20" + pchheader "StdInc.h" pchsource "StdInc.cpp" diff --git a/Client/sdk/game/CModelInfo.h b/Client/sdk/game/CModelInfo.h index 440f079be6..cab25566f4 100644 --- a/Client/sdk/game/CModelInfo.h +++ b/Client/sdk/game/CModelInfo.h @@ -229,7 +229,7 @@ class CModelInfo // Call this to make sure the custom vehicle models are being used after a load. virtual void MakeCustomModel() = 0; virtual RwObject* GetRwObject() = 0; - virtual void MakePedModel(char* szTexture) = 0; + virtual void MakePedModel(const char* szTexture) = 0; virtual void MakeObjectModel(unsigned short usBaseID) = 0; virtual void MakeVehicleAutomobile(unsigned short usBaseID) = 0; virtual void MakeTimedObjectModel(unsigned short usBaseID) = 0; diff --git a/Client/sdk/game/CWeapon.h b/Client/sdk/game/CWeapon.h index 3dbb96c642..527071909f 100644 --- a/Client/sdk/game/CWeapon.h +++ b/Client/sdk/game/CWeapon.h @@ -45,7 +45,7 @@ class CWeapon virtual void Initialize(eWeaponType type, unsigned int uiAmmo, CPed* pPed) = 0; virtual void Update(CPed* pPed) = 0; virtual bool Fire(CEntity* pFiringEntity, CVector* pvecOrigin, CVector* pvecOffset, CEntity* pTargetEntity, CVector* pvec_1, CVector* pvec2) = 0; - virtual void AddGunshell(CEntity* pFiringEntity, CVector* pvecOrigin, CVector2D* pvecDirection, float fSize) = 0; + virtual void AddGunshell(CEntity* pFiringEntity, const CVector& vecOrigin, const CVector2D& vecDirection, float fSize) = 0; virtual void DoBulletImpact(CEntity* pFiringEntity, CEntitySAInterface* pEntityInterface, CVector* pvecOrigin, CVector* pvecTarget, CColPoint* pColPoint, int i_1) = 0; virtual unsigned char GenerateDamageEvent(CPed* pPed, CEntity* pResponsible, eWeaponType weaponType, int iDamagePerHit, ePedPieceTypes hitZone, diff --git a/Server/core/premake5.lua b/Server/core/premake5.lua index 7e52214323..11fb2ac5b7 100644 --- a/Server/core/premake5.lua +++ b/Server/core/premake5.lua @@ -4,6 +4,8 @@ project "Core" targetname "core" targetdir(buildpath("server")) + cppdialect "C++17" + filter "system:windows" includedirs { "../../vendor/sparsehash/current/src/windows" } linkoptions { "/SAFESEH:NO" } diff --git a/Server/launcher/premake5.lua b/Server/launcher/premake5.lua index 3482a3c92b..f14ff994b7 100644 --- a/Server/launcher/premake5.lua +++ b/Server/launcher/premake5.lua @@ -4,6 +4,8 @@ project "Launcher" targetdir(buildpath("server")) targetname "mta-server" + cppdialect "C++17" + includedirs { "../../Shared/sdk", "../sdk", diff --git a/Server/mods/deathmatch/premake5.lua b/Server/mods/deathmatch/premake5.lua index ddecdfb179..4cd3aa7a03 100644 --- a/Server/mods/deathmatch/premake5.lua +++ b/Server/mods/deathmatch/premake5.lua @@ -4,6 +4,8 @@ project "Deathmatch" targetname "deathmatch" targetdir(buildpath("server/mods/deathmatch")) + cppdialect "C++17" + pchheader "StdInc.h" pchsource "StdInc.cpp" diff --git a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp index 0b5847fa09..86fe697b75 100644 --- a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp +++ b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp @@ -263,7 +263,7 @@ int CLuaUtilDefs::GetUserdataType(lua_State* luaVM) else if (iArgument == LUA_TUSERDATA) strType = GetUserDataClassName(*((void**)lua_touserdata(luaVM, 1)), luaVM, false); - strType = strType.empty() ? "userdata" : strType; + strType = strType.empty() ? "userdata" : strType.c_str(); lua_pushstring(luaVM, strType.c_str()); return 1; diff --git a/Shared/sdk/SString.h b/Shared/sdk/SString.h index 00c57d0c1e..f1abc1ec83 100644 --- a/Shared/sdk/SString.h +++ b/Shared/sdk/SString.h @@ -150,15 +150,15 @@ class TSplitString : public std::vector if (ulPos == STRING_TYPE::npos || (uiMaxAmount > 0 && uiMaxAmount <= this->size() + 1)) { if (ulCurrentPoint <= strInput.length()) - push_back(&buffer[ulCurrentPoint]); + this->push_back(&buffer[ulCurrentPoint]); break; } - push_back(&buffer[ulCurrentPoint]); + this->push_back(&buffer[ulCurrentPoint]); buffer[ulPos] = 0; ulCurrentPoint = ulPos + strDelim.length(); } while (this->size() < uiMinAmount) - push_back(&buffer[iInputLength]); + this->push_back(&buffer[iInputLength]); } protected: diff --git a/Shared/sdk/SharedUtil.Logging.hpp b/Shared/sdk/SharedUtil.Logging.hpp index f98b3bbdf6..df25f19d6a 100644 --- a/Shared/sdk/SharedUtil.Logging.hpp +++ b/Shared/sdk/SharedUtil.Logging.hpp @@ -167,8 +167,8 @@ void SharedUtil::CycleFile(const SString& strPathFilename, uint uiCycleThreshKB, // Rename older files .1 .2 etc uint uiNew = uiNumBackups - 1 - i; uint uiOld = uiNumBackups - i; - SString strFilenameNewer = strPathFilename + (uiNew ? SString(".%d", uiNew) : ""); - SString strFilenameOlder = strPathFilename + (uiOld ? SString(".%d", uiOld) : ""); + SString strFilenameNewer = strPathFilename + (uiNew ? SString(".%d", uiNew).c_str() : ""); + SString strFilenameOlder = strPathFilename + (uiOld ? SString(".%d", uiOld).c_str() : ""); FileDelete(strFilenameOlder); FileRename(strFilenameNewer, strFilenameOlder); diff --git a/Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp b/Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp index cbfdc75251..d86d362851 100644 --- a/Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp +++ b/Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp @@ -107,7 +107,7 @@ namespace SharedUtil { #ifdef UTF8_FILE_HOOKS_PERSONALITY_Core static SString gtaDirCP = ToACP(g_gtaDirectory); - static SString gtaDirUTF8 = g_gtaDirectory.u8string(); + static SString gtaDirUTF8 = g_gtaDirectory.string(); if (strOriginal.BeginsWithI(gtaDirCP)) { SString tail = strOriginal.SubStr(gtaDirCP.length()); diff --git a/vendor/sparsehash/src/sparsehash/internal/hashtable-common.h b/vendor/sparsehash/src/sparsehash/internal/hashtable-common.h index bac2b88235..e37d2a0283 100644 --- a/vendor/sparsehash/src/sparsehash/internal/hashtable-common.h +++ b/vendor/sparsehash/src/sparsehash/internal/hashtable-common.h @@ -51,7 +51,7 @@ _START_GOOGLE_NAMESPACE_ template struct SparsehashCompileAssert { }; #define SPARSEHASH_COMPILE_ASSERT(expr, msg) \ - __attribute__((unused)) typedef SparsehashCompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] + [[maybe_unused]] typedef SparsehashCompileAssert msg[expr ? 1 : -1] namespace sparsehash_internal { @@ -163,7 +163,7 @@ bool read_bigendian_number(INPUT* fp, IntType* value, size_t length) { *value = 0; unsigned char byte; // We require IntType to be unsigned or else the shifting gets all screwy. - SPARSEHASH_COMPILE_ASSERT(static_cast(-1) > static_cast(0), + SPARSEHASH_COMPILE_ASSERT(std::is_unsigned_v, serializing_int_requires_an_unsigned_type); for (size_t i = 0; i < length; ++i) { if (!read_data(fp, &byte, sizeof(byte))) return false; @@ -176,7 +176,7 @@ template bool write_bigendian_number(OUTPUT* fp, IntType value, size_t length) { unsigned char byte; // We require IntType to be unsigned or else the shifting gets all screwy. - SPARSEHASH_COMPILE_ASSERT(static_cast(-1) > static_cast(0), + SPARSEHASH_COMPILE_ASSERT(std::is_unsigned_v, serializing_int_requires_an_unsigned_type); for (size_t i = 0; i < length; ++i) { byte = (sizeof(value) <= length-1 - i) From 1f10a855584af5e25482cd5586be1c4733d32124 Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Fri, 9 Aug 2024 17:22:59 +0300 Subject: [PATCH 02/19] Fixed part 1 --- Client/core/CVersionUpdater.Util.hpp | 4 +-- Client/loader/Install.Manifest.cpp | 2 +- Client/loader/Utils.cpp | 2 +- Client/mods/deathmatch/logic/CAntiCheat.cpp | 4 +-- Client/mods/deathmatch/logic/CClientGame.cpp | 3 ++- .../logic/CClientPerfStat.LuaMemory.cpp | 26 +++++++++---------- .../logic/CClientPerfStat.LuaTiming.cpp | 6 ++--- .../deathmatch/logic/CServerIdManager.cpp | 4 +-- .../logic/luadefs/CLuaDrawingDefs.cpp | 2 +- .../logic/luadefs/CLuaEngineDefs.cpp | 16 ++++++------ Server/core/premake5.lua | 2 -- Server/launcher/premake5.lua | 2 -- Server/mods/deathmatch/premake5.lua | 2 -- .../deathmatch/logic/luadefs/CLuaUtilDefs.cpp | 4 +-- 14 files changed, 37 insertions(+), 42 deletions(-) diff --git a/Client/core/CVersionUpdater.Util.hpp b/Client/core/CVersionUpdater.Util.hpp index 38976e2830..f54637b47e 100644 --- a/Client/core/CVersionUpdater.Util.hpp +++ b/Client/core/CVersionUpdater.Util.hpp @@ -391,7 +391,7 @@ namespace SString GetAttribute(const SString& strName) const { const SString* pValue = MapFind(attributeMap, strName); - return pValue ? (*pValue).c_str() : ""; + return pValue ? *pValue : SStringX(""); } void SetAttribute(const SString& strName, const SString& strValue) { MapSet(attributeMap, strName, strValue); } }; @@ -606,7 +606,7 @@ namespace SaveReportSettings(); } - SString GetFilter() const { return strFilter != "" ? strFilter.c_str() : "+all"; } + SString GetFilter() const { return !strFilter.empty() ? strFilter : SStringX("+all"); } int GetMinSize() const { return iMinSize; } diff --git a/Client/loader/Install.Manifest.cpp b/Client/loader/Install.Manifest.cpp index ada7dc4421..188cd0c459 100644 --- a/Client/loader/Install.Manifest.cpp +++ b/Client/loader/Install.Manifest.cpp @@ -63,7 +63,7 @@ static void ParseManifestVersion1(std::ifstream& manifest, std::vector(strchr(pathList[0].c_str(), '?')) > 0) + if (strchr(pathList[0].c_str(), '?') != nullptr) return GAME_PATH_UNICODE_CHARS; } diff --git a/Client/mods/deathmatch/logic/CAntiCheat.cpp b/Client/mods/deathmatch/logic/CAntiCheat.cpp index bc3f80a2d3..a6c3b5a701 100644 --- a/Client/mods/deathmatch/logic/CAntiCheat.cpp +++ b/Client/mods/deathmatch/logic/CAntiCheat.cpp @@ -100,9 +100,9 @@ SString CAntiCheat::GetInfo(const SString& acInfo, const SString& sdInfo) SString strAllowedFiles = "None"; SString strVerifyFiles = acInfo.SplitLeft(","); - SString strEnabledSD = sdInfo == "" ? "None" : sdInfo.c_str(); + SString strEnabledSD = sdInfo.empty() ? SStringX("None") : sdInfo; SString strDisabledAC = acInfo.SplitRight(","); - strDisabledAC = strDisabledAC == "" ? "None" : strDisabledAC.c_str(); + strDisabledAC = strDisabledAC.empty() ? SStringX("None") : strDisabledAC; int iVerifyFiles = atoi(strVerifyFiles); if (iVerifyFiles == 0) diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index 7c536e94d6..dc976f5243 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -1019,7 +1019,8 @@ void CClientGame::DoPulsePostFrame() bool useZoneName = true; const eClientVehicleType vehicleType = (pVehicle) ? CClientVehicleManager::GetVehicleType(pVehicle->GetModel()) : CLIENTVEHICLE_NONE; - std::string discordState = (pVehicle) ? g_vehicleTypePrefixes.at(vehicleType).c_str() : _("Walking around ").c_str(); + + std::string discordState = pVehicle ? g_vehicleTypePrefixes.at(vehicleType) : _("Walking around "); if (task && task->IsValid()) { diff --git a/Client/mods/deathmatch/logic/CClientPerfStat.LuaMemory.cpp b/Client/mods/deathmatch/logic/CClientPerfStat.LuaMemory.cpp index 32c64f3abc..94676edda2 100644 --- a/Client/mods/deathmatch/logic/CClientPerfStat.LuaMemory.cpp +++ b/Client/mods/deathmatch/logic/CClientPerfStat.LuaMemory.cpp @@ -297,15 +297,15 @@ void CClientPerfStatLuaMemoryImpl::GetLuaMemoryStats(CClientPerfStatResult* pRes int WebBrowserCount = g_pClientGame->GetManager()->GetRenderElementManager()->GetWebBrowserCount(); int VectorGraphicCount = g_pClientGame->GetManager()->GetRenderElementManager()->GetVectorGraphicCount(); TextItemCount = std::max(TextItemCount - 4, 0); // Remove count for radar items - row[c++] = !TextItemCount ? "-" : SString("%d", TextItemCount).c_str(); - row[c++] = !DxFontCount ? "-" : SString("%d", DxFontCount).c_str(); - row[c++] = !GuiFontCount ? "-" : SString("%d", GuiFontCount).c_str(); - row[c++] = !TextureCount ? "-" : SString("%d", TextureCount).c_str(); - row[c++] = !ShaderCount ? "-" : SString("%d", ShaderCount).c_str(); - row[c++] = !RenderTargetCount ? "-" : SString("%d", RenderTargetCount).c_str(); - row[c++] = !ScreenSourceCount ? "-" : SString("%d", ScreenSourceCount).c_str(); - row[c++] = !WebBrowserCount ? "-" : SString("%d", WebBrowserCount).c_str(); - row[c++] = !VectorGraphicCount ? "-" : SString("%d", VectorGraphicCount).c_str(); + row[c++] = !TextItemCount ? "-" : std::to_string(TextItemCount); + row[c++] = !DxFontCount ? "-" : std::to_string(DxFontCount); + row[c++] = !GuiFontCount ? "-" : std::to_string(GuiFontCount); + row[c++] = !TextureCount ? "-" : std::to_string(TextureCount); + row[c++] = !ShaderCount ? "-" : std::to_string(ShaderCount); + row[c++] = !RenderTargetCount ? "-" : std::to_string(RenderTargetCount); + row[c++] = !ScreenSourceCount ? "-" : std::to_string(ScreenSourceCount); + row[c++] = !WebBrowserCount ? "-" : std::to_string(WebBrowserCount); + row[c++] = !VectorGraphicCount ? "-" : std::to_string(VectorGraphicCount); } // For each VM @@ -333,9 +333,9 @@ void CClientPerfStatLuaMemoryImpl::GetLuaMemoryStats(CClientPerfStatResult* pRes row[c++] = SString("%d KB", LuaMainMemory.Current); row[c++] = SString("%d KB", LuaMainMemory.Max); - row[c++] = !LuaMainMemory.OpenXMLFiles ? "-" : SString("%d", LuaMainMemory.OpenXMLFiles).c_str(); - row[c++] = !LuaMainMemory.Refs ? "-" : SString("%d", LuaMainMemory.Refs).c_str(); - row[c++] = !LuaMainMemory.TimerCount ? "-" : SString("%d", LuaMainMemory.TimerCount).c_str(); - row[c++] = !LuaMainMemory.ElementCount ? "-" : SString("%d", LuaMainMemory.ElementCount).c_str(); + row[c++] = !LuaMainMemory.OpenXMLFiles ? "-" : std::to_string(LuaMainMemory.OpenXMLFiles); + row[c++] = !LuaMainMemory.Refs ? "-" : std::to_string(LuaMainMemory.Refs); + row[c++] = !LuaMainMemory.TimerCount ? "-" : std::to_string(LuaMainMemory.TimerCount); + row[c++] = !LuaMainMemory.ElementCount ? "-" : std::to_string(LuaMainMemory.ElementCount); } } diff --git a/Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp b/Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp index e46bced15a..9b95fb1f27 100644 --- a/Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp +++ b/Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp @@ -430,9 +430,9 @@ void CClientPerfStatLuaTimingImpl::OutputTimingBlock(CClientPerfStatResult* pRes double total_p = total_s / double(threshList[i]) * 100; - row[c++] = total_p > 0.005 ? SString("%2.2f%%", total_p).c_str() : "-"; - row[c++] = total_s > 0.0005 ? SString("%2.3f", total_s).c_str() : "-"; - row[c++] = p->prev.calls > 0 ? SString("%d", p->prev.calls).c_str() : ""; + row[c++] = total_p > 0.005 ? SString("%2.2f%%", total_p) : SStringX("-"); + row[c++] = total_s > 0.0005 ? SString("%2.3f", total_s) : SStringX("-"); + row[c++] = p->prev.calls > 0 ? SString("%d", p->prev.calls) : SStringX(""); row[c++] = avg_s > 0.0005 ? SString("%2.3f", avg_s).c_str() : bSubBlock ? "-" : ""; row[c++] = max_s > 0.0005 ? SString("%2.3f", max_s).c_str() : bSubBlock ? "-" : ""; } diff --git a/Client/mods/deathmatch/logic/CServerIdManager.cpp b/Client/mods/deathmatch/logic/CServerIdManager.cpp index 2c7349b99b..3836051913 100644 --- a/Client/mods/deathmatch/logic/CServerIdManager.cpp +++ b/Client/mods/deathmatch/logic/CServerIdManager.cpp @@ -70,7 +70,7 @@ class CServerIdManagerImpl : public CServerIdManager bool m_bClearedDefaultDirectory; std::map m_ServerIdMap; SString m_strServerIdLookupBaseDir; - SString m_strTempErrorDir; + std::string m_strTempErrorDir; }; /////////////////////////////////////////////////////////////// @@ -266,7 +266,7 @@ SString CServerIdManagerImpl::GetConnectionPrivateDirectory(bool bPreviousVer) // If ServerId is invalid, use the temp dir if (strServerId.length() < 10) - return bPreviousVer ? "" : m_strTempErrorDir.c_str(); + return bPreviousVer ? "" : m_strTempErrorDir; // Otherwise fetch the server unique dir const CServerIdInfo& info = GetServerIdInfo(strServerId); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp index e0d6b5c798..0b22602949 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp @@ -1195,7 +1195,7 @@ int CLuaDrawingDefs::DxCreateShader(lua_State* luaVM) // Replace any path in the error message with our own one SString strRootPathWithoutResource = strRootPath.Left(strRootPath.TrimEnd("\\").length() - SStringX(pFileResource->GetName()).length()); strStatus = strStatus.ReplaceI(strRootPathWithoutResource, ""); - argStream.SetCustomError(bIsRawData ? "raw data" : strFile.c_str(), strStatus); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : strFile, strStatus); m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); lua_pushboolean(luaVM, false); return 1; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index 9270524460..b699d0321e 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -320,12 +320,12 @@ int CLuaEngineDefs::EngineLoadCOL(lua_State* luaVM) { // Delete it again. We failed delete pCol; - argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Error loading COL"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Error loading COL"); } } else { - argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Bad file path"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Bad file path"); } } } @@ -392,12 +392,12 @@ int CLuaEngineDefs::EngineLoadDFF(lua_State* luaVM) { // Delete it again delete pDFF; - argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Error loading DFF"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Error loading DFF"); } } else { - argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Bad file path"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Bad file path"); } } } @@ -466,11 +466,11 @@ int CLuaEngineDefs::EngineLoadTXD(lua_State* luaVM) { // Delete it again delete pTXD; - argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Error loading TXD"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Error loading TXD"); } } else - argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Bad file path"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Bad file path"); } } } @@ -531,12 +531,12 @@ int CLuaEngineDefs::EngineLoadIFP(lua_State* luaVM) } else { - argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Error loading IFP"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Error loading IFP"); } } else { - argStream.SetCustomError(bIsRawData ? "raw data" : input.c_str(), "Bad file path"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Bad file path"); } } } diff --git a/Server/core/premake5.lua b/Server/core/premake5.lua index 11fb2ac5b7..7e52214323 100644 --- a/Server/core/premake5.lua +++ b/Server/core/premake5.lua @@ -4,8 +4,6 @@ project "Core" targetname "core" targetdir(buildpath("server")) - cppdialect "C++17" - filter "system:windows" includedirs { "../../vendor/sparsehash/current/src/windows" } linkoptions { "/SAFESEH:NO" } diff --git a/Server/launcher/premake5.lua b/Server/launcher/premake5.lua index f14ff994b7..3482a3c92b 100644 --- a/Server/launcher/premake5.lua +++ b/Server/launcher/premake5.lua @@ -4,8 +4,6 @@ project "Launcher" targetdir(buildpath("server")) targetname "mta-server" - cppdialect "C++17" - includedirs { "../../Shared/sdk", "../sdk", diff --git a/Server/mods/deathmatch/premake5.lua b/Server/mods/deathmatch/premake5.lua index 4cd3aa7a03..ddecdfb179 100644 --- a/Server/mods/deathmatch/premake5.lua +++ b/Server/mods/deathmatch/premake5.lua @@ -4,8 +4,6 @@ project "Deathmatch" targetname "deathmatch" targetdir(buildpath("server/mods/deathmatch")) - cppdialect "C++17" - pchheader "StdInc.h" pchsource "StdInc.cpp" diff --git a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp index 86fe697b75..f5d0ceb74e 100644 --- a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp +++ b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp @@ -257,13 +257,13 @@ int CLuaUtilDefs::GetUserdataType(lua_State* luaVM) if (argStream.NextIsUserData()) { - SString strType; + std::string strType; if (iArgument == LUA_TLIGHTUSERDATA) strType = GetUserDataClassName(lua_touserdata(luaVM, 1), luaVM, false); else if (iArgument == LUA_TUSERDATA) strType = GetUserDataClassName(*((void**)lua_touserdata(luaVM, 1)), luaVM, false); - strType = strType.empty() ? "userdata" : strType.c_str(); + strType = strType.empty() ? "userdata" : strType; lua_pushstring(luaVM, strType.c_str()); return 1; From 79b76efefc14c87fd393668f1fbb2e6b6a7663da Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Fri, 9 Aug 2024 18:44:08 +0300 Subject: [PATCH 03/19] Fixed part 2 --- Client/core/CCommands.cpp | 21 +++++++-------------- Shared/sdk/SharedUtil.Logging.hpp | 4 ++-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Client/core/CCommands.cpp b/Client/core/CCommands.cpp index c729a41c14..6e81cb209b 100644 --- a/Client/core/CCommands.cpp +++ b/Client/core/CCommands.cpp @@ -84,13 +84,9 @@ bool CCommands::Execute(const char* szCommandLine) bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool bHandleRemotely, bool bIsScriptedBind) { // Copy szParametersIn so the contents can be changed - const char* szParameters = NULL; + char* szParameters = nullptr; if (szParametersIn) - { - size_t sizeParameters = strlen(szParametersIn) + 1; - szParameters = static_cast(alloca(sizeParameters)); - memcpy(const_cast(szParameters), szParametersIn, sizeParameters); - } + std::strcpy(szParameters, szParametersIn); // HACK: if its a 'chatboxsay' command, use the next parameter // Is the command "say" and the arguments start with /? (command comes from the chatbox) @@ -108,15 +104,12 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool // Split it into command and arguments szCommand = strtok(szBuffer, " "); - szParameters = strtok(NULL, "\0"); - if (szCommand == NULL) - { + szParameters = strtok(nullptr, "\0"); + if (!szCommand) return false; - } - if (szParameters == NULL) - { - szParameters = ""; - } + + if (!szParameters) + std::strcpy(szParameters, ""); } } else diff --git a/Shared/sdk/SharedUtil.Logging.hpp b/Shared/sdk/SharedUtil.Logging.hpp index df25f19d6a..7f623b3f54 100644 --- a/Shared/sdk/SharedUtil.Logging.hpp +++ b/Shared/sdk/SharedUtil.Logging.hpp @@ -167,8 +167,8 @@ void SharedUtil::CycleFile(const SString& strPathFilename, uint uiCycleThreshKB, // Rename older files .1 .2 etc uint uiNew = uiNumBackups - 1 - i; uint uiOld = uiNumBackups - i; - SString strFilenameNewer = strPathFilename + (uiNew ? SString(".%d", uiNew).c_str() : ""); - SString strFilenameOlder = strPathFilename + (uiOld ? SString(".%d", uiOld).c_str() : ""); + SString strFilenameNewer = strPathFilename + (uiNew ? SString(".%d", uiNew) : SStringX("")); + SString strFilenameOlder = strPathFilename + (uiOld ? SString(".%d", uiOld) : SStringX("")); FileDelete(strFilenameOlder); FileRename(strFilenameNewer, strFilenameOlder); From d59efc1ea417aa2787ed8e06982b3e3970c961e1 Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Fri, 9 Aug 2024 20:50:17 +0300 Subject: [PATCH 04/19] Fix crash --- Client/core/CCommands.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Client/core/CCommands.cpp b/Client/core/CCommands.cpp index 6e81cb209b..83fbe4b82f 100644 --- a/Client/core/CCommands.cpp +++ b/Client/core/CCommands.cpp @@ -86,7 +86,10 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool // Copy szParametersIn so the contents can be changed char* szParameters = nullptr; if (szParametersIn) + { + szParameters = static_cast(alloca(strlen(szParametersIn) + 1)); std::strcpy(szParameters, szParametersIn); + } // HACK: if its a 'chatboxsay' command, use the next parameter // Is the command "say" and the arguments start with /? (command comes from the chatbox) From 5cd6fc3560eee0543c165d1c1b17957dc21297bc Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Sat, 10 Aug 2024 00:45:36 +0300 Subject: [PATCH 05/19] Fast fix by TracerDS --- Client/core/CCommands.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Client/core/CCommands.cpp b/Client/core/CCommands.cpp index 83fbe4b82f..4216161a1b 100644 --- a/Client/core/CCommands.cpp +++ b/Client/core/CCommands.cpp @@ -87,7 +87,7 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool char* szParameters = nullptr; if (szParametersIn) { - szParameters = static_cast(alloca(strlen(szParametersIn) + 1)); + szParameters = new char[strlen(szParametersIn) + 1]; std::strcpy(szParameters, szParametersIn); } @@ -177,6 +177,10 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool ss << key << " = " << val; val = ss.str(); CCore::GetSingleton().GetConsole()->Print(val.c_str()); + + if (szParameters) + delete[] szParameters; + return true; } } @@ -205,7 +209,12 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool { bool bAllowScriptedBind = (!pEntry || pEntry->bAllowScriptedBind); if (m_pfnExecuteHandler(szCommand, szParameters, bHandleRemotely, (pEntry != NULL), bIsScriptedBind, bAllowScriptedBind)) + { + if (szParameters) + delete[] szParameters; + return true; + } } // Unknown command From 1d8c1d7d1c3bc948312bb169c129145ef6c53513 Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Sat, 10 Aug 2024 11:29:15 +0300 Subject: [PATCH 06/19] Fixed by Tederis --- Client/core/CCommands.cpp | 45 +++++++++---------- Client/core/CVersionUpdater.Util.hpp | 2 +- .../logic/CClientPerfStat.LuaTiming.cpp | 2 +- Shared/sdk/SharedUtil.Logging.hpp | 5 ++- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Client/core/CCommands.cpp b/Client/core/CCommands.cpp index 4216161a1b..6cf0c9635a 100644 --- a/Client/core/CCommands.cpp +++ b/Client/core/CCommands.cpp @@ -84,11 +84,11 @@ bool CCommands::Execute(const char* szCommandLine) bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool bHandleRemotely, bool bIsScriptedBind) { // Copy szParametersIn so the contents can be changed - char* szParameters = nullptr; + std::unique_ptr szParameters = nullptr; if (szParametersIn) { - szParameters = new char[strlen(szParametersIn) + 1]; - std::strcpy(szParameters, szParametersIn); + szParameters = std::make_unique(strlen(szParametersIn) + 1); + std::strcpy(szParameters.get(), szParametersIn); } // HACK: if its a 'chatboxsay' command, use the next parameter @@ -98,21 +98,29 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool if (szParameters) { // His line starts with '/'? - if (*szParameters == '/') + if (szParameters[0] == '/') { // Copy the characters after the slash to the 0 terminator to a seperate buffer char szBuffer[256]; - strncpy(szBuffer, szParameters + 1, 256); + strncpy(szBuffer, szParameters.get() + 1, 256); szBuffer[255] = 0; // Split it into command and arguments szCommand = strtok(szBuffer, " "); - szParameters = strtok(nullptr, "\0"); if (!szCommand) return false; - if (!szParameters) - std::strcpy(szParameters, ""); + if (char* szNewParameters = strtok(nullptr, "\0"); szNewParameters) + { + szParameters = std::make_unique(strlen(szNewParameters) + 1); + std::strcpy(szParameters.get(), szNewParameters); + } + else + { + // Åñëè íåò ïàðàìåòðîâ, ñîçäàåì ïóñòóþ ñòðîêó + szParameters = std::make_unique(1); + szParameters[0] = '\0'; + } } } else @@ -128,12 +136,12 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool { // Execute it if (!bIsScriptedBind || pEntry->bAllowScriptedBind) - ExecuteHandler(pEntry->pfnCmdFunc, szParameters); + ExecuteHandler(pEntry->pfnCmdFunc, szParameters.get()); } } // Recompose the original command text - std::string val = std::string(szCommand) + " " + std::string(szParameters ? szParameters : ""); + std::string val = std::string(szCommand) + " " + std::string(szParameters ? szParameters.get() : ""); // Is it a cvar? (syntax: cvar[ = value]) { @@ -177,10 +185,6 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool ss << key << " = " << val; val = ss.str(); CCore::GetSingleton().GetConsole()->Print(val.c_str()); - - if (szParameters) - delete[] szParameters; - return true; } } @@ -189,13 +193,13 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool bool bIsNickCommand = !stricmp(szCommand, "nick"); if (bIsNickCommand && szParameters && !bIsScriptedBind) { - if (CCore::GetSingleton().IsValidNick(szParameters)) + if (CCore::GetSingleton().IsValidNick(szParameters.get())) { - CVARS_SET("nick", std::string(szParameters)); + CVARS_SET("nick", std::string(szParameters.get())); if (!CCore::GetSingleton().IsConnected()) { - CCore::GetSingleton().GetConsole()->Printf("nick: You are now known as %s", szParameters); + CCore::GetSingleton().GetConsole()->Printf("nick: You are now known as %s", szParameters.get()); } } else if (!CCore::GetSingleton().IsConnected()) @@ -208,13 +212,8 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool if (m_pfnExecuteHandler) { bool bAllowScriptedBind = (!pEntry || pEntry->bAllowScriptedBind); - if (m_pfnExecuteHandler(szCommand, szParameters, bHandleRemotely, (pEntry != NULL), bIsScriptedBind, bAllowScriptedBind)) - { - if (szParameters) - delete[] szParameters; - + if (m_pfnExecuteHandler(szCommand, szParameters.get(), bHandleRemotely, (pEntry != NULL), bIsScriptedBind, bAllowScriptedBind)) return true; - } } // Unknown command diff --git a/Client/core/CVersionUpdater.Util.hpp b/Client/core/CVersionUpdater.Util.hpp index f54637b47e..e32e97be6d 100644 --- a/Client/core/CVersionUpdater.Util.hpp +++ b/Client/core/CVersionUpdater.Util.hpp @@ -391,7 +391,7 @@ namespace SString GetAttribute(const SString& strName) const { const SString* pValue = MapFind(attributeMap, strName); - return pValue ? *pValue : SStringX(""); + return pValue ? *pValue : SString(); } void SetAttribute(const SString& strName, const SString& strValue) { MapSet(attributeMap, strName, strValue); } }; diff --git a/Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp b/Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp index 9b95fb1f27..c3dac0bd16 100644 --- a/Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp +++ b/Client/mods/deathmatch/logic/CClientPerfStat.LuaTiming.cpp @@ -432,7 +432,7 @@ void CClientPerfStatLuaTimingImpl::OutputTimingBlock(CClientPerfStatResult* pRes row[c++] = total_p > 0.005 ? SString("%2.2f%%", total_p) : SStringX("-"); row[c++] = total_s > 0.0005 ? SString("%2.3f", total_s) : SStringX("-"); - row[c++] = p->prev.calls > 0 ? SString("%d", p->prev.calls) : SStringX(""); + row[c++] = p->prev.calls > 0 ? SString("%d", p->prev.calls) : SString(); row[c++] = avg_s > 0.0005 ? SString("%2.3f", avg_s).c_str() : bSubBlock ? "-" : ""; row[c++] = max_s > 0.0005 ? SString("%2.3f", max_s).c_str() : bSubBlock ? "-" : ""; } diff --git a/Shared/sdk/SharedUtil.Logging.hpp b/Shared/sdk/SharedUtil.Logging.hpp index 7f623b3f54..db0de5f270 100644 --- a/Shared/sdk/SharedUtil.Logging.hpp +++ b/Shared/sdk/SharedUtil.Logging.hpp @@ -167,8 +167,9 @@ void SharedUtil::CycleFile(const SString& strPathFilename, uint uiCycleThreshKB, // Rename older files .1 .2 etc uint uiNew = uiNumBackups - 1 - i; uint uiOld = uiNumBackups - i; - SString strFilenameNewer = strPathFilename + (uiNew ? SString(".%d", uiNew) : SStringX("")); - SString strFilenameOlder = strPathFilename + (uiOld ? SString(".%d", uiOld) : SStringX("")); + + SString strFilenameNewer = strPathFilename + (uiNew ? SString(".%d", uiNew) : SString()); + SString strFilenameOlder = strPathFilename + (uiOld ? SString(".%d", uiOld) : SString()); FileDelete(strFilenameOlder); FileRename(strFilenameNewer, strFilenameOlder); From 6a867884c1d1a7c7a2cd83d90e8571a0a46e308b Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Sat, 10 Aug 2024 11:31:36 +0300 Subject: [PATCH 07/19] Fast 666 --- Client/core/CCommands.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Client/core/CCommands.cpp b/Client/core/CCommands.cpp index 6cf0c9635a..090d32ae43 100644 --- a/Client/core/CCommands.cpp +++ b/Client/core/CCommands.cpp @@ -117,7 +117,6 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool } else { - // Åñëè íåò ïàðàìåòðîâ, ñîçäàåì ïóñòóþ ñòðîêó szParameters = std::make_unique(1); szParameters[0] = '\0'; } From 160909f744292409d46e93d54860a7766bcc1e69 Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Sun, 25 Aug 2024 04:08:14 +0300 Subject: [PATCH 08/19] Fixed by Botder --- Client/core/CCommands.cpp | 8 +-- Client/core/CCore.cpp | 4 +- Client/core/CFilePathTranslator.cpp | 2 +- Client/core/CModManager.cpp | 6 +- Client/core/ServerBrowser/CServerBrowser.cpp | 20 +++--- Client/core/ServerBrowser/CServerList.h | 30 ++++----- Client/game_sa/CWeaponSA.cpp | 14 ++--- Client/launch/Main.cpp | 6 +- Client/loader/CInstallManager.cpp | 19 +++--- Client/loader/Dialogs.cpp | 12 ++-- Client/loader/MainFunctions.cpp | 6 +- Client/loader/Utils.cpp | 4 +- Client/mods/deathmatch/logic/CBassAudio.cpp | 14 ++--- Client/mods/deathmatch/logic/CServer.cpp | 2 +- Shared/sdk/SharedUtil.Buffer.h | 34 ++++++++++ Shared/sdk/SharedUtil.File.h | 11 ++-- Shared/sdk/SharedUtil.File.hpp | 66 +++++++++----------- Shared/sdk/SharedUtil.SysInfo.hpp | 4 +- Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp | 58 ++++++++++------- vendor/tinygettext/dirent_win32.h | 4 +- 20 files changed, 181 insertions(+), 143 deletions(-) diff --git a/Client/core/CCommands.cpp b/Client/core/CCommands.cpp index 090d32ae43..f94ac67d27 100644 --- a/Client/core/CCommands.cpp +++ b/Client/core/CCommands.cpp @@ -101,12 +101,12 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool if (szParameters[0] == '/') { // Copy the characters after the slash to the 0 terminator to a seperate buffer - char szBuffer[256]; - strncpy(szBuffer, szParameters.get() + 1, 256); - szBuffer[255] = 0; + std::array szBuffer = {}; + strncpy(szBuffer.data(), szParameters.get() + 1, szBuffer.size() - 1); + szBuffer.back() = '\0'; // Split it into command and arguments - szCommand = strtok(szBuffer, " "); + szCommand = strtok(szBuffer.data(), " "); if (!szCommand) return false; diff --git a/Client/core/CCore.cpp b/Client/core/CCore.cpp index 6132cf7f69..880aabf931 100644 --- a/Client/core/CCore.cpp +++ b/Client/core/CCore.cpp @@ -60,13 +60,13 @@ static HMODULE WINAPI SkipDirectPlay_LoadLibraryA(LPCSTR fileName) const fs::path inLaunchDir = fs::path{FromUTF8(GetLaunchPath())} / "enbseries" / "enbhelper.dll"; if (fs::is_regular_file(inLaunchDir, ec)) - return Win32LoadLibraryA(inLaunchDir.string().c_str()); + return Win32LoadLibraryA(ToUTF8(inLaunchDir.wstring()).c_str()); // Try to load enbhelper.dll from the GTA install directory second. const fs::path inGTADir = g_gtaDirectory / "enbseries" / "enbhelper.dll"; if (fs::is_regular_file(inGTADir, ec)) - return Win32LoadLibraryA(inGTADir.string().c_str()); + return Win32LoadLibraryA(ToUTF8(inGTADir.wstring()).c_str()); return nullptr; } diff --git a/Client/core/CFilePathTranslator.cpp b/Client/core/CFilePathTranslator.cpp index ce1bb420b6..f7feebd682 100644 --- a/Client/core/CFilePathTranslator.cpp +++ b/Client/core/CFilePathTranslator.cpp @@ -80,7 +80,7 @@ void CFilePathTranslator::GetCurrentWorkingDirectory(std::string& WorkingDirecto void CFilePathTranslator::GetGTARootDirectory(std::string& ModuleRootDirOut) { - ModuleRootDirOut = g_gtaDirectory.string(); + ModuleRootDirOut = ToUTF8(g_gtaDirectory.wstring()); } void CFilePathTranslator::GetMTASARootDirectory(std::string& InstallRootDirOut) diff --git a/Client/core/CModManager.cpp b/Client/core/CModManager.cpp index d1e15b10b9..39d74e56a0 100644 --- a/Client/core/CModManager.cpp +++ b/Client/core/CModManager.cpp @@ -338,18 +338,18 @@ void CModManager::InitializeModList(const char* szModFolderPath) filePathTranslator.SetCurrentWorkingDirectory("mta"); // Create a search - hFind = FindFirstFileW(FromUTF8(strPathWildchars), &FindData); + hFind = FindFirstFileW(FromUTF8(strPathWildchars).c_str(), &FindData); // If we found a first file ... if (hFind != INVALID_HANDLE_VALUE) { // Add it to the list - VerifyAndAddEntry(szModFolderPath, ToUTF8(FindData.cFileName)); + VerifyAndAddEntry(szModFolderPath, ToUTF8(FindData.cFileName).c_str()); // Search until there aren't any files left while (FindNextFileW(hFind, &FindData) == TRUE) { - VerifyAndAddEntry(szModFolderPath, ToUTF8(FindData.cFileName)); + VerifyAndAddEntry(szModFolderPath, ToUTF8(FindData.cFileName).c_str()); } // End the search diff --git a/Client/core/ServerBrowser/CServerBrowser.cpp b/Client/core/ServerBrowser/CServerBrowser.cpp index 978b9811bd..7270ad566f 100644 --- a/Client/core/ServerBrowser/CServerBrowser.cpp +++ b/Client/core/ServerBrowser/CServerBrowser.cpp @@ -914,7 +914,7 @@ void CServerBrowser::CreateHistoryList() for (CServerListReverseIterator it = m_ServersHistory.ReverseIteratorBegin(); it != m_ServersHistory.ReverseIteratorEnd(); it++) { CServerListItem* pServer = *it; - if (pServer->strEndpoint) + if (!pServer->strEndpoint.empty()) { bEmpty = false; for (unsigned int i = 0; i < SERVER_BROWSER_TYPE_COUNT; i++) @@ -1078,21 +1078,21 @@ void CServerBrowser::AddServerToList(CServerListItem* pServer, const ServerBrows pServer->iRowIndex = iIndex; } - const char* szVersion = !bIncludeOtherVersions ? "" : pServer->strVersion.c_str(); - const SString strVersionSortKey = pServer->strVersionSortKey + pServer->strTieBreakSortKey; + const std::string strVersion = !bIncludeOtherVersions ? "" : pServer->strVersion; + const std::string strVersionSortKey = pServer->strVersionSortKey + pServer->strTieBreakSortKey; - const char* szPlayers = pServer->nMaxPlayers == 0 ? "" : SString("%d / %d", pServer->nPlayers, pServer->nMaxPlayers).c_str(); - const SString strPlayersSortKey = SString("%04d-", pServer->nMaxPlayers ? pServer->nPlayers + 1 : 0) + pServer->strTieBreakSortKey; + const std::string strPlayers = pServer->nMaxPlayers == 0 ? "" : std::format("{} / {}", pServer->nPlayers, pServer->nMaxPlayers); + const std::string strPlayersSortKey = std::format("{:04d}-{}", pServer->nMaxPlayers ? pServer->nPlayers + 1 : 0, pServer->strTieBreakSortKey); - const char* szPing = pServer->nPing == 9999 ? "" : SString("%d", pServer->nPing).c_str(); - const SString strPingSortKey = SString("%04d-", pServer->nPing) + pServer->strTieBreakSortKey; + const std::string strPing = pServer->nPing == 9999 ? "" : std::to_string(pServer->nPing); + const std::string strPingSortKey = std::format("{:04d}-{}", pServer->nPing, pServer->strTieBreakSortKey); // The row index could change at any point here if list sorting is enabled - iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hVersion[Type], szVersion, false, false, true, strVersionSortKey); + iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hVersion[Type], strVersion.c_str(), false, false, true, strVersionSortKey.c_str()); iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hName[Type], pServer->strName.c_str(), false, false, true, pServer->strNameSortKey); iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hGame[Type], pServer->strGameMode.c_str(), false, false, true); - iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hPlayers[Type], szPlayers, false, false, true, strPlayersSortKey); - iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hPing[Type], szPing, false, false, true, strPingSortKey); + iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hPlayers[Type], strPlayers.c_str(), false, false, true, strPlayersSortKey.c_str()); + iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hPing[Type], strPing.c_str(), false, false, true, strPingSortKey.c_str()); // Locked icon m_pServerList[Type]->SetItemImage(iIndex, m_hLocked[Type], pServer->bPassworded ? m_pLockedIcon : NULL); diff --git a/Client/core/ServerBrowser/CServerList.h b/Client/core/ServerBrowser/CServerList.h index e2f0b2864f..9400a44b53 100644 --- a/Client/core/ServerBrowser/CServerList.h +++ b/Client/core/ServerBrowser/CServerList.h @@ -196,26 +196,26 @@ class CServerListItem bool bKeepFlag; int iRowIndex; - SString strGameName; // Game name. Always 'mta' - SString strVersion; // Game version - SString strName; // Server name - SString strSearchableName; // Server name to use for searches - SString strHost; // Server host as IP - SString strHostName; // Server host as name - SString strGameMode; // Gamemode - SString strMap; // Map name - SString strEndpoint; // IP:port as a string + std::string strGameName; // Game name. Always 'mta' + std::string strVersion; // Game version + std::string strName; // Server name + std::string strSearchableName; // Server name to use for searches + std::string strHost; // Server host as IP + std::string strHostName; // Server host as name + std::string strGameMode; // Gamemode + std::string strMap; // Map name + std::string strEndpoint; // IP:port as a string int m_iBuildType; // 9=release int m_iBuildNumber; // 00000 and up ushort m_usHttpPort; uchar m_ucSpecialFlags; - SString strNameSortKey; // Server name as a sortable string - SString strVersionSortKey; // Game version as a sortable string - SString strEndpointSortKey; // IP:port as a sortable string - uint uiTieBreakPosition; - SString strTieBreakSortKey; + SString strNameSortKey; // Server name as a sortable string + SString strVersionSortKey; // Game version as a sortable string + SString strEndpointSortKey; // IP:port as a sortable string + uint uiTieBreakPosition; + std::string strTieBreakSortKey; CQueryReceiver queryReceiver; @@ -234,7 +234,7 @@ class CServerListItem void PostChange() { // Update tie break sort key - strTieBreakSortKey = SString("%04d", uiTieBreakPosition); + strTieBreakSortKey = std::format("{:04d}", uiTieBreakPosition); // Update version sort key strVersionSortKey = strVersion; diff --git a/Client/game_sa/CWeaponSA.cpp b/Client/game_sa/CWeaponSA.cpp index 7edace7953..3b7a4ef791 100644 --- a/Client/game_sa/CWeaponSA.cpp +++ b/Client/game_sa/CWeaponSA.cpp @@ -177,20 +177,16 @@ bool CWeaponSA::Fire(CEntity* pFiringEntity, CVector* pvecOrigin, CVector* pvecT void CWeaponSA::AddGunshell(CEntity* pFiringEntity, const CVector& vecOrigin, const CVector2D& vecDirection, float fSize) { - const CVector* pvecOrigin = &vecOrigin; - const CVector2D* pvecDirection = &vecDirection; + DWORD dwEntityInterface = pFiringEntity ? reinterpret_cast(pFiringEntity->GetInterface()) : 0; - DWORD dwEntityInterface = 0; - if (pFiringEntity) - dwEntityInterface = (DWORD)pFiringEntity->GetInterface(); - DWORD dwThis = (DWORD)m_pInterface; - DWORD dwFunc = FUNC_CWeapon_AddGunshell; + static DWORD dwThis = reinterpret_cast(m_pInterface); + static DWORD dwFunc = FUNC_CWeapon_AddGunshell; _asm { mov ecx, dwThis push fSize - push pvecDirection - push pvecOrigin + push vecDirection + push vecOrigin push dwEntityInterface call dwFunc } diff --git a/Client/launch/Main.cpp b/Client/launch/Main.cpp index 27f97b1cff..eadab89838 100644 --- a/Client/launch/Main.cpp +++ b/Client/launch/Main.cpp @@ -52,15 +52,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine // No Windows error box during first load attempt DWORD dwPrevMode = SetErrorMode(SEM_FAILCRITICALERRORS); - HMODULE hModule = LoadLibraryW(FromUTF8(strLoaderDllPathFilename)); + HMODULE hModule = LoadLibraryW(FromUTF8(strLoaderDllPathFilename).c_str()); DWORD dwLoadLibraryError = GetLastError(); SetErrorMode(dwPrevMode); if (!hModule) { // Retry using MTA current directory - SetCurrentDirectoryW(FromUTF8(strMTASAPath)); - hModule = LoadLibraryW(FromUTF8(strLoaderDllPathFilename)); + SetCurrentDirectoryW(FromUTF8(strMTASAPath).c_str()); + hModule = LoadLibraryW(FromUTF8(strLoaderDllPathFilename).c_str()); dwLoadLibraryError = GetLastError(); if (hModule) { diff --git a/Client/loader/CInstallManager.cpp b/Client/loader/CInstallManager.cpp index f0168ea5f4..e3d4e1f9d8 100644 --- a/Client/loader/CInstallManager.cpp +++ b/Client/loader/CInstallManager.cpp @@ -655,13 +655,13 @@ SString CInstallManager::_PrepareLaunchLocation() if (fs::is_regular_file(sourcePath, ec)) { SString strMessage(_("MTA:SA cannot launch because copying a file failed:")); - strMessage += "\n\n" + targetPath.string(); + strMessage += "\n\n" + ToUTF8(targetPath.wstring()); BrowseToSolution("copy-files", ASK_GO_ONLINE, strMessage); } else { SString strMessage(_("MTA:SA cannot launch because an MTA:SA file is incorrect or missing:")); - strMessage += "\n\n" + sourcePath.string(); + strMessage += "\n\n" + ToUTF8(sourcePath.wstring()); BrowseToSolution("mta-datafiles-missing", ASK_GO_ONLINE, strMessage); } @@ -693,7 +693,7 @@ SString CInstallManager::_ProcessGtaPatchCheck() if (!FileGenerator::IsPatchBase(patchBasePath)) { SString strMessage(_("MTA:SA cannot launch because a GTA:SA file is incorrect or missing:")); - strMessage += "\n\n" + patchBasePath.string(); + strMessage += "\n\n" + ToUTF8(patchBasePath.wstring()); BrowseToSolution("gengta_pakfiles", ASK_GO_ONLINE, strMessage); return "quit"; } @@ -701,7 +701,7 @@ SString CInstallManager::_ProcessGtaPatchCheck() if (!FileGenerator::IsPatchDiff(patchDiffPath)) { SString strMessage(_("MTA:SA cannot launch because an MTA:SA file is incorrect or missing:")); - strMessage += "\n\n" + patchDiffPath.string(); + strMessage += "\n\n" + ToUTF8(patchDiffPath.wstring()); BrowseToSolution("mta-datafiles-missing", ASK_GO_ONLINE, strMessage); return "quit"; } @@ -771,7 +771,7 @@ SString CInstallManager::_ProcessGtaDllCheck() if (isAdmin) { SString strMessage(_("MTA:SA cannot launch because a GTA:SA file is incorrect or missing:")); - strMessage += "\n\n" + dependecyPath.string(); + strMessage += "\n\n" + ToUTF8(dependecyPath.wstring()); BrowseToSolution(SString("gendep_error&name=%s", dependency.fileName), ASK_GO_ONLINE, strMessage); return "quit"; } @@ -826,7 +826,7 @@ SString CInstallManager::_ProcessGtaVersionCheck() if (isAdmin) { SString strMessage(_("MTA:SA cannot launch because the GTA:SA executable is incorrect or missing:")); - strMessage += "\n\n" + gtaExePath.string(); + strMessage += "\n\n" + ToUTF8(gtaExePath.wstring()); strMessage += "\n\n" + _("Please check your anti-virus for a false-positive detection, try to add an exception for the GTA:SA executable and restart MTA:SA."); @@ -851,7 +851,7 @@ SString CInstallManager::_ProcessGtaVersionCheck() if (isAdmin) { SString strMessage(_("MTA:SA cannot launch because the GTA:SA executable is not loadable:")); - strMessage += "\n\n" + gtaExePath.string(); + strMessage += "\n\n" + ToUTF8(gtaExePath.wstring()); BrowseToSolution(SString("gengta_error&code=%d", ec.value()), ASK_GO_ONLINE, strMessage); return "quit"; } @@ -874,7 +874,7 @@ SString CInstallManager::_ProcessGtaVersionCheck() if (isAdmin) { SString strMessage(_("MTA:SA cannot launch because patching GTA:SA has failed:")); - strMessage += "\n\n" + gtaExePath.string(); + strMessage += "\n\n" + ToUTF8(gtaExePath.wstring()); BrowseToSolution(SString("patchgta_error&code=%d", ec.value()), ASK_GO_ONLINE, strMessage); return "quit"; } @@ -1275,7 +1275,8 @@ SString CInstallManager::_ProcessAppCompatChecks() WString strUrlValue = ReadCompatibilityEntries(strUrlItem, strUrlKey, HKEY_CURRENT_USER, 0); if (!strUrlValue.empty()) { - WriteDebugEvent(SString("GameUX ServiceLocation was '%s'", *ToUTF8(strUrlValue))); + WriteDebugEvent(std::format("GameUX ServiceLocation was '{}'", ToUTF8(strUrlValue))); + if (strUrlValue.ContainsI(L":")) { strUrlValue = L"disabled"; // Can be anything not containing `:` diff --git a/Client/loader/Dialogs.cpp b/Client/loader/Dialogs.cpp index eb450ff55e..d0ab270b6f 100644 --- a/Client/loader/Dialogs.cpp +++ b/Client/loader/Dialogs.cpp @@ -239,7 +239,7 @@ void InitDialogStrings(HWND hwndDialog, const SDialogItemInfo* dialogItems) SString("Possible text mismatch for dialog item (idx:%d id:%d) '%s' (orig:'%s')", i, item.iItemId, item.szItemText, szPrevText)); } #endif - SetWindowTextW(hwndItem, FromUTF8(strItemText)); + SetWindowTextW(hwndItem, FromUTF8(strItemText).c_str()); } else OutputDebugLine(SString("No dialog item for (idx:%d id:%d) '%s' ", i, item.iItemId, item.szItemText)); @@ -409,7 +409,7 @@ void ShowProgressDialog(HINSTANCE hInstance, const SString& strTitle, bool bAllo hwndProgressDialog = CreateDialogW(hInstance, MAKEINTRESOURCEW(IDD_PROGRESS_DIALOG), 0, DialogProc); dassert((GetWindowLong(hwndProgressDialog, GWL_STYLE) & WS_VISIBLE) == 0); // Should be Visible: False InitDialogStrings(hwndProgressDialog, g_ProgressDialogItems); - SetWindowTextW(hwndProgressDialog, FromUTF8(strTitle)); + SetWindowTextW(hwndProgressDialog, FromUTF8(strTitle).c_str()); ShowWindow(GetDlgItem(hwndProgressDialog, IDCANCEL), bAllowCancel ? SW_SHOW : SW_HIDE); ulProgressStartTime = GetTickCount32(); } @@ -443,7 +443,7 @@ bool UpdateProgress(int iPos, int iMax, const SString& strMsg) char buffer[1024] = ""; GetWindowText(hwndText, buffer, NUMELMS(buffer)); if (strMsg.length() > 0 && strMsg != buffer) - SetWindowTextW(hwndText, FromUTF8(strMsg)); + SetWindowTextW(hwndText, FromUTF8(strMsg).c_str()); HWND hwndBar = GetDlgItem(hwndProgressDialog, IDC_PROGRESS_BAR); PostMessage(hwndBar, PBM_SETPOS, iPos * 100 / std::max(1, iMax), 0); MSG msg; @@ -506,7 +506,7 @@ SString ShowCrashedDialog(HINSTANCE hInstance, const SString& strMessage) hwndCrashedDialog = CreateDialogW(hInstance, MAKEINTRESOURCEW(IDD_CRASHED_DIALOG), 0, DialogProc); dassert((GetWindowLong(hwndCrashedDialog, GWL_STYLE) & WS_VISIBLE) == 0); // Should be Visible: False InitDialogStrings(hwndCrashedDialog, g_CrashedDialogItems); - SetWindowTextW(GetDlgItem(hwndCrashedDialog, IDC_CRASH_INFO_EDIT), FromUTF8(strMessage)); + SetWindowTextW(GetDlgItem(hwndCrashedDialog, IDC_CRASH_INFO_EDIT), FromUTF8(strMessage).c_str()); SendDlgItemMessage(hwndCrashedDialog, IDC_SEND_DUMP_CHECK, BM_SETCHECK, GetApplicationSetting("diagnostics", "send-dumps") != "no" ? BST_CHECKED : BST_UNCHECKED, 0); } @@ -634,7 +634,7 @@ void ShowGraphicsDllDialog(HINSTANCE hInstance, const std::vector selectedItems; @@ -642,7 +642,7 @@ void ShowGraphicsDllDialog(HINSTANCE hInstance, const std::vector(BASS_ChannelGetLength(decoder, BASS_POS_BYTE)); // get the length @@ -457,7 +457,7 @@ DWORD CBassAudio::PlayStreamIntern(LPVOID argument) UnlockCallbackId(); // This can take a while - HSTREAM pSound = BASS_StreamCreateURL(FromUTF8(strURL), 0, lFlags | BASS_UNICODE, NULL, NULL); + HSTREAM pSound = BASS_StreamCreateURL(FromUTF8(strURL).c_str(), 0, lFlags | BASS_UNICODE, NULL, NULL); CBassAudio* pBassAudio = LockCallbackId(argument); if (pBassAudio) @@ -883,11 +883,11 @@ float CBassAudio::GetSoundBPM() float fData = 0.0f; // open the same file as played but for bpm decoding detection - DWORD bpmChan = BASS_StreamCreateFile(false, FromUTF8(m_strPath), 0, 0, BASS_STREAM_DECODE | BASS_UNICODE); + DWORD bpmChan = BASS_StreamCreateFile(false, FromUTF8(m_strPath).c_str(), 0, 0, BASS_STREAM_DECODE | BASS_UNICODE); if (!bpmChan) { - bpmChan = BASS_MusicLoad(false, FromUTF8(m_strPath), 0, 0, BASS_MUSIC_DECODE | BASS_MUSIC_PRESCAN | BASS_UNICODE, 0); + bpmChan = BASS_MusicLoad(false, FromUTF8(m_strPath).c_str(), 0, 0, BASS_MUSIC_DECODE | BASS_MUSIC_PRESCAN | BASS_UNICODE, 0); } if (bpmChan) diff --git a/Client/mods/deathmatch/logic/CServer.cpp b/Client/mods/deathmatch/logic/CServer.cpp index 69484c6ad5..dbd971056f 100644 --- a/Client/mods/deathmatch/logic/CServer.cpp +++ b/Client/mods/deathmatch/logic/CServer.cpp @@ -141,7 +141,7 @@ bool CServer::Start(const char* configFileName) PROCESS_INFORMATION processInfo{}; - if (!CreateProcessW(*FromUTF8(serverExePath), const_cast(*FromUTF8(commandLine)), nullptr, nullptr, TRUE, + if (!CreateProcessW(FromUTF8(serverExePath).c_str(), const_cast(FromUTF8(commandLine).c_str()), nullptr, nullptr, TRUE, CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT, nullptr, nullptr, &startupInfo, &processInfo)) { g_pCore->GetConsole()->Printf("Server process failed to start [error: %08x]: failed to create process\n", GetLastError()); diff --git a/Shared/sdk/SharedUtil.Buffer.h b/Shared/sdk/SharedUtil.Buffer.h index 2fd603d256..0f79788503 100644 --- a/Shared/sdk/SharedUtil.Buffer.h +++ b/Shared/sdk/SharedUtil.Buffer.h @@ -253,6 +253,40 @@ namespace SharedUtil return true; } + bool ReadString(std::string& result, bool bByteLength = false, bool bDoesLengthIncludeLengthOfLength = false) + { + result = ""; + + // Get the length + ushort usLength = 0; + if (bByteLength) + { + uchar ucLength = 0; + if (!Read(ucLength)) + return false; + usLength = ucLength; + } + else if (!Read(usLength)) + return false; + + if (bDoesLengthIncludeLengthOfLength && usLength) + usLength -= bByteLength ? 1 : 2; + + if (usLength) + { + // Check has enough data + if (!CanReadNumberOfBytes(usLength)) + return false; + // Read the data + CScopeAlloc buffer(usLength); + if (!ReadBytes(buffer, usLength, false)) + return false; + + result = std::string(buffer, usLength); + } + return true; + } + bool ReadBuffer(CBuffer& outResult) { outResult.Clear(); diff --git a/Shared/sdk/SharedUtil.File.h b/Shared/sdk/SharedUtil.File.h index 3def283a19..b5870539f4 100644 --- a/Shared/sdk/SharedUtil.File.h +++ b/Shared/sdk/SharedUtil.File.h @@ -1,11 +1,10 @@ /***************************************************************************** * - * PROJECT: Multi Theft Auto v1.0 + * PROJECT: Multi Theft Auto * LICENSE: See LICENSE in the top level directory - * FILE: SharedUtil.File.h - * PURPOSE: + * FILE: Shared/sdk/SharedUtil.File.h * - * Multi Theft Auto is available from http://www.multitheftauto.com/ + * Multi Theft Auto is available from https://multitheftauto.com/ * *****************************************************************************/ #pragma once @@ -99,8 +98,8 @@ namespace SharedUtil uint GetPathFreeSpaceMB(const SString& strPath); SString GetDriveNameWithNotEnoughSpace(uint uiResourcesPathMinMB = 10, uint uiDataPathMinMB = 10); - WString FromUTF8(const SString& strPath); - SString ToUTF8(const WString& strPath); + std::wstring FromUTF8(const std::string& strPath); + std::string ToUTF8(const std::wstring& wstrPath); std::vector ListDir(const char* szPath) noexcept; diff --git a/Shared/sdk/SharedUtil.File.hpp b/Shared/sdk/SharedUtil.File.hpp index 351afa63c3..696029f116 100644 --- a/Shared/sdk/SharedUtil.File.hpp +++ b/Shared/sdk/SharedUtil.File.hpp @@ -1,11 +1,10 @@ /***************************************************************************** * - * PROJECT: Multi Theft Auto v1.0 + * PROJECT: Multi Theft Auto * LICENSE: See LICENSE in the top level directory - * FILE: SharedUtil.File.hpp - * PURPOSE: + * FILE: Shared/sdk/SharedUtil.File.hpp * - * Multi Theft Auto is available from http://www.multitheftauto.com/ + * Multi Theft Auto is available from https://multitheftauto.com/ * *****************************************************************************/ #include "SharedUtil.File.h" @@ -218,7 +217,7 @@ bool SharedUtil::FileDelete(const SString& strFilename, bool bForce) bool SharedUtil::FileRename(const SString& strFilenameOld, const SString& strFilenameNew, int* pOutErrorCode) { #ifdef _WIN32 - if (MoveFileExW(FromUTF8(strFilenameOld), FromUTF8(strFilenameNew), MOVEFILE_COPY_ALLOWED) == 0) + if (MoveFileExW(FromUTF8(strFilenameOld).c_str(), FromUTF8(strFilenameNew).c_str(), MOVEFILE_COPY_ALLOWED) == 0) { int errorCode = GetLastError(); if (errorCode == ERROR_ACCESS_DENIED) @@ -570,7 +569,7 @@ SString SharedUtil::GetLaunchFilename() SString SharedUtil::GetPathDriveName(const SString& strPath) { wchar_t szDrive[4] = L""; - int iDriveNumber = PathGetDriveNumberW(FromUTF8(strPath)); + int iDriveNumber = PathGetDriveNumberW(FromUTF8(strPath).c_str()); if (iDriveNumber > -1) PathBuildRootW(szDrive, iDriveNumber); return ToUTF8(szDrive); @@ -583,7 +582,7 @@ uint SharedUtil::GetPathFreeSpaceMB(const SString& strPath) if (!strDrive.empty()) { ULARGE_INTEGER llUserFreeBytesAvailable; - if (GetDiskFreeSpaceExW(FromUTF8(strDrive), &llUserFreeBytesAvailable, NULL, NULL)) + if (GetDiskFreeSpaceExW(FromUTF8(strDrive).c_str(), &llUserFreeBytesAvailable, NULL, NULL)) { llUserFreeBytesAvailable.QuadPart /= 1048576UL; if (llUserFreeBytesAvailable.HighPart == 0) @@ -611,42 +610,35 @@ SString SharedUtil::GetDriveNameWithNotEnoughSpace(uint uiResourcesPathMinMB, ui #endif // #ifdef MTA_CLIENT #endif // #ifdef _WIN32 -WString SharedUtil::FromUTF8(const SString& strPath) +std::wstring SharedUtil::FromUTF8(const std::string& strPath) { -#ifdef WIN32_TESTING // This might be faster - Needs testing - const char* szSrc = strPath; - uint cCharacters = strlen(szSrc) + 1; +#ifdef WIN32_TESTING // This might be faster - Needs testing + uint cCharacters = strPath.length() + 1; uint cbUnicode = cCharacters * 4; wchar_t* Dest = (wchar_t*)alloca(cbUnicode); - if (MultiByteToWideChar(CP_UTF8, 0, szSrc, -1, Dest, (int)cbUnicode) == 0) - { - return WString(); - } - else - { + if (MultiByteToWideChar(CP_UTF8, 0, &strPath[0], -1, Dest, (int)cbUnicode)) return Dest; - } + + return ""; #else return MbUTF8ToUTF16(strPath); #endif } -SString SharedUtil::ToUTF8(const WString& strPath) +std::string SharedUtil::ToUTF8(const std::wstring& wstrPath) { -#ifdef WIN32_TESTING // This might be faster - Needs testing - const wchar_t* pszW = strPath; - uint cCharacters = wcslen(pszW) + 1; +#ifdef WIN32_TESTING // This might be faster - Needs testing + uint cCharacters = wstrPath.length() + 1; uint cbAnsi = cCharacters * 6; char* pData = (char*)alloca(cbAnsi); - if (0 == WideCharToMultiByte(CP_UTF8, 0, pszW, cCharacters, pData, cbAnsi, NULL, NULL)) - { - return ""; - } - return pData; + if (WideCharToMultiByte(CP_UTF8, 0, &wstrPath[0], cCharacters, pData, cbAnsi, nullptr, nullptr)) + return pData; + + return ""; #else - return UTF16ToMbUTF8(strPath); + return UTF16ToMbUTF8(wstrPath); #endif } @@ -764,7 +756,7 @@ std::vector SharedUtil::FindFiles(const SString& strInMatch, bool bFile strMatch += "*"; _WIN32_FIND_DATAW findData; - HANDLE hFind = FindFirstFileW(FromUTF8(strMatch), &findData); + HANDLE hFind = FindFirstFileW(FromUTF8(strMatch).c_str(), &findData); if (hFind != INVALID_HANDLE_VALUE) { do @@ -1006,7 +998,7 @@ SString SharedUtil::GetSystemShortPathName(const SString& strPath) { wchar_t szBuffer[32000]; szBuffer[0] = 0; - if (!GetShortPathNameW(FromUTF8(strPath), szBuffer, NUMELMS(szBuffer) - 1)) + if (!GetShortPathNameW(FromUTF8(strPath).c_str(), szBuffer, NUMELMS(szBuffer) - 1)) return strPath; return ToUTF8(szBuffer); } @@ -1015,7 +1007,7 @@ SString SharedUtil::GetSystemLongPathName(const SString& strPath) { wchar_t szBuffer[32000]; szBuffer[0] = 0; - if (!GetLongPathNameW(FromUTF8(strPath), szBuffer, NUMELMS(szBuffer) - 1)) + if (!GetLongPathNameW(FromUTF8(strPath).c_str(), szBuffer, NUMELMS(szBuffer) - 1)) return strPath; return ToUTF8(szBuffer); } @@ -1024,7 +1016,7 @@ SString SharedUtil::GetSystemLongPathName(const SString& strPath) FILE* SharedUtil::File::Fopen(const char* szFilename, const char* szMode) { #ifdef _WIN32 - return _wfsopen(FromUTF8(szFilename), FromUTF8(szMode), _SH_DENYNO); + return _wfsopen(FromUTF8(szFilename).c_str(), FromUTF8(szMode).c_str(), _SH_DENYNO); #else return fopen(szFilename, szMode); #endif @@ -1033,7 +1025,7 @@ FILE* SharedUtil::File::Fopen(const char* szFilename, const char* szMode) int SharedUtil::File::Mkdir(const char* szPath, int iMode) { #ifdef _WIN32 - return _wmkdir(FromUTF8(szPath)); + return _wmkdir(FromUTF8(szPath).c_str()); #else return mkdir(szPath, (mode_t)iMode); #endif @@ -1042,7 +1034,7 @@ int SharedUtil::File::Mkdir(const char* szPath, int iMode) int SharedUtil::File::Chdir(const char* szPath) { #ifdef _WIN32 - return _wchdir(FromUTF8(szPath)); + return _wchdir(FromUTF8(szPath).c_str()); #else return chdir(szPath); #endif @@ -1051,7 +1043,7 @@ int SharedUtil::File::Chdir(const char* szPath) int SharedUtil::File::Rmdir(const char* szPath) { #ifdef _WIN32 - return _wrmdir(FromUTF8(szPath)); + return _wrmdir(FromUTF8(szPath).c_str()); #else return rmdir(szPath); #endif @@ -1060,7 +1052,7 @@ int SharedUtil::File::Rmdir(const char* szPath) int SharedUtil::File::Delete(const char* szFilename) { #ifdef _WIN32 - return _wremove(FromUTF8(szFilename)); + return _wremove(FromUTF8(szFilename).c_str()); #else return remove(szFilename); #endif @@ -1069,7 +1061,7 @@ int SharedUtil::File::Delete(const char* szFilename) int SharedUtil::File::Rename(const char* szOldFilename, const char* szNewFilename) { #ifdef _WIN32 - return _wrename(FromUTF8(szOldFilename), FromUTF8(szNewFilename)); + return _wrename(FromUTF8(szOldFilename).c_str(), FromUTF8(szNewFilename).c_str()); #else return rename(szOldFilename, szNewFilename); #endif diff --git a/Shared/sdk/SharedUtil.SysInfo.hpp b/Shared/sdk/SharedUtil.SysInfo.hpp index 8d269626be..d76c3e8696 100644 --- a/Shared/sdk/SharedUtil.SysInfo.hpp +++ b/Shared/sdk/SharedUtil.SysInfo.hpp @@ -449,7 +449,7 @@ bool SharedUtil::IsHotFixInstalled(const SString& strHotFixId) bool SharedUtil::GetLibVersionInfo(const SString& strLibName, SLibVersionInfo* pOutLibVersionInfo) { DWORD dwHandle, dwLen; - dwLen = GetFileVersionInfoSizeW(FromUTF8(strLibName), &dwHandle); + dwLen = GetFileVersionInfoSizeW(FromUTF8(strLibName).c_str(), &dwHandle); if (!dwLen) return FALSE; @@ -458,7 +458,7 @@ bool SharedUtil::GetLibVersionInfo(const SString& strLibName, SLibVersionInfo* p return FALSE; SetLastError(0); - if (!GetFileVersionInfoW(FromUTF8(strLibName), dwHandle, dwLen, lpData)) + if (!GetFileVersionInfoW(FromUTF8(strLibName).c_str(), dwHandle, dwLen, lpData)) { free(lpData); return FALSE; diff --git a/Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp b/Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp index d86d362851..945879ef9d 100644 --- a/Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp +++ b/Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp @@ -1,11 +1,11 @@ /***************************************************************************** * - * PROJECT: Multi Theft Auto v1.0 + * PROJECT: Multi Theft Auto * LICENSE: See LICENSE in the top level directory - * FILE: SharedUtil.Win32Utf8FileHooks.hpp + * FILE: Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp * PURPOSE: Hooks for making Windows file functions use UTF8 strings * - * Multi Theft Auto is available from http://www.multitheftauto.com/ + * Multi Theft Auto is available from https://multitheftauto.com/ * *****************************************************************************/ @@ -107,7 +107,7 @@ namespace SharedUtil { #ifdef UTF8_FILE_HOOKS_PERSONALITY_Core static SString gtaDirCP = ToACP(g_gtaDirectory); - static SString gtaDirUTF8 = g_gtaDirectory.string(); + static SString gtaDirUTF8 = ToUTF8(g_gtaDirectory.wstring()); if (strOriginal.BeginsWithI(gtaDirCP)) { SString tail = strOriginal.SubStr(gtaDirCP.length()); @@ -167,19 +167,28 @@ namespace SharedUtil if (IsGTAProcess()) strFileName = MakeSurePathIsUTF8(strFileName); #endif - return CreateFileW(FromUTF8(strFileName), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, + return CreateFileW(FromUTF8(strFileName).c_str(), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); } HMODULE WINAPI - MyLoadLibraryA(__in LPCSTR lpLibFileName) { return LoadLibraryW(FromUTF8(lpLibFileName)); } + MyLoadLibraryA(__in LPCSTR lpLibFileName) + { + return LoadLibraryW(FromUTF8(lpLibFileName).c_str()); + } HMODULE WINAPI - MyLoadLibraryExA(__in LPCSTR lpLibFileName, __reserved HANDLE hFile, __in DWORD dwFlags) { return LoadLibraryExW(FromUTF8(lpLibFileName), hFile, dwFlags); } + MyLoadLibraryExA(__in LPCSTR lpLibFileName, __reserved HANDLE hFile, __in DWORD dwFlags) + { + return LoadLibraryExW(FromUTF8(lpLibFileName).c_str(), hFile, dwFlags); + } - BOOL WINAPI MySetDllDirectoryA(__in_opt LPCSTR lpPathName) { return SetDllDirectoryW(FromUTF8(lpPathName)); } + BOOL WINAPI MySetDllDirectoryA(__in_opt LPCSTR lpPathName) + { + return SetDllDirectoryW(FromUTF8(lpPathName).c_str()); + } BOOL WINAPI MySetCurrentDirectoryA(__in LPCSTR lpPathName) { @@ -188,12 +197,18 @@ namespace SharedUtil if (IsGTAProcess()) strPathName = MakeSurePathIsUTF8(strPathName); #endif - return SetCurrentDirectoryW(FromUTF8(strPathName)); + return SetCurrentDirectoryW(FromUTF8(strPathName).c_str()); } - int WINAPI MyAddFontResourceExA(__in LPCSTR name, __in DWORD fl, __reserved PVOID res) { return AddFontResourceExW(FromUTF8(name), fl, res); } + int WINAPI MyAddFontResourceExA(__in LPCSTR name, __in DWORD fl, __reserved PVOID res) + { + return AddFontResourceExW(FromUTF8(name).c_str(), fl, res); + } - BOOL WINAPI MyRemoveFontResourceExA(__in LPCSTR name, __in DWORD fl, __reserved PVOID pdv) { return RemoveFontResourceExW(FromUTF8(name), fl, pdv); } + BOOL WINAPI MyRemoveFontResourceExA(__in LPCSTR name, __in DWORD fl, __reserved PVOID pdv) + { + return RemoveFontResourceExW(FromUTF8(name).c_str(), fl, pdv); + } BOOL WINAPI MyRemoveDirectoryA(__in LPCSTR lpPathName) { @@ -202,13 +217,13 @@ namespace SharedUtil if (IsGTAProcess()) strPathName = MakeSurePathIsUTF8(lpPathName); #endif - return RemoveDirectoryW(FromUTF8(strPathName)); + return RemoveDirectoryW(FromUTF8(strPathName).c_str()); } BOOL WINAPI MyGetDiskFreeSpaceExA(__in_opt LPCSTR lpDirectoryName, __out_opt PULARGE_INTEGER lpFreeBytesAvailableToCaller, __out_opt PULARGE_INTEGER lpTotalNumberOfBytes, __out_opt PULARGE_INTEGER lpTotalNumberOfFreeBytes) { - return GetDiskFreeSpaceExW(FromUTF8(lpDirectoryName), lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes); + return GetDiskFreeSpaceExW(FromUTF8(lpDirectoryName).c_str(), lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes); } DWORD @@ -220,7 +235,7 @@ namespace SharedUtil if (IsGTAProcess()) strFileName = MakeSurePathIsUTF8(strFileName); #endif - return GetFileAttributesW(FromUTF8(strFileName)); + return GetFileAttributesW(FromUTF8(strFileName).c_str()); } BOOL WINAPI MySetFileAttributesA(__in LPCSTR lpFileName, __in DWORD dwFileAttributes) @@ -230,12 +245,13 @@ namespace SharedUtil if (IsGTAProcess()) strFileName = MakeSurePathIsUTF8(strFileName); #endif - return SetFileAttributesW(FromUTF8(strFileName), dwFileAttributes); + return SetFileAttributesW(FromUTF8(strFileName).c_str(), dwFileAttributes); } HINSTANCE STDAPICALLTYPE MyShellExecuteA(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd) { - return ShellExecuteW(hwnd, FromUTF8(lpOperation), FromUTF8(lpFile), FromUTF8(lpParameters), FromUTF8(lpDirectory), nShowCmd); + return ShellExecuteW(hwnd, FromUTF8(lpOperation).c_str(), FromUTF8(lpFile).c_str(), FromUTF8(lpParameters).c_str(), FromUTF8(lpDirectory).c_str(), + nShowCmd); } BOOL WINAPI MyCreateDirectoryA(__in LPCSTR lpPathName, __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes) @@ -245,17 +261,17 @@ namespace SharedUtil if (IsGTAProcess()) strPathName = MakeSurePathIsUTF8(strPathName); #endif - return CreateDirectoryW(FromUTF8(strPathName), lpSecurityAttributes); + return CreateDirectoryW(FromUTF8(strPathName).c_str(), lpSecurityAttributes); } BOOL WINAPI MyCopyFileA(__in LPCSTR lpExistingFileName, __in LPCSTR lpNewFileName, __in BOOL bFailIfExists) { - return CopyFileW(FromUTF8(lpExistingFileName), FromUTF8(lpNewFileName), bFailIfExists); + return CopyFileW(FromUTF8(lpExistingFileName).c_str(), FromUTF8(lpNewFileName).c_str(), bFailIfExists); } BOOL WINAPI MyMoveFileA(__in LPCSTR lpExistingFileName, __in LPCSTR lpNewFileName) { - return MoveFileW(FromUTF8(lpExistingFileName), FromUTF8(lpNewFileName)); + return MoveFileW(FromUTF8(lpExistingFileName).c_str(), FromUTF8(lpNewFileName).c_str()); } BOOL WINAPI MyDeleteFileA(__in LPCSTR lpFileName) @@ -265,7 +281,7 @@ namespace SharedUtil if (IsGTAProcess()) strFileName = MakeSurePathIsUTF8(strFileName); #endif - return DeleteFileW(FromUTF8(strFileName)); + return DeleteFileW(FromUTF8(strFileName).c_str()); } HMODULE @@ -274,7 +290,7 @@ namespace SharedUtil { if (!lpModuleName) return GetModuleHandleW(NULL); - return GetModuleHandleW(FromUTF8(lpModuleName)); + return GetModuleHandleW(FromUTF8(lpModuleName).c_str()); } ///////////////////////////////////////////////////////////// diff --git a/vendor/tinygettext/dirent_win32.h b/vendor/tinygettext/dirent_win32.h index 98467af457..79e1c00300 100644 --- a/vendor/tinygettext/dirent_win32.h +++ b/vendor/tinygettext/dirent_win32.h @@ -779,7 +779,7 @@ dirent_mbstowcs_s( #if defined(_MSC_VER) && _MSC_VER >= 1400 - wcscpy_s(wcstr, sizeInWords, *FromUTF8(mbstr)); + wcscpy_s(wcstr, sizeInWords, FromUTF8(mbstr).c_str()); error = 0; #else @@ -829,7 +829,7 @@ dirent_wcstombs_s( #if defined(_MSC_VER) && _MSC_VER >= 1400 - strcpy_s(mbstr, sizeInBytes, *ToUTF8(wcstr)); + strcpy_s(mbstr, sizeInBytes, ToUTF8(wcstr).c_str()); error = 0; #else From 9b171c2968ad7a4b335a47f794e682963f0fdbe9 Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Wed, 28 Aug 2024 04:22:30 +0300 Subject: [PATCH 09/19] Mini refactor --- Client/core/CCore.cpp | 4 ++-- Client/core/CFilePathTranslator.cpp | 2 +- Client/loader/CInstallManager.cpp | 16 ++++++++-------- Client/loader/MainFunctions.cpp | 2 +- Shared/sdk/SharedUtil.File.h | 18 ++++++++++++++++++ Shared/sdk/SharedUtil.File.hpp | 8 ++++++++ Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp | 2 +- 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Client/core/CCore.cpp b/Client/core/CCore.cpp index 880aabf931..171014c092 100644 --- a/Client/core/CCore.cpp +++ b/Client/core/CCore.cpp @@ -60,13 +60,13 @@ static HMODULE WINAPI SkipDirectPlay_LoadLibraryA(LPCSTR fileName) const fs::path inLaunchDir = fs::path{FromUTF8(GetLaunchPath())} / "enbseries" / "enbhelper.dll"; if (fs::is_regular_file(inLaunchDir, ec)) - return Win32LoadLibraryA(ToUTF8(inLaunchDir.wstring()).c_str()); + return Win32LoadLibraryA(PathToUtf8(inLaunchDir).c_str()); // Try to load enbhelper.dll from the GTA install directory second. const fs::path inGTADir = g_gtaDirectory / "enbseries" / "enbhelper.dll"; if (fs::is_regular_file(inGTADir, ec)) - return Win32LoadLibraryA(ToUTF8(inGTADir.wstring()).c_str()); + return Win32LoadLibraryA(PathToUtf8(inGTADir).c_str()); return nullptr; } diff --git a/Client/core/CFilePathTranslator.cpp b/Client/core/CFilePathTranslator.cpp index f7feebd682..089663c8c8 100644 --- a/Client/core/CFilePathTranslator.cpp +++ b/Client/core/CFilePathTranslator.cpp @@ -80,7 +80,7 @@ void CFilePathTranslator::GetCurrentWorkingDirectory(std::string& WorkingDirecto void CFilePathTranslator::GetGTARootDirectory(std::string& ModuleRootDirOut) { - ModuleRootDirOut = ToUTF8(g_gtaDirectory.wstring()); + ModuleRootDirOut = PathToUtf8(g_gtaDirectory); } void CFilePathTranslator::GetMTASARootDirectory(std::string& InstallRootDirOut) diff --git a/Client/loader/CInstallManager.cpp b/Client/loader/CInstallManager.cpp index e3d4e1f9d8..8962218be0 100644 --- a/Client/loader/CInstallManager.cpp +++ b/Client/loader/CInstallManager.cpp @@ -655,13 +655,13 @@ SString CInstallManager::_PrepareLaunchLocation() if (fs::is_regular_file(sourcePath, ec)) { SString strMessage(_("MTA:SA cannot launch because copying a file failed:")); - strMessage += "\n\n" + ToUTF8(targetPath.wstring()); + strMessage += "\n\n" + PathToUtf8(targetPath); BrowseToSolution("copy-files", ASK_GO_ONLINE, strMessage); } else { SString strMessage(_("MTA:SA cannot launch because an MTA:SA file is incorrect or missing:")); - strMessage += "\n\n" + ToUTF8(sourcePath.wstring()); + strMessage += "\n\n" + PathToUtf8(sourcePath); BrowseToSolution("mta-datafiles-missing", ASK_GO_ONLINE, strMessage); } @@ -693,7 +693,7 @@ SString CInstallManager::_ProcessGtaPatchCheck() if (!FileGenerator::IsPatchBase(patchBasePath)) { SString strMessage(_("MTA:SA cannot launch because a GTA:SA file is incorrect or missing:")); - strMessage += "\n\n" + ToUTF8(patchBasePath.wstring()); + strMessage += "\n\n" + PathToUtf8(patchBasePath); BrowseToSolution("gengta_pakfiles", ASK_GO_ONLINE, strMessage); return "quit"; } @@ -701,7 +701,7 @@ SString CInstallManager::_ProcessGtaPatchCheck() if (!FileGenerator::IsPatchDiff(patchDiffPath)) { SString strMessage(_("MTA:SA cannot launch because an MTA:SA file is incorrect or missing:")); - strMessage += "\n\n" + ToUTF8(patchDiffPath.wstring()); + strMessage += "\n\n" + PathToUtf8(patchDiffPath); BrowseToSolution("mta-datafiles-missing", ASK_GO_ONLINE, strMessage); return "quit"; } @@ -771,7 +771,7 @@ SString CInstallManager::_ProcessGtaDllCheck() if (isAdmin) { SString strMessage(_("MTA:SA cannot launch because a GTA:SA file is incorrect or missing:")); - strMessage += "\n\n" + ToUTF8(dependecyPath.wstring()); + strMessage += "\n\n" + PathToUtf8(dependecyPath); BrowseToSolution(SString("gendep_error&name=%s", dependency.fileName), ASK_GO_ONLINE, strMessage); return "quit"; } @@ -826,7 +826,7 @@ SString CInstallManager::_ProcessGtaVersionCheck() if (isAdmin) { SString strMessage(_("MTA:SA cannot launch because the GTA:SA executable is incorrect or missing:")); - strMessage += "\n\n" + ToUTF8(gtaExePath.wstring()); + strMessage += "\n\n" + PathToUtf8(gtaExePath); strMessage += "\n\n" + _("Please check your anti-virus for a false-positive detection, try to add an exception for the GTA:SA executable and restart MTA:SA."); @@ -851,7 +851,7 @@ SString CInstallManager::_ProcessGtaVersionCheck() if (isAdmin) { SString strMessage(_("MTA:SA cannot launch because the GTA:SA executable is not loadable:")); - strMessage += "\n\n" + ToUTF8(gtaExePath.wstring()); + strMessage += "\n\n" + PathToUtf8(gtaExePath); BrowseToSolution(SString("gengta_error&code=%d", ec.value()), ASK_GO_ONLINE, strMessage); return "quit"; } @@ -874,7 +874,7 @@ SString CInstallManager::_ProcessGtaVersionCheck() if (isAdmin) { SString strMessage(_("MTA:SA cannot launch because patching GTA:SA has failed:")); - strMessage += "\n\n" + ToUTF8(gtaExePath.wstring()); + strMessage += "\n\n" + PathToUtf8(gtaExePath); BrowseToSolution(SString("patchgta_error&code=%d", ec.value()), ASK_GO_ONLINE, strMessage); return "quit"; } diff --git a/Client/loader/MainFunctions.cpp b/Client/loader/MainFunctions.cpp index 857ddc052b..598a99f0dd 100644 --- a/Client/loader/MainFunctions.cpp +++ b/Client/loader/MainFunctions.cpp @@ -1115,7 +1115,7 @@ int LaunchGame(SString strCmdLine) const SString strGTAPath = GetGTAPath(); const SString strMTASAPath = GetMTASAPath(); SString strMtaDir = PathJoin(strMTASAPath, "mta"); - SString strGTAEXEPath = ToUTF8(GetGameExecutablePath().wstring()); + SString strGTAEXEPath = PathToUtf8(GetGameExecutablePath()); SetDllDirectory(strMtaDir); if (!CheckService(CHECK_SERVICE_PRE_CREATE) && !IsUserAdmin()) diff --git a/Shared/sdk/SharedUtil.File.h b/Shared/sdk/SharedUtil.File.h index b5870539f4..a07cca2241 100644 --- a/Shared/sdk/SharedUtil.File.h +++ b/Shared/sdk/SharedUtil.File.h @@ -7,6 +7,7 @@ * Multi Theft Auto is available from https://multitheftauto.com/ * *****************************************************************************/ + #pragma once #include @@ -14,6 +15,18 @@ #include "SString.h" #include "WString.h" +// C++20? +#if __cplusplus >= 202002L +// Forward declaration of std::filesystem::path to avoid including the +namespace std +{ + namespace filesystem + { + class path; + } +} +#endif + namespace SharedUtil { // @@ -101,6 +114,11 @@ namespace SharedUtil std::wstring FromUTF8(const std::string& strPath); std::string ToUTF8(const std::wstring& wstrPath); + // C++20? + #if __cplusplus >= 202002L + std::string PathToUtf8(const std::filesystem::path& path); + #endif + std::vector ListDir(const char* szPath) noexcept; namespace File diff --git a/Shared/sdk/SharedUtil.File.hpp b/Shared/sdk/SharedUtil.File.hpp index 696029f116..7252d47248 100644 --- a/Shared/sdk/SharedUtil.File.hpp +++ b/Shared/sdk/SharedUtil.File.hpp @@ -642,6 +642,14 @@ std::string SharedUtil::ToUTF8(const std::wstring& wstrPath) #endif } +// C++20? +#if __cplusplus >= 202002L +std::string SharedUtil::PathToUtf8(const std::filesystem::path& path) +{ + return ToUTF8(path.wstring()); +} +#endif + #ifdef _WIN32 /////////////////////////////////////////////////////////////// // diff --git a/Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp b/Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp index 945879ef9d..1348f2bd44 100644 --- a/Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp +++ b/Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp @@ -107,7 +107,7 @@ namespace SharedUtil { #ifdef UTF8_FILE_HOOKS_PERSONALITY_Core static SString gtaDirCP = ToACP(g_gtaDirectory); - static SString gtaDirUTF8 = ToUTF8(g_gtaDirectory.wstring()); + static SString gtaDirUTF8 = PathToUtf8(g_gtaDirectory); if (strOriginal.BeginsWithI(gtaDirCP)) { SString tail = strOriginal.SubStr(gtaDirCP.length()); From 30c42e75aeda42c24b83e5c91b090b535483c142 Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:26:24 +0300 Subject: [PATCH 10/19] Update CEGUI --- vendor/cegui-0.4.0-custom/premake5.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vendor/cegui-0.4.0-custom/premake5.lua b/vendor/cegui-0.4.0-custom/premake5.lua index c594ea53c7..fc29b411ff 100644 --- a/vendor/cegui-0.4.0-custom/premake5.lua +++ b/vendor/cegui-0.4.0-custom/premake5.lua @@ -3,6 +3,8 @@ project "CEGUI" kind "StaticLib" targetname "CEGUI" + cppdialect "C++20" + pchheader "StdInc.h" pchsource "src/StdInc.cpp" From 33981ff9e2a2070afb47ac54cd0d540928b078de Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:42:33 +0300 Subject: [PATCH 11/19] Update CEGUI (Full) --- vendor/cegui-0.4.0-custom/WidgetSets/Falagard/premake5.lua | 2 ++ .../src/renderers/directx9GUIRenderer/premake5.lua | 2 ++ 2 files changed, 4 insertions(+) diff --git a/vendor/cegui-0.4.0-custom/WidgetSets/Falagard/premake5.lua b/vendor/cegui-0.4.0-custom/WidgetSets/Falagard/premake5.lua index c08bac699a..9e4a82c8d4 100644 --- a/vendor/cegui-0.4.0-custom/WidgetSets/Falagard/premake5.lua +++ b/vendor/cegui-0.4.0-custom/WidgetSets/Falagard/premake5.lua @@ -2,6 +2,8 @@ project "Falagard" language "C++" kind "StaticLib" targetname "Falagard" + + cppdialect "C++20" pchheader "StdInc.h" pchsource "src/StdInc.cpp" diff --git a/vendor/cegui-0.4.0-custom/src/renderers/directx9GUIRenderer/premake5.lua b/vendor/cegui-0.4.0-custom/src/renderers/directx9GUIRenderer/premake5.lua index 5719c8c28e..a31dacb385 100644 --- a/vendor/cegui-0.4.0-custom/src/renderers/directx9GUIRenderer/premake5.lua +++ b/vendor/cegui-0.4.0-custom/src/renderers/directx9GUIRenderer/premake5.lua @@ -3,6 +3,8 @@ project "DirectX9GUIRenderer" kind "StaticLib" targetname "DirectX9GUIRenderer" + cppdialect "C++20" + defines { "_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING" } includedirs { From 055752bdd777bd1204fdfabc8e0f939984249155 Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:53:32 +0300 Subject: [PATCH 12/19] Update Discord RPC and Tinygettext --- vendor/discord-rpc/premake5.lua | 2 ++ vendor/tinygettext/premake5.lua | 2 ++ 2 files changed, 4 insertions(+) diff --git a/vendor/discord-rpc/premake5.lua b/vendor/discord-rpc/premake5.lua index 3ec2d53835..e589e65752 100644 --- a/vendor/discord-rpc/premake5.lua +++ b/vendor/discord-rpc/premake5.lua @@ -3,6 +3,8 @@ project "discord-rpc" language "C++" kind "StaticLib" + cppdialect "C++20" + includedirs { "discord/include", "discord/thirdparty/rapidjson/include" diff --git a/vendor/tinygettext/premake5.lua b/vendor/tinygettext/premake5.lua index c840efdc50..0cb2b3683a 100644 --- a/vendor/tinygettext/premake5.lua +++ b/vendor/tinygettext/premake5.lua @@ -3,6 +3,8 @@ project "tinygettext" kind "StaticLib" targetname "tinygettext" + cppdialect "C++20" + includedirs { "../../Shared/sdk", ".", From e7f3a86fe6b28975316adcda2a6c83fcd43c9f0a Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Fri, 6 Sep 2024 17:21:15 +0300 Subject: [PATCH 13/19] Update Lunasvg --- vendor/lunasvg/premake5.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/lunasvg/premake5.lua b/vendor/lunasvg/premake5.lua index 3c7ce68612..92cc2be7cc 100644 --- a/vendor/lunasvg/premake5.lua +++ b/vendor/lunasvg/premake5.lua @@ -1,6 +1,6 @@ project "lunasvg" language "C++" - cppdialect "C++17" + cppdialect "C++20" kind "StaticLib" targetname "lunasvg" targetdir(buildpath("mta")) From 7a112411d92ba1c1927674ca0c244a41e053882c Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Fri, 6 Sep 2024 21:43:09 +0300 Subject: [PATCH 14/19] Test Fix multiplayer_sa --- Client/multiplayer_sa/CMultiplayerSA.cpp | 777 +++++++++++++---------- Client/multiplayer_sa/premake5.lua | 4 +- 2 files changed, 430 insertions(+), 351 deletions(-) diff --git a/Client/multiplayer_sa/CMultiplayerSA.cpp b/Client/multiplayer_sa/CMultiplayerSA.cpp index 28d5b1f551..0151573d31 100644 --- a/Client/multiplayer_sa/CMultiplayerSA.cpp +++ b/Client/multiplayer_sa/CMultiplayerSA.cpp @@ -2785,9 +2785,9 @@ void CMultiplayerSA::SetCenterOfWorld(CEntity* entity, CVector* vecPosition, FLO } } -void _declspec(naked) HOOK_FindPlayerCoors() +void __declspec(naked) HOOK_FindPlayerCoors() { - _asm + __asm { // Only set our world of center if we have a center of world set push eax @@ -2821,14 +2821,14 @@ void _declspec(naked) HOOK_FindPlayerCoors() } } -void _declspec(naked) HOOK_CStreaming_Update_Caller() +void __declspec(naked) HOOK_CStreaming_Update_Caller() { /* 0053BF09 8BF8 MOV EDI,EAX 0053BF0B E8 6027EDFF CALL gta_sa.0040E670 */ - _asm + __asm { // Store all registers pushad @@ -2841,7 +2841,7 @@ void _declspec(naked) HOOK_CStreaming_Update_Caller() if (activeEntityForStreaming) { // Do something... - _asm + __asm { mov edi, FUNC_CPlayerInfoBase mov ebx, [edi] @@ -2851,7 +2851,7 @@ void _declspec(naked) HOOK_CStreaming_Update_Caller() } } - _asm + __asm { mov edi, eax @@ -2863,7 +2863,7 @@ void _declspec(naked) HOOK_CStreaming_Update_Caller() // We have an entity for streaming? if (activeEntityForStreaming) { - _asm + __asm { // ... mov edi, FUNC_CPlayerInfoBase @@ -2874,7 +2874,7 @@ void _declspec(naked) HOOK_CStreaming_Update_Caller() // We're no longer in streaming update bInStreamingUpdate = false; - _asm + __asm { // Restore registers popad @@ -2886,13 +2886,13 @@ void _declspec(naked) HOOK_CStreaming_Update_Caller() } } -void _declspec(naked) HOOK_CHud_Draw_Caller() +void __declspec(naked) HOOK_CHud_Draw_Caller() { /* 0053E4FA . E8 318BFCFF CALL gta_sa_u.00507030 0053E4FF . E8 DC150500 CALL gta_sa_u.0058FAE0 */ - _asm + __asm { pushad @@ -2902,7 +2902,7 @@ void _declspec(naked) HOOK_CHud_Draw_Caller() if (!bSetCenterOfWorld) { - _asm + __asm { mov edx, FUNC_CHud_Draw call edx @@ -2912,7 +2912,7 @@ void _declspec(naked) HOOK_CHud_Draw_Caller() { /*if ( activeEntityForStreaming ) { - _asm + __asm { mov edi, FUNC_CPlayerInfoBase mov ebx, [edi] @@ -2924,7 +2924,7 @@ void _declspec(naked) HOOK_CHud_Draw_Caller() if (!bHideRadar) { - _asm + __asm { mov edx, 0x58A330 call edx @@ -2933,7 +2933,7 @@ void _declspec(naked) HOOK_CHud_Draw_Caller() /*if ( activeEntityForStreaming ) { - _asm + __asm { mov edi, FUNC_CPlayerInfoBase mov ebx, dwSavedPlayerPointer @@ -2942,7 +2942,7 @@ void _declspec(naked) HOOK_CHud_Draw_Caller() }*/ } - _asm + __asm { popad @@ -2952,14 +2952,14 @@ void _declspec(naked) HOOK_CHud_Draw_Caller() } } -void _declspec(naked) HOOK_FindPlayerCentreOfWorld() +void __declspec(naked) HOOK_FindPlayerCentreOfWorld() { /* 0056E250 /$ 8B4424 04 MOV EAX,DWORD PTR SS:[ESP+4] 0056E254 |. 85C0 TEST EAX,EAX */ - _asm + __asm { mov al, bSetCenterOfWorld test al, al @@ -2979,14 +2979,14 @@ void _declspec(naked) HOOK_FindPlayerCentreOfWorld() } } -void _declspec(naked) HOOK_FindPlayerHeading() +void __declspec(naked) HOOK_FindPlayerHeading() { /* 0056E450 /$ 8B4C24 04 MOV ECX,DWORD PTR SS:[ESP+4] 0056E454 |. 8BD1 MOV EDX,ECX */ - _asm + __asm { // Jump if bSetCenterOfWorld is true push eax @@ -3011,9 +3011,9 @@ void _declspec(naked) HOOK_FindPlayerHeading() } // this hook adds a null check to prevent the game crashing when objects are placed really high up (issue 517) -void _declspec(naked) HOOK_CCustomRoadsignMgr__RenderRoadsignAtomic() +void __declspec(naked) HOOK_CCustomRoadsignMgr__RenderRoadsignAtomic() { - _asm + __asm { cmp esi, 0 jz no_render @@ -3041,16 +3041,16 @@ bool CallBreakTowLinkHandler(CVehicleSAInterface* vehicle) return true; } -void _declspec(naked) HOOK_CRadar__DrawRadarGangOverlay() +void __declspec(naked) HOOK_CRadar__DrawRadarGangOverlay() { - _asm + __asm { pushad } if (m_pDrawRadarAreasHandler) m_pDrawRadarAreasHandler(); - _asm + __asm { popad retn @@ -3059,9 +3059,9 @@ void _declspec(naked) HOOK_CRadar__DrawRadarGangOverlay() CVehicleSAInterface* towingVehicle; -void _declspec(naked) HOOK_Trailer_BreakTowLink() +void __declspec(naked) HOOK_Trailer_BreakTowLink() { - _asm + __asm { mov towingVehicle, ecx pushad @@ -3069,7 +3069,7 @@ void _declspec(naked) HOOK_Trailer_BreakTowLink() if (CallBreakTowLinkHandler(towingVehicle)) { - _asm + __asm { popad call dword ptr [edx+0xF8] @@ -3077,13 +3077,13 @@ void _declspec(naked) HOOK_Trailer_BreakTowLink() } else { - _asm + __asm { popad } } - _asm + __asm { mov ecx, HOOKPOS_Trailer_BreakTowLink add ecx, 6 @@ -3117,9 +3117,9 @@ bool CallExplosionHandler() return m_pExplosionHandler(pExplodingEntity, pExplosionCreator, vecExplosionLocation, explosionType); } -void _declspec(naked) HOOK_CExplosion_AddExplosion() +void __declspec(naked) HOOK_CExplosion_AddExplosion() { - _asm + __asm { // Check if explosions are disabled. push eax @@ -3170,7 +3170,7 @@ void _declspec(naked) HOOK_CExplosion_AddExplosion() // Call the explosion handler if (!CallExplosionHandler()) { - _asm + __asm { popad retn // if they return false from the handler, they don't want the explosion to show @@ -3178,13 +3178,13 @@ void _declspec(naked) HOOK_CExplosion_AddExplosion() } else { - _asm + __asm { popad } } - _asm + __asm { noexplosionhandler: @@ -3226,9 +3226,9 @@ bool processGrab() } // 0x67DABE -void _declspec(naked) HOOK_CTaskComplexJump__CreateSubTask() +void __declspec(naked) HOOK_CTaskComplexJump__CreateSubTask() { - _asm + __asm { mov pedPosition, eax mov eax, [esi+28] @@ -3242,7 +3242,7 @@ void _declspec(naked) HOOK_CTaskComplexJump__CreateSubTask() if (processGrab()) { - _asm + __asm { popad mov eax, 0x67DAD6 @@ -3251,7 +3251,7 @@ void _declspec(naked) HOOK_CTaskComplexJump__CreateSubTask() } else { - _asm + __asm { popad mov eax, 0x67DAD1 @@ -3264,9 +3264,9 @@ char* szCreateFxSystem_ExplosionType = 0; DWORD* pCreateFxSystem_Matrix = 0; DWORD* pNewCreateFxSystem_Matrix = 0; -void _declspec(naked) HOOK_FxManager_CreateFxSystem() +void __declspec(naked) HOOK_FxManager_CreateFxSystem() { - _asm + __asm { // Store the explosion type mov eax, [esp+4] @@ -3296,7 +3296,7 @@ void _declspec(naked) HOOK_FxManager_CreateFxSystem() pNewCreateFxSystem_Matrix = pCreateFxSystem_Matrix; } - _asm + __asm { // Restore the registers popad @@ -3317,9 +3317,9 @@ void _declspec(naked) HOOK_FxManager_CreateFxSystem() DWORD dwDestroyFxSystem_Pointer = 0; DWORD* pDestroyFxSystem_Matrix = 0; -void _declspec(naked) HOOK_FxManager_DestroyFxSystem() +void __declspec(naked) HOOK_FxManager_DestroyFxSystem() { - _asm + __asm { // Grab the FxSystem that's being destroyed mov eax, [esp+4] @@ -3335,7 +3335,7 @@ void _declspec(naked) HOOK_FxManager_DestroyFxSystem() // Delete it if it's in our list RemoveFxSystemPointer(pDestroyFxSystem_Matrix); - _asm + __asm { // Restore the registers popad @@ -3364,23 +3364,23 @@ bool CCam_ProcessFixed(class CCamSAInterface* pCamInterface) CCamSAInterface* CCam_ProcessFixed_pCam; -void _declspec(naked) HOOK_CCam_ProcessFixed() +void __declspec(naked) HOOK_CCam_ProcessFixed() { - _asm + __asm { mov CCam_ProcessFixed_pCam, ecx } if (CCam_ProcessFixed(CCam_ProcessFixed_pCam)) { - _asm + __asm { ret 10h } } else { - _asm + __asm { mov ecx, CCam_ProcessFixed_pCam sub esp, 28h @@ -3391,15 +3391,15 @@ void _declspec(naked) HOOK_CCam_ProcessFixed() } } -void _declspec(naked) HOOK_Render3DStuff() +void __declspec(naked) HOOK_Render3DStuff() { - _asm + __asm { pushad } if (m_pRender3DStuffHandler) m_pRender3DStuffHandler(); - _asm + __asm { popad mov eax, FUNC_Render3DStuff @@ -3429,14 +3429,14 @@ bool ProcessPlayerWeapon() return false; } -void _declspec(naked) HOOK_CTaskSimplePlayerOnFoot_ProcessPlayerWeapon() +void __declspec(naked) HOOK_CTaskSimplePlayerOnFoot_ProcessPlayerWeapon() { /* 006859A0 push 0FFFFFFFFh 006859A2 push 846BCEh 006859A7 mov eax,dword ptr fs:[00000000h] */ - _asm + __asm { mov eax, [esp+4] mov pProcessPlayerWeaponPed, eax @@ -3444,7 +3444,7 @@ void _declspec(naked) HOOK_CTaskSimplePlayerOnFoot_ProcessPlayerWeapon() } if (ProcessPlayerWeapon()) { - _asm + __asm { popad push 0FFFFFFFFh @@ -3454,7 +3454,7 @@ void _declspec(naked) HOOK_CTaskSimplePlayerOnFoot_ProcessPlayerWeapon() } else { - _asm + __asm { popad ret 4 @@ -3468,20 +3468,20 @@ bool IsPlayer() return true; } -void _declspec(naked) HOOK_CPed_IsPlayer() +void __declspec(naked) HOOK_CPed_IsPlayer() { /* 005DF8F0 mov eax,dword ptr [ecx+598h] 005DF8F6 test eax,eax */ - _asm + __asm { mov pIsPlayerPed, ecx pushad } if (IsPlayer()) { - _asm + __asm { popad mov eax,dword ptr [ecx+598h] @@ -3490,7 +3490,7 @@ void _declspec(naked) HOOK_CPed_IsPlayer() } else { - _asm + __asm { popad xor al, al @@ -3511,7 +3511,7 @@ void CRunningScript_Process() char szModelName[64]; strcpy(szModelName, "player"); - _asm + __asm { push 26 lea eax, szModelName @@ -3522,7 +3522,7 @@ void CRunningScript_Process() } dwFunc = 0x40EA10; // load all requested models - _asm + __asm { push 1 call dwFunc @@ -3530,7 +3530,7 @@ void CRunningScript_Process() } dwFunc = 0x60D790; // setup player ped - _asm + __asm { push 0 call dwFunc @@ -3538,7 +3538,7 @@ void CRunningScript_Process() } /*dwFunc = 0x05E47E0; // set created by - _asm + __asm { mov edi, 0xB7CD98 mov ecx, [edi] @@ -3547,7 +3547,7 @@ void CRunningScript_Process() } dwFunc = 0x609520; // deactivate player ped - _asm + __asm { push 0 call dwFunc @@ -3558,7 +3558,7 @@ void CRunningScript_Process() fX = 2488.562f; fY = -1666.864f; fZ = 12.8757f; - _asm + __asm { mov edi, 0xB7CD98 push fZ @@ -3569,7 +3569,7 @@ void CRunningScript_Process() } /* dwFunc = 0x609540; // reactivate player ped - _asm + __asm { push 0 call dwFunc @@ -3577,7 +3577,7 @@ void CRunningScript_Process() } dwFunc = 0x61A5A0; // CTask::operator new - _asm + __asm { push 28 call dwFunc @@ -3585,14 +3585,14 @@ void CRunningScript_Process() } dwFunc = 0x685750; // CTaskSimplePlayerOnFoot::CTaskSimplePlayerOnFoot - _asm + __asm { mov ecx, eax call dwFunc } dwFunc = 0x681AF0; // set task - _asm + __asm { mov edi, 0xB7CD98 mov edi, [edi] @@ -3609,16 +3609,16 @@ void CRunningScript_Process() } } -void _declspec(naked) HOOK_CRunningScript_Process() +void __declspec(naked) HOOK_CRunningScript_Process() { - _asm + __asm { pushad } CRunningScript_Process(); - _asm + __asm { popad retn @@ -3626,10 +3626,10 @@ void _declspec(naked) HOOK_CRunningScript_Process() } static CVehicleSAInterface* pDerailingTrain = NULL; -void _declspec(naked) HOOK_CTrain_ProcessControl_Derail() +void __declspec(naked) HOOK_CTrain_ProcessControl_Derail() { // If the train wouldn't derail, don't modify anything - _asm + __asm { jnp train_would_derail mov eax, 0x6F8F89 @@ -3643,7 +3643,7 @@ void _declspec(naked) HOOK_CTrain_ProcessControl_Derail() if (pDerailingTrain->m_pVehicle->IsDerailable()) { // Go back to the derailment code - _asm + __asm { popad mov eax, 0x6F8DC0 @@ -3652,7 +3652,7 @@ void _declspec(naked) HOOK_CTrain_ProcessControl_Derail() } else { - _asm + __asm { popad mov eax, 0x6F8F89 @@ -3682,7 +3682,7 @@ static void SetEntityAlphaHooked(DWORD dwEntity, DWORD dwCallback, DWORD dwAlpha // Call SetRwObjectAlpha DWORD dwFunc = FUNC_SetRwObjectAlpha; - _asm + __asm { mov ecx, dwEntity push dwAlpha @@ -3753,9 +3753,9 @@ static void SetVehicleAlpha() } static DWORD dwCVehicle_SetupRender_ret = 0x6D6517; -void _declspec(naked) HOOK_CVehicle_SetupRender() +void __declspec(naked) HOOK_CVehicle_SetupRender() { - _asm + __asm { mov dwAlphaEntity, esi pushad @@ -3763,7 +3763,7 @@ void _declspec(naked) HOOK_CVehicle_SetupRender() SetVehicleAlpha(); - _asm + __asm { popad add esp, 0x8 @@ -3773,16 +3773,16 @@ void _declspec(naked) HOOK_CVehicle_SetupRender() } static DWORD dwCVehicle_ResetAfterRender_ret = 0x6D0E43; -void _declspec(naked) HOOK_CVehicle_ResetAfterRender() +void __declspec(naked) HOOK_CVehicle_ResetAfterRender() { - _asm + __asm { pushad } RestoreAlphaValues(); - _asm + __asm { popad add esp, 0x0C @@ -3819,18 +3819,32 @@ static void SetObjectAlpha() } } +void Handle_ObjRndr() +{ + TIMING_CHECKPOINT("+ObjRndr"); + SetObjectAlpha(); +} + +void Handle_ObjRndrF() +{ + TIMING_CHECKPOINT("-ObjRndr"); + RestoreAlphaValues(); +} + DWORD dwCObjectRenderRet = 0; -void _declspec(naked) HOOK_CObject_PostRender() +void __declspec(naked) HOOK_CObject_PostRender() { - _asm + __asm { pushad } - TIMING_CHECKPOINT("-ObjRndr"); - RestoreAlphaValues(); + __asm + { + call Handle_ObjRndrF + } - _asm + __asm { popad mov edx, dwCObjectRenderRet @@ -3839,18 +3853,20 @@ void _declspec(naked) HOOK_CObject_PostRender() } // Note: This hook is also called for world objects (light poles, wooden fences, etc). -void _declspec(naked) HOOK_CObject_Render() +void __declspec(naked) HOOK_CObject_Render() { - _asm + __asm { mov dwAlphaEntity, ecx pushad } - TIMING_CHECKPOINT("+ObjRndr"); - SetObjectAlpha(); + __asm + { + call Handle_ObjRndr + } - _asm + __asm { popad mov edx, [esp] @@ -3862,14 +3878,14 @@ void _declspec(naked) HOOK_CObject_Render() if (bObjectIsAGangTag) goto render_a_tag; - _asm + __asm { popad jmp FUNC_CEntity_Render } render_a_tag: - _asm + __asm { popad // We simulate here the header of the CEntity::Render function @@ -3939,9 +3955,9 @@ void _cdecl DoEndWorldColorsPokes() } // Note: This hook is called at the end of the function that sets the world colours (sky gradient, water colour, etc). -void _declspec(naked) HOOK_EndWorldColors() +void __declspec(naked) HOOK_EndWorldColors() { - _asm + __asm { call DoEndWorldColorsPokes ret @@ -3956,9 +3972,9 @@ static DWORD dwObjectsChecked = 0; static DWORD dwProcessVerticalKeepLooping = 0x5632D1; static DWORD dwProcessVerticalEndLooping = 0x56335F; static DWORD dwGlobalListOfObjects = 0xB9ACCC; -void _declspec(naked) HOOK_CWorld_ProcessVerticalLineSectorList() +void __declspec(naked) HOOK_CWorld_ProcessVerticalLineSectorList() { - _asm + __asm { test ebp, ebp jz end_of_entities_list @@ -3985,9 +4001,9 @@ void _declspec(naked) HOOK_CWorld_ProcessVerticalLineSectorList() static DWORD dwChokingChoke = 0x4C05C1; static DWORD dwChokingDontchoke = 0x4C0620; static unsigned char ucChokingWeaponType = 0; -void _declspec(naked) HOOK_ComputeDamageResponse_StartChoking() +void __declspec(naked) HOOK_ComputeDamageResponse_StartChoking() { - _asm + __asm { pushad mov al, [esp+0x8C] @@ -3996,7 +4012,7 @@ void _declspec(naked) HOOK_ComputeDamageResponse_StartChoking() if (m_pChokingHandler && m_pChokingHandler(ucChokingWeaponType) == false) goto dont_choke; - _asm + __asm { popad mov ecx, [edi] @@ -4005,7 +4021,7 @@ void _declspec(naked) HOOK_ComputeDamageResponse_StartChoking() } dont_choke: - _asm + __asm { popad jmp dwChokingDontchoke @@ -4191,7 +4207,7 @@ void CMultiplayerSA::ConvertEulerAnglesToMatrix(CMatrix& Matrix, float fX, float CMatrix_Padded* pMatrixPadded = &matrixPadded; DWORD dwFunc = FUNC_CMatrix__ConvertFromEulerAngles; int iUnknown = 21; - _asm + __asm { push iUnknown push fZ @@ -4218,7 +4234,7 @@ void CMultiplayerSA::ConvertMatrixToEulerAngles(const CMatrix& Matrix, float& fX float* pfY = &fY; float* pfZ = &fZ; int iUnknown = 21; - _asm + __asm { push iUnknown push pfZ @@ -4324,11 +4340,11 @@ void CMultiplayerSA::SetDebugVars(float f1, float f2, float f3) { } -void _declspec(naked) HOOK_CollisionStreamRead() +void __declspec(naked) HOOK_CollisionStreamRead() { if (*(DWORD*)VAR_CollisionStreamRead_ModelInfo) { - _asm + __asm { mov eax, dword ptr fs:[0] jmp RETURN_CollisionStreamRead @@ -4336,7 +4352,7 @@ void _declspec(naked) HOOK_CollisionStreamRead() } else { - _asm + __asm { ret } @@ -4344,9 +4360,9 @@ void _declspec(naked) HOOK_CollisionStreamRead() } unsigned char ucDesignatedLightState = 0; -void _declspec(naked) HOOK_CTrafficLights_GetPrimaryLightState() +void __declspec(naked) HOOK_CTrafficLights_GetPrimaryLightState() { - _asm + __asm { pushad } @@ -4365,7 +4381,7 @@ void _declspec(naked) HOOK_CTrafficLights_GetPrimaryLightState() } else ucDesignatedLightState = 2; // Red - _asm + __asm { popad mov al, ucDesignatedLightState @@ -4373,9 +4389,9 @@ void _declspec(naked) HOOK_CTrafficLights_GetPrimaryLightState() } } -void _declspec(naked) HOOK_CTrafficLights_GetSecondaryLightState() +void __declspec(naked) HOOK_CTrafficLights_GetSecondaryLightState() { - _asm + __asm { pushad } @@ -4394,7 +4410,7 @@ void _declspec(naked) HOOK_CTrafficLights_GetSecondaryLightState() } else ucDesignatedLightState = 2; // Red - _asm + __asm { popad mov al, ucDesignatedLightState @@ -4402,9 +4418,9 @@ void _declspec(naked) HOOK_CTrafficLights_GetSecondaryLightState() } } -void _declspec(naked) HOOK_CTrafficLights_DisplayActualLight() +void __declspec(naked) HOOK_CTrafficLights_DisplayActualLight() { - _asm + __asm { pushad } @@ -4416,7 +4432,7 @@ void _declspec(naked) HOOK_CTrafficLights_DisplayActualLight() else if (ucTrafficLightState == 9) { ucDesignatedLightState = 1; } else { ucDesignatedLightState = 2; } - _asm + __asm { popad movzx eax, ucDesignatedLightState @@ -4443,9 +4459,9 @@ void CheckVehicleMaxGear() } } -void _declspec(naked) HOOK_Transmission_CalculateDriveAcceleration() +void __declspec(naked) HOOK_Transmission_CalculateDriveAcceleration() { - _asm + __asm { push eax mov pCurTransmission, ecx @@ -4457,7 +4473,7 @@ void _declspec(naked) HOOK_Transmission_CalculateDriveAcceleration() CheckVehicleMaxGear(); - _asm + __asm { popad mov eax, [esp+0x10] @@ -4466,10 +4482,10 @@ void _declspec(naked) HOOK_Transmission_CalculateDriveAcceleration() } } -void _declspec(naked) HOOK_isVehDriveTypeNotRWD() +void __declspec(naked) HOOK_isVehDriveTypeNotRWD() { // Get the Vehicle interface from esi - _asm + __asm { mov pHandlingDriveTypeVeh, esi } @@ -4477,17 +4493,17 @@ void _declspec(naked) HOOK_isVehDriveTypeNotRWD() GetVehicleDriveType(); // push our drive type into bl :) - _asm + __asm { mov bl, ucDriveType jmp RETURN_CHandlingData_isNotRWD } } -void _declspec(naked) HOOK_isVehDriveTypeNotFWD() +void __declspec(naked) HOOK_isVehDriveTypeNotFWD() { // Get the Vehicle SA interface from esi - _asm + __asm { mov pHandlingDriveTypeVeh, esi } @@ -4495,7 +4511,7 @@ void _declspec(naked) HOOK_isVehDriveTypeNotFWD() GetVehicleDriveType(); // push our drive type into bl :) - _asm + __asm { mov bl, ucDriveType jmp RETURN_CHandlingData_isNotFWD @@ -4555,7 +4571,7 @@ void CMultiplayerSA::AllowCreatedObjectsInVerticalLineTest(bool bOn) void _cdecl CPhysical_ApplyGravity(DWORD dwThis) { DWORD dwType; - _asm + __asm { mov ecx, dwThis mov eax, 0x46A2C0 // CEntity::GetType @@ -4587,9 +4603,9 @@ void _cdecl CPhysical_ApplyGravity(DWORD dwThis) } const float kfTimeStepOrg = 5.0f / 3.0f; -void _declspec(naked) HOOK_CVehicle_ApplyBoatWaterResistance() +void __declspec(naked) HOOK_CVehicle_ApplyBoatWaterResistance() { - _asm + __asm { fmul ds : 0x871DDC // Original constant used in code fmul ds : 0xB7CB5C // Multiply by current timestep @@ -4598,9 +4614,9 @@ void _declspec(naked) HOOK_CVehicle_ApplyBoatWaterResistance() } } -void _declspec(naked) HOOK_CPhysical_ApplyGravity() +void __declspec(naked) HOOK_CPhysical_ApplyGravity() { - _asm + __asm { push esi call CPhysical_ApplyGravity @@ -4678,9 +4694,9 @@ bool _cdecl VehicleCamStart(DWORD dwCam, DWORD pVehicleInterface) return true; } -void _declspec(naked) HOOK_VehicleCamStart() +void __declspec(naked) HOOK_VehicleCamStart() { - _asm + __asm { push edi push esi @@ -4706,9 +4722,9 @@ void _cdecl VehicleCamTargetZTweak(CVector* pvecCamTarget, float fTargetZTweak) *pvecCamTarget += gravcam_matGravity.vUp * fTargetZTweak; } -void _declspec(naked) HOOK_VehicleCamTargetZTweak() +void __declspec(naked) HOOK_VehicleCamTargetZTweak() { - _asm + __asm { fstp st @@ -4743,9 +4759,9 @@ void _cdecl VehicleCamLookDir1(DWORD dwCam, DWORD pVehicleInterface) *pvecLookDir = gravcam_matInvertGravity * (*pvecLookDir); } -void _declspec(naked) HOOK_VehicleCamLookDir1() +void __declspec(naked) HOOK_VehicleCamLookDir1() { - _asm + __asm { mov eax, 0x59C910 // CVector::Normalise call eax @@ -4776,9 +4792,9 @@ bool _cdecl VehicleCamLookDir2(DWORD dwCam) return true; } -void _declspec(naked) HOOK_VehicleCamLookDir2() +void __declspec(naked) HOOK_VehicleCamLookDir2() { - _asm + __asm { push esi call VehicleCamLookDir2 @@ -4802,9 +4818,9 @@ void _cdecl VehicleCamHistory(DWORD dwCam, CVector* pvecTarget, float fTargetThe ((CVector*)(dwCam + 0x1D8))[1] = *pvecTarget - vecDir * fZoom; } -void _declspec(naked) HOOK_VehicleCamHistory() +void __declspec(naked) HOOK_VehicleCamHistory() { - _asm + __asm { push [esp+0x0+0x7C] // zoom push [esp+0x4+0x2C] // radius @@ -4835,9 +4851,9 @@ void _cdecl VehicleCamUp(DWORD dwCam) pvecUp->Normalize(); } -void _declspec(naked) HOOK_VehicleCamUp() +void __declspec(naked) HOOK_VehicleCamUp() { - _asm + __asm { mov edx, ecx mov ecx, [ecx+0x21C] // CCam::pTargetEntity @@ -4873,9 +4889,9 @@ void _cdecl VehicleCamEnd(DWORD pVehicleInterface) pVehicle->SetMoveSpeed(&gravcam_vecVehicleVelocity); } -void _declspec(naked) HOOK_VehicleCamEnd() +void __declspec(naked) HOOK_VehicleCamEnd() { - _asm + __asm { mov ds:[0xB6F020], edx @@ -4896,9 +4912,9 @@ void _cdecl VehicleLookBehind(DWORD dwCam, CVector* pvecEntityPos, float fDistan MemPutFast(dwCam + 0x19C, *pvecEntityPos + (gravcam_matVehicleTransform.vFront + gravcam_matGravity.vUp * 0.2f) * fDistance); } -void _declspec(naked) HOOK_VehicleLookBehind() +void __declspec(naked) HOOK_VehicleLookBehind() { - _asm + __asm { push [esp+0x14] lea eax, [esp+4+0x1C] @@ -4931,9 +4947,9 @@ void _cdecl VehicleLookAside(DWORD dwCam, CVector* pvecEntityPos, float fDirecti MemPutFast(dwCam + 0x19C, *pvecEntityPos + (-gravcam_matVehicleTransform.vRight * fDirectionFactor + gravcam_matGravity.vUp * 0.2f) * fDistance); } -void _declspec(naked) HOOK_VehicleLookAside() +void __declspec(naked) HOOK_VehicleLookAside() { - _asm + __asm { push [esp+0x14] push [esp+4+0x1C] @@ -4969,9 +4985,9 @@ float _cdecl VehicleBurnCheck(DWORD pVehicleInterface) return matVehicle.vUp.DotProduct(&vecGravity); } -void _declspec(naked) HOOK_OccupiedVehicleBurnCheck() +void __declspec(naked) HOOK_OccupiedVehicleBurnCheck() { - _asm + __asm { push eax call VehicleBurnCheck @@ -4980,9 +4996,9 @@ void _declspec(naked) HOOK_OccupiedVehicleBurnCheck() } } -void _declspec(naked) HOOK_UnoccupiedVehicleBurnCheck() +void __declspec(naked) HOOK_UnoccupiedVehicleBurnCheck() { - _asm + __asm { mov word ptr [esp+0x78], cx @@ -5011,9 +5027,9 @@ void _cdecl ApplyVehicleBlowHop(DWORD pVehicleInterface) pVehicle->SetMoveSpeed(&vecVelocity); } -void _declspec(naked) HOOK_ApplyCarBlowHop() +void __declspec(naked) HOOK_ApplyCarBlowHop() { - _asm + __asm { push esi call ApplyVehicleBlowHop @@ -5030,19 +5046,35 @@ void _declspec(naked) HOOK_ApplyCarBlowHop() // --------------------------------------------------- +void Handle_CWorld_Process() +{ + TIMING_CHECKPOINT("+CWorld_Process"); + if (m_pPreWorldProcessHandler) + m_pPreWorldProcessHandler(); +} + +void Handle_CWorld_ProcessF() +{ + if (m_pPostWorldProcessHandler) + m_pPostWorldProcessHandler(); + + TIMING_CHECKPOINT("-CWorld_Process"); +} + DWORD CALL_CWorld_Process = 0x5684a0; -void _declspec(naked) HOOK_CGame_Process() +void __declspec(naked) HOOK_CGame_Process() { - _asm + __asm { pushad } - TIMING_CHECKPOINT("+CWorld_Process"); - if (m_pPreWorldProcessHandler) - m_pPreWorldProcessHandler(); + __asm + { + call Handle_CWorld_Process + } - _asm + __asm { popad call CALL_CWorld_Process @@ -5050,11 +5082,12 @@ void _declspec(naked) HOOK_CGame_Process() pushad } - if (m_pPostWorldProcessHandler) m_pPostWorldProcessHandler(); - - TIMING_CHECKPOINT("-CWorld_Process"); + __asm + { + call Handle_CWorld_ProcessF + } - _asm + __asm { popad jmp RETURN_CGame_Process; @@ -5074,24 +5107,42 @@ void __cdecl HandleIdle() m_pIdleHandler(); } -DWORD CALL_CGame_Process = 0x53BEE0; -void _declspec(naked) HOOK_Idle() +void CGame_Process() { TIMING_CHECKPOINT("+CGame_Process"); - _asm - { - call CALL_CGame_Process - pushad - } +} +void CGame_ProcessF() +{ TIMING_CHECKPOINT("-CGame_Process"); +} +void Idle() +{ TIMING_CHECKPOINT("+Idle"); if (m_pIdleHandler) HandleIdle(); TIMING_CHECKPOINT("-Idle"); +} - _asm +DWORD CALL_CGame_Process = 0x53BEE0; +void __declspec(naked) HOOK_Idle() +{ + __asm + { + call CGame_Process + call CALL_CGame_Process + pushad + } + + __asm + { + call CGame_ProcessF + + call Idle + } + + __asm { popad mov ecx, 0B6BC90h @@ -5100,9 +5151,9 @@ void _declspec(naked) HOOK_Idle() } // Hooked from 0049E650 5 bytes -void _declspec(naked) HOOK_PreFxRender() +void __declspec(naked) HOOK_PreFxRender() { - _asm + __asm { pushad mov eax,[esp+32+4*2] @@ -5112,7 +5163,7 @@ void _declspec(naked) HOOK_PreFxRender() if (m_pPreFxRenderHandler) m_pPreFxRenderHandler(); - _asm + __asm { skip: popad @@ -5121,16 +5172,16 @@ void _declspec(naked) HOOK_PreFxRender() } // Hooked from 00705099 5 bytes -void _declspec(naked) HOOK_PostColorFilterRender() +void __declspec(naked) HOOK_PostColorFilterRender() { - _asm + __asm { pushad } if (m_pPostColorFilterRenderHandler) m_pPostColorFilterRenderHandler(); - _asm + __asm { popad mov al, ds:0C402BAh @@ -5139,16 +5190,16 @@ void _declspec(naked) HOOK_PostColorFilterRender() } // Hooked from 0053EAD8 5 bytes -void _declspec(naked) HOOK_PreHUDRender() +void __declspec(naked) HOOK_PreHUDRender() { - _asm + __asm { pushad } if (m_pPreHudRenderHandler) m_pPreHudRenderHandler(); - _asm + __asm { popad mov eax, ds:0B6F0B8h @@ -5216,9 +5267,9 @@ void vehicle_lights_init() } CVehicleSAInterface* pLightsVehicleInterface = NULL; -void _declspec(naked) HOOK_CVehicle_DoVehicleLights() +void __declspec(naked) HOOK_CVehicle_DoVehicleLights() { - _asm + __asm { mov pLightsVehicleInterface, ecx mov al,byte ptr ds:[00C1CC18h] @@ -5245,9 +5296,9 @@ void CVehicle_GetHeadLightColor(CVehicleSAInterface* pInterface, float } CVehicleSAInterface* pHeadLightBeamVehicleInterface = NULL; -void _declspec(naked) HOOK_CVehicle_DoHeadLightBeam_1() +void __declspec(naked) HOOK_CVehicle_DoHeadLightBeam_1() { - _asm + __asm { mov pHeadLightBeamVehicleInterface, ecx sub esp, 94h @@ -5269,9 +5320,9 @@ void CVehicle_DoHeadLightBeam() } } -void _declspec(naked) HOOK_CVehicle_DoHeadLightBeam_2() +void __declspec(naked) HOOK_CVehicle_DoHeadLightBeam_2() { - _asm + __asm { mov eax, [esp] mov pHeadLightVerts, eax @@ -5282,7 +5333,7 @@ void _declspec(naked) HOOK_CVehicle_DoHeadLightBeam_2() CVehicle_DoHeadLightBeam(); - _asm + __asm { popad mov dword ptr ds:[0C4B950h],5 @@ -5291,16 +5342,16 @@ void _declspec(naked) HOOK_CVehicle_DoHeadLightBeam_2() } DWORD dwCCoronas_RegisterCorona = 0x6FC580; -void _declspec(naked) HOOK_CVehicle_DoHeadLightEffect_1() +void __declspec(naked) HOOK_CVehicle_DoHeadLightEffect_1() { - _asm + __asm { pushad } CVehicle_GetHeadLightColor(pLightsVehicleInterface, 160.0f, 160.0f, 140.0f); - _asm + __asm { popad mov eax, ulHeadLightR @@ -5318,16 +5369,16 @@ void _declspec(naked) HOOK_CVehicle_DoHeadLightEffect_1() } } -void _declspec(naked) HOOK_CVehicle_DoHeadLightEffect_2() +void __declspec(naked) HOOK_CVehicle_DoHeadLightEffect_2() { - _asm + __asm { pushad } CVehicle_GetHeadLightColor(pLightsVehicleInterface, 160.0f, 160.0f, 140.0f); - _asm + __asm { popad mov eax, ulHeadLightR @@ -5346,16 +5397,16 @@ void _declspec(naked) HOOK_CVehicle_DoHeadLightEffect_2() } DWORD dwCShadows_StoreCarLightShadow = 0x70C500; -void _declspec(naked) HOOK_CVehicle_DoHeadLightReflectionTwin() +void __declspec(naked) HOOK_CVehicle_DoHeadLightReflectionTwin() { - _asm + __asm { pushad } CVehicle_GetHeadLightColor(pLightsVehicleInterface, 45.0f, 45.0f, 45.0f); - _asm + __asm { popad mov eax, ulHeadLightR @@ -5371,16 +5422,16 @@ void _declspec(naked) HOOK_CVehicle_DoHeadLightReflectionTwin() } } -void _declspec(naked) HOOK_CVehicle_DoHeadLightReflectionSingle() +void __declspec(naked) HOOK_CVehicle_DoHeadLightReflectionSingle() { - _asm + __asm { pushad } CVehicle_GetHeadLightColor(pLightsVehicleInterface, 45.0f, 45.0f, 45.0f); - _asm + __asm { popad mov eax, ulHeadLightR @@ -5402,11 +5453,11 @@ void _declspec(naked) HOOK_CVehicle_DoHeadLightReflectionSingle() // Report fire damage, with correct inflictor entity -void _declspec(naked) HOOK_CWorld_SetWorldOnFire() +void __declspec(naked) HOOK_CWorld_SetWorldOnFire() { // Actually pass the pCreatorEntity parameter that this function receives to CFireManager::StartFire // (instead of a null pointer) - _asm + __asm { push 7000 push [esp+0x18+0x14] @@ -5414,10 +5465,10 @@ void _declspec(naked) HOOK_CWorld_SetWorldOnFire() } } -void _declspec(naked) HOOK_CTaskSimplePlayerOnFire_ProcessPed() +void __declspec(naked) HOOK_CTaskSimplePlayerOnFire_ProcessPed() { // Actually pass the fire's pCreatorEntity to the damage event (instead of a null pointer) - _asm + __asm { push 3 push 0x25 @@ -5429,10 +5480,10 @@ void _declspec(naked) HOOK_CTaskSimplePlayerOnFire_ProcessPed() } } -void _declspec(naked) HOOK_CFire_ProcessFire() +void __declspec(naked) HOOK_CFire_ProcessFire() { // Set the new fire's creator to the original fire's creator - _asm + __asm { mov eax, 0x53A450 // CCreepingFire::TryToStartFireAtCoors call eax @@ -5445,10 +5496,10 @@ void _declspec(naked) HOOK_CFire_ProcessFire() } } -void _declspec(naked) HOOK_CExplosion_Update() +void __declspec(naked) HOOK_CExplosion_Update() { // Set the new fire's creator to the explosion's creator - _asm + __asm { mov eax, 0x53A450 // CCreepingFire::TryToStartFireAtCoors call eax @@ -5461,10 +5512,10 @@ void _declspec(naked) HOOK_CExplosion_Update() } } -void _declspec(naked) HOOK_CWeapon_FireAreaEffect() +void __declspec(naked) HOOK_CWeapon_FireAreaEffect() { // Set the new fire's creator to the weapon's owner - _asm + __asm { mov eax, 0x53A450 // CCreepingFire::TryToStartFireAtCoors call eax @@ -5562,9 +5613,9 @@ void CPlantMgr_Render_Post() // and water is not drawn in front of above-water plants (eg if you're looking at a // lake through some high grass). -void _declspec(naked) HOOK_RenderScene_Plants() +void __declspec(naked) HOOK_RenderScene_Plants() { - _asm + __asm { pushad call CPlantMgr_Render_Pre @@ -5584,9 +5635,9 @@ void _declspec(naked) HOOK_RenderScene_Plants() } } -void _declspec(naked) HOOK_RenderScene_end() +void __declspec(naked) HOOK_RenderScene_end() { - _asm + __asm { pushad call CPlantMgr_Render_Pre @@ -5615,10 +5666,10 @@ bool _cdecl IsPlantBelowWater(float fPlantZ, float fWaterZ) return fPlantZ + 2.0f < fWaterZ; } -void _declspec(naked) HOOK_CPlantMgr_Render() +void __declspec(naked) HOOK_CPlantMgr_Render() { // (bCamBelowWater, bRenderingBeforeWater) - _asm + __asm { sub esp, 4 mov eax, esp @@ -5685,9 +5736,9 @@ void CEventHandler_ComputeKnockOffBikeResponse() } DWORD dw_CEventDamage_AffectsPed = 0x4b35a0; -void _declspec(naked) HOOK_CEventHandler_ComputeKnockOffBikeResponse() +void __declspec(naked) HOOK_CEventHandler_ComputeKnockOffBikeResponse() { - _asm + __asm { mov pBikeDamageInterface, ecx mov pBikePedInterface, edx @@ -5698,7 +5749,7 @@ void _declspec(naked) HOOK_CEventHandler_ComputeKnockOffBikeResponse() } CEventHandler_ComputeKnockOffBikeResponse(); - _asm + __asm { popad call dw_CEventDamage_AffectsPed @@ -5747,9 +5798,9 @@ bool CPed_GetWeaponSkill() return false; } -void _declspec(naked) HOOK_CPed_GetWeaponSkill() +void __declspec(naked) HOOK_CPed_GetWeaponSkill() { - _asm + __asm { mov weaponSkillPed, ecx mov eax, [esp+4] @@ -5759,7 +5810,7 @@ void _declspec(naked) HOOK_CPed_GetWeaponSkill() if (CPed_GetWeaponSkill()) { - _asm + __asm { popad mov al, weaponSkill @@ -5768,7 +5819,7 @@ void _declspec(naked) HOOK_CPed_GetWeaponSkill() } else { - _asm + __asm { popad push esi @@ -5788,9 +5839,9 @@ bool _cdecl CPed_AddGogglesModelCheck(void* pPedInterface) return pPed == pGameInterface->GetPools()->GetPedFromRef(1); } -void _declspec(naked) HOOK_CPed_AddGogglesModel() +void __declspec(naked) HOOK_CPed_AddGogglesModel() { - _asm + __asm { push esi call CPed_AddGogglesModelCheck @@ -5822,7 +5873,7 @@ void CMultiplayerSA::DeleteAndDisableGangTags() DWORD* pTagInterface = VAR_TagInfoArray[i << 1]; if (pTagInterface) { - _asm + __asm { push pTagInterface call dwFunc @@ -5832,7 +5883,7 @@ void CMultiplayerSA::DeleteAndDisableGangTags() } dwFunc = FUNC_CTagManager_ShutdownForRestart; - _asm + __asm { call dwFunc } @@ -5884,9 +5935,9 @@ bool CPhysical_ProcessCollisionSectorList() return true; } -void _declspec(naked) HOOK_CPhysical_ProcessCollisionSectorList() +void __declspec(naked) HOOK_CPhysical_ProcessCollisionSectorList() { - _asm + __asm { mov pCollisionPhysicalThis, esi mov pCollisionPhysical, edi @@ -5896,7 +5947,7 @@ void _declspec(naked) HOOK_CPhysical_ProcessCollisionSectorList() // Carry on with collision? (sets the CElement->bUsesCollision flag check) if (CPhysical_ProcessCollisionSectorList()) { - _asm + __asm { popad mov ecx, [eax+4] @@ -5906,7 +5957,7 @@ void _declspec(naked) HOOK_CPhysical_ProcessCollisionSectorList() } else { - _asm + __asm { popad mov ecx, [eax+4] @@ -5966,9 +6017,9 @@ void _cdecl CheckMatrix(float* pMatrix) } // hooked at 7C5A5C 5 bytes -void _declspec(naked) HOOK_CheckAnimMatrix() +void __declspec(naked) HOOK_CheckAnimMatrix() { - _asm + __asm { // Replaced code lea ecx, [esp+054h] @@ -5998,9 +6049,9 @@ void _cdecl SaveVehColors(DWORD dwThis) } } -void _declspec(naked) HOOK_VehCol() +void __declspec(naked) HOOK_VehCol() { - _asm + __asm { // Get vehColors for this vehicle pushad @@ -6022,9 +6073,9 @@ void _declspec(naked) HOOK_VehCol() } } -void _declspec(naked) HOOK_VehColCB() +void __declspec(naked) HOOK_VehColCB() { - _asm + __asm { // Hooked from 004C838D 29 bytes @@ -6056,9 +6107,9 @@ static bool AllowSwingingDoors() return false; } -void _declspec(naked) HOOK_CAutomobile__ProcessSwingingDoor() +void __declspec(naked) HOOK_CAutomobile__ProcessSwingingDoor() { - _asm + __asm { mov dwSwingingDoorAutomobile, esi mov ecx, [esi+eax*4+0x648] @@ -6067,7 +6118,7 @@ void _declspec(naked) HOOK_CAutomobile__ProcessSwingingDoor() if (AllowSwingingDoors()) { - _asm + __asm { popad jmp dwSwingingRet1 @@ -6075,7 +6126,7 @@ void _declspec(naked) HOOK_CAutomobile__ProcessSwingingDoor() } else { - _asm + __asm { popad jmp dwSwingingRet2 @@ -6120,9 +6171,9 @@ bool CheckHasSuspensionChanged() else return false; } -void _declspec(naked) HOOK_ProcessVehicleCollision() +void __declspec(naked) HOOK_ProcessVehicleCollision() { - _asm + __asm { mov pSuspensionInterface, esi pushad @@ -6133,7 +6184,7 @@ void _declspec(naked) HOOK_ProcessVehicleCollision() // When the vehicle's collision is about to be processed, set its per-vehicle // suspension lines as the per-model suspension lines, and restore the per-model lines // afterwards - _asm + __asm { popad push esi @@ -6170,7 +6221,7 @@ void _declspec(naked) HOOK_ProcessVehicleCollision() else { // Skip our code in this case because they haven't changed anything so it'l just cause problems. - _asm + __asm { popad jmp dwSuspensionChangedJump @@ -6226,9 +6277,9 @@ bool CheckRemovedModel() // Binary // Hook 1 -void _declspec(naked) HOOK_LoadIPLInstance() +void __declspec(naked) HOOK_LoadIPLInstance() { - _asm + __asm { pushad mov pEntityWorldAdd, ecx @@ -6237,7 +6288,7 @@ void _declspec(naked) HOOK_LoadIPLInstance() { CheckRemovedModel(); } - _asm + __asm { popad jmp CALL_LoadIPLInstance @@ -6285,15 +6336,15 @@ void HideEntitySomehow() } // Binary // Hook 2 -void _declspec(naked) HOOK_CWorld_LOD_SETUP() +void __declspec(naked) HOOK_CWorld_LOD_SETUP() { - _asm + __asm { pushad mov pLODInterface, esi } HideEntitySomehow(); - _asm + __asm { popad jmp CALL_CWorld_LODSETUP @@ -6311,15 +6362,15 @@ void StorePointerToBuilding() // Called when a data entity is added to the world (this happens once when the game loads so we just dump those in a list and we can sift through when someone // tries to remove.) -void _declspec(naked) Hook_AddBuildingInstancesToWorld() +void __declspec(naked) Hook_AddBuildingInstancesToWorld() { - _asm + __asm { pushad mov pBuildingAdd, edx } StorePointerToBuilding(); - _asm + __asm { popad jmp JMP_CWorld_Add_AddBuildingInstancesToWorld_CALL_CWorldAdd @@ -6343,16 +6394,16 @@ bool CheckForRemoval() } // Call to CWorld::Add in CPopulation::ConvertToRealObject we just use this to get a list of pointers to valid objects for instant removal -void _declspec(naked) Hook_CWorld_ADD_CPopulation_ConvertToRealObject() +void __declspec(naked) Hook_CWorld_ADD_CPopulation_ConvertToRealObject() { - _asm + __asm { pushad mov pBuildingAdd, esi mov pLODInterface, esi } StorePointerToBuilding(); - _asm + __asm { popad jmp JMP_CWorld_Add_CPopulation_ConvertToRealObject_CallCWorldAdd @@ -6382,15 +6433,15 @@ void RemoveObjectIfNeeded() } // on stream in -> create and remove it from the world just after so we can restore easily -void _declspec(naked) HOOK_ConvertToObject_CPopulationManageDummy() +void __declspec(naked) HOOK_ConvertToObject_CPopulationManageDummy() { - _asm + __asm { pushad mov pBuildingAdd, edx mov pLODInterface, edx } - _asm + __asm { popad push edx @@ -6400,7 +6451,7 @@ void _declspec(naked) HOOK_ConvertToObject_CPopulationManageDummy() pushad } RemoveObjectIfNeeded(); - _asm + __asm { popad jmp JMP_RETN_Cancel_CPopulation_ManageDummy @@ -6419,21 +6470,30 @@ void RemovePointerToBuilding() DWORD dwCWorldRemove = 0x563280; // Call to CWorld::Remove in CPopulation::ConvertToDummyObject this is called just before deleting a CObject so we remove the CObject while we are there and // remove the new dummy if we need to do so before returning -void _declspec(naked) HOOK_CWorld_Remove_CPopulation_ConvertToDummyObject() +void Handle_CWorld_Remove_CPopulation_ConvertToDummyObject() { - _asm + TIMING_CHECKPOINT("+RemovePointerToBuilding"); + RemovePointerToBuilding(); + StorePointerToBuilding(); + RemoveObjectIfNeeded(); + TIMING_CHECKPOINT("-RemovePointerToBuilding"); +} + +void __declspec(naked) HOOK_CWorld_Remove_CPopulation_ConvertToDummyObject(){ + __asm { pushad mov pBuildingRemove, esi mov pBuildingAdd, edi mov pLODInterface, edi } - TIMING_CHECKPOINT("+RemovePointerToBuilding"); - RemovePointerToBuilding(); - StorePointerToBuilding(); - RemoveObjectIfNeeded(); - TIMING_CHECKPOINT("-RemovePointerToBuilding"); - _asm + + __asm + { + call Handle_CWorld_Remove_CPopulation_ConvertToDummyObject + } + + __asm { popad jmp dwCWorldRemove @@ -6453,22 +6513,38 @@ void RemoveDummyIfReplaced() } } +void Handle_CheckForRemoval() +{ + TIMING_CHECKPOINT("+CheckForRemoval"); +} + +void Handle_CheckForRemovalF() +{ + TIMING_CHECKPOINT("-CheckForRemoval"); +} + // Function that handles dummy -> object so we can cancel this process if need be -void _declspec(naked) HOOK_CWorld_Add_CPopulation_ConvertToDummyObject() +void __declspec(naked) HOOK_CWorld_Add_CPopulation_ConvertToDummyObject() { - _asm + __asm { pushad mov pLODInterface, edi mov pBuildingAdd, edi } - TIMING_CHECKPOINT("+CheckForRemoval"); + __asm + { + call Handle_CheckForRemoval + } StorePointerToBuilding(); if (CheckForRemoval()) { - TIMING_CHECKPOINT("-CheckForRemoval"); - _asm + __asm + { + call Handle_CheckForRemovalF + } + __asm { popad jmp JMP_RETN_Cancelled_CPopulation_ConvertToDummyObject @@ -6476,8 +6552,11 @@ void _declspec(naked) HOOK_CWorld_Add_CPopulation_ConvertToDummyObject() } else { - TIMING_CHECKPOINT("-CheckForRemoval"); - _asm + __asm + { + call Handle_CheckForRemovalF + } + __asm { popad push edi @@ -6488,30 +6567,30 @@ void _declspec(naked) HOOK_CWorld_Add_CPopulation_ConvertToDummyObject() } // Destructors to catch element deletion so we can delete their entries -void _declspec(naked) Hook_CBuilding_DTR() +void __declspec(naked) Hook_CBuilding_DTR() { - _asm + __asm { pushad mov pBuildingRemove, ecx } RemovePointerToBuilding(); - _asm + __asm { popad jmp JMP_CBuilding_DTR } } -void _declspec(naked) Hook_CDummy_DTR() +void __declspec(naked) Hook_CDummy_DTR() { - _asm + __asm { pushad mov pBuildingRemove, ecx } RemovePointerToBuilding(); - _asm + __asm { popad jmp JMP_CDummy_DTR @@ -6519,15 +6598,15 @@ void _declspec(naked) Hook_CDummy_DTR() } DWORD dwObjectVtbl = 0x866F60; -void _declspec(naked) Hook_CObject_DTR() +void __declspec(naked) Hook_CObject_DTR() { - _asm + __asm { pushad mov pBuildingRemove, esi } RemovePointerToBuilding(); - _asm + __asm { popad mov dword ptr [esi], offset dwObjectVtbl @@ -6537,9 +6616,9 @@ void _declspec(naked) Hook_CObject_DTR() static DWORD dwEntityVtbl; static DWORD dwMultResult; -void _declspec(naked) HOOK_CEntity_IsOnScreen_FixObjectScale() +void __declspec(naked) HOOK_CEntity_IsOnScreen_FixObjectScale() { - _asm + __asm { push 0xB6FA74 @@ -6550,7 +6629,7 @@ void _declspec(naked) HOOK_CEntity_IsOnScreen_FixObjectScale() if (dwEntityVtbl == 0x866F60) goto IsOnScreen_IsObject; - _asm + __asm { popad mov esi, ecx @@ -6558,7 +6637,7 @@ void _declspec(naked) HOOK_CEntity_IsOnScreen_FixObjectScale() } IsOnScreen_IsObject: - _asm + __asm { popad fld [eax+0x24] @@ -6573,9 +6652,9 @@ void _declspec(naked) HOOK_CEntity_IsOnScreen_FixObjectScale() ////////////////////////////////////////////////////////////////////////////////////////// // Only allow rebuild player on CJ - Stops other models getting corrupted (spider CJ) // hooked at 5A82C0 8 bytes -void _declspec(naked) HOOK_CClothes_RebuildPlayer() +void __declspec(naked) HOOK_CClothes_RebuildPlayer() { - _asm + __asm { push esi mov esi, [esp+8] @@ -6592,13 +6671,13 @@ void _declspec(naked) HOOK_CClothes_RebuildPlayer() } } -void _declspec(naked) HOOK_CProjectileInfo_Update_FindLocalPlayer_FindLocalPlayerVehicle() +void __declspec(naked) HOOK_CProjectileInfo_Update_FindLocalPlayer_FindLocalPlayerVehicle() { // 00739559 E8 B2 4C E3 FF call FindPlayerPed < HOOK > // 00739570 E8 5B 4B E3 FF call FindPlayerVehicle < HOOK > // Checks if the creator is the local player ped or the creator is the local player peds vehicle else decreases the velocity substantially. // We are forcing it to think the creator is not the local player ped or his vehicle for this specific check - _asm + __asm { xor eax, eax retn @@ -6632,7 +6711,7 @@ bool CallHeliKillEvent() return true; } -void _declspec(naked) HOOK_CHeli_ProcessHeliKill() +void __declspec(naked) HOOK_CHeli_ProcessHeliKill() { // 006DB201 0F 85 30 02 00 00 jnz loc_6DB437 < HOOK > // 006DB207 8B 47 14 mov eax, [edi+14h] < RETURN CONTINUE > @@ -6641,7 +6720,7 @@ void _declspec(naked) HOOK_CHeli_ProcessHeliKill() // We hook just after the check if he's touched the blade as before that it's just got the results of if he's near enough the heli to hit the blades // esi = Heli // edi = ped - _asm + __asm { pushfd pushad @@ -6651,7 +6730,7 @@ void _declspec(naked) HOOK_CHeli_ProcessHeliKill() // Call our event if (CallHeliKillEvent() == false) { - _asm + __asm { popad popfd @@ -6661,7 +6740,7 @@ void _declspec(naked) HOOK_CHeli_ProcessHeliKill() } else { - _asm + __asm { popad popfd @@ -6692,7 +6771,7 @@ bool TriggerObjectDamageEvent() return true; } -void _declspec(naked) HOOK_CObject_ProcessDamage() +void __declspec(naked) HOOK_CObject_ProcessDamage() { // .text:005A0DF7 mov ecx, [esi+160h] // .text:005A0DFD fld [esp+0D4h+arg_0] @@ -6700,7 +6779,7 @@ void _declspec(naked) HOOK_CObject_ProcessDamage() // .text:005A0E07 fsubr dword ptr [esi+154h] // .text:005A0E0D fst dword ptr [esi+154h] - _asm + __asm { pushad mov pDamagedObject, esi @@ -6710,7 +6789,7 @@ void _declspec(naked) HOOK_CObject_ProcessDamage() if (TriggerObjectDamageEvent()) { bObjectDamaged = true; - _asm + __asm { popad fst dword ptr [esi+154h] @@ -6720,7 +6799,7 @@ void _declspec(naked) HOOK_CObject_ProcessDamage() else { bObjectDamaged = false; - _asm + __asm { popad ffree st(0) @@ -6740,9 +6819,9 @@ bool TriggerObjectBreakEvent() return true; } -void _declspec(naked) HOOK_CObject_ProcessBreak() +void __declspec(naked) HOOK_CObject_ProcessBreak() { - _asm + __asm { pushad } @@ -6755,7 +6834,7 @@ void _declspec(naked) HOOK_CObject_ProcessBreak() if (!TriggerObjectBreakEvent()) { bObjectDamaged = false; - _asm + __asm { popad jmp RETURN_CObject_ProcessDamage_Cancel @@ -6764,7 +6843,7 @@ void _declspec(naked) HOOK_CObject_ProcessBreak() } } - _asm + __asm { popad cmp eax, 0C9h @@ -6772,11 +6851,11 @@ void _declspec(naked) HOOK_CObject_ProcessBreak() } } -void _declspec(naked) HOOK_CObject_ProcessCollision() +void __declspec(naked) HOOK_CObject_ProcessCollision() { if (bObjectDamaged) { - _asm + __asm { test byte ptr [esi+1Ch], 1 jnz checkfordynamic @@ -6788,7 +6867,7 @@ void _declspec(naked) HOOK_CObject_ProcessCollision() } else { - _asm + __asm { jmp RETURN_CObject_ProcessCollision } @@ -6796,9 +6875,9 @@ void _declspec(naked) HOOK_CObject_ProcessCollision() } DWORD WindowRespondsToCollision_CalledFrom = 0; -void _declspec(naked) HOOK_CGlass_WindowRespondsToCollision() +void __declspec(naked) HOOK_CGlass_WindowRespondsToCollision() { - _asm + __asm { push eax mov eax, [esp + 4] @@ -6810,7 +6889,7 @@ void _declspec(naked) HOOK_CGlass_WindowRespondsToCollision() if (WindowRespondsToCollision_CalledFrom != CALL_FROM_CGlass_WindowRespondsToExplosion) { - _asm + __asm { mov pDamagedObject, esi } @@ -6821,7 +6900,7 @@ void _declspec(naked) HOOK_CGlass_WindowRespondsToCollision() WindowRespondsToCollision_CalledFrom == CALL_FROM_CPhysical_ApplyCollision_2 || WindowRespondsToCollision_CalledFrom == CALL_FROM_CPhysical_ApplySoftCollision) { - _asm + __asm { mov pObjectAttacker, edi } @@ -6829,14 +6908,14 @@ void _declspec(naked) HOOK_CGlass_WindowRespondsToCollision() if (WindowRespondsToCollision_CalledFrom == CALL_FROM_CGlass_WasGlassHitByBullet) { - _asm + __asm { mov pObjectAttacker, ebx // WasGlassHitByBullet called from CWeapon::DoBulletImpact } if (!pObjectAttacker || (pObjectAttacker && !pObjectAttacker->m_pRwObject)) // WasGlassHitByBullet called from CBulletInfo::Update { - _asm + __asm { push ecx mov ecx, [edi] @@ -6848,7 +6927,7 @@ void _declspec(naked) HOOK_CGlass_WindowRespondsToCollision() if (WindowRespondsToCollision_CalledFrom == CALL_FROM_CGlass_WindowRespondsToExplosion) { - _asm + __asm { mov pDamagedObject, edx mov pObjectAttacker, ebp @@ -6860,7 +6939,7 @@ void _declspec(naked) HOOK_CGlass_WindowRespondsToCollision() if (TriggerObjectBreakEvent()) { - _asm + __asm { sub esp, 68h push esi @@ -6870,7 +6949,7 @@ void _declspec(naked) HOOK_CGlass_WindowRespondsToCollision() } else { - _asm + __asm { retn } @@ -6879,9 +6958,9 @@ void _declspec(naked) HOOK_CGlass_WindowRespondsToCollision() // Called when glass object is being broken by ped melee attack DWORD dummy_404350 = 0x404350; -void _declspec(naked) HOOK_CGlass__BreakGlassPhysically() +void __declspec(naked) HOOK_CGlass__BreakGlassPhysically() { - _asm + __asm { mov pDamagedObject, esi push ecx @@ -6892,7 +6971,7 @@ void _declspec(naked) HOOK_CGlass__BreakGlassPhysically() if (TriggerObjectBreakEvent()) { - _asm + __asm { // restore replaced part push dummy_404350 @@ -6902,7 +6981,7 @@ void _declspec(naked) HOOK_CGlass__BreakGlassPhysically() } else { - _asm + __asm { pop edi pop esi @@ -6923,9 +7002,9 @@ void FxManager_c__DestroyFxSystem() } } -void _declspec(naked) HOOK_FxManager_c__DestroyFxSystem() +void __declspec(naked) HOOK_FxManager_c__DestroyFxSystem() { - _asm + __asm { mov pFxSystemToBeDestroyed, edi pushad @@ -6933,7 +7012,7 @@ void _declspec(naked) HOOK_FxManager_c__DestroyFxSystem() FxManager_c__DestroyFxSystem(); - _asm + __asm { popad @@ -6957,16 +7036,16 @@ void CTaskSimpleGangDriveBy__ProcessPed() } DWORD RETURN_CTaskSimpleGangDriveBy_ProcessPed_Cancel = 0x62D5C1; -void _declspec(naked) HOOK_CTaskSimpleGangDriveBy__ProcessPed() +void __declspec(naked) HOOK_CTaskSimpleGangDriveBy__ProcessPed() { // esi contains 'this' - _asm + __asm { mov pProcessedGangDriveBySimpleTask, esi pushad } CTaskSimpleGangDriveBy__ProcessPed(); - _asm + __asm { popad // Replaced code @@ -7149,12 +7228,12 @@ bool ChooseMusicTrackIndex_SteamFix() These are as a result of the fact that steam updated gta-sa.exe and gta_sa.exe is our old exe which contains the arrays the game had originally for audio files All the files related to the deleted audio are zeroed and decompress to 5kb 0 length files which includes intros and outros. */ -void _declspec(naked) HOOK_CAERadioTrackManager__ChooseMusicTrackIndex() +void __declspec(naked) HOOK_CAERadioTrackManager__ChooseMusicTrackIndex() { // esi is our station id // al has the random number picked (music id the game wants to play) - _asm + __asm { add esp, 8 // fix the stack from the function call above as we overrote this instruction pushad // save our registers @@ -7165,7 +7244,7 @@ void _declspec(naked) HOOK_CAERadioTrackManager__ChooseMusicTrackIndex() // returns true if this is a restricted song if (ChooseMusicTrackIndex_SteamFix()) { - _asm + __asm { // pop the stack popad @@ -7176,7 +7255,7 @@ void _declspec(naked) HOOK_CAERadioTrackManager__ChooseMusicTrackIndex() } } // looks good, carry on - _asm + __asm { // pop the stack popad @@ -7188,9 +7267,9 @@ void _declspec(naked) HOOK_CAERadioTrackManager__ChooseMusicTrackIndex() } // Use AI heli rotor sound if player sound bank is not loaded -void _declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyHeli() +void __declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyHeli() { - _asm + __asm { // push our argument push [esp+8Ch+4] @@ -7203,9 +7282,9 @@ void _declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyHeli() } // Use AI plane propeller sound if player sound bank is not loaded -void _declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyProp() +void __declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyProp() { - _asm + __asm { // push our argument push [esp+98h+4] @@ -7218,9 +7297,9 @@ void _declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyProp() } const float kfTimeStepOriginal = 1.66f; -void _declspec(naked) HOOK_CTaskSimpleSwim_ProcessSwimmingResistance() +void __declspec(naked) HOOK_CTaskSimpleSwim_ProcessSwimmingResistance() { - _asm + __asm { fsub st, st(1) @@ -7279,7 +7358,7 @@ void PostCWorld_ProcessPedsAfterPreRender() } const DWORD CWorld_ProcessPedsAfterPreRender = 0x563430; -void _declspec(naked) HOOK_Idle_CWorld_ProcessPedsAfterPreRender() +void __declspec(naked) HOOK_Idle_CWorld_ProcessPedsAfterPreRender() { __asm { @@ -7303,9 +7382,9 @@ void CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_ChangeStation(DWORD } // Start radio after entering audio zone -void _declspec(naked) HOOK_CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_StartRadio() +void __declspec(naked) HOOK_CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_StartRadio() { - _asm + __asm { push [esi+3] call CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_ChangeStation @@ -7320,9 +7399,9 @@ void _declspec(naked) HOOK_CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume } // Stop radio after leaving audio zone -void _declspec(naked) HOOK_CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_StopRadio() +void __declspec(naked) HOOK_CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_StopRadio() { - _asm + __asm { push 0 call CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_ChangeStation @@ -7354,9 +7433,9 @@ static void AddVehicleColoredDebris(CAutomobileSAInterface* pVehicleInterface, C } const DWORD RETURN_CAutomobile__dmgDrawCarCollidingParticles = 0x6A7081; -void _declspec(naked) HOOK_CAutomobile__dmgDrawCarCollidingParticles() +void __declspec(naked) HOOK_CAutomobile__dmgDrawCarCollidingParticles() { - _asm + __asm { lea eax, [esp + 0x1C] push ebp // count @@ -7377,9 +7456,9 @@ static void TakePhotograph() } const DWORD RETURN_CWeapon__TakePhotograph = 0x73C273; -void _declspec(naked) HOOK_CWeapon__TakePhotograph() +void __declspec(naked) HOOK_CWeapon__TakePhotograph() { - _asm + __asm { // Restore instructions replaced by hook add esp, 8 @@ -7419,9 +7498,9 @@ bool CanEntityCollideWithCamera(CEntitySAInterface* pEntity) return true; } -void _declspec(naked) HOOK_CCollision__CheckCameraCollisionObjects() +void __declspec(naked) HOOK_CCollision__CheckCameraCollisionObjects() { - _asm + __asm { // Restore instructions replaced by hook jz out2 diff --git a/Client/multiplayer_sa/premake5.lua b/Client/multiplayer_sa/premake5.lua index 1d2386c9a5..c49a2ccac6 100644 --- a/Client/multiplayer_sa/premake5.lua +++ b/Client/multiplayer_sa/premake5.lua @@ -6,11 +6,11 @@ project "Multiplayer SA" -- HACK(Jusonex): Temp fix for ebp not being set in naked functions -- VS2019 changed the evaluation order as required by the C++17 standard - -- which broke all functions marked with _declspec(naked) that call C++ code + -- which broke all functions marked with __declspec(naked) that call C++ code -- Falling back to the old, C++14 implementing fixes this -- See https://developercommunity.visualstudio.com/content/problem/549628/stack-access-broken-in-naked-function.html -- We're not aware of any workaround to avoid rewriting multiplayer_sa - cppdialect "C++14" + cppdialect "C++20" filter "system:windows" includedirs { "../../vendor/sparsehash/src/windows" } From 903f812da768b2b4f37cadc55380974d2e9f6c57 Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Fri, 6 Sep 2024 22:29:24 +0300 Subject: [PATCH 15/19] Test fix game_sa --- Client/game_sa/CFileLoaderSA.cpp | 6 +++--- Client/game_sa/CWorldSA.cpp | 9 +++++++-- Client/game_sa/HookSystem.h | 6 ++++-- Client/game_sa/premake5.lua | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Client/game_sa/CFileLoaderSA.cpp b/Client/game_sa/CFileLoaderSA.cpp index 67cb476cf5..c446bd23d3 100644 --- a/Client/game_sa/CFileLoaderSA.cpp +++ b/Client/game_sa/CFileLoaderSA.cpp @@ -37,15 +37,15 @@ CEntitySAInterface* CFileLoaderSA::LoadObjectInstance(SFileObjectInstance* obj) class CAtomicModelInfo { public: - void CAtomicModelInfo::DeleteRwObject() { ((void(__thiscall*)(CAtomicModelInfo*))(*(void***)this)[8])(this); } + void DeleteRwObject() { ((void(__thiscall*)(CAtomicModelInfo*))(*(void***)this)[8])(this); } - void CAtomicModelInfo::SetAtomic(RpAtomic* atomic) { ((void(__thiscall*)(CAtomicModelInfo*, RpAtomic*))(*(void***)this)[15])(this, atomic); } + void SetAtomic(RpAtomic* atomic) { ((void(__thiscall*)(CAtomicModelInfo*, RpAtomic*))(*(void***)this)[15])(this, atomic); } }; class CDamagableModelInfo { public: - void CDamagableModelInfo::SetDamagedAtomic(RpAtomic* atomic) { ((void(__thiscall*)(CDamagableModelInfo*, RpAtomic*))0x4C48D0)(this, atomic); } + void SetDamagedAtomic(RpAtomic* atomic) { ((void(__thiscall*)(CDamagableModelInfo*, RpAtomic*))0x4C48D0)(this, atomic); } }; static char* GetFrameNodeName(RwFrame* frame) diff --git a/Client/game_sa/CWorldSA.cpp b/Client/game_sa/CWorldSA.cpp index a60e360464..538c9098e5 100644 --- a/Client/game_sa/CWorldSA.cpp +++ b/Client/game_sa/CWorldSA.cpp @@ -89,9 +89,14 @@ void CWorldSA::InstallHooks() DWORD CONTINUE_CWorld_FallenPeds = 0x00565CBA; DWORD CONTINUE_CWorld_FallenCars = 0x00565E8A; +bool IsUnderWorldWarpEnabled() +{ + return pGame && pGame->IsUnderWorldWarpEnabled(); +} + void _declspec(naked) HOOK_FallenPeds() { - if (pGame && pGame->IsUnderWorldWarpEnabled()) + if (IsUnderWorldWarpEnabled()) { _asm { @@ -112,7 +117,7 @@ void _declspec(naked) HOOK_FallenPeds() void _declspec(naked) HOOK_FallenCars() { - if (pGame && pGame->IsUnderWorldWarpEnabled()) + if (IsUnderWorldWarpEnabled()) { _asm { diff --git a/Client/game_sa/HookSystem.h b/Client/game_sa/HookSystem.h index 19f145a2b7..bfc087babd 100644 --- a/Client/game_sa/HookSystem.h +++ b/Client/game_sa/HookSystem.h @@ -11,6 +11,8 @@ #pragma once +#include "gamesa_init.h" + #define MAX_JUMPCODE_SIZE 20 template @@ -24,6 +26,8 @@ void* FunctionPointerToVoidP(T func) return c.b; } +BYTE* CreateJump(DWORD dwFrom, DWORD dwTo, BYTE* ByteArray); + template bool HookInstall(DWORD dwInstallAddress, T dwHookHandler, int iJmpCodeSize = 5) { @@ -40,8 +44,6 @@ bool HookInstall(DWORD dwInstallAddress, T dwHookHandler, int iJmpCodeSize = 5) } } -BYTE* CreateJump(DWORD dwFrom, DWORD dwTo, BYTE* ByteArray); - // Auto detect requirement of US/EU hook installation #define EZHookInstall(type) \ HookInstall(HOOKPOS_##type, (DWORD)HOOK_##type, HOOKSIZE_##type); diff --git a/Client/game_sa/premake5.lua b/Client/game_sa/premake5.lua index 588a4178cc..8477058369 100644 --- a/Client/game_sa/premake5.lua +++ b/Client/game_sa/premake5.lua @@ -6,7 +6,7 @@ project "Game SA" -- HACK(Jusonex): Temp fix for ebp not being set in naked functions -- More information on this in multiplayer_sa's premake5.lua - cppdialect "C++14" + cppdialect "C++20" pchheader "StdInc.h" pchsource "StdInc.cpp" From 10af729a34b53d548a54871d778d2c970bc453f6 Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:18:56 +0300 Subject: [PATCH 16/19] std::string from CCommands --- Client/core/CCommands.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/Client/core/CCommands.cpp b/Client/core/CCommands.cpp index 285ef11c78..c9b578a3e5 100644 --- a/Client/core/CCommands.cpp +++ b/Client/core/CCommands.cpp @@ -84,25 +84,24 @@ bool CCommands::Execute(const char* szCommandLine) bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool bHandleRemotely, bool bIsScriptedBind) { // Copy szParametersIn so the contents can be changed - std::unique_ptr szParameters = nullptr; + std::string strParameters; if (szParametersIn) { - szParameters = std::make_unique(strlen(szParametersIn) + 1); - std::strcpy(szParameters.get(), szParametersIn); + strParameters = std::string(szParametersIn, strlen(szParametersIn)); } // HACK: if its a 'chatboxsay' command, use the next parameter // Is the command "say" and the arguments start with /? (command comes from the chatbox) if (!bIsScriptedBind && !stricmp(szCommand, "chatboxsay")) { - if (szParameters) + if (!strParameters.empty()) { // His line starts with '/'? - if (szParameters[0] == '/') + if (strParameters[0] == '/') { // Copy the characters after the slash to the 0 terminator to a seperate buffer std::array szBuffer = {}; - strncpy(szBuffer.data(), szParameters.get() + 1, szBuffer.size() - 1); + strncpy(szBuffer.data(), strParameters.c_str() + 1, szBuffer.size() - 1); szBuffer.back() = '\0'; // Split it into command and arguments @@ -110,15 +109,13 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool if (!szCommand) return false; - if (char* szNewParameters = strtok(nullptr, "\0"); szNewParameters) + if (char* szNewParameters = strtok(nullptr, "\0")) { - szParameters = std::make_unique(strlen(szNewParameters) + 1); - std::strcpy(szParameters.get(), szNewParameters); + strParameters = std::string(szNewParameters, strlen(szNewParameters)); } else { - szParameters = std::make_unique(1); - szParameters[0] = '\0'; + strParameters.clear(); } } } @@ -136,14 +133,14 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool { // Execute it if (!bIsScriptedBind || pEntry->bAllowScriptedBind) - ExecuteHandler(pEntry->pfnCmdFunc, szParameters.get()); + ExecuteHandler(pEntry->pfnCmdFunc, strParameters.c_str()); wasHandled = true; } } // Recompose the original command text - std::string val = std::string(szCommand) + " " + std::string(szParameters ? szParameters.get() : ""); + std::string val = std::string(szCommand) + " " + std::string(!strParameters.empty() ? strParameters : ""); // Is it a cvar? (syntax: cvar[ = value]) if (!wasHandled) @@ -194,15 +191,15 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool // HACK: if its a 'nick' command, save it here bool bIsNickCommand = !stricmp(szCommand, "nick"); - if (!wasHandled && bIsNickCommand && szParameters && !bIsScriptedBind) + if (!wasHandled && bIsNickCommand && !strParameters.empty() && !bIsScriptedBind) { - if (CCore::GetSingleton().IsValidNick(szParameters.get())) + if (CCore::GetSingleton().IsValidNick(strParameters.c_str())) { - CVARS_SET("nick", std::string(szParameters.get())); + CVARS_SET("nick", strParameters); if (!CCore::GetSingleton().IsConnected()) { - CCore::GetSingleton().GetConsole()->Printf("nick: You are now known as %s", szParameters.get()); + CCore::GetSingleton().GetConsole()->Print(std::format("nick: You are now known as {}", strParameters).c_str()); } } else if (!CCore::GetSingleton().IsConnected()) @@ -215,7 +212,7 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool if (m_pfnExecuteHandler) { bool bAllowScriptedBind = (!pEntry || pEntry->bAllowScriptedBind); - if (m_pfnExecuteHandler(szCommand, szParameters.get(), bHandleRemotely, wasHandled, bIsScriptedBind, bAllowScriptedBind)) + if (m_pfnExecuteHandler(szCommand, strParameters.c_str(), bHandleRemotely, wasHandled, bIsScriptedBind, bAllowScriptedBind)) return true; } From 062cdff91517c279469ecea3827d284bad38128b Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:42:20 +0300 Subject: [PATCH 17/19] Refactoring changes --- Client/core/CCommands.cpp | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/Client/core/CCommands.cpp b/Client/core/CCommands.cpp index c9b578a3e5..a3a6c399fd 100644 --- a/Client/core/CCommands.cpp +++ b/Client/core/CCommands.cpp @@ -84,11 +84,7 @@ bool CCommands::Execute(const char* szCommandLine) bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool bHandleRemotely, bool bIsScriptedBind) { // Copy szParametersIn so the contents can be changed - std::string strParameters; - if (szParametersIn) - { - strParameters = std::string(szParametersIn, strlen(szParametersIn)); - } + std::string strParameters = szParametersIn ? std::string(szParametersIn, strlen(szParametersIn)) : ""; // HACK: if its a 'chatboxsay' command, use the next parameter // Is the command "say" and the arguments start with /? (command comes from the chatbox) @@ -101,15 +97,15 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool { // Copy the characters after the slash to the 0 terminator to a seperate buffer std::array szBuffer = {}; - strncpy(szBuffer.data(), strParameters.c_str() + 1, szBuffer.size() - 1); + std::strncpy(szBuffer.data(), strParameters.c_str() + 1, szBuffer.size() - 1); szBuffer.back() = '\0'; // Split it into command and arguments - szCommand = strtok(szBuffer.data(), " "); + szCommand = std::strtok(szBuffer.data(), " "); if (!szCommand) return false; - if (char* szNewParameters = strtok(nullptr, "\0")) + if (char* szNewParameters = std::strtok(nullptr, "\0")) { strParameters = std::string(szNewParameters, strlen(szNewParameters)); } @@ -126,21 +122,19 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool // Grab the command tagCOMMANDENTRY* pEntry = Get(szCommand); bool wasHandled = false; - if (pEntry) + + // If its a core command, or if its enabled + if (pEntry && (!pEntry->bModCommand || pEntry->bEnabled)) { - // If its a core command, or if its enabled - if (!pEntry->bModCommand || pEntry->bEnabled) - { - // Execute it - if (!bIsScriptedBind || pEntry->bAllowScriptedBind) - ExecuteHandler(pEntry->pfnCmdFunc, strParameters.c_str()); - - wasHandled = true; - } + // Execute it + if (!bIsScriptedBind || pEntry->bAllowScriptedBind) + ExecuteHandler(pEntry->pfnCmdFunc, strParameters.c_str()); + + wasHandled = true; } // Recompose the original command text - std::string val = std::string(szCommand) + " " + std::string(!strParameters.empty() ? strParameters : ""); + std::string val = std::string(szCommand) + " " + strParameters; // Is it a cvar? (syntax: cvar[ = value]) if (!wasHandled) @@ -221,8 +215,9 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool // Unknown command val = _("Unknown command or cvar: ") + szCommand; - if (!bIsScriptedBind && !bIsNickCommand && pEntry == nullptr) + if (!bIsScriptedBind && !bIsNickCommand && !pEntry) CCore::GetSingleton().GetConsole()->Print(val.c_str()); + return false; } From 034fbf098b02bdb5bbfd37327f313f3befbddd56 Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:46:13 +0300 Subject: [PATCH 18/19] a fix for the minimalism of changes #1 --- Client/multiplayer_sa/CMultiplayerSA.cpp | 672 +++++++++++------------ 1 file changed, 336 insertions(+), 336 deletions(-) diff --git a/Client/multiplayer_sa/CMultiplayerSA.cpp b/Client/multiplayer_sa/CMultiplayerSA.cpp index 0b2dc35c55..acd79c90bc 100644 --- a/Client/multiplayer_sa/CMultiplayerSA.cpp +++ b/Client/multiplayer_sa/CMultiplayerSA.cpp @@ -2789,9 +2789,9 @@ void CMultiplayerSA::SetCenterOfWorld(CEntity* entity, CVector* vecPosition, FLO } } -void __declspec(naked) HOOK_FindPlayerCoors() +void _declspec(naked) HOOK_FindPlayerCoors() { - __asm + _asm { // Only set our world of center if we have a center of world set push eax @@ -2825,14 +2825,14 @@ void __declspec(naked) HOOK_FindPlayerCoors() } } -void __declspec(naked) HOOK_CStreaming_Update_Caller() +void _declspec(naked) HOOK_CStreaming_Update_Caller() { /* 0053BF09 8BF8 MOV EDI,EAX 0053BF0B E8 6027EDFF CALL gta_sa.0040E670 */ - __asm + _asm { // Store all registers pushad @@ -2845,7 +2845,7 @@ void __declspec(naked) HOOK_CStreaming_Update_Caller() if (activeEntityForStreaming) { // Do something... - __asm + _asm { mov edi, FUNC_CPlayerInfoBase mov ebx, [edi] @@ -2855,7 +2855,7 @@ void __declspec(naked) HOOK_CStreaming_Update_Caller() } } - __asm + _asm { mov edi, eax @@ -2867,7 +2867,7 @@ void __declspec(naked) HOOK_CStreaming_Update_Caller() // We have an entity for streaming? if (activeEntityForStreaming) { - __asm + _asm { // ... mov edi, FUNC_CPlayerInfoBase @@ -2878,7 +2878,7 @@ void __declspec(naked) HOOK_CStreaming_Update_Caller() // We're no longer in streaming update bInStreamingUpdate = false; - __asm + _asm { // Restore registers popad @@ -2890,13 +2890,13 @@ void __declspec(naked) HOOK_CStreaming_Update_Caller() } } -void __declspec(naked) HOOK_CHud_Draw_Caller() +void _declspec(naked) HOOK_CHud_Draw_Caller() { /* 0053E4FA . E8 318BFCFF CALL gta_sa_u.00507030 0053E4FF . E8 DC150500 CALL gta_sa_u.0058FAE0 */ - __asm + _asm { pushad @@ -2906,7 +2906,7 @@ void __declspec(naked) HOOK_CHud_Draw_Caller() if (!bSetCenterOfWorld) { - __asm + _asm { mov edx, FUNC_CHud_Draw call edx @@ -2916,7 +2916,7 @@ void __declspec(naked) HOOK_CHud_Draw_Caller() { /*if ( activeEntityForStreaming ) { - __asm + _asm { mov edi, FUNC_CPlayerInfoBase mov ebx, [edi] @@ -2928,7 +2928,7 @@ void __declspec(naked) HOOK_CHud_Draw_Caller() if (!bHideRadar) { - __asm + _asm { mov edx, 0x58A330 call edx @@ -2937,7 +2937,7 @@ void __declspec(naked) HOOK_CHud_Draw_Caller() /*if ( activeEntityForStreaming ) { - __asm + _asm { mov edi, FUNC_CPlayerInfoBase mov ebx, dwSavedPlayerPointer @@ -2946,7 +2946,7 @@ void __declspec(naked) HOOK_CHud_Draw_Caller() }*/ } - __asm + _asm { popad @@ -2956,14 +2956,14 @@ void __declspec(naked) HOOK_CHud_Draw_Caller() } } -void __declspec(naked) HOOK_FindPlayerCentreOfWorld() +void _declspec(naked) HOOK_FindPlayerCentreOfWorld() { /* 0056E250 /$ 8B4424 04 MOV EAX,DWORD PTR SS:[ESP+4] 0056E254 |. 85C0 TEST EAX,EAX */ - __asm + _asm { mov al, bSetCenterOfWorld test al, al @@ -2983,14 +2983,14 @@ void __declspec(naked) HOOK_FindPlayerCentreOfWorld() } } -void __declspec(naked) HOOK_FindPlayerHeading() +void _declspec(naked) HOOK_FindPlayerHeading() { /* 0056E450 /$ 8B4C24 04 MOV ECX,DWORD PTR SS:[ESP+4] 0056E454 |. 8BD1 MOV EDX,ECX */ - __asm + _asm { // Jump if bSetCenterOfWorld is true push eax @@ -3015,9 +3015,9 @@ void __declspec(naked) HOOK_FindPlayerHeading() } // this hook adds a null check to prevent the game crashing when objects are placed really high up (issue 517) -void __declspec(naked) HOOK_CCustomRoadsignMgr__RenderRoadsignAtomic() +void _declspec(naked) HOOK_CCustomRoadsignMgr__RenderRoadsignAtomic() { - __asm + _asm { cmp esi, 0 jz no_render @@ -3045,16 +3045,16 @@ bool CallBreakTowLinkHandler(CVehicleSAInterface* vehicle) return true; } -void __declspec(naked) HOOK_CRadar__DrawRadarGangOverlay() +void _declspec(naked) HOOK_CRadar__DrawRadarGangOverlay() { - __asm + _asm { pushad } if (m_pDrawRadarAreasHandler) m_pDrawRadarAreasHandler(); - __asm + _asm { popad retn @@ -3063,9 +3063,9 @@ void __declspec(naked) HOOK_CRadar__DrawRadarGangOverlay() CVehicleSAInterface* towingVehicle; -void __declspec(naked) HOOK_Trailer_BreakTowLink() +void _declspec(naked) HOOK_Trailer_BreakTowLink() { - __asm + _asm { mov towingVehicle, ecx pushad @@ -3073,7 +3073,7 @@ void __declspec(naked) HOOK_Trailer_BreakTowLink() if (CallBreakTowLinkHandler(towingVehicle)) { - __asm + _asm { popad call dword ptr [edx+0xF8] @@ -3081,13 +3081,13 @@ void __declspec(naked) HOOK_Trailer_BreakTowLink() } else { - __asm + _asm { popad } } - __asm + _asm { mov ecx, HOOKPOS_Trailer_BreakTowLink add ecx, 6 @@ -3121,9 +3121,9 @@ bool CallExplosionHandler() return m_pExplosionHandler(pExplodingEntity, pExplosionCreator, vecExplosionLocation, explosionType); } -void __declspec(naked) HOOK_CExplosion_AddExplosion() +void _declspec(naked) HOOK_CExplosion_AddExplosion() { - __asm + _asm { // Check if explosions are disabled. push eax @@ -3174,7 +3174,7 @@ void __declspec(naked) HOOK_CExplosion_AddExplosion() // Call the explosion handler if (!CallExplosionHandler()) { - __asm + _asm { popad retn // if they return false from the handler, they don't want the explosion to show @@ -3182,13 +3182,13 @@ void __declspec(naked) HOOK_CExplosion_AddExplosion() } else { - __asm + _asm { popad } } - __asm + _asm { noexplosionhandler: @@ -3230,9 +3230,9 @@ bool processGrab() } // 0x67DABE -void __declspec(naked) HOOK_CTaskComplexJump__CreateSubTask() +void _declspec(naked) HOOK_CTaskComplexJump__CreateSubTask() { - __asm + _asm { mov pedPosition, eax mov eax, [esi+28] @@ -3246,7 +3246,7 @@ void __declspec(naked) HOOK_CTaskComplexJump__CreateSubTask() if (processGrab()) { - __asm + _asm { popad mov eax, 0x67DAD6 @@ -3255,7 +3255,7 @@ void __declspec(naked) HOOK_CTaskComplexJump__CreateSubTask() } else { - __asm + _asm { popad mov eax, 0x67DAD1 @@ -3268,9 +3268,9 @@ char* szCreateFxSystem_ExplosionType = 0; DWORD* pCreateFxSystem_Matrix = 0; DWORD* pNewCreateFxSystem_Matrix = 0; -void __declspec(naked) HOOK_FxManager_CreateFxSystem() +void _declspec(naked) HOOK_FxManager_CreateFxSystem() { - __asm + _asm { // Store the explosion type mov eax, [esp+4] @@ -3300,7 +3300,7 @@ void __declspec(naked) HOOK_FxManager_CreateFxSystem() pNewCreateFxSystem_Matrix = pCreateFxSystem_Matrix; } - __asm + _asm { // Restore the registers popad @@ -3321,9 +3321,9 @@ void __declspec(naked) HOOK_FxManager_CreateFxSystem() DWORD dwDestroyFxSystem_Pointer = 0; DWORD* pDestroyFxSystem_Matrix = 0; -void __declspec(naked) HOOK_FxManager_DestroyFxSystem() +void _declspec(naked) HOOK_FxManager_DestroyFxSystem() { - __asm + _asm { // Grab the FxSystem that's being destroyed mov eax, [esp+4] @@ -3339,7 +3339,7 @@ void __declspec(naked) HOOK_FxManager_DestroyFxSystem() // Delete it if it's in our list RemoveFxSystemPointer(pDestroyFxSystem_Matrix); - __asm + _asm { // Restore the registers popad @@ -3368,23 +3368,23 @@ bool CCam_ProcessFixed(class CCamSAInterface* pCamInterface) CCamSAInterface* CCam_ProcessFixed_pCam; -void __declspec(naked) HOOK_CCam_ProcessFixed() +void _declspec(naked) HOOK_CCam_ProcessFixed() { - __asm + _asm { mov CCam_ProcessFixed_pCam, ecx } if (CCam_ProcessFixed(CCam_ProcessFixed_pCam)) { - __asm + _asm { ret 10h } } else { - __asm + _asm { mov ecx, CCam_ProcessFixed_pCam sub esp, 28h @@ -3395,15 +3395,15 @@ void __declspec(naked) HOOK_CCam_ProcessFixed() } } -void __declspec(naked) HOOK_Render3DStuff() +void _declspec(naked) HOOK_Render3DStuff() { - __asm + _asm { pushad } if (m_pRender3DStuffHandler) m_pRender3DStuffHandler(); - __asm + _asm { popad mov eax, FUNC_Render3DStuff @@ -3433,14 +3433,14 @@ bool ProcessPlayerWeapon() return false; } -void __declspec(naked) HOOK_CTaskSimplePlayerOnFoot_ProcessPlayerWeapon() +void _declspec(naked) HOOK_CTaskSimplePlayerOnFoot_ProcessPlayerWeapon() { /* 006859A0 push 0FFFFFFFFh 006859A2 push 846BCEh 006859A7 mov eax,dword ptr fs:[00000000h] */ - __asm + _asm { mov eax, [esp+4] mov pProcessPlayerWeaponPed, eax @@ -3448,7 +3448,7 @@ void __declspec(naked) HOOK_CTaskSimplePlayerOnFoot_ProcessPlayerWeapon() } if (ProcessPlayerWeapon()) { - __asm + _asm { popad push 0FFFFFFFFh @@ -3458,7 +3458,7 @@ void __declspec(naked) HOOK_CTaskSimplePlayerOnFoot_ProcessPlayerWeapon() } else { - __asm + _asm { popad ret 4 @@ -3472,20 +3472,20 @@ bool IsPlayer() return true; } -void __declspec(naked) HOOK_CPed_IsPlayer() +void _declspec(naked) HOOK_CPed_IsPlayer() { /* 005DF8F0 mov eax,dword ptr [ecx+598h] 005DF8F6 test eax,eax */ - __asm + _asm { mov pIsPlayerPed, ecx pushad } if (IsPlayer()) { - __asm + _asm { popad mov eax,dword ptr [ecx+598h] @@ -3494,7 +3494,7 @@ void __declspec(naked) HOOK_CPed_IsPlayer() } else { - __asm + _asm { popad xor al, al @@ -3515,7 +3515,7 @@ void CRunningScript_Process() char szModelName[64]; strcpy(szModelName, "player"); - __asm + _asm { push 26 lea eax, szModelName @@ -3526,7 +3526,7 @@ void CRunningScript_Process() } dwFunc = 0x40EA10; // load all requested models - __asm + _asm { push 1 call dwFunc @@ -3534,7 +3534,7 @@ void CRunningScript_Process() } dwFunc = 0x60D790; // setup player ped - __asm + _asm { push 0 call dwFunc @@ -3542,7 +3542,7 @@ void CRunningScript_Process() } /*dwFunc = 0x05E47E0; // set created by - __asm + _asm { mov edi, 0xB7CD98 mov ecx, [edi] @@ -3551,7 +3551,7 @@ void CRunningScript_Process() } dwFunc = 0x609520; // deactivate player ped - __asm + _asm { push 0 call dwFunc @@ -3562,7 +3562,7 @@ void CRunningScript_Process() fX = 2488.562f; fY = -1666.864f; fZ = 12.8757f; - __asm + _asm { mov edi, 0xB7CD98 push fZ @@ -3573,7 +3573,7 @@ void CRunningScript_Process() } /* dwFunc = 0x609540; // reactivate player ped - __asm + _asm { push 0 call dwFunc @@ -3581,7 +3581,7 @@ void CRunningScript_Process() } dwFunc = 0x61A5A0; // CTask::operator new - __asm + _asm { push 28 call dwFunc @@ -3589,14 +3589,14 @@ void CRunningScript_Process() } dwFunc = 0x685750; // CTaskSimplePlayerOnFoot::CTaskSimplePlayerOnFoot - __asm + _asm { mov ecx, eax call dwFunc } dwFunc = 0x681AF0; // set task - __asm + _asm { mov edi, 0xB7CD98 mov edi, [edi] @@ -3613,16 +3613,16 @@ void CRunningScript_Process() } } -void __declspec(naked) HOOK_CRunningScript_Process() +void _declspec(naked) HOOK_CRunningScript_Process() { - __asm + _asm { pushad } CRunningScript_Process(); - __asm + _asm { popad retn @@ -3630,10 +3630,10 @@ void __declspec(naked) HOOK_CRunningScript_Process() } static CVehicleSAInterface* pDerailingTrain = NULL; -void __declspec(naked) HOOK_CTrain_ProcessControl_Derail() +void _declspec(naked) HOOK_CTrain_ProcessControl_Derail() { // If the train wouldn't derail, don't modify anything - __asm + _asm { jnp train_would_derail mov eax, 0x6F8F89 @@ -3647,7 +3647,7 @@ void __declspec(naked) HOOK_CTrain_ProcessControl_Derail() if (pDerailingTrain->m_pVehicle->IsDerailable()) { // Go back to the derailment code - __asm + _asm { popad mov eax, 0x6F8DC0 @@ -3656,7 +3656,7 @@ void __declspec(naked) HOOK_CTrain_ProcessControl_Derail() } else { - __asm + _asm { popad mov eax, 0x6F8F89 @@ -3686,7 +3686,7 @@ static void SetEntityAlphaHooked(DWORD dwEntity, DWORD dwCallback, DWORD dwAlpha // Call SetRwObjectAlpha DWORD dwFunc = FUNC_SetRwObjectAlpha; - __asm + _asm { mov ecx, dwEntity push dwAlpha @@ -3757,9 +3757,9 @@ static void SetVehicleAlpha() } static DWORD dwCVehicle_SetupRender_ret = 0x6D6517; -void __declspec(naked) HOOK_CVehicle_SetupRender() +void _declspec(naked) HOOK_CVehicle_SetupRender() { - __asm + _asm { mov dwAlphaEntity, esi pushad @@ -3767,7 +3767,7 @@ void __declspec(naked) HOOK_CVehicle_SetupRender() SetVehicleAlpha(); - __asm + _asm { popad add esp, 0x8 @@ -3777,16 +3777,16 @@ void __declspec(naked) HOOK_CVehicle_SetupRender() } static DWORD dwCVehicle_ResetAfterRender_ret = 0x6D0E43; -void __declspec(naked) HOOK_CVehicle_ResetAfterRender() +void _declspec(naked) HOOK_CVehicle_ResetAfterRender() { - __asm + _asm { pushad } RestoreAlphaValues(); - __asm + _asm { popad add esp, 0x0C @@ -3836,19 +3836,19 @@ void Handle_ObjRndrF() } DWORD dwCObjectRenderRet = 0; -void __declspec(naked) HOOK_CObject_PostRender() +void _declspec(naked) HOOK_CObject_PostRender() { - __asm + _asm { pushad } - __asm + _asm { call Handle_ObjRndrF } - __asm + _asm { popad mov edx, dwCObjectRenderRet @@ -3857,20 +3857,20 @@ void __declspec(naked) HOOK_CObject_PostRender() } // Note: This hook is also called for world objects (light poles, wooden fences, etc). -void __declspec(naked) HOOK_CObject_Render() +void _declspec(naked) HOOK_CObject_Render() { - __asm + _asm { mov dwAlphaEntity, ecx pushad } - __asm + _asm { call Handle_ObjRndr } - __asm + _asm { popad mov edx, [esp] @@ -3882,14 +3882,14 @@ void __declspec(naked) HOOK_CObject_Render() if (bObjectIsAGangTag) goto render_a_tag; - __asm + _asm { popad jmp FUNC_CEntity_Render } render_a_tag: - __asm + _asm { popad // We simulate here the header of the CEntity::Render function @@ -3959,9 +3959,9 @@ void _cdecl DoEndWorldColorsPokes() } // Note: This hook is called at the end of the function that sets the world colours (sky gradient, water colour, etc). -void __declspec(naked) HOOK_EndWorldColors() +void _declspec(naked) HOOK_EndWorldColors() { - __asm + _asm { call DoEndWorldColorsPokes ret @@ -3976,9 +3976,9 @@ static DWORD dwObjectsChecked = 0; static DWORD dwProcessVerticalKeepLooping = 0x5632D1; static DWORD dwProcessVerticalEndLooping = 0x56335F; static DWORD dwGlobalListOfObjects = 0xB9ACCC; -void __declspec(naked) HOOK_CWorld_ProcessVerticalLineSectorList() +void _declspec(naked) HOOK_CWorld_ProcessVerticalLineSectorList() { - __asm + _asm { test ebp, ebp jz end_of_entities_list @@ -4005,9 +4005,9 @@ void __declspec(naked) HOOK_CWorld_ProcessVerticalLineSectorList() static DWORD dwChokingChoke = 0x4C05C1; static DWORD dwChokingDontchoke = 0x4C0620; static unsigned char ucChokingWeaponType = 0; -void __declspec(naked) HOOK_ComputeDamageResponse_StartChoking() +void _declspec(naked) HOOK_ComputeDamageResponse_StartChoking() { - __asm + _asm { pushad mov al, [esp+0x8C] @@ -4016,7 +4016,7 @@ void __declspec(naked) HOOK_ComputeDamageResponse_StartChoking() if (m_pChokingHandler && m_pChokingHandler(ucChokingWeaponType) == false) goto dont_choke; - __asm + _asm { popad mov ecx, [edi] @@ -4025,7 +4025,7 @@ void __declspec(naked) HOOK_ComputeDamageResponse_StartChoking() } dont_choke: - __asm + _asm { popad jmp dwChokingDontchoke @@ -4211,7 +4211,7 @@ void CMultiplayerSA::ConvertEulerAnglesToMatrix(CMatrix& Matrix, float fX, float CMatrix_Padded* pMatrixPadded = &matrixPadded; DWORD dwFunc = FUNC_CMatrix__ConvertFromEulerAngles; int iUnknown = 21; - __asm + _asm { push iUnknown push fZ @@ -4238,7 +4238,7 @@ void CMultiplayerSA::ConvertMatrixToEulerAngles(const CMatrix& Matrix, float& fX float* pfY = &fY; float* pfZ = &fZ; int iUnknown = 21; - __asm + _asm { push iUnknown push pfZ @@ -4344,11 +4344,11 @@ void CMultiplayerSA::SetDebugVars(float f1, float f2, float f3) { } -void __declspec(naked) HOOK_CollisionStreamRead() +void _declspec(naked) HOOK_CollisionStreamRead() { if (*(DWORD*)VAR_CollisionStreamRead_ModelInfo) { - __asm + _asm { mov eax, dword ptr fs:[0] jmp RETURN_CollisionStreamRead @@ -4356,7 +4356,7 @@ void __declspec(naked) HOOK_CollisionStreamRead() } else { - __asm + _asm { ret } @@ -4364,9 +4364,9 @@ void __declspec(naked) HOOK_CollisionStreamRead() } unsigned char ucDesignatedLightState = 0; -void __declspec(naked) HOOK_CTrafficLights_GetPrimaryLightState() +void _declspec(naked) HOOK_CTrafficLights_GetPrimaryLightState() { - __asm + _asm { pushad } @@ -4385,7 +4385,7 @@ void __declspec(naked) HOOK_CTrafficLights_GetPrimaryLightState() } else ucDesignatedLightState = 2; // Red - __asm + _asm { popad mov al, ucDesignatedLightState @@ -4393,9 +4393,9 @@ void __declspec(naked) HOOK_CTrafficLights_GetPrimaryLightState() } } -void __declspec(naked) HOOK_CTrafficLights_GetSecondaryLightState() +void _declspec(naked) HOOK_CTrafficLights_GetSecondaryLightState() { - __asm + _asm { pushad } @@ -4414,7 +4414,7 @@ void __declspec(naked) HOOK_CTrafficLights_GetSecondaryLightState() } else ucDesignatedLightState = 2; // Red - __asm + _asm { popad mov al, ucDesignatedLightState @@ -4422,9 +4422,9 @@ void __declspec(naked) HOOK_CTrafficLights_GetSecondaryLightState() } } -void __declspec(naked) HOOK_CTrafficLights_DisplayActualLight() +void _declspec(naked) HOOK_CTrafficLights_DisplayActualLight() { - __asm + _asm { pushad } @@ -4436,7 +4436,7 @@ void __declspec(naked) HOOK_CTrafficLights_DisplayActualLight() else if (ucTrafficLightState == 9) { ucDesignatedLightState = 1; } else { ucDesignatedLightState = 2; } - __asm + _asm { popad movzx eax, ucDesignatedLightState @@ -4463,9 +4463,9 @@ void CheckVehicleMaxGear() } } -void __declspec(naked) HOOK_Transmission_CalculateDriveAcceleration() +void _declspec(naked) HOOK_Transmission_CalculateDriveAcceleration() { - __asm + _asm { push eax mov pCurTransmission, ecx @@ -4477,7 +4477,7 @@ void __declspec(naked) HOOK_Transmission_CalculateDriveAcceleration() CheckVehicleMaxGear(); - __asm + _asm { popad mov eax, [esp+0x10] @@ -4486,10 +4486,10 @@ void __declspec(naked) HOOK_Transmission_CalculateDriveAcceleration() } } -void __declspec(naked) HOOK_isVehDriveTypeNotRWD() +void _declspec(naked) HOOK_isVehDriveTypeNotRWD() { // Get the Vehicle interface from esi - __asm + _asm { mov pHandlingDriveTypeVeh, esi } @@ -4497,17 +4497,17 @@ void __declspec(naked) HOOK_isVehDriveTypeNotRWD() GetVehicleDriveType(); // push our drive type into bl :) - __asm + _asm { mov bl, ucDriveType jmp RETURN_CHandlingData_isNotRWD } } -void __declspec(naked) HOOK_isVehDriveTypeNotFWD() +void _declspec(naked) HOOK_isVehDriveTypeNotFWD() { // Get the Vehicle SA interface from esi - __asm + _asm { mov pHandlingDriveTypeVeh, esi } @@ -4515,7 +4515,7 @@ void __declspec(naked) HOOK_isVehDriveTypeNotFWD() GetVehicleDriveType(); // push our drive type into bl :) - __asm + _asm { mov bl, ucDriveType jmp RETURN_CHandlingData_isNotFWD @@ -4575,7 +4575,7 @@ void CMultiplayerSA::AllowCreatedObjectsInVerticalLineTest(bool bOn) void _cdecl CPhysical_ApplyGravity(DWORD dwThis) { DWORD dwType; - __asm + _asm { mov ecx, dwThis mov eax, 0x46A2C0 // CEntity::GetType @@ -4607,9 +4607,9 @@ void _cdecl CPhysical_ApplyGravity(DWORD dwThis) } const float kfTimeStepOrg = 5.0f / 3.0f; -void __declspec(naked) HOOK_CVehicle_ApplyBoatWaterResistance() +void _declspec(naked) HOOK_CVehicle_ApplyBoatWaterResistance() { - __asm + _asm { fmul ds : 0x871DDC // Original constant used in code fmul ds : 0xB7CB5C // Multiply by current timestep @@ -4618,9 +4618,9 @@ void __declspec(naked) HOOK_CVehicle_ApplyBoatWaterResistance() } } -void __declspec(naked) HOOK_CPhysical_ApplyGravity() +void _declspec(naked) HOOK_CPhysical_ApplyGravity() { - __asm + _asm { push esi call CPhysical_ApplyGravity @@ -4698,9 +4698,9 @@ bool _cdecl VehicleCamStart(DWORD dwCam, DWORD pVehicleInterface) return true; } -void __declspec(naked) HOOK_VehicleCamStart() +void _declspec(naked) HOOK_VehicleCamStart() { - __asm + _asm { push edi push esi @@ -4726,9 +4726,9 @@ void _cdecl VehicleCamTargetZTweak(CVector* pvecCamTarget, float fTargetZTweak) *pvecCamTarget += gravcam_matGravity.vUp * fTargetZTweak; } -void __declspec(naked) HOOK_VehicleCamTargetZTweak() +void _declspec(naked) HOOK_VehicleCamTargetZTweak() { - __asm + _asm { fstp st @@ -4763,9 +4763,9 @@ void _cdecl VehicleCamLookDir1(DWORD dwCam, DWORD pVehicleInterface) *pvecLookDir = gravcam_matInvertGravity * (*pvecLookDir); } -void __declspec(naked) HOOK_VehicleCamLookDir1() +void _declspec(naked) HOOK_VehicleCamLookDir1() { - __asm + _asm { mov eax, 0x59C910 // CVector::Normalise call eax @@ -4796,9 +4796,9 @@ bool _cdecl VehicleCamLookDir2(DWORD dwCam) return true; } -void __declspec(naked) HOOK_VehicleCamLookDir2() +void _declspec(naked) HOOK_VehicleCamLookDir2() { - __asm + _asm { push esi call VehicleCamLookDir2 @@ -4822,9 +4822,9 @@ void _cdecl VehicleCamHistory(DWORD dwCam, CVector* pvecTarget, float fTargetThe ((CVector*)(dwCam + 0x1D8))[1] = *pvecTarget - vecDir * fZoom; } -void __declspec(naked) HOOK_VehicleCamHistory() +void _declspec(naked) HOOK_VehicleCamHistory() { - __asm + _asm { push [esp+0x0+0x7C] // zoom push [esp+0x4+0x2C] // radius @@ -4855,9 +4855,9 @@ void _cdecl VehicleCamUp(DWORD dwCam) pvecUp->Normalize(); } -void __declspec(naked) HOOK_VehicleCamUp() +void _declspec(naked) HOOK_VehicleCamUp() { - __asm + _asm { mov edx, ecx mov ecx, [ecx+0x21C] // CCam::pTargetEntity @@ -4893,9 +4893,9 @@ void _cdecl VehicleCamEnd(DWORD pVehicleInterface) pVehicle->SetMoveSpeed(&gravcam_vecVehicleVelocity); } -void __declspec(naked) HOOK_VehicleCamEnd() +void _declspec(naked) HOOK_VehicleCamEnd() { - __asm + _asm { mov ds:[0xB6F020], edx @@ -4916,9 +4916,9 @@ void _cdecl VehicleLookBehind(DWORD dwCam, CVector* pvecEntityPos, float fDistan MemPutFast(dwCam + 0x19C, *pvecEntityPos + (gravcam_matVehicleTransform.vFront + gravcam_matGravity.vUp * 0.2f) * fDistance); } -void __declspec(naked) HOOK_VehicleLookBehind() +void _declspec(naked) HOOK_VehicleLookBehind() { - __asm + _asm { push [esp+0x14] lea eax, [esp+4+0x1C] @@ -4951,9 +4951,9 @@ void _cdecl VehicleLookAside(DWORD dwCam, CVector* pvecEntityPos, float fDirecti MemPutFast(dwCam + 0x19C, *pvecEntityPos + (-gravcam_matVehicleTransform.vRight * fDirectionFactor + gravcam_matGravity.vUp * 0.2f) * fDistance); } -void __declspec(naked) HOOK_VehicleLookAside() +void _declspec(naked) HOOK_VehicleLookAside() { - __asm + _asm { push [esp+0x14] push [esp+4+0x1C] @@ -4989,9 +4989,9 @@ float _cdecl VehicleBurnCheck(DWORD pVehicleInterface) return matVehicle.vUp.DotProduct(&vecGravity); } -void __declspec(naked) HOOK_OccupiedVehicleBurnCheck() +void _declspec(naked) HOOK_OccupiedVehicleBurnCheck() { - __asm + _asm { push eax call VehicleBurnCheck @@ -5000,9 +5000,9 @@ void __declspec(naked) HOOK_OccupiedVehicleBurnCheck() } } -void __declspec(naked) HOOK_UnoccupiedVehicleBurnCheck() +void _declspec(naked) HOOK_UnoccupiedVehicleBurnCheck() { - __asm + _asm { mov word ptr [esp+0x78], cx @@ -5031,9 +5031,9 @@ void _cdecl ApplyVehicleBlowHop(DWORD pVehicleInterface) pVehicle->SetMoveSpeed(&vecVelocity); } -void __declspec(naked) HOOK_ApplyCarBlowHop() +void _declspec(naked) HOOK_ApplyCarBlowHop() { - __asm + _asm { push esi call ApplyVehicleBlowHop @@ -5066,19 +5066,19 @@ void Handle_CWorld_ProcessF() } DWORD CALL_CWorld_Process = 0x5684a0; -void __declspec(naked) HOOK_CGame_Process() +void _declspec(naked) HOOK_CGame_Process() { - __asm + _asm { pushad } - __asm + _asm { call Handle_CWorld_Process } - __asm + _asm { popad call CALL_CWorld_Process @@ -5086,12 +5086,12 @@ void __declspec(naked) HOOK_CGame_Process() pushad } - __asm + _asm { call Handle_CWorld_ProcessF } - __asm + _asm { popad jmp RETURN_CGame_Process; @@ -5130,23 +5130,23 @@ void Idle() } DWORD CALL_CGame_Process = 0x53BEE0; -void __declspec(naked) HOOK_Idle() +void _declspec(naked) HOOK_Idle() { - __asm + _asm { call CGame_Process call CALL_CGame_Process pushad } - __asm + _asm { call CGame_ProcessF call Idle } - __asm + _asm { popad mov ecx, 0B6BC90h @@ -5155,9 +5155,9 @@ void __declspec(naked) HOOK_Idle() } // Hooked from 0049E650 5 bytes -void __declspec(naked) HOOK_PreFxRender() +void _declspec(naked) HOOK_PreFxRender() { - __asm + _asm { pushad mov eax,[esp+32+4*2] @@ -5167,7 +5167,7 @@ void __declspec(naked) HOOK_PreFxRender() if (m_pPreFxRenderHandler) m_pPreFxRenderHandler(); - __asm + _asm { skip: popad @@ -5176,16 +5176,16 @@ void __declspec(naked) HOOK_PreFxRender() } // Hooked from 00705099 5 bytes -void __declspec(naked) HOOK_PostColorFilterRender() +void _declspec(naked) HOOK_PostColorFilterRender() { - __asm + _asm { pushad } if (m_pPostColorFilterRenderHandler) m_pPostColorFilterRenderHandler(); - __asm + _asm { popad mov al, ds:0C402BAh @@ -5194,16 +5194,16 @@ void __declspec(naked) HOOK_PostColorFilterRender() } // Hooked from 0053EAD8 5 bytes -void __declspec(naked) HOOK_PreHUDRender() +void _declspec(naked) HOOK_PreHUDRender() { - __asm + _asm { pushad } if (m_pPreHudRenderHandler) m_pPreHudRenderHandler(); - __asm + _asm { popad mov eax, ds:0B6F0B8h @@ -5271,9 +5271,9 @@ void vehicle_lights_init() } CVehicleSAInterface* pLightsVehicleInterface = NULL; -void __declspec(naked) HOOK_CVehicle_DoVehicleLights() +void _declspec(naked) HOOK_CVehicle_DoVehicleLights() { - __asm + _asm { mov pLightsVehicleInterface, ecx mov al,byte ptr ds:[00C1CC18h] @@ -5300,9 +5300,9 @@ void CVehicle_GetHeadLightColor(CVehicleSAInterface* pInterface, float } CVehicleSAInterface* pHeadLightBeamVehicleInterface = NULL; -void __declspec(naked) HOOK_CVehicle_DoHeadLightBeam_1() +void _declspec(naked) HOOK_CVehicle_DoHeadLightBeam_1() { - __asm + _asm { mov pHeadLightBeamVehicleInterface, ecx sub esp, 94h @@ -5324,9 +5324,9 @@ void CVehicle_DoHeadLightBeam() } } -void __declspec(naked) HOOK_CVehicle_DoHeadLightBeam_2() +void _declspec(naked) HOOK_CVehicle_DoHeadLightBeam_2() { - __asm + _asm { mov eax, [esp] mov pHeadLightVerts, eax @@ -5337,7 +5337,7 @@ void __declspec(naked) HOOK_CVehicle_DoHeadLightBeam_2() CVehicle_DoHeadLightBeam(); - __asm + _asm { popad mov dword ptr ds:[0C4B950h],5 @@ -5346,16 +5346,16 @@ void __declspec(naked) HOOK_CVehicle_DoHeadLightBeam_2() } DWORD dwCCoronas_RegisterCorona = 0x6FC580; -void __declspec(naked) HOOK_CVehicle_DoHeadLightEffect_1() +void _declspec(naked) HOOK_CVehicle_DoHeadLightEffect_1() { - __asm + _asm { pushad } CVehicle_GetHeadLightColor(pLightsVehicleInterface, 160.0f, 160.0f, 140.0f); - __asm + _asm { popad mov eax, ulHeadLightR @@ -5373,16 +5373,16 @@ void __declspec(naked) HOOK_CVehicle_DoHeadLightEffect_1() } } -void __declspec(naked) HOOK_CVehicle_DoHeadLightEffect_2() +void _declspec(naked) HOOK_CVehicle_DoHeadLightEffect_2() { - __asm + _asm { pushad } CVehicle_GetHeadLightColor(pLightsVehicleInterface, 160.0f, 160.0f, 140.0f); - __asm + _asm { popad mov eax, ulHeadLightR @@ -5401,16 +5401,16 @@ void __declspec(naked) HOOK_CVehicle_DoHeadLightEffect_2() } DWORD dwCShadows_StoreCarLightShadow = 0x70C500; -void __declspec(naked) HOOK_CVehicle_DoHeadLightReflectionTwin() +void _declspec(naked) HOOK_CVehicle_DoHeadLightReflectionTwin() { - __asm + _asm { pushad } CVehicle_GetHeadLightColor(pLightsVehicleInterface, 45.0f, 45.0f, 45.0f); - __asm + _asm { popad mov eax, ulHeadLightR @@ -5426,16 +5426,16 @@ void __declspec(naked) HOOK_CVehicle_DoHeadLightReflectionTwin() } } -void __declspec(naked) HOOK_CVehicle_DoHeadLightReflectionSingle() +void _declspec(naked) HOOK_CVehicle_DoHeadLightReflectionSingle() { - __asm + _asm { pushad } CVehicle_GetHeadLightColor(pLightsVehicleInterface, 45.0f, 45.0f, 45.0f); - __asm + _asm { popad mov eax, ulHeadLightR @@ -5457,11 +5457,11 @@ void __declspec(naked) HOOK_CVehicle_DoHeadLightReflectionSingle() // Report fire damage, with correct inflictor entity -void __declspec(naked) HOOK_CWorld_SetWorldOnFire() +void _declspec(naked) HOOK_CWorld_SetWorldOnFire() { // Actually pass the pCreatorEntity parameter that this function receives to CFireManager::StartFire // (instead of a null pointer) - __asm + _asm { push 7000 push [esp+0x18+0x14] @@ -5469,10 +5469,10 @@ void __declspec(naked) HOOK_CWorld_SetWorldOnFire() } } -void __declspec(naked) HOOK_CTaskSimplePlayerOnFire_ProcessPed() +void _declspec(naked) HOOK_CTaskSimplePlayerOnFire_ProcessPed() { // Actually pass the fire's pCreatorEntity to the damage event (instead of a null pointer) - __asm + _asm { push 3 push 0x25 @@ -5484,10 +5484,10 @@ void __declspec(naked) HOOK_CTaskSimplePlayerOnFire_ProcessPed() } } -void __declspec(naked) HOOK_CFire_ProcessFire() +void _declspec(naked) HOOK_CFire_ProcessFire() { // Set the new fire's creator to the original fire's creator - __asm + _asm { mov eax, 0x53A450 // CCreepingFire::TryToStartFireAtCoors call eax @@ -5500,10 +5500,10 @@ void __declspec(naked) HOOK_CFire_ProcessFire() } } -void __declspec(naked) HOOK_CExplosion_Update() +void _declspec(naked) HOOK_CExplosion_Update() { // Set the new fire's creator to the explosion's creator - __asm + _asm { mov eax, 0x53A450 // CCreepingFire::TryToStartFireAtCoors call eax @@ -5516,10 +5516,10 @@ void __declspec(naked) HOOK_CExplosion_Update() } } -void __declspec(naked) HOOK_CWeapon_FireAreaEffect() +void _declspec(naked) HOOK_CWeapon_FireAreaEffect() { // Set the new fire's creator to the weapon's owner - __asm + _asm { mov eax, 0x53A450 // CCreepingFire::TryToStartFireAtCoors call eax @@ -5617,9 +5617,9 @@ void CPlantMgr_Render_Post() // and water is not drawn in front of above-water plants (eg if you're looking at a // lake through some high grass). -void __declspec(naked) HOOK_RenderScene_Plants() +void _declspec(naked) HOOK_RenderScene_Plants() { - __asm + _asm { pushad call CPlantMgr_Render_Pre @@ -5639,9 +5639,9 @@ void __declspec(naked) HOOK_RenderScene_Plants() } } -void __declspec(naked) HOOK_RenderScene_end() +void _declspec(naked) HOOK_RenderScene_end() { - __asm + _asm { pushad call CPlantMgr_Render_Pre @@ -5670,10 +5670,10 @@ bool _cdecl IsPlantBelowWater(float fPlantZ, float fWaterZ) return fPlantZ + 2.0f < fWaterZ; } -void __declspec(naked) HOOK_CPlantMgr_Render() +void _declspec(naked) HOOK_CPlantMgr_Render() { // (bCamBelowWater, bRenderingBeforeWater) - __asm + _asm { sub esp, 4 mov eax, esp @@ -5740,9 +5740,9 @@ void CEventHandler_ComputeKnockOffBikeResponse() } DWORD dw_CEventDamage_AffectsPed = 0x4b35a0; -void __declspec(naked) HOOK_CEventHandler_ComputeKnockOffBikeResponse() +void _declspec(naked) HOOK_CEventHandler_ComputeKnockOffBikeResponse() { - __asm + _asm { mov pBikeDamageInterface, ecx mov pBikePedInterface, edx @@ -5753,7 +5753,7 @@ void __declspec(naked) HOOK_CEventHandler_ComputeKnockOffBikeResponse() } CEventHandler_ComputeKnockOffBikeResponse(); - __asm + _asm { popad call dw_CEventDamage_AffectsPed @@ -5802,9 +5802,9 @@ bool CPed_GetWeaponSkill() return false; } -void __declspec(naked) HOOK_CPed_GetWeaponSkill() +void _declspec(naked) HOOK_CPed_GetWeaponSkill() { - __asm + _asm { mov weaponSkillPed, ecx mov eax, [esp+4] @@ -5814,7 +5814,7 @@ void __declspec(naked) HOOK_CPed_GetWeaponSkill() if (CPed_GetWeaponSkill()) { - __asm + _asm { popad mov al, weaponSkill @@ -5823,7 +5823,7 @@ void __declspec(naked) HOOK_CPed_GetWeaponSkill() } else { - __asm + _asm { popad push esi @@ -5843,9 +5843,9 @@ bool _cdecl CPed_AddGogglesModelCheck(void* pPedInterface) return pPed == pGameInterface->GetPools()->GetPedFromRef(1); } -void __declspec(naked) HOOK_CPed_AddGogglesModel() +void _declspec(naked) HOOK_CPed_AddGogglesModel() { - __asm + _asm { push esi call CPed_AddGogglesModelCheck @@ -5877,7 +5877,7 @@ void CMultiplayerSA::DeleteAndDisableGangTags() DWORD* pTagInterface = VAR_TagInfoArray[i << 1]; if (pTagInterface) { - __asm + _asm { push pTagInterface call dwFunc @@ -5887,7 +5887,7 @@ void CMultiplayerSA::DeleteAndDisableGangTags() } dwFunc = FUNC_CTagManager_ShutdownForRestart; - __asm + _asm { call dwFunc } @@ -5939,9 +5939,9 @@ bool CPhysical_ProcessCollisionSectorList() return true; } -void __declspec(naked) HOOK_CPhysical_ProcessCollisionSectorList() +void _declspec(naked) HOOK_CPhysical_ProcessCollisionSectorList() { - __asm + _asm { mov pCollisionPhysicalThis, esi mov pCollisionPhysical, edi @@ -5951,7 +5951,7 @@ void __declspec(naked) HOOK_CPhysical_ProcessCollisionSectorList() // Carry on with collision? (sets the CElement->bUsesCollision flag check) if (CPhysical_ProcessCollisionSectorList()) { - __asm + _asm { popad mov ecx, [eax+4] @@ -5961,7 +5961,7 @@ void __declspec(naked) HOOK_CPhysical_ProcessCollisionSectorList() } else { - __asm + _asm { popad mov ecx, [eax+4] @@ -6021,9 +6021,9 @@ void _cdecl CheckMatrix(float* pMatrix) } // hooked at 7C5A5C 5 bytes -void __declspec(naked) HOOK_CheckAnimMatrix() +void _declspec(naked) HOOK_CheckAnimMatrix() { - __asm + _asm { // Replaced code lea ecx, [esp+054h] @@ -6053,9 +6053,9 @@ void _cdecl SaveVehColors(DWORD dwThis) } } -void __declspec(naked) HOOK_VehCol() +void _declspec(naked) HOOK_VehCol() { - __asm + _asm { // Get vehColors for this vehicle pushad @@ -6077,9 +6077,9 @@ void __declspec(naked) HOOK_VehCol() } } -void __declspec(naked) HOOK_VehColCB() +void _declspec(naked) HOOK_VehColCB() { - __asm + _asm { // Hooked from 004C838D 29 bytes @@ -6111,9 +6111,9 @@ static bool AllowSwingingDoors() return false; } -void __declspec(naked) HOOK_CAutomobile__ProcessSwingingDoor() +void _declspec(naked) HOOK_CAutomobile__ProcessSwingingDoor() { - __asm + _asm { mov dwSwingingDoorAutomobile, esi mov ecx, [esi+eax*4+0x648] @@ -6122,7 +6122,7 @@ void __declspec(naked) HOOK_CAutomobile__ProcessSwingingDoor() if (AllowSwingingDoors()) { - __asm + _asm { popad jmp dwSwingingRet1 @@ -6130,7 +6130,7 @@ void __declspec(naked) HOOK_CAutomobile__ProcessSwingingDoor() } else { - __asm + _asm { popad jmp dwSwingingRet2 @@ -6175,9 +6175,9 @@ bool CheckHasSuspensionChanged() else return false; } -void __declspec(naked) HOOK_ProcessVehicleCollision() +void _declspec(naked) HOOK_ProcessVehicleCollision() { - __asm + _asm { mov pSuspensionInterface, esi pushad @@ -6188,7 +6188,7 @@ void __declspec(naked) HOOK_ProcessVehicleCollision() // When the vehicle's collision is about to be processed, set its per-vehicle // suspension lines as the per-model suspension lines, and restore the per-model lines // afterwards - __asm + _asm { popad push esi @@ -6225,7 +6225,7 @@ void __declspec(naked) HOOK_ProcessVehicleCollision() else { // Skip our code in this case because they haven't changed anything so it'l just cause problems. - __asm + _asm { popad jmp dwSuspensionChangedJump @@ -6281,9 +6281,9 @@ bool CheckRemovedModel() // Binary // Hook 1 -void __declspec(naked) HOOK_LoadIPLInstance() +void _declspec(naked) HOOK_LoadIPLInstance() { - __asm + _asm { pushad mov pEntityWorldAdd, ecx @@ -6292,7 +6292,7 @@ void __declspec(naked) HOOK_LoadIPLInstance() { CheckRemovedModel(); } - __asm + _asm { popad jmp CALL_LoadIPLInstance @@ -6340,15 +6340,15 @@ void HideEntitySomehow() } // Binary // Hook 2 -void __declspec(naked) HOOK_CWorld_LOD_SETUP() +void _declspec(naked) HOOK_CWorld_LOD_SETUP() { - __asm + _asm { pushad mov pLODInterface, esi } HideEntitySomehow(); - __asm + _asm { popad jmp CALL_CWorld_LODSETUP @@ -6366,15 +6366,15 @@ void StorePointerToBuilding() // Called when a data entity is added to the world (this happens once when the game loads so we just dump those in a list and we can sift through when someone // tries to remove.) -void __declspec(naked) Hook_AddBuildingInstancesToWorld() +void _declspec(naked) Hook_AddBuildingInstancesToWorld() { - __asm + _asm { pushad mov pBuildingAdd, edx } StorePointerToBuilding(); - __asm + _asm { popad jmp JMP_CWorld_Add_AddBuildingInstancesToWorld_CALL_CWorldAdd @@ -6398,16 +6398,16 @@ bool CheckForRemoval() } // Call to CWorld::Add in CPopulation::ConvertToRealObject we just use this to get a list of pointers to valid objects for instant removal -void __declspec(naked) Hook_CWorld_ADD_CPopulation_ConvertToRealObject() +void _declspec(naked) Hook_CWorld_ADD_CPopulation_ConvertToRealObject() { - __asm + _asm { pushad mov pBuildingAdd, esi mov pLODInterface, esi } StorePointerToBuilding(); - __asm + _asm { popad jmp JMP_CWorld_Add_CPopulation_ConvertToRealObject_CallCWorldAdd @@ -6437,15 +6437,15 @@ void RemoveObjectIfNeeded() } // on stream in -> create and remove it from the world just after so we can restore easily -void __declspec(naked) HOOK_ConvertToObject_CPopulationManageDummy() +void _declspec(naked) HOOK_ConvertToObject_CPopulationManageDummy() { - __asm + _asm { pushad mov pBuildingAdd, edx mov pLODInterface, edx } - __asm + _asm { popad push edx @@ -6455,7 +6455,7 @@ void __declspec(naked) HOOK_ConvertToObject_CPopulationManageDummy() pushad } RemoveObjectIfNeeded(); - __asm + _asm { popad jmp JMP_RETN_Cancel_CPopulation_ManageDummy @@ -6483,8 +6483,8 @@ void Handle_CWorld_Remove_CPopulation_ConvertToDummyObject() TIMING_CHECKPOINT("-RemovePointerToBuilding"); } -void __declspec(naked) HOOK_CWorld_Remove_CPopulation_ConvertToDummyObject(){ - __asm +void _declspec(naked) HOOK_CWorld_Remove_CPopulation_ConvertToDummyObject(){ + _asm { pushad mov pBuildingRemove, esi @@ -6492,12 +6492,12 @@ void __declspec(naked) HOOK_CWorld_Remove_CPopulation_ConvertToDummyObject(){ mov pLODInterface, edi } - __asm + _asm { call Handle_CWorld_Remove_CPopulation_ConvertToDummyObject } - __asm + _asm { popad jmp dwCWorldRemove @@ -6528,27 +6528,27 @@ void Handle_CheckForRemovalF() } // Function that handles dummy -> object so we can cancel this process if need be -void __declspec(naked) HOOK_CWorld_Add_CPopulation_ConvertToDummyObject() +void _declspec(naked) HOOK_CWorld_Add_CPopulation_ConvertToDummyObject() { - __asm + _asm { pushad mov pLODInterface, edi mov pBuildingAdd, edi } - __asm + _asm { call Handle_CheckForRemoval } StorePointerToBuilding(); if (CheckForRemoval()) { - __asm + _asm { call Handle_CheckForRemovalF } - __asm + _asm { popad jmp JMP_RETN_Cancelled_CPopulation_ConvertToDummyObject @@ -6556,11 +6556,11 @@ void __declspec(naked) HOOK_CWorld_Add_CPopulation_ConvertToDummyObject() } else { - __asm + _asm { call Handle_CheckForRemovalF } - __asm + _asm { popad push edi @@ -6571,30 +6571,30 @@ void __declspec(naked) HOOK_CWorld_Add_CPopulation_ConvertToDummyObject() } // Destructors to catch element deletion so we can delete their entries -void __declspec(naked) Hook_CBuilding_DTR() +void _declspec(naked) Hook_CBuilding_DTR() { - __asm + _asm { pushad mov pBuildingRemove, ecx } RemovePointerToBuilding(); - __asm + _asm { popad jmp JMP_CBuilding_DTR } } -void __declspec(naked) Hook_CDummy_DTR() +void _declspec(naked) Hook_CDummy_DTR() { - __asm + _asm { pushad mov pBuildingRemove, ecx } RemovePointerToBuilding(); - __asm + _asm { popad jmp JMP_CDummy_DTR @@ -6602,15 +6602,15 @@ void __declspec(naked) Hook_CDummy_DTR() } DWORD dwObjectVtbl = 0x866F60; -void __declspec(naked) Hook_CObject_DTR() +void _declspec(naked) Hook_CObject_DTR() { - __asm + _asm { pushad mov pBuildingRemove, esi } RemovePointerToBuilding(); - __asm + _asm { popad mov dword ptr [esi], offset dwObjectVtbl @@ -6620,9 +6620,9 @@ void __declspec(naked) Hook_CObject_DTR() static DWORD dwEntityVtbl; static DWORD dwMultResult; -void __declspec(naked) HOOK_CEntity_IsOnScreen_FixObjectScale() +void _declspec(naked) HOOK_CEntity_IsOnScreen_FixObjectScale() { - __asm + _asm { push 0xB6FA74 @@ -6633,7 +6633,7 @@ void __declspec(naked) HOOK_CEntity_IsOnScreen_FixObjectScale() if (dwEntityVtbl == 0x866F60) goto IsOnScreen_IsObject; - __asm + _asm { popad mov esi, ecx @@ -6641,7 +6641,7 @@ void __declspec(naked) HOOK_CEntity_IsOnScreen_FixObjectScale() } IsOnScreen_IsObject: - __asm + _asm { popad fld [eax+0x24] @@ -6656,9 +6656,9 @@ void __declspec(naked) HOOK_CEntity_IsOnScreen_FixObjectScale() ////////////////////////////////////////////////////////////////////////////////////////// // Only allow rebuild player on CJ - Stops other models getting corrupted (spider CJ) // hooked at 5A82C0 8 bytes -void __declspec(naked) HOOK_CClothes_RebuildPlayer() +void _declspec(naked) HOOK_CClothes_RebuildPlayer() { - __asm + _asm { push esi mov esi, [esp+8] @@ -6675,13 +6675,13 @@ void __declspec(naked) HOOK_CClothes_RebuildPlayer() } } -void __declspec(naked) HOOK_CProjectileInfo_Update_FindLocalPlayer_FindLocalPlayerVehicle() +void _declspec(naked) HOOK_CProjectileInfo_Update_FindLocalPlayer_FindLocalPlayerVehicle() { // 00739559 E8 B2 4C E3 FF call FindPlayerPed < HOOK > // 00739570 E8 5B 4B E3 FF call FindPlayerVehicle < HOOK > // Checks if the creator is the local player ped or the creator is the local player peds vehicle else decreases the velocity substantially. // We are forcing it to think the creator is not the local player ped or his vehicle for this specific check - __asm + _asm { xor eax, eax retn @@ -6715,7 +6715,7 @@ bool CallHeliKillEvent() return true; } -void __declspec(naked) HOOK_CHeli_ProcessHeliKill() +void _declspec(naked) HOOK_CHeli_ProcessHeliKill() { // 006DB201 0F 85 30 02 00 00 jnz loc_6DB437 < HOOK > // 006DB207 8B 47 14 mov eax, [edi+14h] < RETURN CONTINUE > @@ -6724,7 +6724,7 @@ void __declspec(naked) HOOK_CHeli_ProcessHeliKill() // We hook just after the check if he's touched the blade as before that it's just got the results of if he's near enough the heli to hit the blades // esi = Heli // edi = ped - __asm + _asm { pushfd pushad @@ -6734,7 +6734,7 @@ void __declspec(naked) HOOK_CHeli_ProcessHeliKill() // Call our event if (CallHeliKillEvent() == false) { - __asm + _asm { popad popfd @@ -6744,7 +6744,7 @@ void __declspec(naked) HOOK_CHeli_ProcessHeliKill() } else { - __asm + _asm { popad popfd @@ -6775,7 +6775,7 @@ bool TriggerObjectDamageEvent() return true; } -void __declspec(naked) HOOK_CObject_ProcessDamage() +void _declspec(naked) HOOK_CObject_ProcessDamage() { // .text:005A0DF7 mov ecx, [esi+160h] // .text:005A0DFD fld [esp+0D4h+arg_0] @@ -6783,7 +6783,7 @@ void __declspec(naked) HOOK_CObject_ProcessDamage() // .text:005A0E07 fsubr dword ptr [esi+154h] // .text:005A0E0D fst dword ptr [esi+154h] - __asm + _asm { pushad mov pDamagedObject, esi @@ -6793,7 +6793,7 @@ void __declspec(naked) HOOK_CObject_ProcessDamage() if (TriggerObjectDamageEvent()) { bObjectDamaged = true; - __asm + _asm { popad fst dword ptr [esi+154h] @@ -6803,7 +6803,7 @@ void __declspec(naked) HOOK_CObject_ProcessDamage() else { bObjectDamaged = false; - __asm + _asm { popad ffree st(0) @@ -6823,9 +6823,9 @@ bool TriggerObjectBreakEvent() return true; } -void __declspec(naked) HOOK_CObject_ProcessBreak() +void _declspec(naked) HOOK_CObject_ProcessBreak() { - __asm + _asm { pushad } @@ -6838,7 +6838,7 @@ void __declspec(naked) HOOK_CObject_ProcessBreak() if (!TriggerObjectBreakEvent()) { bObjectDamaged = false; - __asm + _asm { popad jmp RETURN_CObject_ProcessDamage_Cancel @@ -6847,7 +6847,7 @@ void __declspec(naked) HOOK_CObject_ProcessBreak() } } - __asm + _asm { popad cmp eax, 0C9h @@ -6855,11 +6855,11 @@ void __declspec(naked) HOOK_CObject_ProcessBreak() } } -void __declspec(naked) HOOK_CObject_ProcessCollision() +void _declspec(naked) HOOK_CObject_ProcessCollision() { if (bObjectDamaged) { - __asm + _asm { test byte ptr [esi+1Ch], 1 jnz checkfordynamic @@ -6871,7 +6871,7 @@ void __declspec(naked) HOOK_CObject_ProcessCollision() } else { - __asm + _asm { jmp RETURN_CObject_ProcessCollision } @@ -6879,9 +6879,9 @@ void __declspec(naked) HOOK_CObject_ProcessCollision() } DWORD WindowRespondsToCollision_CalledFrom = 0; -void __declspec(naked) HOOK_CGlass_WindowRespondsToCollision() +void _declspec(naked) HOOK_CGlass_WindowRespondsToCollision() { - __asm + _asm { push eax mov eax, [esp + 4] @@ -6893,7 +6893,7 @@ void __declspec(naked) HOOK_CGlass_WindowRespondsToCollision() if (WindowRespondsToCollision_CalledFrom != CALL_FROM_CGlass_WindowRespondsToExplosion) { - __asm + _asm { mov pDamagedObject, esi } @@ -6904,7 +6904,7 @@ void __declspec(naked) HOOK_CGlass_WindowRespondsToCollision() WindowRespondsToCollision_CalledFrom == CALL_FROM_CPhysical_ApplyCollision_2 || WindowRespondsToCollision_CalledFrom == CALL_FROM_CPhysical_ApplySoftCollision) { - __asm + _asm { mov pObjectAttacker, edi } @@ -6912,14 +6912,14 @@ void __declspec(naked) HOOK_CGlass_WindowRespondsToCollision() if (WindowRespondsToCollision_CalledFrom == CALL_FROM_CGlass_WasGlassHitByBullet) { - __asm + _asm { mov pObjectAttacker, ebx // WasGlassHitByBullet called from CWeapon::DoBulletImpact } if (!pObjectAttacker || (pObjectAttacker && !pObjectAttacker->m_pRwObject)) // WasGlassHitByBullet called from CBulletInfo::Update { - __asm + _asm { push ecx mov ecx, [edi] @@ -6931,7 +6931,7 @@ void __declspec(naked) HOOK_CGlass_WindowRespondsToCollision() if (WindowRespondsToCollision_CalledFrom == CALL_FROM_CGlass_WindowRespondsToExplosion) { - __asm + _asm { mov pDamagedObject, edx mov pObjectAttacker, ebp @@ -6943,7 +6943,7 @@ void __declspec(naked) HOOK_CGlass_WindowRespondsToCollision() if (TriggerObjectBreakEvent()) { - __asm + _asm { sub esp, 68h push esi @@ -6953,7 +6953,7 @@ void __declspec(naked) HOOK_CGlass_WindowRespondsToCollision() } else { - __asm + _asm { retn } @@ -6962,9 +6962,9 @@ void __declspec(naked) HOOK_CGlass_WindowRespondsToCollision() // Called when glass object is being broken by ped melee attack DWORD dummy_404350 = 0x404350; -void __declspec(naked) HOOK_CGlass__BreakGlassPhysically() +void _declspec(naked) HOOK_CGlass__BreakGlassPhysically() { - __asm + _asm { mov pDamagedObject, esi push ecx @@ -6975,7 +6975,7 @@ void __declspec(naked) HOOK_CGlass__BreakGlassPhysically() if (TriggerObjectBreakEvent()) { - __asm + _asm { // restore replaced part push dummy_404350 @@ -6985,7 +6985,7 @@ void __declspec(naked) HOOK_CGlass__BreakGlassPhysically() } else { - __asm + _asm { pop edi pop esi @@ -7006,9 +7006,9 @@ void FxManager_c__DestroyFxSystem() } } -void __declspec(naked) HOOK_FxManager_c__DestroyFxSystem() +void _declspec(naked) HOOK_FxManager_c__DestroyFxSystem() { - __asm + _asm { mov pFxSystemToBeDestroyed, edi pushad @@ -7016,7 +7016,7 @@ void __declspec(naked) HOOK_FxManager_c__DestroyFxSystem() FxManager_c__DestroyFxSystem(); - __asm + _asm { popad @@ -7040,16 +7040,16 @@ void CTaskSimpleGangDriveBy__ProcessPed() } DWORD RETURN_CTaskSimpleGangDriveBy_ProcessPed_Cancel = 0x62D5C1; -void __declspec(naked) HOOK_CTaskSimpleGangDriveBy__ProcessPed() +void _declspec(naked) HOOK_CTaskSimpleGangDriveBy__ProcessPed() { // esi contains 'this' - __asm + _asm { mov pProcessedGangDriveBySimpleTask, esi pushad } CTaskSimpleGangDriveBy__ProcessPed(); - __asm + _asm { popad // Replaced code @@ -7232,12 +7232,12 @@ bool ChooseMusicTrackIndex_SteamFix() These are as a result of the fact that steam updated gta-sa.exe and gta_sa.exe is our old exe which contains the arrays the game had originally for audio files All the files related to the deleted audio are zeroed and decompress to 5kb 0 length files which includes intros and outros. */ -void __declspec(naked) HOOK_CAERadioTrackManager__ChooseMusicTrackIndex() +void _declspec(naked) HOOK_CAERadioTrackManager__ChooseMusicTrackIndex() { // esi is our station id // al has the random number picked (music id the game wants to play) - __asm + _asm { add esp, 8 // fix the stack from the function call above as we overrote this instruction pushad // save our registers @@ -7248,7 +7248,7 @@ void __declspec(naked) HOOK_CAERadioTrackManager__ChooseMusicTrackIndex() // returns true if this is a restricted song if (ChooseMusicTrackIndex_SteamFix()) { - __asm + _asm { // pop the stack popad @@ -7259,7 +7259,7 @@ void __declspec(naked) HOOK_CAERadioTrackManager__ChooseMusicTrackIndex() } } // looks good, carry on - __asm + _asm { // pop the stack popad @@ -7271,9 +7271,9 @@ void __declspec(naked) HOOK_CAERadioTrackManager__ChooseMusicTrackIndex() } // Use AI heli rotor sound if player sound bank is not loaded -void __declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyHeli() +void _declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyHeli() { - __asm + _asm { // push our argument push [esp+8Ch+4] @@ -7286,9 +7286,9 @@ void __declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyHeli() } // Use AI plane propeller sound if player sound bank is not loaded -void __declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyProp() +void _declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyProp() { - __asm + _asm { // push our argument push [esp+98h+4] @@ -7301,9 +7301,9 @@ void __declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyProp() } const float kfTimeStepOriginal = 1.66f; -void __declspec(naked) HOOK_CTaskSimpleSwim_ProcessSwimmingResistance() +void _declspec(naked) HOOK_CTaskSimpleSwim_ProcessSwimmingResistance() { - __asm + _asm { fsub st, st(1) @@ -7362,9 +7362,9 @@ void PostCWorld_ProcessPedsAfterPreRender() } const DWORD CWorld_ProcessPedsAfterPreRender = 0x563430; -void __declspec(naked) HOOK_Idle_CWorld_ProcessPedsAfterPreRender() +void _declspec(naked) HOOK_Idle_CWorld_ProcessPedsAfterPreRender() { - __asm + _asm { call CWorld_ProcessPedsAfterPreRender call PostCWorld_ProcessPedsAfterPreRender @@ -7386,9 +7386,9 @@ void CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_ChangeStation(DWORD } // Start radio after entering audio zone -void __declspec(naked) HOOK_CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_StartRadio() +void _declspec(naked) HOOK_CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_StartRadio() { - __asm + _asm { push [esi+3] call CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_ChangeStation @@ -7403,9 +7403,9 @@ void __declspec(naked) HOOK_CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolum } // Stop radio after leaving audio zone -void __declspec(naked) HOOK_CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_StopRadio() +void _declspec(naked) HOOK_CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_StopRadio() { - __asm + _asm { push 0 call CAEAmbienceTrackManager__UpdateAmbienceTrackAndVolume_ChangeStation @@ -7437,9 +7437,9 @@ static void AddVehicleColoredDebris(CAutomobileSAInterface* pVehicleInterface, C } const DWORD RETURN_CAutomobile__dmgDrawCarCollidingParticles = 0x6A7081; -void __declspec(naked) HOOK_CAutomobile__dmgDrawCarCollidingParticles() +void _declspec(naked) HOOK_CAutomobile__dmgDrawCarCollidingParticles() { - __asm + _asm { lea eax, [esp + 0x1C] push ebp // count @@ -7460,9 +7460,9 @@ static void TakePhotograph() } const DWORD RETURN_CWeapon__TakePhotograph = 0x73C273; -void __declspec(naked) HOOK_CWeapon__TakePhotograph() +void _declspec(naked) HOOK_CWeapon__TakePhotograph() { - __asm + _asm { // Restore instructions replaced by hook add esp, 8 @@ -7502,9 +7502,9 @@ bool CanEntityCollideWithCamera(CEntitySAInterface* pEntity) return true; } -void __declspec(naked) HOOK_CCollision__CheckCameraCollisionObjects() +void _declspec(naked) HOOK_CCollision__CheckCameraCollisionObjects() { - __asm + _asm { // Restore instructions replaced by hook jz out2 From 22f98f7de02460ceb73f0e3a8154daded2fc0aec Mon Sep 17 00:00:00 2001 From: G_Moris <129879037+Black-Sun-Team@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:48:44 +0300 Subject: [PATCH 19/19] adjustments --- Client/game_sa/premake5.lua | 2 -- Client/multiplayer_sa/CMultiplayerSA.cpp | 2 +- Client/multiplayer_sa/premake5.lua | 6 ------ 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/Client/game_sa/premake5.lua b/Client/game_sa/premake5.lua index 8477058369..308ae0a6a2 100644 --- a/Client/game_sa/premake5.lua +++ b/Client/game_sa/premake5.lua @@ -4,8 +4,6 @@ project "Game SA" targetname "game_sa" targetdir(buildpath("mta")) - -- HACK(Jusonex): Temp fix for ebp not being set in naked functions - -- More information on this in multiplayer_sa's premake5.lua cppdialect "C++20" pchheader "StdInc.h" diff --git a/Client/multiplayer_sa/CMultiplayerSA.cpp b/Client/multiplayer_sa/CMultiplayerSA.cpp index acd79c90bc..0268688823 100644 --- a/Client/multiplayer_sa/CMultiplayerSA.cpp +++ b/Client/multiplayer_sa/CMultiplayerSA.cpp @@ -7364,7 +7364,7 @@ void PostCWorld_ProcessPedsAfterPreRender() const DWORD CWorld_ProcessPedsAfterPreRender = 0x563430; void _declspec(naked) HOOK_Idle_CWorld_ProcessPedsAfterPreRender() { - _asm + __asm { call CWorld_ProcessPedsAfterPreRender call PostCWorld_ProcessPedsAfterPreRender diff --git a/Client/multiplayer_sa/premake5.lua b/Client/multiplayer_sa/premake5.lua index c49a2ccac6..08893b884c 100644 --- a/Client/multiplayer_sa/premake5.lua +++ b/Client/multiplayer_sa/premake5.lua @@ -4,12 +4,6 @@ project "Multiplayer SA" targetname "multiplayer_sa" targetdir(buildpath("mta")) - -- HACK(Jusonex): Temp fix for ebp not being set in naked functions - -- VS2019 changed the evaluation order as required by the C++17 standard - -- which broke all functions marked with __declspec(naked) that call C++ code - -- Falling back to the old, C++14 implementing fixes this - -- See https://developercommunity.visualstudio.com/content/problem/549628/stack-access-broken-in-naked-function.html - -- We're not aware of any workaround to avoid rewriting multiplayer_sa cppdialect "C++20" filter "system:windows"