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
;
104 g_gui
, g_menu
, g_touch
,
106 g_textures
, e_input
, g_game
, g_gfx
, g_player
, g_items
,
107 SysUtils
, g_basic
, g_options
, Math
, e_res
,
108 g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
111 configComment
= 'generated by doom2d, do not modify';
114 PCommand
= ^TCommand
;
116 TCmdProc
= procedure (p
: SSArray
);
117 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
125 ptr
: Pointer; // various data
126 msg
: AnsiString; // message for var changes
128 action
: Integer; // >= 0 for action commands
129 player
: Integer; // used for action commands
140 MaxScriptRecursion
= 16;
143 RecursionDepth
: Word = 0;
144 RecursionLimitHit
: Boolean = False;
145 InputReady
: Boolean; // allow text input in console/chat
146 //ConsoleHistory: SSArray;
147 CommandHistory
: SSArray
;
149 commands
: Array of TCommand
= nil;
150 Aliases
: Array of TAlias
= nil;
153 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
157 menu_toggled
: BOOLEAN; (* hack for menu controls *)
159 procedure g_Console_Switch
;
162 gConsoleShow
:= not gConsoleShow
;
165 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
169 procedure g_Console_Chat_Switch (Team
: Boolean = False);
171 if not g_Game_IsNet
then Exit
;
172 gConsoleShow
:= False;
173 gChatShow
:= not gChatShow
;
179 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
183 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
184 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
193 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
194 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
195 if (pos
> slen
) then exit
;
196 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
198 while (pos
<= slen
) do
200 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
201 res
:= res
*10+Byte(s
[pos
])-48;
204 if (pos
<= slen
) then
207 if (s
[pos
] <> '.') then exit
;
209 while (pos
<= slen
) do
211 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
213 res
+= frac
*(Byte(s
[pos
])-48);
217 if (pos
<= slen
) then exit
; // oops
222 // ////////////////////////////////////////////////////////////////////////// //
223 // <0: no arg; 0/1: true/false; 666: toggle
224 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
226 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
228 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
229 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
230 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
231 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
235 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
236 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
240 if (Length(p
) > 2) then
242 conwritefln('too many arguments to ''%s''', [p
[0]]);
247 case conGetBoolArg(p
, 1) of
249 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
250 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
251 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
254 g_Console_WriteGameConfig();
255 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
256 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
260 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
264 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
268 if (Length(p
) <> 2) then
270 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
275 old
:= PInteger(me
.ptr
)^;
276 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
277 if PInteger(me
.ptr
)^ <> old
then
278 g_Console_WriteGameConfig();
280 conwritefln('invalid integer value: "%s"', [p
[1]]);
286 procedure wordVarHandler (me
: PCommand
; p
: SSArray
);
290 if (Length(p
) <> 2) then
292 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
297 old
:= PWord(me
.ptr
)^;
298 PWord(me
.ptr
)^ := min($FFFF, StrToDWord(p
[1]));
299 if PWord(me
.ptr
)^ <> old
then
300 g_Console_WriteGameConfig();
302 conwritefln('invalid word value: "%s"', [p
[1]]);
308 procedure dwordVarHandler (me
: PCommand
; p
: SSArray
);
312 if (Length(p
) <> 2) then
314 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
319 old
:= PCardinal(me
.ptr
)^;
320 PCardinal(me
.ptr
)^ := StrToDWord(p
[1]);
321 if PCardinal(me
.ptr
)^ <> old
then
322 g_Console_WriteGameConfig();
324 conwritefln('invalid dword value: "%s"', [p
[1]]);
330 procedure strVarHandler (me
: PCommand
; p
: SSArray
);
334 if (Length(p
) <> 2) then
336 conwritefln('%s %s', [me
.cmd
, QuoteStr(PAnsiString(me
.ptr
)^)]);
340 old
:= PAnsiString(me
.ptr
)^;
341 PAnsiString(me
.ptr
)^ := p
[1];
342 if PAnsiString(me
.ptr
)^ <> old
then
343 g_Console_WriteGameConfig();
348 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
353 f
:= Length(commands
);
354 SetLength(commands
, f
+1);
356 cp
.cmd
:= LowerCase(conname
);
358 cp
.procEx
:= boolVarHandler
;
360 cp
.hidden
:= ahidden
;
369 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
374 f
:= Length(commands
);
375 SetLength(commands
, f
+1);
377 cp
.cmd
:= LowerCase(conname
);
379 cp
.procEx
:= intVarHandler
;
381 cp
.hidden
:= ahidden
;
390 procedure conRegVar (const conname
: AnsiString; pvar
: PWord; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
395 f
:= Length(commands
);
396 SetLength(commands
, f
+1);
398 cp
.cmd
:= LowerCase(conname
);
400 cp
.procEx
:= wordVarHandler
;
402 cp
.hidden
:= ahidden
;
411 procedure conRegVar (const conname
: AnsiString; pvar
: PCardinal; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
416 f
:= Length(commands
);
417 SetLength(commands
, f
+1);
419 cp
.cmd
:= LowerCase(conname
);
421 cp
.procEx
:= dwordVarHandler
;
423 cp
.hidden
:= ahidden
;
432 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
437 f
:= Length(commands
);
438 SetLength(commands
, f
+1);
440 cp
.cmd
:= LowerCase(conname
);
442 cp
.procEx
:= strVarHandler
;
444 cp
.hidden
:= ahidden
;
452 // ////////////////////////////////////////////////////////////////////////// //
454 PVarSingle
= ^TVarSingle
;
457 min
, max
, def
: Single; // default will be starting value
461 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
467 if (Length(p
) > 2) then
469 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
472 pv
:= PVarSingle(me
.ptr
);
474 if (Length(p
) = 2) then
476 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
477 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
478 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
479 (CompareText(p
[1], 'ona') = 0) then
485 if not conParseFloat(nv
, p
[1]) then
487 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
490 if (nv
< pv
.min
) then nv
:= pv
.min
;
491 if (nv
> pv
.max
) then nv
:= pv
.max
;
495 if pv
.val
^ <> old
then
496 g_Console_WriteGameConfig();
498 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
499 conwritefln('%s %s', [msg
, pv
.val
^]);
503 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
509 GetMem(pv
, sizeof(TVarSingle
));
514 f
:= Length(commands
);
515 SetLength(commands
, f
+1);
517 cp
.cmd
:= LowerCase(conname
);
519 cp
.procEx
:= singleVarHandler
;
521 cp
.hidden
:= ahidden
;
530 // ////////////////////////////////////////////////////////////////////////// //
531 function GetStrACmd(var Str
: AnsiString): AnsiString;
536 for a
:= 1 to Length(Str
) do
537 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
539 Result
:= Copy(Str
, 1, a
);
546 function ParseAlias(Str
: AnsiString): SSArray
;
557 SetLength(Result
, Length(Result
)+1);
558 Result
[High(Result
)] := GetStrACmd(Str
);
562 procedure ConsoleCommands(p
: SSArray
);
568 cmd
:= LowerCase(p
[0]);
571 if cmd
= 'clear' then
573 //ConsoleHistory := nil;
577 for a
:= 0 to High(MsgArray
) do
585 if cmd
= 'clearhistory' then
586 CommandHistory
:= nil;
588 if cmd
= 'showhistory' then
589 if CommandHistory
<> nil then
592 for a
:= 0 to High(CommandHistory
) do
593 g_Console_Add(' '+CommandHistory
[a
]);
596 if cmd
= 'commands' then
599 g_Console_Add('commands list:');
600 for a
:= High(commands
) downto 0 do
602 if (Length(commands
[a
].help
) > 0) then
604 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
608 g_Console_Add(' '+commands
[a
].cmd
);
614 g_Console_Add(TimeToStr(Now
), True);
617 g_Console_Add(DateToStr(Now
), True);
620 if Length(p
) > 1 then
622 if p
[1] = 'ololo' then
627 for a
:= 1 to High(p
) do
629 g_Console_Add(b_Text_Format(s
), True);
638 if ConsoleHistory <> nil then
640 if Length(P) > 1 then
643 s := GameDir+'/console.txt';
648 if IOResult <> 0 then
650 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
655 for a := 0 to High(ConsoleHistory) do
656 WriteLn(F, ConsoleHistory[a]);
659 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
668 if Length(p
) = 2 then
669 g_Console_ReadConfig(p
[1])
671 g_Console_Add('exec <script file>');
674 if cmd
= 'writeconfig' then
676 // writeconfig <filename>
677 if Length(p
) = 2 then
679 s
:= e_GetWriteableDir(ConfigDirs
);
680 g_Console_WriteConfig(e_CatPath(s
, p
[1]))
684 g_Console_Add('writeconfig <file>')
688 if (cmd
= 'ver') or (cmd
= 'version') then
690 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
691 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
692 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
695 if cmd
= 'alias' then
697 // alias [alias_name] [commands]
698 if Length(p
) > 1 then
700 for a
:= 0 to High(Aliases
) do
701 if Aliases
[a
].name
= p
[1] then
703 if Length(p
) > 2 then
704 Aliases
[a
].commands
:= ParseAlias(p
[2])
706 for b
:= 0 to High(Aliases
[a
].commands
) do
707 g_Console_Add(Aliases
[a
].commands
[b
]);
710 SetLength(Aliases
, Length(Aliases
)+1);
712 Aliases
[a
].name
:= p
[1];
713 if Length(p
) > 2 then
714 Aliases
[a
].commands
:= ParseAlias(p
[2])
716 for b
:= 0 to High(Aliases
[a
].commands
) do
717 g_Console_Add(Aliases
[a
].commands
[b
]);
719 for a
:= 0 to High(Aliases
) do
720 if Aliases
[a
].commands
<> nil then
721 g_Console_Add(Aliases
[a
].name
);
727 if Length(p
) > 1 then
729 if Aliases
= nil then
731 for a
:= 0 to High(Aliases
) do
732 if Aliases
[a
].name
= p
[1] then
734 if Aliases
[a
].commands
<> nil then
736 // with this system proper endless loop detection seems either impossible
737 // or very dirty to implement, so let's have this instead
738 // prevents endless loops
739 for b
:= 0 to High(Aliases
[a
].commands
) do
742 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
743 if not RecursionLimitHit
then
744 g_Console_Process(Aliases
[a
].commands
[b
], True);
747 if (RecursionDepth
= 0) and RecursionLimitHit
then
749 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
750 RecursionLimitHit
:= False;
757 g_Console_Add('call <alias name>');
761 procedure WhitelistCommand(cmd
: AnsiString);
765 SetLength(Whitelist
, Length(Whitelist
)+1);
766 a
:= High(Whitelist
);
767 Whitelist
[a
] := LowerCase(cmd
);
770 procedure segfault (p
: SSArray
);
777 function GetCommandString (p
: SSArray
): AnsiString;
781 if Length(p
) >= 1 then
784 for i
:= 1 to High(p
) do
785 result
:= result
+ '; ' + p
[i
]
789 function QuoteStr(str
: String): String;
791 if Pos(' ', str
) > 0 then
792 Result
:= '"' + str
+ '"'
797 procedure BindCommands (p
: SSArray
);
798 var cmd
, key
: AnsiString; i
: Integer;
800 cmd
:= LowerCase(p
[0]);
803 // bind <key> [down [up]]
804 if (Length(p
) >= 2) and (Length(p
) <= 4) then
807 key
:= LowerCase(p
[1]);
808 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
809 if i
< e_MaxInputKeys
then
811 if Length(p
) = 2 then
812 g_Console_Add(QuoteStr(e_KeyNames
[i
]) + ' = ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)))
813 else if Length(p
) = 3 then
814 g_Console_BindKey(i
, p
[2], '')
816 g_Console_BindKey(i
, p
[2], p
[3])
819 g_Console_Add('bind: "' + p
[1] + '" is not a key')
823 g_Console_Add('bind <key> <down action> [up action]')
827 if Length(p
) = 2 then
829 key
:= LowerCase(p
[1]);
831 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
832 if i
< e_MaxInputKeys
then
833 gInputBinds
[i
].rep
:= True
835 g_Console_Add('bindrep: "' + p
[1] + '" is not a key')
838 g_Console_Add('bindrep <key>');
841 if Length(p
) = 2 then
843 key
:= LowerCase(p
[1]);
845 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
846 if i
< e_MaxInputKeys
then
847 gInputBinds
[i
].rep
:= False
849 g_Console_Add('bindunrep: "' + p
[1] + '" is not a key')
852 g_Console_Add('bindunrep <key>');
854 for i
:= 0 to e_MaxInputKeys
- 1 do
855 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
856 g_Console_Add(e_KeyNames
[i
] + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
859 if Length(p
) = 2 then
861 key
:= LowerCase(p
[1]);
863 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
864 if i
< e_MaxInputKeys
then
865 g_Console_BindKey(i
, '')
867 g_Console_Add('unbind: "' + p
[1] + '" is not a key')
870 g_Console_Add('unbind <key>');
872 for i
:= 0 to e_MaxInputKeys
- 1 do
873 g_Console_BindKey(i
, '');
876 g_Touch_ShowKeyboard(True);
878 g_Touch_ShowKeyboard(False);
884 else if gChatShow
then
885 g_Console_Chat_Switch
893 g_Console_Chat_Switch
;
895 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
896 g_Console_Chat_Switch(True);
900 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
905 SetLength(commands
, Length(commands
)+1);
908 cp
.cmd
:= LowerCase(cmd
);
912 cp
.hidden
:= ahidden
;
920 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
922 PrefixList
: array [0..1] of AnsiString = ('+', '-');
923 PlayerList
: array [0..1] of Integer = (1, 2);
928 procedure NewAction (cmd
: AnsiString; player
: Integer);
931 SetLength(commands
, Length(commands
) + 1);
932 cp
:= @commands
[High(commands
)];
933 cp
.cmd
:= LowerCase(cmd
);
946 ASSERT(action
>= FIRST_ACTION
);
947 ASSERT(action
<= LAST_ACTION
);
948 for s
in PrefixList
do
950 NewAction(s
+ cmd
, 0);
951 for i
in PlayerList
do
952 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
956 procedure g_Console_Initialize
;
959 gConsoleShow
:= False;
964 for a
:= 0 to High(MsgArray
) do
971 AddCommand('segfault', segfault
, 'make segfault');
973 AddCommand('quit', SystemCommands
);
974 AddCommand('exit', SystemCommands
);
975 AddCommand('r_reset', SystemCommands
);
976 AddCommand('r_maxfps', SystemCommands
);
977 AddCommand('g_language', SystemCommands
);
979 AddCommand('bind', BindCommands
);
980 AddCommand('bindrep', BindCommands
);
981 AddCommand('bindunrep', BindCommands
);
982 AddCommand('bindlist', BindCommands
);
983 AddCommand('unbind', BindCommands
);
984 AddCommand('unbindall', BindCommands
);
985 AddCommand('showkeyboard', BindCommands
);
986 AddCommand('hidekeyboard', BindCommands
);
987 AddCommand('togglemenu', BindCommands
);
988 AddCommand('toggleconsole', BindCommands
);
989 AddCommand('togglechat', BindCommands
);
990 AddCommand('toggleteamchat', BindCommands
);
992 AddCommand('clear', ConsoleCommands
, 'clear console');
993 AddCommand('clearhistory', ConsoleCommands
);
994 AddCommand('showhistory', ConsoleCommands
);
995 AddCommand('commands', ConsoleCommands
);
996 AddCommand('time', ConsoleCommands
);
997 AddCommand('date', ConsoleCommands
);
998 AddCommand('echo', ConsoleCommands
);
999 AddCommand('dump', ConsoleCommands
);
1000 AddCommand('exec', ConsoleCommands
);
1001 AddCommand('writeconfig', ConsoleCommands
);
1002 AddCommand('alias', ConsoleCommands
);
1003 AddCommand('call', ConsoleCommands
);
1004 AddCommand('ver', ConsoleCommands
);
1005 AddCommand('version', ConsoleCommands
);
1007 AddCommand('d_window', DebugCommands
);
1008 AddCommand('d_sounds', DebugCommands
);
1009 AddCommand('d_frames', DebugCommands
);
1010 AddCommand('d_winmsg', DebugCommands
);
1011 AddCommand('d_monoff', DebugCommands
);
1012 AddCommand('d_botoff', DebugCommands
);
1013 AddCommand('d_monster', DebugCommands
);
1014 AddCommand('d_health', DebugCommands
);
1015 AddCommand('d_player', DebugCommands
);
1016 AddCommand('d_joy', DebugCommands
);
1017 AddCommand('d_mem', DebugCommands
);
1019 AddCommand('p1_name', PlayerSettingsCVars
);
1020 AddCommand('p2_name', PlayerSettingsCVars
);
1021 AddCommand('p1_color', PlayerSettingsCVars
);
1022 AddCommand('p2_color', PlayerSettingsCVars
);
1023 AddCommand('p1_model', PlayerSettingsCVars
);
1024 AddCommand('p2_model', PlayerSettingsCVars
);
1025 AddCommand('p1_team', PlayerSettingsCVars
);
1026 AddCommand('p2_team', PlayerSettingsCVars
);
1028 AddCommand('g_max_particles', GameCVars
);
1029 AddCommand('g_max_shells', GameCVars
);
1030 AddCommand('g_max_gibs', GameCVars
);
1031 AddCommand('g_max_corpses', GameCVars
);
1032 AddCommand('g_gamemode', GameCVars
);
1033 AddCommand('g_friendlyfire', GameCVars
);
1034 AddCommand('g_friendly_hit_trace', GameCVars
);
1035 AddCommand('g_friendly_hit_projectile', GameCVars
);
1036 AddCommand('g_friendly_absorb_damage', GameCVars
);
1037 AddCommand('g_weaponstay', GameCVars
);
1038 AddCommand('g_allow_exit', GameCVars
);
1039 AddCommand('g_dm_keys', GameCVars
);
1040 AddCommand('g_allow_monsters', GameCVars
);
1041 AddCommand('g_bot_vsmonsters', GameCVars
);
1042 AddCommand('g_bot_vsplayers', GameCVars
);
1043 AddCommand('g_scorelimit', GameCVars
);
1044 AddCommand('g_timelimit', GameCVars
);
1045 AddCommand('g_maxlives', GameCVars
);
1046 AddCommand('g_warmup_time', GameCVars
);
1047 AddCommand('g_spawn_invul', GameCVars
);
1048 AddCommand('g_item_respawn_time', GameCVars
);
1049 AddCommand('sv_intertime', GameCVars
);
1051 AddCommand('sv_name', NetServerCVars
);
1052 AddCommand('sv_passwd', NetServerCVars
);
1053 AddCommand('sv_maxplrs', NetServerCVars
);
1054 AddCommand('sv_public', NetServerCVars
);
1055 AddCommand('sv_port', NetServerCVars
);
1057 AddCommand('pause', GameCommands
);
1058 AddCommand('endgame', GameCommands
);
1059 AddCommand('restart', GameCommands
);
1060 AddCommand('addbot', GameCommands
);
1061 AddCommand('bot_add', GameCommands
);
1062 AddCommand('bot_addlist', GameCommands
);
1063 AddCommand('bot_addred', GameCommands
);
1064 AddCommand('bot_addblue', GameCommands
);
1065 AddCommand('bot_removeall', GameCommands
);
1066 AddCommand('chat', GameCommands
);
1067 AddCommand('teamchat', GameCommands
);
1068 AddCommand('game', GameCommands
);
1069 AddCommand('host', GameCommands
);
1070 AddCommand('map', GameCommands
);
1071 AddCommand('nextmap', GameCommands
);
1072 AddCommand('endmap', GameCommands
);
1073 AddCommand('goodbye', GameCommands
);
1074 AddCommand('suicide', GameCommands
);
1075 AddCommand('spectate', GameCommands
);
1076 AddCommand('ready', GameCommands
);
1077 AddCommand('kick', GameCommands
);
1078 AddCommand('kick_id', GameCommands
);
1079 AddCommand('kick_pid', GameCommands
);
1080 AddCommand('ban', GameCommands
);
1081 AddCommand('ban_id', GameCommands
);
1082 AddCommand('ban_pid', GameCommands
);
1083 AddCommand('permban', GameCommands
);
1084 AddCommand('permban_id', GameCommands
);
1085 AddCommand('permban_pid', GameCommands
);
1086 AddCommand('permban_ip', GameCommands
);
1087 AddCommand('unban', GameCommands
);
1088 AddCommand('connect', GameCommands
);
1089 AddCommand('disconnect', GameCommands
);
1090 AddCommand('reconnect', GameCommands
);
1091 AddCommand('say', GameCommands
);
1092 AddCommand('tell', GameCommands
);
1093 AddCommand('centerprint', GameCommands
);
1094 AddCommand('overtime', GameCommands
);
1095 AddCommand('rcon_password', GameCommands
);
1096 AddCommand('rcon', GameCommands
);
1097 AddCommand('callvote', GameCommands
);
1098 AddCommand('vote', GameCommands
);
1099 AddCommand('clientlist', GameCommands
);
1100 AddCommand('event', GameCommands
);
1101 AddCommand('screenshot', GameCommands
);
1102 AddCommand('weapon', GameCommands
);
1103 AddCommand('p1_weapon', GameCommands
);
1104 AddCommand('p2_weapon', GameCommands
);
1106 AddCommand('god', GameCheats
);
1107 AddCommand('notarget', GameCheats
);
1108 AddCommand('give', GameCheats
); // "exit" too ;-)
1109 AddCommand('open', GameCheats
);
1110 AddCommand('fly', GameCheats
);
1111 AddCommand('noclip', GameCheats
);
1112 AddCommand('speedy', GameCheats
);
1113 AddCommand('jumpy', GameCheats
);
1114 AddCommand('noreload', GameCheats
);
1115 AddCommand('aimline', GameCheats
);
1116 AddCommand('automap', GameCheats
);
1118 AddAction('jump', ACTION_JUMP
);
1119 AddAction('moveleft', ACTION_MOVELEFT
);
1120 AddAction('moveright', ACTION_MOVERIGHT
);
1121 AddAction('lookup', ACTION_LOOKUP
);
1122 AddAction('lookdown', ACTION_LOOKDOWN
);
1123 AddAction('attack', ACTION_ATTACK
);
1124 AddAction('scores', ACTION_SCORES
);
1125 AddAction('activate', ACTION_ACTIVATE
);
1126 AddAction('strafe', ACTION_STRAFE
);
1127 AddAction('weapnext', ACTION_WEAPNEXT
);
1128 AddAction('weapprev', ACTION_WEAPPREV
);
1130 WhitelistCommand('say');
1131 WhitelistCommand('tell');
1132 WhitelistCommand('overtime');
1133 WhitelistCommand('ready');
1134 WhitelistCommand('map');
1135 WhitelistCommand('nextmap');
1136 WhitelistCommand('endmap');
1137 WhitelistCommand('restart');
1138 WhitelistCommand('kick');
1139 WhitelistCommand('kick_pid');
1140 WhitelistCommand('ban');
1141 WhitelistCommand('ban_pid');
1142 WhitelistCommand('centerprint');
1144 WhitelistCommand('addbot');
1145 WhitelistCommand('bot_add');
1146 WhitelistCommand('bot_addred');
1147 WhitelistCommand('bot_addblue');
1148 WhitelistCommand('bot_removeall');
1150 WhitelistCommand('g_gamemode');
1151 WhitelistCommand('g_friendlyfire');
1152 WhitelistCommand('g_friendly_hit_trace');
1153 WhitelistCommand('g_friendly_hit_projectile');
1154 WhitelistCommand('g_friendly_absorb_damage');
1155 WhitelistCommand('g_weaponstay');
1156 WhitelistCommand('g_allow_exit');
1157 WhitelistCommand('g_dm_keys');
1158 WhitelistCommand('g_allow_monsters');
1159 WhitelistCommand('g_bot_vsmonsters');
1160 WhitelistCommand('g_bot_vsplayers');
1161 WhitelistCommand('g_scorelimit');
1162 WhitelistCommand('g_timelimit');
1163 WhitelistCommand('g_maxlives');
1164 WhitelistCommand('g_warmup_time');
1165 WhitelistCommand('g_spawn_invul');
1166 WhitelistCommand('g_item_respawn_time');
1168 g_Console_ResetBinds
;
1169 g_Console_ReadConfig(gConfigScript
);
1170 // g_Console_ReadConfig(autoexecScript);
1171 g_Console_ReadConfig('autoexec.cfg');
1173 gParsingBinds
:= False;
1176 procedure g_Console_Finalize
;
1181 procedure g_Console_Init
;
1183 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
1187 procedure g_Console_Update
;
1191 InputReady
:= gConsoleShow
or gChatShow
;
1194 while a
<= High(MsgArray
) do
1196 if MsgArray
[a
].Time
> 0 then
1198 if MsgArray
[a
].Time
= 1 then
1200 if a
< High(MsgArray
) then
1202 for b
:= a
to High(MsgArray
)-1 do
1203 MsgArray
[b
] := MsgArray
[b
+1];
1205 MsgArray
[High(MsgArray
)].Time
:= 0;
1211 Dec(MsgArray
[a
].Time
);
1218 procedure g_Console_Char(C
: AnsiChar);
1220 if InputReady
and (gConsoleShow
or gChatShow
) then
1222 Insert(C
, Line
, CPos
);
1229 tcomplist
: array of AnsiString = nil;
1230 tcompidx
: array of Integer = nil;
1232 procedure Complete ();
1236 ll
, lpfx
, cmd
: AnsiString;
1238 if (Length(Line
) = 0) then
1241 for i
:= 0 to High(commands
) do
1243 // hidden commands are hidden when cheats aren't enabled
1244 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1245 if (Length(commands
[i
].help
) > 0) then
1247 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1251 g_Console_Add(' '+commands
[i
].cmd
);
1257 ll
:= LowerCase(Line
);
1260 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1262 ll
:= Copy(ll
, 0, Length(ll
)-1);
1263 for i
:= 0 to High(commands
) do
1265 // hidden commands are hidden when cheats aren't enabled
1266 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1267 if (commands
[i
].cmd
= ll
) then
1269 if (Length(commands
[i
].help
) > 0) then
1271 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1278 // build completion list
1280 for i
:= 0 to High(commands
) do
1282 // hidden commands are hidden when cheats aren't enabled
1283 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1284 cmd
:= commands
[i
].cmd
;
1285 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1287 if (tused
= Length(tcomplist
)) then
1289 SetLength(tcomplist
, Length(tcomplist
)+128);
1290 SetLength(tcompidx
, Length(tcompidx
)+128);
1292 tcomplist
[tused
] := cmd
;
1293 tcompidx
[tused
] := i
;
1295 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1299 // get longest prefix
1300 for i
:= 0 to tused
-1 do
1302 cmd
:= tcomplist
[i
];
1303 for c
:= 1 to Length(lpfx
) do
1305 if (c
> Length(cmd
)) then break
;
1306 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1310 if (tused
= 0) then exit
;
1314 Line
:= tcomplist
[0]+' ';
1315 CPos
:= Length(Line
)+1;
1319 // has longest prefix?
1320 if (Length(lpfx
) > Length(ll
)) then
1323 CPos
:= Length(Line
)+1;
1328 for i
:= 0 to tused
-1 do
1330 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1332 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1336 g_Console_Add(' '+tcomplist
[i
]);
1344 procedure g_Console_Control(K
: Word);
1348 if (Length(Line
) > 0) and (CPos
> 1) then
1350 Delete(Line
, CPos
-1, 1);
1354 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1355 Delete(Line
, CPos
, 1);
1356 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1359 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1360 if CPos
<= Length(Line
) then
1362 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1364 if gConsoleShow
then
1365 g_Console_Process(Line
)
1369 if (Length(Line
) > 0) and g_Game_IsNet
then
1373 if g_Game_IsClient
then
1374 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1376 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1377 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1381 if g_Game_IsClient
then
1382 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1384 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1391 gJustChatted
:= True;
1392 g_Console_Chat_Switch
;
1393 InputReady
:= False;
1397 if not gChatShow
then
1399 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1400 if not gChatShow
then
1401 if (CommandHistory
<> nil) and
1402 (CmdIndex
< Length(CommandHistory
)) then
1404 if CmdIndex
< Length(CommandHistory
)-1 then
1405 CmdIndex
:= CmdIndex
+ 1;
1406 Line
:= CommandHistory
[CmdIndex
];
1407 CPos
:= Length(Line
) + 1;
1409 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1410 if not gChatShow
then
1411 if (CommandHistory
<> nil) and
1412 (CmdIndex
<= Length(CommandHistory
)) then
1414 if CmdIndex
> 0 then
1415 CmdIndex
:= CmdIndex
- 1;
1416 Line
:= CommandHistory
[CmdIndex
];
1417 Cpos
:= Length(Line
) + 1;
1419 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1420 if not gChatShow
then Inc(conSkipLines
);
1421 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1422 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1426 CPos
:= Length(Line
) + 1;
1427 IK_A
..IK_Z
, IK_SPACE
, IK_SHIFT
, IK_RSHIFT
, IK_CAPSLOCK
, IK_LBRACKET
, IK_RBRACKET
,
1428 IK_SEMICOLON
, IK_QUOTE
, IK_BACKSLASH
, IK_SLASH
, IK_COMMA
, IK_DOT
, (*IK_EQUALS,*)
1429 IK_0
, IK_1
, IK_2
, IK_3
, IK_4
, IK_5
, IK_6
, IK_7
, IK_8
, IK_9
, IK_MINUS
, IK_EQUALS
:
1430 (* see TEXTINPUT event *)
1434 function GetStr(var Str
: AnsiString): AnsiString;
1439 if Str
[1] = '"' then
1441 for b
:= 1 to Length(Str
) do
1442 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1444 Result
:= Copy(Str
, 2, b
-1);
1445 Delete(Str
, 1, b
+1);
1451 for a
:= 1 to Length(Str
) do
1452 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1454 Result
:= Copy(Str
, 1, a
);
1455 Delete(Str
, 1, a
+1);
1461 function ParseString(Str
: AnsiString): SSArray
;
1472 SetLength(Result
, Length(Result
)+1);
1473 Result
[High(Result
)] := GetStr(Str
);
1477 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1479 procedure conmsg (s
: AnsiString);
1483 if length(s
) = 0 then exit
;
1484 for a
:= 0 to High(MsgArray
) do
1496 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1497 with MsgArray
[High(MsgArray
)] do
1507 // put it to console
1509 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1511 // now show 'em out of console too
1512 show
:= show
and gAllowConsoleMessages
;
1513 if show
and gShowMessages
then
1515 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1516 while length(L
) > 0 do
1519 if f
<= 0 then f
:= length(L
)+1;
1520 conmsg(Copy(L
, 1, f
-1));
1525 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1526 //ConsoleHistory[High(ConsoleHistory)] := L;
1530 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1537 consolewriterLastWasEOL
: Boolean = false;
1539 procedure consolewriter (constref buf
; len
: SizeUInt
);
1543 if (len
< 1) then exit
;
1545 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1548 if (b
[0] <> 13) and (b
[0] <> 10) then
1550 cbufPut(AnsiChar(b
[0]));
1554 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1563 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1564 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1565 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1566 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1568 g_Console_Add(s
, show
);
1572 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1576 g_Console_Add(formatstrf(s
, args
), true);
1580 consolewriterLastWasEOL
:= false;
1581 formatstrf(s
, args
, consolewriter
);
1582 if not consolewriterLastWasEOL
then cbufPut(#10);
1587 procedure g_Console_Clear();
1589 //ConsoleHistory := nil;
1594 procedure AddToHistory(L
: AnsiString);
1598 len
:= Length(CommandHistory
);
1601 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1603 SetLength(CommandHistory
, len
+1);
1604 CommandHistory
[len
] := L
;
1607 CmdIndex
:= Length(CommandHistory
);
1610 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1619 if Trim(C
) = '' then
1622 Arr
:= ParseString(C
);
1626 for i
:= 0 to High(Whitelist
) do
1627 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1631 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1638 if Trim(L
) = '' then
1641 conSkipLines
:= 0; // "unscroll"
1643 if L
= 'goobers' then
1648 g_Console_Add('Your memory serves you well.');
1654 g_Console_Add('> '+L
);
1659 Arr
:= ParseString(L
);
1663 if commands
= nil then
1669 for i
:= 0 to High(commands
) do
1671 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1673 if commands
[i
].action
>= 0 then
1675 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1678 if assigned(commands
[i
].procEx
) then
1680 commands
[i
].procEx(@commands
[i
], Arr
);
1683 if assigned(commands
[i
].proc
) then
1685 commands
[i
].proc(Arr
);
1691 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1695 function g_Console_Interactive
: Boolean;
1697 Result
:= gConsoleShow
1700 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1702 // e_LogWritefln('bind "%s" "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), down, up, key]);
1704 ASSERT(key
< e_MaxInputKeys
);
1707 gInputBinds
[key
].rep
:= False;
1708 gInputBinds
[key
].down
:= ParseAlias(down
);
1709 gInputBinds
[key
].up
:= ParseAlias(up
);
1711 g_Console_WriteGameConfig();
1714 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
1716 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1717 var i
, len
: Integer;
1721 if len
= Length(b
) then
1724 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1732 ASSERT(key
< e_MaxInputKeys
);
1733 result
:= EqualsCommandLists(ParseAlias(down
), gInputBinds
[key
].down
) and EqualsCommandLists(ParseAlias(up
), gInputBinds
[key
].up
)
1736 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1741 if commands
= nil then Exit
;
1743 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1745 if g_Console_MatchBind(i
, down
, up
) then
1756 function g_Console_Action (action
: Integer): Boolean;
1757 var i
, len
: Integer;
1759 ASSERT(action
>= FIRST_ACTION
);
1760 ASSERT(action
<= LAST_ACTION
);
1762 len
:= Length(gPlayerAction
);
1763 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1767 function BindsAllowed (key
: Integer): Boolean;
1768 var grab
, active
: Boolean;
1775 grab
:= g_GUIGrabInput
;
1776 active
:= g_ActiveWindow
<> nil;
1778 if (not grab
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1781 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1782 g_Console_MatchBind(key
, 'showkeyboard') or
1783 g_Console_MatchBind(key
, 'hidekeyboard')
1784 else if gConsoleShow
or active
or (gGameSettings
.GameType
= GT_NONE
) then
1785 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1786 g_Console_MatchBind(key
, 'toggleconsole') or
1787 g_Console_MatchBind(key
, 'showkeyboard') or
1788 g_Console_MatchBind(key
, 'hidekeyboard')
1794 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1797 if BindsAllowed(key
) then
1800 for i
:= 0 to High(gInputBinds
[key
].down
) do
1801 g_Console_Process(gInputBinds
[key
].down
[i
], True)
1803 for i
:= 0 to High(gInputBinds
[key
].up
) do
1804 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1806 if down
and not menu_toggled
then
1808 menu_toggled
:= False
1811 procedure g_Console_ProcessBindRepeat (key
: Integer);
1812 var i
: Integer; active
: Boolean;
1817 active
:= g_ActiveWindow
<> nil;
1819 if gConsoleShow
or gChatShow
or active
then
1821 KeyPress(key
); // key repeat in menus and shit
1824 if BindsAllowed(key
) and gInputBinds
[key
].rep
then
1826 for i
:= 0 to High(gInputBinds
[key
].down
) do
1827 g_Console_Process(gInputBinds
[key
].down
[i
], True);
1831 procedure g_Console_ResetBinds
;
1834 for i
:= 0 to e_MaxInputKeys
- 1 do
1835 g_Console_BindKey(i
, '', '');
1837 g_Console_BindKey(IK_GRAVE
, 'toggleconsole');
1838 g_Console_BindKey(IK_ESCAPE
, 'togglemenu');
1839 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1840 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1841 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1842 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1843 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1844 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1845 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1846 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1847 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1848 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1849 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1850 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1851 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1852 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1853 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1854 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1855 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1856 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1857 g_Console_BindKey(IK_9
, 'p1_weapon 9');
1858 g_Console_BindKey(IK_0
, 'p1_weapon 10');
1859 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
1860 g_Console_BindKey(IK_T
, 'togglechat');
1861 g_Console_BindKey(IK_Y
, 'toggleteamchat');
1862 g_Console_BindKey(IK_F11
, 'screenshot');
1863 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
1864 g_Console_BindKey(IK_PAUSE
, 'pause');
1865 g_Console_BindKey(IK_F1
, 'vote');
1867 (* for i := 0 to e_MaxJoys - 1 do *)
1870 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_LEFT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
1871 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_RIGHT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
1872 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_UP
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
1873 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_DOWN
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
1874 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
1875 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
1876 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
1877 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
1878 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
1879 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
1880 g_Console_BindKey(e_JoyButtonToKey(i
, 10), 'togglemenu');
1883 g_Console_BindKey(VK_ESCAPE
, 'togglemenu');
1884 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
1885 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
1886 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
1887 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
1888 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
1889 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
1890 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
1891 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
1892 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
1893 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
1894 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
1895 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
1896 g_Console_BindKey(VK_0
, 'weapon 1');
1897 g_Console_BindKey(VK_1
, 'weapon 2');
1898 g_Console_BindKey(VK_2
, 'weapon 3');
1899 g_Console_BindKey(VK_3
, 'weapon 4');
1900 g_Console_BindKey(VK_4
, 'weapon 5');
1901 g_Console_BindKey(VK_5
, 'weapon 6');
1902 g_Console_BindKey(VK_6
, 'weapon 7');
1903 g_Console_BindKey(VK_7
, 'weapon 8');
1904 g_Console_BindKey(VK_8
, 'weapon 9');
1905 g_Console_BindKey(VK_9
, 'weapon 10');
1906 g_Console_BindKey(VK_A
, 'weapon 11');
1907 g_Console_BindKey(VK_CHAT
, 'togglechat');
1908 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
1909 g_Console_BindKey(VK_CONSOLE
, 'toggleconsole');
1910 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
1911 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
1912 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
1913 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
1916 procedure g_Console_ReadConfig (filename
: String);
1917 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1919 e_LogWritefln('g_Console_ReadConfig (1) "%s"', [filename
]);
1920 if e_FindResource(ConfigDirs
, filename
, false) = true then
1922 e_LogWritefln('g_Console_ReadConfig (2) "%s"', [filename
]);
1923 AssignFile(f
, filename
);
1933 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1935 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1936 g_Console_Process(s
, True);
1943 procedure g_Console_WriteConfig (filename
: String);
1944 var f
: TextFile
; i
, j
: Integer;
1946 procedure WriteFlag(name
: string; flag
: LongWord);
1948 WriteLn(f
, name
, IfThen(LongBool(gsGameFlags
and flag
), 1, 0));
1951 function FormatTeam(team
: Byte): string;
1953 if team
= TEAM_BLUE
then
1960 // e_LogWritefln('g_Console_WriteConfig: %s', [filename]);
1961 AssignFile(f
, filename
);
1963 WriteLn(f
, '// ' + configComment
);
1966 WriteLn(f
, 'unbindall');
1967 for i
:= 0 to e_MaxInputKeys
- 1 do
1968 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
1970 Write(f
, 'bind ', e_KeyNames
[i
], ' ', QuoteStr(GetCommandString(gInputBinds
[i
].down
)));
1971 if Length(gInputBinds
[i
].down
) = 0 then
1973 if Length(gInputBinds
[i
].up
) > 0 then
1974 Write(f
, ' ', QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
1976 if gInputBinds
[i
].rep
then
1977 WriteLn(f
, 'bindrep ', e_KeyNames
[i
]);
1981 if gAskLanguage
then
1982 WriteLn(f
, 'g_language ask')
1984 WriteLn(f
, 'g_language ', gLanguage
);
1987 WriteLn(f
, 'sv_name ', QuoteStr(NetServerName
));
1988 WriteLn(f
, 'sv_passwd ', QuoteStr(NetPassword
));
1989 WriteLn(f
, 'sv_maxplrs ', NetMaxClients
);
1990 WriteLn(f
, 'sv_port ', NetPort
);
1991 WriteLn(f
, 'sv_public ', IfThen(NetUseMaster
, 1, 0));
1994 WriteLn(f
, 'g_max_particles ', g_GFX_GetMax());
1995 WriteLn(f
, 'g_max_shells ', g_Shells_GetMax());
1996 WriteLn(f
, 'g_max_gibs ', g_Gibs_GetMax());
1997 WriteLn(f
, 'g_max_corpses ', g_Corpses_GetMax());
1998 WriteLn(f
, 'sv_intertime ', gDefInterTime
);
2000 // gameplay settings
2001 WriteLn(f
, 'g_gamemode ', gsGameMode
);
2002 WriteLn(f
, 'g_scorelimit ', gsGoalLimit
);
2003 WriteLn(f
, 'g_timelimit ', gsTimeLimit
);
2004 WriteLn(f
, 'g_maxlives ', gsMaxLives
);
2005 WriteLn(f
, 'g_item_respawn_time ', gsItemRespawnTime
);
2006 WriteLn(f
, 'g_spawn_invul ', gsSpawnInvul
);
2007 WriteLn(f
, 'g_warmup_time ', gsWarmupTime
);
2009 WriteFlag('g_friendlyfire ', GAME_OPTION_TEAMDAMAGE
);
2010 WriteFlag('g_friendly_hit_trace ', GAME_OPTION_TEAMHITTRACE
);
2011 WriteFlag('g_friendly_hit_projectile ', GAME_OPTION_TEAMHITPROJECTILE
);
2012 WriteFlag('g_allow_exit ', GAME_OPTION_ALLOWEXIT
);
2013 WriteFlag('g_allow_monsters ', GAME_OPTION_MONSTERS
);
2014 WriteFlag('g_dm_keys ', GAME_OPTION_DMKEYS
);
2015 WriteFlag('g_weaponstay ', GAME_OPTION_WEAPONSTAY
);
2016 WriteFlag('g_bot_vsmonsters ', GAME_OPTION_BOTVSMONSTER
);
2017 WriteFlag('g_bot_vsplayers ', GAME_OPTION_BOTVSPLAYER
);
2020 with gPlayer1Settings
do
2022 WriteLn(f
, 'p1_name ', QuoteStr(Name
));
2023 WriteLn(f
, 'p1_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2024 WriteLn(f
, 'p1_model ', QuoteStr(Model
));
2025 WriteLn(f
, 'p1_team ', FormatTeam(Team
));
2027 with gPlayer2Settings
do
2029 WriteLn(f
, 'p2_name ', QuoteStr(Name
));
2030 WriteLn(f
, 'p2_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2031 WriteLn(f
, 'p2_model ', QuoteStr(Model
));
2032 WriteLn(f
, 'p2_team ', FormatTeam(Team
));
2036 for i
:= 0 to High(commands
) do
2038 if not commands
[i
].cheat
then
2040 if @commands
[i
].procEx
= @boolVarHandler
then
2042 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
2043 WriteLn(f
, commands
[i
].cmd
, ' ', j
)
2045 else if @commands
[i
].procEx
= @intVarHandler
then
2047 WriteLn(f
, commands
[i
].cmd
, ' ', PInteger(commands
[i
].ptr
)^)
2049 else if @commands
[i
].procEx
= @wordVarHandler
then
2051 WriteLn(f
, commands
[i
].cmd
, ' ', PWord(commands
[i
].ptr
)^)
2053 else if @commands
[i
].procEx
= @dwordVarHandler
then
2055 WriteLn(f
, commands
[i
].cmd
, ' ', PCardinal(commands
[i
].ptr
)^)
2057 else if @commands
[i
].procEx
= @singleVarHandler
then
2059 WriteLn(f
, commands
[i
].cmd
, ' ', PVarSingle(commands
[i
].ptr
).val
^:0:6)
2061 else if @commands
[i
].procEx
= @strVarHandler
then
2063 if Length(PAnsiString(commands
[i
].ptr
)^) = 0 then
2064 WriteLn(f
, commands
[i
].cmd
, ' ""')
2066 WriteLn(f
, commands
[i
].cmd
, ' ', QuoteStr(PAnsiString(commands
[i
].ptr
)^))
2071 WriteLn(f
, 'r_maxfps ', gMaxFPS
);
2072 WriteLn(f
, 'r_reset');
2076 procedure g_Console_WriteGameConfig
;
2079 if gParsingBinds
= false then
2081 s
:= e_GetWriteableDir(ConfigDirs
);
2082 g_Console_WriteConfig(e_CatPath(s
, gConfigScript
))
2089 conRegVar('d_eres', @debug_e_res
, '', '');
2090 for i
:= 1 to e_MaxJoys
do
2091 conRegVar('joy' + IntToStr(i
) + '_deadzone', @e_JoystickDeadzones
[i
- 1], '', '')