diff --git a/UE4SS/src/Mod/LuaMod.cpp b/UE4SS/src/Mod/LuaMod.cpp index 1b6e766aa..09c5f6875 100644 --- a/UE4SS/src/Mod/LuaMod.cpp +++ b/UE4SS/src/Mod/LuaMod.cpp @@ -816,20 +816,20 @@ namespace RC lua_getglobal(lua_state, "package"); lua_getfield(lua_state, -1, "path"); - std::string current_paths = lua_tostring(lua_state, -1); - current_paths.append(fmt::format(";{}\\{}\\Scripts\\?.lua", to_string(m_program.get_mods_directory()).c_str(), to_string(get_name()))); - current_paths.append(fmt::format(";{}\\shared\\?.lua", to_string(m_program.get_mods_directory()).c_str())); - current_paths.append(fmt::format(";{}\\shared\\?\\?.lua", to_string(m_program.get_mods_directory()).c_str())); + std::wstring current_paths = to_wstring(lua_tostring(lua_state, -1)); + current_paths.append(fmt::format(STR(";{}\\{}\\Scripts\\?.lua"), m_program.get_mods_directory(), get_name())); + current_paths.append(fmt::format(STR(";{}\\shared\\?.lua"), m_program.get_mods_directory())); + current_paths.append(fmt::format(STR(";{}\\shared\\?\\?.lua"), m_program.get_mods_directory())); lua_pop(lua_state, 1); - lua_pushstring(lua_state, current_paths.c_str()); + lua_pushstring(lua_state, to_string(current_paths).c_str()); lua_setfield(lua_state, -2, "path"); lua_getfield(lua_state, -1, "cpath"); - std::string current_cpaths = lua_tostring(lua_state, -1); - current_cpaths.append(fmt::format(";{}\\{}\\Scripts\\?.dll", to_string(m_program.get_mods_directory()).c_str(), to_string(get_name()))); - current_cpaths.append(fmt::format(";{}\\{}\\?.dll", to_string(m_program.get_mods_directory()).c_str(), to_string(get_name()))); + std::wstring current_cpaths = to_wstring(lua_tostring(lua_state, -1)); + current_cpaths.append(fmt::format(STR(";{}\\{}\\Scripts\\?.dll"), m_program.get_mods_directory(), get_name())); + current_cpaths.append(fmt::format(STR(";{}\\{}\\?.dll"), m_program.get_mods_directory(), get_name())); lua_pop(lua_state, 1); - lua_pushstring(lua_state, current_cpaths.c_str()); + lua_pushstring(lua_state, to_string(current_cpaths).c_str()); lua_setfield(lua_state, -2, "cpath"); lua_pop(lua_state, 1); @@ -2198,7 +2198,7 @@ No overload found for function 'IterateGameDirectories'. { throw std::runtime_error{"Couldn't find '__absolute_path' for directory entry."}; } - const auto current_path = std::string{lua.get_string()}; + const auto current_path = to_wstring(lua.get_string()); auto files_table = lua.prepare_new_table(); auto index = 1; for (const auto& item : std::filesystem::directory_iterator(current_path)) @@ -3364,7 +3364,7 @@ No overload found for function 'FPackageName:IsValidLongPackageName'. // Don't crash on syntax errors. try { - main_lua()->execute_file((m_scripts_path / STR("main.lua")).string()); + main_lua()->execute_file((m_scripts_path / STR("main.lua")).wstring()); } catch (std::runtime_error& e) { diff --git a/UE4SS/src/UE4SSProgram.cpp b/UE4SS/src/UE4SSProgram.cpp index 785b8eb97..db0c4c70b 100644 --- a/UE4SS/src/UE4SSProgram.cpp +++ b/UE4SS/src/UE4SSProgram.cpp @@ -1359,27 +1359,27 @@ namespace RC auto UE4SSProgram::get_module_directory() -> File::StringType { - return ensure_str(m_module_file_path); + return ensure_str(m_module_file_path.wstring()); } auto UE4SSProgram::get_game_executable_directory() -> File::StringType { - return ensure_str(m_game_executable_directory); + return ensure_str(m_game_executable_directory.wstring()); } auto UE4SSProgram::get_working_directory() -> File::StringType { - return ensure_str(m_working_directory); + return ensure_str(m_working_directory.wstring()); } auto UE4SSProgram::get_mods_directory() -> File::StringType { - return ensure_str(m_mods_directory); + return ensure_str(m_mods_directory.wstring()); } auto UE4SSProgram::get_legacy_root_directory() -> File::StringType { - return ensure_str(m_legacy_root_directory); + return ensure_str(m_legacy_root_directory.wstring()); } auto UE4SSProgram::generate_uht_compatible_headers() -> void diff --git a/deps/first/LuaRaw/include/lauxlib.h b/deps/first/LuaRaw/include/lauxlib.h index 5b977e2a3..34dd5659c 100644 --- a/deps/first/LuaRaw/include/lauxlib.h +++ b/deps/first/LuaRaw/include/lauxlib.h @@ -296,6 +296,7 @@ typedef struct luaL_Stream { +FILE* wfopen(const char *filename, const char *mode); #endif diff --git a/deps/first/LuaRaw/src/lauxlib.c b/deps/first/LuaRaw/src/lauxlib.c index 8ed1da112..fb8ba2957 100644 --- a/deps/first/LuaRaw/src/lauxlib.c +++ b/deps/first/LuaRaw/src/lauxlib.c @@ -9,6 +9,8 @@ #include "lprefix.h" +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include #include #include @@ -785,7 +787,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, } else { lua_pushfstring(L, "@%s", filename); - lf.f = fopen(filename, "r"); + lf.f = wfopen(filename, "r"); if (lf.f == NULL) return errfile(L, "open", fnameindex); } if (skipcomment(&lf, &c)) /* read initial portion */ @@ -1104,3 +1106,12 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) { (LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)v); } +FILE* wfopen(const char *filename, const char *mode) +{ + wchar_t buff[MAX_PATH+1]; + wchar_t modeBuff[MAX_PATH+1]; + if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, buff, MAX_PATH) == 0 || MultiByteToWideChar(CP_UTF8, 0, mode, -1, modeBuff, MAX_PATH) == 0) + return fopen(filename, mode); + + return _wfopen(buff, modeBuff); +} diff --git a/deps/first/LuaRaw/src/liolib.c b/deps/first/LuaRaw/src/liolib.c index b08397da4..43d6a0254 100644 --- a/deps/first/LuaRaw/src/liolib.c +++ b/deps/first/LuaRaw/src/liolib.c @@ -260,7 +260,7 @@ static LStream *newfile (lua_State *L) { static void opencheck (lua_State *L, const char *fname, const char *mode) { LStream *p = newfile(L); - p->f = fopen(fname, mode); + p->f = wfopen(fname, mode); if (l_unlikely(p->f == NULL)) luaL_error(L, "cannot open file '%s' (%s)", fname, strerror(errno)); } @@ -272,7 +272,7 @@ static int io_open (lua_State *L) { LStream *p = newfile(L); const char *md = mode; /* to traverse/check mode */ luaL_argcheck(L, l_checkmode(md), 2, "invalid mode"); - p->f = fopen(filename, mode); + p->f = wfopen(filename, mode); return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; } diff --git a/deps/first/LuaRaw/src/loadlib.c b/deps/first/LuaRaw/src/loadlib.c index 6f9fa3736..1a2e44f31 100644 --- a/deps/first/LuaRaw/src/loadlib.c +++ b/deps/first/LuaRaw/src/loadlib.c @@ -175,16 +175,21 @@ static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { ** of LUA_EXEC_DIR with the executable's path. */ static void setprogdir (lua_State *L) { + wchar_t wbuff[MAX_PATH + 1]; char buff[MAX_PATH + 1]; - char *lb; - DWORD nsize = sizeof(buff)/sizeof(char); - DWORD n = GetModuleFileNameA(NULL, buff, nsize); /* get exec. name */ - if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) - luaL_error(L, "unable to get ModuleFileName"); + wchar_t *lb; + DWORD nsize = sizeof(wbuff)/sizeof(wchar_t); + DWORD n = GetModuleFileNameW(NULL, wbuff, nsize); /* get exec. name */ + if (n == 0 || n == nsize || (lb = wcsrchr(wbuff, L'\\')) == NULL) + luaL_error(L, "unable to get ModuleFileName"); else { - *lb = '\0'; /* cut name on the last '\\' to get the path */ - luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff); - lua_remove(L, -2); /* remove original string */ + *lb = L'\0'; /* cut name on the last '\\' to get the path */ + if (WideCharToMultiByte(CP_UTF8,0,wbuff,-1,buff,MAX_PATH + 1,NULL,NULL) == 0) + luaL_error(L, "unable to get ModuleFileName"); + else { + luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff); + lua_remove(L, -2); /* remove original string */ + } } } @@ -432,7 +437,7 @@ static int ll_loadlib (lua_State *L) { static int readable (const char *filename) { - FILE *f = fopen(filename, "r"); /* try to open file */ + FILE *f = wfopen(filename, "r"); /* try to open file */ if (f == NULL) return 0; /* open failed */ fclose(f); return 1; diff --git a/deps/first/LuaRaw/src/luac.c b/deps/first/LuaRaw/src/luac.c index f6db9cf65..655f5ae5d 100644 --- a/deps/first/LuaRaw/src/luac.c +++ b/deps/first/LuaRaw/src/luac.c @@ -184,7 +184,7 @@ static int pmain(lua_State* L) if (listing) luaU_print(f,listing>1); if (dumping) { - FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); + FILE* D= (output==NULL) ? stdout : wfopen(output,"wb"); if (D==NULL) cannot("open"); lua_lock(L); luaU_dump(L,f,writer,D,stripping);