r5sdk/r5dev/public/tier0/tslist.h
Kawe Mazidjatari edc52ad669 IDetour: remove extraneous pointer assignments
Originally, we store the search results in a CMemory instance which we then assign to the actual function pointer. CMemory is just a pointer class; we can assign the results directly to the actual function pointer. This commit reduces a lot of code verbosity, and also reduced roughly 2KiB worth of static pointers in the resulting executable. This commit also officially deprecates the support for any GameDLL's below S3 (Season 3), since it makes more sense to port the assets from earlier/later games back to the version this SDK supports.
2024-04-05 17:19:32 +02:00

60 lines
1.9 KiB
C++

#ifndef TSLIST_H
#define TSLIST_H
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
class CAlignedMemAlloc
{
public:
// Passed explicit parameters for 'this' pointer; the game expects one,
// albeit unused. Do NOT optimize this away!
typedef void* (*FnAlloc_t)(CAlignedMemAlloc* thisptr, size_t nSize, size_t nAlignment);
typedef void (*FnFree_t)(CAlignedMemAlloc* thisptr, void* pMem);
CAlignedMemAlloc(FnAlloc_t pAllocCallback, FnFree_t pFreeCallback);
inline void* Alloc(size_t nSize, size_t nAlign = 0)
{
return m_pAllocCallback(this, nSize, nAlign);
}
inline void Free(void* pMem)
{
m_pFreeCallback(this, pMem);
}
private:
FnAlloc_t m_pAllocCallback;
FnFree_t m_pFreeCallback;
};
extern CAlignedMemAlloc* g_pAlignedMemAlloc;
//-----------------------------------------------------------------------------
// Singleton aligned memalloc
//-----------------------------------------------------------------------------
inline CAlignedMemAlloc* AlignedMemAlloc()
{
return g_pAlignedMemAlloc;
}
///////////////////////////////////////////////////////////////////////////////
class VTSListBase : public IDetour
{
virtual void GetAdr(void) const
{
LogVarAdr("g_AlignedMemAlloc", g_pAlignedMemAlloc);
}
virtual void GetFun(void) const { }
virtual void GetVar(void) const
{
g_pAlignedMemAlloc = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 74 24 ?? 48 89 7C 24 ?? 55 41 54 41 55 41 56 41 57 48 8D AC 24 ?? ?? ?? ?? B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 48 8B D9")
.Offset(0x130).FindPatternSelf("48 8D 15 ?? ?? ?? 01", CMemory::Direction::DOWN, 100).ResolveRelativeAddressSelf(0x3, 0x7).RCast<CAlignedMemAlloc*>();
}
virtual void GetCon(void) const { }
virtual void Detour(const bool bAttach) const { }
};
///////////////////////////////////////////////////////////////////////////////
#endif // TSLIST_H