summaryrefslogtreecommitdiffstats
path: root/src/studio.cpp
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-04 18:08:07 +0100
committersalmonik <salmonik@tuta.io>2026-11-04 18:08:07 +0100
commitb3003583a1a66f5ae2eae63763f285635b43d58f (patch)
treed4d2e778a2265652befcc86fbaa8bf1f4fcb30c3 /src/studio.cpp
parentChams: quiet material lookup, accept any fallback by name (diff)
downloadhl2h-b3003583a1a66f5ae2eae63763f285635b43d58f.tar.gz
hl2h-b3003583a1a66f5ae2eae63763f285635b43d58f.zip
Chams: material styles and viewmodel support
- Material selector 0..4: debugwhite, debug wireframe (ignorez), vgui white_additive, debugtranslucentsinglecolor, vgui/white; cached per index with a debugwhite fallback. - Add "Viewmodel (hands/weapon)" toggle; viewmodel entities (class contains viewmodel or model path /v_...) get a normal-depth chams pass. - [chams] gains viewmodel= and material=.
Diffstat (limited to 'src/studio.cpp')
-rw-r--r--src/studio.cpp58
1 files changed, 38 insertions, 20 deletions
diff --git a/src/studio.cpp b/src/studio.cpp
index a1aae12..e667c4b 100644
--- a/src/studio.cpp
+++ b/src/studio.cpp
@@ -197,15 +197,29 @@ void *g_modelrender = nullptr;
197ModelExecFn g_orig_model_exec = nullptr; 197ModelExecFn g_orig_model_exec = nullptr;
198ForceOverrideFn g_force_override = nullptr; 198ForceOverrideFn g_force_override = nullptr;
199void *g_chams_mat = nullptr; 199void *g_chams_mat = nullptr;
200bool g_chams_mat_tried = false; 200int g_chams_mat_idx = -1;
201
202const char *chams_material_name(int idx) {
203 switch (idx) {
204 case 1: return "debug/debugwireframevertexcolorignorez";
205 case 2: return "vgui/white_additive";
206 case 3: return "debug/debugtranslucentsinglecolor";
207 case 4: return "vgui/white";
208 default: return "models/debug/debugwhite";
209 }
210}
201 211
202void *chams_material() { 212void *chams_material() {
203 if (g_chams_mat_tried) 213 int idx = g_chams_mat_index;
214 if (idx < 0) idx = 0;
215 if (idx > 4) idx = 4;
216 if (g_chams_mat && g_chams_mat_idx == idx)
204 return g_chams_mat; 217 return g_chams_mat;
205 g_chams_mat_tried = true; 218 g_chams_mat = world_find_material(chams_material_name(idx));
206 g_chams_mat = world_find_material("models/debug/debugwhite");
207 if (!g_chams_mat) 219 if (!g_chams_mat)
208 logf("chams: no usable material"); 220 g_chams_mat = world_find_material("models/debug/debugwhite");
221 g_chams_mat_idx = idx;
222 logf("chams: style %d -> %p", idx, g_chams_mat);
209 return g_chams_mat; 223 return g_chams_mat;
210} 224}
211 225
@@ -239,23 +253,27 @@ void hkdModelExecute(void *self, const void *state, const void *info,
239 if (feature_active(FEAT_CHAMS) && info && g_force_override) { 253 if (feature_active(FEAT_CHAMS) && info && g_force_override) {
240 // ModelRenderInfo_t::entity_index is at 0x30 on 32-bit. 254 // ModelRenderInfo_t::entity_index is at 0x30 on 32-bit.
241 int idx = *(const int *)((const char *)info + 0x30); 255 int idx = *(const int *)((const char *)info + 0x30);
242 if (idx > 0 && idx <= 8192 && esp_is_npc_index(idx)) { 256 if (idx > 0 && idx <= 8192) {
243 void *mat = chams_material(); 257 bool is_npc = esp_is_npc_index(idx);
244 if (mat) { 258 bool is_vm = g_chams_viewmodel && esp_is_viewmodel_index(idx);
245 if (g_chams_walls) { 259 if (is_npc || is_vm) {
246 chams_apply(mat, true); 260 void *mat = chams_material();
247 g_force_override(self, mat, 0 /* OVERRIDE_NORMAL */); 261 if (mat) {
262 if (g_chams_walls && !is_vm) {
263 chams_apply(mat, true);
264 g_force_override(self, mat, 0 /* OVERRIDE_NORMAL */);
265 g_orig_model_exec(self, state, info, bone);
266 }
267 chams_apply(mat, false);
268 g_force_override(self, mat, 0);
248 g_orig_model_exec(self, state, info, bone); 269 g_orig_model_exec(self, state, info, bone);
270 g_force_override(self, nullptr, 0);
271 // debugwhite is shared: restore colour and depth behaviour.
272 using FlagFn = void (*)(void *, int, bool);
273 vfunc<FlagFn>(mat, 29)(mat, 1 << 15, false);
274 chams_color(mat, 1.0f, 1.0f, 1.0f);
275 return;
249 } 276 }
250 chams_apply(mat, false);
251 g_force_override(self, mat, 0);
252 g_orig_model_exec(self, state, info, bone);
253 g_force_override(self, nullptr, 0);
254 // debugwhite is shared: restore colour and depth behaviour.
255 using FlagFn = void (*)(void *, int, bool);
256 vfunc<FlagFn>(mat, 29)(mat, 1 << 15, false);
257 chams_color(mat, 1.0f, 1.0f, 1.0f);
258 return;
259 } 277 }
260 } 278 }
261 } 279 }