Skip to content

Commit af30d18

Browse files
committed
Fix UTF-8 file hooks in core and game
The game couldn't open GXT files because changing the current directory "failed successfully" due to path truncation (invalid UTF-8 code-unit).
1 parent 4946dd4 commit af30d18

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Client/core/Core.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <filesystem>
1414
#define DECLARE_PROFILER_SECTION_Core
1515
#include "profiler/SharedUtil.Profiler.h"
16+
#define UTF8_FILE_HOOKS_PERSONALITY_Core
1617
#include "SharedUtil.Win32Utf8FileHooks.hpp"
1718

1819
#define CORE_API extern "C" __declspec(dllexport)

Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ BUT
4646
and many more...
4747
*/
4848

49+
#ifdef UTF8_FILE_HOOKS_PERSONALITY_Core
50+
#include <filesystem>
51+
52+
extern std::filesystem::path g_gtaDirectory;
53+
#endif
54+
4955
namespace SharedUtil
5056
{
5157
/////////////////////////////////////////////////////////////
@@ -83,6 +89,16 @@ namespace SharedUtil
8389
/////////////////////////////////////////////////////////////
8490
SString MakeSurePathIsUTF8(const SString& strOriginal)
8591
{
92+
#ifdef UTF8_FILE_HOOKS_PERSONALITY_Core
93+
static SString gtaDirCP = g_gtaDirectory.string();
94+
static SString gtaDirUTF8 = ToUTF8(g_gtaDirectory.wstring());
95+
if (strOriginal.BeginsWithI(gtaDirCP))
96+
{
97+
SString tail = strOriginal.SubStr(gtaDirCP.length());
98+
return PathJoin(gtaDirUTF8, tail);
99+
}
100+
#endif
101+
86102
static SString strLaunchPathCP, strLaunchPathUTF8;
87103
if (strLaunchPathCP.empty())
88104
{

0 commit comments

Comments
 (0)