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

С++20 for Client #3636

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open

С++20 for Client #3636

wants to merge 36 commits into from

Conversation

G-Moris
Copy link
Contributor

@G-Moris G-Moris commented Aug 9, 2024

С++20 for Client, my test version

Copy link
Contributor

@TracerDS TracerDS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to introduce C++20 for Client but you change server code?
You also didnt tackle any issues regarding game_sa and multiplayer_sa

Client/core/CCommands.cpp Outdated Show resolved Hide resolved
Client/core/CCommands.cpp Outdated Show resolved Hide resolved
@@ -60,13 +60,13 @@ static HMODULE WINAPI SkipDirectPlay_LoadLibraryA(LPCSTR fileName)
const fs::path inLaunchDir = fs::path{FromUTF8(GetLaunchPath())} / "enbseries" / "enbhelper.dll";

if (fs::is_regular_file(inLaunchDir, ec))
return Win32LoadLibraryA(inLaunchDir.u8string().c_str());
return Win32LoadLibraryA(inLaunchDir.string().c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave it as u8string for utf8 compatibility

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this conversation marked as resolved?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below. In C++20 path.u8string may/will return std::basic_string<char8_t> which is incompatible with std::string

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something you're not aware of: in the MSVC STL implementation of std::filesystem::path the actual path is stored as a wide string (using string_type = std::wstring) and the path::u8string function uses _Convert_wide_to_narrow to convert the wide string to a narrow variant with the UTF-8 codepage there, but the path::string() function uses the active code page (ACP), which isn't going to be UTF-8 in most cases.

Copy link
Contributor Author

@G-Moris G-Moris Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something you're not aware of: in the MSVC STL implementation of std::filesystem::path the actual path is stored as a wide string (using string_type = std::wstring) and the path::u8string function uses _Convert_wide_to_narrow to convert the wide string to a narrow variant with the UTF-8 codepage there, but the path::string() function uses the active code page (ACP), which isn't going to be UTF-8 in most cases.

Should I use ToACP for u8string? I understood correctly? For example: ToACP(inLaunchDir.u8string()).c_str();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to call Windows API functions like LoadLibraryA with the *A suffix, then you need the active code page encoding (ACP), which you get from path::string(). For any other code that expects UTF-8, you have to take the wide string path::wstring() and convert it with ToUTF8 (one of our functions - but please double-check that it actually converts from wide to narrow UTF-8), or you continue using path::u8string() but cast the values from char8_t* to char*, for example.


// Try to load enbhelper.dll from the GTA install directory second.
const fs::path inGTADir = g_gtaDirectory / "enbseries" / "enbhelper.dll";

if (fs::is_regular_file(inGTADir, ec))
return Win32LoadLibraryA(inGTADir.u8string().c_str());
return Win32LoadLibraryA(inGTADir.string().c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave it as u8string for utf8 compatibility

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c_str in 'u8' returns char8_t, which is not compatible with LPCSTR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it changes in the C++20. Nevermind then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I close this and the like?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment

Client/core/CEntryHistory.h Show resolved Hide resolved
Server/launcher/premake5.lua Outdated Show resolved Hide resolved
Server/mods/deathmatch/premake5.lua Outdated Show resolved Hide resolved
Shared/sdk/SharedUtil.Logging.hpp Outdated Show resolved Hide resolved
Shared/sdk/SString.h Show resolved Hide resolved
Client/core/CCommands.cpp Outdated Show resolved Hide resolved
Client/core/CCommands.cpp Outdated Show resolved Hide resolved
@@ -60,13 +60,13 @@ static HMODULE WINAPI SkipDirectPlay_LoadLibraryA(LPCSTR fileName)
const fs::path inLaunchDir = fs::path{FromUTF8(GetLaunchPath())} / "enbseries" / "enbhelper.dll";

if (fs::is_regular_file(inLaunchDir, ec))
return Win32LoadLibraryA(inLaunchDir.u8string().c_str());
return Win32LoadLibraryA(inLaunchDir.string().c_str());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this conversation marked as resolved?

Client/core/CVersionUpdater.Util.hpp Outdated Show resolved Hide resolved
@G-Moris G-Moris requested a review from tederis August 15, 2024 16:19
@@ -84,12 +84,11 @@ bool CCommands::Execute(const char* szCommandLine)
bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool bHandleRemotely, bool bIsScriptedBind)
{
// Copy szParametersIn so the contents can be changed
char* szParameters = NULL;
std::unique_ptr<char[]> szParameters = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you not using std::string?

@@ -99,23 +98,27 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
if (szParameters)
{
// His line starts with '/'?
if (*szParameters == '/')
if (szParameters[0] == '/')
{
// Copy the characters after the slash to the 0 terminator to a seperate buffer
char szBuffer[256];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you already refactor this code, use a std::array here.

const SString strVersionSortKey = pServer->strVersionSortKey + pServer->strTieBreakSortKey;

const SString strPlayers = pServer->nMaxPlayers == 0 ? "" : SString("%d / %d", pServer->nPlayers, pServer->nMaxPlayers);
const char* szPlayers = pServer->nMaxPlayers == 0 ? "" : SString("%d / %d", pServer->nPlayers, pServer->nMaxPlayers).c_str();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You create a SString on the right side, and take the pointer to the internal heap allocated string (though small string optimization might work here and you would get a stack pointer instead), but after this statement/line, the SString will go through the destructor and your szPlayers pointer will point to freed memory.

const SString strPlayersSortKey = SString("%04d-", pServer->nMaxPlayers ? pServer->nPlayers + 1 : 0) + pServer->strTieBreakSortKey;

const SString strPing = pServer->nPing == 9999 ? "" : SString("%d", pServer->nPing);
const char* szPing = pServer->nPing == 9999 ? "" : SString("%d", pServer->nPing).c_str();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same problem with the SString. See other review comment.

Comment on lines 180 to 181
const CVector* pvecOrigin = &vecOrigin;
const CVector2D* pvecDirection = &vecDirection;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just lazy. Refactor the code to work with the references.

Shared/sdk/SString.h Show resolved Hide resolved
@@ -107,7 +107,7 @@ namespace SharedUtil
{
#ifdef UTF8_FILE_HOOKS_PERSONALITY_Core
static SString gtaDirCP = ToACP(g_gtaDirectory);
static SString gtaDirUTF8 = g_gtaDirectory.u8string();
static SString gtaDirUTF8 = g_gtaDirectory.string();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::filesystem::path::string does not return a narrow string with UTF-8 encoding.

@G-Moris
Copy link
Contributor Author

G-Moris commented Aug 25, 2024

@botder @tederis Do my corrections fit your requirements?

@G-Moris
Copy link
Contributor Author

G-Moris commented Aug 31, 2024

@Dutchman101 Hello! Sorry for the trouble and for the fact that this is not on the topic of PR, can you please unblock me in the Multi Theft Development group? I'm not going to bother anyone or prescribe something bad. It's just that in some developments I want to work together with those who want it.

@G-Moris
Copy link
Contributor Author

G-Moris commented Sep 6, 2024

You want to introduce C++20 for Client but you change server code? You also didnt tackle any issues regarding game_sa and multiplayer_sa

Maybe I'll try to solve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants