1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
37 FIRST_ACTION
= ACTION_JUMP
;
38 LAST_ACTION
= ACTION_WEAPPREV
;
40 procedure g_Console_Init ();
41 procedure g_Console_Update ();
42 procedure g_Console_Draw ();
43 procedure g_Console_Switch ();
44 procedure g_Console_Char (C
: AnsiChar);
45 procedure g_Console_Control (K
: Word);
46 procedure g_Console_Process (L
: AnsiString; quiet
: Boolean=false);
47 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
48 procedure g_Console_Clear ();
49 function g_Console_CommandBlacklisted (C
: AnsiString): Boolean;
50 procedure g_Console_ReadConfig (filename
: String);
52 function g_Console_Interactive
: Boolean;
53 function g_Console_Action (action
: Integer): Boolean;
54 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
56 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
57 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
59 // <0: no arg; 0/1: true/false
60 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
62 procedure g_Console_Chat_Switch (team
: Boolean=false);
64 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
65 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
66 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
68 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
69 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
73 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
74 gChatShow
: Boolean = false;
75 gChatTeam
: Boolean = false;
76 gAllowConsoleMessages
: Boolean = true;
77 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
78 gPlayerAction
, gDefaultAction
: Array [0..1, 0..LAST_ACTION
] of Boolean; // [player, action]
83 g_textures
, g_main
, e_graphics
, e_input
, g_game
,
84 SysUtils
, g_basic
, g_options
, Math
, g_touch
,
85 g_menu
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
91 TCmdProc
= procedure (p
: SSArray
);
92 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
100 ptr
: Pointer; // various data
101 msg
: AnsiString; // message for var changes
103 action
: Integer; // >= 0 for action commands
104 player
: Integer; // used for action commands
117 MaxScriptRecursion
= 16;
119 DEBUG_STRING
= 'DEBUG MODE';
123 RecursionDepth
: Word = 0;
124 RecursionLimitHit
: Boolean = False;
126 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
129 //ConsoleHistory: SSArray;
130 CommandHistory
: SSArray
;
132 commands
: Array of TCommand
= nil;
133 Aliases
: Array of TAlias
= nil;
135 conSkipLines
: Integer = 0;
136 MsgArray
: Array [0..4] of record
141 bindDown
, bindProcess
: Boolean;
142 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
147 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
148 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
157 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
158 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
159 if (pos
> slen
) then exit
;
160 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
162 while (pos
<= slen
) do
164 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
165 res
:= res
*10+Byte(s
[pos
])-48;
168 if (pos
<= slen
) then
171 if (s
[pos
] <> '.') then exit
;
173 while (pos
<= slen
) do
175 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
177 res
+= frac
*(Byte(s
[pos
])-48);
181 if (pos
<= slen
) then exit
; // oops
186 // ////////////////////////////////////////////////////////////////////////// //
187 // <0: no arg; 0/1: true/false; 666: toggle
188 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
190 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
192 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
193 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
194 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
195 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
199 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
200 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
202 if (Length(p
) > 2) then
204 conwritefln('too many arguments to ''%s''', [p
[0]]);
208 case conGetBoolArg(p
, 1) of
210 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
211 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
212 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
214 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
215 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
219 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
223 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
224 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
226 if (Length(p
) > 2) then
228 conwritefln('too many arguments to ''%s''', [p
[0]]);
232 case conGetBoolArg(p
, 1) of
234 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
235 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
236 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
238 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
239 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
243 if (Length(p
) <> 2) then
245 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
250 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
252 conwritefln('invalid integer value: "%s"', [p
[1]]);
258 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
263 f
:= Length(commands
);
264 SetLength(commands
, f
+1);
266 cp
.cmd
:= LowerCase(conname
);
268 cp
.procEx
:= boolVarHandler
;
270 cp
.hidden
:= ahidden
;
279 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
284 f
:= Length(commands
);
285 SetLength(commands
, f
+1);
287 cp
.cmd
:= LowerCase(conname
);
289 cp
.procEx
:= intVarHandler
;
291 cp
.hidden
:= ahidden
;
300 // ////////////////////////////////////////////////////////////////////////// //
302 PVarSingle
= ^TVarSingle
;
305 min
, max
, def
: Single; // default will be starting value
309 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
315 if (Length(p
) > 2) then
317 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
320 pv
:= PVarSingle(me
.ptr
);
321 if (Length(p
) = 2) then
323 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
324 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
325 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
326 (CompareText(p
[1], 'ona') = 0) then
332 if not conParseFloat(nv
, p
[1]) then
334 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
337 if (nv
< pv
.min
) then nv
:= pv
.min
;
338 if (nv
> pv
.max
) then nv
:= pv
.max
;
343 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
344 conwritefln('%s %s', [msg
, pv
.val
^]);
348 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
354 GetMem(pv
, sizeof(TVarSingle
));
359 f
:= Length(commands
);
360 SetLength(commands
, f
+1);
362 cp
.cmd
:= LowerCase(conname
);
364 cp
.procEx
:= singleVarHandler
;
366 cp
.hidden
:= ahidden
;
375 // ////////////////////////////////////////////////////////////////////////// //
376 function GetStrACmd(var Str
: AnsiString): AnsiString;
381 for a
:= 1 to Length(Str
) do
382 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
384 Result
:= Copy(Str
, 1, a
);
391 function ParseAlias(Str
: AnsiString): SSArray
;
402 SetLength(Result
, Length(Result
)+1);
403 Result
[High(Result
)] := GetStrACmd(Str
);
407 procedure ConsoleCommands(p
: SSArray
);
413 cmd
:= LowerCase(p
[0]);
416 if cmd
= 'clear' then
418 //ConsoleHistory := nil;
422 for a
:= 0 to High(MsgArray
) do
430 if cmd
= 'clearhistory' then
431 CommandHistory
:= nil;
433 if cmd
= 'showhistory' then
434 if CommandHistory
<> nil then
437 for a
:= 0 to High(CommandHistory
) do
438 g_Console_Add(' '+CommandHistory
[a
]);
441 if cmd
= 'commands' then
444 g_Console_Add('commands list:');
445 for a
:= High(commands
) downto 0 do
447 if (Length(commands
[a
].help
) > 0) then
449 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
453 g_Console_Add(' '+commands
[a
].cmd
);
459 g_Console_Add(TimeToStr(Now
), True);
462 g_Console_Add(DateToStr(Now
), True);
465 if Length(p
) > 1 then
467 if p
[1] = 'ololo' then
472 for a
:= 1 to High(p
) do
474 g_Console_Add(b_Text_Format(s
), True);
483 if ConsoleHistory <> nil then
485 if Length(P) > 1 then
488 s := GameDir+'/console.txt';
493 if IOResult <> 0 then
495 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
500 for a := 0 to High(ConsoleHistory) do
501 WriteLn(F, ConsoleHistory[a]);
504 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
513 if Length(p
) = 2 then
515 s
:= GameDir
+ '/' + p
[1];
516 g_Console_ReadConfig(s
);
519 g_Console_Add('exec <script file>');
522 if (cmd
= 'ver') or (cmd
= 'version') then
524 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
525 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
526 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
529 if cmd
= 'alias' then
531 // alias [alias_name] [commands]
532 if Length(p
) > 1 then
534 for a
:= 0 to High(Aliases
) do
535 if Aliases
[a
].name
= p
[1] then
537 if Length(p
) > 2 then
538 Aliases
[a
].commands
:= ParseAlias(p
[2])
540 for b
:= 0 to High(Aliases
[a
].commands
) do
541 g_Console_Add(Aliases
[a
].commands
[b
]);
544 SetLength(Aliases
, Length(Aliases
)+1);
546 Aliases
[a
].name
:= p
[1];
547 if Length(p
) > 2 then
548 Aliases
[a
].commands
:= ParseAlias(p
[2])
550 for b
:= 0 to High(Aliases
[a
].commands
) do
551 g_Console_Add(Aliases
[a
].commands
[b
]);
553 for a
:= 0 to High(Aliases
) do
554 if Aliases
[a
].commands
<> nil then
555 g_Console_Add(Aliases
[a
].name
);
561 if Length(p
) > 1 then
563 if Aliases
= nil then
565 for a
:= 0 to High(Aliases
) do
566 if Aliases
[a
].name
= p
[1] then
568 if Aliases
[a
].commands
<> nil then
570 // with this system proper endless loop detection seems either impossible
571 // or very dirty to implement, so let's have this instead
572 // prevents endless loops
573 for b
:= 0 to High(Aliases
[a
].commands
) do
576 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
577 if not RecursionLimitHit
then
578 g_Console_Process(Aliases
[a
].commands
[b
], True);
581 if (RecursionDepth
= 0) and RecursionLimitHit
then
583 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
584 RecursionLimitHit
:= False;
591 g_Console_Add('call <alias name>');
598 procedure WhitelistCommand(cmd
: AnsiString);
602 SetLength(Whitelist
, Length(Whitelist
)+1);
603 a
:= High(Whitelist
);
604 Whitelist
[a
] := LowerCase(cmd
);
607 procedure segfault (p
: SSArray
);
614 procedure BindCommands (p
: SSArray
);
615 var cmd
, key
, act
: AnsiString; i
, j
: Integer;
617 cmd
:= LowerCase(p
[0]);
620 // bind <key> <action>
621 if Length(p
) = 3 then
623 key
:= LowerCase(p
[1]);
625 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
626 if i
< e_MaxInputKeys
then
627 gInputBinds
[i
].commands
:= ParseAlias(p
[2])
630 for i
:= 0 to e_MaxInputKeys
- 1 do
632 if gInputBinds
[i
].commands
<> nil then
634 act
:= gInputBinds
[i
].commands
[0];
635 for j
:= 1 to High(gInputBinds
[i
].commands
) do
636 act
:= act
+ ' ;' + gInputBinds
[i
].commands
[j
];
637 g_Console_Add(LowerCase(e_KeyNames
[i
]) + ' "' + act
+ '"')
642 if Length(p
) = 2 then
644 key
:= LowerCase(p
[1]);
646 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
647 if i
< e_MaxInputKeys
then
648 gInputBinds
[i
].commands
:= nil
651 for i
:= 0 to e_MaxInputKeys
- 1 do
652 if gInputBinds
[i
].commands
<> nil then
653 gInputBinds
[i
].commands
:= nil;
655 for i
:= 0 to e_MaxInputKeys
- 1 do
656 if e_KeyNames
[i
] <> '' then
657 g_Console_Add(LowerCase(e_KeyNames
[i
]));
661 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
666 SetLength(commands
, Length(commands
)+1);
669 cp
.cmd
:= LowerCase(cmd
);
673 cp
.hidden
:= ahidden
;
681 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
683 PrefixList
: array [0..1] of AnsiString = ('+', '-');
684 PlayerList
: array [0..1] of Integer = (1, 2);
689 procedure NewAction (cmd
: AnsiString; player
: Integer);
692 SetLength(commands
, Length(commands
) + 1);
693 cp
:= @commands
[High(commands
)];
694 cp
.cmd
:= LowerCase(cmd
);
708 ASSERT(action
<= LAST_ACTION
);
709 for s
in PrefixList
do
711 NewAction(s
+ cmd
, 0);
712 for i
in PlayerList
do
713 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
717 procedure g_Console_Init();
721 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
722 Cons_Y
:= -(gScreenHeight
div 2);
723 gConsoleShow
:= False;
728 for a
:= 0 to High(MsgArray
) do
735 AddCommand('segfault', segfault
, 'make segfault');
737 AddCommand('bind', BindCommands
);
738 AddCommand('bindlist', BindCommands
);
739 AddCommand('unbind', BindCommands
);
740 AddCommand('unbindall', BindCommands
);
741 AddCommand('bindkeys', BindCommands
);
743 AddAction('jump', ACTION_JUMP
);
744 AddAction('moveleft', ACTION_MOVELEFT
);
745 AddAction('moveright', ACTION_MOVERIGHT
);
746 AddAction('lookup', ACTION_LOOKUP
);
747 AddAction('lookdown', ACTION_LOOKDOWN
);
748 AddAction('attack', ACTION_ATTACK
);
749 AddAction('scores', ACTION_SCORES
);
750 AddAction('activate', ACTION_ACTIVATE
);
751 AddAction('strafe', ACTION_STRAFE
);
752 AddAction('weapnext', ACTION_WEAPNEXT
);
753 AddAction('weapprev', ACTION_WEAPPREV
);
755 AddCommand('clear', ConsoleCommands
, 'clear console');
756 AddCommand('clearhistory', ConsoleCommands
);
757 AddCommand('showhistory', ConsoleCommands
);
758 AddCommand('commands', ConsoleCommands
);
759 AddCommand('time', ConsoleCommands
);
760 AddCommand('date', ConsoleCommands
);
761 AddCommand('echo', ConsoleCommands
);
762 AddCommand('dump', ConsoleCommands
);
763 AddCommand('exec', ConsoleCommands
);
764 AddCommand('alias', ConsoleCommands
);
765 AddCommand('call', ConsoleCommands
);
766 AddCommand('ver', ConsoleCommands
);
767 AddCommand('version', ConsoleCommands
);
769 AddCommand('d_window', DebugCommands
);
770 AddCommand('d_sounds', DebugCommands
);
771 AddCommand('d_frames', DebugCommands
);
772 AddCommand('d_winmsg', DebugCommands
);
773 AddCommand('d_monoff', DebugCommands
);
774 AddCommand('d_botoff', DebugCommands
);
775 AddCommand('d_monster', DebugCommands
);
776 AddCommand('d_health', DebugCommands
);
777 AddCommand('d_player', DebugCommands
);
778 AddCommand('d_joy', DebugCommands
);
779 AddCommand('d_mem', DebugCommands
);
781 AddCommand('p1_name', GameCVars
);
782 AddCommand('p2_name', GameCVars
);
783 AddCommand('p1_color', GameCVars
);
784 AddCommand('p2_color', GameCVars
);
785 AddCommand('r_showfps', GameCVars
);
786 AddCommand('r_showtime', GameCVars
);
787 AddCommand('r_showscore', GameCVars
);
788 AddCommand('r_showlives', GameCVars
);
789 AddCommand('r_showstat', GameCVars
);
790 AddCommand('r_showkillmsg', GameCVars
);
791 AddCommand('r_showspect', GameCVars
);
792 AddCommand('r_showping', GameCVars
);
793 AddCommand('g_gamemode', GameCVars
);
794 AddCommand('g_friendlyfire', GameCVars
);
795 AddCommand('g_weaponstay', GameCVars
);
796 AddCommand('g_allow_exit', GameCVars
);
797 AddCommand('g_allow_monsters', GameCVars
);
798 AddCommand('g_bot_vsmonsters', GameCVars
);
799 AddCommand('g_bot_vsplayers', GameCVars
);
800 AddCommand('g_scorelimit', GameCVars
);
801 AddCommand('g_timelimit', GameCVars
);
802 AddCommand('g_maxlives', GameCVars
);
803 AddCommand('g_warmuptime', GameCVars
);
804 AddCommand('net_interp', GameCVars
);
805 AddCommand('net_forceplayerupdate', GameCVars
);
806 AddCommand('net_predictself', GameCVars
);
807 AddCommand('sv_name', GameCVars
);
808 AddCommand('sv_passwd', GameCVars
);
809 AddCommand('sv_maxplrs', GameCVars
);
810 AddCommand('sv_public', GameCVars
);
811 AddCommand('sv_intertime', GameCVars
);
813 AddCommand('quit', GameCommands
);
814 AddCommand('exit', GameCommands
);
815 AddCommand('pause', GameCommands
);
816 AddCommand('endgame', GameCommands
);
817 AddCommand('restart', GameCommands
);
818 AddCommand('addbot', GameCommands
);
819 AddCommand('bot_add', GameCommands
);
820 AddCommand('bot_addlist', GameCommands
);
821 AddCommand('bot_addred', GameCommands
);
822 AddCommand('bot_addblue', GameCommands
);
823 AddCommand('bot_removeall', GameCommands
);
824 AddCommand('chat', GameCommands
);
825 AddCommand('teamchat', GameCommands
);
826 AddCommand('game', GameCommands
);
827 AddCommand('host', GameCommands
);
828 AddCommand('map', GameCommands
);
829 AddCommand('nextmap', GameCommands
);
830 AddCommand('endmap', GameCommands
);
831 AddCommand('goodbye', GameCommands
);
832 AddCommand('suicide', GameCommands
);
833 AddCommand('spectate', GameCommands
);
834 AddCommand('ready', GameCommands
);
835 AddCommand('kick', GameCommands
);
836 AddCommand('kick_id', GameCommands
);
837 AddCommand('ban', GameCommands
);
838 AddCommand('permban', GameCommands
);
839 AddCommand('ban_id', GameCommands
);
840 AddCommand('permban_id', GameCommands
);
841 AddCommand('unban', GameCommands
);
842 AddCommand('connect', GameCommands
);
843 AddCommand('disconnect', GameCommands
);
844 AddCommand('reconnect', GameCommands
);
845 AddCommand('say', GameCommands
);
846 AddCommand('tell', GameCommands
);
847 AddCommand('overtime', GameCommands
);
848 AddCommand('rcon_password', GameCommands
);
849 AddCommand('rcon', GameCommands
);
850 AddCommand('callvote', GameCommands
);
851 AddCommand('vote', GameCommands
);
852 AddCommand('clientlist', GameCommands
);
853 AddCommand('event', GameCommands
);
854 AddCommand('screenshot', GameCommands
);
855 AddCommand('togglechat', GameCommands
);
856 AddCommand('toggleteamchat', GameCommands
);
857 AddCommand('weapon', GameCommands
);
858 AddCommand('p1_weapon', GameCommands
);
859 AddCommand('p2_weapon', GameCommands
);
861 AddCommand('god', GameCheats
);
862 AddCommand('notarget', GameCheats
);
863 AddCommand('give', GameCheats
); // "exit" too ;-)
864 AddCommand('open', GameCheats
);
865 AddCommand('fly', GameCheats
);
866 AddCommand('noclip', GameCheats
);
867 AddCommand('speedy', GameCheats
);
868 AddCommand('jumpy', GameCheats
);
869 AddCommand('noreload', GameCheats
);
870 AddCommand('aimline', GameCheats
);
871 AddCommand('automap', GameCheats
);
873 WhitelistCommand('say');
874 WhitelistCommand('tell');
875 WhitelistCommand('overtime');
876 WhitelistCommand('ready');
877 WhitelistCommand('map');
878 WhitelistCommand('nextmap');
879 WhitelistCommand('endmap');
880 WhitelistCommand('restart');
881 WhitelistCommand('kick');
882 WhitelistCommand('ban');
884 WhitelistCommand('addbot');
885 WhitelistCommand('bot_add');
886 WhitelistCommand('bot_addred');
887 WhitelistCommand('bot_addblue');
888 WhitelistCommand('bot_removeall');
890 WhitelistCommand('g_gamemode');
891 WhitelistCommand('g_friendlyfire');
892 WhitelistCommand('g_weaponstay');
893 WhitelistCommand('g_allow_exit');
894 WhitelistCommand('g_allow_monsters');
895 WhitelistCommand('g_scorelimit');
896 WhitelistCommand('g_timelimit');
898 g_Console_ReadConfig(GameDir
+ '/dfconfig.cfg');
899 g_Console_ReadConfig(GameDir
+ '/autoexec.cfg');
901 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
905 procedure g_Console_Update();
911 // Â ïðîöåññå îòêðûòèÿ:
912 if gConsoleShow
and (Cons_Y
< 0) then
914 Cons_Y
:= Cons_Y
+Step
;
917 // Â ïðîöåññå çàêðûòèÿ:
918 if (not gConsoleShow
) and
919 (Cons_Y
> -(gScreenHeight
div 2)) then
920 Cons_Y
:= Cons_Y
-Step
;
922 // Îêîí÷àòåëüíî îòêðûëàñü:
926 // Îêîí÷àòåëüíî çàêðûëàñü:
927 if Cons_Y
<= (-(gScreenHeight
div 2)) then
929 Cons_Y
:= -(gScreenHeight
div 2);
935 while a
<= High(MsgArray
) do
937 if MsgArray
[a
].Time
> 0 then
939 if MsgArray
[a
].Time
= 1 then
941 if a
< High(MsgArray
) then
943 for b
:= a
to High(MsgArray
)-1 do
944 MsgArray
[b
] := MsgArray
[b
+1];
946 MsgArray
[High(MsgArray
)].Time
:= 0;
952 Dec(MsgArray
[a
].Time
);
960 procedure drawConsoleText ();
962 CWidth
, CHeight
: Byte;
967 procedure putLine (sp
, ep
: LongWord);
976 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
977 if wdt
+cw
> gScreenWidth
-8 then break
;
978 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
982 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
983 // now print our part
991 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
992 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1005 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1006 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
1007 skip
:= conSkipLines
;
1008 cbufLastLine(sp
, ep
);
1011 if ty
+CHeight
<= 0 then break
;
1012 until not cbufLineUp(sp
, ep
);
1015 procedure g_Console_Draw();
1017 CWidth
, CHeight
: Byte;
1021 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1023 for a
:= 0 to High(MsgArray
) do
1024 if MsgArray
[a
].Time
> 0 then
1025 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
1028 if not Cons_Shown
then
1034 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
1035 gStdFont
, 255, 255, 255, 1, True);
1036 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1037 gStdFont
, 255, 255, 255, 1, True);
1041 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
1042 gStdFont
, 255, 255, 255, 1, True);
1043 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1044 gStdFont
, 255, 255, 255, 1, True);
1052 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1053 a
:= (gScreenWidth
- 2*mfW
) div 2;
1054 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
1055 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1056 _RGB(128, 0, 0), 2.0);
1059 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
1060 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
1064 if ConsoleHistory <> nil then
1068 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
1069 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
1071 b := Max(b-Offset, 0);
1072 d := Max(High(ConsoleHistory)-Offset, 0);
1075 for a := d downto b do
1077 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
1084 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
1087 procedure g_Console_Switch();
1090 gConsoleShow
:= not gConsoleShow
;
1092 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1095 procedure g_Console_Chat_Switch(Team
: Boolean = False);
1097 if not g_Game_IsNet
then Exit
;
1098 gConsoleShow
:= False;
1099 gChatShow
:= not gChatShow
;
1103 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1106 procedure g_Console_Char(C
: AnsiChar);
1108 // if gChatShow then
1110 Insert(C
, Line
, CPos
);
1116 tcomplist
: array of AnsiString = nil;
1117 tcompidx
: array of Integer = nil;
1119 procedure Complete ();
1123 ll
, lpfx
, cmd
: AnsiString;
1125 if (Length(Line
) = 0) then
1128 for i
:= 0 to High(commands
) do
1130 // hidden commands are hidden when cheats aren't enabled
1131 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1132 if (Length(commands
[i
].help
) > 0) then
1134 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1138 g_Console_Add(' '+commands
[i
].cmd
);
1144 ll
:= LowerCase(Line
);
1147 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1149 ll
:= Copy(ll
, 0, Length(ll
)-1);
1150 for i
:= 0 to High(commands
) do
1152 // hidden commands are hidden when cheats aren't enabled
1153 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1154 if (commands
[i
].cmd
= ll
) then
1156 if (Length(commands
[i
].help
) > 0) then
1158 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1165 // build completion list
1167 for i
:= 0 to High(commands
) do
1169 // hidden commands are hidden when cheats aren't enabled
1170 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1171 cmd
:= commands
[i
].cmd
;
1172 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1174 if (tused
= Length(tcomplist
)) then
1176 SetLength(tcomplist
, Length(tcomplist
)+128);
1177 SetLength(tcompidx
, Length(tcompidx
)+128);
1179 tcomplist
[tused
] := cmd
;
1180 tcompidx
[tused
] := i
;
1182 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1186 // get longest prefix
1187 for i
:= 0 to tused
-1 do
1189 cmd
:= tcomplist
[i
];
1190 for c
:= 1 to Length(lpfx
) do
1192 if (c
> Length(cmd
)) then break
;
1193 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1197 if (tused
= 0) then exit
;
1201 Line
:= tcomplist
[0]+' ';
1202 CPos
:= Length(Line
)+1;
1206 // has longest prefix?
1207 if (Length(lpfx
) > Length(ll
)) then
1210 CPos
:= Length(Line
)+1;
1215 for i
:= 0 to tused
-1 do
1217 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1219 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1223 g_Console_Add(' '+tcomplist
[i
]);
1231 procedure g_Console_Control(K
: Word);
1235 if (Length(Line
) > 0) and (CPos
> 1) then
1237 Delete(Line
, CPos
-1, 1);
1241 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1242 Delete(Line
, CPos
, 1);
1243 IK_LEFT
, IK_KPLEFT
, VK_LEFT
:
1246 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
:
1247 if CPos
<= Length(Line
) then
1249 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
:
1252 g_Console_Process(Line
)
1256 if (Length(Line
) > 0) and g_Game_IsNet
then
1260 if g_Game_IsClient
then
1261 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1263 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1264 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1268 if g_Game_IsClient
then
1269 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1271 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1279 gJustChatted
:= True;
1280 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1284 if not gChatShow
then
1286 IK_DOWN
, IK_KPDOWN
, VK_DOWN
:
1287 if not gChatShow
then
1288 if (CommandHistory
<> nil) and
1289 (CmdIndex
< Length(CommandHistory
)) then
1291 if CmdIndex
< Length(CommandHistory
)-1 then
1292 CmdIndex
:= CmdIndex
+ 1;
1293 Line
:= CommandHistory
[CmdIndex
];
1294 CPos
:= Length(Line
) + 1;
1296 IK_UP
, IK_KPUP
, VK_UP
:
1297 if not gChatShow
then
1298 if (CommandHistory
<> nil) and
1299 (CmdIndex
<= Length(CommandHistory
)) then
1301 if CmdIndex
> 0 then
1302 CmdIndex
:= CmdIndex
- 1;
1303 Line
:= CommandHistory
[CmdIndex
];
1304 Cpos
:= Length(Line
) + 1;
1306 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
: // PgUp
1307 if not gChatShow
then Inc(conSkipLines
);
1308 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
: // PgDown
1309 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1313 CPos
:= Length(Line
) + 1;
1317 function GetStr(var Str
: AnsiString): AnsiString;
1322 if Str
[1] = '"' then
1324 for b
:= 1 to Length(Str
) do
1325 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1327 Result
:= Copy(Str
, 2, b
-1);
1328 Delete(Str
, 1, b
+1);
1334 for a
:= 1 to Length(Str
) do
1335 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1337 Result
:= Copy(Str
, 1, a
);
1338 Delete(Str
, 1, a
+1);
1344 function ParseString(Str
: AnsiString): SSArray
;
1355 SetLength(Result
, Length(Result
)+1);
1356 Result
[High(Result
)] := GetStr(Str
);
1360 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1362 procedure conmsg (s
: AnsiString);
1366 if length(s
) = 0 then exit
;
1367 for a
:= 0 to High(MsgArray
) do
1379 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1380 with MsgArray
[High(MsgArray
)] do
1390 // put it to console
1392 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1394 // now show 'em out of console too
1395 show
:= show
and gAllowConsoleMessages
;
1396 if show
and gShowMessages
then
1398 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1399 while length(L
) > 0 do
1402 if f
<= 0 then f
:= length(L
)+1;
1403 conmsg(Copy(L
, 1, f
-1));
1408 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1409 //ConsoleHistory[High(ConsoleHistory)] := L;
1413 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1420 consolewriterLastWasEOL
: Boolean = false;
1422 procedure consolewriter (constref buf
; len
: SizeUInt
);
1426 if (len
< 1) then exit
;
1428 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1431 if (b
[0] <> 13) and (b
[0] <> 10) then
1433 cbufPut(AnsiChar(b
[0]));
1437 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1446 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1447 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1448 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1449 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1451 g_Console_Add(s
, show
);
1455 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1459 g_Console_Add(formatstrf(s
, args
), true);
1463 consolewriterLastWasEOL
:= false;
1464 formatstrf(s
, args
, consolewriter
);
1465 if not consolewriterLastWasEOL
then cbufPut(#10);
1470 procedure g_Console_Clear();
1472 //ConsoleHistory := nil;
1477 procedure AddToHistory(L
: AnsiString);
1481 len
:= Length(CommandHistory
);
1484 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1486 SetLength(CommandHistory
, len
+1);
1487 CommandHistory
[len
] := L
;
1490 CmdIndex
:= Length(CommandHistory
);
1493 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1502 if Trim(C
) = '' then
1505 Arr
:= ParseString(C
);
1509 for i
:= 0 to High(Whitelist
) do
1510 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1514 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1521 if Trim(L
) = '' then
1524 conSkipLines
:= 0; // "unscroll"
1526 if L
= 'goobers' then
1531 g_Console_Add('Your memory serves you well.');
1537 g_Console_Add('> '+L
);
1542 Arr
:= ParseString(L
);
1546 if commands
= nil then
1552 for i
:= 0 to High(commands
) do
1554 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1556 if commands
[i
].action
>= 0 then
1561 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+'
1563 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := gDefaultAction
[commands
[i
].player
, commands
[i
].action
]
1567 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1568 gDefaultAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+'
1572 else if bindProcess
and not bindDown
then
1574 (* command is not action, so do not execute it again after button release *)
1578 if assigned(commands
[i
].procEx
) then
1580 commands
[i
].procEx(@commands
[i
], Arr
);
1583 if assigned(commands
[i
].proc
) then
1585 commands
[i
].proc(Arr
);
1591 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1595 function g_Console_Interactive
: Boolean;
1597 Result
:= not bindProcess
1600 function g_Console_Action (action
: Integer): Boolean;
1601 var i
, len
: Integer;
1603 ASSERT(action
>= 0);
1604 ASSERT(action
<= LAST_ACTION
);
1606 len
:= Length(gPlayerAction
);
1607 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1611 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1614 if (not gChatShow
) and (not gConsoleShow
) and (key
>= 0) and (key
< e_MaxInputKeys
) and (gInputBinds
[key
].commands
<> nil) then
1617 bindProcess
:= True;
1618 for i
:= 0 to High(gInputBinds
[key
].commands
) do
1619 g_Console_Process(gInputBinds
[key
].commands
[i
], True);
1620 bindProcess
:= False;
1625 procedure g_Console_ReadConfig (filename
: String);
1626 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1628 if FileExists(filename
) then
1630 AssignFile(f
, filename
);
1640 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1642 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1643 g_Console_Process(s
, True)