Skip to content

Commit 160909f

Browse files
author
G_Moris
committed
Fixed by Botder
1 parent 6a86788 commit 160909f

20 files changed

+181
-143
lines changed

Client/core/CCommands.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
101101
if (szParameters[0] == '/')
102102
{
103103
// Copy the characters after the slash to the 0 terminator to a seperate buffer
104-
char szBuffer[256];
105-
strncpy(szBuffer, szParameters.get() + 1, 256);
106-
szBuffer[255] = 0;
104+
std::array<char, 256> szBuffer = {};
105+
strncpy(szBuffer.data(), szParameters.get() + 1, szBuffer.size() - 1);
106+
szBuffer.back() = '\0';
107107

108108
// Split it into command and arguments
109-
szCommand = strtok(szBuffer, " ");
109+
szCommand = strtok(szBuffer.data(), " ");
110110
if (!szCommand)
111111
return false;
112112

Client/core/CCore.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ static HMODULE WINAPI SkipDirectPlay_LoadLibraryA(LPCSTR fileName)
6060
const fs::path inLaunchDir = fs::path{FromUTF8(GetLaunchPath())} / "enbseries" / "enbhelper.dll";
6161

6262
if (fs::is_regular_file(inLaunchDir, ec))
63-
return Win32LoadLibraryA(inLaunchDir.string().c_str());
63+
return Win32LoadLibraryA(ToUTF8(inLaunchDir.wstring()).c_str());
6464

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

6868
if (fs::is_regular_file(inGTADir, ec))
69-
return Win32LoadLibraryA(inGTADir.string().c_str());
69+
return Win32LoadLibraryA(ToUTF8(inGTADir.wstring()).c_str());
7070

7171
return nullptr;
7272
}

Client/core/CFilePathTranslator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void CFilePathTranslator::GetCurrentWorkingDirectory(std::string& WorkingDirecto
8080

8181
void CFilePathTranslator::GetGTARootDirectory(std::string& ModuleRootDirOut)
8282
{
83-
ModuleRootDirOut = g_gtaDirectory.string();
83+
ModuleRootDirOut = ToUTF8(g_gtaDirectory.wstring());
8484
}
8585

8686
void CFilePathTranslator::GetMTASARootDirectory(std::string& InstallRootDirOut)

Client/core/CModManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,18 +338,18 @@ void CModManager::InitializeModList(const char* szModFolderPath)
338338
filePathTranslator.SetCurrentWorkingDirectory("mta");
339339

340340
// Create a search
341-
hFind = FindFirstFileW(FromUTF8(strPathWildchars), &FindData);
341+
hFind = FindFirstFileW(FromUTF8(strPathWildchars).c_str(), &FindData);
342342

343343
// If we found a first file ...
344344
if (hFind != INVALID_HANDLE_VALUE)
345345
{
346346
// Add it to the list
347-
VerifyAndAddEntry(szModFolderPath, ToUTF8(FindData.cFileName));
347+
VerifyAndAddEntry(szModFolderPath, ToUTF8(FindData.cFileName).c_str());
348348

349349
// Search until there aren't any files left
350350
while (FindNextFileW(hFind, &FindData) == TRUE)
351351
{
352-
VerifyAndAddEntry(szModFolderPath, ToUTF8(FindData.cFileName));
352+
VerifyAndAddEntry(szModFolderPath, ToUTF8(FindData.cFileName).c_str());
353353
}
354354

355355
// End the search

Client/core/ServerBrowser/CServerBrowser.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ void CServerBrowser::CreateHistoryList()
914914
for (CServerListReverseIterator it = m_ServersHistory.ReverseIteratorBegin(); it != m_ServersHistory.ReverseIteratorEnd(); it++)
915915
{
916916
CServerListItem* pServer = *it;
917-
if (pServer->strEndpoint)
917+
if (!pServer->strEndpoint.empty())
918918
{
919919
bEmpty = false;
920920
for (unsigned int i = 0; i < SERVER_BROWSER_TYPE_COUNT; i++)
@@ -1078,21 +1078,21 @@ void CServerBrowser::AddServerToList(CServerListItem* pServer, const ServerBrows
10781078
pServer->iRowIndex = iIndex;
10791079
}
10801080

1081-
const char* szVersion = !bIncludeOtherVersions ? "" : pServer->strVersion.c_str();
1082-
const SString strVersionSortKey = pServer->strVersionSortKey + pServer->strTieBreakSortKey;
1081+
const std::string strVersion = !bIncludeOtherVersions ? "" : pServer->strVersion;
1082+
const std::string strVersionSortKey = pServer->strVersionSortKey + pServer->strTieBreakSortKey;
10831083

1084-
const char* szPlayers = pServer->nMaxPlayers == 0 ? "" : SString("%d / %d", pServer->nPlayers, pServer->nMaxPlayers).c_str();
1085-
const SString strPlayersSortKey = SString("%04d-", pServer->nMaxPlayers ? pServer->nPlayers + 1 : 0) + pServer->strTieBreakSortKey;
1084+
const std::string strPlayers = pServer->nMaxPlayers == 0 ? "" : std::format("{} / {}", pServer->nPlayers, pServer->nMaxPlayers);
1085+
const std::string strPlayersSortKey = std::format("{:04d}-{}", pServer->nMaxPlayers ? pServer->nPlayers + 1 : 0, pServer->strTieBreakSortKey);
10861086

1087-
const char* szPing = pServer->nPing == 9999 ? "" : SString("%d", pServer->nPing).c_str();
1088-
const SString strPingSortKey = SString("%04d-", pServer->nPing) + pServer->strTieBreakSortKey;
1087+
const std::string strPing = pServer->nPing == 9999 ? "" : std::to_string(pServer->nPing);
1088+
const std::string strPingSortKey = std::format("{:04d}-{}", pServer->nPing, pServer->strTieBreakSortKey);
10891089

10901090
// The row index could change at any point here if list sorting is enabled
1091-
iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hVersion[Type], szVersion, false, false, true, strVersionSortKey);
1091+
iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hVersion[Type], strVersion.c_str(), false, false, true, strVersionSortKey.c_str());
10921092
iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hName[Type], pServer->strName.c_str(), false, false, true, pServer->strNameSortKey);
10931093
iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hGame[Type], pServer->strGameMode.c_str(), false, false, true);
1094-
iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hPlayers[Type], szPlayers, false, false, true, strPlayersSortKey);
1095-
iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hPing[Type], szPing, false, false, true, strPingSortKey);
1094+
iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hPlayers[Type], strPlayers.c_str(), false, false, true, strPlayersSortKey.c_str());
1095+
iIndex = m_pServerList[Type]->SetItemText(iIndex, m_hPing[Type], strPing.c_str(), false, false, true, strPingSortKey.c_str());
10961096

10971097
// Locked icon
10981098
m_pServerList[Type]->SetItemImage(iIndex, m_hLocked[Type], pServer->bPassworded ? m_pLockedIcon : NULL);

Client/core/ServerBrowser/CServerList.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,26 +196,26 @@ class CServerListItem
196196
bool bKeepFlag;
197197
int iRowIndex;
198198

199-
SString strGameName; // Game name. Always 'mta'
200-
SString strVersion; // Game version
201-
SString strName; // Server name
202-
SString strSearchableName; // Server name to use for searches
203-
SString strHost; // Server host as IP
204-
SString strHostName; // Server host as name
205-
SString strGameMode; // Gamemode
206-
SString strMap; // Map name
207-
SString strEndpoint; // IP:port as a string
199+
std::string strGameName; // Game name. Always 'mta'
200+
std::string strVersion; // Game version
201+
std::string strName; // Server name
202+
std::string strSearchableName; // Server name to use for searches
203+
std::string strHost; // Server host as IP
204+
std::string strHostName; // Server host as name
205+
std::string strGameMode; // Gamemode
206+
std::string strMap; // Map name
207+
std::string strEndpoint; // IP:port as a string
208208

209209
int m_iBuildType; // 9=release
210210
int m_iBuildNumber; // 00000 and up
211211
ushort m_usHttpPort;
212212
uchar m_ucSpecialFlags;
213213

214-
SString strNameSortKey; // Server name as a sortable string
215-
SString strVersionSortKey; // Game version as a sortable string
216-
SString strEndpointSortKey; // IP:port as a sortable string
217-
uint uiTieBreakPosition;
218-
SString strTieBreakSortKey;
214+
SString strNameSortKey; // Server name as a sortable string
215+
SString strVersionSortKey; // Game version as a sortable string
216+
SString strEndpointSortKey; // IP:port as a sortable string
217+
uint uiTieBreakPosition;
218+
std::string strTieBreakSortKey;
219219

220220
CQueryReceiver queryReceiver;
221221

@@ -234,7 +234,7 @@ class CServerListItem
234234
void PostChange()
235235
{
236236
// Update tie break sort key
237-
strTieBreakSortKey = SString("%04d", uiTieBreakPosition);
237+
strTieBreakSortKey = std::format("{:04d}", uiTieBreakPosition);
238238

239239
// Update version sort key
240240
strVersionSortKey = strVersion;

Client/game_sa/CWeaponSA.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,16 @@ bool CWeaponSA::Fire(CEntity* pFiringEntity, CVector* pvecOrigin, CVector* pvecT
177177

178178
void CWeaponSA::AddGunshell(CEntity* pFiringEntity, const CVector& vecOrigin, const CVector2D& vecDirection, float fSize)
179179
{
180-
const CVector* pvecOrigin = &vecOrigin;
181-
const CVector2D* pvecDirection = &vecDirection;
180+
DWORD dwEntityInterface = pFiringEntity ? reinterpret_cast<DWORD>(pFiringEntity->GetInterface()) : 0;
182181

183-
DWORD dwEntityInterface = 0;
184-
if (pFiringEntity)
185-
dwEntityInterface = (DWORD)pFiringEntity->GetInterface();
186-
DWORD dwThis = (DWORD)m_pInterface;
187-
DWORD dwFunc = FUNC_CWeapon_AddGunshell;
182+
static DWORD dwThis = reinterpret_cast<DWORD>(m_pInterface);
183+
static DWORD dwFunc = FUNC_CWeapon_AddGunshell;
188184
_asm
189185
{
190186
mov ecx, dwThis
191187
push fSize
192-
push pvecDirection
193-
push pvecOrigin
188+
push vecDirection
189+
push vecOrigin
194190
push dwEntityInterface
195191
call dwFunc
196192
}

Client/launch/Main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
5252

5353
// No Windows error box during first load attempt
5454
DWORD dwPrevMode = SetErrorMode(SEM_FAILCRITICALERRORS);
55-
HMODULE hModule = LoadLibraryW(FromUTF8(strLoaderDllPathFilename));
55+
HMODULE hModule = LoadLibraryW(FromUTF8(strLoaderDllPathFilename).c_str());
5656
DWORD dwLoadLibraryError = GetLastError();
5757
SetErrorMode(dwPrevMode);
5858

5959
if (!hModule)
6060
{
6161
// Retry using MTA current directory
62-
SetCurrentDirectoryW(FromUTF8(strMTASAPath));
63-
hModule = LoadLibraryW(FromUTF8(strLoaderDllPathFilename));
62+
SetCurrentDirectoryW(FromUTF8(strMTASAPath).c_str());
63+
hModule = LoadLibraryW(FromUTF8(strLoaderDllPathFilename).c_str());
6464
dwLoadLibraryError = GetLastError();
6565
if (hModule)
6666
{

Client/loader/CInstallManager.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -655,13 +655,13 @@ SString CInstallManager::_PrepareLaunchLocation()
655655
if (fs::is_regular_file(sourcePath, ec))
656656
{
657657
SString strMessage(_("MTA:SA cannot launch because copying a file failed:"));
658-
strMessage += "\n\n" + targetPath.string();
658+
strMessage += "\n\n" + ToUTF8(targetPath.wstring());
659659
BrowseToSolution("copy-files", ASK_GO_ONLINE, strMessage);
660660
}
661661
else
662662
{
663663
SString strMessage(_("MTA:SA cannot launch because an MTA:SA file is incorrect or missing:"));
664-
strMessage += "\n\n" + sourcePath.string();
664+
strMessage += "\n\n" + ToUTF8(sourcePath.wstring());
665665
BrowseToSolution("mta-datafiles-missing", ASK_GO_ONLINE, strMessage);
666666
}
667667

@@ -693,15 +693,15 @@ SString CInstallManager::_ProcessGtaPatchCheck()
693693
if (!FileGenerator::IsPatchBase(patchBasePath))
694694
{
695695
SString strMessage(_("MTA:SA cannot launch because a GTA:SA file is incorrect or missing:"));
696-
strMessage += "\n\n" + patchBasePath.string();
696+
strMessage += "\n\n" + ToUTF8(patchBasePath.wstring());
697697
BrowseToSolution("gengta_pakfiles", ASK_GO_ONLINE, strMessage);
698698
return "quit";
699699
}
700700

701701
if (!FileGenerator::IsPatchDiff(patchDiffPath))
702702
{
703703
SString strMessage(_("MTA:SA cannot launch because an MTA:SA file is incorrect or missing:"));
704-
strMessage += "\n\n" + patchDiffPath.string();
704+
strMessage += "\n\n" + ToUTF8(patchDiffPath.wstring());
705705
BrowseToSolution("mta-datafiles-missing", ASK_GO_ONLINE, strMessage);
706706
return "quit";
707707
}
@@ -771,7 +771,7 @@ SString CInstallManager::_ProcessGtaDllCheck()
771771
if (isAdmin)
772772
{
773773
SString strMessage(_("MTA:SA cannot launch because a GTA:SA file is incorrect or missing:"));
774-
strMessage += "\n\n" + dependecyPath.string();
774+
strMessage += "\n\n" + ToUTF8(dependecyPath.wstring());
775775
BrowseToSolution(SString("gendep_error&name=%s", dependency.fileName), ASK_GO_ONLINE, strMessage);
776776
return "quit";
777777
}
@@ -826,7 +826,7 @@ SString CInstallManager::_ProcessGtaVersionCheck()
826826
if (isAdmin)
827827
{
828828
SString strMessage(_("MTA:SA cannot launch because the GTA:SA executable is incorrect or missing:"));
829-
strMessage += "\n\n" + gtaExePath.string();
829+
strMessage += "\n\n" + ToUTF8(gtaExePath.wstring());
830830
strMessage +=
831831
"\n\n" +
832832
_("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()
851851
if (isAdmin)
852852
{
853853
SString strMessage(_("MTA:SA cannot launch because the GTA:SA executable is not loadable:"));
854-
strMessage += "\n\n" + gtaExePath.string();
854+
strMessage += "\n\n" + ToUTF8(gtaExePath.wstring());
855855
BrowseToSolution(SString("gengta_error&code=%d", ec.value()), ASK_GO_ONLINE, strMessage);
856856
return "quit";
857857
}
@@ -874,7 +874,7 @@ SString CInstallManager::_ProcessGtaVersionCheck()
874874
if (isAdmin)
875875
{
876876
SString strMessage(_("MTA:SA cannot launch because patching GTA:SA has failed:"));
877-
strMessage += "\n\n" + gtaExePath.string();
877+
strMessage += "\n\n" + ToUTF8(gtaExePath.wstring());
878878
BrowseToSolution(SString("patchgta_error&code=%d", ec.value()), ASK_GO_ONLINE, strMessage);
879879
return "quit";
880880
}
@@ -1275,7 +1275,8 @@ SString CInstallManager::_ProcessAppCompatChecks()
12751275
WString strUrlValue = ReadCompatibilityEntries(strUrlItem, strUrlKey, HKEY_CURRENT_USER, 0);
12761276
if (!strUrlValue.empty())
12771277
{
1278-
WriteDebugEvent(SString("GameUX ServiceLocation was '%s'", *ToUTF8(strUrlValue)));
1278+
WriteDebugEvent(std::format("GameUX ServiceLocation was '{}'", ToUTF8(strUrlValue)));
1279+
12791280
if (strUrlValue.ContainsI(L":"))
12801281
{
12811282
strUrlValue = L"disabled"; // Can be anything not containing `:`

Client/loader/Dialogs.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void InitDialogStrings(HWND hwndDialog, const SDialogItemInfo* dialogItems)
239239
SString("Possible text mismatch for dialog item (idx:%d id:%d) '%s' (orig:'%s')", i, item.iItemId, item.szItemText, szPrevText));
240240
}
241241
#endif
242-
SetWindowTextW(hwndItem, FromUTF8(strItemText));
242+
SetWindowTextW(hwndItem, FromUTF8(strItemText).c_str());
243243
}
244244
else
245245
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
409409
hwndProgressDialog = CreateDialogW(hInstance, MAKEINTRESOURCEW(IDD_PROGRESS_DIALOG), 0, DialogProc);
410410
dassert((GetWindowLong(hwndProgressDialog, GWL_STYLE) & WS_VISIBLE) == 0); // Should be Visible: False
411411
InitDialogStrings(hwndProgressDialog, g_ProgressDialogItems);
412-
SetWindowTextW(hwndProgressDialog, FromUTF8(strTitle));
412+
SetWindowTextW(hwndProgressDialog, FromUTF8(strTitle).c_str());
413413
ShowWindow(GetDlgItem(hwndProgressDialog, IDCANCEL), bAllowCancel ? SW_SHOW : SW_HIDE);
414414
ulProgressStartTime = GetTickCount32();
415415
}
@@ -443,7 +443,7 @@ bool UpdateProgress(int iPos, int iMax, const SString& strMsg)
443443
char buffer[1024] = "";
444444
GetWindowText(hwndText, buffer, NUMELMS(buffer));
445445
if (strMsg.length() > 0 && strMsg != buffer)
446-
SetWindowTextW(hwndText, FromUTF8(strMsg));
446+
SetWindowTextW(hwndText, FromUTF8(strMsg).c_str());
447447
HWND hwndBar = GetDlgItem(hwndProgressDialog, IDC_PROGRESS_BAR);
448448
PostMessage(hwndBar, PBM_SETPOS, iPos * 100 / std::max(1, iMax), 0);
449449
MSG msg;
@@ -506,7 +506,7 @@ SString ShowCrashedDialog(HINSTANCE hInstance, const SString& strMessage)
506506
hwndCrashedDialog = CreateDialogW(hInstance, MAKEINTRESOURCEW(IDD_CRASHED_DIALOG), 0, DialogProc);
507507
dassert((GetWindowLong(hwndCrashedDialog, GWL_STYLE) & WS_VISIBLE) == 0); // Should be Visible: False
508508
InitDialogStrings(hwndCrashedDialog, g_CrashedDialogItems);
509-
SetWindowTextW(GetDlgItem(hwndCrashedDialog, IDC_CRASH_INFO_EDIT), FromUTF8(strMessage));
509+
SetWindowTextW(GetDlgItem(hwndCrashedDialog, IDC_CRASH_INFO_EDIT), FromUTF8(strMessage).c_str());
510510
SendDlgItemMessage(hwndCrashedDialog, IDC_SEND_DUMP_CHECK, BM_SETCHECK,
511511
GetApplicationSetting("diagnostics", "send-dumps") != "no" ? BST_CHECKED : BST_UNCHECKED, 0);
512512
}
@@ -634,15 +634,15 @@ void ShowGraphicsDllDialog(HINSTANCE hInstance, const std::vector<GraphicsLibrar
634634
{
635635
// We grab the first offender's absolute file path to retrieve GTA's install directory
636636
SString gtaDirectory = ExtractPath(offenders.front().absoluteFilePath);
637-
LPITEMIDLIST gtaDirectoryItem = ILCreateFromPathW(FromUTF8(gtaDirectory));
637+
LPITEMIDLIST gtaDirectoryItem = ILCreateFromPathW(FromUTF8(gtaDirectory).c_str());
638638

639639
std::vector<LPITEMIDLIST> selectedItems;
640640

641641
if (gtaDirectoryItem != nullptr)
642642
{
643643
for (const GraphicsLibrary& library : offenders)
644644
{
645-
if (LPITEMIDLIST item = ILCreateFromPathW(FromUTF8(library.absoluteFilePath)); item != nullptr)
645+
if (LPITEMIDLIST item = ILCreateFromPathW(FromUTF8(library.absoluteFilePath).c_str()); item != nullptr)
646646
{
647647
selectedItems.emplace_back(item);
648648
}

0 commit comments

Comments
 (0)