summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/esp.cpp51
-rw-r--r--src/studio.cpp60
2 files changed, 55 insertions, 56 deletions
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) {
1405 return false; 1405 return false;
1406} 1406}
1407 1407
1408// Tints dynamic props by writing their client render colour. StudioRender 1408// Props are tinted through IStudioRender (studio.cpp), which covers both
1409// uses m_clrRender as the per-model colour modulation, which is why changing 1409// dynamic prop_physics entities and map-static props. There is no per-entity
1410// the prop MATERIAL colour had no effect. 1410// netvar write here: m_clrRender resolved to offset 0 in this build.
1411void prop_tint_update() { 1411void prop_tint_update() {
1412 static bool applied = false; 1412 if (feature_active(FEAT_WORLD_TINT) && g_tint_prop_on)
1413 static bool logged_missing = false;
1414 static bool logged_touched = false;
1415 bool on = feature_active(FEAT_WORLD_TINT) && g_tint_prop_on;
1416 if (on)
1417 studio_props_init(); 1413 studio_props_init();
1418 if (!on && !applied)
1419 return;
1420 if (!g_iface.entitylist || g_net.clr_render < 0) {
1421 if (on && !logged_missing) {
1422 logged_missing = true;
1423 logf("prop tint: m_clrRender unavailable");
1424 }
1425 return;
1426 }
1427 static double last = 0.0;
1428 double now = esp_now();
1429 if (on && now - last < 0.01)
1430 return;
1431 last = now;
1432
1433 using Fn = int (*)(void *);
1434 int hi = vfunc<Fn>(g_iface.entitylist, 6)(g_iface.entitylist);
1435 if (hi < 0 || hi > 4096)
1436 hi = 4096;
1437 uint32_t col =
1438 on ? ((uint32_t)g_tint_prop_rgb[0] | ((uint32_t)g_tint_prop_rgb[1] << 8) |
1439 ((uint32_t)g_tint_prop_rgb[2] << 16) | (255u << 24))
1440 : 0xFFFFFFFFu;
1441 int touched = 0;
1442 for (int idx = 1; idx <= hi; idx++) {
1443 void *ent = entitylist_get(idx);
1444 if (!ent)
1445 continue;
1446 const char *model = entity_model_name(ent);
1447 if (!model || strncmp(model, "models/props", 12) != 0)
1448 continue;
1449 *(uint32_t *)((uintptr_t)ent + (uintptr_t)g_net.clr_render) = col;
1450 touched++;
1451 }
1452 applied = on;
1453 if (on && touched > 0 && !logged_touched) {
1454 logged_touched = true;
1455 logf("prop tint: %d prop entities", touched);
1456 }
1457} 1414}
1458 1415
1459void esp_draw() { 1416void 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 {
25using SetColorFn = void (*)(void *, const float *); 25using SetColorFn = void (*)(void *, const float *);
26using SetAlphaFn = void (*)(void *, float); 26using SetAlphaFn = void (*)(void *, float);
27using DrawStaticFn = void (*)(void *, void *, void *, int); 27using DrawStaticFn = void (*)(void *, void *, void *, int);
28using DrawModelFn = void (*)(void *, void *, void *, void *, void *, void *,
29 int);
30using DrawArrayFn = void (*)(void *, void *, int, void *, int, int);
28 31
29SetColorFn g_orig_set_color = nullptr; 32SetColorFn g_orig_set_color = nullptr;
30SetAlphaFn g_orig_set_alpha = nullptr; 33SetAlphaFn g_orig_set_alpha = nullptr;
31DrawStaticFn g_orig_draw_static = nullptr; 34DrawStaticFn g_orig_draw_static = nullptr;
35DrawModelFn g_orig_draw_model = nullptr;
36DrawArrayFn g_orig_draw_array = nullptr;
32 37
33bool g_install_tried = false; 38bool g_install_tried = false;
34bool g_installed = false; 39bool g_installed = false;
@@ -89,6 +94,44 @@ void hook_set_alpha(void *self, float alpha) {
89 g_orig_set_alpha(self, alpha); 94 g_orig_set_alpha(self, alpha);
90} 95}
91 96
97void force_prop_color(void *self) {
98 float c[4];
99 prop_color(c);
100 g_orig_set_color(self, c);
101 g_orig_set_alpha(self, 1.0f);
102}
103
104void hook_draw_model(void *self, void *results, void *info, void *bone,
105 void *flex, void *flex_delayed, int flags) {
106 const char *model = info_model_name(info);
107 bool prop = prop_tint_on() && is_prop_model(model);
108 if (g_static_calls < 3 && prop)
109 logf("studio: DrawModel prop model=\"%s\"", model ? model : "?");
110 if (prop) {
111 force_prop_color(self);
112 g_prop_depth++;
113 }
114 g_orig_draw_model(self, results, info, bone, flex, flex_delayed, flags);
115 if (prop)
116 g_prop_depth--;
117}
118
119void hook_draw_array(void *self, void *info, int count, void *instances,
120 int stride, int flags) {
121 const char *model = info_model_name(info);
122 bool prop = prop_tint_on() && is_prop_model(model);
123 if (g_static_calls < 3)
124 logf("studio: DrawModelArray count=%d model=\"%s\" prop=%d", count,
125 model ? model : "?", (int)prop);
126 if (prop) {
127 force_prop_color(self);
128 g_prop_depth++;
129 }
130 g_orig_draw_array(self, info, count, instances, stride, flags);
131 if (prop)
132 g_prop_depth--;
133}
134
92void hook_draw_static_prop(void *self, void *info, void *model_to_world, 135void hook_draw_static_prop(void *self, void *info, void *model_to_world,
93 int flags) { 136 int flags) {
94 const char *model = info_model_name(info); 137 const char *model = info_model_name(info);
@@ -103,13 +146,7 @@ void hook_draw_static_prop(void *self, void *info, void *model_to_world,
103 logf("studio: static draws=%d prop_draws=%d", g_static_calls, 146 logf("studio: static draws=%d prop_draws=%d", g_static_calls,
104 g_static_props); 147 g_static_props);
105 if (prop) { 148 if (prop) {
106 // The engine may have set the modulation just before this call; override 149 force_prop_color(self);
107 // it here as well as from the SetColorModulation hook (the static-prop
108 // renderer can call it either side of DrawModelStaticProp).
109 float c[4];
110 prop_color(c);
111 g_orig_set_color(self, c);
112 g_orig_set_alpha(self, 1.0f);
113 g_prop_depth++; 150 g_prop_depth++;
114 } 151 }
115 g_orig_draw_static(self, info, model_to_world, flags); 152 g_orig_draw_static(self, info, model_to_world, flags);
@@ -178,13 +215,18 @@ void studio_props_init() {
178 215
179 g_orig_set_color = (SetColorFn)vt[27]; 216 g_orig_set_color = (SetColorFn)vt[27];
180 g_orig_set_alpha = (SetAlphaFn)vt[28]; 217 g_orig_set_alpha = (SetAlphaFn)vt[28];
218 g_orig_draw_model = (DrawModelFn)vt[29];
181 g_orig_draw_static = (DrawStaticFn)vt[30]; 219 g_orig_draw_static = (DrawStaticFn)vt[30];
220 g_orig_draw_array = (DrawArrayFn)vt[46];
182 vt[27] = (void *)&hook_set_color; 221 vt[27] = (void *)&hook_set_color;
183 vt[28] = (void *)&hook_set_alpha; 222 vt[28] = (void *)&hook_set_alpha;
223 vt[29] = (void *)&hook_draw_model;
184 vt[30] = (void *)&hook_draw_static_prop; 224 vt[30] = (void *)&hook_draw_static_prop;
225 vt[46] = (void *)&hook_draw_array;
185 226
186 *(void ***)sr = vt; 227 *(void ***)sr = vt;
187 g_installed = true; 228 g_installed = true;
188 logf("studio: IStudioRender %p hooked (setcolor=%p drawstatic=%p)", sr, 229 logf("studio: IStudioRender %p hooked (color=%p draw=%p static=%p "
189 (void *)g_orig_set_color, (void *)g_orig_draw_static); 230 "array=%p)", sr, (void *)g_orig_set_color, (void *)g_orig_draw_model,
231 (void *)g_orig_draw_static, (void *)g_orig_draw_array);
190} 232}