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_Switch ();
44 procedure g_Console_Char (C
: AnsiChar);
45 procedure g_Console_Control (K
: Word);
46 procedure g_Console_Process (L
: AnsiString; quiet
: Boolean=false);
47 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
48 procedure g_Console_Clear ();
49 function g_Console_CommandBlacklisted (C
: AnsiString): Boolean;
50 procedure g_Console_ReadConfig (filename
: String);
51 procedure g_Console_WriteConfig (filename
: String);
53 function g_Console_Interactive
: Boolean;
54 function g_Console_Action (action
: Integer): 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 // <0: no arg; 0/1: true/false
64 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
66 procedure g_Console_Chat_Switch (team
: Boolean=false);
68 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
69 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
70 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
72 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
73 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
77 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
78 gChatShow
: Boolean = false;
79 gChatTeam
: Boolean = false;
80 gAllowConsoleMessages
: Boolean = true;
81 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
82 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_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
150 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
151 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
160 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
161 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
162 if (pos
> slen
) then exit
;
163 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
165 while (pos
<= slen
) do
167 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
168 res
:= res
*10+Byte(s
[pos
])-48;
171 if (pos
<= slen
) then
174 if (s
[pos
] <> '.') then exit
;
176 while (pos
<= slen
) do
178 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
180 res
+= frac
*(Byte(s
[pos
])-48);
184 if (pos
<= slen
) then exit
; // oops
189 // ////////////////////////////////////////////////////////////////////////// //
190 // <0: no arg; 0/1: true/false; 666: toggle
191 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
193 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
195 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
196 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
197 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
198 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
202 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
203 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
205 if (Length(p
) > 2) then
207 conwritefln('too many arguments to ''%s''', [p
[0]]);
211 case conGetBoolArg(p
, 1) of
213 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
214 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
215 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
217 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
218 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
222 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
226 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
227 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
229 if (Length(p
) > 2) then
231 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;
241 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
242 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
246 if (Length(p
) <> 2) then
248 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
253 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
255 conwritefln('invalid integer value: "%s"', [p
[1]]);
261 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
266 f
:= Length(commands
);
267 SetLength(commands
, f
+1);
269 cp
.cmd
:= LowerCase(conname
);
271 cp
.procEx
:= boolVarHandler
;
273 cp
.hidden
:= ahidden
;
282 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
287 f
:= Length(commands
);
288 SetLength(commands
, f
+1);
290 cp
.cmd
:= LowerCase(conname
);
292 cp
.procEx
:= intVarHandler
;
294 cp
.hidden
:= ahidden
;
303 // ////////////////////////////////////////////////////////////////////////// //
305 PVarSingle
= ^TVarSingle
;
308 min
, max
, def
: Single; // default will be starting value
312 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
318 if (Length(p
) > 2) then
320 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
323 pv
:= PVarSingle(me
.ptr
);
324 if (Length(p
) = 2) then
326 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
327 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
328 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
329 (CompareText(p
[1], 'ona') = 0) then
335 if not conParseFloat(nv
, p
[1]) then
337 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
340 if (nv
< pv
.min
) then nv
:= pv
.min
;
341 if (nv
> pv
.max
) then nv
:= pv
.max
;
346 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
347 conwritefln('%s %s', [msg
, pv
.val
^]);
351 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
357 GetMem(pv
, sizeof(TVarSingle
));
362 f
:= Length(commands
);
363 SetLength(commands
, f
+1);
365 cp
.cmd
:= LowerCase(conname
);
367 cp
.procEx
:= singleVarHandler
;
369 cp
.hidden
:= ahidden
;
378 // ////////////////////////////////////////////////////////////////////////// //
379 function GetStrACmd(var Str
: AnsiString): AnsiString;
384 for a
:= 1 to Length(Str
) do
385 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
387 Result
:= Copy(Str
, 1, a
);
394 function ParseAlias(Str
: AnsiString): SSArray
;
405 SetLength(Result
, Length(Result
)+1);
406 Result
[High(Result
)] := GetStrACmd(Str
);
410 procedure ConsoleCommands(p
: SSArray
);
416 cmd
:= LowerCase(p
[0]);
419 if cmd
= 'clear' then
421 //ConsoleHistory := nil;
425 for a
:= 0 to High(MsgArray
) do
433 if cmd
= 'clearhistory' then
434 CommandHistory
:= nil;
436 if cmd
= 'showhistory' then
437 if CommandHistory
<> nil then
440 for a
:= 0 to High(CommandHistory
) do
441 g_Console_Add(' '+CommandHistory
[a
]);
444 if cmd
= 'commands' then
447 g_Console_Add('commands list:');
448 for a
:= High(commands
) downto 0 do
450 if (Length(commands
[a
].help
) > 0) then
452 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
456 g_Console_Add(' '+commands
[a
].cmd
);
462 g_Console_Add(TimeToStr(Now
), True);
465 g_Console_Add(DateToStr(Now
), True);
468 if Length(p
) > 1 then
470 if p
[1] = 'ololo' then
475 for a
:= 1 to High(p
) do
477 g_Console_Add(b_Text_Format(s
), True);
486 if ConsoleHistory <> nil then
488 if Length(P) > 1 then
491 s := GameDir+'/console.txt';
496 if IOResult <> 0 then
498 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
503 for a := 0 to High(ConsoleHistory) do
504 WriteLn(F, ConsoleHistory[a]);
507 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
516 if Length(p
) = 2 then
517 g_Console_ReadConfig(GameDir
+ '/' + p
[1])
519 g_Console_Add('exec <script file>');
522 if cmd
= 'writeconfig' then
524 // writeconfig <filename>
525 if Length(p
) = 2 then
526 g_Console_WriteConfig(GameDir
+ '/' + p
[1])
528 g_Console_Add('writeconfig <file>');
531 if (cmd
= 'ver') or (cmd
= 'version') then
533 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
534 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
535 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
538 if cmd
= 'alias' then
540 // alias [alias_name] [commands]
541 if Length(p
) > 1 then
543 for a
:= 0 to High(Aliases
) do
544 if Aliases
[a
].name
= p
[1] then
546 if Length(p
) > 2 then
547 Aliases
[a
].commands
:= ParseAlias(p
[2])
549 for b
:= 0 to High(Aliases
[a
].commands
) do
550 g_Console_Add(Aliases
[a
].commands
[b
]);
553 SetLength(Aliases
, Length(Aliases
)+1);
555 Aliases
[a
].name
:= p
[1];
556 if Length(p
) > 2 then
557 Aliases
[a
].commands
:= ParseAlias(p
[2])
559 for b
:= 0 to High(Aliases
[a
].commands
) do
560 g_Console_Add(Aliases
[a
].commands
[b
]);
562 for a
:= 0 to High(Aliases
) do
563 if Aliases
[a
].commands
<> nil then
564 g_Console_Add(Aliases
[a
].name
);
570 if Length(p
) > 1 then
572 if Aliases
= nil then
574 for a
:= 0 to High(Aliases
) do
575 if Aliases
[a
].name
= p
[1] then
577 if Aliases
[a
].commands
<> nil then
579 // with this system proper endless loop detection seems either impossible
580 // or very dirty to implement, so let's have this instead
581 // prevents endless loops
582 for b
:= 0 to High(Aliases
[a
].commands
) do
585 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
586 if not RecursionLimitHit
then
587 g_Console_Process(Aliases
[a
].commands
[b
], True);
590 if (RecursionDepth
= 0) and RecursionLimitHit
then
592 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
593 RecursionLimitHit
:= False;
600 g_Console_Add('call <alias name>');
604 procedure WhitelistCommand(cmd
: AnsiString);
608 SetLength(Whitelist
, Length(Whitelist
)+1);
609 a
:= High(Whitelist
);
610 Whitelist
[a
] := LowerCase(cmd
);
613 procedure segfault (p
: SSArray
);
620 function GetCommandString (p
: SSArray
): AnsiString;
624 if Length(p
) >= 1 then
627 for i
:= 1 to High(p
) do
628 result
:= result
+ '; ' + p
[i
]
632 procedure BindCommands (p
: SSArray
);
633 var cmd
, key
: AnsiString; i
: Integer;
635 cmd
:= LowerCase(p
[0]);
638 // bind <key> [down [up]]
639 if Length(p
) >= 2 then
642 key
:= LowerCase(p
[1]);
643 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
644 if i
< e_MaxInputKeys
then
646 if Length(p
) = 2 then
647 g_Console_Add('"' + e_KeyNames
[i
] + '" = "' + GetCommandString(gInputBinds
[i
].down
) + '" "' + GetCommandString(gInputBinds
[i
].up
) + '"')
648 else if Length(p
) >= 4 then
649 g_Console_BindKey(i
, p
[2], p
[3])
651 g_Console_BindKey(i
, p
[2], '')
655 g_Console_Add('bind <key> <down action> [up action]');
657 for i
:= 0 to e_MaxInputKeys
- 1 do
658 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
659 g_Console_Add(e_KeyNames
[i
] + ' "' + GetCommandString(gInputBinds
[i
].down
) + '" "' + GetCommandString(gInputBinds
[i
].up
) + '"');
662 if Length(p
) = 2 then
664 key
:= LowerCase(p
[1]);
666 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
667 if i
< e_MaxInputKeys
then
668 g_Console_BindKey(i
, '')
671 g_Console_Add('unbind <key>');
673 for i
:= 0 to e_MaxInputKeys
- 1 do
674 g_Console_BindKey(i
, '');
676 g_Touch_ShowKeyboard(True);
678 g_Touch_ShowKeyboard(False);
682 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
687 SetLength(commands
, Length(commands
)+1);
690 cp
.cmd
:= LowerCase(cmd
);
694 cp
.hidden
:= ahidden
;
702 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
704 PrefixList
: array [0..1] of AnsiString = ('+', '-');
705 PlayerList
: array [0..1] of Integer = (1, 2);
710 procedure NewAction (cmd
: AnsiString; player
: Integer);
713 SetLength(commands
, Length(commands
) + 1);
714 cp
:= @commands
[High(commands
)];
715 cp
.cmd
:= LowerCase(cmd
);
728 ASSERT(action
>= FIRST_ACTION
);
729 ASSERT(action
<= LAST_ACTION
);
730 for s
in PrefixList
do
732 NewAction(s
+ cmd
, 0);
733 for i
in PlayerList
do
734 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
738 procedure g_Console_Init();
742 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
743 Cons_Y
:= -(gScreenHeight
div 2);
744 gConsoleShow
:= False;
749 for a
:= 0 to High(MsgArray
) do
756 AddCommand('segfault', segfault
, 'make segfault');
758 AddCommand('bind', BindCommands
);
759 AddCommand('bindlist', BindCommands
);
760 AddCommand('unbind', BindCommands
);
761 AddCommand('unbindall', BindCommands
);
762 AddCommand('showkeyboard', BindCommands
);
763 AddCommand('hidekeyboard', BindCommands
);
765 AddCommand('clear', ConsoleCommands
, 'clear console');
766 AddCommand('clearhistory', ConsoleCommands
);
767 AddCommand('showhistory', ConsoleCommands
);
768 AddCommand('commands', ConsoleCommands
);
769 AddCommand('time', ConsoleCommands
);
770 AddCommand('date', ConsoleCommands
);
771 AddCommand('echo', ConsoleCommands
);
772 AddCommand('dump', ConsoleCommands
);
773 AddCommand('exec', ConsoleCommands
);
774 AddCommand('writeconfig', ConsoleCommands
);
775 AddCommand('alias', ConsoleCommands
);
776 AddCommand('call', ConsoleCommands
);
777 AddCommand('ver', ConsoleCommands
);
778 AddCommand('version', ConsoleCommands
);
780 AddCommand('d_window', DebugCommands
);
781 AddCommand('d_sounds', DebugCommands
);
782 AddCommand('d_frames', DebugCommands
);
783 AddCommand('d_winmsg', DebugCommands
);
784 AddCommand('d_monoff', DebugCommands
);
785 AddCommand('d_botoff', DebugCommands
);
786 AddCommand('d_monster', DebugCommands
);
787 AddCommand('d_health', DebugCommands
);
788 AddCommand('d_player', DebugCommands
);
789 AddCommand('d_joy', DebugCommands
);
790 AddCommand('d_mem', DebugCommands
);
792 AddCommand('p1_name', GameCVars
);
793 AddCommand('p2_name', GameCVars
);
794 AddCommand('p1_color', GameCVars
);
795 AddCommand('p2_color', GameCVars
);
796 AddCommand('r_showtime', GameCVars
);
797 AddCommand('r_showscore', GameCVars
);
798 AddCommand('r_showlives', GameCVars
);
799 AddCommand('r_showstat', GameCVars
);
800 AddCommand('r_showkillmsg', GameCVars
);
801 AddCommand('r_showspect', GameCVars
);
802 AddCommand('r_showping', GameCVars
);
803 AddCommand('g_gamemode', GameCVars
);
804 AddCommand('g_friendlyfire', GameCVars
);
805 AddCommand('g_weaponstay', GameCVars
);
806 AddCommand('g_allow_exit', GameCVars
);
807 AddCommand('g_allow_monsters', GameCVars
);
808 AddCommand('g_bot_vsmonsters', GameCVars
);
809 AddCommand('g_bot_vsplayers', GameCVars
);
810 AddCommand('g_scorelimit', GameCVars
);
811 AddCommand('g_timelimit', GameCVars
);
812 AddCommand('g_maxlives', GameCVars
);
813 AddCommand('g_warmuptime', GameCVars
);
814 AddCommand('net_interp', GameCVars
);
815 AddCommand('net_forceplayerupdate', GameCVars
);
816 AddCommand('net_predictself', GameCVars
);
817 AddCommand('sv_name', GameCVars
);
818 AddCommand('sv_passwd', GameCVars
);
819 AddCommand('sv_maxplrs', GameCVars
);
820 AddCommand('sv_public', GameCVars
);
821 AddCommand('sv_intertime', GameCVars
);
823 AddCommand('quit', GameCommands
);
824 AddCommand('exit', GameCommands
);
825 AddCommand('pause', GameCommands
);
826 AddCommand('endgame', GameCommands
);
827 AddCommand('restart', GameCommands
);
828 AddCommand('addbot', GameCommands
);
829 AddCommand('bot_add', GameCommands
);
830 AddCommand('bot_addlist', GameCommands
);
831 AddCommand('bot_addred', GameCommands
);
832 AddCommand('bot_addblue', GameCommands
);
833 AddCommand('bot_removeall', GameCommands
);
834 AddCommand('chat', GameCommands
);
835 AddCommand('teamchat', GameCommands
);
836 AddCommand('game', GameCommands
);
837 AddCommand('host', GameCommands
);
838 AddCommand('map', GameCommands
);
839 AddCommand('nextmap', GameCommands
);
840 AddCommand('endmap', GameCommands
);
841 AddCommand('goodbye', GameCommands
);
842 AddCommand('suicide', GameCommands
);
843 AddCommand('spectate', GameCommands
);
844 AddCommand('ready', GameCommands
);
845 AddCommand('kick', GameCommands
);
846 AddCommand('kick_id', GameCommands
);
847 AddCommand('ban', GameCommands
);
848 AddCommand('permban', GameCommands
);
849 AddCommand('ban_id', GameCommands
);
850 AddCommand('permban_id', GameCommands
);
851 AddCommand('unban', GameCommands
);
852 AddCommand('connect', GameCommands
);
853 AddCommand('disconnect', GameCommands
);
854 AddCommand('reconnect', GameCommands
);
855 AddCommand('say', GameCommands
);
856 AddCommand('tell', GameCommands
);
857 AddCommand('overtime', GameCommands
);
858 AddCommand('rcon_password', GameCommands
);
859 AddCommand('rcon', GameCommands
);
860 AddCommand('callvote', GameCommands
);
861 AddCommand('vote', GameCommands
);
862 AddCommand('clientlist', GameCommands
);
863 AddCommand('event', GameCommands
);
864 AddCommand('screenshot', GameCommands
);
865 AddCommand('togglechat', GameCommands
);
866 AddCommand('toggleteamchat', GameCommands
);
867 AddCommand('weapon', GameCommands
);
868 AddCommand('p1_weapon', GameCommands
);
869 AddCommand('p2_weapon', GameCommands
);
871 AddCommand('god', GameCheats
);
872 AddCommand('notarget', GameCheats
);
873 AddCommand('give', GameCheats
); // "exit" too ;-)
874 AddCommand('open', GameCheats
);
875 AddCommand('fly', GameCheats
);
876 AddCommand('noclip', GameCheats
);
877 AddCommand('speedy', GameCheats
);
878 AddCommand('jumpy', GameCheats
);
879 AddCommand('noreload', GameCheats
);
880 AddCommand('aimline', GameCheats
);
881 AddCommand('automap', GameCheats
);
883 AddAction('jump', ACTION_JUMP
);
884 AddAction('moveleft', ACTION_MOVELEFT
);
885 AddAction('moveright', ACTION_MOVERIGHT
);
886 AddAction('lookup', ACTION_LOOKUP
);
887 AddAction('lookdown', ACTION_LOOKDOWN
);
888 AddAction('attack', ACTION_ATTACK
);
889 AddAction('scores', ACTION_SCORES
);
890 AddAction('activate', ACTION_ACTIVATE
);
891 AddAction('strafe', ACTION_STRAFE
);
892 AddAction('weapnext', ACTION_WEAPNEXT
);
893 AddAction('weapprev', ACTION_WEAPPREV
);
895 WhitelistCommand('say');
896 WhitelistCommand('tell');
897 WhitelistCommand('overtime');
898 WhitelistCommand('ready');
899 WhitelistCommand('map');
900 WhitelistCommand('nextmap');
901 WhitelistCommand('endmap');
902 WhitelistCommand('restart');
903 WhitelistCommand('kick');
904 WhitelistCommand('ban');
906 WhitelistCommand('addbot');
907 WhitelistCommand('bot_add');
908 WhitelistCommand('bot_addred');
909 WhitelistCommand('bot_addblue');
910 WhitelistCommand('bot_removeall');
912 WhitelistCommand('g_gamemode');
913 WhitelistCommand('g_friendlyfire');
914 WhitelistCommand('g_weaponstay');
915 WhitelistCommand('g_allow_exit');
916 WhitelistCommand('g_allow_monsters');
917 WhitelistCommand('g_scorelimit');
918 WhitelistCommand('g_timelimit');
920 g_Console_ResetBinds
;
921 g_Console_ReadConfig(GameDir
+ '/dfconfig.cfg');
922 g_Console_ReadConfig(GameDir
+ '/autoexec.cfg');
924 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
928 procedure g_Console_Update();
934 // Â ïðîöåññå îòêðûòèÿ:
935 if gConsoleShow
and (Cons_Y
< 0) then
937 Cons_Y
:= Cons_Y
+Step
;
940 // Â ïðîöåññå çàêðûòèÿ:
941 if (not gConsoleShow
) and
942 (Cons_Y
> -(gScreenHeight
div 2)) then
943 Cons_Y
:= Cons_Y
-Step
;
945 // Îêîí÷àòåëüíî îòêðûëàñü:
949 // Îêîí÷àòåëüíî çàêðûëàñü:
950 if Cons_Y
<= (-(gScreenHeight
div 2)) then
952 Cons_Y
:= -(gScreenHeight
div 2);
958 while a
<= High(MsgArray
) do
960 if MsgArray
[a
].Time
> 0 then
962 if MsgArray
[a
].Time
= 1 then
964 if a
< High(MsgArray
) then
966 for b
:= a
to High(MsgArray
)-1 do
967 MsgArray
[b
] := MsgArray
[b
+1];
969 MsgArray
[High(MsgArray
)].Time
:= 0;
975 Dec(MsgArray
[a
].Time
);
983 procedure drawConsoleText ();
985 CWidth
, CHeight
: Byte;
990 procedure putLine (sp
, ep
: LongWord);
999 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1000 if wdt
+cw
> gScreenWidth
-8 then break
;
1001 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1005 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1006 // now print our part
1014 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1015 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1028 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1029 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
1030 skip
:= conSkipLines
;
1031 cbufLastLine(sp
, ep
);
1034 if ty
+CHeight
<= 0 then break
;
1035 until not cbufLineUp(sp
, ep
);
1038 procedure g_Console_Draw();
1040 CWidth
, CHeight
: Byte;
1044 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1046 for a
:= 0 to High(MsgArray
) do
1047 if MsgArray
[a
].Time
> 0 then
1048 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
1051 if not Cons_Shown
then
1057 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
1058 gStdFont
, 255, 255, 255, 1, True);
1059 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1060 gStdFont
, 255, 255, 255, 1, True);
1064 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
1065 gStdFont
, 255, 255, 255, 1, True);
1066 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1067 gStdFont
, 255, 255, 255, 1, True);
1075 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1076 a
:= (gScreenWidth
- 2*mfW
) div 2;
1077 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
1078 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1079 _RGB(128, 0, 0), 2.0);
1082 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
1083 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
1087 if ConsoleHistory <> nil then
1091 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
1092 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
1094 b := Max(b-Offset, 0);
1095 d := Max(High(ConsoleHistory)-Offset, 0);
1098 for a := d downto b do
1100 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
1107 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
1110 procedure g_Console_Switch();
1113 gConsoleShow
:= not gConsoleShow
;
1115 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1118 procedure g_Console_Chat_Switch(Team
: Boolean = False);
1120 if not g_Game_IsNet
then Exit
;
1121 gConsoleShow
:= False;
1122 gChatShow
:= not gChatShow
;
1126 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1129 procedure g_Console_Char(C
: AnsiChar);
1131 // if gChatShow then
1133 Insert(C
, Line
, CPos
);
1139 tcomplist
: array of AnsiString = nil;
1140 tcompidx
: array of Integer = nil;
1142 procedure Complete ();
1146 ll
, lpfx
, cmd
: AnsiString;
1148 if (Length(Line
) = 0) then
1151 for i
:= 0 to High(commands
) do
1153 // hidden commands are hidden when cheats aren't enabled
1154 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1155 if (Length(commands
[i
].help
) > 0) then
1157 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1161 g_Console_Add(' '+commands
[i
].cmd
);
1167 ll
:= LowerCase(Line
);
1170 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1172 ll
:= Copy(ll
, 0, Length(ll
)-1);
1173 for i
:= 0 to High(commands
) do
1175 // hidden commands are hidden when cheats aren't enabled
1176 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1177 if (commands
[i
].cmd
= ll
) then
1179 if (Length(commands
[i
].help
) > 0) then
1181 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1188 // build completion list
1190 for i
:= 0 to High(commands
) do
1192 // hidden commands are hidden when cheats aren't enabled
1193 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1194 cmd
:= commands
[i
].cmd
;
1195 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1197 if (tused
= Length(tcomplist
)) then
1199 SetLength(tcomplist
, Length(tcomplist
)+128);
1200 SetLength(tcompidx
, Length(tcompidx
)+128);
1202 tcomplist
[tused
] := cmd
;
1203 tcompidx
[tused
] := i
;
1205 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1209 // get longest prefix
1210 for i
:= 0 to tused
-1 do
1212 cmd
:= tcomplist
[i
];
1213 for c
:= 1 to Length(lpfx
) do
1215 if (c
> Length(cmd
)) then break
;
1216 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1220 if (tused
= 0) then exit
;
1224 Line
:= tcomplist
[0]+' ';
1225 CPos
:= Length(Line
)+1;
1229 // has longest prefix?
1230 if (Length(lpfx
) > Length(ll
)) then
1233 CPos
:= Length(Line
)+1;
1238 for i
:= 0 to tused
-1 do
1240 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1242 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1246 g_Console_Add(' '+tcomplist
[i
]);
1254 procedure g_Console_Control(K
: Word);
1258 if (Length(Line
) > 0) and (CPos
> 1) then
1260 Delete(Line
, CPos
-1, 1);
1264 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1265 Delete(Line
, CPos
, 1);
1266 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1269 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1270 if CPos
<= Length(Line
) then
1272 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1275 g_Console_Process(Line
)
1279 if (Length(Line
) > 0) and g_Game_IsNet
then
1283 if g_Game_IsClient
then
1284 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1286 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1287 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1291 if g_Game_IsClient
then
1292 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1294 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1302 gJustChatted
:= True;
1303 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1307 if not gChatShow
then
1309 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1310 if not gChatShow
then
1311 if (CommandHistory
<> nil) and
1312 (CmdIndex
< Length(CommandHistory
)) then
1314 if CmdIndex
< Length(CommandHistory
)-1 then
1315 CmdIndex
:= CmdIndex
+ 1;
1316 Line
:= CommandHistory
[CmdIndex
];
1317 CPos
:= Length(Line
) + 1;
1319 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1320 if not gChatShow
then
1321 if (CommandHistory
<> nil) and
1322 (CmdIndex
<= Length(CommandHistory
)) then
1324 if CmdIndex
> 0 then
1325 CmdIndex
:= CmdIndex
- 1;
1326 Line
:= CommandHistory
[CmdIndex
];
1327 Cpos
:= Length(Line
) + 1;
1329 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1330 if not gChatShow
then Inc(conSkipLines
);
1331 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1332 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1336 CPos
:= Length(Line
) + 1;
1340 function GetStr(var Str
: AnsiString): AnsiString;
1345 if Str
[1] = '"' then
1347 for b
:= 1 to Length(Str
) do
1348 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1350 Result
:= Copy(Str
, 2, b
-1);
1351 Delete(Str
, 1, b
+1);
1357 for a
:= 1 to Length(Str
) do
1358 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1360 Result
:= Copy(Str
, 1, a
);
1361 Delete(Str
, 1, a
+1);
1367 function ParseString(Str
: AnsiString): SSArray
;
1378 SetLength(Result
, Length(Result
)+1);
1379 Result
[High(Result
)] := GetStr(Str
);
1383 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1385 procedure conmsg (s
: AnsiString);
1389 if length(s
) = 0 then exit
;
1390 for a
:= 0 to High(MsgArray
) do
1402 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1403 with MsgArray
[High(MsgArray
)] do
1413 // put it to console
1415 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1417 // now show 'em out of console too
1418 show
:= show
and gAllowConsoleMessages
;
1419 if show
and gShowMessages
then
1421 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1422 while length(L
) > 0 do
1425 if f
<= 0 then f
:= length(L
)+1;
1426 conmsg(Copy(L
, 1, f
-1));
1431 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1432 //ConsoleHistory[High(ConsoleHistory)] := L;
1436 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1443 consolewriterLastWasEOL
: Boolean = false;
1445 procedure consolewriter (constref buf
; len
: SizeUInt
);
1449 if (len
< 1) then exit
;
1451 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1454 if (b
[0] <> 13) and (b
[0] <> 10) then
1456 cbufPut(AnsiChar(b
[0]));
1460 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1469 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1470 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1471 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1472 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1474 g_Console_Add(s
, show
);
1478 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1482 g_Console_Add(formatstrf(s
, args
), true);
1486 consolewriterLastWasEOL
:= false;
1487 formatstrf(s
, args
, consolewriter
);
1488 if not consolewriterLastWasEOL
then cbufPut(#10);
1493 procedure g_Console_Clear();
1495 //ConsoleHistory := nil;
1500 procedure AddToHistory(L
: AnsiString);
1504 len
:= Length(CommandHistory
);
1507 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1509 SetLength(CommandHistory
, len
+1);
1510 CommandHistory
[len
] := L
;
1513 CmdIndex
:= Length(CommandHistory
);
1516 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1525 if Trim(C
) = '' then
1528 Arr
:= ParseString(C
);
1532 for i
:= 0 to High(Whitelist
) do
1533 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1537 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1544 if Trim(L
) = '' then
1547 conSkipLines
:= 0; // "unscroll"
1549 if L
= 'goobers' then
1554 g_Console_Add('Your memory serves you well.');
1560 g_Console_Add('> '+L
);
1565 Arr
:= ParseString(L
);
1569 if commands
= nil then
1575 for i
:= 0 to High(commands
) do
1577 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1579 if commands
[i
].action
>= 0 then
1581 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1584 if assigned(commands
[i
].procEx
) then
1586 commands
[i
].procEx(@commands
[i
], Arr
);
1589 if assigned(commands
[i
].proc
) then
1591 commands
[i
].proc(Arr
);
1597 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1601 function g_Console_Interactive
: Boolean;
1603 Result
:= gConsoleShow
1606 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1608 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1610 ASSERT(key
< e_MaxInputKeys
);
1613 gInputBinds
[key
].down
:= ParseAlias(down
);
1614 gInputBinds
[key
].up
:= ParseAlias(up
)
1618 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1621 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1622 var i
, len
: Integer;
1626 if len
= Length(b
) then
1629 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1638 if commands
= nil then Exit
;
1640 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1642 if EqualsCommandLists(ParseAlias(down
), gInputBinds
[i
].down
) then
1644 if EqualsCommandLists(ParseAlias(up
), gInputBinds
[i
].up
) then
1656 function g_Console_Action (action
: Integer): Boolean;
1657 var i
, len
: Integer;
1659 ASSERT(action
>= FIRST_ACTION
);
1660 ASSERT(action
<= LAST_ACTION
);
1662 len
:= Length(gPlayerAction
);
1663 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1667 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1670 if (not gChatShow
) and (not gConsoleShow
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1673 for i
:= 0 to High(gInputBinds
[key
].down
) do
1674 g_Console_Process(gInputBinds
[key
].down
[i
], True)
1676 for i
:= 0 to High(gInputBinds
[key
].up
) do
1677 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1681 procedure g_Console_ResetBinds
;
1684 for i
:= 0 to e_MaxInputKeys
- 1 do
1685 g_Console_BindKey(i
, '', '');
1687 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1688 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1689 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1690 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1691 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1692 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1693 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1694 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1695 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1696 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1697 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1698 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1699 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1700 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1701 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1702 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1703 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1704 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1705 g_Console_BindKey(IK_9
, 'p1_weapon 9');
1706 g_Console_BindKey(IK_0
, 'p1_weapon 10');
1707 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
1708 g_Console_BindKey(IK_T
, 'togglechat');
1709 g_Console_BindKey(IK_Y
, 'toggleteamchat');
1710 g_Console_BindKey(IK_F11
, 'screenshot');
1711 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
1712 g_Console_BindKey(IK_PAUSE
, 'pause');
1713 g_Console_BindKey(IK_F1
, 'vote');
1715 (* for i := 0 to e_MaxJoys - 1 do *)
1718 g_Console_BindKey(e_JoyAxisToKey(i
, 0, AX_MINUS
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
1719 g_Console_BindKey(e_JoyAxisToKey(i
, 0, AX_PLUS
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
1720 g_Console_BindKey(e_JoyAxisToKey(i
, 1, AX_MINUS
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
1721 g_Console_BindKey(e_JoyAxisToKey(i
, 1, AX_PLUS
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
1722 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
1723 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
1724 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
1725 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
1726 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
1727 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
1730 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
1731 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
1732 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
1733 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
1734 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
1735 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
1736 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
1737 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
1738 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
1739 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
1740 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
1741 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
1742 g_Console_BindKey(VK_0
, 'weapon 1');
1743 g_Console_BindKey(VK_1
, 'weapon 2');
1744 g_Console_BindKey(VK_2
, 'weapon 3');
1745 g_Console_BindKey(VK_3
, 'weapon 4');
1746 g_Console_BindKey(VK_4
, 'weapon 5');
1747 g_Console_BindKey(VK_5
, 'weapon 6');
1748 g_Console_BindKey(VK_6
, 'weapon 7');
1749 g_Console_BindKey(VK_7
, 'weapon 8');
1750 g_Console_BindKey(VK_8
, 'weapon 9');
1751 g_Console_BindKey(VK_9
, 'weapon 10');
1752 g_Console_BindKey(VK_A
, 'weapon 11');
1753 g_Console_BindKey(VK_CHAT
, 'togglechat');
1754 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
1755 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
1756 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
1757 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
1758 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
1764 procedure g_Console_ReadConfig (filename
: String);
1765 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1767 if FileExists(filename
) then
1769 AssignFile(f
, filename
);
1779 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1781 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1782 g_Console_Process(s
, True)
1789 procedure g_Console_WriteConfig (filename
: String);
1790 var f
: TextFile
; i
, j
: Integer;
1792 AssignFile(f
, filename
);
1794 WriteLn(f
, '// generated by doom2d, do not modify');
1795 WriteLn(f
, 'unbindall');
1796 for i
:= 0 to e_MaxInputKeys
- 1 do
1797 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
1798 WriteLn(f
, 'bind ', e_KeyNames
[i
], ' "', GetCommandString(gInputBinds
[i
].down
), '" "', GetCommandString(gInputBinds
[i
].up
), '"');
1799 for i
:= 0 to High(commands
) do
1801 if not commands
[i
].cheat
then
1803 if @commands
[i
].procEx
= @boolVarHandler
then
1805 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
1806 WriteLn(f
, commands
[i
].cmd
, ' "', j
, '"')
1808 else if @commands
[i
].procEx
= @intVarHandler
then
1810 WriteLn(f
, commands
[i
].cmd
, ' "', PInteger(commands
[i
].ptr
)^, '"')
1812 else if @commands
[i
].procEx
= @singleVarHandler
then
1814 WriteLn(f
, commands
[i
].cmd
, ' "', PVarSingle(commands
[i
].ptr
).val
^:0:6, '"')