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;
38 o += this.tag_entity.origin;
39 WriteCoord(channel, o.x); WriteCoord(channel, o.y); WriteCoord(channel, o.z);
40 WriteString(channel, this.classname);
41 WriteString(channel, this.sourceLoc);
51 * 3: on (.entnum != 0)
52 * 4: on (.origin == '0 0 0')
53 * 5: on (.debug != 0), server only
56 bool autocvar_debugdraw;
60 string autocvar_debugdraw_filter, autocvar_debugdraw_filterout;
62 vector project_3d_to_2d(vector vec);
65 if (!autocvar_debugdraw) return;
66 static int debugdraw_frame;
69 FOREACH_ENTITY(true, {
70 if (it.debugdraw_last == debugdraw_frame) continue;
72 FOREACH_ENTITY_RADIUS(it.origin, 100, it.debugdraw_last != debugdraw_frame, {
73 it.debugdraw_last = debugdraw_frame;
74 vector rgb = (it.debug) ? '0 0 1' : '1 0 0';
75 if (autocvar_debugdraw_filterout != "" && strhasword(autocvar_debugdraw_filterout, it.classname)) continue;
76 if (autocvar_debugdraw_filter != "" && !strhasword(autocvar_debugdraw_filter, it.classname)) continue;
77 if (autocvar_debugdraw == 3)
79 if (!it.entnum) continue;
81 if (autocvar_debugdraw == 4)
83 if (it.origin) continue;
85 if (autocvar_debugdraw == 5)
87 if (!it.debug) continue;
89 else if (autocvar_debugdraw > 5)
93 // if (it.modelindex) break;
94 // if (it.absmin) break;
95 // if (it.absmax) break;
96 // if (it.entnum) break;
97 // if (it.drawmask) break;
98 // if (it.predraw) break;
99 // if (it.movetype) break;
101 // if (it.origin) break;
102 // if (it.oldorigin) break;
103 // if (it.velocity) break;
104 // if (it.angles) break;
105 // if (it.avelocity) break;
106 // if (it.classname) break;
107 // if (it.model) break;
108 // if (it.frame) break;
109 // if (it.skin) break;
110 // if (it.effects) break;
111 // if (it.mins) break;
112 // if (it.maxs) break;
113 // if (it.size) break;
114 // if (it.touch) break;
115 // if (it.use) break;
116 // if (it.think) break;
117 // if (it.blocked) break;
118 // if (it.nextthink) break;
119 // if (it.chain) break;
120 // if (it.netname) break;
121 // if (it.enemy) break;
122 // if (it.flags) break;
123 // if (it.colormap) break;
124 // if (it.owner) break;
129 else if (is_pure(it))
131 if (autocvar_debugdraw < 2) continue;
134 vector o = it.origin;
136 o += it.tag_entity.origin;
137 vector pos = project_3d_to_2d(o);
138 if (pos.z < 0) continue;
141 drawcolorcodedstring2(pos,
142 sprintf("%d: '%s'@%s", (it.debug ? it.sv_entnum : etof(it)),
143 it.classname, it.sourceLoc),
144 sz * '1 1 0', rgb, 0.5, DRAWFLAG_NORMAL);
152 COMMON_COMMAND(debugdraw_sv, "Dump all server entities")
156 case CMD_REQUEST_COMMAND:
158 if (!autocvar_debugdraw) return;
161 for (entity e = NULL; (e = findfloat(e, debug, 0)) && rem > 0; )
163 if (autocvar_debugdraw < 2 && is_pure(e)) continue;
164 debug_send(e, caller, 0);
168 LOG_INFOF("%d server entities sent\n", n - rem);
173 case CMD_REQUEST_USAGE:
175 LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " debugdraw_sv"));
182 GENERIC_COMMAND(bufstr_get, "Examine a string buffer object")
186 case CMD_REQUEST_COMMAND:
188 int bufhandle = stof(argv(1));
189 int string_index = stof(argv(2));
190 string s = bufstr_get(bufhandle, string_index);
191 LOG_INFOF("%s\n", s);
196 case CMD_REQUEST_USAGE:
198 LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " bufstr_get bufhandle string_index"));
204 GENERIC_COMMAND(version, "Print the current version")
208 case CMD_REQUEST_COMMAND:
210 LOG_INFO(WATERMARK "\n");
214 case CMD_REQUEST_USAGE:
216 LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " version"));
222 REGISTER_STAT(TRACE_ENT, int)
224 bool autocvar_debugtrace;
226 REGISTER_MUTATOR(trace, autocvar_debugtrace);
228 .bool debug_trace_button;
230 MUTATOR_HOOKFUNCTION(trace, SV_StartFrame)
232 FOREACH_CLIENT(true, {
234 bool btn = PHYS_INPUT_BUTTON_HOOK(it);
235 if (btn == it.debug_trace_button) skip = true;
236 it.debug_trace_button = btn;
237 if (!btn || skip) continue;
238 FOREACH_ENTITY(true, {
239 it.solid_prev = it.solid;
240 it.solid = SOLID_BBOX;
242 vector forward; vector right; vector up;
243 MAKEVECTORS(makevectors, it.v_angle, forward, right, up);
244 vector pos = it.origin + it.view_ofs;
245 traceline(pos, pos + forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, it);
246 FOREACH_ENTITY(true, {
247 it.solid = it.solid_prev;
250 entity e = trace_ent;
252 STAT(TRACE_ENT, it) = i;
254 setorigin(e, e.origin + '0 0 100');
255 stuffcmd(it, sprintf("prvm_edict server %d\n", i));
261 void Trace_draw2d(entity this)
263 int e = STAT(TRACE_ENT);
265 vector pos = '0 0 0';
266 pos.y += vid_conheight / 2;
267 drawstring(pos, sprintf("prvm_edict server %d", e), '10 10 0', '1 1 1', 1, DRAWFLAG_NORMAL);
270 STATIC_INIT(TRACE_ENT)
272 entity e = TRACE_ENT = new_pure(TRACE_ENT);
273 e.draw2d = Trace_draw2d;
277 GENERIC_COMMAND(find, "Search through entities for matching classname")
281 case CMD_REQUEST_COMMAND:
283 FOREACH_ENTITY_CLASS_ORDERED(argv(1), true, LOG_INFOF("%i (%s)\n", it, it.classname));
289 LOG_INFO("Incorrect parameters for ^2find^7\n");
291 case CMD_REQUEST_USAGE:
293 LOG_INFO("\nUsage:^3 " GetProgramCommandPrefix() " find classname\n");
294 LOG_INFO(" Where 'classname' is the classname to search for.\n");
300 GENERIC_COMMAND(findat, "Search through entities for matching origin")
304 case CMD_REQUEST_COMMAND:
306 vector match = stov(argv(1));
307 FOREACH_ENTITY_ORDERED(it.origin == match, LOG_INFOF("%i (%s)\n", it, it.classname));
312 LOG_INFO("Incorrect parameters for ^2findat^7\n");
313 case CMD_REQUEST_USAGE:
315 LOG_INFO("\nUsage:^3 " GetProgramCommandPrefix() " findat \"0 0 0\"\n");