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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
36 FIRST_ACTION
= ACTION_JUMP
;
37 LAST_ACTION
= ACTION_WEAPPREV
;
39 var (* private state *)
42 conSkipLines
: Integer;
43 MsgArray
: Array [0..4] of record
48 procedure g_Console_Init
;
49 procedure g_Console_Initialize
;
50 procedure g_Console_Finalize
;
51 procedure g_Console_Update
;
52 procedure g_Console_Char (C
: AnsiChar);
53 procedure g_Console_Control (K
: Word);
54 procedure g_Console_Process (L
: AnsiString; quiet
: Boolean=false);
55 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
56 procedure g_Console_Clear
;
57 function g_Console_CommandBlacklisted (C
: AnsiString): Boolean;
58 procedure g_Console_ReadConfig (filename
: String);
59 procedure g_Console_WriteConfig (filename
: String);
60 procedure g_Console_WriteGameConfig
;
62 function g_Console_Interactive
: Boolean;
63 function g_Console_Action (action
: Integer): Boolean;
64 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
65 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
66 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
67 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
68 procedure g_Console_ProcessBindRepeat (key
: Integer);
69 procedure g_Console_ResetBinds
;
71 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
72 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
74 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
75 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
76 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
77 procedure conRegVar (const conname
: AnsiString; pvar
: PWord; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
78 procedure conRegVar (const conname
: AnsiString; pvar
: PCardinal; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
79 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
81 // <0: no arg; 0/1: true/false
82 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
84 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
85 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
88 defaultConfigScript
= 'dfconfig.cfg';
91 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
92 gChatShow
: Boolean = false;
93 gChatTeam
: Boolean = false;
94 gAllowConsoleMessages
: Boolean = true;
95 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
96 gParsingBinds
: Boolean = true; // íå ïåðåñîõðàíÿòü êîíôèã âî âðåìÿ ïàðñèíãà
97 gPlayerAction
: Array [0..1, 0..LAST_ACTION
] of Boolean; // [player, action]
98 gConfigScript
: string = defaultConfigScript
;
106 {$IFDEF ENABLE_TOUCH}
112 g_textures
, e_input
, g_game
, g_player
, g_items
,
113 SysUtils
, g_basic
, g_options
, Math
, e_res
,
114 g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
117 configComment
= 'generated by doom2d, do not modify';
120 PCommand
= ^TCommand
;
122 TCmdProc
= procedure (p
: SSArray
);
123 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
131 ptr
: Pointer; // various data
132 msg
: AnsiString; // message for var changes
134 action
: Integer; // >= 0 for action commands
135 player
: Integer; // used for action commands
146 MaxScriptRecursion
= 16;
149 RecursionDepth
: Word = 0;
150 RecursionLimitHit
: Boolean = False;
151 InputReady
: Boolean; // allow text input in console/chat
152 //ConsoleHistory: SSArray;
153 CommandHistory
: SSArray
;
155 commands
: Array of TCommand
= nil;
156 Aliases
: Array of TAlias
= nil;
159 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
164 menu_toggled
: BOOLEAN; (* hack for menu controls *)
166 procedure g_Console_Switch
;
169 gConsoleShow
:= not gConsoleShow
;
171 {$IFDEF ENABLE_TOUCH}
172 sys_ShowKeyboard(gConsoleShow
or gChatShow
);
176 procedure g_Console_Chat_Switch (Team
: Boolean = False);
178 if not g_Game_IsNet
then Exit
;
179 gConsoleShow
:= False;
180 gChatShow
:= not gChatShow
;
185 {$IFDEF ENABLE_TOUCH}
186 sys_ShowKeyboard(gConsoleShow
or gChatShow
);
190 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
191 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
200 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
201 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
202 if (pos
> slen
) then exit
;
203 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
205 while (pos
<= slen
) do
207 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
208 res
:= res
*10+Byte(s
[pos
])-48;
211 if (pos
<= slen
) then
214 if (s
[pos
] <> '.') then exit
;
216 while (pos
<= slen
) do
218 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
220 res
+= frac
*(Byte(s
[pos
])-48);
224 if (pos
<= slen
) then exit
; // oops
229 // ////////////////////////////////////////////////////////////////////////// //
230 // <0: no arg; 0/1: true/false; 666: toggle
231 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
233 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
235 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
236 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
237 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
238 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
242 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
243 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
247 if (Length(p
) > 2) then
249 conwritefln('too many arguments to ''%s''', [p
[0]]);
254 case conGetBoolArg(p
, 1) of
256 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
257 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
258 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
261 g_Console_WriteGameConfig();
262 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
263 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
267 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
271 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
275 if (Length(p
) <> 2) then
277 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
282 old
:= PInteger(me
.ptr
)^;
283 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
284 if PInteger(me
.ptr
)^ <> old
then
285 g_Console_WriteGameConfig();
287 conwritefln('invalid integer value: "%s"', [p
[1]]);
293 procedure wordVarHandler (me
: PCommand
; p
: SSArray
);
297 if (Length(p
) <> 2) then
299 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
304 old
:= PWord(me
.ptr
)^;
305 PWord(me
.ptr
)^ := min($FFFF, StrToDWord(p
[1]));
306 if PWord(me
.ptr
)^ <> old
then
307 g_Console_WriteGameConfig();
309 conwritefln('invalid word value: "%s"', [p
[1]]);
315 procedure dwordVarHandler (me
: PCommand
; p
: SSArray
);
319 if (Length(p
) <> 2) then
321 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
326 old
:= PCardinal(me
.ptr
)^;
327 PCardinal(me
.ptr
)^ := StrToDWord(p
[1]);
328 if PCardinal(me
.ptr
)^ <> old
then
329 g_Console_WriteGameConfig();
331 conwritefln('invalid dword value: "%s"', [p
[1]]);
337 procedure strVarHandler (me
: PCommand
; p
: SSArray
);
341 if (Length(p
) <> 2) then
343 conwritefln('%s %s', [me
.cmd
, QuoteStr(PAnsiString(me
.ptr
)^)]);
347 old
:= PAnsiString(me
.ptr
)^;
348 PAnsiString(me
.ptr
)^ := p
[1];
349 if PAnsiString(me
.ptr
)^ <> old
then
350 g_Console_WriteGameConfig();
355 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
360 f
:= Length(commands
);
361 SetLength(commands
, f
+1);
363 cp
.cmd
:= LowerCase(conname
);
365 cp
.procEx
:= boolVarHandler
;
367 cp
.hidden
:= ahidden
;
376 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
381 f
:= Length(commands
);
382 SetLength(commands
, f
+1);
384 cp
.cmd
:= LowerCase(conname
);
386 cp
.procEx
:= intVarHandler
;
388 cp
.hidden
:= ahidden
;
397 procedure conRegVar (const conname
: AnsiString; pvar
: PWord; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
402 f
:= Length(commands
);
403 SetLength(commands
, f
+1);
405 cp
.cmd
:= LowerCase(conname
);
407 cp
.procEx
:= wordVarHandler
;
409 cp
.hidden
:= ahidden
;
418 procedure conRegVar (const conname
: AnsiString; pvar
: PCardinal; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
423 f
:= Length(commands
);
424 SetLength(commands
, f
+1);
426 cp
.cmd
:= LowerCase(conname
);
428 cp
.procEx
:= dwordVarHandler
;
430 cp
.hidden
:= ahidden
;
439 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
444 f
:= Length(commands
);
445 SetLength(commands
, f
+1);
447 cp
.cmd
:= LowerCase(conname
);
449 cp
.procEx
:= strVarHandler
;
451 cp
.hidden
:= ahidden
;
459 // ////////////////////////////////////////////////////////////////////////// //
461 PVarSingle
= ^TVarSingle
;
464 min
, max
, def
: Single; // default will be starting value
468 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
474 if (Length(p
) > 2) then
476 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
479 pv
:= PVarSingle(me
.ptr
);
481 if (Length(p
) = 2) then
483 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
484 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
485 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
486 (CompareText(p
[1], 'ona') = 0) then
492 if not conParseFloat(nv
, p
[1]) then
494 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
497 if (nv
< pv
.min
) then nv
:= pv
.min
;
498 if (nv
> pv
.max
) then nv
:= pv
.max
;
502 if pv
.val
^ <> old
then
503 g_Console_WriteGameConfig();
505 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
506 conwritefln('%s %s', [msg
, pv
.val
^]);
510 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
516 GetMem(pv
, sizeof(TVarSingle
));
521 f
:= Length(commands
);
522 SetLength(commands
, f
+1);
524 cp
.cmd
:= LowerCase(conname
);
526 cp
.procEx
:= singleVarHandler
;
528 cp
.hidden
:= ahidden
;
537 // ////////////////////////////////////////////////////////////////////////// //
538 function GetStrACmd(var Str
: AnsiString): AnsiString;
543 for a
:= 1 to Length(Str
) do
544 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
546 Result
:= Copy(Str
, 1, a
);
553 function ParseAlias(Str
: AnsiString): SSArray
;
564 SetLength(Result
, Length(Result
)+1);
565 Result
[High(Result
)] := GetStrACmd(Str
);
569 procedure ConsoleCommands(p
: SSArray
);
575 cmd
:= LowerCase(p
[0]);
578 if cmd
= 'clear' then
580 //ConsoleHistory := nil;
584 for a
:= 0 to High(MsgArray
) do
592 if cmd
= 'clearhistory' then
593 CommandHistory
:= nil;
595 if cmd
= 'showhistory' then
596 if CommandHistory
<> nil then
599 for a
:= 0 to High(CommandHistory
) do
600 g_Console_Add(' '+CommandHistory
[a
]);
603 if cmd
= 'commands' then
606 g_Console_Add('commands list:');
607 for a
:= High(commands
) downto 0 do
609 if (Length(commands
[a
].help
) > 0) then
611 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
615 g_Console_Add(' '+commands
[a
].cmd
);
621 g_Console_Add(TimeToStr(Now
), True);
624 g_Console_Add(DateToStr(Now
), True);
627 if Length(p
) > 1 then
629 if p
[1] = 'ololo' then
634 for a
:= 1 to High(p
) do
636 g_Console_Add(b_Text_Format(s
), True);
645 if ConsoleHistory <> nil then
647 if Length(P) > 1 then
650 s := GameDir+'/console.txt';
655 if IOResult <> 0 then
657 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
662 for a := 0 to High(ConsoleHistory) do
663 WriteLn(F, ConsoleHistory[a]);
666 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
675 if Length(p
) = 2 then
676 g_Console_ReadConfig(p
[1])
678 g_Console_Add('exec <script file>');
681 if cmd
= 'writeconfig' then
683 // writeconfig <filename>
684 if Length(p
) = 2 then
686 s
:= e_GetWriteableDir(ConfigDirs
);
687 g_Console_WriteConfig(e_CatPath(s
, p
[1]))
691 g_Console_Add('writeconfig <file>')
695 if (cmd
= 'ver') or (cmd
= 'version') then
697 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
698 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
699 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
702 if cmd
= 'alias' then
704 // alias [alias_name] [commands]
705 if Length(p
) > 1 then
707 for a
:= 0 to High(Aliases
) do
708 if Aliases
[a
].name
= p
[1] then
710 if Length(p
) > 2 then
711 Aliases
[a
].commands
:= ParseAlias(p
[2])
713 for b
:= 0 to High(Aliases
[a
].commands
) do
714 g_Console_Add(Aliases
[a
].commands
[b
]);
717 SetLength(Aliases
, Length(Aliases
)+1);
719 Aliases
[a
].name
:= p
[1];
720 if Length(p
) > 2 then
721 Aliases
[a
].commands
:= ParseAlias(p
[2])
723 for b
:= 0 to High(Aliases
[a
].commands
) do
724 g_Console_Add(Aliases
[a
].commands
[b
]);
726 for a
:= 0 to High(Aliases
) do
727 if Aliases
[a
].commands
<> nil then
728 g_Console_Add(Aliases
[a
].name
);
734 if Length(p
) > 1 then
736 if Aliases
= nil then
738 for a
:= 0 to High(Aliases
) do
739 if Aliases
[a
].name
= p
[1] then
741 if Aliases
[a
].commands
<> nil then
743 // with this system proper endless loop detection seems either impossible
744 // or very dirty to implement, so let's have this instead
745 // prevents endless loops
746 for b
:= 0 to High(Aliases
[a
].commands
) do
749 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
750 if not RecursionLimitHit
then
751 g_Console_Process(Aliases
[a
].commands
[b
], True);
754 if (RecursionDepth
= 0) and RecursionLimitHit
then
756 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
757 RecursionLimitHit
:= False;
764 g_Console_Add('call <alias name>');
768 procedure WhitelistCommand(cmd
: AnsiString);
772 SetLength(Whitelist
, Length(Whitelist
)+1);
773 a
:= High(Whitelist
);
774 Whitelist
[a
] := LowerCase(cmd
);
777 procedure segfault (p
: SSArray
);
784 function GetCommandString (p
: SSArray
): AnsiString;
788 if Length(p
) >= 1 then
791 for i
:= 1 to High(p
) do
792 result
:= result
+ '; ' + p
[i
]
796 function QuoteStr(str
: String): String;
798 if Pos(' ', str
) > 0 then
799 Result
:= '"' + str
+ '"'
804 procedure BindCommands (p
: SSArray
);
805 var cmd
, key
: AnsiString; i
: Integer;
807 cmd
:= LowerCase(p
[0]);
810 // bind <key> [down [up]]
811 if (Length(p
) >= 2) and (Length(p
) <= 4) then
814 key
:= LowerCase(p
[1]);
815 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
816 if i
< e_MaxInputKeys
then
818 if Length(p
) = 2 then
819 g_Console_Add(QuoteStr(e_KeyNames
[i
]) + ' = ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)))
820 else if Length(p
) = 3 then
821 g_Console_BindKey(i
, p
[2], '')
823 g_Console_BindKey(i
, p
[2], p
[3])
826 g_Console_Add('bind: "' + p
[1] + '" is not a key')
830 g_Console_Add('bind <key> <down action> [up action]')
834 if Length(p
) = 2 then
836 key
:= LowerCase(p
[1]);
838 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
839 if i
< e_MaxInputKeys
then
840 gInputBinds
[i
].rep
:= True
842 g_Console_Add('bindrep: "' + p
[1] + '" is not a key')
845 g_Console_Add('bindrep <key>');
848 if Length(p
) = 2 then
850 key
:= LowerCase(p
[1]);
852 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
853 if i
< e_MaxInputKeys
then
854 gInputBinds
[i
].rep
:= False
856 g_Console_Add('bindunrep: "' + p
[1] + '" is not a key')
859 g_Console_Add('bindunrep <key>');
861 for i
:= 0 to e_MaxInputKeys
- 1 do
862 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
863 g_Console_Add(e_KeyNames
[i
] + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
866 if Length(p
) = 2 then
868 key
:= LowerCase(p
[1]);
870 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
871 if i
< e_MaxInputKeys
then
872 g_Console_BindKey(i
, '')
874 g_Console_Add('unbind: "' + p
[1] + '" is not a key')
877 g_Console_Add('unbind <key>');
879 for i
:= 0 to e_MaxInputKeys
- 1 do
880 g_Console_BindKey(i
, '');
881 {$IFDEF ENABLE_TOUCH}
883 sys_ShowKeyboard(True);
885 sys_ShowKeyboard(False);
891 else if gChatShow
then
892 g_Console_Chat_Switch
902 g_Console_Chat_Switch
;
904 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
905 g_Console_Chat_Switch(True);
909 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
914 SetLength(commands
, Length(commands
)+1);
917 cp
.cmd
:= LowerCase(cmd
);
921 cp
.hidden
:= ahidden
;
929 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
931 PrefixList
: array [0..1] of AnsiString = ('+', '-');
932 PlayerList
: array [0..1] of Integer = (1, 2);
937 procedure NewAction (cmd
: AnsiString; player
: Integer);
940 SetLength(commands
, Length(commands
) + 1);
941 cp
:= @commands
[High(commands
)];
942 cp
.cmd
:= LowerCase(cmd
);
955 ASSERT(action
>= FIRST_ACTION
);
956 ASSERT(action
<= LAST_ACTION
);
957 for s
in PrefixList
do
959 NewAction(s
+ cmd
, 0);
960 for i
in PlayerList
do
961 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
965 procedure g_Console_Initialize
;
968 gConsoleShow
:= False;
973 for a
:= 0 to High(MsgArray
) do
980 AddCommand('segfault', segfault
, 'make segfault');
982 AddCommand('quit', SystemCommands
);
983 AddCommand('exit', SystemCommands
);
984 AddCommand('r_reset', SystemCommands
);
985 AddCommand('r_maxfps', SystemCommands
);
986 AddCommand('g_language', SystemCommands
);
988 AddCommand('bind', BindCommands
);
989 AddCommand('bindrep', BindCommands
);
990 AddCommand('bindunrep', BindCommands
);
991 AddCommand('bindlist', BindCommands
);
992 AddCommand('unbind', BindCommands
);
993 AddCommand('unbindall', BindCommands
);
994 AddCommand('showkeyboard', BindCommands
);
995 AddCommand('hidekeyboard', BindCommands
);
996 AddCommand('togglemenu', BindCommands
);
997 AddCommand('toggleconsole', BindCommands
);
998 AddCommand('togglechat', BindCommands
);
999 AddCommand('toggleteamchat', BindCommands
);
1001 AddCommand('clear', ConsoleCommands
, 'clear console');
1002 AddCommand('clearhistory', ConsoleCommands
);
1003 AddCommand('showhistory', ConsoleCommands
);
1004 AddCommand('commands', ConsoleCommands
);
1005 AddCommand('time', ConsoleCommands
);
1006 AddCommand('date', ConsoleCommands
);
1007 AddCommand('echo', ConsoleCommands
);
1008 AddCommand('dump', ConsoleCommands
);
1009 AddCommand('exec', ConsoleCommands
);
1010 AddCommand('writeconfig', ConsoleCommands
);
1011 AddCommand('alias', ConsoleCommands
);
1012 AddCommand('call', ConsoleCommands
);
1013 AddCommand('ver', ConsoleCommands
);
1014 AddCommand('version', ConsoleCommands
);
1016 AddCommand('d_window', DebugCommands
);
1017 AddCommand('d_sounds', DebugCommands
);
1018 AddCommand('d_frames', DebugCommands
);
1019 AddCommand('d_winmsg', DebugCommands
);
1020 AddCommand('d_monoff', DebugCommands
);
1021 AddCommand('d_botoff', DebugCommands
);
1022 AddCommand('d_monster', DebugCommands
);
1023 AddCommand('d_health', DebugCommands
);
1024 AddCommand('d_player', DebugCommands
);
1025 AddCommand('d_joy', DebugCommands
);
1026 AddCommand('d_mem', DebugCommands
);
1028 AddCommand('p1_name', PlayerSettingsCVars
);
1029 AddCommand('p2_name', PlayerSettingsCVars
);
1030 AddCommand('p1_color', PlayerSettingsCVars
);
1031 AddCommand('p2_color', PlayerSettingsCVars
);
1032 AddCommand('p1_model', PlayerSettingsCVars
);
1033 AddCommand('p2_model', PlayerSettingsCVars
);
1034 AddCommand('p1_team', PlayerSettingsCVars
);
1035 AddCommand('p2_team', PlayerSettingsCVars
);
1037 AddCommand('g_max_particles', GameCVars
);
1038 AddCommand('g_max_shells', GameCVars
);
1039 AddCommand('g_max_gibs', GameCVars
);
1040 AddCommand('g_max_corpses', GameCVars
);
1041 AddCommand('g_gamemode', GameCVars
);
1042 AddCommand('g_friendlyfire', GameCVars
);
1043 AddCommand('g_friendly_hit_trace', GameCVars
);
1044 AddCommand('g_friendly_hit_projectile', GameCVars
);
1045 AddCommand('g_friendly_absorb_damage', GameCVars
);
1046 AddCommand('g_weaponstay', GameCVars
);
1047 AddCommand('g_allow_exit', GameCVars
);
1048 AddCommand('g_dm_keys', GameCVars
);
1049 AddCommand('g_allow_monsters', GameCVars
);
1050 AddCommand('g_bot_vsmonsters', GameCVars
);
1051 AddCommand('g_bot_vsplayers', GameCVars
);
1052 AddCommand('g_scorelimit', GameCVars
);
1053 AddCommand('g_timelimit', GameCVars
);
1054 AddCommand('g_maxlives', GameCVars
);
1055 AddCommand('g_warmup_time', GameCVars
);
1056 AddCommand('g_spawn_invul', GameCVars
);
1057 AddCommand('g_item_respawn_time', GameCVars
);
1058 AddCommand('sv_intertime', GameCVars
);
1060 AddCommand('sv_name', NetServerCVars
);
1061 AddCommand('sv_passwd', NetServerCVars
);
1062 AddCommand('sv_maxplrs', NetServerCVars
);
1063 AddCommand('sv_public', NetServerCVars
);
1064 AddCommand('sv_port', NetServerCVars
);
1066 AddCommand('pause', GameCommands
);
1067 AddCommand('endgame', GameCommands
);
1068 AddCommand('restart', GameCommands
);
1069 AddCommand('addbot', GameCommands
);
1070 AddCommand('bot_add', GameCommands
);
1071 AddCommand('bot_addlist', GameCommands
);
1072 AddCommand('bot_addred', GameCommands
);
1073 AddCommand('bot_addblue', GameCommands
);
1074 AddCommand('bot_removeall', GameCommands
);
1075 AddCommand('chat', GameCommands
);
1076 AddCommand('teamchat', GameCommands
);
1077 AddCommand('game', GameCommands
);
1078 AddCommand('host', GameCommands
);
1079 AddCommand('map', GameCommands
);
1080 AddCommand('nextmap', GameCommands
);
1081 AddCommand('endmap', GameCommands
);
1082 AddCommand('goodbye', GameCommands
);
1083 AddCommand('suicide', GameCommands
);
1084 AddCommand('spectate', GameCommands
);
1085 AddCommand('ready', GameCommands
);
1086 AddCommand('kick', GameCommands
);
1087 AddCommand('kick_id', GameCommands
);
1088 AddCommand('kick_pid', GameCommands
);
1089 AddCommand('ban', GameCommands
);
1090 AddCommand('ban_id', GameCommands
);
1091 AddCommand('ban_pid', GameCommands
);
1092 AddCommand('permban', GameCommands
);
1093 AddCommand('permban_id', GameCommands
);
1094 AddCommand('permban_pid', GameCommands
);
1095 AddCommand('permban_ip', GameCommands
);
1096 AddCommand('unban', GameCommands
);
1097 AddCommand('connect', GameCommands
);
1098 AddCommand('disconnect', GameCommands
);
1099 AddCommand('reconnect', GameCommands
);
1100 AddCommand('say', GameCommands
);
1101 AddCommand('tell', GameCommands
);
1102 AddCommand('centerprint', GameCommands
);
1103 AddCommand('overtime', GameCommands
);
1104 AddCommand('rcon_password', GameCommands
);
1105 AddCommand('rcon', GameCommands
);
1106 AddCommand('callvote', GameCommands
);
1107 AddCommand('vote', GameCommands
);
1108 AddCommand('clientlist', GameCommands
);
1109 AddCommand('event', GameCommands
);
1110 AddCommand('screenshot', GameCommands
);
1111 AddCommand('weapon', GameCommands
);
1112 AddCommand('p1_weapon', GameCommands
);
1113 AddCommand('p2_weapon', GameCommands
);
1115 AddCommand('god', GameCheats
);
1116 AddCommand('notarget', GameCheats
);
1117 AddCommand('give', GameCheats
); // "exit" too ;-)
1118 AddCommand('open', GameCheats
);
1119 AddCommand('fly', GameCheats
);
1120 AddCommand('noclip', GameCheats
);
1121 AddCommand('speedy', GameCheats
);
1122 AddCommand('jumpy', GameCheats
);
1123 AddCommand('noreload', GameCheats
);
1124 AddCommand('aimline', GameCheats
);
1125 AddCommand('automap', GameCheats
);
1127 AddAction('jump', ACTION_JUMP
);
1128 AddAction('moveleft', ACTION_MOVELEFT
);
1129 AddAction('moveright', ACTION_MOVERIGHT
);
1130 AddAction('lookup', ACTION_LOOKUP
);
1131 AddAction('lookdown', ACTION_LOOKDOWN
);
1132 AddAction('attack', ACTION_ATTACK
);
1133 AddAction('scores', ACTION_SCORES
);
1134 AddAction('activate', ACTION_ACTIVATE
);
1135 AddAction('strafe', ACTION_STRAFE
);
1136 AddAction('weapnext', ACTION_WEAPNEXT
);
1137 AddAction('weapprev', ACTION_WEAPPREV
);
1139 WhitelistCommand('say');
1140 WhitelistCommand('tell');
1141 WhitelistCommand('overtime');
1142 WhitelistCommand('ready');
1143 WhitelistCommand('map');
1144 WhitelistCommand('nextmap');
1145 WhitelistCommand('endmap');
1146 WhitelistCommand('restart');
1147 WhitelistCommand('kick');
1148 WhitelistCommand('kick_pid');
1149 WhitelistCommand('ban');
1150 WhitelistCommand('ban_pid');
1151 WhitelistCommand('centerprint');
1153 WhitelistCommand('addbot');
1154 WhitelistCommand('bot_add');
1155 WhitelistCommand('bot_addred');
1156 WhitelistCommand('bot_addblue');
1157 WhitelistCommand('bot_removeall');
1159 WhitelistCommand('g_gamemode');
1160 WhitelistCommand('g_friendlyfire');
1161 WhitelistCommand('g_friendly_hit_trace');
1162 WhitelistCommand('g_friendly_hit_projectile');
1163 WhitelistCommand('g_friendly_absorb_damage');
1164 WhitelistCommand('g_weaponstay');
1165 WhitelistCommand('g_allow_exit');
1166 WhitelistCommand('g_dm_keys');
1167 WhitelistCommand('g_allow_monsters');
1168 WhitelistCommand('g_bot_vsmonsters');
1169 WhitelistCommand('g_bot_vsplayers');
1170 WhitelistCommand('g_scorelimit');
1171 WhitelistCommand('g_timelimit');
1172 WhitelistCommand('g_maxlives');
1173 WhitelistCommand('g_warmup_time');
1174 WhitelistCommand('g_spawn_invul');
1175 WhitelistCommand('g_item_respawn_time');
1177 g_Console_ResetBinds
;
1178 g_Console_ReadConfig(gConfigScript
);
1179 // g_Console_ReadConfig(autoexecScript);
1180 g_Console_ReadConfig('autoexec.cfg');
1182 gParsingBinds
:= False;
1185 procedure g_Console_Finalize
;
1190 procedure g_Console_Init
;
1192 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
1196 procedure g_Console_Update
;
1200 InputReady
:= gConsoleShow
or gChatShow
;
1203 while a
<= High(MsgArray
) do
1205 if MsgArray
[a
].Time
> 0 then
1207 if MsgArray
[a
].Time
= 1 then
1209 if a
< High(MsgArray
) then
1211 for b
:= a
to High(MsgArray
)-1 do
1212 MsgArray
[b
] := MsgArray
[b
+1];
1214 MsgArray
[High(MsgArray
)].Time
:= 0;
1220 Dec(MsgArray
[a
].Time
);
1227 procedure g_Console_Char(C
: AnsiChar);
1229 if InputReady
and (gConsoleShow
or gChatShow
) then
1231 Insert(C
, Line
, CPos
);
1238 tcomplist
: array of AnsiString = nil;
1239 tcompidx
: array of Integer = nil;
1241 procedure Complete ();
1245 ll
, lpfx
, cmd
: AnsiString;
1247 if (Length(Line
) = 0) then
1250 for i
:= 0 to High(commands
) do
1252 // hidden commands are hidden when cheats aren't enabled
1253 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1254 if (Length(commands
[i
].help
) > 0) then
1256 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1260 g_Console_Add(' '+commands
[i
].cmd
);
1266 ll
:= LowerCase(Line
);
1269 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1271 ll
:= Copy(ll
, 0, Length(ll
)-1);
1272 for i
:= 0 to High(commands
) do
1274 // hidden commands are hidden when cheats aren't enabled
1275 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1276 if (commands
[i
].cmd
= ll
) then
1278 if (Length(commands
[i
].help
) > 0) then
1280 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1287 // build completion list
1289 for i
:= 0 to High(commands
) do
1291 // hidden commands are hidden when cheats aren't enabled
1292 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1293 cmd
:= commands
[i
].cmd
;
1294 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1296 if (tused
= Length(tcomplist
)) then
1298 SetLength(tcomplist
, Length(tcomplist
)+128);
1299 SetLength(tcompidx
, Length(tcompidx
)+128);
1301 tcomplist
[tused
] := cmd
;
1302 tcompidx
[tused
] := i
;
1304 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1308 // get longest prefix
1309 for i
:= 0 to tused
-1 do
1311 cmd
:= tcomplist
[i
];
1312 for c
:= 1 to Length(lpfx
) do
1314 if (c
> Length(cmd
)) then break
;
1315 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1319 if (tused
= 0) then exit
;
1323 Line
:= tcomplist
[0]+' ';
1324 CPos
:= Length(Line
)+1;
1328 // has longest prefix?
1329 if (Length(lpfx
) > Length(ll
)) then
1332 CPos
:= Length(Line
)+1;
1337 for i
:= 0 to tused
-1 do
1339 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1341 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1345 g_Console_Add(' '+tcomplist
[i
]);
1353 procedure g_Console_Control(K
: Word);
1357 if (Length(Line
) > 0) and (CPos
> 1) then
1359 Delete(Line
, CPos
-1, 1);
1363 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1364 Delete(Line
, CPos
, 1);
1365 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1368 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1369 if CPos
<= Length(Line
) then
1371 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1373 if gConsoleShow
then
1374 g_Console_Process(Line
)
1378 if (Length(Line
) > 0) and g_Game_IsNet
then
1382 if g_Game_IsClient
then
1383 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1385 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1386 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1390 if g_Game_IsClient
then
1391 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1393 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1400 gJustChatted
:= True;
1401 g_Console_Chat_Switch
;
1402 InputReady
:= False;
1406 if not gChatShow
then
1408 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1409 if not gChatShow
then
1410 if (CommandHistory
<> nil) and
1411 (CmdIndex
< Length(CommandHistory
)) then
1413 if CmdIndex
< Length(CommandHistory
)-1 then
1414 CmdIndex
:= CmdIndex
+ 1;
1415 Line
:= CommandHistory
[CmdIndex
];
1416 CPos
:= Length(Line
) + 1;
1418 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1419 if not gChatShow
then
1420 if (CommandHistory
<> nil) and
1421 (CmdIndex
<= Length(CommandHistory
)) then
1423 if CmdIndex
> 0 then
1424 CmdIndex
:= CmdIndex
- 1;
1425 Line
:= CommandHistory
[CmdIndex
];
1426 Cpos
:= Length(Line
) + 1;
1428 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1429 if not gChatShow
then Inc(conSkipLines
);
1430 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1431 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1435 CPos
:= Length(Line
) + 1;
1436 IK_A
..IK_Z
, IK_SPACE
, IK_SHIFT
, IK_RSHIFT
, IK_CAPSLOCK
, IK_LBRACKET
, IK_RBRACKET
,
1437 IK_SEMICOLON
, IK_QUOTE
, IK_BACKSLASH
, IK_SLASH
, IK_COMMA
, IK_DOT
, (*IK_EQUALS,*)
1438 IK_0
, IK_1
, IK_2
, IK_3
, IK_4
, IK_5
, IK_6
, IK_7
, IK_8
, IK_9
, IK_MINUS
, IK_EQUALS
:
1439 (* see TEXTINPUT event *)
1443 function GetStr(var Str
: AnsiString): AnsiString;
1448 if Str
[1] = '"' then
1450 for b
:= 1 to Length(Str
) do
1451 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1453 Result
:= Copy(Str
, 2, b
-1);
1454 Delete(Str
, 1, b
+1);
1460 for a
:= 1 to Length(Str
) do
1461 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1463 Result
:= Copy(Str
, 1, a
);
1464 Delete(Str
, 1, a
+1);
1470 function ParseString(Str
: AnsiString): SSArray
;
1481 SetLength(Result
, Length(Result
)+1);
1482 Result
[High(Result
)] := GetStr(Str
);
1486 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1488 procedure conmsg (s
: AnsiString);
1492 if length(s
) = 0 then exit
;
1493 for a
:= 0 to High(MsgArray
) do
1505 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1506 with MsgArray
[High(MsgArray
)] do
1516 // put it to console
1518 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1520 // now show 'em out of console too
1521 show
:= show
and gAllowConsoleMessages
;
1522 if show
and gShowMessages
then
1524 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1525 while length(L
) > 0 do
1528 if f
<= 0 then f
:= length(L
)+1;
1529 conmsg(Copy(L
, 1, f
-1));
1534 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1535 //ConsoleHistory[High(ConsoleHistory)] := L;
1539 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1546 consolewriterLastWasEOL
: Boolean = false;
1548 procedure consolewriter (constref buf
; len
: SizeUInt
);
1552 if (len
< 1) then exit
;
1554 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1557 if (b
[0] <> 13) and (b
[0] <> 10) then
1559 cbufPut(AnsiChar(b
[0]));
1563 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1572 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1573 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1574 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1575 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1577 g_Console_Add(s
, show
);
1581 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1585 g_Console_Add(formatstrf(s
, args
), true);
1589 consolewriterLastWasEOL
:= false;
1590 formatstrf(s
, args
, consolewriter
);
1591 if not consolewriterLastWasEOL
then cbufPut(#10);
1596 procedure g_Console_Clear();
1598 //ConsoleHistory := nil;
1603 procedure AddToHistory(L
: AnsiString);
1607 len
:= Length(CommandHistory
);
1610 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1612 SetLength(CommandHistory
, len
+1);
1613 CommandHistory
[len
] := L
;
1616 CmdIndex
:= Length(CommandHistory
);
1619 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1628 if Trim(C
) = '' then
1631 Arr
:= ParseString(C
);
1635 for i
:= 0 to High(Whitelist
) do
1636 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1640 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1647 if Trim(L
) = '' then
1650 conSkipLines
:= 0; // "unscroll"
1652 if L
= 'goobers' then
1657 g_Console_Add('Your memory serves you well.');
1663 g_Console_Add('> '+L
);
1668 Arr
:= ParseString(L
);
1672 if commands
= nil then
1678 for i
:= 0 to High(commands
) do
1680 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1682 if commands
[i
].action
>= 0 then
1684 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1687 if assigned(commands
[i
].procEx
) then
1689 commands
[i
].procEx(@commands
[i
], Arr
);
1692 if assigned(commands
[i
].proc
) then
1694 commands
[i
].proc(Arr
);
1700 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1704 function g_Console_Interactive
: Boolean;
1706 Result
:= gConsoleShow
1709 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1711 // e_LogWritefln('bind "%s" "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), down, up, key]);
1713 ASSERT(key
< e_MaxInputKeys
);
1716 gInputBinds
[key
].rep
:= False;
1717 gInputBinds
[key
].down
:= ParseAlias(down
);
1718 gInputBinds
[key
].up
:= ParseAlias(up
);
1720 g_Console_WriteGameConfig();
1723 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
1725 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1726 var i
, len
: Integer;
1730 if len
= Length(b
) then
1733 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1741 ASSERT(key
< e_MaxInputKeys
);
1742 result
:= EqualsCommandLists(ParseAlias(down
), gInputBinds
[key
].down
) and EqualsCommandLists(ParseAlias(up
), gInputBinds
[key
].up
)
1745 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1750 if commands
= nil then Exit
;
1752 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1754 if g_Console_MatchBind(i
, down
, up
) then
1765 function g_Console_Action (action
: Integer): Boolean;
1766 var i
, len
: Integer;
1768 ASSERT(action
>= FIRST_ACTION
);
1769 ASSERT(action
<= LAST_ACTION
);
1771 len
:= Length(gPlayerAction
);
1772 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1776 function BindsAllowed (key
: Integer): Boolean;
1777 var grab
, active
: Boolean;
1780 {$IFDEF DISABLE_MENU}
1784 grab
:= g_GUIGrabInput
;
1785 active
:= g_ActiveWindow
<> nil;
1787 if (not grab
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1790 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1791 g_Console_MatchBind(key
, 'showkeyboard') or
1792 g_Console_MatchBind(key
, 'hidekeyboard')
1793 else if gConsoleShow
or active
or (gGameSettings
.GameType
= GT_NONE
) then
1794 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1795 g_Console_MatchBind(key
, 'toggleconsole') or
1796 g_Console_MatchBind(key
, 'showkeyboard') or
1797 g_Console_MatchBind(key
, 'hidekeyboard')
1803 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1806 if BindsAllowed(key
) then
1809 for i
:= 0 to High(gInputBinds
[key
].down
) do
1810 g_Console_Process(gInputBinds
[key
].down
[i
], True)
1812 for i
:= 0 to High(gInputBinds
[key
].up
) do
1813 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1815 if down
and not menu_toggled
then
1817 menu_toggled
:= False
1820 procedure g_Console_ProcessBindRepeat (key
: Integer);
1821 var i
: Integer; active
: Boolean;
1823 {$IFDEF DISABLE_MENU}
1826 active
:= g_ActiveWindow
<> nil;
1828 if gConsoleShow
or gChatShow
or active
then
1830 KeyPress(key
); // key repeat in menus and shit
1833 if BindsAllowed(key
) and gInputBinds
[key
].rep
then
1835 for i
:= 0 to High(gInputBinds
[key
].down
) do
1836 g_Console_Process(gInputBinds
[key
].down
[i
], True);
1840 procedure g_Console_ResetBinds
;
1843 for i
:= 0 to e_MaxInputKeys
- 1 do
1844 g_Console_BindKey(i
, '', '');
1846 g_Console_BindKey(IK_GRAVE
, 'toggleconsole');
1847 g_Console_BindKey(IK_ESCAPE
, 'togglemenu');
1848 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1849 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1850 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1851 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1852 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1853 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1854 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1855 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1856 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1857 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1858 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1859 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1860 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1861 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1862 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1863 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1864 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1865 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1866 g_Console_BindKey(IK_9
, 'p1_weapon 9');
1867 g_Console_BindKey(IK_0
, 'p1_weapon 10');
1868 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
1869 g_Console_BindKey(IK_T
, 'togglechat');
1870 g_Console_BindKey(IK_Y
, 'toggleteamchat');
1871 g_Console_BindKey(IK_F11
, 'screenshot');
1872 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
1873 g_Console_BindKey(IK_PAUSE
, 'pause');
1874 g_Console_BindKey(IK_F1
, 'vote');
1876 (* for i := 0 to e_MaxJoys - 1 do *)
1879 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_LEFT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
1880 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_RIGHT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
1881 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_UP
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
1882 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_DOWN
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
1883 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
1884 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
1885 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
1886 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
1887 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
1888 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
1889 g_Console_BindKey(e_JoyButtonToKey(i
, 10), 'togglemenu');
1892 g_Console_BindKey(VK_ESCAPE
, 'togglemenu');
1893 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
1894 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
1895 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
1896 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
1897 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
1898 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
1899 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
1900 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
1901 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
1902 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
1903 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
1904 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
1905 g_Console_BindKey(VK_0
, 'weapon 1');
1906 g_Console_BindKey(VK_1
, 'weapon 2');
1907 g_Console_BindKey(VK_2
, 'weapon 3');
1908 g_Console_BindKey(VK_3
, 'weapon 4');
1909 g_Console_BindKey(VK_4
, 'weapon 5');
1910 g_Console_BindKey(VK_5
, 'weapon 6');
1911 g_Console_BindKey(VK_6
, 'weapon 7');
1912 g_Console_BindKey(VK_7
, 'weapon 8');
1913 g_Console_BindKey(VK_8
, 'weapon 9');
1914 g_Console_BindKey(VK_9
, 'weapon 10');
1915 g_Console_BindKey(VK_A
, 'weapon 11');
1916 g_Console_BindKey(VK_CHAT
, 'togglechat');
1917 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
1918 g_Console_BindKey(VK_CONSOLE
, 'toggleconsole');
1919 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
1920 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
1921 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
1922 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
1925 procedure g_Console_ReadConfig (filename
: String);
1926 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1928 e_LogWritefln('g_Console_ReadConfig (1) "%s"', [filename
]);
1929 if e_FindResource(ConfigDirs
, filename
, false) = true then
1931 e_LogWritefln('g_Console_ReadConfig (2) "%s"', [filename
]);
1932 AssignFile(f
, filename
);
1942 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1944 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1945 g_Console_Process(s
, True);
1952 procedure g_Console_WriteConfig (filename
: String);
1953 var f
: TextFile
; i
, j
: Integer;
1955 procedure WriteFlag(name
: string; flag
: LongWord);
1957 WriteLn(f
, name
, IfThen(LongBool(gsGameFlags
and flag
), 1, 0));
1960 function FormatTeam(team
: Byte): string;
1962 if team
= TEAM_BLUE
then
1969 // e_LogWritefln('g_Console_WriteConfig: %s', [filename]);
1970 AssignFile(f
, filename
);
1972 WriteLn(f
, '// ' + configComment
);
1975 WriteLn(f
, 'unbindall');
1976 for i
:= 0 to e_MaxInputKeys
- 1 do
1977 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
1979 Write(f
, 'bind ', e_KeyNames
[i
], ' ', QuoteStr(GetCommandString(gInputBinds
[i
].down
)));
1980 if Length(gInputBinds
[i
].down
) = 0 then
1982 if Length(gInputBinds
[i
].up
) > 0 then
1983 Write(f
, ' ', QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
1985 if gInputBinds
[i
].rep
then
1986 WriteLn(f
, 'bindrep ', e_KeyNames
[i
]);
1990 if gAskLanguage
then
1991 WriteLn(f
, 'g_language ask')
1993 WriteLn(f
, 'g_language ', gLanguage
);
1996 WriteLn(f
, 'sv_name ', QuoteStr(NetServerName
));
1997 WriteLn(f
, 'sv_passwd ', QuoteStr(NetPassword
));
1998 WriteLn(f
, 'sv_maxplrs ', NetMaxClients
);
1999 WriteLn(f
, 'sv_port ', NetPort
);
2000 WriteLn(f
, 'sv_public ', IfThen(NetUseMaster
, 1, 0));
2004 WriteLn(f
, 'g_max_particles ', g_GFX_GetMax());
2006 WriteLn(f
, 'g_max_shells ', g_Shells_GetMax());
2007 WriteLn(f
, 'g_max_gibs ', g_Gibs_GetMax());
2008 WriteLn(f
, 'g_max_corpses ', g_Corpses_GetMax());
2009 WriteLn(f
, 'sv_intertime ', gDefInterTime
);
2011 // gameplay settings
2012 WriteLn(f
, 'g_gamemode ', gsGameMode
);
2013 WriteLn(f
, 'g_scorelimit ', gsGoalLimit
);
2014 WriteLn(f
, 'g_timelimit ', gsTimeLimit
);
2015 WriteLn(f
, 'g_maxlives ', gsMaxLives
);
2016 WriteLn(f
, 'g_item_respawn_time ', gsItemRespawnTime
);
2017 WriteLn(f
, 'g_spawn_invul ', gsSpawnInvul
);
2018 WriteLn(f
, 'g_warmup_time ', gsWarmupTime
);
2020 WriteFlag('g_friendlyfire ', GAME_OPTION_TEAMDAMAGE
);
2021 WriteFlag('g_friendly_hit_trace ', GAME_OPTION_TEAMHITTRACE
);
2022 WriteFlag('g_friendly_hit_projectile ', GAME_OPTION_TEAMHITPROJECTILE
);
2023 WriteFlag('g_allow_exit ', GAME_OPTION_ALLOWEXIT
);
2024 WriteFlag('g_allow_monsters ', GAME_OPTION_MONSTERS
);
2025 WriteFlag('g_dm_keys ', GAME_OPTION_DMKEYS
);
2026 WriteFlag('g_weaponstay ', GAME_OPTION_WEAPONSTAY
);
2027 WriteFlag('g_bot_vsmonsters ', GAME_OPTION_BOTVSMONSTER
);
2028 WriteFlag('g_bot_vsplayers ', GAME_OPTION_BOTVSPLAYER
);
2031 with gPlayer1Settings
do
2033 WriteLn(f
, 'p1_name ', QuoteStr(Name
));
2034 WriteLn(f
, 'p1_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2035 WriteLn(f
, 'p1_model ', QuoteStr(Model
));
2036 WriteLn(f
, 'p1_team ', FormatTeam(Team
));
2038 with gPlayer2Settings
do
2040 WriteLn(f
, 'p2_name ', QuoteStr(Name
));
2041 WriteLn(f
, 'p2_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2042 WriteLn(f
, 'p2_model ', QuoteStr(Model
));
2043 WriteLn(f
, 'p2_team ', FormatTeam(Team
));
2047 for i
:= 0 to High(commands
) do
2049 if not commands
[i
].cheat
then
2051 if @commands
[i
].procEx
= @boolVarHandler
then
2053 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
2054 WriteLn(f
, commands
[i
].cmd
, ' ', j
)
2056 else if @commands
[i
].procEx
= @intVarHandler
then
2058 WriteLn(f
, commands
[i
].cmd
, ' ', PInteger(commands
[i
].ptr
)^)
2060 else if @commands
[i
].procEx
= @wordVarHandler
then
2062 WriteLn(f
, commands
[i
].cmd
, ' ', PWord(commands
[i
].ptr
)^)
2064 else if @commands
[i
].procEx
= @dwordVarHandler
then
2066 WriteLn(f
, commands
[i
].cmd
, ' ', PCardinal(commands
[i
].ptr
)^)
2068 else if @commands
[i
].procEx
= @singleVarHandler
then
2070 WriteLn(f
, commands
[i
].cmd
, ' ', PVarSingle(commands
[i
].ptr
).val
^:0:6)
2072 else if @commands
[i
].procEx
= @strVarHandler
then
2074 if Length(PAnsiString(commands
[i
].ptr
)^) = 0 then
2075 WriteLn(f
, commands
[i
].cmd
, ' ""')
2077 WriteLn(f
, commands
[i
].cmd
, ' ', QuoteStr(PAnsiString(commands
[i
].ptr
)^))
2082 WriteLn(f
, 'r_maxfps ', gMaxFPS
);
2083 WriteLn(f
, 'r_reset');
2087 procedure g_Console_WriteGameConfig
;
2090 if gParsingBinds
= false then
2092 s
:= e_GetWriteableDir(ConfigDirs
);
2093 g_Console_WriteConfig(e_CatPath(s
, gConfigScript
))
2100 conRegVar('d_eres', @debug_e_res
, '', '');
2101 for i
:= 1 to e_MaxJoys
do
2102 conRegVar('joy' + IntToStr(i
) + '_deadzone', @e_JoystickDeadzones
[i
- 1], '', '')