-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
chams.cpp
220 lines (177 loc) · 7.7 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "chams.h"
// used: game's interfaces
#include "../../core/interfaces.h"
#include "../../sdk/interfaces/imaterialsystem.h"
#include "../../sdk/interfaces/igameresourceservice.h"
#include "../../sdk/interfaces/cgameentitysystem.h"
#include "../../sdk/interfaces/iresourcesystem.h"
#include "../../core/sdk.h"
#include "../../sdk/entity.h"
// used: original call in hooked function
#include "../../core/hooks.h"
// used: cheat variables
#include "../../core/variables.h"
struct CustomMaterial_t
{
CMaterial2* pMaterial;
CMaterial2* pMaterialInvisible;
//bool bIsOwner = false;
};
static CustomMaterial_t arrMaterials[VISUAL_MATERIAL_MAX];
bool F::VISUALS::CHAMS::Initialize()
{
// check if we already initialized materials
if (bInitialized)
return bInitialized;
arrMaterials[VISUAL_MATERIAL_PRIMARY_WHITE] = CustomMaterial_t{
.pMaterial = CreateMaterial(CS_XOR("primary_white"), CS_XOR("materials/dev/primary_white.vmat"), CS_XOR("csgo_unlitgeneric.vfx"), true, true, false),
.pMaterialInvisible = CreateMaterial(CS_XOR("primary_white_invisible"), CS_XOR("materials/dev/primary_white.vmat"), CS_XOR("csgo_unlitgeneric.vfx"), true, true, true)
};
arrMaterials[VISUAL_MATERIAL_WIREFRAME] = CustomMaterial_t{
.pMaterial = CreateMaterial(CS_XOR("wireframe"), CS_XOR("materials/dev/debug_wireframe.vmat"), CS_XOR("csgo_unlitgeneric.vfx"), true, true, false),
.pMaterialInvisible = CreateMaterial(CS_XOR("wireframe_invisible"), CS_XOR("materials/dev/debug_wireframe.vmat"), CS_XOR("csgo_unlitgeneric.vfx"), true, true, true)
};
bInitialized = true;
for (auto& [pMaterial, pMaterialInvisible] : arrMaterials)
{
if (pMaterial == nullptr || pMaterialInvisible == nullptr)
bInitialized = false;
}
return bInitialized;
}
void F::VISUALS::CHAMS::Destroy()
{
#ifdef TEST_CREATE_CHAMS
for (auto& [pMaterial] : arrMaterials)
{
if (pMaterial != nullptr)
I::ResourceHandleUtils->DeleteResource(pMaterial.pBinding);
}
#endif
}
bool F::VISUALS::CHAMS::OnDrawObject(void* pAnimatableSceneObjectDesc, void* pDx11, CMeshData* arrMeshDraw, int nDataCount, void* pSceneView, void* pSceneLayer, void* pUnk, void* pUnk2)
{
if (!bInitialized)
return false;
if (!C_GET(bool, Vars.bVisualChams))
return false;
if (arrMeshDraw == nullptr)
return false;
if (arrMeshDraw->pSceneAnimatableObject == nullptr)
return false;
CBaseHandle hOwner = arrMeshDraw->pSceneAnimatableObject->hOwner;
auto pEntity = I::GameResourceService->pGameEntitySystem->Get<C_BaseEntity>(hOwner);
if (pEntity == nullptr)
return false;
SchemaClassInfoData_t* pClassInfo;
pEntity->GetSchemaClassInfo(&pClassInfo);
if (pClassInfo == nullptr)
return false;
if (CRT::StringCompare(pClassInfo->szName, CS_XOR("C_CSPlayerPawn")) != 0)
return false;
auto pPawn = I::GameResourceService->pGameEntitySystem->Get<C_CSPlayerPawn>(hOwner);
if (pPawn == nullptr)
return false;
if (!pPawn->IsOtherEnemy(SDK::LocalPawn))
return false;
// alive state
if (pPawn->GetHealth() == 0)
return false;
return OverrideMaterial(pAnimatableSceneObjectDesc, pDx11, arrMeshDraw, nDataCount, pSceneView, pSceneLayer, pUnk, pUnk2);
}
#ifdef TEST_CREATE_CHAMS
CStrongHandle<CMaterial2> F::VISUALS::CHAMS::CreateMaterial(const char* szName)
{
const char szVmatBuffer[] = R"(<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
{
Shader = "csgo_unlitgeneric.vfx"
F_DISABLE_Z_BUFFERING = 0
g_flBumpStrength = 1
g_vColorTint = [1.000000, 1.000000, 1.000000, 0.000000]
g_vGlossinessRange = [0.000000, 1.000000, 0.000000, 0.000000]
g_vNormalTexCoordScale = [1.000000, 1.000000, 0.000000, 0.000000]
g_vTexCoordOffset = [0.000000, 0.000000, 0.000000, 0.000000]
g_vTexCoordScale = [1.000000, 1.000000, 0.000000, 0.000000]
g_tColor = resource:"materials/dev/primary_white_color_tga_f7b257f6.vtex"
g_tNormal = resource:"materials/default/default_normal_tga_7652cb.vtex"
g_tRoughness = resource:"materials/default/default_normal_tga_b3f4ec4c.vtex"
})";
auto buffer = new unsigned char[0x100 + sizeof(CKeyValues3)];
CRT::MemorySet(buffer, 0, sizeof(buffer));
CKeyValues3* kv3 = (CKeyValues3*)(buffer + 0x100);
KV3ID_t kv3ID;
kv3ID.szName = "generic";
kv3ID.unk0 = 0x469806E97412167C;
kv3ID.unk1 = 0xE73790B53EE6F2AF;
if (!MEM::fnLoadKV3(kv3, nullptr, szVmatBuffer, &kv3ID, nullptr))
throw;
CStrongHandle<CMaterial2> custom_material;
MEM::fnCreateMaterial(nullptr, &custom_material, szName, kv3, 0, 1);
return custom_material;
}
CStrongHandle<CMaterial2> F::VISUALS::CHAMS::CreateMaterialInvis(const char* szName)
{
const char szVmatBuffer[] = R"(<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
{
Shader = "csgo_unlitgeneric.vfx"
F_DISABLE_Z_BUFFERING = 1
g_flBumpStrength = 1
g_vColorTint = [1.000000, 1.000000, 1.000000, 0.000000]
g_vGlossinessRange = [0.000000, 1.000000, 0.000000, 0.000000]
g_vNormalTexCoordScale = [1.000000, 1.000000, 0.000000, 0.000000]
g_vTexCoordOffset = [0.000000, 0.000000, 0.000000, 0.000000]
g_vTexCoordScale = [1.000000, 1.000000, 0.000000, 0.000000]
g_tColor = resource:"materials/dev/primary_white_color_tga_f7b257f6.vtex"
g_tNormal = resource:"materials/default/default_normal_tga_7652cb.vtex"
g_tRoughness = resource:"materials/default/default_normal_tga_b3f4ec4c.vtex"
})";
auto buffer = new unsigned char[0x100 + sizeof(CKeyValues3)];
CRT::MemorySet(buffer, 0, sizeof(buffer));
CKeyValues3* kv3 = (CKeyValues3*)(buffer + 0x100);
KV3ID_t kv3ID;
kv3ID.szName = "csgo_unlitgeneric2";
kv3ID.unk0 = 0x469806E97412167C;
kv3ID.unk1 = 0xE73790B53EE6F2AF;
if (!MEM::fnLoadKV3(kv3, nullptr, szVmatBuffer, &kv3ID, nullptr))
throw;
CStrongHandle<CMaterial2> custom_material;
MEM::fnCreateMaterial(nullptr, &custom_material, szName, kv3, 0, 1);
return custom_material;
}
#endif
CMaterial2* F::VISUALS::CHAMS::CreateMaterial(const char* szName, const char* szMaterialVMAT, const char* szShaderType, bool bBlendMode, bool bTranslucent, bool bDisableZBuffering)
{
CMeshData* pData = reinterpret_cast<CMeshData*>(static_cast<std::byte*>(I::MemAlloc->Alloc(0x200)) + 0x50);
CMaterial2** pMatPrototype;
I::MaterialSystem2->FindOrCreateFromResource(&pMatPrototype, szMaterialVMAT);
if (pMatPrototype == nullptr)
return nullptr;
// @note: SetCreateDataByMaterial failed on release build idk why
#ifdef _DEBUG
I::MaterialSystem2->SetCreateDataByMaterial(pData, &pMatPrototype);
pData->SetShaderType(szShaderType);
pData->SetMaterialFunction(CS_XOR("F_DISABLE_Z_BUFFERING"), bDisableZBuffering ? 1 : 0);
pData->SetMaterialFunction(CS_XOR("F_BLEND_MODE"), bBlendMode ? 1 : 0);
pData->SetMaterialFunction(CS_XOR("F_TRANSLUCENT"), bTranslucent ? 1 : 0);
CMaterial2** pMaterial;
I::MaterialSystem2->CreateMaterial(&pMaterial, szName, pData);
I::MemAlloc->Free(pData);
return *pMaterial;
#endif
return *pMatPrototype;
}
bool F::VISUALS::CHAMS::OverrideMaterial(void* pAnimatableSceneObjectDesc, void* pDx11, CMeshData* arrMeshDraw, int nDataCount, void* pSceneView, void* pSceneLayer, void* pUnk, void* pUnk2)
{
const auto oDrawObject = H::hkDrawObject.GetOriginal();
const CustomMaterial_t customMaterial = arrMaterials[C_GET(int, Vars.nVisualChamMaterial)];
if (C_GET(bool, Vars.bVisualChamsIgnoreZ))
{
arrMeshDraw->pMaterial = customMaterial.pMaterialInvisible;
arrMeshDraw->colValue = C_GET(Color_t, Vars.colVisualChamsIgnoreZ);
oDrawObject(pAnimatableSceneObjectDesc, pDx11, arrMeshDraw, nDataCount, pSceneView, pSceneLayer, pUnk, pUnk2);
}
arrMeshDraw->pMaterial = customMaterial.pMaterial;
arrMeshDraw->colValue = C_GET(Color_t, Vars.colVisualChams);
oDrawObject(pAnimatableSceneObjectDesc, pDx11, arrMeshDraw, nDataCount, pSceneView, pSceneLayer, pUnk, pUnk2);
return true;
}