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.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(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"));
226 REGISTER_STAT(TRACE_ENT, int)
228 bool autocvar_debugtrace;
230 REGISTER_MUTATOR(trace, autocvar_debugtrace);
232 .bool debug_trace_button;
234 MUTATOR_HOOKFUNCTION(trace, SV_StartFrame)
236 FOREACH_CLIENT(true, {
238 bool btn = PHYS_INPUT_BUTTON_HOOK(it);
239 if (btn == it.debug_trace_button) skip = true;
240 it.debug_trace_button = btn;
241 if (!btn || skip) continue;
242 FOREACH_ENTITY(true, {
243 it.solid_prev = it.solid;
244 it.solid = SOLID_BBOX;
246 vector forward = '0 0 0'; vector right = '0 0 0'; vector up = '0 0 0';
247 MAKEVECTORS(makevectors, it.v_angle, forward, right, up);
248 vector pos = it.origin + it.view_ofs;
249 traceline(pos, pos + forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, it);
250 FOREACH_ENTITY(true, {
251 it.solid = it.solid_prev;
254 entity e = trace_ent;
256 STAT(TRACE_ENT, it) = i;
258 setorigin(e, e.origin + '0 0 100');
259 stuffcmd(it, sprintf("prvm_edict server %d\n", i));
265 void Trace_draw2d(entity this)
267 int e = STAT(TRACE_ENT);
269 vector pos = '0 0 0';
270 pos.y += vid_conheight / 2;
271 drawstring(pos, sprintf("prvm_edict server %d", e), '10 10 0', '1 1 1', 1, DRAWFLAG_NORMAL);
274 STATIC_INIT(TRACE_ENT)
276 entity e = TRACE_ENT = new_pure(TRACE_ENT);
277 e.draw2d = Trace_draw2d;
281 GENERIC_COMMAND(find, "Search through entities for matching classname")
285 case CMD_REQUEST_COMMAND:
287 FOREACH_ENTITY_CLASS_ORDERED(argv(1), true, LOG_INFOF("%i (%s)\n", it, it.classname));
293 LOG_INFO("Incorrect parameters for ^2find^7\n");
295 case CMD_REQUEST_USAGE:
297 LOG_INFO("\nUsage:^3 " GetProgramCommandPrefix() " find classname\n");
298 LOG_INFO(" Where 'classname' is the classname to search for.\n");
304 GENERIC_COMMAND(findat, "Search through entities for matching origin")
308 case CMD_REQUEST_COMMAND:
310 vector match = stov(argv(1));
311 FOREACH_ENTITY_ORDERED(it.origin == match, LOG_INFOF("%i (%s)\n", it, it.classname));
316 LOG_INFO("Incorrect parameters for ^2findat^7\n");
317 case CMD_REQUEST_USAGE:
319 LOG_INFO("\nUsage:^3 " GetProgramCommandPrefix() " findat \"0 0 0\"\n");