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_ResetBinds
;
61 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
62 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
64 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
65 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
66 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
67 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
69 // <0: no arg; 0/1: true/false
70 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
72 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
73 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
77 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
78 gChatShow
: Boolean = false;
79 gChatTeam
: Boolean = false;
80 gAllowConsoleMessages
: Boolean = true;
81 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
82 gParsingBinds
: Boolean = true; // íå ïåðåñîõðàíÿòü êîíôèã âî âðåìÿ ïàðñèíãà
83 gPlayerAction
: Array [0..1, 0..LAST_ACTION
] of Boolean; // [player, action]
88 g_textures
, g_main
, e_graphics
, e_input
, g_game
, g_gfx
, g_player
, g_items
,
89 SysUtils
, g_basic
, g_options
, Math
, g_touch
, e_res
,
90 g_menu
, g_gui
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
93 configScript
= 'dfconfig.cfg';
94 autoexecScript
= 'autoexec.cfg';
95 configComment
= 'generated by doom2d, do not modify';
100 TCmdProc
= procedure (p
: SSArray
);
101 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
109 ptr
: Pointer; // various data
110 msg
: AnsiString; // message for var changes
112 action
: Integer; // >= 0 for action commands
113 player
: Integer; // used for action commands
124 MaxScriptRecursion
= 16;
126 DEBUG_STRING
= 'DEBUG MODE';
130 RecursionDepth
: Word = 0;
131 RecursionLimitHit
: Boolean = False;
133 ConsoleHeight
: Single;
134 Cons_Shown
: Boolean; // draw console
135 InputReady
: Boolean; // allow text input in console/chat
138 //ConsoleHistory: SSArray;
139 CommandHistory
: SSArray
;
141 commands
: Array of TCommand
= nil;
142 Aliases
: Array of TAlias
= nil;
144 conSkipLines
: Integer = 0;
145 MsgArray
: Array [0..4] of record
150 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
153 menu_toggled
: BOOLEAN; (* hack for menu controls *)
156 ConsoleTrans
: Single;
159 procedure g_Console_Switch
;
161 Cons_Y
:= Min(0, Max(Cons_Y
, -Floor(gScreenHeight
* ConsoleHeight
)));
162 if Cons_Shown
= False then
163 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
165 gConsoleShow
:= not gConsoleShow
;
168 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
171 procedure g_Console_Chat_Switch (Team
: Boolean = False);
173 if not g_Game_IsNet
then Exit
;
174 Cons_Y
:= Min(0, Max(Cons_Y
, -Floor(gScreenHeight
* ConsoleHeight
)));
175 if Cons_Shown
= False then
176 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
177 gConsoleShow
:= False;
178 gChatShow
:= not gChatShow
;
184 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
187 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
188 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
197 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
198 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
199 if (pos
> slen
) then exit
;
200 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
202 while (pos
<= slen
) do
204 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
205 res
:= res
*10+Byte(s
[pos
])-48;
208 if (pos
<= slen
) then
211 if (s
[pos
] <> '.') then exit
;
213 while (pos
<= slen
) do
215 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
217 res
+= frac
*(Byte(s
[pos
])-48);
221 if (pos
<= slen
) then exit
; // oops
226 // ////////////////////////////////////////////////////////////////////////// //
227 // <0: no arg; 0/1: true/false; 666: toggle
228 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
230 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
232 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
233 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
234 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
235 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
239 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
240 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
244 if (Length(p
) > 2) then
246 conwritefln('too many arguments to ''%s''', [p
[0]]);
251 case conGetBoolArg(p
, 1) of
253 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
254 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
255 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
258 g_Console_WriteGameConfig();
259 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
260 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
264 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
268 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
272 if (Length(p
) <> 2) then
274 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
279 old
:= PInteger(me
.ptr
)^;
280 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
281 if PInteger(me
.ptr
)^ <> old
then
282 g_Console_WriteGameConfig();
284 conwritefln('invalid integer value: "%s"', [p
[1]]);
290 procedure strVarHandler (me
: PCommand
; p
: SSArray
);
294 if (Length(p
) <> 2) then
296 conwritefln('%s %s', [me
.cmd
, QuoteStr(PAnsiString(me
.ptr
)^)]);
300 old
:= PAnsiString(me
.ptr
)^;
301 PAnsiString(me
.ptr
)^ := p
[1];
302 if PAnsiString(me
.ptr
)^ <> old
then
303 g_Console_WriteGameConfig();
308 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
313 f
:= Length(commands
);
314 SetLength(commands
, f
+1);
316 cp
.cmd
:= LowerCase(conname
);
318 cp
.procEx
:= boolVarHandler
;
320 cp
.hidden
:= ahidden
;
329 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
334 f
:= Length(commands
);
335 SetLength(commands
, f
+1);
337 cp
.cmd
:= LowerCase(conname
);
339 cp
.procEx
:= intVarHandler
;
341 cp
.hidden
:= ahidden
;
350 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
355 f
:= Length(commands
);
356 SetLength(commands
, f
+1);
358 cp
.cmd
:= LowerCase(conname
);
360 cp
.procEx
:= strVarHandler
;
362 cp
.hidden
:= ahidden
;
370 // ////////////////////////////////////////////////////////////////////////// //
372 PVarSingle
= ^TVarSingle
;
375 min
, max
, def
: Single; // default will be starting value
379 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
385 if (Length(p
) > 2) then
387 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
390 pv
:= PVarSingle(me
.ptr
);
392 if (Length(p
) = 2) then
394 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
395 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
396 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
397 (CompareText(p
[1], 'ona') = 0) then
403 if not conParseFloat(nv
, p
[1]) then
405 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
408 if (nv
< pv
.min
) then nv
:= pv
.min
;
409 if (nv
> pv
.max
) then nv
:= pv
.max
;
413 if pv
.val
^ <> old
then
414 g_Console_WriteGameConfig();
416 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
417 conwritefln('%s %s', [msg
, pv
.val
^]);
421 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
427 GetMem(pv
, sizeof(TVarSingle
));
432 f
:= Length(commands
);
433 SetLength(commands
, f
+1);
435 cp
.cmd
:= LowerCase(conname
);
437 cp
.procEx
:= singleVarHandler
;
439 cp
.hidden
:= ahidden
;
448 // ////////////////////////////////////////////////////////////////////////// //
449 function GetStrACmd(var Str
: AnsiString): AnsiString;
454 for a
:= 1 to Length(Str
) do
455 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
457 Result
:= Copy(Str
, 1, a
);
464 function ParseAlias(Str
: AnsiString): SSArray
;
475 SetLength(Result
, Length(Result
)+1);
476 Result
[High(Result
)] := GetStrACmd(Str
);
480 procedure ConsoleCommands(p
: SSArray
);
486 cmd
:= LowerCase(p
[0]);
489 if cmd
= 'clear' then
491 //ConsoleHistory := nil;
495 for a
:= 0 to High(MsgArray
) do
503 if cmd
= 'clearhistory' then
504 CommandHistory
:= nil;
506 if cmd
= 'showhistory' then
507 if CommandHistory
<> nil then
510 for a
:= 0 to High(CommandHistory
) do
511 g_Console_Add(' '+CommandHistory
[a
]);
514 if cmd
= 'commands' then
517 g_Console_Add('commands list:');
518 for a
:= High(commands
) downto 0 do
520 if (Length(commands
[a
].help
) > 0) then
522 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
526 g_Console_Add(' '+commands
[a
].cmd
);
532 g_Console_Add(TimeToStr(Now
), True);
535 g_Console_Add(DateToStr(Now
), True);
538 if Length(p
) > 1 then
540 if p
[1] = 'ololo' then
545 for a
:= 1 to High(p
) do
547 g_Console_Add(b_Text_Format(s
), True);
556 if ConsoleHistory <> nil then
558 if Length(P) > 1 then
561 s := GameDir+'/console.txt';
566 if IOResult <> 0 then
568 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
573 for a := 0 to High(ConsoleHistory) do
574 WriteLn(F, ConsoleHistory[a]);
577 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
586 if Length(p
) = 2 then
587 g_Console_ReadConfig(p
[1])
589 g_Console_Add('exec <script file>');
592 if cmd
= 'writeconfig' then
594 // writeconfig <filename>
595 if Length(p
) = 2 then
597 s
:= e_GetWriteableDir(ConfigDirs
);
598 g_Console_WriteConfig(e_CatPath(s
, p
[1]))
602 g_Console_Add('writeconfig <file>')
606 if (cmd
= 'ver') or (cmd
= 'version') then
608 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
609 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
610 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
613 if cmd
= 'alias' then
615 // alias [alias_name] [commands]
616 if Length(p
) > 1 then
618 for a
:= 0 to High(Aliases
) do
619 if Aliases
[a
].name
= p
[1] then
621 if Length(p
) > 2 then
622 Aliases
[a
].commands
:= ParseAlias(p
[2])
624 for b
:= 0 to High(Aliases
[a
].commands
) do
625 g_Console_Add(Aliases
[a
].commands
[b
]);
628 SetLength(Aliases
, Length(Aliases
)+1);
630 Aliases
[a
].name
:= p
[1];
631 if Length(p
) > 2 then
632 Aliases
[a
].commands
:= ParseAlias(p
[2])
634 for b
:= 0 to High(Aliases
[a
].commands
) do
635 g_Console_Add(Aliases
[a
].commands
[b
]);
637 for a
:= 0 to High(Aliases
) do
638 if Aliases
[a
].commands
<> nil then
639 g_Console_Add(Aliases
[a
].name
);
645 if Length(p
) > 1 then
647 if Aliases
= nil then
649 for a
:= 0 to High(Aliases
) do
650 if Aliases
[a
].name
= p
[1] then
652 if Aliases
[a
].commands
<> nil then
654 // with this system proper endless loop detection seems either impossible
655 // or very dirty to implement, so let's have this instead
656 // prevents endless loops
657 for b
:= 0 to High(Aliases
[a
].commands
) do
660 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
661 if not RecursionLimitHit
then
662 g_Console_Process(Aliases
[a
].commands
[b
], True);
665 if (RecursionDepth
= 0) and RecursionLimitHit
then
667 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
668 RecursionLimitHit
:= False;
675 g_Console_Add('call <alias name>');
679 procedure WhitelistCommand(cmd
: AnsiString);
683 SetLength(Whitelist
, Length(Whitelist
)+1);
684 a
:= High(Whitelist
);
685 Whitelist
[a
] := LowerCase(cmd
);
688 procedure segfault (p
: SSArray
);
695 function GetCommandString (p
: SSArray
): AnsiString;
699 if Length(p
) >= 1 then
702 for i
:= 1 to High(p
) do
703 result
:= result
+ '; ' + p
[i
]
707 function QuoteStr(str
: String): String;
709 if Pos(' ', str
) > 0 then
710 Result
:= '"' + str
+ '"'
715 procedure BindCommands (p
: SSArray
);
716 var cmd
, key
: AnsiString; i
: Integer;
718 cmd
:= LowerCase(p
[0]);
721 // bind <key> [down [up]]
722 if (Length(p
) >= 2) and (Length(p
) <= 4) then
725 key
:= LowerCase(p
[1]);
726 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
727 if i
< e_MaxInputKeys
then
729 if Length(p
) = 2 then
730 g_Console_Add(QuoteStr(e_KeyNames
[i
]) + ' = ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)))
731 else if Length(p
) = 3 then
732 g_Console_BindKey(i
, p
[2], '')
734 g_Console_BindKey(i
, p
[2], p
[3])
737 g_Console_Add('bind: "' + p
[1] + '" is not a key')
741 g_Console_Add('bind <key> <down action> [up action]')
744 for i
:= 0 to e_MaxInputKeys
- 1 do
745 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
746 g_Console_Add(e_KeyNames
[i
] + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
749 if Length(p
) = 2 then
751 key
:= LowerCase(p
[1]);
753 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
754 if i
< e_MaxInputKeys
then
755 g_Console_BindKey(i
, '')
757 g_Console_Add('unbind: "' + p
[1] + '" is not a key')
760 g_Console_Add('unbind <key>');
762 for i
:= 0 to e_MaxInputKeys
- 1 do
763 g_Console_BindKey(i
, '');
765 g_Touch_ShowKeyboard(True);
767 g_Touch_ShowKeyboard(False);
772 else if gChatShow
then
773 g_Console_Chat_Switch
781 g_Console_Chat_Switch
;
783 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
784 g_Console_Chat_Switch(True);
788 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
793 SetLength(commands
, Length(commands
)+1);
796 cp
.cmd
:= LowerCase(cmd
);
800 cp
.hidden
:= ahidden
;
808 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
810 PrefixList
: array [0..1] of AnsiString = ('+', '-');
811 PlayerList
: array [0..1] of Integer = (1, 2);
816 procedure NewAction (cmd
: AnsiString; player
: Integer);
819 SetLength(commands
, Length(commands
) + 1);
820 cp
:= @commands
[High(commands
)];
821 cp
.cmd
:= LowerCase(cmd
);
834 ASSERT(action
>= FIRST_ACTION
);
835 ASSERT(action
<= LAST_ACTION
);
836 for s
in PrefixList
do
838 NewAction(s
+ cmd
, 0);
839 for i
in PlayerList
do
840 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
844 procedure g_Console_SysInit
;
847 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
848 gConsoleShow
:= False;
854 for a
:= 0 to High(MsgArray
) do
861 AddCommand('segfault', segfault
, 'make segfault');
863 AddCommand('r_reset', g_Options_Commands
);
864 AddCommand('g_language', g_Options_Commands
);
865 AddCommand('g_max_particles', g_Options_Commands
);
866 AddCommand('g_max_shells', g_Options_Commands
);
867 AddCommand('g_max_gibs', g_Options_Commands
);
868 AddCommand('g_max_corpses', g_Options_Commands
);
869 AddCommand('g_item_respawn_time', g_Options_Commands
);
871 AddCommand('bind', BindCommands
);
872 AddCommand('bindlist', BindCommands
);
873 AddCommand('unbind', BindCommands
);
874 AddCommand('unbindall', BindCommands
);
875 AddCommand('showkeyboard', BindCommands
);
876 AddCommand('hidekeyboard', BindCommands
);
877 AddCommand('togglemenu', BindCommands
);
878 AddCommand('toggleconsole', BindCommands
);
879 AddCommand('togglechat', BindCommands
);
880 AddCommand('toggleteamchat', BindCommands
);
882 AddCommand('clear', ConsoleCommands
, 'clear console');
883 AddCommand('clearhistory', ConsoleCommands
);
884 AddCommand('showhistory', ConsoleCommands
);
885 AddCommand('commands', ConsoleCommands
);
886 AddCommand('time', ConsoleCommands
);
887 AddCommand('date', ConsoleCommands
);
888 AddCommand('echo', ConsoleCommands
);
889 AddCommand('dump', ConsoleCommands
);
890 AddCommand('exec', ConsoleCommands
);
891 AddCommand('writeconfig', ConsoleCommands
);
892 AddCommand('alias', ConsoleCommands
);
893 AddCommand('call', ConsoleCommands
);
894 AddCommand('ver', ConsoleCommands
);
895 AddCommand('version', ConsoleCommands
);
897 AddCommand('d_window', DebugCommands
);
898 AddCommand('d_sounds', DebugCommands
);
899 AddCommand('d_frames', DebugCommands
);
900 AddCommand('d_winmsg', DebugCommands
);
901 AddCommand('d_monoff', DebugCommands
);
902 AddCommand('d_botoff', DebugCommands
);
903 AddCommand('d_monster', DebugCommands
);
904 AddCommand('d_health', DebugCommands
);
905 AddCommand('d_player', DebugCommands
);
906 AddCommand('d_joy', DebugCommands
);
907 AddCommand('d_mem', DebugCommands
);
909 AddCommand('p1_name', GameCVars
);
910 AddCommand('p2_name', GameCVars
);
911 AddCommand('p1_color', GameCVars
);
912 AddCommand('p2_color', GameCVars
);
913 AddCommand('r_showscore', GameCVars
);
914 AddCommand('r_showlives', GameCVars
);
915 AddCommand('r_showstat', GameCVars
);
916 AddCommand('r_showkillmsg', GameCVars
);
917 AddCommand('r_showspect', GameCVars
);
918 AddCommand('r_showping', GameCVars
);
919 AddCommand('g_gamemode', GameCVars
);
920 AddCommand('g_friendlyfire', GameCVars
);
921 AddCommand('g_weaponstay', GameCVars
);
922 AddCommand('g_allow_exit', GameCVars
);
923 AddCommand('g_allow_monsters', GameCVars
);
924 AddCommand('g_bot_vsmonsters', GameCVars
);
925 AddCommand('g_bot_vsplayers', GameCVars
);
926 AddCommand('g_scorelimit', GameCVars
);
927 AddCommand('g_timelimit', GameCVars
);
928 AddCommand('g_maxlives', GameCVars
);
929 AddCommand('g_warmuptime', GameCVars
);
930 AddCommand('net_interp', GameCVars
);
931 AddCommand('net_forceplayerupdate', GameCVars
);
932 AddCommand('net_predictself', GameCVars
);
933 AddCommand('sv_name', GameCVars
);
934 AddCommand('sv_passwd', GameCVars
);
935 AddCommand('sv_maxplrs', GameCVars
);
936 AddCommand('sv_public', GameCVars
);
937 AddCommand('sv_intertime', GameCVars
);
939 AddCommand('quit', GameCommands
);
940 AddCommand('exit', GameCommands
);
941 AddCommand('pause', GameCommands
);
942 AddCommand('endgame', GameCommands
);
943 AddCommand('restart', GameCommands
);
944 AddCommand('addbot', GameCommands
);
945 AddCommand('bot_add', GameCommands
);
946 AddCommand('bot_addlist', GameCommands
);
947 AddCommand('bot_addred', GameCommands
);
948 AddCommand('bot_addblue', GameCommands
);
949 AddCommand('bot_removeall', GameCommands
);
950 AddCommand('chat', GameCommands
);
951 AddCommand('teamchat', GameCommands
);
952 AddCommand('game', GameCommands
);
953 AddCommand('host', GameCommands
);
954 AddCommand('map', GameCommands
);
955 AddCommand('nextmap', GameCommands
);
956 AddCommand('endmap', GameCommands
);
957 AddCommand('goodbye', GameCommands
);
958 AddCommand('suicide', GameCommands
);
959 AddCommand('spectate', GameCommands
);
960 AddCommand('ready', GameCommands
);
961 AddCommand('kick', GameCommands
);
962 AddCommand('kick_id', GameCommands
);
963 AddCommand('ban', GameCommands
);
964 AddCommand('permban', GameCommands
);
965 AddCommand('ban_id', GameCommands
);
966 AddCommand('permban_id', GameCommands
);
967 AddCommand('unban', GameCommands
);
968 AddCommand('connect', GameCommands
);
969 AddCommand('disconnect', GameCommands
);
970 AddCommand('reconnect', GameCommands
);
971 AddCommand('say', GameCommands
);
972 AddCommand('tell', GameCommands
);
973 AddCommand('overtime', GameCommands
);
974 AddCommand('rcon_password', GameCommands
);
975 AddCommand('rcon', GameCommands
);
976 AddCommand('callvote', GameCommands
);
977 AddCommand('vote', GameCommands
);
978 AddCommand('clientlist', GameCommands
);
979 AddCommand('event', GameCommands
);
980 AddCommand('screenshot', GameCommands
);
981 AddCommand('weapon', GameCommands
);
982 AddCommand('p1_weapon', GameCommands
);
983 AddCommand('p2_weapon', GameCommands
);
985 AddCommand('god', GameCheats
);
986 AddCommand('notarget', GameCheats
);
987 AddCommand('give', GameCheats
); // "exit" too ;-)
988 AddCommand('open', GameCheats
);
989 AddCommand('fly', GameCheats
);
990 AddCommand('noclip', GameCheats
);
991 AddCommand('speedy', GameCheats
);
992 AddCommand('jumpy', GameCheats
);
993 AddCommand('noreload', GameCheats
);
994 AddCommand('aimline', GameCheats
);
995 AddCommand('automap', GameCheats
);
997 AddAction('jump', ACTION_JUMP
);
998 AddAction('moveleft', ACTION_MOVELEFT
);
999 AddAction('moveright', ACTION_MOVERIGHT
);
1000 AddAction('lookup', ACTION_LOOKUP
);
1001 AddAction('lookdown', ACTION_LOOKDOWN
);
1002 AddAction('attack', ACTION_ATTACK
);
1003 AddAction('scores', ACTION_SCORES
);
1004 AddAction('activate', ACTION_ACTIVATE
);
1005 AddAction('strafe', ACTION_STRAFE
);
1006 AddAction('weapnext', ACTION_WEAPNEXT
);
1007 AddAction('weapprev', ACTION_WEAPPREV
);
1009 WhitelistCommand('say');
1010 WhitelistCommand('tell');
1011 WhitelistCommand('overtime');
1012 WhitelistCommand('ready');
1013 WhitelistCommand('map');
1014 WhitelistCommand('nextmap');
1015 WhitelistCommand('endmap');
1016 WhitelistCommand('restart');
1017 WhitelistCommand('kick');
1018 WhitelistCommand('ban');
1020 WhitelistCommand('addbot');
1021 WhitelistCommand('bot_add');
1022 WhitelistCommand('bot_addred');
1023 WhitelistCommand('bot_addblue');
1024 WhitelistCommand('bot_removeall');
1026 WhitelistCommand('g_gamemode');
1027 WhitelistCommand('g_friendlyfire');
1028 WhitelistCommand('g_weaponstay');
1029 WhitelistCommand('g_allow_exit');
1030 WhitelistCommand('g_allow_monsters');
1031 WhitelistCommand('g_scorelimit');
1032 WhitelistCommand('g_timelimit');
1034 g_Console_ResetBinds
;
1035 g_Console_ReadConfig(configScript
);
1036 g_Console_ReadConfig(autoexecScript
);
1037 gParsingBinds
:= False;
1040 procedure g_Console_Init
;
1042 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
1043 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
1047 procedure g_Console_Update
;
1049 a
, b
, Step
: Integer;
1053 Step
:= Max(1, Round(Floor(gScreenHeight
* ConsoleHeight
) * ConsoleStep
));
1054 if gConsoleShow
then
1056 (* Open animation *)
1057 Cons_Y
:= Min(Cons_Y
+ Step
, 0);
1062 (* Close animation *)
1063 Cons_Y
:= Max(Cons_Y
- Step
, -Floor(gScreenHeight
* ConsoleHeight
));
1064 Cons_Shown
:= Cons_Y
> -Floor(gScreenHeight
* ConsoleHeight
);
1073 while a
<= High(MsgArray
) do
1075 if MsgArray
[a
].Time
> 0 then
1077 if MsgArray
[a
].Time
= 1 then
1079 if a
< High(MsgArray
) then
1081 for b
:= a
to High(MsgArray
)-1 do
1082 MsgArray
[b
] := MsgArray
[b
+1];
1084 MsgArray
[High(MsgArray
)].Time
:= 0;
1090 Dec(MsgArray
[a
].Time
);
1098 procedure drawConsoleText ();
1100 CWidth
, CHeight
: Byte;
1105 procedure putLine (sp
, ep
: LongWord);
1114 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1115 if wdt
+cw
> gScreenWidth
-8 then break
;
1116 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1120 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1121 // now print our part
1129 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1130 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1143 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1144 ty
:= Floor(gScreenHeight
* ConsoleHeight
) - 4 - 2 * CHeight
- Abs(Cons_Y
);
1145 skip
:= conSkipLines
;
1146 cbufLastLine(sp
, ep
);
1149 if ty
+CHeight
<= 0 then break
;
1150 until not cbufLineUp(sp
, ep
);
1153 procedure g_Console_Draw(MessagesOnly
: Boolean = False);
1155 CWidth
, CHeight
: Byte;
1157 a
, b
, offset_y
: Integer;
1159 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1161 if ChatTop
and gChatShow
then
1166 for a
:= 0 to High(MsgArray
) do
1167 if MsgArray
[a
].Time
> 0 then
1168 e_TextureFontPrintFmt(0, offset_y
+ CHeight
* a
, MsgArray
[a
].Msg
, gStdFont
, True);
1170 if MessagesOnly
then Exit
;
1177 offset_y
:= gScreenHeight
- CHeight
- 1;
1180 e_TextureFontPrintEx(0, offset_y
, 'say team> ' + Line
, gStdFont
, 255, 255, 255, 1, True);
1181 e_TextureFontPrintEx((CPos
+ 9) * CWidth
, offset_y
, '_', gStdFont
, 255, 255, 255, 1, True);
1185 e_TextureFontPrintEx(0, offset_y
, 'say> ' + Line
, gStdFont
, 255, 255, 255, 1, True);
1186 e_TextureFontPrintEx((CPos
+ 4) * CWidth
, offset_y
, '_', gStdFont
, 255, 255, 255, 1, True);
1190 if not Cons_Shown
then
1195 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1196 a
:= (gScreenWidth
- 2*mfW
) div 2;
1197 b
:= Cons_Y
+ (Floor(gScreenHeight
* ConsoleHeight
) - 2 * mfH
) div 2;
1198 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1199 _RGB(128, 0, 0), 2.0);
1202 e_DrawSize(ID
, 0, Cons_Y
, Round(ConsoleTrans
* 255), False, False, gScreenWidth
, Floor(gScreenHeight
* ConsoleHeight
));
1203 e_TextureFontPrint(0, Cons_Y
+ Floor(gScreenHeight
* ConsoleHeight
) - CHeight
- 4, '> ' + Line
, gStdFont
);
1207 if ConsoleHistory <> nil then
1211 if Length(ConsoleHistory) > (Floor(gScreenHeight * ConsoleHeight) div CHeight) - 1 then
1212 b := Length(ConsoleHistory) - (Floor(gScreenHeight * ConsoleHeight) div CHeight) + 1;
1214 b := Max(b-Offset, 0);
1215 d := Max(High(ConsoleHistory)-Offset, 0);
1218 for a := d downto b do
1220 e_TextureFontPrintFmt(0, Floor(gScreenHeight * ConsoleHeight) - 4 - c * CHeight - Abs(Cons_Y), ConsoleHistory[a], gStdFont, True);
1226 e_TextureFontPrint((CPos
+ 1) * CWidth
, Cons_Y
+ Floor(gScreenHeight
* ConsoleHeight
) - 21, '_', gStdFont
);
1229 procedure g_Console_Char(C
: AnsiChar);
1231 if InputReady
and (gConsoleShow
or gChatShow
) then
1233 Insert(C
, Line
, CPos
);
1240 tcomplist
: array of AnsiString = nil;
1241 tcompidx
: array of Integer = nil;
1243 procedure Complete ();
1247 ll
, lpfx
, cmd
: AnsiString;
1249 if (Length(Line
) = 0) then
1252 for i
:= 0 to High(commands
) do
1254 // hidden commands are hidden when cheats aren't enabled
1255 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1256 if (Length(commands
[i
].help
) > 0) then
1258 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1262 g_Console_Add(' '+commands
[i
].cmd
);
1268 ll
:= LowerCase(Line
);
1271 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1273 ll
:= Copy(ll
, 0, Length(ll
)-1);
1274 for i
:= 0 to High(commands
) do
1276 // hidden commands are hidden when cheats aren't enabled
1277 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1278 if (commands
[i
].cmd
= ll
) then
1280 if (Length(commands
[i
].help
) > 0) then
1282 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1289 // build completion list
1291 for i
:= 0 to High(commands
) do
1293 // hidden commands are hidden when cheats aren't enabled
1294 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1295 cmd
:= commands
[i
].cmd
;
1296 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1298 if (tused
= Length(tcomplist
)) then
1300 SetLength(tcomplist
, Length(tcomplist
)+128);
1301 SetLength(tcompidx
, Length(tcompidx
)+128);
1303 tcomplist
[tused
] := cmd
;
1304 tcompidx
[tused
] := i
;
1306 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1310 // get longest prefix
1311 for i
:= 0 to tused
-1 do
1313 cmd
:= tcomplist
[i
];
1314 for c
:= 1 to Length(lpfx
) do
1316 if (c
> Length(cmd
)) then break
;
1317 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1321 if (tused
= 0) then exit
;
1325 Line
:= tcomplist
[0]+' ';
1326 CPos
:= Length(Line
)+1;
1330 // has longest prefix?
1331 if (Length(lpfx
) > Length(ll
)) then
1334 CPos
:= Length(Line
)+1;
1339 for i
:= 0 to tused
-1 do
1341 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1343 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1347 g_Console_Add(' '+tcomplist
[i
]);
1355 procedure g_Console_Control(K
: Word);
1359 if (Length(Line
) > 0) and (CPos
> 1) then
1361 Delete(Line
, CPos
-1, 1);
1365 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1366 Delete(Line
, CPos
, 1);
1367 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1370 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1371 if CPos
<= Length(Line
) then
1373 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1375 if gConsoleShow
then
1376 g_Console_Process(Line
)
1380 if (Length(Line
) > 0) and g_Game_IsNet
then
1384 if g_Game_IsClient
then
1385 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1387 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1388 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1392 if g_Game_IsClient
then
1393 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1395 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1402 gJustChatted
:= True;
1403 g_Console_Chat_Switch
;
1404 InputReady
:= False;
1408 if not gChatShow
then
1410 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1411 if not gChatShow
then
1412 if (CommandHistory
<> nil) and
1413 (CmdIndex
< Length(CommandHistory
)) then
1415 if CmdIndex
< Length(CommandHistory
)-1 then
1416 CmdIndex
:= CmdIndex
+ 1;
1417 Line
:= CommandHistory
[CmdIndex
];
1418 CPos
:= Length(Line
) + 1;
1420 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1421 if not gChatShow
then
1422 if (CommandHistory
<> nil) and
1423 (CmdIndex
<= Length(CommandHistory
)) then
1425 if CmdIndex
> 0 then
1426 CmdIndex
:= CmdIndex
- 1;
1427 Line
:= CommandHistory
[CmdIndex
];
1428 Cpos
:= Length(Line
) + 1;
1430 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1431 if not gChatShow
then Inc(conSkipLines
);
1432 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1433 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1437 CPos
:= Length(Line
) + 1;
1438 IK_A
..IK_Z
, IK_SPACE
, IK_SHIFT
, IK_RSHIFT
, IK_CAPSLOCK
, IK_LBRACKET
, IK_RBRACKET
,
1439 IK_SEMICOLON
, IK_QUOTE
, IK_BACKSLASH
, IK_SLASH
, IK_COMMA
, IK_DOT
, (*IK_EQUALS,*)
1440 IK_0
, IK_1
, IK_2
, IK_3
, IK_4
, IK_5
, IK_6
, IK_7
, IK_8
, IK_9
, IK_MINUS
, IK_EQUALS
:
1441 (* see TEXTINPUT event *)
1445 function GetStr(var Str
: AnsiString): AnsiString;
1450 if Str
[1] = '"' then
1452 for b
:= 1 to Length(Str
) do
1453 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1455 Result
:= Copy(Str
, 2, b
-1);
1456 Delete(Str
, 1, b
+1);
1462 for a
:= 1 to Length(Str
) do
1463 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1465 Result
:= Copy(Str
, 1, a
);
1466 Delete(Str
, 1, a
+1);
1472 function ParseString(Str
: AnsiString): SSArray
;
1483 SetLength(Result
, Length(Result
)+1);
1484 Result
[High(Result
)] := GetStr(Str
);
1488 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1490 procedure conmsg (s
: AnsiString);
1494 if length(s
) = 0 then exit
;
1495 for a
:= 0 to High(MsgArray
) do
1507 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1508 with MsgArray
[High(MsgArray
)] do
1518 // put it to console
1520 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1522 // now show 'em out of console too
1523 show
:= show
and gAllowConsoleMessages
;
1524 if show
and gShowMessages
then
1526 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1527 while length(L
) > 0 do
1530 if f
<= 0 then f
:= length(L
)+1;
1531 conmsg(Copy(L
, 1, f
-1));
1536 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1537 //ConsoleHistory[High(ConsoleHistory)] := L;
1541 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1548 consolewriterLastWasEOL
: Boolean = false;
1550 procedure consolewriter (constref buf
; len
: SizeUInt
);
1554 if (len
< 1) then exit
;
1556 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1559 if (b
[0] <> 13) and (b
[0] <> 10) then
1561 cbufPut(AnsiChar(b
[0]));
1565 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1574 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1575 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1576 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1577 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1579 g_Console_Add(s
, show
);
1583 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1587 g_Console_Add(formatstrf(s
, args
), true);
1591 consolewriterLastWasEOL
:= false;
1592 formatstrf(s
, args
, consolewriter
);
1593 if not consolewriterLastWasEOL
then cbufPut(#10);
1598 procedure g_Console_Clear();
1600 //ConsoleHistory := nil;
1605 procedure AddToHistory(L
: AnsiString);
1609 len
:= Length(CommandHistory
);
1612 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1614 SetLength(CommandHistory
, len
+1);
1615 CommandHistory
[len
] := L
;
1618 CmdIndex
:= Length(CommandHistory
);
1621 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1630 if Trim(C
) = '' then
1633 Arr
:= ParseString(C
);
1637 for i
:= 0 to High(Whitelist
) do
1638 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1642 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1649 if Trim(L
) = '' then
1652 conSkipLines
:= 0; // "unscroll"
1654 if L
= 'goobers' then
1659 g_Console_Add('Your memory serves you well.');
1665 g_Console_Add('> '+L
);
1670 Arr
:= ParseString(L
);
1674 if commands
= nil then
1680 for i
:= 0 to High(commands
) do
1682 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1684 if commands
[i
].action
>= 0 then
1686 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1689 if assigned(commands
[i
].procEx
) then
1691 commands
[i
].procEx(@commands
[i
], Arr
);
1694 if assigned(commands
[i
].proc
) then
1696 commands
[i
].proc(Arr
);
1702 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1706 function g_Console_Interactive
: Boolean;
1708 Result
:= gConsoleShow
1711 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1713 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1715 ASSERT(key
< e_MaxInputKeys
);
1718 gInputBinds
[key
].down
:= ParseAlias(down
);
1719 gInputBinds
[key
].up
:= ParseAlias(up
);
1721 g_Console_WriteGameConfig();
1724 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
1726 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1727 var i
, len
: Integer;
1731 if len
= Length(b
) then
1734 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1742 ASSERT(key
< e_MaxInputKeys
);
1743 result
:= EqualsCommandLists(ParseAlias(down
), gInputBinds
[key
].down
) and EqualsCommandLists(ParseAlias(up
), gInputBinds
[key
].up
)
1746 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1751 if commands
= nil then Exit
;
1753 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1755 if g_Console_MatchBind(i
, down
, up
) then
1766 function g_Console_Action (action
: Integer): Boolean;
1767 var i
, len
: Integer;
1769 ASSERT(action
>= FIRST_ACTION
);
1770 ASSERT(action
<= LAST_ACTION
);
1772 len
:= Length(gPlayerAction
);
1773 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1777 function BindsAllowed (key
: Integer): Boolean;
1780 if (not g_GUIGrabInput
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1783 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1784 g_Console_MatchBind(key
, 'showkeyboard') or
1785 g_Console_MatchBind(key
, 'hidekeyboard')
1786 else if gConsoleShow
or (g_ActiveWindow
<> nil) or (gGameSettings
.GameType
= GT_NONE
) then
1787 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1788 g_Console_MatchBind(key
, 'toggleconsole') or
1789 g_Console_MatchBind(key
, 'showkeyboard') or
1790 g_Console_MatchBind(key
, 'hidekeyboard')
1796 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1799 if BindsAllowed(key
) then
1802 for i
:= 0 to High(gInputBinds
[key
].down
) do
1803 g_Console_Process(gInputBinds
[key
].down
[i
], True)
1805 for i
:= 0 to High(gInputBinds
[key
].up
) do
1806 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1808 if down
and not menu_toggled
then
1810 menu_toggled
:= False
1813 procedure g_Console_ResetBinds
;
1816 for i
:= 0 to e_MaxInputKeys
- 1 do
1817 g_Console_BindKey(i
, '', '');
1819 g_Console_BindKey(IK_GRAVE
, 'toggleconsole');
1820 g_Console_BindKey(IK_ESCAPE
, 'togglemenu');
1821 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1822 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1823 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1824 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1825 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1826 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1827 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1828 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1829 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1830 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1831 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1832 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1833 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1834 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1835 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1836 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1837 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1838 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1839 g_Console_BindKey(IK_9
, 'p1_weapon 9');
1840 g_Console_BindKey(IK_0
, 'p1_weapon 10');
1841 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
1842 g_Console_BindKey(IK_T
, 'togglechat');
1843 g_Console_BindKey(IK_Y
, 'toggleteamchat');
1844 g_Console_BindKey(IK_F11
, 'screenshot');
1845 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
1846 g_Console_BindKey(IK_PAUSE
, 'pause');
1847 g_Console_BindKey(IK_F1
, 'vote');
1849 (* for i := 0 to e_MaxJoys - 1 do *)
1852 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_LEFT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
1853 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_RIGHT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
1854 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_UP
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
1855 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_DOWN
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
1856 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
1857 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
1858 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
1859 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
1860 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
1861 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
1862 g_Console_BindKey(e_JoyButtonToKey(i
, 10), 'togglemenu');
1865 g_Console_BindKey(VK_ESCAPE
, 'togglemenu');
1866 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
1867 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
1868 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
1869 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
1870 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
1871 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
1872 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
1873 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
1874 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
1875 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
1876 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
1877 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
1878 g_Console_BindKey(VK_0
, 'weapon 1');
1879 g_Console_BindKey(VK_1
, 'weapon 2');
1880 g_Console_BindKey(VK_2
, 'weapon 3');
1881 g_Console_BindKey(VK_3
, 'weapon 4');
1882 g_Console_BindKey(VK_4
, 'weapon 5');
1883 g_Console_BindKey(VK_5
, 'weapon 6');
1884 g_Console_BindKey(VK_6
, 'weapon 7');
1885 g_Console_BindKey(VK_7
, 'weapon 8');
1886 g_Console_BindKey(VK_8
, 'weapon 9');
1887 g_Console_BindKey(VK_9
, 'weapon 10');
1888 g_Console_BindKey(VK_A
, 'weapon 11');
1889 g_Console_BindKey(VK_CHAT
, 'togglechat');
1890 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
1891 g_Console_BindKey(VK_CONSOLE
, 'toggleconsole');
1892 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
1893 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
1894 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
1895 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
1898 procedure g_Console_ReadConfig (filename
: String);
1899 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1901 e_LogWritefln('g_Console_ReadConfig (1) "%s"', [filename
]);
1902 if e_FindResource(ConfigDirs
, filename
, false) = true then
1904 e_LogWritefln('g_Console_ReadConfig (2) "%s"', [filename
]);
1905 AssignFile(f
, filename
);
1915 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1917 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1918 g_Console_Process(s
, True);
1925 procedure g_Console_WriteConfig (filename
: String);
1926 var f
: TextFile
; i
, j
: Integer;
1928 AssignFile(f
, filename
);
1930 WriteLn(f
, '// ' + configComment
);
1931 WriteLn(f
, 'unbindall');
1932 for i
:= 0 to e_MaxInputKeys
- 1 do
1933 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
1935 Write(f
, 'bind ', e_KeyNames
[i
], ' ', QuoteStr(GetCommandString(gInputBinds
[i
].down
)));
1936 if Length(gInputBinds
[i
].down
) = 0 then
1938 if Length(gInputBinds
[i
].up
) > 0 then
1939 Write(f
, ' ', QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
1942 if gAskLanguage
then
1943 WriteLn(f
, 'g_language ask')
1945 WriteLn(f
, 'g_language ', gLanguage
);
1946 WriteLn(f
, 'g_max_particles ', g_GFX_GetMax());
1947 WriteLn(f
, 'g_max_shells ', g_Shells_GetMax());
1948 WriteLn(f
, 'g_max_gibs ', g_Gibs_GetMax());
1949 WriteLn(f
, 'g_max_corpses ', g_Corpses_GetMax());
1950 WriteLn(f
, 'g_item_respawn_time ', ITEM_RESPAWNTIME
div 36);
1951 with gPlayer1Settings
do
1953 WriteLn(f
, 'p1_name ', QuoteStr(Name
));
1954 WriteLn(f
, 'p1_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
1956 with gPlayer2Settings
do
1958 WriteLn(f
, 'p2_name ', QuoteStr(Name
));
1959 WriteLn(f
, 'p2_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
1961 for i
:= 0 to High(commands
) do
1963 if not commands
[i
].cheat
then
1965 if @commands
[i
].procEx
= @boolVarHandler
then
1967 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
1968 WriteLn(f
, commands
[i
].cmd
, ' ', j
)
1970 else if @commands
[i
].procEx
= @intVarHandler
then
1972 WriteLn(f
, commands
[i
].cmd
, ' ', PInteger(commands
[i
].ptr
)^)
1974 else if @commands
[i
].procEx
= @singleVarHandler
then
1976 WriteLn(f
, commands
[i
].cmd
, ' ', PVarSingle(commands
[i
].ptr
).val
^:0:6)
1978 else if @commands
[i
].procEx
= @strVarHandler
then
1980 if Length(PAnsiString(commands
[i
].ptr
)^) = 0 then
1981 WriteLn(f
, commands
[i
].cmd
, ' ""')
1983 WriteLn(f
, commands
[i
].cmd
, ' ', QuoteStr(PAnsiString(commands
[i
].ptr
)^))
1987 WriteLn(f
, 'r_reset');
1991 procedure g_Console_WriteGameConfig
;
1994 if gParsingBinds
= false then
1996 s
:= e_GetWriteableDir(ConfigDirs
);
1997 g_Console_WriteConfig(e_CatPath(s
, configScript
))
2004 conRegVar('chat_at_top', @ChatTop
, 'draw chat at top border', 'draw chat at top border');
2005 conRegVar('console_height', @ConsoleHeight
, 0.0, 1.0, 'set console size', 'set console size');
2006 conRegVar('console_trans', @ConsoleTrans
, 0.0, 1.0, 'set console transparency', 'set console transparency');
2007 conRegVar('console_step', @ConsoleStep
, 0.0, 1.0, 'set console animation speed', 'set console animation speed');
2010 ConsoleHeight
:= 0.35;
2013 ConsoleHeight
:= 0.5;
2015 ConsoleTrans
:= 0.1;
2016 ConsoleStep
:= 0.07;
2017 conRegVar('d_eres', @debug_e_res
, '', '');
2018 for i
:= 1 to e_MaxJoys
do
2019 conRegVar('joy' + IntToStr(i
) + '_deadzone', @e_JoystickDeadzones
[i
- 1], '', '')