summaryrefslogtreecommitdiffstats
path: root/src/studio.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/studio.cpp60
1 files changed, 51 insertions, 9 deletions
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}