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
) 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
, '')
679 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
684 SetLength(commands
, Length(commands
)+1);
687 cp
.cmd
:= LowerCase(cmd
);
691 cp
.hidden
:= ahidden
;
699 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
701 PrefixList
: array [0..1] of AnsiString = ('+', '-');
702 PlayerList
: array [0..1] of Integer = (1, 2);
707 procedure NewAction (cmd
: AnsiString; player
: Integer);
710 SetLength(commands
, Length(commands
) + 1);
711 cp
:= @commands
[High(commands
)];
712 cp
.cmd
:= LowerCase(cmd
);
725 ASSERT(action
>= FIRST_ACTION
);
726 ASSERT(action
<= LAST_ACTION
);
727 for s
in PrefixList
do
729 NewAction(s
+ cmd
, 0);
730 for i
in PlayerList
do
731 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
735 procedure g_Console_Init();
739 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
740 Cons_Y
:= -(gScreenHeight
div 2);
741 gConsoleShow
:= False;
746 for a
:= 0 to High(MsgArray
) do
753 AddCommand('segfault', segfault
, 'make segfault');
755 AddCommand('bind', BindCommands
);
756 AddCommand('bindlist', BindCommands
);
757 AddCommand('unbind', BindCommands
);
758 AddCommand('unbindall', BindCommands
);
760 AddCommand('clear', ConsoleCommands
, 'clear console');
761 AddCommand('clearhistory', ConsoleCommands
);
762 AddCommand('showhistory', ConsoleCommands
);
763 AddCommand('commands', ConsoleCommands
);
764 AddCommand('time', ConsoleCommands
);
765 AddCommand('date', ConsoleCommands
);
766 AddCommand('echo', ConsoleCommands
);
767 AddCommand('dump', ConsoleCommands
);
768 AddCommand('exec', ConsoleCommands
);
769 AddCommand('writeconfig', ConsoleCommands
);
770 AddCommand('alias', ConsoleCommands
);
771 AddCommand('call', ConsoleCommands
);
772 AddCommand('ver', ConsoleCommands
);
773 AddCommand('version', ConsoleCommands
);
775 AddCommand('d_window', DebugCommands
);
776 AddCommand('d_sounds', DebugCommands
);
777 AddCommand('d_frames', DebugCommands
);
778 AddCommand('d_winmsg', DebugCommands
);
779 AddCommand('d_monoff', DebugCommands
);
780 AddCommand('d_botoff', DebugCommands
);
781 AddCommand('d_monster', DebugCommands
);
782 AddCommand('d_health', DebugCommands
);
783 AddCommand('d_player', DebugCommands
);
784 AddCommand('d_joy', DebugCommands
);
785 AddCommand('d_mem', DebugCommands
);
787 AddCommand('p1_name', GameCVars
);
788 AddCommand('p2_name', GameCVars
);
789 AddCommand('p1_color', GameCVars
);
790 AddCommand('p2_color', GameCVars
);
791 AddCommand('r_showtime', GameCVars
);
792 AddCommand('r_showscore', GameCVars
);
793 AddCommand('r_showlives', GameCVars
);
794 AddCommand('r_showstat', GameCVars
);
795 AddCommand('r_showkillmsg', GameCVars
);
796 AddCommand('r_showspect', GameCVars
);
797 AddCommand('r_showping', GameCVars
);
798 AddCommand('g_gamemode', GameCVars
);
799 AddCommand('g_friendlyfire', GameCVars
);
800 AddCommand('g_weaponstay', GameCVars
);
801 AddCommand('g_allow_exit', GameCVars
);
802 AddCommand('g_allow_monsters', GameCVars
);
803 AddCommand('g_bot_vsmonsters', GameCVars
);
804 AddCommand('g_bot_vsplayers', GameCVars
);
805 AddCommand('g_scorelimit', GameCVars
);
806 AddCommand('g_timelimit', GameCVars
);
807 AddCommand('g_maxlives', GameCVars
);
808 AddCommand('g_warmuptime', GameCVars
);
809 AddCommand('net_interp', GameCVars
);
810 AddCommand('net_forceplayerupdate', GameCVars
);
811 AddCommand('net_predictself', GameCVars
);
812 AddCommand('sv_name', GameCVars
);
813 AddCommand('sv_passwd', GameCVars
);
814 AddCommand('sv_maxplrs', GameCVars
);
815 AddCommand('sv_public', GameCVars
);
816 AddCommand('sv_intertime', GameCVars
);
818 AddCommand('quit', GameCommands
);
819 AddCommand('exit', GameCommands
);
820 AddCommand('pause', GameCommands
);
821 AddCommand('endgame', GameCommands
);
822 AddCommand('restart', GameCommands
);
823 AddCommand('addbot', GameCommands
);
824 AddCommand('bot_add', GameCommands
);
825 AddCommand('bot_addlist', GameCommands
);
826 AddCommand('bot_addred', GameCommands
);
827 AddCommand('bot_addblue', GameCommands
);
828 AddCommand('bot_removeall', GameCommands
);
829 AddCommand('chat', GameCommands
);
830 AddCommand('teamchat', GameCommands
);
831 AddCommand('game', GameCommands
);
832 AddCommand('host', GameCommands
);
833 AddCommand('map', GameCommands
);
834 AddCommand('nextmap', GameCommands
);
835 AddCommand('endmap', GameCommands
);
836 AddCommand('goodbye', GameCommands
);
837 AddCommand('suicide', GameCommands
);
838 AddCommand('spectate', GameCommands
);
839 AddCommand('ready', GameCommands
);
840 AddCommand('kick', GameCommands
);
841 AddCommand('kick_id', GameCommands
);
842 AddCommand('ban', GameCommands
);
843 AddCommand('permban', GameCommands
);
844 AddCommand('ban_id', GameCommands
);
845 AddCommand('permban_id', GameCommands
);
846 AddCommand('unban', GameCommands
);
847 AddCommand('connect', GameCommands
);
848 AddCommand('disconnect', GameCommands
);
849 AddCommand('reconnect', GameCommands
);
850 AddCommand('say', GameCommands
);
851 AddCommand('tell', GameCommands
);
852 AddCommand('overtime', GameCommands
);
853 AddCommand('rcon_password', GameCommands
);
854 AddCommand('rcon', GameCommands
);
855 AddCommand('callvote', GameCommands
);
856 AddCommand('vote', GameCommands
);
857 AddCommand('clientlist', GameCommands
);
858 AddCommand('event', GameCommands
);
859 AddCommand('screenshot', GameCommands
);
860 AddCommand('togglechat', GameCommands
);
861 AddCommand('toggleteamchat', GameCommands
);
862 AddCommand('weapon', GameCommands
);
863 AddCommand('p1_weapon', GameCommands
);
864 AddCommand('p2_weapon', GameCommands
);
866 AddCommand('god', GameCheats
);
867 AddCommand('notarget', GameCheats
);
868 AddCommand('give', GameCheats
); // "exit" too ;-)
869 AddCommand('open', GameCheats
);
870 AddCommand('fly', GameCheats
);
871 AddCommand('noclip', GameCheats
);
872 AddCommand('speedy', GameCheats
);
873 AddCommand('jumpy', GameCheats
);
874 AddCommand('noreload', GameCheats
);
875 AddCommand('aimline', GameCheats
);
876 AddCommand('automap', GameCheats
);
878 AddAction('jump', ACTION_JUMP
);
879 AddAction('moveleft', ACTION_MOVELEFT
);
880 AddAction('moveright', ACTION_MOVERIGHT
);
881 AddAction('lookup', ACTION_LOOKUP
);
882 AddAction('lookdown', ACTION_LOOKDOWN
);
883 AddAction('attack', ACTION_ATTACK
);
884 AddAction('scores', ACTION_SCORES
);
885 AddAction('activate', ACTION_ACTIVATE
);
886 AddAction('strafe', ACTION_STRAFE
);
887 AddAction('weapnext', ACTION_WEAPNEXT
);
888 AddAction('weapprev', ACTION_WEAPPREV
);
890 WhitelistCommand('say');
891 WhitelistCommand('tell');
892 WhitelistCommand('overtime');
893 WhitelistCommand('ready');
894 WhitelistCommand('map');
895 WhitelistCommand('nextmap');
896 WhitelistCommand('endmap');
897 WhitelistCommand('restart');
898 WhitelistCommand('kick');
899 WhitelistCommand('ban');
901 WhitelistCommand('addbot');
902 WhitelistCommand('bot_add');
903 WhitelistCommand('bot_addred');
904 WhitelistCommand('bot_addblue');
905 WhitelistCommand('bot_removeall');
907 WhitelistCommand('g_gamemode');
908 WhitelistCommand('g_friendlyfire');
909 WhitelistCommand('g_weaponstay');
910 WhitelistCommand('g_allow_exit');
911 WhitelistCommand('g_allow_monsters');
912 WhitelistCommand('g_scorelimit');
913 WhitelistCommand('g_timelimit');
915 g_Console_ResetBinds
;
916 g_Console_ReadConfig(GameDir
+ '/dfconfig.cfg');
917 g_Console_ReadConfig(GameDir
+ '/autoexec.cfg');
919 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
923 procedure g_Console_Update();
929 // Â ïðîöåññå îòêðûòèÿ:
930 if gConsoleShow
and (Cons_Y
< 0) then
932 Cons_Y
:= Cons_Y
+Step
;
935 // Â ïðîöåññå çàêðûòèÿ:
936 if (not gConsoleShow
) and
937 (Cons_Y
> -(gScreenHeight
div 2)) then
938 Cons_Y
:= Cons_Y
-Step
;
940 // Îêîí÷àòåëüíî îòêðûëàñü:
944 // Îêîí÷àòåëüíî çàêðûëàñü:
945 if Cons_Y
<= (-(gScreenHeight
div 2)) then
947 Cons_Y
:= -(gScreenHeight
div 2);
953 while a
<= High(MsgArray
) do
955 if MsgArray
[a
].Time
> 0 then
957 if MsgArray
[a
].Time
= 1 then
959 if a
< High(MsgArray
) then
961 for b
:= a
to High(MsgArray
)-1 do
962 MsgArray
[b
] := MsgArray
[b
+1];
964 MsgArray
[High(MsgArray
)].Time
:= 0;
970 Dec(MsgArray
[a
].Time
);
978 procedure drawConsoleText ();
980 CWidth
, CHeight
: Byte;
985 procedure putLine (sp
, ep
: LongWord);
994 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
995 if wdt
+cw
> gScreenWidth
-8 then break
;
996 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1000 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1001 // now print our part
1009 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1010 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1023 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1024 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
1025 skip
:= conSkipLines
;
1026 cbufLastLine(sp
, ep
);
1029 if ty
+CHeight
<= 0 then break
;
1030 until not cbufLineUp(sp
, ep
);
1033 procedure g_Console_Draw();
1035 CWidth
, CHeight
: Byte;
1039 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1041 for a
:= 0 to High(MsgArray
) do
1042 if MsgArray
[a
].Time
> 0 then
1043 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
1046 if not Cons_Shown
then
1052 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
1053 gStdFont
, 255, 255, 255, 1, True);
1054 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1055 gStdFont
, 255, 255, 255, 1, True);
1059 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
1060 gStdFont
, 255, 255, 255, 1, True);
1061 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
1062 gStdFont
, 255, 255, 255, 1, True);
1070 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1071 a
:= (gScreenWidth
- 2*mfW
) div 2;
1072 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
1073 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1074 _RGB(128, 0, 0), 2.0);
1077 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
1078 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
1082 if ConsoleHistory <> nil then
1086 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
1087 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
1089 b := Max(b-Offset, 0);
1090 d := Max(High(ConsoleHistory)-Offset, 0);
1093 for a := d downto b do
1095 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
1102 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
1105 procedure g_Console_Switch();
1108 gConsoleShow
:= not gConsoleShow
;
1110 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1113 procedure g_Console_Chat_Switch(Team
: Boolean = False);
1115 if not g_Game_IsNet
then Exit
;
1116 gConsoleShow
:= False;
1117 gChatShow
:= not gChatShow
;
1121 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1124 procedure g_Console_Char(C
: AnsiChar);
1126 // if gChatShow then
1128 Insert(C
, Line
, CPos
);
1134 tcomplist
: array of AnsiString = nil;
1135 tcompidx
: array of Integer = nil;
1137 procedure Complete ();
1141 ll
, lpfx
, cmd
: AnsiString;
1143 if (Length(Line
) = 0) then
1146 for i
:= 0 to High(commands
) do
1148 // hidden commands are hidden when cheats aren't enabled
1149 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1150 if (Length(commands
[i
].help
) > 0) then
1152 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1156 g_Console_Add(' '+commands
[i
].cmd
);
1162 ll
:= LowerCase(Line
);
1165 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1167 ll
:= Copy(ll
, 0, Length(ll
)-1);
1168 for i
:= 0 to High(commands
) do
1170 // hidden commands are hidden when cheats aren't enabled
1171 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1172 if (commands
[i
].cmd
= ll
) then
1174 if (Length(commands
[i
].help
) > 0) then
1176 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1183 // build completion list
1185 for i
:= 0 to High(commands
) do
1187 // hidden commands are hidden when cheats aren't enabled
1188 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1189 cmd
:= commands
[i
].cmd
;
1190 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1192 if (tused
= Length(tcomplist
)) then
1194 SetLength(tcomplist
, Length(tcomplist
)+128);
1195 SetLength(tcompidx
, Length(tcompidx
)+128);
1197 tcomplist
[tused
] := cmd
;
1198 tcompidx
[tused
] := i
;
1200 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1204 // get longest prefix
1205 for i
:= 0 to tused
-1 do
1207 cmd
:= tcomplist
[i
];
1208 for c
:= 1 to Length(lpfx
) do
1210 if (c
> Length(cmd
)) then break
;
1211 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1215 if (tused
= 0) then exit
;
1219 Line
:= tcomplist
[0]+' ';
1220 CPos
:= Length(Line
)+1;
1224 // has longest prefix?
1225 if (Length(lpfx
) > Length(ll
)) then
1228 CPos
:= Length(Line
)+1;
1233 for i
:= 0 to tused
-1 do
1235 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1237 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1241 g_Console_Add(' '+tcomplist
[i
]);
1249 procedure g_Console_Control(K
: Word);
1253 if (Length(Line
) > 0) and (CPos
> 1) then
1255 Delete(Line
, CPos
-1, 1);
1259 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1260 Delete(Line
, CPos
, 1);
1261 IK_LEFT
, IK_KPLEFT
, VK_LEFT
:
1264 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
:
1265 if CPos
<= Length(Line
) then
1267 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
:
1270 g_Console_Process(Line
)
1274 if (Length(Line
) > 0) and g_Game_IsNet
then
1278 if g_Game_IsClient
then
1279 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1281 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1282 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1286 if g_Game_IsClient
then
1287 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1289 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1297 gJustChatted
:= True;
1298 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
1302 if not gChatShow
then
1304 IK_DOWN
, IK_KPDOWN
, VK_DOWN
:
1305 if not gChatShow
then
1306 if (CommandHistory
<> nil) and
1307 (CmdIndex
< Length(CommandHistory
)) then
1309 if CmdIndex
< Length(CommandHistory
)-1 then
1310 CmdIndex
:= CmdIndex
+ 1;
1311 Line
:= CommandHistory
[CmdIndex
];
1312 CPos
:= Length(Line
) + 1;
1314 IK_UP
, IK_KPUP
, VK_UP
:
1315 if not gChatShow
then
1316 if (CommandHistory
<> nil) and
1317 (CmdIndex
<= Length(CommandHistory
)) then
1319 if CmdIndex
> 0 then
1320 CmdIndex
:= CmdIndex
- 1;
1321 Line
:= CommandHistory
[CmdIndex
];
1322 Cpos
:= Length(Line
) + 1;
1324 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
: // PgUp
1325 if not gChatShow
then Inc(conSkipLines
);
1326 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
: // PgDown
1327 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1331 CPos
:= Length(Line
) + 1;
1335 function GetStr(var Str
: AnsiString): AnsiString;
1340 if Str
[1] = '"' then
1342 for b
:= 1 to Length(Str
) do
1343 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1345 Result
:= Copy(Str
, 2, b
-1);
1346 Delete(Str
, 1, b
+1);
1352 for a
:= 1 to Length(Str
) do
1353 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1355 Result
:= Copy(Str
, 1, a
);
1356 Delete(Str
, 1, a
+1);
1362 function ParseString(Str
: AnsiString): SSArray
;
1373 SetLength(Result
, Length(Result
)+1);
1374 Result
[High(Result
)] := GetStr(Str
);
1378 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1380 procedure conmsg (s
: AnsiString);
1384 if length(s
) = 0 then exit
;
1385 for a
:= 0 to High(MsgArray
) do
1397 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1398 with MsgArray
[High(MsgArray
)] do
1408 // put it to console
1410 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1412 // now show 'em out of console too
1413 show
:= show
and gAllowConsoleMessages
;
1414 if show
and gShowMessages
then
1416 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1417 while length(L
) > 0 do
1420 if f
<= 0 then f
:= length(L
)+1;
1421 conmsg(Copy(L
, 1, f
-1));
1426 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1427 //ConsoleHistory[High(ConsoleHistory)] := L;
1431 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1438 consolewriterLastWasEOL
: Boolean = false;
1440 procedure consolewriter (constref buf
; len
: SizeUInt
);
1444 if (len
< 1) then exit
;
1446 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1449 if (b
[0] <> 13) and (b
[0] <> 10) then
1451 cbufPut(AnsiChar(b
[0]));
1455 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1464 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1465 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1466 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1467 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1469 g_Console_Add(s
, show
);
1473 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1477 g_Console_Add(formatstrf(s
, args
), true);
1481 consolewriterLastWasEOL
:= false;
1482 formatstrf(s
, args
, consolewriter
);
1483 if not consolewriterLastWasEOL
then cbufPut(#10);
1488 procedure g_Console_Clear();
1490 //ConsoleHistory := nil;
1495 procedure AddToHistory(L
: AnsiString);
1499 len
:= Length(CommandHistory
);
1502 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1504 SetLength(CommandHistory
, len
+1);
1505 CommandHistory
[len
] := L
;
1508 CmdIndex
:= Length(CommandHistory
);
1511 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1520 if Trim(C
) = '' then
1523 Arr
:= ParseString(C
);
1527 for i
:= 0 to High(Whitelist
) do
1528 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1532 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1539 if Trim(L
) = '' then
1542 conSkipLines
:= 0; // "unscroll"
1544 if L
= 'goobers' then
1549 g_Console_Add('Your memory serves you well.');
1555 g_Console_Add('> '+L
);
1560 Arr
:= ParseString(L
);
1564 if commands
= nil then
1570 for i
:= 0 to High(commands
) do
1572 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1574 if commands
[i
].action
>= 0 then
1576 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1579 if assigned(commands
[i
].procEx
) then
1581 commands
[i
].procEx(@commands
[i
], Arr
);
1584 if assigned(commands
[i
].proc
) then
1586 commands
[i
].proc(Arr
);
1592 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1596 function g_Console_Interactive
: Boolean;
1598 Result
:= gConsoleShow
1601 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1603 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1605 ASSERT(key
< e_MaxInputKeys
);
1608 gInputBinds
[key
].down
:= ParseAlias(down
);
1609 gInputBinds
[key
].up
:= ParseAlias(up
)
1613 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1616 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1617 var i
, len
: Integer;
1621 if len
= Length(b
) then
1624 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1633 if commands
= nil then Exit
;
1635 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1637 if EqualsCommandLists(ParseAlias(down
), gInputBinds
[i
].down
) then
1639 if EqualsCommandLists(ParseAlias(up
), gInputBinds
[i
].up
) then
1651 function g_Console_Action (action
: Integer): Boolean;
1652 var i
, len
: Integer;
1654 ASSERT(action
>= FIRST_ACTION
);
1655 ASSERT(action
<= LAST_ACTION
);
1657 len
:= Length(gPlayerAction
);
1658 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1662 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1665 if (not gChatShow
) and (not gConsoleShow
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1668 for i
:= 0 to High(gInputBinds
[key
].down
) do
1669 g_Console_Process(gInputBinds
[key
].down
[i
], True)
1671 for i
:= 0 to High(gInputBinds
[key
].up
) do
1672 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1676 procedure g_Console_ResetBinds
;
1679 for i
:= 0 to e_MaxInputKeys
- 1 do
1680 g_Console_BindKey(i
, '', '');
1682 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1683 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1684 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1685 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1686 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1687 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1688 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1689 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1690 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1691 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1692 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1693 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1694 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1695 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1696 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1697 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1698 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1699 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1700 g_Console_BindKey(IK_9
, 'p1_weapon 9');
1701 g_Console_BindKey(IK_0
, 'p1_weapon 10');
1702 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
1703 g_Console_BindKey(IK_T
, 'togglechat');
1704 g_Console_BindKey(IK_Y
, 'toggleteamchat');
1705 g_Console_BindKey(IK_F11
, 'screenshot');
1706 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
1707 g_Console_BindKey(IK_PAUSE
, 'pause');
1708 g_Console_BindKey(IK_F1
, 'vote');
1710 (* for i := 0 to e_MaxJoys - 1 do *)
1713 g_Console_BindKey(e_JoyAxisToKey(i
, 0, 0), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
1714 g_Console_BindKey(e_JoyAxisToKey(i
, 0, 1), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
1715 g_Console_BindKey(e_JoyAxisToKey(i
, 1, 0), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
1716 g_Console_BindKey(e_JoyAxisToKey(i
, 1, 1), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
1717 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
1718 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
1719 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
1720 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
1721 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
1722 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
1725 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
1726 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
1727 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
1728 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
1729 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
1730 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
1731 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
1732 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
1733 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
1734 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
1735 g_Console_BindKey(VK_0
, 'weapon 1');
1736 g_Console_BindKey(VK_1
, 'weapon 2');
1737 g_Console_BindKey(VK_2
, 'weapon 3');
1738 g_Console_BindKey(VK_3
, 'weapon 4');
1739 g_Console_BindKey(VK_4
, 'weapon 5');
1740 g_Console_BindKey(VK_5
, 'weapon 6');
1741 g_Console_BindKey(VK_6
, 'weapon 7');
1742 g_Console_BindKey(VK_7
, 'weapon 8');
1743 g_Console_BindKey(VK_8
, 'weapon 9');
1744 g_Console_BindKey(VK_9
, 'weapon 10');
1745 g_Console_BindKey(VK_A
, 'weapon 11');
1746 g_Console_BindKey(VK_CHAT
, 'togglechat');
1747 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
1748 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
1749 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
1755 procedure g_Console_ReadConfig (filename
: String);
1756 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
1758 if FileExists(filename
) then
1760 AssignFile(f
, filename
);
1770 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
1772 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
1773 g_Console_Process(s
, True)
1780 procedure g_Console_WriteConfig (filename
: String);
1781 var f
: TextFile
; i
, j
: Integer;
1783 AssignFile(f
, filename
);
1785 WriteLn(f
, '// generated by doom2d, do not modify');
1786 WriteLn(f
, 'unbindall');
1787 for i
:= 0 to e_MaxInputKeys
- 1 do
1789 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
1791 Write(f
, 'bind ', e_KeyNames
[i
], ' "');
1792 if Length(gInputBinds
[i
].down
) > 0 then
1794 Write(f
, gInputBinds
[i
].down
[0]);
1795 for j
:= 1 to High(gInputBinds
[i
].down
) do
1796 Write(f
, '; ', gInputBinds
[i
].down
[j
])
1799 if Length(gInputBinds
[i
].up
) > 0 then
1801 Write(f
, ' "', gInputBinds
[i
].up
[0]);
1802 for j
:= 1 to High(gInputBinds
[i
].up
) do
1803 Write(f
, '; ', gInputBinds
[i
].up
[j
]);
1809 for i
:= 0 to High(commands
) do
1811 if not commands
[i
].cheat
then
1813 if @commands
[i
].procEx
= @boolVarHandler
then
1815 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
1816 WriteLn(f
, commands
[i
].cmd
, ' "', j
, '"')
1818 else if @commands
[i
].procEx
= @intVarHandler
then
1820 WriteLn(f
, commands
[i
].cmd
, ' "', PInteger(commands
[i
].ptr
)^, '"')
1822 else if @commands
[i
].procEx
= @singleVarHandler
then
1824 WriteLn(f
, commands
[i
].cmd
, ' "', PVarSingle(commands
[i
].ptr
).val
^:0:6, '"')