From b3003583a1a66f5ae2eae63763f285635b43d58f Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 18:08:07 +0100 Subject: 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=. --- src/studio.cpp | 58 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'src/studio.cpp') 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; ModelExecFn g_orig_model_exec = nullptr; ForceOverrideFn g_force_override = nullptr; void *g_chams_mat = nullptr; -bool g_chams_mat_tried = false; +int g_chams_mat_idx = -1; + +const char *chams_material_name(int idx) { + switch (idx) { + case 1: return "debug/debugwireframevertexcolorignorez"; + case 2: return "vgui/white_additive"; + case 3: return "debug/debugtranslucentsinglecolor"; + case 4: return "vgui/white"; + default: return "models/debug/debugwhite"; + } +} void *chams_material() { - if (g_chams_mat_tried) + int idx = g_chams_mat_index; + if (idx < 0) idx = 0; + if (idx > 4) idx = 4; + if (g_chams_mat && g_chams_mat_idx == idx) return g_chams_mat; - g_chams_mat_tried = true; - g_chams_mat = world_find_material("models/debug/debugwhite"); + g_chams_mat = world_find_material(chams_material_name(idx)); if (!g_chams_mat) - logf("chams: no usable material"); + g_chams_mat = world_find_material("models/debug/debugwhite"); + g_chams_mat_idx = idx; + logf("chams: style %d -> %p", idx, g_chams_mat); return g_chams_mat; } @@ -239,23 +253,27 @@ void hkdModelExecute(void *self, const void *state, const void *info, if (feature_active(FEAT_CHAMS) && info && g_force_override) { // ModelRenderInfo_t::entity_index is at 0x30 on 32-bit. int idx = *(const int *)((const char *)info + 0x30); - if (idx > 0 && idx <= 8192 && esp_is_npc_index(idx)) { - void *mat = chams_material(); - if (mat) { - if (g_chams_walls) { - chams_apply(mat, true); - g_force_override(self, mat, 0 /* OVERRIDE_NORMAL */); + if (idx > 0 && idx <= 8192) { + bool is_npc = esp_is_npc_index(idx); + bool is_vm = g_chams_viewmodel && esp_is_viewmodel_index(idx); + if (is_npc || is_vm) { + void *mat = chams_material(); + if (mat) { + if (g_chams_walls && !is_vm) { + chams_apply(mat, true); + g_force_override(self, mat, 0 /* OVERRIDE_NORMAL */); + g_orig_model_exec(self, state, info, bone); + } + chams_apply(mat, false); + g_force_override(self, mat, 0); g_orig_model_exec(self, state, info, bone); + g_force_override(self, nullptr, 0); + // debugwhite is shared: restore colour and depth behaviour. + using FlagFn = void (*)(void *, int, bool); + vfunc(mat, 29)(mat, 1 << 15, false); + chams_color(mat, 1.0f, 1.0f, 1.0f); + return; } - chams_apply(mat, false); - g_force_override(self, mat, 0); - g_orig_model_exec(self, state, info, bone); - g_force_override(self, nullptr, 0); - // debugwhite is shared: restore colour and depth behaviour. - using FlagFn = void (*)(void *, int, bool); - vfunc(mat, 29)(mat, 1 << 15, false); - chams_color(mat, 1.0f, 1.0f, 1.0f); - return; } } } -- cgit v1.2.3