From cc06dab406a0086ddcb9e4ced3759614f65e069e Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 11:49:32 +0100 Subject: Props: remove studio diagnostics; document the prop tint path Drop the temporary DrawModel/SetColor logs now that the prop tint works, and document the IStudioRender hook layout, the short model-name format used for prop detection, the SetColor-before-DrawModel ordering, and why prop materials cannot be tinted directly. --- CONTEXT.md | 26 +++++++++++++++++++++----- src/studio.cpp | 20 -------------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/CONTEXT.md b/CONTEXT.md index 5eca9f8..2199be6 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -329,11 +329,27 @@ vocabulary / decisions. already-loaded `materialsystem.so` and walk every material with `FirstMaterial` / `NextMaterial` / `GetMaterial`. - `IMaterial::ColorModulate(r,g,b)` is applied to materials whose - `GetTextureGroupName()` is `World textures` (sky names excluded), to - `SkyBox textures` (or names containing `sky`), and to prop materials whose - name starts with `models/props` (static props and prop_physics share those - model materials; NPC/player/weapon materials are excluded). Lightmaps are - not touched. + `GetTextureGroupName()` is `World textures` (sky names excluded) and to + `SkyBox textures` (or names containing `sky`). Lightmaps are not touched. +- Props are NOT tinted through their materials: VertexLitGeneric materials get + their colour modulation from `IStudioRender`, which the engine sets per + model draw (white), so the material var is overridden. `src/studio.cpp` + hooks the `VStudioRender025` interface object instead: + `SetColorModulation`/`SetAlphaModulation` (slots 27/28), `DrawModel` (29), + `DrawModelStaticProp` (30) and `DrawModelArray` (46), all checked against + `CStudioRenderContext`'s vtable in `studiorender.so`. + `DrawModel` checks `DrawModelInfo_t::m_pStudioHdr->name`; note the name is + the short form with Windows separators (`props_junk\wood_crate002a.mdl`, + no `models/` prefix), so prop detection matches `props/`, `props\` and + `props_` after stripping `models/` (excluding `props_skybox`). For a prop it + sets the prop colour right before calling the original draw; setting the + colour from a flag inside the draw does not work because the engine calls + `SetColorModulation(1,1,1)` *before* `DrawModel`. + Do not force `SetAlphaModulation` there: the earlier attempt produced + error-material props and a material-system crash. +- `prop_tint_update()` also writes `m_clrRender` on prop entities (dynamic + props) as a secondary path; the netvar resolver rejects offset 0 (an + embedded-table false positive) and only accepts 0x20..0x2000. - Slot map (2013 SDK layout, registered under `VMaterialSystem080`): `IMaterialSystem` 73/74/75/76/77 = First/Next/Invalid/Get/GetNumMaterials; `IMaterial` 0/1/28 = GetName/GetTextureGroupName/ColorModulate. diff --git a/src/studio.cpp b/src/studio.cpp index c4c3cfb..485b4fb 100644 --- a/src/studio.cpp +++ b/src/studio.cpp @@ -40,8 +40,6 @@ bool g_installed = false; int g_prop_depth = 0; int g_static_calls = 0; int g_static_props = 0; -int g_model_logs = 0; -int g_array_logs = 0; bool prop_tint_on() { return feature_active(FEAT_WORLD_TINT) && g_tint_prop_on; @@ -89,15 +87,7 @@ bool is_prop_model(const char *name) { strncmp(name, "props_", 6) == 0; } -int g_color_logs = 0; - void hook_set_color(void *self, const float *color) { - if (g_color_logs < 10) { - g_color_logs++; - logf("studio: SetColorModulation depth=%d color=%.2f,%.2f,%.2f", - g_prop_depth, color ? color[0] : 0.0f, color ? color[1] : 0.0f, - color ? color[2] : 0.0f); - } if (g_prop_depth > 0 && prop_tint_on()) { float c[4]; prop_color(c); @@ -120,11 +110,6 @@ 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_model_logs < 10) { - g_model_logs++; - logf("studio: DrawModel model=\"%s\" prop=%d", model ? model : "?", - (int)prop); - } if (prop) { float c[4]; prop_color(c); @@ -140,11 +125,6 @@ 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_array_logs < 10) { - g_array_logs++; - logf("studio: DrawModelArray count=%d model=\"%s\" prop=%d", count, - model ? model : "?", (int)prop); - } if (prop) g_prop_depth++; g_orig_draw_array(self, info, count, instances, stride, flags); -- cgit v1.2.3