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 procedure g_Console_Init
;
40 procedure g_Console_SysInit
;
41 procedure g_Console_Update
;
42 procedure g_Console_Draw (MessagesOnly
: Boolean = False);
43 procedure g_Console_Char (C
: AnsiChar);
44 procedure g_Console_Control (K
: Word);
45 procedure g_Console_Process (L
: AnsiString; quiet
: Boolean=false);
46 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
47 procedure g_Console_Clear
;
48 function g_Console_CommandBlacklisted (C
: AnsiString): Boolean;
49 procedure g_Console_ReadConfig (filename
: String);
50 procedure g_Console_WriteConfig (filename
: String);
51 procedure g_Console_WriteGameConfig
;
53 function g_Console_Interactive
: Boolean;
54 function g_Console_Action (action
: Integer): Boolean;
55 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
56 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
57 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
58 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
59 procedure g_Console_ProcessBindRepeat (key
: Integer);
60 procedure g_Console_ResetBinds
;
62 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
63 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
65 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
66 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
67 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
68 procedure conRegVar (const conname
: AnsiString; pvar
: PWord; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
69 procedure conRegVar (const conname
: AnsiString; pvar
: PCardinal; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
70 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
72 // <0: no arg; 0/1: true/false
73 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
75 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
76 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
79 defaultConfigScript
= 'dfconfig.cfg';
82 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
83 gChatShow
: Boolean = false;
84 gChatTeam
: Boolean = false;
85 gAllowConsoleMessages
: Boolean = true;
86 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
87 gParsingBinds
: Boolean = true; // íå ïåðåñîõðàíÿòü êîíôèã âî âðåìÿ ïàðñèíãà
88 gPlayerAction
: Array [0..1, 0..LAST_ACTION
] of Boolean; // [player, action]
89 gConfigScript
: string = defaultConfigScript
;
94 g_textures
, g_main
, e_graphics
, e_input
, g_game
, g_gfx
, g_player
, g_items
,
95 SysUtils
, g_basic
, g_options
, Math
, g_touch
, e_res
,
96 g_menu
, g_gui
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
99 autoexecScript
= 'autoexec.cfg';
100 configComment
= 'generated by doom2d, do not modify';
103 PCommand
= ^TCommand
;
105 TCmdProc
= procedure (p
: SSArray
);
106 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
114 ptr
: Pointer; // various data
115 msg
: AnsiString; // message for var changes
117 action
: Integer; // >= 0 for action commands
118 player
: Integer; // used for action commands
129 MaxScriptRecursion
= 16;
131 DEBUG_STRING
= 'DEBUG MODE';
135 RecursionDepth
: Word = 0;
136 RecursionLimitHit
: Boolean = False;
138 ConsoleHeight
: Single;
139 Cons_Shown
: Boolean; // draw console
140 InputReady
: Boolean; // allow text input in console/chat
143 //ConsoleHistory: SSArray;
144 CommandHistory
: SSArray
;
146 commands
: Array of TCommand
= nil;
147 Aliases
: Array of TAlias
= nil;
149 conSkipLines
: Integer = 0;
150 MsgArray
: Array [0..4] of record
155 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
159 menu_toggled
: BOOLEAN; (* hack for menu controls *)
162 ConsoleTrans
: Single;
165 procedure g_Console_Switch
;
167 Cons_Y
:= Min(0, Max(Cons_Y
, -Floor(gScreenHeight
* ConsoleHeight
)));
168 if Cons_Shown
= False then
169 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
171 gConsoleShow
:= not gConsoleShow
;
174 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
177 procedure g_Console_Chat_Switch (Team
: Boolean = False);
179 if not g_Game_IsNet
then Exit
;
180 Cons_Y
:= Min(0, Max(Cons_Y
, -Floor(gScreenHeight
* ConsoleHeight
)));
181 if Cons_Shown
= False then
182 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
183 gConsoleShow
:= False;
184 gChatShow
:= not gChatShow
;
190 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
193 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
194 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
203 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
204 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
205 if (pos
> slen
) then exit
;
206 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
208 while (pos
<= slen
) do
210 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
211 res
:= res
*10+Byte(s
[pos
])-48;
214 if (pos
<= slen
) then
217 if (s
[pos
] <> '.') then exit
;
219 while (pos
<= slen
) do
221 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
223 res
+= frac
*(Byte(s
[pos
])-48);
227 if (pos
<= slen
) then exit
; // oops
232 // ////////////////////////////////////////////////////////////////////////// //
233 // <0: no arg; 0/1: true/false; 666: toggle
234 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
236 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
238 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
239 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
240 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
241 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
245 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
246 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
250 if (Length(p
) > 2) then
252 conwritefln('too many arguments to ''%s''', [p
[0]]);
257 case conGetBoolArg(p
, 1) of
259 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
260 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
261 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
264 g_Console_WriteGameConfig();
265 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
266 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
270 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
274 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
278 if (Length(p
) <> 2) then
280 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
285 old
:= PInteger(me
.ptr
)^;
286 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
287 if PInteger(me
.ptr
)^ <> old
then
288 g_Console_WriteGameConfig();
290 conwritefln('invalid integer value: "%s"', [p
[1]]);
296 procedure wordVarHandler (me
: PCommand
; p
: SSArray
);
300 if (Length(p
) <> 2) then
302 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
307 old
:= PWord(me
.ptr
)^;
308 PWord(me
.ptr
)^ := min($FFFF, StrToDWord(p
[1]));
309 if PWord(me
.ptr
)^ <> old
then
310 g_Console_WriteGameConfig();
312 conwritefln('invalid word value: "%s"', [p
[1]]);
318 procedure dwordVarHandler (me
: PCommand
; p
: SSArray
);
322 if (Length(p
) <> 2) then
324 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
329 old
:= PCardinal(me
.ptr
)^;
330 PCardinal(me
.ptr
)^ := StrToDWord(p
[1]);
331 if PCardinal(me
.ptr
)^ <> old
then
332 g_Console_WriteGameConfig();
334 conwritefln('invalid dword value: "%s"', [p
[1]]);
340 procedure strVarHandler (me
: PCommand
; p
: SSArray
);
344 if (Length(p
) <> 2) then
346 conwritefln('%s %s', [me
.cmd
, QuoteStr(PAnsiString(me
.ptr
)^)]);
350 old
:= PAnsiString(me
.ptr
)^;
351 PAnsiString(me
.ptr
)^ := p
[1];
352 if PAnsiString(me
.ptr
)^ <> old
then
353 g_Console_WriteGameConfig();
358 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
363 f
:= Length(commands
);
364 SetLength(commands
, f
+1);
366 cp
.cmd
:= LowerCase(conname
);
368 cp
.procEx
:= boolVarHandler
;
370 cp
.hidden
:= ahidden
;
379 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
384 f
:= Length(commands
);
385 SetLength(commands
, f
+1);
387 cp
.cmd
:= LowerCase(conname
);
389 cp
.procEx
:= intVarHandler
;
391 cp
.hidden
:= ahidden
;
400 procedure conRegVar (const conname
: AnsiString; pvar
: PWord; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
405 f
:= Length(commands
);
406 SetLength(commands
, f
+1);
408 cp
.cmd
:= LowerCase(conname
);
410 cp
.procEx
:= wordVarHandler
;
412 cp
.hidden
:= ahidden
;
421 procedure conRegVar (const conname
: AnsiString; pvar
: PCardinal; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
426 f
:= Length(commands
);
427 SetLength(commands
, f
+1);
429 cp
.cmd
:= LowerCase(conname
);
431 cp
.procEx
:= dwordVarHandler
;
433 cp
.hidden
:= ahidden
;
442 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
447 f
:= Length(commands
);
448 SetLength(commands
, f
+1);
450 cp
.cmd
:= LowerCase(conname
);
452 cp
.procEx
:= strVarHandler
;
454 cp
.hidden
:= ahidden
;
462 // ////////////////////////////////////////////////////////////////////////// //
464 PVarSingle
= ^TVarSingle
;
467 min
, max
, def
: Single; // default will be starting value
471 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
477 if (Length(p
) > 2) then
479 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
482 pv
:= PVarSingle(me
.ptr
);
484 if (Length(p
) = 2) then
486 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
487 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
488 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
489 (CompareText(p
[1], 'ona') = 0) then
495 if not conParseFloat(nv
, p
[1]) then
497 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
500 if (nv
< pv
.min
) then nv
:= pv
.min
;
501 if (nv
> pv
.max
) then nv
:= pv
.max
;
505 if pv
.val
^ <> old
then
506 g_Console_WriteGameConfig();
508 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
509 conwritefln('%s %s', [msg
, pv
.val
^]);
513 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
519 GetMem(pv
, sizeof(TVarSingle
));
524 f
:= Length(commands
);
525 SetLength(commands
, f
+1);
527 cp
.cmd
:= LowerCase(conname
);
529 cp
.procEx
:= singleVarHandler
;
531 cp
.hidden
:= ahidden
;
540 // ////////////////////////////////////////////////////////////////////////// //
541 function GetStrACmd(var Str
: AnsiString): AnsiString;
546 for a
:= 1 to Length(Str
) do
547 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
549 Result
:= Copy(Str
, 1, a
);
556 function ParseAlias(Str
: AnsiString): SSArray
;
567 SetLength(Result
, Length(Result
)+1);
568 Result
[High(Result
)] := GetStrACmd(Str
);
572 procedure ConsoleCommands(p
: SSArray
);
578 cmd
:= LowerCase(p
[0]);
581 if cmd
= 'clear' then
583 //ConsoleHistory := nil;
587 for a
:= 0 to High(MsgArray
) do
595 if cmd
= 'clearhistory' then
596 CommandHistory
:= nil;
598 if cmd
= 'showhistory' then
599 if CommandHistory
<> nil then
602 for a
:= 0 to High(CommandHistory
) do
603 g_Console_Add(' '+CommandHistory
[a
]);
606 if cmd
= 'commands' then
609 g_Console_Add('commands list:');
610 for a
:= High(commands
) downto 0 do
612 if (Length(commands
[a
].help
) > 0) then
614 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
618 g_Console_Add(' '+commands
[a
].cmd
);
624 g_Console_Add(TimeToStr(Now
), True);
627 g_Console_Add(DateToStr(Now
), True);
630 if Length(p
) > 1 then
632 if p
[1] = 'ololo' then
637 for a
:= 1 to High(p
) do
639 g_Console_Add(b_Text_Format(s
), True);
648 if ConsoleHistory <> nil then
650 if Length(P) > 1 then
653 s := GameDir+'/console.txt';
658 if IOResult <> 0 then
660 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
665 for a := 0 to High(ConsoleHistory) do
666 WriteLn(F, ConsoleHistory[a]);
669 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
678 if Length(p
) = 2 then
679 g_Console_ReadConfig(p
[1])
681 g_Console_Add('exec <script file>');
684 if cmd
= 'writeconfig' then
686 // writeconfig <filename>
687 if Length(p
) = 2 then
689 s
:= e_GetWriteableDir(ConfigDirs
);
690 g_Console_WriteConfig(e_CatPath(s
, p
[1]))
694 g_Console_Add('writeconfig <file>')
698 if (cmd
= 'ver') or (cmd
= 'version') then
700 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
701 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
702 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
705 if cmd
= 'alias' then
707 // alias [alias_name] [commands]
708 if Length(p
) > 1 then
710 for a
:= 0 to High(Aliases
) do
711 if Aliases
[a
].name
= p
[1] then
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
]);
720 SetLength(Aliases
, Length(Aliases
)+1);
722 Aliases
[a
].name
:= p
[1];
723 if Length(p
) > 2 then
724 Aliases
[a
].commands
:= ParseAlias(p
[2])
726 for b
:= 0 to High(Aliases
[a
].commands
) do
727 g_Console_Add(Aliases
[a
].commands
[b
]);
729 for a
:= 0 to High(Aliases
) do
730 if Aliases
[a
].commands
<> nil then
731 g_Console_Add(Aliases
[a
].name
);
737 if Length(p
) > 1 then
739 if Aliases
= nil then
741 for a
:= 0 to High(Aliases
) do
742 if Aliases
[a
].name
= p
[1] then
744 if Aliases
[a
].commands
<> nil then
746 // with this system proper endless loop detection seems either impossible
747 // or very dirty to implement, so let's have this instead
748 // prevents endless loops
749 for b
:= 0 to High(Aliases
[a
].commands
) do
752 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
753 if not RecursionLimitHit
then
754 g_Console_Process(Aliases
[a
].commands
[b
], True);
757 if (RecursionDepth
= 0) and RecursionLimitHit
then
759 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
760 RecursionLimitHit
:= False;
767 g_Console_Add('call <alias name>');
771 procedure WhitelistCommand(cmd
: AnsiString);
775 SetLength(Whitelist
, Length(Whitelist
)+1);
776 a
:= High(Whitelist
);
777 Whitelist
[a
] := LowerCase(cmd
);
780 procedure segfault (p
: SSArray
);
787 function GetCommandString (p
: SSArray
): AnsiString;
791 if Length(p
) >= 1 then
794 for i
:= 1 to High(p
) do
795 result
:= result
+ '; ' + p
[i
]
799 function QuoteStr(str
: String): String;
801 if Pos(' ', str
) > 0 then
802 Result
:= '"' + str
+ '"'
807 procedure BindCommands (p
: SSArray
);
808 var cmd
, key
: AnsiString; i
: Integer;
810 cmd
:= LowerCase(p
[0]);
813 // bind <key> [down [up]]
814 if (Length(p
) >= 2) and (Length(p
) <= 4) then
817 key
:= LowerCase(p
[1]);
818 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
819 if i
< e_MaxInputKeys
then
821 if Length(p
) = 2 then
822 g_Console_Add(QuoteStr(e_KeyNames
[i
]) + ' = ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)))
823 else if Length(p
) = 3 then
824 g_Console_BindKey(i
, p
[2], '')
826 g_Console_BindKey(i
, p
[2], p
[3])
829 g_Console_Add('bind: "' + p
[1] + '" is not a key')
833 g_Console_Add('bind <key> <down action> [up action]')
837 if Length(p
) = 2 then
839 key
:= LowerCase(p
[1]);
841 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
842 if i
< e_MaxInputKeys
then
843 gInputBinds
[i
].rep
:= True
845 g_Console_Add('bindrep: "' + p
[1] + '" is not a key')
848 g_Console_Add('bindrep <key>');
851 if Length(p
) = 2 then
853 key
:= LowerCase(p
[1]);
855 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
856 if i
< e_MaxInputKeys
then
857 gInputBinds
[i
].rep
:= False
859 g_Console_Add('bindunrep: "' + p
[1] + '" is not a key')
862 g_Console_Add('bindunrep <key>');
864 for i
:= 0 to e_MaxInputKeys
- 1 do
865 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
866 g_Console_Add(e_KeyNames
[i
] + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
869 if Length(p
) = 2 then
871 key
:= LowerCase(p
[1]);
873 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
874 if i
< e_MaxInputKeys
then
875 g_Console_BindKey(i
, '')
877 g_Console_Add('unbind: "' + p
[1] + '" is not a key')
880 g_Console_Add('unbind <key>');
882 for i
:= 0 to e_MaxInputKeys
- 1 do
883 g_Console_BindKey(i
, '');
885 g_Touch_ShowKeyboard(True);
887 g_Touch_ShowKeyboard(False);
892 else if gChatShow
then
893 g_Console_Chat_Switch
901 g_Console_Chat_Switch
;
903 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
904 g_Console_Chat_Switch(True);
908 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
913 SetLength(commands
, Length(commands
)+1);
916 cp
.cmd
:= LowerCase(cmd
);
920 cp
.hidden
:= ahidden
;
928 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
930 PrefixList
: array [0..1] of AnsiString = ('+', '-');
931 PlayerList
: array [0..1] of Integer = (1, 2);
936 procedure NewAction (cmd
: AnsiString; player
: Integer);
939 SetLength(commands
, Length(commands
) + 1);
940 cp
:= @commands
[High(commands
)];
941 cp
.cmd
:= LowerCase(cmd
);
954 ASSERT(action
>= FIRST_ACTION
);
955 ASSERT(action
<= LAST_ACTION
);
956 for s
in PrefixList
do
958 NewAction(s
+ cmd
, 0);
959 for i
in PlayerList
do
960 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
964 procedure g_Console_SysInit
;
967 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
968 gConsoleShow
:= False;
974 for a
:= 0 to High(MsgArray
) do
981 AddCommand('segfault', segfault
, 'make segfault');
983 AddCommand('quit', SystemCommands
);
984 AddCommand('exit', SystemCommands
);
985 AddCommand('r_reset', SystemCommands
);
986 AddCommand('r_maxfps', SystemCommands
);
987 AddCommand('g_language', SystemCommands
);
989 AddCommand('bind', BindCommands
);
990 AddCommand('bindrep', BindCommands
);
991 AddCommand('bindunrep', BindCommands
);
992 AddCommand('bindlist', BindCommands
);
993 AddCommand('unbind', BindCommands
);
994 AddCommand('unbindall', BindCommands
);
995 AddCommand('showkeyboard', BindCommands
);
996 AddCommand('hidekeyboard', BindCommands
);
997 AddCommand('togglemenu', BindCommands
);
998 AddCommand('toggleconsole', BindCommands
);
999 AddCommand('togglechat', BindCommands
);
1000 AddCommand('toggleteamchat', BindCommands
);
1002 AddCommand('clear', ConsoleCommands
, 'clear console');
1003 AddCommand('clearhistory', ConsoleCommands
);
1004 AddCommand('showhistory', ConsoleCommands
);
1005 AddCommand('commands', ConsoleCommands
);
1006 AddCommand('time', ConsoleCommands
);
1007 AddCommand('date', ConsoleCommands
);
1008 AddCommand('echo', ConsoleCommands
);
1009 AddCommand('dump', ConsoleCommands
);
1010 AddCommand('exec', ConsoleCommands
);
1011 AddCommand('writeconfig', ConsoleCommands
);
1012 AddCommand('alias', ConsoleCommands
);
1013 AddCommand('call', ConsoleCommands
);
1014 AddCommand('ver', ConsoleCommands
);
1015 AddCommand('version', ConsoleCommands
);
1017 AddCommand('d_window', DebugCommands
);
1018 AddCommand('d_sounds', DebugCommands
);
1019 AddCommand('d_frames', DebugCommands
);
1020 AddCommand('d_winmsg', DebugCommands
);
1021 AddCommand('d_monoff', DebugCommands
);
1022 AddCommand('d_botoff', DebugCommands
);
1023 AddCommand('d_monster', DebugCommands
);
1024 AddCommand('d_health', DebugCommands
);
1025 AddCommand('d_player', DebugCommands
);
1026 AddCommand('d_joy', DebugCommands
);
1027 AddCommand('d_mem', DebugCommands
);
1029 AddCommand('p1_name', PlayerSettingsCVars
);
1030 AddCommand('p2_name', PlayerSettingsCVars
);
1031 AddCommand('p1_color', PlayerSettingsCVars
);
1032 AddCommand('p2_color', PlayerSettingsCVars
);
1033 AddCommand('p1_model', PlayerSettingsCVars
);
1034 AddCommand('p2_model', PlayerSettingsCVars
);
1035 AddCommand('p1_team', PlayerSettingsCVars
);
1036 AddCommand('p2_team', PlayerSettingsCVars
);
1038 AddCommand('g_max_particles', GameCVars
);
1039 AddCommand('g_max_shells', GameCVars
);
1040 AddCommand('g_max_gibs', GameCVars
);
1041 AddCommand('g_max_corpses', GameCVars
);
1042 AddCommand('g_gamemode', GameCVars
);
1043 AddCommand('g_friendlyfire', GameCVars
);
1044 AddCommand('g_friendly_hit_trace', GameCVars
);
1045 AddCommand('g_friendly_hit_projectile', GameCVars
);
1046 AddCommand('g_friendly_absorb_damage', GameCVars
);
1047 AddCommand('g_weaponstay', GameCVars
);
1048 AddCommand('g_allow_exit', GameCVars
);
1049 AddCommand('g_dm_keys', GameCVars
);
1050 AddCommand('g_allow_monsters', GameCVars
);
1051 AddCommand('g_bot_vsmonsters', GameCVars
);
1052 AddCommand('g_bot_vsplayers', GameCVars
);
1053 AddCommand('g_scorelimit', GameCVars
);
1054 AddCommand('g_timelimit', GameCVars
);
1055 AddCommand('g_maxlives', GameCVars
);
1056 AddCommand('g_warmup_time', GameCVars
);
1057 AddCommand('g_spawn_invul', GameCVars
);
1058 AddCommand('g_item_respawn_time', GameCVars
);
1059 AddCommand('sv_intertime', GameCVars
);
1061 AddCommand('sv_name', NetServerCVars
);
1062 AddCommand('sv_passwd', NetServerCVars
);
1063 AddCommand('sv_maxplrs', NetServerCVars
);
1064 AddCommand('sv_public', NetServerCVars
);
1065 AddCommand('sv_port', NetServerCVars
);
1067 AddCommand('pause', GameCommands
);
1068 AddCommand('endgame', GameCommands
);
1069 AddCommand('restart', GameCommands
);
1070 AddCommand('addbot', GameCommands
);
1071 AddCommand('bot_add', GameCommands
);
1072 AddCommand('bot_addlist', GameCommands
);
1073 AddCommand('bot_addred', GameCommands
);
1074 AddCommand('bot_addblue', GameCommands
);
1075 AddCommand('bot_removeall', GameCommands
);
1076 AddCommand('chat', GameCommands
);
1077 AddCommand('teamchat', GameCommands
);
1078 AddCommand('game', GameCommands
);
1079 AddCommand('host', GameCommands
);
1080 AddCommand('map', GameCommands
);
1081 AddCommand('nextmap', GameCommands
);
1082 AddCommand('endmap', GameCommands
);
1083 AddCommand('goodbye', GameCommands
);
1084 AddCommand('suicide', GameCommands
);
1085 AddCommand('spectate', GameCommands
);
1086 AddCommand('ready', GameCommands
);
1087 AddCommand('kick', GameCommands
);
1088 AddCommand('kick_id', GameCommands
);
1089 AddCommand('kick_pid', GameCommands
);
1090 AddCommand('ban', GameCommands
);
1091 AddCommand('ban_id', GameCommands
);
1092 AddCommand('ban_pid', GameCommands
);
1093 AddCommand('permban', GameCommands
);
1094 AddCommand('permban_id', GameCommands
);
1095 AddCommand('permban_pid', GameCommands
);
1096 AddCommand('permban_ip', GameCommands
);
1097 AddCommand('unban', GameCommands
);
1098 AddCommand('connect', GameCommands
);
1099 AddCommand('disconnect', GameCommands
);
1100 AddCommand('reconnect', GameCommands
);
1101 AddCommand('say', GameCommands
);
1102 AddCommand('tell', GameCommands
);
1103 AddCommand('centerprint', GameCommands
);
1104 AddCommand('overtime', GameCommands
);
1105 AddCommand('rcon_password', GameCommands
);
1106 AddCommand('rcon', GameCommands
);
1107 AddCommand('callvote', GameCommands
);
1108 AddCommand('vote', GameCommands
);
1109 AddCommand('clientlist', GameCommands
);
1110 AddCommand('event', GameCommands
);
1111 AddCommand('screenshot', GameCommands
);
1112 AddCommand('weapon', GameCommands
);
1113 AddCommand('p1_weapon', GameCommands
);
1114 AddCommand('p2_weapon', GameCommands
);
1116 AddCommand('god', GameCheats
);
1117 AddCommand('notarget', GameCheats
);
1118 AddCommand('give', GameCheats
); // "exit" too ;-)
1119 AddCommand('open', GameCheats
);
1120 AddCommand('fly', GameCheats
);
1121 AddCommand('noclip', GameCheats
);
1122 AddCommand('speedy', GameCheats
);
1123 AddCommand('jumpy', GameCheats
);
1124 AddCommand('noreload', GameCheats
);
1125 AddCommand('aimline', GameCheats
);
1126 AddCommand('automap', GameCheats
);
1128 AddAction('jump', ACTION_JUMP
);
1129 AddAction('moveleft', ACTION_MOVELEFT
);
1130 AddAction('moveright', ACTION_MOVERIGHT
);
1131 AddAction('lookup', ACTION_LOOKUP
);
1132 AddAction('lookdown', ACTION_LOOKDOWN
);
1133 AddAction('attack', ACTION_ATTACK
);
1134 AddAction('scores', ACTION_SCORES
);
1135 AddAction('activate', ACTION_ACTIVATE
);
1136 AddAction('strafe', ACTION_STRAFE
);
1137 AddAction('weapnext', ACTION_WEAPNEXT
);
1138 AddAction('weapprev', ACTION_WEAPPREV
);
1140 WhitelistCommand('say');
1141 WhitelistCommand('tell');
1142 WhitelistCommand('overtime');
1143 WhitelistCommand('ready');
1144 WhitelistCommand('map');
1145 WhitelistCommand('nextmap');
1146 WhitelistCommand('endmap');
1147 WhitelistCommand('restart');
1148 WhitelistCommand('kick');
1149 WhitelistCommand('kick_pid');
1150 WhitelistCommand('ban');
1151 WhitelistCommand('ban_pid');
1152 WhitelistCommand('centerprint');
1154 WhitelistCommand('addbot');
1155 WhitelistCommand('bot_add');
1156 WhitelistCommand('bot_addred');
1157 WhitelistCommand('bot_addblue');
1158 WhitelistCommand('bot_removeall');
1160 WhitelistCommand('g_gamemode');
1161 WhitelistCommand('g_friendlyfire');
1162 WhitelistCommand('g_friendly_hit_trace');
1163 WhitelistCommand('g_friendly_hit_projectile');
1164 WhitelistCommand('g_friendly_absorb_damage');
1165 WhitelistCommand('g_weaponstay');
1166 WhitelistCommand('g_allow_exit');
1167 WhitelistCommand('g_dm_keys');
1168 WhitelistCommand('g_allow_monsters');
1169 WhitelistCommand('g_bot_vsmonsters');
1170 WhitelistCommand('g_bot_vsplayers');
1171 WhitelistCommand('g_scorelimit');
1172 WhitelistCommand('g_timelimit');
1173 WhitelistCommand('g_maxlives');
1174 WhitelistCommand('g_warmup_time');
1175 WhitelistCommand('g_spawn_invul');
1176 WhitelistCommand('g_item_respawn_time');
1178 g_Console_ResetBinds
;
1179 g_Console_ReadConfig(gConfigScript
);
1180 g_Console_ReadConfig(autoexecScript
);
1181 gParsingBinds
:= False;
1184 procedure g_Console_Init
;
1186 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
1187 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
1191 procedure g_Console_Update
;
1193 a
, b
, Step
: Integer;
1197 Step
:= Max(1, Round(Floor(gScreenHeight
* ConsoleHeight
) * ConsoleStep
));
1198 if gConsoleShow
then
1200 (* Open animation *)
1201 Cons_Y
:= Min(Cons_Y
+ Step
, 0);
1206 (* Close animation *)
1207 Cons_Y
:= Max(Cons_Y
- Step
, -Floor(gScreenHeight
* ConsoleHeight
));
1208 Cons_Shown
:= Cons_Y
> -Floor(gScreenHeight
* ConsoleHeight
);
1217 while a
<= High(MsgArray
) do
1219 if MsgArray
[a
].Time
> 0 then
1221 if MsgArray
[a
].Time
= 1 then
1223 if a
< High(MsgArray
) then
1225 for b
:= a
to High(MsgArray
)-1 do
1226 MsgArray
[b
] := MsgArray
[b
+1];
1228 MsgArray
[High(MsgArray
)].Time
:= 0;
1234 Dec(MsgArray
[a
].Time
);
1242 procedure drawConsoleText ();
1244 CWidth
, CHeight
: Byte;
1249 procedure putLine (sp
, ep
: LongWord);
1258 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1259 if wdt
+cw
> gScreenWidth
-8 then break
;
1260 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1264 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1265 // now print our part
1273 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1274 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1287 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1288 ty
:= Floor(gScreenHeight
* ConsoleHeight
) - 4 - 2 * CHeight
- Abs(Cons_Y
);
1289 skip
:= conSkipLines
;
1290 cbufLastLine(sp
, ep
);
1293 if ty
+CHeight
<= 0 then break
;
1294 until not cbufLineUp(sp
, ep
);
1297 procedure g_Console_Draw(MessagesOnly
: Boolean = False);
1299 CWidth
, CHeight
: Byte;
1301 a
, b
, offset_y
: Integer;
1303 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1305 if ChatTop
and gChatShow
then
1310 for a
:= 0 to High(MsgArray
) do
1311 if MsgArray
[a
].Time
> 0 then
1312 e_TextureFontPrintFmt(0, offset_y
+ CHeight
* a
, MsgArray
[a
].Msg
, gStdFont
, True);
1314 if MessagesOnly
then Exit
;
1321 offset_y
:= gScreenHeight
- CHeight
- 1;
1324 e_TextureFontPrintEx(0, offset_y
, 'say team> ' + Line
, gStdFont
, 255, 255, 255, 1, True);
1325 e_TextureFontPrintEx((CPos
+ 9) * CWidth
, offset_y
, '_', gStdFont
, 255, 255, 255, 1, True);
1329 e_TextureFontPrintEx(0, offset_y
, 'say> ' + Line
, gStdFont
, 255, 255, 255, 1, True);
1330 e_TextureFontPrintEx((CPos
+ 4) * CWidth
, offset_y
, '_', gStdFont
, 255, 255, 255, 1, True);
1334 if not Cons_Shown
then
1339 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1340 a
:= (gScreenWidth
- 2*mfW
) div 2;
1341 b
:= Cons_Y
+ (Floor(gScreenHeight
* ConsoleHeight
) - 2 * mfH
) div 2;
1342 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1343 _RGB(128, 0, 0), 2.0);
1346 e_DrawSize(ID
, 0, Cons_Y
, Round(ConsoleTrans
* 255), False, False, gScreenWidth
, Floor(gScreenHeight
* ConsoleHeight
));
1347 e_TextureFontPrint(0, Cons_Y
+ Floor(gScreenHeight
* ConsoleHeight
) - CHeight
- 4, '> ' + Line
, gStdFont
);
1351 if ConsoleHistory <> nil then
1355 if Length(ConsoleHistory) > (Floor(gScreenHeight * ConsoleHeight) div CHeight) - 1 then
1356 b := Length(ConsoleHistory) - (Floor(gScreenHeight * ConsoleHeight) div CHeight) + 1;
1358 b := Max(b-Offset, 0);
1359 d := Max(High(ConsoleHistory)-Offset, 0);
1362 for a := d downto b do
1364 e_TextureFontPrintFmt(0, Floor(gScreenHeight * ConsoleHeight) - 4 - c * CHeight - Abs(Cons_Y), ConsoleHistory[a], gStdFont, True);
1370 e_TextureFontPrint((CPos
+ 1) * CWidth
, Cons_Y
+ Floor(gScreenHeight
* ConsoleHeight
) - 21, '_', gStdFont
);
1373 procedure g_Console_Char(C
: AnsiChar);
1375 if InputReady
and (gConsoleShow
or gChatShow
) then
1377 Insert(C
, Line
, CPos
);
1384 tcomplist
: array of AnsiString = nil;
1385 tcompidx
: array of Integer = nil;
1387 procedure Complete ();
1391 ll
, lpfx
, cmd
: AnsiString;
1393 if (Length(Line
) = 0) then
1396 for i
:= 0 to High(commands
) do
1398 // hidden commands are hidden when cheats aren't enabled
1399 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1400 if (Length(commands
[i
].help
) > 0) then
1402 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1406 g_Console_Add(' '+commands
[i
].cmd
);
1412 ll
:= LowerCase(Line
);
1415 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1417 ll
:= Copy(ll
, 0, Length(ll
)-1);
1418 for i
:= 0 to High(commands
) do
1420 // hidden commands are hidden when cheats aren't enabled
1421 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1422 if (commands
[i
].cmd
= ll
) then
1424 if (Length(commands
[i
].help
) > 0) then
1426 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1433 // build completion list
1435 for i
:= 0 to High(commands
) do
1437 // hidden commands are hidden when cheats aren't enabled
1438 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1439 cmd
:= commands
[i
].cmd
;
1440 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1442 if (tused
= Length(tcomplist
)) then
1444 SetLength(tcomplist
, Length(tcomplist
)+128);
1445 SetLength(tcompidx
, Length(tcompidx
)+128);
1447 tcomplist
[tused
] := cmd
;
1448 tcompidx
[tused
] := i
;
1450 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1454 // get longest prefix
1455 for i
:= 0 to tused
-1 do
1457 cmd
:= tcomplist
[i
];
1458 for c
:= 1 to Length(lpfx
) do
1460 if (c
> Length(cmd
)) then break
;
1461 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1465 if (tused
= 0) then exit
;
1469 Line
:= tcomplist
[0]+' ';
1470 CPos
:= Length(Line
)+1;
1474 // has longest prefix?
1475 if (Length(lpfx
) > Length(ll
)) then
1478 CPos
:= Length(Line
)+1;
1483 for i
:= 0 to tused
-1 do
1485 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1487 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1491 g_Console_Add(' '+tcomplist
[i
]);
1499 procedure g_Console_Control(K
: Word);
1503 if (Length(Line
) > 0) and (CPos
> 1) then
1505 Delete(Line
, CPos
-1, 1);
1509 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1510 Delete(Line
, CPos
, 1);
1511 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1514 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1515 if CPos
<= Length(Line
) then
1517 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1519 if gConsoleShow
then
1520 g_Console_Process(Line
)
1524 if (Length(Line
) > 0) and g_Game_IsNet
then
1528 if g_Game_IsClient
then
1529 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1531 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1532 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1536 if g_Game_IsClient
then
1537 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1539 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1546 gJustChatted
:= True;
1547 g_Console_Chat_Switch
;
1548 InputReady
:= False;
1552 if not gChatShow
then
1554 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1555 if not gChatShow
then
1556 if (CommandHistory
<> nil) and
1557 (CmdIndex
< Length(CommandHistory
)) then
1559 if CmdIndex
< Length(CommandHistory
)-1 then
1560 CmdIndex
:= CmdIndex
+ 1;
1561 Line
:= CommandHistory
[CmdIndex
];
1562 CPos
:= Length(Line
) + 1;
1564 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1565 if not gChatShow
then
1566 if (CommandHistory
<> nil) and
1567 (CmdIndex
<= Length(CommandHistory
)) then
1569 if CmdIndex
> 0 then
1570 CmdIndex
:= CmdIndex
- 1;
1571 Line
:= CommandHistory
[CmdIndex
];
1572 Cpos
:= Length(Line
) + 1;
1574 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1575 if not gChatShow
then Inc(conSkipLines
);
1576 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1577 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1581 CPos
:= Length(Line
) + 1;
1582 IK_A
..IK_Z
, IK_SPACE
, IK_SHIFT
, IK_RSHIFT
, IK_CAPSLOCK
, IK_LBRACKET
, IK_RBRACKET
,
1583 IK_SEMICOLON
, IK_QUOTE
, IK_BACKSLASH
, IK_SLASH
, IK_COMMA
, IK_DOT
, (*IK_EQUALS,*)
1584 IK_0
, IK_1
, IK_2
, IK_3
, IK_4
, IK_5
, IK_6
, IK_7
, IK_8
, IK_9
, IK_MINUS
, IK_EQUALS
:
1585 (* see TEXTINPUT event *)
1589 function GetStr(var Str
: AnsiString): AnsiString;
1594 if Str
[1] = '"' then
1596 for b
:= 1 to Length(Str
) do
1597 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1599 Result
:= Copy(Str
, 2, b
-1);
1600 Delete(Str
, 1, b
+1);
1606 for a
:= 1 to Length(Str
) do
1607 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1609 Result
:= Copy(Str
, 1, a
);
1610 Delete(Str
, 1, a
+1);
1616 function ParseString(Str
: AnsiString): SSArray
;
1627 SetLength(Result
, Length(Result
)+1);
1628 Result
[High(Result
)] := GetStr(Str
);
1632 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1634 procedure conmsg (s
: AnsiString);
1638 if length(s
) = 0 then exit
;
1639 for a
:= 0 to High(MsgArray
) do
1651 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1652 with MsgArray
[High(MsgArray
)] do
1662 // put it to console
1664 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1666 // now show 'em out of console too
1667 show
:= show
and gAllowConsoleMessages
;
1668 if show
and gShowMessages
then
1670 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1671 while length(L
) > 0 do
1674 if f
<= 0 then f
:= length(L
)+1;
1675 conmsg(Copy(L
, 1, f
-1));
1680 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1681 //ConsoleHistory[High(ConsoleHistory)] := L;
1685 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1692 consolewriterLastWasEOL
: Boolean = false;
1694 procedure consolewriter (constref buf
; len
: SizeUInt
);
1698 if (len
< 1) then exit
;
1700 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1703 if (b
[0] <> 13) and (b
[0] <> 10) then
1705 cbufPut(AnsiChar(b
[0]));
1709 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1718 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1719 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1720 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1721 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1723 g_Console_Add(s
, show
);
1727 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1731 g_Console_Add(formatstrf(s
, args
), true);
1735 consolewriterLastWasEOL
:= false;
1736 formatstrf(s
, args
, consolewriter
);
1737 if not consolewriterLastWasEOL
then cbufPut(#10);
1742 procedure g_Console_Clear();
1744 //ConsoleHistory := nil;
1749 procedure AddToHistory(L
: AnsiString);
1753 len
:= Length(CommandHistory
);
1756 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1758 SetLength(CommandHistory
, len
+1);
1759 CommandHistory
[len
] := L
;
1762 CmdIndex
:= Length(CommandHistory
);
1765 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1774 if Trim(C
) = '' then
1777 Arr
:= ParseString(C
);
1781 for i
:= 0 to High(Whitelist
) do
1782 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1786 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1793 if Trim(L
) = '' then
1796 conSkipLines
:= 0; // "unscroll"
1798 if L
= 'goobers' then
1803 g_Console_Add('Your memory serves you well.');
1809 g_Console_Add('> '+L
);
1814 Arr
:= ParseString(L
);
1818 if commands
= nil then
1824 for i
:= 0 to High(commands
) do
1826 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1828 if commands
[i
].action
>= 0 then
1830 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1833 if assigned(commands
[i
].procEx
) then
1835 commands
[i
].procEx(@commands
[i
], Arr
);
1838 if assigned(commands
[i
].proc
) then
1840 commands
[i
].proc(Arr
);
1846 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1850 function g_Console_Interactive
: Boolean;
1852 Result
:= gConsoleShow
1855 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1857 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1859 ASSERT(key
< e_MaxInputKeys
);
1862 gInputBinds
[key
].rep
:= False;
1863 gInputBinds
[key
].down
:= ParseAlias(down
);
1864 gInputBinds
[key
].up
:= ParseAlias(up
);
1866 g_Console_WriteGameConfig();
1869 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
1871 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1872 var i
, len
: Integer;
1876 if len
= Length(b
) then
1879 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1887 ASSERT(key
< e_MaxInputKeys
);
1888 result
:= EqualsCommandLists(ParseAlias(down
), gInputBinds
[key
].down
) and EqualsCommandLists(ParseAlias(up
), gInputBinds
[key
].up
)
1891 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1896 if commands
= nil then Exit
;
1898 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1900 if g_Console_MatchBind(i
, down
, up
) then
1911 function g_Console_Action (action
: Integer): Boolean;
1912 var i
, len
: Integer;
1914 ASSERT(action
>= FIRST_ACTION
);
1915 ASSERT(action
<= LAST_ACTION
);
1917 len
:= Length(gPlayerAction
);
1918 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1922 function BindsAllowed (key
: Integer): Boolean;
1925 if (not g_GUIGrabInput
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1928 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1929 g_Console_MatchBind(key
, 'showkeyboard') or
1930 g_Console_MatchBind(key
, 'hidekeyboard')
1931 else if gConsoleShow
or (g_ActiveWindow
<> nil) or (gGameSettings
.GameType
= GT_NONE
) then
1932 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1933 g_Console_MatchBind(key
, 'toggleconsole') or
1934 g_Console_MatchBind(key
, 'showkeyboard') or
1935 g_Console_MatchBind(key
, 'hidekeyboard')
1941 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1944 if BindsAllowed(key
) then
1947 for i
:= 0 to High(gInputBinds
[key
].down
) do
1948 g_Console_Process(gInputBinds
[key
].down
[i
], True)
1950 for i
:= 0 to High(gInputBinds
[key
].up
) do
1951 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1953 if down
and not menu_toggled
then
1955 menu_toggled
:= False
1958 procedure g_Console_ProcessBindRepeat (key
: Integer);
1961 if gConsoleShow
or gChatShow
or (g_ActiveWindow
<> nil) then
1963 KeyPress(key
); // key repeat in menus and shit
1966 if BindsAllowed(key
) and gInputBinds
[key
].rep
then
1968 for i
:= 0 to High(gInputBinds
[key
].down
) do
1969 g_Console_Process(gInputBinds
[key
].down
[i
], True);
1973 procedure g_Console_ResetBinds
;
1976 for i
:= 0 to e_MaxInputKeys
- 1 do
1977 g_Console_BindKey(i
, '', '');
1979 g_Console_BindKey(IK_GRAVE
, 'toggleconsole');
1980 g_Console_BindKey(IK_ESCAPE
, 'togglemenu');
1981 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1982 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1983 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1984 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1985 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1986 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1987 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1988 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1989 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1990 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1991 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1992 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1993 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1994 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1995 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1996 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1997 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1998 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1999 g_Console_BindKey(IK_9
, 'p1_weapon 9');
2000 g_Console_BindKey(IK_0
, 'p1_weapon 10');
2001 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
2002 g_Console_BindKey(IK_T
, 'togglechat');
2003 g_Console_BindKey(IK_Y
, 'toggleteamchat');
2004 g_Console_BindKey(IK_F11
, 'screenshot');
2005 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
2006 g_Console_BindKey(IK_PAUSE
, 'pause');
2007 g_Console_BindKey(IK_F1
, 'vote');
2009 (* for i := 0 to e_MaxJoys - 1 do *)
2012 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_LEFT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
2013 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_RIGHT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
2014 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_UP
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
2015 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_DOWN
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
2016 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
2017 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
2018 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
2019 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
2020 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
2021 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
2022 g_Console_BindKey(e_JoyButtonToKey(i
, 10), 'togglemenu');
2025 g_Console_BindKey(VK_ESCAPE
, 'togglemenu');
2026 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
2027 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
2028 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
2029 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
2030 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
2031 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
2032 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
2033 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
2034 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
2035 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
2036 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
2037 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
2038 g_Console_BindKey(VK_0
, 'weapon 1');
2039 g_Console_BindKey(VK_1
, 'weapon 2');
2040 g_Console_BindKey(VK_2
, 'weapon 3');
2041 g_Console_BindKey(VK_3
, 'weapon 4');
2042 g_Console_BindKey(VK_4
, 'weapon 5');
2043 g_Console_BindKey(VK_5
, 'weapon 6');
2044 g_Console_BindKey(VK_6
, 'weapon 7');
2045 g_Console_BindKey(VK_7
, 'weapon 8');
2046 g_Console_BindKey(VK_8
, 'weapon 9');
2047 g_Console_BindKey(VK_9
, 'weapon 10');
2048 g_Console_BindKey(VK_A
, 'weapon 11');
2049 g_Console_BindKey(VK_CHAT
, 'togglechat');
2050 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
2051 g_Console_BindKey(VK_CONSOLE
, 'toggleconsole');
2052 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
2053 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
2054 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
2055 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
2058 procedure g_Console_ReadConfig (filename
: String);
2059 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
2061 e_LogWritefln('g_Console_ReadConfig (1) "%s"', [filename
]);
2062 if e_FindResource(ConfigDirs
, filename
, false) = true then
2064 e_LogWritefln('g_Console_ReadConfig (2) "%s"', [filename
]);
2065 AssignFile(f
, filename
);
2075 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
2077 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
2078 g_Console_Process(s
, True);
2085 procedure g_Console_WriteConfig (filename
: String);
2086 var f
: TextFile
; i
, j
: Integer;
2088 procedure WriteFlag(name
: string; flag
: LongWord);
2090 WriteLn(f
, name
, IfThen(LongBool(gsGameFlags
and flag
), 1, 0));
2093 function FormatTeam(team
: Byte): string;
2095 if team
= TEAM_BLUE
then
2102 AssignFile(f
, filename
);
2104 WriteLn(f
, '// ' + configComment
);
2107 WriteLn(f
, 'unbindall');
2108 for i
:= 0 to e_MaxInputKeys
- 1 do
2109 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
2111 Write(f
, 'bind ', e_KeyNames
[i
], ' ', QuoteStr(GetCommandString(gInputBinds
[i
].down
)));
2112 if Length(gInputBinds
[i
].down
) = 0 then
2114 if Length(gInputBinds
[i
].up
) > 0 then
2115 Write(f
, ' ', QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
2117 if gInputBinds
[i
].rep
then
2118 WriteLn(f
, 'bindrep ', e_KeyNames
[i
]);
2122 if gAskLanguage
then
2123 WriteLn(f
, 'g_language ask')
2125 WriteLn(f
, 'g_language ', gLanguage
);
2128 WriteLn(f
, 'sv_name ', QuoteStr(NetServerName
));
2129 WriteLn(f
, 'sv_passwd ', QuoteStr(NetPassword
));
2130 WriteLn(f
, 'sv_maxplrs ', NetMaxClients
);
2131 WriteLn(f
, 'sv_port ', NetPort
);
2132 WriteLn(f
, 'sv_public ', IfThen(NetUseMaster
, 1, 0));
2135 WriteLn(f
, 'g_max_particles ', g_GFX_GetMax());
2136 WriteLn(f
, 'g_max_shells ', g_Shells_GetMax());
2137 WriteLn(f
, 'g_max_gibs ', g_Gibs_GetMax());
2138 WriteLn(f
, 'g_max_corpses ', g_Corpses_GetMax());
2139 WriteLn(f
, 'sv_intertime ', gDefInterTime
);
2141 // gameplay settings
2142 WriteLn(f
, 'g_gamemode ', gsGameMode
);
2143 WriteLn(f
, 'g_scorelimit ', gsGoalLimit
);
2144 WriteLn(f
, 'g_timelimit ', gsTimeLimit
);
2145 WriteLn(f
, 'g_maxlives ', gsMaxLives
);
2146 WriteLn(f
, 'g_item_respawn_time ', gsItemRespawnTime
);
2147 WriteLn(f
, 'g_spawn_invul ', gsSpawnInvul
);
2148 WriteLn(f
, 'g_warmup_time ', gsWarmupTime
);
2150 WriteFlag('g_friendlyfire ', GAME_OPTION_TEAMDAMAGE
);
2151 WriteFlag('g_friendly_hit_trace ', GAME_OPTION_TEAMHITTRACE
);
2152 WriteFlag('g_friendly_hit_projectile ', GAME_OPTION_TEAMHITPROJECTILE
);
2153 WriteFlag('g_allow_exit ', GAME_OPTION_ALLOWEXIT
);
2154 WriteFlag('g_allow_monsters ', GAME_OPTION_MONSTERS
);
2155 WriteFlag('g_dm_keys ', GAME_OPTION_DMKEYS
);
2156 WriteFlag('g_weaponstay ', GAME_OPTION_WEAPONSTAY
);
2157 WriteFlag('g_bot_vsmonsters ', GAME_OPTION_BOTVSMONSTER
);
2158 WriteFlag('g_bot_vsplayers ', GAME_OPTION_BOTVSPLAYER
);
2161 with gPlayer1Settings
do
2163 WriteLn(f
, 'p1_name ', QuoteStr(Name
));
2164 WriteLn(f
, 'p1_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2165 WriteLn(f
, 'p1_model ', QuoteStr(Model
));
2166 WriteLn(f
, 'p1_team ', FormatTeam(Team
));
2168 with gPlayer2Settings
do
2170 WriteLn(f
, 'p2_name ', QuoteStr(Name
));
2171 WriteLn(f
, 'p2_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2172 WriteLn(f
, 'p2_model ', QuoteStr(Model
));
2173 WriteLn(f
, 'p2_team ', FormatTeam(Team
));
2177 for i
:= 0 to High(commands
) do
2179 if not commands
[i
].cheat
then
2181 if @commands
[i
].procEx
= @boolVarHandler
then
2183 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
2184 WriteLn(f
, commands
[i
].cmd
, ' ', j
)
2186 else if @commands
[i
].procEx
= @intVarHandler
then
2188 WriteLn(f
, commands
[i
].cmd
, ' ', PInteger(commands
[i
].ptr
)^)
2190 else if @commands
[i
].procEx
= @wordVarHandler
then
2192 WriteLn(f
, commands
[i
].cmd
, ' ', PWord(commands
[i
].ptr
)^)
2194 else if @commands
[i
].procEx
= @dwordVarHandler
then
2196 WriteLn(f
, commands
[i
].cmd
, ' ', PCardinal(commands
[i
].ptr
)^)
2198 else if @commands
[i
].procEx
= @singleVarHandler
then
2200 WriteLn(f
, commands
[i
].cmd
, ' ', PVarSingle(commands
[i
].ptr
).val
^:0:6)
2202 else if @commands
[i
].procEx
= @strVarHandler
then
2204 if Length(PAnsiString(commands
[i
].ptr
)^) = 0 then
2205 WriteLn(f
, commands
[i
].cmd
, ' ""')
2207 WriteLn(f
, commands
[i
].cmd
, ' ', QuoteStr(PAnsiString(commands
[i
].ptr
)^))
2212 WriteLn(f
, 'r_maxfps ', gMaxFPS
);
2213 WriteLn(f
, 'r_reset');
2217 procedure g_Console_WriteGameConfig
;
2220 if gParsingBinds
= false then
2222 s
:= e_GetWriteableDir(ConfigDirs
);
2223 g_Console_WriteConfig(e_CatPath(s
, gConfigScript
))
2230 conRegVar('chat_at_top', @ChatTop
, 'draw chat at top border', 'draw chat at top border');
2231 conRegVar('console_height', @ConsoleHeight
, 0.0, 1.0, 'set console size', 'set console size');
2232 conRegVar('console_trans', @ConsoleTrans
, 0.0, 1.0, 'set console transparency', 'set console transparency');
2233 conRegVar('console_step', @ConsoleStep
, 0.0, 1.0, 'set console animation speed', 'set console animation speed');
2236 ConsoleHeight
:= 0.35;
2239 ConsoleHeight
:= 0.5;
2241 ConsoleTrans
:= 0.1;
2242 ConsoleStep
:= 0.07;
2243 conRegVar('d_eres', @debug_e_res
, '', '');
2244 for i
:= 1 to e_MaxJoys
do
2245 conRegVar('joy' + IntToStr(i
) + '_deadzone', @e_JoystickDeadzones
[i
- 1], '', '')