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}
115 {$IFDEF ENABLE_SHELLS}
118 {$IFDEF ENABLE_CORPSES}
121 g_textures
, e_input
, g_game
, g_player
, g_items
,
122 SysUtils
, g_basic
, g_options
, Math
, e_res
,
123 g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
126 configComment
= 'generated by doom2d, do not modify';
129 PCommand
= ^TCommand
;
131 TCmdProc
= procedure (p
: SSArray
);
132 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
140 ptr
: Pointer; // various data
141 msg
: AnsiString; // message for var changes
143 action
: Integer; // >= 0 for action commands
144 player
: Integer; // used for action commands
155 MaxScriptRecursion
= 16;
158 RecursionDepth
: Word = 0;
159 RecursionLimitHit
: Boolean = False;
160 InputReady
: Boolean; // allow text input in console/chat
161 //ConsoleHistory: SSArray;
162 CommandHistory
: SSArray
;
164 commands
: Array of TCommand
= nil;
165 Aliases
: Array of TAlias
= nil;
168 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
173 menu_toggled
: BOOLEAN; (* hack for menu controls *)
175 procedure g_Console_Switch
;
178 gConsoleShow
:= not gConsoleShow
;
180 {$IFDEF ENABLE_TOUCH}
181 sys_ShowKeyboard(gConsoleShow
or gChatShow
);
185 procedure g_Console_Chat_Switch (Team
: Boolean = False);
187 if not g_Game_IsNet
then Exit
;
188 gConsoleShow
:= False;
189 gChatShow
:= not gChatShow
;
194 {$IFDEF ENABLE_TOUCH}
195 sys_ShowKeyboard(gConsoleShow
or gChatShow
);
199 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
200 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
209 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
210 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
211 if (pos
> slen
) then exit
;
212 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
214 while (pos
<= slen
) do
216 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
217 res
:= res
*10+Byte(s
[pos
])-48;
220 if (pos
<= slen
) then
223 if (s
[pos
] <> '.') then exit
;
225 while (pos
<= slen
) do
227 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
229 res
+= frac
*(Byte(s
[pos
])-48);
233 if (pos
<= slen
) then exit
; // oops
238 // ////////////////////////////////////////////////////////////////////////// //
239 // <0: no arg; 0/1: true/false; 666: toggle
240 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
242 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
244 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
245 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
246 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
247 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
251 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
252 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
256 if (Length(p
) > 2) then
258 conwritefln('too many arguments to ''%s''', [p
[0]]);
263 case conGetBoolArg(p
, 1) of
265 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
266 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
267 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
270 g_Console_WriteGameConfig();
271 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
272 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
276 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
280 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
284 if (Length(p
) <> 2) then
286 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
291 old
:= PInteger(me
.ptr
)^;
292 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
293 if PInteger(me
.ptr
)^ <> old
then
294 g_Console_WriteGameConfig();
296 conwritefln('invalid integer value: "%s"', [p
[1]]);
302 procedure wordVarHandler (me
: PCommand
; p
: SSArray
);
306 if (Length(p
) <> 2) then
308 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
313 old
:= PWord(me
.ptr
)^;
314 PWord(me
.ptr
)^ := min($FFFF, StrToDWord(p
[1]));
315 if PWord(me
.ptr
)^ <> old
then
316 g_Console_WriteGameConfig();
318 conwritefln('invalid word value: "%s"', [p
[1]]);
324 procedure dwordVarHandler (me
: PCommand
; p
: SSArray
);
328 if (Length(p
) <> 2) then
330 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
335 old
:= PCardinal(me
.ptr
)^;
336 PCardinal(me
.ptr
)^ := StrToDWord(p
[1]);
337 if PCardinal(me
.ptr
)^ <> old
then
338 g_Console_WriteGameConfig();
340 conwritefln('invalid dword value: "%s"', [p
[1]]);
346 procedure strVarHandler (me
: PCommand
; p
: SSArray
);
350 if (Length(p
) <> 2) then
352 conwritefln('%s %s', [me
.cmd
, QuoteStr(PAnsiString(me
.ptr
)^)]);
356 old
:= PAnsiString(me
.ptr
)^;
357 PAnsiString(me
.ptr
)^ := p
[1];
358 if PAnsiString(me
.ptr
)^ <> old
then
359 g_Console_WriteGameConfig();
364 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
369 f
:= Length(commands
);
370 SetLength(commands
, f
+1);
372 cp
.cmd
:= LowerCase(conname
);
374 cp
.procEx
:= boolVarHandler
;
376 cp
.hidden
:= ahidden
;
385 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
390 f
:= Length(commands
);
391 SetLength(commands
, f
+1);
393 cp
.cmd
:= LowerCase(conname
);
395 cp
.procEx
:= intVarHandler
;
397 cp
.hidden
:= ahidden
;
406 procedure conRegVar (const conname
: AnsiString; pvar
: PWord; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
411 f
:= Length(commands
);
412 SetLength(commands
, f
+1);
414 cp
.cmd
:= LowerCase(conname
);
416 cp
.procEx
:= wordVarHandler
;
418 cp
.hidden
:= ahidden
;
427 procedure conRegVar (const conname
: AnsiString; pvar
: PCardinal; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
432 f
:= Length(commands
);
433 SetLength(commands
, f
+1);
435 cp
.cmd
:= LowerCase(conname
);
437 cp
.procEx
:= dwordVarHandler
;
439 cp
.hidden
:= ahidden
;
448 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
453 f
:= Length(commands
);
454 SetLength(commands
, f
+1);
456 cp
.cmd
:= LowerCase(conname
);
458 cp
.procEx
:= strVarHandler
;
460 cp
.hidden
:= ahidden
;
468 // ////////////////////////////////////////////////////////////////////////// //
470 PVarSingle
= ^TVarSingle
;
473 min
, max
, def
: Single; // default will be starting value
477 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
483 if (Length(p
) > 2) then
485 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
488 pv
:= PVarSingle(me
.ptr
);
490 if (Length(p
) = 2) then
492 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
493 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
494 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
495 (CompareText(p
[1], 'ona') = 0) then
501 if not conParseFloat(nv
, p
[1]) then
503 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
506 if (nv
< pv
.min
) then nv
:= pv
.min
;
507 if (nv
> pv
.max
) then nv
:= pv
.max
;
511 if pv
.val
^ <> old
then
512 g_Console_WriteGameConfig();
514 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
515 conwritefln('%s %s', [msg
, pv
.val
^]);
519 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
525 GetMem(pv
, sizeof(TVarSingle
));
530 f
:= Length(commands
);
531 SetLength(commands
, f
+1);
533 cp
.cmd
:= LowerCase(conname
);
535 cp
.procEx
:= singleVarHandler
;
537 cp
.hidden
:= ahidden
;
546 // ////////////////////////////////////////////////////////////////////////// //
547 function GetStrACmd(var Str
: AnsiString): AnsiString;
552 for a
:= 1 to Length(Str
) do
553 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
555 Result
:= Copy(Str
, 1, a
);
562 function ParseAlias(Str
: AnsiString): SSArray
;
573 SetLength(Result
, Length(Result
)+1);
574 Result
[High(Result
)] := GetStrACmd(Str
);
578 procedure ConsoleCommands(p
: SSArray
);
584 cmd
:= LowerCase(p
[0]);
587 if cmd
= 'clear' then
589 //ConsoleHistory := nil;
593 for a
:= 0 to High(MsgArray
) do
601 if cmd
= 'clearhistory' then
602 CommandHistory
:= nil;
604 if cmd
= 'showhistory' then
605 if CommandHistory
<> nil then
608 for a
:= 0 to High(CommandHistory
) do
609 g_Console_Add(' '+CommandHistory
[a
]);
612 if cmd
= 'commands' then
615 g_Console_Add('commands list:');
616 for a
:= High(commands
) downto 0 do
618 if (Length(commands
[a
].help
) > 0) then
620 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
624 g_Console_Add(' '+commands
[a
].cmd
);
630 g_Console_Add(TimeToStr(Now
), True);
633 g_Console_Add(DateToStr(Now
), True);
636 if Length(p
) > 1 then
638 if p
[1] = 'ololo' then
643 for a
:= 1 to High(p
) do
645 g_Console_Add(b_Text_Format(s
), True);
654 if ConsoleHistory <> nil then
656 if Length(P) > 1 then
659 s := GameDir+'/console.txt';
664 if IOResult <> 0 then
666 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
671 for a := 0 to High(ConsoleHistory) do
672 WriteLn(F, ConsoleHistory[a]);
675 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
684 if Length(p
) = 2 then
685 g_Console_ReadConfig(p
[1])
687 g_Console_Add('exec <script file>');
690 if cmd
= 'writeconfig' then
692 // writeconfig <filename>
693 if Length(p
) = 2 then
695 s
:= e_GetWriteableDir(ConfigDirs
);
696 g_Console_WriteConfig(e_CatPath(s
, p
[1]))
700 g_Console_Add('writeconfig <file>')
704 if (cmd
= 'ver') or (cmd
= 'version') then
706 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
707 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
708 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
711 if cmd
= 'alias' then
713 // alias [alias_name] [commands]
714 if Length(p
) > 1 then
716 for a
:= 0 to High(Aliases
) do
717 if Aliases
[a
].name
= p
[1] then
719 if Length(p
) > 2 then
720 Aliases
[a
].commands
:= ParseAlias(p
[2])
722 for b
:= 0 to High(Aliases
[a
].commands
) do
723 g_Console_Add(Aliases
[a
].commands
[b
]);
726 SetLength(Aliases
, Length(Aliases
)+1);
728 Aliases
[a
].name
:= p
[1];
729 if Length(p
) > 2 then
730 Aliases
[a
].commands
:= ParseAlias(p
[2])
732 for b
:= 0 to High(Aliases
[a
].commands
) do
733 g_Console_Add(Aliases
[a
].commands
[b
]);
735 for a
:= 0 to High(Aliases
) do
736 if Aliases
[a
].commands
<> nil then
737 g_Console_Add(Aliases
[a
].name
);
743 if Length(p
) > 1 then
745 if Aliases
= nil then
747 for a
:= 0 to High(Aliases
) do
748 if Aliases
[a
].name
= p
[1] then
750 if Aliases
[a
].commands
<> nil then
752 // with this system proper endless loop detection seems either impossible
753 // or very dirty to implement, so let's have this instead
754 // prevents endless loops
755 for b
:= 0 to High(Aliases
[a
].commands
) do
758 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
759 if not RecursionLimitHit
then
760 g_Console_Process(Aliases
[a
].commands
[b
], True);
763 if (RecursionDepth
= 0) and RecursionLimitHit
then
765 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
766 RecursionLimitHit
:= False;
773 g_Console_Add('call <alias name>');
777 procedure WhitelistCommand(cmd
: AnsiString);
781 SetLength(Whitelist
, Length(Whitelist
)+1);
782 a
:= High(Whitelist
);
783 Whitelist
[a
] := LowerCase(cmd
);
786 procedure segfault (p
: SSArray
);
793 function GetCommandString (p
: SSArray
): AnsiString;
797 if Length(p
) >= 1 then
800 for i
:= 1 to High(p
) do
801 result
:= result
+ '; ' + p
[i
]
805 function QuoteStr(str
: String): String;
807 if Pos(' ', str
) > 0 then
808 Result
:= '"' + str
+ '"'
813 procedure BindCommands (p
: SSArray
);
814 var cmd
, key
: AnsiString; i
: Integer;
816 cmd
:= LowerCase(p
[0]);
819 // bind <key> [down [up]]
820 if (Length(p
) >= 2) and (Length(p
) <= 4) then
823 key
:= LowerCase(p
[1]);
824 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
825 if i
< e_MaxInputKeys
then
827 if Length(p
) = 2 then
828 g_Console_Add(QuoteStr(e_KeyNames
[i
]) + ' = ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)))
829 else if Length(p
) = 3 then
830 g_Console_BindKey(i
, p
[2], '')
832 g_Console_BindKey(i
, p
[2], p
[3])
835 g_Console_Add('bind: "' + p
[1] + '" is not a key')
839 g_Console_Add('bind <key> <down action> [up action]')
843 if Length(p
) = 2 then
845 key
:= LowerCase(p
[1]);
847 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
848 if i
< e_MaxInputKeys
then
849 gInputBinds
[i
].rep
:= True
851 g_Console_Add('bindrep: "' + p
[1] + '" is not a key')
854 g_Console_Add('bindrep <key>');
857 if Length(p
) = 2 then
859 key
:= LowerCase(p
[1]);
861 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
862 if i
< e_MaxInputKeys
then
863 gInputBinds
[i
].rep
:= False
865 g_Console_Add('bindunrep: "' + p
[1] + '" is not a key')
868 g_Console_Add('bindunrep <key>');
870 for i
:= 0 to e_MaxInputKeys
- 1 do
871 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
872 g_Console_Add(e_KeyNames
[i
] + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
875 if Length(p
) = 2 then
877 key
:= LowerCase(p
[1]);
879 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
880 if i
< e_MaxInputKeys
then
881 g_Console_BindKey(i
, '')
883 g_Console_Add('unbind: "' + p
[1] + '" is not a key')
886 g_Console_Add('unbind <key>');
888 for i
:= 0 to e_MaxInputKeys
- 1 do
889 g_Console_BindKey(i
, '');
890 {$IFDEF ENABLE_TOUCH}
892 sys_ShowKeyboard(True);
894 sys_ShowKeyboard(False);
900 else if gChatShow
then
901 g_Console_Chat_Switch
911 g_Console_Chat_Switch
;
913 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
914 g_Console_Chat_Switch(True);
918 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
923 SetLength(commands
, Length(commands
)+1);
926 cp
.cmd
:= LowerCase(cmd
);
930 cp
.hidden
:= ahidden
;
938 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
940 PrefixList
: array [0..1] of AnsiString = ('+', '-');
941 PlayerList
: array [0..1] of Integer = (1, 2);
946 procedure NewAction (cmd
: AnsiString; player
: Integer);
949 SetLength(commands
, Length(commands
) + 1);
950 cp
:= @commands
[High(commands
)];
951 cp
.cmd
:= LowerCase(cmd
);
964 ASSERT(action
>= FIRST_ACTION
);
965 ASSERT(action
<= LAST_ACTION
);
966 for s
in PrefixList
do
968 NewAction(s
+ cmd
, 0);
969 for i
in PlayerList
do
970 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
974 procedure g_Console_Initialize
;
977 gConsoleShow
:= False;
982 for a
:= 0 to High(MsgArray
) do
989 AddCommand('segfault', segfault
, 'make segfault');
991 AddCommand('quit', SystemCommands
);
992 AddCommand('exit', SystemCommands
);
993 AddCommand('r_reset', SystemCommands
);
994 AddCommand('r_maxfps', SystemCommands
);
995 AddCommand('g_language', SystemCommands
);
997 AddCommand('bind', BindCommands
);
998 AddCommand('bindrep', BindCommands
);
999 AddCommand('bindunrep', BindCommands
);
1000 AddCommand('bindlist', BindCommands
);
1001 AddCommand('unbind', BindCommands
);
1002 AddCommand('unbindall', BindCommands
);
1003 AddCommand('showkeyboard', BindCommands
);
1004 AddCommand('hidekeyboard', BindCommands
);
1005 AddCommand('togglemenu', BindCommands
);
1006 AddCommand('toggleconsole', BindCommands
);
1007 AddCommand('togglechat', BindCommands
);
1008 AddCommand('toggleteamchat', BindCommands
);
1010 AddCommand('clear', ConsoleCommands
, 'clear console');
1011 AddCommand('clearhistory', ConsoleCommands
);
1012 AddCommand('showhistory', ConsoleCommands
);
1013 AddCommand('commands', ConsoleCommands
);
1014 AddCommand('time', ConsoleCommands
);
1015 AddCommand('date', ConsoleCommands
);
1016 AddCommand('echo', ConsoleCommands
);
1017 AddCommand('dump', ConsoleCommands
);
1018 AddCommand('exec', ConsoleCommands
);
1019 AddCommand('writeconfig', ConsoleCommands
);
1020 AddCommand('alias', ConsoleCommands
);
1021 AddCommand('call', ConsoleCommands
);
1022 AddCommand('ver', ConsoleCommands
);
1023 AddCommand('version', ConsoleCommands
);
1025 AddCommand('d_window', DebugCommands
);
1026 AddCommand('d_sounds', DebugCommands
);
1027 AddCommand('d_frames', DebugCommands
);
1028 AddCommand('d_winmsg', DebugCommands
);
1029 AddCommand('d_monoff', DebugCommands
);
1030 AddCommand('d_botoff', DebugCommands
);
1031 AddCommand('d_monster', DebugCommands
);
1032 AddCommand('d_health', DebugCommands
);
1033 AddCommand('d_player', DebugCommands
);
1034 AddCommand('d_joy', DebugCommands
);
1035 AddCommand('d_mem', DebugCommands
);
1037 AddCommand('p1_name', PlayerSettingsCVars
);
1038 AddCommand('p2_name', PlayerSettingsCVars
);
1039 AddCommand('p1_color', PlayerSettingsCVars
);
1040 AddCommand('p2_color', PlayerSettingsCVars
);
1041 AddCommand('p1_model', PlayerSettingsCVars
);
1042 AddCommand('p2_model', PlayerSettingsCVars
);
1043 AddCommand('p1_team', PlayerSettingsCVars
);
1044 AddCommand('p2_team', PlayerSettingsCVars
);
1046 AddCommand('g_max_particles', GameCVars
);
1047 AddCommand('g_max_shells', GameCVars
);
1048 AddCommand('g_max_gibs', GameCVars
);
1049 AddCommand('g_max_corpses', GameCVars
);
1050 AddCommand('g_gamemode', GameCVars
);
1051 AddCommand('g_friendlyfire', GameCVars
);
1052 AddCommand('g_friendly_hit_trace', GameCVars
);
1053 AddCommand('g_friendly_hit_projectile', GameCVars
);
1054 AddCommand('g_friendly_absorb_damage', GameCVars
);
1055 AddCommand('g_weaponstay', GameCVars
);
1056 AddCommand('g_allow_exit', GameCVars
);
1057 AddCommand('g_dm_keys', GameCVars
);
1058 AddCommand('g_allow_monsters', GameCVars
);
1059 AddCommand('g_bot_vsmonsters', GameCVars
);
1060 AddCommand('g_bot_vsplayers', GameCVars
);
1061 AddCommand('g_scorelimit', GameCVars
);
1062 AddCommand('g_timelimit', GameCVars
);
1063 AddCommand('g_maxlives', GameCVars
);
1064 AddCommand('g_warmup_time', GameCVars
);
1065 AddCommand('g_spawn_invul', GameCVars
);
1066 AddCommand('g_item_respawn_time', GameCVars
);
1067 AddCommand('sv_intertime', GameCVars
);
1069 AddCommand('sv_name', NetServerCVars
);
1070 AddCommand('sv_passwd', NetServerCVars
);
1071 AddCommand('sv_maxplrs', NetServerCVars
);
1072 AddCommand('sv_public', NetServerCVars
);
1073 AddCommand('sv_port', NetServerCVars
);
1075 AddCommand('pause', GameCommands
);
1076 AddCommand('endgame', GameCommands
);
1077 AddCommand('restart', GameCommands
);
1078 AddCommand('addbot', GameCommands
);
1079 AddCommand('bot_add', GameCommands
);
1080 AddCommand('bot_addlist', GameCommands
);
1081 AddCommand('bot_addred', GameCommands
);
1082 AddCommand('bot_addblue', GameCommands
);
1083 AddCommand('bot_removeall', GameCommands
);
1084 AddCommand('chat', GameCommands
);
1085 AddCommand('teamchat', GameCommands
);
1086 AddCommand('game', GameCommands
);
1087 AddCommand('host', GameCommands
);
1088 AddCommand('map', GameCommands
);
1089 AddCommand('nextmap', GameCommands
);
1090 AddCommand('endmap', GameCommands
);
1091 AddCommand('goodbye', GameCommands
);
1092 AddCommand('suicide', GameCommands
);
1093 AddCommand('spectate', GameCommands
);
1094 AddCommand('ready', GameCommands
);
1095 AddCommand('kick', GameCommands
);
1096 AddCommand('kick_id', GameCommands
);
1097 AddCommand('kick_pid', GameCommands
);
1098 AddCommand('ban', GameCommands
);
1099 AddCommand('ban_id', GameCommands
);
1100 AddCommand('ban_pid', GameCommands
);
1101 AddCommand('permban', GameCommands
);
1102 AddCommand('permban_id', GameCommands
);
1103 AddCommand('permban_pid', GameCommands
);
1104 AddCommand('permban_ip', GameCommands
);
1105 AddCommand('unban', GameCommands
);
1106 AddCommand('connect', GameCommands
);
1107 AddCommand('disconnect', GameCommands
);
1108 AddCommand('reconnect', GameCommands
);
1109 AddCommand('say', GameCommands
);
1110 AddCommand('tell', GameCommands
);
1111 AddCommand('centerprint', GameCommands
);
1112 AddCommand('overtime', GameCommands
);
1113 AddCommand('rcon_password', GameCommands
);
1114 AddCommand('rcon', GameCommands
);
1115 AddCommand('callvote', GameCommands
);
1116 AddCommand('vote', GameCommands
);
1117 AddCommand('clientlist', GameCommands
);
1118 AddCommand('event', GameCommands
);
1119 AddCommand('screenshot', GameCommands
);
1120 AddCommand('weapon', GameCommands
);
1121 AddCommand('p1_weapon', GameCommands
);
1122 AddCommand('p2_weapon', GameCommands
);
1124 AddCommand('god', GameCheats
);
1125 AddCommand('notarget', GameCheats
);
1126 AddCommand('give', GameCheats
); // "exit" too ;-)
1127 AddCommand('open', GameCheats
);
1128 AddCommand('fly', GameCheats
);
1129 AddCommand('noclip', GameCheats
);
1130 AddCommand('speedy', GameCheats
);
1131 AddCommand('jumpy', GameCheats
);
1132 AddCommand('noreload', GameCheats
);
1133 AddCommand('aimline', GameCheats
);
1134 AddCommand('automap', GameCheats
);
1136 AddAction('jump', ACTION_JUMP
);
1137 AddAction('moveleft', ACTION_MOVELEFT
);
1138 AddAction('moveright', ACTION_MOVERIGHT
);
1139 AddAction('lookup', ACTION_LOOKUP
);
1140 AddAction('lookdown', ACTION_LOOKDOWN
);
1141 AddAction('attack', ACTION_ATTACK
);
1142 AddAction('scores', ACTION_SCORES
);
1143 AddAction('activate', ACTION_ACTIVATE
);
1144 AddAction('strafe', ACTION_STRAFE
);
1145 AddAction('weapnext', ACTION_WEAPNEXT
);
1146 AddAction('weapprev', ACTION_WEAPPREV
);
1148 WhitelistCommand('say');
1149 WhitelistCommand('tell');
1150 WhitelistCommand('overtime');
1151 WhitelistCommand('ready');
1152 WhitelistCommand('map');
1153 WhitelistCommand('nextmap');
1154 WhitelistCommand('endmap');
1155 WhitelistCommand('restart');
1156 WhitelistCommand('kick');
1157 WhitelistCommand('kick_pid');
1158 WhitelistCommand('ban');
1159 WhitelistCommand('ban_pid');
1160 WhitelistCommand('centerprint');
1162 WhitelistCommand('addbot');
1163 WhitelistCommand('bot_add');
1164 WhitelistCommand('bot_addred');
1165 WhitelistCommand('bot_addblue');
1166 WhitelistCommand('bot_removeall');
1168 WhitelistCommand('g_gamemode');
1169 WhitelistCommand('g_friendlyfire');
1170 WhitelistCommand('g_friendly_hit_trace');
1171 WhitelistCommand('g_friendly_hit_projectile');
1172 WhitelistCommand('g_friendly_absorb_damage');
1173 WhitelistCommand('g_weaponstay');
1174 WhitelistCommand('g_allow_exit');
1175 WhitelistCommand('g_dm_keys');
1176 WhitelistCommand('g_allow_monsters');
1177 WhitelistCommand('g_bot_vsmonsters');
1178 WhitelistCommand('g_bot_vsplayers');
1179 WhitelistCommand('g_scorelimit');
1180 WhitelistCommand('g_timelimit');
1181 WhitelistCommand('g_maxlives');
1182 WhitelistCommand('g_warmup_time');
1183 WhitelistCommand('g_spawn_invul');
1184 WhitelistCommand('g_item_respawn_time');
1186 g_Console_ResetBinds
;
1187 g_Console_ReadConfig(gConfigScript
);
1188 // g_Console_ReadConfig(autoexecScript);
1189 g_Console_ReadConfig('autoexec.cfg');
1191 gParsingBinds
:= False;
1194 procedure g_Console_Finalize
;
1199 procedure g_Console_Init
;
1201 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
1205 procedure g_Console_Update
;
1209 InputReady
:= gConsoleShow
or gChatShow
;
1212 while a
<= High(MsgArray
) do
1214 if MsgArray
[a
].Time
> 0 then
1216 if MsgArray
[a
].Time
= 1 then
1218 if a
< High(MsgArray
) then
1220 for b
:= a
to High(MsgArray
)-1 do
1221 MsgArray
[b
] := MsgArray
[b
+1];
1223 MsgArray
[High(MsgArray
)].Time
:= 0;
1229 Dec(MsgArray
[a
].Time
);
1236 procedure g_Console_Char(C
: AnsiChar);
1238 if InputReady
and (gConsoleShow
or gChatShow
) then
1240 Insert(C
, Line
, CPos
);
1247 tcomplist
: array of AnsiString = nil;
1248 tcompidx
: array of Integer = nil;
1250 procedure Complete ();
1254 ll
, lpfx
, cmd
: AnsiString;
1256 if (Length(Line
) = 0) then
1259 for i
:= 0 to High(commands
) do
1261 // hidden commands are hidden when cheats aren't enabled
1262 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1263 if (Length(commands
[i
].help
) > 0) then
1265 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1269 g_Console_Add(' '+commands
[i
].cmd
);
1275 ll
:= LowerCase(Line
);
1278 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1280 ll
:= Copy(ll
, 0, Length(ll
)-1);
1281 for i
:= 0 to High(commands
) do
1283 // hidden commands are hidden when cheats aren't enabled
1284 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1285 if (commands
[i
].cmd
= ll
) then
1287 if (Length(commands
[i
].help
) > 0) then
1289 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1296 // build completion list
1298 for i
:= 0 to High(commands
) do
1300 // hidden commands are hidden when cheats aren't enabled
1301 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1302 cmd
:= commands
[i
].cmd
;
1303 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1305 if (tused
= Length(tcomplist
)) then
1307 SetLength(tcomplist
, Length(tcomplist
)+128);
1308 SetLength(tcompidx
, Length(tcompidx
)+128);
1310 tcomplist
[tused
] := cmd
;
1311 tcompidx
[tused
] := i
;
1313 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1317 // get longest prefix
1318 for i
:= 0 to tused
-1 do
1320 cmd
:= tcomplist
[i
];
1321 for c
:= 1 to Length(lpfx
) do
1323 if (c
> Length(cmd
)) then break
;
1324 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1328 if (tused
= 0) then exit
;
1332 Line
:= tcomplist
[0]+' ';
1333 CPos
:= Length(Line
)+1;
1337 // has longest prefix?
1338 if (Length(lpfx
) > Length(ll
)) then
1341 CPos
:= Length(Line
)+1;
1346 for i
:= 0 to tused
-1 do
1348 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1350 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1354 g_Console_Add(' '+tcomplist
[i
]);
1362 procedure g_Console_Control(K
: Word);
1366 if (Length(Line
) > 0) and (CPos
> 1) then
1368 Delete(Line
, CPos
-1, 1);
1372 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1373 Delete(Line
, CPos
, 1);
1374 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1377 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1378 if CPos
<= Length(Line
) then
1380 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1382 if gConsoleShow
then
1383 g_Console_Process(Line
)
1387 if (Length(Line
) > 0) and g_Game_IsNet
then
1391 if g_Game_IsClient
then
1392 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1394 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1395 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1399 if g_Game_IsClient
then
1400 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1402 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1409 gJustChatted
:= True;
1410 g_Console_Chat_Switch
;
1411 InputReady
:= False;
1415 if not gChatShow
then
1417 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1418 if not gChatShow
then
1419 if (CommandHistory
<> nil) and
1420 (CmdIndex
< Length(CommandHistory
)) then
1422 if CmdIndex
< Length(CommandHistory
)-1 then
1423 CmdIndex
:= CmdIndex
+ 1;
1424 Line
:= CommandHistory
[CmdIndex
];
1425 CPos
:= Length(Line
) + 1;
1427 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1428 if not gChatShow
then
1429 if (CommandHistory
<> nil) and
1430 (CmdIndex
<= Length(CommandHistory
)) then
1432 if CmdIndex
> 0 then
1433 CmdIndex
:= CmdIndex
- 1;
1434 Line
:= CommandHistory
[CmdIndex
];
1435 Cpos
:= Length(Line
) + 1;
1437 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1438 if not gChatShow
then Inc(conSkipLines
);
1439 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1440 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1444 CPos
:= Length(Line
) + 1;
1445 IK_A
..IK_Z
, IK_SPACE
, IK_SHIFT
, IK_RSHIFT
, IK_CAPSLOCK
, IK_LBRACKET
, IK_RBRACKET
,
1446 IK_SEMICOLON
, IK_QUOTE
, IK_BACKSLASH
, IK_SLASH
, IK_COMMA
, IK_DOT
, (*IK_EQUALS,*)
1447 IK_0
, IK_1
, IK_2
, IK_3
, IK_4
, IK_5
, IK_6
, IK_7
, IK_8
, IK_9
, IK_MINUS
, IK_EQUALS
:
1448 (* see TEXTINPUT event *)
1452 function GetStr(var Str
: AnsiString): AnsiString;
1457 if Str
[1] = '"' then
1459 for b
:= 1 to Length(Str
) do
1460 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1462 Result
:= Copy(Str
, 2, b
-1);
1463 Delete(Str
, 1, b
+1);
1469 for a
:= 1 to Length(Str
) do
1470 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1472 Result
:= Copy(Str
, 1, a
);
1473 Delete(Str
, 1, a
+1);
1479 function ParseString(Str
: AnsiString): SSArray
;
1490 SetLength(Result
, Length(Result
)+1);
1491 Result
[High(Result
)] := GetStr(Str
);
1495 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1497 procedure conmsg (s
: AnsiString);
1501 if length(s
) = 0 then exit
;
1502 for a
:= 0 to High(MsgArray
) do
1514 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1515 with MsgArray
[High(MsgArray
)] do
1525 // put it to console
1527 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1529 // now show 'em out of console too
1530 show
:= show
and gAllowConsoleMessages
;
1531 if show
and gShowMessages
then
1533 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1534 while length(L
) > 0 do
1537 if f
<= 0 then f
:= length(L
)+1;
1538 conmsg(Copy(L
, 1, f
-1));
1543 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1544 //ConsoleHistory[High(ConsoleHistory)] := L;
1548 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1555 consolewriterLastWasEOL
: Boolean = false;
1557 procedure consolewriter (constref buf
; len
: SizeUInt
);
1561 if (len
< 1) then exit
;
1563 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1566 if (b
[0] <> 13) and (b
[0] <> 10) then
1568 cbufPut(AnsiChar(b
[0]));
1572 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1581 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1582 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1583 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1584 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1586 g_Console_Add(s
, show
);
1590 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1594 g_Console_Add(formatstrf(s
, args
), true);
1598 consolewriterLastWasEOL
:= false;
1599 formatstrf(s
, args
, consolewriter
);
1600 if not consolewriterLastWasEOL
then cbufPut(#10);
1605 procedure g_Console_Clear();
1607 //ConsoleHistory := nil;
1612 procedure AddToHistory(L
: AnsiString);
1616 len
:= Length(CommandHistory
);
1619 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1621 SetLength(CommandHistory
, len
+1);
1622 CommandHistory
[len
] := L
;
1625 CmdIndex
:= Length(CommandHistory
);
1628 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1637 if Trim(C
) = '' then
1640 Arr
:= ParseString(C
);
1644 for i
:= 0 to High(Whitelist
) do
1645 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1649 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1656 if Trim(L
) = '' then
1659 conSkipLines
:= 0; // "unscroll"
1661 if L
= 'goobers' then
1666 g_Console_Add('Your memory serves you well.');
1672 g_Console_Add('> '+L
);
1677 Arr
:= ParseString(L
);
1681 if commands
= nil then
1687 for i
:= 0 to High(commands
) do
1689 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1691 if commands
[i
].action
>= 0 then
1693 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1696 if assigned(commands
[i
].procEx
) then
1698 commands
[i
].procEx(@commands
[i
], Arr
);
1701 if assigned(commands
[i
].proc
) then
1703 commands
[i
].proc(Arr
);
1709 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1713 function g_Console_Interactive
: Boolean;
1715 Result
:= gConsoleShow
1718 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1720 // e_LogWritefln('bind "%s" "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), down, up, key]);
1722 ASSERT(key
< e_MaxInputKeys
);
1725 gInputBinds
[key
].rep
:= False;
1726 gInputBinds
[key
].down
:= ParseAlias(down
);
1727 gInputBinds
[key
].up
:= ParseAlias(up
);
1729 g_Console_WriteGameConfig();
1732 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
1734 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1735 var i
, len
: Integer;
1739 if len
= Length(b
) then
1742 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1750 ASSERT(key
< e_MaxInputKeys
);
1751 result
:= EqualsCommandLists(ParseAlias(down
), gInputBinds
[key
].down
) and EqualsCommandLists(ParseAlias(up
), gInputBinds
[key
].up
)
1754 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1759 if commands
= nil then Exit
;
1761 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1763 if g_Console_MatchBind(i
, down
, up
) then
1774 function g_Console_Action (action
: Integer): Boolean;
1775 var i
, len
: Integer;
1777 ASSERT(action
>= FIRST_ACTION
);
1778 ASSERT(action
<= LAST_ACTION
);
1780 len
:= Length(gPlayerAction
);
1781 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1785 function BindsAllowed (key
: Integer): Boolean;
1786 var grab
, active
: Boolean;
1789 {$IFDEF DISABLE_MENU}
1793 grab
:= g_GUIGrabInput
;
1794 active
:= g_ActiveWindow
<> nil;
1796 if (not grab
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1799 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1800 g_Console_MatchBind(key
, 'showkeyboard') or
1801 g_Console_MatchBind(key
, 'hidekeyboard')
1802 else if gConsoleShow
or active
or (gGameSettings
.GameType
= GT_NONE
) then
1803 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1804 g_Console_MatchBind(key
, 'toggleconsole') or
1805 g_Console_MatchBind(key
, 'showkeyboard') or
1806 g_Console_MatchBind(key
, 'hidekeyboard')
1812 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1815 if BindsAllowed(key
) then
1818 for i
:= 0 to High(gInputBinds
[key
].down
) do
1819 g_Console_Process(gInputBinds
[key
].down
[i
], True)
1821 for i
:= 0 to High(gInputBinds
[key
].up
) do
1822 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1824 if down
and not menu_toggled
then
1826 menu_toggled
:= False
1829 procedure g_Console_ProcessBindRepeat (key
: Integer);
1830 var i
: Integer; active
: Boolean;
1832 {$IFDEF DISABLE_MENU}
1835 active
:= g_ActiveWindow
<> nil;
1837 if gConsoleShow
or gChatShow
or active
then
1839 KeyPress(key
); // key repeat in menus and shit
1842 if BindsAllowed(key
) and gInputBinds
[key
].rep
then
1844 for i
:= 0 to High(gInputBinds
[key
].down
) do
1845 g_Console_Process(gInputBinds
[key
].down
[i
], True);
1849 procedure g_Console_ResetBinds
;
1852 for i
:= 0 to e_MaxInputKeys
- 1 do
1853 g_Console_BindKey(i
, '', '');
1855 g_Console_BindKey(IK_GRAVE
, 'toggleconsole');
1856 g_Console_BindKey(IK_ESCAPE
, 'togglemenu');
1857 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1858 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1859 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1860 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1861 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1862 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1863 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1864 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1865 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1866 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1867 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1868 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1869 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1870 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1871 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1872 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1873 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1874 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1875 g_Console_BindKey(IK_9
, 'p1_weapon 9');
1876 g_Console_BindKey(IK_0
, 'p1_weapon 10');
1877 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
1878 g_Console_BindKey(IK_T
, 'togglechat');
1879 g_Console_BindKey(IK_Y
, 'toggleteamchat');
1880 g_Console_BindKey(IK_F11
, 'screenshot');
1881 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
1882 g_Console_BindKey(IK_PAUSE
, 'pause');
1883 g_Console_BindKey(IK_F1
, 'vote');
1885 (* for i := 0 to e_MaxJoys - 1 do *)
1888 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_LEFT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
1889 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_RIGHT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
1890 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_UP
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
1891 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_DOWN
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
1892 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
1893 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
1894 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
1895 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
1896 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
1897 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
1898 g_Console_BindKey(e_JoyButtonToKey(i
, 10), 'togglemenu');
1901 g_Console_BindKey(VK_ESCAPE
, 'togglemenu');
1902 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
1903 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
1904 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
1905 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
1906 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
1907 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
1908 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
1909 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
1910 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
1911 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
1912 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
1913 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
1914 g_Console_BindKey(VK_0
, 'weapon 1');
1915 g_Console_BindKey(VK_1
, 'weapon 2');
1916 g_Console_BindKey(VK_2
, 'weapon 3');
1917 g_Console_BindKey(VK_3
, 'weapon 4');
1918 g_Console_BindKey(VK_4
, 'weapon 5');
1919 g_Console_BindKey(VK_5
, 'weapon 6');
1920 g_Console_BindKey(VK_6
, 'weapon 7');
1921 g_Console_BindKey(VK_7
, 'weapon 8');
1922 g_Console_BindKey(VK_8
, 'weapon 9');
1923 g_Console_BindKey(VK_9
, 'weapon 10');
1924 g_Console_BindKey(VK_A
, 'weapon 11');
1925 g_Console_BindKey(VK_CHAT
, 'togglechat');
1926 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
1927 g_Console_BindKey(VK_CONSOLE
, 'toggleconsole');
1928 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
1929 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
1930 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
1931 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
1934 procedure g_Console_ReadConfig (filename
: String);
1935 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1937 e_LogWritefln('g_Console_ReadConfig (1) "%s"', [filename
]);
1938 if e_FindResource(ConfigDirs
, filename
, false) = true then
1940 e_LogWritefln('g_Console_ReadConfig (2) "%s"', [filename
]);
1941 AssignFile(f
, filename
);
1951 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1953 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1954 g_Console_Process(s
, True);
1961 procedure g_Console_WriteConfig (filename
: String);
1962 var f
: TextFile
; i
, j
: Integer;
1964 procedure WriteFlag(name
: string; flag
: LongWord);
1966 WriteLn(f
, name
, IfThen(LongBool(gsGameFlags
and flag
), 1, 0));
1969 function FormatTeam(team
: Byte): string;
1971 if team
= TEAM_BLUE
then
1978 // e_LogWritefln('g_Console_WriteConfig: %s', [filename]);
1979 AssignFile(f
, filename
);
1981 WriteLn(f
, '// ' + configComment
);
1984 WriteLn(f
, 'unbindall');
1985 for i
:= 0 to e_MaxInputKeys
- 1 do
1986 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
1988 Write(f
, 'bind ', e_KeyNames
[i
], ' ', QuoteStr(GetCommandString(gInputBinds
[i
].down
)));
1989 if Length(gInputBinds
[i
].down
) = 0 then
1991 if Length(gInputBinds
[i
].up
) > 0 then
1992 Write(f
, ' ', QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
1994 if gInputBinds
[i
].rep
then
1995 WriteLn(f
, 'bindrep ', e_KeyNames
[i
]);
1999 if gAskLanguage
then
2000 WriteLn(f
, 'g_language ask')
2002 WriteLn(f
, 'g_language ', gLanguage
);
2005 WriteLn(f
, 'sv_name ', QuoteStr(NetServerName
));
2006 WriteLn(f
, 'sv_passwd ', QuoteStr(NetPassword
));
2007 WriteLn(f
, 'sv_maxplrs ', NetMaxClients
);
2008 WriteLn(f
, 'sv_port ', NetPort
);
2009 WriteLn(f
, 'sv_public ', IfThen(NetUseMaster
, 1, 0));
2013 WriteLn(f
, 'g_max_particles ', g_GFX_GetMax());
2015 {$IFDEF ENABLE_SHELLS}
2016 WriteLn(f
, 'g_max_shells ', g_Shells_GetMax());
2018 {$IFDEF ENABLE_GIBS}
2019 WriteLn(f
, 'g_max_gibs ', g_Gibs_GetMax());
2021 {$IFDEF ENABLE_CORPSES}
2022 WriteLn(f
, 'g_max_corpses ', g_Corpses_GetMax());
2024 WriteLn(f
, 'sv_intertime ', gDefInterTime
);
2026 // gameplay settings
2027 WriteLn(f
, 'g_gamemode ', gsGameMode
);
2028 WriteLn(f
, 'g_scorelimit ', gsGoalLimit
);
2029 WriteLn(f
, 'g_timelimit ', gsTimeLimit
);
2030 WriteLn(f
, 'g_maxlives ', gsMaxLives
);
2031 WriteLn(f
, 'g_item_respawn_time ', gsItemRespawnTime
);
2032 WriteLn(f
, 'g_spawn_invul ', gsSpawnInvul
);
2033 WriteLn(f
, 'g_warmup_time ', gsWarmupTime
);
2035 WriteFlag('g_friendlyfire ', GAME_OPTION_TEAMDAMAGE
);
2036 WriteFlag('g_friendly_hit_trace ', GAME_OPTION_TEAMHITTRACE
);
2037 WriteFlag('g_friendly_hit_projectile ', GAME_OPTION_TEAMHITPROJECTILE
);
2038 WriteFlag('g_allow_exit ', GAME_OPTION_ALLOWEXIT
);
2039 WriteFlag('g_allow_monsters ', GAME_OPTION_MONSTERS
);
2040 WriteFlag('g_dm_keys ', GAME_OPTION_DMKEYS
);
2041 WriteFlag('g_weaponstay ', GAME_OPTION_WEAPONSTAY
);
2042 WriteFlag('g_bot_vsmonsters ', GAME_OPTION_BOTVSMONSTER
);
2043 WriteFlag('g_bot_vsplayers ', GAME_OPTION_BOTVSPLAYER
);
2046 with gPlayer1Settings
do
2048 WriteLn(f
, 'p1_name ', QuoteStr(Name
));
2049 WriteLn(f
, 'p1_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2050 WriteLn(f
, 'p1_model ', QuoteStr(Model
));
2051 WriteLn(f
, 'p1_team ', FormatTeam(Team
));
2053 with gPlayer2Settings
do
2055 WriteLn(f
, 'p2_name ', QuoteStr(Name
));
2056 WriteLn(f
, 'p2_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2057 WriteLn(f
, 'p2_model ', QuoteStr(Model
));
2058 WriteLn(f
, 'p2_team ', FormatTeam(Team
));
2062 for i
:= 0 to High(commands
) do
2064 if not commands
[i
].cheat
then
2066 if @commands
[i
].procEx
= @boolVarHandler
then
2068 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
2069 WriteLn(f
, commands
[i
].cmd
, ' ', j
)
2071 else if @commands
[i
].procEx
= @intVarHandler
then
2073 WriteLn(f
, commands
[i
].cmd
, ' ', PInteger(commands
[i
].ptr
)^)
2075 else if @commands
[i
].procEx
= @wordVarHandler
then
2077 WriteLn(f
, commands
[i
].cmd
, ' ', PWord(commands
[i
].ptr
)^)
2079 else if @commands
[i
].procEx
= @dwordVarHandler
then
2081 WriteLn(f
, commands
[i
].cmd
, ' ', PCardinal(commands
[i
].ptr
)^)
2083 else if @commands
[i
].procEx
= @singleVarHandler
then
2085 WriteLn(f
, commands
[i
].cmd
, ' ', PVarSingle(commands
[i
].ptr
).val
^:0:6)
2087 else if @commands
[i
].procEx
= @strVarHandler
then
2089 if Length(PAnsiString(commands
[i
].ptr
)^) = 0 then
2090 WriteLn(f
, commands
[i
].cmd
, ' ""')
2092 WriteLn(f
, commands
[i
].cmd
, ' ', QuoteStr(PAnsiString(commands
[i
].ptr
)^))
2097 WriteLn(f
, 'r_maxfps ', gMaxFPS
);
2098 WriteLn(f
, 'r_reset');
2102 procedure g_Console_WriteGameConfig
;
2105 if gParsingBinds
= false then
2107 s
:= e_GetWriteableDir(ConfigDirs
);
2108 g_Console_WriteConfig(e_CatPath(s
, gConfigScript
))
2115 conRegVar('d_eres', @debug_e_res
, '', '');
2116 for i
:= 1 to e_MaxJoys
do
2117 conRegVar('joy' + IntToStr(i
) + '_deadzone', @e_JoystickDeadzones
[i
- 1], '', '')