Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <datamap.h>
- #include <const.h>
- #include <tier1.h>
- #include <tier2.h>
- #include <tier3.h>
- #include <eiface.h>
- #include <igameevents.h>
- #include <iclient.h>
- #include <inetmessage.h>
- #include <shareddefs.h>
- #include <inetchannel.h>
- #include <igameevents.h>
- #include "igameserverdata.h"
- #include <iachievementmgr.h>
- #include <utllinkedlist.h>
- #include <game/server/iplayerinfo.h>
- #include <vphysics_interface.h>
- #include <vphysics/performance.h>
- #include "VTableUtil.h"
- #include "igameserverdata.h"
- #include <vstdlib/cvar.h>
- // VTable stuff
- #define __thiscall
- typedef void *PVOID;
- template< class T > inline T* makeptr(void* pObj, unsigned int offset) {
- return reinterpret_cast< T* >(reinterpret_cast< unsigned char* >(pObj) + offset);
- }
- inline void**& getvtable(void* inst, size_t offset = 0) {
- return *reinterpret_cast<void***>(reinterpret_cast<size_t>(inst) + offset);
- }
- inline const void** getvtable(const void* inst, size_t offset = 0) {
- return *reinterpret_cast<const void***>(reinterpret_cast<size_t>(inst) + offset);
- }
- template< typename Fn >
- inline Fn getvfunc(const void* inst, size_t index, size_t offset = 0) {
- return reinterpret_cast<Fn>(getvtable(inst, offset)[index]);
- }
- //------------------------------------------------------------------------
- // Forward declarations
- //------------------------------------------------------------------------
- class CTakeDamageInfo;
- class CNPC_VehicleDriver;
- class IVehicle;
- class IServerVehicle;
- class CBaseEntity;
- class CBaseAnimating;
- class CBaseAnimatingOverlay;
- class CBaseFlex;
- class CBaseCombatCharacter;
- class CBaseAnimating;
- class IEntitySaveUtils;
- class CBaseClient;
- class IServer;
- class CBaseServer;
- class CClientFrame;
- class CFrameSnapshot;
- class CGameServer;
- class CUserCmd;
- class IMoveHelper;
- class CMoveData;
- class CBaseCombatCharacter;
- class CBasePlayer;
- class CServerRemoteAccess;
- class CPhysicsProp;
- class CServerNetworkProperty;
- //------------------------------------------------------------------------
- // CBaseServer
- //------------------------------------------------------------------------
- class CBaseServer
- : public IServer
- {
- static const int m_vtOffset = 1;
- public:
- virtual ~CBaseServer();
- const char* GetMapName( void ) {
- typedef const char*(__thiscall* vtGetMapName)(PVOID);
- return getvfunc< vtGetMapName >(this, 14 - m_vtOffset)(this);
- }
- void BroadcastPrintf(const char *fmt, ...) {
- va_list vl;
- va_start(vl, fmt);
- char buffer[1024];
- vsprintf(buffer, fmt, vl);
- va_end(vl);
- typedef void(__thiscall* vtBroadcastPrintf)(PVOID, const char *);
- return getvfunc< vtBroadcastPrintf >(this, 36 - m_vtOffset)(this, buffer);
- }
- };
- ///////// Signature searching
- void* UTIL_FindSignatureInRunTime( const char* pSignature, const char* pModule ) {
- if (!pSignature || pSignature[0] == 0) {
- return nullptr;
- }
- static char pSig[512];
- auto siglen = UTIL_StringToSignature( pSignature, pSig, sizeof pSig );
- auto moduleHandle = dlopen(pModule, RTLD_NOW );
- if ( !moduleHandle) {
- return nullptr;
- }
- auto moduleAddr = dlsym( moduleHandle, "CreateInterface" );
- if ( !moduleAddr) {
- printf("(UTIL_FindSignatureInRunTime) Cannot found module CreateInterface '%s'!\n", pModule);
- return nullptr;
- }
- Dl_info dlInfo;
- if ( !dladdr(moduleAddr, &dlInfo) ) {
- printf("(UTIL_FindSignatureInRunTime) Cannot exec dladdr[%p] on module '%s': %s!\n", moduleAddr, pModule, dlerror());
- return nullptr;
- }
- if ( !dlInfo.dli_fbase || !dlInfo.dli_fname ) {
- return nullptr;
- }
- struct stat buf;
- if ( stat( dlInfo.dli_fname, &buf ) != 0 ) {
- return nullptr;
- }
- auto ptr = reinterpret_cast<char *>( dlInfo.dli_fbase );
- auto end = ptr + buf.st_size - 1;
- char* retn = nullptr;
- bool found = false;
- // printf( "ptr: %p, end: %p, sz: %d [%d]\n", ptr, end, end - ptr, dlInfo.dli_saddr);
- while (ptr < end) {
- found = true;
- for (register unsigned int i = 0; i < siglen; i++) {
- if (pSig[i] != '\x2A' && pSig[i] != ptr[i]) {
- found = false;
- break;
- }
- }
- if (found) {
- if (retn) {
- return reinterpret_cast<void *>(-1);
- }
- retn = ptr;
- }
- ptr++;
- }
- return retn;
- }
- unsigned GetModuleSize( unsigned& hmod ) {
- Dl_info info;
- struct stat buf;
- if (!dladdr(reinterpret_cast< void* >( hmod ), &info))
- return 0;
- if (!info.dli_fbase || !info.dli_fname)
- return 0;
- if (stat(info.dli_fname, &buf) != 0)
- return 0;
- hmod = (unsigned int)( info.dli_fbase );
- return buf.st_size;
- }
- void* SigScan( void* hmod, const char* pSignature ) {
- if (!pSignature || pSignature[0] == 0) {
- return nullptr;
- }
- static char pSig[512];
- auto siglen = UTIL_StringToSignature( pSignature, pSig, sizeof pSig );
- auto moduleSize = GetModuleSize(reinterpret_cast< unsigned int& >( hmod ));
- if (moduleSize != 0) {
- char* retn = nullptr;
- auto found = false;
- auto ptr = reinterpret_cast<char *>( hmod );
- auto end = ptr + moduleSize - 1;
- while (hmod < end) {
- found = true;
- for (register unsigned int i = 0; i < siglen; i++) {
- if (pSig[i] != '\x2A' && pSig[i] != ptr[i]) {
- found = false;
- break;
- }
- }
- if (found) {
- if (retn) {
- return reinterpret_cast<void *>(-1);
- }
- retn = ptr;
- break;
- }
- ptr++;
- }
- // printf("sigscan retn [%p]\n", retn);
- return retn;
- }
- return nullptr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement