6 REGISTER_NET_TEMP(net_debug)
10 NET_HANDLE(net_debug, bool isNew)
12 Net_Accept(net_debug);
13 this.sv_entnum = ReadShort();
14 if (ReadByte()) make_pure(this);
15 this.origin_x = ReadCoord();
16 this.origin_y = ReadCoord();
17 this.origin_z = ReadCoord();
18 setorigin(this, this.origin);
19 this.debug = true; // identify server entities by this
20 this.classname = strzone(ReadString());
21 this.sourceLoc = strzone(ReadString());
27 bool debug_send(entity this, entity to, int sf)
29 int channel = MSG_ONE;
31 WriteHeader(channel, net_debug);
32 WriteShort(channel, etof(this));
33 WriteByte(channel, is_pure(this));
34 vector o = this.origin;
35 if (o == '0 0 0') // brushes
36 o = (this.absmin + this.absmax) / 2;
37 WriteCoord(channel, o.x); WriteCoord(channel, o.y); WriteCoord(channel, o.z);
38 WriteString(channel, this.classname);
39 WriteString(channel, this.sourceLoc);
49 * 3: on (.entnum != 0)
50 * 4: on (.origin == '0 0 0')
51 * 5: on (.debug != 0), server only
54 bool autocvar_debugdraw;
58 string autocvar_debugdraw_filter, autocvar_debugdraw_filterout;
60 vector project_3d_to_2d(vector vec);
63 if (!autocvar_debugdraw) return;
64 static int debugdraw_frame;
67 FOREACH_ENTITY(true, LAMBDA(
68 if (it.debugdraw_last == debugdraw_frame) continue;
70 for (entity e = findradius(it.origin, 100); e; e = e.chain)
72 if (e.debugdraw_last == debugdraw_frame) continue;
73 e.debugdraw_last = debugdraw_frame;
74 vector rgb = (e.debug) ? '0 0 1' : '1 0 0';
75 if (autocvar_debugdraw_filterout != "" && strhasword(autocvar_debugdraw_filterout, e.classname)) continue;
76 if (autocvar_debugdraw_filter != "" && !strhasword(autocvar_debugdraw_filter, e.classname)) continue;
77 if (autocvar_debugdraw == 3)
79 if (!e.entnum) continue;
81 if (autocvar_debugdraw == 4)
83 if (e.origin) continue;
85 if (autocvar_debugdraw == 5)
87 if (!e.debug) continue;
89 else if (autocvar_debugdraw > 5)
93 // if (e.modelindex) break;
94 // if (e.absmin) break;
95 // if (e.absmax) break;
96 // if (e.entnum) break;
97 // if (e.drawmask) break;
98 // if (e.predraw) break;
99 // if (e.movetype) break;
101 // if (e.origin) break;
102 // if (e.oldorigin) break;
103 // if (e.velocity) break;
104 // if (e.angles) break;
105 // if (e.avelocity) break;
106 // if (e.classname) break;
107 // if (e.model) break;
108 // if (e.frame) break;
109 // if (e.skin) break;
110 // if (e.effects) break;
111 // if (e.mins) break;
112 // if (e.maxs) break;
113 // if (e.size) break;
114 // if (e.touch) break;
116 // if (e.think) break;
117 // if (e.blocked) break;
118 // if (e.nextthink) break;
119 // if (e.chain) break;
120 // if (e.netname) break;
121 // if (e.enemy) break;
122 // if (e.flags) break;
123 // if (e.colormap) break;
124 // if (e.owner) break;
131 if (autocvar_debugdraw < 2) continue;
134 vector pos = project_3d_to_2d(e.origin);
135 if (pos.z < 0) continue;
138 drawcolorcodedstring2(pos,
139 sprintf("%d: '%s'@%s", (e.debug ? e.sv_entnum : etof(e)),
140 e.classname, e.sourceLoc),
141 sz * '1 1 0', rgb, 0.5, DRAWFLAG_NORMAL);
149 COMMON_COMMAND(debugdraw_sv, "Dump all server entities")
153 case CMD_REQUEST_COMMAND:
155 if (!autocvar_debugdraw) return;
158 for (entity e = NULL; (e = findfloat(e, debug, 0)) && rem > 0; )
160 if (autocvar_debugdraw < 2 && is_pure(e)) continue;
161 debug_send(e, nextent(NULL), 0);
165 LOG_INFOF("%d server entities sent\n", n - rem);
170 case CMD_REQUEST_USAGE:
172 LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " debugdraw_sv"));
179 GENERIC_COMMAND(bufstr_get, "Examine a string buffer object")
183 case CMD_REQUEST_COMMAND:
185 int bufhandle = stof(argv(1));
186 int string_index = stof(argv(2));
187 string s = bufstr_get(bufhandle, string_index);
188 LOG_INFOF("%s\n", s);
193 case CMD_REQUEST_USAGE:
195 LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " bufstr_get bufhandle string_index"));
201 GENERIC_COMMAND(version, "Print the current version")
205 case CMD_REQUEST_COMMAND:
207 LOG_INFO(WATERMARK "\n");
211 case CMD_REQUEST_USAGE:
213 LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " version"));
219 REGISTER_STAT(TRACE_ENT, int)
221 bool autocvar_debugtrace;
223 REGISTER_MUTATOR(trace, autocvar_debugtrace);
225 .bool debug_trace_button;
227 MUTATOR_HOOKFUNCTION(trace, SV_StartFrame)
229 FOREACH_CLIENT(true, {
231 bool btn = PHYS_INPUT_BUTTON_HOOK(it);
232 if (btn == it.debug_trace_button) skip = true;
233 it.debug_trace_button = btn;
234 if (!btn || skip) continue;
235 FOREACH_ENTITY(true, {
236 it.solid_prev = it.solid;
237 it.solid = SOLID_BBOX;
239 vector forward; vector right; vector up;
240 MAKEVECTORS(makevectors, it.v_angle, forward, right, up);
241 vector pos = it.origin + it.view_ofs;
242 traceline(pos, pos + forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, it);
243 FOREACH_ENTITY(true, {
244 it.solid = it.solid_prev;
247 entity e = trace_ent;
249 STAT(TRACE_ENT, it) = i;
251 setorigin(e, e.origin + '0 0 100');
252 stuffcmd(it, sprintf("prvm_edict server %d\n", i));
258 void Trace_draw2d(entity this)
260 int e = STAT(TRACE_ENT);
262 vector pos = '0 0 0';
263 pos.y += vid_conheight / 2;
264 drawstring(pos, sprintf("prvm_edict server %d", e), '10 10 0', '1 1 1', 1, DRAWFLAG_NORMAL);
267 STATIC_INIT(TRACE_ENT)
269 entity e = TRACE_ENT = new_pure(TRACE_ENT);
270 e.draw2d = Trace_draw2d;