DEADSOFTWARE

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