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}
34 FIRST_ACTION
= ACTION_JUMP
;
35 LAST_ACTION
= ACTION_STRAFE
;
37 procedure g_Console_Init
;
38 procedure g_Console_SysInit
;
39 procedure g_Console_Update
;
40 procedure g_Console_Draw (MessagesOnly
: Boolean = False);
41 procedure g_Console_Char (C
: AnsiChar);
42 procedure g_Console_Control (K
: Word);
43 procedure g_Console_Process (L
: AnsiString; quiet
: Boolean=false);
44 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
45 procedure g_Console_Clear
;
46 function g_Console_CommandBlacklisted (C
: AnsiString): Boolean;
47 procedure g_Console_ReadConfig (filename
: String);
48 procedure g_Console_WriteConfig (filename
: String);
49 procedure g_Console_WriteGameConfig
;
51 function g_Console_Interactive
: Boolean;
52 function g_Console_Action (action
: Integer): Boolean;
53 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
54 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
55 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = ''; rep
: Boolean = False);
56 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
57 procedure g_Console_ProcessBindRepeat (key
: Integer);
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 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
64 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
65 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
66 procedure conRegVar (const conname
: AnsiString; pvar
: PWord; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
67 procedure conRegVar (const conname
: AnsiString; pvar
: PCardinal; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
68 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
70 // <0: no arg; 0/1: true/false
71 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
73 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
74 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
78 defaultConfigScript
= 'dfserver.cfg';
80 defaultConfigScript
= 'dfconfig.cfg';
84 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
85 gChatShow
: Boolean = false;
86 gChatTeam
: Boolean = false;
87 gAllowConsoleMessages
: Boolean = true;
88 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
89 gParsingBinds
: Boolean = true; // íå ïåðåñîõðàíÿòü êîíôèã âî âðåìÿ ïàðñèíãà
90 gPlayerAction
: Array [0..1, 0..LAST_ACTION
] of Boolean; // [player, action]
91 gConfigScript
: string = defaultConfigScript
;
96 g_textures
, g_main
, e_graphics
, e_input
, g_game
, g_gfx
, g_player
, g_items
,
97 SysUtils
, g_basic
, g_options
, Math
, g_touch
, e_res
,
98 g_menu
, g_gui
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
, g_weapons
,
102 autoexecScript
= 'autoexec.cfg';
103 configComment
= 'generated by doom2d, do not modify';
106 PCommand
= ^TCommand
;
108 TCmdProc
= procedure (p
: SSArray
);
109 TCmdProcEx
= procedure (me
: PCommand
; p
: SSArray
);
117 ptr
: Pointer; // various data
118 msg
: AnsiString; // message for var changes
120 action
: Integer; // >= 0 for action commands
121 player
: Integer; // used for action commands
132 MaxScriptRecursion
= 16;
134 DEBUG_STRING
= 'DEBUG MODE';
138 RecursionDepth
: Word = 0;
139 RecursionLimitHit
: Boolean = False;
141 ConsoleHeight
: Single;
142 Cons_Shown
: Boolean; // draw console
143 InputReady
: Boolean; // allow text input in console/chat
146 //ConsoleHistory: SSArray;
147 CommandHistory
: SSArray
;
149 commands
: Array of TCommand
= nil;
150 Aliases
: Array of TAlias
= nil;
152 conSkipLines
: Integer = 0;
153 MsgArray
: Array [0..4] of record
158 gInputBinds
: Array [0..e_MaxInputKeys
- 1] of record
162 menu_toggled
: BOOLEAN; (* hack for menu controls *)
165 ConsoleTrans
: Single;
166 ConsoleStdIn
: Boolean;
169 procedure g_Console_Switch
;
171 Cons_Y
:= Min(0, Max(Cons_Y
, -Floor(gScreenHeight
* ConsoleHeight
)));
172 if Cons_Shown
= False then
173 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
175 gConsoleShow
:= not gConsoleShow
;
178 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
181 procedure g_Console_Chat_Switch (Team
: Boolean = False);
183 if not g_Game_IsNet
then Exit
;
184 Cons_Y
:= Min(0, Max(Cons_Y
, -Floor(gScreenHeight
* ConsoleHeight
)));
185 if Cons_Shown
= False then
186 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
187 gConsoleShow
:= False;
188 gChatShow
:= not gChatShow
;
194 g_Touch_ShowKeyboard(gConsoleShow
or gChatShow
);
197 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
198 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
207 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
208 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
209 if (pos
> slen
) then exit
;
210 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
212 while (pos
<= slen
) do
214 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
215 res
:= res
*10+Byte(s
[pos
])-48;
218 if (pos
<= slen
) then
221 if (s
[pos
] <> '.') then exit
;
223 while (pos
<= slen
) do
225 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
227 res
+= frac
*(Byte(s
[pos
])-48);
231 if (pos
<= slen
) then exit
; // oops
236 // ////////////////////////////////////////////////////////////////////////// //
237 // <0: no arg; 0/1: true/false; 666: toggle
238 function conGetBoolArg (p
: SSArray
; idx
: Integer): Integer;
240 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
242 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
243 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
244 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
245 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
249 procedure boolVarHandler (me
: PCommand
; p
: SSArray
);
250 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
254 if (Length(p
) > 2) then
256 conwritefln('too many arguments to ''%s''', [p
[0]]);
261 case conGetBoolArg(p
, 1) of
263 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
264 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
265 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
268 g_Console_WriteGameConfig();
269 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
270 if flag
then conwritefln('%s tan', [msg
]) else conwritefln('%s ona', [msg
]);
274 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
278 procedure intVarHandler (me
: PCommand
; p
: SSArray
);
282 if (Length(p
) <> 2) then
284 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
289 old
:= PInteger(me
.ptr
)^;
290 PInteger(me
.ptr
)^ := StrToInt(p
[1]);
291 if PInteger(me
.ptr
)^ <> old
then
292 g_Console_WriteGameConfig();
294 conwritefln('invalid integer value: "%s"', [p
[1]]);
300 procedure wordVarHandler (me
: PCommand
; p
: SSArray
);
304 if (Length(p
) <> 2) then
306 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
311 old
:= PWord(me
.ptr
)^;
312 PWord(me
.ptr
)^ := min($FFFF, StrToDWord(p
[1]));
313 if PWord(me
.ptr
)^ <> old
then
314 g_Console_WriteGameConfig();
316 conwritefln('invalid word value: "%s"', [p
[1]]);
322 procedure dwordVarHandler (me
: PCommand
; p
: SSArray
);
326 if (Length(p
) <> 2) then
328 conwritefln('%s %d', [me
.cmd
, PInteger(me
.ptr
)^]);
333 old
:= PCardinal(me
.ptr
)^;
334 PCardinal(me
.ptr
)^ := StrToDWord(p
[1]);
335 if PCardinal(me
.ptr
)^ <> old
then
336 g_Console_WriteGameConfig();
338 conwritefln('invalid dword value: "%s"', [p
[1]]);
344 procedure strVarHandler (me
: PCommand
; p
: SSArray
);
348 if (Length(p
) <> 2) then
350 conwritefln('%s %s', [me
.cmd
, QuoteStr(PAnsiString(me
.ptr
)^)]);
354 old
:= PAnsiString(me
.ptr
)^;
355 PAnsiString(me
.ptr
)^ := p
[1];
356 if PAnsiString(me
.ptr
)^ <> old
then
357 g_Console_WriteGameConfig();
362 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
367 f
:= Length(commands
);
368 SetLength(commands
, f
+1);
370 cp
.cmd
:= LowerCase(conname
);
372 cp
.procEx
:= boolVarHandler
;
374 cp
.hidden
:= ahidden
;
383 procedure conRegVar (const conname
: AnsiString; pvar
: PInteger; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
388 f
:= Length(commands
);
389 SetLength(commands
, f
+1);
391 cp
.cmd
:= LowerCase(conname
);
393 cp
.procEx
:= intVarHandler
;
395 cp
.hidden
:= ahidden
;
404 procedure conRegVar (const conname
: AnsiString; pvar
: PWord; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
409 f
:= Length(commands
);
410 SetLength(commands
, f
+1);
412 cp
.cmd
:= LowerCase(conname
);
414 cp
.procEx
:= wordVarHandler
;
416 cp
.hidden
:= ahidden
;
425 procedure conRegVar (const conname
: AnsiString; pvar
: PCardinal; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
430 f
:= Length(commands
);
431 SetLength(commands
, f
+1);
433 cp
.cmd
:= LowerCase(conname
);
435 cp
.procEx
:= dwordVarHandler
;
437 cp
.hidden
:= ahidden
;
446 procedure conRegVar (const conname
: AnsiString; pvar
: PAnsiString; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
451 f
:= Length(commands
);
452 SetLength(commands
, f
+1);
454 cp
.cmd
:= LowerCase(conname
);
456 cp
.procEx
:= strVarHandler
;
458 cp
.hidden
:= ahidden
;
466 // ////////////////////////////////////////////////////////////////////////// //
468 PVarSingle
= ^TVarSingle
;
471 min
, max
, def
: Single; // default will be starting value
475 procedure singleVarHandler (me
: PCommand
; p
: SSArray
);
481 if (Length(p
) > 2) then
483 conwritefln('too many arguments to ''%s''', [me
.cmd
]);
486 pv
:= PVarSingle(me
.ptr
);
488 if (Length(p
) = 2) then
490 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
491 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
492 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
493 (CompareText(p
[1], 'ona') = 0) then
499 if not conParseFloat(nv
, p
[1]) then
501 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me
.cmd
, p
[1]]);
504 if (nv
< pv
.min
) then nv
:= pv
.min
;
505 if (nv
> pv
.max
) then nv
:= pv
.max
;
509 if pv
.val
^ <> old
then
510 g_Console_WriteGameConfig();
512 if (Length(msg
) = 0) then msg
:= me
.cmd
else msg
+= ':';
513 conwritefln('%s %s', [msg
, pv
.val
^]);
517 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false; ahidden
: Boolean=false); overload
;
523 GetMem(pv
, sizeof(TVarSingle
));
528 f
:= Length(commands
);
529 SetLength(commands
, f
+1);
531 cp
.cmd
:= LowerCase(conname
);
533 cp
.procEx
:= singleVarHandler
;
535 cp
.hidden
:= ahidden
;
544 // ////////////////////////////////////////////////////////////////////////// //
545 function GetStrACmd(var Str
: AnsiString): AnsiString;
550 for a
:= 1 to Length(Str
) do
551 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
553 Result
:= Copy(Str
, 1, a
);
560 function ParseAlias(Str
: AnsiString): SSArray
;
571 SetLength(Result
, Length(Result
)+1);
572 Result
[High(Result
)] := GetStrACmd(Str
);
576 procedure ConsoleCommands(p
: SSArray
);
582 cmd
:= LowerCase(p
[0]);
585 if cmd
= 'clear' then
587 //ConsoleHistory := nil;
591 for a
:= 0 to High(MsgArray
) do
599 if cmd
= 'clearhistory' then
600 CommandHistory
:= nil;
602 if cmd
= 'showhistory' then
603 if CommandHistory
<> nil then
606 for a
:= 0 to High(CommandHistory
) do
607 g_Console_Add(' '+CommandHistory
[a
]);
610 if cmd
= 'commands' then
613 g_Console_Add('commands list:');
614 for a
:= High(commands
) downto 0 do
616 if (Length(commands
[a
].help
) > 0) then
618 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
622 g_Console_Add(' '+commands
[a
].cmd
);
628 g_Console_Add(TimeToStr(Now
), True);
631 g_Console_Add(DateToStr(Now
), True);
634 if Length(p
) > 1 then
636 if p
[1] = 'ololo' then
641 for a
:= 1 to High(p
) do
643 g_Console_Add(b_Text_Format(s
), True);
652 if ConsoleHistory <> nil then
654 if Length(P) > 1 then
657 s := GameDir+'/console.txt';
662 if IOResult <> 0 then
664 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
669 for a := 0 to High(ConsoleHistory) do
670 WriteLn(F, ConsoleHistory[a]);
673 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
682 if Length(p
) = 2 then
683 g_Console_ReadConfig(p
[1])
685 g_Console_Add('exec <script file>');
688 if cmd
= 'writeconfig' then
690 // writeconfig <filename>
691 if Length(p
) = 2 then
693 s
:= e_GetWriteableDir(ConfigDirs
);
694 g_Console_WriteConfig(e_CatPath(s
, p
[1]))
698 g_Console_Add('writeconfig <file>')
702 if (cmd
= 'ver') or (cmd
= 'version') then
704 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION
);
705 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER
]);
706 conwritefln('Build date: %s at %s', [GAME_BUILDDATE
, GAME_BUILDTIME
]);
709 if cmd
= 'alias' then
711 // alias [alias_name] [commands]
712 if Length(p
) > 1 then
714 for a
:= 0 to High(Aliases
) do
715 if Aliases
[a
].name
= p
[1] then
717 if Length(p
) > 2 then
718 Aliases
[a
].commands
:= ParseAlias(p
[2])
720 for b
:= 0 to High(Aliases
[a
].commands
) do
721 g_Console_Add(Aliases
[a
].commands
[b
]);
724 SetLength(Aliases
, Length(Aliases
)+1);
726 Aliases
[a
].name
:= p
[1];
727 if Length(p
) > 2 then
728 Aliases
[a
].commands
:= ParseAlias(p
[2])
730 for b
:= 0 to High(Aliases
[a
].commands
) do
731 g_Console_Add(Aliases
[a
].commands
[b
]);
733 for a
:= 0 to High(Aliases
) do
734 if Aliases
[a
].commands
<> nil then
735 g_Console_Add(Aliases
[a
].name
);
741 if Length(p
) > 1 then
743 if Aliases
= nil then
745 for a
:= 0 to High(Aliases
) do
746 if Aliases
[a
].name
= p
[1] then
748 if Aliases
[a
].commands
<> nil then
750 // with this system proper endless loop detection seems either impossible
751 // or very dirty to implement, so let's have this instead
752 // prevents endless loops
753 for b
:= 0 to High(Aliases
[a
].commands
) do
756 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
757 if not RecursionLimitHit
then
758 g_Console_Process(Aliases
[a
].commands
[b
], True);
761 if (RecursionDepth
= 0) and RecursionLimitHit
then
763 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
764 RecursionLimitHit
:= False;
771 g_Console_Add('call <alias name>');
775 procedure WhitelistCommand(cmd
: AnsiString);
779 SetLength(Whitelist
, Length(Whitelist
)+1);
780 a
:= High(Whitelist
);
781 Whitelist
[a
] := LowerCase(cmd
);
784 procedure segfault (p
: SSArray
);
791 function GetCommandString (p
: SSArray
): AnsiString;
795 if Length(p
) >= 1 then
798 for i
:= 1 to High(p
) do
799 result
:= result
+ '; ' + p
[i
]
803 function QuoteStr(str
: String): String;
805 if Pos(' ', str
) > 0 then
806 Result
:= '"' + str
+ '"'
811 procedure BindCommands (p
: SSArray
);
812 var cmd
, key
: AnsiString; i
: Integer;
814 cmd
:= LowerCase(p
[0]);
817 // bind <key> [down [up]]
818 if (Length(p
) >= 2) and (Length(p
) <= 4) then
821 key
:= LowerCase(p
[1]);
822 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
823 if i
< e_MaxInputKeys
then
825 if Length(p
) = 2 then
826 g_Console_Add(QuoteStr(e_KeyNames
[i
]) + ' = ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)))
827 else if Length(p
) = 3 then
828 g_Console_BindKey(i
, p
[2], '')
830 g_Console_BindKey(i
, p
[2], p
[3])
833 g_Console_Add('bind: "' + p
[1] + '" is not a key')
837 g_Console_Add('bind <key> <down action> [up action]')
841 if Length(p
) = 2 then
843 key
:= LowerCase(p
[1]);
845 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
846 if i
< e_MaxInputKeys
then
847 gInputBinds
[i
].rep
:= True
849 g_Console_Add('bindrep: "' + p
[1] + '" is not a key')
852 g_Console_Add('bindrep <key>');
855 if Length(p
) = 2 then
857 key
:= LowerCase(p
[1]);
859 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
860 if i
< e_MaxInputKeys
then
861 gInputBinds
[i
].rep
:= False
863 g_Console_Add('bindunrep: "' + p
[1] + '" is not a key')
866 g_Console_Add('bindunrep <key>');
868 for i
:= 0 to e_MaxInputKeys
- 1 do
869 if (gInputBinds
[i
].down
<> nil) or (gInputBinds
[i
].up
<> nil) then
870 g_Console_Add(e_KeyNames
[i
] + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].down
)) + ' ' + QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
873 if Length(p
) = 2 then
875 key
:= LowerCase(p
[1]);
877 while (i
< e_MaxInputKeys
) and (key
<> LowerCase(e_KeyNames
[i
])) do inc(i
);
878 if i
< e_MaxInputKeys
then
879 g_Console_BindKey(i
, '')
881 g_Console_Add('unbind: "' + p
[1] + '" is not a key')
884 g_Console_Add('unbind <key>');
886 for i
:= 0 to e_MaxInputKeys
- 1 do
887 g_Console_BindKey(i
, '');
889 g_Touch_ShowKeyboard(True);
891 g_Touch_ShowKeyboard(False);
896 else if gChatShow
then
897 g_Console_Chat_Switch
905 g_Console_Chat_Switch
;
907 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
908 g_Console_Chat_Switch(True);
912 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
917 SetLength(commands
, Length(commands
)+1);
920 cp
.cmd
:= LowerCase(cmd
);
924 cp
.hidden
:= ahidden
;
932 procedure AddAction (cmd
: AnsiString; action
: Integer; help
: AnsiString = ''; hidden
: Boolean = False; cheat
: Boolean = False);
934 PrefixList
: array [0..1] of AnsiString = ('+', '-');
935 PlayerList
: array [0..1] of Integer = (1, 2);
940 procedure NewAction (cmd
: AnsiString; player
: Integer);
943 SetLength(commands
, Length(commands
) + 1);
944 cp
:= @commands
[High(commands
)];
945 cp
.cmd
:= LowerCase(cmd
);
958 ASSERT(action
>= FIRST_ACTION
);
959 ASSERT(action
<= LAST_ACTION
);
960 for s
in PrefixList
do
962 NewAction(s
+ cmd
, 0);
963 for i
in PlayerList
do
964 NewAction(s
+ 'p' + IntToStr(i
) + '_' + cmd
, i
- 1)
973 gConsoleShow
:= True;
976 KEv
:= PollKeyEvent();
979 K
:= GetKeyEventChar(TranslateKeyEvent(GetKeyEvent()));
982 #8: g_Console_Control(IK_BACKSPACE
);
983 #10, #13: g_Console_Control(IK_RETURN
);
984 #32..#126: g_Console_Char(K
);
985 // arrow keys and DEL all return 0 for some reason, so fuck em
990 procedure g_Console_SysInit
;
993 Cons_Y
:= -Floor(gScreenHeight
* ConsoleHeight
);
994 gConsoleShow
:= False;
1000 for a
:= 0 to High(MsgArray
) do
1007 AddCommand('segfault', segfault
, 'make segfault');
1009 AddCommand('quit', SystemCommands
);
1010 AddCommand('exit', SystemCommands
);
1011 AddCommand('r_reset', SystemCommands
);
1012 AddCommand('r_maxfps', SystemCommands
);
1013 AddCommand('g_language', SystemCommands
);
1015 AddCommand('bind', BindCommands
);
1016 AddCommand('bindrep', BindCommands
);
1017 AddCommand('bindunrep', BindCommands
);
1018 AddCommand('bindlist', BindCommands
);
1019 AddCommand('unbind', BindCommands
);
1020 AddCommand('unbindall', BindCommands
);
1021 AddCommand('showkeyboard', BindCommands
);
1022 AddCommand('hidekeyboard', BindCommands
);
1023 AddCommand('togglemenu', BindCommands
);
1024 AddCommand('toggleconsole', BindCommands
);
1025 AddCommand('togglechat', BindCommands
);
1026 AddCommand('toggleteamchat', BindCommands
);
1028 AddCommand('clear', ConsoleCommands
, 'clear console');
1029 AddCommand('clearhistory', ConsoleCommands
);
1030 AddCommand('showhistory', ConsoleCommands
);
1031 AddCommand('commands', ConsoleCommands
);
1032 AddCommand('time', ConsoleCommands
);
1033 AddCommand('date', ConsoleCommands
);
1034 AddCommand('echo', ConsoleCommands
);
1035 AddCommand('dump', ConsoleCommands
);
1036 AddCommand('exec', ConsoleCommands
);
1037 AddCommand('writeconfig', ConsoleCommands
);
1038 AddCommand('alias', ConsoleCommands
);
1039 AddCommand('call', ConsoleCommands
);
1040 AddCommand('ver', ConsoleCommands
);
1041 AddCommand('version', ConsoleCommands
);
1043 AddCommand('d_window', DebugCommands
);
1044 AddCommand('d_sounds', DebugCommands
);
1045 AddCommand('d_frames', DebugCommands
);
1046 AddCommand('d_winmsg', DebugCommands
);
1047 AddCommand('d_monoff', DebugCommands
);
1048 AddCommand('d_botoff', DebugCommands
);
1049 AddCommand('d_monster', DebugCommands
);
1050 AddCommand('d_health', DebugCommands
);
1051 AddCommand('d_player', DebugCommands
);
1052 AddCommand('d_joy', DebugCommands
);
1053 AddCommand('d_mem', DebugCommands
);
1055 AddCommand('p1_name', PlayerSettingsCVars
);
1056 AddCommand('p2_name', PlayerSettingsCVars
);
1057 AddCommand('p1_color', PlayerSettingsCVars
);
1058 AddCommand('p2_color', PlayerSettingsCVars
);
1059 AddCommand('p1_model', PlayerSettingsCVars
);
1060 AddCommand('p2_model', PlayerSettingsCVars
);
1061 AddCommand('p1_team', PlayerSettingsCVars
);
1062 AddCommand('p2_team', PlayerSettingsCVars
);
1063 AddCommand('p1_autoswitch', PlayerSettingsCVars
);
1064 AddCommand('p2_autoswitch', PlayerSettingsCVars
);
1065 AddCommand('p1_switch_empty', PlayerSettingsCVars
);
1066 AddCommand('p2_switch_empty', PlayerSettingsCVars
);
1067 AddCommand('p1_skip_fist', PlayerSettingsCVars
);
1068 AddCommand('p2_skip_fist', PlayerSettingsCVars
);
1069 AddCommand('p1_priority_kastet', PlayerSettingsCVars
);
1070 AddCommand('p2_priority_kastet', PlayerSettingsCVars
);
1071 AddCommand('p1_priority_saw', PlayerSettingsCVars
);
1072 AddCommand('p2_priority_saw', PlayerSettingsCVars
);
1073 AddCommand('p1_priority_pistol', PlayerSettingsCVars
);
1074 AddCommand('p2_priority_pistol', PlayerSettingsCVars
);
1075 AddCommand('p1_priority_shotgun1', PlayerSettingsCVars
);
1076 AddCommand('p2_priority_shotgun1', PlayerSettingsCVars
);
1077 AddCommand('p1_priority_shotgun2', PlayerSettingsCVars
);
1078 AddCommand('p2_priority_shotgun2', PlayerSettingsCVars
);
1079 AddCommand('p1_priority_chaingun', PlayerSettingsCVars
);
1080 AddCommand('p2_priority_chaingun', PlayerSettingsCVars
);
1081 AddCommand('p1_priority_rocketlauncher', PlayerSettingsCVars
);
1082 AddCommand('p2_priority_rocketlauncher', PlayerSettingsCVars
);
1083 AddCommand('p1_priority_plasma', PlayerSettingsCVars
);
1084 AddCommand('p2_priority_plasma', PlayerSettingsCVars
);
1085 AddCommand('p1_priority_bfg', PlayerSettingsCVars
);
1086 AddCommand('p2_priority_bfg', PlayerSettingsCVars
);
1087 AddCommand('p1_priority_super', PlayerSettingsCVars
);
1088 AddCommand('p2_priority_super', PlayerSettingsCVars
);
1089 AddCommand('p1_priority_flamethrower', PlayerSettingsCVars
);
1090 AddCommand('p2_priority_flamethrower', PlayerSettingsCVars
);
1091 AddCommand('p1_priority_berserk', PlayerSettingsCVars
);
1092 AddCommand('p2_priority_berserk', PlayerSettingsCVars
);
1094 AddCommand('g_max_particles', GameCVars
);
1095 AddCommand('g_max_shells', GameCVars
);
1096 AddCommand('g_max_gibs', GameCVars
);
1097 AddCommand('g_max_corpses', GameCVars
);
1098 AddCommand('g_force_model', GameCVars
);
1099 AddCommand('g_force_model_name', GameCVars
);
1100 AddCommand('g_gamemode', GameCVars
);
1101 AddCommand('g_friendlyfire', GameCVars
);
1102 AddCommand('g_friendly_hit_trace', GameCVars
);
1103 AddCommand('g_friendly_hit_projectile', GameCVars
);
1104 AddCommand('g_friendly_absorb_damage', GameCVars
);
1105 AddCommand('g_weaponstay', GameCVars
);
1106 AddCommand('g_allow_exit', GameCVars
);
1107 AddCommand('g_dm_keys', GameCVars
);
1108 AddCommand('g_allow_monsters', GameCVars
);
1109 AddCommand('g_allow_dropflag', GameCVars
);
1110 AddCommand('g_throw_flag', GameCVars
);
1111 AddCommand('g_bot_vsmonsters', GameCVars
);
1112 AddCommand('g_bot_vsplayers', GameCVars
);
1113 AddCommand('g_max_bots', GameCVars
); // intentionally not whitelisted
1114 AddCommand('g_scorelimit', GameCVars
);
1115 AddCommand('g_timelimit', GameCVars
);
1116 AddCommand('g_maxlives', GameCVars
);
1117 AddCommand('g_warmup_time', GameCVars
);
1118 AddCommand('g_spawn_invul', GameCVars
);
1119 AddCommand('g_item_respawn_time', GameCVars
);
1120 AddCommand('g_rulez_randomize_respawn', GameCVars
);
1121 AddCommand('g_rulez_time_multiplier', GameCVars
);
1122 AddCommand('sv_intertime', GameCVars
);
1124 AddCommand('sv_name', NetServerCVars
);
1125 AddCommand('sv_passwd', NetServerCVars
);
1126 AddCommand('sv_maxplrs', NetServerCVars
);
1127 AddCommand('sv_public', NetServerCVars
);
1128 AddCommand('sv_port', NetServerCVars
);
1130 AddCommand('pause', GameCommands
);
1131 AddCommand('endgame', GameCommands
);
1132 AddCommand('restart', GameCommands
);
1133 AddCommand('addbot', GameCommands
);
1134 AddCommand('bot_add', GameCommands
);
1135 AddCommand('bot_addlist', GameCommands
);
1136 AddCommand('bot_addred', GameCommands
);
1137 AddCommand('bot_addblue', GameCommands
);
1138 AddCommand('bot_removeall', GameCommands
);
1139 AddCommand('chat', GameCommands
);
1140 AddCommand('teamchat', GameCommands
);
1141 AddCommand('announce', GameCommands
);
1142 AddCommand('an', GameCommands
);
1143 AddCommand('game', GameCommands
);
1144 AddCommand('host', GameCommands
);
1145 AddCommand('map', GameCommands
);
1146 AddCommand('nextmap', GameCommands
);
1147 AddCommand('endmap', GameCommands
);
1148 AddCommand('goodbye', GameCommands
);
1149 AddCommand('suicide', GameCommands
);
1150 AddCommand('spectate', GameCommands
);
1151 AddCommand('ready', GameCommands
);
1152 AddCommand('kick', GameCommands
);
1153 AddCommand('kick_id', GameCommands
);
1154 AddCommand('kick_pid', GameCommands
);
1155 AddCommand('ban', GameCommands
);
1156 AddCommand('ban_id', GameCommands
);
1157 AddCommand('ban_pid', GameCommands
);
1158 AddCommand('permban', GameCommands
);
1159 AddCommand('permban_id', GameCommands
);
1160 AddCommand('permban_pid', GameCommands
);
1161 AddCommand('permban_ip', GameCommands
);
1162 AddCommand('unban', GameCommands
);
1163 AddCommand('connect', GameCommands
);
1164 AddCommand('disconnect', GameCommands
);
1165 AddCommand('reconnect', GameCommands
);
1166 AddCommand('say', GameCommands
);
1167 AddCommand('tell', GameCommands
);
1168 AddCommand('centerprint', GameCommands
);
1169 AddCommand('overtime', GameCommands
);
1170 AddCommand('rcon_password', GameCommands
);
1171 AddCommand('rcon', GameCommands
);
1172 AddCommand('callvote', GameCommands
);
1173 AddCommand('vote', GameCommands
);
1174 AddCommand('clientlist', GameCommands
);
1175 AddCommand('event', GameCommands
);
1176 AddCommand('screenshot', GameCommands
);
1177 AddCommand('weapnext', GameCommands
);
1178 AddCommand('weapprev', GameCommands
);
1179 AddCommand('weapon', GameCommands
);
1180 AddCommand('dropflag', GameCommands
);
1181 AddCommand('p1_weapnext', GameCommands
);
1182 AddCommand('p1_weapprev', GameCommands
);
1183 AddCommand('p1_weapon', GameCommands
);
1184 AddCommand('p1_weapbest', GameCommands
);
1185 AddCommand('p1_dropflag', GameCommands
);
1186 AddCommand('p2_weapnext', GameCommands
);
1187 AddCommand('p2_weapprev', GameCommands
);
1188 AddCommand('p2_weapon', GameCommands
);
1189 AddCommand('p2_weapbest', GameCommands
);
1190 AddCommand('p2_dropflag', GameCommands
);
1192 AddCommand('god', GameCheats
);
1193 AddCommand('notarget', GameCheats
);
1194 AddCommand('give', GameCheats
); // "exit" too ;-)
1195 AddCommand('open', GameCheats
);
1196 AddCommand('fly', GameCheats
);
1197 AddCommand('noclip', GameCheats
);
1198 AddCommand('speedy', GameCheats
);
1199 AddCommand('jumpy', GameCheats
);
1200 AddCommand('noreload', GameCheats
);
1201 AddCommand('aimline', GameCheats
);
1202 AddCommand('automap', GameCheats
);
1204 AddAction('jump', ACTION_JUMP
);
1205 AddAction('moveleft', ACTION_MOVELEFT
);
1206 AddAction('moveright', ACTION_MOVERIGHT
);
1207 AddAction('lookup', ACTION_LOOKUP
);
1208 AddAction('lookdown', ACTION_LOOKDOWN
);
1209 AddAction('attack', ACTION_ATTACK
);
1210 AddAction('scores', ACTION_SCORES
);
1211 AddAction('activate', ACTION_ACTIVATE
);
1212 AddAction('strafe', ACTION_STRAFE
);
1214 WhitelistCommand('say');
1215 WhitelistCommand('tell');
1216 WhitelistCommand('overtime');
1217 WhitelistCommand('ready');
1218 WhitelistCommand('map');
1219 WhitelistCommand('nextmap');
1220 WhitelistCommand('endmap');
1221 WhitelistCommand('restart');
1222 WhitelistCommand('kick');
1223 WhitelistCommand('kick_pid');
1224 WhitelistCommand('ban');
1225 WhitelistCommand('ban_pid');
1226 WhitelistCommand('centerprint');
1228 WhitelistCommand('addbot');
1229 WhitelistCommand('bot_add');
1230 WhitelistCommand('bot_addred');
1231 WhitelistCommand('bot_addblue');
1232 WhitelistCommand('bot_removeall');
1234 WhitelistCommand('g_gamemode');
1235 WhitelistCommand('g_friendlyfire');
1236 WhitelistCommand('g_friendly_hit_trace');
1237 WhitelistCommand('g_friendly_hit_projectile');
1238 WhitelistCommand('g_friendly_absorb_damage');
1239 WhitelistCommand('g_weaponstay');
1240 WhitelistCommand('g_allow_exit');
1241 WhitelistCommand('g_dm_keys');
1242 WhitelistCommand('g_allow_monsters');
1243 WhitelistCommand('g_bot_vsmonsters');
1244 WhitelistCommand('g_bot_vsplayers');
1245 WhitelistCommand('g_scorelimit');
1246 WhitelistCommand('g_timelimit');
1247 WhitelistCommand('g_maxlives');
1248 WhitelistCommand('g_warmup_time');
1249 WhitelistCommand('g_spawn_invul');
1250 WhitelistCommand('g_item_respawn_time');
1251 WhitelistCommand('g_rulez_randomize_respawn');
1252 WhitelistCommand('g_rulez_time_multiplier');
1254 g_Console_ResetBinds
;
1255 g_Console_ReadConfig(gConfigScript
);
1256 g_Console_ReadConfig(autoexecScript
);
1257 gParsingBinds
:= False;
1260 procedure g_Console_Init
;
1262 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
1263 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
1266 if ConsoleStdIn
then
1269 conbufStdOutRawMode
:= true;
1274 procedure g_Console_Update
;
1276 a
, b
, Step
: Integer;
1279 if ConsoleStdIn
then
1285 Step
:= Max(1, Round(Floor(gScreenHeight
* ConsoleHeight
) * ConsoleStep
));
1286 if gConsoleShow
then
1288 (* Open animation *)
1289 Cons_Y
:= Min(Cons_Y
+ Step
, 0);
1294 (* Close animation *)
1295 Cons_Y
:= Max(Cons_Y
- Step
, -Floor(gScreenHeight
* ConsoleHeight
));
1296 Cons_Shown
:= Cons_Y
> -Floor(gScreenHeight
* ConsoleHeight
);
1305 while a
<= High(MsgArray
) do
1307 if MsgArray
[a
].Time
> 0 then
1309 if MsgArray
[a
].Time
= 1 then
1311 if a
< High(MsgArray
) then
1313 for b
:= a
to High(MsgArray
)-1 do
1314 MsgArray
[b
] := MsgArray
[b
+1];
1316 MsgArray
[High(MsgArray
)].Time
:= 0;
1322 Dec(MsgArray
[a
].Time
);
1330 procedure drawConsoleText ();
1332 CWidth
, CHeight
: Byte;
1337 procedure putLine (sp
, ep
: LongWord);
1346 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1347 if wdt
+cw
> gScreenWidth
-8 then break
;
1348 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1352 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
1353 // now print our part
1361 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
1362 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
1375 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1376 ty
:= Floor(gScreenHeight
* ConsoleHeight
) - 4 - 2 * CHeight
- Abs(Cons_Y
);
1377 skip
:= conSkipLines
;
1378 cbufLastLine(sp
, ep
);
1381 if ty
+CHeight
<= 0 then break
;
1382 until not cbufLineUp(sp
, ep
);
1385 procedure g_Console_Draw(MessagesOnly
: Boolean = False);
1387 CWidth
, CHeight
: Byte;
1389 a
, b
, offset_y
: Integer;
1391 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
1393 if ChatTop
and gChatShow
then
1398 for a
:= 0 to High(MsgArray
) do
1399 if MsgArray
[a
].Time
> 0 then
1400 e_TextureFontPrintFmt(0, offset_y
+ CHeight
* a
, MsgArray
[a
].Msg
, gStdFont
, True);
1402 if MessagesOnly
then Exit
;
1409 offset_y
:= gScreenHeight
- CHeight
- 1;
1412 e_TextureFontPrintEx(0, offset_y
, 'say team> ' + Line
, gStdFont
, 255, 255, 255, 1, True);
1413 e_TextureFontPrintEx((CPos
+ 9) * CWidth
, offset_y
, '_', gStdFont
, 255, 255, 255, 1, True);
1417 e_TextureFontPrintEx(0, offset_y
, 'say> ' + Line
, gStdFont
, 255, 255, 255, 1, True);
1418 e_TextureFontPrintEx((CPos
+ 4) * CWidth
, offset_y
, '_', gStdFont
, 255, 255, 255, 1, True);
1422 if not Cons_Shown
then
1427 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
1428 a
:= (gScreenWidth
- 2*mfW
) div 2;
1429 b
:= Cons_Y
+ (Floor(gScreenHeight
* ConsoleHeight
) - 2 * mfH
) div 2;
1430 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
1431 _RGB(128, 0, 0), 2.0);
1434 e_DrawSize(ID
, 0, Cons_Y
, Round(ConsoleTrans
* 255), False, False, gScreenWidth
, Floor(gScreenHeight
* ConsoleHeight
));
1435 e_TextureFontPrint(0, Cons_Y
+ Floor(gScreenHeight
* ConsoleHeight
) - CHeight
- 4, '> ' + Line
, gStdFont
);
1439 if ConsoleHistory <> nil then
1443 if Length(ConsoleHistory) > (Floor(gScreenHeight * ConsoleHeight) div CHeight) - 1 then
1444 b := Length(ConsoleHistory) - (Floor(gScreenHeight * ConsoleHeight) div CHeight) + 1;
1446 b := Max(b-Offset, 0);
1447 d := Max(High(ConsoleHistory)-Offset, 0);
1450 for a := d downto b do
1452 e_TextureFontPrintFmt(0, Floor(gScreenHeight * ConsoleHeight) - 4 - c * CHeight - Abs(Cons_Y), ConsoleHistory[a], gStdFont, True);
1458 e_TextureFontPrint((CPos
+ 1) * CWidth
, Cons_Y
+ Floor(gScreenHeight
* ConsoleHeight
) - 21, '_', gStdFont
);
1461 procedure g_Console_Char(C
: AnsiChar);
1463 if InputReady
and (gConsoleShow
or gChatShow
) then
1465 Insert(C
, Line
, CPos
);
1472 tcomplist
: array of AnsiString = nil;
1473 tcompidx
: array of Integer = nil;
1475 procedure Complete ();
1479 ll
, lpfx
, cmd
: AnsiString;
1481 if (Length(Line
) = 0) then
1484 for i
:= 0 to High(commands
) do
1486 // hidden commands are hidden when cheats aren't enabled
1487 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1488 if (Length(commands
[i
].help
) > 0) then
1490 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1494 g_Console_Add(' '+commands
[i
].cmd
);
1500 ll
:= LowerCase(Line
);
1503 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
1505 ll
:= Copy(ll
, 0, Length(ll
)-1);
1506 for i
:= 0 to High(commands
) do
1508 // hidden commands are hidden when cheats aren't enabled
1509 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1510 if (commands
[i
].cmd
= ll
) then
1512 if (Length(commands
[i
].help
) > 0) then
1514 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
1521 // build completion list
1523 for i
:= 0 to High(commands
) do
1525 // hidden commands are hidden when cheats aren't enabled
1526 if commands
[i
].hidden
and not conIsCheatsEnabled
then continue
;
1527 cmd
:= commands
[i
].cmd
;
1528 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
1530 if (tused
= Length(tcomplist
)) then
1532 SetLength(tcomplist
, Length(tcomplist
)+128);
1533 SetLength(tcompidx
, Length(tcompidx
)+128);
1535 tcomplist
[tused
] := cmd
;
1536 tcompidx
[tused
] := i
;
1538 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1542 // get longest prefix
1543 for i
:= 0 to tused
-1 do
1545 cmd
:= tcomplist
[i
];
1546 for c
:= 1 to Length(lpfx
) do
1548 if (c
> Length(cmd
)) then break
;
1549 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1553 if (tused
= 0) then exit
;
1557 Line
:= tcomplist
[0]+' ';
1558 CPos
:= Length(Line
)+1;
1562 // has longest prefix?
1563 if (Length(lpfx
) > Length(ll
)) then
1566 CPos
:= Length(Line
)+1;
1571 for i
:= 0 to tused
-1 do
1573 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1575 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1579 g_Console_Add(' '+tcomplist
[i
]);
1587 procedure g_Console_Control(K
: Word);
1591 if (Length(Line
) > 0) and (CPos
> 1) then
1593 Delete(Line
, CPos
-1, 1);
1597 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1598 Delete(Line
, CPos
, 1);
1599 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1602 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1603 if CPos
<= Length(Line
) then
1605 IK_RETURN
, IK_KPRETURN
, VK_OPEN
, VK_FIRE
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1607 if gConsoleShow
then
1608 g_Console_Process(Line
)
1612 if (Length(Line
) > 0) and g_Game_IsNet
then
1616 if g_Game_IsClient
then
1617 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1619 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1620 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1624 if g_Game_IsClient
then
1625 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1627 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1634 gJustChatted
:= True;
1635 g_Console_Chat_Switch
;
1636 InputReady
:= False;
1640 if not gChatShow
then
1642 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1643 if not gChatShow
then
1644 if (CommandHistory
<> nil) and
1645 (CmdIndex
< Length(CommandHistory
)) then
1647 if CmdIndex
< Length(CommandHistory
)-1 then
1648 CmdIndex
:= CmdIndex
+ 1;
1649 Line
:= CommandHistory
[CmdIndex
];
1650 CPos
:= Length(Line
) + 1;
1652 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1653 if not gChatShow
then
1654 if (CommandHistory
<> nil) and
1655 (CmdIndex
<= Length(CommandHistory
)) then
1657 if CmdIndex
> 0 then
1658 CmdIndex
:= CmdIndex
- 1;
1659 Line
:= CommandHistory
[CmdIndex
];
1660 Cpos
:= Length(Line
) + 1;
1662 IK_PAGEUP
, IK_KPPAGEUP
, VK_PREV
, JOY0_PREV
, JOY1_PREV
, JOY2_PREV
, JOY3_PREV
: // PgUp
1663 if not gChatShow
then Inc(conSkipLines
);
1664 IK_PAGEDN
, IK_KPPAGEDN
, VK_NEXT
, JOY0_NEXT
, JOY1_NEXT
, JOY2_NEXT
, JOY3_NEXT
: // PgDown
1665 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1669 CPos
:= Length(Line
) + 1;
1670 IK_A
..IK_Z
, IK_SPACE
, IK_SHIFT
, IK_RSHIFT
, IK_CAPSLOCK
, IK_LBRACKET
, IK_RBRACKET
,
1671 IK_SEMICOLON
, IK_QUOTE
, IK_BACKSLASH
, IK_SLASH
, IK_COMMA
, IK_DOT
, (*IK_EQUALS,*)
1672 IK_0
, IK_1
, IK_2
, IK_3
, IK_4
, IK_5
, IK_6
, IK_7
, IK_8
, IK_9
, IK_MINUS
, IK_EQUALS
:
1673 (* see TEXTINPUT event *)
1677 function GetStr(var Str
: AnsiString): AnsiString;
1682 if Str
[1] = '"' then
1684 for b
:= 1 to Length(Str
) do
1685 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1687 Result
:= Copy(Str
, 2, b
-1);
1688 Delete(Str
, 1, b
+1);
1694 for a
:= 1 to Length(Str
) do
1695 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1697 Result
:= Copy(Str
, 1, a
);
1698 Delete(Str
, 1, a
+1);
1704 function ParseString(Str
: AnsiString): SSArray
;
1715 SetLength(Result
, Length(Result
)+1);
1716 Result
[High(Result
)] := GetStr(Str
);
1720 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1722 procedure conmsg (s
: AnsiString);
1726 if length(s
) = 0 then exit
;
1727 for a
:= 0 to High(MsgArray
) do
1739 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1740 with MsgArray
[High(MsgArray
)] do
1750 // put it to console
1752 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1754 // now show 'em out of console too
1755 show
:= show
and gAllowConsoleMessages
;
1756 if show
and gShowMessages
then
1758 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1759 while length(L
) > 0 do
1762 if f
<= 0 then f
:= length(L
)+1;
1763 conmsg(Copy(L
, 1, f
-1));
1768 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1769 //ConsoleHistory[High(ConsoleHistory)] := L;
1773 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1780 consolewriterLastWasEOL
: Boolean = false;
1782 procedure consolewriter (constref buf
; len
: SizeUInt
);
1786 if (len
< 1) then exit
;
1788 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1791 if (b
[0] <> 13) and (b
[0] <> 10) then
1793 cbufPut(AnsiChar(b
[0]));
1797 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1806 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1807 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1808 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1809 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1811 g_Console_Add(s
, show
);
1815 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1819 g_Console_Add(formatstrf(s
, args
), true);
1823 consolewriterLastWasEOL
:= false;
1824 formatstrf(s
, args
, consolewriter
);
1825 if not consolewriterLastWasEOL
then cbufPut(#10);
1830 procedure g_Console_Clear();
1832 //ConsoleHistory := nil;
1837 procedure AddToHistory(L
: AnsiString);
1841 len
:= Length(CommandHistory
);
1844 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1846 SetLength(CommandHistory
, len
+1);
1847 CommandHistory
[len
] := L
;
1850 CmdIndex
:= Length(CommandHistory
);
1853 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1862 if Trim(C
) = '' then
1865 Arr
:= ParseString(C
);
1869 for i
:= 0 to High(Whitelist
) do
1870 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1874 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1881 if Trim(L
) = '' then
1884 conSkipLines
:= 0; // "unscroll"
1886 if L
= 'goobers' then
1891 g_Console_Add('Your memory serves you well.');
1897 g_Console_Add('> '+L
);
1902 Arr
:= ParseString(L
);
1906 if commands
= nil then
1912 for i
:= 0 to High(commands
) do
1914 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1916 if commands
[i
].action
>= 0 then
1918 gPlayerAction
[commands
[i
].player
, commands
[i
].action
] := commands
[i
].cmd
[1] = '+';
1921 if assigned(commands
[i
].procEx
) then
1923 commands
[i
].procEx(@commands
[i
], Arr
);
1926 if assigned(commands
[i
].proc
) then
1928 commands
[i
].proc(Arr
);
1934 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));
1938 function g_Console_Interactive
: Boolean;
1940 Result
:= gConsoleShow
1943 procedure g_Console_BindKey (key
: Integer; down
: AnsiString; up
: AnsiString = ''; rep
: Boolean = False);
1945 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1947 ASSERT(key
< e_MaxInputKeys
);
1950 gInputBinds
[key
].rep
:= rep
;
1951 gInputBinds
[key
].down
:= ParseAlias(down
);
1952 gInputBinds
[key
].up
:= ParseAlias(up
);
1954 g_Console_WriteGameConfig();
1957 function g_Console_MatchBind (key
: Integer; down
: AnsiString; up
: AnsiString = ''): Boolean;
1959 function EqualsCommandLists (a
, b
: SSArray
): Boolean;
1960 var i
, len
: Integer;
1964 if len
= Length(b
) then
1967 while (i
< len
) and (a
[i
] = b
[i
]) do inc(i
);
1975 ASSERT(key
< e_MaxInputKeys
);
1976 result
:= EqualsCommandLists(ParseAlias(down
), gInputBinds
[key
].down
) and EqualsCommandLists(ParseAlias(up
), gInputBinds
[key
].up
)
1979 function g_Console_FindBind (n
: Integer; down
: AnsiString; up
: AnsiString = ''): Integer;
1984 if commands
= nil then Exit
;
1986 while (n
>= 1) and (i
< e_MaxInputKeys
) do
1988 if (i
< VK_FIRSTKEY
) or (i
> VK_LASTKEY
) then (* never show virtual keys in gui *)
1990 if g_Console_MatchBind(i
, down
, up
) then
2002 function g_Console_Action (action
: Integer): Boolean;
2003 var i
, len
: Integer;
2005 ASSERT(action
>= FIRST_ACTION
);
2006 ASSERT(action
<= LAST_ACTION
);
2008 len
:= Length(gPlayerAction
);
2009 while (i
< len
) and (not gPlayerAction
[i
, action
]) do inc(i
);
2013 function BindsAllowed (key
: Integer): Boolean;
2016 if (not g_GUIGrabInput
) and (key
>= 0) and (key
< e_MaxInputKeys
) and ((gInputBinds
[key
].down
<> nil) or (gInputBinds
[key
].up
<> nil)) then
2019 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
2020 g_Console_MatchBind(key
, 'showkeyboard') or
2021 g_Console_MatchBind(key
, 'hidekeyboard')
2022 else if gConsoleShow
or (g_ActiveWindow
<> nil) or (gGameSettings
.GameType
= GT_NONE
) then
2023 Result
:= g_Console_MatchBind(key
, 'togglemenu') or
2024 g_Console_MatchBind(key
, 'toggleconsole') or
2025 g_Console_MatchBind(key
, 'showkeyboard') or
2026 g_Console_MatchBind(key
, 'hidekeyboard')
2032 procedure g_Console_ProcessBind (key
: Integer; down
: Boolean);
2035 if BindsAllowed(key
) then
2038 for i
:= 0 to High(gInputBinds
[key
].down
) do
2039 g_Console_Process(gInputBinds
[key
].down
[i
], True)
2041 for i
:= 0 to High(gInputBinds
[key
].up
) do
2042 g_Console_Process(gInputBinds
[key
].up
[i
], True)
2044 if down
and not menu_toggled
then
2046 menu_toggled
:= False
2049 procedure g_Console_ProcessBindRepeat (key
: Integer);
2052 if gConsoleShow
or gChatShow
or (g_ActiveWindow
<> nil) then
2054 KeyPress(key
); // key repeat in menus and shit
2057 if BindsAllowed(key
) and gInputBinds
[key
].rep
then
2059 for i
:= 0 to High(gInputBinds
[key
].down
) do
2060 g_Console_Process(gInputBinds
[key
].down
[i
], True);
2064 procedure g_Console_ResetBinds
;
2067 for i
:= 0 to e_MaxInputKeys
- 1 do
2068 g_Console_BindKey(i
, '', '');
2070 g_Console_BindKey(IK_GRAVE
, 'toggleconsole');
2071 g_Console_BindKey(IK_ESCAPE
, 'togglemenu');
2072 g_Console_BindKey(IK_A
, '+p1_moveleft', '-p1_moveleft');
2073 g_Console_BindKey(IK_D
, '+p1_moveright', '-p1_moveright');
2074 g_Console_BindKey(IK_W
, '+p1_lookup', '-p1_lookup');
2075 g_Console_BindKey(IK_S
, '+p1_lookdown', '-p1_lookdown');
2076 g_Console_BindKey(IK_SPACE
, '+p1_jump', '-p1_jump');
2077 g_Console_BindKey(IK_H
, '+p1_attack', '-p1_attack');
2078 g_Console_BindKey(IK_J
, '+p1_activate', '-p1_activate');
2079 g_Console_BindKey(IK_ALT
, '+p1_strafe', '-p1_strafe');
2080 g_Console_BindKey(IK_E
, 'p1_weapnext', '', True);
2081 g_Console_BindKey(IK_Q
, 'p1_weapprev', '', True);
2082 g_Console_BindKey(IK_R
, 'p1_dropflag', '');
2083 g_Console_BindKey(IK_1
, 'p1_weapon 1');
2084 g_Console_BindKey(IK_2
, 'p1_weapon 2');
2085 g_Console_BindKey(IK_3
, 'p1_weapon 3');
2086 g_Console_BindKey(IK_4
, 'p1_weapon 4');
2087 g_Console_BindKey(IK_5
, 'p1_weapon 5');
2088 g_Console_BindKey(IK_6
, 'p1_weapon 6');
2089 g_Console_BindKey(IK_7
, 'p1_weapon 7');
2090 g_Console_BindKey(IK_8
, 'p1_weapon 8');
2091 g_Console_BindKey(IK_9
, 'p1_weapon 9');
2092 g_Console_BindKey(IK_0
, 'p1_weapon 10');
2093 g_Console_BindKey(IK_MINUS
, 'p1_weapon 11');
2094 g_Console_BindKey(IK_T
, 'togglechat');
2095 g_Console_BindKey(IK_Y
, 'toggleteamchat');
2096 g_Console_BindKey(IK_F11
, 'screenshot');
2097 g_Console_BindKey(IK_TAB
, '+scores', '-scores');
2098 g_Console_BindKey(IK_PAUSE
, 'pause');
2099 g_Console_BindKey(IK_F1
, 'vote');
2101 (* for i := 0 to e_MaxJoys - 1 do *)
2104 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_LEFT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveleft', '-p' + IntToStr(i
mod 2 + 1) + '_moveleft');
2105 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_RIGHT
), '+p' + IntToStr(i
mod 2 + 1) + '_moveright', '-p' + IntToStr(i
mod 2 + 1) + '_moveright');
2106 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_UP
), '+p' + IntToStr(i
mod 2 + 1) + '_lookup', '-p' + IntToStr(i
mod 2 + 1) + '_lookup');
2107 g_Console_BindKey(e_JoyHatToKey(i
, 0, HAT_DOWN
), '+p' + IntToStr(i
mod 2 + 1) + '_lookdown', '-p' + IntToStr(i
mod 2 + 1) + '_lookdown');
2108 g_Console_BindKey(e_JoyButtonToKey(i
, 2), '+p' + IntToStr(i
mod 2 + 1) + '_jump', '-p' + IntToStr(i
mod 2 + 1) + '_jump');
2109 g_Console_BindKey(e_JoyButtonToKey(i
, 0), '+p' + IntToStr(i
mod 2 + 1) + '_attack', '-p' + IntToStr(i
mod 2 + 1) + '_attack');
2110 g_Console_BindKey(e_JoyButtonToKey(i
, 3), '+p' + IntToStr(i
mod 2 + 1) + '_activate', '-p' + IntToStr(i
mod 2 + 1) + '_activate');
2111 g_Console_BindKey(e_JoyButtonToKey(i
, 7), '+p' + IntToStr(i
mod 2 + 1) + '_strafe', '-p' + IntToStr(i
mod 2 + 1) + '_strafe');
2112 g_Console_BindKey(e_JoyButtonToKey(i
, 1), 'p' + IntToStr(i
mod 2 + 1) + '_weapnext', '', True);
2113 g_Console_BindKey(e_JoyButtonToKey(i
, 4), 'p' + IntToStr(i
mod 2 + 1) + '_weapprev', '', True);
2114 g_Console_BindKey(e_JoyButtonToKey(i
, 10), 'togglemenu');
2117 g_Console_BindKey(VK_ESCAPE
, 'togglemenu');
2118 g_Console_BindKey(VK_LSTRAFE
, '+moveleft; +strafe', '-moveleft; -strafe');
2119 g_Console_BindKey(VK_RSTRAFE
, '+moveright; +strafe', '-moveright; -strafe');
2120 g_Console_BindKey(VK_LEFT
, '+moveleft', '-moveleft');
2121 g_Console_BindKey(VK_RIGHT
, '+moveright', '-moveright');
2122 g_Console_BindKey(VK_UP
, '+lookup', '-lookup');
2123 g_Console_BindKey(VK_DOWN
, '+lookdown', '-lookdown');
2124 g_Console_BindKey(VK_JUMP
, '+jump', '-jump');
2125 g_Console_BindKey(VK_FIRE
, '+attack', '-attack');
2126 g_Console_BindKey(VK_OPEN
, '+activate', '-activate');
2127 g_Console_BindKey(VK_STRAFE
, '+strafe', '-strafe');
2128 g_Console_BindKey(VK_NEXT
, 'weapnext', '', True);
2129 g_Console_BindKey(VK_PREV
, 'weapprev', '', True);
2130 g_Console_BindKey(VK_0
, 'weapon 1');
2131 g_Console_BindKey(VK_1
, 'weapon 2');
2132 g_Console_BindKey(VK_2
, 'weapon 3');
2133 g_Console_BindKey(VK_3
, 'weapon 4');
2134 g_Console_BindKey(VK_4
, 'weapon 5');
2135 g_Console_BindKey(VK_5
, 'weapon 6');
2136 g_Console_BindKey(VK_6
, 'weapon 7');
2137 g_Console_BindKey(VK_7
, 'weapon 8');
2138 g_Console_BindKey(VK_8
, 'weapon 9');
2139 g_Console_BindKey(VK_9
, 'weapon 10');
2140 g_Console_BindKey(VK_A
, 'weapon 11');
2141 g_Console_BindKey(VK_CHAT
, 'togglechat');
2142 g_Console_BindKey(VK_TEAM
, 'toggleteamchat');
2143 g_Console_BindKey(VK_CONSOLE
, 'toggleconsole');
2144 g_Console_BindKey(VK_PRINTSCR
, 'screenshot');
2145 g_Console_BindKey(VK_STATUS
, '+scores', '-scores');
2146 g_Console_BindKey(VK_SHOWKBD
, 'showkeyboard');
2147 g_Console_BindKey(VK_HIDEKBD
, 'hidekeyboard');
2150 procedure g_Console_ReadConfig (filename
: String);
2151 var f
: TextFile
; s
: AnsiString; i
, len
: Integer;
2153 e_LogWritefln('g_Console_ReadConfig (1) "%s"', [filename
]);
2154 if e_FindResource(ConfigDirs
, filename
, false) = true then
2156 e_LogWritefln('g_Console_ReadConfig (2) "%s"', [filename
]);
2157 AssignFile(f
, filename
);
2167 while (i
<= len
) and (s
[i
] <= ' ') do inc(i
);
2169 if (i
<= len
) and ((s
[i
] <> '#') and ((i
+ 1 > len
) or (s
[i
] <> '/') or (s
[i
+ 1] <> '/'))) then
2170 g_Console_Process(s
, True);
2177 procedure g_Console_WriteConfig (filename
: String);
2178 var f
: TextFile
; i
, j
: Integer;
2180 procedure WriteFlag(name
: string; flag
: LongWord);
2182 WriteLn(f
, name
, IfThen(LongBool(gsGameFlags
and flag
), 1, 0));
2185 function FormatTeam(team
: Byte): string;
2187 if team
= TEAM_BLUE
then
2194 AssignFile(f
, filename
);
2196 WriteLn(f
, '// ' + configComment
);
2199 WriteLn(f
, 'unbindall');
2200 for i
:= 0 to e_MaxInputKeys
- 1 do
2201 if (Length(gInputBinds
[i
].down
) > 0) or (Length(gInputBinds
[i
].up
) > 0) then
2203 Write(f
, 'bind ', e_KeyNames
[i
], ' ', QuoteStr(GetCommandString(gInputBinds
[i
].down
)));
2204 if Length(gInputBinds
[i
].down
) = 0 then
2206 if Length(gInputBinds
[i
].up
) > 0 then
2207 Write(f
, ' ', QuoteStr(GetCommandString(gInputBinds
[i
].up
)));
2209 if gInputBinds
[i
].rep
then
2210 WriteLn(f
, 'bindrep ', e_KeyNames
[i
]);
2214 if gAskLanguage
then
2215 WriteLn(f
, 'g_language ask')
2217 WriteLn(f
, 'g_language ', gLanguage
);
2220 WriteLn(f
, 'sv_name ', QuoteStr(NetServerName
));
2221 WriteLn(f
, 'sv_passwd ', QuoteStr(NetPassword
));
2222 WriteLn(f
, 'sv_maxplrs ', NetMaxClients
);
2223 WriteLn(f
, 'sv_port ', NetPort
);
2224 WriteLn(f
, 'sv_public ', IfThen(NetUseMaster
, 1, 0));
2227 WriteLn(f
, 'g_max_particles ', g_GFX_GetMax());
2228 WriteLn(f
, 'g_max_shells ', g_Shells_GetMax());
2229 WriteLn(f
, 'g_max_gibs ', g_Gibs_GetMax());
2230 WriteLn(f
, 'g_max_corpses ', g_Corpses_GetMax());
2231 WriteLn(f
, 'g_force_model ', g_Force_Model_Get());
2232 WriteLn(f
, 'g_force_model_name ', g_Forced_Model_GetName());
2233 WriteLn(f
, 'sv_intertime ', gDefInterTime
);
2235 // gameplay settings
2236 WriteLn(f
, 'g_gamemode ', gsGameMode
);
2237 WriteLn(f
, 'g_scorelimit ', gsScoreLimit
);
2238 WriteLn(f
, 'g_timelimit ', gsTimeLimit
);
2239 WriteLn(f
, 'g_maxlives ', gsMaxLives
);
2240 WriteLn(f
, 'g_item_respawn_time ', gsItemRespawnTime
);
2241 WriteLn(f
, 'g_rulez_time_multiplier ', gsRulezTimeMultiplier
);
2242 WriteLn(f
, 'g_spawn_invul ', gsSpawnInvul
);
2243 WriteLn(f
, 'g_warmup_time ', gsWarmupTime
);
2245 WriteFlag('g_friendlyfire ', GAME_OPTION_TEAMDAMAGE
);
2246 WriteFlag('g_friendly_hit_trace ', GAME_OPTION_TEAMHITTRACE
);
2247 WriteFlag('g_friendly_hit_projectile ', GAME_OPTION_TEAMHITPROJECTILE
);
2248 WriteFlag('g_rulez_randomize_respawn ', GAME_OPTION_RULEZRANDOM
);
2249 WriteFlag('g_allow_exit ', GAME_OPTION_ALLOWEXIT
);
2250 WriteFlag('g_allow_monsters ', GAME_OPTION_MONSTERS
);
2251 WriteFlag('g_allow_dropflag ', GAME_OPTION_ALLOWDROPFLAG
);
2252 WriteFlag('g_throw_flag ', GAME_OPTION_THROWFLAG
);
2253 WriteFlag('g_dm_keys ', GAME_OPTION_DMKEYS
);
2254 WriteFlag('g_weaponstay ', GAME_OPTION_WEAPONSTAY
);
2255 WriteFlag('g_bot_vsmonsters ', GAME_OPTION_BOTVSMONSTER
);
2256 WriteFlag('g_bot_vsplayers ', GAME_OPTION_BOTVSPLAYER
);
2259 with gPlayer1Settings
do
2261 WriteLn(f
, 'p1_name ', QuoteStr(Name
));
2262 WriteLn(f
, 'p1_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2263 WriteLn(f
, 'p1_model ', QuoteStr(Model
));
2264 WriteLn(f
, 'p1_team ', FormatTeam(Team
));
2265 WriteLn(f
, 'p1_autoswitch ', WeaponSwitch
);
2266 WriteLn(f
, 'p1_switch_empty ', SwitchToEmpty
);
2267 WriteLn(f
, 'p1_priority_kastet ', Max(0, WeaponPreferences
[WEAPON_KASTET
]));
2268 WriteLn(f
, 'p1_priority_saw ', Max(0, WeaponPreferences
[WEAPON_SAW
]));
2269 WriteLn(f
, 'p1_priority_pistol ', Max(0, WeaponPreferences
[WEAPON_PISTOL
]));
2270 WriteLn(f
, 'p1_priority_shotgun1 ', Max(0, WeaponPreferences
[WEAPON_SHOTGUN1
]));
2271 WriteLn(f
, 'p1_priority_shotgun2 ', Max(0, WeaponPreferences
[WEAPON_SHOTGUN2
] ));
2272 WriteLn(f
, 'p1_priority_chaingun ', Max(0, WeaponPreferences
[WEAPON_CHAINGUN
]));
2273 WriteLn(f
, 'p1_priority_rocketlauncher ', Max(0, WeaponPreferences
[WEAPON_ROCKETLAUNCHER
]));
2274 WriteLn(f
, 'p1_priority_plasma ', Max(0, WeaponPreferences
[WEAPON_PLASMA
]));
2275 WriteLn(f
, 'p1_priority_bfg ', Max(0, WeaponPreferences
[WEAPON_BFG
]));
2276 WriteLn(f
, 'p1_priority_super ', Max(0, WeaponPreferences
[WEAPON_SUPERPULEMET
]));
2277 WriteLn(f
, 'p1_priority_flamethrower ', Max(0, WeaponPreferences
[WEAPON_FLAMETHROWER
]));
2278 WriteLn(f
, 'p1_priority_berserk ', Max(0, WeaponPreferences
[WP_LAST
+1]));
2281 with gPlayer2Settings
do
2283 WriteLn(f
, 'p2_name ', QuoteStr(Name
));
2284 WriteLn(f
, 'p2_color ', Color
.R
, ' ', Color
.G
, ' ', Color
.B
);
2285 WriteLn(f
, 'p2_model ', QuoteStr(Model
));
2286 WriteLn(f
, 'p2_team ', FormatTeam(Team
));
2287 WriteLn(f
, 'p2_autoswitch ', WeaponSwitch
);
2288 WriteLn(f
, 'p2_switch_empty ', SwitchToEmpty
);
2289 WriteLn(f
, 'p2_priority_kastet ', Max(0, WeaponPreferences
[WEAPON_KASTET
]));
2290 WriteLn(f
, 'p2_priority_saw ', Max(0, WeaponPreferences
[WEAPON_SAW
]));
2291 WriteLn(f
, 'p2_priority_pistol ', Max(0, WeaponPreferences
[WEAPON_PISTOL
]));
2292 WriteLn(f
, 'p2_priority_shotgun1 ', Max(0, WeaponPreferences
[WEAPON_SHOTGUN1
]));
2293 WriteLn(f
, 'p2_priority_shotgun2 ', Max(0, WeaponPreferences
[WEAPON_SHOTGUN1
]));
2294 WriteLn(f
, 'p2_priority_chaingun ', Max(0, WeaponPreferences
[WEAPON_CHAINGUN
]));
2295 WriteLn(f
, 'p2_priority_rocketlauncher ', Max(0, WeaponPreferences
[WEAPON_ROCKETLAUNCHER
]));
2296 WriteLn(f
, 'p2_priority_plasma ', Max(0, WeaponPreferences
[WEAPON_PLASMA
]));
2297 WriteLn(f
, 'p2_priority_bfg ', Max(0, WeaponPreferences
[WEAPON_BFG
]));
2298 WriteLn(f
, 'p2_priority_super ', Max(0, WeaponPreferences
[WEAPON_SUPERPULEMET
]));
2299 WriteLn(f
, 'p2_priority_flamethrower ', Max(0, WeaponPreferences
[WEAPON_FLAMETHROWER
]));
2300 WriteLn(f
, 'p2_priority_berserk ', Max(0, WeaponPreferences
[WP_LAST
+1]));
2304 for i
:= 0 to High(commands
) do
2306 if not commands
[i
].cheat
then
2308 if @commands
[i
].procEx
= @boolVarHandler
then
2310 if PBoolean(commands
[i
].ptr
)^ then j
:= 1 else j
:= 0;
2311 WriteLn(f
, commands
[i
].cmd
, ' ', j
)
2313 else if @commands
[i
].procEx
= @intVarHandler
then
2315 WriteLn(f
, commands
[i
].cmd
, ' ', PInteger(commands
[i
].ptr
)^)
2317 else if @commands
[i
].procEx
= @wordVarHandler
then
2319 WriteLn(f
, commands
[i
].cmd
, ' ', PWord(commands
[i
].ptr
)^)
2321 else if @commands
[i
].procEx
= @dwordVarHandler
then
2323 WriteLn(f
, commands
[i
].cmd
, ' ', PCardinal(commands
[i
].ptr
)^)
2325 else if @commands
[i
].procEx
= @singleVarHandler
then
2327 WriteLn(f
, commands
[i
].cmd
, ' ', PVarSingle(commands
[i
].ptr
).val
^:0:6)
2329 else if @commands
[i
].procEx
= @strVarHandler
then
2331 if Length(PAnsiString(commands
[i
].ptr
)^) = 0 then
2332 WriteLn(f
, commands
[i
].cmd
, ' ""')
2334 WriteLn(f
, commands
[i
].cmd
, ' ', QuoteStr(PAnsiString(commands
[i
].ptr
)^))
2339 WriteLn(f
, 'r_maxfps ', gMaxFPS
);
2340 WriteLn(f
, 'r_reset');
2344 procedure g_Console_WriteGameConfig
;
2347 if gParsingBinds
= false then
2349 s
:= e_GetWriteableDir(ConfigDirs
);
2350 g_Console_WriteConfig(e_CatPath(s
, gConfigScript
))
2357 conRegVar('chat_at_top', @ChatTop
, 'draw chat at top border', 'draw chat at top border');
2358 conRegVar('console_height', @ConsoleHeight
, 0.0, 1.0, 'set console size', 'set console size');
2359 conRegVar('console_trans', @ConsoleTrans
, 0.0, 1.0, 'set console transparency', 'set console transparency');
2360 conRegVar('console_step', @ConsoleStep
, 0.0, 1.0, 'set console animation speed', 'set console animation speed');
2361 conRegVar('console_stdin', @ConsoleStdIn
, 'enable reading commands from stdin', 'enable reading commands from stdin');
2364 ConsoleHeight
:= 0.35;
2367 ConsoleHeight
:= 0.5;
2369 ConsoleTrans
:= 0.1;
2370 ConsoleStep
:= 0.07;
2372 ConsoleStdIn
:= True;
2374 ConsoleStdIn
:= False;
2376 conRegVar('d_eres', @debug_e_res
, '', '');
2377 for i
:= 1 to e_MaxJoys
do
2378 conRegVar('joy' + IntToStr(i
) + '_deadzone', @e_JoystickDeadzones
[i
- 1], '', '')
2387 conbufStdOutRawMode
:= false;