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}
34 FIRST_ACTION
= ACTION_JUMP
;
35 LAST_ACTION
= ACTION_STRAFE
;
37 procedure g_Console_Init
;
38 procedure g_Console_SysInit
;
39 procedure g_Console_Update
;
40 procedure g_Console_Draw (MessagesOnly
: Boolean = False);
41 procedure g_Console_Char (C
: AnsiChar);
42 procedure g_Console_Control (K
: Word);
43 procedure g_Console_Process (L
: AnsiString; quiet
: Boolean=false);
44 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
45 procedure g_Console_Clear
;
46 function g_Console_CommandBlacklisted (C
: AnsiString): Boolean;
47 procedure g_Console_ReadConfig (filename
: String);
48 procedure g_Console_WriteConfig (filename
: String);
49 procedure g_Console_WriteGameConfig
;
51 function g_Console_Interactive
: Boolean;
52 function g_Console_Action (action
: Integer): Boolean;
53 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
54 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
55 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = ''; rep
: Boolean = False);
56 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
57 procedure g_Console_ProcessBindRepeat (key
: Integer);
58 procedure g_Console_ResetBinds
;
60 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
61 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
63 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
64 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
65 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
66 procedure conRegVar (const conname
: AnsiString; pvar
: PWord; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
67 procedure conRegVar (const conname
: AnsiString; pvar
: PCardinal; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
68 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
70 // <0: no arg; 0/1: true/false
71 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
73 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
74 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
78 defaultConfigScript
= 'dfserver.cfg';
80 defaultConfigScript
= 'dfconfig.cfg';
84 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
85 gChatShow
: Boolean = false;
86 gChatTeam
: Boolean = false;
87 gAllowConsoleMessages
: Boolean = true;
88 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
89 gParsingBinds
: Boolean = true; // íå ïåðåñîõðàíÿòü êîíôèã âî âðåìÿ ïàðñèíãà
90 gPlayerAction
: Array [0..1, 0..LAST_ACTION
] of Boolean; // [player, action]
91 gConfigScript
: string = defaultConfigScript
;
96 g_textures
, g_main
, e_graphics
, e_input
, g_game
, g_gfx
, g_player
, g_items
,
97 SysUtils
, g_basic
, g_options
, Math
, g_touch
, e_res
,
98 g_menu
, g_gui
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
101 autoexecScript
= 'autoexec.cfg';
102 configComment
= 'generated by doom2d, do not modify';
105 PCommand
= ^TCommand
;
107 TCmdProc
= procedure (p
: SSArray
);
108 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
116 ptr
: Pointer; // various data
117 msg
: AnsiString; // message for var changes
119 action
: Integer; // >= 0 for action commands
120 player
: Integer; // used for action commands
131 MaxScriptRecursion
= 16;
133 DEBUG_STRING
= 'DEBUG MODE';
137 RecursionDepth
: Word = 0;
138 RecursionLimitHit
: Boolean = False;
140 ConsoleHeight
: Single;
141 Cons_Shown
: Boolean; // draw console
142 InputReady
: Boolean; // allow text input in console/chat
145 //ConsoleHistory: SSArray;
146 CommandHistory
: SSArray
;
148 commands
: Array of TCommand
= nil;
149 Aliases
: Array of TAlias
= nil;
151 conSkipLines
: Integer = 0;
152 MsgArray
: Array [0..4] of record
157 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
161 menu_toggled
: BOOLEAN; (* hack for menu controls *)
164 ConsoleTrans
: Single;
167 procedure g_Console_Switch
;
169 Cons_Y
:= Min(0, Max(Cons_Y
, -Floor(gScreenHeight
* ConsoleHeight
)));
170 if Cons_Shown
= False then
171 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
173 gConsoleShow
:= not gConsoleShow
;
176 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
179 procedure g_Console_Chat_Switch (Team
: Boolean = False);
181 if not g_Game_IsNet
then Exit
;
182 Cons_Y
:= Min(0, Max(Cons_Y
, -Floor(gScreenHeight
* ConsoleHeight
)));
183 if Cons_Shown
= False then
184 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
185 gConsoleShow
:= False;
186 gChatShow
:= not gChatShow
;
192 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
195 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
196 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
205 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
206 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
207 if (pos
> slen
) then exit
;
208 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
210 while (pos
<= slen
) do
212 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
213 res
:= res
*10+Byte(s
[pos
])-48;
216 if (pos
<= slen
) then
219 if (s
[pos
] <> '.') then exit
;
221 while (pos
<= slen
) do
223 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
225 res
+= frac
*(Byte(s
[pos
])-48);
229 if (pos
<= slen
) then exit
; // oops
234 // ////////////////////////////////////////////////////////////////////////// //
235 // <0: no arg; 0/1: true/false; 666: toggle
236 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
238 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
240 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
241 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
242 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
243 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
247 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
248 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
252 if (Length(p
) > 2) then
254 conwritefln('too many arguments to ''%s''', [p
[0]]);
259 case conGetBoolArg(p
, 1) of
261 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
262 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
263 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
266 g_Console_WriteGameConfig();
267 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
268 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
272 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
276 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
280 if (Length(p
) <> 2) then
282 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
287 old
:= PInteger(me
.ptr
)^;
288 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
289 if PInteger(me
.ptr
)^ <> old
then
290 g_Console_WriteGameConfig();
292 conwritefln('invalid integer value: "%s"', [p
[1]]);
298 procedure wordVarHandler (me
: PCommand
; p
: SSArray
);
302 if (Length(p
) <> 2) then
304 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
309 old
:= PWord(me
.ptr
)^;
310 PWord(me
.ptr
)^ := min($FFFF, StrToDWord(p
[1]));
311 if PWord(me
.ptr
)^ <> old
then
312 g_Console_WriteGameConfig();
314 conwritefln('invalid word value: "%s"', [p
[1]]);
320 procedure dwordVarHandler (me
: PCommand
; p
: SSArray
);
324 if (Length(p
) <> 2) then
326 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
331 old
:= PCardinal(me
.ptr
)^;
332 PCardinal(me
.ptr
)^ := StrToDWord(p
[1]);
333 if PCardinal(me
.ptr
)^ <> old
then
334 g_Console_WriteGameConfig();
336 conwritefln('invalid dword value: "%s"', [p
[1]]);
342 procedure strVarHandler (me
: PCommand
; p
: SSArray
);
346 if (Length(p
) <> 2) then
348 conwritefln('%s %s', [me
.cmd
, QuoteStr(PAnsiString(me
.ptr
)^)]);
352 old
:= PAnsiString(me
.ptr
)^;
353 PAnsiString(me
.ptr
)^ := p
[1];
354 if PAnsiString(me
.ptr
)^ <> old
then
355 g_Console_WriteGameConfig();
360 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
365 f
:= Length(commands
);
366 SetLength(commands
, f
+1);
368 cp
.cmd
:= LowerCase(conname
);
370 cp
.procEx
:= boolVarHandler
;
372 cp
.hidden
:= ahidden
;
381 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
386 f
:= Length(commands
);
387 SetLength(commands
, f
+1);
389 cp
.cmd
:= LowerCase(conname
);
391 cp
.procEx
:= intVarHandler
;
393 cp
.hidden
:= ahidden
;
402 procedure conRegVar (const conname
: AnsiString; pvar
: PWord; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
407 f
:= Length(commands
);
408 SetLength(commands
, f
+1);
410 cp
.cmd
:= LowerCase(conname
);
412 cp
.procEx
:= wordVarHandler
;
414 cp
.hidden
:= ahidden
;
423 procedure conRegVar (const conname
: AnsiString; pvar
: PCardinal; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
428 f
:= Length(commands
);
429 SetLength(commands
, f
+1);
431 cp
.cmd
:= LowerCase(conname
);
433 cp
.procEx
:= dwordVarHandler
;
435 cp
.hidden
:= ahidden
;
444 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
449 f
:= Length(commands
);
450 SetLength(commands
, f
+1);
452 cp
.cmd
:= LowerCase(conname
);
454 cp
.procEx
:= strVarHandler
;
456 cp
.hidden
:= ahidden
;
464 // ////////////////////////////////////////////////////////////////////////// //
466 PVarSingle
= ^TVarSingle
;
469 min
, max
, def
: Single; // default will be starting value
473 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
479 if (Length(p
) > 2) then
481 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
484 pv
:= PVarSingle(me
.ptr
);
486 if (Length(p
) = 2) then
488 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
489 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
490 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
491 (CompareText(p
[1], 'ona') = 0) then
497 if not conParseFloat(nv
, p
[1]) then
499 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
502 if (nv
< pv
.min
) then nv
:= pv
.min
;
503 if (nv
> pv
.max
) then nv
:= pv
.max
;
507 if pv
.val
^ <> old
then
508 g_Console_WriteGameConfig();
510 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
511 conwritefln('%s %s', [msg
, pv
.val
^]);
515 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
521 GetMem(pv
, sizeof(TVarSingle
));
526 f
:= Length(commands
);
527 SetLength(commands
, f
+1);
529 cp
.cmd
:= LowerCase(conname
);
531 cp
.procEx
:= singleVarHandler
;
533 cp
.hidden
:= ahidden
;
542 // ////////////////////////////////////////////////////////////////////////// //
543 function GetStrACmd(var Str
: AnsiString): AnsiString;
548 for a
:= 1 to Length(Str
) do
549 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
551 Result
:= Copy(Str
, 1, a
);
558 function ParseAlias(Str
: AnsiString): SSArray
;
569 SetLength(Result
, Length(Result
)+1);
570 Result
[High(Result
)] := GetStrACmd(Str
);
574 procedure ConsoleCommands(p
: SSArray
);
580 cmd
:= LowerCase(p
[0]);
583 if cmd
= 'clear' then
585 //ConsoleHistory := nil;
589 for a
:= 0 to High(MsgArray
) do
597 if cmd
= 'clearhistory' then
598 CommandHistory
:= nil;
600 if cmd
= 'showhistory' then
601 if CommandHistory
<> nil then
604 for a
:= 0 to High(CommandHistory
) do
605 g_Console_Add(' '+CommandHistory
[a
]);
608 if cmd
= 'commands' then
611 g_Console_Add('commands list:');
612 for a
:= High(commands
) downto 0 do
614 if (Length(commands
[a
].help
) > 0) then
616 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
620 g_Console_Add(' '+commands
[a
].cmd
);
626 g_Console_Add(TimeToStr(Now
), True);
629 g_Console_Add(DateToStr(Now
), True);
632 if Length(p
) > 1 then
634 if p
[1] = 'ololo' then
639 for a
:= 1 to High(p
) do
641 g_Console_Add(b_Text_Format(s
), True);
650 if ConsoleHistory <> nil then
652 if Length(P) > 1 then
655 s := GameDir+'/console.txt';
660 if IOResult <> 0 then
662 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
667 for a := 0 to High(ConsoleHistory) do
668 WriteLn(F, ConsoleHistory[a]);
671 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
680 if Length(p
) = 2 then
681 g_Console_ReadConfig(p
[1])
683 g_Console_Add('exec <script file>');
686 if cmd
= 'writeconfig' then
688 // writeconfig <filename>
689 if Length(p
) = 2 then
691 s
:= e_GetWriteableDir(ConfigDirs
);
692 g_Console_WriteConfig(e_CatPath(s
, p
[1]))
696 g_Console_Add('writeconfig <file>')
700 if (cmd
= 'ver') or (cmd
= 'version') then
702 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
703 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
704 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
707 if cmd
= 'alias' then
709 // alias [alias_name] [commands]
710 if Length(p
) > 1 then
712 for a
:= 0 to High(Aliases
) do
713 if Aliases
[a
].name
= p
[1] then
715 if Length(p
) > 2 then
716 Aliases
[a
].commands
:= ParseAlias(p
[2])
718 for b
:= 0 to High(Aliases
[a
].commands
) do
719 g_Console_Add(Aliases
[a
].commands
[b
]);
722 SetLength(Aliases
, Length(Aliases
)+1);
724 Aliases
[a
].name
:= p
[1];
725 if Length(p
) > 2 then
726 Aliases
[a
].commands
:= ParseAlias(p
[2])
728 for b
:= 0 to High(Aliases
[a
].commands
) do
729 g_Console_Add(Aliases
[a
].commands
[b
]);
731 for a
:= 0 to High(Aliases
) do
732 if Aliases
[a
].commands
<> nil then
733 g_Console_Add(Aliases
[a
].name
);
739 if Length(p
) > 1 then
741 if Aliases
= nil then
743 for a
:= 0 to High(Aliases
) do
744 if Aliases
[a
].name
= p
[1] then
746 if Aliases
[a
].commands
<> nil then
748 // with this system proper endless loop detection seems either impossible
749 // or very dirty to implement, so let's have this instead
750 // prevents endless loops
751 for b
:= 0 to High(Aliases
[a
].commands
) do
754 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
755 if not RecursionLimitHit
then
756 g_Console_Process(Aliases
[a
].commands
[b
], True);
759 if (RecursionDepth
= 0) and RecursionLimitHit
then
761 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
762 RecursionLimitHit
:= False;
769 g_Console_Add('call <alias name>');
773 procedure WhitelistCommand(cmd
: AnsiString);
777 SetLength(Whitelist
, Length(Whitelist
)+1);
778 a
:= High(Whitelist
);
779 Whitelist
[a
] := LowerCase(cmd
);
782 procedure segfault (p
: SSArray
);
789 function GetCommandString (p
: SSArray
): AnsiString;
793 if Length(p
) >= 1 then
796 for i
:= 1 to High(p
) do
797 result
:= result
+ '; ' + p
[i
]
801 function QuoteStr(str
: String): String;
803 if Pos(' ', str
) > 0 then
804 Result
:= '"' + str
+ '"'
809 procedure BindCommands (p
: SSArray
);
810 var cmd
, key
: AnsiString; i
: Integer;
812 cmd
:= LowerCase(p
[0]);
815 // bind <key> [down [up]]
816 if (Length(p
) >= 2) and (Length(p
) <= 4) then
819 key
:= LowerCase(p
[1]);
820 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
821 if i
< e_MaxInputKeys
then
823 if Length(p
) = 2 then
824 g_Console_Add(QuoteStr(e_KeyNames
[i
]) + ' = ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)))
825 else if Length(p
) = 3 then
826 g_Console_BindKey(i
, p
[2], '')
828 g_Console_BindKey(i
, p
[2], p
[3])
831 g_Console_Add('bind: "' + p
[1] + '" is not a key')
835 g_Console_Add('bind <key> <down action> [up action]')
839 if Length(p
) = 2 then
841 key
:= LowerCase(p
[1]);
843 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
844 if i
< e_MaxInputKeys
then
845 gInputBinds
[i
].rep
:= True
847 g_Console_Add('bindrep: "' + p
[1] + '" is not a key')
850 g_Console_Add('bindrep <key>');
853 if Length(p
) = 2 then
855 key
:= LowerCase(p
[1]);
857 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
858 if i
< e_MaxInputKeys
then
859 gInputBinds
[i
].rep
:= False
861 g_Console_Add('bindunrep: "' + p
[1] + '" is not a key')
864 g_Console_Add('bindunrep <key>');
866 for i
:= 0 to e_MaxInputKeys
- 1 do
867 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
868 g_Console_Add(e_KeyNames
[i
] + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
871 if Length(p
) = 2 then
873 key
:= LowerCase(p
[1]);
875 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
876 if i
< e_MaxInputKeys
then
877 g_Console_BindKey(i
, '')
879 g_Console_Add('unbind: "' + p
[1] + '" is not a key')
882 g_Console_Add('unbind <key>');
884 for i
:= 0 to e_MaxInputKeys
- 1 do
885 g_Console_BindKey(i
, '');
887 g_Touch_ShowKeyboard(True);
889 g_Touch_ShowKeyboard(False);
894 else if gChatShow
then
895 g_Console_Chat_Switch
903 g_Console_Chat_Switch
;
905 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
906 g_Console_Chat_Switch(True);
910 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
915 SetLength(commands
, Length(commands
)+1);
918 cp
.cmd
:= LowerCase(cmd
);
922 cp
.hidden
:= ahidden
;
930 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
932 PrefixList
: array [0..1] of AnsiString = ('+', '-');
933 PlayerList
: array [0..1] of Integer = (1, 2);
938 procedure NewAction (cmd
: AnsiString; player
: Integer);
941 SetLength(commands
, Length(commands
) + 1);
942 cp
:= @commands
[High(commands
)];
943 cp
.cmd
:= LowerCase(cmd
);
956 ASSERT(action
>= FIRST_ACTION
);
957 ASSERT(action
<= LAST_ACTION
);
958 for s
in PrefixList
do
960 NewAction(s
+ cmd
, 0);
961 for i
in PlayerList
do
962 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
966 procedure g_Console_SysInit
;
969 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
970 gConsoleShow
:= False;
976 for a
:= 0 to High(MsgArray
) do
983 AddCommand('segfault', segfault
, 'make segfault');
985 AddCommand('quit', SystemCommands
);
986 AddCommand('exit', SystemCommands
);
987 AddCommand('r_reset', SystemCommands
);
988 AddCommand('r_maxfps', SystemCommands
);
989 AddCommand('g_language', SystemCommands
);
991 AddCommand('bind', BindCommands
);
992 AddCommand('bindrep', BindCommands
);
993 AddCommand('bindunrep', BindCommands
);
994 AddCommand('bindlist', BindCommands
);
995 AddCommand('unbind', BindCommands
);
996 AddCommand('unbindall', BindCommands
);
997 AddCommand('showkeyboard', BindCommands
);
998 AddCommand('hidekeyboard', BindCommands
);
999 AddCommand('togglemenu', BindCommands
);
1000 AddCommand('toggleconsole', BindCommands
);
1001 AddCommand('togglechat', BindCommands
);
1002 AddCommand('toggleteamchat', BindCommands
);
1004 AddCommand('clear', ConsoleCommands
, 'clear console');
1005 AddCommand('clearhistory', ConsoleCommands
);
1006 AddCommand('showhistory', ConsoleCommands
);
1007 AddCommand('commands', ConsoleCommands
);
1008 AddCommand('time', ConsoleCommands
);
1009 AddCommand('date', ConsoleCommands
);
1010 AddCommand('echo', ConsoleCommands
);
1011 AddCommand('dump', ConsoleCommands
);
1012 AddCommand('exec', ConsoleCommands
);
1013 AddCommand('writeconfig', ConsoleCommands
);
1014 AddCommand('alias', ConsoleCommands
);
1015 AddCommand('call', ConsoleCommands
);
1016 AddCommand('ver', ConsoleCommands
);
1017 AddCommand('version', ConsoleCommands
);
1019 AddCommand('d_window', DebugCommands
);
1020 AddCommand('d_sounds', DebugCommands
);
1021 AddCommand('d_frames', DebugCommands
);
1022 AddCommand('d_winmsg', DebugCommands
);
1023 AddCommand('d_monoff', DebugCommands
);
1024 AddCommand('d_botoff', DebugCommands
);
1025 AddCommand('d_monster', DebugCommands
);
1026 AddCommand('d_health', DebugCommands
);
1027 AddCommand('d_player', DebugCommands
);
1028 AddCommand('d_joy', DebugCommands
);
1029 AddCommand('d_mem', DebugCommands
);
1031 AddCommand('p1_name', PlayerSettingsCVars
);
1032 AddCommand('p2_name', PlayerSettingsCVars
);
1033 AddCommand('p1_color', PlayerSettingsCVars
);
1034 AddCommand('p2_color', PlayerSettingsCVars
);
1035 AddCommand('p1_model', PlayerSettingsCVars
);
1036 AddCommand('p2_model', PlayerSettingsCVars
);
1037 AddCommand('p1_team', PlayerSettingsCVars
);
1038 AddCommand('p2_team', PlayerSettingsCVars
);
1040 AddCommand('g_max_particles', GameCVars
);
1041 AddCommand('g_max_shells', GameCVars
);
1042 AddCommand('g_max_gibs', GameCVars
);
1043 AddCommand('g_max_corpses', GameCVars
);
1044 AddCommand('g_gamemode', GameCVars
);
1045 AddCommand('g_friendlyfire', GameCVars
);
1046 AddCommand('g_friendly_hit_trace', GameCVars
);
1047 AddCommand('g_friendly_hit_projectile', GameCVars
);
1048 AddCommand('g_friendly_absorb_damage', GameCVars
);
1049 AddCommand('g_weaponstay', GameCVars
);
1050 AddCommand('g_allow_exit', GameCVars
);
1051 AddCommand('g_dm_keys', GameCVars
);
1052 AddCommand('g_allow_monsters', GameCVars
);
1053 AddCommand('g_allow_dropflag', GameCVars
);
1054 AddCommand('g_throw_flag', GameCVars
);
1055 AddCommand('g_bot_vsmonsters', GameCVars
);
1056 AddCommand('g_bot_vsplayers', GameCVars
);
1057 AddCommand('g_scorelimit', GameCVars
);
1058 AddCommand('g_timelimit', GameCVars
);
1059 AddCommand('g_maxlives', GameCVars
);
1060 AddCommand('g_warmup_time', GameCVars
);
1061 AddCommand('g_spawn_invul', GameCVars
);
1062 AddCommand('g_item_respawn_time', GameCVars
);
1063 AddCommand('sv_intertime', GameCVars
);
1065 AddCommand('sv_name', NetServerCVars
);
1066 AddCommand('sv_passwd', NetServerCVars
);
1067 AddCommand('sv_maxplrs', NetServerCVars
);
1068 AddCommand('sv_public', NetServerCVars
);
1069 AddCommand('sv_port', NetServerCVars
);
1071 AddCommand('pause', GameCommands
);
1072 AddCommand('endgame', GameCommands
);
1073 AddCommand('restart', GameCommands
);
1074 AddCommand('addbot', GameCommands
);
1075 AddCommand('bot_add', GameCommands
);
1076 AddCommand('bot_addlist', GameCommands
);
1077 AddCommand('bot_addred', GameCommands
);
1078 AddCommand('bot_addblue', GameCommands
);
1079 AddCommand('bot_removeall', GameCommands
);
1080 AddCommand('chat', GameCommands
);
1081 AddCommand('teamchat', GameCommands
);
1082 AddCommand('game', GameCommands
);
1083 AddCommand('host', GameCommands
);
1084 AddCommand('map', GameCommands
);
1085 AddCommand('nextmap', GameCommands
);
1086 AddCommand('endmap', GameCommands
);
1087 AddCommand('goodbye', GameCommands
);
1088 AddCommand('suicide', GameCommands
);
1089 AddCommand('spectate', GameCommands
);
1090 AddCommand('ready', GameCommands
);
1091 AddCommand('kick', GameCommands
);
1092 AddCommand('kick_id', GameCommands
);
1093 AddCommand('kick_pid', GameCommands
);
1094 AddCommand('ban', GameCommands
);
1095 AddCommand('ban_id', GameCommands
);
1096 AddCommand('ban_pid', GameCommands
);
1097 AddCommand('permban', GameCommands
);
1098 AddCommand('permban_id', GameCommands
);
1099 AddCommand('permban_pid', GameCommands
);
1100 AddCommand('permban_ip', GameCommands
);
1101 AddCommand('unban', GameCommands
);
1102 AddCommand('connect', GameCommands
);
1103 AddCommand('disconnect', GameCommands
);
1104 AddCommand('reconnect', GameCommands
);
1105 AddCommand('say', GameCommands
);
1106 AddCommand('tell', GameCommands
);
1107 AddCommand('centerprint', GameCommands
);
1108 AddCommand('overtime', GameCommands
);
1109 AddCommand('rcon_password', GameCommands
);
1110 AddCommand('rcon', GameCommands
);
1111 AddCommand('callvote', GameCommands
);
1112 AddCommand('vote', GameCommands
);
1113 AddCommand('clientlist', GameCommands
);
1114 AddCommand('event', GameCommands
);
1115 AddCommand('screenshot', GameCommands
);
1116 AddCommand('weapnext', GameCommands
);
1117 AddCommand('weapprev', GameCommands
);
1118 AddCommand('weapon', GameCommands
);
1119 AddCommand('dropflag', GameCommands
);
1120 AddCommand('p1_weapnext', GameCommands
);
1121 AddCommand('p1_weapprev', GameCommands
);
1122 AddCommand('p1_weapon', GameCommands
);
1123 AddCommand('p1_dropflag', GameCommands
);
1124 AddCommand('p2_weapnext', GameCommands
);
1125 AddCommand('p2_weapprev', GameCommands
);
1126 AddCommand('p2_weapon', GameCommands
);
1127 AddCommand('p2_dropflag', GameCommands
);
1129 AddCommand('god', GameCheats
);
1130 AddCommand('notarget', GameCheats
);
1131 AddCommand('give', GameCheats
); // "exit" too ;-)
1132 AddCommand('open', GameCheats
);
1133 AddCommand('fly', GameCheats
);
1134 AddCommand('noclip', GameCheats
);
1135 AddCommand('speedy', GameCheats
);
1136 AddCommand('jumpy', GameCheats
);
1137 AddCommand('noreload', GameCheats
);
1138 AddCommand('aimline', GameCheats
);
1139 AddCommand('automap', GameCheats
);
1141 AddAction('jump', ACTION_JUMP
);
1142 AddAction('moveleft', ACTION_MOVELEFT
);
1143 AddAction('moveright', ACTION_MOVERIGHT
);
1144 AddAction('lookup', ACTION_LOOKUP
);
1145 AddAction('lookdown', ACTION_LOOKDOWN
);
1146 AddAction('attack', ACTION_ATTACK
);
1147 AddAction('scores', ACTION_SCORES
);
1148 AddAction('activate', ACTION_ACTIVATE
);
1149 AddAction('strafe', ACTION_STRAFE
);
1151 WhitelistCommand('say');
1152 WhitelistCommand('tell');
1153 WhitelistCommand('overtime');
1154 WhitelistCommand('ready');
1155 WhitelistCommand('map');
1156 WhitelistCommand('nextmap');
1157 WhitelistCommand('endmap');
1158 WhitelistCommand('restart');
1159 WhitelistCommand('kick');
1160 WhitelistCommand('kick_pid');
1161 WhitelistCommand('ban');
1162 WhitelistCommand('ban_pid');
1163 WhitelistCommand('centerprint');
1165 WhitelistCommand('addbot');
1166 WhitelistCommand('bot_add');
1167 WhitelistCommand('bot_addred');
1168 WhitelistCommand('bot_addblue');
1169 WhitelistCommand('bot_removeall');
1171 WhitelistCommand('g_gamemode');
1172 WhitelistCommand('g_friendlyfire');
1173 WhitelistCommand('g_friendly_hit_trace');
1174 WhitelistCommand('g_friendly_hit_projectile');
1175 WhitelistCommand('g_friendly_absorb_damage');
1176 WhitelistCommand('g_weaponstay');
1177 WhitelistCommand('g_allow_exit');
1178 WhitelistCommand('g_dm_keys');
1179 WhitelistCommand('g_allow_monsters');
1180 WhitelistCommand('g_bot_vsmonsters');
1181 WhitelistCommand('g_bot_vsplayers');
1182 WhitelistCommand('g_scorelimit');
1183 WhitelistCommand('g_timelimit');
1184 WhitelistCommand('g_maxlives');
1185 WhitelistCommand('g_warmup_time');
1186 WhitelistCommand('g_spawn_invul');
1187 WhitelistCommand('g_item_respawn_time');
1189 g_Console_ResetBinds
;
1190 g_Console_ReadConfig(gConfigScript
);
1191 g_Console_ReadConfig(autoexecScript
);
1192 gParsingBinds
:= False;
1195 procedure g_Console_Init
;
1197 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
1198 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
1202 procedure g_Console_Update
;
1204 a
, b
, Step
: Integer;
1208 Step
:= Max(1, Round(Floor(gScreenHeight
* ConsoleHeight
) * ConsoleStep
));
1209 if gConsoleShow
then
1211 (* Open animation *)
1212 Cons_Y
:= Min(Cons_Y
+ Step
, 0);
1217 (* Close animation *)
1218 Cons_Y
:= Max(Cons_Y
- Step
, -Floor(gScreenHeight
* ConsoleHeight
));
1219 Cons_Shown
:= Cons_Y
> -Floor(gScreenHeight
* ConsoleHeight
);
1228 while a
<= High(MsgArray
) do
1230 if MsgArray
[a
].Time
> 0 then
1232 if MsgArray
[a
].Time
= 1 then
1234 if a
< High(MsgArray
) then
1236 for b
:= a
to High(MsgArray
)-1 do
1237 MsgArray
[b
] := MsgArray
[b
+1];
1239 MsgArray
[High(MsgArray
)].Time
:= 0;
1245 Dec(MsgArray
[a
].Time
);
1253 procedure drawConsoleText ();
1255 CWidth
, CHeight
: Byte;
1260 procedure putLine (sp
, ep
: LongWord);
1269 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1270 if wdt
+cw
> gScreenWidth
-8 then break
;
1271 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1275 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1276 // now print our part
1284 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1285 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1298 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1299 ty
:= Floor(gScreenHeight
* ConsoleHeight
) - 4 - 2 * CHeight
- Abs(Cons_Y
);
1300 skip
:= conSkipLines
;
1301 cbufLastLine(sp
, ep
);
1304 if ty
+CHeight
<= 0 then break
;
1305 until not cbufLineUp(sp
, ep
);
1308 procedure g_Console_Draw(MessagesOnly
: Boolean = False);
1310 CWidth
, CHeight
: Byte;
1312 a
, b
, offset_y
: Integer;
1314 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1316 if ChatTop
and gChatShow
then
1321 for a
:= 0 to High(MsgArray
) do
1322 if MsgArray
[a
].Time
> 0 then
1323 e_TextureFontPrintFmt(0, offset_y
+ CHeight
* a
, MsgArray
[a
].Msg
, gStdFont
, True);
1325 if MessagesOnly
then Exit
;
1332 offset_y
:= gScreenHeight
- CHeight
- 1;
1335 e_TextureFontPrintEx(0, offset_y
, 'say team> ' + Line
, gStdFont
, 255, 255, 255, 1, True);
1336 e_TextureFontPrintEx((CPos
+ 9) * CWidth
, offset_y
, '_', gStdFont
, 255, 255, 255, 1, True);
1340 e_TextureFontPrintEx(0, offset_y
, 'say> ' + Line
, gStdFont
, 255, 255, 255, 1, True);
1341 e_TextureFontPrintEx((CPos
+ 4) * CWidth
, offset_y
, '_', gStdFont
, 255, 255, 255, 1, True);
1345 if not Cons_Shown
then
1350 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1351 a
:= (gScreenWidth
- 2*mfW
) div 2;
1352 b
:= Cons_Y
+ (Floor(gScreenHeight
* ConsoleHeight
) - 2 * mfH
) div 2;
1353 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1354 _RGB(128, 0, 0), 2.0);
1357 e_DrawSize(ID
, 0, Cons_Y
, Round(ConsoleTrans
* 255), False, False, gScreenWidth
, Floor(gScreenHeight
* ConsoleHeight
));
1358 e_TextureFontPrint(0, Cons_Y
+ Floor(gScreenHeight
* ConsoleHeight
) - CHeight
- 4, '> ' + Line
, gStdFont
);
1362 if ConsoleHistory <> nil then
1366 if Length(ConsoleHistory) > (Floor(gScreenHeight * ConsoleHeight) div CHeight) - 1 then
1367 b := Length(ConsoleHistory) - (Floor(gScreenHeight * ConsoleHeight) div CHeight) + 1;
1369 b := Max(b-Offset, 0);
1370 d := Max(High(ConsoleHistory)-Offset, 0);
1373 for a := d downto b do
1375 e_TextureFontPrintFmt(0, Floor(gScreenHeight * ConsoleHeight) - 4 - c * CHeight - Abs(Cons_Y), ConsoleHistory[a], gStdFont, True);
1381 e_TextureFontPrint((CPos
+ 1) * CWidth
, Cons_Y
+ Floor(gScreenHeight
* ConsoleHeight
) - 21, '_', gStdFont
);
1384 procedure g_Console_Char(C
: AnsiChar);
1386 if InputReady
and (gConsoleShow
or gChatShow
) then
1388 Insert(C
, Line
, CPos
);
1395 tcomplist
: array of AnsiString = nil;
1396 tcompidx
: array of Integer = nil;
1398 procedure Complete ();
1402 ll
, lpfx
, cmd
: AnsiString;
1404 if (Length(Line
) = 0) then
1407 for i
:= 0 to High(commands
) do
1409 // hidden commands are hidden when cheats aren't enabled
1410 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1411 if (Length(commands
[i
].help
) > 0) then
1413 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1417 g_Console_Add(' '+commands
[i
].cmd
);
1423 ll
:= LowerCase(Line
);
1426 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1428 ll
:= Copy(ll
, 0, Length(ll
)-1);
1429 for i
:= 0 to High(commands
) do
1431 // hidden commands are hidden when cheats aren't enabled
1432 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1433 if (commands
[i
].cmd
= ll
) then
1435 if (Length(commands
[i
].help
) > 0) then
1437 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1444 // build completion list
1446 for i
:= 0 to High(commands
) do
1448 // hidden commands are hidden when cheats aren't enabled
1449 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1450 cmd
:= commands
[i
].cmd
;
1451 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1453 if (tused
= Length(tcomplist
)) then
1455 SetLength(tcomplist
, Length(tcomplist
)+128);
1456 SetLength(tcompidx
, Length(tcompidx
)+128);
1458 tcomplist
[tused
] := cmd
;
1459 tcompidx
[tused
] := i
;
1461 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1465 // get longest prefix
1466 for i
:= 0 to tused
-1 do
1468 cmd
:= tcomplist
[i
];
1469 for c
:= 1 to Length(lpfx
) do
1471 if (c
> Length(cmd
)) then break
;
1472 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1476 if (tused
= 0) then exit
;
1480 Line
:= tcomplist
[0]+' ';
1481 CPos
:= Length(Line
)+1;
1485 // has longest prefix?
1486 if (Length(lpfx
) > Length(ll
)) then
1489 CPos
:= Length(Line
)+1;
1494 for i
:= 0 to tused
-1 do
1496 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1498 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1502 g_Console_Add(' '+tcomplist
[i
]);
1510 procedure g_Console_Control(K
: Word);
1514 if (Length(Line
) > 0) and (CPos
> 1) then
1516 Delete(Line
, CPos
-1, 1);
1520 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1521 Delete(Line
, CPos
, 1);
1522 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1525 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1526 if CPos
<= Length(Line
) then
1528 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1530 if gConsoleShow
then
1531 g_Console_Process(Line
)
1535 if (Length(Line
) > 0) and g_Game_IsNet
then
1539 if g_Game_IsClient
then
1540 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1542 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1543 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1547 if g_Game_IsClient
then
1548 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1550 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1557 gJustChatted
:= True;
1558 g_Console_Chat_Switch
;
1559 InputReady
:= False;
1563 if not gChatShow
then
1565 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1566 if not gChatShow
then
1567 if (CommandHistory
<> nil) and
1568 (CmdIndex
< Length(CommandHistory
)) then
1570 if CmdIndex
< Length(CommandHistory
)-1 then
1571 CmdIndex
:= CmdIndex
+ 1;
1572 Line
:= CommandHistory
[CmdIndex
];
1573 CPos
:= Length(Line
) + 1;
1575 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1576 if not gChatShow
then
1577 if (CommandHistory
<> nil) and
1578 (CmdIndex
<= Length(CommandHistory
)) then
1580 if CmdIndex
> 0 then
1581 CmdIndex
:= CmdIndex
- 1;
1582 Line
:= CommandHistory
[CmdIndex
];
1583 Cpos
:= Length(Line
) + 1;
1585 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1586 if not gChatShow
then Inc(conSkipLines
);
1587 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1588 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1592 CPos
:= Length(Line
) + 1;
1593 IK_A
..IK_Z
, IK_SPACE
, IK_SHIFT
, IK_RSHIFT
, IK_CAPSLOCK
, IK_LBRACKET
, IK_RBRACKET
,
1594 IK_SEMICOLON
, IK_QUOTE
, IK_BACKSLASH
, IK_SLASH
, IK_COMMA
, IK_DOT
, (*IK_EQUALS,*)
1595 IK_0
, IK_1
, IK_2
, IK_3
, IK_4
, IK_5
, IK_6
, IK_7
, IK_8
, IK_9
, IK_MINUS
, IK_EQUALS
:
1596 (* see TEXTINPUT event *)
1600 function GetStr(var Str
: AnsiString): AnsiString;
1605 if Str
[1] = '"' then
1607 for b
:= 1 to Length(Str
) do
1608 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1610 Result
:= Copy(Str
, 2, b
-1);
1611 Delete(Str
, 1, b
+1);
1617 for a
:= 1 to Length(Str
) do
1618 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1620 Result
:= Copy(Str
, 1, a
);
1621 Delete(Str
, 1, a
+1);
1627 function ParseString(Str
: AnsiString): SSArray
;
1638 SetLength(Result
, Length(Result
)+1);
1639 Result
[High(Result
)] := GetStr(Str
);
1643 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1645 procedure conmsg (s
: AnsiString);
1649 if length(s
) = 0 then exit
;
1650 for a
:= 0 to High(MsgArray
) do
1662 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1663 with MsgArray
[High(MsgArray
)] do
1673 // put it to console
1675 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1677 // now show 'em out of console too
1678 show
:= show
and gAllowConsoleMessages
;
1679 if show
and gShowMessages
then
1681 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1682 while length(L
) > 0 do
1685 if f
<= 0 then f
:= length(L
)+1;
1686 conmsg(Copy(L
, 1, f
-1));
1691 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1692 //ConsoleHistory[High(ConsoleHistory)] := L;
1696 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1703 consolewriterLastWasEOL
: Boolean = false;
1705 procedure consolewriter (constref buf
; len
: SizeUInt
);
1709 if (len
< 1) then exit
;
1711 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1714 if (b
[0] <> 13) and (b
[0] <> 10) then
1716 cbufPut(AnsiChar(b
[0]));
1720 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1729 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1730 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1731 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1732 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1734 g_Console_Add(s
, show
);
1738 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1742 g_Console_Add(formatstrf(s
, args
), true);
1746 consolewriterLastWasEOL
:= false;
1747 formatstrf(s
, args
, consolewriter
);
1748 if not consolewriterLastWasEOL
then cbufPut(#10);
1753 procedure g_Console_Clear();
1755 //ConsoleHistory := nil;
1760 procedure AddToHistory(L
: AnsiString);
1764 len
:= Length(CommandHistory
);
1767 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1769 SetLength(CommandHistory
, len
+1);
1770 CommandHistory
[len
] := L
;
1773 CmdIndex
:= Length(CommandHistory
);
1776 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1785 if Trim(C
) = '' then
1788 Arr
:= ParseString(C
);
1792 for i
:= 0 to High(Whitelist
) do
1793 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1797 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1804 if Trim(L
) = '' then
1807 conSkipLines
:= 0; // "unscroll"
1809 if L
= 'goobers' then
1814 g_Console_Add('Your memory serves you well.');
1820 g_Console_Add('> '+L
);
1825 Arr
:= ParseString(L
);
1829 if commands
= nil then
1835 for i
:= 0 to High(commands
) do
1837 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1839 if commands
[i
].action
>= 0 then
1841 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1844 if assigned(commands
[i
].procEx
) then
1846 commands
[i
].procEx(@commands
[i
], Arr
);
1849 if assigned(commands
[i
].proc
) then
1851 commands
[i
].proc(Arr
);
1857 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1861 function g_Console_Interactive
: Boolean;
1863 Result
:= gConsoleShow
1866 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = ''; rep
: Boolean = False);
1868 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1870 ASSERT(key
< e_MaxInputKeys
);
1873 gInputBinds
[key
].rep
:= rep
;
1874 gInputBinds
[key
].down
:= ParseAlias(down
);
1875 gInputBinds
[key
].up
:= ParseAlias(up
);
1877 g_Console_WriteGameConfig();
1880 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
1882 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1883 var i
, len
: Integer;
1887 if len
= Length(b
) then
1890 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1898 ASSERT(key
< e_MaxInputKeys
);
1899 result
:= EqualsCommandLists(ParseAlias(down
), gInputBinds
[key
].down
) and EqualsCommandLists(ParseAlias(up
), gInputBinds
[key
].up
)
1902 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1907 if commands
= nil then Exit
;
1909 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1911 if g_Console_MatchBind(i
, down
, up
) then
1922 function g_Console_Action (action
: Integer): Boolean;
1923 var i
, len
: Integer;
1925 ASSERT(action
>= FIRST_ACTION
);
1926 ASSERT(action
<= LAST_ACTION
);
1928 len
:= Length(gPlayerAction
);
1929 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1933 function BindsAllowed (key
: Integer): Boolean;
1936 if (not g_GUIGrabInput
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1939 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1940 g_Console_MatchBind(key
, 'showkeyboard') or
1941 g_Console_MatchBind(key
, 'hidekeyboard')
1942 else if gConsoleShow
or (g_ActiveWindow
<> nil) or (gGameSettings
.GameType
= GT_NONE
) then
1943 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1944 g_Console_MatchBind(key
, 'toggleconsole') or
1945 g_Console_MatchBind(key
, 'showkeyboard') or
1946 g_Console_MatchBind(key
, 'hidekeyboard')
1952 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1955 if BindsAllowed(key
) then
1958 for i
:= 0 to High(gInputBinds
[key
].down
) do
1959 g_Console_Process(gInputBinds
[key
].down
[i
], True)
1961 for i
:= 0 to High(gInputBinds
[key
].up
) do
1962 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1964 if down
and not menu_toggled
then
1966 menu_toggled
:= False
1969 procedure g_Console_ProcessBindRepeat (key
: Integer);
1972 if gConsoleShow
or gChatShow
or (g_ActiveWindow
<> nil) then
1974 KeyPress(key
); // key repeat in menus and shit
1977 if BindsAllowed(key
) and gInputBinds
[key
].rep
then
1979 for i
:= 0 to High(gInputBinds
[key
].down
) do
1980 g_Console_Process(gInputBinds
[key
].down
[i
], True);
1984 procedure g_Console_ResetBinds
;
1987 for i
:= 0 to e_MaxInputKeys
- 1 do
1988 g_Console_BindKey(i
, '', '');
1990 g_Console_BindKey(IK_GRAVE
, 'toggleconsole');
1991 g_Console_BindKey(IK_ESCAPE
, 'togglemenu');
1992 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1993 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1994 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1995 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1996 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1997 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1998 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1999 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
2000 g_Console_BindKey(IK_E
, 'p1_weapnext', '', True);
2001 g_Console_BindKey(IK_Q
, 'p1_weapprev', '', True);
2002 g_Console_BindKey(IK_R
, 'p1_dropflag', '');
2003 g_Console_BindKey(IK_1
, 'p1_weapon 1');
2004 g_Console_BindKey(IK_2
, 'p1_weapon 2');
2005 g_Console_BindKey(IK_3
, 'p1_weapon 3');
2006 g_Console_BindKey(IK_4
, 'p1_weapon 4');
2007 g_Console_BindKey(IK_5
, 'p1_weapon 5');
2008 g_Console_BindKey(IK_6
, 'p1_weapon 6');
2009 g_Console_BindKey(IK_7
, 'p1_weapon 7');
2010 g_Console_BindKey(IK_8
, 'p1_weapon 8');
2011 g_Console_BindKey(IK_9
, 'p1_weapon 9');
2012 g_Console_BindKey(IK_0
, 'p1_weapon 10');
2013 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
2014 g_Console_BindKey(IK_T
, 'togglechat');
2015 g_Console_BindKey(IK_Y
, 'toggleteamchat');
2016 g_Console_BindKey(IK_F11
, 'screenshot');
2017 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
2018 g_Console_BindKey(IK_PAUSE
, 'pause');
2019 g_Console_BindKey(IK_F1
, 'vote');
2021 (* for i := 0 to e_MaxJoys - 1 do *)
2024 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_LEFT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
2025 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_RIGHT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
2026 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_UP
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
2027 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_DOWN
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
2028 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
2029 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
2030 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
2031 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
2032 g_Console_BindKey(e_JoyButtonToKey(i
, 1), 'p' + IntToStr(i
mod 2 + 1) + '_weapnext', '', True);
2033 g_Console_BindKey(e_JoyButtonToKey(i
, 4), 'p' + IntToStr(i
mod 2 + 1) + '_weapprev', '', True);
2034 g_Console_BindKey(e_JoyButtonToKey(i
, 10), 'togglemenu');
2037 g_Console_BindKey(VK_ESCAPE
, 'togglemenu');
2038 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
2039 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
2040 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
2041 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
2042 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
2043 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
2044 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
2045 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
2046 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
2047 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
2048 g_Console_BindKey(VK_NEXT
, 'weapnext', '', True);
2049 g_Console_BindKey(VK_PREV
, 'weapprev', '', True);
2050 g_Console_BindKey(VK_0
, 'weapon 1');
2051 g_Console_BindKey(VK_1
, 'weapon 2');
2052 g_Console_BindKey(VK_2
, 'weapon 3');
2053 g_Console_BindKey(VK_3
, 'weapon 4');
2054 g_Console_BindKey(VK_4
, 'weapon 5');
2055 g_Console_BindKey(VK_5
, 'weapon 6');
2056 g_Console_BindKey(VK_6
, 'weapon 7');
2057 g_Console_BindKey(VK_7
, 'weapon 8');
2058 g_Console_BindKey(VK_8
, 'weapon 9');
2059 g_Console_BindKey(VK_9
, 'weapon 10');
2060 g_Console_BindKey(VK_A
, 'weapon 11');
2061 g_Console_BindKey(VK_CHAT
, 'togglechat');
2062 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
2063 g_Console_BindKey(VK_CONSOLE
, 'toggleconsole');
2064 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
2065 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
2066 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
2067 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
2070 procedure g_Console_ReadConfig (filename
: String);
2071 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
2073 e_LogWritefln('g_Console_ReadConfig (1) "%s"', [filename
]);
2074 if e_FindResource(ConfigDirs
, filename
, false) = true then
2076 e_LogWritefln('g_Console_ReadConfig (2) "%s"', [filename
]);
2077 AssignFile(f
, filename
);
2087 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
2089 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
2090 g_Console_Process(s
, True);
2097 procedure g_Console_WriteConfig (filename
: String);
2098 var f
: TextFile
; i
, j
: Integer;
2100 procedure WriteFlag(name
: string; flag
: LongWord);
2102 WriteLn(f
, name
, IfThen(LongBool(gsGameFlags
and flag
), 1, 0));
2105 function FormatTeam(team
: Byte): string;
2107 if team
= TEAM_BLUE
then
2114 AssignFile(f
, filename
);
2116 WriteLn(f
, '// ' + configComment
);
2119 WriteLn(f
, 'unbindall');
2120 for i
:= 0 to e_MaxInputKeys
- 1 do
2121 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
2123 Write(f
, 'bind ', e_KeyNames
[i
], ' ', QuoteStr(GetCommandString(gInputBinds
[i
].down
)));
2124 if Length(gInputBinds
[i
].down
) = 0 then
2126 if Length(gInputBinds
[i
].up
) > 0 then
2127 Write(f
, ' ', QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
2129 if gInputBinds
[i
].rep
then
2130 WriteLn(f
, 'bindrep ', e_KeyNames
[i
]);
2134 if gAskLanguage
then
2135 WriteLn(f
, 'g_language ask')
2137 WriteLn(f
, 'g_language ', gLanguage
);
2140 WriteLn(f
, 'sv_name ', QuoteStr(NetServerName
));
2141 WriteLn(f
, 'sv_passwd ', QuoteStr(NetPassword
));
2142 WriteLn(f
, 'sv_maxplrs ', NetMaxClients
);
2143 WriteLn(f
, 'sv_port ', NetPort
);
2144 WriteLn(f
, 'sv_public ', IfThen(NetUseMaster
, 1, 0));
2147 WriteLn(f
, 'g_max_particles ', g_GFX_GetMax());
2148 WriteLn(f
, 'g_max_shells ', g_Shells_GetMax());
2149 WriteLn(f
, 'g_max_gibs ', g_Gibs_GetMax());
2150 WriteLn(f
, 'g_max_corpses ', g_Corpses_GetMax());
2151 WriteLn(f
, 'sv_intertime ', gDefInterTime
);
2153 // gameplay settings
2154 WriteLn(f
, 'g_gamemode ', gsGameMode
);
2155 WriteLn(f
, 'g_scorelimit ', gsGoalLimit
);
2156 WriteLn(f
, 'g_timelimit ', gsTimeLimit
);
2157 WriteLn(f
, 'g_maxlives ', gsMaxLives
);
2158 WriteLn(f
, 'g_item_respawn_time ', gsItemRespawnTime
);
2159 WriteLn(f
, 'g_spawn_invul ', gsSpawnInvul
);
2160 WriteLn(f
, 'g_warmup_time ', gsWarmupTime
);
2162 WriteFlag('g_friendlyfire ', GAME_OPTION_TEAMDAMAGE
);
2163 WriteFlag('g_friendly_hit_trace ', GAME_OPTION_TEAMHITTRACE
);
2164 WriteFlag('g_friendly_hit_projectile ', GAME_OPTION_TEAMHITPROJECTILE
);
2165 WriteFlag('g_allow_exit ', GAME_OPTION_ALLOWEXIT
);
2166 WriteFlag('g_allow_monsters ', GAME_OPTION_MONSTERS
);
2167 WriteFlag('g_allow_dropflag ', GAME_OPTION_ALLOWDROPFLAG
);
2168 WriteFlag('g_throw_flag ', GAME_OPTION_THROWFLAG
);
2169 WriteFlag('g_dm_keys ', GAME_OPTION_DMKEYS
);
2170 WriteFlag('g_weaponstay ', GAME_OPTION_WEAPONSTAY
);
2171 WriteFlag('g_bot_vsmonsters ', GAME_OPTION_BOTVSMONSTER
);
2172 WriteFlag('g_bot_vsplayers ', GAME_OPTION_BOTVSPLAYER
);
2175 with gPlayer1Settings
do
2177 WriteLn(f
, 'p1_name ', QuoteStr(Name
));
2178 WriteLn(f
, 'p1_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2179 WriteLn(f
, 'p1_model ', QuoteStr(Model
));
2180 WriteLn(f
, 'p1_team ', FormatTeam(Team
));
2182 with gPlayer2Settings
do
2184 WriteLn(f
, 'p2_name ', QuoteStr(Name
));
2185 WriteLn(f
, 'p2_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2186 WriteLn(f
, 'p2_model ', QuoteStr(Model
));
2187 WriteLn(f
, 'p2_team ', FormatTeam(Team
));
2191 for i
:= 0 to High(commands
) do
2193 if not commands
[i
].cheat
then
2195 if @commands
[i
].procEx
= @boolVarHandler
then
2197 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
2198 WriteLn(f
, commands
[i
].cmd
, ' ', j
)
2200 else if @commands
[i
].procEx
= @intVarHandler
then
2202 WriteLn(f
, commands
[i
].cmd
, ' ', PInteger(commands
[i
].ptr
)^)
2204 else if @commands
[i
].procEx
= @wordVarHandler
then
2206 WriteLn(f
, commands
[i
].cmd
, ' ', PWord(commands
[i
].ptr
)^)
2208 else if @commands
[i
].procEx
= @dwordVarHandler
then
2210 WriteLn(f
, commands
[i
].cmd
, ' ', PCardinal(commands
[i
].ptr
)^)
2212 else if @commands
[i
].procEx
= @singleVarHandler
then
2214 WriteLn(f
, commands
[i
].cmd
, ' ', PVarSingle(commands
[i
].ptr
).val
^:0:6)
2216 else if @commands
[i
].procEx
= @strVarHandler
then
2218 if Length(PAnsiString(commands
[i
].ptr
)^) = 0 then
2219 WriteLn(f
, commands
[i
].cmd
, ' ""')
2221 WriteLn(f
, commands
[i
].cmd
, ' ', QuoteStr(PAnsiString(commands
[i
].ptr
)^))
2226 WriteLn(f
, 'r_maxfps ', gMaxFPS
);
2227 WriteLn(f
, 'r_reset');
2231 procedure g_Console_WriteGameConfig
;
2234 if gParsingBinds
= false then
2236 s
:= e_GetWriteableDir(ConfigDirs
);
2237 g_Console_WriteConfig(e_CatPath(s
, gConfigScript
))
2244 conRegVar('chat_at_top', @ChatTop
, 'draw chat at top border', 'draw chat at top border');
2245 conRegVar('console_height', @ConsoleHeight
, 0.0, 1.0, 'set console size', 'set console size');
2246 conRegVar('console_trans', @ConsoleTrans
, 0.0, 1.0, 'set console transparency', 'set console transparency');
2247 conRegVar('console_step', @ConsoleStep
, 0.0, 1.0, 'set console animation speed', 'set console animation speed');
2250 ConsoleHeight
:= 0.35;
2253 ConsoleHeight
:= 0.5;
2255 ConsoleTrans
:= 0.1;
2256 ConsoleStep
:= 0.07;
2257 conRegVar('d_eres', @debug_e_res
, '', '');
2258 for i
:= 1 to e_MaxJoys
do
2259 conRegVar('joy' + IntToStr(i
) + '_deadzone', @e_JoystickDeadzones
[i
- 1], '', '')