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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
36 FIRST_ACTION
= ACTION_JUMP
;
37 LAST_ACTION
= ACTION_WEAPPREV
;
39 procedure g_Console_Init
;
40 procedure g_Console_SysInit
;
41 procedure g_Console_Update
;
42 procedure g_Console_Draw (MessagesOnly
: Boolean = False);
43 procedure g_Console_Char (C
: AnsiChar);
44 procedure g_Console_Control (K
: Word);
45 procedure g_Console_Process (L
: AnsiString; quiet
: Boolean=false);
46 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
47 procedure g_Console_Clear
;
48 function g_Console_CommandBlacklisted (C
: AnsiString): Boolean;
49 procedure g_Console_ReadConfig (filename
: String);
50 procedure g_Console_WriteConfig (filename
: String);
51 procedure g_Console_WriteGameConfig
;
53 function g_Console_Interactive
: Boolean;
54 function g_Console_Action (action
: Integer): Boolean;
55 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
56 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
57 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
58 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
59 procedure g_Console_ResetBinds
;
61 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
62 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
64 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
65 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
66 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
67 procedure conRegVar (const conname
: AnsiString; pvar
: PWord; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
68 procedure conRegVar (const conname
: AnsiString; pvar
: PCardinal; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
69 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
71 // <0: no arg; 0/1: true/false
72 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
74 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
75 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
78 defaultConfigScript
= 'dfconfig.cfg';
81 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
82 gChatShow
: Boolean = false;
83 gChatTeam
: Boolean = false;
84 gAllowConsoleMessages
: Boolean = true;
85 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
86 gParsingBinds
: Boolean = true; // íå ïåðåñîõðàíÿòü êîíôèã âî âðåìÿ ïàðñèíãà
87 gPlayerAction
: Array [0..1, 0..LAST_ACTION
] of Boolean; // [player, action]
88 gConfigScript
: string = defaultConfigScript
;
93 g_textures
, g_main
, e_graphics
, e_input
, g_game
, g_gfx
, g_player
, g_items
,
94 SysUtils
, g_basic
, g_options
, Math
, g_touch
, e_res
,
95 g_menu
, g_gui
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
98 autoexecScript
= 'autoexec.cfg';
99 configComment
= 'generated by doom2d, do not modify';
102 PCommand
= ^TCommand
;
104 TCmdProc
= procedure (p
: SSArray
);
105 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
113 ptr
: Pointer; // various data
114 msg
: AnsiString; // message for var changes
116 action
: Integer; // >= 0 for action commands
117 player
: Integer; // used for action commands
128 MaxScriptRecursion
= 16;
130 DEBUG_STRING
= 'DEBUG MODE';
134 RecursionDepth
: Word = 0;
135 RecursionLimitHit
: Boolean = False;
137 ConsoleHeight
: Single;
138 Cons_Shown
: Boolean; // draw console
139 InputReady
: Boolean; // allow text input in console/chat
142 //ConsoleHistory: SSArray;
143 CommandHistory
: SSArray
;
145 commands
: Array of TCommand
= nil;
146 Aliases
: Array of TAlias
= nil;
148 conSkipLines
: Integer = 0;
149 MsgArray
: Array [0..4] of record
154 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
157 menu_toggled
: BOOLEAN; (* hack for menu controls *)
160 ConsoleTrans
: Single;
163 procedure g_Console_Switch
;
165 Cons_Y
:= Min(0, Max(Cons_Y
, -Floor(gScreenHeight
* ConsoleHeight
)));
166 if Cons_Shown
= False then
167 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
169 gConsoleShow
:= not gConsoleShow
;
172 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
175 procedure g_Console_Chat_Switch (Team
: Boolean = False);
177 if not g_Game_IsNet
then Exit
;
178 Cons_Y
:= Min(0, Max(Cons_Y
, -Floor(gScreenHeight
* ConsoleHeight
)));
179 if Cons_Shown
= False then
180 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
181 gConsoleShow
:= False;
182 gChatShow
:= not gChatShow
;
188 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
191 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
192 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
201 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
202 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
203 if (pos
> slen
) then exit
;
204 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
206 while (pos
<= slen
) do
208 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
209 res
:= res
*10+Byte(s
[pos
])-48;
212 if (pos
<= slen
) then
215 if (s
[pos
] <> '.') then exit
;
217 while (pos
<= slen
) do
219 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
221 res
+= frac
*(Byte(s
[pos
])-48);
225 if (pos
<= slen
) then exit
; // oops
230 // ////////////////////////////////////////////////////////////////////////// //
231 // <0: no arg; 0/1: true/false; 666: toggle
232 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
234 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
236 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
237 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
238 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
239 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
243 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
244 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
248 if (Length(p
) > 2) then
250 conwritefln('too many arguments to ''%s''', [p
[0]]);
255 case conGetBoolArg(p
, 1) of
257 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
258 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
259 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
262 g_Console_WriteGameConfig();
263 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
264 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
268 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
272 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
276 if (Length(p
) <> 2) then
278 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
283 old
:= PInteger(me
.ptr
)^;
284 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
285 if PInteger(me
.ptr
)^ <> old
then
286 g_Console_WriteGameConfig();
288 conwritefln('invalid integer value: "%s"', [p
[1]]);
294 procedure wordVarHandler (me
: PCommand
; p
: SSArray
);
298 if (Length(p
) <> 2) then
300 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
305 old
:= PWord(me
.ptr
)^;
306 PWord(me
.ptr
)^ := min($FFFF, StrToDWord(p
[1]));
307 if PWord(me
.ptr
)^ <> old
then
308 g_Console_WriteGameConfig();
310 conwritefln('invalid word value: "%s"', [p
[1]]);
316 procedure dwordVarHandler (me
: PCommand
; p
: SSArray
);
320 if (Length(p
) <> 2) then
322 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
327 old
:= PCardinal(me
.ptr
)^;
328 PCardinal(me
.ptr
)^ := StrToDWord(p
[1]);
329 if PCardinal(me
.ptr
)^ <> old
then
330 g_Console_WriteGameConfig();
332 conwritefln('invalid dword value: "%s"', [p
[1]]);
338 procedure strVarHandler (me
: PCommand
; p
: SSArray
);
342 if (Length(p
) <> 2) then
344 conwritefln('%s %s', [me
.cmd
, QuoteStr(PAnsiString(me
.ptr
)^)]);
348 old
:= PAnsiString(me
.ptr
)^;
349 PAnsiString(me
.ptr
)^ := p
[1];
350 if PAnsiString(me
.ptr
)^ <> old
then
351 g_Console_WriteGameConfig();
356 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
361 f
:= Length(commands
);
362 SetLength(commands
, f
+1);
364 cp
.cmd
:= LowerCase(conname
);
366 cp
.procEx
:= boolVarHandler
;
368 cp
.hidden
:= ahidden
;
377 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
382 f
:= Length(commands
);
383 SetLength(commands
, f
+1);
385 cp
.cmd
:= LowerCase(conname
);
387 cp
.procEx
:= intVarHandler
;
389 cp
.hidden
:= ahidden
;
398 procedure conRegVar (const conname
: AnsiString; pvar
: PWord; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
403 f
:= Length(commands
);
404 SetLength(commands
, f
+1);
406 cp
.cmd
:= LowerCase(conname
);
408 cp
.procEx
:= wordVarHandler
;
410 cp
.hidden
:= ahidden
;
419 procedure conRegVar (const conname
: AnsiString; pvar
: PCardinal; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
424 f
:= Length(commands
);
425 SetLength(commands
, f
+1);
427 cp
.cmd
:= LowerCase(conname
);
429 cp
.procEx
:= dwordVarHandler
;
431 cp
.hidden
:= ahidden
;
440 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
445 f
:= Length(commands
);
446 SetLength(commands
, f
+1);
448 cp
.cmd
:= LowerCase(conname
);
450 cp
.procEx
:= strVarHandler
;
452 cp
.hidden
:= ahidden
;
460 // ////////////////////////////////////////////////////////////////////////// //
462 PVarSingle
= ^TVarSingle
;
465 min
, max
, def
: Single; // default will be starting value
469 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
475 if (Length(p
) > 2) then
477 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
480 pv
:= PVarSingle(me
.ptr
);
482 if (Length(p
) = 2) then
484 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
485 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
486 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
487 (CompareText(p
[1], 'ona') = 0) then
493 if not conParseFloat(nv
, p
[1]) then
495 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
498 if (nv
< pv
.min
) then nv
:= pv
.min
;
499 if (nv
> pv
.max
) then nv
:= pv
.max
;
503 if pv
.val
^ <> old
then
504 g_Console_WriteGameConfig();
506 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
507 conwritefln('%s %s', [msg
, pv
.val
^]);
511 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
517 GetMem(pv
, sizeof(TVarSingle
));
522 f
:= Length(commands
);
523 SetLength(commands
, f
+1);
525 cp
.cmd
:= LowerCase(conname
);
527 cp
.procEx
:= singleVarHandler
;
529 cp
.hidden
:= ahidden
;
538 // ////////////////////////////////////////////////////////////////////////// //
539 function GetStrACmd(var Str
: AnsiString): AnsiString;
544 for a
:= 1 to Length(Str
) do
545 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
547 Result
:= Copy(Str
, 1, a
);
554 function ParseAlias(Str
: AnsiString): SSArray
;
565 SetLength(Result
, Length(Result
)+1);
566 Result
[High(Result
)] := GetStrACmd(Str
);
570 procedure ConsoleCommands(p
: SSArray
);
576 cmd
:= LowerCase(p
[0]);
579 if cmd
= 'clear' then
581 //ConsoleHistory := nil;
585 for a
:= 0 to High(MsgArray
) do
593 if cmd
= 'clearhistory' then
594 CommandHistory
:= nil;
596 if cmd
= 'showhistory' then
597 if CommandHistory
<> nil then
600 for a
:= 0 to High(CommandHistory
) do
601 g_Console_Add(' '+CommandHistory
[a
]);
604 if cmd
= 'commands' then
607 g_Console_Add('commands list:');
608 for a
:= High(commands
) downto 0 do
610 if (Length(commands
[a
].help
) > 0) then
612 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
616 g_Console_Add(' '+commands
[a
].cmd
);
622 g_Console_Add(TimeToStr(Now
), True);
625 g_Console_Add(DateToStr(Now
), True);
628 if Length(p
) > 1 then
630 if p
[1] = 'ololo' then
635 for a
:= 1 to High(p
) do
637 g_Console_Add(b_Text_Format(s
), True);
646 if ConsoleHistory <> nil then
648 if Length(P) > 1 then
651 s := GameDir+'/console.txt';
656 if IOResult <> 0 then
658 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
663 for a := 0 to High(ConsoleHistory) do
664 WriteLn(F, ConsoleHistory[a]);
667 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
676 if Length(p
) = 2 then
677 g_Console_ReadConfig(p
[1])
679 g_Console_Add('exec <script file>');
682 if cmd
= 'writeconfig' then
684 // writeconfig <filename>
685 if Length(p
) = 2 then
687 s
:= e_GetWriteableDir(ConfigDirs
);
688 g_Console_WriteConfig(e_CatPath(s
, p
[1]))
692 g_Console_Add('writeconfig <file>')
696 if (cmd
= 'ver') or (cmd
= 'version') then
698 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
699 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
700 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
703 if cmd
= 'alias' then
705 // alias [alias_name] [commands]
706 if Length(p
) > 1 then
708 for a
:= 0 to High(Aliases
) do
709 if Aliases
[a
].name
= p
[1] then
711 if Length(p
) > 2 then
712 Aliases
[a
].commands
:= ParseAlias(p
[2])
714 for b
:= 0 to High(Aliases
[a
].commands
) do
715 g_Console_Add(Aliases
[a
].commands
[b
]);
718 SetLength(Aliases
, Length(Aliases
)+1);
720 Aliases
[a
].name
:= p
[1];
721 if Length(p
) > 2 then
722 Aliases
[a
].commands
:= ParseAlias(p
[2])
724 for b
:= 0 to High(Aliases
[a
].commands
) do
725 g_Console_Add(Aliases
[a
].commands
[b
]);
727 for a
:= 0 to High(Aliases
) do
728 if Aliases
[a
].commands
<> nil then
729 g_Console_Add(Aliases
[a
].name
);
735 if Length(p
) > 1 then
737 if Aliases
= nil then
739 for a
:= 0 to High(Aliases
) do
740 if Aliases
[a
].name
= p
[1] then
742 if Aliases
[a
].commands
<> nil then
744 // with this system proper endless loop detection seems either impossible
745 // or very dirty to implement, so let's have this instead
746 // prevents endless loops
747 for b
:= 0 to High(Aliases
[a
].commands
) do
750 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
751 if not RecursionLimitHit
then
752 g_Console_Process(Aliases
[a
].commands
[b
], True);
755 if (RecursionDepth
= 0) and RecursionLimitHit
then
757 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
758 RecursionLimitHit
:= False;
765 g_Console_Add('call <alias name>');
769 procedure WhitelistCommand(cmd
: AnsiString);
773 SetLength(Whitelist
, Length(Whitelist
)+1);
774 a
:= High(Whitelist
);
775 Whitelist
[a
] := LowerCase(cmd
);
778 procedure segfault (p
: SSArray
);
785 function GetCommandString (p
: SSArray
): AnsiString;
789 if Length(p
) >= 1 then
792 for i
:= 1 to High(p
) do
793 result
:= result
+ '; ' + p
[i
]
797 function QuoteStr(str
: String): String;
799 if Pos(' ', str
) > 0 then
800 Result
:= '"' + str
+ '"'
805 procedure BindCommands (p
: SSArray
);
806 var cmd
, key
: AnsiString; i
: Integer;
808 cmd
:= LowerCase(p
[0]);
811 // bind <key> [down [up]]
812 if (Length(p
) >= 2) and (Length(p
) <= 4) then
815 key
:= LowerCase(p
[1]);
816 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
817 if i
< e_MaxInputKeys
then
819 if Length(p
) = 2 then
820 g_Console_Add(QuoteStr(e_KeyNames
[i
]) + ' = ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)))
821 else if Length(p
) = 3 then
822 g_Console_BindKey(i
, p
[2], '')
824 g_Console_BindKey(i
, p
[2], p
[3])
827 g_Console_Add('bind: "' + p
[1] + '" is not a key')
831 g_Console_Add('bind <key> <down action> [up action]')
834 for i
:= 0 to e_MaxInputKeys
- 1 do
835 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
836 g_Console_Add(e_KeyNames
[i
] + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
839 if Length(p
) = 2 then
841 key
:= LowerCase(p
[1]);
843 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
844 if i
< e_MaxInputKeys
then
845 g_Console_BindKey(i
, '')
847 g_Console_Add('unbind: "' + p
[1] + '" is not a key')
850 g_Console_Add('unbind <key>');
852 for i
:= 0 to e_MaxInputKeys
- 1 do
853 g_Console_BindKey(i
, '');
855 g_Touch_ShowKeyboard(True);
857 g_Touch_ShowKeyboard(False);
862 else if gChatShow
then
863 g_Console_Chat_Switch
871 g_Console_Chat_Switch
;
873 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
874 g_Console_Chat_Switch(True);
878 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
883 SetLength(commands
, Length(commands
)+1);
886 cp
.cmd
:= LowerCase(cmd
);
890 cp
.hidden
:= ahidden
;
898 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
900 PrefixList
: array [0..1] of AnsiString = ('+', '-');
901 PlayerList
: array [0..1] of Integer = (1, 2);
906 procedure NewAction (cmd
: AnsiString; player
: Integer);
909 SetLength(commands
, Length(commands
) + 1);
910 cp
:= @commands
[High(commands
)];
911 cp
.cmd
:= LowerCase(cmd
);
924 ASSERT(action
>= FIRST_ACTION
);
925 ASSERT(action
<= LAST_ACTION
);
926 for s
in PrefixList
do
928 NewAction(s
+ cmd
, 0);
929 for i
in PlayerList
do
930 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
934 procedure g_Console_SysInit
;
937 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
938 gConsoleShow
:= False;
944 for a
:= 0 to High(MsgArray
) do
951 AddCommand('segfault', segfault
, 'make segfault');
953 AddCommand('quit', SystemCommands
);
954 AddCommand('exit', SystemCommands
);
955 AddCommand('r_reset', SystemCommands
);
956 AddCommand('r_maxfps', SystemCommands
);
957 AddCommand('g_language', SystemCommands
);
959 AddCommand('bind', BindCommands
);
960 AddCommand('bindlist', BindCommands
);
961 AddCommand('unbind', BindCommands
);
962 AddCommand('unbindall', BindCommands
);
963 AddCommand('showkeyboard', BindCommands
);
964 AddCommand('hidekeyboard', BindCommands
);
965 AddCommand('togglemenu', BindCommands
);
966 AddCommand('toggleconsole', BindCommands
);
967 AddCommand('togglechat', BindCommands
);
968 AddCommand('toggleteamchat', BindCommands
);
970 AddCommand('clear', ConsoleCommands
, 'clear console');
971 AddCommand('clearhistory', ConsoleCommands
);
972 AddCommand('showhistory', ConsoleCommands
);
973 AddCommand('commands', ConsoleCommands
);
974 AddCommand('time', ConsoleCommands
);
975 AddCommand('date', ConsoleCommands
);
976 AddCommand('echo', ConsoleCommands
);
977 AddCommand('dump', ConsoleCommands
);
978 AddCommand('exec', ConsoleCommands
);
979 AddCommand('writeconfig', ConsoleCommands
);
980 AddCommand('alias', ConsoleCommands
);
981 AddCommand('call', ConsoleCommands
);
982 AddCommand('ver', ConsoleCommands
);
983 AddCommand('version', ConsoleCommands
);
985 AddCommand('d_window', DebugCommands
);
986 AddCommand('d_sounds', DebugCommands
);
987 AddCommand('d_frames', DebugCommands
);
988 AddCommand('d_winmsg', DebugCommands
);
989 AddCommand('d_monoff', DebugCommands
);
990 AddCommand('d_botoff', DebugCommands
);
991 AddCommand('d_monster', DebugCommands
);
992 AddCommand('d_health', DebugCommands
);
993 AddCommand('d_player', DebugCommands
);
994 AddCommand('d_joy', DebugCommands
);
995 AddCommand('d_mem', DebugCommands
);
997 AddCommand('p1_name', PlayerSettingsCVars
);
998 AddCommand('p2_name', PlayerSettingsCVars
);
999 AddCommand('p1_color', PlayerSettingsCVars
);
1000 AddCommand('p2_color', PlayerSettingsCVars
);
1001 AddCommand('p1_model', PlayerSettingsCVars
);
1002 AddCommand('p2_model', PlayerSettingsCVars
);
1004 AddCommand('g_max_particles', GameCVars
);
1005 AddCommand('g_max_shells', GameCVars
);
1006 AddCommand('g_max_gibs', GameCVars
);
1007 AddCommand('g_max_corpses', GameCVars
);
1008 AddCommand('g_gamemode', GameCVars
);
1009 AddCommand('g_friendlyfire', GameCVars
);
1010 AddCommand('g_weaponstay', GameCVars
);
1011 AddCommand('g_allow_exit', GameCVars
);
1012 AddCommand('g_dm_keys', GameCVars
);
1013 AddCommand('g_allow_monsters', GameCVars
);
1014 AddCommand('g_bot_vsmonsters', GameCVars
);
1015 AddCommand('g_bot_vsplayers', GameCVars
);
1016 AddCommand('g_scorelimit', GameCVars
);
1017 AddCommand('g_timelimit', GameCVars
);
1018 AddCommand('g_maxlives', GameCVars
);
1019 AddCommand('g_warmup_time', GameCVars
);
1020 AddCommand('g_spawn_invul', GameCVars
);
1021 AddCommand('g_item_respawn_time', GameCVars
);
1022 AddCommand('sv_intertime', GameCVars
);
1024 AddCommand('sv_name', NetServerCVars
);
1025 AddCommand('sv_passwd', NetServerCVars
);
1026 AddCommand('sv_maxplrs', NetServerCVars
);
1027 AddCommand('sv_public', NetServerCVars
);
1028 AddCommand('sv_port', NetServerCVars
);
1030 AddCommand('pause', GameCommands
);
1031 AddCommand('endgame', GameCommands
);
1032 AddCommand('restart', GameCommands
);
1033 AddCommand('addbot', GameCommands
);
1034 AddCommand('bot_add', GameCommands
);
1035 AddCommand('bot_addlist', GameCommands
);
1036 AddCommand('bot_addred', GameCommands
);
1037 AddCommand('bot_addblue', GameCommands
);
1038 AddCommand('bot_removeall', GameCommands
);
1039 AddCommand('chat', GameCommands
);
1040 AddCommand('teamchat', GameCommands
);
1041 AddCommand('game', GameCommands
);
1042 AddCommand('host', GameCommands
);
1043 AddCommand('map', GameCommands
);
1044 AddCommand('nextmap', GameCommands
);
1045 AddCommand('endmap', GameCommands
);
1046 AddCommand('goodbye', GameCommands
);
1047 AddCommand('suicide', GameCommands
);
1048 AddCommand('spectate', GameCommands
);
1049 AddCommand('ready', GameCommands
);
1050 AddCommand('kick', GameCommands
);
1051 AddCommand('kick_id', GameCommands
);
1052 AddCommand('kick_pid', GameCommands
);
1053 AddCommand('ban', GameCommands
);
1054 AddCommand('ban_id', GameCommands
);
1055 AddCommand('ban_pid', GameCommands
);
1056 AddCommand('permban', GameCommands
);
1057 AddCommand('permban_id', GameCommands
);
1058 AddCommand('permban_pid', GameCommands
);
1059 AddCommand('permban_ip', GameCommands
);
1060 AddCommand('unban', GameCommands
);
1061 AddCommand('connect', GameCommands
);
1062 AddCommand('disconnect', GameCommands
);
1063 AddCommand('reconnect', GameCommands
);
1064 AddCommand('say', GameCommands
);
1065 AddCommand('tell', GameCommands
);
1066 AddCommand('centerprint', GameCommands
);
1067 AddCommand('overtime', GameCommands
);
1068 AddCommand('rcon_password', GameCommands
);
1069 AddCommand('rcon', GameCommands
);
1070 AddCommand('callvote', GameCommands
);
1071 AddCommand('vote', GameCommands
);
1072 AddCommand('clientlist', GameCommands
);
1073 AddCommand('event', GameCommands
);
1074 AddCommand('screenshot', GameCommands
);
1075 AddCommand('weapon', GameCommands
);
1076 AddCommand('p1_weapon', GameCommands
);
1077 AddCommand('p2_weapon', GameCommands
);
1079 AddCommand('god', GameCheats
);
1080 AddCommand('notarget', GameCheats
);
1081 AddCommand('give', GameCheats
); // "exit" too ;-)
1082 AddCommand('open', GameCheats
);
1083 AddCommand('fly', GameCheats
);
1084 AddCommand('noclip', GameCheats
);
1085 AddCommand('speedy', GameCheats
);
1086 AddCommand('jumpy', GameCheats
);
1087 AddCommand('noreload', GameCheats
);
1088 AddCommand('aimline', GameCheats
);
1089 AddCommand('automap', GameCheats
);
1091 AddAction('jump', ACTION_JUMP
);
1092 AddAction('moveleft', ACTION_MOVELEFT
);
1093 AddAction('moveright', ACTION_MOVERIGHT
);
1094 AddAction('lookup', ACTION_LOOKUP
);
1095 AddAction('lookdown', ACTION_LOOKDOWN
);
1096 AddAction('attack', ACTION_ATTACK
);
1097 AddAction('scores', ACTION_SCORES
);
1098 AddAction('activate', ACTION_ACTIVATE
);
1099 AddAction('strafe', ACTION_STRAFE
);
1100 AddAction('weapnext', ACTION_WEAPNEXT
);
1101 AddAction('weapprev', ACTION_WEAPPREV
);
1103 WhitelistCommand('say');
1104 WhitelistCommand('tell');
1105 WhitelistCommand('overtime');
1106 WhitelistCommand('ready');
1107 WhitelistCommand('map');
1108 WhitelistCommand('nextmap');
1109 WhitelistCommand('endmap');
1110 WhitelistCommand('restart');
1111 WhitelistCommand('kick');
1112 WhitelistCommand('kick_pid');
1113 WhitelistCommand('ban');
1114 WhitelistCommand('ban_pid');
1115 WhitelistCommand('centerprint');
1117 WhitelistCommand('addbot');
1118 WhitelistCommand('bot_add');
1119 WhitelistCommand('bot_addred');
1120 WhitelistCommand('bot_addblue');
1121 WhitelistCommand('bot_removeall');
1123 WhitelistCommand('g_gamemode');
1124 WhitelistCommand('g_friendlyfire');
1125 WhitelistCommand('g_weaponstay');
1126 WhitelistCommand('g_allow_exit');
1127 WhitelistCommand('g_dm_keys');
1128 WhitelistCommand('g_allow_monsters');
1129 WhitelistCommand('g_bot_vsmonsters');
1130 WhitelistCommand('g_bot_vsplayers');
1131 WhitelistCommand('g_scorelimit');
1132 WhitelistCommand('g_timelimit');
1133 WhitelistCommand('g_maxlives');
1134 WhitelistCommand('g_warmup_time');
1135 WhitelistCommand('g_spawn_invul');
1136 WhitelistCommand('g_item_respawn_time');
1138 g_Console_ResetBinds
;
1139 g_Console_ReadConfig(gConfigScript
);
1140 g_Console_ReadConfig(autoexecScript
);
1141 gParsingBinds
:= False;
1144 procedure g_Console_Init
;
1146 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
1147 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
1151 procedure g_Console_Update
;
1153 a
, b
, Step
: Integer;
1157 Step
:= Max(1, Round(Floor(gScreenHeight
* ConsoleHeight
) * ConsoleStep
));
1158 if gConsoleShow
then
1160 (* Open animation *)
1161 Cons_Y
:= Min(Cons_Y
+ Step
, 0);
1166 (* Close animation *)
1167 Cons_Y
:= Max(Cons_Y
- Step
, -Floor(gScreenHeight
* ConsoleHeight
));
1168 Cons_Shown
:= Cons_Y
> -Floor(gScreenHeight
* ConsoleHeight
);
1177 while a
<= High(MsgArray
) do
1179 if MsgArray
[a
].Time
> 0 then
1181 if MsgArray
[a
].Time
= 1 then
1183 if a
< High(MsgArray
) then
1185 for b
:= a
to High(MsgArray
)-1 do
1186 MsgArray
[b
] := MsgArray
[b
+1];
1188 MsgArray
[High(MsgArray
)].Time
:= 0;
1194 Dec(MsgArray
[a
].Time
);
1202 procedure drawConsoleText ();
1204 CWidth
, CHeight
: Byte;
1209 procedure putLine (sp
, ep
: LongWord);
1218 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1219 if wdt
+cw
> gScreenWidth
-8 then break
;
1220 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1224 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1225 // now print our part
1233 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1234 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1247 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1248 ty
:= Floor(gScreenHeight
* ConsoleHeight
) - 4 - 2 * CHeight
- Abs(Cons_Y
);
1249 skip
:= conSkipLines
;
1250 cbufLastLine(sp
, ep
);
1253 if ty
+CHeight
<= 0 then break
;
1254 until not cbufLineUp(sp
, ep
);
1257 procedure g_Console_Draw(MessagesOnly
: Boolean = False);
1259 CWidth
, CHeight
: Byte;
1261 a
, b
, offset_y
: Integer;
1263 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1265 if ChatTop
and gChatShow
then
1270 for a
:= 0 to High(MsgArray
) do
1271 if MsgArray
[a
].Time
> 0 then
1272 e_TextureFontPrintFmt(0, offset_y
+ CHeight
* a
, MsgArray
[a
].Msg
, gStdFont
, True);
1274 if MessagesOnly
then Exit
;
1281 offset_y
:= gScreenHeight
- CHeight
- 1;
1284 e_TextureFontPrintEx(0, offset_y
, 'say team> ' + Line
, gStdFont
, 255, 255, 255, 1, True);
1285 e_TextureFontPrintEx((CPos
+ 9) * CWidth
, offset_y
, '_', gStdFont
, 255, 255, 255, 1, True);
1289 e_TextureFontPrintEx(0, offset_y
, 'say> ' + Line
, gStdFont
, 255, 255, 255, 1, True);
1290 e_TextureFontPrintEx((CPos
+ 4) * CWidth
, offset_y
, '_', gStdFont
, 255, 255, 255, 1, True);
1294 if not Cons_Shown
then
1299 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1300 a
:= (gScreenWidth
- 2*mfW
) div 2;
1301 b
:= Cons_Y
+ (Floor(gScreenHeight
* ConsoleHeight
) - 2 * mfH
) div 2;
1302 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1303 _RGB(128, 0, 0), 2.0);
1306 e_DrawSize(ID
, 0, Cons_Y
, Round(ConsoleTrans
* 255), False, False, gScreenWidth
, Floor(gScreenHeight
* ConsoleHeight
));
1307 e_TextureFontPrint(0, Cons_Y
+ Floor(gScreenHeight
* ConsoleHeight
) - CHeight
- 4, '> ' + Line
, gStdFont
);
1311 if ConsoleHistory <> nil then
1315 if Length(ConsoleHistory) > (Floor(gScreenHeight * ConsoleHeight) div CHeight) - 1 then
1316 b := Length(ConsoleHistory) - (Floor(gScreenHeight * ConsoleHeight) div CHeight) + 1;
1318 b := Max(b-Offset, 0);
1319 d := Max(High(ConsoleHistory)-Offset, 0);
1322 for a := d downto b do
1324 e_TextureFontPrintFmt(0, Floor(gScreenHeight * ConsoleHeight) - 4 - c * CHeight - Abs(Cons_Y), ConsoleHistory[a], gStdFont, True);
1330 e_TextureFontPrint((CPos
+ 1) * CWidth
, Cons_Y
+ Floor(gScreenHeight
* ConsoleHeight
) - 21, '_', gStdFont
);
1333 procedure g_Console_Char(C
: AnsiChar);
1335 if InputReady
and (gConsoleShow
or gChatShow
) then
1337 Insert(C
, Line
, CPos
);
1344 tcomplist
: array of AnsiString = nil;
1345 tcompidx
: array of Integer = nil;
1347 procedure Complete ();
1351 ll
, lpfx
, cmd
: AnsiString;
1353 if (Length(Line
) = 0) then
1356 for i
:= 0 to High(commands
) do
1358 // hidden commands are hidden when cheats aren't enabled
1359 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1360 if (Length(commands
[i
].help
) > 0) then
1362 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1366 g_Console_Add(' '+commands
[i
].cmd
);
1372 ll
:= LowerCase(Line
);
1375 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1377 ll
:= Copy(ll
, 0, Length(ll
)-1);
1378 for i
:= 0 to High(commands
) do
1380 // hidden commands are hidden when cheats aren't enabled
1381 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1382 if (commands
[i
].cmd
= ll
) then
1384 if (Length(commands
[i
].help
) > 0) then
1386 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1393 // build completion list
1395 for i
:= 0 to High(commands
) do
1397 // hidden commands are hidden when cheats aren't enabled
1398 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1399 cmd
:= commands
[i
].cmd
;
1400 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1402 if (tused
= Length(tcomplist
)) then
1404 SetLength(tcomplist
, Length(tcomplist
)+128);
1405 SetLength(tcompidx
, Length(tcompidx
)+128);
1407 tcomplist
[tused
] := cmd
;
1408 tcompidx
[tused
] := i
;
1410 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1414 // get longest prefix
1415 for i
:= 0 to tused
-1 do
1417 cmd
:= tcomplist
[i
];
1418 for c
:= 1 to Length(lpfx
) do
1420 if (c
> Length(cmd
)) then break
;
1421 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1425 if (tused
= 0) then exit
;
1429 Line
:= tcomplist
[0]+' ';
1430 CPos
:= Length(Line
)+1;
1434 // has longest prefix?
1435 if (Length(lpfx
) > Length(ll
)) then
1438 CPos
:= Length(Line
)+1;
1443 for i
:= 0 to tused
-1 do
1445 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1447 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1451 g_Console_Add(' '+tcomplist
[i
]);
1459 procedure g_Console_Control(K
: Word);
1463 if (Length(Line
) > 0) and (CPos
> 1) then
1465 Delete(Line
, CPos
-1, 1);
1469 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1470 Delete(Line
, CPos
, 1);
1471 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1474 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1475 if CPos
<= Length(Line
) then
1477 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1479 if gConsoleShow
then
1480 g_Console_Process(Line
)
1484 if (Length(Line
) > 0) and g_Game_IsNet
then
1488 if g_Game_IsClient
then
1489 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1491 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1492 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1496 if g_Game_IsClient
then
1497 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1499 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1506 gJustChatted
:= True;
1507 g_Console_Chat_Switch
;
1508 InputReady
:= False;
1512 if not gChatShow
then
1514 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1515 if not gChatShow
then
1516 if (CommandHistory
<> nil) and
1517 (CmdIndex
< Length(CommandHistory
)) then
1519 if CmdIndex
< Length(CommandHistory
)-1 then
1520 CmdIndex
:= CmdIndex
+ 1;
1521 Line
:= CommandHistory
[CmdIndex
];
1522 CPos
:= Length(Line
) + 1;
1524 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1525 if not gChatShow
then
1526 if (CommandHistory
<> nil) and
1527 (CmdIndex
<= Length(CommandHistory
)) then
1529 if CmdIndex
> 0 then
1530 CmdIndex
:= CmdIndex
- 1;
1531 Line
:= CommandHistory
[CmdIndex
];
1532 Cpos
:= Length(Line
) + 1;
1534 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1535 if not gChatShow
then Inc(conSkipLines
);
1536 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1537 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1541 CPos
:= Length(Line
) + 1;
1542 IK_A
..IK_Z
, IK_SPACE
, IK_SHIFT
, IK_RSHIFT
, IK_CAPSLOCK
, IK_LBRACKET
, IK_RBRACKET
,
1543 IK_SEMICOLON
, IK_QUOTE
, IK_BACKSLASH
, IK_SLASH
, IK_COMMA
, IK_DOT
, (*IK_EQUALS,*)
1544 IK_0
, IK_1
, IK_2
, IK_3
, IK_4
, IK_5
, IK_6
, IK_7
, IK_8
, IK_9
, IK_MINUS
, IK_EQUALS
:
1545 (* see TEXTINPUT event *)
1549 function GetStr(var Str
: AnsiString): AnsiString;
1554 if Str
[1] = '"' then
1556 for b
:= 1 to Length(Str
) do
1557 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1559 Result
:= Copy(Str
, 2, b
-1);
1560 Delete(Str
, 1, b
+1);
1566 for a
:= 1 to Length(Str
) do
1567 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1569 Result
:= Copy(Str
, 1, a
);
1570 Delete(Str
, 1, a
+1);
1576 function ParseString(Str
: AnsiString): SSArray
;
1587 SetLength(Result
, Length(Result
)+1);
1588 Result
[High(Result
)] := GetStr(Str
);
1592 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1594 procedure conmsg (s
: AnsiString);
1598 if length(s
) = 0 then exit
;
1599 for a
:= 0 to High(MsgArray
) do
1611 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1612 with MsgArray
[High(MsgArray
)] do
1622 // put it to console
1624 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1626 // now show 'em out of console too
1627 show
:= show
and gAllowConsoleMessages
;
1628 if show
and gShowMessages
then
1630 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1631 while length(L
) > 0 do
1634 if f
<= 0 then f
:= length(L
)+1;
1635 conmsg(Copy(L
, 1, f
-1));
1640 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1641 //ConsoleHistory[High(ConsoleHistory)] := L;
1645 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1652 consolewriterLastWasEOL
: Boolean = false;
1654 procedure consolewriter (constref buf
; len
: SizeUInt
);
1658 if (len
< 1) then exit
;
1660 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1663 if (b
[0] <> 13) and (b
[0] <> 10) then
1665 cbufPut(AnsiChar(b
[0]));
1669 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1678 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1679 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1680 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1681 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1683 g_Console_Add(s
, show
);
1687 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1691 g_Console_Add(formatstrf(s
, args
), true);
1695 consolewriterLastWasEOL
:= false;
1696 formatstrf(s
, args
, consolewriter
);
1697 if not consolewriterLastWasEOL
then cbufPut(#10);
1702 procedure g_Console_Clear();
1704 //ConsoleHistory := nil;
1709 procedure AddToHistory(L
: AnsiString);
1713 len
:= Length(CommandHistory
);
1716 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1718 SetLength(CommandHistory
, len
+1);
1719 CommandHistory
[len
] := L
;
1722 CmdIndex
:= Length(CommandHistory
);
1725 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1734 if Trim(C
) = '' then
1737 Arr
:= ParseString(C
);
1741 for i
:= 0 to High(Whitelist
) do
1742 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1746 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1753 if Trim(L
) = '' then
1756 conSkipLines
:= 0; // "unscroll"
1758 if L
= 'goobers' then
1763 g_Console_Add('Your memory serves you well.');
1769 g_Console_Add('> '+L
);
1774 Arr
:= ParseString(L
);
1778 if commands
= nil then
1784 for i
:= 0 to High(commands
) do
1786 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1788 if commands
[i
].action
>= 0 then
1790 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1793 if assigned(commands
[i
].procEx
) then
1795 commands
[i
].procEx(@commands
[i
], Arr
);
1798 if assigned(commands
[i
].proc
) then
1800 commands
[i
].proc(Arr
);
1806 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1810 function g_Console_Interactive
: Boolean;
1812 Result
:= gConsoleShow
1815 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = '');
1817 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1819 ASSERT(key
< e_MaxInputKeys
);
1822 gInputBinds
[key
].down
:= ParseAlias(down
);
1823 gInputBinds
[key
].up
:= ParseAlias(up
);
1825 g_Console_WriteGameConfig();
1828 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
1830 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1831 var i
, len
: Integer;
1835 if len
= Length(b
) then
1838 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1846 ASSERT(key
< e_MaxInputKeys
);
1847 result
:= EqualsCommandLists(ParseAlias(down
), gInputBinds
[key
].down
) and EqualsCommandLists(ParseAlias(up
), gInputBinds
[key
].up
)
1850 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1855 if commands
= nil then Exit
;
1857 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1859 if g_Console_MatchBind(i
, down
, up
) then
1870 function g_Console_Action (action
: Integer): Boolean;
1871 var i
, len
: Integer;
1873 ASSERT(action
>= FIRST_ACTION
);
1874 ASSERT(action
<= LAST_ACTION
);
1876 len
:= Length(gPlayerAction
);
1877 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
1881 function BindsAllowed (key
: Integer): Boolean;
1884 if (not g_GUIGrabInput
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
1887 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1888 g_Console_MatchBind(key
, 'showkeyboard') or
1889 g_Console_MatchBind(key
, 'hidekeyboard')
1890 else if gConsoleShow
or (g_ActiveWindow
<> nil) or (gGameSettings
.GameType
= GT_NONE
) then
1891 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
1892 g_Console_MatchBind(key
, 'toggleconsole') or
1893 g_Console_MatchBind(key
, 'showkeyboard') or
1894 g_Console_MatchBind(key
, 'hidekeyboard')
1900 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
1903 if BindsAllowed(key
) then
1906 for i
:= 0 to High(gInputBinds
[key
].down
) do
1907 g_Console_Process(gInputBinds
[key
].down
[i
], True)
1909 for i
:= 0 to High(gInputBinds
[key
].up
) do
1910 g_Console_Process(gInputBinds
[key
].up
[i
], True)
1912 if down
and not menu_toggled
then
1914 menu_toggled
:= False
1917 procedure g_Console_ResetBinds
;
1920 for i
:= 0 to e_MaxInputKeys
- 1 do
1921 g_Console_BindKey(i
, '', '');
1923 g_Console_BindKey(IK_GRAVE
, 'toggleconsole');
1924 g_Console_BindKey(IK_ESCAPE
, 'togglemenu');
1925 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
1926 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
1927 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
1928 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
1929 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
1930 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
1931 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
1932 g_Console_BindKey(IK_E
, '+p1_weapnext', '-p1_weapnext');
1933 g_Console_BindKey(IK_Q
, '+p1_weapprev', '-p1_weapprev');
1934 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
1935 g_Console_BindKey(IK_1
, 'p1_weapon 1');
1936 g_Console_BindKey(IK_2
, 'p1_weapon 2');
1937 g_Console_BindKey(IK_3
, 'p1_weapon 3');
1938 g_Console_BindKey(IK_4
, 'p1_weapon 4');
1939 g_Console_BindKey(IK_5
, 'p1_weapon 5');
1940 g_Console_BindKey(IK_6
, 'p1_weapon 6');
1941 g_Console_BindKey(IK_7
, 'p1_weapon 7');
1942 g_Console_BindKey(IK_8
, 'p1_weapon 8');
1943 g_Console_BindKey(IK_9
, 'p1_weapon 9');
1944 g_Console_BindKey(IK_0
, 'p1_weapon 10');
1945 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
1946 g_Console_BindKey(IK_T
, 'togglechat');
1947 g_Console_BindKey(IK_Y
, 'toggleteamchat');
1948 g_Console_BindKey(IK_F11
, 'screenshot');
1949 g_Console_BindKey(IK_TAB
, '+p1_scores', '-p1_scores');
1950 g_Console_BindKey(IK_PAUSE
, 'pause');
1951 g_Console_BindKey(IK_F1
, 'vote');
1953 (* for i := 0 to e_MaxJoys - 1 do *)
1956 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_LEFT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
1957 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_RIGHT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
1958 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_UP
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
1959 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_DOWN
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
1960 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
1961 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
1962 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
1963 g_Console_BindKey(e_JoyButtonToKey(i
, 1), '+p' + IntToStr(i
mod 2 + 1) + '_weapnext', '-p' + IntToStr(i
mod 2 + 1) + '_weapnext');
1964 g_Console_BindKey(e_JoyButtonToKey(i
, 4), '+p' + IntToStr(i
mod 2 + 1) + '_weapprev', '-p' + IntToStr(i
mod 2 + 1) + '_weapprev');
1965 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
1966 g_Console_BindKey(e_JoyButtonToKey(i
, 10), 'togglemenu');
1969 g_Console_BindKey(VK_ESCAPE
, 'togglemenu');
1970 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
1971 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
1972 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
1973 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
1974 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
1975 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
1976 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
1977 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
1978 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
1979 g_Console_BindKey(VK_NEXT
, '+weapnext', '-weapnext');
1980 g_Console_BindKey(VK_PREV
, '+weapprev', '-weapprev');
1981 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
1982 g_Console_BindKey(VK_0
, 'weapon 1');
1983 g_Console_BindKey(VK_1
, 'weapon 2');
1984 g_Console_BindKey(VK_2
, 'weapon 3');
1985 g_Console_BindKey(VK_3
, 'weapon 4');
1986 g_Console_BindKey(VK_4
, 'weapon 5');
1987 g_Console_BindKey(VK_5
, 'weapon 6');
1988 g_Console_BindKey(VK_6
, 'weapon 7');
1989 g_Console_BindKey(VK_7
, 'weapon 8');
1990 g_Console_BindKey(VK_8
, 'weapon 9');
1991 g_Console_BindKey(VK_9
, 'weapon 10');
1992 g_Console_BindKey(VK_A
, 'weapon 11');
1993 g_Console_BindKey(VK_CHAT
, 'togglechat');
1994 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
1995 g_Console_BindKey(VK_CONSOLE
, 'toggleconsole');
1996 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
1997 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
1998 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
1999 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
2002 procedure g_Console_ReadConfig (filename
: String);
2003 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
2005 e_LogWritefln('g_Console_ReadConfig (1) "%s"', [filename
]);
2006 if e_FindResource(ConfigDirs
, filename
, false) = true then
2008 e_LogWritefln('g_Console_ReadConfig (2) "%s"', [filename
]);
2009 AssignFile(f
, filename
);
2019 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
2021 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
2022 g_Console_Process(s
, True);
2029 procedure g_Console_WriteConfig (filename
: String);
2030 var f
: TextFile
; i
, j
: Integer;
2032 procedure WriteFlag(name
: string; flag
: LongWord);
2034 WriteLn(f
, name
, IfThen(LongBool(gsGameFlags
and flag
), 1, 0));
2038 AssignFile(f
, filename
);
2040 WriteLn(f
, '// ' + configComment
);
2043 WriteLn(f
, 'unbindall');
2044 for i
:= 0 to e_MaxInputKeys
- 1 do
2045 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
2047 Write(f
, 'bind ', e_KeyNames
[i
], ' ', QuoteStr(GetCommandString(gInputBinds
[i
].down
)));
2048 if Length(gInputBinds
[i
].down
) = 0 then
2050 if Length(gInputBinds
[i
].up
) > 0 then
2051 Write(f
, ' ', QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
2056 if gAskLanguage
then
2057 WriteLn(f
, 'g_language ask')
2059 WriteLn(f
, 'g_language ', gLanguage
);
2062 WriteLn(f
, 'sv_name ', QuoteStr(NetServerName
));
2063 WriteLn(f
, 'sv_passwd ', QuoteStr(NetPassword
));
2064 WriteLn(f
, 'sv_maxplrs ', NetMaxClients
);
2065 WriteLn(f
, 'sv_port ', NetPort
);
2066 WriteLn(f
, 'sv_public ', IfThen(NetUseMaster
, 1, 0));
2069 WriteLn(f
, 'g_max_particles ', g_GFX_GetMax());
2070 WriteLn(f
, 'g_max_shells ', g_Shells_GetMax());
2071 WriteLn(f
, 'g_max_gibs ', g_Gibs_GetMax());
2072 WriteLn(f
, 'g_max_corpses ', g_Corpses_GetMax());
2073 WriteLn(f
, 'sv_intertime ', gDefInterTime
);
2075 // gameplay settings
2076 WriteLn(f
, 'g_gamemode ', gsGameMode
);
2077 WriteLn(f
, 'g_scorelimit ', gsGoalLimit
);
2078 WriteLn(f
, 'g_timelimit ', gsTimeLimit
);
2079 WriteLn(f
, 'g_maxlives ', gsMaxLives
);
2080 WriteLn(f
, 'g_item_respawn_time ', gsItemRespawnTime
);
2081 WriteLn(f
, 'g_spawn_invul ', gsSpawnInvul
);
2082 WriteLn(f
, 'g_warmup_time ', gsWarmupTime
);
2084 WriteFlag('g_friendlyfire ', GAME_OPTION_TEAMDAMAGE
);
2085 WriteFlag('g_allow_exit ', GAME_OPTION_ALLOWEXIT
);
2086 WriteFlag('g_allow_monsters ', GAME_OPTION_MONSTERS
);
2087 WriteFlag('g_dm_keys ', GAME_OPTION_DMKEYS
);
2088 WriteFlag('g_weaponstay ', GAME_OPTION_WEAPONSTAY
);
2089 WriteFlag('g_bot_vsmonsters ', GAME_OPTION_BOTVSMONSTER
);
2090 WriteFlag('g_bot_vsplayers ', GAME_OPTION_BOTVSPLAYER
);
2093 with gPlayer1Settings
do
2095 WriteLn(f
, 'p1_name ', QuoteStr(Name
));
2096 WriteLn(f
, 'p1_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2097 WriteLn(f
, 'p1_model ', QuoteStr(Model
));
2099 with gPlayer2Settings
do
2101 WriteLn(f
, 'p2_name ', QuoteStr(Name
));
2102 WriteLn(f
, 'p2_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2103 WriteLn(f
, 'p2_model ', QuoteStr(Model
));
2107 for i
:= 0 to High(commands
) do
2109 if not commands
[i
].cheat
then
2111 if @commands
[i
].procEx
= @boolVarHandler
then
2113 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
2114 WriteLn(f
, commands
[i
].cmd
, ' ', j
)
2116 else if @commands
[i
].procEx
= @intVarHandler
then
2118 WriteLn(f
, commands
[i
].cmd
, ' ', PInteger(commands
[i
].ptr
)^)
2120 else if @commands
[i
].procEx
= @wordVarHandler
then
2122 WriteLn(f
, commands
[i
].cmd
, ' ', PWord(commands
[i
].ptr
)^)
2124 else if @commands
[i
].procEx
= @dwordVarHandler
then
2126 WriteLn(f
, commands
[i
].cmd
, ' ', PCardinal(commands
[i
].ptr
)^)
2128 else if @commands
[i
].procEx
= @singleVarHandler
then
2130 WriteLn(f
, commands
[i
].cmd
, ' ', PVarSingle(commands
[i
].ptr
).val
^:0:6)
2132 else if @commands
[i
].procEx
= @strVarHandler
then
2134 if Length(PAnsiString(commands
[i
].ptr
)^) = 0 then
2135 WriteLn(f
, commands
[i
].cmd
, ' ""')
2137 WriteLn(f
, commands
[i
].cmd
, ' ', QuoteStr(PAnsiString(commands
[i
].ptr
)^))
2142 WriteLn(f
, 'r_maxfps ', gMaxFPS
);
2143 WriteLn(f
, 'r_reset');
2147 procedure g_Console_WriteGameConfig
;
2150 if gParsingBinds
= false then
2152 s
:= e_GetWriteableDir(ConfigDirs
);
2153 g_Console_WriteConfig(e_CatPath(s
, gConfigScript
))
2160 conRegVar('chat_at_top', @ChatTop
, 'draw chat at top border', 'draw chat at top border');
2161 conRegVar('console_height', @ConsoleHeight
, 0.0, 1.0, 'set console size', 'set console size');
2162 conRegVar('console_trans', @ConsoleTrans
, 0.0, 1.0, 'set console transparency', 'set console transparency');
2163 conRegVar('console_step', @ConsoleStep
, 0.0, 1.0, 'set console animation speed', 'set console animation speed');
2166 ConsoleHeight
:= 0.35;
2169 ConsoleHeight
:= 0.5;
2171 ConsoleTrans
:= 0.1;
2172 ConsoleStep
:= 0.07;
2173 conRegVar('d_eres', @debug_e_res
, '', '');
2174 for i
:= 1 to e_MaxJoys
do
2175 conRegVar('joy' + IntToStr(i
) + '_deadzone', @e_JoystickDeadzones
[i
- 1], '', '')