diff options
-rw-r--r-- | NorthstarDedicatedTest/filesystem.cpp | 18 | ||||
-rw-r--r-- | NorthstarDedicatedTest/keyvalues.cpp | 20 | ||||
-rw-r--r-- | NorthstarDedicatedTest/modmanager.cpp | 5 |
3 files changed, 16 insertions, 27 deletions
diff --git a/NorthstarDedicatedTest/filesystem.cpp b/NorthstarDedicatedTest/filesystem.cpp index 72d7d4fc..73cb5a1a 100644 --- a/NorthstarDedicatedTest/filesystem.cpp +++ b/NorthstarDedicatedTest/filesystem.cpp @@ -101,25 +101,23 @@ bool TryReplaceFile(const char* pPath, bool shouldCompile) return false; } +// force modded files to be read from mods, not cache typedef bool (*ReadFromCacheType)(IFileSystem* filesystem, char* path, void* result); ReadFromCacheType ReadFromCache; bool ReadFromCacheHook(IFileSystem* filesystem, char* pPath, void* result) { - if (TryReplaceFile(pPath, false)) + if (TryReplaceFile(pPath, true)) return false; return ReadFromCache(filesystem, pPath, result); } +// force modded files to be read from mods, not vpk typedef FileHandle_t (*ReadFileFromVPKType)(VPKData* vpkInfo, __int64* b, char* filename); ReadFileFromVPKType ReadFileFromVPK; FileHandle_t ReadFileFromVPKHook(VPKData* vpkInfo, __int64* b, char* filename) { - // move this to a convar at some point when we can read them in native - //spdlog::info("ReadFileFromVPKHook {} {}", filename, vpkInfo->path); - - // there is literally never any reason to compile here, since we'll always compile in ReadFileFromFilesystemHook in the same codepath - // this is called + // don't compile here because this is only ever called from OpenEx, which already compiles if (TryReplaceFile(filename, false)) { *b = -1; @@ -134,13 +132,7 @@ typedef FileHandle_t (*CBaseFileSystem__OpenExType)( CBaseFileSystem__OpenExType CBaseFileSystem__OpenEx; FileHandle_t CBaseFileSystem__OpenExHook(IFileSystem* filesystem, const char* pPath, const char* pOptions, uint32_t flags, const char* pPathID, char **ppszResolvedFilename) { - //if (Cvar_ns_fs_log_reads->GetBool()) - - // this isn't super efficient, but it's necessary, since calling addsearchpath in readfilefromvpk doesn't work, possibly refactor later - // it also might be possible to hook functions that are called later, idk look into callstack for ReadFileFromVPK - if (!bReadingOriginalFile) - TryReplaceFile(pPath, true); - + TryReplaceFile(pPath, true); return CBaseFileSystem__OpenEx(filesystem, pPath, pOptions, flags, pPathID, ppszResolvedFilename); } diff --git a/NorthstarDedicatedTest/keyvalues.cpp b/NorthstarDedicatedTest/keyvalues.cpp index 0d6ae964..f79ff194 100644 --- a/NorthstarDedicatedTest/keyvalues.cpp +++ b/NorthstarDedicatedTest/keyvalues.cpp @@ -7,20 +7,9 @@ #include <fstream> -// hook forward defs typedef char (*KeyValues__LoadFromBufferType)( void* self, const char* resourceName, const char* pBuffer, void* pFileSystem, void* a5, void* a6, int a7); KeyValues__LoadFromBufferType KeyValues__LoadFromBuffer; -char KeyValues__LoadFromBufferHook( - void* self, const char* resourceName, const char* pBuffer, void* pFileSystem, void* a5, void* a6, int a7); - -ON_DLL_LOAD("engine.dll", KeyValues, [](HMODULE baseAddress) -{ - HookEnabler hook; - ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x426C30, &KeyValues__LoadFromBufferHook, reinterpret_cast<LPVOID*>(&KeyValues__LoadFromBuffer)); -}) - char KeyValues__LoadFromBufferHook(void* self, const char* resourceName, const char* pBuffer, void* pFileSystem, void* a5, void* a6, int a7) { static void* pSavedFilesystemPtr = nullptr; @@ -135,4 +124,11 @@ void ModManager::TryBuildKeyValues(const char* filename) m_modFiles.insert(std::make_pair(normalisedPath, overrideFile)); else m_modFiles[normalisedPath] = overrideFile; -}
\ No newline at end of file +} + +ON_DLL_LOAD("engine.dll", KeyValues, [](HMODULE baseAddress) +{ + HookEnabler hook; + ENABLER_CREATEHOOK( + hook, (char*)baseAddress + 0x426C30, &KeyValues__LoadFromBufferHook, reinterpret_cast<LPVOID*>(&KeyValues__LoadFromBuffer)); +})
\ No newline at end of file diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp index dd8e55cd..88aea71e 100644 --- a/NorthstarDedicatedTest/modmanager.cpp +++ b/NorthstarDedicatedTest/modmanager.cpp @@ -588,7 +588,8 @@ void ModManager::UnloadMods() std::string ModManager::NormaliseModFilePath(const fs::path path) { std::string str = path.lexically_normal().string(); - // go to lowercase + + // force to lowercase for (char& c : str) if (c <= 'Z' && c >= 'A') c = c - ('Z' - 'z'); @@ -598,7 +599,7 @@ std::string ModManager::NormaliseModFilePath(const fs::path path) void ModManager::CompileAssetsForFile(const char* filename) { - size_t fileHash = STR_HASH(fs::path(filename).lexically_normal().string()); + size_t fileHash = STR_HASH(NormaliseModFilePath(fs::path(filename))); if (fileHash == m_hScriptsRsonHash) BuildScriptsRson(); |