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 procedure BindCommands (p
: SSArray
);
621 var cmd
, key
, act
: AnsiString; i
, j
: Integer;
623 cmd
:= LowerCase(p
[0]);
626 // bind <key> <down> [up]
627 if Length(p
) >= 3 then
630 key
:= LowerCase(p
[1]);
631 if Length(p
) = 4 then act
:= p
[3] else act
:= '';
632 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
633 if i
< e_MaxInputKeys
then
634 g_Console_BindKey(i
, p
[2], act
)
637 g_Console_Add('bind <key> <down action> [up action]');
639 for i
:= 0 to e_MaxInputKeys
- 1 do
641 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
643 act
:= e_KeyNames
[i
] + ' "';
644 if (gInputBinds
[i
].down
<> nil) then
646 act
:= act
+ gInputBinds
[i
].down
[0];
647 for j
:= 1 to High(gInputBinds
[i
].down
) - 1 do
648 act
:= act
+ '; ' + gInputBinds
[i
].down
[j
];
651 if (gInputBinds
[i
].up
<> nil) then
653 act
:= act
+ gInputBinds
[i
].up
[0];
654 for j
:= 1 to High(gInputBinds
[i
].up
) do
655 act
:= act
+ '; ' + gInputBinds
[i
].up
[j
];
663 if Length(p
) = 2 then
665 key
:= LowerCase(p
[1]);
667 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
668 if i
< e_MaxInputKeys
then
669 g_Console_BindKey(i
, '')
672 g_Console_Add('unbind <key>');
674 for i
:= 0 to e_MaxInputKeys
- 1 do
675 g_Console_BindKey(i
, '');
677 g_Touch_ShowKeyboard(True);
679 g_Touch_ShowKeyboard(False);
683 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
688 SetLength(commands
, Length(commands
)+1);
691 cp
.cmd
:= LowerCase(cmd
);
695 cp
.hidden
:= ahidden
;
703 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
705 PrefixList
: array [0..1] of AnsiString = ('+', '-');
706 PlayerList
: array [0..1] of Integer = (1, 2);
711 procedure NewAction (cmd
: AnsiString; player
: Integer);
714 SetLength(commands
, Length(commands
) + 1);
715 cp
:= @commands
[High(commands
)];
716 cp
.cmd
:= LowerCase(cmd
);
729 ASSERT(action
>= FIRST_ACTION
);
730 ASSERT(action
<= LAST_ACTION
);
731 for s
in PrefixList
do
733 NewAction(s
+ cmd
, 0);
734 for i
in PlayerList
do
735 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
739 procedure g_Console_Init();
743 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
744 Cons_Y
:= -(gScreenHeight
div 2);
745 gConsoleShow
:= False;
750 for a
:= 0 to High(MsgArray
) do
757 AddCommand('segfault', segfault
, 'make segfault');
759 AddCommand('bind', BindCommands
);
760 AddCommand('bindlist', BindCommands
);
761 AddCommand('unbind', BindCommands
);
762 AddCommand('unbindall', BindCommands
);
763 AddCommand('showkeyboard', BindCommands
);
764 AddCommand('hidekeyboard', BindCommands
);
766 AddCommand('clear', ConsoleCommands
, 'clear console');
767 AddCommand('clearhistory', ConsoleCommands
);
768 AddCommand('showhistory', ConsoleCommands
);
769 AddCommand('commands', ConsoleCommands
);
770 AddCommand('time', ConsoleCommands
);
771 AddCommand('date', ConsoleCommands
);
772 AddCommand('echo', ConsoleCommands
);
773 AddCommand('dump', ConsoleCommands
);
774 AddCommand('exec', ConsoleCommands
);
775 AddCommand('writeconfig', ConsoleCommands
);
776 AddCommand('alias', ConsoleCommands
);
777 AddCommand('call', ConsoleCommands
);
778 AddCommand('ver', ConsoleCommands
);
779 AddCommand('version', ConsoleCommands
);
781 AddCommand('d_window', DebugCommands
);
782 AddCommand('d_sounds', DebugCommands
);
783 AddCommand('d_frames', DebugCommands
);
784 AddCommand('d_winmsg', DebugCommands
);
785 AddCommand('d_monoff', DebugCommands
);
786 AddCommand('d_botoff', DebugCommands
);
787 AddCommand('d_monster', DebugCommands
);
788 AddCommand('d_health', DebugCommands
);
789 AddCommand('d_player', DebugCommands
);
790 AddCommand('d_joy', DebugCommands
);
791 AddCommand('d_mem', DebugCommands
);
793 AddCommand('p1_name', GameCVars
);
794 AddCommand('p2_name', GameCVars
);
795 AddCommand('p1_color', GameCVars
);
796 AddCommand('p2_color', GameCVars
);
797 AddCommand('r_showtime', GameCVars
);
798 AddCommand('r_showscore', GameCVars
);
799 AddCommand('r_showlives', GameCVars
);
800 AddCommand('r_showstat', GameCVars
);
801 AddCommand('r_showkillmsg', GameCVars
);
802 AddCommand('r_showspect', GameCVars
);
803 AddCommand('r_showping', GameCVars
);
804 AddCommand('g_gamemode', GameCVars
);
805 AddCommand('g_friendlyfire', GameCVars
);
806 AddCommand('g_weaponstay', GameCVars
);
807 AddCommand('g_allow_exit', GameCVars
);
808 AddCommand('g_allow_monsters', GameCVars
);
809 AddCommand('g_bot_vsmonsters', GameCVars
);
810 AddCommand('g_bot_vsplayers', GameCVars
);
811 AddCommand('g_scorelimit', GameCVars
);
812 AddCommand('g_timelimit', GameCVars
);
813 AddCommand('g_maxlives', GameCVars
);
814 AddCommand('g_warmuptime', GameCVars
);
815 AddCommand('net_interp', GameCVars
);
816 AddCommand('net_forceplayerupdate', GameCVars
);
817 AddCommand('net_predictself', GameCVars
);
818 AddCommand('sv_name', GameCVars
);
819 AddCommand('sv_passwd', GameCVars
);
820 AddCommand('sv_maxplrs', GameCVars
);
821 AddCommand('sv_public', GameCVars
);
822 AddCommand('sv_intertime', GameCVars
);
824 AddCommand('quit', GameCommands
);
825 AddCommand('exit', GameCommands
);
826 AddCommand('pause', GameCommands
);
827 AddCommand('endgame', GameCommands
);
828 AddCommand('restart', GameCommands
);
829 AddCommand('addbot', GameCommands
);
830 AddCommand('bot_add', GameCommands
);
831 AddCommand('bot_addlist', GameCommands
);
832 AddCommand('bot_addred', GameCommands
);
833 AddCommand('bot_addblue', GameCommands
);
834 AddCommand('bot_removeall', GameCommands
);
835 AddCommand('chat', GameCommands
);
836 AddCommand('teamchat', GameCommands
);
837 AddCommand('game', GameCommands
);
838 AddCommand('host', GameCommands
);
839 AddCommand('map', GameCommands
);
840 AddCommand('nextmap', GameCommands
);
841 AddCommand('endmap', GameCommands
);
842 AddCommand('goodbye', GameCommands
);
843 AddCommand('suicide', GameCommands
);
844 AddCommand('spectate', GameCommands
);
845 AddCommand('ready', GameCommands
);
846 AddCommand('kick', GameCommands
);
847 AddCommand('kick_id', GameCommands
);
848 AddCommand('ban', GameCommands
);
849 AddCommand('permban', GameCommands
);
850 AddCommand('ban_id', GameCommands
);
851 AddCommand('permban_id', GameCommands
);
852 AddCommand('unban', GameCommands
);
853 AddCommand('connect', GameCommands
);
854 AddCommand('disconnect', GameCommands
);
855 AddCommand('reconnect', GameCommands
);
856 AddCommand('say', GameCommands
);
857 AddCommand('tell', GameCommands
);
858 AddCommand('overtime', GameCommands
);
859 AddCommand('rcon_password', GameCommands
);
860 AddCommand('rcon', GameCommands
);
861 AddCommand('callvote', GameCommands
);
862 AddCommand('vote', GameCommands
);
863 AddCommand('clientlist', GameCommands
);
864 AddCommand('event', GameCommands
);
865 AddCommand('screenshot', GameCommands
);
866 AddCommand('togglechat', GameCommands
);
867 AddCommand('toggleteamchat', GameCommands
);
868 AddCommand('weapon', GameCommands
);
869 AddCommand('p1_weapon', GameCommands
);
870 AddCommand('p2_weapon', GameCommands
);
872 AddCommand('god', GameCheats
);
873 AddCommand('notarget', GameCheats
);
874 AddCommand('give', GameCheats
); // "exit" too ;-)
875 AddCommand('open', GameCheats
);
876 AddCommand('fly', GameCheats
);
877 AddCommand('noclip', GameCheats
);
878 AddCommand('speedy', GameCheats
);
879 AddCommand('jumpy', GameCheats
);
880 AddCommand('noreload', GameCheats
);
881 AddCommand('aimline', GameCheats
);
882 AddCommand('automap', GameCheats
);
884 AddAction('jump', ACTION_JUMP
);
885 AddAction('moveleft', ACTION_MOVELEFT
);
886 AddAction('moveright', ACTION_MOVERIGHT
);
887 AddAction('lookup', ACTION_LOOKUP
);
888 AddAction('lookdown', ACTION_LOOKDOWN
);
889 AddAction('attack', ACTION_ATTACK
);
890 AddAction('scores', ACTION_SCORES
);
891 AddAction('activate', ACTION_ACTIVATE
);
892 AddAction('strafe', ACTION_STRAFE
);
893 AddAction('weapnext', ACTION_WEAPNEXT
);
894 AddAction('weapprev', ACTION_WEAPPREV
);
896 WhitelistCommand('say');
897 WhitelistCommand('tell');
898 WhitelistCommand('overtime');
899 WhitelistCommand('ready');
900 WhitelistCommand('map');
901 WhitelistCommand('nextmap');
902 WhitelistCommand('endmap');
903 WhitelistCommand('restart');
904 WhitelistCommand('kick');
905 WhitelistCommand('ban');
907 WhitelistCommand('addbot');
908 WhitelistCommand('bot_add');
909 WhitelistCommand('bot_addred');
910 WhitelistCommand('bot_addblue');
911 WhitelistCommand('bot_removeall');
913 WhitelistCommand('g_gamemode');
914 WhitelistCommand('g_friendlyfire');
915 WhitelistCommand('g_weaponstay');
916 WhitelistCommand('g_allow_exit');
917 WhitelistCommand('g_allow_monsters');
918 WhitelistCommand('g_scorelimit');
919 WhitelistCommand('g_timelimit');
921 g_Console_ResetBinds
;
922 g_Console_ReadConfig(GameDir
+ '/dfconfig.cfg');
923 g_Console_ReadConfig(GameDir
+ '/autoexec.cfg');
925 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
929 procedure g_Console_Update();
935 // Â ïðîöåññå îòêðûòèÿ:
936 if gConsoleShow
and (Cons_Y
< 0) then
938 Cons_Y
:= Cons_Y
+Step
;
941 // Â ïðîöåññå çàêðûòèÿ:
942 if (not gConsoleShow
) and
943 (Cons_Y
> -(gScreenHeight
div 2)) then
944 Cons_Y
:= Cons_Y
-Step
;
946 // Îêîí÷àòåëüíî îòêðûëàñü:
950 // Îêîí÷àòåëüíî çàêðûëàñü:
951 if Cons_Y
<= (-(gScreenHeight
div 2)) then
953 Cons_Y
:= -(gScreenHeight
div 2);
959 while a
<= High(MsgArray
) do
961 if MsgArray
[a
].Time
> 0 then
963 if MsgArray
[a
].Time
= 1 then
965 if a
< High(MsgArray
) then
967 for b
:= a
to High(MsgArray
)-1 do
968 MsgArray
[b
] := MsgArray
[b
+1];
970 MsgArray
[High(MsgArray
)].Time
:= 0;
976 Dec(MsgArray
[a
].Time
);
984 procedure drawConsoleText ();
986 CWidth
, CHeight
: Byte;
991 procedure putLine (sp
, ep
: LongWord);
1000 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1001 if wdt
+cw
> gScreenWidth
-8 then break
;
1002 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1006 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1007 // now print our part
1015 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1016 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1029 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1030 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
1031 skip
:= conSkipLines
;
1032 cbufLastLine(sp
, ep
);
1035 if ty
+CHeight
<= 0 then break
;
1036 until not cbufLineUp(sp
, ep
);
1039 procedure g_Console_Draw();
1041 CWidth
, CHeight
: Byte;
1045 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1047 for a
:= 0 to High(MsgArray
) do
1048 if MsgArray
[a
].Time
> 0 then
1049 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
1052 if not Cons_Shown
then
1058 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
1059 gStdFont
, 255, 255, 255, 1, True);
1060 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1061 gStdFont
, 255, 255, 255, 1, True);
1065 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
1066 gStdFont
, 255, 255, 255, 1, True);
1067 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1068 gStdFont
, 255, 255, 255, 1, True);
1076 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1077 a
:= (gScreenWidth
- 2*mfW
) div 2;
1078 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
1079 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1080 _RGB(128, 0, 0), 2.0);
1083 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
1084 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
1088 if ConsoleHistory <> nil then
1092 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
1093 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
1095 b := Max(b-Offset, 0);
1096 d := Max(High(ConsoleHistory)-Offset, 0);
1099 for a := d downto b do
1101 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
1108 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
1111 procedure g_Console_Switch();
1114 gConsoleShow
:= not gConsoleShow
;
1116 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1119 procedure g_Console_Chat_Switch(Team
: Boolean = False);
1121 if not g_Game_IsNet
then Exit
;
1122 gConsoleShow
:= False;
1123 gChatShow
:= not gChatShow
;
1127 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1130 procedure g_Console_Char(C
: AnsiChar);
1132 // if gChatShow then
1134 Insert(C
, Line
, CPos
);
1140 tcomplist
: array of AnsiString = nil;
1141 tcompidx
: array of Integer = nil;
1143 procedure Complete ();
1147 ll
, lpfx
, cmd
: AnsiString;
1149 if (Length(Line
) = 0) then
1152 for i
:= 0 to High(commands
) do
1154 // hidden commands are hidden when cheats aren't enabled
1155 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1156 if (Length(commands
[i
].help
) > 0) then
1158 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1162 g_Console_Add(' '+commands
[i
].cmd
);
1168 ll
:= LowerCase(Line
);
1171 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1173 ll
:= Copy(ll
, 0, Length(ll
)-1);
1174 for i
:= 0 to High(commands
) do
1176 // hidden commands are hidden when cheats aren't enabled
1177 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1178 if (commands
[i
].cmd
= ll
) then
1180 if (Length(commands
[i
].help
) > 0) then
1182 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1189 // build completion list
1191 for i
:= 0 to High(commands
) do
1193 // hidden commands are hidden when cheats aren't enabled
1194 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1195 cmd
:= commands
[i
].cmd
;
1196 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1198 if (tused
= Length(tcomplist
)) then
1200 SetLength(tcomplist
, Length(tcomplist
)+128);
1201 SetLength(tcompidx
, Length(tcompidx
)+128);
1203 tcomplist
[tused
] := cmd
;
1204 tcompidx
[tused
] := i
;
1206 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1210 // get longest prefix
1211 for i
:= 0 to tused
-1 do
1213 cmd
:= tcomplist
[i
];
1214 for c
:= 1 to Length(lpfx
) do
1216 if (c
> Length(cmd
)) then break
;
1217 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1221 if (tused
= 0) then exit
;
1225 Line
:= tcomplist
[0]+' ';
1226 CPos
:= Length(Line
)+1;
1230 // has longest prefix?
1231 if (Length(lpfx
) > Length(ll
)) then
1234 CPos
:= Length(Line
)+1;
1239 for i
:= 0 to tused
-1 do
1241 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1243 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1247 g_Console_Add(' '+tcomplist
[i
]);
1255 procedure g_Console_Control(K
: Word);
1259 if (Length(Line
) > 0) and (CPos
> 1) then
1261 Delete(Line
, CPos
-1, 1);
1265 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1266 Delete(Line
, CPos
, 1);
1267 IK_LEFT
, IK_KPLEFT
, VK_LEFT
:
1270 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
:
1271 if CPos
<= Length(Line
) then
1273 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
:
1276 g_Console_Process(Line
)
1280 if (Length(Line
) > 0) and g_Game_IsNet
then
1284 if g_Game_IsClient
then
1285 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1287 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1288 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1292 if g_Game_IsClient
then
1293 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1295 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1303 gJustChatted
:= True;
1304 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1308 if not gChatShow
then
1310 IK_DOWN
, IK_KPDOWN
, VK_DOWN
:
1311 if not gChatShow
then
1312 if (CommandHistory
<> nil) and
1313 (CmdIndex
< Length(CommandHistory
)) then
1315 if CmdIndex
< Length(CommandHistory
)-1 then
1316 CmdIndex
:= CmdIndex
+ 1;
1317 Line
:= CommandHistory
[CmdIndex
];
1318 CPos
:= Length(Line
) + 1;
1320 IK_UP
, IK_KPUP
, VK_UP
:
1321 if not gChatShow
then
1322 if (CommandHistory
<> nil) and
1323 (CmdIndex
<= Length(CommandHistory
)) then
1325 if CmdIndex
> 0 then
1326 CmdIndex
:= CmdIndex
- 1;
1327 Line
:= CommandHistory
[CmdIndex
];
1328 Cpos
:= Length(Line
) + 1;
1330 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
: // PgUp
1331 if not gChatShow
then Inc(conSkipLines
);
1332 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
: // PgDown
1333 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1337 CPos
:= Length(Line
) + 1;
1341 function GetStr(var Str
: AnsiString): AnsiString;
1346 if Str
[1] = '"' then
1348 for b
:= 1 to Length(Str
) do
1349 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1351 Result
:= Copy(Str
, 2, b
-1);
1352 Delete(Str
, 1, b
+1);
1358 for a
:= 1 to Length(Str
) do
1359 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1361 Result
:= Copy(Str
, 1, a
);
1362 Delete(Str
, 1, a
+1);
1368 function ParseString(Str
: AnsiString): SSArray
;
1379 SetLength(Result
, Length(Result
)+1);
1380 Result
[High(Result
)] := GetStr(Str
);
1384 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1386 procedure conmsg (s
: AnsiString);
1390 if length(s
) = 0 then exit
;
1391 for a
:= 0 to High(MsgArray
) do
1403 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1404 with MsgArray
[High(MsgArray
)] do
1414 // put it to console
1416 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1418 // now show 'em out of console too
1419 show
:= show
and gAllowConsoleMessages
;
1420 if show
and gShowMessages
then
1422 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1423 while length(L
) > 0 do
1426 if f
<= 0 then f
:= length(L
)+1;
1427 conmsg(Copy(L
, 1, f
-1));
1432 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1433 //ConsoleHistory[High(ConsoleHistory)] := L;
1437 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1444 consolewriterLastWasEOL
: Boolean = false;
1446 procedure consolewriter (constref buf
; len
: SizeUInt
);
1450 if (len
< 1) then exit
;
1452 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1455 if (b
[0] <> 13) and (b
[0] <> 10) then
1457 cbufPut(AnsiChar(b
[0]));
1461 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1470 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1471 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1472 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1473 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1475 g_Console_Add(s
, show
);
1479 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1483 g_Console_Add(formatstrf(s
, args
), true);
1487 consolewriterLastWasEOL
:= false;
1488 formatstrf(s
, args
, consolewriter
);
1489 if not consolewriterLastWasEOL
then cbufPut(#10);
1494 procedure g_Console_Clear();
1496 //ConsoleHistory := nil;
1501 procedure AddToHistory(L
: AnsiString);
1505 len
:= Length(CommandHistory
);
1508 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1510 SetLength(CommandHistory
, len
+1);
1511 CommandHistory
[len
] := L
;
1514 CmdIndex
:= Length(CommandHistory
);
1517 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1526 if Trim(C
) = '' then
1529 Arr
:= ParseString(C
);
1533 for i
:= 0 to High(Whitelist
) do
1534 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1538 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1545 if Trim(L
) = '' then
1548 conSkipLines
:= 0; // "unscroll"
1550 if L
= 'goobers' then
1555 g_Console_Add('Your memory serves you well.');
1561 g_Console_Add('> '+L
);
1566 Arr
:= ParseString(L
);
1570 if commands
= nil then
1576 for i
:= 0 to High(commands
) do
1578 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1580 if commands
[i
].action
>= 0 then
1582 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1585 if assigned(commands
[i
].procEx
) then
1587 commands
[i
].procEx(@commands
[i
], Arr
);
1590 if assigned(commands
[i
].proc
) then
1592 commands
[i
].proc(Arr
);
1598 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1602 function g_Console_Interactive
: Boolean;
1604 Result
:= gConsoleShow
1607 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1609 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1611 ASSERT(key
< e_MaxInputKeys
);
1614 gInputBinds
[key
].down
:= ParseAlias(down
);
1615 gInputBinds
[key
].up
:= ParseAlias(up
)
1619 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1622 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1623 var i
, len
: Integer;
1627 if len
= Length(b
) then
1630 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1639 if commands
= nil then Exit
;
1641 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1643 if EqualsCommandLists(ParseAlias(down
), gInputBinds
[i
].down
) then
1645 if EqualsCommandLists(ParseAlias(up
), gInputBinds
[i
].up
) then
1657 function g_Console_Action (action
: Integer): Boolean;
1658 var i
, len
: Integer;
1660 ASSERT(action
>= FIRST_ACTION
);
1661 ASSERT(action
<= LAST_ACTION
);
1663 len
:= Length(gPlayerAction
);
1664 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1668 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1671 if (not gChatShow
) and (not gConsoleShow
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1674 for i
:= 0 to High(gInputBinds
[key
].down
) do
1675 g_Console_Process(gInputBinds
[key
].down
[i
], True)
1677 for i
:= 0 to High(gInputBinds
[key
].up
) do
1678 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1682 procedure g_Console_ResetBinds
;
1685 for i
:= 0 to e_MaxInputKeys
- 1 do
1686 g_Console_BindKey(i
, '', '');
1688 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1689 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1690 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1691 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1692 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1693 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1694 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1695 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1696 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1697 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1698 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1699 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1700 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1701 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1702 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1703 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1704 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1705 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1706 g_Console_BindKey(IK_9
, 'p1_weapon 9');
1707 g_Console_BindKey(IK_0
, 'p1_weapon 10');
1708 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
1709 g_Console_BindKey(IK_T
, 'togglechat');
1710 g_Console_BindKey(IK_Y
, 'toggleteamchat');
1711 g_Console_BindKey(IK_F11
, 'screenshot');
1712 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
1713 g_Console_BindKey(IK_PAUSE
, 'pause');
1714 g_Console_BindKey(IK_F1
, 'vote');
1716 (* for i := 0 to e_MaxJoys - 1 do *)
1719 g_Console_BindKey(e_JoyAxisToKey(i
, 0, 0), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
1720 g_Console_BindKey(e_JoyAxisToKey(i
, 0, 1), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
1721 g_Console_BindKey(e_JoyAxisToKey(i
, 1, 0), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
1722 g_Console_BindKey(e_JoyAxisToKey(i
, 1, 1), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
1723 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
1724 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
1725 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
1726 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
1727 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
1728 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
1731 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
1732 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
1733 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
1734 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
1735 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
1736 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
1737 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
1738 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
1739 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
1740 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
1741 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
1742 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
1743 g_Console_BindKey(VK_0
, 'weapon 1');
1744 g_Console_BindKey(VK_1
, 'weapon 2');
1745 g_Console_BindKey(VK_2
, 'weapon 3');
1746 g_Console_BindKey(VK_3
, 'weapon 4');
1747 g_Console_BindKey(VK_4
, 'weapon 5');
1748 g_Console_BindKey(VK_5
, 'weapon 6');
1749 g_Console_BindKey(VK_6
, 'weapon 7');
1750 g_Console_BindKey(VK_7
, 'weapon 8');
1751 g_Console_BindKey(VK_8
, 'weapon 9');
1752 g_Console_BindKey(VK_9
, 'weapon 10');
1753 g_Console_BindKey(VK_A
, 'weapon 11');
1754 g_Console_BindKey(VK_CHAT
, 'togglechat');
1755 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
1756 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
1757 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
1758 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
1759 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
1765 procedure g_Console_ReadConfig (filename
: String);
1766 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1768 if FileExists(filename
) then
1770 AssignFile(f
, filename
);
1780 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1782 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1783 g_Console_Process(s
, True)
1790 procedure g_Console_WriteConfig (filename
: String);
1791 var f
: TextFile
; i
, j
: Integer;
1793 AssignFile(f
, filename
);
1795 WriteLn(f
, '// generated by doom2d, do not modify');
1796 WriteLn(f
, 'unbindall');
1797 for i
:= 0 to e_MaxInputKeys
- 1 do
1799 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
1801 Write(f
, 'bind ', e_KeyNames
[i
], ' "');
1802 if Length(gInputBinds
[i
].down
) > 0 then
1804 Write(f
, gInputBinds
[i
].down
[0]);
1805 for j
:= 1 to High(gInputBinds
[i
].down
) do
1806 Write(f
, '; ', gInputBinds
[i
].down
[j
])
1809 if Length(gInputBinds
[i
].up
) > 0 then
1811 Write(f
, ' "', gInputBinds
[i
].up
[0]);
1812 for j
:= 1 to High(gInputBinds
[i
].up
) do
1813 Write(f
, '; ', gInputBinds
[i
].up
[j
]);
1819 for i
:= 0 to High(commands
) do
1821 if not commands
[i
].cheat
then
1823 if @commands
[i
].procEx
= @boolVarHandler
then
1825 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
1826 WriteLn(f
, commands
[i
].cmd
, ' "', j
, '"')
1828 else if @commands
[i
].procEx
= @intVarHandler
then
1830 WriteLn(f
, commands
[i
].cmd
, ' "', PInteger(commands
[i
].ptr
)^, '"')
1832 else if @commands
[i
].procEx
= @singleVarHandler
then
1834 WriteLn(f
, commands
[i
].cmd
, ' "', PVarSingle(commands
[i
].ptr
).val
^:0:6, '"')