Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C++20 support for Client #3636

Open
wants to merge 74 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
4d49b80
Main
Moris-Onz Aug 9, 2024
1f10a85
Fixed part 1
Moris-Onz Aug 9, 2024
79b76ef
Fixed part 2
Moris-Onz Aug 9, 2024
d59efc1
Fix crash
Moris-Onz Aug 9, 2024
5cd6fc3
Fast fix by TracerDS
Moris-Onz Aug 9, 2024
1d8c1d7
Fixed by Tederis
Moris-Onz Aug 10, 2024
6a86788
Fast 666
Moris-Onz Aug 10, 2024
87a30e2
Merge branch 'master' into client_c20
G-Moris Aug 12, 2024
bd8e747
Merge branch 'master' into client_c20
G-Moris Aug 14, 2024
d64cd42
Merge branch 'master' into client_c20
G-Moris Aug 15, 2024
649cc85
Merge branch 'master' into client_c20
G-Moris Aug 15, 2024
41a6ccb
Merge branch 'master' into client_c20
G-Moris Aug 17, 2024
c55ed03
Merge branch 'master' into client_c20
G-Moris Aug 18, 2024
876e654
Merge branch 'master' into client_c20
G-Moris Aug 19, 2024
8c58a63
Merge branch 'master' into client_c20
G-Moris Aug 19, 2024
17f9dae
Merge branch 'master' into client_c20
G-Moris Aug 20, 2024
9fbe17f
Merge branch 'master' into client_c20
G-Moris Aug 22, 2024
3e8779b
Merge branch 'master' into client_c20
G-Moris Aug 25, 2024
160909f
Fixed by Botder
Moris-Onz Aug 25, 2024
9f3ebd3
Merge branch 'client_c20' of https://github.com/G-Moris/mtasa-blue in…
Moris-Onz Aug 25, 2024
fb1b6f7
Merge branch 'master' into client_c20
G-Moris Aug 28, 2024
9b171c2
Mini refactor
Moris-Onz Aug 28, 2024
6383ddf
Merge branch 'client_c20' of https://github.com/G-Moris/mtasa-blue in…
Moris-Onz Aug 28, 2024
4f0f087
Merge branch 'master' into client_c20
G-Moris Aug 31, 2024
65644c4
Merge branch 'master' into client_c20
G-Moris Sep 3, 2024
e964cb2
Merge branch 'master' into client_c20
G-Moris Sep 6, 2024
30c42e7
Update CEGUI
Moris-Onz Sep 6, 2024
01f3de7
Merge branch 'client_c20' of https://github.com/G-Moris/mtasa-blue in…
Moris-Onz Sep 6, 2024
33981ff
Update CEGUI (Full)
Moris-Onz Sep 6, 2024
055752b
Update Discord RPC and Tinygettext
Moris-Onz Sep 6, 2024
e7f3a86
Update Lunasvg
Moris-Onz Sep 6, 2024
7a11241
Test Fix multiplayer_sa
Moris-Onz Sep 6, 2024
903f812
Test fix game_sa
Moris-Onz Sep 6, 2024
50b0ac8
Merge branch 'master' into client_c20
G-Moris Sep 17, 2024
a9ff24c
Merge branch 'master' into client_c20
G-Moris Sep 22, 2024
0e16f15
Merge branch 'master' into client_c20
G-Moris Sep 26, 2024
ec3c7de
Merge branch 'master' into client_c20
G-Moris Sep 28, 2024
56990d5
Merge branch 'master' into client_c20
G-Moris Oct 5, 2024
5c137e2
Merge branch 'master' into client_c20
G-Moris Oct 11, 2024
c589f0b
Merge branch 'master' into client_c20
G-Moris Oct 14, 2024
10af729
std::string from CCommands
Moris-Onz Oct 14, 2024
b98217d
Merge branch 'client_c20' of https://github.com/G-Moris/mtasa-blue in…
Moris-Onz Oct 14, 2024
062cdff
Refactoring changes
Moris-Onz Oct 14, 2024
034fbf0
a fix for the minimalism of changes #1
Moris-Onz Oct 14, 2024
22f98f7
adjustments
Moris-Onz Oct 14, 2024
d39d170
a fix for the minimalism of changes #1
Moris-Onz Oct 14, 2024
7daf065
Merge branch 'master' into client_c20
G-Moris Oct 16, 2024
8b44e2a
Merge branch 'master' into client_c20
G-Moris Oct 19, 2024
1face51
Merge branch 'master' into client_c20
G-Moris Nov 7, 2024
249aadf
Merge branch 'master' into client_c20
G-Moris Nov 16, 2024
7ae7194
Merge branch 'master' into client_c20
G-Moris Nov 20, 2024
440b169
Merge branch 'master' into client_c20
G-Moris Nov 21, 2024
021fda4
Merge branch 'master' into client_c20
G-Moris Nov 27, 2024
0b9a97b
Merge branch 'master' into client_c20
G-Moris Nov 30, 2024
60865bb
Merge branch 'master' into client_c20
G-Moris Dec 4, 2024
def3d2a
Merge branch 'master' into client_c20
G-Moris Dec 24, 2024
cdeaad3
Merge branch 'master' into client_c20
G-Moris Dec 31, 2024
f920945
Merge branch 'client_c20' of https://github.com/G-Moris/mtasa-blue in…
Moris-Onz Jan 1, 2025
2380f38
Fix for new commits
Moris-Onz Jan 1, 2025
1a42391
Merge branch 'master' into client_c20
G-Moris Jan 1, 2025
1b65afd
Merge branch 'master' into client_c20
G-Moris Jan 2, 2025
422e2de
Merge branch 'master' into client_c20
G-Moris Jan 2, 2025
f6d4efe
Merge branch 'master' into client_c20
G-Moris Jan 2, 2025
e76d579
Merge branch 'master' into client_c20
G-Moris Jan 3, 2025
ac3895b
Merge branch 'master' into client_c20
G-Moris Jan 7, 2025
9d3df36
Merge branch 'master' into client_c20
G-Moris Jan 8, 2025
d2ecacb
Merge branch 'master' into client_c20
G-Moris Jan 9, 2025
4a44ad4
Merge branch 'master' into client_c20
G-Moris Jan 11, 2025
4925c4f
Fix for new commits 2
Moris-Onz Jan 11, 2025
01e64fc
Refactor CCommands::Execute
Moris-Onz Jan 11, 2025
471412b
Merge branch 'client_c20' of https://github.com/G-Moris/mtasa-blue in…
Moris-Onz Jan 11, 2025
c9a6eda
Merge branch 'master' into client_c20
G-Moris Jan 11, 2025
a89fb9f
Merge branch 'master' into client_c20
G-Moris Jan 12, 2025
8ec4253
Merge branch 'master' into client_c20
G-Moris Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Client/ceflauncher/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ project "CEFLauncher"
targetname "CEFLauncher"
targetdir(buildpath("mta/cef"))

cppdialect "C++20"

includedirs { "../sdk" }

links { "CEFLauncher DLL"}
Expand Down
2 changes: 2 additions & 0 deletions Client/ceflauncher_DLL/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
2 changes: 2 additions & 0 deletions Client/cefweb/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 2 additions & 2 deletions Client/core/CAdditionalVertexStreamManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
89 changes: 43 additions & 46 deletions Client/core/CCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>(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<char, 256> 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();
}
}
}
Expand All @@ -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)
Expand All @@ -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;

Expand All @@ -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())
Expand All @@ -211,18 +207,19 @@ 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;
}

if (wasHandled)
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;
}

Expand Down
2 changes: 1 addition & 1 deletion Client/core/CCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CCommands : public CCommandsInterface, public CSingleton<CCommands>
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();
Expand Down
43 changes: 35 additions & 8 deletions Client/core/CConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions Client/core/CConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions Client/core/CCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Client/core/CEntryHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
G-Moris marked this conversation as resolved.
Show resolved Hide resolved
if (iter != m_entries.end())
return &(*iter);
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Client/core/CFilePathTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Client/core/CKeyBinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,7 @@ void CKeyBinds::BindCommand(const char* szCmdLine)
{
CConsoleInterface* pConsole = m_pCore->GetConsole();

char* szError = "* Syntax: bind <defaults/key> [<up/down>] <command> [<arguments>]";
const char* szError = "* Syntax: bind <defaults/key> [<up/down>] <command> [<arguments>]";
if (szCmdLine == NULL)
{
pConsole->Print(szError);
Expand Down Expand Up @@ -2384,7 +2384,7 @@ void CKeyBinds::UnbindCommand(const char* szCmdLine)
{
CConsoleInterface* pConsole = m_pCore->GetConsole();

char* szError = "* Syntax: unbind <all/key> [<up/down/both> <command>]";
const char* szError = "* Syntax: unbind <all/key> [<up/down/both> <command>]";
if (szCmdLine == NULL)
{
pConsole->Print(szError);
Expand Down
6 changes: 3 additions & 3 deletions Client/core/CModManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Client/core/CVersionUpdater.Util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
};
Expand Down Expand Up @@ -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; }

Expand Down
Loading
Loading