DEADSOFTWARE

cleanup: clean boot sequence
[d2df-sdl.git] / src / game / g_console.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
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.
6 *
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.
11 *
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/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_console;
18 interface
20 uses
21 utils; // for SSArray
23 const
24 ACTION_JUMP = 0;
25 ACTION_MOVELEFT = 1;
26 ACTION_MOVERIGHT = 2;
27 ACTION_LOOKDOWN = 3;
28 ACTION_LOOKUP = 4;
29 ACTION_ATTACK = 5;
30 ACTION_SCORES = 6;
31 ACTION_ACTIVATE = 7;
32 ACTION_STRAFE = 8;
33 ACTION_WEAPNEXT = 9;
34 ACTION_WEAPPREV = 10;
36 FIRST_ACTION = ACTION_JUMP;
37 LAST_ACTION = ACTION_WEAPPREV;
39 var (* private state *)
40 Line: AnsiString;
41 CPos: Word;
42 conSkipLines: Integer;
43 MsgArray: Array [0..4] of record
44 Msg: AnsiString;
45 Time: Word;
46 end;
48 procedure g_Console_Init;
49 procedure g_Console_Initialize;
50 procedure g_Console_Finalize;
51 procedure g_Console_Update;
52 procedure g_Console_Char (C: AnsiChar);
53 procedure g_Console_Control (K: Word);
54 procedure g_Console_Process (L: AnsiString; quiet: Boolean=false);
55 procedure g_Console_Add (L: AnsiString; show: Boolean=false);
56 procedure g_Console_Clear;
57 function g_Console_CommandBlacklisted (C: AnsiString): Boolean;
58 procedure g_Console_ReadConfig (filename: String);
59 procedure g_Console_WriteConfig (filename: String);
60 procedure g_Console_WriteGameConfig;
62 function g_Console_Interactive: Boolean;
63 function g_Console_Action (action: Integer): Boolean;
64 function g_Console_MatchBind (key: Integer; down: AnsiString; up: AnsiString = ''): Boolean;
65 function g_Console_FindBind (n: Integer; down: AnsiString; up: AnsiString = ''): Integer;
66 procedure g_Console_BindKey (key: Integer; down: AnsiString; up: AnsiString = '');
67 procedure g_Console_ProcessBind (key: Integer; down: Boolean);
68 procedure g_Console_ProcessBindRepeat (key: Integer);
69 procedure g_Console_ResetBinds;
71 procedure conwriteln (const s: AnsiString; show: Boolean=false);
72 procedure conwritefln (const s: AnsiString; args: array of const; show: Boolean=false);
74 procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
75 procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
76 procedure conRegVar (const conname: AnsiString; pvar: PInteger; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
77 procedure conRegVar (const conname: AnsiString; pvar: PWord; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
78 procedure conRegVar (const conname: AnsiString; pvar: PCardinal; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
79 procedure conRegVar (const conname: AnsiString; pvar: PAnsiString; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
81 // <0: no arg; 0/1: true/false
82 function conGetBoolArg (p: SSArray; idx: Integer): Integer;
84 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
85 function conParseFloat (var res: Single; const s: AnsiString): Boolean;
87 const
88 defaultConfigScript = 'dfconfig.cfg';
90 var
91 gConsoleShow: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
92 gChatShow: Boolean = false;
93 gChatTeam: Boolean = false;
94 gAllowConsoleMessages: Boolean = true;
95 gJustChatted: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
96 gParsingBinds: Boolean = true; // íå ïåðåñîõðàíÿòü êîíôèã âî âðåìÿ ïàðñèíãà
97 gPlayerAction: Array [0..1, 0..LAST_ACTION] of Boolean; // [player, action]
98 gConfigScript: string = defaultConfigScript;
100 implementation
102 uses
103 g_textures, e_input, g_game, g_gfx, g_player, g_items,
104 SysUtils, g_basic, g_options, Math, g_touch, e_res,
105 g_menu, g_gui, g_language, g_net, g_netmsg, e_log, conbuf;
107 const
108 configComment = 'generated by doom2d, do not modify';
110 type
111 PCommand = ^TCommand;
113 TCmdProc = procedure (p: SSArray);
114 TCmdProcEx = procedure (me: PCommand; p: SSArray);
116 TCommand = record
117 cmd: AnsiString;
118 proc: TCmdProc;
119 procEx: TCmdProcEx;
120 help: AnsiString;
121 hidden: Boolean;
122 ptr: Pointer; // various data
123 msg: AnsiString; // message for var changes
124 cheat: Boolean;
125 action: Integer; // >= 0 for action commands
126 player: Integer; // used for action commands
127 end;
129 TAlias = record
130 name: AnsiString;
131 commands: SSArray;
132 end;
135 const
136 MsgTime = 144;
137 MaxScriptRecursion = 16;
139 var
140 RecursionDepth: Word = 0;
141 RecursionLimitHit: Boolean = False;
142 InputReady: Boolean; // allow text input in console/chat
143 //ConsoleHistory: SSArray;
144 CommandHistory: SSArray;
145 Whitelist: SSArray;
146 commands: Array of TCommand = nil;
147 Aliases: Array of TAlias = nil;
148 CmdIndex: Word;
150 gInputBinds: Array [0..e_MaxInputKeys - 1] of record
151 rep: Boolean;
152 down, up: SSArray;
153 end;
154 menu_toggled: BOOLEAN; (* hack for menu controls *)
156 procedure g_Console_Switch;
157 begin
158 gChatShow := False;
159 gConsoleShow := not gConsoleShow;
160 InputReady := False;
161 g_Touch_ShowKeyboard(gConsoleShow or gChatShow);
162 end;
164 procedure g_Console_Chat_Switch (Team: Boolean = False);
165 begin
166 if not g_Game_IsNet then Exit;
167 gConsoleShow := False;
168 gChatShow := not gChatShow;
169 gChatTeam := Team;
170 InputReady := False;
171 Line := '';
172 CPos := 1;
173 g_Touch_ShowKeyboard(gConsoleShow or gChatShow);
174 end;
176 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
177 function conParseFloat (var res: Single; const s: AnsiString): Boolean;
178 var
179 pos: Integer = 1;
180 frac: Single = 1;
181 slen: Integer;
182 begin
183 result := false;
184 res := 0;
185 slen := Length(s);
186 while (slen > 0) and (s[slen] <= ' ') do Dec(slen);
187 while (pos <= slen) and (s[pos] <= ' ') do Inc(pos);
188 if (pos > slen) then exit;
189 if (slen-pos = 1) and (s[pos] = '.') then exit; // single dot
190 // integral part
191 while (pos <= slen) do
192 begin
193 if (s[pos] < '0') or (s[pos] > '9') then break;
194 res := res*10+Byte(s[pos])-48;
195 Inc(pos);
196 end;
197 if (pos <= slen) then
198 begin
199 // must be a dot
200 if (s[pos] <> '.') then exit;
201 Inc(pos);
202 while (pos <= slen) do
203 begin
204 if (s[pos] < '0') or (s[pos] > '9') then break;
205 frac := frac/10;
206 res += frac*(Byte(s[pos])-48);
207 Inc(pos);
208 end;
209 end;
210 if (pos <= slen) then exit; // oops
211 result := true;
212 end;
215 // ////////////////////////////////////////////////////////////////////////// //
216 // <0: no arg; 0/1: true/false; 666: toggle
217 function conGetBoolArg (p: SSArray; idx: Integer): Integer;
218 begin
219 if (idx < 0) or (idx > High(p)) then begin result := -1; exit; end;
220 result := 0;
221 if (p[idx] = '1') or (CompareText(p[idx], 'on') = 0) or (CompareText(p[idx], 'true') = 0) or
222 (CompareText(p[idx], 'tan') = 0) or (CompareText(p[idx], 'yes') = 0) then result := 1
223 else if (CompareText(p[idx], 'toggle') = 0) or (CompareText(p[idx], 'switch') = 0) or
224 (CompareText(p[idx], 't') = 0) then result := 666;
225 end;
228 procedure boolVarHandler (me: PCommand; p: SSArray);
229 procedure binaryFlag (var flag: Boolean; msg: AnsiString);
230 var
231 old: Boolean;
232 begin
233 if (Length(p) > 2) then
234 begin
235 conwritefln('too many arguments to ''%s''', [p[0]]);
236 end
237 else
238 begin
239 old := flag;
240 case conGetBoolArg(p, 1) of
241 -1: begin end;
242 0: if not me.cheat or conIsCheatsEnabled then flag := false else begin conwriteln('not available'); exit; end;
243 1: if not me.cheat or conIsCheatsEnabled then flag := true else begin conwriteln('not available'); exit; end;
244 666: if not me.cheat or conIsCheatsEnabled then flag := not flag else begin conwriteln('not available'); exit; end;
245 end;
246 if flag <> old then
247 g_Console_WriteGameConfig();
248 if (Length(msg) = 0) then msg := p[0] else msg += ':';
249 if flag then conwritefln('%s tan', [msg]) else conwritefln('%s ona', [msg]);
250 end;
251 end;
252 begin
253 binaryFlag(PBoolean(me.ptr)^, me.msg);
254 end;
257 procedure intVarHandler (me: PCommand; p: SSArray);
258 var
259 old: Integer;
260 begin
261 if (Length(p) <> 2) then
262 begin
263 conwritefln('%s %d', [me.cmd, PInteger(me.ptr)^]);
264 end
265 else
266 begin
267 try
268 old := PInteger(me.ptr)^;
269 PInteger(me.ptr)^ := StrToInt(p[1]);
270 if PInteger(me.ptr)^ <> old then
271 g_Console_WriteGameConfig();
272 except
273 conwritefln('invalid integer value: "%s"', [p[1]]);
274 end;
275 end;
276 end;
279 procedure wordVarHandler (me: PCommand; p: SSArray);
280 var
281 old: Integer;
282 begin
283 if (Length(p) <> 2) then
284 begin
285 conwritefln('%s %d', [me.cmd, PInteger(me.ptr)^]);
286 end
287 else
288 begin
289 try
290 old := PWord(me.ptr)^;
291 PWord(me.ptr)^ := min($FFFF, StrToDWord(p[1]));
292 if PWord(me.ptr)^ <> old then
293 g_Console_WriteGameConfig();
294 except
295 conwritefln('invalid word value: "%s"', [p[1]]);
296 end;
297 end;
298 end;
301 procedure dwordVarHandler (me: PCommand; p: SSArray);
302 var
303 old: Integer;
304 begin
305 if (Length(p) <> 2) then
306 begin
307 conwritefln('%s %d', [me.cmd, PInteger(me.ptr)^]);
308 end
309 else
310 begin
311 try
312 old := PCardinal(me.ptr)^;
313 PCardinal(me.ptr)^ := StrToDWord(p[1]);
314 if PCardinal(me.ptr)^ <> old then
315 g_Console_WriteGameConfig();
316 except
317 conwritefln('invalid dword value: "%s"', [p[1]]);
318 end;
319 end;
320 end;
323 procedure strVarHandler (me: PCommand; p: SSArray);
324 var
325 old: AnsiString;
326 begin
327 if (Length(p) <> 2) then
328 begin
329 conwritefln('%s %s', [me.cmd, QuoteStr(PAnsiString(me.ptr)^)]);
330 end
331 else
332 begin
333 old := PAnsiString(me.ptr)^;
334 PAnsiString(me.ptr)^ := p[1];
335 if PAnsiString(me.ptr)^ <> old then
336 g_Console_WriteGameConfig();
337 end;
338 end;
341 procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
342 var
343 f: Integer;
344 cp: PCommand;
345 begin
346 f := Length(commands);
347 SetLength(commands, f+1);
348 cp := @commands[f];
349 cp.cmd := LowerCase(conname);
350 cp.proc := nil;
351 cp.procEx := boolVarHandler;
352 cp.help := ahelp;
353 cp.hidden := ahidden;
354 cp.ptr := pvar;
355 cp.msg := amsg;
356 cp.cheat := acheat;
357 cp.action := -1;
358 cp.player := -1;
359 end;
362 procedure conRegVar (const conname: AnsiString; pvar: PInteger; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
363 var
364 f: Integer;
365 cp: PCommand;
366 begin
367 f := Length(commands);
368 SetLength(commands, f+1);
369 cp := @commands[f];
370 cp.cmd := LowerCase(conname);
371 cp.proc := nil;
372 cp.procEx := intVarHandler;
373 cp.help := ahelp;
374 cp.hidden := ahidden;
375 cp.ptr := pvar;
376 cp.msg := amsg;
377 cp.cheat := acheat;
378 cp.action := -1;
379 cp.player := -1;
380 end;
383 procedure conRegVar (const conname: AnsiString; pvar: PWord; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
384 var
385 f: Integer;
386 cp: PCommand;
387 begin
388 f := Length(commands);
389 SetLength(commands, f+1);
390 cp := @commands[f];
391 cp.cmd := LowerCase(conname);
392 cp.proc := nil;
393 cp.procEx := wordVarHandler;
394 cp.help := ahelp;
395 cp.hidden := ahidden;
396 cp.ptr := pvar;
397 cp.msg := amsg;
398 cp.cheat := acheat;
399 cp.action := -1;
400 cp.player := -1;
401 end;
404 procedure conRegVar (const conname: AnsiString; pvar: PCardinal; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
405 var
406 f: Integer;
407 cp: PCommand;
408 begin
409 f := Length(commands);
410 SetLength(commands, f+1);
411 cp := @commands[f];
412 cp.cmd := LowerCase(conname);
413 cp.proc := nil;
414 cp.procEx := dwordVarHandler;
415 cp.help := ahelp;
416 cp.hidden := ahidden;
417 cp.ptr := pvar;
418 cp.msg := amsg;
419 cp.cheat := acheat;
420 cp.action := -1;
421 cp.player := -1;
422 end;
425 procedure conRegVar (const conname: AnsiString; pvar: PAnsiString; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
426 var
427 f: Integer;
428 cp: PCommand;
429 begin
430 f := Length(commands);
431 SetLength(commands, f+1);
432 cp := @commands[f];
433 cp.cmd := LowerCase(conname);
434 cp.proc := nil;
435 cp.procEx := strVarHandler;
436 cp.help := ahelp;
437 cp.hidden := ahidden;
438 cp.ptr := pvar;
439 cp.msg := amsg;
440 cp.cheat := acheat;
441 cp.action := -1;
442 cp.player := -1;
443 end;
445 // ////////////////////////////////////////////////////////////////////////// //
446 type
447 PVarSingle = ^TVarSingle;
448 TVarSingle = record
449 val: PSingle;
450 min, max, def: Single; // default will be starting value
451 end;
454 procedure singleVarHandler (me: PCommand; p: SSArray);
455 var
456 pv: PVarSingle;
457 nv, old: Single;
458 msg: AnsiString;
459 begin
460 if (Length(p) > 2) then
461 begin
462 conwritefln('too many arguments to ''%s''', [me.cmd]);
463 exit;
464 end;
465 pv := PVarSingle(me.ptr);
466 old := pv.val^;
467 if (Length(p) = 2) then
468 begin
469 if me.cheat and (not conIsCheatsEnabled) then begin conwriteln('not available'); exit; end;
470 if (CompareText(p[1], 'default') = 0) or (CompareText(p[1], 'def') = 0) or
471 (CompareText(p[1], 'd') = 0) or (CompareText(p[1], 'off') = 0) or
472 (CompareText(p[1], 'ona') = 0) then
473 begin
474 pv.val^ := pv.def;
475 end
476 else
477 begin
478 if not conParseFloat(nv, p[1]) then
479 begin
480 conwritefln('%s: ''%s'' doesn''t look like a floating number', [me.cmd, p[1]]);
481 exit;
482 end;
483 if (nv < pv.min) then nv := pv.min;
484 if (nv > pv.max) then nv := pv.max;
485 pv.val^ := nv;
486 end;
487 end;
488 if pv.val^ <> old then
489 g_Console_WriteGameConfig();
490 msg := me.msg;
491 if (Length(msg) = 0) then msg := me.cmd else msg += ':';
492 conwritefln('%s %s', [msg, pv.val^]);
493 end;
496 procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
497 var
498 f: Integer;
499 cp: PCommand;
500 pv: PVarSingle;
501 begin
502 GetMem(pv, sizeof(TVarSingle));
503 pv.val := pvar;
504 pv.min := amin;
505 pv.max := amax;
506 pv.def := pvar^;
507 f := Length(commands);
508 SetLength(commands, f+1);
509 cp := @commands[f];
510 cp.cmd := LowerCase(conname);
511 cp.proc := nil;
512 cp.procEx := singleVarHandler;
513 cp.help := ahelp;
514 cp.hidden := ahidden;
515 cp.ptr := pv;
516 cp.msg := amsg;
517 cp.cheat := acheat;
518 cp.action := -1;
519 cp.player := -1;
520 end;
523 // ////////////////////////////////////////////////////////////////////////// //
524 function GetStrACmd(var Str: AnsiString): AnsiString;
525 var
526 a: Integer;
527 begin
528 Result := '';
529 for a := 1 to Length(Str) do
530 if (a = Length(Str)) or (Str[a+1] = ';') then
531 begin
532 Result := Copy(Str, 1, a);
533 Delete(Str, 1, a+1);
534 Str := Trim(Str);
535 Exit;
536 end;
537 end;
539 function ParseAlias(Str: AnsiString): SSArray;
540 begin
541 Result := nil;
543 Str := Trim(Str);
545 if Str = '' then
546 Exit;
548 while Str <> '' do
549 begin
550 SetLength(Result, Length(Result)+1);
551 Result[High(Result)] := GetStrACmd(Str);
552 end;
553 end;
555 procedure ConsoleCommands(p: SSArray);
556 var
557 cmd, s: AnsiString;
558 a, b: Integer;
559 (* F: TextFile; *)
560 begin
561 cmd := LowerCase(p[0]);
562 s := '';
564 if cmd = 'clear' then
565 begin
566 //ConsoleHistory := nil;
567 cbufClear();
568 conSkipLines := 0;
570 for a := 0 to High(MsgArray) do
571 with MsgArray[a] do
572 begin
573 Msg := '';
574 Time := 0;
575 end;
576 end;
578 if cmd = 'clearhistory' then
579 CommandHistory := nil;
581 if cmd = 'showhistory' then
582 if CommandHistory <> nil then
583 begin
584 g_Console_Add('');
585 for a := 0 to High(CommandHistory) do
586 g_Console_Add(' '+CommandHistory[a]);
587 end;
589 if cmd = 'commands' then
590 begin
591 g_Console_Add('');
592 g_Console_Add('commands list:');
593 for a := High(commands) downto 0 do
594 begin
595 if (Length(commands[a].help) > 0) then
596 begin
597 g_Console_Add(' '+commands[a].cmd+' -- '+commands[a].help);
598 end
599 else
600 begin
601 g_Console_Add(' '+commands[a].cmd);
602 end;
603 end;
604 end;
606 if cmd = 'time' then
607 g_Console_Add(TimeToStr(Now), True);
609 if cmd = 'date' then
610 g_Console_Add(DateToStr(Now), True);
612 if cmd = 'echo' then
613 if Length(p) > 1 then
614 begin
615 if p[1] = 'ololo' then
616 gCheats := True
617 else
618 begin
619 s := '';
620 for a := 1 to High(p) do
621 s := s + p[a] + ' ';
622 g_Console_Add(b_Text_Format(s), True);
623 end;
624 end
625 else
626 g_Console_Add('');
628 if cmd = 'dump' then
629 begin
630 (*
631 if ConsoleHistory <> nil then
632 begin
633 if Length(P) > 1 then
634 s := P[1]
635 else
636 s := GameDir+'/console.txt';
638 {$I-}
639 AssignFile(F, s);
640 Rewrite(F);
641 if IOResult <> 0 then
642 begin
643 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
644 CloseFile(F);
645 Exit;
646 end;
648 for a := 0 to High(ConsoleHistory) do
649 WriteLn(F, ConsoleHistory[a]);
651 CloseFile(F);
652 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
653 {$I+}
654 end;
655 *)
656 end;
658 if cmd = 'exec' then
659 begin
660 // exec <filename>
661 if Length(p) = 2 then
662 g_Console_ReadConfig(p[1])
663 else
664 g_Console_Add('exec <script file>');
665 end;
667 if cmd = 'writeconfig' then
668 begin
669 // writeconfig <filename>
670 if Length(p) = 2 then
671 begin
672 s := e_GetWriteableDir(ConfigDirs);
673 g_Console_WriteConfig(e_CatPath(s, p[1]))
674 end
675 else
676 begin
677 g_Console_Add('writeconfig <file>')
678 end
679 end;
681 if (cmd = 'ver') or (cmd = 'version') then
682 begin
683 conwriteln('Doom 2D: Forever v. ' + GAME_VERSION);
684 conwritefln('Net protocol v. %d', [NET_PROTOCOL_VER]);
685 conwritefln('Build date: %s at %s', [GAME_BUILDDATE, GAME_BUILDTIME]);
686 end;
688 if cmd = 'alias' then
689 begin
690 // alias [alias_name] [commands]
691 if Length(p) > 1 then
692 begin
693 for a := 0 to High(Aliases) do
694 if Aliases[a].name = p[1] then
695 begin
696 if Length(p) > 2 then
697 Aliases[a].commands := ParseAlias(p[2])
698 else
699 for b := 0 to High(Aliases[a].commands) do
700 g_Console_Add(Aliases[a].commands[b]);
701 Exit;
702 end;
703 SetLength(Aliases, Length(Aliases)+1);
704 a := High(Aliases);
705 Aliases[a].name := p[1];
706 if Length(p) > 2 then
707 Aliases[a].commands := ParseAlias(p[2])
708 else
709 for b := 0 to High(Aliases[a].commands) do
710 g_Console_Add(Aliases[a].commands[b]);
711 end else
712 for a := 0 to High(Aliases) do
713 if Aliases[a].commands <> nil then
714 g_Console_Add(Aliases[a].name);
715 end;
717 if cmd = 'call' then
718 begin
719 // call <alias_name>
720 if Length(p) > 1 then
721 begin
722 if Aliases = nil then
723 Exit;
724 for a := 0 to High(Aliases) do
725 if Aliases[a].name = p[1] then
726 begin
727 if Aliases[a].commands <> nil then
728 begin
729 // with this system proper endless loop detection seems either impossible
730 // or very dirty to implement, so let's have this instead
731 // prevents endless loops
732 for b := 0 to High(Aliases[a].commands) do
733 begin
734 Inc(RecursionDepth);
735 RecursionLimitHit := (RecursionDepth > MaxScriptRecursion) or RecursionLimitHit;
736 if not RecursionLimitHit then
737 g_Console_Process(Aliases[a].commands[b], True);
738 Dec(RecursionDepth);
739 end;
740 if (RecursionDepth = 0) and RecursionLimitHit then
741 begin
742 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_CALL], [s]));
743 RecursionLimitHit := False;
744 end;
745 end;
746 Exit;
747 end;
748 end
749 else
750 g_Console_Add('call <alias name>');
751 end;
752 end;
754 procedure WhitelistCommand(cmd: AnsiString);
755 var
756 a: Integer;
757 begin
758 SetLength(Whitelist, Length(Whitelist)+1);
759 a := High(Whitelist);
760 Whitelist[a] := LowerCase(cmd);
761 end;
763 procedure segfault (p: SSArray);
764 var
765 pp: PByte = nil;
766 begin
767 pp^ := 0;
768 end;
770 function GetCommandString (p: SSArray): AnsiString;
771 var i: Integer;
772 begin
773 result := '';
774 if Length(p) >= 1 then
775 begin
776 result := p[0];
777 for i := 1 to High(p) do
778 result := result + '; ' + p[i]
779 end
780 end;
782 function QuoteStr(str: String): String;
783 begin
784 if Pos(' ', str) > 0 then
785 Result := '"' + str + '"'
786 else
787 Result := str;
788 end;
790 procedure BindCommands (p: SSArray);
791 var cmd, key: AnsiString; i: Integer;
792 begin
793 cmd := LowerCase(p[0]);
794 case cmd of
795 'bind':
796 // bind <key> [down [up]]
797 if (Length(p) >= 2) and (Length(p) <= 4) then
798 begin
799 i := 0;
800 key := LowerCase(p[1]);
801 while (i < e_MaxInputKeys) and (key <> LowerCase(e_KeyNames[i])) do inc(i);
802 if i < e_MaxInputKeys then
803 begin
804 if Length(p) = 2 then
805 g_Console_Add(QuoteStr(e_KeyNames[i]) + ' = ' + QuoteStr(GetCommandString(gInputBinds[i].down)) + ' ' + QuoteStr(GetCommandString(gInputBinds[i].up)))
806 else if Length(p) = 3 then
807 g_Console_BindKey(i, p[2], '')
808 else (* len = 4 *)
809 g_Console_BindKey(i, p[2], p[3])
810 end
811 else
812 g_Console_Add('bind: "' + p[1] + '" is not a key')
813 end
814 else
815 begin
816 g_Console_Add('bind <key> <down action> [up action]')
817 end;
818 'bindrep':
819 // bindrep <key>
820 if Length(p) = 2 then
821 begin
822 key := LowerCase(p[1]);
823 i := 0;
824 while (i < e_MaxInputKeys) and (key <> LowerCase(e_KeyNames[i])) do inc(i);
825 if i < e_MaxInputKeys then
826 gInputBinds[i].rep := True
827 else
828 g_Console_Add('bindrep: "' + p[1] + '" is not a key')
829 end
830 else
831 g_Console_Add('bindrep <key>');
832 'bindunrep':
833 // bindunrep <key>
834 if Length(p) = 2 then
835 begin
836 key := LowerCase(p[1]);
837 i := 0;
838 while (i < e_MaxInputKeys) and (key <> LowerCase(e_KeyNames[i])) do inc(i);
839 if i < e_MaxInputKeys then
840 gInputBinds[i].rep := False
841 else
842 g_Console_Add('bindunrep: "' + p[1] + '" is not a key')
843 end
844 else
845 g_Console_Add('bindunrep <key>');
846 'bindlist':
847 for i := 0 to e_MaxInputKeys - 1 do
848 if (gInputBinds[i].down <> nil) or (gInputBinds[i].up <> nil) then
849 g_Console_Add(e_KeyNames[i] + ' ' + QuoteStr(GetCommandString(gInputBinds[i].down)) + ' ' + QuoteStr(GetCommandString(gInputBinds[i].up)));
850 'unbind':
851 // unbind <key>
852 if Length(p) = 2 then
853 begin
854 key := LowerCase(p[1]);
855 i := 0;
856 while (i < e_MaxInputKeys) and (key <> LowerCase(e_KeyNames[i])) do inc(i);
857 if i < e_MaxInputKeys then
858 g_Console_BindKey(i, '')
859 else
860 g_Console_Add('unbind: "' + p[1] + '" is not a key')
861 end
862 else
863 g_Console_Add('unbind <key>');
864 'unbindall':
865 for i := 0 to e_MaxInputKeys - 1 do
866 g_Console_BindKey(i, '');
867 'showkeyboard':
868 g_Touch_ShowKeyboard(True);
869 'hidekeyboard':
870 g_Touch_ShowKeyboard(False);
871 'togglemenu':
872 begin
873 if gConsoleShow then
874 g_Console_Switch
875 else if gChatShow then
876 g_Console_Chat_Switch
877 else
878 KeyPress(VK_ESCAPE);
879 menu_toggled := True
880 end;
881 'toggleconsole':
882 g_Console_Switch;
883 'togglechat':
884 g_Console_Chat_Switch;
885 'toggleteamchat':
886 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
887 g_Console_Chat_Switch(True);
888 end
889 end;
891 procedure AddCommand(cmd: AnsiString; proc: TCmdProc; ahelp: AnsiString=''; ahidden: Boolean=false; acheat: Boolean=false);
892 var
893 a: Integer;
894 cp: PCommand;
895 begin
896 SetLength(commands, Length(commands)+1);
897 a := High(commands);
898 cp := @commands[a];
899 cp.cmd := LowerCase(cmd);
900 cp.proc := proc;
901 cp.procEx := nil;
902 cp.help := ahelp;
903 cp.hidden := ahidden;
904 cp.ptr := nil;
905 cp.msg := '';
906 cp.cheat := acheat;
907 cp.action := -1;
908 cp.player := -1;
909 end;
911 procedure AddAction (cmd: AnsiString; action: Integer; help: AnsiString = ''; hidden: Boolean = False; cheat: Boolean = False);
912 const
913 PrefixList: array [0..1] of AnsiString = ('+', '-');
914 PlayerList: array [0..1] of Integer = (1, 2);
915 var
916 s: AnsiString;
917 i: Integer;
919 procedure NewAction (cmd: AnsiString; player: Integer);
920 var cp: PCommand;
921 begin
922 SetLength(commands, Length(commands) + 1);
923 cp := @commands[High(commands)];
924 cp.cmd := LowerCase(cmd);
925 cp.proc := nil;
926 cp.procEx := nil;
927 cp.help := help;
928 cp.hidden := hidden;
929 cp.ptr := nil;
930 cp.msg := '';
931 cp.cheat := cheat;
932 cp.action := action;
933 cp.player := player;
934 end;
936 begin
937 ASSERT(action >= FIRST_ACTION);
938 ASSERT(action <= LAST_ACTION);
939 for s in PrefixList do
940 begin
941 NewAction(s + cmd, 0);
942 for i in PlayerList do
943 NewAction(s + 'p' + IntToStr(i) + '_' + cmd, i - 1)
944 end
945 end;
947 procedure g_Console_Initialize;
948 var a: Integer;
949 begin
950 gConsoleShow := False;
951 gChatShow := False;
952 InputReady := False;
953 CPos := 1;
955 for a := 0 to High(MsgArray) do
956 with MsgArray[a] do
957 begin
958 Msg := '';
959 Time := 0;
960 end;
962 AddCommand('segfault', segfault, 'make segfault');
964 AddCommand('quit', SystemCommands);
965 AddCommand('exit', SystemCommands);
966 AddCommand('r_reset', SystemCommands);
967 AddCommand('r_maxfps', SystemCommands);
968 AddCommand('g_language', SystemCommands);
970 AddCommand('bind', BindCommands);
971 AddCommand('bindrep', BindCommands);
972 AddCommand('bindunrep', BindCommands);
973 AddCommand('bindlist', BindCommands);
974 AddCommand('unbind', BindCommands);
975 AddCommand('unbindall', BindCommands);
976 AddCommand('showkeyboard', BindCommands);
977 AddCommand('hidekeyboard', BindCommands);
978 AddCommand('togglemenu', BindCommands);
979 AddCommand('toggleconsole', BindCommands);
980 AddCommand('togglechat', BindCommands);
981 AddCommand('toggleteamchat', BindCommands);
983 AddCommand('clear', ConsoleCommands, 'clear console');
984 AddCommand('clearhistory', ConsoleCommands);
985 AddCommand('showhistory', ConsoleCommands);
986 AddCommand('commands', ConsoleCommands);
987 AddCommand('time', ConsoleCommands);
988 AddCommand('date', ConsoleCommands);
989 AddCommand('echo', ConsoleCommands);
990 AddCommand('dump', ConsoleCommands);
991 AddCommand('exec', ConsoleCommands);
992 AddCommand('writeconfig', ConsoleCommands);
993 AddCommand('alias', ConsoleCommands);
994 AddCommand('call', ConsoleCommands);
995 AddCommand('ver', ConsoleCommands);
996 AddCommand('version', ConsoleCommands);
998 AddCommand('d_window', DebugCommands);
999 AddCommand('d_sounds', DebugCommands);
1000 AddCommand('d_frames', DebugCommands);
1001 AddCommand('d_winmsg', DebugCommands);
1002 AddCommand('d_monoff', DebugCommands);
1003 AddCommand('d_botoff', DebugCommands);
1004 AddCommand('d_monster', DebugCommands);
1005 AddCommand('d_health', DebugCommands);
1006 AddCommand('d_player', DebugCommands);
1007 AddCommand('d_joy', DebugCommands);
1008 AddCommand('d_mem', DebugCommands);
1010 AddCommand('p1_name', PlayerSettingsCVars);
1011 AddCommand('p2_name', PlayerSettingsCVars);
1012 AddCommand('p1_color', PlayerSettingsCVars);
1013 AddCommand('p2_color', PlayerSettingsCVars);
1014 AddCommand('p1_model', PlayerSettingsCVars);
1015 AddCommand('p2_model', PlayerSettingsCVars);
1016 AddCommand('p1_team', PlayerSettingsCVars);
1017 AddCommand('p2_team', PlayerSettingsCVars);
1019 AddCommand('g_max_particles', GameCVars);
1020 AddCommand('g_max_shells', GameCVars);
1021 AddCommand('g_max_gibs', GameCVars);
1022 AddCommand('g_max_corpses', GameCVars);
1023 AddCommand('g_gamemode', GameCVars);
1024 AddCommand('g_friendlyfire', GameCVars);
1025 AddCommand('g_friendly_hit_trace', GameCVars);
1026 AddCommand('g_friendly_hit_projectile', GameCVars);
1027 AddCommand('g_friendly_absorb_damage', GameCVars);
1028 AddCommand('g_weaponstay', GameCVars);
1029 AddCommand('g_allow_exit', GameCVars);
1030 AddCommand('g_dm_keys', GameCVars);
1031 AddCommand('g_allow_monsters', GameCVars);
1032 AddCommand('g_bot_vsmonsters', GameCVars);
1033 AddCommand('g_bot_vsplayers', GameCVars);
1034 AddCommand('g_scorelimit', GameCVars);
1035 AddCommand('g_timelimit', GameCVars);
1036 AddCommand('g_maxlives', GameCVars);
1037 AddCommand('g_warmup_time', GameCVars);
1038 AddCommand('g_spawn_invul', GameCVars);
1039 AddCommand('g_item_respawn_time', GameCVars);
1040 AddCommand('sv_intertime', GameCVars);
1042 AddCommand('sv_name', NetServerCVars);
1043 AddCommand('sv_passwd', NetServerCVars);
1044 AddCommand('sv_maxplrs', NetServerCVars);
1045 AddCommand('sv_public', NetServerCVars);
1046 AddCommand('sv_port', NetServerCVars);
1048 AddCommand('pause', GameCommands);
1049 AddCommand('endgame', GameCommands);
1050 AddCommand('restart', GameCommands);
1051 AddCommand('addbot', GameCommands);
1052 AddCommand('bot_add', GameCommands);
1053 AddCommand('bot_addlist', GameCommands);
1054 AddCommand('bot_addred', GameCommands);
1055 AddCommand('bot_addblue', GameCommands);
1056 AddCommand('bot_removeall', GameCommands);
1057 AddCommand('chat', GameCommands);
1058 AddCommand('teamchat', GameCommands);
1059 AddCommand('game', GameCommands);
1060 AddCommand('host', GameCommands);
1061 AddCommand('map', GameCommands);
1062 AddCommand('nextmap', GameCommands);
1063 AddCommand('endmap', GameCommands);
1064 AddCommand('goodbye', GameCommands);
1065 AddCommand('suicide', GameCommands);
1066 AddCommand('spectate', GameCommands);
1067 AddCommand('ready', GameCommands);
1068 AddCommand('kick', GameCommands);
1069 AddCommand('kick_id', GameCommands);
1070 AddCommand('kick_pid', GameCommands);
1071 AddCommand('ban', GameCommands);
1072 AddCommand('ban_id', GameCommands);
1073 AddCommand('ban_pid', GameCommands);
1074 AddCommand('permban', GameCommands);
1075 AddCommand('permban_id', GameCommands);
1076 AddCommand('permban_pid', GameCommands);
1077 AddCommand('permban_ip', GameCommands);
1078 AddCommand('unban', GameCommands);
1079 AddCommand('connect', GameCommands);
1080 AddCommand('disconnect', GameCommands);
1081 AddCommand('reconnect', GameCommands);
1082 AddCommand('say', GameCommands);
1083 AddCommand('tell', GameCommands);
1084 AddCommand('centerprint', GameCommands);
1085 AddCommand('overtime', GameCommands);
1086 AddCommand('rcon_password', GameCommands);
1087 AddCommand('rcon', GameCommands);
1088 AddCommand('callvote', GameCommands);
1089 AddCommand('vote', GameCommands);
1090 AddCommand('clientlist', GameCommands);
1091 AddCommand('event', GameCommands);
1092 AddCommand('screenshot', GameCommands);
1093 AddCommand('weapon', GameCommands);
1094 AddCommand('p1_weapon', GameCommands);
1095 AddCommand('p2_weapon', GameCommands);
1097 AddCommand('god', GameCheats);
1098 AddCommand('notarget', GameCheats);
1099 AddCommand('give', GameCheats); // "exit" too ;-)
1100 AddCommand('open', GameCheats);
1101 AddCommand('fly', GameCheats);
1102 AddCommand('noclip', GameCheats);
1103 AddCommand('speedy', GameCheats);
1104 AddCommand('jumpy', GameCheats);
1105 AddCommand('noreload', GameCheats);
1106 AddCommand('aimline', GameCheats);
1107 AddCommand('automap', GameCheats);
1109 AddAction('jump', ACTION_JUMP);
1110 AddAction('moveleft', ACTION_MOVELEFT);
1111 AddAction('moveright', ACTION_MOVERIGHT);
1112 AddAction('lookup', ACTION_LOOKUP);
1113 AddAction('lookdown', ACTION_LOOKDOWN);
1114 AddAction('attack', ACTION_ATTACK);
1115 AddAction('scores', ACTION_SCORES);
1116 AddAction('activate', ACTION_ACTIVATE);
1117 AddAction('strafe', ACTION_STRAFE);
1118 AddAction('weapnext', ACTION_WEAPNEXT);
1119 AddAction('weapprev', ACTION_WEAPPREV);
1121 WhitelistCommand('say');
1122 WhitelistCommand('tell');
1123 WhitelistCommand('overtime');
1124 WhitelistCommand('ready');
1125 WhitelistCommand('map');
1126 WhitelistCommand('nextmap');
1127 WhitelistCommand('endmap');
1128 WhitelistCommand('restart');
1129 WhitelistCommand('kick');
1130 WhitelistCommand('kick_pid');
1131 WhitelistCommand('ban');
1132 WhitelistCommand('ban_pid');
1133 WhitelistCommand('centerprint');
1135 WhitelistCommand('addbot');
1136 WhitelistCommand('bot_add');
1137 WhitelistCommand('bot_addred');
1138 WhitelistCommand('bot_addblue');
1139 WhitelistCommand('bot_removeall');
1141 WhitelistCommand('g_gamemode');
1142 WhitelistCommand('g_friendlyfire');
1143 WhitelistCommand('g_friendly_hit_trace');
1144 WhitelistCommand('g_friendly_hit_projectile');
1145 WhitelistCommand('g_friendly_absorb_damage');
1146 WhitelistCommand('g_weaponstay');
1147 WhitelistCommand('g_allow_exit');
1148 WhitelistCommand('g_dm_keys');
1149 WhitelistCommand('g_allow_monsters');
1150 WhitelistCommand('g_bot_vsmonsters');
1151 WhitelistCommand('g_bot_vsplayers');
1152 WhitelistCommand('g_scorelimit');
1153 WhitelistCommand('g_timelimit');
1154 WhitelistCommand('g_maxlives');
1155 WhitelistCommand('g_warmup_time');
1156 WhitelistCommand('g_spawn_invul');
1157 WhitelistCommand('g_item_respawn_time');
1159 g_Console_ResetBinds;
1160 g_Console_ReadConfig(gConfigScript);
1161 // g_Console_ReadConfig(autoexecScript);
1162 g_Console_ReadConfig('autoexec.cfg');
1164 gParsingBinds := False;
1165 end;
1167 procedure g_Console_Finalize;
1168 begin
1170 end;
1172 procedure g_Console_Init;
1173 begin
1174 g_Console_Add(Format(_lc[I_CONSOLE_WELCOME], [GAME_VERSION]));
1175 g_Console_Add('');
1176 end;
1178 procedure g_Console_Update;
1179 var
1180 a, b: Integer;
1181 begin
1182 InputReady := gConsoleShow or gChatShow;
1184 a := 0;
1185 while a <= High(MsgArray) do
1186 begin
1187 if MsgArray[a].Time > 0 then
1188 begin
1189 if MsgArray[a].Time = 1 then
1190 begin
1191 if a < High(MsgArray) then
1192 begin
1193 for b := a to High(MsgArray)-1 do
1194 MsgArray[b] := MsgArray[b+1];
1196 MsgArray[High(MsgArray)].Time := 0;
1198 a := a - 1;
1199 end;
1200 end
1201 else
1202 Dec(MsgArray[a].Time);
1203 end;
1205 a := a + 1;
1206 end;
1207 end;
1209 procedure g_Console_Char(C: AnsiChar);
1210 begin
1211 if InputReady and (gConsoleShow or gChatShow) then
1212 begin
1213 Insert(C, Line, CPos);
1214 CPos := CPos + 1;
1215 end
1216 end;
1219 var
1220 tcomplist: array of AnsiString = nil;
1221 tcompidx: array of Integer = nil;
1223 procedure Complete ();
1224 var
1225 i, c: Integer;
1226 tused: Integer;
1227 ll, lpfx, cmd: AnsiString;
1228 begin
1229 if (Length(Line) = 0) then
1230 begin
1231 g_Console_Add('');
1232 for i := 0 to High(commands) do
1233 begin
1234 // hidden commands are hidden when cheats aren't enabled
1235 if commands[i].hidden and not conIsCheatsEnabled then continue;
1236 if (Length(commands[i].help) > 0) then
1237 begin
1238 g_Console_Add(' '+commands[i].cmd+' -- '+commands[i].help);
1239 end
1240 else
1241 begin
1242 g_Console_Add(' '+commands[i].cmd);
1243 end;
1244 end;
1245 exit;
1246 end;
1248 ll := LowerCase(Line);
1249 lpfx := '';
1251 if (Length(ll) > 1) and (ll[Length(ll)] = ' ') then
1252 begin
1253 ll := Copy(ll, 0, Length(ll)-1);
1254 for i := 0 to High(commands) do
1255 begin
1256 // hidden commands are hidden when cheats aren't enabled
1257 if commands[i].hidden and not conIsCheatsEnabled then continue;
1258 if (commands[i].cmd = ll) then
1259 begin
1260 if (Length(commands[i].help) > 0) then
1261 begin
1262 g_Console_Add(' '+commands[i].cmd+' -- '+commands[i].help);
1263 end;
1264 end;
1265 end;
1266 exit;
1267 end;
1269 // build completion list
1270 tused := 0;
1271 for i := 0 to High(commands) do
1272 begin
1273 // hidden commands are hidden when cheats aren't enabled
1274 if commands[i].hidden and not conIsCheatsEnabled then continue;
1275 cmd := commands[i].cmd;
1276 if (Length(cmd) >= Length(ll)) and (ll = Copy(cmd, 0, Length(ll))) then
1277 begin
1278 if (tused = Length(tcomplist)) then
1279 begin
1280 SetLength(tcomplist, Length(tcomplist)+128);
1281 SetLength(tcompidx, Length(tcompidx)+128);
1282 end;
1283 tcomplist[tused] := cmd;
1284 tcompidx[tused] := i;
1285 Inc(tused);
1286 if (Length(cmd) > Length(lpfx)) then lpfx := cmd;
1287 end;
1288 end;
1290 // get longest prefix
1291 for i := 0 to tused-1 do
1292 begin
1293 cmd := tcomplist[i];
1294 for c := 1 to Length(lpfx) do
1295 begin
1296 if (c > Length(cmd)) then break;
1297 if (cmd[c] <> lpfx[c]) then begin lpfx := Copy(lpfx, 0, c-1); break; end;
1298 end;
1299 end;
1301 if (tused = 0) then exit;
1303 if (tused = 1) then
1304 begin
1305 Line := tcomplist[0]+' ';
1306 CPos := Length(Line)+1;
1307 end
1308 else
1309 begin
1310 // has longest prefix?
1311 if (Length(lpfx) > Length(ll)) then
1312 begin
1313 Line := lpfx;
1314 CPos:= Length(Line)+1;
1315 end
1316 else
1317 begin
1318 g_Console_Add('');
1319 for i := 0 to tused-1 do
1320 begin
1321 if (Length(commands[tcompidx[i]].help) > 0) then
1322 begin
1323 g_Console_Add(' '+tcomplist[i]+' -- '+commands[tcompidx[i]].help);
1324 end
1325 else
1326 begin
1327 g_Console_Add(' '+tcomplist[i]);
1328 end;
1329 end;
1330 end;
1331 end;
1332 end;
1335 procedure g_Console_Control(K: Word);
1336 begin
1337 case K of
1338 IK_BACKSPACE:
1339 if (Length(Line) > 0) and (CPos > 1) then
1340 begin
1341 Delete(Line, CPos-1, 1);
1342 CPos := CPos-1;
1343 end;
1344 IK_DELETE:
1345 if (Length(Line) > 0) and (CPos <= Length(Line)) then
1346 Delete(Line, CPos, 1);
1347 IK_LEFT, IK_KPLEFT, VK_LEFT, JOY0_LEFT, JOY1_LEFT, JOY2_LEFT, JOY3_LEFT:
1348 if CPos > 1 then
1349 CPos := CPos - 1;
1350 IK_RIGHT, IK_KPRIGHT, VK_RIGHT, JOY0_RIGHT, JOY1_RIGHT, JOY2_RIGHT, JOY3_RIGHT:
1351 if CPos <= Length(Line) then
1352 CPos := CPos + 1;
1353 IK_RETURN, IK_KPRETURN, VK_OPEN, VK_FIRE, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK:
1354 begin
1355 if gConsoleShow then
1356 g_Console_Process(Line)
1357 else
1358 if gChatShow then
1359 begin
1360 if (Length(Line) > 0) and g_Game_IsNet then
1361 begin
1362 if gChatTeam then
1363 begin
1364 if g_Game_IsClient then
1365 MC_SEND_Chat(b_Text_Format(Line), NET_CHAT_TEAM)
1366 else
1367 MH_SEND_Chat('[' + gPlayer1Settings.name + ']: ' + b_Text_Format(Line),
1368 NET_CHAT_TEAM, gPlayer1Settings.Team);
1369 end
1370 else
1371 begin
1372 if g_Game_IsClient then
1373 MC_SEND_Chat(b_Text_Format(Line), NET_CHAT_PLAYER)
1374 else
1375 MH_SEND_Chat('[' + gPlayer1Settings.name + ']: ' + b_Text_Format(Line),
1376 NET_CHAT_PLAYER);
1377 end;
1378 end;
1380 Line := '';
1381 CPos := 1;
1382 gJustChatted := True;
1383 g_Console_Chat_Switch;
1384 InputReady := False;
1385 end;
1386 end;
1387 IK_TAB:
1388 if not gChatShow then
1389 Complete();
1390 IK_DOWN, IK_KPDOWN, VK_DOWN, JOY0_DOWN, JOY1_DOWN, JOY2_DOWN, JOY3_DOWN:
1391 if not gChatShow then
1392 if (CommandHistory <> nil) and
1393 (CmdIndex < Length(CommandHistory)) then
1394 begin
1395 if CmdIndex < Length(CommandHistory)-1 then
1396 CmdIndex := CmdIndex + 1;
1397 Line := CommandHistory[CmdIndex];
1398 CPos := Length(Line) + 1;
1399 end;
1400 IK_UP, IK_KPUP, VK_UP, JOY0_UP, JOY1_UP, JOY2_UP, JOY3_UP:
1401 if not gChatShow then
1402 if (CommandHistory <> nil) and
1403 (CmdIndex <= Length(CommandHistory)) then
1404 begin
1405 if CmdIndex > 0 then
1406 CmdIndex := CmdIndex - 1;
1407 Line := CommandHistory[CmdIndex];
1408 Cpos := Length(Line) + 1;
1409 end;
1410 IK_PAGEUP, IK_KPPAGEUP, VK_PREV, JOY0_PREV, JOY1_PREV, JOY2_PREV, JOY3_PREV: // PgUp
1411 if not gChatShow then Inc(conSkipLines);
1412 IK_PAGEDN, IK_KPPAGEDN, VK_NEXT, JOY0_NEXT, JOY1_NEXT, JOY2_NEXT, JOY3_NEXT: // PgDown
1413 if not gChatShow and (conSkipLines > 0) then Dec(conSkipLines);
1414 IK_HOME, IK_KPHOME:
1415 CPos := 1;
1416 IK_END, IK_KPEND:
1417 CPos := Length(Line) + 1;
1418 IK_A..IK_Z, IK_SPACE, IK_SHIFT, IK_RSHIFT, IK_CAPSLOCK, IK_LBRACKET, IK_RBRACKET,
1419 IK_SEMICOLON, IK_QUOTE, IK_BACKSLASH, IK_SLASH, IK_COMMA, IK_DOT, (*IK_EQUALS,*)
1420 IK_0, IK_1, IK_2, IK_3, IK_4, IK_5, IK_6, IK_7, IK_8, IK_9, IK_MINUS, IK_EQUALS:
1421 (* see TEXTINPUT event *)
1422 end
1423 end;
1425 function GetStr(var Str: AnsiString): AnsiString;
1426 var
1427 a, b: Integer;
1428 begin
1429 Result := '';
1430 if Str[1] = '"' then
1431 begin
1432 for b := 1 to Length(Str) do
1433 if (b = Length(Str)) or (Str[b+1] = '"') then
1434 begin
1435 Result := Copy(Str, 2, b-1);
1436 Delete(Str, 1, b+1);
1437 Str := Trim(Str);
1438 Exit;
1439 end;
1440 end;
1442 for a := 1 to Length(Str) do
1443 if (a = Length(Str)) or (Str[a+1] = ' ') then
1444 begin
1445 Result := Copy(Str, 1, a);
1446 Delete(Str, 1, a+1);
1447 Str := Trim(Str);
1448 Exit;
1449 end;
1450 end;
1452 function ParseString(Str: AnsiString): SSArray;
1453 begin
1454 Result := nil;
1456 Str := Trim(Str);
1458 if Str = '' then
1459 Exit;
1461 while Str <> '' do
1462 begin
1463 SetLength(Result, Length(Result)+1);
1464 Result[High(Result)] := GetStr(Str);
1465 end;
1466 end;
1468 procedure g_Console_Add (L: AnsiString; show: Boolean=false);
1470 procedure conmsg (s: AnsiString);
1471 var
1472 a: Integer;
1473 begin
1474 if length(s) = 0 then exit;
1475 for a := 0 to High(MsgArray) do
1476 begin
1477 with MsgArray[a] do
1478 begin
1479 if Time = 0 then
1480 begin
1481 Msg := s;
1482 Time := MsgTime;
1483 exit;
1484 end;
1485 end;
1486 end;
1487 for a := 0 to High(MsgArray)-1 do MsgArray[a] := MsgArray[a+1];
1488 with MsgArray[High(MsgArray)] do
1489 begin
1490 Msg := L;
1491 Time := MsgTime;
1492 end;
1493 end;
1495 var
1496 f: Integer;
1497 begin
1498 // put it to console
1499 cbufPut(L);
1500 if (length(L) = 0) or ((L[length(L)] <> #10) and (L[length(L)] <> #13)) then cbufPut(#10);
1502 // now show 'em out of console too
1503 show := show and gAllowConsoleMessages;
1504 if show and gShowMessages then
1505 begin
1506 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1507 while length(L) > 0 do
1508 begin
1509 f := Pos(#10, L);
1510 if f <= 0 then f := length(L)+1;
1511 conmsg(Copy(L, 1, f-1));
1512 Delete(L, 1, f);
1513 end;
1514 end;
1516 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1517 //ConsoleHistory[High(ConsoleHistory)] := L;
1519 (*
1520 {$IFDEF HEADLESS}
1521 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1522 {$ENDIF}
1523 *)
1524 end;
1527 var
1528 consolewriterLastWasEOL: Boolean = false;
1530 procedure consolewriter (constref buf; len: SizeUInt);
1531 var
1532 b: PByte;
1533 begin
1534 if (len < 1) then exit;
1535 b := PByte(@buf);
1536 consolewriterLastWasEOL := (b[len-1] = 13) or (b[len-1] = 10);
1537 while (len > 0) do
1538 begin
1539 if (b[0] <> 13) and (b[0] <> 10) then
1540 begin
1541 cbufPut(AnsiChar(b[0]));
1542 end
1543 else
1544 begin
1545 if (len > 1) and (b[0] = 13) then begin len -= 1; b += 1; end;
1546 cbufPut(#10);
1547 end;
1548 len -= 1;
1549 b += 1;
1550 end;
1551 end;
1554 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1555 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1556 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1557 procedure conwriteln (const s: AnsiString; show: Boolean=false);
1558 begin
1559 g_Console_Add(s, show);
1560 end;
1563 procedure conwritefln (const s: AnsiString; args: array of const; show: Boolean=false);
1564 begin
1565 if show then
1566 begin
1567 g_Console_Add(formatstrf(s, args), true);
1568 end
1569 else
1570 begin
1571 consolewriterLastWasEOL := false;
1572 formatstrf(s, args, consolewriter);
1573 if not consolewriterLastWasEOL then cbufPut(#10);
1574 end;
1575 end;
1578 procedure g_Console_Clear();
1579 begin
1580 //ConsoleHistory := nil;
1581 cbufClear();
1582 conSkipLines := 0;
1583 end;
1585 procedure AddToHistory(L: AnsiString);
1586 var
1587 len: Integer;
1588 begin
1589 len := Length(CommandHistory);
1591 if (len = 0) or
1592 (LowerCase(CommandHistory[len-1]) <> LowerCase(L)) then
1593 begin
1594 SetLength(CommandHistory, len+1);
1595 CommandHistory[len] := L;
1596 end;
1598 CmdIndex := Length(CommandHistory);
1599 end;
1601 function g_Console_CommandBlacklisted(C: AnsiString): Boolean;
1602 var
1603 Arr: SSArray;
1604 i: Integer;
1605 begin
1606 Result := True;
1608 Arr := nil;
1610 if Trim(C) = '' then
1611 Exit;
1613 Arr := ParseString(C);
1614 if Arr = nil then
1615 Exit;
1617 for i := 0 to High(Whitelist) do
1618 if Whitelist[i] = LowerCase(Arr[0]) then
1619 Result := False;
1620 end;
1622 procedure g_Console_Process(L: AnsiString; quiet: Boolean = False);
1623 var
1624 Arr: SSArray;
1625 i: Integer;
1626 begin
1627 Arr := nil;
1629 if Trim(L) = '' then
1630 Exit;
1632 conSkipLines := 0; // "unscroll"
1634 if L = 'goobers' then
1635 begin
1636 Line := '';
1637 CPos := 1;
1638 gCheats := true;
1639 g_Console_Add('Your memory serves you well.');
1640 exit;
1641 end;
1643 if not quiet then
1644 begin
1645 g_Console_Add('> '+L);
1646 Line := '';
1647 CPos := 1;
1648 end;
1650 Arr := ParseString(L);
1651 if Arr = nil then
1652 Exit;
1654 if commands = nil then
1655 Exit;
1657 if not quiet then
1658 AddToHistory(L);
1660 for i := 0 to High(commands) do
1661 begin
1662 if commands[i].cmd = LowerCase(Arr[0]) then
1663 begin
1664 if commands[i].action >= 0 then
1665 begin
1666 gPlayerAction[commands[i].player, commands[i].action] := commands[i].cmd[1] = '+';
1667 exit
1668 end;
1669 if assigned(commands[i].procEx) then
1670 begin
1671 commands[i].procEx(@commands[i], Arr);
1672 exit
1673 end;
1674 if assigned(commands[i].proc) then
1675 begin
1676 commands[i].proc(Arr);
1677 exit
1678 end
1679 end
1680 end;
1682 g_Console_Add(Format(_lc[I_CONSOLE_UNKNOWN], [Arr[0]]));
1683 end;
1686 function g_Console_Interactive: Boolean;
1687 begin
1688 Result := gConsoleShow
1689 end;
1691 procedure g_Console_BindKey (key: Integer; down: AnsiString; up: AnsiString = '');
1692 begin
1693 // e_LogWritefln('bind "%s" "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), down, up, key]);
1694 ASSERT(key >= 0);
1695 ASSERT(key < e_MaxInputKeys);
1696 if key > 0 then
1697 begin
1698 gInputBinds[key].rep := False;
1699 gInputBinds[key].down := ParseAlias(down);
1700 gInputBinds[key].up := ParseAlias(up);
1701 end;
1702 g_Console_WriteGameConfig();
1703 end;
1705 function g_Console_MatchBind (key: Integer; down: AnsiString; up: AnsiString = ''): Boolean;
1707 function EqualsCommandLists (a, b: SSArray): Boolean;
1708 var i, len: Integer;
1709 begin
1710 result := False;
1711 len := Length(a);
1712 if len = Length(b) then
1713 begin
1714 i := 0;
1715 while (i < len) and (a[i] = b[i]) do inc(i);
1716 if i >= len then
1717 result := True
1718 end
1719 end;
1721 begin
1722 ASSERT(key >= 0);
1723 ASSERT(key < e_MaxInputKeys);
1724 result := EqualsCommandLists(ParseAlias(down), gInputBinds[key].down) and EqualsCommandLists(ParseAlias(up), gInputBinds[key].up)
1725 end;
1727 function g_Console_FindBind (n: Integer; down: AnsiString; up: AnsiString = ''): Integer;
1728 var i: Integer;
1729 begin
1730 ASSERT(n >= 1);
1731 result := 0;
1732 if commands = nil then Exit;
1733 i := 0;
1734 while (n >= 1) and (i < e_MaxInputKeys) do
1735 begin
1736 if g_Console_MatchBind(i, down, up) then
1737 begin
1738 result := i;
1739 dec(n)
1740 end;
1741 inc(i)
1742 end;
1743 if n >= 1 then
1744 result := 0
1745 end;
1747 function g_Console_Action (action: Integer): Boolean;
1748 var i, len: Integer;
1749 begin
1750 ASSERT(action >= FIRST_ACTION);
1751 ASSERT(action <= LAST_ACTION);
1752 i := 0;
1753 len := Length(gPlayerAction);
1754 while (i < len) and (not gPlayerAction[i, action]) do inc(i);
1755 Result := i < len
1756 end;
1758 function BindsAllowed (key: Integer): Boolean;
1759 begin
1760 Result := False;
1761 if (not g_GUIGrabInput) and (key >= 0) and (key < e_MaxInputKeys) and ((gInputBinds[key].down <> nil) or (gInputBinds[key].up <> nil)) then
1762 begin
1763 if gChatShow then
1764 Result := g_Console_MatchBind(key, 'togglemenu') or
1765 g_Console_MatchBind(key, 'showkeyboard') or
1766 g_Console_MatchBind(key, 'hidekeyboard')
1767 else if gConsoleShow or (g_ActiveWindow <> nil) or (gGameSettings.GameType = GT_NONE) then
1768 Result := g_Console_MatchBind(key, 'togglemenu') or
1769 g_Console_MatchBind(key, 'toggleconsole') or
1770 g_Console_MatchBind(key, 'showkeyboard') or
1771 g_Console_MatchBind(key, 'hidekeyboard')
1772 else (* in game *)
1773 Result := True
1774 end
1775 end;
1777 procedure g_Console_ProcessBind (key: Integer; down: Boolean);
1778 var i: Integer;
1779 begin
1780 if BindsAllowed(key) then
1781 begin
1782 if down then
1783 for i := 0 to High(gInputBinds[key].down) do
1784 g_Console_Process(gInputBinds[key].down[i], True)
1785 else
1786 for i := 0 to High(gInputBinds[key].up) do
1787 g_Console_Process(gInputBinds[key].up[i], True)
1788 end;
1789 if down and not menu_toggled then
1790 KeyPress(key);
1791 menu_toggled := False
1792 end;
1794 procedure g_Console_ProcessBindRepeat (key: Integer);
1795 var i: Integer;
1796 begin
1797 if gConsoleShow or gChatShow or (g_ActiveWindow <> nil) then
1798 begin
1799 KeyPress(key); // key repeat in menus and shit
1800 Exit;
1801 end;
1802 if BindsAllowed(key) and gInputBinds[key].rep then
1803 begin
1804 for i := 0 to High(gInputBinds[key].down) do
1805 g_Console_Process(gInputBinds[key].down[i], True);
1806 end;
1807 end;
1809 procedure g_Console_ResetBinds;
1810 var i: Integer;
1811 begin
1812 for i := 0 to e_MaxInputKeys - 1 do
1813 g_Console_BindKey(i, '', '');
1815 g_Console_BindKey(IK_GRAVE, 'toggleconsole');
1816 g_Console_BindKey(IK_ESCAPE, 'togglemenu');
1817 g_Console_BindKey(IK_A, '+p1_moveleft', '-p1_moveleft');
1818 g_Console_BindKey(IK_D, '+p1_moveright', '-p1_moveright');
1819 g_Console_BindKey(IK_W, '+p1_lookup', '-p1_lookup');
1820 g_Console_BindKey(IK_S, '+p1_lookdown', '-p1_lookdown');
1821 g_Console_BindKey(IK_SPACE, '+p1_jump', '-p1_jump');
1822 g_Console_BindKey(IK_H, '+p1_attack', '-p1_attack');
1823 g_Console_BindKey(IK_J, '+p1_activate', '-p1_activate');
1824 g_Console_BindKey(IK_E, '+p1_weapnext', '-p1_weapnext');
1825 g_Console_BindKey(IK_Q, '+p1_weapprev', '-p1_weapprev');
1826 g_Console_BindKey(IK_ALT, '+p1_strafe', '-p1_strafe');
1827 g_Console_BindKey(IK_1, 'p1_weapon 1');
1828 g_Console_BindKey(IK_2, 'p1_weapon 2');
1829 g_Console_BindKey(IK_3, 'p1_weapon 3');
1830 g_Console_BindKey(IK_4, 'p1_weapon 4');
1831 g_Console_BindKey(IK_5, 'p1_weapon 5');
1832 g_Console_BindKey(IK_6, 'p1_weapon 6');
1833 g_Console_BindKey(IK_7, 'p1_weapon 7');
1834 g_Console_BindKey(IK_8, 'p1_weapon 8');
1835 g_Console_BindKey(IK_9, 'p1_weapon 9');
1836 g_Console_BindKey(IK_0, 'p1_weapon 10');
1837 g_Console_BindKey(IK_MINUS, 'p1_weapon 11');
1838 g_Console_BindKey(IK_T, 'togglechat');
1839 g_Console_BindKey(IK_Y, 'toggleteamchat');
1840 g_Console_BindKey(IK_F11, 'screenshot');
1841 g_Console_BindKey(IK_TAB, '+p1_scores', '-p1_scores');
1842 g_Console_BindKey(IK_PAUSE, 'pause');
1843 g_Console_BindKey(IK_F1, 'vote');
1845 (* for i := 0 to e_MaxJoys - 1 do *)
1846 for i := 0 to 1 do
1847 begin
1848 g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_LEFT), '+p' + IntToStr(i mod 2 + 1) + '_moveleft', '-p' + IntToStr(i mod 2 + 1) + '_moveleft');
1849 g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_RIGHT), '+p' + IntToStr(i mod 2 + 1) + '_moveright', '-p' + IntToStr(i mod 2 + 1) + '_moveright');
1850 g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_UP), '+p' + IntToStr(i mod 2 + 1) + '_lookup', '-p' + IntToStr(i mod 2 + 1) + '_lookup');
1851 g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_DOWN), '+p' + IntToStr(i mod 2 + 1) + '_lookdown', '-p' + IntToStr(i mod 2 + 1) + '_lookdown');
1852 g_Console_BindKey(e_JoyButtonToKey(i, 2), '+p' + IntToStr(i mod 2 + 1) + '_jump', '-p' + IntToStr(i mod 2 + 1) + '_jump');
1853 g_Console_BindKey(e_JoyButtonToKey(i, 0), '+p' + IntToStr(i mod 2 + 1) + '_attack', '-p' + IntToStr(i mod 2 + 1) + '_attack');
1854 g_Console_BindKey(e_JoyButtonToKey(i, 3), '+p' + IntToStr(i mod 2 + 1) + '_activate', '-p' + IntToStr(i mod 2 + 1) + '_activate');
1855 g_Console_BindKey(e_JoyButtonToKey(i, 1), '+p' + IntToStr(i mod 2 + 1) + '_weapnext', '-p' + IntToStr(i mod 2 + 1) + '_weapnext');
1856 g_Console_BindKey(e_JoyButtonToKey(i, 4), '+p' + IntToStr(i mod 2 + 1) + '_weapprev', '-p' + IntToStr(i mod 2 + 1) + '_weapprev');
1857 g_Console_BindKey(e_JoyButtonToKey(i, 7), '+p' + IntToStr(i mod 2 + 1) + '_strafe', '-p' + IntToStr(i mod 2 + 1) + '_strafe');
1858 g_Console_BindKey(e_JoyButtonToKey(i, 10), 'togglemenu');
1859 end;
1861 g_Console_BindKey(VK_ESCAPE, 'togglemenu');
1862 g_Console_BindKey(VK_LSTRAFE, '+moveleft; +strafe', '-moveleft; -strafe');
1863 g_Console_BindKey(VK_RSTRAFE, '+moveright; +strafe', '-moveright; -strafe');
1864 g_Console_BindKey(VK_LEFT, '+moveleft', '-moveleft');
1865 g_Console_BindKey(VK_RIGHT, '+moveright', '-moveright');
1866 g_Console_BindKey(VK_UP, '+lookup', '-lookup');
1867 g_Console_BindKey(VK_DOWN, '+lookdown', '-lookdown');
1868 g_Console_BindKey(VK_JUMP, '+jump', '-jump');
1869 g_Console_BindKey(VK_FIRE, '+attack', '-attack');
1870 g_Console_BindKey(VK_OPEN, '+activate', '-activate');
1871 g_Console_BindKey(VK_NEXT, '+weapnext', '-weapnext');
1872 g_Console_BindKey(VK_PREV, '+weapprev', '-weapprev');
1873 g_Console_BindKey(VK_STRAFE, '+strafe', '-strafe');
1874 g_Console_BindKey(VK_0, 'weapon 1');
1875 g_Console_BindKey(VK_1, 'weapon 2');
1876 g_Console_BindKey(VK_2, 'weapon 3');
1877 g_Console_BindKey(VK_3, 'weapon 4');
1878 g_Console_BindKey(VK_4, 'weapon 5');
1879 g_Console_BindKey(VK_5, 'weapon 6');
1880 g_Console_BindKey(VK_6, 'weapon 7');
1881 g_Console_BindKey(VK_7, 'weapon 8');
1882 g_Console_BindKey(VK_8, 'weapon 9');
1883 g_Console_BindKey(VK_9, 'weapon 10');
1884 g_Console_BindKey(VK_A, 'weapon 11');
1885 g_Console_BindKey(VK_CHAT, 'togglechat');
1886 g_Console_BindKey(VK_TEAM, 'toggleteamchat');
1887 g_Console_BindKey(VK_CONSOLE, 'toggleconsole');
1888 g_Console_BindKey(VK_PRINTSCR, 'screenshot');
1889 g_Console_BindKey(VK_STATUS, '+scores', '-scores');
1890 g_Console_BindKey(VK_SHOWKBD, 'showkeyboard');
1891 g_Console_BindKey(VK_HIDEKBD, 'hidekeyboard');
1892 end;
1894 procedure g_Console_ReadConfig (filename: String);
1895 var f: TextFile; s: AnsiString; i, len: Integer;
1896 begin
1897 e_LogWritefln('g_Console_ReadConfig (1) "%s"', [filename]);
1898 if e_FindResource(ConfigDirs, filename, false) = true then
1899 begin
1900 e_LogWritefln('g_Console_ReadConfig (2) "%s"', [filename]);
1901 AssignFile(f, filename);
1902 Reset(f);
1903 while not EOF(f) do
1904 begin
1905 ReadLn(f, s);
1906 len := Length(s);
1907 if len > 0 then
1908 begin
1909 i := 1;
1910 (* skip spaces *)
1911 while (i <= len) and (s[i] <= ' ') do inc(i);
1912 (* skip comments *)
1913 if (i <= len) and ((s[i] <> '#') and ((i + 1 > len) or (s[i] <> '/') or (s[i + 1] <> '/'))) then
1914 g_Console_Process(s, True);
1915 end
1916 end;
1917 CloseFile(f);
1918 end
1919 end;
1921 procedure g_Console_WriteConfig (filename: String);
1922 var f: TextFile; i, j: Integer;
1924 procedure WriteFlag(name: string; flag: LongWord);
1925 begin
1926 WriteLn(f, name, IfThen(LongBool(gsGameFlags and flag), 1, 0));
1927 end;
1929 function FormatTeam(team: Byte): string;
1930 begin
1931 if team = TEAM_BLUE then
1932 result := 'blue'
1933 else
1934 result := 'red';
1935 end;
1937 begin
1938 // e_LogWritefln('g_Console_WriteConfig: %s', [filename]);
1939 AssignFile(f, filename);
1940 Rewrite(f);
1941 WriteLn(f, '// ' + configComment);
1943 // binds
1944 WriteLn(f, 'unbindall');
1945 for i := 0 to e_MaxInputKeys - 1 do
1946 if (Length(gInputBinds[i].down) > 0) or (Length(gInputBinds[i].up) > 0) then
1947 begin
1948 Write(f, 'bind ', e_KeyNames[i], ' ', QuoteStr(GetCommandString(gInputBinds[i].down)));
1949 if Length(gInputBinds[i].down) = 0 then
1950 Write(f, '""');
1951 if Length(gInputBinds[i].up) > 0 then
1952 Write(f, ' ', QuoteStr(GetCommandString(gInputBinds[i].up)));
1953 WriteLn(f, '');
1954 if gInputBinds[i].rep then
1955 WriteLn(f, 'bindrep ', e_KeyNames[i]);
1956 end;
1958 // lang
1959 if gAskLanguage then
1960 WriteLn(f, 'g_language ask')
1961 else
1962 WriteLn(f, 'g_language ', gLanguage);
1964 // net server
1965 WriteLn(f, 'sv_name ', QuoteStr(NetServerName));
1966 WriteLn(f, 'sv_passwd ', QuoteStr(NetPassword));
1967 WriteLn(f, 'sv_maxplrs ', NetMaxClients);
1968 WriteLn(f, 'sv_port ', NetPort);
1969 WriteLn(f, 'sv_public ', IfThen(NetUseMaster, 1, 0));
1971 // game settings
1972 WriteLn(f, 'g_max_particles ', g_GFX_GetMax());
1973 WriteLn(f, 'g_max_shells ', g_Shells_GetMax());
1974 WriteLn(f, 'g_max_gibs ', g_Gibs_GetMax());
1975 WriteLn(f, 'g_max_corpses ', g_Corpses_GetMax());
1976 WriteLn(f, 'sv_intertime ', gDefInterTime);
1978 // gameplay settings
1979 WriteLn(f, 'g_gamemode ', gsGameMode);
1980 WriteLn(f, 'g_scorelimit ', gsGoalLimit);
1981 WriteLn(f, 'g_timelimit ', gsTimeLimit);
1982 WriteLn(f, 'g_maxlives ', gsMaxLives);
1983 WriteLn(f, 'g_item_respawn_time ', gsItemRespawnTime);
1984 WriteLn(f, 'g_spawn_invul ', gsSpawnInvul);
1985 WriteLn(f, 'g_warmup_time ', gsWarmupTime);
1987 WriteFlag('g_friendlyfire ', GAME_OPTION_TEAMDAMAGE);
1988 WriteFlag('g_friendly_hit_trace ', GAME_OPTION_TEAMHITTRACE);
1989 WriteFlag('g_friendly_hit_projectile ', GAME_OPTION_TEAMHITPROJECTILE);
1990 WriteFlag('g_allow_exit ', GAME_OPTION_ALLOWEXIT);
1991 WriteFlag('g_allow_monsters ', GAME_OPTION_MONSTERS);
1992 WriteFlag('g_dm_keys ', GAME_OPTION_DMKEYS);
1993 WriteFlag('g_weaponstay ', GAME_OPTION_WEAPONSTAY);
1994 WriteFlag('g_bot_vsmonsters ', GAME_OPTION_BOTVSMONSTER);
1995 WriteFlag('g_bot_vsplayers ', GAME_OPTION_BOTVSPLAYER);
1997 // players
1998 with gPlayer1Settings do
1999 begin
2000 WriteLn(f, 'p1_name ', QuoteStr(Name));
2001 WriteLn(f, 'p1_color ', Color.R, ' ', Color.G, ' ', Color.B);
2002 WriteLn(f, 'p1_model ', QuoteStr(Model));
2003 WriteLn(f, 'p1_team ', FormatTeam(Team));
2004 end;
2005 with gPlayer2Settings do
2006 begin
2007 WriteLn(f, 'p2_name ', QuoteStr(Name));
2008 WriteLn(f, 'p2_color ', Color.R, ' ', Color.G, ' ', Color.B);
2009 WriteLn(f, 'p2_model ', QuoteStr(Model));
2010 WriteLn(f, 'p2_team ', FormatTeam(Team));
2011 end;
2013 // all cvars
2014 for i := 0 to High(commands) do
2015 begin
2016 if not commands[i].cheat then
2017 begin
2018 if @commands[i].procEx = @boolVarHandler then
2019 begin
2020 if PBoolean(commands[i].ptr)^ then j := 1 else j := 0;
2021 WriteLn(f, commands[i].cmd, ' ', j)
2022 end
2023 else if @commands[i].procEx = @intVarHandler then
2024 begin
2025 WriteLn(f, commands[i].cmd, ' ', PInteger(commands[i].ptr)^)
2026 end
2027 else if @commands[i].procEx = @wordVarHandler then
2028 begin
2029 WriteLn(f, commands[i].cmd, ' ', PWord(commands[i].ptr)^)
2030 end
2031 else if @commands[i].procEx = @dwordVarHandler then
2032 begin
2033 WriteLn(f, commands[i].cmd, ' ', PCardinal(commands[i].ptr)^)
2034 end
2035 else if @commands[i].procEx = @singleVarHandler then
2036 begin
2037 WriteLn(f, commands[i].cmd, ' ', PVarSingle(commands[i].ptr).val^:0:6)
2038 end
2039 else if @commands[i].procEx = @strVarHandler then
2040 begin
2041 if Length(PAnsiString(commands[i].ptr)^) = 0 then
2042 WriteLn(f, commands[i].cmd, ' ""')
2043 else
2044 WriteLn(f, commands[i].cmd, ' ', QuoteStr(PAnsiString(commands[i].ptr)^))
2045 end
2046 end
2047 end;
2049 WriteLn(f, 'r_maxfps ', gMaxFPS);
2050 WriteLn(f, 'r_reset');
2051 CloseFile(f)
2052 end;
2054 procedure g_Console_WriteGameConfig;
2055 var s: AnsiString;
2056 begin
2057 if gParsingBinds = false then
2058 begin
2059 s := e_GetWriteableDir(ConfigDirs);
2060 g_Console_WriteConfig(e_CatPath(s, gConfigScript))
2061 end
2062 end;
2064 procedure Init;
2065 var i: Integer;
2066 begin
2067 conRegVar('d_eres', @debug_e_res, '', '');
2068 for i := 1 to e_MaxJoys do
2069 conRegVar('joy' + IntToStr(i) + '_deadzone', @e_JoystickDeadzones[i - 1], '', '')
2070 end;
2072 initialization
2073 Init
2074 end.