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 fecc85c3c6..471eb5b525 100644 --- a/Client/core/CCommands.cpp +++ b/Client/core/CCommands.cpp @@ -81,41 +81,37 @@ bool CCommands::Execute(const char* szCommandLine) return Execute(strCmd.c_str(), strCmdLine.c_str()); } -bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool bHandleRemotely, bool bIsScriptedBind) +bool CCommands::Execute(const char* command, const char* parametersIn, bool handleRemotely, bool isScriptedBind) { // Copy szParametersIn so the contents can be changed - char* szParameters = NULL; - if (szParametersIn) - { - size_t sizeParameters = strlen(szParametersIn) + 1; - szParameters = static_cast(alloca(sizeParameters)); - memcpy(szParameters, szParametersIn, sizeParameters); - } + std::string parameters(parametersIn ? parametersIn : ""); // 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 (!handleRemotely && !stricmp(command, "chatboxsay")) { - if (szParameters) + if (!parameters.empty()) { // His line starts with '/'? - if (*szParameters == '/') + if (parameters[0] == '/') { // Copy the characters after the slash to the 0 terminator to a seperate buffer - char szBuffer[256]; - strncpy(szBuffer, szParameters + 1, 256); - szBuffer[255] = 0; + std::array buffer = {}; + std::strncpy(buffer.data(), parameters.c_str() + 1, buffer.size() - 1); + buffer.back() = '\0'; // Split it into command and arguments - szCommand = strtok(szBuffer, " "); - szParameters = strtok(NULL, "\0"); - if (szCommand == NULL) - { + command = std::strtok(buffer.data(), " "); + if (!command) return false; + + if (char* newParameters = std::strtok(nullptr, "\0")) + { + parameters = std::string(newParameters); } - if (szParameters == NULL) + else { - szParameters = ""; + parameters.clear(); } } } @@ -124,30 +120,30 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool } // Grab the command - tagCOMMANDENTRY* pEntry = Get(szCommand); - bool wasHandled = false; - if (pEntry) + const tagCOMMANDENTRY* entry = Get(command); + bool wasHandled = false; + + // If its a core command, or if its enabled + if (entry && (!entry->bModCommand || entry->bEnabled)) { - // If its a core command, or if its enabled - if (!pEntry->bModCommand || pEntry->bEnabled) - { - // Execute it - if (!bIsScriptedBind || pEntry->bAllowScriptedBind) - ExecuteHandler(pEntry->pfnCmdFunc, szParameters); + // Execute it + if (!isScriptedBind || entry->bAllowScriptedBind) + ExecuteHandler(entry->pfnCmdFunc, parameters.c_str()); - wasHandled = true; - } + wasHandled = true; } // Recompose the original command text - std::string val = std::string(szCommand) + " " + std::string(szParameters ? szParameters : ""); + std::string val = command; + val += " "; + val += parameters; // Is it a cvar? (syntax: cvar[ = value]) if (!wasHandled) { // Check to see if '=' exists - unsigned int nOpIndex = val.find('='); - std::string key = val.substr(0, nOpIndex); + std::size_t nOpIndex = val.find('='); + std::string key = val.substr(0, nOpIndex); // Check to see if ' =' exists if (val.find(" =") != std::string::npos) @@ -158,7 +154,7 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool TrimWhiteSpace(key); // Handle the cvar if it exists - if (CClientVariables::GetSingleton().Exists(key) && !bIsScriptedBind) + if (CClientVariables::GetSingleton().Exists(key) && !isScriptedBind) { std::stringstream ss; @@ -184,22 +180,22 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool } ss << key << " = " << val; val = ss.str(); - CCore::GetSingleton().GetConsole()->Print(val.c_str()); + CCore::GetSingleton().GetConsole()->Print(val); return true; } } // HACK: if its a 'nick' command, save it here - bool bIsNickCommand = !stricmp(szCommand, "nick"); - if (!wasHandled && bIsNickCommand && szParameters && !bIsScriptedBind) + bool isNickCommand = !stricmp(command, "nick"); + if (!wasHandled && isNickCommand && !parameters.empty() && !isScriptedBind) { - if (CCore::GetSingleton().IsValidNick(szParameters)) + if (CCore::GetSingleton().IsValidNick(parameters.c_str())) { - CVARS_SET("nick", std::string(szParameters)); + CVARS_SET("nick", parameters); if (!CCore::GetSingleton().IsConnected()) { - CCore::GetSingleton().GetConsole()->Printf("nick: You are now known as %s", szParameters); + CCore::GetSingleton().GetConsole()->Print(std::format("nick: You are now known as {}", parameters)); } } else if (!CCore::GetSingleton().IsConnected()) @@ -211,8 +207,8 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool // Try to execute the handler if (m_pfnExecuteHandler) { - bool bAllowScriptedBind = (!pEntry || pEntry->bAllowScriptedBind); - if (m_pfnExecuteHandler(szCommand, szParameters, bHandleRemotely, wasHandled, bIsScriptedBind, bAllowScriptedBind)) + bool bAllowScriptedBind = (!entry || entry->bAllowScriptedBind); + if (m_pfnExecuteHandler(command, parameters.c_str(), handleRemotely, wasHandled, isScriptedBind, bAllowScriptedBind)) return true; } @@ -220,9 +216,10 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool return true; // Unknown command - val = _("Unknown command or cvar: ") + szCommand; - if (!bIsScriptedBind && !bIsNickCommand && pEntry == nullptr) - CCore::GetSingleton().GetConsole()->Print(val.c_str()); + val = _("Unknown command or cvar: ") + command; + if (!isScriptedBind && !isNickCommand && !entry) + CCore::GetSingleton().GetConsole()->Print(val); + return false; } diff --git a/Client/core/CCommands.h b/Client/core/CCommands.h index f05f47c207..e3b5e4d2d6 100644 --- a/Client/core/CCommands.h +++ b/Client/core/CCommands.h @@ -27,7 +27,7 @@ class CCommands : public CCommandsInterface, public CSingleton bool Exists(const char* szCommand); bool Execute(const char* szCommandLine); - bool Execute(const char* szCommand, const char* szParameters, bool bHandleRemotely = false, bool bIsScriptedBind = false); + bool Execute(const char* command, const char* parametersIn, bool handleRemotely = false, bool isScriptedBind = false); void Delete(const char* szCommand); void DeleteAll(); diff --git a/Client/core/CConsole.cpp b/Client/core/CConsole.cpp index 909d35ed37..d72ea7c1cf 100644 --- a/Client/core/CConsole.cpp +++ b/Client/core/CConsole.cpp @@ -64,10 +64,10 @@ CConsole::~CConsole() delete m_pConsoleHistory; } -void CConsole::Echo(const char* szText) +void CConsole::Echo(const char* text) { // Add to add buffer - m_strPendingAdd += szText; + m_strPendingAdd += text; if (!m_strPendingAdd.EndsWith("\n")) m_strPendingAdd += "\n"; @@ -83,27 +83,54 @@ void CConsole::Echo(const char* szText) if (m_pWindow->IsVisible()) FlushPendingAdd(); - CConsoleLogger::GetSingleton().LinePrintf("[Output] : %s", szText); + CConsoleLogger::GetSingleton().LinePrintf("[Output] : %s", text); } -void CConsole::Print(const char* szText) +void CConsole::Echo(const std::string& text) { - Echo(szText); + // Add to add buffer + m_strPendingAdd += text; + if (!m_strPendingAdd.EndsWith("\n")) + m_strPendingAdd += "\n"; + + // Trim add buffer + if (m_strPendingAdd.length() > CONSOLE_SIZE) + { + m_strPendingAdd = m_strPendingAdd.Right(CONSOLE_SIZE); + m_strPendingAdd = m_strPendingAdd.SplitRight("\n"); + m_pHistory->SetText(""); + } + + // Flush add buffer is window is visible + if (m_pWindow->IsVisible()) + FlushPendingAdd(); + + CConsoleLogger::GetSingleton().WriteLine("[Output] : " + text); } -void CConsole::Printf(const char* szFormat, ...) +void CConsole::Print(const char* text) +{ + Echo(text); +} + +void CConsole::Printf(const char* format, ...) { // Parse the formatted string to a string we can echo char szBuffer[1024]; va_list ap; - va_start(ap, szFormat); - VSNPRINTF(szBuffer, 1024, szFormat, ap); + va_start(ap, format); + VSNPRINTF(szBuffer, 1024, format, ap); va_end(ap); // Echo it Echo(szBuffer); } +void CConsole::Print(const std::string& text) +{ + Echo(text); +} + void CConsole::Clear() { // Clear the history buffer. diff --git a/Client/core/CConsole.h b/Client/core/CConsole.h index 677e1133ff..f83f284eb4 100644 --- a/Client/core/CConsole.h +++ b/Client/core/CConsole.h @@ -25,9 +25,12 @@ class CConsole : public CConsoleInterface CConsole(CGUI* pManager, CGUIElement* pParent = NULL); ~CConsole(); - void Echo(const char* szText); - void Print(const char* szText); - void Printf(const char* szFormat, ...); + void Echo(const char* text); + void Echo(const std::string& text); + + void Print(const char* text); + void Printf(const char* format, ...); + void Print(const std::string& text); void Clear(); diff --git a/Client/core/CCore.cpp b/Client/core/CCore.cpp index 12e8cf81d5..8bcc801773 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(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(inGTADir.u8string().c_str()); + return Win32LoadLibraryA(PathToUtf8(inGTADir).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..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 = g_gtaDirectory.u8string(); + ModuleRootDirOut = PathToUtf8(g_gtaDirectory); } void CFilePathTranslator::GetMTASARootDirectory(std::string& InstallRootDirOut) diff --git a/Client/core/CKeyBinds.cpp b/Client/core/CKeyBinds.cpp index 0a1eee4a1e..bc2e82ba3c 100644 --- a/Client/core/CKeyBinds.cpp +++ b/Client/core/CKeyBinds.cpp @@ -2301,7 +2301,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); @@ -2384,7 +2384,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/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/CVersionUpdater.Util.hpp b/Client/core/CVersionUpdater.Util.hpp index d6f7677c9a..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 : ""; + return pValue ? *pValue : SString(); } 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.empty() ? strFilter : SStringX("+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 2ea47cafdf..9ef6c1e9df 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++) @@ -1054,22 +1054,22 @@ void CServerBrowser::AddServerToList(CServerListItem* pServer, const ServerBrows pServer->iRowIndex = iIndex; } - const SString strVersion = !bIncludeOtherVersions ? "" : pServer->strVersion; - const SString strVersionSortKey = pServer->strVersionSortKey + pServer->strTieBreakSortKey; + const std::string strVersion = !bIncludeOtherVersions ? "" : pServer->strVersion; + const std::string strVersionSortKey = pServer->strVersionSortKey + pServer->strTieBreakSortKey; - const SString strVerified = pServer->isStatusVerified ? "" : "*"; - const SString strPlayers = pServer->nMaxPlayers == 0 ? "" : SString("%d / %d %s", pServer->nPlayers, pServer->nMaxPlayers, *strVerified); - const SString strPlayersSortKey = SString("%04d-", pServer->nMaxPlayers ? pServer->nPlayers + 1 : 0) + pServer->strTieBreakSortKey; + const std::string strVerified = pServer->isStatusVerified ? "" : "*"; + const std::string strPlayers = pServer->nMaxPlayers == 0 ? "" : std::format("{} / {} {}", pServer->nPlayers, pServer->nMaxPlayers, strVerified); + const std::string strPlayersSortKey = std::format("{:04d}-{}", pServer->nMaxPlayers ? pServer->nPlayers + 1 : 0, pServer->strTieBreakSortKey); - const SString strPing = pServer->nPing == 9999 ? "" : SString("%d", pServer->nPing); - 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], 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], 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], 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 5d0e450873..9aeb1f23be 100644 --- a/Client/core/ServerBrowser/CServerList.h +++ b/Client/core/ServerBrowser/CServerList.h @@ -198,26 +198,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; @@ -236,7 +236,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/core/premake5.lua b/Client/core/premake5.lua index 49755743a2..38fd14dc52 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/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/CModelInfoSA.cpp b/Client/game_sa/CModelInfoSA.cpp index 1c9e4ed4bf..5fcc25fe0c 100644 --- a/Client/game_sa/CModelInfoSA.cpp +++ b/Client/game_sa/CModelInfoSA.cpp @@ -1735,7 +1735,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 6d0e00c758..aee6cb7e1c 100644 --- a/Client/game_sa/CModelInfoSA.h +++ b/Client/game_sa/CModelInfoSA.h @@ -470,7 +470,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 MakeObjectDamageableModel(std::uint16_t usBaseModelID) override; void MakeVehicleAutomobile(ushort usBaseModelID); diff --git a/Client/game_sa/CWeaponSA.cpp b/Client/game_sa/CWeaponSA.cpp index d419734b8e..3b7a4ef791 100644 --- a/Client/game_sa/CWeaponSA.cpp +++ b/Client/game_sa/CWeaponSA.cpp @@ -175,19 +175,18 @@ 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) { - DWORD dwEntityInterface = 0; - if (pFiringEntity) - dwEntityInterface = (DWORD)pFiringEntity->GetInterface(); - DWORD dwThis = (DWORD)m_pInterface; - DWORD dwFunc = FUNC_CWeapon_AddGunshell; + DWORD dwEntityInterface = pFiringEntity ? reinterpret_cast(pFiringEntity->GetInterface()) : 0; + + 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/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/game_sa/CWorldSA.cpp b/Client/game_sa/CWorldSA.cpp index 72befc316e..6c1c02422d 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 646cfd6c66..85c9c06c7f 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); + void HookInstallCall(DWORD dwInstallAddress, DWORD dwHookFunction); template @@ -42,8 +46,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..308ae0a6a2 100644 --- a/Client/game_sa/premake5.lua +++ b/Client/game_sa/premake5.lua @@ -4,9 +4,7 @@ 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++14" + cppdialect "C++20" pchheader "StdInc.h" pchsource "StdInc.cpp" 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/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/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..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" + targetPath.u8string(); + 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" + sourcePath.u8string(); + 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" + patchBasePath.u8string(); + 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" + patchDiffPath.u8string(); + 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" + dependecyPath.u8string(); + 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" + gtaExePath.u8string(); + 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" + gtaExePath.u8string(); + 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" + gtaExePath.u8string(); + strMessage += "\n\n" + PathToUtf8(gtaExePath); 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 0) + if (strchr(pathList[0].c_str(), '?') != nullptr) return GAME_PATH_UNICODE_CHARS; } @@ -1280,7 +1280,7 @@ bool CheckService(uint uiStage) int GetFileAge(const SString& strPathFilename) { WIN32_FIND_DATAW findFileData; - HANDLE hFind = FindFirstFileW(FromUTF8(strPathFilename), &findFileData); + HANDLE hFind = FindFirstFileW(FromUTF8(strPathFilename).c_str(), &findFileData); if (hFind != INVALID_HANDLE_VALUE) { FindClose(hFind); @@ -1679,7 +1679,7 @@ void BsodDetectionPreLaunch() SString strMatch = PathJoin(GetSystemWindowsPath(), "MiniDump", "*"); SString strMinidumpTime; WIN32_FIND_DATAW findData; - HANDLE hFind = FindFirstFileW(FromUTF8(strMatch), &findData); + HANDLE hFind = FindFirstFileW(FromUTF8(strMatch).c_str(), &findData); if (hFind != INVALID_HANDLE_VALUE) { do 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..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; + SString strEnabledSD = sdInfo.empty() ? SStringX("None") : sdInfo; SString strDisabledAC = acInfo.SplitRight(","); - strDisabledAC = strDisabledAC == "" ? "None" : strDisabledAC; + strDisabledAC = strDisabledAC.empty() ? SStringX("None") : strDisabledAC; int iVerifyFiles = atoi(strVerifyFiles); if (iVerifyFiles == 0) diff --git a/Client/mods/deathmatch/logic/CBassAudio.cpp b/Client/mods/deathmatch/logic/CBassAudio.cpp index 21111ad224..d387963eb7 100644 --- a/Client/mods/deathmatch/logic/CBassAudio.cpp +++ b/Client/mods/deathmatch/logic/CBassAudio.cpp @@ -173,9 +173,9 @@ bool CBassAudio::BeginLoadingMedia() if (!m_pBuffer) { - m_pSound = BASS_StreamCreateFile(false, FromUTF8(m_strPath), 0, 0, lCreateFlags | BASS_UNICODE); + m_pSound = BASS_StreamCreateFile(false, FromUTF8(m_strPath).c_str(), 0, 0, lCreateFlags | BASS_UNICODE); if (!m_pSound) - m_pSound = BASS_MusicLoad(false, FromUTF8(m_strPath), 0, 0, BASS_MUSIC_RAMP | BASS_MUSIC_PRESCAN | BASS_STREAM_DECODE | BASS_UNICODE, + m_pSound = BASS_MusicLoad(false, FromUTF8(m_strPath).c_str(), 0, 0, BASS_MUSIC_RAMP | BASS_MUSIC_PRESCAN | BASS_STREAM_DECODE | BASS_UNICODE, 0); // Try again if (!m_pSound && m_b3D) m_pSound = ConvertFileToMono(m_strPath); // Last try if 3D @@ -346,8 +346,8 @@ int CBassAudio::ErrorGetCode() // HSTREAM CBassAudio::ConvertFileToMono(const SString& strPath) { - HSTREAM decoder = - BASS_StreamCreateFile(false, FromUTF8(strPath), 0, 0, BASS_STREAM_DECODE | BASS_SAMPLE_MONO | BASS_UNICODE); // open file for decoding + HSTREAM decoder = BASS_StreamCreateFile(false, FromUTF8(strPath).c_str(), 0, 0, + BASS_STREAM_DECODE | BASS_SAMPLE_MONO | BASS_UNICODE); // open file for decoding if (!decoder) return 0; // failed DWORD length = static_cast(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/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index dcb73b1738..2afb56975b 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -1031,7 +1031,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 "); + + std::string discordState = pVehicle ? g_vehicleTypePrefixes.at(vehicleType) : _("Walking around "); 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..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); - 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 ? "-" : 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); - 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 ? "-" : 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 e89923a5f8..c3dac0bd16 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) : SStringX("-"); + row[c++] = total_s > 0.0005 ? SString("%2.3f", total_s) : 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/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/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/Client/mods/deathmatch/logic/CServerIdManager.cpp b/Client/mods/deathmatch/logic/CServerIdManager.cpp index d8fc1d0ba8..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; }; /////////////////////////////////////////////////////////////// diff --git a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp index 4c70d03f04..0150e246fb 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp @@ -144,7 +144,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)) { @@ -157,5 +157,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 a622b3c54d..bdf88333b0 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, std::u // 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 adc83a1224..90c364e5b7 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp @@ -1196,7 +1196,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 ? 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 a6a688c366..bce009164b 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -325,12 +325,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 ? SStringX("raw data") : input, "Error loading COL"); } } else { - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Bad file path"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Bad file path"); } } } @@ -397,12 +397,12 @@ int CLuaEngineDefs::EngineLoadDFF(lua_State* luaVM) { // Delete it again delete pDFF; - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Error loading DFF"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Error loading DFF"); } } else { - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Bad file path"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Bad file path"); } } } @@ -471,11 +471,11 @@ int CLuaEngineDefs::EngineLoadTXD(lua_State* luaVM) { // Delete it again delete pTXD; - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Error loading TXD"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Error loading TXD"); } } else - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Bad file path"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Bad file path"); } } } @@ -536,12 +536,12 @@ int CLuaEngineDefs::EngineLoadIFP(lua_State* luaVM) } else { - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Error loading IFP"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Error loading IFP"); } } else { - argStream.SetCustomError(bIsRawData ? "raw data" : input, "Bad file path"); + argStream.SetCustomError(bIsRawData ? SStringX("raw data") : input, "Bad file path"); } } } @@ -655,7 +655,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/logic/luadefs/CLuaPlayerDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp index 4702e9ce3d..a0ae1ab437 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp @@ -944,18 +944,18 @@ std::variant, CLuaMultiR if (component == HUD_ALL || component == HUD_CROSSHAIR || component == HUD_VITAL_STATS || component == HUD_HELP_TEXT || component == HUD_RADAR) return false; - CHud* hud = g_pGame->GetHud(); + const CHud* hud = g_pGame->GetHud(); switch (property) { case eHudComponentProperty::POSITION: { - CVector2D& pos = hud->GetComponentPosition(component); + const CVector2D& pos = hud->GetComponentPosition(component); return CLuaMultiReturn{pos.fX, pos.fY}; } case eHudComponentProperty::SIZE: { - CVector2D& size = hud->GetComponentSize(component); + const CVector2D& size = hud->GetComponentSize(component); return CLuaMultiReturn{size.fX, size.fY}; } case eHudComponentProperty::FILL_COLOR: @@ -963,7 +963,7 @@ std::variant, CLuaMultiR if (!hud->IsComponentBar(component) && !hud->IsComponentText(component) && component != HUD_WEAPON) return false; - SColor& color = hud->GetComponentColor(component); + const SColor& color = hud->GetComponentColor(component); return CLuaMultiReturn{color.R, color.G, color.B, color.A}; } case eHudComponentProperty::FILL_COLOR_SECONDARY: @@ -971,7 +971,7 @@ std::variant, CLuaMultiR if (component != HUD_RADIO && component != HUD_MONEY && component != HUD_WANTED && component != HUD_WEAPON) return false; - SColor& color = hud->GetComponentSecondaryColor(component); + const SColor& color = hud->GetComponentSecondaryColor(component); return CLuaMultiReturn{color.R, color.G, color.B, color.A}; } case eHudComponentProperty::DROP_COLOR: @@ -979,7 +979,7 @@ std::variant, CLuaMultiR if (!hud->IsComponentText(component)) return false; - SColor& color = hud->GetComponentFontDropColor(component); + const SColor& color = hud->GetComponentFontDropColor(component); return CLuaMultiReturn{color.R, color.G, color.B, color.A}; } case eHudComponentProperty::DRAW_BLACK_BORDER: @@ -1042,7 +1042,7 @@ std::variant, CLuaMultiR return hud->GetComponentUseCustomAlpha(component); case eHudComponentProperty::TEXT_SIZE: { - CVector2D& size = hud->GetComponentTextSize(component); + const CVector2D& size = hud->GetComponentTextSize(component); return CLuaMultiReturn{size.fX, size.fY}; } } 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/multiplayer_sa/CMultiplayerSA.cpp b/Client/multiplayer_sa/CMultiplayerSA.cpp index f0cd566133..4d091f2e5b 100644 --- a/Client/multiplayer_sa/CMultiplayerSA.cpp +++ b/Client/multiplayer_sa/CMultiplayerSA.cpp @@ -3825,6 +3825,18 @@ 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() { @@ -3833,8 +3845,10 @@ void _declspec(naked) HOOK_CObject_PostRender() pushad } - TIMING_CHECKPOINT("-ObjRndr"); - RestoreAlphaValues(); + _asm + { + call Handle_ObjRndrF + } _asm { @@ -3853,8 +3867,10 @@ void _declspec(naked) HOOK_CObject_Render() pushad } - TIMING_CHECKPOINT("+ObjRndr"); - SetObjectAlpha(); + _asm + { + call Handle_ObjRndr + } _asm { @@ -5036,6 +5052,21 @@ 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() { @@ -5044,9 +5075,10 @@ void _declspec(naked) HOOK_CGame_Process() pushad } - TIMING_CHECKPOINT("+CWorld_Process"); - if (m_pPreWorldProcessHandler) - m_pPreWorldProcessHandler(); + _asm + { + call Handle_CWorld_Process + } _asm { @@ -5056,9 +5088,10 @@ void _declspec(naked) HOOK_CGame_Process() pushad } - if (m_pPostWorldProcessHandler) m_pPostWorldProcessHandler(); - - TIMING_CHECKPOINT("-CWorld_Process"); + _asm + { + call Handle_CWorld_ProcessF + } _asm { @@ -5080,22 +5113,40 @@ void __cdecl HandleIdle() m_pIdleHandler(); } +void CGame_Process() +{ + TIMING_CHECKPOINT("+CGame_Process"); +} + +void CGame_ProcessF() +{ + TIMING_CHECKPOINT("-CGame_Process"); +} + +void Idle() +{ + TIMING_CHECKPOINT("+Idle"); + if (m_pIdleHandler) + HandleIdle(); + TIMING_CHECKPOINT("-Idle"); +} + DWORD CALL_CGame_Process = 0x53BEE0; void _declspec(naked) HOOK_Idle() { - TIMING_CHECKPOINT("+CGame_Process"); _asm { + call CGame_Process call CALL_CGame_Process pushad } - TIMING_CHECKPOINT("-CGame_Process"); + _asm + { + call CGame_ProcessF - TIMING_CHECKPOINT("+Idle"); - if (m_pIdleHandler) - HandleIdle(); - TIMING_CHECKPOINT("-Idle"); + call Idle + } _asm { @@ -6425,8 +6476,16 @@ 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() { + TIMING_CHECKPOINT("+RemovePointerToBuilding"); + RemovePointerToBuilding(); + StorePointerToBuilding(); + RemoveObjectIfNeeded(); + TIMING_CHECKPOINT("-RemovePointerToBuilding"); +} + +void _declspec(naked) HOOK_CWorld_Remove_CPopulation_ConvertToDummyObject(){ _asm { pushad @@ -6434,11 +6493,12 @@ void _declspec(naked) HOOK_CWorld_Remove_CPopulation_ConvertToDummyObject() mov pBuildingAdd, edi mov pLODInterface, edi } - TIMING_CHECKPOINT("+RemovePointerToBuilding"); - RemovePointerToBuilding(); - StorePointerToBuilding(); - RemoveObjectIfNeeded(); - TIMING_CHECKPOINT("-RemovePointerToBuilding"); + + _asm + { + call Handle_CWorld_Remove_CPopulation_ConvertToDummyObject + } + _asm { popad @@ -6459,6 +6519,16 @@ 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() { @@ -6469,11 +6539,17 @@ void _declspec(naked) HOOK_CWorld_Add_CPopulation_ConvertToDummyObject() mov pBuildingAdd, edi } - TIMING_CHECKPOINT("+CheckForRemoval"); + _asm + { + call Handle_CheckForRemoval + } StorePointerToBuilding(); if (CheckForRemoval()) { - TIMING_CHECKPOINT("-CheckForRemoval"); + _asm + { + call Handle_CheckForRemovalF + } _asm { popad @@ -6482,7 +6558,10 @@ void _declspec(naked) HOOK_CWorld_Add_CPopulation_ConvertToDummyObject() } else { - TIMING_CHECKPOINT("-CheckForRemoval"); + _asm + { + call Handle_CheckForRemovalF + } _asm { popad @@ -7287,7 +7366,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 1d2386c9a5..08893b884c 100644 --- a/Client/multiplayer_sa/premake5.lua +++ b/Client/multiplayer_sa/premake5.lua @@ -4,13 +4,7 @@ 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++14" + cppdialect "C++20" filter "system:windows" includedirs { "../../vendor/sparsehash/src/windows" } diff --git a/Client/sdk/core/CCommandsInterface.h b/Client/sdk/core/CCommandsInterface.h index 2820bec69b..100d9e97ae 100644 --- a/Client/sdk/core/CCommandsInterface.h +++ b/Client/sdk/core/CCommandsInterface.h @@ -41,7 +41,7 @@ class CCommandsInterface virtual bool Exists(const char* szCommand) = 0; virtual bool Execute(const char* szCommandLine) = 0; - virtual bool Execute(const char* szCommand, const char* szParameters, bool bHandleRemotely = false, bool bIsScriptedBind = false) = 0; + virtual bool Execute(const char* command, const char* parametersIn, bool handleRemotely = false, bool isScriptedBind = false) = 0; virtual void Delete(const char* szCommand) = 0; virtual void DeleteAll() = 0; diff --git a/Client/sdk/core/CConsoleInterface.h b/Client/sdk/core/CConsoleInterface.h index 2937a89e5a..6faf90f9ed 100644 --- a/Client/sdk/core/CConsoleInterface.h +++ b/Client/sdk/core/CConsoleInterface.h @@ -14,9 +14,12 @@ class CConsoleInterface { public: - virtual void Echo(const char* szText) = 0; - virtual void Print(const char* szText) = 0; - virtual void Printf(const char* szFormat, ...) = 0; + virtual void Echo(const char* text) = 0; + virtual void Echo(const std::string& text) = 0; + + virtual void Print(const char* text) = 0; + virtual void Printf(const char* format, ...) = 0; + virtual void Print(const std::string& text) = 0; virtual void Clear() = 0; diff --git a/Client/sdk/game/CModelInfo.h b/Client/sdk/game/CModelInfo.h index 8b27fc0304..fa61351bba 100644 --- a/Client/sdk/game/CModelInfo.h +++ b/Client/sdk/game/CModelInfo.h @@ -234,7 +234,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 MakeObjectDamageableModel(std::uint16_t baseID) = 0; virtual void MakeVehicleAutomobile(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/Shared/mods/deathmatch/logic/lua/LuaBasic.h b/Shared/mods/deathmatch/logic/lua/LuaBasic.h index 5da557a64d..30c1c7fca8 100644 --- a/Shared/mods/deathmatch/logic/lua/LuaBasic.h +++ b/Shared/mods/deathmatch/logic/lua/LuaBasic.h @@ -31,7 +31,7 @@ namespace lua // PopTrival should read a simple value of type T from the stack without extra type checks // If whatever is at that point in the stack is not convertible to T, the behavior is undefined template - inline T PopPrimitive(lua_State* L, int& index); + T PopPrimitive(lua_State* L, int& index); // Push should push a value of type T to the Lua Stack // This will always increase the stack size by 1 diff --git a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp index 0b5847fa09..f5d0ceb74e 100644 --- a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp +++ b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp @@ -257,7 +257,7 @@ 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) diff --git a/Shared/sdk/SString.h b/Shared/sdk/SString.h index 4874073652..88a39390d5 100644 --- a/Shared/sdk/SString.h +++ b/Shared/sdk/SString.h @@ -152,15 +152,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.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..a07cca2241 100644 --- a/Shared/sdk/SharedUtil.File.h +++ b/Shared/sdk/SharedUtil.File.h @@ -1,13 +1,13 @@ /***************************************************************************** * - * 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 #include @@ -15,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 { // @@ -99,8 +111,13 @@ 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); + + // C++20? + #if __cplusplus >= 202002L + std::string PathToUtf8(const std::filesystem::path& path); + #endif std::vector ListDir(const char* szPath) noexcept; diff --git a/Shared/sdk/SharedUtil.File.hpp b/Shared/sdk/SharedUtil.File.hpp index 0a1cf56c7c..b39040378f 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" @@ -225,7 +224,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) @@ -577,7 +576,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); @@ -590,7 +589,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) @@ -618,45 +617,46 @@ 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 } +// C++20? +#if __cplusplus >= 202002L +std::string SharedUtil::PathToUtf8(const std::filesystem::path& path) +{ + return ToUTF8(path.wstring()); +} +#endif + #ifdef _WIN32 /////////////////////////////////////////////////////////////// // @@ -771,7 +771,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 @@ -1013,7 +1013,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); } @@ -1022,7 +1022,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); } @@ -1031,7 +1031,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 @@ -1040,7 +1040,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 @@ -1049,7 +1049,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 @@ -1058,7 +1058,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 @@ -1067,7 +1067,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 @@ -1076,7 +1076,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.Logging.hpp b/Shared/sdk/SharedUtil.Logging.hpp index f98b3bbdf6..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) : ""); - SString strFilenameOlder = strPathFilename + (uiOld ? SString(".%d", uiOld) : ""); + + SString strFilenameNewer = strPathFilename + (uiNew ? SString(".%d", uiNew) : SString()); + SString strFilenameOlder = strPathFilename + (uiOld ? SString(".%d", uiOld) : SString()); FileDelete(strFilenameOlder); FileRename(strFilenameNewer, strFilenameOlder); 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 cbfdc75251..1348f2bd44 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.u8string(); + static SString gtaDirUTF8 = PathToUtf8(g_gtaDirectory); 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/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/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" 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 { 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/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")) 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) 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 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", ".",