-
Notifications
You must be signed in to change notification settings - Fork 2
/
Chams.cpp
102 lines (84 loc) · 2.2 KB
/
Chams.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
// Don't take credits for this ;) Joplin / Manhhao are the first uploaders ;)
#include "Chams.h"
#include "offsets.h"
#include "SDK.h"
#include "Interfaces.h"
void InitKeyValues(KeyValues* keyValues, char* name)
{
DWORD dwFunction = (DWORD)Offsets::Functions::KeyValues_KeyValues;
__asm
{
push name
mov ecx, keyValues
call dwFunction
}
}
void LoadFromBuffer(KeyValues* keyValues, char const *resourceName, const char *pBuffer)
{
DWORD dwFunction = (DWORD)Offsets::Functions::KeyValues_LoadFromBuffer;
__asm
{
push 0
push 0
push 0
push pBuffer
push resourceName
mov ecx, keyValues
call dwFunction
}
}
IMaterial *CreateMaterial(bool shouldIgnoreZ, bool isLit, bool isWireframe) //credits to ph0ne
{
static int created = 0;
static const char tmp[] =
{
"\"%s\"\
\n{\
\n\t\"$basetexture\" \"vgui/white_additive\"\
\n\t\"$envmap\" \"\"\
\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\"$ignorez\" \"%i\"\
\n\t\"$znearer\" \"0\"\
\n\t\"$wireframe\" \"%i\"\
\n}\n"
};
char* baseType = (isLit == true ? "VertexLitGeneric" : "UnlitGeneric");
char material[512];
sprintf_s(material, sizeof(material), tmp, baseType, (shouldIgnoreZ) ? 1 : 0, (isWireframe) ? 1 : 0);
char name[512];
sprintf_s(name, sizeof(name), "#ayy_meme_%i.vmt", created);
++created;
KeyValues* keyValues = (KeyValues*)malloc(sizeof(KeyValues));
InitKeyValues(keyValues, baseType);
LoadFromBuffer(keyValues, name, material);
IMaterial *createdMaterial = Interfaces::MaterialSystem->CreateMaterial(name, keyValues);
createdMaterial->IncrementReferenceCount();
return createdMaterial;
}
void ForceMaterial(Color color, IMaterial* material, bool useColor, bool forceMaterial)
{
if (useColor)
{
float temp[3] =
{
color.r(),
color.g(),
color.b()
};
temp[0] /= 255.f;
temp[1] /= 255.f;
temp[2] /= 255.f;
float alpha = color.a();
Interfaces::RenderView->SetBlend(1.0f);
Interfaces::RenderView->SetColorModulation(temp);
}
if (forceMaterial)
Interfaces::ModelRender->ForcedMaterialOverride(material);
else
Interfaces::ModelRender->ForcedMaterialOverride(NULL);
}