diff --git a/r5dev/core/CMakeLists.txt b/r5dev/core/CMakeLists.txt index f074d6d5..21871024 100644 --- a/r5dev/core/CMakeLists.txt +++ b/r5dev/core/CMakeLists.txt @@ -102,6 +102,7 @@ target_link_libraries( ${PROJECT_NAME} PRIVATE else() target_link_libraries( ${PROJECT_NAME} PRIVATE "engine_ds" + "materialsystem_nodx" # Needs the No-DirectX version for patching. ) endif() @@ -114,6 +115,7 @@ elseif( ${PROJECT_NAME} STREQUAL "dedicated" ) end_sources() target_compile_definitions( ${PROJECT_NAME} PRIVATE "DEDICATED" + "MATERIALSYSTEM_NODX" # Needs the No-DirectX version for patching. ) elseif( ${PROJECT_NAME} STREQUAL "client" ) end_sources( "${BUILD_OUTPUT_DIR}/bin/x64_retail/" ) diff --git a/r5dev/core/init.cpp b/r5dev/core/init.cpp index 8b086192..43d9d923 100644 --- a/r5dev/core/init.cpp +++ b/r5dev/core/init.cpp @@ -440,9 +440,9 @@ void DetourRegister() // Register detour classes to be searched and hooked. // StaticPropMgr REGISTER(VStaticPropMgr); -#ifndef DEDICATED // MaterialSystem REGISTER(VMaterialSystem); +#ifndef DEDICATED REGISTER(VMaterialGlue); REGISTER(VShaderGlue); diff --git a/r5dev/materialsystem/CMakeLists.txt b/r5dev/materialsystem/CMakeLists.txt index 9dfd63b2..4c71a4ba 100644 --- a/r5dev/materialsystem/CMakeLists.txt +++ b/r5dev/materialsystem/CMakeLists.txt @@ -19,3 +19,22 @@ add_sources( SOURCE_GROUP "Public" ) end_sources() + +add_module( "lib" "materialsystem_nodx" "vpc" ${FOLDER_CONTEXT} TRUE TRUE ) + +start_sources() + +add_sources( SOURCE_GROUP "Private" + "cmaterialsystem.cpp" + "cmaterialsystem.h" +) + +add_sources( SOURCE_GROUP "Public" + "${ENGINE_SOURCE_DIR}/public/imaterialsystem.h" +) + +end_sources() + +target_compile_definitions( ${PROJECT_NAME} PRIVATE + "MATERIALSYSTEM_NODX" +) \ No newline at end of file diff --git a/r5dev/materialsystem/cmaterialsystem.cpp b/r5dev/materialsystem/cmaterialsystem.cpp index 167148cf..23356536 100644 --- a/r5dev/materialsystem/cmaterialsystem.cpp +++ b/r5dev/materialsystem/cmaterialsystem.cpp @@ -9,10 +9,32 @@ #include "vpc/keyvalues.h" #include "rtech/rtech_utils.h" #include "engine/cmodel_bsp.h" +#ifndef MATERIALSYSTEM_NODX #include "materialsystem/cmaterialglue.h" +#endif // !MATERIALSYSTEM_NODX #include "materialsystem/cmaterialsystem.h" -#ifndef DEDICATED +//----------------------------------------------------------------------------- +// Purpose: initialization of the material system +//----------------------------------------------------------------------------- +InitReturnVal_t CMaterialSystem::Init(CMaterialSystem* thisptr) +{ +#ifdef MATERIALSYSTEM_NODX + // Only load the 'startup.rpak' file, as 'common_early.rpak' has assets + // that references assets in 'startup.rpak'. + RPakHandle_t pakHandle = g_pakLoadApi->LoadAsync("startup.rpak", AlignedMemAlloc(), 5); + g_pakLoadApi->WaitAsync(pakHandle); + + // Trick: return INIT_FAILED to disable the loading of hardware + // configuration data, since we don't need it on the dedi. + return INIT_FAILED; +#else + // Initialize as usual. + return CMaterialSystem__Init(thisptr); +#endif +} + +#ifndef MATERIALSYSTEM_NODX //--------------------------------------------------------------------------------- // Purpose: loads and processes STBSP files // (overrides level name if stbsp field has value in prerequisites file) @@ -60,9 +82,9 @@ void* __fastcall DispatchDrawCall(int64_t a1, uint64_t a2, int a3, int a4, int64 return v_DispatchDrawCall(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14); #endif } -#endif // !DEDICATED +#endif // !MATERIALSYSTEM_NODX -#ifndef DEDICATED +#ifndef MATERIALSYSTEM_NODX //----------------------------------------------------------------------------- // Purpose: finds a material // Input : *pMatSys - @@ -96,23 +118,25 @@ Vector2D CMaterialSystem::GetScreenSize(CMaterialSystem* pMatSys) return vecScreenSize; } -#endif // !DEDICATED +#endif // !MATERIALSYSTEM_NODX /////////////////////////////////////////////////////////////////////////////// void VMaterialSystem::Attach() const { -#ifndef DEDICATED + DetourAttach((LPVOID*)&CMaterialSystem__Init, &CMaterialSystem::Init); +#ifndef MATERIALSYSTEM_NODX DetourAttach((LPVOID*)&v_StreamDB_Init, &StreamDB_Init); DetourAttach((LPVOID*)&v_DispatchDrawCall, &DispatchDrawCall); DetourAttach((LPVOID*)&CMaterialSystem__FindMaterialEx, &CMaterialSystem::FindMaterialEx); -#endif // !DEDICATED +#endif // !MATERIALSYSTEM_NODX } void VMaterialSystem::Detach() const { -#ifndef DEDICATED + DetourDetach((LPVOID*)&CMaterialSystem__Init, &CMaterialSystem::Init); +#ifndef MATERIALSYSTEM_NODX DetourDetach((LPVOID*)&v_StreamDB_Init, &StreamDB_Init); DetourDetach((LPVOID*)&v_DispatchDrawCall, &DispatchDrawCall); DetourDetach((LPVOID*)&CMaterialSystem__FindMaterialEx, &CMaterialSystem::FindMaterialEx); -#endif // !DEDICATED +#endif // !MATERIALSYSTEM_NODX } \ No newline at end of file diff --git a/r5dev/materialsystem/cmaterialsystem.h b/r5dev/materialsystem/cmaterialsystem.h index c0221a88..185b75e1 100644 --- a/r5dev/materialsystem/cmaterialsystem.h +++ b/r5dev/materialsystem/cmaterialsystem.h @@ -7,19 +7,20 @@ class CMaterialSystem { public: -#ifndef DEDICATED + static InitReturnVal_t Init(CMaterialSystem* thisptr); +#ifndef MATERIALSYSTEM_NODX static CMaterialGlue* FindMaterialEx(CMaterialSystem* pMatSys, const char* pMaterialName, uint8_t nMaterialType, int nUnk, bool bComplain); static Vector2D GetScreenSize(CMaterialSystem* pMatSys = nullptr); -#endif // !DEDICATED +#endif // !MATERIALSYSTEM_NODX }; /* ==== MATERIALSYSTEM ================================================================================================================================================== */ inline CMemory p_CMaterialSystem__Init; -inline void*(*CMaterialSystem__Init)(CMaterialSystem* thisptr); +inline InitReturnVal_t(*CMaterialSystem__Init)(CMaterialSystem* thisptr); inline void* g_pMaterialSystem = nullptr; inline void* g_pMaterialVFTable = nullptr; -#ifndef DEDICATED +#ifndef MATERIALSYSTEM_NODX inline CMemory p_CMaterialSystem__FindMaterialEx; inline CMaterialGlue*(*CMaterialSystem__FindMaterialEx)(CMaterialSystem* pMatSys, const char* pMaterialName, uint8_t nMaterialType, int nUnk, bool bComplain); @@ -44,7 +45,7 @@ inline CMemory s_pRenderContext; inline int* g_nTotalStreamingTextureMemory = nullptr; inline int* g_nUnfreeStreamingTextureMemory = nullptr; inline int* g_nUnusableStreamingTextureMemory = nullptr; -#endif // !DEDICATED +#endif // !MATERIALSYSTEM_NODX /////////////////////////////////////////////////////////////////////////////// class VMaterialSystem : public IDetour @@ -53,7 +54,7 @@ class VMaterialSystem : public IDetour { LogConAdr("CMaterial::`vftable'", reinterpret_cast(g_pMaterialVFTable)); LogFunAdr("CMaterialSystem::Init", p_CMaterialSystem__Init.GetPtr()); -#ifndef DEDICATED +#ifndef MATERIALSYSTEM_NODX LogFunAdr("CMaterialSystem::FindMaterialEx", p_CMaterialSystem__FindMaterialEx.GetPtr()); LogFunAdr("CMaterialSystem::GetScreenSize", p_CMaterialSystem_GetScreenSize.GetPtr()); LogFunAdr("CMaterialSystem::DispatchDrawCall", p_DispatchDrawCall.GetPtr()); @@ -63,14 +64,14 @@ class VMaterialSystem : public IDetour LogVarAdr("g_nUnfreeStreamingTextureMemory", reinterpret_cast(g_nUnfreeStreamingTextureMemory)); LogVarAdr("g_nUnusableStreamingTextureMemory", reinterpret_cast(g_nUnusableStreamingTextureMemory)); LogVarAdr("s_pRenderContext", s_pRenderContext.GetPtr()); -#endif // !DEDICATED +#endif // !MATERIALSYSTEM_NODX LogVarAdr("g_pMaterialSystem", reinterpret_cast(g_pMaterialSystem)); } virtual void GetFun(void) const { p_CMaterialSystem__Init = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 55 56 57 41 54 41 55 41 56 41 57 48 83 EC 70 48 83 3D ?? ?? ?? ?? ??"); - CMaterialSystem__Init = p_CMaterialSystem__Init.RCast(); /*48 89 5C 24 ?? 55 56 57 41 54 41 55 41 56 41 57 48 83 EC 70 48 83 3D ?? ?? ?? ?? ??*/ -#ifndef DEDICATED + CMaterialSystem__Init = p_CMaterialSystem__Init.RCast(); /*48 89 5C 24 ?? 55 56 57 41 54 41 55 41 56 41 57 48 83 EC 70 48 83 3D ?? ?? ?? ?? ??*/ +#ifndef MATERIALSYSTEM_NODX p_CMaterialSystem__FindMaterialEx = g_GameDll.FindPatternSIMD("44 89 4C 24 ?? 44 88 44 24 ?? 48 89 4C 24 ??"); CMaterialSystem__FindMaterialEx = p_CMaterialSystem__FindMaterialEx.RCast(); /*44 89 4C 24 ?? 44 88 44 24 ?? 48 89 4C 24 ??*/ @@ -88,17 +89,17 @@ class VMaterialSystem : public IDetour p_DrawStreamOverlay = g_GameDll.FindPatternSIMD("41 56 B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 C6 02 ??"); v_DrawStreamOverlay = p_DrawStreamOverlay.RCast(); // 41 56 B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 C6 02 00 // -#endif // !DEDICATED +#endif // !MATERIALSYSTEM_NODX } virtual void GetVar(void) const { -#ifndef DEDICATED +#ifndef MATERIALSYSTEM_NODX g_nTotalStreamingTextureMemory = p_DrawStreamOverlay.Offset(0x1C).FindPatternSelf("48 8B 05", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); g_nUnfreeStreamingTextureMemory = p_DrawStreamOverlay.Offset(0x2D).FindPatternSelf("48 8B 05", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); g_nUnusableStreamingTextureMemory = p_DrawStreamOverlay.Offset(0x50).FindPatternSelf("48 8B 05", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); s_pRenderContext = p_DispatchDrawCall.FindPattern("48 8B ?? ?? ?? ?? 01").ResolveRelativeAddressSelf(0x3, 0x7); -#endif // !DEDICATED +#endif // !MATERIALSYSTEM_NODX g_pMaterialSystem = g_GameDll.FindPatternSIMD("48 8B 0D ?? ?? ?? ?? 48 85 C9 74 11 48 8B 01 48 8D 15 ?? ?? ?? ??").ResolveRelativeAddressSelf(0x3, 0x7).RCast(); } virtual void GetCon(void) const @@ -110,4 +111,4 @@ class VMaterialSystem : public IDetour }; /////////////////////////////////////////////////////////////////////////////// -#endif // MATERIALSYSTEM_H \ No newline at end of file +#endif // MATERIALSYSTEM_H