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);
228 if (Length(p
) > 2) then
230 conwritefln('too many arguments to ''%s''', [p
[0]]);
235 case conGetBoolArg(p
, 1) of
237 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
238 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
239 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
242 g_Console_WriteGameConfig();
243 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
244 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
248 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
252 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
256 if (Length(p
) <> 2) then
258 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
263 old
:= PInteger(me
.ptr
)^;
264 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
265 if PInteger(me
.ptr
)^ <> old
then
266 g_Console_WriteGameConfig();
268 conwritefln('invalid integer value: "%s"', [p
[1]]);
274 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
279 f
:= Length(commands
);
280 SetLength(commands
, f
+1);
282 cp
.cmd
:= LowerCase(conname
);
284 cp
.procEx
:= boolVarHandler
;
286 cp
.hidden
:= ahidden
;
295 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
300 f
:= Length(commands
);
301 SetLength(commands
, f
+1);
303 cp
.cmd
:= LowerCase(conname
);
305 cp
.procEx
:= intVarHandler
;
307 cp
.hidden
:= ahidden
;
316 // ////////////////////////////////////////////////////////////////////////// //
318 PVarSingle
= ^TVarSingle
;
321 min
, max
, def
: Single; // default will be starting value
325 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
331 if (Length(p
) > 2) then
333 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
336 pv
:= PVarSingle(me
.ptr
);
338 if (Length(p
) = 2) then
340 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
341 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
342 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
343 (CompareText(p
[1], 'ona') = 0) then
349 if not conParseFloat(nv
, p
[1]) then
351 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
354 if (nv
< pv
.min
) then nv
:= pv
.min
;
355 if (nv
> pv
.max
) then nv
:= pv
.max
;
359 if pv
.val
^ <> old
then
360 g_Console_WriteGameConfig();
362 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
363 conwritefln('%s %s', [msg
, pv
.val
^]);
367 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
373 GetMem(pv
, sizeof(TVarSingle
));
378 f
:= Length(commands
);
379 SetLength(commands
, f
+1);
381 cp
.cmd
:= LowerCase(conname
);
383 cp
.procEx
:= singleVarHandler
;
385 cp
.hidden
:= ahidden
;
394 // ////////////////////////////////////////////////////////////////////////// //
395 function GetStrACmd(var Str
: AnsiString): AnsiString;
400 for a
:= 1 to Length(Str
) do
401 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
403 Result
:= Copy(Str
, 1, a
);
410 function ParseAlias(Str
: AnsiString): SSArray
;
421 SetLength(Result
, Length(Result
)+1);
422 Result
[High(Result
)] := GetStrACmd(Str
);
426 procedure ConsoleCommands(p
: SSArray
);
432 cmd
:= LowerCase(p
[0]);
435 if cmd
= 'clear' then
437 //ConsoleHistory := nil;
441 for a
:= 0 to High(MsgArray
) do
449 if cmd
= 'clearhistory' then
450 CommandHistory
:= nil;
452 if cmd
= 'showhistory' then
453 if CommandHistory
<> nil then
456 for a
:= 0 to High(CommandHistory
) do
457 g_Console_Add(' '+CommandHistory
[a
]);
460 if cmd
= 'commands' then
463 g_Console_Add('commands list:');
464 for a
:= High(commands
) downto 0 do
466 if (Length(commands
[a
].help
) > 0) then
468 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
472 g_Console_Add(' '+commands
[a
].cmd
);
478 g_Console_Add(TimeToStr(Now
), True);
481 g_Console_Add(DateToStr(Now
), True);
484 if Length(p
) > 1 then
486 if p
[1] = 'ololo' then
491 for a
:= 1 to High(p
) do
493 g_Console_Add(b_Text_Format(s
), True);
502 if ConsoleHistory <> nil then
504 if Length(P) > 1 then
507 s := GameDir+'/console.txt';
512 if IOResult <> 0 then
514 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
519 for a := 0 to High(ConsoleHistory) do
520 WriteLn(F, ConsoleHistory[a]);
523 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
532 if Length(p
) = 2 then
533 g_Console_ReadConfig(GameDir
+ '/' + p
[1])
535 g_Console_Add('exec <script file>');
538 if cmd
= 'writeconfig' then
540 // writeconfig <filename>
541 if Length(p
) = 2 then
542 g_Console_WriteConfig(GameDir
+ '/' + p
[1])
544 g_Console_Add('writeconfig <file>');
547 if (cmd
= 'ver') or (cmd
= 'version') then
549 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
550 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
551 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
554 if cmd
= 'alias' then
556 // alias [alias_name] [commands]
557 if Length(p
) > 1 then
559 for a
:= 0 to High(Aliases
) do
560 if Aliases
[a
].name
= p
[1] then
562 if Length(p
) > 2 then
563 Aliases
[a
].commands
:= ParseAlias(p
[2])
565 for b
:= 0 to High(Aliases
[a
].commands
) do
566 g_Console_Add(Aliases
[a
].commands
[b
]);
569 SetLength(Aliases
, Length(Aliases
)+1);
571 Aliases
[a
].name
:= p
[1];
572 if Length(p
) > 2 then
573 Aliases
[a
].commands
:= ParseAlias(p
[2])
575 for b
:= 0 to High(Aliases
[a
].commands
) do
576 g_Console_Add(Aliases
[a
].commands
[b
]);
578 for a
:= 0 to High(Aliases
) do
579 if Aliases
[a
].commands
<> nil then
580 g_Console_Add(Aliases
[a
].name
);
586 if Length(p
) > 1 then
588 if Aliases
= nil then
590 for a
:= 0 to High(Aliases
) do
591 if Aliases
[a
].name
= p
[1] then
593 if Aliases
[a
].commands
<> nil then
595 // with this system proper endless loop detection seems either impossible
596 // or very dirty to implement, so let's have this instead
597 // prevents endless loops
598 for b
:= 0 to High(Aliases
[a
].commands
) do
601 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
602 if not RecursionLimitHit
then
603 g_Console_Process(Aliases
[a
].commands
[b
], True);
606 if (RecursionDepth
= 0) and RecursionLimitHit
then
608 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
609 RecursionLimitHit
:= False;
616 g_Console_Add('call <alias name>');
620 procedure WhitelistCommand(cmd
: AnsiString);
624 SetLength(Whitelist
, Length(Whitelist
)+1);
625 a
:= High(Whitelist
);
626 Whitelist
[a
] := LowerCase(cmd
);
629 procedure segfault (p
: SSArray
);
636 function GetCommandString (p
: SSArray
): AnsiString;
640 if Length(p
) >= 1 then
643 for i
:= 1 to High(p
) do
644 result
:= result
+ '; ' + p
[i
]
648 function QuoteStr(str
: String): String;
650 if Pos(' ', str
) > 0 then
651 Result
:= '"' + str
+ '"'
656 procedure BindCommands (p
: SSArray
);
657 var cmd
, key
: AnsiString; i
: Integer;
659 cmd
:= LowerCase(p
[0]);
662 // bind <key> [down [up]]
663 if (Length(p
) >= 2) and (Length(p
) <= 4) then
666 key
:= LowerCase(p
[1]);
667 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
668 if i
< e_MaxInputKeys
then
670 if Length(p
) = 2 then
671 g_Console_Add(QuoteStr(e_KeyNames
[i
]) + ' = ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)))
672 else if Length(p
) = 3 then
673 g_Console_BindKey(i
, p
[2], '')
675 g_Console_BindKey(i
, p
[2], p
[3])
678 g_Console_Add('bind: "' + p
[1] + '" is not a key')
682 g_Console_Add('bind <key> <down action> [up action]')
685 for i
:= 0 to e_MaxInputKeys
- 1 do
686 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
687 g_Console_Add(e_KeyNames
[i
] + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
690 if Length(p
) = 2 then
692 key
:= LowerCase(p
[1]);
694 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
695 if i
< e_MaxInputKeys
then
696 g_Console_BindKey(i
, '')
698 g_Console_Add('unbind: "' + p
[1] + '" is not a key')
701 g_Console_Add('unbind <key>');
703 for i
:= 0 to e_MaxInputKeys
- 1 do
704 g_Console_BindKey(i
, '');
706 g_Touch_ShowKeyboard(True);
708 g_Touch_ShowKeyboard(False);
723 gSkipFirstChar
:= g_Console_Interactive();
727 if not gConsoleShow
and (g_ActiveWindow
= nil) then
728 g_Console_Chat_Switch
;
729 gSkipFirstChar
:= not g_Console_Interactive()
732 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
734 if not gConsoleShow
and (g_ActiveWindow
= nil) then
735 g_Console_Chat_Switch(True);
736 gSkipFirstChar
:= not g_Console_Interactive()
741 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
746 SetLength(commands
, Length(commands
)+1);
749 cp
.cmd
:= LowerCase(cmd
);
753 cp
.hidden
:= ahidden
;
761 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
763 PrefixList
: array [0..1] of AnsiString = ('+', '-');
764 PlayerList
: array [0..1] of Integer = (1, 2);
769 procedure NewAction (cmd
: AnsiString; player
: Integer);
772 SetLength(commands
, Length(commands
) + 1);
773 cp
:= @commands
[High(commands
)];
774 cp
.cmd
:= LowerCase(cmd
);
787 ASSERT(action
>= FIRST_ACTION
);
788 ASSERT(action
<= LAST_ACTION
);
789 for s
in PrefixList
do
791 NewAction(s
+ cmd
, 0);
792 for i
in PlayerList
do
793 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
797 procedure g_Console_Init();
801 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
802 Cons_Y
:= -(gScreenHeight
div 2);
803 gConsoleShow
:= False;
808 for a
:= 0 to High(MsgArray
) do
815 AddCommand('segfault', segfault
, 'make segfault');
817 AddCommand('bind', BindCommands
);
818 AddCommand('bindlist', BindCommands
);
819 AddCommand('unbind', BindCommands
);
820 AddCommand('unbindall', BindCommands
);
821 AddCommand('showkeyboard', BindCommands
);
822 AddCommand('hidekeyboard', BindCommands
);
823 AddCommand('togglemenu', BindCommands
);
824 AddCommand('toggleconsole', BindCommands
);
825 AddCommand('togglechat', BindCommands
);
826 AddCommand('toggleteamchat', BindCommands
);
828 AddCommand('clear', ConsoleCommands
, 'clear console');
829 AddCommand('clearhistory', ConsoleCommands
);
830 AddCommand('showhistory', ConsoleCommands
);
831 AddCommand('commands', ConsoleCommands
);
832 AddCommand('time', ConsoleCommands
);
833 AddCommand('date', ConsoleCommands
);
834 AddCommand('echo', ConsoleCommands
);
835 AddCommand('dump', ConsoleCommands
);
836 AddCommand('exec', ConsoleCommands
);
837 AddCommand('writeconfig', ConsoleCommands
);
838 AddCommand('alias', ConsoleCommands
);
839 AddCommand('call', ConsoleCommands
);
840 AddCommand('ver', ConsoleCommands
);
841 AddCommand('version', ConsoleCommands
);
843 AddCommand('d_window', DebugCommands
);
844 AddCommand('d_sounds', DebugCommands
);
845 AddCommand('d_frames', DebugCommands
);
846 AddCommand('d_winmsg', DebugCommands
);
847 AddCommand('d_monoff', DebugCommands
);
848 AddCommand('d_botoff', DebugCommands
);
849 AddCommand('d_monster', DebugCommands
);
850 AddCommand('d_health', DebugCommands
);
851 AddCommand('d_player', DebugCommands
);
852 AddCommand('d_joy', DebugCommands
);
853 AddCommand('d_mem', DebugCommands
);
855 AddCommand('p1_name', GameCVars
);
856 AddCommand('p2_name', GameCVars
);
857 AddCommand('p1_color', GameCVars
);
858 AddCommand('p2_color', GameCVars
);
859 AddCommand('r_showscore', GameCVars
);
860 AddCommand('r_showlives', GameCVars
);
861 AddCommand('r_showstat', GameCVars
);
862 AddCommand('r_showkillmsg', GameCVars
);
863 AddCommand('r_showspect', GameCVars
);
864 AddCommand('r_showping', GameCVars
);
865 AddCommand('g_gamemode', GameCVars
);
866 AddCommand('g_friendlyfire', GameCVars
);
867 AddCommand('g_weaponstay', GameCVars
);
868 AddCommand('g_allow_exit', GameCVars
);
869 AddCommand('g_allow_monsters', GameCVars
);
870 AddCommand('g_bot_vsmonsters', GameCVars
);
871 AddCommand('g_bot_vsplayers', GameCVars
);
872 AddCommand('g_scorelimit', GameCVars
);
873 AddCommand('g_timelimit', GameCVars
);
874 AddCommand('g_maxlives', GameCVars
);
875 AddCommand('g_warmuptime', GameCVars
);
876 AddCommand('net_interp', GameCVars
);
877 AddCommand('net_forceplayerupdate', GameCVars
);
878 AddCommand('net_predictself', GameCVars
);
879 AddCommand('sv_name', GameCVars
);
880 AddCommand('sv_passwd', GameCVars
);
881 AddCommand('sv_maxplrs', GameCVars
);
882 AddCommand('sv_public', GameCVars
);
883 AddCommand('sv_intertime', GameCVars
);
885 AddCommand('quit', GameCommands
);
886 AddCommand('exit', GameCommands
);
887 AddCommand('pause', GameCommands
);
888 AddCommand('endgame', GameCommands
);
889 AddCommand('restart', GameCommands
);
890 AddCommand('addbot', GameCommands
);
891 AddCommand('bot_add', GameCommands
);
892 AddCommand('bot_addlist', GameCommands
);
893 AddCommand('bot_addred', GameCommands
);
894 AddCommand('bot_addblue', GameCommands
);
895 AddCommand('bot_removeall', GameCommands
);
896 AddCommand('chat', GameCommands
);
897 AddCommand('teamchat', GameCommands
);
898 AddCommand('game', GameCommands
);
899 AddCommand('host', GameCommands
);
900 AddCommand('map', GameCommands
);
901 AddCommand('nextmap', GameCommands
);
902 AddCommand('endmap', GameCommands
);
903 AddCommand('goodbye', GameCommands
);
904 AddCommand('suicide', GameCommands
);
905 AddCommand('spectate', GameCommands
);
906 AddCommand('ready', GameCommands
);
907 AddCommand('kick', GameCommands
);
908 AddCommand('kick_id', GameCommands
);
909 AddCommand('ban', GameCommands
);
910 AddCommand('permban', GameCommands
);
911 AddCommand('ban_id', GameCommands
);
912 AddCommand('permban_id', GameCommands
);
913 AddCommand('unban', GameCommands
);
914 AddCommand('connect', GameCommands
);
915 AddCommand('disconnect', GameCommands
);
916 AddCommand('reconnect', GameCommands
);
917 AddCommand('say', GameCommands
);
918 AddCommand('tell', GameCommands
);
919 AddCommand('overtime', GameCommands
);
920 AddCommand('rcon_password', GameCommands
);
921 AddCommand('rcon', GameCommands
);
922 AddCommand('callvote', GameCommands
);
923 AddCommand('vote', GameCommands
);
924 AddCommand('clientlist', GameCommands
);
925 AddCommand('event', GameCommands
);
926 AddCommand('screenshot', GameCommands
);
927 AddCommand('weapon', GameCommands
);
928 AddCommand('p1_weapon', GameCommands
);
929 AddCommand('p2_weapon', GameCommands
);
931 AddCommand('god', GameCheats
);
932 AddCommand('notarget', GameCheats
);
933 AddCommand('give', GameCheats
); // "exit" too ;-)
934 AddCommand('open', GameCheats
);
935 AddCommand('fly', GameCheats
);
936 AddCommand('noclip', GameCheats
);
937 AddCommand('speedy', GameCheats
);
938 AddCommand('jumpy', GameCheats
);
939 AddCommand('noreload', GameCheats
);
940 AddCommand('aimline', GameCheats
);
941 AddCommand('automap', GameCheats
);
943 AddAction('jump', ACTION_JUMP
);
944 AddAction('moveleft', ACTION_MOVELEFT
);
945 AddAction('moveright', ACTION_MOVERIGHT
);
946 AddAction('lookup', ACTION_LOOKUP
);
947 AddAction('lookdown', ACTION_LOOKDOWN
);
948 AddAction('attack', ACTION_ATTACK
);
949 AddAction('scores', ACTION_SCORES
);
950 AddAction('activate', ACTION_ACTIVATE
);
951 AddAction('strafe', ACTION_STRAFE
);
952 AddAction('weapnext', ACTION_WEAPNEXT
);
953 AddAction('weapprev', ACTION_WEAPPREV
);
955 WhitelistCommand('say');
956 WhitelistCommand('tell');
957 WhitelistCommand('overtime');
958 WhitelistCommand('ready');
959 WhitelistCommand('map');
960 WhitelistCommand('nextmap');
961 WhitelistCommand('endmap');
962 WhitelistCommand('restart');
963 WhitelistCommand('kick');
964 WhitelistCommand('ban');
966 WhitelistCommand('addbot');
967 WhitelistCommand('bot_add');
968 WhitelistCommand('bot_addred');
969 WhitelistCommand('bot_addblue');
970 WhitelistCommand('bot_removeall');
972 WhitelistCommand('g_gamemode');
973 WhitelistCommand('g_friendlyfire');
974 WhitelistCommand('g_weaponstay');
975 WhitelistCommand('g_allow_exit');
976 WhitelistCommand('g_allow_monsters');
977 WhitelistCommand('g_scorelimit');
978 WhitelistCommand('g_timelimit');
980 gParsingBinds
:= True;
981 g_Console_ResetBinds
;
982 g_Console_ReadConfig(GameDir
+ '/dfconfig.cfg');
983 g_Console_ReadConfig(GameDir
+ '/autoexec.cfg');
984 gParsingBinds
:= False;
986 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
990 procedure g_Console_Update();
996 // Â ïðîöåññå îòêðûòèÿ:
997 if gConsoleShow
and (Cons_Y
< 0) then
999 Cons_Y
:= Cons_Y
+Step
;
1002 // Â ïðîöåññå çàêðûòèÿ:
1003 if (not gConsoleShow
) and
1004 (Cons_Y
> -(gScreenHeight
div 2)) then
1005 Cons_Y
:= Cons_Y
-Step
;
1007 // Îêîí÷àòåëüíî îòêðûëàñü:
1011 // Îêîí÷àòåëüíî çàêðûëàñü:
1012 if Cons_Y
<= (-(gScreenHeight
div 2)) then
1014 Cons_Y
:= -(gScreenHeight
div 2);
1015 Cons_Shown
:= False;
1020 while a
<= High(MsgArray
) do
1022 if MsgArray
[a
].Time
> 0 then
1024 if MsgArray
[a
].Time
= 1 then
1026 if a
< High(MsgArray
) then
1028 for b
:= a
to High(MsgArray
)-1 do
1029 MsgArray
[b
] := MsgArray
[b
+1];
1031 MsgArray
[High(MsgArray
)].Time
:= 0;
1037 Dec(MsgArray
[a
].Time
);
1045 procedure drawConsoleText ();
1047 CWidth
, CHeight
: Byte;
1052 procedure putLine (sp
, ep
: LongWord);
1061 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1062 if wdt
+cw
> gScreenWidth
-8 then break
;
1063 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1067 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1068 // now print our part
1076 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1077 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1090 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1091 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
1092 skip
:= conSkipLines
;
1093 cbufLastLine(sp
, ep
);
1096 if ty
+CHeight
<= 0 then break
;
1097 until not cbufLineUp(sp
, ep
);
1100 procedure g_Console_Draw();
1102 CWidth
, CHeight
: Byte;
1106 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1108 for a
:= 0 to High(MsgArray
) do
1109 if MsgArray
[a
].Time
> 0 then
1110 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
1113 if not Cons_Shown
then
1119 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
1120 gStdFont
, 255, 255, 255, 1, True);
1121 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1122 gStdFont
, 255, 255, 255, 1, True);
1126 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
1127 gStdFont
, 255, 255, 255, 1, True);
1128 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1129 gStdFont
, 255, 255, 255, 1, True);
1137 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1138 a
:= (gScreenWidth
- 2*mfW
) div 2;
1139 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
1140 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1141 _RGB(128, 0, 0), 2.0);
1144 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
1145 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
1149 if ConsoleHistory <> nil then
1153 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
1154 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
1156 b := Max(b-Offset, 0);
1157 d := Max(High(ConsoleHistory)-Offset, 0);
1160 for a := d downto b do
1162 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
1169 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
1172 procedure g_Console_Char(C
: AnsiChar);
1174 if not gSkipFirstChar
then
1176 Insert(C
, Line
, CPos
);
1179 gSkipFirstChar
:= False
1184 tcomplist
: array of AnsiString = nil;
1185 tcompidx
: array of Integer = nil;
1187 procedure Complete ();
1191 ll
, lpfx
, cmd
: AnsiString;
1193 if (Length(Line
) = 0) then
1196 for i
:= 0 to High(commands
) do
1198 // hidden commands are hidden when cheats aren't enabled
1199 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1200 if (Length(commands
[i
].help
) > 0) then
1202 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1206 g_Console_Add(' '+commands
[i
].cmd
);
1212 ll
:= LowerCase(Line
);
1215 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1217 ll
:= Copy(ll
, 0, Length(ll
)-1);
1218 for i
:= 0 to High(commands
) do
1220 // hidden commands are hidden when cheats aren't enabled
1221 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1222 if (commands
[i
].cmd
= ll
) then
1224 if (Length(commands
[i
].help
) > 0) then
1226 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1233 // build completion list
1235 for i
:= 0 to High(commands
) do
1237 // hidden commands are hidden when cheats aren't enabled
1238 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1239 cmd
:= commands
[i
].cmd
;
1240 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1242 if (tused
= Length(tcomplist
)) then
1244 SetLength(tcomplist
, Length(tcomplist
)+128);
1245 SetLength(tcompidx
, Length(tcompidx
)+128);
1247 tcomplist
[tused
] := cmd
;
1248 tcompidx
[tused
] := i
;
1250 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1254 // get longest prefix
1255 for i
:= 0 to tused
-1 do
1257 cmd
:= tcomplist
[i
];
1258 for c
:= 1 to Length(lpfx
) do
1260 if (c
> Length(cmd
)) then break
;
1261 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1265 if (tused
= 0) then exit
;
1269 Line
:= tcomplist
[0]+' ';
1270 CPos
:= Length(Line
)+1;
1274 // has longest prefix?
1275 if (Length(lpfx
) > Length(ll
)) then
1278 CPos
:= Length(Line
)+1;
1283 for i
:= 0 to tused
-1 do
1285 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1287 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1291 g_Console_Add(' '+tcomplist
[i
]);
1299 procedure g_Console_Control(K
: Word);
1303 if (Length(Line
) > 0) and (CPos
> 1) then
1305 Delete(Line
, CPos
-1, 1);
1309 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1310 Delete(Line
, CPos
, 1);
1311 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1314 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1315 if CPos
<= Length(Line
) then
1317 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1320 g_Console_Process(Line
)
1324 if (Length(Line
) > 0) and g_Game_IsNet
then
1328 if g_Game_IsClient
then
1329 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1331 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1332 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1336 if g_Game_IsClient
then
1337 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1339 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1347 gJustChatted
:= True;
1348 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1352 if not gChatShow
then
1354 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1355 if not gChatShow
then
1356 if (CommandHistory
<> nil) and
1357 (CmdIndex
< Length(CommandHistory
)) then
1359 if CmdIndex
< Length(CommandHistory
)-1 then
1360 CmdIndex
:= CmdIndex
+ 1;
1361 Line
:= CommandHistory
[CmdIndex
];
1362 CPos
:= Length(Line
) + 1;
1364 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1365 if not gChatShow
then
1366 if (CommandHistory
<> nil) and
1367 (CmdIndex
<= Length(CommandHistory
)) then
1369 if CmdIndex
> 0 then
1370 CmdIndex
:= CmdIndex
- 1;
1371 Line
:= CommandHistory
[CmdIndex
];
1372 Cpos
:= Length(Line
) + 1;
1374 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1375 if not gChatShow
then Inc(conSkipLines
);
1376 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1377 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1381 CPos
:= Length(Line
) + 1;
1382 IK_A
..IK_Z
, IK_SPACE
, IK_SHIFT
, IK_RSHIFT
, IK_CAPSLOCK
, IK_LBRACKET
, IK_RBRACKET
,
1383 IK_SEMICOLON
, IK_QUOTE
, IK_BACKSLASH
, IK_SLASH
, IK_COMMA
, IK_DOT
, IK_EQUALS
,
1384 IK_0
, IK_1
, IK_2
, IK_3
, IK_4
, IK_5
, IK_6
, IK_7
, IK_8
, IK_9
, IK_MINUS
, IK_EQUALS
:
1385 (* see TEXTINPUT event *)
1387 if not gSkipFirstChar
then
1389 if gConsoleShow
and g_Console_MatchBind(K
, 'toggleconsole') then
1392 if g_Console_MatchBind(K
, 'togglemenu') then
1394 menu_toggled
:= True;
1396 g_Console_Chat_Switch
1397 else if gConsoleShow
then
1404 function GetStr(var Str
: AnsiString): AnsiString;
1409 if Str
[1] = '"' then
1411 for b
:= 1 to Length(Str
) do
1412 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1414 Result
:= Copy(Str
, 2, b
-1);
1415 Delete(Str
, 1, b
+1);
1421 for a
:= 1 to Length(Str
) do
1422 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1424 Result
:= Copy(Str
, 1, a
);
1425 Delete(Str
, 1, a
+1);
1431 function ParseString(Str
: AnsiString): SSArray
;
1442 SetLength(Result
, Length(Result
)+1);
1443 Result
[High(Result
)] := GetStr(Str
);
1447 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1449 procedure conmsg (s
: AnsiString);
1453 if length(s
) = 0 then exit
;
1454 for a
:= 0 to High(MsgArray
) do
1466 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1467 with MsgArray
[High(MsgArray
)] do
1477 // put it to console
1479 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1481 // now show 'em out of console too
1482 show
:= show
and gAllowConsoleMessages
;
1483 if show
and gShowMessages
then
1485 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1486 while length(L
) > 0 do
1489 if f
<= 0 then f
:= length(L
)+1;
1490 conmsg(Copy(L
, 1, f
-1));
1495 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1496 //ConsoleHistory[High(ConsoleHistory)] := L;
1500 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1507 consolewriterLastWasEOL
: Boolean = false;
1509 procedure consolewriter (constref buf
; len
: SizeUInt
);
1513 if (len
< 1) then exit
;
1515 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1518 if (b
[0] <> 13) and (b
[0] <> 10) then
1520 cbufPut(AnsiChar(b
[0]));
1524 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1533 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1534 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1535 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1536 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1538 g_Console_Add(s
, show
);
1542 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1546 g_Console_Add(formatstrf(s
, args
), true);
1550 consolewriterLastWasEOL
:= false;
1551 formatstrf(s
, args
, consolewriter
);
1552 if not consolewriterLastWasEOL
then cbufPut(#10);
1557 procedure g_Console_Clear();
1559 //ConsoleHistory := nil;
1564 procedure AddToHistory(L
: AnsiString);
1568 len
:= Length(CommandHistory
);
1571 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1573 SetLength(CommandHistory
, len
+1);
1574 CommandHistory
[len
] := L
;
1577 CmdIndex
:= Length(CommandHistory
);
1580 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1589 if Trim(C
) = '' then
1592 Arr
:= ParseString(C
);
1596 for i
:= 0 to High(Whitelist
) do
1597 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1601 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1608 if Trim(L
) = '' then
1611 conSkipLines
:= 0; // "unscroll"
1613 if L
= 'goobers' then
1618 g_Console_Add('Your memory serves you well.');
1624 g_Console_Add('> '+L
);
1629 Arr
:= ParseString(L
);
1633 if commands
= nil then
1639 for i
:= 0 to High(commands
) do
1641 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1643 if commands
[i
].action
>= 0 then
1645 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1648 if assigned(commands
[i
].procEx
) then
1650 commands
[i
].procEx(@commands
[i
], Arr
);
1653 if assigned(commands
[i
].proc
) then
1655 commands
[i
].proc(Arr
);
1661 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1665 function g_Console_Interactive
: Boolean;
1667 Result
:= gConsoleShow
1670 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1672 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1674 ASSERT(key
< e_MaxInputKeys
);
1677 gInputBinds
[key
].down
:= ParseAlias(down
);
1678 gInputBinds
[key
].up
:= ParseAlias(up
);
1680 g_Console_WriteGameConfig();
1683 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
1685 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1686 var i
, len
: Integer;
1690 if len
= Length(b
) then
1693 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1701 ASSERT(key
< e_MaxInputKeys
);
1702 result
:= EqualsCommandLists(ParseAlias(down
), gInputBinds
[key
].down
) and EqualsCommandLists(ParseAlias(up
), gInputBinds
[key
].up
)
1705 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1710 if commands
= nil then Exit
;
1712 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1714 if g_Console_MatchBind(i
, down
, up
) then
1725 function g_Console_Action (action
: Integer): Boolean;
1726 var i
, len
: Integer;
1728 ASSERT(action
>= FIRST_ACTION
);
1729 ASSERT(action
<= LAST_ACTION
);
1731 len
:= Length(gPlayerAction
);
1732 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1736 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1739 if (not g_GUIGrabInput
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1743 if not gChatShow
then
1744 for i
:= 0 to High(gInputBinds
[key
].down
) do
1745 g_Console_Process(gInputBinds
[key
].down
[i
], True);
1748 for i
:= 0 to High(gInputBinds
[key
].up
) do
1749 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1751 if down
and not menu_toggled
then
1753 menu_toggled
:= False
1756 procedure g_Console_ResetBinds
;
1759 for i
:= 0 to e_MaxInputKeys
- 1 do
1760 g_Console_BindKey(i
, '', '');
1762 g_Console_BindKey(IK_GRAVE
, 'toggleconsole');
1763 g_Console_BindKey(IK_ESCAPE
, 'togglemenu');
1764 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1765 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1766 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1767 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1768 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1769 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1770 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1771 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1772 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1773 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1774 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1775 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1776 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1777 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1778 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1779 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1780 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1781 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1782 g_Console_BindKey(IK_9
, 'p1_weapon 9');
1783 g_Console_BindKey(IK_0
, 'p1_weapon 10');
1784 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
1785 g_Console_BindKey(IK_T
, 'togglechat');
1786 g_Console_BindKey(IK_Y
, 'toggleteamchat');
1787 g_Console_BindKey(IK_F11
, 'screenshot');
1788 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
1789 g_Console_BindKey(IK_PAUSE
, 'pause');
1790 g_Console_BindKey(IK_F1
, 'vote');
1792 (* for i := 0 to e_MaxJoys - 1 do *)
1795 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_LEFT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
1796 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_RIGHT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
1797 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_UP
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
1798 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_DOWN
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
1799 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
1800 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
1801 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
1802 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
1803 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
1804 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
1805 g_Console_BindKey(e_JoyButtonToKey(i
, 10), 'togglemenu');
1808 g_Console_BindKey(VK_ESCAPE
, 'togglemenu');
1809 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
1810 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
1811 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
1812 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
1813 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
1814 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
1815 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
1816 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
1817 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
1818 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
1819 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
1820 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
1821 g_Console_BindKey(VK_0
, 'weapon 1');
1822 g_Console_BindKey(VK_1
, 'weapon 2');
1823 g_Console_BindKey(VK_2
, 'weapon 3');
1824 g_Console_BindKey(VK_3
, 'weapon 4');
1825 g_Console_BindKey(VK_4
, 'weapon 5');
1826 g_Console_BindKey(VK_5
, 'weapon 6');
1827 g_Console_BindKey(VK_6
, 'weapon 7');
1828 g_Console_BindKey(VK_7
, 'weapon 8');
1829 g_Console_BindKey(VK_8
, 'weapon 9');
1830 g_Console_BindKey(VK_9
, 'weapon 10');
1831 g_Console_BindKey(VK_A
, 'weapon 11');
1832 g_Console_BindKey(VK_CHAT
, 'togglechat');
1833 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
1834 g_Console_BindKey(VK_CONSOLE
, 'toggleconsole');
1835 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
1836 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
1837 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
1838 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
1841 procedure g_Console_ReadConfig (filename
: String);
1842 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1844 if FileExists(filename
) then
1846 AssignFile(f
, filename
);
1856 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1858 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1859 g_Console_Process(s
, True);
1866 procedure g_Console_WriteConfig (filename
: String);
1867 var f
: TextFile
; i
, j
: Integer;
1869 AssignFile(f
, filename
);
1871 WriteLn(f
, '// generated by doom2d, do not modify');
1872 WriteLn(f
, 'unbindall');
1873 for i
:= 0 to e_MaxInputKeys
- 1 do
1874 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
1876 Write(f
, 'bind ', e_KeyNames
[i
], ' ', QuoteStr(GetCommandString(gInputBinds
[i
].down
)));
1877 if Length(gInputBinds
[i
].up
) > 0 then
1878 Write(f
, ' ', QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
1881 for i
:= 0 to High(commands
) do
1883 if not commands
[i
].cheat
then
1885 if @commands
[i
].procEx
= @boolVarHandler
then
1887 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
1888 WriteLn(f
, commands
[i
].cmd
, ' ', j
)
1890 else if @commands
[i
].procEx
= @intVarHandler
then
1892 WriteLn(f
, commands
[i
].cmd
, ' ', PInteger(commands
[i
].ptr
)^)
1894 else if @commands
[i
].procEx
= @singleVarHandler
then
1896 WriteLn(f
, commands
[i
].cmd
, ' ', PVarSingle(commands
[i
].ptr
).val
^:0:6)
1903 procedure g_Console_WriteGameConfig
;
1905 if gParsingBinds
then
1907 g_Console_WriteConfig(GameDir
+ '/dfconfig.cfg');