DEADSOFTWARE

cleanup: remove g_main.pas
[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_SysInit;
50 procedure g_Console_Update;
51 procedure g_Console_Char (C: AnsiChar);
52 procedure g_Console_Control (K: Word);
53 procedure g_Console_Process (L: AnsiString; quiet: Boolean=false);
54 procedure g_Console_Add (L: AnsiString; show: Boolean=false);
55 procedure g_Console_Clear;
56 function g_Console_CommandBlacklisted (C: AnsiString): Boolean;
57 procedure g_Console_ReadConfig (filename: String);
58 procedure g_Console_WriteConfig (filename: String);
59 procedure g_Console_WriteGameConfig;
61 function g_Console_Interactive: Boolean;
62 function g_Console_Action (action: Integer): Boolean;
63 function g_Console_MatchBind (key: Integer; down: AnsiString; up: AnsiString = ''): Boolean;
64 function g_Console_FindBind (n: Integer; down: AnsiString; up: AnsiString = ''): Integer;
65 procedure g_Console_BindKey (key: Integer; down: AnsiString; up: AnsiString = '');
66 procedure g_Console_ProcessBind (key: Integer; down: Boolean);
67 procedure g_Console_ProcessBindRepeat (key: Integer);
68 procedure g_Console_ResetBinds;
70 procedure conwriteln (const s: AnsiString; show: Boolean=false);
71 procedure conwritefln (const s: AnsiString; args: array of const; show: Boolean=false);
73 procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
74 procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
75 procedure conRegVar (const conname: AnsiString; pvar: PInteger; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
76 procedure conRegVar (const conname: AnsiString; pvar: PWord; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
77 procedure conRegVar (const conname: AnsiString; pvar: PCardinal; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
78 procedure conRegVar (const conname: AnsiString; pvar: PAnsiString; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
80 // <0: no arg; 0/1: true/false
81 function conGetBoolArg (p: SSArray; idx: Integer): Integer;
83 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
84 function conParseFloat (var res: Single; const s: AnsiString): Boolean;
86 const
87 defaultConfigScript = 'dfconfig.cfg';
89 var
90 gConsoleShow: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
91 gChatShow: Boolean = false;
92 gChatTeam: Boolean = false;
93 gAllowConsoleMessages: Boolean = true;
94 gJustChatted: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
95 gParsingBinds: Boolean = true; // íå ïåðåñîõðàíÿòü êîíôèã âî âðåìÿ ïàðñèíãà
96 gPlayerAction: Array [0..1, 0..LAST_ACTION] of Boolean; // [player, action]
97 gConfigScript: string = defaultConfigScript;
99 implementation
101 uses
102 g_textures, e_input, g_game, g_gfx, g_player, g_items,
103 SysUtils, g_basic, g_options, Math, g_touch, e_res,
104 g_menu, g_gui, g_language, g_net, g_netmsg, e_log, conbuf;
106 const
107 autoexecScript = 'autoexec.cfg';
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_SysInit;
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 gParsingBinds := False;
1163 end;
1165 procedure g_Console_Init;
1166 begin
1167 g_Console_Add(Format(_lc[I_CONSOLE_WELCOME], [GAME_VERSION]));
1168 g_Console_Add('');
1169 end;
1171 procedure g_Console_Update;
1172 var
1173 a, b: Integer;
1174 begin
1175 InputReady := gConsoleShow or gChatShow;
1177 a := 0;
1178 while a <= High(MsgArray) do
1179 begin
1180 if MsgArray[a].Time > 0 then
1181 begin
1182 if MsgArray[a].Time = 1 then
1183 begin
1184 if a < High(MsgArray) then
1185 begin
1186 for b := a to High(MsgArray)-1 do
1187 MsgArray[b] := MsgArray[b+1];
1189 MsgArray[High(MsgArray)].Time := 0;
1191 a := a - 1;
1192 end;
1193 end
1194 else
1195 Dec(MsgArray[a].Time);
1196 end;
1198 a := a + 1;
1199 end;
1200 end;
1202 procedure g_Console_Char(C: AnsiChar);
1203 begin
1204 if InputReady and (gConsoleShow or gChatShow) then
1205 begin
1206 Insert(C, Line, CPos);
1207 CPos := CPos + 1;
1208 end
1209 end;
1212 var
1213 tcomplist: array of AnsiString = nil;
1214 tcompidx: array of Integer = nil;
1216 procedure Complete ();
1217 var
1218 i, c: Integer;
1219 tused: Integer;
1220 ll, lpfx, cmd: AnsiString;
1221 begin
1222 if (Length(Line) = 0) then
1223 begin
1224 g_Console_Add('');
1225 for i := 0 to High(commands) do
1226 begin
1227 // hidden commands are hidden when cheats aren't enabled
1228 if commands[i].hidden and not conIsCheatsEnabled then continue;
1229 if (Length(commands[i].help) > 0) then
1230 begin
1231 g_Console_Add(' '+commands[i].cmd+' -- '+commands[i].help);
1232 end
1233 else
1234 begin
1235 g_Console_Add(' '+commands[i].cmd);
1236 end;
1237 end;
1238 exit;
1239 end;
1241 ll := LowerCase(Line);
1242 lpfx := '';
1244 if (Length(ll) > 1) and (ll[Length(ll)] = ' ') then
1245 begin
1246 ll := Copy(ll, 0, Length(ll)-1);
1247 for i := 0 to High(commands) do
1248 begin
1249 // hidden commands are hidden when cheats aren't enabled
1250 if commands[i].hidden and not conIsCheatsEnabled then continue;
1251 if (commands[i].cmd = ll) then
1252 begin
1253 if (Length(commands[i].help) > 0) then
1254 begin
1255 g_Console_Add(' '+commands[i].cmd+' -- '+commands[i].help);
1256 end;
1257 end;
1258 end;
1259 exit;
1260 end;
1262 // build completion list
1263 tused := 0;
1264 for i := 0 to High(commands) do
1265 begin
1266 // hidden commands are hidden when cheats aren't enabled
1267 if commands[i].hidden and not conIsCheatsEnabled then continue;
1268 cmd := commands[i].cmd;
1269 if (Length(cmd) >= Length(ll)) and (ll = Copy(cmd, 0, Length(ll))) then
1270 begin
1271 if (tused = Length(tcomplist)) then
1272 begin
1273 SetLength(tcomplist, Length(tcomplist)+128);
1274 SetLength(tcompidx, Length(tcompidx)+128);
1275 end;
1276 tcomplist[tused] := cmd;
1277 tcompidx[tused] := i;
1278 Inc(tused);
1279 if (Length(cmd) > Length(lpfx)) then lpfx := cmd;
1280 end;
1281 end;
1283 // get longest prefix
1284 for i := 0 to tused-1 do
1285 begin
1286 cmd := tcomplist[i];
1287 for c := 1 to Length(lpfx) do
1288 begin
1289 if (c > Length(cmd)) then break;
1290 if (cmd[c] <> lpfx[c]) then begin lpfx := Copy(lpfx, 0, c-1); break; end;
1291 end;
1292 end;
1294 if (tused = 0) then exit;
1296 if (tused = 1) then
1297 begin
1298 Line := tcomplist[0]+' ';
1299 CPos := Length(Line)+1;
1300 end
1301 else
1302 begin
1303 // has longest prefix?
1304 if (Length(lpfx) > Length(ll)) then
1305 begin
1306 Line := lpfx;
1307 CPos:= Length(Line)+1;
1308 end
1309 else
1310 begin
1311 g_Console_Add('');
1312 for i := 0 to tused-1 do
1313 begin
1314 if (Length(commands[tcompidx[i]].help) > 0) then
1315 begin
1316 g_Console_Add(' '+tcomplist[i]+' -- '+commands[tcompidx[i]].help);
1317 end
1318 else
1319 begin
1320 g_Console_Add(' '+tcomplist[i]);
1321 end;
1322 end;
1323 end;
1324 end;
1325 end;
1328 procedure g_Console_Control(K: Word);
1329 begin
1330 case K of
1331 IK_BACKSPACE:
1332 if (Length(Line) > 0) and (CPos > 1) then
1333 begin
1334 Delete(Line, CPos-1, 1);
1335 CPos := CPos-1;
1336 end;
1337 IK_DELETE:
1338 if (Length(Line) > 0) and (CPos <= Length(Line)) then
1339 Delete(Line, CPos, 1);
1340 IK_LEFT, IK_KPLEFT, VK_LEFT, JOY0_LEFT, JOY1_LEFT, JOY2_LEFT, JOY3_LEFT:
1341 if CPos > 1 then
1342 CPos := CPos - 1;
1343 IK_RIGHT, IK_KPRIGHT, VK_RIGHT, JOY0_RIGHT, JOY1_RIGHT, JOY2_RIGHT, JOY3_RIGHT:
1344 if CPos <= Length(Line) then
1345 CPos := CPos + 1;
1346 IK_RETURN, IK_KPRETURN, VK_OPEN, VK_FIRE, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK:
1347 begin
1348 if gConsoleShow then
1349 g_Console_Process(Line)
1350 else
1351 if gChatShow then
1352 begin
1353 if (Length(Line) > 0) and g_Game_IsNet then
1354 begin
1355 if gChatTeam then
1356 begin
1357 if g_Game_IsClient then
1358 MC_SEND_Chat(b_Text_Format(Line), NET_CHAT_TEAM)
1359 else
1360 MH_SEND_Chat('[' + gPlayer1Settings.name + ']: ' + b_Text_Format(Line),
1361 NET_CHAT_TEAM, gPlayer1Settings.Team);
1362 end
1363 else
1364 begin
1365 if g_Game_IsClient then
1366 MC_SEND_Chat(b_Text_Format(Line), NET_CHAT_PLAYER)
1367 else
1368 MH_SEND_Chat('[' + gPlayer1Settings.name + ']: ' + b_Text_Format(Line),
1369 NET_CHAT_PLAYER);
1370 end;
1371 end;
1373 Line := '';
1374 CPos := 1;
1375 gJustChatted := True;
1376 g_Console_Chat_Switch;
1377 InputReady := False;
1378 end;
1379 end;
1380 IK_TAB:
1381 if not gChatShow then
1382 Complete();
1383 IK_DOWN, IK_KPDOWN, VK_DOWN, JOY0_DOWN, JOY1_DOWN, JOY2_DOWN, JOY3_DOWN:
1384 if not gChatShow then
1385 if (CommandHistory <> nil) and
1386 (CmdIndex < Length(CommandHistory)) then
1387 begin
1388 if CmdIndex < Length(CommandHistory)-1 then
1389 CmdIndex := CmdIndex + 1;
1390 Line := CommandHistory[CmdIndex];
1391 CPos := Length(Line) + 1;
1392 end;
1393 IK_UP, IK_KPUP, VK_UP, JOY0_UP, JOY1_UP, JOY2_UP, JOY3_UP:
1394 if not gChatShow then
1395 if (CommandHistory <> nil) and
1396 (CmdIndex <= Length(CommandHistory)) then
1397 begin
1398 if CmdIndex > 0 then
1399 CmdIndex := CmdIndex - 1;
1400 Line := CommandHistory[CmdIndex];
1401 Cpos := Length(Line) + 1;
1402 end;
1403 IK_PAGEUP, IK_KPPAGEUP, VK_PREV, JOY0_PREV, JOY1_PREV, JOY2_PREV, JOY3_PREV: // PgUp
1404 if not gChatShow then Inc(conSkipLines);
1405 IK_PAGEDN, IK_KPPAGEDN, VK_NEXT, JOY0_NEXT, JOY1_NEXT, JOY2_NEXT, JOY3_NEXT: // PgDown
1406 if not gChatShow and (conSkipLines > 0) then Dec(conSkipLines);
1407 IK_HOME, IK_KPHOME:
1408 CPos := 1;
1409 IK_END, IK_KPEND:
1410 CPos := Length(Line) + 1;
1411 IK_A..IK_Z, IK_SPACE, IK_SHIFT, IK_RSHIFT, IK_CAPSLOCK, IK_LBRACKET, IK_RBRACKET,
1412 IK_SEMICOLON, IK_QUOTE, IK_BACKSLASH, IK_SLASH, IK_COMMA, IK_DOT, (*IK_EQUALS,*)
1413 IK_0, IK_1, IK_2, IK_3, IK_4, IK_5, IK_6, IK_7, IK_8, IK_9, IK_MINUS, IK_EQUALS:
1414 (* see TEXTINPUT event *)
1415 end
1416 end;
1418 function GetStr(var Str: AnsiString): AnsiString;
1419 var
1420 a, b: Integer;
1421 begin
1422 Result := '';
1423 if Str[1] = '"' then
1424 begin
1425 for b := 1 to Length(Str) do
1426 if (b = Length(Str)) or (Str[b+1] = '"') then
1427 begin
1428 Result := Copy(Str, 2, b-1);
1429 Delete(Str, 1, b+1);
1430 Str := Trim(Str);
1431 Exit;
1432 end;
1433 end;
1435 for a := 1 to Length(Str) do
1436 if (a = Length(Str)) or (Str[a+1] = ' ') then
1437 begin
1438 Result := Copy(Str, 1, a);
1439 Delete(Str, 1, a+1);
1440 Str := Trim(Str);
1441 Exit;
1442 end;
1443 end;
1445 function ParseString(Str: AnsiString): SSArray;
1446 begin
1447 Result := nil;
1449 Str := Trim(Str);
1451 if Str = '' then
1452 Exit;
1454 while Str <> '' do
1455 begin
1456 SetLength(Result, Length(Result)+1);
1457 Result[High(Result)] := GetStr(Str);
1458 end;
1459 end;
1461 procedure g_Console_Add (L: AnsiString; show: Boolean=false);
1463 procedure conmsg (s: AnsiString);
1464 var
1465 a: Integer;
1466 begin
1467 if length(s) = 0 then exit;
1468 for a := 0 to High(MsgArray) do
1469 begin
1470 with MsgArray[a] do
1471 begin
1472 if Time = 0 then
1473 begin
1474 Msg := s;
1475 Time := MsgTime;
1476 exit;
1477 end;
1478 end;
1479 end;
1480 for a := 0 to High(MsgArray)-1 do MsgArray[a] := MsgArray[a+1];
1481 with MsgArray[High(MsgArray)] do
1482 begin
1483 Msg := L;
1484 Time := MsgTime;
1485 end;
1486 end;
1488 var
1489 f: Integer;
1490 begin
1491 // put it to console
1492 cbufPut(L);
1493 if (length(L) = 0) or ((L[length(L)] <> #10) and (L[length(L)] <> #13)) then cbufPut(#10);
1495 // now show 'em out of console too
1496 show := show and gAllowConsoleMessages;
1497 if show and gShowMessages then
1498 begin
1499 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1500 while length(L) > 0 do
1501 begin
1502 f := Pos(#10, L);
1503 if f <= 0 then f := length(L)+1;
1504 conmsg(Copy(L, 1, f-1));
1505 Delete(L, 1, f);
1506 end;
1507 end;
1509 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1510 //ConsoleHistory[High(ConsoleHistory)] := L;
1512 (*
1513 {$IFDEF HEADLESS}
1514 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1515 {$ENDIF}
1516 *)
1517 end;
1520 var
1521 consolewriterLastWasEOL: Boolean = false;
1523 procedure consolewriter (constref buf; len: SizeUInt);
1524 var
1525 b: PByte;
1526 begin
1527 if (len < 1) then exit;
1528 b := PByte(@buf);
1529 consolewriterLastWasEOL := (b[len-1] = 13) or (b[len-1] = 10);
1530 while (len > 0) do
1531 begin
1532 if (b[0] <> 13) and (b[0] <> 10) then
1533 begin
1534 cbufPut(AnsiChar(b[0]));
1535 end
1536 else
1537 begin
1538 if (len > 1) and (b[0] = 13) then begin len -= 1; b += 1; end;
1539 cbufPut(#10);
1540 end;
1541 len -= 1;
1542 b += 1;
1543 end;
1544 end;
1547 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1548 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1549 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1550 procedure conwriteln (const s: AnsiString; show: Boolean=false);
1551 begin
1552 g_Console_Add(s, show);
1553 end;
1556 procedure conwritefln (const s: AnsiString; args: array of const; show: Boolean=false);
1557 begin
1558 if show then
1559 begin
1560 g_Console_Add(formatstrf(s, args), true);
1561 end
1562 else
1563 begin
1564 consolewriterLastWasEOL := false;
1565 formatstrf(s, args, consolewriter);
1566 if not consolewriterLastWasEOL then cbufPut(#10);
1567 end;
1568 end;
1571 procedure g_Console_Clear();
1572 begin
1573 //ConsoleHistory := nil;
1574 cbufClear();
1575 conSkipLines := 0;
1576 end;
1578 procedure AddToHistory(L: AnsiString);
1579 var
1580 len: Integer;
1581 begin
1582 len := Length(CommandHistory);
1584 if (len = 0) or
1585 (LowerCase(CommandHistory[len-1]) <> LowerCase(L)) then
1586 begin
1587 SetLength(CommandHistory, len+1);
1588 CommandHistory[len] := L;
1589 end;
1591 CmdIndex := Length(CommandHistory);
1592 end;
1594 function g_Console_CommandBlacklisted(C: AnsiString): Boolean;
1595 var
1596 Arr: SSArray;
1597 i: Integer;
1598 begin
1599 Result := True;
1601 Arr := nil;
1603 if Trim(C) = '' then
1604 Exit;
1606 Arr := ParseString(C);
1607 if Arr = nil then
1608 Exit;
1610 for i := 0 to High(Whitelist) do
1611 if Whitelist[i] = LowerCase(Arr[0]) then
1612 Result := False;
1613 end;
1615 procedure g_Console_Process(L: AnsiString; quiet: Boolean = False);
1616 var
1617 Arr: SSArray;
1618 i: Integer;
1619 begin
1620 Arr := nil;
1622 if Trim(L) = '' then
1623 Exit;
1625 conSkipLines := 0; // "unscroll"
1627 if L = 'goobers' then
1628 begin
1629 Line := '';
1630 CPos := 1;
1631 gCheats := true;
1632 g_Console_Add('Your memory serves you well.');
1633 exit;
1634 end;
1636 if not quiet then
1637 begin
1638 g_Console_Add('> '+L);
1639 Line := '';
1640 CPos := 1;
1641 end;
1643 Arr := ParseString(L);
1644 if Arr = nil then
1645 Exit;
1647 if commands = nil then
1648 Exit;
1650 if not quiet then
1651 AddToHistory(L);
1653 for i := 0 to High(commands) do
1654 begin
1655 if commands[i].cmd = LowerCase(Arr[0]) then
1656 begin
1657 if commands[i].action >= 0 then
1658 begin
1659 gPlayerAction[commands[i].player, commands[i].action] := commands[i].cmd[1] = '+';
1660 exit
1661 end;
1662 if assigned(commands[i].procEx) then
1663 begin
1664 commands[i].procEx(@commands[i], Arr);
1665 exit
1666 end;
1667 if assigned(commands[i].proc) then
1668 begin
1669 commands[i].proc(Arr);
1670 exit
1671 end
1672 end
1673 end;
1675 g_Console_Add(Format(_lc[I_CONSOLE_UNKNOWN], [Arr[0]]));
1676 end;
1679 function g_Console_Interactive: Boolean;
1680 begin
1681 Result := gConsoleShow
1682 end;
1684 procedure g_Console_BindKey (key: Integer; down: AnsiString; up: AnsiString = '');
1685 begin
1686 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1687 ASSERT(key >= 0);
1688 ASSERT(key < e_MaxInputKeys);
1689 if key > 0 then
1690 begin
1691 gInputBinds[key].rep := False;
1692 gInputBinds[key].down := ParseAlias(down);
1693 gInputBinds[key].up := ParseAlias(up);
1694 end;
1695 g_Console_WriteGameConfig();
1696 end;
1698 function g_Console_MatchBind (key: Integer; down: AnsiString; up: AnsiString = ''): Boolean;
1700 function EqualsCommandLists (a, b: SSArray): Boolean;
1701 var i, len: Integer;
1702 begin
1703 result := False;
1704 len := Length(a);
1705 if len = Length(b) then
1706 begin
1707 i := 0;
1708 while (i < len) and (a[i] = b[i]) do inc(i);
1709 if i >= len then
1710 result := True
1711 end
1712 end;
1714 begin
1715 ASSERT(key >= 0);
1716 ASSERT(key < e_MaxInputKeys);
1717 result := EqualsCommandLists(ParseAlias(down), gInputBinds[key].down) and EqualsCommandLists(ParseAlias(up), gInputBinds[key].up)
1718 end;
1720 function g_Console_FindBind (n: Integer; down: AnsiString; up: AnsiString = ''): Integer;
1721 var i: Integer;
1722 begin
1723 ASSERT(n >= 1);
1724 result := 0;
1725 if commands = nil then Exit;
1726 i := 0;
1727 while (n >= 1) and (i < e_MaxInputKeys) do
1728 begin
1729 if g_Console_MatchBind(i, down, up) then
1730 begin
1731 result := i;
1732 dec(n)
1733 end;
1734 inc(i)
1735 end;
1736 if n >= 1 then
1737 result := 0
1738 end;
1740 function g_Console_Action (action: Integer): Boolean;
1741 var i, len: Integer;
1742 begin
1743 ASSERT(action >= FIRST_ACTION);
1744 ASSERT(action <= LAST_ACTION);
1745 i := 0;
1746 len := Length(gPlayerAction);
1747 while (i < len) and (not gPlayerAction[i, action]) do inc(i);
1748 Result := i < len
1749 end;
1751 function BindsAllowed (key: Integer): Boolean;
1752 begin
1753 Result := False;
1754 if (not g_GUIGrabInput) and (key >= 0) and (key < e_MaxInputKeys) and ((gInputBinds[key].down <> nil) or (gInputBinds[key].up <> nil)) then
1755 begin
1756 if gChatShow then
1757 Result := g_Console_MatchBind(key, 'togglemenu') or
1758 g_Console_MatchBind(key, 'showkeyboard') or
1759 g_Console_MatchBind(key, 'hidekeyboard')
1760 else if gConsoleShow or (g_ActiveWindow <> nil) or (gGameSettings.GameType = GT_NONE) then
1761 Result := g_Console_MatchBind(key, 'togglemenu') or
1762 g_Console_MatchBind(key, 'toggleconsole') or
1763 g_Console_MatchBind(key, 'showkeyboard') or
1764 g_Console_MatchBind(key, 'hidekeyboard')
1765 else (* in game *)
1766 Result := True
1767 end
1768 end;
1770 procedure g_Console_ProcessBind (key: Integer; down: Boolean);
1771 var i: Integer;
1772 begin
1773 if BindsAllowed(key) then
1774 begin
1775 if down then
1776 for i := 0 to High(gInputBinds[key].down) do
1777 g_Console_Process(gInputBinds[key].down[i], True)
1778 else
1779 for i := 0 to High(gInputBinds[key].up) do
1780 g_Console_Process(gInputBinds[key].up[i], True)
1781 end;
1782 if down and not menu_toggled then
1783 KeyPress(key);
1784 menu_toggled := False
1785 end;
1787 procedure g_Console_ProcessBindRepeat (key: Integer);
1788 var i: Integer;
1789 begin
1790 if gConsoleShow or gChatShow or (g_ActiveWindow <> nil) then
1791 begin
1792 KeyPress(key); // key repeat in menus and shit
1793 Exit;
1794 end;
1795 if BindsAllowed(key) and gInputBinds[key].rep then
1796 begin
1797 for i := 0 to High(gInputBinds[key].down) do
1798 g_Console_Process(gInputBinds[key].down[i], True);
1799 end;
1800 end;
1802 procedure g_Console_ResetBinds;
1803 var i: Integer;
1804 begin
1805 for i := 0 to e_MaxInputKeys - 1 do
1806 g_Console_BindKey(i, '', '');
1808 g_Console_BindKey(IK_GRAVE, 'toggleconsole');
1809 g_Console_BindKey(IK_ESCAPE, 'togglemenu');
1810 g_Console_BindKey(IK_A, '+p1_moveleft', '-p1_moveleft');
1811 g_Console_BindKey(IK_D, '+p1_moveright', '-p1_moveright');
1812 g_Console_BindKey(IK_W, '+p1_lookup', '-p1_lookup');
1813 g_Console_BindKey(IK_S, '+p1_lookdown', '-p1_lookdown');
1814 g_Console_BindKey(IK_SPACE, '+p1_jump', '-p1_jump');
1815 g_Console_BindKey(IK_H, '+p1_attack', '-p1_attack');
1816 g_Console_BindKey(IK_J, '+p1_activate', '-p1_activate');
1817 g_Console_BindKey(IK_E, '+p1_weapnext', '-p1_weapnext');
1818 g_Console_BindKey(IK_Q, '+p1_weapprev', '-p1_weapprev');
1819 g_Console_BindKey(IK_ALT, '+p1_strafe', '-p1_strafe');
1820 g_Console_BindKey(IK_1, 'p1_weapon 1');
1821 g_Console_BindKey(IK_2, 'p1_weapon 2');
1822 g_Console_BindKey(IK_3, 'p1_weapon 3');
1823 g_Console_BindKey(IK_4, 'p1_weapon 4');
1824 g_Console_BindKey(IK_5, 'p1_weapon 5');
1825 g_Console_BindKey(IK_6, 'p1_weapon 6');
1826 g_Console_BindKey(IK_7, 'p1_weapon 7');
1827 g_Console_BindKey(IK_8, 'p1_weapon 8');
1828 g_Console_BindKey(IK_9, 'p1_weapon 9');
1829 g_Console_BindKey(IK_0, 'p1_weapon 10');
1830 g_Console_BindKey(IK_MINUS, 'p1_weapon 11');
1831 g_Console_BindKey(IK_T, 'togglechat');
1832 g_Console_BindKey(IK_Y, 'toggleteamchat');
1833 g_Console_BindKey(IK_F11, 'screenshot');
1834 g_Console_BindKey(IK_TAB, '+p1_scores', '-p1_scores');
1835 g_Console_BindKey(IK_PAUSE, 'pause');
1836 g_Console_BindKey(IK_F1, 'vote');
1838 (* for i := 0 to e_MaxJoys - 1 do *)
1839 for i := 0 to 1 do
1840 begin
1841 g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_LEFT), '+p' + IntToStr(i mod 2 + 1) + '_moveleft', '-p' + IntToStr(i mod 2 + 1) + '_moveleft');
1842 g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_RIGHT), '+p' + IntToStr(i mod 2 + 1) + '_moveright', '-p' + IntToStr(i mod 2 + 1) + '_moveright');
1843 g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_UP), '+p' + IntToStr(i mod 2 + 1) + '_lookup', '-p' + IntToStr(i mod 2 + 1) + '_lookup');
1844 g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_DOWN), '+p' + IntToStr(i mod 2 + 1) + '_lookdown', '-p' + IntToStr(i mod 2 + 1) + '_lookdown');
1845 g_Console_BindKey(e_JoyButtonToKey(i, 2), '+p' + IntToStr(i mod 2 + 1) + '_jump', '-p' + IntToStr(i mod 2 + 1) + '_jump');
1846 g_Console_BindKey(e_JoyButtonToKey(i, 0), '+p' + IntToStr(i mod 2 + 1) + '_attack', '-p' + IntToStr(i mod 2 + 1) + '_attack');
1847 g_Console_BindKey(e_JoyButtonToKey(i, 3), '+p' + IntToStr(i mod 2 + 1) + '_activate', '-p' + IntToStr(i mod 2 + 1) + '_activate');
1848 g_Console_BindKey(e_JoyButtonToKey(i, 1), '+p' + IntToStr(i mod 2 + 1) + '_weapnext', '-p' + IntToStr(i mod 2 + 1) + '_weapnext');
1849 g_Console_BindKey(e_JoyButtonToKey(i, 4), '+p' + IntToStr(i mod 2 + 1) + '_weapprev', '-p' + IntToStr(i mod 2 + 1) + '_weapprev');
1850 g_Console_BindKey(e_JoyButtonToKey(i, 7), '+p' + IntToStr(i mod 2 + 1) + '_strafe', '-p' + IntToStr(i mod 2 + 1) + '_strafe');
1851 g_Console_BindKey(e_JoyButtonToKey(i, 10), 'togglemenu');
1852 end;
1854 g_Console_BindKey(VK_ESCAPE, 'togglemenu');
1855 g_Console_BindKey(VK_LSTRAFE, '+moveleft; +strafe', '-moveleft; -strafe');
1856 g_Console_BindKey(VK_RSTRAFE, '+moveright; +strafe', '-moveright; -strafe');
1857 g_Console_BindKey(VK_LEFT, '+moveleft', '-moveleft');
1858 g_Console_BindKey(VK_RIGHT, '+moveright', '-moveright');
1859 g_Console_BindKey(VK_UP, '+lookup', '-lookup');
1860 g_Console_BindKey(VK_DOWN, '+lookdown', '-lookdown');
1861 g_Console_BindKey(VK_JUMP, '+jump', '-jump');
1862 g_Console_BindKey(VK_FIRE, '+attack', '-attack');
1863 g_Console_BindKey(VK_OPEN, '+activate', '-activate');
1864 g_Console_BindKey(VK_NEXT, '+weapnext', '-weapnext');
1865 g_Console_BindKey(VK_PREV, '+weapprev', '-weapprev');
1866 g_Console_BindKey(VK_STRAFE, '+strafe', '-strafe');
1867 g_Console_BindKey(VK_0, 'weapon 1');
1868 g_Console_BindKey(VK_1, 'weapon 2');
1869 g_Console_BindKey(VK_2, 'weapon 3');
1870 g_Console_BindKey(VK_3, 'weapon 4');
1871 g_Console_BindKey(VK_4, 'weapon 5');
1872 g_Console_BindKey(VK_5, 'weapon 6');
1873 g_Console_BindKey(VK_6, 'weapon 7');
1874 g_Console_BindKey(VK_7, 'weapon 8');
1875 g_Console_BindKey(VK_8, 'weapon 9');
1876 g_Console_BindKey(VK_9, 'weapon 10');
1877 g_Console_BindKey(VK_A, 'weapon 11');
1878 g_Console_BindKey(VK_CHAT, 'togglechat');
1879 g_Console_BindKey(VK_TEAM, 'toggleteamchat');
1880 g_Console_BindKey(VK_CONSOLE, 'toggleconsole');
1881 g_Console_BindKey(VK_PRINTSCR, 'screenshot');
1882 g_Console_BindKey(VK_STATUS, '+scores', '-scores');
1883 g_Console_BindKey(VK_SHOWKBD, 'showkeyboard');
1884 g_Console_BindKey(VK_HIDEKBD, 'hidekeyboard');
1885 end;
1887 procedure g_Console_ReadConfig (filename: String);
1888 var f: TextFile; s: AnsiString; i, len: Integer;
1889 begin
1890 e_LogWritefln('g_Console_ReadConfig (1) "%s"', [filename]);
1891 if e_FindResource(ConfigDirs, filename, false) = true then
1892 begin
1893 e_LogWritefln('g_Console_ReadConfig (2) "%s"', [filename]);
1894 AssignFile(f, filename);
1895 Reset(f);
1896 while not EOF(f) do
1897 begin
1898 ReadLn(f, s);
1899 len := Length(s);
1900 if len > 0 then
1901 begin
1902 i := 1;
1903 (* skip spaces *)
1904 while (i <= len) and (s[i] <= ' ') do inc(i);
1905 (* skip comments *)
1906 if (i <= len) and ((s[i] <> '#') and ((i + 1 > len) or (s[i] <> '/') or (s[i + 1] <> '/'))) then
1907 g_Console_Process(s, True);
1908 end
1909 end;
1910 CloseFile(f);
1911 end
1912 end;
1914 procedure g_Console_WriteConfig (filename: String);
1915 var f: TextFile; i, j: Integer;
1917 procedure WriteFlag(name: string; flag: LongWord);
1918 begin
1919 WriteLn(f, name, IfThen(LongBool(gsGameFlags and flag), 1, 0));
1920 end;
1922 function FormatTeam(team: Byte): string;
1923 begin
1924 if team = TEAM_BLUE then
1925 result := 'blue'
1926 else
1927 result := 'red';
1928 end;
1930 begin
1931 AssignFile(f, filename);
1932 Rewrite(f);
1933 WriteLn(f, '// ' + configComment);
1935 // binds
1936 WriteLn(f, 'unbindall');
1937 for i := 0 to e_MaxInputKeys - 1 do
1938 if (Length(gInputBinds[i].down) > 0) or (Length(gInputBinds[i].up) > 0) then
1939 begin
1940 Write(f, 'bind ', e_KeyNames[i], ' ', QuoteStr(GetCommandString(gInputBinds[i].down)));
1941 if Length(gInputBinds[i].down) = 0 then
1942 Write(f, '""');
1943 if Length(gInputBinds[i].up) > 0 then
1944 Write(f, ' ', QuoteStr(GetCommandString(gInputBinds[i].up)));
1945 WriteLn(f, '');
1946 if gInputBinds[i].rep then
1947 WriteLn(f, 'bindrep ', e_KeyNames[i]);
1948 end;
1950 // lang
1951 if gAskLanguage then
1952 WriteLn(f, 'g_language ask')
1953 else
1954 WriteLn(f, 'g_language ', gLanguage);
1956 // net server
1957 WriteLn(f, 'sv_name ', QuoteStr(NetServerName));
1958 WriteLn(f, 'sv_passwd ', QuoteStr(NetPassword));
1959 WriteLn(f, 'sv_maxplrs ', NetMaxClients);
1960 WriteLn(f, 'sv_port ', NetPort);
1961 WriteLn(f, 'sv_public ', IfThen(NetUseMaster, 1, 0));
1963 // game settings
1964 WriteLn(f, 'g_max_particles ', g_GFX_GetMax());
1965 WriteLn(f, 'g_max_shells ', g_Shells_GetMax());
1966 WriteLn(f, 'g_max_gibs ', g_Gibs_GetMax());
1967 WriteLn(f, 'g_max_corpses ', g_Corpses_GetMax());
1968 WriteLn(f, 'sv_intertime ', gDefInterTime);
1970 // gameplay settings
1971 WriteLn(f, 'g_gamemode ', gsGameMode);
1972 WriteLn(f, 'g_scorelimit ', gsGoalLimit);
1973 WriteLn(f, 'g_timelimit ', gsTimeLimit);
1974 WriteLn(f, 'g_maxlives ', gsMaxLives);
1975 WriteLn(f, 'g_item_respawn_time ', gsItemRespawnTime);
1976 WriteLn(f, 'g_spawn_invul ', gsSpawnInvul);
1977 WriteLn(f, 'g_warmup_time ', gsWarmupTime);
1979 WriteFlag('g_friendlyfire ', GAME_OPTION_TEAMDAMAGE);
1980 WriteFlag('g_friendly_hit_trace ', GAME_OPTION_TEAMHITTRACE);
1981 WriteFlag('g_friendly_hit_projectile ', GAME_OPTION_TEAMHITPROJECTILE);
1982 WriteFlag('g_allow_exit ', GAME_OPTION_ALLOWEXIT);
1983 WriteFlag('g_allow_monsters ', GAME_OPTION_MONSTERS);
1984 WriteFlag('g_dm_keys ', GAME_OPTION_DMKEYS);
1985 WriteFlag('g_weaponstay ', GAME_OPTION_WEAPONSTAY);
1986 WriteFlag('g_bot_vsmonsters ', GAME_OPTION_BOTVSMONSTER);
1987 WriteFlag('g_bot_vsplayers ', GAME_OPTION_BOTVSPLAYER);
1989 // players
1990 with gPlayer1Settings do
1991 begin
1992 WriteLn(f, 'p1_name ', QuoteStr(Name));
1993 WriteLn(f, 'p1_color ', Color.R, ' ', Color.G, ' ', Color.B);
1994 WriteLn(f, 'p1_model ', QuoteStr(Model));
1995 WriteLn(f, 'p1_team ', FormatTeam(Team));
1996 end;
1997 with gPlayer2Settings do
1998 begin
1999 WriteLn(f, 'p2_name ', QuoteStr(Name));
2000 WriteLn(f, 'p2_color ', Color.R, ' ', Color.G, ' ', Color.B);
2001 WriteLn(f, 'p2_model ', QuoteStr(Model));
2002 WriteLn(f, 'p2_team ', FormatTeam(Team));
2003 end;
2005 // all cvars
2006 for i := 0 to High(commands) do
2007 begin
2008 if not commands[i].cheat then
2009 begin
2010 if @commands[i].procEx = @boolVarHandler then
2011 begin
2012 if PBoolean(commands[i].ptr)^ then j := 1 else j := 0;
2013 WriteLn(f, commands[i].cmd, ' ', j)
2014 end
2015 else if @commands[i].procEx = @intVarHandler then
2016 begin
2017 WriteLn(f, commands[i].cmd, ' ', PInteger(commands[i].ptr)^)
2018 end
2019 else if @commands[i].procEx = @wordVarHandler then
2020 begin
2021 WriteLn(f, commands[i].cmd, ' ', PWord(commands[i].ptr)^)
2022 end
2023 else if @commands[i].procEx = @dwordVarHandler then
2024 begin
2025 WriteLn(f, commands[i].cmd, ' ', PCardinal(commands[i].ptr)^)
2026 end
2027 else if @commands[i].procEx = @singleVarHandler then
2028 begin
2029 WriteLn(f, commands[i].cmd, ' ', PVarSingle(commands[i].ptr).val^:0:6)
2030 end
2031 else if @commands[i].procEx = @strVarHandler then
2032 begin
2033 if Length(PAnsiString(commands[i].ptr)^) = 0 then
2034 WriteLn(f, commands[i].cmd, ' ""')
2035 else
2036 WriteLn(f, commands[i].cmd, ' ', QuoteStr(PAnsiString(commands[i].ptr)^))
2037 end
2038 end
2039 end;
2041 WriteLn(f, 'r_maxfps ', gMaxFPS);
2042 WriteLn(f, 'r_reset');
2043 CloseFile(f)
2044 end;
2046 procedure g_Console_WriteGameConfig;
2047 var s: AnsiString;
2048 begin
2049 if gParsingBinds = false then
2050 begin
2051 s := e_GetWriteableDir(ConfigDirs);
2052 g_Console_WriteConfig(e_CatPath(s, gConfigScript))
2053 end
2054 end;
2056 procedure Init;
2057 var i: Integer;
2058 begin
2059 conRegVar('d_eres', @debug_e_res, '', '');
2060 for i := 1 to e_MaxJoys do
2061 conRegVar('joy' + IntToStr(i) + '_deadzone', @e_JoystickDeadzones[i - 1], '', '')
2062 end;
2064 initialization
2065 Init
2066 end.