69158eae2eb830bacfa8b785e2f09b35b28dde35
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 function g_Console_FindBind (n
: Integer; cmd
: AnsiString): Integer;
55 procedure g_Console_BindKey (key
: Integer; cmd
: AnsiString);
56 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
58 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
59 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
61 // <0: no arg; 0/1: true/false
62 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
64 procedure g_Console_Chat_Switch (team
: Boolean=false);
66 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
67 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
68 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
70 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
71 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
75 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
76 gChatShow
: Boolean = false;
77 gChatTeam
: Boolean = false;
78 gAllowConsoleMessages
: Boolean = true;
79 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
80 gPlayerAction
, gDefaultAction
: Array [0..1, 0..LAST_ACTION
] of Boolean; // [player, action]
85 g_textures
, g_main
, e_graphics
, e_input
, g_game
,
86 SysUtils
, g_basic
, g_options
, Math
, g_touch
,
87 g_menu
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
93 TCmdProc
= procedure (p
: SSArray
);
94 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
102 ptr
: Pointer; // various data
103 msg
: AnsiString; // message for var changes
105 action
: Integer; // >= 0 for action commands
106 player
: Integer; // used for action commands
119 MaxScriptRecursion
= 16;
121 DEBUG_STRING
= 'DEBUG MODE';
125 RecursionDepth
: Word = 0;
126 RecursionLimitHit
: Boolean = False;
128 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
131 //ConsoleHistory: SSArray;
132 CommandHistory
: SSArray
;
134 commands
: Array of TCommand
= nil;
135 Aliases
: Array of TAlias
= nil;
137 conSkipLines
: Integer = 0;
138 MsgArray
: Array [0..4] of record
143 bindDown
, bindProcess
: Boolean;
144 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
149 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
150 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
159 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
160 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
161 if (pos
> slen
) then exit
;
162 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
164 while (pos
<= slen
) do
166 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
167 res
:= res
*10+Byte(s
[pos
])-48;
170 if (pos
<= slen
) then
173 if (s
[pos
] <> '.') then exit
;
175 while (pos
<= slen
) do
177 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
179 res
+= frac
*(Byte(s
[pos
])-48);
183 if (pos
<= slen
) then exit
; // oops
188 // ////////////////////////////////////////////////////////////////////////// //
189 // <0: no arg; 0/1: true/false; 666: toggle
190 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
192 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
194 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
195 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
196 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
197 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
201 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
202 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
204 if (Length(p
) > 2) then
206 conwritefln('too many arguments to ''%s''', [p
[0]]);
210 case conGetBoolArg(p
, 1) of
212 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
213 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
214 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
216 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
217 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
221 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
225 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
226 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
228 if (Length(p
) > 2) then
230 conwritefln('too many arguments to ''%s''', [p
[0]]);
234 case conGetBoolArg(p
, 1) of
236 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
237 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
238 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
240 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
241 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
245 if (Length(p
) <> 2) then
247 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
252 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
254 conwritefln('invalid integer value: "%s"', [p
[1]]);
260 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
265 f
:= Length(commands
);
266 SetLength(commands
, f
+1);
268 cp
.cmd
:= LowerCase(conname
);
270 cp
.procEx
:= boolVarHandler
;
272 cp
.hidden
:= ahidden
;
281 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
286 f
:= Length(commands
);
287 SetLength(commands
, f
+1);
289 cp
.cmd
:= LowerCase(conname
);
291 cp
.procEx
:= intVarHandler
;
293 cp
.hidden
:= ahidden
;
302 // ////////////////////////////////////////////////////////////////////////// //
304 PVarSingle
= ^TVarSingle
;
307 min
, max
, def
: Single; // default will be starting value
311 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
317 if (Length(p
) > 2) then
319 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
322 pv
:= PVarSingle(me
.ptr
);
323 if (Length(p
) = 2) then
325 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
326 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
327 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
328 (CompareText(p
[1], 'ona') = 0) then
334 if not conParseFloat(nv
, p
[1]) then
336 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
339 if (nv
< pv
.min
) then nv
:= pv
.min
;
340 if (nv
> pv
.max
) then nv
:= pv
.max
;
345 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
346 conwritefln('%s %s', [msg
, pv
.val
^]);
350 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
356 GetMem(pv
, sizeof(TVarSingle
));
361 f
:= Length(commands
);
362 SetLength(commands
, f
+1);
364 cp
.cmd
:= LowerCase(conname
);
366 cp
.procEx
:= singleVarHandler
;
368 cp
.hidden
:= ahidden
;
377 // ////////////////////////////////////////////////////////////////////////// //
378 function GetStrACmd(var Str
: AnsiString): AnsiString;
383 for a
:= 1 to Length(Str
) do
384 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
386 Result
:= Copy(Str
, 1, a
);
393 function ParseAlias(Str
: AnsiString): SSArray
;
404 SetLength(Result
, Length(Result
)+1);
405 Result
[High(Result
)] := GetStrACmd(Str
);
409 procedure ConsoleCommands(p
: SSArray
);
415 cmd
:= LowerCase(p
[0]);
418 if cmd
= 'clear' then
420 //ConsoleHistory := nil;
424 for a
:= 0 to High(MsgArray
) do
432 if cmd
= 'clearhistory' then
433 CommandHistory
:= nil;
435 if cmd
= 'showhistory' then
436 if CommandHistory
<> nil then
439 for a
:= 0 to High(CommandHistory
) do
440 g_Console_Add(' '+CommandHistory
[a
]);
443 if cmd
= 'commands' then
446 g_Console_Add('commands list:');
447 for a
:= High(commands
) downto 0 do
449 if (Length(commands
[a
].help
) > 0) then
451 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
455 g_Console_Add(' '+commands
[a
].cmd
);
461 g_Console_Add(TimeToStr(Now
), True);
464 g_Console_Add(DateToStr(Now
), True);
467 if Length(p
) > 1 then
469 if p
[1] = 'ololo' then
474 for a
:= 1 to High(p
) do
476 g_Console_Add(b_Text_Format(s
), True);
485 if ConsoleHistory <> nil then
487 if Length(P) > 1 then
490 s := GameDir+'/console.txt';
495 if IOResult <> 0 then
497 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
502 for a := 0 to High(ConsoleHistory) do
503 WriteLn(F, ConsoleHistory[a]);
506 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
515 if Length(p
) = 2 then
517 s
:= GameDir
+ '/' + p
[1];
518 g_Console_ReadConfig(s
);
521 g_Console_Add('exec <script file>');
524 if (cmd
= 'ver') or (cmd
= 'version') then
526 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
527 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
528 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
531 if cmd
= 'alias' then
533 // alias [alias_name] [commands]
534 if Length(p
) > 1 then
536 for a
:= 0 to High(Aliases
) do
537 if Aliases
[a
].name
= p
[1] then
539 if Length(p
) > 2 then
540 Aliases
[a
].commands
:= ParseAlias(p
[2])
542 for b
:= 0 to High(Aliases
[a
].commands
) do
543 g_Console_Add(Aliases
[a
].commands
[b
]);
546 SetLength(Aliases
, Length(Aliases
)+1);
548 Aliases
[a
].name
:= p
[1];
549 if Length(p
) > 2 then
550 Aliases
[a
].commands
:= ParseAlias(p
[2])
552 for b
:= 0 to High(Aliases
[a
].commands
) do
553 g_Console_Add(Aliases
[a
].commands
[b
]);
555 for a
:= 0 to High(Aliases
) do
556 if Aliases
[a
].commands
<> nil then
557 g_Console_Add(Aliases
[a
].name
);
563 if Length(p
) > 1 then
565 if Aliases
= nil then
567 for a
:= 0 to High(Aliases
) do
568 if Aliases
[a
].name
= p
[1] then
570 if Aliases
[a
].commands
<> nil then
572 // with this system proper endless loop detection seems either impossible
573 // or very dirty to implement, so let's have this instead
574 // prevents endless loops
575 for b
:= 0 to High(Aliases
[a
].commands
) do
578 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
579 if not RecursionLimitHit
then
580 g_Console_Process(Aliases
[a
].commands
[b
], True);
583 if (RecursionDepth
= 0) and RecursionLimitHit
then
585 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
586 RecursionLimitHit
:= False;
593 g_Console_Add('call <alias name>');
600 procedure WhitelistCommand(cmd
: AnsiString);
604 SetLength(Whitelist
, Length(Whitelist
)+1);
605 a
:= High(Whitelist
);
606 Whitelist
[a
] := LowerCase(cmd
);
609 procedure segfault (p
: SSArray
);
616 procedure BindCommands (p
: SSArray
);
617 var cmd
, key
, act
: AnsiString; i
, j
: Integer;
619 cmd
:= LowerCase(p
[0]);
622 // bind <key> <action>
623 if Length(p
) = 3 then
625 key
:= LowerCase(p
[1]);
627 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
628 if i
< e_MaxInputKeys
then
629 gInputBinds
[i
].commands
:= ParseAlias(p
[2])
632 for i
:= 0 to e_MaxInputKeys
- 1 do
634 if gInputBinds
[i
].commands
<> nil then
636 act
:= gInputBinds
[i
].commands
[0];
637 for j
:= 1 to High(gInputBinds
[i
].commands
) do
638 act
:= act
+ ' ;' + gInputBinds
[i
].commands
[j
];
639 g_Console_Add(LowerCase(e_KeyNames
[i
]) + ' "' + act
+ '"')
644 if Length(p
) = 2 then
646 key
:= LowerCase(p
[1]);
648 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
649 if i
< e_MaxInputKeys
then
650 gInputBinds
[i
].commands
:= nil
653 for i
:= 0 to e_MaxInputKeys
- 1 do
654 if gInputBinds
[i
].commands
<> nil then
655 gInputBinds
[i
].commands
:= nil;
657 for i
:= 0 to e_MaxInputKeys
- 1 do
658 if e_KeyNames
[i
] <> '' then
659 g_Console_Add(LowerCase(e_KeyNames
[i
]));
663 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
668 SetLength(commands
, Length(commands
)+1);
671 cp
.cmd
:= LowerCase(cmd
);
675 cp
.hidden
:= ahidden
;
683 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
685 PrefixList
: array [0..1] of AnsiString = ('+', '-');
686 PlayerList
: array [0..1] of Integer = (1, 2);
691 procedure NewAction (cmd
: AnsiString; player
: Integer);
694 SetLength(commands
, Length(commands
) + 1);
695 cp
:= @commands
[High(commands
)];
696 cp
.cmd
:= LowerCase(cmd
);
710 ASSERT(action
<= LAST_ACTION
);
711 for s
in PrefixList
do
713 NewAction(s
+ cmd
, 0);
714 for i
in PlayerList
do
715 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
719 procedure g_Console_Init();
723 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
724 Cons_Y
:= -(gScreenHeight
div 2);
725 gConsoleShow
:= False;
730 for a
:= 0 to High(MsgArray
) do
737 AddCommand('segfault', segfault
, 'make segfault');
739 AddCommand('bind', BindCommands
);
740 AddCommand('bindlist', BindCommands
);
741 AddCommand('unbind', BindCommands
);
742 AddCommand('unbindall', BindCommands
);
743 AddCommand('bindkeys', BindCommands
);
745 AddAction('jump', ACTION_JUMP
);
746 AddAction('moveleft', ACTION_MOVELEFT
);
747 AddAction('moveright', ACTION_MOVERIGHT
);
748 AddAction('lookup', ACTION_LOOKUP
);
749 AddAction('lookdown', ACTION_LOOKDOWN
);
750 AddAction('attack', ACTION_ATTACK
);
751 AddAction('scores', ACTION_SCORES
);
752 AddAction('activate', ACTION_ACTIVATE
);
753 AddAction('strafe', ACTION_STRAFE
);
754 AddAction('weapnext', ACTION_WEAPNEXT
);
755 AddAction('weapprev', ACTION_WEAPPREV
);
757 AddCommand('clear', ConsoleCommands
, 'clear console');
758 AddCommand('clearhistory', ConsoleCommands
);
759 AddCommand('showhistory', ConsoleCommands
);
760 AddCommand('commands', ConsoleCommands
);
761 AddCommand('time', ConsoleCommands
);
762 AddCommand('date', ConsoleCommands
);
763 AddCommand('echo', ConsoleCommands
);
764 AddCommand('dump', ConsoleCommands
);
765 AddCommand('exec', ConsoleCommands
);
766 AddCommand('alias', ConsoleCommands
);
767 AddCommand('call', ConsoleCommands
);
768 AddCommand('ver', ConsoleCommands
);
769 AddCommand('version', ConsoleCommands
);
771 AddCommand('d_window', DebugCommands
);
772 AddCommand('d_sounds', DebugCommands
);
773 AddCommand('d_frames', DebugCommands
);
774 AddCommand('d_winmsg', DebugCommands
);
775 AddCommand('d_monoff', DebugCommands
);
776 AddCommand('d_botoff', DebugCommands
);
777 AddCommand('d_monster', DebugCommands
);
778 AddCommand('d_health', DebugCommands
);
779 AddCommand('d_player', DebugCommands
);
780 AddCommand('d_joy', DebugCommands
);
781 AddCommand('d_mem', DebugCommands
);
783 AddCommand('p1_name', GameCVars
);
784 AddCommand('p2_name', GameCVars
);
785 AddCommand('p1_color', GameCVars
);
786 AddCommand('p2_color', GameCVars
);
787 AddCommand('r_showfps', GameCVars
);
788 AddCommand('r_showtime', GameCVars
);
789 AddCommand('r_showscore', GameCVars
);
790 AddCommand('r_showlives', GameCVars
);
791 AddCommand('r_showstat', GameCVars
);
792 AddCommand('r_showkillmsg', GameCVars
);
793 AddCommand('r_showspect', GameCVars
);
794 AddCommand('r_showping', GameCVars
);
795 AddCommand('g_gamemode', GameCVars
);
796 AddCommand('g_friendlyfire', GameCVars
);
797 AddCommand('g_weaponstay', GameCVars
);
798 AddCommand('g_allow_exit', GameCVars
);
799 AddCommand('g_allow_monsters', GameCVars
);
800 AddCommand('g_bot_vsmonsters', GameCVars
);
801 AddCommand('g_bot_vsplayers', GameCVars
);
802 AddCommand('g_scorelimit', GameCVars
);
803 AddCommand('g_timelimit', GameCVars
);
804 AddCommand('g_maxlives', GameCVars
);
805 AddCommand('g_warmuptime', GameCVars
);
806 AddCommand('net_interp', GameCVars
);
807 AddCommand('net_forceplayerupdate', GameCVars
);
808 AddCommand('net_predictself', GameCVars
);
809 AddCommand('sv_name', GameCVars
);
810 AddCommand('sv_passwd', GameCVars
);
811 AddCommand('sv_maxplrs', GameCVars
);
812 AddCommand('sv_public', GameCVars
);
813 AddCommand('sv_intertime', GameCVars
);
815 AddCommand('quit', GameCommands
);
816 AddCommand('exit', GameCommands
);
817 AddCommand('pause', GameCommands
);
818 AddCommand('endgame', GameCommands
);
819 AddCommand('restart', GameCommands
);
820 AddCommand('addbot', GameCommands
);
821 AddCommand('bot_add', GameCommands
);
822 AddCommand('bot_addlist', GameCommands
);
823 AddCommand('bot_addred', GameCommands
);
824 AddCommand('bot_addblue', GameCommands
);
825 AddCommand('bot_removeall', GameCommands
);
826 AddCommand('chat', GameCommands
);
827 AddCommand('teamchat', GameCommands
);
828 AddCommand('game', GameCommands
);
829 AddCommand('host', GameCommands
);
830 AddCommand('map', GameCommands
);
831 AddCommand('nextmap', GameCommands
);
832 AddCommand('endmap', GameCommands
);
833 AddCommand('goodbye', GameCommands
);
834 AddCommand('suicide', GameCommands
);
835 AddCommand('spectate', GameCommands
);
836 AddCommand('ready', GameCommands
);
837 AddCommand('kick', GameCommands
);
838 AddCommand('kick_id', GameCommands
);
839 AddCommand('ban', GameCommands
);
840 AddCommand('permban', GameCommands
);
841 AddCommand('ban_id', GameCommands
);
842 AddCommand('permban_id', GameCommands
);
843 AddCommand('unban', GameCommands
);
844 AddCommand('connect', GameCommands
);
845 AddCommand('disconnect', GameCommands
);
846 AddCommand('reconnect', GameCommands
);
847 AddCommand('say', GameCommands
);
848 AddCommand('tell', GameCommands
);
849 AddCommand('overtime', GameCommands
);
850 AddCommand('rcon_password', GameCommands
);
851 AddCommand('rcon', GameCommands
);
852 AddCommand('callvote', GameCommands
);
853 AddCommand('vote', GameCommands
);
854 AddCommand('clientlist', GameCommands
);
855 AddCommand('event', GameCommands
);
856 AddCommand('screenshot', GameCommands
);
857 AddCommand('togglechat', GameCommands
);
858 AddCommand('toggleteamchat', GameCommands
);
859 AddCommand('weapon', GameCommands
);
860 AddCommand('p1_weapon', GameCommands
);
861 AddCommand('p2_weapon', GameCommands
);
863 AddCommand('god', GameCheats
);
864 AddCommand('notarget', GameCheats
);
865 AddCommand('give', GameCheats
); // "exit" too ;-)
866 AddCommand('open', GameCheats
);
867 AddCommand('fly', GameCheats
);
868 AddCommand('noclip', GameCheats
);
869 AddCommand('speedy', GameCheats
);
870 AddCommand('jumpy', GameCheats
);
871 AddCommand('noreload', GameCheats
);
872 AddCommand('aimline', GameCheats
);
873 AddCommand('automap', GameCheats
);
875 WhitelistCommand('say');
876 WhitelistCommand('tell');
877 WhitelistCommand('overtime');
878 WhitelistCommand('ready');
879 WhitelistCommand('map');
880 WhitelistCommand('nextmap');
881 WhitelistCommand('endmap');
882 WhitelistCommand('restart');
883 WhitelistCommand('kick');
884 WhitelistCommand('ban');
886 WhitelistCommand('addbot');
887 WhitelistCommand('bot_add');
888 WhitelistCommand('bot_addred');
889 WhitelistCommand('bot_addblue');
890 WhitelistCommand('bot_removeall');
892 WhitelistCommand('g_gamemode');
893 WhitelistCommand('g_friendlyfire');
894 WhitelistCommand('g_weaponstay');
895 WhitelistCommand('g_allow_exit');
896 WhitelistCommand('g_allow_monsters');
897 WhitelistCommand('g_scorelimit');
898 WhitelistCommand('g_timelimit');
900 g_Console_ReadConfig(GameDir
+ '/dfconfig.cfg');
901 g_Console_ReadConfig(GameDir
+ '/autoexec.cfg');
903 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
907 procedure g_Console_Update();
913 // Â ïðîöåññå îòêðûòèÿ:
914 if gConsoleShow
and (Cons_Y
< 0) then
916 Cons_Y
:= Cons_Y
+Step
;
919 // Â ïðîöåññå çàêðûòèÿ:
920 if (not gConsoleShow
) and
921 (Cons_Y
> -(gScreenHeight
div 2)) then
922 Cons_Y
:= Cons_Y
-Step
;
924 // Îêîí÷àòåëüíî îòêðûëàñü:
928 // Îêîí÷àòåëüíî çàêðûëàñü:
929 if Cons_Y
<= (-(gScreenHeight
div 2)) then
931 Cons_Y
:= -(gScreenHeight
div 2);
937 while a
<= High(MsgArray
) do
939 if MsgArray
[a
].Time
> 0 then
941 if MsgArray
[a
].Time
= 1 then
943 if a
< High(MsgArray
) then
945 for b
:= a
to High(MsgArray
)-1 do
946 MsgArray
[b
] := MsgArray
[b
+1];
948 MsgArray
[High(MsgArray
)].Time
:= 0;
954 Dec(MsgArray
[a
].Time
);
962 procedure drawConsoleText ();
964 CWidth
, CHeight
: Byte;
969 procedure putLine (sp
, ep
: LongWord);
978 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
979 if wdt
+cw
> gScreenWidth
-8 then break
;
980 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
984 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
985 // now print our part
993 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
994 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1007 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1008 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
1009 skip
:= conSkipLines
;
1010 cbufLastLine(sp
, ep
);
1013 if ty
+CHeight
<= 0 then break
;
1014 until not cbufLineUp(sp
, ep
);
1017 procedure g_Console_Draw();
1019 CWidth
, CHeight
: Byte;
1023 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1025 for a
:= 0 to High(MsgArray
) do
1026 if MsgArray
[a
].Time
> 0 then
1027 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
1030 if not Cons_Shown
then
1036 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
1037 gStdFont
, 255, 255, 255, 1, True);
1038 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1039 gStdFont
, 255, 255, 255, 1, True);
1043 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
1044 gStdFont
, 255, 255, 255, 1, True);
1045 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1046 gStdFont
, 255, 255, 255, 1, True);
1054 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1055 a
:= (gScreenWidth
- 2*mfW
) div 2;
1056 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
1057 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1058 _RGB(128, 0, 0), 2.0);
1061 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
1062 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
1066 if ConsoleHistory <> nil then
1070 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
1071 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
1073 b := Max(b-Offset, 0);
1074 d := Max(High(ConsoleHistory)-Offset, 0);
1077 for a := d downto b do
1079 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
1086 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
1089 procedure g_Console_Switch();
1092 gConsoleShow
:= not gConsoleShow
;
1094 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1097 procedure g_Console_Chat_Switch(Team
: Boolean = False);
1099 if not g_Game_IsNet
then Exit
;
1100 gConsoleShow
:= False;
1101 gChatShow
:= not gChatShow
;
1105 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1108 procedure g_Console_Char(C
: AnsiChar);
1110 // if gChatShow then
1112 Insert(C
, Line
, CPos
);
1118 tcomplist
: array of AnsiString = nil;
1119 tcompidx
: array of Integer = nil;
1121 procedure Complete ();
1125 ll
, lpfx
, cmd
: AnsiString;
1127 if (Length(Line
) = 0) then
1130 for i
:= 0 to High(commands
) do
1132 // hidden commands are hidden when cheats aren't enabled
1133 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1134 if (Length(commands
[i
].help
) > 0) then
1136 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1140 g_Console_Add(' '+commands
[i
].cmd
);
1146 ll
:= LowerCase(Line
);
1149 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1151 ll
:= Copy(ll
, 0, Length(ll
)-1);
1152 for i
:= 0 to High(commands
) do
1154 // hidden commands are hidden when cheats aren't enabled
1155 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1156 if (commands
[i
].cmd
= ll
) then
1158 if (Length(commands
[i
].help
) > 0) then
1160 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1167 // build completion list
1169 for i
:= 0 to High(commands
) do
1171 // hidden commands are hidden when cheats aren't enabled
1172 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1173 cmd
:= commands
[i
].cmd
;
1174 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1176 if (tused
= Length(tcomplist
)) then
1178 SetLength(tcomplist
, Length(tcomplist
)+128);
1179 SetLength(tcompidx
, Length(tcompidx
)+128);
1181 tcomplist
[tused
] := cmd
;
1182 tcompidx
[tused
] := i
;
1184 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1188 // get longest prefix
1189 for i
:= 0 to tused
-1 do
1191 cmd
:= tcomplist
[i
];
1192 for c
:= 1 to Length(lpfx
) do
1194 if (c
> Length(cmd
)) then break
;
1195 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1199 if (tused
= 0) then exit
;
1203 Line
:= tcomplist
[0]+' ';
1204 CPos
:= Length(Line
)+1;
1208 // has longest prefix?
1209 if (Length(lpfx
) > Length(ll
)) then
1212 CPos
:= Length(Line
)+1;
1217 for i
:= 0 to tused
-1 do
1219 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1221 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1225 g_Console_Add(' '+tcomplist
[i
]);
1233 procedure g_Console_Control(K
: Word);
1237 if (Length(Line
) > 0) and (CPos
> 1) then
1239 Delete(Line
, CPos
-1, 1);
1243 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1244 Delete(Line
, CPos
, 1);
1245 IK_LEFT
, IK_KPLEFT
, VK_LEFT
:
1248 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
:
1249 if CPos
<= Length(Line
) then
1251 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
:
1254 g_Console_Process(Line
)
1258 if (Length(Line
) > 0) and g_Game_IsNet
then
1262 if g_Game_IsClient
then
1263 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1265 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1266 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1270 if g_Game_IsClient
then
1271 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1273 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1281 gJustChatted
:= True;
1282 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1286 if not gChatShow
then
1288 IK_DOWN
, IK_KPDOWN
, VK_DOWN
:
1289 if not gChatShow
then
1290 if (CommandHistory
<> nil) and
1291 (CmdIndex
< Length(CommandHistory
)) then
1293 if CmdIndex
< Length(CommandHistory
)-1 then
1294 CmdIndex
:= CmdIndex
+ 1;
1295 Line
:= CommandHistory
[CmdIndex
];
1296 CPos
:= Length(Line
) + 1;
1298 IK_UP
, IK_KPUP
, VK_UP
:
1299 if not gChatShow
then
1300 if (CommandHistory
<> nil) and
1301 (CmdIndex
<= Length(CommandHistory
)) then
1303 if CmdIndex
> 0 then
1304 CmdIndex
:= CmdIndex
- 1;
1305 Line
:= CommandHistory
[CmdIndex
];
1306 Cpos
:= Length(Line
) + 1;
1308 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
: // PgUp
1309 if not gChatShow
then Inc(conSkipLines
);
1310 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
: // PgDown
1311 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1315 CPos
:= Length(Line
) + 1;
1319 function GetStr(var Str
: AnsiString): AnsiString;
1324 if Str
[1] = '"' then
1326 for b
:= 1 to Length(Str
) do
1327 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1329 Result
:= Copy(Str
, 2, b
-1);
1330 Delete(Str
, 1, b
+1);
1336 for a
:= 1 to Length(Str
) do
1337 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1339 Result
:= Copy(Str
, 1, a
);
1340 Delete(Str
, 1, a
+1);
1346 function ParseString(Str
: AnsiString): SSArray
;
1357 SetLength(Result
, Length(Result
)+1);
1358 Result
[High(Result
)] := GetStr(Str
);
1362 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1364 procedure conmsg (s
: AnsiString);
1368 if length(s
) = 0 then exit
;
1369 for a
:= 0 to High(MsgArray
) do
1381 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1382 with MsgArray
[High(MsgArray
)] do
1392 // put it to console
1394 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1396 // now show 'em out of console too
1397 show
:= show
and gAllowConsoleMessages
;
1398 if show
and gShowMessages
then
1400 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1401 while length(L
) > 0 do
1404 if f
<= 0 then f
:= length(L
)+1;
1405 conmsg(Copy(L
, 1, f
-1));
1410 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1411 //ConsoleHistory[High(ConsoleHistory)] := L;
1415 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1422 consolewriterLastWasEOL
: Boolean = false;
1424 procedure consolewriter (constref buf
; len
: SizeUInt
);
1428 if (len
< 1) then exit
;
1430 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1433 if (b
[0] <> 13) and (b
[0] <> 10) then
1435 cbufPut(AnsiChar(b
[0]));
1439 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1448 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1449 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1450 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1451 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1453 g_Console_Add(s
, show
);
1457 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1461 g_Console_Add(formatstrf(s
, args
), true);
1465 consolewriterLastWasEOL
:= false;
1466 formatstrf(s
, args
, consolewriter
);
1467 if not consolewriterLastWasEOL
then cbufPut(#10);
1472 procedure g_Console_Clear();
1474 //ConsoleHistory := nil;
1479 procedure AddToHistory(L
: AnsiString);
1483 len
:= Length(CommandHistory
);
1486 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1488 SetLength(CommandHistory
, len
+1);
1489 CommandHistory
[len
] := L
;
1492 CmdIndex
:= Length(CommandHistory
);
1495 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1504 if Trim(C
) = '' then
1507 Arr
:= ParseString(C
);
1511 for i
:= 0 to High(Whitelist
) do
1512 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1516 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1523 if Trim(L
) = '' then
1526 conSkipLines
:= 0; // "unscroll"
1528 if L
= 'goobers' then
1533 g_Console_Add('Your memory serves you well.');
1539 g_Console_Add('> '+L
);
1544 Arr
:= ParseString(L
);
1548 if commands
= nil then
1554 for i
:= 0 to High(commands
) do
1556 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1558 if commands
[i
].action
>= 0 then
1563 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+'
1565 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := gDefaultAction
[commands
[i
].player
, commands
[i
].action
]
1569 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1570 gDefaultAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+'
1574 else if bindProcess
and not bindDown
then
1576 (* command is not action, so do not execute it again after button release *)
1580 if assigned(commands
[i
].procEx
) then
1582 commands
[i
].procEx(@commands
[i
], Arr
);
1585 if assigned(commands
[i
].proc
) then
1587 commands
[i
].proc(Arr
);
1593 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1597 function g_Console_Interactive
: Boolean;
1599 Result
:= not bindProcess
1602 procedure g_Console_BindKey (key
: Integer; cmd
: AnsiString);
1605 ASSERT(key
< e_MaxInputKeys
);
1606 gInputBinds
[key
].commands
:= ParseAlias(cmd
)
1609 function g_Console_FindBind (n
: Integer; cmd
: AnsiString): Integer;
1614 if commands
= nil then Exit
;
1616 cmd
:= LowerCase(cmd
);
1617 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1619 if (Length(gInputBinds
[i
].commands
) = 1) and (gInputBinds
[i
].commands
[0] = cmd
) then
1630 function g_Console_Action (action
: Integer): Boolean;
1631 var i
, len
: Integer;
1633 ASSERT(action
>= FIRST_ACTION
);
1634 ASSERT(action
<= LAST_ACTION
);
1636 len
:= Length(gPlayerAction
);
1637 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1641 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1644 if (not gChatShow
) and (not gConsoleShow
) and (key
>= 0) and (key
< e_MaxInputKeys
) and (gInputBinds
[key
].commands
<> nil) then
1647 bindProcess
:= True;
1648 for i
:= 0 to High(gInputBinds
[key
].commands
) do
1649 g_Console_Process(gInputBinds
[key
].commands
[i
], True);
1650 bindProcess
:= False;
1655 procedure g_Console_ReadConfig (filename
: String);
1656 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1658 if FileExists(filename
) then
1660 AssignFile(f
, filename
);
1670 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1672 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1673 g_Console_Process(s
, True)