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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
37 FIRST_ACTION
= ACTION_JUMP
;
38 LAST_ACTION
= ACTION_WEAPPREV
;
40 procedure g_Console_Init
;
41 procedure g_Console_Update
;
42 procedure g_Console_Draw
;
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
;
68 // <0: no arg; 0/1: true/false
69 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
71 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
72 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
76 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
77 gChatShow
: Boolean = false;
78 gChatTeam
: Boolean = false;
79 gAllowConsoleMessages
: Boolean = true;
80 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
81 gParsingBinds
: Boolean = false; // íå ïåðåñîõðàíÿòü êîíôèã âî âðåìÿ ïàðñèíãà
82 gPlayerAction
: Array [0..1, 0..LAST_ACTION
] of Boolean; // [player, action]
87 g_textures
, g_main
, e_graphics
, e_input
, g_game
,
88 SysUtils
, g_basic
, g_options
, Math
, g_touch
,
89 g_menu
, g_gui
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
95 TCmdProc
= procedure (p
: SSArray
);
96 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
104 ptr
: Pointer; // various data
105 msg
: AnsiString; // message for var changes
107 action
: Integer; // >= 0 for action commands
108 player
: Integer; // used for action commands
121 MaxScriptRecursion
= 16;
123 DEBUG_STRING
= 'DEBUG MODE';
127 RecursionDepth
: Word = 0;
128 RecursionLimitHit
: Boolean = False;
130 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
133 //ConsoleHistory: SSArray;
134 CommandHistory
: SSArray
;
136 commands
: Array of TCommand
= nil;
137 Aliases
: Array of TAlias
= nil;
139 conSkipLines
: Integer = 0;
140 MsgArray
: Array [0..4] of record
145 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
148 menu_toggled
: BOOLEAN; (* hack for menu controls *)
149 gSkipFirstChar
: Boolean; (* hack for console/chat input *)
152 procedure g_Console_Switch
;
155 gConsoleShow
:= not gConsoleShow
;
157 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
160 procedure g_Console_Chat_Switch (Team
: Boolean = False);
162 if not g_Game_IsNet
then Exit
;
163 gConsoleShow
:= False;
164 gChatShow
:= not gChatShow
;
168 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
171 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
172 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
181 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
182 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
183 if (pos
> slen
) then exit
;
184 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
186 while (pos
<= slen
) do
188 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
189 res
:= res
*10+Byte(s
[pos
])-48;
192 if (pos
<= slen
) then
195 if (s
[pos
] <> '.') then exit
;
197 while (pos
<= slen
) do
199 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
201 res
+= frac
*(Byte(s
[pos
])-48);
205 if (pos
<= slen
) then exit
; // oops
210 // ////////////////////////////////////////////////////////////////////////// //
211 // <0: no arg; 0/1: true/false; 666: toggle
212 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
214 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
216 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
217 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
218 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
219 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
223 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
224 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
226 if (Length(p
) > 2) then
228 conwritefln('too many arguments to ''%s''', [p
[0]]);
232 case conGetBoolArg(p
, 1) of
234 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
235 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
236 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
238 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
239 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
243 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
247 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
249 if (Length(p
) <> 2) then
251 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
256 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
258 conwritefln('invalid integer value: "%s"', [p
[1]]);
264 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
269 f
:= Length(commands
);
270 SetLength(commands
, f
+1);
272 cp
.cmd
:= LowerCase(conname
);
274 cp
.procEx
:= boolVarHandler
;
276 cp
.hidden
:= ahidden
;
285 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
290 f
:= Length(commands
);
291 SetLength(commands
, f
+1);
293 cp
.cmd
:= LowerCase(conname
);
295 cp
.procEx
:= intVarHandler
;
297 cp
.hidden
:= ahidden
;
306 // ////////////////////////////////////////////////////////////////////////// //
308 PVarSingle
= ^TVarSingle
;
311 min
, max
, def
: Single; // default will be starting value
315 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
321 if (Length(p
) > 2) then
323 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
326 pv
:= PVarSingle(me
.ptr
);
327 if (Length(p
) = 2) then
329 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
330 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
331 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
332 (CompareText(p
[1], 'ona') = 0) then
338 if not conParseFloat(nv
, p
[1]) then
340 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
343 if (nv
< pv
.min
) then nv
:= pv
.min
;
344 if (nv
> pv
.max
) then nv
:= pv
.max
;
349 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
350 conwritefln('%s %s', [msg
, pv
.val
^]);
354 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
360 GetMem(pv
, sizeof(TVarSingle
));
365 f
:= Length(commands
);
366 SetLength(commands
, f
+1);
368 cp
.cmd
:= LowerCase(conname
);
370 cp
.procEx
:= singleVarHandler
;
372 cp
.hidden
:= ahidden
;
381 // ////////////////////////////////////////////////////////////////////////// //
382 function GetStrACmd(var Str
: AnsiString): AnsiString;
387 for a
:= 1 to Length(Str
) do
388 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
390 Result
:= Copy(Str
, 1, a
);
397 function ParseAlias(Str
: AnsiString): SSArray
;
408 SetLength(Result
, Length(Result
)+1);
409 Result
[High(Result
)] := GetStrACmd(Str
);
413 procedure ConsoleCommands(p
: SSArray
);
419 cmd
:= LowerCase(p
[0]);
422 if cmd
= 'clear' then
424 //ConsoleHistory := nil;
428 for a
:= 0 to High(MsgArray
) do
436 if cmd
= 'clearhistory' then
437 CommandHistory
:= nil;
439 if cmd
= 'showhistory' then
440 if CommandHistory
<> nil then
443 for a
:= 0 to High(CommandHistory
) do
444 g_Console_Add(' '+CommandHistory
[a
]);
447 if cmd
= 'commands' then
450 g_Console_Add('commands list:');
451 for a
:= High(commands
) downto 0 do
453 if (Length(commands
[a
].help
) > 0) then
455 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
459 g_Console_Add(' '+commands
[a
].cmd
);
465 g_Console_Add(TimeToStr(Now
), True);
468 g_Console_Add(DateToStr(Now
), True);
471 if Length(p
) > 1 then
473 if p
[1] = 'ololo' then
478 for a
:= 1 to High(p
) do
480 g_Console_Add(b_Text_Format(s
), True);
489 if ConsoleHistory <> nil then
491 if Length(P) > 1 then
494 s := GameDir+'/console.txt';
499 if IOResult <> 0 then
501 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
506 for a := 0 to High(ConsoleHistory) do
507 WriteLn(F, ConsoleHistory[a]);
510 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
519 if Length(p
) = 2 then
520 g_Console_ReadConfig(GameDir
+ '/' + p
[1])
522 g_Console_Add('exec <script file>');
525 if cmd
= 'writeconfig' then
527 // writeconfig <filename>
528 if Length(p
) = 2 then
529 g_Console_WriteConfig(GameDir
+ '/' + p
[1])
531 g_Console_Add('writeconfig <file>');
534 if (cmd
= 'ver') or (cmd
= 'version') then
536 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
537 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
538 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
541 if cmd
= 'alias' then
543 // alias [alias_name] [commands]
544 if Length(p
) > 1 then
546 for a
:= 0 to High(Aliases
) do
547 if Aliases
[a
].name
= p
[1] then
549 if Length(p
) > 2 then
550 Aliases
[a
].commands
:= ParseAlias(p
[2])
552 for b
:= 0 to High(Aliases
[a
].commands
) do
553 g_Console_Add(Aliases
[a
].commands
[b
]);
556 SetLength(Aliases
, Length(Aliases
)+1);
558 Aliases
[a
].name
:= p
[1];
559 if Length(p
) > 2 then
560 Aliases
[a
].commands
:= ParseAlias(p
[2])
562 for b
:= 0 to High(Aliases
[a
].commands
) do
563 g_Console_Add(Aliases
[a
].commands
[b
]);
565 for a
:= 0 to High(Aliases
) do
566 if Aliases
[a
].commands
<> nil then
567 g_Console_Add(Aliases
[a
].name
);
573 if Length(p
) > 1 then
575 if Aliases
= nil then
577 for a
:= 0 to High(Aliases
) do
578 if Aliases
[a
].name
= p
[1] then
580 if Aliases
[a
].commands
<> nil then
582 // with this system proper endless loop detection seems either impossible
583 // or very dirty to implement, so let's have this instead
584 // prevents endless loops
585 for b
:= 0 to High(Aliases
[a
].commands
) do
588 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
589 if not RecursionLimitHit
then
590 g_Console_Process(Aliases
[a
].commands
[b
], True);
593 if (RecursionDepth
= 0) and RecursionLimitHit
then
595 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
596 RecursionLimitHit
:= False;
603 g_Console_Add('call <alias name>');
607 procedure WhitelistCommand(cmd
: AnsiString);
611 SetLength(Whitelist
, Length(Whitelist
)+1);
612 a
:= High(Whitelist
);
613 Whitelist
[a
] := LowerCase(cmd
);
616 procedure segfault (p
: SSArray
);
623 function GetCommandString (p
: SSArray
): AnsiString;
627 if Length(p
) >= 1 then
630 for i
:= 1 to High(p
) do
631 result
:= result
+ '; ' + p
[i
]
635 procedure BindCommands (p
: SSArray
);
636 var cmd
, key
: AnsiString; i
: Integer;
638 cmd
:= LowerCase(p
[0]);
641 // bind <key> [down [up]]
642 if (Length(p
) >= 2) and (Length(p
) <= 4) then
645 key
:= LowerCase(p
[1]);
646 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
647 if i
< e_MaxInputKeys
then
649 if Length(p
) = 2 then
650 g_Console_Add('"' + e_KeyNames
[i
] + '" = "' + GetCommandString(gInputBinds
[i
].down
) + '" "' + GetCommandString(gInputBinds
[i
].up
) + '"')
651 else if Length(p
) = 3 then
652 g_Console_BindKey(i
, p
[2], '')
654 g_Console_BindKey(i
, p
[2], p
[3])
657 g_Console_Add('bind: "' + p
[1] + '" is not a key')
661 g_Console_Add('bind <key> <down action> [up action]')
664 for i
:= 0 to e_MaxInputKeys
- 1 do
665 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
666 g_Console_Add(e_KeyNames
[i
] + ' "' + GetCommandString(gInputBinds
[i
].down
) + '" "' + GetCommandString(gInputBinds
[i
].up
) + '"');
669 if Length(p
) = 2 then
671 key
:= LowerCase(p
[1]);
673 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
674 if i
< e_MaxInputKeys
then
675 g_Console_BindKey(i
, '')
677 g_Console_Add('unbind: "' + p
[1] + '" is not a key')
680 g_Console_Add('unbind <key>');
682 for i
:= 0 to e_MaxInputKeys
- 1 do
683 g_Console_BindKey(i
, '');
685 g_Touch_ShowKeyboard(True);
687 g_Touch_ShowKeyboard(False);
702 gSkipFirstChar
:= g_Console_Interactive();
706 if not gConsoleShow
and (g_ActiveWindow
= nil) then
707 g_Console_Chat_Switch
;
708 gSkipFirstChar
:= not g_Console_Interactive()
711 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
713 if not gConsoleShow
and (g_ActiveWindow
= nil) then
714 g_Console_Chat_Switch(True);
715 gSkipFirstChar
:= not g_Console_Interactive()
720 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
725 SetLength(commands
, Length(commands
)+1);
728 cp
.cmd
:= LowerCase(cmd
);
732 cp
.hidden
:= ahidden
;
740 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
742 PrefixList
: array [0..1] of AnsiString = ('+', '-');
743 PlayerList
: array [0..1] of Integer = (1, 2);
748 procedure NewAction (cmd
: AnsiString; player
: Integer);
751 SetLength(commands
, Length(commands
) + 1);
752 cp
:= @commands
[High(commands
)];
753 cp
.cmd
:= LowerCase(cmd
);
766 ASSERT(action
>= FIRST_ACTION
);
767 ASSERT(action
<= LAST_ACTION
);
768 for s
in PrefixList
do
770 NewAction(s
+ cmd
, 0);
771 for i
in PlayerList
do
772 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
776 procedure g_Console_Init();
780 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
781 Cons_Y
:= -(gScreenHeight
div 2);
782 gConsoleShow
:= False;
787 for a
:= 0 to High(MsgArray
) do
794 AddCommand('segfault', segfault
, 'make segfault');
796 AddCommand('bind', BindCommands
);
797 AddCommand('bindlist', BindCommands
);
798 AddCommand('unbind', BindCommands
);
799 AddCommand('unbindall', BindCommands
);
800 AddCommand('showkeyboard', BindCommands
);
801 AddCommand('hidekeyboard', BindCommands
);
802 AddCommand('togglemenu', BindCommands
);
803 AddCommand('toggleconsole', BindCommands
);
804 AddCommand('togglechat', BindCommands
);
805 AddCommand('toggleteamchat', BindCommands
);
807 AddCommand('clear', ConsoleCommands
, 'clear console');
808 AddCommand('clearhistory', ConsoleCommands
);
809 AddCommand('showhistory', ConsoleCommands
);
810 AddCommand('commands', ConsoleCommands
);
811 AddCommand('time', ConsoleCommands
);
812 AddCommand('date', ConsoleCommands
);
813 AddCommand('echo', ConsoleCommands
);
814 AddCommand('dump', ConsoleCommands
);
815 AddCommand('exec', ConsoleCommands
);
816 AddCommand('writeconfig', ConsoleCommands
);
817 AddCommand('alias', ConsoleCommands
);
818 AddCommand('call', ConsoleCommands
);
819 AddCommand('ver', ConsoleCommands
);
820 AddCommand('version', ConsoleCommands
);
822 AddCommand('d_window', DebugCommands
);
823 AddCommand('d_sounds', DebugCommands
);
824 AddCommand('d_frames', DebugCommands
);
825 AddCommand('d_winmsg', DebugCommands
);
826 AddCommand('d_monoff', DebugCommands
);
827 AddCommand('d_botoff', DebugCommands
);
828 AddCommand('d_monster', DebugCommands
);
829 AddCommand('d_health', DebugCommands
);
830 AddCommand('d_player', DebugCommands
);
831 AddCommand('d_joy', DebugCommands
);
832 AddCommand('d_mem', DebugCommands
);
834 AddCommand('p1_name', GameCVars
);
835 AddCommand('p2_name', GameCVars
);
836 AddCommand('p1_color', GameCVars
);
837 AddCommand('p2_color', GameCVars
);
838 AddCommand('r_showscore', GameCVars
);
839 AddCommand('r_showlives', GameCVars
);
840 AddCommand('r_showstat', GameCVars
);
841 AddCommand('r_showkillmsg', GameCVars
);
842 AddCommand('r_showspect', GameCVars
);
843 AddCommand('r_showping', GameCVars
);
844 AddCommand('g_gamemode', GameCVars
);
845 AddCommand('g_friendlyfire', GameCVars
);
846 AddCommand('g_weaponstay', GameCVars
);
847 AddCommand('g_allow_exit', GameCVars
);
848 AddCommand('g_allow_monsters', GameCVars
);
849 AddCommand('g_bot_vsmonsters', GameCVars
);
850 AddCommand('g_bot_vsplayers', GameCVars
);
851 AddCommand('g_scorelimit', GameCVars
);
852 AddCommand('g_timelimit', GameCVars
);
853 AddCommand('g_maxlives', GameCVars
);
854 AddCommand('g_warmuptime', GameCVars
);
855 AddCommand('net_interp', GameCVars
);
856 AddCommand('net_forceplayerupdate', GameCVars
);
857 AddCommand('net_predictself', GameCVars
);
858 AddCommand('sv_name', GameCVars
);
859 AddCommand('sv_passwd', GameCVars
);
860 AddCommand('sv_maxplrs', GameCVars
);
861 AddCommand('sv_public', GameCVars
);
862 AddCommand('sv_intertime', GameCVars
);
864 AddCommand('quit', GameCommands
);
865 AddCommand('exit', GameCommands
);
866 AddCommand('pause', GameCommands
);
867 AddCommand('endgame', GameCommands
);
868 AddCommand('restart', GameCommands
);
869 AddCommand('addbot', GameCommands
);
870 AddCommand('bot_add', GameCommands
);
871 AddCommand('bot_addlist', GameCommands
);
872 AddCommand('bot_addred', GameCommands
);
873 AddCommand('bot_addblue', GameCommands
);
874 AddCommand('bot_removeall', GameCommands
);
875 AddCommand('chat', GameCommands
);
876 AddCommand('teamchat', GameCommands
);
877 AddCommand('game', GameCommands
);
878 AddCommand('host', GameCommands
);
879 AddCommand('map', GameCommands
);
880 AddCommand('nextmap', GameCommands
);
881 AddCommand('endmap', GameCommands
);
882 AddCommand('goodbye', GameCommands
);
883 AddCommand('suicide', GameCommands
);
884 AddCommand('spectate', GameCommands
);
885 AddCommand('ready', GameCommands
);
886 AddCommand('kick', GameCommands
);
887 AddCommand('kick_id', GameCommands
);
888 AddCommand('ban', GameCommands
);
889 AddCommand('permban', GameCommands
);
890 AddCommand('ban_id', GameCommands
);
891 AddCommand('permban_id', GameCommands
);
892 AddCommand('unban', GameCommands
);
893 AddCommand('connect', GameCommands
);
894 AddCommand('disconnect', GameCommands
);
895 AddCommand('reconnect', GameCommands
);
896 AddCommand('say', GameCommands
);
897 AddCommand('tell', GameCommands
);
898 AddCommand('overtime', GameCommands
);
899 AddCommand('rcon_password', GameCommands
);
900 AddCommand('rcon', GameCommands
);
901 AddCommand('callvote', GameCommands
);
902 AddCommand('vote', GameCommands
);
903 AddCommand('clientlist', GameCommands
);
904 AddCommand('event', GameCommands
);
905 AddCommand('screenshot', GameCommands
);
906 AddCommand('weapon', GameCommands
);
907 AddCommand('p1_weapon', GameCommands
);
908 AddCommand('p2_weapon', GameCommands
);
910 AddCommand('god', GameCheats
);
911 AddCommand('notarget', GameCheats
);
912 AddCommand('give', GameCheats
); // "exit" too ;-)
913 AddCommand('open', GameCheats
);
914 AddCommand('fly', GameCheats
);
915 AddCommand('noclip', GameCheats
);
916 AddCommand('speedy', GameCheats
);
917 AddCommand('jumpy', GameCheats
);
918 AddCommand('noreload', GameCheats
);
919 AddCommand('aimline', GameCheats
);
920 AddCommand('automap', GameCheats
);
922 AddAction('jump', ACTION_JUMP
);
923 AddAction('moveleft', ACTION_MOVELEFT
);
924 AddAction('moveright', ACTION_MOVERIGHT
);
925 AddAction('lookup', ACTION_LOOKUP
);
926 AddAction('lookdown', ACTION_LOOKDOWN
);
927 AddAction('attack', ACTION_ATTACK
);
928 AddAction('scores', ACTION_SCORES
);
929 AddAction('activate', ACTION_ACTIVATE
);
930 AddAction('strafe', ACTION_STRAFE
);
931 AddAction('weapnext', ACTION_WEAPNEXT
);
932 AddAction('weapprev', ACTION_WEAPPREV
);
934 WhitelistCommand('say');
935 WhitelistCommand('tell');
936 WhitelistCommand('overtime');
937 WhitelistCommand('ready');
938 WhitelistCommand('map');
939 WhitelistCommand('nextmap');
940 WhitelistCommand('endmap');
941 WhitelistCommand('restart');
942 WhitelistCommand('kick');
943 WhitelistCommand('ban');
945 WhitelistCommand('addbot');
946 WhitelistCommand('bot_add');
947 WhitelistCommand('bot_addred');
948 WhitelistCommand('bot_addblue');
949 WhitelistCommand('bot_removeall');
951 WhitelistCommand('g_gamemode');
952 WhitelistCommand('g_friendlyfire');
953 WhitelistCommand('g_weaponstay');
954 WhitelistCommand('g_allow_exit');
955 WhitelistCommand('g_allow_monsters');
956 WhitelistCommand('g_scorelimit');
957 WhitelistCommand('g_timelimit');
959 gParsingBinds
:= True;
960 g_Console_ResetBinds
;
961 g_Console_ReadConfig(GameDir
+ '/dfconfig.cfg');
962 g_Console_ReadConfig(GameDir
+ '/autoexec.cfg');
963 gParsingBinds
:= False;
965 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
969 procedure g_Console_Update();
975 // Â ïðîöåññå îòêðûòèÿ:
976 if gConsoleShow
and (Cons_Y
< 0) then
978 Cons_Y
:= Cons_Y
+Step
;
981 // Â ïðîöåññå çàêðûòèÿ:
982 if (not gConsoleShow
) and
983 (Cons_Y
> -(gScreenHeight
div 2)) then
984 Cons_Y
:= Cons_Y
-Step
;
986 // Îêîí÷àòåëüíî îòêðûëàñü:
990 // Îêîí÷àòåëüíî çàêðûëàñü:
991 if Cons_Y
<= (-(gScreenHeight
div 2)) then
993 Cons_Y
:= -(gScreenHeight
div 2);
999 while a
<= High(MsgArray
) do
1001 if MsgArray
[a
].Time
> 0 then
1003 if MsgArray
[a
].Time
= 1 then
1005 if a
< High(MsgArray
) then
1007 for b
:= a
to High(MsgArray
)-1 do
1008 MsgArray
[b
] := MsgArray
[b
+1];
1010 MsgArray
[High(MsgArray
)].Time
:= 0;
1016 Dec(MsgArray
[a
].Time
);
1024 procedure drawConsoleText ();
1026 CWidth
, CHeight
: Byte;
1031 procedure putLine (sp
, ep
: LongWord);
1040 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1041 if wdt
+cw
> gScreenWidth
-8 then break
;
1042 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1046 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1047 // now print our part
1055 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1056 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1069 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1070 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
1071 skip
:= conSkipLines
;
1072 cbufLastLine(sp
, ep
);
1075 if ty
+CHeight
<= 0 then break
;
1076 until not cbufLineUp(sp
, ep
);
1079 procedure g_Console_Draw();
1081 CWidth
, CHeight
: Byte;
1085 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1087 for a
:= 0 to High(MsgArray
) do
1088 if MsgArray
[a
].Time
> 0 then
1089 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
1092 if not Cons_Shown
then
1098 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
1099 gStdFont
, 255, 255, 255, 1, True);
1100 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1101 gStdFont
, 255, 255, 255, 1, True);
1105 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
1106 gStdFont
, 255, 255, 255, 1, True);
1107 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1108 gStdFont
, 255, 255, 255, 1, True);
1116 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1117 a
:= (gScreenWidth
- 2*mfW
) div 2;
1118 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
1119 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1120 _RGB(128, 0, 0), 2.0);
1123 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
1124 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
1128 if ConsoleHistory <> nil then
1132 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
1133 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
1135 b := Max(b-Offset, 0);
1136 d := Max(High(ConsoleHistory)-Offset, 0);
1139 for a := d downto b do
1141 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
1148 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
1151 procedure g_Console_Char(C
: AnsiChar);
1153 if not gSkipFirstChar
then
1155 Insert(C
, Line
, CPos
);
1158 gSkipFirstChar
:= False
1163 tcomplist
: array of AnsiString = nil;
1164 tcompidx
: array of Integer = nil;
1166 procedure Complete ();
1170 ll
, lpfx
, cmd
: AnsiString;
1172 if (Length(Line
) = 0) then
1175 for i
:= 0 to High(commands
) do
1177 // hidden commands are hidden when cheats aren't enabled
1178 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1179 if (Length(commands
[i
].help
) > 0) then
1181 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1185 g_Console_Add(' '+commands
[i
].cmd
);
1191 ll
:= LowerCase(Line
);
1194 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1196 ll
:= Copy(ll
, 0, Length(ll
)-1);
1197 for i
:= 0 to High(commands
) do
1199 // hidden commands are hidden when cheats aren't enabled
1200 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1201 if (commands
[i
].cmd
= ll
) then
1203 if (Length(commands
[i
].help
) > 0) then
1205 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1212 // build completion list
1214 for i
:= 0 to High(commands
) do
1216 // hidden commands are hidden when cheats aren't enabled
1217 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1218 cmd
:= commands
[i
].cmd
;
1219 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1221 if (tused
= Length(tcomplist
)) then
1223 SetLength(tcomplist
, Length(tcomplist
)+128);
1224 SetLength(tcompidx
, Length(tcompidx
)+128);
1226 tcomplist
[tused
] := cmd
;
1227 tcompidx
[tused
] := i
;
1229 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1233 // get longest prefix
1234 for i
:= 0 to tused
-1 do
1236 cmd
:= tcomplist
[i
];
1237 for c
:= 1 to Length(lpfx
) do
1239 if (c
> Length(cmd
)) then break
;
1240 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1244 if (tused
= 0) then exit
;
1248 Line
:= tcomplist
[0]+' ';
1249 CPos
:= Length(Line
)+1;
1253 // has longest prefix?
1254 if (Length(lpfx
) > Length(ll
)) then
1257 CPos
:= Length(Line
)+1;
1262 for i
:= 0 to tused
-1 do
1264 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1266 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1270 g_Console_Add(' '+tcomplist
[i
]);
1278 procedure g_Console_Control(K
: Word);
1282 if (Length(Line
) > 0) and (CPos
> 1) then
1284 Delete(Line
, CPos
-1, 1);
1288 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1289 Delete(Line
, CPos
, 1);
1290 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1293 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1294 if CPos
<= Length(Line
) then
1296 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1299 g_Console_Process(Line
)
1303 if (Length(Line
) > 0) and g_Game_IsNet
then
1307 if g_Game_IsClient
then
1308 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1310 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1311 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1315 if g_Game_IsClient
then
1316 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1318 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1326 gJustChatted
:= True;
1327 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1331 if not gChatShow
then
1333 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1334 if not gChatShow
then
1335 if (CommandHistory
<> nil) and
1336 (CmdIndex
< Length(CommandHistory
)) then
1338 if CmdIndex
< Length(CommandHistory
)-1 then
1339 CmdIndex
:= CmdIndex
+ 1;
1340 Line
:= CommandHistory
[CmdIndex
];
1341 CPos
:= Length(Line
) + 1;
1343 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1344 if not gChatShow
then
1345 if (CommandHistory
<> nil) and
1346 (CmdIndex
<= Length(CommandHistory
)) then
1348 if CmdIndex
> 0 then
1349 CmdIndex
:= CmdIndex
- 1;
1350 Line
:= CommandHistory
[CmdIndex
];
1351 Cpos
:= Length(Line
) + 1;
1353 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1354 if not gChatShow
then Inc(conSkipLines
);
1355 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1356 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1360 CPos
:= Length(Line
) + 1;
1361 IK_A
..IK_Z
, IK_SPACE
, IK_SHIFT
, IK_RSHIFT
, IK_CAPSLOCK
, IK_LBRACKET
, IK_RBRACKET
,
1362 IK_SEMICOLON
, IK_QUOTE
, IK_BACKSLASH
, IK_SLASH
, IK_COMMA
, IK_DOT
, IK_EQUALS
,
1363 IK_0
, IK_1
, IK_2
, IK_3
, IK_4
, IK_5
, IK_6
, IK_7
, IK_8
, IK_9
, IK_MINUS
, IK_EQUALS
:
1364 (* see TEXTINPUT event *)
1366 if not gSkipFirstChar
then
1368 if gConsoleShow
and g_Console_MatchBind(K
, 'toggleconsole') then
1371 if g_Console_MatchBind(K
, 'togglemenu') then
1373 menu_toggled
:= True;
1375 g_Console_Chat_Switch
1376 else if gConsoleShow
then
1383 function GetStr(var Str
: AnsiString): AnsiString;
1388 if Str
[1] = '"' then
1390 for b
:= 1 to Length(Str
) do
1391 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1393 Result
:= Copy(Str
, 2, b
-1);
1394 Delete(Str
, 1, b
+1);
1400 for a
:= 1 to Length(Str
) do
1401 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1403 Result
:= Copy(Str
, 1, a
);
1404 Delete(Str
, 1, a
+1);
1410 function ParseString(Str
: AnsiString): SSArray
;
1421 SetLength(Result
, Length(Result
)+1);
1422 Result
[High(Result
)] := GetStr(Str
);
1426 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1428 procedure conmsg (s
: AnsiString);
1432 if length(s
) = 0 then exit
;
1433 for a
:= 0 to High(MsgArray
) do
1445 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1446 with MsgArray
[High(MsgArray
)] do
1456 // put it to console
1458 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1460 // now show 'em out of console too
1461 show
:= show
and gAllowConsoleMessages
;
1462 if show
and gShowMessages
then
1464 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1465 while length(L
) > 0 do
1468 if f
<= 0 then f
:= length(L
)+1;
1469 conmsg(Copy(L
, 1, f
-1));
1474 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1475 //ConsoleHistory[High(ConsoleHistory)] := L;
1479 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1486 consolewriterLastWasEOL
: Boolean = false;
1488 procedure consolewriter (constref buf
; len
: SizeUInt
);
1492 if (len
< 1) then exit
;
1494 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1497 if (b
[0] <> 13) and (b
[0] <> 10) then
1499 cbufPut(AnsiChar(b
[0]));
1503 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1512 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1513 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1514 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1515 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1517 g_Console_Add(s
, show
);
1521 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1525 g_Console_Add(formatstrf(s
, args
), true);
1529 consolewriterLastWasEOL
:= false;
1530 formatstrf(s
, args
, consolewriter
);
1531 if not consolewriterLastWasEOL
then cbufPut(#10);
1536 procedure g_Console_Clear();
1538 //ConsoleHistory := nil;
1543 procedure AddToHistory(L
: AnsiString);
1547 len
:= Length(CommandHistory
);
1550 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1552 SetLength(CommandHistory
, len
+1);
1553 CommandHistory
[len
] := L
;
1556 CmdIndex
:= Length(CommandHistory
);
1559 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1568 if Trim(C
) = '' then
1571 Arr
:= ParseString(C
);
1575 for i
:= 0 to High(Whitelist
) do
1576 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1580 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1587 if Trim(L
) = '' then
1590 conSkipLines
:= 0; // "unscroll"
1592 if L
= 'goobers' then
1597 g_Console_Add('Your memory serves you well.');
1603 g_Console_Add('> '+L
);
1608 Arr
:= ParseString(L
);
1612 if commands
= nil then
1618 for i
:= 0 to High(commands
) do
1620 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1622 if commands
[i
].action
>= 0 then
1624 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1627 if assigned(commands
[i
].procEx
) then
1629 commands
[i
].procEx(@commands
[i
], Arr
);
1632 if assigned(commands
[i
].proc
) then
1634 commands
[i
].proc(Arr
);
1640 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1644 function g_Console_Interactive
: Boolean;
1646 Result
:= gConsoleShow
1649 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1651 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1653 ASSERT(key
< e_MaxInputKeys
);
1656 gInputBinds
[key
].down
:= ParseAlias(down
);
1657 gInputBinds
[key
].up
:= ParseAlias(up
);
1659 g_Console_WriteGameConfig();
1662 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
1664 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1665 var i
, len
: Integer;
1669 if len
= Length(b
) then
1672 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1680 ASSERT(key
< e_MaxInputKeys
);
1681 result
:= EqualsCommandLists(ParseAlias(down
), gInputBinds
[key
].down
) and EqualsCommandLists(ParseAlias(up
), gInputBinds
[key
].up
)
1684 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1689 if commands
= nil then Exit
;
1691 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1693 if g_Console_MatchBind(i
, down
, up
) then
1704 function g_Console_Action (action
: Integer): Boolean;
1705 var i
, len
: Integer;
1707 ASSERT(action
>= FIRST_ACTION
);
1708 ASSERT(action
<= LAST_ACTION
);
1710 len
:= Length(gPlayerAction
);
1711 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1715 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1718 if (not g_GUIGrabInput
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1722 if not gChatShow
then
1723 for i
:= 0 to High(gInputBinds
[key
].down
) do
1724 g_Console_Process(gInputBinds
[key
].down
[i
], True);
1727 for i
:= 0 to High(gInputBinds
[key
].up
) do
1728 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1730 if down
and not menu_toggled
then
1732 menu_toggled
:= False
1735 procedure g_Console_ResetBinds
;
1738 for i
:= 0 to e_MaxInputKeys
- 1 do
1739 g_Console_BindKey(i
, '', '');
1741 g_Console_BindKey(IK_GRAVE
, 'toggleconsole');
1742 g_Console_BindKey(IK_ESCAPE
, 'togglemenu');
1743 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1744 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1745 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1746 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1747 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1748 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1749 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1750 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1751 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1752 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1753 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1754 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1755 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1756 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1757 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1758 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1759 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1760 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1761 g_Console_BindKey(IK_9
, 'p1_weapon 9');
1762 g_Console_BindKey(IK_0
, 'p1_weapon 10');
1763 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
1764 g_Console_BindKey(IK_T
, 'togglechat');
1765 g_Console_BindKey(IK_Y
, 'toggleteamchat');
1766 g_Console_BindKey(IK_F11
, 'screenshot');
1767 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
1768 g_Console_BindKey(IK_PAUSE
, 'pause');
1769 g_Console_BindKey(IK_F1
, 'vote');
1771 (* for i := 0 to e_MaxJoys - 1 do *)
1774 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_LEFT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
1775 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_RIGHT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
1776 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_UP
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
1777 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_DOWN
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
1778 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
1779 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
1780 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
1781 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
1782 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
1783 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
1784 g_Console_BindKey(e_JoyButtonToKey(i
, 10), 'togglemenu');
1787 g_Console_BindKey(VK_ESCAPE
, 'togglemenu');
1788 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
1789 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
1790 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
1791 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
1792 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
1793 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
1794 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
1795 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
1796 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
1797 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
1798 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
1799 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
1800 g_Console_BindKey(VK_0
, 'weapon 1');
1801 g_Console_BindKey(VK_1
, 'weapon 2');
1802 g_Console_BindKey(VK_2
, 'weapon 3');
1803 g_Console_BindKey(VK_3
, 'weapon 4');
1804 g_Console_BindKey(VK_4
, 'weapon 5');
1805 g_Console_BindKey(VK_5
, 'weapon 6');
1806 g_Console_BindKey(VK_6
, 'weapon 7');
1807 g_Console_BindKey(VK_7
, 'weapon 8');
1808 g_Console_BindKey(VK_8
, 'weapon 9');
1809 g_Console_BindKey(VK_9
, 'weapon 10');
1810 g_Console_BindKey(VK_A
, 'weapon 11');
1811 g_Console_BindKey(VK_CHAT
, 'togglechat');
1812 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
1813 g_Console_BindKey(VK_CONSOLE
, 'toggleconsole');
1814 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
1815 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
1816 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
1817 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
1820 procedure g_Console_ReadConfig (filename
: String);
1821 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1823 if FileExists(filename
) then
1825 AssignFile(f
, filename
);
1835 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1837 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1838 g_Console_Process(s
, True);
1845 procedure g_Console_WriteConfig (filename
: String);
1846 var f
: TextFile
; i
, j
: Integer;
1848 AssignFile(f
, filename
);
1850 WriteLn(f
, '// generated by doom2d, do not modify');
1851 WriteLn(f
, 'unbindall');
1852 for i
:= 0 to e_MaxInputKeys
- 1 do
1853 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
1854 WriteLn(f
, 'bind ', e_KeyNames
[i
], ' "', GetCommandString(gInputBinds
[i
].down
), '" "', GetCommandString(gInputBinds
[i
].up
), '"');
1855 for i
:= 0 to High(commands
) do
1857 if not commands
[i
].cheat
then
1859 if @commands
[i
].procEx
= @boolVarHandler
then
1861 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
1862 WriteLn(f
, commands
[i
].cmd
, ' "', j
, '"')
1864 else if @commands
[i
].procEx
= @intVarHandler
then
1866 WriteLn(f
, commands
[i
].cmd
, ' "', PInteger(commands
[i
].ptr
)^, '"')
1868 else if @commands
[i
].procEx
= @singleVarHandler
then
1870 WriteLn(f
, commands
[i
].cmd
, ' "', PVarSingle(commands
[i
].ptr
).val
^:0:6, '"')
1877 procedure g_Console_WriteGameConfig
;
1879 if gParsingBinds
then
1881 g_Console_WriteConfig(GameDir
+ '/dfconfig.cfg');