From f57da25341d8f71bfad9c6893182637710877447 Mon Sep 17 00:00:00 2001 From: PixieCore <41352111+IcePixelx@users.noreply.github.com> Date: Wed, 20 Jul 2022 11:27:42 +0200 Subject: [PATCH] RTech changes. * Added RPakAssetBinding_t. * Added RPakUnknownStruct_t * PatternScan the global RPakUnknownStruct_t. * Renamed Members of CMaterialGlue * RTechTextureInfo_t now has another unknown member named. --- r5dev/materialsystem/cmaterialglue.h | 4 ++-- r5dev/public/module.cpp | 12 +++++------ r5dev/rtech/rtech_utils.cpp | 6 +++++- r5dev/rtech/rtech_utils.h | 31 ++++++++++++++++++++++++---- r5dev/vstdlib/callback.cpp | 4 ++-- 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/r5dev/materialsystem/cmaterialglue.h b/r5dev/materialsystem/cmaterialglue.h index 55995bf5..dd3740de 100644 --- a/r5dev/materialsystem/cmaterialglue.h +++ b/r5dev/materialsystem/cmaterialglue.h @@ -20,7 +20,7 @@ public: CMaterialGlue* m_pDepthShadowTight; //0x0048 CMaterialGlue* m_pColPass; //0x0050 CShaderGlue* m_pShaderGlue; //0x0058 - void* m_pTextureGUID1; //0x0060 + void* m_pTextureGUID; //0x0060 void* m_pStreamableTextures; //0x0068 int16_t m_nStreamableTextureCount; //0x0070 int16_t m_iWidth; //0x0072 @@ -34,7 +34,7 @@ public: uint8_t m_iUnknown1; //0x00F3 char pad_00F4[12]; //0x00F4 void* m_pDXBuffer; //0x0100 [ PIXIE ]: ID3D11Buffer*, might need to include dx here. - void* m_pID3D11BufferVTable; //0x0108 [ PIXIE ]: ID3D11BufferVtbl, probably just leave it as a void* + void* m_pDXBufferVTable; //0x0108 [ PIXIE ]: ID3D11BufferVtbl, probably just leave it as a void* void* m_pUnknown2; //0x0110 uint32_t m_iUnknown3; //0x0118 uint16_t m_iUnknown4; //0x011C diff --git a/r5dev/public/module.cpp b/r5dev/public/module.cpp index d66ee280..a1c4ce7e 100644 --- a/r5dev/public/module.cpp +++ b/r5dev/public/module.cpp @@ -208,7 +208,7 @@ CMemory CModule::GetExportedFunction(const string& svFunctionName) const if (!m_pNTHeaders || m_pNTHeaders->Signature != IMAGE_NT_SIGNATURE) // Is ntHeader valid? return CMemory(); - // Get the location of IMAGE_EXPORT_DIRECTORY for this module by adding the IMAGE_DIRECTORY_ENTRY_EXPORT relative virtual Address onto our module base Address. + // Get the location of IMAGE_EXPORT_DIRECTORY for this module by adding the IMAGE_DIRECTORY_ENTRY_EXPORT relative virtual address onto our module base address. const IMAGE_EXPORT_DIRECTORY* pImageExportDirectory = reinterpret_cast(m_pModuleBase + m_pNTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress); if (!pImageExportDirectory) return CMemory(); @@ -217,17 +217,17 @@ CMemory CModule::GetExportedFunction(const string& svFunctionName) const if (!pImageExportDirectory->NumberOfFunctions) return CMemory(); - // Get the location of the functions via adding the relative virtual Address from the struct into our module base Address. + // Get the location of the functions via adding the relative virtual address from the struct into our module base address. const DWORD* pAddressOfFunctions = reinterpret_cast(m_pModuleBase + pImageExportDirectory->AddressOfFunctions); if (!pAddressOfFunctions) return CMemory(); - // Get the names of the functions via adding the relative virtual Address from the struct into our module base Address. + // Get the names of the functions via adding the relative virtual address from the struct into our module base Address. const DWORD* pAddressOfName = reinterpret_cast(m_pModuleBase + pImageExportDirectory->AddressOfNames); if (!pAddressOfName) return CMemory(); - // Get the ordinals of the functions via adding the relative virtual Address from the struct into our module base Address. + // Get the ordinals of the functions via adding the relative virtual Address from the struct into our module base address. DWORD* pAddressOfOrdinals = reinterpret_cast(m_pModuleBase + pImageExportDirectory->AddressOfNameOrdinals); if (!pAddressOfOrdinals) return CMemory(); @@ -239,8 +239,8 @@ CMemory CModule::GetExportedFunction(const string& svFunctionName) const if (ExportFunctionName.compare(svFunctionName) == 0) // Is this our wanted exported function? { - // Get the function ordinal. Then grab the relative virtual Address of our wanted function. Then add module base Address so we get the actual location. - return CMemory(m_pModuleBase + pAddressOfFunctions[reinterpret_cast(pAddressOfOrdinals)[i]]); // Return as Address class. + // Get the function ordinal. Then grab the relative virtual address of our wanted function. Then add module base address so we get the actual location. + return CMemory(m_pModuleBase + pAddressOfFunctions[reinterpret_cast(pAddressOfOrdinals)[i]]); // Return as CMemory class. } } return CMemory(); diff --git a/r5dev/rtech/rtech_utils.cpp b/r5dev/rtech/rtech_utils.cpp index daaddf66..76e6a5b1 100644 --- a/r5dev/rtech/rtech_utils.cpp +++ b/r5dev/rtech/rtech_utils.cpp @@ -505,6 +505,10 @@ std::uint8_t __fastcall RTech::DecompressPakFile(RPakDecompState_t* state, std:: #pragma warning( push ) #pragma warning( disable : 6262 ) // Disable stack warning, tells us to move more data to the heap instead. Not really possible with 'initialData' here. Since its parallel processed. + +//---------------------------------------------------------------------------------- +// Purpose: creates 2D texture and shader resource from textureHeader and imageData. +//---------------------------------------------------------------------------------- void RTech::CreateDXTexture(RTechTextureInfo_t* textureHeader, int64_t imageData) { if (textureHeader->unk0 && !textureHeader->m_nHeight) // Return never gets hit. Maybe its some debug check? @@ -566,7 +570,7 @@ void RTech::CreateDXTexture(RTechTextureInfo_t* textureHeader, int64_t imageData textureDesc.Format = dxgiFormat; textureDesc.SampleDesc.Count = 1; textureDesc.SampleDesc.Quality = 0; - textureDesc.Usage = (D3D11_USAGE)(textureHeader->unk2 != 2); + textureDesc.Usage = (D3D11_USAGE)(textureHeader->m_nCPUAccessFlag != 2); textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; textureDesc.MiscFlags = 0; diff --git a/r5dev/rtech/rtech_utils.h b/r5dev/rtech/rtech_utils.h index e149bb4b..95b0756b 100644 --- a/r5dev/rtech/rtech_utils.h +++ b/r5dev/rtech/rtech_utils.h @@ -85,6 +85,27 @@ const std::map RPakStatusToString { { RPakStatus_t::PAK_STATUS_BUSY, "PAK_STATUS_BUSY" }, }; +struct RPakAssetBinding_t +{ + uint32_t m_nExtension; // For example '0x6C74616D' for the material asset. + int m_iVersion; + const char* m_szDescription; // Description/Name of asset. + void* m_pLoadAssetFunction; + void* m_pUnloadAssetFunction; + void* m_pReplaceAssetFunction; + void* m_pUnknownAssetFunction; // [ PIXIE ]: Also a function pointer just sometimes it's set to CStdMemAlloc and sometimes it handles some data. + int m_iSubHeaderSize; + int m_iNativeClassSize; // Native class size, for 'material' it would be CMaterialGlue full size. + uint32_t unk2; + int unk3; + // [ PIXIE ]: Should be the full size across Season 0-3. +}; + +struct RPakUnknownStruct_t +{ + RPakAssetBinding_t m_nAssetBindings[64]; // [ PIXIE ]: Max possible registered assets on Season 3, 0-2 I did not check yet. + // End size unknown. +}; struct RPakHeader_t { @@ -181,7 +202,7 @@ struct RTechTextureInfo_t uint8_t m_nMipLevelsStreamedOpt; uint8_t m_nArraySize; uint8_t m_nLayerCount; - uint8_t unk2; + uint8_t m_nCPUAccessFlag; // [ PIXIE ]: In RTech::CreateDXBuffer textureDescription Usage is determined by the CPU Access Flag so I assume it's the same case here. uint8_t m_nMipLevels; uint8_t m_nMipLevelsStreamed; uint8_t unk3[24]; @@ -433,6 +454,7 @@ inline auto RTech_CreateDXTexture = p_RTech_CreateDXTexture.RCast("\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x30\x8B\xC1"), "xxxx?xxxx?xxxxxxx"); + g_pUnknownPakStruct = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x8D\x1D\x00\x00\x00\x00\x45\x8D\x5A\x0E"), "xxx????xxxx").ResolveRelativeAddressSelf(0x3, 0x7).RCast(); /*48 8D 1D ? ? ? ? 45 8D 5A 0E*/ - g_pLoadedPakInfo = localRef.FindPattern("48 8D 05", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); - s_pLoadedPakCount = localRef.FindPattern("66 89", CMemory::Direction::DOWN, 450).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); + CMemory RTech_UnloadPak = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x30\x8B\xC1"), "xxxx?xxxx?xxxxxxx"); + g_pLoadedPakInfo = RTech_UnloadPak.FindPattern("48 8D 05", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); + s_pLoadedPakCount = RTech_UnloadPak.FindPattern("66 89", CMemory::Direction::DOWN, 450).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); } virtual void GetCon(void) const { } virtual void Attach(void) const { } diff --git a/r5dev/vstdlib/callback.cpp b/r5dev/vstdlib/callback.cpp index 1284cc93..b8b26b5a 100644 --- a/r5dev/vstdlib/callback.cpp +++ b/r5dev/vstdlib/callback.cpp @@ -879,7 +879,7 @@ void Mat_CrossHair_f(const CCommand& args) DevMsg(eDLL_T::MS, " |-- Material Surface Name 1: '%s'\n", material->m_pszSurfaceName1); DevMsg(eDLL_T::MS, " |-- Material Surface Name 2: '%s'\n", material->m_pszSurfaceName2); DevMsg(eDLL_T::MS, " |-- DX Buffer: '%llX'\n", material->m_pDXBuffer); - DevMsg(eDLL_T::MS, " |-- DX BufferVTable: '%llX'\n", material->m_pID3D11BufferVTable); + DevMsg(eDLL_T::MS, " |-- DX BufferVTable: '%llX'\n", material->m_pDXBufferVTable); material->m_pDepthShadow ? fnPrintChild(material->m_pDepthShadow, " | |-+ DepthShadow Addr: '%llX'\n") : DevMsg(eDLL_T::MS, " | |-+ DepthShadow Addr: 'NULL'\n"); material->m_pDepthPrepass ? fnPrintChild(material->m_pDepthPrepass, " | |-+ DepthPrepass Addr: '%llX'\n") : DevMsg(eDLL_T::MS, " | |-+ DepthPrepass Addr: 'NULL'\n"); @@ -888,7 +888,7 @@ void Mat_CrossHair_f(const CCommand& args) material->m_pColPass ? fnPrintChild(material->m_pColPass, " | |-+ ColPass Addr: '%llX'\n") : DevMsg(eDLL_T::MS, " | |-+ ColPass Addr: 'NULL'\n"); DevMsg(eDLL_T::MS, "-+ Texture GUID map ------------------------------------------\n"); - material->m_pTextureGUID1 ? DevMsg(eDLL_T::MS, " |-- TextureMap 1 Addr: '%llX'\n", material->m_pTextureGUID1) : DevMsg(eDLL_T::MS, " |-- TextureMap 1 Addr: 'NULL'\n"); + material->m_pTextureGUID ? DevMsg(eDLL_T::MS, " |-- TextureMap 1 Addr: '%llX'\n", material->m_pTextureGUID) : DevMsg(eDLL_T::MS, " |-- TextureMap 1 Addr: 'NULL'\n"); material->m_pStreamableTextures ? DevMsg(eDLL_T::MS, " |-- TextureMap 2 Addr: '%llX'\n", material->m_pStreamableTextures) : DevMsg(eDLL_T::MS, " |-- TextureMap 2 Addr: 'NULL'\n"); DevMsg(eDLL_T::MS, "--------------------------------------------------------------\n");