DEADSOFTWARE

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