033a46827d5a3312a6b062fa335d37446edc5038
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 = true; // íå ïåðåñîõðàíÿòü êîíôèã âî âðåìÿ ïàðñèíãà
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 ConsoleHeight
: Single;
131 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
135 //ConsoleHistory: SSArray;
136 CommandHistory
: SSArray
;
138 commands
: Array of TCommand
= nil;
139 Aliases
: Array of TAlias
= nil;
141 conSkipLines
: Integer = 0;
142 MsgArray
: Array [0..4] of record
147 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
150 menu_toggled
: BOOLEAN; (* hack for menu controls *)
154 procedure g_Console_Switch
;
157 gConsoleShow
:= not gConsoleShow
;
160 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
163 procedure g_Console_Chat_Switch (Team
: Boolean = False);
165 if not g_Game_IsNet
then Exit
;
166 gConsoleShow
:= False;
167 gChatShow
:= not gChatShow
;
173 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
176 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
177 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
186 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
187 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
188 if (pos
> slen
) then exit
;
189 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
191 while (pos
<= slen
) do
193 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
194 res
:= res
*10+Byte(s
[pos
])-48;
197 if (pos
<= slen
) then
200 if (s
[pos
] <> '.') then exit
;
202 while (pos
<= slen
) do
204 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
206 res
+= frac
*(Byte(s
[pos
])-48);
210 if (pos
<= slen
) then exit
; // oops
215 // ////////////////////////////////////////////////////////////////////////// //
216 // <0: no arg; 0/1: true/false; 666: toggle
217 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
219 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
221 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
222 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
223 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
224 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
228 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
229 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
233 if (Length(p
) > 2) then
235 conwritefln('too many arguments to ''%s''', [p
[0]]);
240 case conGetBoolArg(p
, 1) of
242 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
243 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
244 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
247 g_Console_WriteGameConfig();
248 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
249 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
253 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
257 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
261 if (Length(p
) <> 2) then
263 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
268 old
:= PInteger(me
.ptr
)^;
269 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
270 if PInteger(me
.ptr
)^ <> old
then
271 g_Console_WriteGameConfig();
273 conwritefln('invalid integer value: "%s"', [p
[1]]);
279 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
284 f
:= Length(commands
);
285 SetLength(commands
, f
+1);
287 cp
.cmd
:= LowerCase(conname
);
289 cp
.procEx
:= boolVarHandler
;
291 cp
.hidden
:= ahidden
;
300 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
305 f
:= Length(commands
);
306 SetLength(commands
, f
+1);
308 cp
.cmd
:= LowerCase(conname
);
310 cp
.procEx
:= intVarHandler
;
312 cp
.hidden
:= ahidden
;
321 // ////////////////////////////////////////////////////////////////////////// //
323 PVarSingle
= ^TVarSingle
;
326 min
, max
, def
: Single; // default will be starting value
330 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
336 if (Length(p
) > 2) then
338 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
341 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
;
364 if pv
.val
^ <> old
then
365 g_Console_WriteGameConfig();
367 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
368 conwritefln('%s %s', [msg
, pv
.val
^]);
372 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
378 GetMem(pv
, sizeof(TVarSingle
));
383 f
:= Length(commands
);
384 SetLength(commands
, f
+1);
386 cp
.cmd
:= LowerCase(conname
);
388 cp
.procEx
:= singleVarHandler
;
390 cp
.hidden
:= ahidden
;
399 // ////////////////////////////////////////////////////////////////////////// //
400 function GetStrACmd(var Str
: AnsiString): AnsiString;
405 for a
:= 1 to Length(Str
) do
406 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
408 Result
:= Copy(Str
, 1, a
);
415 function ParseAlias(Str
: AnsiString): SSArray
;
426 SetLength(Result
, Length(Result
)+1);
427 Result
[High(Result
)] := GetStrACmd(Str
);
431 procedure ConsoleCommands(p
: SSArray
);
437 cmd
:= LowerCase(p
[0]);
440 if cmd
= 'clear' then
442 //ConsoleHistory := nil;
446 for a
:= 0 to High(MsgArray
) do
454 if cmd
= 'clearhistory' then
455 CommandHistory
:= nil;
457 if cmd
= 'showhistory' then
458 if CommandHistory
<> nil then
461 for a
:= 0 to High(CommandHistory
) do
462 g_Console_Add(' '+CommandHistory
[a
]);
465 if cmd
= 'commands' then
468 g_Console_Add('commands list:');
469 for a
:= High(commands
) downto 0 do
471 if (Length(commands
[a
].help
) > 0) then
473 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
477 g_Console_Add(' '+commands
[a
].cmd
);
483 g_Console_Add(TimeToStr(Now
), True);
486 g_Console_Add(DateToStr(Now
), True);
489 if Length(p
) > 1 then
491 if p
[1] = 'ololo' then
496 for a
:= 1 to High(p
) do
498 g_Console_Add(b_Text_Format(s
), True);
507 if ConsoleHistory <> nil then
509 if Length(P) > 1 then
512 s := GameDir+'/console.txt';
517 if IOResult <> 0 then
519 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
524 for a := 0 to High(ConsoleHistory) do
525 WriteLn(F, ConsoleHistory[a]);
528 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
537 if Length(p
) = 2 then
538 g_Console_ReadConfig(GameDir
+ '/' + p
[1])
540 g_Console_Add('exec <script file>');
543 if cmd
= 'writeconfig' then
545 // writeconfig <filename>
546 if Length(p
) = 2 then
547 g_Console_WriteConfig(GameDir
+ '/' + p
[1])
549 g_Console_Add('writeconfig <file>');
552 if (cmd
= 'ver') or (cmd
= 'version') then
554 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
555 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
556 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
559 if cmd
= 'alias' then
561 // alias [alias_name] [commands]
562 if Length(p
) > 1 then
564 for a
:= 0 to High(Aliases
) do
565 if Aliases
[a
].name
= p
[1] then
567 if Length(p
) > 2 then
568 Aliases
[a
].commands
:= ParseAlias(p
[2])
570 for b
:= 0 to High(Aliases
[a
].commands
) do
571 g_Console_Add(Aliases
[a
].commands
[b
]);
574 SetLength(Aliases
, Length(Aliases
)+1);
576 Aliases
[a
].name
:= p
[1];
577 if Length(p
) > 2 then
578 Aliases
[a
].commands
:= ParseAlias(p
[2])
580 for b
:= 0 to High(Aliases
[a
].commands
) do
581 g_Console_Add(Aliases
[a
].commands
[b
]);
583 for a
:= 0 to High(Aliases
) do
584 if Aliases
[a
].commands
<> nil then
585 g_Console_Add(Aliases
[a
].name
);
591 if Length(p
) > 1 then
593 if Aliases
= nil then
595 for a
:= 0 to High(Aliases
) do
596 if Aliases
[a
].name
= p
[1] then
598 if Aliases
[a
].commands
<> nil then
600 // with this system proper endless loop detection seems either impossible
601 // or very dirty to implement, so let's have this instead
602 // prevents endless loops
603 for b
:= 0 to High(Aliases
[a
].commands
) do
606 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
607 if not RecursionLimitHit
then
608 g_Console_Process(Aliases
[a
].commands
[b
], True);
611 if (RecursionDepth
= 0) and RecursionLimitHit
then
613 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
614 RecursionLimitHit
:= False;
621 g_Console_Add('call <alias name>');
625 procedure WhitelistCommand(cmd
: AnsiString);
629 SetLength(Whitelist
, Length(Whitelist
)+1);
630 a
:= High(Whitelist
);
631 Whitelist
[a
] := LowerCase(cmd
);
634 procedure segfault (p
: SSArray
);
641 function GetCommandString (p
: SSArray
): AnsiString;
645 if Length(p
) >= 1 then
648 for i
:= 1 to High(p
) do
649 result
:= result
+ '; ' + p
[i
]
653 function QuoteStr(str
: String): String;
655 if Pos(' ', str
) > 0 then
656 Result
:= '"' + str
+ '"'
661 procedure BindCommands (p
: SSArray
);
662 var cmd
, key
: AnsiString; i
: Integer;
664 cmd
:= LowerCase(p
[0]);
667 // bind <key> [down [up]]
668 if (Length(p
) >= 2) and (Length(p
) <= 4) then
671 key
:= LowerCase(p
[1]);
672 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
673 if i
< e_MaxInputKeys
then
675 if Length(p
) = 2 then
676 g_Console_Add(QuoteStr(e_KeyNames
[i
]) + ' = ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)))
677 else if Length(p
) = 3 then
678 g_Console_BindKey(i
, p
[2], '')
680 g_Console_BindKey(i
, p
[2], p
[3])
683 g_Console_Add('bind: "' + p
[1] + '" is not a key')
687 g_Console_Add('bind <key> <down action> [up action]')
690 for i
:= 0 to e_MaxInputKeys
- 1 do
691 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
692 g_Console_Add(e_KeyNames
[i
] + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
695 if Length(p
) = 2 then
697 key
:= LowerCase(p
[1]);
699 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
700 if i
< e_MaxInputKeys
then
701 g_Console_BindKey(i
, '')
703 g_Console_Add('unbind: "' + p
[1] + '" is not a key')
706 g_Console_Add('unbind <key>');
708 for i
:= 0 to e_MaxInputKeys
- 1 do
709 g_Console_BindKey(i
, '');
711 g_Touch_ShowKeyboard(True);
713 g_Touch_ShowKeyboard(False);
718 else if gChatShow
then
719 g_Console_Chat_Switch
727 if not gConsoleShow
and (g_ActiveWindow
= nil) then
728 g_Console_Chat_Switch
;
730 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
731 if not gConsoleShow
and (g_ActiveWindow
= nil) then
732 g_Console_Chat_Switch(True);
736 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
741 SetLength(commands
, Length(commands
)+1);
744 cp
.cmd
:= LowerCase(cmd
);
748 cp
.hidden
:= ahidden
;
756 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
758 PrefixList
: array [0..1] of AnsiString = ('+', '-');
759 PlayerList
: array [0..1] of Integer = (1, 2);
764 procedure NewAction (cmd
: AnsiString; player
: Integer);
767 SetLength(commands
, Length(commands
) + 1);
768 cp
:= @commands
[High(commands
)];
769 cp
.cmd
:= LowerCase(cmd
);
782 ASSERT(action
>= FIRST_ACTION
);
783 ASSERT(action
<= LAST_ACTION
);
784 for s
in PrefixList
do
786 NewAction(s
+ cmd
, 0);
787 for i
in PlayerList
do
788 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
792 procedure g_Console_Init();
796 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
797 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
798 gConsoleShow
:= False;
804 for a
:= 0 to High(MsgArray
) do
811 AddCommand('segfault', segfault
, 'make segfault');
813 AddCommand('bind', BindCommands
);
814 AddCommand('bindlist', BindCommands
);
815 AddCommand('unbind', BindCommands
);
816 AddCommand('unbindall', BindCommands
);
817 AddCommand('showkeyboard', BindCommands
);
818 AddCommand('hidekeyboard', BindCommands
);
819 AddCommand('togglemenu', BindCommands
);
820 AddCommand('toggleconsole', BindCommands
);
821 AddCommand('togglechat', BindCommands
);
822 AddCommand('toggleteamchat', BindCommands
);
824 AddCommand('clear', ConsoleCommands
, 'clear console');
825 AddCommand('clearhistory', ConsoleCommands
);
826 AddCommand('showhistory', ConsoleCommands
);
827 AddCommand('commands', ConsoleCommands
);
828 AddCommand('time', ConsoleCommands
);
829 AddCommand('date', ConsoleCommands
);
830 AddCommand('echo', ConsoleCommands
);
831 AddCommand('dump', ConsoleCommands
);
832 AddCommand('exec', ConsoleCommands
);
833 AddCommand('writeconfig', ConsoleCommands
);
834 AddCommand('alias', ConsoleCommands
);
835 AddCommand('call', ConsoleCommands
);
836 AddCommand('ver', ConsoleCommands
);
837 AddCommand('version', ConsoleCommands
);
839 AddCommand('d_window', DebugCommands
);
840 AddCommand('d_sounds', DebugCommands
);
841 AddCommand('d_frames', DebugCommands
);
842 AddCommand('d_winmsg', DebugCommands
);
843 AddCommand('d_monoff', DebugCommands
);
844 AddCommand('d_botoff', DebugCommands
);
845 AddCommand('d_monster', DebugCommands
);
846 AddCommand('d_health', DebugCommands
);
847 AddCommand('d_player', DebugCommands
);
848 AddCommand('d_joy', DebugCommands
);
849 AddCommand('d_mem', DebugCommands
);
851 AddCommand('p1_name', GameCVars
);
852 AddCommand('p2_name', GameCVars
);
853 AddCommand('p1_color', GameCVars
);
854 AddCommand('p2_color', GameCVars
);
855 AddCommand('r_showscore', GameCVars
);
856 AddCommand('r_showlives', GameCVars
);
857 AddCommand('r_showstat', GameCVars
);
858 AddCommand('r_showkillmsg', GameCVars
);
859 AddCommand('r_showspect', GameCVars
);
860 AddCommand('r_showping', GameCVars
);
861 AddCommand('g_gamemode', GameCVars
);
862 AddCommand('g_friendlyfire', GameCVars
);
863 AddCommand('g_weaponstay', GameCVars
);
864 AddCommand('g_allow_exit', GameCVars
);
865 AddCommand('g_allow_monsters', GameCVars
);
866 AddCommand('g_bot_vsmonsters', GameCVars
);
867 AddCommand('g_bot_vsplayers', GameCVars
);
868 AddCommand('g_scorelimit', GameCVars
);
869 AddCommand('g_timelimit', GameCVars
);
870 AddCommand('g_maxlives', GameCVars
);
871 AddCommand('g_warmuptime', GameCVars
);
872 AddCommand('net_interp', GameCVars
);
873 AddCommand('net_forceplayerupdate', GameCVars
);
874 AddCommand('net_predictself', GameCVars
);
875 AddCommand('sv_name', GameCVars
);
876 AddCommand('sv_passwd', GameCVars
);
877 AddCommand('sv_maxplrs', GameCVars
);
878 AddCommand('sv_public', GameCVars
);
879 AddCommand('sv_intertime', GameCVars
);
881 AddCommand('quit', GameCommands
);
882 AddCommand('exit', GameCommands
);
883 AddCommand('pause', GameCommands
);
884 AddCommand('endgame', GameCommands
);
885 AddCommand('restart', GameCommands
);
886 AddCommand('addbot', GameCommands
);
887 AddCommand('bot_add', GameCommands
);
888 AddCommand('bot_addlist', GameCommands
);
889 AddCommand('bot_addred', GameCommands
);
890 AddCommand('bot_addblue', GameCommands
);
891 AddCommand('bot_removeall', GameCommands
);
892 AddCommand('chat', GameCommands
);
893 AddCommand('teamchat', GameCommands
);
894 AddCommand('game', GameCommands
);
895 AddCommand('host', GameCommands
);
896 AddCommand('map', GameCommands
);
897 AddCommand('nextmap', GameCommands
);
898 AddCommand('endmap', GameCommands
);
899 AddCommand('goodbye', GameCommands
);
900 AddCommand('suicide', GameCommands
);
901 AddCommand('spectate', GameCommands
);
902 AddCommand('ready', GameCommands
);
903 AddCommand('kick', GameCommands
);
904 AddCommand('kick_id', GameCommands
);
905 AddCommand('ban', GameCommands
);
906 AddCommand('permban', GameCommands
);
907 AddCommand('ban_id', GameCommands
);
908 AddCommand('permban_id', GameCommands
);
909 AddCommand('unban', GameCommands
);
910 AddCommand('connect', GameCommands
);
911 AddCommand('disconnect', GameCommands
);
912 AddCommand('reconnect', GameCommands
);
913 AddCommand('say', GameCommands
);
914 AddCommand('tell', GameCommands
);
915 AddCommand('overtime', GameCommands
);
916 AddCommand('rcon_password', GameCommands
);
917 AddCommand('rcon', GameCommands
);
918 AddCommand('callvote', GameCommands
);
919 AddCommand('vote', GameCommands
);
920 AddCommand('clientlist', GameCommands
);
921 AddCommand('event', GameCommands
);
922 AddCommand('screenshot', GameCommands
);
923 AddCommand('weapon', GameCommands
);
924 AddCommand('p1_weapon', GameCommands
);
925 AddCommand('p2_weapon', GameCommands
);
927 AddCommand('god', GameCheats
);
928 AddCommand('notarget', GameCheats
);
929 AddCommand('give', GameCheats
); // "exit" too ;-)
930 AddCommand('open', GameCheats
);
931 AddCommand('fly', GameCheats
);
932 AddCommand('noclip', GameCheats
);
933 AddCommand('speedy', GameCheats
);
934 AddCommand('jumpy', GameCheats
);
935 AddCommand('noreload', GameCheats
);
936 AddCommand('aimline', GameCheats
);
937 AddCommand('automap', GameCheats
);
939 AddAction('jump', ACTION_JUMP
);
940 AddAction('moveleft', ACTION_MOVELEFT
);
941 AddAction('moveright', ACTION_MOVERIGHT
);
942 AddAction('lookup', ACTION_LOOKUP
);
943 AddAction('lookdown', ACTION_LOOKDOWN
);
944 AddAction('attack', ACTION_ATTACK
);
945 AddAction('scores', ACTION_SCORES
);
946 AddAction('activate', ACTION_ACTIVATE
);
947 AddAction('strafe', ACTION_STRAFE
);
948 AddAction('weapnext', ACTION_WEAPNEXT
);
949 AddAction('weapprev', ACTION_WEAPPREV
);
951 WhitelistCommand('say');
952 WhitelistCommand('tell');
953 WhitelistCommand('overtime');
954 WhitelistCommand('ready');
955 WhitelistCommand('map');
956 WhitelistCommand('nextmap');
957 WhitelistCommand('endmap');
958 WhitelistCommand('restart');
959 WhitelistCommand('kick');
960 WhitelistCommand('ban');
962 WhitelistCommand('addbot');
963 WhitelistCommand('bot_add');
964 WhitelistCommand('bot_addred');
965 WhitelistCommand('bot_addblue');
966 WhitelistCommand('bot_removeall');
968 WhitelistCommand('g_gamemode');
969 WhitelistCommand('g_friendlyfire');
970 WhitelistCommand('g_weaponstay');
971 WhitelistCommand('g_allow_exit');
972 WhitelistCommand('g_allow_monsters');
973 WhitelistCommand('g_scorelimit');
974 WhitelistCommand('g_timelimit');
976 g_Console_ResetBinds
;
977 g_Console_ReadConfig(GameDir
+ '/dfconfig.cfg');
978 g_Console_ReadConfig(GameDir
+ '/autoexec.cfg');
979 gParsingBinds
:= False;
981 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
985 procedure g_Console_Update();
992 if gConsoleShow
and (Cons_Y
< 0) then
993 Cons_Y
:= Cons_Y
+Step
;
995 (* Colse animation *)
996 if (not gConsoleShow
) and (Cons_Y
> -Floor(gScreenHeight
* ConsoleHeight
)) then
997 Cons_Y
:= Cons_Y
-Step
;
1001 (* End open chat animation. Do not show console *)
1002 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
1003 Cons_Shown
:= False;
1009 (* End open animation *)
1015 if Cons_Y
<= -Floor(gScreenHeight
* ConsoleHeight
) then
1017 (* End close animation *)
1018 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
1019 Cons_Shown
:= False;
1020 InputReady
:= False;
1025 while a
<= High(MsgArray
) do
1027 if MsgArray
[a
].Time
> 0 then
1029 if MsgArray
[a
].Time
= 1 then
1031 if a
< High(MsgArray
) then
1033 for b
:= a
to High(MsgArray
)-1 do
1034 MsgArray
[b
] := MsgArray
[b
+1];
1036 MsgArray
[High(MsgArray
)].Time
:= 0;
1042 Dec(MsgArray
[a
].Time
);
1050 procedure drawConsoleText ();
1052 CWidth
, CHeight
: Byte;
1057 procedure putLine (sp
, ep
: LongWord);
1066 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1067 if wdt
+cw
> gScreenWidth
-8 then break
;
1068 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1072 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1073 // now print our part
1081 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1082 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1095 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1096 ty
:= Floor(gScreenHeight
* ConsoleHeight
) - 4 - 2 * CHeight
- Abs(Cons_Y
);
1097 skip
:= conSkipLines
;
1098 cbufLastLine(sp
, ep
);
1101 if ty
+CHeight
<= 0 then break
;
1102 until not cbufLineUp(sp
, ep
);
1105 procedure g_Console_Draw();
1107 CWidth
, CHeight
: Byte;
1109 a
, b
, offset_y
: Integer;
1111 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1113 if ChatTop
and gChatShow
then
1118 for a
:= 0 to High(MsgArray
) do
1119 if MsgArray
[a
].Time
> 0 then
1120 e_TextureFontPrintFmt(0, offset_y
+ CHeight
* a
, MsgArray
[a
].Msg
, gStdFont
, True);
1127 offset_y
:= gScreenHeight
- CHeight
- 1;
1130 e_TextureFontPrintEx(0, offset_y
, 'say team> ' + Line
, gStdFont
, 255, 255, 255, 1, True);
1131 e_TextureFontPrintEx((CPos
+ 9) * CWidth
, offset_y
, '_', gStdFont
, 255, 255, 255, 1, True);
1135 e_TextureFontPrintEx(0, offset_y
, 'say> ' + Line
, gStdFont
, 255, 255, 255, 1, True);
1136 e_TextureFontPrintEx((CPos
+ 4) * CWidth
, offset_y
, '_', gStdFont
, 255, 255, 255, 1, True);
1140 if not Cons_Shown
then
1145 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1146 a
:= (gScreenWidth
- 2*mfW
) div 2;
1147 b
:= Cons_Y
+ (Floor(gScreenHeight
* ConsoleHeight
) - 2 * mfH
) div 2;
1148 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1149 _RGB(128, 0, 0), 2.0);
1152 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, Floor(gScreenHeight
* ConsoleHeight
));
1153 e_TextureFontPrint(0, Cons_Y
+ Floor(gScreenHeight
* ConsoleHeight
) - CHeight
- 4, '> ' + Line
, gStdFont
);
1157 if ConsoleHistory <> nil then
1161 if Length(ConsoleHistory) > (Floor(gScreenHeight * ConsoleHeight) div CHeight) - 1 then
1162 b := Length(ConsoleHistory) - (Floor(gScreenHeight * ConsoleHeight) div CHeight) + 1;
1164 b := Max(b-Offset, 0);
1165 d := Max(High(ConsoleHistory)-Offset, 0);
1168 for a := d downto b do
1170 e_TextureFontPrintFmt(0, Floor(gScreenHeight * ConsoleHeight) - 4 - c * CHeight - Abs(Cons_Y), ConsoleHistory[a], gStdFont, True);
1176 e_TextureFontPrint((CPos
+ 1) * CWidth
, Cons_Y
+ Floor(gScreenHeight
* ConsoleHeight
) - 21, '_', gStdFont
);
1179 procedure g_Console_Char(C
: AnsiChar);
1181 if InputReady
and (gConsoleShow
or gChatShow
) then
1183 Insert(C
, Line
, CPos
);
1190 tcomplist
: array of AnsiString = nil;
1191 tcompidx
: array of Integer = nil;
1193 procedure Complete ();
1197 ll
, lpfx
, cmd
: AnsiString;
1199 if (Length(Line
) = 0) then
1202 for i
:= 0 to High(commands
) do
1204 // hidden commands are hidden when cheats aren't enabled
1205 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1206 if (Length(commands
[i
].help
) > 0) then
1208 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1212 g_Console_Add(' '+commands
[i
].cmd
);
1218 ll
:= LowerCase(Line
);
1221 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1223 ll
:= Copy(ll
, 0, Length(ll
)-1);
1224 for i
:= 0 to High(commands
) do
1226 // hidden commands are hidden when cheats aren't enabled
1227 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1228 if (commands
[i
].cmd
= ll
) then
1230 if (Length(commands
[i
].help
) > 0) then
1232 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1239 // build completion list
1241 for i
:= 0 to High(commands
) do
1243 // hidden commands are hidden when cheats aren't enabled
1244 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1245 cmd
:= commands
[i
].cmd
;
1246 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1248 if (tused
= Length(tcomplist
)) then
1250 SetLength(tcomplist
, Length(tcomplist
)+128);
1251 SetLength(tcompidx
, Length(tcompidx
)+128);
1253 tcomplist
[tused
] := cmd
;
1254 tcompidx
[tused
] := i
;
1256 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1260 // get longest prefix
1261 for i
:= 0 to tused
-1 do
1263 cmd
:= tcomplist
[i
];
1264 for c
:= 1 to Length(lpfx
) do
1266 if (c
> Length(cmd
)) then break
;
1267 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1271 if (tused
= 0) then exit
;
1275 Line
:= tcomplist
[0]+' ';
1276 CPos
:= Length(Line
)+1;
1280 // has longest prefix?
1281 if (Length(lpfx
) > Length(ll
)) then
1284 CPos
:= Length(Line
)+1;
1289 for i
:= 0 to tused
-1 do
1291 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1293 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1297 g_Console_Add(' '+tcomplist
[i
]);
1305 procedure g_Console_Control(K
: Word);
1309 if (Length(Line
) > 0) and (CPos
> 1) then
1311 Delete(Line
, CPos
-1, 1);
1315 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1316 Delete(Line
, CPos
, 1);
1317 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1320 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1321 if CPos
<= Length(Line
) then
1323 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1325 if gConsoleShow
then
1326 g_Console_Process(Line
)
1330 if (Length(Line
) > 0) and g_Game_IsNet
then
1334 if g_Game_IsClient
then
1335 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1337 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1338 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1342 if g_Game_IsClient
then
1343 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1345 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1352 gJustChatted
:= True;
1353 g_Console_Chat_Switch
;
1354 InputReady
:= False;
1358 if not gChatShow
then
1360 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1361 if not gChatShow
then
1362 if (CommandHistory
<> nil) and
1363 (CmdIndex
< Length(CommandHistory
)) then
1365 if CmdIndex
< Length(CommandHistory
)-1 then
1366 CmdIndex
:= CmdIndex
+ 1;
1367 Line
:= CommandHistory
[CmdIndex
];
1368 CPos
:= Length(Line
) + 1;
1370 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1371 if not gChatShow
then
1372 if (CommandHistory
<> nil) and
1373 (CmdIndex
<= Length(CommandHistory
)) then
1375 if CmdIndex
> 0 then
1376 CmdIndex
:= CmdIndex
- 1;
1377 Line
:= CommandHistory
[CmdIndex
];
1378 Cpos
:= Length(Line
) + 1;
1380 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1381 if not gChatShow
then Inc(conSkipLines
);
1382 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1383 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1387 CPos
:= Length(Line
) + 1;
1388 IK_A
..IK_Z
, IK_SPACE
, IK_SHIFT
, IK_RSHIFT
, IK_CAPSLOCK
, IK_LBRACKET
, IK_RBRACKET
,
1389 IK_SEMICOLON
, IK_QUOTE
, IK_BACKSLASH
, IK_SLASH
, IK_COMMA
, IK_DOT
, IK_EQUALS
,
1390 IK_0
, IK_1
, IK_2
, IK_3
, IK_4
, IK_5
, IK_6
, IK_7
, IK_8
, IK_9
, IK_MINUS
, IK_EQUALS
:
1391 (* see TEXTINPUT event *)
1395 function GetStr(var Str
: AnsiString): AnsiString;
1400 if Str
[1] = '"' then
1402 for b
:= 1 to Length(Str
) do
1403 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1405 Result
:= Copy(Str
, 2, b
-1);
1406 Delete(Str
, 1, b
+1);
1412 for a
:= 1 to Length(Str
) do
1413 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1415 Result
:= Copy(Str
, 1, a
);
1416 Delete(Str
, 1, a
+1);
1422 function ParseString(Str
: AnsiString): SSArray
;
1433 SetLength(Result
, Length(Result
)+1);
1434 Result
[High(Result
)] := GetStr(Str
);
1438 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1440 procedure conmsg (s
: AnsiString);
1444 if length(s
) = 0 then exit
;
1445 for a
:= 0 to High(MsgArray
) do
1457 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1458 with MsgArray
[High(MsgArray
)] do
1468 // put it to console
1470 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1472 // now show 'em out of console too
1473 show
:= show
and gAllowConsoleMessages
;
1474 if show
and gShowMessages
then
1476 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1477 while length(L
) > 0 do
1480 if f
<= 0 then f
:= length(L
)+1;
1481 conmsg(Copy(L
, 1, f
-1));
1486 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1487 //ConsoleHistory[High(ConsoleHistory)] := L;
1491 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1498 consolewriterLastWasEOL
: Boolean = false;
1500 procedure consolewriter (constref buf
; len
: SizeUInt
);
1504 if (len
< 1) then exit
;
1506 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1509 if (b
[0] <> 13) and (b
[0] <> 10) then
1511 cbufPut(AnsiChar(b
[0]));
1515 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1524 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1525 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1526 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1527 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1529 g_Console_Add(s
, show
);
1533 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1537 g_Console_Add(formatstrf(s
, args
), true);
1541 consolewriterLastWasEOL
:= false;
1542 formatstrf(s
, args
, consolewriter
);
1543 if not consolewriterLastWasEOL
then cbufPut(#10);
1548 procedure g_Console_Clear();
1550 //ConsoleHistory := nil;
1555 procedure AddToHistory(L
: AnsiString);
1559 len
:= Length(CommandHistory
);
1562 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1564 SetLength(CommandHistory
, len
+1);
1565 CommandHistory
[len
] := L
;
1568 CmdIndex
:= Length(CommandHistory
);
1571 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1580 if Trim(C
) = '' then
1583 Arr
:= ParseString(C
);
1587 for i
:= 0 to High(Whitelist
) do
1588 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1592 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1599 if Trim(L
) = '' then
1602 conSkipLines
:= 0; // "unscroll"
1604 if L
= 'goobers' then
1609 g_Console_Add('Your memory serves you well.');
1615 g_Console_Add('> '+L
);
1620 Arr
:= ParseString(L
);
1624 if commands
= nil then
1630 for i
:= 0 to High(commands
) do
1632 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1634 if commands
[i
].action
>= 0 then
1636 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1639 if assigned(commands
[i
].procEx
) then
1641 commands
[i
].procEx(@commands
[i
], Arr
);
1644 if assigned(commands
[i
].proc
) then
1646 commands
[i
].proc(Arr
);
1652 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1656 function g_Console_Interactive
: Boolean;
1658 Result
:= gConsoleShow
1661 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1663 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1665 ASSERT(key
< e_MaxInputKeys
);
1668 gInputBinds
[key
].down
:= ParseAlias(down
);
1669 gInputBinds
[key
].up
:= ParseAlias(up
);
1671 g_Console_WriteGameConfig();
1674 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
1676 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1677 var i
, len
: Integer;
1681 if len
= Length(b
) then
1684 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1692 ASSERT(key
< e_MaxInputKeys
);
1693 result
:= EqualsCommandLists(ParseAlias(down
), gInputBinds
[key
].down
) and EqualsCommandLists(ParseAlias(up
), gInputBinds
[key
].up
)
1696 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1701 if commands
= nil then Exit
;
1703 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1705 if g_Console_MatchBind(i
, down
, up
) then
1716 function g_Console_Action (action
: Integer): Boolean;
1717 var i
, len
: Integer;
1719 ASSERT(action
>= FIRST_ACTION
);
1720 ASSERT(action
<= LAST_ACTION
);
1722 len
:= Length(gPlayerAction
);
1723 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1727 function BindsAllowed (key
: Integer): Boolean;
1730 if (not g_GUIGrabInput
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1733 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1734 g_Console_MatchBind(key
, 'showkeyboard') or
1735 g_Console_MatchBind(key
, 'hidekeyboard')
1736 else if gConsoleShow
or (g_ActiveWindow
<> nil) or (gGameSettings
.GameType
= GT_NONE
) then
1737 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1738 g_Console_MatchBind(key
, 'toggleconsole') or
1739 g_Console_MatchBind(key
, 'showkeyboard') or
1740 g_Console_MatchBind(key
, 'hidekeyboard')
1746 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1749 if BindsAllowed(key
) then
1752 for i
:= 0 to High(gInputBinds
[key
].down
) do
1753 g_Console_Process(gInputBinds
[key
].down
[i
], True)
1755 for i
:= 0 to High(gInputBinds
[key
].up
) do
1756 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1758 if down
and not menu_toggled
then
1760 menu_toggled
:= False
1763 procedure g_Console_ResetBinds
;
1766 for i
:= 0 to e_MaxInputKeys
- 1 do
1767 g_Console_BindKey(i
, '', '');
1769 g_Console_BindKey(IK_GRAVE
, 'toggleconsole');
1770 g_Console_BindKey(IK_ESCAPE
, 'togglemenu');
1771 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1772 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1773 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1774 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1775 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1776 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1777 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1778 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1779 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1780 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1781 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1782 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1783 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1784 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1785 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1786 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1787 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1788 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1789 g_Console_BindKey(IK_9
, 'p1_weapon 9');
1790 g_Console_BindKey(IK_0
, 'p1_weapon 10');
1791 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
1792 g_Console_BindKey(IK_T
, 'togglechat');
1793 g_Console_BindKey(IK_Y
, 'toggleteamchat');
1794 g_Console_BindKey(IK_F11
, 'screenshot');
1795 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
1796 g_Console_BindKey(IK_PAUSE
, 'pause');
1797 g_Console_BindKey(IK_F1
, 'vote');
1799 (* for i := 0 to e_MaxJoys - 1 do *)
1802 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_LEFT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
1803 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_RIGHT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
1804 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_UP
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
1805 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_DOWN
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
1806 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
1807 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
1808 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
1809 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
1810 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
1811 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
1812 g_Console_BindKey(e_JoyButtonToKey(i
, 10), 'togglemenu');
1815 g_Console_BindKey(VK_ESCAPE
, 'togglemenu');
1816 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
1817 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
1818 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
1819 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
1820 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
1821 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
1822 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
1823 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
1824 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
1825 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
1826 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
1827 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
1828 g_Console_BindKey(VK_0
, 'weapon 1');
1829 g_Console_BindKey(VK_1
, 'weapon 2');
1830 g_Console_BindKey(VK_2
, 'weapon 3');
1831 g_Console_BindKey(VK_3
, 'weapon 4');
1832 g_Console_BindKey(VK_4
, 'weapon 5');
1833 g_Console_BindKey(VK_5
, 'weapon 6');
1834 g_Console_BindKey(VK_6
, 'weapon 7');
1835 g_Console_BindKey(VK_7
, 'weapon 8');
1836 g_Console_BindKey(VK_8
, 'weapon 9');
1837 g_Console_BindKey(VK_9
, 'weapon 10');
1838 g_Console_BindKey(VK_A
, 'weapon 11');
1839 g_Console_BindKey(VK_CHAT
, 'togglechat');
1840 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
1841 g_Console_BindKey(VK_CONSOLE
, 'toggleconsole');
1842 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
1843 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
1844 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
1845 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
1848 procedure g_Console_ReadConfig (filename
: String);
1849 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1851 if FileExists(filename
) then
1853 AssignFile(f
, filename
);
1863 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1865 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1866 g_Console_Process(s
, True);
1873 procedure g_Console_WriteConfig (filename
: String);
1874 var f
: TextFile
; i
, j
: Integer;
1876 AssignFile(f
, filename
);
1878 WriteLn(f
, '// generated by doom2d, do not modify');
1879 WriteLn(f
, 'unbindall');
1880 for i
:= 0 to e_MaxInputKeys
- 1 do
1881 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
1883 Write(f
, 'bind ', e_KeyNames
[i
], ' ', QuoteStr(GetCommandString(gInputBinds
[i
].down
)));
1884 if Length(gInputBinds
[i
].down
) = 0 then
1886 if Length(gInputBinds
[i
].up
) > 0 then
1887 Write(f
, ' ', QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
1890 for i
:= 0 to High(commands
) do
1892 if not commands
[i
].cheat
then
1894 if @commands
[i
].procEx
= @boolVarHandler
then
1896 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
1897 WriteLn(f
, commands
[i
].cmd
, ' ', j
)
1899 else if @commands
[i
].procEx
= @intVarHandler
then
1901 WriteLn(f
, commands
[i
].cmd
, ' ', PInteger(commands
[i
].ptr
)^)
1903 else if @commands
[i
].procEx
= @singleVarHandler
then
1905 WriteLn(f
, commands
[i
].cmd
, ' ', PVarSingle(commands
[i
].ptr
).val
^:0:6)
1912 procedure g_Console_WriteGameConfig
;
1914 if gParsingBinds
then
1916 g_Console_WriteConfig(GameDir
+ '/dfconfig.cfg');
1920 conRegVar('chat_at_top', @ChatTop
, 'draw chat at top border', 'draw chat at top border');
1921 conRegVar('console_height', @ConsoleHeight
, 0.0, 1.0, 'set console size', 'set console size');
1924 ConsoleHeight
:= 0.35
1927 ConsoleHeight
:= 0.5