-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInterfaces.cpp
111 lines (100 loc) · 5.8 KB
/
Interfaces.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
Syn's AyyWare Framework 2015
*/
#include "Interfaces.h"
#include "Utilities.h"
//SDK Specific Definitions
typedef void* (__cdecl* CreateInterface_t)(const char*, int*);
typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode);
//Some globals for later
CreateInterface_t EngineFactory = NULL; // These are used to store the individual
CreateInterface_t ClientFactory = NULL; // CreateInterface functions for each game
CreateInterface_t VGUISurfaceFactory = NULL; // dll that we need access to. Can call
CreateInterface_t VGUI2Factory = NULL; // them to recieve pointers to game classes.
CreateInterface_t MatFactory = NULL;
CreateInterface_t PhysFactory = NULL;
CreateInterface_t StdFactory = NULL;
void Interfaces::Initialise()
{
//Get function pointers to the CreateInterface function of each module
EngineFactory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::Engine, "CreateInterface");
ClientFactory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::Client, "CreateInterface");
VGUI2Factory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::VGUI2, "CreateInterface");
VGUISurfaceFactory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::VGUISurface, "CreateInterface");
MatFactory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::Material, "CreateInterface");
PhysFactory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::VPhysics, "CreateInterface");
StdFactory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::Stdlib, "CreateInterface");
//Get the interface names regardless of their version number by scanning for each string
char* CHLClientInterfaceName = (char*)Utilities::Memory::FindTextPattern("client.dll", "VClient0");
char* VGUI2PanelsInterfaceName = (char*)Utilities::Memory::FindTextPattern("vgui2.dll", "VGUI_Panel0");
char* VGUISurfaceInterfaceName = (char*)Utilities::Memory::FindTextPattern("vguimatsurface.dll", "VGUI_Surface0");
char* EntityListInterfaceName = (char*)Utilities::Memory::FindTextPattern("client.dll", "VClientEntityList0");
char* EngineDebugThingInterface = (char*)Utilities::Memory::FindTextPattern("engine.dll", "VDebugOverlay0");
char* EngineClientInterfaceName = (char*)Utilities::Memory::FindTextPattern("engine.dll","VEngineClient0");
char* ClientPredictionInterface = (char*)Utilities::Memory::FindTextPattern("client.dll", "VClientPrediction0");
char* MatSystemInterfaceName = (char*)Utilities::Memory::FindTextPattern("materialsystem.dll", "VMaterialSystem0");
char* EngineRenderViewInterface = (char*)Utilities::Memory::FindTextPattern("engine.dll", "VEngineRenderView0");
char* EngineModelRenderInterface = (char*)Utilities::Memory::FindTextPattern("engine.dll", "VEngineModel0");
char* EngineModelInfoInterface = (char*)Utilities::Memory::FindTextPattern("engine.dll", "VModelInfoClient0");
char* EngineTraceInterfaceName = (char*)Utilities::Memory::FindTextPattern("engine.dll", "EngineTraceClient0");
char* PhysPropsInterfaces = (char*)Utilities::Memory::FindTextPattern("client.dll", "VPhysicsSurfaceProps0");
char* VEngineCvarName = (char*)Utilities::Memory::FindTextPattern("engine.dll", "VEngineCvar00");
// Use the factory function pointers along with the interface versions to grab
// pointers to the interfaces
Client = (IBaseClientDLL*)ClientFactory(CHLClientInterfaceName, NULL);
Engine = (IVEngineClient*)EngineFactory(EngineClientInterfaceName, NULL);
Panels = (IPanel*)VGUI2Factory(VGUI2PanelsInterfaceName, NULL);
Surface = (ISurface*)VGUISurfaceFactory(VGUISurfaceInterfaceName, NULL);
EntList = (IClientEntityList*)ClientFactory(EntityListInterfaceName, NULL);
DebugOverlay = (IVDebugOverlay*)EngineFactory(EngineDebugThingInterface, NULL);
Prediction = (DWORD*)ClientFactory(ClientPredictionInterface, NULL);
MaterialSystem = (CMaterialSystem*)MatFactory(MatSystemInterfaceName, NULL);
RenderView = (CVRenderView*)EngineFactory(EngineRenderViewInterface, NULL);
ModelRender = (IVModelRender*)EngineFactory(EngineModelRenderInterface, NULL);
ModelInfo = (CModelInfo*)EngineFactory(EngineModelInfoInterface, NULL);
Trace = (IEngineTrace*)EngineFactory(EngineTraceInterfaceName, NULL);
PhysProps = (IPhysicsSurfaceProps*)PhysFactory(PhysPropsInterfaces, NULL);
CVar = (ICVar*)StdFactory(VEngineCvarName, NULL);
// Get ClientMode Pointer
DWORD* ppClientMode;
ppClientMode = nullptr; // before "scripts/vgui_screens.txt"
DWORD p = Utilities::Memory::FindPattern("client.dll", (BYTE*)"\xC7\x05\x00\x00\x00\x00\x00\x00\x00\x00\xA8\x01\x75\x1A\x83\xC8\x01\xA3\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x68\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x83\xC4\x04\xA1\x00\x00\x00\x00\xB9\x00\x00\x00\x00\x56", "xx????????xxxxxxxx????x????x????x????xxxx????x????x");
if (p)
{
ppClientMode = **(DWORD***)(p + 2);
ClientMode = ppClientMode;
}
// Search through the first entry of the Client VTable
// The initializer contains a pointer to the 'GlobalsVariables' Table
PDWORD pdwClient = (PDWORD)*(PDWORD)Client;
DWORD dwInitAddr = (DWORD)(pdwClient[0]);
for (DWORD dwIter = 0; dwIter <= 0xFF; dwIter++)
{
if (*(PBYTE)(dwInitAddr + dwIter - 1) == 0x08 && *(PBYTE)(dwInitAddr + dwIter) == 0xA3)
{
Globals = (CGlobalVarsBase*)*(PDWORD)*(PDWORD)(dwInitAddr + dwIter + 1);
break;
}
}
Utilities::Log("Interfaces Ready");
}
// Namespace to contain all the valve interfaces
namespace Interfaces
{
IBaseClientDLL* Client;
IVEngineClient* Engine;
IPanel* Panels;
IClientEntityList* EntList;
ISurface* Surface;
IVDebugOverlay* DebugOverlay;
DWORD *ClientMode;
CGlobalVarsBase *Globals;
DWORD *Prediction;
CMaterialSystem* MaterialSystem;
CVRenderView* RenderView;
IVModelRender* ModelRender;
CModelInfo* ModelInfo;
IEngineTrace* Trace;
IPhysicsSurfaceProps* PhysProps;
ICVar *CVar;
};