From 3a8647b6f49eba3c40dd80baa57882a9e631b637 Mon Sep 17 00:00:00 2001 From: Marvin D <41352111+IcePixelx@users.noreply.github.com> Date: Mon, 22 Aug 2022 14:43:06 +0200 Subject: [PATCH] Load .starpak from /Win32/ support * S3< not tested. --- r5dev/common/opcodes.cpp | 25 +++++++++++++++++++++++++ r5dev/rtech/rtech_game.h | 8 +++++++- r5dev/rtech/rtech_utils.cpp | 4 +++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/r5dev/common/opcodes.cpp b/r5dev/common/opcodes.cpp index 43ef9a60..2d81a0d2 100644 --- a/r5dev/common/opcodes.cpp +++ b/r5dev/common/opcodes.cpp @@ -377,4 +377,29 @@ void RuntimePtc_Init() /* .TEXT */ #ifndef CLIENT_DLL Server_S2C_CONNECT_1.Offset(0x7).Patch({ 0xEB }); // JZ --> JMP | Prevent entitlement check to kick player from server on S2C_CONNECT Packet if it does not match the servers one. #endif // !CLIENT_DLL + + vector starPakOpenFile = { + 0x4D, 0x31, 0xC0, // xor, r8, r8 + 0x48, 0x8D, 0x8C, 0x24, 0x90, 0x00, 0x00, 0x00, // lea rcx, [rsp+378h+90h] FileName + // call RTech::OpenFile [RIP+RVA] + #if defined (GAMEDLL_S0) + 0xE8, 0x87, 0x96, 0xFF, 0xFF, + #elif defined (GAMEDLL_S1) + 0xE8, 0x27, 0x95, 0xFF, 0xFF, + #elif defined (GAMEDLL_S2) + 0xE8, 0x97, 0x95, 0xFF, 0xFF, + #elif defined (GAMEDLL_S3) + 0xE8, 0x77, 0x8F, 0xFF, 0xFF, + #endif + + 0x8B, 0xF8, // mov edi, eax + // jmp [RIP+RVA] + #if defined (GAMEDLL_S0) || defined(GAMEDLL_S1) + 0xE9, 0xDC, 0x00, 0x00, 0x00 + #elif defined (GAMEDLL_S2) || defined(GAMEDLL_S3) + 0xE9, 0xDA, 0x00, 0x00, 0x00 + #endif + }; + + p_CPakFile_LoadPak_OpenFileOffset.Patch(starPakOpenFile); } diff --git a/r5dev/rtech/rtech_game.h b/r5dev/rtech/rtech_game.h index 5fc89b2f..a56d4470 100644 --- a/r5dev/rtech/rtech_game.h +++ b/r5dev/rtech/rtech_game.h @@ -34,6 +34,8 @@ inline auto CPakFile_LoadPak = p_CPakFile_LoadPak.RCast(); +inline CMemory p_CPakFile_LoadPak_OpenFileOffset; + class CPakFile { public: @@ -54,6 +56,7 @@ class VRTechGame : public IDetour spdlog::debug("| FUN: CPakFile::LoadAsync : {:#18x} |\n", p_CPakFile_LoadAsync.GetPtr()); spdlog::debug("| FUN: CPakFile::LoadPak : {:#18x} |\n", p_CPakFile_LoadPak.GetPtr()); spdlog::debug("| FUN: CPakFile::UnloadPak : {:#18x} |\n", p_CPakFile_UnloadPak.GetPtr()); + spdlog::debug("| CON: CPakFile::LoadPak_OpenFileOffset : {:#18x} |\n", p_CPakFile_LoadPak_OpenFileOffset.GetPtr()); spdlog::debug("+----------------------------------------------------------------+\n"); } virtual void GetFun(void) const @@ -76,7 +79,10 @@ class VRTechGame : public IDetour CPakFile_UnloadPak = p_CPakFile_UnloadPak.RCast(); /*48 89 5C 24 ? 48 89 74 24 ? 57 48 83 EC 30 8B C1*/ } virtual void GetVar(void) const { } - virtual void GetCon(void) const { } + virtual void GetCon(void) const + { + p_CPakFile_LoadPak_OpenFileOffset = g_GameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x7C\x24\x30\xC7\x44\x24\x28\x00\x00\x00\x40"), "xxxxxxxxxxxxx"); + } virtual void Attach(void) const { } virtual void Detach(void) const { } }; diff --git a/r5dev/rtech/rtech_utils.cpp b/r5dev/rtech/rtech_utils.cpp index ce1fd09c..393ff9c8 100644 --- a/r5dev/rtech/rtech_utils.cpp +++ b/r5dev/rtech/rtech_utils.cpp @@ -622,7 +622,7 @@ int32_t RTech::OpenFile(const CHAR* szFilePath, void* unused, LONGLONG* fileSize const string svModDir = "paks\\Win32\\"; const string svBaseDir = "paks\\Win64\\"; - if (strstr(szFilePath, svBaseDir.c_str())) + if (strstr(ConvertToWinPath(szFilePath).c_str(), svBaseDir.c_str())) { svBaseFile.erase(0, 11); // Erase 'base_dir'. svModFile = svModDir + svBaseFile; // Prepend 'mod_dir'. @@ -637,6 +637,8 @@ int32_t RTech::OpenFile(const CHAR* szFilePath, void* unused, LONGLONG* fileSize if (hFile == INVALID_HANDLE_VALUE) return -1; + DevMsg(eDLL_T::RTECH, "%s - opened: '%s'\n", __FUNCTION__, svModFile.c_str()); + if (fileSizeOut) { LARGE_INTEGER fileSize{};