Debian Codegraph @

prboom2/src/dsda/console.c

raw
1 //
2 // Copyright(C) 2020 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Console
16 //
17
18 #include "d_deh.h"
19 #include "doomstat.h"
20 #include "g_game.h"
21 #include "hu_lib.h"
22 #include "hu_stuff.h"
23 #include "i_main.h"
24 #include "i_system.h"
25 #include "lprintf.h"
26 #include "m_cheat.h"
27 #include "m_file.h"
28 #include "m_menu.h"
29 #include "m_misc.h"
30 #include "p_inter.h"
31 #include "p_map.h"
32 #include "p_maputl.h"
33 #include "p_mobj.h"
34 #include "p_setup.h"
35 #include "p_spec.h"
36 #include "p_tick.h"
37 #include "p_user.h"
38 #include "s_sound.h"
39 #include "smooth.h"
40 #include "v_video.h"
41
42 #include "dsda.h"
43 #include "dsda/build.h"
44 #include "dsda/brute_force.h"
45 #include "dsda/configuration.h"
46 #include "dsda/demo.h"
47 #include "dsda/exhud.h"
48 #include "dsda/features.h"
49 #include "dsda/font.h"
50 #include "dsda/global.h"
51 #include "dsda/map_format.h"
52 #include "dsda/messenger.h"
53 #include "dsda/mobjinfo.h"
54 #include "dsda/playback.h"
55 #include "dsda/settings.h"
56 #include "dsda/stretch.h"
57 #include "dsda/tracker.h"
58 #include "dsda/utility.h"
59
60 #include "console.h"
61
62 #define target_player players[consoleplayer]
63
64 #define CONSOLE_TEXT_FLAGS (VPT_ALIGN_TOP | VPT_EX_TEXT)
65 #define CONSOLE_ENTRY_SIZE 64
66
67 #define CF_NEVER 0x00
68 #define CF_DEMO 0x01
69 #define CF_STRICT 0x02
70 #define CF_ALWAYS (CF_DEMO|CF_STRICT)
71
72 typedef struct console_entry_s {
73 char text[CONSOLE_ENTRY_SIZE];
74 struct console_entry_s* prev;
75 struct console_entry_s* next;
76 } console_entry_t;
77
78 static console_entry_t* console_history_head;
79 static console_entry_t* console_entry;
80 static int console_entry_index;
81 static char console_message[CONSOLE_ENTRY_SIZE + 2] = { ' ', ' ' };
82 static char* console_message_entry = console_message + 2;
83 static hu_textline_t hu_console_prompt;
84 static hu_textline_t hu_console_message;
85
86 static char** dsda_console_script_lines[CONSOLE_SCRIPT_COUNT];
87
88 static int console_height;
89
90 int dsda_ConsoleHeight(void) {
91 return console_height;
92 }
93
94 static void dsda_DrawConsole(void) {
95 console_height = V_FillHeightVPT(0, 0, 16, 0, CONSOLE_TEXT_FLAGS);
96 HUlib_drawTextLine(&hu_console_prompt, false);
97 HUlib_drawTextLine(&hu_console_message, false);
98 }
99
100 menu_t dsda_ConsoleDef = {
101 0,
102 NULL,
103 NULL,
104 dsda_DrawConsole,
105 0, 0,
106 0, MENUF_TEXTINPUT
107 };
108
109 static dboolean dsda_ExecuteConsole(const char* command_line, dboolean noise);
110
111 static void dsda_UpdateConsoleDisplay(void) {
112 const char* s;
113 int i;
114
115 s = console_entry->text;
116 HUlib_clearTextLine(&hu_console_prompt);
117 HUlib_addCharToTextLine(&hu_console_prompt, '$');
118 HUlib_addCharToTextLine(&hu_console_prompt, ' ');
119 for (i = 0; *s && i < console_entry_index; ++i)
120 HUlib_addCharToTextLine(&hu_console_prompt, *(s++));
121 HUlib_addCharToTextLine(&hu_console_prompt, '_');
122 while (*s) HUlib_addCharToTextLine(&hu_console_prompt, *(s++));
123
124 s = console_message;
125 HUlib_clearTextLine(&hu_console_message);
126 while (*s) HUlib_addCharToTextLine(&hu_console_message, *(s++));
127 }
128
129 static void dsda_ResetConsoleEntry(void) {
130 console_entry_index = strlen(console_entry->text);
131 dsda_UpdateConsoleDisplay();
132 }
133
134 dboolean dsda_OpenConsole(void) {
135 static dboolean firsttime = true;
136
137 if (gamestate != GS_LEVEL)
138 return false;
139
140 if (firsttime) {
141 firsttime = false;
142
143 HUlib_initTextLine(
144 &hu_console_prompt,
145 0,
146 8,
147 &exhud_font,
148 CR_GRAY,
149 CONSOLE_TEXT_FLAGS
150 );
151
152 HUlib_initTextLine(
153 &hu_console_message,
154 0,
155 0,
156 &exhud_font,
157 CR_GRAY,
158 CONSOLE_TEXT_FLAGS
159 );
160
161 console_history_head = Z_Calloc(sizeof(console_entry_t), 1);
162 console_entry = console_history_head;
163 }
164
165 dsda_TrackFeature(uf_console);
166
167 M_StartControlPanel();
168 M_SetupNextMenu(&dsda_ConsoleDef);
169 dsda_ResetConsoleEntry();
170
171 return true;
172 }
173
174 static dboolean console_LevelExit(const char* command, const char* args) {
175 void G_ExitLevel(int position);
176
177 int position = 0;
178
179 if (hexen)
180 return false;
181
182 sscanf(args, "%d", &position);
183
184 G_ExitLevel(position);
185
186 return true;
187 }
188
189 static dboolean console_LevelSecretExit(const char* command, const char* args) {
190 void G_SecretExitLevel(int position);
191
192 int position = 0;
193
194 if (hexen)
195 return false;
196
197 sscanf(args, "%d", &position);
198
199 G_SecretExitLevel(position);
200
201 return true;
202 }
203
204 static dboolean console_ActivateLine(mobj_t* mobj, int id, dboolean bossaction) {
205 if (!mobj || id < 0 || id >= numlines)
206 return false;
207
208 P_MapStart();
209 P_UseSpecialLine(mobj, &lines[id], 0, bossaction);
210 map_format.cross_special_line(&lines[id], 0, mobj, bossaction);
211 map_format.shoot_special_line(mobj, &lines[id]);
212 P_MapEnd();
213
214 return true;
215 }
216
217 static dboolean console_PlayerActivateLine(const char* command, const char* args) {
218 int id;
219
220 if (sscanf(args, "%i", &id) != 1)
221 return false;
222
223 return console_ActivateLine(target_player.mo, id, false);
224 }
225
226 static dboolean console_PlayerSetHealth(const char* command, const char* args) {
227 int health;
228
229 if (sscanf(args, "%i", &health)) {
230 target_player.mo->health = health;
231 target_player.health = health;
232
233 return true;
234 }
235
236 return false;
237 }
238
239 static dboolean console_PlayerKill(const char* command, const char* args) {
240 P_DamageMobj(target_player.mo, NULL, NULL, 10000);
241
242 return true;
243 }
244
245 static dboolean console_PlayerSetArmor(const char* command, const char* args) {
246 int arg_count;
247 int armorpoints, armortype;
248
249 arg_count = sscanf(args, "%i %i", &armorpoints, &armortype);
250
251 if (arg_count != 2 || (armortype != 1 && armortype != 2))
252 armortype = target_player.armortype;
253
254 if (arg_count) {
255 target_player.armorpoints[ARMOR_ARMOR] = armorpoints;
256
257 if (armortype == 0) armortype = 1;
258 target_player.armortype = armortype;
259
260 return true;
261 }
262
263 return false;
264 }
265
266 static dboolean console_PlayerGiveWeapon(const char* command, const char* args) {
267 dboolean P_GiveWeapon(player_t *player, weapontype_t weapon, dboolean dropped);
268 void TryPickupWeapon(player_t * player, pclass_t weaponClass,
269 weapontype_t weaponType, mobj_t * weapon,
270 const char *message);
271
272 int weapon;
273
274 if (sscanf(args, "%i", &weapon)) {
275 if (hexen) {
276 mobj_t mo;
277
278 if (weapon < 0 || weapon >= HEXEN_NUMWEAPONS)
279 return false;
280
281 memset(&mo, 0, sizeof(mo));
282
283 mo.intflags |= MIF_FAKE;
284
285 TryPickupWeapon(&target_player, target_player.pclass, weapon, &mo, "WEAPON");
286 }
287 else {
288 if (weapon < 0 || weapon >= NUMWEAPONS)
289 return false;
290
291 P_GiveWeapon(&target_player, weapon, false);
292 }
293
294 return true;
295 }
296
297 return false;
298 }
299
300 static dboolean console_PlayerGiveAmmo(const char* command, const char* args) {
301 int ammo;
302 int amount;
303 int arg_count;
304
305 arg_count = sscanf(args, "%i %i", &ammo, &amount);
306
307 if (arg_count == 2) {
308 if (ammo < 0 || ammo >= g_numammo || amount <= 0)
309 return false;
310
311 if (hexen) {
312 target_player.ammo[ammo] += amount;
313 if (target_player.ammo[ammo] > MAX_MANA)
314 target_player.ammo[ammo] = MAX_MANA;
315 }
316 else {
317 target_player.ammo[ammo] += amount;
318 if (target_player.ammo[ammo] > target_player.maxammo[ammo])
319 target_player.ammo[ammo] = target_player.maxammo[ammo];
320 }
321
322 return true;
323 }
324 else if (arg_count == 1) {
325 if (ammo < 0 || ammo >= g_numammo)
326 return false;
327
328 if (hexen)
329 target_player.ammo[ammo] = MAX_MANA;
330 else
331 target_player.ammo[ammo] = target_player.maxammo[ammo];
332
333 return true;
334 }
335
336 return false;
337 }
338
339 static dboolean console_PlayerSetAmmo(const char* command, const char* args) {
340 int ammo;
341 int amount;
342
343 if (sscanf(args, "%i %i", &ammo, &amount) == 2) {
344 if (ammo < 0 || ammo >= g_numammo || amount < 0)
345 return false;
346
347 if (hexen) {
348 target_player.ammo[ammo] = amount;
349 if (target_player.ammo[ammo] > MAX_MANA)
350 target_player.ammo[ammo] = MAX_MANA;
351 }
352 else {
353 target_player.ammo[ammo] = amount;
354 if (target_player.ammo[ammo] > target_player.maxammo[ammo])
355 target_player.ammo[ammo] = target_player.maxammo[ammo];
356 }
357
358 return true;
359 }
360
361 return false;
362 }
363
364 static dboolean console_PlayerGiveKey(const char* command, const char* args) {
365 int key;
366
367 if (sscanf(args, "%i", &key)) {
368 if (key < 0 || key >= NUMCARDS)
369 return false;
370
371 target_player.cards[key] = true;
372 target_player.ravenkeys |= 1 << key;
373
374 return true;
375 }
376
377 return false;
378 }
379
380 static dboolean console_PlayerRemoveKey(const char* command, const char* args) {
381 int key;
382
383 if (sscanf(args, "%i", &key)) {
384 if (key < 0 || key >= NUMCARDS)
385 return false;
386
387 target_player.cards[key] = false;
388 target_player.ravenkeys &= ~(1 << key);
389
390 return true;
391 }
392
393 return false;
394 }
395
396 static dboolean console_PlayerGivePower(const char* command, const char* args) {
397 dboolean P_GivePower(player_t *player, int power);
398 void SB_Start(void);
399
400 int power;
401 int duration = -1;
402
403 if (sscanf(args, "%i %i", &power, &duration)) {
404 if (power < 0 || power >= NUMPOWERS ||
405 power == pw_shield || power == pw_health2 || power == pw_minotaur)
406 return false;
407
408 target_player.powers[power] = 0;
409 P_GivePower(&target_player, power);
410 if (power != pw_strength)
411 target_player.powers[power] = duration;
412
413 if (raven) SB_Start();
414
415 return true;
416 }
417
418 return false;
419 }
420
421 static dboolean console_PlayerRemovePower(const char* command, const char* args) {
422 void SB_Start(void);
423
424 int power;
425
426 if (sscanf(args, "%i", &power)) {
427 if (power < 0 || power >= NUMPOWERS ||
428 power == pw_shield || power == pw_health2 || power == pw_minotaur)
429 return false;
430
431 target_player.powers[power] = 0;
432
433 if (power == pw_invulnerability) {
434 target_player.mo->flags2 &= ~(MF2_INVULNERABLE | MF2_REFLECTIVE);
435 if (target_player.pclass == PCLASS_CLERIC)
436 {
437 target_player.mo->flags2 &= ~(MF2_DONTDRAW | MF2_NONSHOOTABLE);
438 target_player.mo->flags &= ~(MF_SHADOW | MF_ALTSHADOW);
439 }
440 }
441 else if (power == pw_invisibility)
442 target_player.mo->flags &= ~MF_SHADOW;
443 else if (power == pw_flight) {
444 P_PlayerEndFlight(&target_player);
445 }
446 else if (power == pw_weaponlevel2 && heretic) {
447 if ((target_player.readyweapon == wp_phoenixrod)
448 && (target_player.psprites[ps_weapon].state
449 != &states[HERETIC_S_PHOENIXREADY])
450 && (target_player.psprites[ps_weapon].state
451 != &states[HERETIC_S_PHOENIXUP]))
452 {
453 P_SetPsprite(&target_player, ps_weapon, HERETIC_S_PHOENIXREADY);
454 target_player.ammo[am_phoenixrod] -= USE_PHRD_AMMO_2;
455 target_player.refire = 0;
456 }
457 else if ((target_player.readyweapon == wp_gauntlets)
458 || (target_player.readyweapon == wp_staff))
459 {
460 target_player.pendingweapon = target_player.readyweapon;
461 }
462 }
463
464 if (raven) SB_Start();
465
466 return true;
467 }
468
469 return false;
470 }
471
472 static dboolean console_PlayerSetCoordinate(const char* args, int* dest) {
473 int x, x_frac = 0;
474
475 if (sscanf(args, "%i.%i", &x, &x_frac)) {
476 *dest = FRACUNIT * x;
477
478 if (args[0] == '-')
479 *dest -= x_frac;
480 else
481 *dest += x_frac;
482
483 return true;
484 }
485
486 return false;
487 }
488
489 static dboolean console_PlayerSetX(const char* command, const char* args) {
490 return console_PlayerSetCoordinate(args, &target_player.mo->x);
491 }
492
493 static dboolean console_PlayerSetY(const char* command, const char* args) {
494 return console_PlayerSetCoordinate(args, &target_player.mo->y);
495 }
496
497 static dboolean console_PlayerSetZ(const char* command, const char* args) {
498 return console_PlayerSetCoordinate(args, &target_player.mo->z);
499 }
500
501 static dboolean console_PlayerSetVX(const char* command, const char* args) {
502 return console_PlayerSetCoordinate(args, &target_player.mo->momx);
503 }
504
505 static dboolean console_PlayerSetVY(const char* command, const char* args) {
506 return console_PlayerSetCoordinate(args, &target_player.mo->momy);
507 }
508
509 static dboolean console_PlayerSetVZ(const char* command, const char* args) {
510 return console_PlayerSetCoordinate(args, &target_player.mo->momz);
511 }
512
513 static void console_PlayerRoundCoordinate(int* x) {
514 int bits = *x & 0xffff;
515
516 if (!bits)
517 return;
518
519 if (bits >= 0x8000)
520 *x = (*x & ~0xffff) + FRACUNIT;
521 else
522 *x = *x & ~0xffff;
523 }
524
525 static dboolean console_PlayerRoundX(const char* command, const char* args) {
526 console_PlayerRoundCoordinate(&target_player.mo->x);
527
528 return true;
529 }
530
531 static dboolean console_PlayerRoundY(const char* command, const char* args) {
532 console_PlayerRoundCoordinate(&target_player.mo->y);
533
534 return true;
535 }
536
537 static dboolean console_PlayerRoundXY(const char* command, const char* args) {
538 console_PlayerRoundCoordinate(&target_player.mo->x);
539 console_PlayerRoundCoordinate(&target_player.mo->y);
540
541 return true;
542 }
543
544 static dboolean console_PlayerSetAngle(const char* command, const char* args) {
545 int a, a_frac = 0;
546
547 if (sscanf(args, "%d.%d", &a, &a_frac)) {
548 target_player.mo->angle = ((angle_t) a) << 24;
549
550 if (args[0] == '-')
551 target_player.mo->angle -= (a_frac << 16);
552 else
553 target_player.mo->angle += (a_frac << 16);
554
555 R_SmoothPlaying_Reset(&target_player);
556
557 return true;
558 }
559
560 return false;
561 }
562
563 static dboolean console_PlayerRoundAngle(const char* command, const char* args) {
564 int remainder;
565
566 remainder = (target_player.mo->angle >> 16) & 0xff;
567
568 target_player.mo->angle &= 0xff000000;
569
570 if (remainder >= 0x80)
571 target_player.mo->angle += 0x01000000;
572
573 R_SmoothPlaying_Reset(&target_player);
574
575 return true;
576 }
577
578 static dboolean console_DemoExport(const char* command, const char* args) {
579 char name[CONSOLE_ENTRY_SIZE];
580
581 if (sscanf(args, "%s", name) == 1) {
582 dsda_ExportDemo(name);
583 return true;
584 }
585
586 return false;
587 }
588
589 static dboolean console_DemoStart(const char* command, const char* args) {
590 char name[CONSOLE_ENTRY_SIZE];
591
592 if (sscanf(args, "%s", name) == 1)
593 return dsda_StartDemoSegment(name);
594
595 return false;
596 }
597
598 static dboolean console_DemoStop(const char* command, const char* args) {
599 if (!demorecording)
600 return false;
601
602 G_CheckDemoStatus();
603 dsda_UpdateStrictMode();
604
605 return true;
606 }
607
608 static dboolean console_DemoJoin(const char* command, const char* args) {
609 if (!demoplayback)
610 return false;
611
612 dsda_JoinDemo(NULL);
613
614 return true;
615 }
616
617 static dboolean console_GameQuit(const char* command, const char* args) {
618 I_SafeExit(0);
619
620 return true;
621 }
622
623 static dboolean console_GameDescribe(const char* command, const char* args) {
624 extern dsda_string_t hud_title;
625
626 dsda_string_t str;
627
628 dsda_StringPrintF(&str, "%s\n"
629 "Skill %d\n"
630 "%s%s%s",
631 hud_title.string, gameskill + 1,
632 nomonsters ? "-nomo " : "",
633 respawnparm ? "-respawn " : "",
634 fastparm ? "-fast" : "");
635
636 dsda_AddAlert(str.string);
637
638 dsda_FreeString(&str);
639
640 return true;
641 }
642
643 static dboolean console_TrackerAddLine(const char* command, const char* args) {
644 int id;
645
646 if (sscanf(args, "%i", &id))
647 return dsda_TrackLine(id);
648
649 return false;
650 }
651
652 static dboolean console_TrackerRemoveLine(const char* command, const char* args) {
653 int id;
654
655 if (sscanf(args, "%i", &id))
656 return dsda_UntrackLine(id);
657
658 return false;
659 }
660
661 static dboolean console_TrackerAddLineDistance(const char* command, const char* args) {
662 int id;
663
664 if (sscanf(args, "%i", &id))
665 return dsda_TrackLineDistance(id);
666
667 return false;
668 }
669
670 static dboolean console_TrackerRemoveLineDistance(const char* command, const char* args) {
671 int id;
672
673 if (sscanf(args, "%i", &id))
674 return dsda_UntrackLineDistance(id);
675
676 return false;
677 }
678
679 static dboolean console_TrackerAddSector(const char* command, const char* args) {
680 int id;
681
682 if (sscanf(args, "%i", &id))
683 return dsda_TrackSector(id);
684
685 return false;
686 }
687
688 static dboolean console_TrackerRemoveSector(const char* command, const char* args) {
689 int id;
690
691 if (sscanf(args, "%i", &id))
692 return dsda_UntrackSector(id);
693
694 return false;
695 }
696
697 static dboolean console_TrackerAddMobj(const char* command, const char* args) {
698 int id;
699
700 if (sscanf(args, "%i", &id))
701 return dsda_TrackMobj(id);
702
703 return false;
704 }
705
706 static dboolean console_TrackerRemoveMobj(const char* command, const char* args) {
707 int id;
708
709 if (sscanf(args, "%i", &id))
710 return dsda_UntrackMobj(id);
711
712 return false;
713 }
714
715 static dboolean console_TrackerAddPlayer(const char* command, const char* args) {
716 return dsda_TrackPlayer(0);
717 }
718
719 static dboolean console_TrackerRemovePlayer(const char* command, const char* args) {
720 return dsda_UntrackPlayer(0);
721 }
722
723 static dboolean console_TrackerReset(const char* command, const char* args) {
724 dsda_WipeTrackers();
725
726 return true;
727 }
728
729 static dboolean console_JumpToTic(const char* command, const char* args) {
730 int tic;
731
732 if (sscanf(args, "%i", &tic)) {
733 if (tic < 0)
734 return false;
735
736 dsda_JumpToLogicTic(tic);
737
738 return true;
739 }
740
741 return false;
742 }
743
744 static dboolean console_JumpByTic(const char* command, const char* args) {
745 int tic;
746
747 if (sscanf(args, "%i", &tic)) {
748 tic = true_logictic + tic;
749
750 dsda_JumpToLogicTic(tic);
751
752 return true;
753 }
754
755 return false;
756 }
757
758 static dboolean console_BuildMF(const char* command, const char* args) {
759 int x;
760
761 return sscanf(args, "%i", &x) && dsda_BuildMF(x);
762 }
763
764 static dboolean console_BuildMB(const char* command, const char* args) {
765 int x;
766
767 return sscanf(args, "%i", &x) && dsda_BuildMB(x);
768 }
769
770 static dboolean console_BuildSR(const char* command, const char* args) {
771 int x;
772
773 return sscanf(args, "%i", &x) && dsda_BuildSR(x);
774 }
775
776 static dboolean console_BuildSL(const char* command, const char* args) {
777 int x;
778
779 return sscanf(args, "%i", &x) && dsda_BuildSL(x);
780 }
781
782 static dboolean console_BuildTR(const char* command, const char* args) {
783 int x;
784
785 return sscanf(args, "%i", &x) && dsda_BuildTR(x);
786 }
787
788 static dboolean console_BuildTL(const char* command, const char* args) {
789 int x;
790
791 return sscanf(args, "%i", &x) && dsda_BuildTL(x);
792 }
793
794 static dboolean console_BuildFU(const char* command, const char* args) {
795 int x;
796
797 return sscanf(args, "%i", &x) && dsda_BuildFU(x);
798 }
799
800 static dboolean console_BuildFD(const char* command, const char* args) {
801 int x;
802
803 return sscanf(args, "%i", &x) && dsda_BuildFD(x);
804 }
805
806 static dboolean console_BuildFC(const char* command, const char* args) {
807 return dsda_BuildFC();
808 }
809
810 static dboolean console_BuildLU(const char* command, const char* args) {
811 int x;
812
813 return sscanf(args, "%i", &x) && dsda_BuildLU(x);
814 }
815
816 static dboolean console_BuildLD(const char* command, const char* args) {
817 int x;
818
819 return sscanf(args, "%i", &x) && dsda_BuildLD(x);
820 }
821
822 static dboolean console_BuildLC(const char* command, const char* args) {
823 return dsda_BuildLC();
824 }
825
826 static dboolean console_BuildUA(const char* command, const char* args) {
827 int x;
828
829 return sscanf(args, "%i", &x) && dsda_BuildUA(x);
830 }
831
832 static dboolean console_BruteForceKeep(const char* command, const char* args) {
833 int frame;
834
835 if (!sscanf(args, "%d", &frame))
836 return false;
837
838 return dsda_KeepBruteForceFrame(frame);
839 }
840
841 static dboolean console_BruteForceNoMonsters(const char* command, const char* args) {
842 dsda_BruteForceWithoutMonsters();
843
844 return true;
845 }
846
847 static dboolean console_BruteForceMonsters(const char* command, const char* args) {
848 dsda_BruteForceWithMonsters();
849
850 return true;
851 }
852
853 static dboolean console_BruteForceFrame(const char* command, const char* args) {
854 int frame;
855 int forwardmove_min, forwardmove_max;
856 int sidemove_min, sidemove_max;
857 int angleturn_min, angleturn_max;
858 byte buttons = 0;
859 int weapon = 0;
860 char button_str[4] = { 0 };
861 int i, arg_count;
862
863 arg_count = sscanf(
864 args, "%i %i:%i %i:%i %i:%i %3s %d", &frame,
865 &forwardmove_min, &forwardmove_max,
866 &sidemove_min, &sidemove_max,
867 &angleturn_min, &angleturn_max,
868 button_str, &weapon
869 );
870
871 if (arg_count < 7)
872 return false;
873
874 if (arg_count > 7)
875 for (i = 0; i < 3; ++i)
876 switch (button_str[i]) {
877 case 'a':
878 buttons |= BT_ATTACK;
879 break;
880 case 'u':
881 buttons |= BT_USE;
882 break;
883 case 'c':
884 if (weapon > 0 && weapon < 16) {
885 buttons |= BT_CHANGE;
886 buttons |= (weapon << BT_WEAPONSHIFT);
887 }
888 else
889 return false;
890 break;
891 case '\0':
892 break;
893 default:
894 return false;
895 }
896
897 return dsda_AddBruteForceFrame(frame,
898 forwardmove_min, forwardmove_max,
899 sidemove_min, sidemove_max,
900 angleturn_min, angleturn_max,
901 buttons);
902 }
903
904 static dboolean console_BruteForceStart(const char* command, const char* args) {
905 int depth;
906 int forwardmove_min, forwardmove_max;
907 int sidemove_min, sidemove_max;
908 int angleturn_min, angleturn_max;
909 char condition_args[CONSOLE_ENTRY_SIZE];
910 int arg_count;
911
912 dsda_ResetBruteForceConditions();
913
914 arg_count = sscanf(
915 args, "%i %i:%i %i:%i %i:%i %[^;]", &depth,
916 &forwardmove_min, &forwardmove_max,
917 &sidemove_min, &sidemove_max,
918 &angleturn_min, &angleturn_max,
919 condition_args
920 );
921
922 if (arg_count == 8) {
923 int i;
924
925 for (i = 0; i < depth; ++i)
926 dsda_AddBruteForceFrame(i,
927 forwardmove_min, forwardmove_max,
928 sidemove_min, sidemove_max,
929 angleturn_min, angleturn_max,
930 0);
931 }
932 else {
933 arg_count = sscanf(args, "%i %[^;]", &depth, condition_args);
934
935 if (arg_count != 2)
936 return false;
937 }
938
939 {
940 int i;
941 char** conditions;
942
943 conditions = dsda_SplitString(condition_args, ",");
944
945 if (!conditions)
946 return false;
947
948 for (i = 0; conditions[i]; ++i) {
949 fixed_t value;
950 char attr_s[4] = { 0 };
951 char oper_s[5] = { 0 };
952
953 if (sscanf(conditions[i], " skip %i", &value) == 1) {
954 if (value >= numlines || value < 0)
955 return false;
956
957 dsda_AddMiscBruteForceCondition(dsda_bf_line_skip, value);
958 }
959 else if (sscanf(conditions[i], " act %i", &value) == 1) {
960 if (value >= numlines || value < 0)
961 return false;
962
963 dsda_AddMiscBruteForceCondition(dsda_bf_line_activation, value);
964 }
965 else if (sscanf(conditions[i], " have %3[a-zA-Z]", attr_s) == 1) {
966 int attr_i;
967
968 for (attr_i = 0; attr_i < dsda_bf_item_max; ++attr_i)
969 if (!strcmp(attr_s, dsda_bf_item_names[attr_i]))
970 break;
971
972 if (attr_i == dsda_bf_item_max)
973 return false;
974
975 dsda_AddMiscBruteForceCondition(dsda_bf_have_item, attr_i);
976 }
977 else if (sscanf(conditions[i], " lack %3[a-zA-Z]", attr_s) == 1) {
978 int attr_i;
979
980 for (attr_i = 0; attr_i < dsda_bf_item_max; ++attr_i)
981 if (!strcmp(attr_s, dsda_bf_item_names[attr_i]))
982 break;
983
984 if (attr_i == dsda_bf_item_max)
985 return false;
986
987 dsda_AddMiscBruteForceCondition(dsda_bf_lack_item, attr_i);
988 }
989 else if (sscanf(conditions[i], " %3[a-zA-Z] %4[a-zA-Z><!=] %i", attr_s, oper_s, &value) == 3) {
990 int attr_i, oper_i;
991
992 if (oper_s[0] == '=' && !oper_s[1])
993 oper_s[1] = '=';
994
995 for (attr_i = 0; attr_i < dsda_bf_attribute_max; ++attr_i)
996 if (!strcmp(attr_s, dsda_bf_attribute_names[attr_i]))
997 break;
998
999 if (attr_i == dsda_bf_attribute_max)
1000 return false;
1001
1002 for (oper_i = dsda_bf_limit_trio_zero; oper_i < dsda_bf_limit_trio_max; ++oper_i)
1003 if (!strcmp(oper_s, dsda_bf_limit_names[oper_i]))
1004 break;
1005
1006 if (oper_i != dsda_bf_limit_trio_max) {
1007 dsda_SetBruteForceTarget(attr_i, oper_i, value, true);
1008 continue;
1009 }
1010
1011 for (oper_i = 0; oper_i < dsda_bf_operator_max; ++oper_i)
1012 if (!strcmp(oper_s, dsda_bf_operator_names[oper_i]))
1013 break;
1014
1015 if (oper_i == dsda_bf_operator_max)
1016 return false;
1017
1018 dsda_AddBruteForceCondition(attr_i, oper_i, value);
1019 }
1020 else if (sscanf(conditions[i], " %3s %4s", attr_s, oper_s) == 2) {
1021 int attr_i, oper_i;
1022
1023 for (attr_i = 0; attr_i < dsda_bf_attribute_max; ++attr_i)
1024 if (!strcmp(attr_s, dsda_bf_attribute_names[attr_i]))
1025 break;
1026
1027 if (attr_i == dsda_bf_attribute_max)
1028 return false;
1029
1030 for (oper_i = dsda_bf_limit_duo_zero; oper_i < dsda_bf_limit_duo_max; ++oper_i)
1031 if (!strcmp(oper_s, dsda_bf_limit_names[oper_i]))
1032 break;
1033
1034 if (oper_i == dsda_bf_limit_duo_max)
1035 return false;
1036
1037 dsda_SetBruteForceTarget(attr_i, oper_i, 0, false);
1038 }
1039 else {
1040 return false;
1041 }
1042 }
1043
1044 Z_Free(conditions);
1045 }
1046
1047 return dsda_StartBruteForce(depth);
1048 }
1049
1050 static dboolean console_BuildTurbo(const char* command, const char* args) {
1051 dsda_ToggleBuildTurbo();
1052
1053 return true;
1054 }
1055
1056 static dboolean console_Exit(const char* command, const char* args) {
1057 extern void M_ClearMenus(void);
1058
1059 M_ClearMenus();
1060
1061 return true;
1062 }
1063
1064 static dboolean console_BasicCheat(const char* command, const char* args) {
1065 return M_CheatEntered(command, args);
1066 }
1067
1068 static dboolean console_IDDT(const char* command, const char* args) {
1069 M_CheatIDDT();
1070
1071 return true;
1072 }
1073
1074 static dboolean console_CheatFullClip(const char* command, const char* args) {
1075 target_player.cheats ^= CF_INFINITE_AMMO;
1076 return true;
1077 }
1078
1079 static dboolean console_Freeze(const char* command, const char* args) {
1080 dsda_ToggleFrozenMode();
1081 return true;
1082 }
1083
1084 static dboolean console_NoSleep(const char* command, const char* args) {
1085 int i;
1086
1087 for (i = 0; i < numsectors; ++i)
1088 sectors[i].soundtarget = target_player.mo;
1089
1090 return true;
1091 }
1092
1093 static dboolean console_ScriptRunLine(const char* line) {
1094 if (strlen(line) && line[0] != '#' && line[0] != '!' && line[0] != '/') {
1095 if (strlen(line) >= CONSOLE_ENTRY_SIZE) {
1096 lprintf(LO_ERROR, "Script line too long: \"%s\" (limit %d)\n", line, CONSOLE_ENTRY_SIZE);
1097 return false;
1098 }
1099
1100 if (!dsda_ExecuteConsole(line, false)) {
1101 lprintf(LO_ERROR, "Script line failed: \"%s\"\n", line);
1102 return false;
1103 }
1104 }
1105
1106 return true;
1107 }
1108
1109 static dboolean console_ScriptRun(const char* command, const char* args) {
1110 char name[CONSOLE_ENTRY_SIZE];
1111 dboolean ret = true;
1112
1113 if (sscanf(args, "%s", name)) {
1114 char* filename;
1115 char* buffer;
1116
1117 filename = I_FindFile(name, "");
1118
1119 if (filename) {
1120 if (M_ReadFileToString(filename, &buffer) != -1) {
1121 char* line;
1122
1123 for (line = strtok(buffer, "\n;"); line; line = strtok(NULL, "\n;"))
1124 if (!console_ScriptRunLine(line)) {
1125 ret = false;
1126 break;
1127 }
1128
1129 Z_Free(buffer);
1130 }
1131 else {
1132 lprintf(LO_ERROR, "Unable to read script file (%s)\n", filename);
1133 ret = false;
1134 }
1135
1136 Z_Free(filename);
1137 }
1138 else {
1139 lprintf(LO_ERROR, "Cannot find script file (%s)\n", name);
1140 ret = false;
1141 }
1142
1143 return ret;
1144 }
1145
1146 return false;
1147 }
1148
1149 static dboolean console_Check(const char* command, const char* args) {
1150 char name[CONSOLE_ENTRY_SIZE];
1151
1152 if (sscanf(args, "%s", name)) {
1153 char* summary;
1154
1155 summary = dsda_ConfigSummary(name);
1156
1157 if (summary) {
1158 lprintf(LO_INFO, "%s\n", summary);
1159 Z_Free(summary);
1160 return true;
1161 }
1162 }
1163
1164 return false;
1165 }
1166
1167 static dboolean console_ChangeConfig(const char* command, const char* args, dboolean persist) {
1168 char name[CONSOLE_ENTRY_SIZE];
1169 char value_string[CONSOLE_ENTRY_SIZE];
1170
1171 if (sscanf(args, "%s %s", name, value_string)) {
1172 int id;
1173
1174 id = dsda_ConfigIDByName(name);
1175 if (id) {
1176 dsda_config_type_t config_type;
1177
1178 config_type = dsda_ConfigType(id);
1179 if (config_type == dsda_config_int) {
1180 int value_int;
1181
1182 if (sscanf(value_string, "%d", &value_int)) {
1183 dsda_UpdateIntConfig(id, value_int, persist);
1184 return true;
1185 }
1186 }
1187 else {
1188 dsda_UpdateStringConfig(id, value_string, persist);
1189 return true;
1190 }
1191 }
1192 }
1193
1194 return false;
1195 }
1196
1197 static dboolean console_Assign(const char* command, const char* args) {
1198 return console_ChangeConfig(command, args, false);
1199 }
1200
1201 static dboolean console_Update(const char* command, const char* args) {
1202 return console_ChangeConfig(command, args, true);
1203 }
1204
1205 static dboolean console_ToggleConfig(const char* command, const char* args, dboolean persist) {
1206 char name[CONSOLE_ENTRY_SIZE];
1207
1208 if (sscanf(args, "%s", name)) {
1209 int id;
1210
1211 id = dsda_ConfigIDByName(name);
1212 if (id) {
1213 dsda_config_type_t config_type;
1214
1215 config_type = dsda_ConfigType(id);
1216 if (config_type == dsda_config_int) {
1217 dsda_ToggleConfig(id, persist);
1218 return true;
1219 }
1220 }
1221 }
1222
1223 return false;
1224 }
1225
1226 static dboolean console_ToggleAssign(const char* command, const char* args) {
1227 return console_ToggleConfig(command, args, false);
1228 }
1229
1230 static dboolean console_ToggleUpdate(const char* command, const char* args) {
1231 return console_ToggleConfig(command, args, true);
1232 }
1233
1234 static dboolean console_ConfigForget(const char* command, const char* args) {
1235 void M_ForgetCurrentConfig(void);
1236
1237 M_ForgetCurrentConfig();
1238
1239 return true;
1240 }
1241
1242 static dboolean console_ConfigRemember(const char* command, const char* args) {
1243 void M_RememberCurrentConfig(void);
1244
1245 M_RememberCurrentConfig();
1246
1247 return true;
1248 }
1249
1250 static dboolean console_WadStatsForget(const char* command, const char* args) {
1251 void M_ForgetWadStats(void);
1252
1253 M_ForgetWadStats();
1254
1255 return true;
1256 }
1257
1258 static dboolean console_WadStatsRemember(const char* command, const char* args) {
1259 void M_RememberWadStats(void);
1260
1261 M_RememberWadStats();
1262
1263 return true;
1264 }
1265
1266 static dboolean console_FreeTextUpdate(const char* command, const char* args) {
1267 dsda_UpdateStringConfig(dsda_config_free_text, args, true);
1268
1269 return true;
1270 }
1271
1272 static dboolean console_FreeTextClear(const char* command, const char* args) {
1273 dsda_UpdateStringConfig(dsda_config_free_text, "", true);
1274
1275 return true;
1276 }
1277
1278 static dboolean console_SetMobjState(mobj_t* mobj, statenum_t state) {
1279 if (!state)
1280 return false;
1281
1282 P_MapStart();
1283 P_SetMobjState(mobj, state);
1284 P_MapEnd();
1285
1286 return true;
1287 }
1288
1289 static dboolean console_MoveMobj(mobj_t* mobj, fixed_t x, fixed_t y) {
1290 if (!mobj)
1291 return false;
1292
1293 P_MapStart();
1294 P_UnqualifiedMove(mobj, x, y);
1295 P_MapEnd();
1296
1297 return true;
1298 }
1299
1300 static dboolean console_SetTarget(mobj_t* mobj, mobj_t* target) {
1301 if (!mobj || !target)
1302 return false;
1303
1304 P_SetTarget(&mobj->target, target);
1305 mobj->threshold = BASETHRESHOLD;
1306
1307 return true;
1308 }
1309
1310 static void console_SetMobjFlags(mobj_t* mobj, uint64_t flags, uint64_t flags2) {
1311 P_MapStart();
1312 P_UnsetThingPosition(mobj);
1313 mobj->flags = flags;
1314 mobj->flags2 = flags2;
1315 P_SetThingPosition(mobj);
1316 P_MapEnd();
1317 }
1318
1319 static dboolean console_TargetSpawn(const char* command, const char* args) {
1320 mobj_t* target;
1321
1322 target = HU_Target();
1323
1324 return target && console_SetMobjState(target, target->info->spawnstate);
1325 }
1326
1327 static dboolean console_TargetSee(const char* command, const char* args) {
1328 mobj_t* target;
1329
1330 target = HU_Target();
1331
1332 return target && console_SetMobjState(target, target->info->seestate);
1333 }
1334
1335 static dboolean console_TargetPain(const char* command, const char* args) {
1336 mobj_t* target;
1337
1338 target = HU_Target();
1339
1340 return target && console_SetMobjState(target, target->info->painstate);
1341 }
1342
1343 static dboolean console_TargetMelee(const char* command, const char* args) {
1344 mobj_t* target;
1345
1346 target = HU_Target();
1347
1348 return target && console_SetMobjState(target, target->info->meleestate);
1349 }
1350
1351 static dboolean console_TargetMissile(const char* command, const char* args) {
1352 mobj_t* target;
1353
1354 target = HU_Target();
1355
1356 return target && console_SetMobjState(target, target->info->missilestate);
1357 }
1358
1359 static dboolean console_TargetDeath(const char* command, const char* args) {
1360 mobj_t* target;
1361
1362 target = HU_Target();
1363
1364 return target && console_SetMobjState(target, target->info->deathstate);
1365 }
1366
1367 static dboolean console_TargetXDeath(const char* command, const char* args) {
1368 mobj_t* target;
1369
1370 target = HU_Target();
1371
1372 return target && console_SetMobjState(target, target->info->xdeathstate);
1373 }
1374
1375 static dboolean console_TargetRaise(const char* command, const char* args) {
1376 mobj_t* target;
1377
1378 target = HU_Target();
1379
1380 return target && console_SetMobjState(target, target->info->raisestate);
1381 }
1382
1383 static dboolean console_TargetSetState(const char* command, const char* args) {
1384 int state;
1385 mobj_t* target;
1386
1387 if (sscanf(args, "%d", &state) != 1 || state < 0 || state >= num_states)
1388 return false;
1389
1390 target = HU_Target();
1391
1392 return target && console_SetMobjState(target, state);
1393 }
1394
1395 static dboolean console_TargetSetHealth(const char* command, const char* args) {
1396 int health;
1397 mobj_t* target;
1398
1399 if (sscanf(args, "%i", &health) != 1)
1400 return false;
1401
1402 target = HU_Target();
1403
1404 if (!target)
1405 return false;
1406
1407 target->health = health;
1408 if (target->player)
1409 target->player->health = health;
1410
1411 return true;
1412 }
1413
1414 static dboolean console_TargetMove(const char* command, const char* args) {
1415 fixed_t x, y;
1416 mobj_t* target;
1417
1418 if (sscanf(args, "%d %d", &x, &y) != 2)
1419 return false;
1420
1421 x <<= FRACBITS;
1422 y <<= FRACBITS;
1423
1424 target = HU_Target();
1425
1426 return console_MoveMobj(target, x, y);
1427 }
1428
1429 static dboolean console_TargetSetTarget(const char* command, const char* args) {
1430 mobj_t* target;
1431 int new_target_index;
1432 mobj_t* new_target;
1433
1434 if (sscanf(args, "%d", &new_target_index) != 1)
1435 return false;
1436
1437 target = HU_Target();
1438 new_target = dsda_FindMobj(new_target_index);
1439
1440 return console_SetTarget(target, new_target);
1441 }
1442
1443 static dboolean console_TargetTargetPlayer(const char* command, const char* args) {
1444 mobj_t* target;
1445
1446 target = HU_Target();
1447
1448 return console_SetTarget(target, target_player.mo);
1449 }
1450
1451 static dboolean console_TargetActivateLine(const char* command, const char* args) {
1452 int id;
1453 mobj_t* target;
1454
1455 if (sscanf(args, "%i", &id) != 1)
1456 return false;
1457
1458 target = HU_Target();
1459
1460 return console_ActivateLine(target, id, false);
1461 }
1462
1463 static dboolean console_TargetAddFlags(const char* command, const char* args) {
1464 mobj_t* target;
1465 uint64_t flags, flags2;
1466 char flag_str[CONSOLE_ENTRY_SIZE];
1467
1468 if (sscanf(args, "%s", flag_str) != 1)
1469 return false;
1470
1471 target = HU_Target();
1472
1473 if (!target)
1474 return false;
1475
1476 flags = target->flags | deh_stringToMobjFlags(flag_str);
1477 flags2 = target->flags2 | deh_stringToMBF21MobjFlags(flag_str);
1478
1479 console_SetMobjFlags(target, flags, flags2);
1480
1481 return true;
1482 }
1483
1484 static dboolean console_TargetRemoveFlags(const char* command, const char* args) {
1485 mobj_t* target;
1486 uint64_t flags, flags2;
1487 char flag_str[CONSOLE_ENTRY_SIZE];
1488
1489 if (sscanf(args, "%s", flag_str) != 1)
1490 return false;
1491
1492 target = HU_Target();
1493
1494 if (!target)
1495 return false;
1496
1497 flags = target->flags & ~deh_stringToMobjFlags(flag_str);
1498 flags2 = target->flags2 & ~deh_stringToMBF21MobjFlags(flag_str);
1499
1500 console_SetMobjFlags(target, flags, flags2);
1501
1502 return true;
1503 }
1504
1505 static dboolean console_TargetSetFlags(const char* command, const char* args) {
1506 mobj_t* target;
1507 uint64_t flags, flags2;
1508 char flag_str[CONSOLE_ENTRY_SIZE];
1509
1510 if (sscanf(args, "%s", flag_str) != 1)
1511 return false;
1512
1513 target = HU_Target();
1514
1515 if (!target)
1516 return false;
1517
1518 flags = deh_stringToMobjFlags(flag_str);
1519 flags2 = deh_stringToMBF21MobjFlags(flag_str);
1520
1521 console_SetMobjFlags(target, flags, flags2);
1522
1523 return true;
1524 }
1525
1526 static dboolean console_MobjSpawn(const char* command, const char* args) {
1527 int index;
1528 mobj_t* target;
1529
1530 if (sscanf(args, "%d", &index) != 1 || index < 0)
1531 return false;
1532
1533 target = dsda_FindMobj(index);
1534
1535 return target && console_SetMobjState(target, target->info->spawnstate);
1536 }
1537
1538 static dboolean console_MobjSee(const char* command, const char* args) {
1539 int index;
1540 mobj_t* target;
1541
1542 if (sscanf(args, "%d", &index) != 1 || index < 0)
1543 return false;
1544
1545 target = dsda_FindMobj(index);
1546
1547 return target && console_SetMobjState(target, target->info->seestate);
1548 }
1549
1550 static dboolean console_MobjPain(const char* command, const char* args) {
1551 int index;
1552 mobj_t* target;
1553
1554 if (sscanf(args, "%d", &index) != 1 || index < 0)
1555 return false;
1556
1557 target = dsda_FindMobj(index);
1558
1559 return target && console_SetMobjState(target, target->info->painstate);
1560 }
1561
1562 static dboolean console_MobjMelee(const char* command, const char* args) {
1563 int index;
1564 mobj_t* target;
1565
1566 if (sscanf(args, "%d", &index) != 1 || index < 0)
1567 return false;
1568
1569 target = dsda_FindMobj(index);
1570
1571 return target && console_SetMobjState(target, target->info->meleestate);
1572 }
1573
1574 static dboolean console_MobjMissile(const char* command, const char* args) {
1575 int index;
1576 mobj_t* target;
1577
1578 if (sscanf(args, "%d", &index) != 1 || index < 0)
1579 return false;
1580
1581 target = dsda_FindMobj(index);
1582
1583 return target && console_SetMobjState(target, target->info->missilestate);
1584 }
1585
1586 static dboolean console_MobjDeath(const char* command, const char* args) {
1587 int index;
1588 mobj_t* target;
1589
1590 if (sscanf(args, "%d", &index) != 1 || index < 0)
1591 return false;
1592
1593 target = dsda_FindMobj(index);
1594
1595 return target && console_SetMobjState(target, target->info->deathstate);
1596 }
1597
1598 static dboolean console_MobjXDeath(const char* command, const char* args) {
1599 int index;
1600 mobj_t* target;
1601
1602 if (sscanf(args, "%d", &index) != 1 || index < 0)
1603 return false;
1604
1605 target = dsda_FindMobj(index);
1606
1607 return target && console_SetMobjState(target, target->info->xdeathstate);
1608 }
1609
1610 static dboolean console_MobjRaise(const char* command, const char* args) {
1611 int index;
1612 mobj_t* target;
1613
1614 if (sscanf(args, "%d", &index) != 1 || index < 0)
1615 return false;
1616
1617 target = dsda_FindMobj(index);
1618
1619 return target && console_SetMobjState(target, target->info->raisestate);
1620 }
1621
1622 static dboolean console_MobjSetState(const char* command, const char* args) {
1623 int state;
1624 int index;
1625 mobj_t* target;
1626
1627 if (sscanf(args, "%d %d", &index, &state) != 2 || index < 0 || state < 0 || state >= num_states)
1628 return false;
1629
1630 target = dsda_FindMobj(index);
1631
1632 return target && console_SetMobjState(target, state);
1633 }
1634
1635 static dboolean console_MobjSetHealth(const char* command, const char* args) {
1636 int health;
1637 int index;
1638 mobj_t* target;
1639
1640 if (sscanf(args, "%d %i", &index, &health) != 2)
1641 return false;
1642
1643 target = dsda_FindMobj(index);
1644
1645 if (!target)
1646 return false;
1647
1648 target->health = health;
1649 if (target->player)
1650 target->player->health = health;
1651
1652 return true;
1653 }
1654
1655 static dboolean console_MobjMove(const char* command, const char* args) {
1656 fixed_t x, y;
1657 int index;
1658 mobj_t* target;
1659
1660 if (sscanf(args, "%d %d %d", &index, &x, &y) != 3)
1661 return false;
1662
1663 x <<= FRACBITS;
1664 y <<= FRACBITS;
1665
1666 target = dsda_FindMobj(index);
1667
1668 return console_MoveMobj(target, x, y);
1669 }
1670
1671 static dboolean console_MobjSetTarget(const char* command, const char* args) {
1672 int index;
1673 mobj_t* target;
1674 int new_target_index;
1675 mobj_t* new_target;
1676
1677 if (sscanf(args, "%d %d", &index, &new_target_index) != 2)
1678 return false;
1679
1680 target = dsda_FindMobj(index);
1681 new_target = dsda_FindMobj(new_target_index);
1682
1683 return console_SetTarget(target, new_target);
1684 }
1685
1686 static dboolean console_MobjTargetPlayer(const char* command, const char* args) {
1687 int index;
1688 mobj_t* target;
1689
1690 if (sscanf(args, "%d", &index) != 1)
1691 return false;
1692
1693 target = dsda_FindMobj(index);
1694
1695 return console_SetTarget(target, target_player.mo);
1696 }
1697
1698 static dboolean console_MobjActivateLine(const char* command, const char* args) {
1699 int id;
1700 int index;
1701 mobj_t* target;
1702
1703 if (sscanf(args, "%d %i", &index, &id) != 2)
1704 return false;
1705
1706 target = dsda_FindMobj(index);
1707
1708 return console_ActivateLine(target, id, false);
1709 }
1710
1711 static dboolean console_MobjAddFlags(const char* command, const char* args) {
1712 int index;
1713 mobj_t* target;
1714 uint64_t flags, flags2;
1715 char flag_str[CONSOLE_ENTRY_SIZE];
1716
1717 if (sscanf(args, "%d %s", &index, flag_str) != 2)
1718 return false;
1719
1720 target = dsda_FindMobj(index);
1721
1722 if (!target)
1723 return false;
1724
1725 flags = target->flags | deh_stringToMobjFlags(flag_str);
1726 flags2 = target->flags2 | deh_stringToMBF21MobjFlags(flag_str);
1727
1728 console_SetMobjFlags(target, flags, flags2);
1729
1730 return true;
1731 }
1732
1733 static dboolean console_MobjRemoveFlags(const char* command, const char* args) {
1734 int index;
1735 mobj_t* target;
1736 uint64_t flags, flags2;
1737 char flag_str[CONSOLE_ENTRY_SIZE];
1738
1739 if (sscanf(args, "%d %s", &index, flag_str) != 2)
1740 return false;
1741
1742 target = dsda_FindMobj(index);
1743
1744 if (!target)
1745 return false;
1746
1747 flags = target->flags & ~deh_stringToMobjFlags(flag_str);
1748 flags2 = target->flags2 & ~deh_stringToMBF21MobjFlags(flag_str);
1749
1750 console_SetMobjFlags(target, flags, flags2);
1751
1752 return true;
1753 }
1754
1755 static dboolean console_MobjSetFlags(const char* command, const char* args) {
1756 int index;
1757 mobj_t* target;
1758 uint64_t flags, flags2;
1759 char flag_str[CONSOLE_ENTRY_SIZE];
1760
1761 if (sscanf(args, "%d %s", &index, flag_str) != 2)
1762 return false;
1763
1764 target = dsda_FindMobj(index);
1765
1766 if (!target)
1767 return false;
1768
1769 flags = deh_stringToMobjFlags(flag_str);
1770 flags2 = deh_stringToMBF21MobjFlags(flag_str);
1771
1772 console_SetMobjFlags(target, flags, flags2);
1773
1774 return true;
1775 }
1776
1777 static dboolean console_BossActivateLine(const char* command, const char* args) {
1778 int id;
1779 int index;
1780 mobj_t* target;
1781
1782 if (sscanf(args, "%d %i", &index, &id) != 2)
1783 return false;
1784
1785 target = dsda_FindMobj(index);
1786
1787 return console_ActivateLine(target, id, true);
1788 }
1789
1790 static dboolean console_Spawn(const char* command, const char* args) {
1791 fixed_t x, y, z;
1792 int type;
1793
1794 if (sscanf(args, "%d %d %d %d", &x, &y, &z, &type) != 4 || type < 0)
1795 return false;
1796
1797 x <<= FRACBITS;
1798 y <<= FRACBITS;
1799 z <<= FRACBITS;
1800
1801 type = dsda_FindDehMobjIndex(type - 1);
1802
1803 if (type == DEH_INDEX_NOT_FOUND)
1804 return false;
1805
1806 return P_SpawnMobj(x, y, z, type) != NULL;
1807 }
1808
1809 static dboolean console_StateSetTics(const char* command, const char* args) {
1810 int id;
1811 int value;
1812
1813 if (sscanf(args, "%d %i", &id, &value) != 2 || id < 0 || id >= num_states)
1814 return false;
1815
1816 states[id].tics = value;
1817
1818 return true;
1819 }
1820
1821 static dboolean console_StateSetMisc1(const char* command, const char* args) {
1822 int id;
1823 int value;
1824
1825 if (sscanf(args, "%d %i", &id, &value) != 2 || id < 0 || id >= num_states)
1826 return false;
1827
1828 states[id].misc1 = value;
1829
1830 return true;
1831 }
1832
1833 static dboolean console_StateSetMisc2(const char* command, const char* args) {
1834 int id;
1835 int value;
1836
1837 if (sscanf(args, "%d %i", &id, &value) != 2 || id < 0 || id >= num_states)
1838 return false;
1839
1840 states[id].misc2 = value;
1841
1842 return true;
1843 }
1844
1845 static dboolean console_StateSetArgs1(const char* command, const char* args) {
1846 int id;
1847 statearg_t value;
1848
1849 if (sscanf(args, "%d %lli", &id, &value) != 2 || id < 0 || id >= num_states)
1850 return false;
1851
1852 states[id].args[0] = value;
1853
1854 return true;
1855 }
1856
1857 static dboolean console_StateSetArgs2(const char* command, const char* args) {
1858 int id;
1859 statearg_t value;
1860
1861 if (sscanf(args, "%d %lli", &id, &value) != 2 || id < 0 || id >= num_states)
1862 return false;
1863
1864 states[id].args[1] = value;
1865
1866 return true;
1867 }
1868
1869 static dboolean console_StateSetArgs3(const char* command, const char* args) {
1870 int id;
1871 statearg_t value;
1872
1873 if (sscanf(args, "%d %lli", &id, &value) != 2 || id < 0 || id >= num_states)
1874 return false;
1875
1876 states[id].args[2] = value;
1877
1878 return true;
1879 }
1880
1881 static dboolean console_StateSetArgs4(const char* command, const char* args) {
1882 int id;
1883 statearg_t value;
1884
1885 if (sscanf(args, "%d %lli", &id, &value) != 2 || id < 0 || id >= num_states)
1886 return false;
1887
1888 states[id].args[3] = value;
1889
1890 return true;
1891 }
1892
1893 static dboolean console_StateSetArgs5(const char* command, const char* args) {
1894 int id;
1895 statearg_t value;
1896
1897 if (sscanf(args, "%d %lli", &id, &value) != 2 || id < 0 || id >= num_states)
1898 return false;
1899
1900 states[id].args[4] = value;
1901
1902 return true;
1903 }
1904
1905 static dboolean console_StateSetArgs6(const char* command, const char* args) {
1906 int id;
1907 statearg_t value;
1908
1909 if (sscanf(args, "%d %lli", &id, &value) != 2 || id < 0 || id >= num_states)
1910 return false;
1911
1912 states[id].args[5] = value;
1913
1914 return true;
1915 }
1916
1917 static dboolean console_StateSetArgs7(const char* command, const char* args) {
1918 int id;
1919 statearg_t value;
1920
1921 if (sscanf(args, "%d %lli", &id, &value) != 2 || id < 0 || id >= num_states)
1922 return false;
1923
1924 states[id].args[6] = value;
1925
1926 return true;
1927 }
1928
1929 static dboolean console_StateSetArgs8(const char* command, const char* args) {
1930 int id;
1931 statearg_t value;
1932
1933 if (sscanf(args, "%d %lli", &id, &value) != 2 || id < 0 || id >= num_states)
1934 return false;
1935
1936 states[id].args[7] = value;
1937
1938 return true;
1939 }
1940
1941 static dboolean console_MobjInfoSetHealth(const char* command, const char* args) {
1942 int type;
1943 int value;
1944
1945 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
1946 return false;
1947
1948 type = dsda_FindDehMobjIndex(type - 1);
1949
1950 if (type == DEH_INDEX_NOT_FOUND)
1951 return false;
1952
1953 mobjinfo[type].spawnhealth = value;
1954
1955 return true;
1956 }
1957
1958 static dboolean console_MobjInfoSetRadius(const char* command, const char* args) {
1959 int type;
1960 int value;
1961
1962 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
1963 return false;
1964
1965 type = dsda_FindDehMobjIndex(type - 1);
1966
1967 if (type == DEH_INDEX_NOT_FOUND)
1968 return false;
1969
1970 value <<= FRACBITS;
1971
1972 mobjinfo[type].radius = value;
1973
1974 return true;
1975 }
1976
1977 static dboolean console_MobjInfoSetHeight(const char* command, const char* args) {
1978 int type;
1979 int value;
1980
1981 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
1982 return false;
1983
1984 type = dsda_FindDehMobjIndex(type - 1);
1985
1986 if (type == DEH_INDEX_NOT_FOUND)
1987 return false;
1988
1989 value <<= FRACBITS;
1990
1991 mobjinfo[type].height = value;
1992
1993 return true;
1994 }
1995
1996 static dboolean console_MobjInfoSetMass(const char* command, const char* args) {
1997 int type;
1998 int value;
1999
2000 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
2001 return false;
2002
2003 type = dsda_FindDehMobjIndex(type - 1);
2004
2005 if (type == DEH_INDEX_NOT_FOUND)
2006 return false;
2007
2008 mobjinfo[type].mass = value;
2009
2010 return true;
2011 }
2012
2013 static dboolean console_MobjInfoSetDamage(const char* command, const char* args) {
2014 int type;
2015 int value;
2016
2017 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
2018 return false;
2019
2020 type = dsda_FindDehMobjIndex(type - 1);
2021
2022 if (type == DEH_INDEX_NOT_FOUND)
2023 return false;
2024
2025 mobjinfo[type].damage = value;
2026
2027 return true;
2028 }
2029
2030 static dboolean console_MobjInfoSetSpeed(const char* command, const char* args) {
2031 int type;
2032 int value;
2033
2034 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
2035 return false;
2036
2037 type = dsda_FindDehMobjIndex(type - 1);
2038
2039 if (type == DEH_INDEX_NOT_FOUND)
2040 return false;
2041
2042 mobjinfo[type].speed = value;
2043
2044 return true;
2045 }
2046
2047 static dboolean console_MobjInfoSetFastSpeed(const char* command, const char* args) {
2048 int type;
2049 int value;
2050
2051 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
2052 return false;
2053
2054 type = dsda_FindDehMobjIndex(type - 1);
2055
2056 if (type == DEH_INDEX_NOT_FOUND)
2057 return false;
2058
2059 mobjinfo[type].altspeed = value;
2060
2061 return true;
2062 }
2063
2064 static dboolean console_MobjInfoSetMeleeRange(const char* command, const char* args) {
2065 int type;
2066 int value;
2067
2068 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
2069 return false;
2070
2071 type = dsda_FindDehMobjIndex(type - 1);
2072
2073 if (type == DEH_INDEX_NOT_FOUND)
2074 return false;
2075
2076 value <<= FRACBITS;
2077
2078 mobjinfo[type].meleerange = value;
2079
2080 return true;
2081 }
2082
2083 static dboolean console_MobjInfoSetReactionTime(const char* command, const char* args) {
2084 int type;
2085 int value;
2086
2087 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
2088 return false;
2089
2090 type = dsda_FindDehMobjIndex(type - 1);
2091
2092 if (type == DEH_INDEX_NOT_FOUND)
2093 return false;
2094
2095 mobjinfo[type].reactiontime = value;
2096
2097 return true;
2098 }
2099
2100 static dboolean console_MobjInfoSetPainChance(const char* command, const char* args) {
2101 int type;
2102 int value;
2103
2104 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
2105 return false;
2106
2107 type = dsda_FindDehMobjIndex(type - 1);
2108
2109 if (type == DEH_INDEX_NOT_FOUND)
2110 return false;
2111
2112 mobjinfo[type].painchance = value;
2113
2114 return true;
2115 }
2116
2117 static dboolean console_MobjInfoSetInfightingGroup(const char* command, const char* args) {
2118 int type;
2119 int value;
2120
2121 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
2122 return false;
2123
2124 type = dsda_FindDehMobjIndex(type - 1);
2125
2126 if (type == DEH_INDEX_NOT_FOUND)
2127 return false;
2128
2129 if (value < 0)
2130 value = IG_DEFAULT;
2131 else
2132 value += IG_END;
2133
2134 mobjinfo[type].infighting_group = value;
2135
2136 return true;
2137 }
2138
2139 static dboolean console_MobjInfoSetProjectileGroup(const char* command, const char* args) {
2140 int type;
2141 int value;
2142
2143 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
2144 return false;
2145
2146 type = dsda_FindDehMobjIndex(type - 1);
2147
2148 if (type == DEH_INDEX_NOT_FOUND)
2149 return false;
2150
2151 if (value < 0)
2152 value = PG_GROUPLESS;
2153 else
2154 value += PG_END;
2155
2156 mobjinfo[type].projectile_group = value;
2157
2158 return true;
2159 }
2160
2161 static dboolean console_MobjInfoSetSplashGroup(const char* command, const char* args) {
2162 int type;
2163 int value;
2164
2165 if (sscanf(args, "%d %i", &type, &value) != 2 || type < 0)
2166 return false;
2167
2168 type = dsda_FindDehMobjIndex(type - 1);
2169
2170 if (type == DEH_INDEX_NOT_FOUND)
2171 return false;
2172
2173 if (value < 0)
2174 value = SG_DEFAULT;
2175 else
2176 value += SG_END;
2177
2178 mobjinfo[type].splash_group = value;
2179
2180 return true;
2181 }
2182
2183 static dboolean console_MobjInfoAddFlags(const char* command, const char* args) {
2184 int type;
2185 char flag_str[CONSOLE_ENTRY_SIZE];
2186
2187 if (sscanf(args, "%d %s", &type, flag_str) != 2 || type < 0)
2188 return false;
2189
2190 type = dsda_FindDehMobjIndex(type - 1);
2191
2192 if (type == DEH_INDEX_NOT_FOUND)
2193 return false;
2194
2195 mobjinfo[type].flags |= deh_stringToMobjFlags(flag_str);
2196 mobjinfo[type].flags2 |= deh_stringToMBF21MobjFlags(flag_str);
2197
2198 return true;
2199 }
2200
2201 static dboolean console_MobjInfoRemoveFlags(const char* command, const char* args) {
2202 int type;
2203 char flag_str[CONSOLE_ENTRY_SIZE];
2204
2205 if (sscanf(args, "%d %s", &type, flag_str) != 2 || type < 0)
2206 return false;
2207
2208 type = dsda_FindDehMobjIndex(type - 1);
2209
2210 if (type == DEH_INDEX_NOT_FOUND)
2211 return false;
2212
2213 mobjinfo[type].flags &= ~deh_stringToMobjFlags(flag_str);
2214 mobjinfo[type].flags2 &= ~deh_stringToMBF21MobjFlags(flag_str);
2215
2216 return true;
2217 }
2218
2219 static dboolean console_MobjInfoSetFlags(const char* command, const char* args) {
2220 int type;
2221 char flag_str[CONSOLE_ENTRY_SIZE];
2222
2223 if (sscanf(args, "%d %s", &type, flag_str) != 2 || type < 0)
2224 return false;
2225
2226 type = dsda_FindDehMobjIndex(type - 1);
2227
2228 if (type == DEH_INDEX_NOT_FOUND)
2229 return false;
2230
2231 mobjinfo[type].flags = deh_stringToMobjFlags(flag_str);
2232 mobjinfo[type].flags2 = deh_stringToMBF21MobjFlags(flag_str);
2233
2234 return true;
2235 }
2236
2237 static dboolean console_MusicRestart(const char* command, const char* args) {
2238 S_StopMusic();
2239 S_RestartMusic();
2240
2241 return true;
2242 }
2243
2244 static dboolean console_AllGhosts(const char* command, const char* args) {
2245 if (bmapwidth)
2246 bmapwidth = 0;
2247 else
2248 P_RestoreOriginalBlockMap();
2249
2250 return true;
2251 }
2252
2253 typedef dboolean (*console_command_t)(const char*, const char*);
2254
2255 typedef struct {
2256 const char* command_name;
2257 console_command_t command;
2258 int flags;
2259 } console_command_entry_t;
2260
2261 static console_command_entry_t console_commands[] = {
2262 // commands
2263 { "player.set_health", console_PlayerSetHealth, CF_NEVER },
2264 { "player.set_armor", console_PlayerSetArmor, CF_NEVER },
2265 { "player.give_weapon", console_PlayerGiveWeapon, CF_NEVER },
2266 { "player.give_ammo", console_PlayerGiveAmmo, CF_NEVER },
2267 { "player.set_ammo", console_PlayerSetAmmo, CF_NEVER },
2268 { "player.give_key", console_PlayerGiveKey, CF_NEVER },
2269 { "player.remove_key", console_PlayerRemoveKey, CF_NEVER },
2270 { "player.give_power", console_PlayerGivePower, CF_NEVER },
2271 { "player.remove_power", console_PlayerRemovePower, CF_NEVER },
2272 { "player.set_x", console_PlayerSetX, CF_NEVER },
2273 { "player.set_y", console_PlayerSetY, CF_NEVER },
2274 { "player.set_z", console_PlayerSetZ, CF_NEVER },
2275 { "player.round_x", console_PlayerRoundX, CF_NEVER },
2276 { "player.round_y", console_PlayerRoundY, CF_NEVER },
2277 { "player.round_xy", console_PlayerRoundXY, CF_NEVER },
2278 { "player.set_angle", console_PlayerSetAngle, CF_NEVER },
2279 { "player.round_angle", console_PlayerRoundAngle, CF_NEVER },
2280 { "player.set_vx", console_PlayerSetVX, CF_NEVER },
2281 { "player.set_vy", console_PlayerSetVY, CF_NEVER },
2282 { "player.set_vz", console_PlayerSetVZ, CF_NEVER },
2283 { "player.kill", console_PlayerKill, CF_NEVER },
2284
2285 { "music.restart", console_MusicRestart, CF_ALWAYS },
2286
2287 { "level.exit", console_LevelExit, CF_NEVER },
2288 { "level.secret_exit", console_LevelSecretExit, CF_NEVER },
2289
2290 { "script.run", console_ScriptRun, CF_ALWAYS },
2291 { "check", console_Check, CF_ALWAYS },
2292 { "assign", console_Assign, CF_ALWAYS },
2293 { "update", console_Update, CF_ALWAYS },
2294 { "toggle_assign", console_ToggleAssign, CF_ALWAYS },
2295 { "toggle_update", console_ToggleUpdate, CF_ALWAYS },
2296 { "config.forget", console_ConfigForget, CF_ALWAYS },
2297 { "config.remember", console_ConfigRemember, CF_ALWAYS },
2298 { "wad_stats.forget", console_WadStatsForget, CF_ALWAYS },
2299 { "wad_stats.remember", console_WadStatsRemember, CF_ALWAYS },
2300 { "free_text.update", console_FreeTextUpdate, CF_ALWAYS },
2301 { "free_text.clear", console_FreeTextClear, CF_ALWAYS },
2302
2303 // tracking
2304 { "tracker.add_line", console_TrackerAddLine, CF_DEMO },
2305 { "t.al", console_TrackerAddLine, CF_DEMO },
2306 { "tracker.remove_line", console_TrackerRemoveLine, CF_DEMO },
2307 { "t.rl", console_TrackerRemoveLine, CF_DEMO },
2308 { "tracker.add_line_distance", console_TrackerAddLineDistance, CF_DEMO },
2309 { "t.ald", console_TrackerAddLineDistance, CF_DEMO },
2310 { "tracker.remove_line_distance", console_TrackerRemoveLineDistance, CF_DEMO },
2311 { "t.rld", console_TrackerRemoveLineDistance, CF_DEMO },
2312 { "tracker.add_sector", console_TrackerAddSector, CF_DEMO },
2313 { "t.as", console_TrackerAddSector, CF_DEMO },
2314 { "tracker.remove_sector", console_TrackerRemoveSector, CF_DEMO },
2315 { "t.rs", console_TrackerRemoveSector, CF_DEMO },
2316 { "tracker.add_mobj", console_TrackerAddMobj, CF_DEMO },
2317 { "t.am", console_TrackerAddMobj, CF_DEMO },
2318 { "tracker.remove_mobj", console_TrackerRemoveMobj, CF_DEMO },
2319 { "t.rm", console_TrackerRemoveMobj, CF_DEMO },
2320 { "tracker.add_player", console_TrackerAddPlayer, CF_DEMO },
2321 { "t.ap", console_TrackerAddPlayer, CF_DEMO },
2322 { "tracker.remove_player", console_TrackerRemovePlayer, CF_DEMO },
2323 { "t.rp", console_TrackerRemovePlayer, CF_DEMO },
2324 { "tracker.reset", console_TrackerReset, CF_DEMO },
2325 { "t.r", console_TrackerReset, CF_DEMO },
2326
2327 // thing manipulation
2328 { "target.spawn", console_TargetSpawn, CF_NEVER },
2329 { "target.see", console_TargetSee, CF_NEVER },
2330 { "target.pain", console_TargetPain, CF_NEVER },
2331 { "target.melee", console_TargetMelee, CF_NEVER },
2332 { "target.missile", console_TargetMissile, CF_NEVER },
2333 { "target.death", console_TargetDeath, CF_NEVER },
2334 { "target.xdeath", console_TargetXDeath, CF_NEVER },
2335 { "target.raise", console_TargetRaise, CF_NEVER },
2336 { "target.set_state", console_TargetSetState, CF_NEVER },
2337 { "target.set_health", console_TargetSetHealth, CF_NEVER },
2338 { "target.move", console_TargetMove, CF_NEVER },
2339 { "target.set_target", console_TargetSetTarget, CF_NEVER },
2340 { "target.target_player", console_TargetTargetPlayer, CF_NEVER },
2341 { "target.add_flags", console_TargetAddFlags, CF_NEVER },
2342 { "target.remove_flags", console_TargetRemoveFlags, CF_NEVER },
2343 { "target.set_flags", console_TargetSetFlags, CF_NEVER },
2344
2345 { "mobj.spawn", console_MobjSpawn, CF_NEVER },
2346 { "mobj.see", console_MobjSee, CF_NEVER },
2347 { "mobj.pain", console_MobjPain, CF_NEVER },
2348 { "mobj.melee", console_MobjMelee, CF_NEVER },
2349 { "mobj.missile", console_MobjMissile, CF_NEVER },
2350 { "mobj.death", console_MobjDeath, CF_NEVER },
2351 { "mobj.xdeath", console_MobjXDeath, CF_NEVER },
2352 { "mobj.raise", console_MobjRaise, CF_NEVER },
2353 { "mobj.set_state", console_MobjSetState, CF_NEVER },
2354 { "mobj.set_health", console_MobjSetHealth, CF_NEVER },
2355 { "mobj.move", console_MobjMove, CF_NEVER },
2356 { "mobj.set_target", console_MobjSetTarget, CF_NEVER },
2357 { "mobj.target_player", console_MobjTargetPlayer, CF_NEVER },
2358 { "mobj.add_flags", console_MobjAddFlags, CF_NEVER },
2359 { "mobj.remove_flags", console_MobjRemoveFlags, CF_NEVER },
2360 { "mobj.set_flags", console_MobjSetFlags, CF_NEVER },
2361
2362 { "spawn", console_Spawn, CF_NEVER },
2363
2364 // lines
2365 { "player.activate_line", console_PlayerActivateLine, CF_NEVER },
2366 { "target.activate_line", console_TargetActivateLine, CF_NEVER },
2367 { "mobj.activate_line", console_MobjActivateLine, CF_NEVER },
2368 { "boss.activate_line", console_BossActivateLine, CF_NEVER },
2369
2370 // states
2371 { "state.set_tics", console_StateSetTics, CF_NEVER },
2372 { "state.set_misc1", console_StateSetMisc1, CF_NEVER },
2373 { "state.set_misc2", console_StateSetMisc2, CF_NEVER },
2374 { "state.set_args1", console_StateSetArgs1, CF_NEVER },
2375 { "state.set_args2", console_StateSetArgs2, CF_NEVER },
2376 { "state.set_args3", console_StateSetArgs3, CF_NEVER },
2377 { "state.set_args4", console_StateSetArgs4, CF_NEVER },
2378 { "state.set_args5", console_StateSetArgs5, CF_NEVER },
2379 { "state.set_args6", console_StateSetArgs6, CF_NEVER },
2380 { "state.set_args7", console_StateSetArgs7, CF_NEVER },
2381 { "state.set_args8", console_StateSetArgs8, CF_NEVER },
2382
2383 // mobjinfo
2384 { "mobjinfo.set_health", console_MobjInfoSetHealth, CF_NEVER },
2385 { "mobjinfo.set_radius", console_MobjInfoSetRadius, CF_NEVER },
2386 { "mobjinfo.set_height", console_MobjInfoSetHeight, CF_NEVER },
2387 { "mobjinfo.set_mass", console_MobjInfoSetMass, CF_NEVER },
2388 { "mobjinfo.set_damage", console_MobjInfoSetDamage, CF_NEVER },
2389 { "mobjinfo.set_speed", console_MobjInfoSetSpeed, CF_NEVER },
2390 { "mobjinfo.set_fast_speed", console_MobjInfoSetFastSpeed, CF_NEVER },
2391 { "mobjinfo.set_melee_range", console_MobjInfoSetMeleeRange, CF_NEVER },
2392 { "mobjinfo.set_reaction_time", console_MobjInfoSetReactionTime, CF_NEVER },
2393 { "mobjinfo.set_pain_chance", console_MobjInfoSetPainChance, CF_NEVER },
2394 { "mobjinfo.set_infighting_group", console_MobjInfoSetInfightingGroup, CF_NEVER },
2395 { "mobjinfo.set_projectile_group", console_MobjInfoSetProjectileGroup, CF_NEVER },
2396 { "mobjinfo.set_splash_group", console_MobjInfoSetSplashGroup, CF_NEVER },
2397 { "mobjinfo.add_flags", console_MobjInfoAddFlags, CF_NEVER },
2398 { "mobjinfo.remove_flags", console_MobjInfoRemoveFlags, CF_NEVER },
2399 { "mobjinfo.set_flags", console_MobjInfoSetFlags, CF_NEVER },
2400
2401 // traversing time
2402 { "jump.to_tic", console_JumpToTic, CF_DEMO },
2403 { "jump.by_tic", console_JumpByTic, CF_DEMO },
2404
2405 // build mode
2406 { "brute_force.start", console_BruteForceStart, CF_DEMO },
2407 { "bf.start", console_BruteForceStart, CF_DEMO },
2408 { "brute_force.frame", console_BruteForceFrame, CF_DEMO },
2409 { "bf.frame", console_BruteForceFrame, CF_DEMO },
2410 { "brute_force.keep", console_BruteForceKeep, CF_DEMO },
2411 { "bf.keep", console_BruteForceKeep, CF_DEMO },
2412 { "brute_force.nomonsters", console_BruteForceNoMonsters, CF_DEMO },
2413 { "bf.nomo", console_BruteForceNoMonsters, CF_DEMO },
2414 { "brute_force.monsters", console_BruteForceMonsters, CF_DEMO },
2415 { "bf.mo", console_BruteForceMonsters, CF_DEMO },
2416 { "build.turbo", console_BuildTurbo, CF_DEMO },
2417 { "b.turbo", console_BuildTurbo, CF_DEMO },
2418 { "mf", console_BuildMF, CF_DEMO },
2419 { "mb", console_BuildMB, CF_DEMO },
2420 { "sr", console_BuildSR, CF_DEMO },
2421 { "sl", console_BuildSL, CF_DEMO },
2422 { "tr", console_BuildTR, CF_DEMO },
2423 { "tl", console_BuildTL, CF_DEMO },
2424 { "fu", console_BuildFU, CF_DEMO },
2425 { "fd", console_BuildFD, CF_DEMO },
2426 { "fc", console_BuildFC, CF_DEMO },
2427 { "lu", console_BuildLU, CF_DEMO },
2428 { "ld", console_BuildLD, CF_DEMO },
2429 { "lc", console_BuildLC, CF_DEMO },
2430 { "ua", console_BuildUA, CF_DEMO },
2431
2432 // demos
2433 { "demo.export", console_DemoExport, CF_ALWAYS },
2434 { "demo.start", console_DemoStart, CF_NEVER },
2435 { "demo.stop", console_DemoStop, CF_ALWAYS },
2436 { "demo.join", console_DemoJoin, CF_ALWAYS },
2437
2438 { "game.quit", console_GameQuit, CF_ALWAYS },
2439 { "game.describe", console_GameDescribe, CF_ALWAYS },
2440
2441 // cheats
2442 { "idchoppers", console_BasicCheat, CF_DEMO },
2443 { "iddqd", console_BasicCheat, CF_DEMO },
2444 { "idkfa", console_BasicCheat, CF_DEMO },
2445 { "idfa", console_BasicCheat, CF_DEMO },
2446 { "idspispopd", console_BasicCheat, CF_DEMO },
2447 { "idclip", console_BasicCheat, CF_DEMO },
2448 { "idmypos", console_BasicCheat, CF_DEMO },
2449 { "idrate", console_BasicCheat, CF_DEMO },
2450 { "iddt", console_IDDT, CF_DEMO },
2451 { "iddst", console_BasicCheat, CF_DEMO },
2452 { "iddkt", console_BasicCheat, CF_DEMO },
2453 { "iddit", console_BasicCheat, CF_DEMO },
2454 { "idclev", console_BasicCheat, CF_DEMO },
2455 { "idmus", console_BasicCheat, CF_DEMO },
2456 { "idbeholdv", console_BasicCheat, CF_DEMO },
2457 { "idbeholds", console_BasicCheat, CF_DEMO },
2458 { "idbeholdi", console_BasicCheat, CF_DEMO },
2459 { "idbeholdr", console_BasicCheat, CF_DEMO },
2460 { "idbeholda", console_BasicCheat, CF_DEMO },
2461 { "idbeholdl", console_BasicCheat, CF_DEMO },
2462
2463 { "skill", console_BasicCheat, CF_DEMO },
2464 { "tntcomp", console_BasicCheat, CF_DEMO },
2465 { "tntem", console_BasicCheat, CF_DEMO },
2466 { "tnthom", console_BasicCheat, CF_DEMO },
2467 { "tntka", console_BasicCheat, CF_DEMO },
2468 { "tntsmart", console_BasicCheat, CF_DEMO },
2469 { "tntpitch", console_BasicCheat, CF_DEMO },
2470 { "tntfast", console_BasicCheat, CF_DEMO },
2471 { "tntice", console_BasicCheat, CF_DEMO },
2472 { "tntpush", console_BasicCheat, CF_DEMO },
2473
2474 { "notarget", console_BasicCheat, CF_DEMO },
2475 { "fly", console_BasicCheat, CF_DEMO },
2476 { "fullclip", console_CheatFullClip, CF_NEVER },
2477 { "freeze", console_Freeze, CF_NEVER },
2478 { "nosleep", console_NoSleep, CF_NEVER },
2479 { "allghosts", console_AllGhosts, CF_NEVER },
2480
2481 { "quicken", console_BasicCheat, CF_DEMO },
2482 { "ponce", console_BasicCheat, CF_DEMO },
2483 { "kitty", console_BasicCheat, CF_DEMO },
2484 { "massacre", console_BasicCheat, CF_DEMO },
2485 { "rambo", console_BasicCheat, CF_DEMO },
2486 { "skel", console_BasicCheat, CF_DEMO },
2487 { "shazam", console_BasicCheat, CF_DEMO },
2488 { "ravmap", console_IDDT, CF_DEMO },
2489 { "cockadoodledoo", console_BasicCheat, CF_DEMO },
2490 { "gimme", console_BasicCheat, CF_DEMO },
2491 { "engage", console_BasicCheat, CF_DEMO },
2492
2493 { "satan", console_BasicCheat, CF_DEMO },
2494 { "clubmed", console_BasicCheat, CF_DEMO },
2495 { "butcher", console_BasicCheat, CF_DEMO },
2496 { "nra", console_BasicCheat, CF_DEMO },
2497 { "indiana", console_BasicCheat, CF_DEMO },
2498 { "locksmith", console_BasicCheat, CF_DEMO },
2499 { "sherlock", console_BasicCheat, CF_DEMO },
2500 { "casper", console_BasicCheat, CF_DEMO },
2501 { "init", console_BasicCheat, CF_DEMO },
2502 { "mapsco", console_IDDT, CF_DEMO },
2503 { "deliverance", console_BasicCheat, CF_DEMO },
2504 { "shadowcaster", console_BasicCheat, CF_DEMO },
2505 { "visit", console_BasicCheat, CF_DEMO },
2506 { "puke", console_BasicCheat, CF_DEMO },
2507
2508 // exit
2509 { "exit", console_Exit, CF_ALWAYS },
2510 { "quit", console_Exit, CF_ALWAYS },
2511 { NULL }
2512 };
2513
2514 static void dsda_AddConsoleMessage(const char* message) {
2515 strncpy(console_message_entry, message, CONSOLE_ENTRY_SIZE - 1);
2516 }
2517
2518 static dboolean dsda_AuthorizeCommand(console_command_entry_t* entry) {
2519 if (!(entry->flags & CF_DEMO) && (demorecording || demoplayback)) {
2520 dsda_AddConsoleMessage("command not allowed in demo mode");
2521 return false;
2522 }
2523
2524 if (!(entry->flags & CF_STRICT) && dsda_StrictMode()) {
2525 dsda_AddConsoleMessage("command not allowed in strict mode");
2526 return false;
2527 }
2528
2529 if (gamestate != GS_LEVEL) {
2530 dsda_AddConsoleMessage("command only allowed during levels");
2531 return false;
2532 }
2533
2534 return true;
2535 }
2536
2537 static dboolean dsda_ExecuteConsole(const char* command_line, dboolean noise) {
2538 char command[CONSOLE_ENTRY_SIZE];
2539 char args[CONSOLE_ENTRY_SIZE];
2540 int scan_count;
2541 dboolean ret = true;
2542
2543 scan_count = sscanf(command_line, "%s %[^;]", command, args);
2544
2545 if (scan_count) {
2546 console_command_entry_t* entry;
2547
2548 if (scan_count == 1) args[0] = '\0';
2549
2550 for (entry = console_commands; entry->command; entry++) {
2551 if (!stricmp(command, entry->command_name)) {
2552 if (dsda_AuthorizeCommand(entry)) {
2553 if (entry->command(command, args)) {
2554 dsda_AddConsoleMessage("command executed");
2555
2556 if (noise)
2557 S_StartVoidSound(g_sfx_console);
2558 }
2559 else {
2560 dsda_AddConsoleMessage("command invalid");
2561 ret = false;
2562
2563 if (noise)
2564 S_StartVoidSound(g_sfx_oof);
2565 }
2566 }
2567 else {
2568 ret = false;
2569
2570 if (noise)
2571 S_StartVoidSound(g_sfx_oof);
2572 }
2573
2574 break;
2575 }
2576 }
2577
2578 if (!entry->command) {
2579 dsda_AddConsoleMessage("command unknown");
2580 ret = false;
2581
2582 if (noise)
2583 S_StartVoidSound(g_sfx_oof);
2584 }
2585 }
2586
2587 return ret;
2588 }
2589
2590 void dsda_UpdateConsoleText(char* text) {
2591 int i;
2592 int length;
2593
2594 length = strlen(text);
2595
2596 for (i = 0; i < length; ++i) {
2597 int shift_i;
2598
2599 if (text[i] < 32 || text[i] > 126)
2600 continue;
2601
2602 if (console_entry_index > CONSOLE_ENTRY_SIZE - 2)
2603 console_entry_index = CONSOLE_ENTRY_SIZE - 2;
2604
2605 for (shift_i = strlen(console_entry->text) - 1; shift_i > console_entry_index; --shift_i)
2606 console_entry->text[shift_i] = console_entry->text[shift_i - 1];
2607
2608 console_entry->text[console_entry_index] = tolower(text[i]);
2609 ++console_entry_index;
2610 }
2611
2612 dsda_UpdateConsoleDisplay();
2613 }
2614
2615 void dsda_UpdateConsoleHistory(void) {
2616 console_entry_t* last_command;
2617
2618 if (console_entry != console_history_head)
2619 strcpy(console_history_head->text, console_entry->text);
2620
2621 last_command = console_history_head->prev;
2622 if (!last_command || strcmp(last_command->text, console_entry->text)) {
2623 console_entry_t* new_head;
2624
2625 new_head = Z_Calloc(sizeof(*new_head), 1);
2626 new_head->prev = console_history_head;
2627 console_history_head->next = new_head;
2628 console_history_head = new_head;
2629 }
2630 else
2631 memset(console_history_head->text, 0, CONSOLE_ENTRY_SIZE);
2632
2633 console_entry = console_history_head;
2634 }
2635
2636 void dsda_InterpretConsoleCommands(const char* str, dboolean noise, dboolean raise_errors) {
2637 int line;
2638 char* entry;
2639 char** lines;
2640
2641 entry = Z_Strdup(str);
2642 lines = dsda_SplitString(entry, ";");
2643 for (line = 0; lines[line]; ++line)
2644 if (!dsda_ExecuteConsole(lines[line], noise) && raise_errors)
2645 I_Error("Console command failed: %s", lines[line]);
2646
2647 Z_Free(lines);
2648 Z_Free(entry);
2649 }
2650
2651 void dsda_UpdateConsole(int action) {
2652 if (action == MENU_BACKSPACE && console_entry_index > 0) {
2653 int shift_i;
2654
2655 for (shift_i = console_entry_index; console_entry->text[shift_i]; ++shift_i)
2656 console_entry->text[shift_i - 1] = console_entry->text[shift_i];
2657 console_entry->text[shift_i - 1] = '\0';
2658
2659 --console_entry_index;
2660 dsda_UpdateConsoleDisplay();
2661 }
2662 else if (action == MENU_ENTER) {
2663 dsda_InterpretConsoleCommands(console_entry->text, true, false);
2664
2665 dsda_UpdateConsoleHistory();
2666 dsda_ResetConsoleEntry();
2667 }
2668 else if (action == MENU_UP) {
2669 if (console_entry->prev)
2670 console_entry = console_entry->prev;
2671 console_entry_index = strlen(console_entry->text);
2672 dsda_UpdateConsoleDisplay();
2673 }
2674 else if (action == MENU_DOWN) {
2675 if (console_entry->next)
2676 console_entry = console_entry->next;
2677 console_entry_index = strlen(console_entry->text);
2678 dsda_UpdateConsoleDisplay();
2679 }
2680 else if (action == MENU_RIGHT && console_entry->text[console_entry_index]) {
2681 ++console_entry_index;
2682 dsda_UpdateConsoleDisplay();
2683 }
2684 else if (action == MENU_LEFT && console_entry_index > 0) {
2685 --console_entry_index;
2686 dsda_UpdateConsoleDisplay();
2687 }
2688 }
2689
2690 void dsda_ExecuteConsoleScript(int i) {
2691 int line;
2692
2693 if (gamestate != GS_LEVEL || i < 0 || i >= CONSOLE_SCRIPT_COUNT)
2694 return;
2695
2696 if (!dsda_console_script_lines[i]) {
2697 char* dup;
2698
2699 dup = Z_Strdup(dsda_StringConfig(dsda_config_script_0 + i));
2700 dsda_console_script_lines[i] = dsda_SplitString(dup, ";");
2701 }
2702
2703 for (line = 0; dsda_console_script_lines[i][line]; ++line)
2704 if (!console_ScriptRunLine(dsda_console_script_lines[i][line])) {
2705 doom_printf("Script %d failed", i);
2706
2707 return;
2708 }
2709
2710 doom_printf("Script %d executed", i);
2711 }