From fd9fb062a3e8bfabb48d2fd9db90a00c0bcc53a2 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 11:28:49 +0100 Subject: Props: tint through DrawModel/DrawModelArray; drop m_clrRender writes m_clrRender resolved to offset 0 in this build; writing it stomped entity vtables instead of tinting anything. Remove that path. The static-prop logging showed DrawModelStaticProp is never called for these props, so hook the other studio draw entries as well: DrawModel (29) for entity models and DrawModelArray (46, the instanced static-prop path). Both read the model name from DrawModelInfo_t::m_pStudioHdr and force the prop colour for models/props* draws. --- src/esp.cpp | 51 ++++--------------------------------------------- src/studio.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 56 deletions(-) (limited to 'src') diff --git a/src/esp.cpp b/src/esp.cpp index 67fbad2..1fd4904 100644 --- a/src/esp.cpp +++ b/src/esp.cpp @@ -1405,55 +1405,12 @@ bool triggerbot_apply(CUserCmd *cmd) { return false; } -// Tints dynamic props by writing their client render colour. StudioRender -// uses m_clrRender as the per-model colour modulation, which is why changing -// the prop MATERIAL colour had no effect. +// Props are tinted through IStudioRender (studio.cpp), which covers both +// dynamic prop_physics entities and map-static props. There is no per-entity +// netvar write here: m_clrRender resolved to offset 0 in this build. void prop_tint_update() { - static bool applied = false; - static bool logged_missing = false; - static bool logged_touched = false; - bool on = feature_active(FEAT_WORLD_TINT) && g_tint_prop_on; - if (on) + if (feature_active(FEAT_WORLD_TINT) && g_tint_prop_on) studio_props_init(); - if (!on && !applied) - return; - if (!g_iface.entitylist || g_net.clr_render < 0) { - if (on && !logged_missing) { - logged_missing = true; - logf("prop tint: m_clrRender unavailable"); - } - return; - } - static double last = 0.0; - double now = esp_now(); - if (on && now - last < 0.01) - return; - last = now; - - using Fn = int (*)(void *); - int hi = vfunc(g_iface.entitylist, 6)(g_iface.entitylist); - if (hi < 0 || hi > 4096) - hi = 4096; - uint32_t col = - on ? ((uint32_t)g_tint_prop_rgb[0] | ((uint32_t)g_tint_prop_rgb[1] << 8) | - ((uint32_t)g_tint_prop_rgb[2] << 16) | (255u << 24)) - : 0xFFFFFFFFu; - int touched = 0; - for (int idx = 1; idx <= hi; idx++) { - void *ent = entitylist_get(idx); - if (!ent) - continue; - const char *model = entity_model_name(ent); - if (!model || strncmp(model, "models/props", 12) != 0) - continue; - *(uint32_t *)((uintptr_t)ent + (uintptr_t)g_net.clr_render) = col; - touched++; - } - applied = on; - if (on && touched > 0 && !logged_touched) { - logged_touched = true; - logf("prop tint: %d prop entities", touched); - } } void esp_draw() { diff --git a/src/studio.cpp b/src/studio.cpp index 0c988dc..01f4830 100644 --- a/src/studio.cpp +++ b/src/studio.cpp @@ -25,10 +25,15 @@ namespace { using SetColorFn = void (*)(void *, const float *); using SetAlphaFn = void (*)(void *, float); using DrawStaticFn = void (*)(void *, void *, void *, int); +using DrawModelFn = void (*)(void *, void *, void *, void *, void *, void *, + int); +using DrawArrayFn = void (*)(void *, void *, int, void *, int, int); SetColorFn g_orig_set_color = nullptr; SetAlphaFn g_orig_set_alpha = nullptr; DrawStaticFn g_orig_draw_static = nullptr; +DrawModelFn g_orig_draw_model = nullptr; +DrawArrayFn g_orig_draw_array = nullptr; bool g_install_tried = false; bool g_installed = false; @@ -89,6 +94,44 @@ void hook_set_alpha(void *self, float alpha) { g_orig_set_alpha(self, alpha); } +void force_prop_color(void *self) { + float c[4]; + prop_color(c); + g_orig_set_color(self, c); + g_orig_set_alpha(self, 1.0f); +} + +void hook_draw_model(void *self, void *results, void *info, void *bone, + void *flex, void *flex_delayed, int flags) { + const char *model = info_model_name(info); + bool prop = prop_tint_on() && is_prop_model(model); + if (g_static_calls < 3 && prop) + logf("studio: DrawModel prop model=\"%s\"", model ? model : "?"); + if (prop) { + force_prop_color(self); + g_prop_depth++; + } + g_orig_draw_model(self, results, info, bone, flex, flex_delayed, flags); + if (prop) + g_prop_depth--; +} + +void hook_draw_array(void *self, void *info, int count, void *instances, + int stride, int flags) { + const char *model = info_model_name(info); + bool prop = prop_tint_on() && is_prop_model(model); + if (g_static_calls < 3) + logf("studio: DrawModelArray count=%d model=\"%s\" prop=%d", count, + model ? model : "?", (int)prop); + if (prop) { + force_prop_color(self); + g_prop_depth++; + } + g_orig_draw_array(self, info, count, instances, stride, flags); + if (prop) + g_prop_depth--; +} + void hook_draw_static_prop(void *self, void *info, void *model_to_world, int flags) { const char *model = info_model_name(info); @@ -103,13 +146,7 @@ void hook_draw_static_prop(void *self, void *info, void *model_to_world, logf("studio: static draws=%d prop_draws=%d", g_static_calls, g_static_props); if (prop) { - // The engine may have set the modulation just before this call; override - // it here as well as from the SetColorModulation hook (the static-prop - // renderer can call it either side of DrawModelStaticProp). - float c[4]; - prop_color(c); - g_orig_set_color(self, c); - g_orig_set_alpha(self, 1.0f); + force_prop_color(self); g_prop_depth++; } g_orig_draw_static(self, info, model_to_world, flags); @@ -178,13 +215,18 @@ void studio_props_init() { g_orig_set_color = (SetColorFn)vt[27]; g_orig_set_alpha = (SetAlphaFn)vt[28]; + g_orig_draw_model = (DrawModelFn)vt[29]; g_orig_draw_static = (DrawStaticFn)vt[30]; + g_orig_draw_array = (DrawArrayFn)vt[46]; vt[27] = (void *)&hook_set_color; vt[28] = (void *)&hook_set_alpha; + vt[29] = (void *)&hook_draw_model; vt[30] = (void *)&hook_draw_static_prop; + vt[46] = (void *)&hook_draw_array; *(void ***)sr = vt; g_installed = true; - logf("studio: IStudioRender %p hooked (setcolor=%p drawstatic=%p)", sr, - (void *)g_orig_set_color, (void *)g_orig_draw_static); + logf("studio: IStudioRender %p hooked (color=%p draw=%p static=%p " + "array=%p)", sr, (void *)g_orig_set_color, (void *)g_orig_draw_model, + (void *)g_orig_draw_static, (void *)g_orig_draw_array); } -- cgit v1.2.3