ecc6677e9d30b0b97ecffbc8e9a378d40520b011
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}
50 LAST_ACTION
= ACTION_WEAP11
;
51 MAX_ACTION_WEAP
= ACTION_WEAP11
- ACTION_WEAP1
+ 1;
53 procedure g_Console_Init ();
54 procedure g_Console_Update ();
55 procedure g_Console_Draw ();
56 procedure g_Console_Switch ();
57 procedure g_Console_Char (C
: AnsiChar);
58 procedure g_Console_Control (K
: Word);
59 procedure g_Console_Process (L
: AnsiString; quiet
: Boolean=false);
60 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
61 procedure g_Console_Clear ();
62 function g_Console_CommandBlacklisted (C
: AnsiString): Boolean;
63 procedure g_Console_ReadConfig (filename
: String);
65 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
67 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
68 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
70 // <0: no arg; 0/1: true/false
71 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
73 procedure g_Console_Chat_Switch (team
: Boolean=false);
75 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
76 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
77 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
79 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
80 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
84 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
85 gChatShow
: Boolean = false;
86 gChatTeam
: Boolean = false;
87 gAllowConsoleMessages
: Boolean = true;
88 gChatEnter
: Boolean = true;
89 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
90 gPlayerAction
: Array [0..1, 0..LAST_ACTION
] of Boolean; // [player, action]
95 g_textures
, g_main
, e_graphics
, e_input
, g_game
,
96 SysUtils
, g_basic
, g_options
, Math
, g_touch
,
97 g_menu
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
101 PCommand
= ^TCommand
;
103 TCmdProc
= procedure (p
: SSArray
);
104 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
112 ptr
: Pointer; // various data
113 msg
: AnsiString; // message for var changes
127 MaxScriptRecursion
= 16;
129 DEBUG_STRING
= 'DEBUG MODE';
133 RecursionDepth
: Word = 0;
134 RecursionLimitHit
: Boolean = False;
136 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
139 //ConsoleHistory: SSArray;
140 CommandHistory
: SSArray
;
142 commands
: Array of TCommand
= nil;
143 Aliases
: Array of TAlias
= nil;
145 conSkipLines
: Integer = 0;
146 MsgArray
: Array [0..4] of record
150 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
153 bindDown
, bindProcess
: Boolean;
156 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
157 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
166 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
167 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
168 if (pos
> slen
) then exit
;
169 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
171 while (pos
<= slen
) do
173 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
174 res
:= res
*10+Byte(s
[pos
])-48;
177 if (pos
<= slen
) then
180 if (s
[pos
] <> '.') then exit
;
182 while (pos
<= slen
) do
184 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
186 res
+= frac
*(Byte(s
[pos
])-48);
190 if (pos
<= slen
) then exit
; // oops
195 // ////////////////////////////////////////////////////////////////////////// //
196 // <0: no arg; 0/1: true/false; 666: toggle
197 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
199 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
201 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
202 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
203 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
204 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
208 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
209 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
211 if (Length(p
) > 2) then
213 conwritefln('too many arguments to ''%s''', [p
[0]]);
217 case conGetBoolArg(p
, 1) of
219 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
220 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
221 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
223 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
224 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
228 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
232 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
233 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
235 if (Length(p
) > 2) then
237 conwritefln('too many arguments to ''%s''', [p
[0]]);
241 case conGetBoolArg(p
, 1) of
243 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
244 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
245 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
247 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
248 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
252 if (Length(p
) <> 2) then
254 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
259 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
261 conwritefln('invalid integer value: "%s"', [p
[1]]);
267 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
272 f
:= Length(commands
);
273 SetLength(commands
, f
+1);
275 cp
.cmd
:= LowerCase(conname
);
277 cp
.procEx
:= boolVarHandler
;
279 cp
.hidden
:= ahidden
;
286 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
291 f
:= Length(commands
);
292 SetLength(commands
, f
+1);
294 cp
.cmd
:= LowerCase(conname
);
296 cp
.procEx
:= intVarHandler
;
298 cp
.hidden
:= ahidden
;
305 // ////////////////////////////////////////////////////////////////////////// //
307 PVarSingle
= ^TVarSingle
;
310 min
, max
, def
: Single; // default will be starting value
314 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
320 if (Length(p
) > 2) then
322 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
325 pv
:= PVarSingle(me
.ptr
);
326 if (Length(p
) = 2) then
328 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
329 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
330 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
331 (CompareText(p
[1], 'ona') = 0) then
337 if not conParseFloat(nv
, p
[1]) then
339 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
342 if (nv
< pv
.min
) then nv
:= pv
.min
;
343 if (nv
> pv
.max
) then nv
:= pv
.max
;
348 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
349 conwritefln('%s %s', [msg
, pv
.val
^]);
353 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
359 GetMem(pv
, sizeof(TVarSingle
));
364 f
:= Length(commands
);
365 SetLength(commands
, f
+1);
367 cp
.cmd
:= LowerCase(conname
);
369 cp
.procEx
:= singleVarHandler
;
371 cp
.hidden
:= ahidden
;
378 // ////////////////////////////////////////////////////////////////////////// //
379 function GetStrACmd(var Str
: AnsiString): AnsiString;
384 for a
:= 1 to Length(Str
) do
385 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
387 Result
:= Copy(Str
, 1, a
);
394 function ParseAlias(Str
: AnsiString): SSArray
;
405 SetLength(Result
, Length(Result
)+1);
406 Result
[High(Result
)] := GetStrACmd(Str
);
410 procedure ConsoleCommands(p
: SSArray
);
416 cmd
:= LowerCase(p
[0]);
419 if cmd
= 'clear' then
421 //ConsoleHistory := nil;
425 for a
:= 0 to High(MsgArray
) do
433 if cmd
= 'clearhistory' then
434 CommandHistory
:= nil;
436 if cmd
= 'showhistory' then
437 if CommandHistory
<> nil then
440 for a
:= 0 to High(CommandHistory
) do
441 g_Console_Add(' '+CommandHistory
[a
]);
444 if cmd
= 'commands' then
447 g_Console_Add('commands list:');
448 for a
:= High(commands
) downto 0 do
450 if (Length(commands
[a
].help
) > 0) then
452 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
456 g_Console_Add(' '+commands
[a
].cmd
);
462 g_Console_Add(TimeToStr(Now
), True);
465 g_Console_Add(DateToStr(Now
), True);
468 if Length(p
) > 1 then
470 if p
[1] = 'ololo' then
475 for a
:= 1 to High(p
) do
477 g_Console_Add(b_Text_Format(s
), True);
486 if ConsoleHistory <> nil then
488 if Length(P) > 1 then
491 s := GameDir+'/console.txt';
496 if IOResult <> 0 then
498 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
503 for a := 0 to High(ConsoleHistory) do
504 WriteLn(F, ConsoleHistory[a]);
507 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
516 if Length(p
) = 2 then
518 s
:= GameDir
+ '/' + p
[1];
519 g_Console_ReadConfig(s
);
522 g_Console_Add('exec <script file>');
525 if (cmd
= 'ver') or (cmd
= 'version') then
527 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
528 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
529 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
532 if cmd
= 'alias' then
534 // alias [alias_name] [commands]
535 if Length(p
) > 1 then
537 for a
:= 0 to High(Aliases
) do
538 if Aliases
[a
].name
= p
[1] then
540 if Length(p
) > 2 then
541 Aliases
[a
].commands
:= ParseAlias(p
[2])
543 for b
:= 0 to High(Aliases
[a
].commands
) do
544 g_Console_Add(Aliases
[a
].commands
[b
]);
547 SetLength(Aliases
, Length(Aliases
)+1);
549 Aliases
[a
].name
:= p
[1];
550 if Length(p
) > 2 then
551 Aliases
[a
].commands
:= ParseAlias(p
[2])
553 for b
:= 0 to High(Aliases
[a
].commands
) do
554 g_Console_Add(Aliases
[a
].commands
[b
]);
556 for a
:= 0 to High(Aliases
) do
557 if Aliases
[a
].commands
<> nil then
558 g_Console_Add(Aliases
[a
].name
);
564 if Length(p
) > 1 then
566 if Aliases
= nil then
568 for a
:= 0 to High(Aliases
) do
569 if Aliases
[a
].name
= p
[1] then
571 if Aliases
[a
].commands
<> nil then
573 // with this system proper endless loop detection seems either impossible
574 // or very dirty to implement, so let's have this instead
575 // prevents endless loops
576 for b
:= 0 to High(Aliases
[a
].commands
) do
579 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
580 if not RecursionLimitHit
then
581 g_Console_Process(Aliases
[a
].commands
[b
], True);
584 if (RecursionDepth
= 0) and RecursionLimitHit
then
586 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
587 RecursionLimitHit
:= False;
594 g_Console_Add('call <alias name>');
601 procedure WhitelistCommand(cmd
: AnsiString);
605 SetLength(Whitelist
, Length(Whitelist
)+1);
606 a
:= High(Whitelist
);
607 Whitelist
[a
] := LowerCase(cmd
);
610 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
615 SetLength(commands
, Length(commands
)+1);
618 cp
.cmd
:= LowerCase(cmd
);
622 cp
.hidden
:= ahidden
;
629 procedure segfault (p
: SSArray
);
637 procedure BindCommands (p
: SSArray
);
638 var cmd
, key
, act
: AnsiString; i
: Integer;
640 cmd
:= LowerCase(p
[0]);
643 // bind <key> <action>
644 if Length(p
) = 3 then
646 key
:= LowerCase(p
[1]);
649 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
650 if i
< e_MaxInputKeys
then
651 gInputBinds
[i
].cmd
:= act
654 for i
:= 0 to e_MaxInputKeys
- 1 do
655 if gInputBinds
[i
].cmd
<> '' then
656 g_Console_Add(LowerCase(e_KeyNames
[i
]) + ' "' + gInputBinds
[i
].cmd
+ '"');
659 if Length(p
) = 2 then
661 key
:= LowerCase(p
[1]);
663 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
664 if i
< e_MaxInputKeys
then
665 gInputBinds
[i
].cmd
:= ''
668 for i
:= 0 to e_MaxInputKeys
- 1 do
669 gInputBinds
[i
].cmd
:= '';
671 for i
:= 0 to e_MaxInputKeys
- 1 do
672 if e_KeyNames
[i
] <> '' then
673 g_Console_Add(IntToStr(i
) + ': ' + LowerCase(e_KeyNames
[i
]));
678 procedure KeyActionCommands (p
: SSArray
);
679 var cmd
: AnsiString; val
: Boolean; player
, action
, offset
: Integer;
681 // syntax: ("+" | "-") ["p" digit "_"] Command
682 cmd
:= LowerCase(p
[0]);
685 val
:= (not bindProcess
) or (bindProcess
and bindDown
)
686 else if cmd
[1] = '-' then
687 val
:= bindProcess
and bindDown
693 if (Length(cmd
) >= 4) and (cmd
[2] = 'p') and (cmd
[3] >= '1') and (cmd
[3] <= '9') and (cmd
[4] = '_') then
695 player
:= ord(cmd
[3]) - ord('1') - 1;
699 case Copy(cmd
, offset
) of
700 'moveup': action
:= ACTION_MOVEUP
;
701 'movedown': action
:= ACTION_MOVEDOWN
;
702 'moveleft': action
:= ACTION_MOVELEFT
;
703 'moveright': action
:= ACTION_MOVERIGHT
;
704 'speed': action
:= ACTION_SPEED
;
705 'scores': action
:= ACTION_SCORES
;
706 'lookup': action
:= ACTION_LOOKUP
;
707 'lookdown': action
:= ACTION_LOOKDOWN
;
708 'attack': action
:= ACTION_ATTACK
;
709 'activate': action
:= ACTION_ACTIVATE
;
710 'strafe': action
:= ACTION_STRAFE
;
711 'weapnext': action
:= ACTION_WEAPNEXT
;
712 'weapprev': action
:= ACTION_WEAPPREV
;
717 gPlayerAction
[player
, action
] := val
;
720 procedure ActionCommands (p
: SSArray
);
721 var cmd
: AnsiString; i
, player
, offset
, action
: Integer;
723 cmd
:= LowerCase(p
[0]);
727 if (Length(cmd
) >= 3) and (cmd
[1] = 'p') and (cmd
[2] >= '1') and (cmd
[2] <= '9') and (cmd
[3] = '_') then
729 player
:= ord(cmd
[2]) - ord('1') - 1;
733 case Copy(cmd
, offset
) of
734 'weapnext': action
:= ACTION_WEAPNEXT
;
735 'weapprev': action
:= ACTION_WEAPPREV
;
737 if Length(p
) = 2 then
740 if (i
> 0) and (i
<= MAX_ACTION_WEAP
) then
741 action
:= ACTION_WEAP1
+ i
- 1
749 gPlayerAction
[player
, action
] := bindDown
;
752 procedure g_Console_Init();
754 PrefixList
: array [0..1] of AnsiString = ('+', '-');
755 PlayerList
: array [0..2] of AnsiString = ('', 'p1_', 'p2_');
756 KeyActionList
: array [0..12] of AnsiString = ('moveup', 'movedown', 'moveleft', 'moveright', 'speed', 'scores', 'lookup', 'lookdown', 'attack', 'activate', 'strafe', 'weapnext', 'weapprev');
757 ActionList
: array [0..2] of AnsiString = ('weapnext', 'weapprev', 'weapon');
760 s0
, s1
, s2
: AnsiString;
762 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
763 Cons_Y
:= -(gScreenHeight
div 2);
764 gConsoleShow
:= False;
769 for a
:= 0 to High(MsgArray
) do
776 AddCommand('segfault', segfault
, 'make segfault');
778 AddCommand('bind', BindCommands
);
779 AddCommand('bindlist', BindCommands
);
780 AddCommand('unbind', BindCommands
);
781 AddCommand('unbindall', BindCommands
);
782 AddCommand('bindkeys', BindCommands
);
784 for s0
in PrefixList
do
785 for s1
in PlayerList
do
786 for s2
in KeyActionList
do
787 AddCommand(s0
+ s1
+ s2
, KeyActionCommands
);
789 for s1
in PlayerList
do
790 for s2
in ActionList
do
791 AddCommand(s1
+ s2
, ActionCommands
);
793 AddCommand('clear', ConsoleCommands
, 'clear console');
794 AddCommand('clearhistory', ConsoleCommands
);
795 AddCommand('showhistory', ConsoleCommands
);
796 AddCommand('commands', ConsoleCommands
);
797 AddCommand('time', ConsoleCommands
);
798 AddCommand('date', ConsoleCommands
);
799 AddCommand('echo', ConsoleCommands
);
800 AddCommand('dump', ConsoleCommands
);
801 AddCommand('exec', ConsoleCommands
);
802 AddCommand('alias', ConsoleCommands
);
803 AddCommand('call', ConsoleCommands
);
804 AddCommand('ver', ConsoleCommands
);
805 AddCommand('version', ConsoleCommands
);
807 AddCommand('d_window', DebugCommands
);
808 AddCommand('d_sounds', DebugCommands
);
809 AddCommand('d_frames', DebugCommands
);
810 AddCommand('d_winmsg', DebugCommands
);
811 AddCommand('d_monoff', DebugCommands
);
812 AddCommand('d_botoff', DebugCommands
);
813 AddCommand('d_monster', DebugCommands
);
814 AddCommand('d_health', DebugCommands
);
815 AddCommand('d_player', DebugCommands
);
816 AddCommand('d_joy', DebugCommands
);
817 AddCommand('d_mem', DebugCommands
);
819 AddCommand('p1_name', GameCVars
);
820 AddCommand('p2_name', GameCVars
);
821 AddCommand('p1_color', GameCVars
);
822 AddCommand('p2_color', GameCVars
);
823 AddCommand('r_showfps', GameCVars
);
824 AddCommand('r_showtime', GameCVars
);
825 AddCommand('r_showscore', GameCVars
);
826 AddCommand('r_showlives', GameCVars
);
827 AddCommand('r_showstat', GameCVars
);
828 AddCommand('r_showkillmsg', GameCVars
);
829 AddCommand('r_showspect', GameCVars
);
830 AddCommand('r_showping', GameCVars
);
831 AddCommand('g_gamemode', GameCVars
);
832 AddCommand('g_friendlyfire', GameCVars
);
833 AddCommand('g_weaponstay', GameCVars
);
834 AddCommand('g_allow_exit', GameCVars
);
835 AddCommand('g_allow_monsters', GameCVars
);
836 AddCommand('g_bot_vsmonsters', GameCVars
);
837 AddCommand('g_bot_vsplayers', GameCVars
);
838 AddCommand('g_scorelimit', GameCVars
);
839 AddCommand('g_timelimit', GameCVars
);
840 AddCommand('g_maxlives', GameCVars
);
841 AddCommand('g_warmuptime', GameCVars
);
842 AddCommand('net_interp', GameCVars
);
843 AddCommand('net_forceplayerupdate', GameCVars
);
844 AddCommand('net_predictself', GameCVars
);
845 AddCommand('sv_name', GameCVars
);
846 AddCommand('sv_passwd', GameCVars
);
847 AddCommand('sv_maxplrs', GameCVars
);
848 AddCommand('sv_public', GameCVars
);
849 AddCommand('sv_intertime', GameCVars
);
851 AddCommand('quit', GameCommands
);
852 AddCommand('exit', GameCommands
);
853 AddCommand('pause', GameCommands
);
854 AddCommand('endgame', GameCommands
);
855 AddCommand('restart', GameCommands
);
856 AddCommand('addbot', GameCommands
);
857 AddCommand('bot_add', GameCommands
);
858 AddCommand('bot_addlist', GameCommands
);
859 AddCommand('bot_addred', GameCommands
);
860 AddCommand('bot_addblue', GameCommands
);
861 AddCommand('bot_removeall', GameCommands
);
862 AddCommand('chat', GameCommands
);
863 AddCommand('teamchat', GameCommands
);
864 AddCommand('game', GameCommands
);
865 AddCommand('host', GameCommands
);
866 AddCommand('map', GameCommands
);
867 AddCommand('nextmap', GameCommands
);
868 AddCommand('endmap', GameCommands
);
869 AddCommand('goodbye', GameCommands
);
870 AddCommand('suicide', GameCommands
);
871 AddCommand('spectate', GameCommands
);
872 AddCommand('ready', GameCommands
);
873 AddCommand('kick', GameCommands
);
874 AddCommand('kick_id', GameCommands
);
875 AddCommand('ban', GameCommands
);
876 AddCommand('permban', GameCommands
);
877 AddCommand('ban_id', GameCommands
);
878 AddCommand('permban_id', GameCommands
);
879 AddCommand('unban', GameCommands
);
880 AddCommand('connect', GameCommands
);
881 AddCommand('disconnect', GameCommands
);
882 AddCommand('reconnect', GameCommands
);
883 AddCommand('say', GameCommands
);
884 AddCommand('tell', GameCommands
);
885 AddCommand('overtime', GameCommands
);
886 AddCommand('rcon_password', GameCommands
);
887 AddCommand('rcon', GameCommands
);
888 AddCommand('callvote', GameCommands
);
889 AddCommand('vote', GameCommands
);
890 AddCommand('clientlist', GameCommands
);
891 AddCommand('event', GameCommands
);
893 AddCommand('god', GameCheats
);
894 AddCommand('notarget', GameCheats
);
895 AddCommand('give', GameCheats
); // "exit" too ;-)
896 AddCommand('open', GameCheats
);
897 AddCommand('fly', GameCheats
);
898 AddCommand('noclip', GameCheats
);
899 AddCommand('speedy', GameCheats
);
900 AddCommand('jumpy', GameCheats
);
901 AddCommand('noreload', GameCheats
);
902 AddCommand('aimline', GameCheats
);
903 AddCommand('automap', GameCheats
);
905 WhitelistCommand('say');
906 WhitelistCommand('tell');
907 WhitelistCommand('overtime');
908 WhitelistCommand('ready');
909 WhitelistCommand('map');
910 WhitelistCommand('nextmap');
911 WhitelistCommand('endmap');
912 WhitelistCommand('restart');
913 WhitelistCommand('kick');
914 WhitelistCommand('ban');
916 WhitelistCommand('addbot');
917 WhitelistCommand('bot_add');
918 WhitelistCommand('bot_addred');
919 WhitelistCommand('bot_addblue');
920 WhitelistCommand('bot_removeall');
922 WhitelistCommand('g_gamemode');
923 WhitelistCommand('g_friendlyfire');
924 WhitelistCommand('g_weaponstay');
925 WhitelistCommand('g_allow_exit');
926 WhitelistCommand('g_allow_monsters');
927 WhitelistCommand('g_scorelimit');
928 WhitelistCommand('g_timelimit');
930 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
933 g_Console_ReadConfig(GameDir
+ '/dfconfig.cfg');
934 g_Console_ReadConfig(GameDir
+ '/autoexec.cfg');
937 procedure g_Console_Update();
943 // Â ïðîöåññå îòêðûòèÿ:
944 if gConsoleShow
and (Cons_Y
< 0) then
946 Cons_Y
:= Cons_Y
+Step
;
949 // Â ïðîöåññå çàêðûòèÿ:
950 if (not gConsoleShow
) and
951 (Cons_Y
> -(gScreenHeight
div 2)) then
952 Cons_Y
:= Cons_Y
-Step
;
954 // Îêîí÷àòåëüíî îòêðûëàñü:
958 // Îêîí÷àòåëüíî çàêðûëàñü:
959 if Cons_Y
<= (-(gScreenHeight
div 2)) then
961 Cons_Y
:= -(gScreenHeight
div 2);
967 while a
<= High(MsgArray
) do
969 if MsgArray
[a
].Time
> 0 then
971 if MsgArray
[a
].Time
= 1 then
973 if a
< High(MsgArray
) then
975 for b
:= a
to High(MsgArray
)-1 do
976 MsgArray
[b
] := MsgArray
[b
+1];
978 MsgArray
[High(MsgArray
)].Time
:= 0;
984 Dec(MsgArray
[a
].Time
);
992 procedure drawConsoleText ();
994 CWidth
, CHeight
: Byte;
999 procedure putLine (sp
, ep
: LongWord);
1008 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1009 if wdt
+cw
> gScreenWidth
-8 then break
;
1010 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1014 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1015 // now print our part
1023 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1024 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1037 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1038 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
1039 skip
:= conSkipLines
;
1040 cbufLastLine(sp
, ep
);
1043 if ty
+CHeight
<= 0 then break
;
1044 until not cbufLineUp(sp
, ep
);
1047 procedure g_Console_Draw();
1049 CWidth
, CHeight
: Byte;
1053 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1055 for a
:= 0 to High(MsgArray
) do
1056 if MsgArray
[a
].Time
> 0 then
1057 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
1060 if not Cons_Shown
then
1066 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
1067 gStdFont
, 255, 255, 255, 1, True);
1068 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1069 gStdFont
, 255, 255, 255, 1, True);
1073 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
1074 gStdFont
, 255, 255, 255, 1, True);
1075 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1076 gStdFont
, 255, 255, 255, 1, True);
1084 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1085 a
:= (gScreenWidth
- 2*mfW
) div 2;
1086 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
1087 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1088 _RGB(128, 0, 0), 2.0);
1091 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
1092 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
1096 if ConsoleHistory <> nil then
1100 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
1101 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
1103 b := Max(b-Offset, 0);
1104 d := Max(High(ConsoleHistory)-Offset, 0);
1107 for a := d downto b do
1109 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
1116 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
1119 procedure g_Console_Switch();
1121 if gChatShow
then Exit
;
1122 gConsoleShow
:= not gConsoleShow
;
1124 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1127 procedure g_Console_Chat_Switch(Team
: Boolean = False);
1129 if gConsoleShow
then Exit
;
1130 if not g_Game_IsNet
then Exit
;
1131 gChatShow
:= not gChatShow
;
1134 gChatEnter
:= False;
1137 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1140 procedure g_Console_Char(C
: AnsiChar);
1142 if gChatShow
and (not gChatEnter
) then
1144 Insert(C
, Line
, CPos
);
1150 tcomplist
: array of AnsiString = nil;
1151 tcompidx
: array of Integer = nil;
1153 procedure Complete ();
1157 ll
, lpfx
, cmd
: AnsiString;
1159 if (Length(Line
) = 0) then
1162 for i
:= 0 to High(commands
) do
1164 // hidden commands are hidden when cheats aren't enabled
1165 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1166 if (Length(commands
[i
].help
) > 0) then
1168 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1172 g_Console_Add(' '+commands
[i
].cmd
);
1178 ll
:= LowerCase(Line
);
1181 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1183 ll
:= Copy(ll
, 0, Length(ll
)-1);
1184 for i
:= 0 to High(commands
) do
1186 // hidden commands are hidden when cheats aren't enabled
1187 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1188 if (commands
[i
].cmd
= ll
) then
1190 if (Length(commands
[i
].help
) > 0) then
1192 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1199 // build completion list
1201 for i
:= 0 to High(commands
) do
1203 // hidden commands are hidden when cheats aren't enabled
1204 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1205 cmd
:= commands
[i
].cmd
;
1206 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1208 if (tused
= Length(tcomplist
)) then
1210 SetLength(tcomplist
, Length(tcomplist
)+128);
1211 SetLength(tcompidx
, Length(tcompidx
)+128);
1213 tcomplist
[tused
] := cmd
;
1214 tcompidx
[tused
] := i
;
1216 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1220 // get longest prefix
1221 for i
:= 0 to tused
-1 do
1223 cmd
:= tcomplist
[i
];
1224 for c
:= 1 to Length(lpfx
) do
1226 if (c
> Length(cmd
)) then break
;
1227 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1231 if (tused
= 0) then exit
;
1235 Line
:= tcomplist
[0]+' ';
1236 CPos
:= Length(Line
)+1;
1240 // has longest prefix?
1241 if (Length(lpfx
) > Length(ll
)) then
1244 CPos
:= Length(Line
)+1;
1249 for i
:= 0 to tused
-1 do
1251 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1253 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1257 g_Console_Add(' '+tcomplist
[i
]);
1265 procedure g_Console_Control(K
: Word);
1269 if (Length(Line
) > 0) and (CPos
> 1) then
1271 Delete(Line
, CPos
-1, 1);
1275 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1276 Delete(Line
, CPos
, 1);
1277 IK_LEFT
, IK_KPLEFT
, VK_LEFT
:
1280 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
:
1281 if CPos
<= Length(Line
) then
1283 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
:
1286 g_Console_Process(Line
)
1290 if (Length(Line
) > 0) and g_Game_IsNet
then
1294 if g_Game_IsClient
then
1295 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1297 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1298 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1302 if g_Game_IsClient
then
1303 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1305 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1313 gJustChatted
:= True;
1314 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1318 if not gChatShow
then
1320 IK_DOWN
, IK_KPDOWN
, VK_DOWN
:
1321 if not gChatShow
then
1322 if (CommandHistory
<> nil) and
1323 (CmdIndex
< Length(CommandHistory
)) then
1325 if CmdIndex
< Length(CommandHistory
)-1 then
1326 CmdIndex
:= CmdIndex
+ 1;
1327 Line
:= CommandHistory
[CmdIndex
];
1328 CPos
:= Length(Line
) + 1;
1330 IK_UP
, IK_KPUP
, VK_UP
:
1331 if not gChatShow
then
1332 if (CommandHistory
<> nil) and
1333 (CmdIndex
<= Length(CommandHistory
)) then
1335 if CmdIndex
> 0 then
1336 CmdIndex
:= CmdIndex
- 1;
1337 Line
:= CommandHistory
[CmdIndex
];
1338 Cpos
:= Length(Line
) + 1;
1340 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
: // PgUp
1341 if not gChatShow
then Inc(conSkipLines
);
1342 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
: // PgDown
1343 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1347 CPos
:= Length(Line
) + 1;
1351 function GetStr(var Str
: AnsiString): AnsiString;
1356 if Str
[1] = '"' then
1358 for b
:= 1 to Length(Str
) do
1359 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1361 Result
:= Copy(Str
, 2, b
-1);
1362 Delete(Str
, 1, b
+1);
1368 for a
:= 1 to Length(Str
) do
1369 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1371 Result
:= Copy(Str
, 1, a
);
1372 Delete(Str
, 1, a
+1);
1378 function ParseString(Str
: AnsiString): SSArray
;
1389 SetLength(Result
, Length(Result
)+1);
1390 Result
[High(Result
)] := GetStr(Str
);
1394 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1396 procedure conmsg (s
: AnsiString);
1400 if length(s
) = 0 then exit
;
1401 for a
:= 0 to High(MsgArray
) do
1413 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1414 with MsgArray
[High(MsgArray
)] do
1424 // put it to console
1426 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1428 // now show 'em out of console too
1429 show
:= show
and gAllowConsoleMessages
;
1430 if show
and gShowMessages
then
1432 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1433 while length(L
) > 0 do
1436 if f
<= 0 then f
:= length(L
)+1;
1437 conmsg(Copy(L
, 1, f
-1));
1442 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1443 //ConsoleHistory[High(ConsoleHistory)] := L;
1447 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1454 consolewriterLastWasEOL
: Boolean = false;
1456 procedure consolewriter (constref buf
; len
: SizeUInt
);
1460 if (len
< 1) then exit
;
1462 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1465 if (b
[0] <> 13) and (b
[0] <> 10) then
1467 cbufPut(AnsiChar(b
[0]));
1471 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1480 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1481 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1482 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1483 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1485 g_Console_Add(s
, show
);
1489 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1493 g_Console_Add(formatstrf(s
, args
), true);
1497 consolewriterLastWasEOL
:= false;
1498 formatstrf(s
, args
, consolewriter
);
1499 if not consolewriterLastWasEOL
then cbufPut(#10);
1504 procedure g_Console_Clear();
1506 //ConsoleHistory := nil;
1511 procedure AddToHistory(L
: AnsiString);
1515 len
:= Length(CommandHistory
);
1518 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1520 SetLength(CommandHistory
, len
+1);
1521 CommandHistory
[len
] := L
;
1524 CmdIndex
:= Length(CommandHistory
);
1527 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1536 if Trim(C
) = '' then
1539 Arr
:= ParseString(C
);
1543 for i
:= 0 to High(Whitelist
) do
1544 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1548 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1555 if Trim(L
) = '' then
1558 conSkipLines
:= 0; // "unscroll"
1560 if L
= 'goobers' then
1565 g_Console_Add('Your memory serves you well.');
1571 g_Console_Add('> '+L
);
1576 Arr
:= ParseString(L
);
1580 if commands
= nil then
1586 for i
:= 0 to High(commands
) do
1588 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1590 if assigned(commands
[i
].procEx
) then
1592 commands
[i
].procEx(@commands
[i
], Arr
);
1595 if assigned(commands
[i
].proc
) then
1597 commands
[i
].proc(Arr
);
1603 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1607 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1609 if (key
>= 0) and (key
< e_MaxInputKeys
) and (gInputBinds
[key
].cmd
<> '') then
1612 bindProcess
:= True;
1613 g_Console_Process(gInputBinds
[key
].cmd
, True);
1614 bindProcess
:= False;
1619 procedure g_Console_ReadConfig (filename
: String);
1620 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1622 if FileExists(filename
) then
1624 AssignFile(f
, filename
);
1634 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1636 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1637 g_Console_Process(s
)