-
Notifications
You must be signed in to change notification settings - Fork 1
/
Materials.h
233 lines (167 loc) · 7.65 KB
/
Materials.h
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
221
222
223
224
225
226
227
228
229
230
231
232
233
/*credits by ibanned*/
#pragma once
#include "MiscDefinitions.h"
#include "ClientRecvProps.h"
#include "offsets.h"
#include "Vector.h"
#include "MiscClasses.h"
#include "Vector2D.h"
struct PreviewImageRetVal_t;
struct MaterialPropertyTypes_t;
class IMaterialVar;
class ImageFormat;
typedef int64_t VertexFormat_t;
class IMaterial
{
public:
virtual const char * GetName() const = 0;
virtual const char * GetTextureGroupName() const = 0;
virtual PreviewImageRetVal_t GetPreviewImageProperties(int *width, int *height, ImageFormat *imageFormat, bool* isTranslucent) const = 0;
virtual PreviewImageRetVal_t GetPreviewImage(unsigned char *data, int width, int height, ImageFormat imageFormat) const = 0;
virtual int GetMappingWidth() = 0;
virtual int GetMappingHeight() = 0;
virtual int GetNumAnimationFrames() = 0;
virtual bool InMaterialPage(void) = 0;
virtual void GetMaterialOffset(float *pOffset) = 0;
virtual void GetMaterialScale(float *pScale) = 0;
virtual IMaterial *GetMaterialPage(void) = 0;
virtual IMaterialVar * FindVar(const char *varName, bool *found, bool complain = true) = 0;
virtual void IncrementReferenceCount(void) = 0;
virtual void DecrementReferenceCount(void) = 0;
inline void AddRef() { IncrementReferenceCount(); }
inline void Release() { DecrementReferenceCount(); }
virtual int GetEnumerationID(void) const = 0;
virtual void GetLowResColorSample(float s, float t, float *color) const = 0;
virtual void RecomputeStateSnapshots() = 0;
virtual bool IsTranslucent() = 0;
virtual bool IsAlphaTested() = 0;
virtual bool IsVertexLit() = 0;
virtual VertexFormat_t GetVertexFormat() const = 0;
virtual bool HasProxy(void) const = 0;
virtual bool UsesEnvCubemap(void) = 0;
virtual bool NeedsTangentSpace(void) = 0;
virtual bool NeedsPowerOfTwoFrameBufferTexture(bool bCheckSpecificToThisFrame = true) = 0;
virtual bool NeedsFullFrameBufferTexture(bool bCheckSpecificToThisFrame = true) = 0;
virtual bool NeedsSoftwareSkinning(void) = 0;
virtual void AlphaModulate(float alpha) = 0;
virtual void ColorModulate(float r, float g, float b) = 0;
virtual void SetMaterialVarFlag(MaterialVarFlags_t flag, bool on) = 0;
virtual bool GetMaterialVarFlag(MaterialVarFlags_t flag) = 0;
virtual void GetReflectivity(Vector& reflect) = 0;
virtual bool GetPropertyFlag(MaterialPropertyTypes_t type) = 0;
virtual bool IsTwoSided() = 0;
virtual void SetShader(const char *pShaderName) = 0;
virtual int GetNumPasses(void) = 0;
virtual int GetTextureMemoryBytes(void) = 0;
virtual void Refresh() = 0;
virtual bool NeedsLightmapBlendAlpha(void) = 0;
virtual bool NeedsSoftwareLighting(void) = 0;
virtual int ShaderParamCount() const = 0;
virtual IMaterialVar **GetShaderParams(void) = 0;
virtual bool IsErrorMaterial() const = 0;
virtual void Unused() = 0;
virtual float GetAlphaModulation() = 0;
virtual void GetColorModulation(float *r, float *g, float *b) = 0;
virtual bool IsTranslucentUnderModulation(float fAlphaModulation = 1.0f) const = 0;
virtual IMaterialVar * FindVarFast(char const *pVarName, unsigned int *pToken) = 0;
virtual void SetShaderAndParams(void *pKeyValues) = 0;
virtual const char * GetShaderName() const = 0;
virtual void DeleteIfUnreferenced() = 0;
virtual bool IsSpriteCard() = 0;
virtual void CallBindProxy(void *proxyData) = 0;
virtual void RefreshPreservingMaterialVars() = 0;
virtual bool WasReloadedFromWhitelist() = 0;
virtual bool SetTempExcluded(bool bSet, int nExcludedDimensionLimit) = 0;
virtual int GetReferenceCount() const = 0;
};
class CMaterialSystem
{
public:
void ColorModulation(float r, float g, float b)
{
typedef void(__thiscall* ColorModulation_t)(void*, float, float, float);
return call_vfunc<ColorModulation_t>(this, 28)(this, r, g, b);
}
IMaterial* FindMaterial(char const* pMaterialName, const char *pTextureGroupName, bool complain = true, const char *pComplainPrefix = NULL)
{
typedef IMaterial*(__thiscall* oFindMaterial)(PVOID, char const*, char const*, bool, char const*);
return call_vfunc< oFindMaterial >(this, Offsets::VMT::MaterialSystem_FindMaterial)(this, pMaterialName, pTextureGroupName, complain, pComplainPrefix);
}
IMaterial* CreateMaterial(const char *pMaterialName, KeyValues *pVMTKeyValues)
{
typedef IMaterial* (__thiscall* oCreateMaterial)(PVOID, const char *, KeyValues*);
return call_vfunc<oCreateMaterial>(this, Offsets::VMT::MaterialSystem_CreateMaterial)(this, pMaterialName, pVMTKeyValues);
}
MaterialHandle_t FirstMaterial()
{
typedef MaterialHandle_t(__thiscall* FirstMaterialFn)(void*);
return call_vfunc<FirstMaterialFn>(this, 86)(this);
}
MaterialHandle_t NextMaterial(MaterialHandle_t h)
{
typedef MaterialHandle_t(__thiscall* NextMaterialFn)(void*, MaterialHandle_t);
return call_vfunc<NextMaterialFn>(this, 87)(this, h);
}
MaterialHandle_t InvalidMaterial()
{
typedef MaterialHandle_t(__thiscall* InvalidMaterialFn)(void*);
return call_vfunc<InvalidMaterialFn>(this, 88)(this);
}
IMaterial* GetMaterial(MaterialHandle_t h)
{
typedef IMaterial*(__thiscall* GetMaterialFn)(void*, MaterialHandle_t);
return call_vfunc<GetMaterialFn>(this, 89)(this, h);
}
};
class IVModelRender
{
public:
void ForcedMaterialOverride(IMaterial *material, OverrideType_t type = OVERRIDE_NORMAL, int idk = NULL)
{
typedef void(__thiscall* Fn)(void*, IMaterial*, OverrideType_t, int);
return call_vfunc<Fn>(this, Offsets::VMT::ModelRender_ForcedMaterialOverride)(this, material, type, idk);
}
};
template <typename Fn> __forceinline Fn GetVirtualFunction(void* pClassBase, int nFunctionIndex) {
return (Fn)((PDWORD)*(PDWORD*)pClassBase)[nFunctionIndex];
}
class CModelInfo
{
public:
inline void* GetModel(int Index)
{
return GetVirtualFunction<void*(__thiscall *)(void*, int)>(this, 1)(this, Index);
}
int GetModelIndex(const char *name)
{
typedef int (__thiscall* oGetModelName)(PVOID, const char *);
return call_vfunc< oGetModelName >(this, 2)(this, name);
}
inline const char* GetModelName(const void* Model) {
return GetVirtualFunction<const char*(__thiscall *)(void*, const void*)>(this, 3)(this, Model);
}
void GetModelMaterials(const model_t *model, int count, IMaterial** ppMaterial)
{
typedef void *(__thiscall* oGetModelMaterials)(PVOID, const model_t*, int, IMaterial**);
call_vfunc<oGetModelMaterials>(this, 19)(this, model, count, ppMaterial);
}
studiohdr_t *GetStudiomodel(const model_t *mod)
{
typedef studiohdr_t*(__stdcall* oGetStudiomodel)(const model_t*);
return call_vfunc<oGetStudiomodel>(this, 32)(mod);
}
};
class CVRenderView
{
public:
void SetBlend(float alpha)
{
typedef void(__thiscall* oDrawModelExecute)(PVOID, float);
return call_vfunc< oDrawModelExecute >(this, Offsets::VMT::RenderView_SetBlend)(this, alpha);
}
void SetColorModulation(float const* colors)
{
typedef void(__thiscall* oDrawModelExecute)(PVOID, float const*);
return call_vfunc< oDrawModelExecute >(this, Offsets::VMT::RenderView_SetColorModulation)(this, colors);
}
};