forked from faggotman69/Prometheus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChams.cpp
More file actions
124 lines (103 loc) · 3.5 KB
/
Chams.cpp
File metadata and controls
124 lines (103 loc) · 3.5 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "Chams.h"
#include "SDK.h"
#include "Interfaces.h"
#include <sstream>
#define RandomInt(nMin, nMax) (rand() % (nMax - nMin + 1) + nMin);
void InitKeyValues(KeyValues* keyValues, const char* name)
{
static uint8_t* sig1;
if (!sig1)
{
sig1 = U::pattern_scan(GetModuleHandleW(L"client.dll"), "68 ? ? ? ? 8B C8 E8 ? ? ? ? 89 45 FC EB 07 C7 45 ? ? ? ? ? 8B 03 56");
sig1 += 7;
sig1 = sig1 + *reinterpret_cast<PDWORD_PTR>(sig1 + 1) + 5;
}
static auto function = (void(__thiscall*)(KeyValues*, const char*))sig1;
function(keyValues, name);
}
void LoadFromBuffer(KeyValues* keyValues, char const* resourceName, const char* pBuffer)
{
static uint8_t* offset;
if (!offset) offset = U::pattern_scan(GetModuleHandleW(L"client.dll"), "55 8B EC 83 E4 F8 83 EC 34 53 8B 5D 0C 89 4C 24 04");
static auto function = (void(__thiscall*)(KeyValues*, char const*, const char*, void*, const char*, void*))offset;
function(keyValues, resourceName, pBuffer, 0, 0, 0);
}
IMaterial* CreateMaterial(bool Ignore, bool Lit, bool Wireframe)
{
static int created = 0;
static const char tmp[] =
{
"\"%s\"\
\n{\
\n\t\"$basetexture\" \"vgui/white_additive\"\
\n\t\"$envmap\" \"\"\
\n\t\"$ignorez\" \"%i\"\
\n\t\"$model\" \"1\"\
\n\t\"$flat\" \"1\"\
\n\t\"$nocull\" \"0\"\
\n\t\"$selfillum\" \"1\"\
\n\t\"$halflambert\" \"1\"\
\n\t\"$nofog\" \"0\"\
\n\t\"$znearer\" \"0\"\
\n\t\"$wireframe\" \"%i\"\
\n}\n"
};
char* baseType = (Lit == true ? "VertexLitGeneric" : "UnlitGeneric");
char material[512];
char name[512];
sprintf_s(material, sizeof(material), tmp, baseType, (Ignore) ? 1 : 0, (Wireframe) ? 1 : 0);
sprintf_s(name, sizeof(name), "#Aimpulse_Chams_%i.vmt", created);
++created;
KeyValues* keyValues = new KeyValues(name);
InitKeyValues(keyValues, baseType);
LoadFromBuffer(keyValues, name, material);
IMaterial* createdMaterial = g_MaterialSystem->CreateMaterial(name, keyValues);
createdMaterial->IncrementReferenceCount();
return createdMaterial;
}
void ForceMaterial(Color color, IMaterial* material, bool useColor, bool forceMaterial)
{
if (useColor)
{
float temp[3] =
{
(float)color.r(),
(float)color.g(),
(float)color.b()
};
temp[0] /= 255.f;
temp[1] /= 255.f;
temp[2] /= 255.f;
float alpha = (float)color.a();
g_RenderView->SetBlend(1.0f);
g_RenderView->SetColorModulation(temp);
}
if (forceMaterial)
g_ModelRender->ForcedMaterialOverride(material);
else
g_ModelRender->ForcedMaterialOverride(NULL);
}
void *KeyValues::operator new(size_t iAllocSize)
{
static PVOID pKeyValuesSystem;
if (!pKeyValuesSystem)
{
typedef PVOID(__cdecl* oKeyValuesSystem)();
oKeyValuesSystem KeyValuesSystem = (oKeyValuesSystem)GetProcAddress(GetModuleHandleA("vstdlib.dll"), "KeyValuesSystem");
pKeyValuesSystem = KeyValuesSystem();
}
typedef PVOID(__thiscall* oAllocKeyValuesMemory)(PVOID, size_t);
return call_vfunc<oAllocKeyValuesMemory>(pKeyValuesSystem, 1)(pKeyValuesSystem, iAllocSize);
}
void KeyValues::operator delete(void * pMem)
{
static PVOID pKeyValuesSystem;
if (!pKeyValuesSystem)
{
typedef PVOID(__cdecl* oKeyValuesSystem)();
oKeyValuesSystem KeyValuesSystem = (oKeyValuesSystem)GetProcAddress(GetModuleHandleA("vstdlib.dll"), "KeyValuesSystem");
pKeyValuesSystem = KeyValuesSystem();
}
typedef void(__thiscall* oFreeKeyValuesMemory)(PVOID, PVOID);
call_vfunc<oFreeKeyValuesMemory>(pKeyValuesSystem, 2)(pKeyValuesSystem, pMem);
}