DEADSOFTWARE

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