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_x = ReadCoord();
20 this.origin_y = ReadCoord();
21 this.origin_z = ReadCoord();
22 setorigin(this, this.origin);
23 this.debug = true; // identify server entities by this
24 this.classname = strzone(ReadString());
25 this.sourceLoc = strzone(ReadString());
31 bool debug_send(entity this, entity to, int sf)
33 int channel = MSG_ONE;
35 WriteHeader(channel, net_debug);
36 WriteShort(channel, etof(this));
37 WriteByte(channel, is_pure(this));
38 vector o = this.origin;
39 if (o == '0 0 0') // brushes
40 o = (this.absmin + this.absmax) / 2;
42 o += this.tag_entity.origin;
43 WriteCoord(channel, o.x); WriteCoord(channel, o.y); WriteCoord(channel, o.z);
44 WriteString(channel, this.classname);
45 WriteString(channel, this.sourceLoc);
55 * 3: on (.entnum != 0)
56 * 4: on (.origin == '0 0 0')
57 * 5: on (.debug != 0), server only
60 bool autocvar_debugdraw;
64 string autocvar_debugdraw_filter, autocvar_debugdraw_filterout;
66 vector project_3d_to_2d(vector vec);
69 if (!autocvar_debugdraw) return;
70 static int debugdraw_frame;
73 FOREACH_ENTITY(true, {
74 if (it.debugdraw_last == debugdraw_frame) continue;
76 FOREACH_ENTITY_RADIUS(it.origin, 100, it.debugdraw_last != debugdraw_frame, {
77 it.debugdraw_last = debugdraw_frame;
78 vector rgb = (it.debug) ? '0 0 1' : '1 0 0';
79 if (autocvar_debugdraw_filterout != "" && strhasword(autocvar_debugdraw_filterout, it.classname)) continue;
80 if (autocvar_debugdraw_filter != "" && !strhasword(autocvar_debugdraw_filter, it.classname)) continue;
81 if (autocvar_debugdraw == 3)
83 if (!it.entnum) continue;
85 if (autocvar_debugdraw == 4)
87 if (it.origin) continue;
89 if (autocvar_debugdraw == 5)
91 if (!it.debug) continue;
93 else if (autocvar_debugdraw > 5)
97 // if (it.modelindex) break;
98 // if (it.absmin) break;
99 // if (it.absmax) break;
100 // if (it.entnum) break;
101 // if (it.drawmask) break;
102 // if (it.predraw) break;
103 // if (it.move_movetype) break;
105 // if (it.origin) break;
106 // if (it.oldorigin) break;
107 // if (it.velocity) break;
108 // if (it.angles) break;
109 // if (it.avelocity) break;
110 // if (it.classname) break;
111 // if (it.model) break;
112 // if (it.frame) break;
113 // if (it.skin) break;
114 // if (it.effects) break;
115 // if (it.mins) break;
116 // if (it.maxs) break;
117 // if (it.size) break;
118 // if (it.touch) break;
119 // if (it.use) break;
120 // if (it.think) break;
121 // if (it.blocked) break;
122 // if (it.nextthink) break;
123 // if (it.chain) break;
124 // if (it.netname) break;
125 // if (it.enemy) break;
126 // if (it.flags) break;
127 // if (it.colormap) break;
128 // if (it.owner) break;
133 else if (is_pure(it))
135 if (autocvar_debugdraw < 2) continue;
138 vector o = it.origin;
140 o += it.tag_entity.origin;
141 vector pos = project_3d_to_2d(o);
142 if (pos.z < 0) continue;
145 drawcolorcodedstring2_builtin(pos,
146 sprintf("%d: '%s'@%s", (it.debug ? it.sv_entnum : etof(it)),
147 it.classname, it.sourceLoc),
148 sz * '1 1 0', rgb, 0.5, DRAWFLAG_NORMAL);
156 COMMON_COMMAND(debugdraw_sv, "Dump all server entities")
160 case CMD_REQUEST_COMMAND:
162 if (!autocvar_debugdraw) return;
165 for (entity e = NULL; (e = findfloat(e, debug, 0)) && rem > 0; )
167 if (autocvar_debugdraw < 2 && is_pure(e)) continue;
168 debug_send(e, caller, 0);
172 LOG_INFOF("%d server entities sent\n", n - rem);
177 case CMD_REQUEST_USAGE:
179 LOG_INFO(strcat("\nUsage:^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);
195 LOG_INFOF("%s\n", s);
200 case CMD_REQUEST_USAGE:
202 LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " bufstr_get bufhandle string_index"));
208 GENERIC_COMMAND(version, "Print the current version")
212 case CMD_REQUEST_COMMAND:
214 LOG_INFO(WATERMARK "\n");
218 case CMD_REQUEST_USAGE:
220 LOG_INFO(strcat("\nUsage:^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(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " cvar_localchanges"));
260 REGISTER_STAT(TRACE_ENT, int)
262 bool autocvar_debugtrace;
264 REGISTER_MUTATOR(trace, autocvar_debugtrace);
266 .bool debug_trace_button;
268 MUTATOR_HOOKFUNCTION(trace, SV_StartFrame)
270 FOREACH_CLIENT(true, {
272 bool btn = PHYS_INPUT_BUTTON_HOOK(it);
273 if (btn == it.debug_trace_button) skip = true;
274 it.debug_trace_button = btn;
275 if (!btn || skip) continue;
276 FOREACH_ENTITY(true, {
277 it.solid_prev = it.solid;
278 it.solid = SOLID_BBOX;
280 vector forward = '0 0 0'; vector right = '0 0 0'; vector up = '0 0 0';
281 MAKEVECTORS(makevectors, it.v_angle, forward, right, up);
282 vector pos = it.origin + it.view_ofs;
283 traceline(pos, pos + forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, it);
284 FOREACH_ENTITY(true, {
285 it.solid = it.solid_prev;
288 entity e = trace_ent;
290 STAT(TRACE_ENT, it) = i;
292 setorigin(e, e.origin + '0 0 100');
293 stuffcmd(it, sprintf("prvm_edict server %d\n", i));
299 void Trace_draw2d(entity this)
301 int e = STAT(TRACE_ENT);
303 vector pos = '0 0 0';
304 pos.y += vid_conheight / 2;
305 drawstring(pos, sprintf("prvm_edict server %d", e), '10 10 0', '1 1 1', 1, DRAWFLAG_NORMAL);
308 STATIC_INIT(TRACE_ENT)
310 entity e = TRACE_ENT = new_pure(TRACE_ENT);
311 e.draw2d = Trace_draw2d;
312 IL_PUSH(g_drawables_2d, e);
316 GENERIC_COMMAND(find, "Search through entities for matching classname")
320 case CMD_REQUEST_COMMAND:
322 FOREACH_ENTITY_CLASS_ORDERED(argv(1), true, LOG_INFOF("%i (%s)\n", it, it.classname));
328 LOG_INFO("Incorrect parameters for ^2find^7\n");
330 case CMD_REQUEST_USAGE:
332 LOG_INFO("\nUsage:^3 " GetProgramCommandPrefix() " find classname\n");
333 LOG_INFO(" Where 'classname' is the classname to search for.\n");
339 GENERIC_COMMAND(findat, "Search through entities for matching origin")
343 case CMD_REQUEST_COMMAND:
345 vector match = stov(argv(1));
346 FOREACH_ENTITY_ORDERED(it.origin == match, LOG_INFOF("%i (%s)\n", it, it.classname));
351 LOG_INFO("Incorrect parameters for ^2findat^7\n");
352 case CMD_REQUEST_USAGE:
354 LOG_INFO("\nUsage:^3 " GetProgramCommandPrefix() " findat \"0 0 0\"\n");