diff --git a/UnleashedRecomp/kernel/io/file_system.cpp b/UnleashedRecomp/kernel/io/file_system.cpp index 3079cdff..b9bf3610 100644 --- a/UnleashedRecomp/kernel/io/file_system.cpp +++ b/UnleashedRecomp/kernel/io/file_system.cpp @@ -54,7 +54,7 @@ struct FindHandle : KernelObject } } - addDirectory(std::u8string_view((const char8_t*)FileSystem::TransformPath(path))); + addDirectory(FileSystem::ResolvePath(path, false)); iterator = searchResult.begin(); } @@ -75,15 +75,6 @@ struct FindHandle : KernelObject } }; -static std::filesystem::path TransformOrRedirectPath(const char* path) -{ - std::filesystem::path redirectedPath = ModLoader::RedirectPath(path); - if (redirectedPath.empty()) - redirectedPath = std::u8string_view((const char8_t*)FileSystem::TransformPath(path)); - - return redirectedPath; -} - SWA_API FileHandle* XCreateFileA ( const char* lpFileName, @@ -98,7 +89,7 @@ SWA_API FileHandle* XCreateFileA assert(((dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE)) == 0) && "Unknown share mode bits."); assert(((dwCreationDisposition & ~(CREATE_NEW | CREATE_ALWAYS)) == 0) && "Unknown creation disposition bits."); - std::filesystem::path filePath = TransformOrRedirectPath(lpFileName); + std::filesystem::path filePath = FileSystem::ResolvePath(lpFileName, true); std::fstream fileStream; std::ios::openmode fileOpenMode = std::ios::binary; if (dwDesiredAccess & (GENERIC_READ | FILE_READ_DATA)) @@ -343,7 +334,7 @@ uint32_t XReadFileEx(FileHandle* hFile, void* lpBuffer, uint32_t nNumberOfBytesT uint32_t XGetFileAttributesA(const char* lpFileName) { - std::filesystem::path filePath = TransformOrRedirectPath(lpFileName); + std::filesystem::path filePath = FileSystem::ResolvePath(lpFileName, true); if (std::filesystem::is_directory(filePath)) return FILE_ATTRIBUTE_DIRECTORY; else if (std::filesystem::is_regular_file(filePath)) @@ -366,8 +357,15 @@ uint32_t XWriteFile(FileHandle* hFile, const void* lpBuffer, uint32_t nNumberOfB return TRUE; } -const char* FileSystem::TransformPath(const std::string_view& path) +std::filesystem::path FileSystem::ResolvePath(const std::string_view& path, bool checkForMods) { + if (checkForMods) + { + std::filesystem::path resolvedPath = ModLoader::ResolvePath(path); + if (!resolvedPath.empty()) + return resolvedPath; + } + thread_local std::string builtPath; builtPath.clear(); @@ -393,12 +391,7 @@ const char* FileSystem::TransformPath(const std::string_view& path) std::replace(builtPath.begin(), builtPath.end(), '\\', '/'); - return builtPath.c_str(); -} - -SWA_API const char* XExpandFilePathA(const char* path) -{ - return FileSystem::TransformPath(path); + return std::u8string_view((const char8_t*)builtPath.c_str()); } GUEST_FUNCTION_HOOK(sub_82BD4668, XCreateFileA); diff --git a/UnleashedRecomp/kernel/io/file_system.h b/UnleashedRecomp/kernel/io/file_system.h index b3929e4b..86c73b70 100644 --- a/UnleashedRecomp/kernel/io/file_system.h +++ b/UnleashedRecomp/kernel/io/file_system.h @@ -2,5 +2,5 @@ struct FileSystem { - static const char* TransformPath(const std::string_view& path); + static std::filesystem::path ResolvePath(const std::string_view& path, bool checkForMods); }; diff --git a/UnleashedRecomp/main.cpp b/UnleashedRecomp/main.cpp index 8b255632..c7a6a718 100644 --- a/UnleashedRecomp/main.cpp +++ b/UnleashedRecomp/main.cpp @@ -182,8 +182,8 @@ int main(int argc, char *argv[]) KiSystemStartup(); - const char *modulePath = FileSystem::TransformPath(GAME_XEX_PATH); - uint32_t entry = LdrLoadModule(std::u8string_view((const char8_t*)(modulePath))); + auto modulePath = FileSystem::ResolvePath(GAME_XEX_PATH, false); + uint32_t entry = LdrLoadModule(modulePath); if (!runInstallerWizard) Video::CreateHostDevice(sdlVideoDriver); diff --git a/UnleashedRecomp/mod/mod_loader.cpp b/UnleashedRecomp/mod/mod_loader.cpp index 5da26730..9b8c3528 100644 --- a/UnleashedRecomp/mod/mod_loader.cpp +++ b/UnleashedRecomp/mod/mod_loader.cpp @@ -23,7 +23,7 @@ struct Mod static std::vector g_mods; -std::filesystem::path ModLoader::RedirectPath(std::string_view path) +std::filesystem::path ModLoader::ResolvePath(std::string_view path) { if (g_mods.empty()) return {}; diff --git a/UnleashedRecomp/mod/mod_loader.h b/UnleashedRecomp/mod/mod_loader.h index 73f4961a..84a58302 100644 --- a/UnleashedRecomp/mod/mod_loader.h +++ b/UnleashedRecomp/mod/mod_loader.h @@ -4,7 +4,7 @@ struct ModLoader { static inline std::filesystem::path s_saveFilePath; - static std::filesystem::path RedirectPath(std::string_view path); + static std::filesystem::path ResolvePath(std::string_view path); static std::vector* GetIncludeDirectories(size_t modIndex);