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);
52 function g_Console_Interactive
: Boolean;
53 function g_Console_Action (action
: Integer): Boolean;
54 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
55 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
56 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
57 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
58 procedure g_Console_ResetBinds
;
60 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
61 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
63 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
64 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
65 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
67 // <0: no arg; 0/1: true/false
68 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
70 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
71 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
75 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
76 gChatShow
: Boolean = false;
77 gChatTeam
: Boolean = false;
78 gAllowConsoleMessages
: Boolean = true;
79 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
80 gPlayerAction
: Array [0..1, 0..LAST_ACTION
] of Boolean; // [player, action]
85 g_textures
, g_main
, e_graphics
, e_input
, g_game
,
86 SysUtils
, g_basic
, g_options
, Math
, g_touch
,
87 g_menu
, g_gui
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
93 TCmdProc
= procedure (p
: SSArray
);
94 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
102 ptr
: Pointer; // various data
103 msg
: AnsiString; // message for var changes
105 action
: Integer; // >= 0 for action commands
106 player
: Integer; // used for action commands
119 MaxScriptRecursion
= 16;
121 DEBUG_STRING
= 'DEBUG MODE';
125 RecursionDepth
: Word = 0;
126 RecursionLimitHit
: Boolean = False;
128 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
131 //ConsoleHistory: SSArray;
132 CommandHistory
: SSArray
;
134 commands
: Array of TCommand
= nil;
135 Aliases
: Array of TAlias
= nil;
137 conSkipLines
: Integer = 0;
138 MsgArray
: Array [0..4] of record
143 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
146 menu_toggled
: BOOLEAN; (* hack for menu controls *)
147 gSkipFirstChar
: Boolean; (* hack for console/chat input *)
150 procedure g_Console_Switch
;
153 gConsoleShow
:= not gConsoleShow
;
155 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
158 procedure g_Console_Chat_Switch (Team
: Boolean = False);
160 if not g_Game_IsNet
then Exit
;
161 gConsoleShow
:= False;
162 gChatShow
:= not gChatShow
;
166 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
169 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
170 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
179 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
180 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
181 if (pos
> slen
) then exit
;
182 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
184 while (pos
<= slen
) do
186 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
187 res
:= res
*10+Byte(s
[pos
])-48;
190 if (pos
<= slen
) then
193 if (s
[pos
] <> '.') then exit
;
195 while (pos
<= slen
) do
197 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
199 res
+= frac
*(Byte(s
[pos
])-48);
203 if (pos
<= slen
) then exit
; // oops
208 // ////////////////////////////////////////////////////////////////////////// //
209 // <0: no arg; 0/1: true/false; 666: toggle
210 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
212 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
214 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
215 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
216 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
217 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
221 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
222 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
224 if (Length(p
) > 2) then
226 conwritefln('too many arguments to ''%s''', [p
[0]]);
230 case conGetBoolArg(p
, 1) of
232 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
233 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
234 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
236 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
237 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
241 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
245 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
246 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
248 if (Length(p
) > 2) then
250 conwritefln('too many arguments to ''%s''', [p
[0]]);
254 case conGetBoolArg(p
, 1) of
256 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
257 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
258 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
260 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
261 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
265 if (Length(p
) <> 2) then
267 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
272 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
274 conwritefln('invalid integer value: "%s"', [p
[1]]);
280 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
285 f
:= Length(commands
);
286 SetLength(commands
, f
+1);
288 cp
.cmd
:= LowerCase(conname
);
290 cp
.procEx
:= boolVarHandler
;
292 cp
.hidden
:= ahidden
;
301 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
306 f
:= Length(commands
);
307 SetLength(commands
, f
+1);
309 cp
.cmd
:= LowerCase(conname
);
311 cp
.procEx
:= intVarHandler
;
313 cp
.hidden
:= ahidden
;
322 // ////////////////////////////////////////////////////////////////////////// //
324 PVarSingle
= ^TVarSingle
;
327 min
, max
, def
: Single; // default will be starting value
331 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
337 if (Length(p
) > 2) then
339 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
342 pv
:= PVarSingle(me
.ptr
);
343 if (Length(p
) = 2) then
345 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
346 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
347 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
348 (CompareText(p
[1], 'ona') = 0) then
354 if not conParseFloat(nv
, p
[1]) then
356 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
359 if (nv
< pv
.min
) then nv
:= pv
.min
;
360 if (nv
> pv
.max
) then nv
:= pv
.max
;
365 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
366 conwritefln('%s %s', [msg
, pv
.val
^]);
370 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
376 GetMem(pv
, sizeof(TVarSingle
));
381 f
:= Length(commands
);
382 SetLength(commands
, f
+1);
384 cp
.cmd
:= LowerCase(conname
);
386 cp
.procEx
:= singleVarHandler
;
388 cp
.hidden
:= ahidden
;
397 // ////////////////////////////////////////////////////////////////////////// //
398 function GetStrACmd(var Str
: AnsiString): AnsiString;
403 for a
:= 1 to Length(Str
) do
404 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
406 Result
:= Copy(Str
, 1, a
);
413 function ParseAlias(Str
: AnsiString): SSArray
;
424 SetLength(Result
, Length(Result
)+1);
425 Result
[High(Result
)] := GetStrACmd(Str
);
429 procedure ConsoleCommands(p
: SSArray
);
435 cmd
:= LowerCase(p
[0]);
438 if cmd
= 'clear' then
440 //ConsoleHistory := nil;
444 for a
:= 0 to High(MsgArray
) do
452 if cmd
= 'clearhistory' then
453 CommandHistory
:= nil;
455 if cmd
= 'showhistory' then
456 if CommandHistory
<> nil then
459 for a
:= 0 to High(CommandHistory
) do
460 g_Console_Add(' '+CommandHistory
[a
]);
463 if cmd
= 'commands' then
466 g_Console_Add('commands list:');
467 for a
:= High(commands
) downto 0 do
469 if (Length(commands
[a
].help
) > 0) then
471 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
475 g_Console_Add(' '+commands
[a
].cmd
);
481 g_Console_Add(TimeToStr(Now
), True);
484 g_Console_Add(DateToStr(Now
), True);
487 if Length(p
) > 1 then
489 if p
[1] = 'ololo' then
494 for a
:= 1 to High(p
) do
496 g_Console_Add(b_Text_Format(s
), True);
505 if ConsoleHistory <> nil then
507 if Length(P) > 1 then
510 s := GameDir+'/console.txt';
515 if IOResult <> 0 then
517 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
522 for a := 0 to High(ConsoleHistory) do
523 WriteLn(F, ConsoleHistory[a]);
526 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
535 if Length(p
) = 2 then
536 g_Console_ReadConfig(GameDir
+ '/' + p
[1])
538 g_Console_Add('exec <script file>');
541 if cmd
= 'writeconfig' then
543 // writeconfig <filename>
544 if Length(p
) = 2 then
545 g_Console_WriteConfig(GameDir
+ '/' + p
[1])
547 g_Console_Add('writeconfig <file>');
550 if (cmd
= 'ver') or (cmd
= 'version') then
552 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
553 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
554 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
557 if cmd
= 'alias' then
559 // alias [alias_name] [commands]
560 if Length(p
) > 1 then
562 for a
:= 0 to High(Aliases
) do
563 if Aliases
[a
].name
= p
[1] then
565 if Length(p
) > 2 then
566 Aliases
[a
].commands
:= ParseAlias(p
[2])
568 for b
:= 0 to High(Aliases
[a
].commands
) do
569 g_Console_Add(Aliases
[a
].commands
[b
]);
572 SetLength(Aliases
, Length(Aliases
)+1);
574 Aliases
[a
].name
:= p
[1];
575 if Length(p
) > 2 then
576 Aliases
[a
].commands
:= ParseAlias(p
[2])
578 for b
:= 0 to High(Aliases
[a
].commands
) do
579 g_Console_Add(Aliases
[a
].commands
[b
]);
581 for a
:= 0 to High(Aliases
) do
582 if Aliases
[a
].commands
<> nil then
583 g_Console_Add(Aliases
[a
].name
);
589 if Length(p
) > 1 then
591 if Aliases
= nil then
593 for a
:= 0 to High(Aliases
) do
594 if Aliases
[a
].name
= p
[1] then
596 if Aliases
[a
].commands
<> nil then
598 // with this system proper endless loop detection seems either impossible
599 // or very dirty to implement, so let's have this instead
600 // prevents endless loops
601 for b
:= 0 to High(Aliases
[a
].commands
) do
604 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
605 if not RecursionLimitHit
then
606 g_Console_Process(Aliases
[a
].commands
[b
], True);
609 if (RecursionDepth
= 0) and RecursionLimitHit
then
611 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
612 RecursionLimitHit
:= False;
619 g_Console_Add('call <alias name>');
623 procedure WhitelistCommand(cmd
: AnsiString);
627 SetLength(Whitelist
, Length(Whitelist
)+1);
628 a
:= High(Whitelist
);
629 Whitelist
[a
] := LowerCase(cmd
);
632 procedure segfault (p
: SSArray
);
639 function GetCommandString (p
: SSArray
): AnsiString;
643 if Length(p
) >= 1 then
646 for i
:= 1 to High(p
) do
647 result
:= result
+ '; ' + p
[i
]
651 procedure BindCommands (p
: SSArray
);
652 var cmd
, key
: AnsiString; i
: Integer;
654 cmd
:= LowerCase(p
[0]);
657 // bind <key> [down [up]]
658 if (Length(p
) >= 2) and (Length(p
) <= 4) then
661 key
:= LowerCase(p
[1]);
662 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
663 if i
< e_MaxInputKeys
then
665 if Length(p
) = 2 then
666 g_Console_Add('"' + e_KeyNames
[i
] + '" = "' + GetCommandString(gInputBinds
[i
].down
) + '" "' + GetCommandString(gInputBinds
[i
].up
) + '"')
667 else if Length(p
) = 3 then
668 g_Console_BindKey(i
, p
[2], '')
670 g_Console_BindKey(i
, p
[2], p
[3])
673 g_Console_Add('bind: "' + p
[1] + '" is not a key')
677 g_Console_Add('bind <key> <down action> [up action]')
680 for i
:= 0 to e_MaxInputKeys
- 1 do
681 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
682 g_Console_Add(e_KeyNames
[i
] + ' "' + GetCommandString(gInputBinds
[i
].down
) + '" "' + GetCommandString(gInputBinds
[i
].up
) + '"');
685 if Length(p
) = 2 then
687 key
:= LowerCase(p
[1]);
689 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
690 if i
< e_MaxInputKeys
then
691 g_Console_BindKey(i
, '')
693 g_Console_Add('unbind: "' + p
[1] + '" is not a key')
696 g_Console_Add('unbind <key>');
698 for i
:= 0 to e_MaxInputKeys
- 1 do
699 g_Console_BindKey(i
, '');
701 g_Touch_ShowKeyboard(True);
703 g_Touch_ShowKeyboard(False);
713 gSkipFirstChar
:= g_Console_Interactive();
717 g_Console_Chat_Switch
;
718 gSkipFirstChar
:= not g_Console_Interactive()
721 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
723 g_Console_Chat_Switch(True);
724 gSkipFirstChar
:= not g_Console_Interactive()
729 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
734 SetLength(commands
, Length(commands
)+1);
737 cp
.cmd
:= LowerCase(cmd
);
741 cp
.hidden
:= ahidden
;
749 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
751 PrefixList
: array [0..1] of AnsiString = ('+', '-');
752 PlayerList
: array [0..1] of Integer = (1, 2);
757 procedure NewAction (cmd
: AnsiString; player
: Integer);
760 SetLength(commands
, Length(commands
) + 1);
761 cp
:= @commands
[High(commands
)];
762 cp
.cmd
:= LowerCase(cmd
);
775 ASSERT(action
>= FIRST_ACTION
);
776 ASSERT(action
<= LAST_ACTION
);
777 for s
in PrefixList
do
779 NewAction(s
+ cmd
, 0);
780 for i
in PlayerList
do
781 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
785 procedure g_Console_Init();
789 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
790 Cons_Y
:= -(gScreenHeight
div 2);
791 gConsoleShow
:= False;
796 for a
:= 0 to High(MsgArray
) do
803 AddCommand('segfault', segfault
, 'make segfault');
805 AddCommand('bind', BindCommands
);
806 AddCommand('bindlist', BindCommands
);
807 AddCommand('unbind', BindCommands
);
808 AddCommand('unbindall', BindCommands
);
809 AddCommand('showkeyboard', BindCommands
);
810 AddCommand('hidekeyboard', BindCommands
);
811 AddCommand('togglemenu', BindCommands
);
812 AddCommand('toggleconsole', BindCommands
);
813 AddCommand('togglechat', BindCommands
);
814 AddCommand('toggleteamchat', BindCommands
);
816 AddCommand('clear', ConsoleCommands
, 'clear console');
817 AddCommand('clearhistory', ConsoleCommands
);
818 AddCommand('showhistory', ConsoleCommands
);
819 AddCommand('commands', ConsoleCommands
);
820 AddCommand('time', ConsoleCommands
);
821 AddCommand('date', ConsoleCommands
);
822 AddCommand('echo', ConsoleCommands
);
823 AddCommand('dump', ConsoleCommands
);
824 AddCommand('exec', ConsoleCommands
);
825 AddCommand('writeconfig', ConsoleCommands
);
826 AddCommand('alias', ConsoleCommands
);
827 AddCommand('call', ConsoleCommands
);
828 AddCommand('ver', ConsoleCommands
);
829 AddCommand('version', ConsoleCommands
);
831 AddCommand('d_window', DebugCommands
);
832 AddCommand('d_sounds', DebugCommands
);
833 AddCommand('d_frames', DebugCommands
);
834 AddCommand('d_winmsg', DebugCommands
);
835 AddCommand('d_monoff', DebugCommands
);
836 AddCommand('d_botoff', DebugCommands
);
837 AddCommand('d_monster', DebugCommands
);
838 AddCommand('d_health', DebugCommands
);
839 AddCommand('d_player', DebugCommands
);
840 AddCommand('d_joy', DebugCommands
);
841 AddCommand('d_mem', DebugCommands
);
843 AddCommand('p1_name', GameCVars
);
844 AddCommand('p2_name', GameCVars
);
845 AddCommand('p1_color', GameCVars
);
846 AddCommand('p2_color', GameCVars
);
847 AddCommand('r_showtime', GameCVars
);
848 AddCommand('r_showscore', GameCVars
);
849 AddCommand('r_showlives', GameCVars
);
850 AddCommand('r_showstat', GameCVars
);
851 AddCommand('r_showkillmsg', GameCVars
);
852 AddCommand('r_showspect', GameCVars
);
853 AddCommand('r_showping', GameCVars
);
854 AddCommand('g_gamemode', GameCVars
);
855 AddCommand('g_friendlyfire', GameCVars
);
856 AddCommand('g_weaponstay', GameCVars
);
857 AddCommand('g_allow_exit', GameCVars
);
858 AddCommand('g_allow_monsters', GameCVars
);
859 AddCommand('g_bot_vsmonsters', GameCVars
);
860 AddCommand('g_bot_vsplayers', GameCVars
);
861 AddCommand('g_scorelimit', GameCVars
);
862 AddCommand('g_timelimit', GameCVars
);
863 AddCommand('g_maxlives', GameCVars
);
864 AddCommand('g_warmuptime', GameCVars
);
865 AddCommand('net_interp', GameCVars
);
866 AddCommand('net_forceplayerupdate', GameCVars
);
867 AddCommand('net_predictself', GameCVars
);
868 AddCommand('sv_name', GameCVars
);
869 AddCommand('sv_passwd', GameCVars
);
870 AddCommand('sv_maxplrs', GameCVars
);
871 AddCommand('sv_public', GameCVars
);
872 AddCommand('sv_intertime', GameCVars
);
874 AddCommand('quit', GameCommands
);
875 AddCommand('exit', GameCommands
);
876 AddCommand('pause', GameCommands
);
877 AddCommand('endgame', GameCommands
);
878 AddCommand('restart', GameCommands
);
879 AddCommand('addbot', GameCommands
);
880 AddCommand('bot_add', GameCommands
);
881 AddCommand('bot_addlist', GameCommands
);
882 AddCommand('bot_addred', GameCommands
);
883 AddCommand('bot_addblue', GameCommands
);
884 AddCommand('bot_removeall', GameCommands
);
885 AddCommand('chat', GameCommands
);
886 AddCommand('teamchat', GameCommands
);
887 AddCommand('game', GameCommands
);
888 AddCommand('host', GameCommands
);
889 AddCommand('map', GameCommands
);
890 AddCommand('nextmap', GameCommands
);
891 AddCommand('endmap', GameCommands
);
892 AddCommand('goodbye', GameCommands
);
893 AddCommand('suicide', GameCommands
);
894 AddCommand('spectate', GameCommands
);
895 AddCommand('ready', GameCommands
);
896 AddCommand('kick', GameCommands
);
897 AddCommand('kick_id', GameCommands
);
898 AddCommand('ban', GameCommands
);
899 AddCommand('permban', GameCommands
);
900 AddCommand('ban_id', GameCommands
);
901 AddCommand('permban_id', GameCommands
);
902 AddCommand('unban', GameCommands
);
903 AddCommand('connect', GameCommands
);
904 AddCommand('disconnect', GameCommands
);
905 AddCommand('reconnect', GameCommands
);
906 AddCommand('say', GameCommands
);
907 AddCommand('tell', GameCommands
);
908 AddCommand('overtime', GameCommands
);
909 AddCommand('rcon_password', GameCommands
);
910 AddCommand('rcon', GameCommands
);
911 AddCommand('callvote', GameCommands
);
912 AddCommand('vote', GameCommands
);
913 AddCommand('clientlist', GameCommands
);
914 AddCommand('event', GameCommands
);
915 AddCommand('screenshot', GameCommands
);
916 AddCommand('weapon', GameCommands
);
917 AddCommand('p1_weapon', GameCommands
);
918 AddCommand('p2_weapon', GameCommands
);
920 AddCommand('god', GameCheats
);
921 AddCommand('notarget', GameCheats
);
922 AddCommand('give', GameCheats
); // "exit" too ;-)
923 AddCommand('open', GameCheats
);
924 AddCommand('fly', GameCheats
);
925 AddCommand('noclip', GameCheats
);
926 AddCommand('speedy', GameCheats
);
927 AddCommand('jumpy', GameCheats
);
928 AddCommand('noreload', GameCheats
);
929 AddCommand('aimline', GameCheats
);
930 AddCommand('automap', GameCheats
);
932 AddAction('jump', ACTION_JUMP
);
933 AddAction('moveleft', ACTION_MOVELEFT
);
934 AddAction('moveright', ACTION_MOVERIGHT
);
935 AddAction('lookup', ACTION_LOOKUP
);
936 AddAction('lookdown', ACTION_LOOKDOWN
);
937 AddAction('attack', ACTION_ATTACK
);
938 AddAction('scores', ACTION_SCORES
);
939 AddAction('activate', ACTION_ACTIVATE
);
940 AddAction('strafe', ACTION_STRAFE
);
941 AddAction('weapnext', ACTION_WEAPNEXT
);
942 AddAction('weapprev', ACTION_WEAPPREV
);
944 WhitelistCommand('say');
945 WhitelistCommand('tell');
946 WhitelistCommand('overtime');
947 WhitelistCommand('ready');
948 WhitelistCommand('map');
949 WhitelistCommand('nextmap');
950 WhitelistCommand('endmap');
951 WhitelistCommand('restart');
952 WhitelistCommand('kick');
953 WhitelistCommand('ban');
955 WhitelistCommand('addbot');
956 WhitelistCommand('bot_add');
957 WhitelistCommand('bot_addred');
958 WhitelistCommand('bot_addblue');
959 WhitelistCommand('bot_removeall');
961 WhitelistCommand('g_gamemode');
962 WhitelistCommand('g_friendlyfire');
963 WhitelistCommand('g_weaponstay');
964 WhitelistCommand('g_allow_exit');
965 WhitelistCommand('g_allow_monsters');
966 WhitelistCommand('g_scorelimit');
967 WhitelistCommand('g_timelimit');
969 g_Console_ResetBinds
;
970 g_Console_ReadConfig(GameDir
+ '/dfconfig.cfg');
971 g_Console_ReadConfig(GameDir
+ '/autoexec.cfg');
973 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
977 procedure g_Console_Update();
983 // Â ïðîöåññå îòêðûòèÿ:
984 if gConsoleShow
and (Cons_Y
< 0) then
986 Cons_Y
:= Cons_Y
+Step
;
989 // Â ïðîöåññå çàêðûòèÿ:
990 if (not gConsoleShow
) and
991 (Cons_Y
> -(gScreenHeight
div 2)) then
992 Cons_Y
:= Cons_Y
-Step
;
994 // Îêîí÷àòåëüíî îòêðûëàñü:
998 // Îêîí÷àòåëüíî çàêðûëàñü:
999 if Cons_Y
<= (-(gScreenHeight
div 2)) then
1001 Cons_Y
:= -(gScreenHeight
div 2);
1002 Cons_Shown
:= False;
1007 while a
<= High(MsgArray
) do
1009 if MsgArray
[a
].Time
> 0 then
1011 if MsgArray
[a
].Time
= 1 then
1013 if a
< High(MsgArray
) then
1015 for b
:= a
to High(MsgArray
)-1 do
1016 MsgArray
[b
] := MsgArray
[b
+1];
1018 MsgArray
[High(MsgArray
)].Time
:= 0;
1024 Dec(MsgArray
[a
].Time
);
1032 procedure drawConsoleText ();
1034 CWidth
, CHeight
: Byte;
1039 procedure putLine (sp
, ep
: LongWord);
1048 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1049 if wdt
+cw
> gScreenWidth
-8 then break
;
1050 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1054 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1055 // now print our part
1063 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1064 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1077 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1078 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
1079 skip
:= conSkipLines
;
1080 cbufLastLine(sp
, ep
);
1083 if ty
+CHeight
<= 0 then break
;
1084 until not cbufLineUp(sp
, ep
);
1087 procedure g_Console_Draw();
1089 CWidth
, CHeight
: Byte;
1093 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1095 for a
:= 0 to High(MsgArray
) do
1096 if MsgArray
[a
].Time
> 0 then
1097 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
1100 if not Cons_Shown
then
1106 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
1107 gStdFont
, 255, 255, 255, 1, True);
1108 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1109 gStdFont
, 255, 255, 255, 1, True);
1113 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
1114 gStdFont
, 255, 255, 255, 1, True);
1115 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1116 gStdFont
, 255, 255, 255, 1, True);
1124 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1125 a
:= (gScreenWidth
- 2*mfW
) div 2;
1126 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
1127 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1128 _RGB(128, 0, 0), 2.0);
1131 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
1132 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
1136 if ConsoleHistory <> nil then
1140 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
1141 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
1143 b := Max(b-Offset, 0);
1144 d := Max(High(ConsoleHistory)-Offset, 0);
1147 for a := d downto b do
1149 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
1156 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
1159 procedure g_Console_Char(C
: AnsiChar);
1161 if not gSkipFirstChar
then
1163 Insert(C
, Line
, CPos
);
1166 gSkipFirstChar
:= False
1171 tcomplist
: array of AnsiString = nil;
1172 tcompidx
: array of Integer = nil;
1174 procedure Complete ();
1178 ll
, lpfx
, cmd
: AnsiString;
1180 if (Length(Line
) = 0) then
1183 for i
:= 0 to High(commands
) do
1185 // hidden commands are hidden when cheats aren't enabled
1186 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1187 if (Length(commands
[i
].help
) > 0) then
1189 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1193 g_Console_Add(' '+commands
[i
].cmd
);
1199 ll
:= LowerCase(Line
);
1202 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1204 ll
:= Copy(ll
, 0, Length(ll
)-1);
1205 for i
:= 0 to High(commands
) do
1207 // hidden commands are hidden when cheats aren't enabled
1208 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1209 if (commands
[i
].cmd
= ll
) then
1211 if (Length(commands
[i
].help
) > 0) then
1213 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1220 // build completion list
1222 for i
:= 0 to High(commands
) do
1224 // hidden commands are hidden when cheats aren't enabled
1225 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1226 cmd
:= commands
[i
].cmd
;
1227 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1229 if (tused
= Length(tcomplist
)) then
1231 SetLength(tcomplist
, Length(tcomplist
)+128);
1232 SetLength(tcompidx
, Length(tcompidx
)+128);
1234 tcomplist
[tused
] := cmd
;
1235 tcompidx
[tused
] := i
;
1237 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1241 // get longest prefix
1242 for i
:= 0 to tused
-1 do
1244 cmd
:= tcomplist
[i
];
1245 for c
:= 1 to Length(lpfx
) do
1247 if (c
> Length(cmd
)) then break
;
1248 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1252 if (tused
= 0) then exit
;
1256 Line
:= tcomplist
[0]+' ';
1257 CPos
:= Length(Line
)+1;
1261 // has longest prefix?
1262 if (Length(lpfx
) > Length(ll
)) then
1265 CPos
:= Length(Line
)+1;
1270 for i
:= 0 to tused
-1 do
1272 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1274 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1278 g_Console_Add(' '+tcomplist
[i
]);
1286 procedure g_Console_Control(K
: Word);
1290 if (Length(Line
) > 0) and (CPos
> 1) then
1292 Delete(Line
, CPos
-1, 1);
1296 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1297 Delete(Line
, CPos
, 1);
1298 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1301 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1302 if CPos
<= Length(Line
) then
1304 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1307 g_Console_Process(Line
)
1311 if (Length(Line
) > 0) and g_Game_IsNet
then
1315 if g_Game_IsClient
then
1316 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1318 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1319 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1323 if g_Game_IsClient
then
1324 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1326 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1334 gJustChatted
:= True;
1335 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1339 if not gChatShow
then
1341 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1342 if not gChatShow
then
1343 if (CommandHistory
<> nil) and
1344 (CmdIndex
< Length(CommandHistory
)) then
1346 if CmdIndex
< Length(CommandHistory
)-1 then
1347 CmdIndex
:= CmdIndex
+ 1;
1348 Line
:= CommandHistory
[CmdIndex
];
1349 CPos
:= Length(Line
) + 1;
1351 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1352 if not gChatShow
then
1353 if (CommandHistory
<> nil) and
1354 (CmdIndex
<= Length(CommandHistory
)) then
1356 if CmdIndex
> 0 then
1357 CmdIndex
:= CmdIndex
- 1;
1358 Line
:= CommandHistory
[CmdIndex
];
1359 Cpos
:= Length(Line
) + 1;
1361 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1362 if not gChatShow
then Inc(conSkipLines
);
1363 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1364 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1368 CPos
:= Length(Line
) + 1;
1369 IK_A
..IK_Z
, IK_SPACE
, IK_SHIFT
, IK_RSHIFT
, IK_CAPSLOCK
, IK_LBRACKET
, IK_RBRACKET
,
1370 IK_SEMICOLON
, IK_QUOTE
, IK_BACKSLASH
, IK_SLASH
, IK_COMMA
, IK_DOT
, IK_EQUALS
,
1371 IK_0
, IK_1
, IK_2
, IK_3
, IK_4
, IK_5
, IK_6
, IK_7
, IK_8
, IK_9
, IK_MINUS
, IK_EQUALS
:
1372 (* see TEXTINPUT event *)
1374 if not gSkipFirstChar
then
1376 if gConsoleShow
and g_Console_MatchBind(K
, 'toggleconsole') then
1379 if g_Console_MatchBind(K
, 'togglemenu') then
1382 g_Console_Chat_Switch
1383 else if gConsoleShow
then
1390 function GetStr(var Str
: AnsiString): AnsiString;
1395 if Str
[1] = '"' then
1397 for b
:= 1 to Length(Str
) do
1398 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1400 Result
:= Copy(Str
, 2, b
-1);
1401 Delete(Str
, 1, b
+1);
1407 for a
:= 1 to Length(Str
) do
1408 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1410 Result
:= Copy(Str
, 1, a
);
1411 Delete(Str
, 1, a
+1);
1417 function ParseString(Str
: AnsiString): SSArray
;
1428 SetLength(Result
, Length(Result
)+1);
1429 Result
[High(Result
)] := GetStr(Str
);
1433 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1435 procedure conmsg (s
: AnsiString);
1439 if length(s
) = 0 then exit
;
1440 for a
:= 0 to High(MsgArray
) do
1452 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1453 with MsgArray
[High(MsgArray
)] do
1463 // put it to console
1465 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1467 // now show 'em out of console too
1468 show
:= show
and gAllowConsoleMessages
;
1469 if show
and gShowMessages
then
1471 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1472 while length(L
) > 0 do
1475 if f
<= 0 then f
:= length(L
)+1;
1476 conmsg(Copy(L
, 1, f
-1));
1481 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1482 //ConsoleHistory[High(ConsoleHistory)] := L;
1486 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1493 consolewriterLastWasEOL
: Boolean = false;
1495 procedure consolewriter (constref buf
; len
: SizeUInt
);
1499 if (len
< 1) then exit
;
1501 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1504 if (b
[0] <> 13) and (b
[0] <> 10) then
1506 cbufPut(AnsiChar(b
[0]));
1510 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1519 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1520 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1521 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1522 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1524 g_Console_Add(s
, show
);
1528 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1532 g_Console_Add(formatstrf(s
, args
), true);
1536 consolewriterLastWasEOL
:= false;
1537 formatstrf(s
, args
, consolewriter
);
1538 if not consolewriterLastWasEOL
then cbufPut(#10);
1543 procedure g_Console_Clear();
1545 //ConsoleHistory := nil;
1550 procedure AddToHistory(L
: AnsiString);
1554 len
:= Length(CommandHistory
);
1557 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1559 SetLength(CommandHistory
, len
+1);
1560 CommandHistory
[len
] := L
;
1563 CmdIndex
:= Length(CommandHistory
);
1566 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1575 if Trim(C
) = '' then
1578 Arr
:= ParseString(C
);
1582 for i
:= 0 to High(Whitelist
) do
1583 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1587 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1594 if Trim(L
) = '' then
1597 conSkipLines
:= 0; // "unscroll"
1599 if L
= 'goobers' then
1604 g_Console_Add('Your memory serves you well.');
1610 g_Console_Add('> '+L
);
1615 Arr
:= ParseString(L
);
1619 if commands
= nil then
1625 for i
:= 0 to High(commands
) do
1627 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1629 if commands
[i
].action
>= 0 then
1631 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1634 if assigned(commands
[i
].procEx
) then
1636 commands
[i
].procEx(@commands
[i
], Arr
);
1639 if assigned(commands
[i
].proc
) then
1641 commands
[i
].proc(Arr
);
1647 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1651 function g_Console_Interactive
: Boolean;
1653 Result
:= gConsoleShow
1656 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1658 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1660 ASSERT(key
< e_MaxInputKeys
);
1663 gInputBinds
[key
].down
:= ParseAlias(down
);
1664 gInputBinds
[key
].up
:= ParseAlias(up
)
1668 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
1670 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1671 var i
, len
: Integer;
1675 if len
= Length(b
) then
1678 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1686 ASSERT(key
< e_MaxInputKeys
);
1687 result
:= EqualsCommandLists(ParseAlias(down
), gInputBinds
[key
].down
) and EqualsCommandLists(ParseAlias(up
), gInputBinds
[key
].up
)
1690 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1695 if commands
= nil then Exit
;
1697 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1699 if g_Console_MatchBind(i
, down
, up
) then
1710 function g_Console_Action (action
: Integer): Boolean;
1711 var i
, len
: Integer;
1713 ASSERT(action
>= FIRST_ACTION
);
1714 ASSERT(action
<= LAST_ACTION
);
1716 len
:= Length(gPlayerAction
);
1717 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1721 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1724 if (not g_GUIGrabInput
) and (not gChatShow
) and (not gConsoleShow
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1727 for i
:= 0 to High(gInputBinds
[key
].down
) do
1728 g_Console_Process(gInputBinds
[key
].down
[i
], True)
1730 for i
:= 0 to High(gInputBinds
[key
].up
) do
1731 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1733 if down
and not menu_toggled
then
1735 menu_toggled
:= False
1738 procedure g_Console_ResetBinds
;
1741 for i
:= 0 to e_MaxInputKeys
- 1 do
1742 g_Console_BindKey(i
, '', '');
1744 g_Console_BindKey(IK_GRAVE
, 'toggleconsole');
1745 g_Console_BindKey(IK_ESCAPE
, 'togglemenu');
1746 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1747 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1748 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1749 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1750 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1751 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1752 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1753 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1754 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1755 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1756 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1757 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1758 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1759 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1760 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1761 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1762 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1763 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1764 g_Console_BindKey(IK_9
, 'p1_weapon 9');
1765 g_Console_BindKey(IK_0
, 'p1_weapon 10');
1766 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
1767 g_Console_BindKey(IK_T
, 'togglechat');
1768 g_Console_BindKey(IK_Y
, 'toggleteamchat');
1769 g_Console_BindKey(IK_F11
, 'screenshot');
1770 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
1771 g_Console_BindKey(IK_PAUSE
, 'pause');
1772 g_Console_BindKey(IK_F1
, 'vote');
1774 (* for i := 0 to e_MaxJoys - 1 do *)
1777 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_LEFT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
1778 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_RIGHT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
1779 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_UP
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
1780 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_DOWN
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
1781 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
1782 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
1783 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
1784 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
1785 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
1786 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
1787 g_Console_BindKey(e_JoyButtonToKey(i
, 10), 'togglemenu');
1790 // HACK: VK_ESCAPE always used as togglemenu, so don't touch it!
1792 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
1793 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
1794 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
1795 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
1796 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
1797 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
1798 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
1799 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
1800 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
1801 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
1802 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
1803 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
1804 g_Console_BindKey(VK_0
, 'weapon 1');
1805 g_Console_BindKey(VK_1
, 'weapon 2');
1806 g_Console_BindKey(VK_2
, 'weapon 3');
1807 g_Console_BindKey(VK_3
, 'weapon 4');
1808 g_Console_BindKey(VK_4
, 'weapon 5');
1809 g_Console_BindKey(VK_5
, 'weapon 6');
1810 g_Console_BindKey(VK_6
, 'weapon 7');
1811 g_Console_BindKey(VK_7
, 'weapon 8');
1812 g_Console_BindKey(VK_8
, 'weapon 9');
1813 g_Console_BindKey(VK_9
, 'weapon 10');
1814 g_Console_BindKey(VK_A
, 'weapon 11');
1815 g_Console_BindKey(VK_CHAT
, 'togglechat');
1816 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
1817 g_Console_BindKey(VK_CONSOLE
, 'toggleconsole');
1818 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
1819 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
1820 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
1821 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
1824 procedure g_Console_ReadConfig (filename
: String);
1825 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1827 if FileExists(filename
) then
1829 AssignFile(f
, filename
);
1839 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1841 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1842 g_Console_Process(s
, True)
1849 procedure g_Console_WriteConfig (filename
: String);
1850 var f
: TextFile
; i
, j
: Integer;
1852 AssignFile(f
, filename
);
1854 WriteLn(f
, '// generated by doom2d, do not modify');
1855 WriteLn(f
, 'unbindall');
1856 for i
:= 0 to e_MaxInputKeys
- 1 do
1857 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
1858 WriteLn(f
, 'bind ', e_KeyNames
[i
], ' "', GetCommandString(gInputBinds
[i
].down
), '" "', GetCommandString(gInputBinds
[i
].up
), '"');
1859 for i
:= 0 to High(commands
) do
1861 if not commands
[i
].cheat
then
1863 if @commands
[i
].procEx
= @boolVarHandler
then
1865 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
1866 WriteLn(f
, commands
[i
].cmd
, ' "', j
, '"')
1868 else if @commands
[i
].procEx
= @intVarHandler
then
1870 WriteLn(f
, commands
[i
].cmd
, ' "', PInteger(commands
[i
].ptr
)^, '"')
1872 else if @commands
[i
].procEx
= @singleVarHandler
then
1874 WriteLn(f
, commands
[i
].cmd
, ' "', PVarSingle(commands
[i
].ptr
).val
^:0:6, '"')