2022-10-13 02:41:09 +02:00
# ifndef MATERIALSYSTEM_H
# define MATERIALSYSTEM_H
2022-10-13 02:22:50 +02:00
# include "cmaterialglue.h"
2022-10-13 02:41:09 +02:00
2022-08-11 11:07:45 +02:00
# define STREAM_DB_EXT "stbsp"
2022-10-13 02:22:50 +02:00
class CMaterialSystem
{
public :
2023-02-17 23:56:56 +01:00
FORCENOINLINE static bool IsMaterialInternal ( void * * pCandidate ) ;
2022-10-13 02:22:50 +02:00
# ifndef DEDICATED
static CMaterialGlue * FindMaterialEx ( CMaterialSystem * pMatSys , const char * pMaterialName , uint8_t nMaterialType , int nUnk , bool bComplain ) ;
2022-10-23 01:20:49 +02:00
static Vector2D GetScreenSize ( CMaterialSystem * pMatSys = nullptr ) ;
2022-10-13 02:22:50 +02:00
# endif // !DEDICATED
} ;
2022-04-09 02:18:57 +02:00
/* ==== MATERIALSYSTEM ================================================================================================================================================== */
2022-04-18 03:35:08 +02:00
inline CMemory p_CMaterialSystem__Init ;
2022-10-23 01:20:49 +02:00
inline auto CMaterialSystem__Init = p_CMaterialSystem__Init . RCast < void * ( * ) ( CMaterialSystem * thisptr ) > ( ) ;
2022-05-18 01:01:49 +02:00
inline void * g_pMaterialSystem = nullptr ;
2022-10-03 01:15:02 +02:00
inline void * g_pMaterialVFTable = nullptr ;
2022-03-02 01:16:35 +01:00
# ifndef DEDICATED
2022-10-13 02:22:50 +02:00
inline CMemory p_CMaterialSystem__FindMaterialEx ;
2022-10-23 01:20:49 +02:00
inline auto CMaterialSystem__FindMaterialEx = p_CMaterialSystem__FindMaterialEx . RCast < CMaterialGlue * ( * ) ( CMaterialSystem * pMatSys , const char * pMaterialName , uint8_t nMaterialType , int nUnk , bool bComplain ) > ( ) ;
inline CMemory p_CMaterialSystem_GetScreenSize ;
inline auto CMaterialSystem_GetScreenSize = p_CMaterialSystem_GetScreenSize . RCast < void ( * ) ( CMaterialSystem * pMatSys , float * outX , float * outY ) > ( ) ;
2022-10-13 02:22:50 +02:00
2022-04-30 20:35:08 +02:00
# if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
2022-05-18 01:22:59 +02:00
inline CMemory p_DispatchDrawCall ;
2022-10-23 01:20:49 +02:00
inline auto v_DispatchDrawCall = p_DispatchDrawCall . RCast < void * ( * ) ( int64_t a1 , uint64_t a2 , int a3 , int a4 , char a5 , int a6 , uint8_t a7 , int64_t a8 , uint32_t a9 , uint32_t a10 , __m128 * a11 , int a12 ) > ( ) ;
2022-04-30 20:35:08 +02:00
# elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
inline CMemory p_DispatchDrawCall ;
2022-10-23 01:20:49 +02:00
inline auto v_DispatchDrawCall = p_DispatchDrawCall . RCast < void * ( * ) ( int64_t a1 , uint64_t a2 , int a3 , int a4 , int64_t a5 , int a6 , uint8_t a7 , int64_t a8 , uint32_t a9 , uint32_t a10 , int a11 , __m128 * a12 , int a13 , int64_t a14 ) > ( ) ;
2022-04-30 20:35:08 +02:00
# endif
2022-04-18 03:35:08 +02:00
inline CMemory p_DrawStreamOverlay ;
2022-10-23 01:20:49 +02:00
inline auto v_DrawStreamOverlay = p_DrawStreamOverlay . RCast < const char * ( * ) ( void * thisptr , uint8_t * a2 , void * unused , void * a4 ) > ( ) ;
2022-03-02 01:16:35 +01:00
2022-04-30 20:35:08 +02:00
inline CMemory s_pRenderContext ;
2022-08-18 02:15:23 +02:00
inline int * g_nTotalStreamingTextureMemory = nullptr ;
inline int * g_nUnfreeStreamingTextureMemory = nullptr ;
inline int * g_nUnusableStreamingTextureMemory = nullptr ;
2022-04-09 06:05:47 +02:00
# endif // !DEDICATED
2022-01-04 11:53:54 +01:00
///////////////////////////////////////////////////////////////////////////////
2022-05-13 14:53:25 +02:00
class VMaterialSystem : public IDetour
2022-01-04 11:53:54 +01:00
{
2022-04-11 01:44:30 +02:00
virtual void GetAdr ( void ) const
2022-01-04 11:53:54 +01:00
{
2023-01-25 11:19:53 +01:00
LogConAdr ( " CMaterial::`vftable' " , reinterpret_cast < uintptr_t > ( g_pMaterialVFTable ) ) ;
2023-01-25 02:26:52 +01:00
LogFunAdr ( " CMaterialSystem::Init " , p_CMaterialSystem__Init . GetPtr ( ) ) ;
2022-03-02 01:16:35 +01:00
# ifndef DEDICATED
2023-03-01 00:09:38 +01:00
LogFunAdr ( " CMaterialSystem::FindMaterialEx " , p_CMaterialSystem__FindMaterialEx . GetPtr ( ) ) ;
LogFunAdr ( " CMaterialSystem::GetScreenSize " , p_CMaterialSystem_GetScreenSize . GetPtr ( ) ) ;
2023-01-25 02:26:52 +01:00
LogFunAdr ( " CMaterialSystem::DispatchDrawCall " , p_DispatchDrawCall . GetPtr ( ) ) ;
LogFunAdr ( " CMaterialSystem::DrawStreamOverlay " , p_DrawStreamOverlay . GetPtr ( ) ) ;
LogVarAdr ( " g_nTotalStreamingTextureMemory " , reinterpret_cast < uintptr_t > ( g_nTotalStreamingTextureMemory ) ) ;
LogVarAdr ( " g_nUnfreeStreamingTextureMemory " , reinterpret_cast < uintptr_t > ( g_nUnfreeStreamingTextureMemory ) ) ;
LogVarAdr ( " g_nUnusableStreamingTextureMemory " , reinterpret_cast < uintptr_t > ( g_nUnusableStreamingTextureMemory ) ) ;
LogVarAdr ( " s_pRenderContext " , s_pRenderContext . GetPtr ( ) ) ;
2022-08-18 02:15:23 +02:00
# endif // !DEDICATED
2023-01-25 02:26:52 +01:00
LogVarAdr ( " g_pMaterialSystem " , reinterpret_cast < uintptr_t > ( g_pMaterialSystem ) ) ;
2022-01-04 11:53:54 +01:00
}
2022-04-18 03:35:08 +02:00
virtual void GetFun ( void ) const
{
2022-12-01 22:44:55 +01:00
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 ?? ?? ?? ?? ?? " ) ;
2022-10-23 01:20:49 +02:00
CMaterialSystem__Init = p_CMaterialSystem__Init . RCast < void * ( * ) ( CMaterialSystem * ) > ( ) ; /*48 89 5C 24 ?? 55 56 57 41 54 41 55 41 56 41 57 48 83 EC 70 48 83 3D ?? ?? ?? ?? ??*/
2022-04-18 03:35:08 +02:00
# ifndef DEDICATED
2022-12-01 22:44:55 +01:00
p_CMaterialSystem__FindMaterialEx = g_GameDll . FindPatternSIMD ( " 44 89 4C 24 ?? 44 88 44 24 ?? 48 89 4C 24 ?? " ) ;
2022-10-23 01:20:49 +02:00
CMaterialSystem__FindMaterialEx = p_CMaterialSystem__FindMaterialEx . RCast < CMaterialGlue * ( * ) ( CMaterialSystem * , const char * , uint8_t , int , bool ) > ( ) ; /*44 89 4C 24 ?? 44 88 44 24 ?? 48 89 4C 24 ??*/
2022-12-01 22:44:55 +01:00
p_CMaterialSystem_GetScreenSize = g_GameDll . FindPatternSIMD ( " 8B 05 ?? ?? ?? ?? 89 02 8B 05 ?? ?? ?? ?? 41 89 ?? C3 CC CC CC CC CC CC CC CC CC CC CC CC CC CC 8B 05 ?? ?? ?? ?? " ) ;
2022-10-23 01:20:49 +02:00
CMaterialSystem_GetScreenSize = p_CMaterialSystem_GetScreenSize . RCast < void ( * ) ( CMaterialSystem * pMatSys , float * outX , float * outY ) > ( ) ; /*8B 05 ? ? ? ? 89 02 8B 05 ? ? ? ? 41 89 00 C3 CC CC CC CC CC CC CC CC CC CC CC CC CC CC 8B 05 ? ? ? ?*/
2022-04-30 20:35:08 +02:00
# if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
2022-12-01 22:44:55 +01:00
p_DispatchDrawCall = g_GameDll . FindPatternSIMD ( " 44 89 4C 24 ?? 44 89 44 24 ?? 48 89 4C 24 ?? 55 53 " ) ;
2022-10-23 01:20:49 +02:00
v_DispatchDrawCall = p_DispatchDrawCall . RCast < void * ( * ) ( int64_t , uint64_t , int , int , char , int , uint8_t , int64_t , uint32_t , uint32_t , __m128 * , int ) > ( ) ;
2022-04-30 20:35:08 +02:00
# elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
2022-12-01 22:44:55 +01:00
p_DispatchDrawCall = g_GameDll . FindPatternSIMD ( " 44 89 4C 24 ?? 44 89 44 24 ?? 48 89 4C 24 ?? 55 53 56 " ) ;
2022-10-23 01:20:49 +02:00
v_DispatchDrawCall = p_DispatchDrawCall . RCast < void * ( * ) ( int64_t , uint64_t , int , int , int64_t , int , uint8_t , int64_t , uint32_t , uint32_t , int , __m128 * , int , int64_t ) > ( ) ;
2022-04-30 20:35:08 +02:00
# endif
2022-12-01 22:44:55 +01:00
p_DrawStreamOverlay = g_GameDll . FindPatternSIMD ( " 41 56 B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 C6 02 ?? " ) ;
2022-10-23 01:20:49 +02:00
v_DrawStreamOverlay = p_DrawStreamOverlay . RCast < const char * ( * ) ( void * , uint8_t * , void * , void * ) > ( ) ; // 41 56 B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 C6 02 00 //
2022-04-18 03:35:08 +02:00
# endif // !DEDICATED
}
virtual void GetVar ( void ) const
{
2022-05-18 01:01:49 +02:00
# ifndef DEDICATED
2022-10-30 10:18:22 +01:00
g_nTotalStreamingTextureMemory = p_DrawStreamOverlay . Offset ( 0x1C ) . FindPatternSelf ( " 48 8B 05 " , CMemory : : Direction : : DOWN ) . ResolveRelativeAddressSelf ( 0x3 , 0x7 ) . RCast < int * > ( ) ;
2023-01-31 23:42:43 +01:00
g_nUnfreeStreamingTextureMemory = p_DrawStreamOverlay . Offset ( 0x2D ) . FindPatternSelf ( " 48 8B 05 " , CMemory : : Direction : : DOWN ) . ResolveRelativeAddressSelf ( 0x3 , 0x7 ) . RCast < int * > ( ) ;
2022-08-18 02:15:23 +02:00
g_nUnusableStreamingTextureMemory = p_DrawStreamOverlay . Offset ( 0x50 ) . FindPatternSelf ( " 48 8B 05 " , CMemory : : Direction : : DOWN ) . ResolveRelativeAddressSelf ( 0x3 , 0x7 ) . RCast < int * > ( ) ;
2022-10-03 01:15:02 +02:00
s_pRenderContext = p_DispatchDrawCall . FindPattern ( " 48 8B ?? ?? ?? ?? 01 " ) . ResolveRelativeAddressSelf ( 0x3 , 0x7 ) ;
2022-04-18 03:35:08 +02:00
# endif // !DEDICATED
2022-12-01 22:44:55 +01:00
g_pMaterialSystem = g_GameDll . FindPatternSIMD ( " 48 8B 0D ?? ?? ?? ?? 48 85 C9 74 11 48 8B 01 48 8D 15 ?? ?? ?? ?? " ) . ResolveRelativeAddressSelf ( 0x3 , 0x7 ) . RCast < void * > ( ) ;
2022-10-03 01:15:02 +02:00
}
virtual void GetCon ( void ) const
{
g_pMaterialVFTable = g_GameDll . GetVirtualMethodTable ( " .?AVCMaterial@@ " ) . RCast < void * > ( ) ;
2022-04-18 03:35:08 +02:00
}
2023-01-25 02:26:52 +01:00
virtual void Attach ( void ) const ;
virtual void Detach ( void ) const ;
2022-01-04 11:53:54 +01:00
} ;
///////////////////////////////////////////////////////////////////////////////
2022-10-13 02:41:09 +02:00
# endif // MATERIALSYSTEM_H