r5sdk/r5dev/vpc/interfaces.h
Kawe Mazidjatari a618990937 Detour code refactor
This change was planned for a long time. This moves all REGISTER calls to a single translation unit, this is required as we currently added a very dirty workaround for not registering duplicates by checking if VFTable pointer was already present in the vector... Registering from single translation unit prevents duplicate instances that gets created if header is included by more cpp files.
Reworking this reduced 100kb+ of compiled code. This commit also reworked the way functions/variables/constant gets logged with their addresses; the new code formats them on the fly, and allows for resize at any time. Formatting is no longer required by programmer.

TODO: currently there are some compile errors for dedicated and client dll's. These will be resolved very soon as they need to be properly worked out still (server & client only stuff needs to be properly split). Use the 'main' (stable) branch for the time being if you need to compile these dll's.
2023-01-25 02:26:52 +01:00

120 lines
5.3 KiB
C++

#pragma once
/*-----------------------------------------------------------------------------
* _interfaces.h
*-----------------------------------------------------------------------------*/
// Maybe make them constexpr.
#define VENGINE_LAUNCHER_API_VERSION "VENGINE_LAUNCHER_API_VERSION004"
#define VENGINE_GAMEUIFUNCS_VERSION "VENGINE_GAMEUIFUNCS_VERSION005"
#define VENGINE_RENDERVIEW_INTERFACE_VERSION "VEngineRenderView014"
#define VENGINE_RANDOM_INTERFACE_VERSION "VEngineRandom001"
#define VENGINE_HUDMODEL_INTERFACE_VERSION "VEngineModel016"
#define MATERIALSYSTEM_CONFIG_VERSION "VMaterialSystemConfig004"
#define SERVER_DLL_SHARED_APPSYSTEMS "VServerDllSharedAppSystems001"
#define INTERFACEVERSION_SERVERGAMECLIENTS_NEW "ServerGameClients004"
#define INTERFACEVERSION_SERVERGAMECLIENTS "ServerGameClients003"
#define INTERFACEVERSION_SERVERGAMEENTS "ServerGameEnts002"
#define INTERFACEVERSION_SERVERGAMEDLL "ServerGameDLL005"
#define VCLIENT_PREDICTION_INTERFACE_VERSION "VClientPrediction001"
#define VCLIENTENTITYLIST_INTERFACE_VERSION "VClientEntityList003"
#define CLIENT_DLL_INTERFACE_VERSION "VClient018"
#define CLIENTRENDERTARGETS_INTERFACE_VERSION "ClientRenderTargets001"
#define INTERFACEVERSION_ENGINETRACE_CLIENT "EngineTraceClient004"
#define INTERFACEVERSION_ENGINETRACEDECALS_CLIENT "EngineTraceClientDecals004"
#define VGUI_SYSTEM_INTERFACE_VERSION "VGUI_System010"
#define GAMEUI_INTERFACE_VERSION "GameUI011"
#define RUNGAMEENGINE_INTERFACE_VERSION "RunGameEngine005"
#define EVENTSYSTEM_INTERFACE_VERSION "EventSystem001"
#define CVAR_QUERY_INTERFACE_VERSION "VCvarQuery001"
#define VPHYSICS_DEBUG_OVERLAY_INTERFACE_VERSION "VPhysicsDebugOverlay001"
#define VDEBUG_OVERLAY_INTERFACE_VERSION "VDebugOverlay004"
#define SOUNDCARD_INTERFACE_VERSION "ISoundC002"
#define SHADERSYSTEM_INTERFACE_VERSION "ShaderSystem002"
#define FACTORY_INTERFACE_VERSION "VFactorySystem001"
#define FILESYSTEM_INTERFACE_VERSION "VFileSystem017"
#define BASEFILESYSTEM_INTERFACE_VERSION "VBaseFileSystem011"
//-----------------------------------------------------------------------------
enum class InterfaceStatus_t : int
{
IFACE_OK = 0,
IFACE_FAILED
};
//-----------------------------------------------------------------------------
// Mapping of interface string to globals
//-----------------------------------------------------------------------------
typedef void* (*CreateInterfaceFn)(const char* pName, int* pReturnCode);
typedef void* (*InstantiateInterfaceFn)();
typedef HINSTANCE CSysModule;
struct InterfaceGlobals_t
{
InstantiateInterfaceFn m_pInterfacePtr;
const char* m_pInterfaceName;
InterfaceGlobals_t* m_pNextInterfacePtr;
};
//-----------------------------------------------------------------------------
struct FactoryInfo_t
{
CMemory m_pFactoryPtr;
string m_szFactoryFullName;
string m_szFactoryName;
string m_szFactoryVersion;
FactoryInfo_t() : m_szFactoryFullName(string()), m_szFactoryName(string()), m_szFactoryVersion(string()), m_pFactoryPtr(nullptr) {}
FactoryInfo_t(string factoryFullName, string factoryName, string factoryVersion, uintptr_t factoryPtr) :
m_szFactoryFullName(factoryFullName), m_szFactoryName(factoryName), m_szFactoryVersion(factoryVersion), m_pFactoryPtr(factoryPtr) {}
FactoryInfo_t(string factoryFullName, uintptr_t factoryPtr) :
m_szFactoryFullName(factoryFullName), m_szFactoryName(string()), m_szFactoryVersion(string()), m_pFactoryPtr(factoryPtr) {}
};
//-----------------------------------------------------------------------------
// Class to hold all factories (interfaces)
//-----------------------------------------------------------------------------
class CFactory
{
public:
virtual void AddFactory(const string& svFactoryName, void* pFactory);
virtual void AddFactory(FactoryInfo_t factoryInfo);
virtual size_t GetVersionIndex(const string& svInterfaceName) const;
virtual void GetFactoriesFromRegister(void);
virtual CMemory GetFactoryPtr(const string& svFactoryName, bool versionLess = true) const;
virtual const char* GetFactoryFullName(const string& svFactoryName) const;
private:
vector<FactoryInfo_t> m_vFactories;
};
extern CFactory* g_pFactory;
/* ==== s_pInterfaceRegs ==================================================================================================================================================== */
inline CMemory s_pInterfacesRegs;
///////////////////////////////////////////////////////////////////////////////
class VFactory : public IDetour
{
virtual void GetAdr(void) const
{
LogVarAdr("s_pInterfacesRegs", s_pInterfacesRegs.GetPtr());
spdlog::debug("+----------------------------------------------------------------+\n");
}
virtual void GetFun(void) const { }
virtual void GetVar(void) const
{
s_pInterfacesRegs = g_GameDll.FindPatternSIMD("E9 ?? ?? ?? ?? CC CC 89 91 ?? ?? ?? ??").FollowNearCallSelf().FindPatternSelf("48 8B 1D", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7);
}
virtual void GetCon(void) const { }
virtual void Attach(void) const { }
virtual void Detach(void) const { }
};
///////////////////////////////////////////////////////////////////////////////