10 REGISTER_NET_TEMP(net_debug)
14 NET_HANDLE(net_debug, bool isNew)
16 Net_Accept(net_debug);
17 this.sv_entnum = ReadShort();
18 if (ReadByte()) make_pure(this);
19 this.origin = ReadVector();
20 setorigin(this, this.origin);
21 this.debug = true; // identify server entities by this
22 this.classname = strzone(ReadString());
23 this.sourceLoc = strzone(ReadString());
29 bool debug_send(entity this, entity to, int sf)
31 int channel = MSG_ONE;
33 WriteHeader(channel, net_debug);
34 WriteShort(channel, etof(this));
35 WriteByte(channel, is_pure(this));
36 vector o = this.origin;
37 if (o == '0 0 0') // brushes
38 o = (this.absmin + this.absmax) / 2;
40 o += this.tag_entity.origin;
41 WriteVector(channel, o);
42 WriteString(channel, this.classname);
43 WriteString(channel, this.sourceLoc);
54 * 3: on (.entnum != 0)
55 * 4: on (.origin == '0 0 0')
56 * 5: on (.debug != 0), server only
59 bool autocvar_debugdraw;
63 string autocvar_debugdraw_filter, autocvar_debugdraw_filterout;
65 vector project_3d_to_2d(vector vec);
68 if (!autocvar_debugdraw) return;
69 static int debugdraw_frame;
72 FOREACH_ENTITY(true, {
73 if (it.debugdraw_last == debugdraw_frame) continue;
75 FOREACH_ENTITY_RADIUS(it.origin, 100, it.debugdraw_last != debugdraw_frame, {
76 it.debugdraw_last = debugdraw_frame;
77 vector rgb = (it.debug) ? '0 0 1' : '1 0 0';
78 if (autocvar_debugdraw_filterout != "" && strhasword(autocvar_debugdraw_filterout, it.classname)) continue;
79 if (autocvar_debugdraw_filter != "" && !strhasword(autocvar_debugdraw_filter, it.classname)) continue;
80 if (autocvar_debugdraw == 3)
82 if (!it.entnum) continue;
84 if (autocvar_debugdraw == 4)
86 if (it.origin) continue;
88 if (autocvar_debugdraw == 5)
90 if (!it.debug) continue;
92 else if (autocvar_debugdraw > 5)
96 // if (it.modelindex) break;
97 // if (it.absmin) break;
98 // if (it.absmax) break;
99 // if (it.entnum) break;
100 // if (it.drawmask) break;
101 // if (it.predraw) break;
102 // if (it.move_movetype) break;
104 // if (it.origin) break;
105 // if (it.oldorigin) break;
106 // if (it.velocity) break;
107 // if (it.angles) break;
108 // if (it.avelocity) break;
109 // if (it.classname) break;
110 // if (it.model) break;
111 // if (it.frame) break;
112 // if (it.skin) break;
113 // if (it.effects) break;
114 // if (it.mins) break;
115 // if (it.maxs) break;
116 // if (it.size) break;
117 // if (it.touch) break;
118 // if (it.use) break;
119 // if (it.think) break;
120 // if (it.blocked) break;
121 // if (it.nextthink) break;
122 // if (it.chain) break;
123 // if (it.netname) break;
124 // if (it.enemy) break;
125 // if (it.flags) break;
126 // if (it.colormap) break;
127 // if (it.owner) break;
132 else if (is_pure(it))
134 if (autocvar_debugdraw < 2) continue;
137 vector o = it.origin;
139 o += it.tag_entity.origin;
140 vector pos = project_3d_to_2d(o);
141 if (pos.z < 0) continue;
144 drawcolorcodedstring2_builtin(pos,
145 sprintf("%d: '%s'@%s", (it.debug ? it.sv_entnum : etof(it)),
146 it.classname, it.sourceLoc),
147 sz * '1 1 0', rgb, 0.5, DRAWFLAG_NORMAL);
155 COMMON_COMMAND(debugdraw_sv, "Dump all server entities")
159 case CMD_REQUEST_COMMAND:
161 if (!autocvar_debugdraw) return;
164 for (entity e = NULL; (e = findfloat(e, debug, 0)) && rem > 0; )
166 if (autocvar_debugdraw < 2 && is_pure(e)) continue;
167 debug_send(e, caller, 0);
171 LOG_INFOF("%d server entities sent", n - rem);
176 case CMD_REQUEST_USAGE:
178 LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " debugdraw_sv");
186 GENERIC_COMMAND(bufstr_get, "Examine a string buffer object")
190 case CMD_REQUEST_COMMAND:
192 int bufhandle = stof(argv(1));
193 int string_index = stof(argv(2));
194 string s = bufstr_get(bufhandle, string_index);
200 case CMD_REQUEST_USAGE:
202 LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " bufstr_get bufhandle string_index");
208 GENERIC_COMMAND(version, "Print the current version")
212 case CMD_REQUEST_COMMAND:
218 case CMD_REQUEST_USAGE:
220 LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " version");
227 void(float bufhandle, string pattern, string antipattern) buf_cvarlist = #517;
229 GENERIC_COMMAND(cvar_localchanges, "Print locally changed cvars")
233 case CMD_REQUEST_COMMAND:
236 int h = buf_create();
237 buf_cvarlist(h, "", "_"); // exclude all _ cvars as they are temporary
238 int n = buf_getsize(h);
239 for (int i = 0; i < n; ++i) {
240 string k = bufstr_get(h, i);
241 string v = cvar_string(k);
242 string d = cvar_defstring(k);
245 s = strcat(s, k, " \"", v, "\" // \"", d, "\"\n");
252 case CMD_REQUEST_USAGE:
254 LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " cvar_localchanges");
260 #if ENABLE_DEBUGTRACE
261 REGISTER_STAT(TRACE_ENT, int)
263 bool autocvar_debugtrace;
265 REGISTER_MUTATOR(trace, autocvar_debugtrace);
267 .bool debug_trace_button;
269 MUTATOR_HOOKFUNCTION(trace, SV_StartFrame)
271 FOREACH_CLIENT(true, {
273 bool btn = PHYS_INPUT_BUTTON_HOOK(it);
274 if (btn == it.debug_trace_button) skip = true;
275 it.debug_trace_button = btn;
276 if (!btn || skip) continue;
277 FOREACH_ENTITY(true, {
278 it.solid_prev = it.solid;
279 it.solid = SOLID_BBOX;
281 vector forward = '0 0 0'; vector right = '0 0 0'; vector up = '0 0 0';
282 MAKEVECTORS(makevectors, it.v_angle, forward, right, up);
283 vector pos = it.origin + it.view_ofs;
284 traceline(pos, pos + forward * max_shot_distance, MOVE_NORMAL, it);
285 FOREACH_ENTITY(true, {
286 it.solid = it.solid_prev;
289 entity e = trace_ent;
291 STAT(TRACE_ENT, it) = i;
293 setorigin(e, e.origin + '0 0 100');
294 stuffcmd(it, sprintf("prvm_edict server %d\n", i));
300 void Trace_draw2d(entity this)
302 int e = STAT(TRACE_ENT);
304 vector pos = '0 0 0';
305 pos.y += vid_conheight / 2;
306 drawstring(pos, sprintf("prvm_edict server %d", e), '10 10 0', '1 1 1', 1, DRAWFLAG_NORMAL);
309 STATIC_INIT(TRACE_ENT)
311 entity e = TRACE_ENT = new_pure(TRACE_ENT);
312 e.draw2d = Trace_draw2d;
313 IL_PUSH(g_drawables_2d, e);
318 GENERIC_COMMAND(find, "Search through entities for matching classname")
322 case CMD_REQUEST_COMMAND:
325 FOREACH_ENTITY_CLASS_ORDERED(argv(1), true,
327 LOG_INFOF("%i (%s)", it, it.classname);
331 LOG_INFOF("Found %d entities", entcnt);
337 LOG_INFO("Incorrect parameters for ^2find^7");
339 case CMD_REQUEST_USAGE:
341 LOG_INFO("Usage:^3 " GetProgramCommandPrefix() " find classname");
342 LOG_INFO(" Where 'classname' is the classname to search for.");
348 GENERIC_COMMAND(findat, "Search through entities for matching origin")
352 case CMD_REQUEST_COMMAND:
354 vector match = stov(argv(1));
355 FOREACH_ENTITY_ORDERED(it.origin == match, LOG_INFOF("%i (%s)", it, it.classname));
360 LOG_INFO("Incorrect parameters for ^2findat^7");
361 case CMD_REQUEST_USAGE:
363 LOG_INFO("Usage:^3 " GetProgramCommandPrefix() " findat \"0 0 0\"");