DEADSOFTWARE

read dfconfig.cfg before init
[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,
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_SysInit;
836 var a: Integer;
837 begin
838 Cons_Y := -Floor(gScreenHeight * ConsoleHeight);
839 gConsoleShow := False;
840 gChatShow := False;
841 Cons_Shown := False;
842 InputReady := False;
843 CPos := 1;
845 for a := 0 to High(MsgArray) do
846 with MsgArray[a] do
847 begin
848 Msg := '';
849 Time := 0;
850 end;
852 AddCommand('segfault', segfault, 'make segfault');
854 AddCommand('bind', BindCommands);
855 AddCommand('bindlist', BindCommands);
856 AddCommand('unbind', BindCommands);
857 AddCommand('unbindall', BindCommands);
858 AddCommand('showkeyboard', BindCommands);
859 AddCommand('hidekeyboard', BindCommands);
860 AddCommand('togglemenu', BindCommands);
861 AddCommand('toggleconsole', BindCommands);
862 AddCommand('togglechat', BindCommands);
863 AddCommand('toggleteamchat', BindCommands);
865 AddCommand('clear', ConsoleCommands, 'clear console');
866 AddCommand('clearhistory', ConsoleCommands);
867 AddCommand('showhistory', ConsoleCommands);
868 AddCommand('commands', ConsoleCommands);
869 AddCommand('time', ConsoleCommands);
870 AddCommand('date', ConsoleCommands);
871 AddCommand('echo', ConsoleCommands);
872 AddCommand('dump', ConsoleCommands);
873 AddCommand('exec', ConsoleCommands);
874 AddCommand('writeconfig', ConsoleCommands);
875 AddCommand('alias', ConsoleCommands);
876 AddCommand('call', ConsoleCommands);
877 AddCommand('ver', ConsoleCommands);
878 AddCommand('version', ConsoleCommands);
880 AddCommand('d_window', DebugCommands);
881 AddCommand('d_sounds', DebugCommands);
882 AddCommand('d_frames', DebugCommands);
883 AddCommand('d_winmsg', DebugCommands);
884 AddCommand('d_monoff', DebugCommands);
885 AddCommand('d_botoff', DebugCommands);
886 AddCommand('d_monster', DebugCommands);
887 AddCommand('d_health', DebugCommands);
888 AddCommand('d_player', DebugCommands);
889 AddCommand('d_joy', DebugCommands);
890 AddCommand('d_mem', DebugCommands);
892 AddCommand('p1_name', GameCVars);
893 AddCommand('p2_name', GameCVars);
894 AddCommand('p1_color', GameCVars);
895 AddCommand('p2_color', GameCVars);
896 AddCommand('r_showscore', GameCVars);
897 AddCommand('r_showlives', GameCVars);
898 AddCommand('r_showstat', GameCVars);
899 AddCommand('r_showkillmsg', GameCVars);
900 AddCommand('r_showspect', GameCVars);
901 AddCommand('r_showping', GameCVars);
902 AddCommand('g_gamemode', GameCVars);
903 AddCommand('g_friendlyfire', GameCVars);
904 AddCommand('g_weaponstay', GameCVars);
905 AddCommand('g_allow_exit', GameCVars);
906 AddCommand('g_allow_monsters', GameCVars);
907 AddCommand('g_bot_vsmonsters', GameCVars);
908 AddCommand('g_bot_vsplayers', GameCVars);
909 AddCommand('g_scorelimit', GameCVars);
910 AddCommand('g_timelimit', GameCVars);
911 AddCommand('g_maxlives', GameCVars);
912 AddCommand('g_warmuptime', GameCVars);
913 AddCommand('net_interp', GameCVars);
914 AddCommand('net_forceplayerupdate', GameCVars);
915 AddCommand('net_predictself', GameCVars);
916 AddCommand('sv_name', GameCVars);
917 AddCommand('sv_passwd', GameCVars);
918 AddCommand('sv_maxplrs', GameCVars);
919 AddCommand('sv_public', GameCVars);
920 AddCommand('sv_intertime', GameCVars);
922 AddCommand('quit', GameCommands);
923 AddCommand('exit', GameCommands);
924 AddCommand('pause', GameCommands);
925 AddCommand('endgame', GameCommands);
926 AddCommand('restart', GameCommands);
927 AddCommand('addbot', GameCommands);
928 AddCommand('bot_add', GameCommands);
929 AddCommand('bot_addlist', GameCommands);
930 AddCommand('bot_addred', GameCommands);
931 AddCommand('bot_addblue', GameCommands);
932 AddCommand('bot_removeall', GameCommands);
933 AddCommand('chat', GameCommands);
934 AddCommand('teamchat', GameCommands);
935 AddCommand('game', GameCommands);
936 AddCommand('host', GameCommands);
937 AddCommand('map', GameCommands);
938 AddCommand('nextmap', GameCommands);
939 AddCommand('endmap', GameCommands);
940 AddCommand('goodbye', GameCommands);
941 AddCommand('suicide', GameCommands);
942 AddCommand('spectate', GameCommands);
943 AddCommand('ready', GameCommands);
944 AddCommand('kick', GameCommands);
945 AddCommand('kick_id', GameCommands);
946 AddCommand('ban', GameCommands);
947 AddCommand('permban', GameCommands);
948 AddCommand('ban_id', GameCommands);
949 AddCommand('permban_id', GameCommands);
950 AddCommand('unban', GameCommands);
951 AddCommand('connect', GameCommands);
952 AddCommand('disconnect', GameCommands);
953 AddCommand('reconnect', GameCommands);
954 AddCommand('say', GameCommands);
955 AddCommand('tell', GameCommands);
956 AddCommand('overtime', GameCommands);
957 AddCommand('rcon_password', GameCommands);
958 AddCommand('rcon', GameCommands);
959 AddCommand('callvote', GameCommands);
960 AddCommand('vote', GameCommands);
961 AddCommand('clientlist', GameCommands);
962 AddCommand('event', GameCommands);
963 AddCommand('screenshot', GameCommands);
964 AddCommand('weapon', GameCommands);
965 AddCommand('p1_weapon', GameCommands);
966 AddCommand('p2_weapon', GameCommands);
968 AddCommand('god', GameCheats);
969 AddCommand('notarget', GameCheats);
970 AddCommand('give', GameCheats); // "exit" too ;-)
971 AddCommand('open', GameCheats);
972 AddCommand('fly', GameCheats);
973 AddCommand('noclip', GameCheats);
974 AddCommand('speedy', GameCheats);
975 AddCommand('jumpy', GameCheats);
976 AddCommand('noreload', GameCheats);
977 AddCommand('aimline', GameCheats);
978 AddCommand('automap', GameCheats);
980 AddAction('jump', ACTION_JUMP);
981 AddAction('moveleft', ACTION_MOVELEFT);
982 AddAction('moveright', ACTION_MOVERIGHT);
983 AddAction('lookup', ACTION_LOOKUP);
984 AddAction('lookdown', ACTION_LOOKDOWN);
985 AddAction('attack', ACTION_ATTACK);
986 AddAction('scores', ACTION_SCORES);
987 AddAction('activate', ACTION_ACTIVATE);
988 AddAction('strafe', ACTION_STRAFE);
989 AddAction('weapnext', ACTION_WEAPNEXT);
990 AddAction('weapprev', ACTION_WEAPPREV);
992 WhitelistCommand('say');
993 WhitelistCommand('tell');
994 WhitelistCommand('overtime');
995 WhitelistCommand('ready');
996 WhitelistCommand('map');
997 WhitelistCommand('nextmap');
998 WhitelistCommand('endmap');
999 WhitelistCommand('restart');
1000 WhitelistCommand('kick');
1001 WhitelistCommand('ban');
1003 WhitelistCommand('addbot');
1004 WhitelistCommand('bot_add');
1005 WhitelistCommand('bot_addred');
1006 WhitelistCommand('bot_addblue');
1007 WhitelistCommand('bot_removeall');
1009 WhitelistCommand('g_gamemode');
1010 WhitelistCommand('g_friendlyfire');
1011 WhitelistCommand('g_weaponstay');
1012 WhitelistCommand('g_allow_exit');
1013 WhitelistCommand('g_allow_monsters');
1014 WhitelistCommand('g_scorelimit');
1015 WhitelistCommand('g_timelimit');
1017 g_Console_ResetBinds;
1018 g_Console_ReadConfig(GameDir + '/dfconfig.cfg');
1019 g_Console_ReadConfig(GameDir + '/autoexec.cfg');
1020 gParsingBinds := False;
1021 end;
1023 procedure g_Console_Init;
1024 begin
1025 g_Texture_CreateWAD(ID, GameWAD+':TEXTURES\CONSOLE');
1026 g_Console_Add(Format(_lc[I_CONSOLE_WELCOME], [GAME_VERSION]));
1027 g_Console_Add('');
1028 end;
1030 procedure g_Console_Update;
1031 var
1032 a, b, Step: Integer;
1033 begin
1034 if Cons_Shown then
1035 begin
1036 Step := Max(1, Round(Floor(gScreenHeight * ConsoleHeight) * ConsoleStep));
1037 if gConsoleShow then
1038 begin
1039 (* Open animation *)
1040 Cons_Y := Min(Cons_Y + Step, 0);
1041 InputReady := True
1042 end
1043 else
1044 begin
1045 (* Close animation *)
1046 Cons_Y := Max(Cons_Y - Step, -Floor(gScreenHeight * ConsoleHeight));
1047 Cons_Shown := Cons_Y > -Floor(gScreenHeight * ConsoleHeight);
1048 InputReady := False
1049 end;
1051 if gChatShow then
1052 InputReady := True
1053 end;
1055 a := 0;
1056 while a <= High(MsgArray) do
1057 begin
1058 if MsgArray[a].Time > 0 then
1059 begin
1060 if MsgArray[a].Time = 1 then
1061 begin
1062 if a < High(MsgArray) then
1063 begin
1064 for b := a to High(MsgArray)-1 do
1065 MsgArray[b] := MsgArray[b+1];
1067 MsgArray[High(MsgArray)].Time := 0;
1069 a := a - 1;
1070 end;
1071 end
1072 else
1073 Dec(MsgArray[a].Time);
1074 end;
1076 a := a + 1;
1077 end;
1078 end;
1081 procedure drawConsoleText ();
1082 var
1083 CWidth, CHeight: Byte;
1084 ty: Integer;
1085 sp, ep: LongWord;
1086 skip: Integer;
1088 procedure putLine (sp, ep: LongWord);
1089 var
1090 p: LongWord;
1091 wdt, cw: Integer;
1092 begin
1093 p := sp;
1094 wdt := 0;
1095 while p <> ep do
1096 begin
1097 cw := e_TextureFontCharWidth(cbufAt(p), gStdFont);
1098 if wdt+cw > gScreenWidth-8 then break;
1099 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
1100 Inc(wdt, cw);
1101 cbufNext(p);
1102 end;
1103 if p <> ep then putLine(p, ep); // do rest of the line first
1104 // now print our part
1105 if skip = 0 then
1106 begin
1107 ep := p;
1108 p := sp;
1109 wdt := 2;
1110 while p <> ep do
1111 begin
1112 cw := e_TextureFontCharWidth(cbufAt(p), gStdFont);
1113 e_TextureFontPrintCharEx(wdt, ty, cbufAt(p), gStdFont);
1114 Inc(wdt, cw);
1115 cbufNext(p);
1116 end;
1117 Dec(ty, CHeight);
1118 end
1119 else
1120 begin
1121 Dec(skip);
1122 end;
1123 end;
1125 begin
1126 e_TextureFontGetSize(gStdFont, CWidth, CHeight);
1127 ty := Floor(gScreenHeight * ConsoleHeight) - 4 - 2 * CHeight - Abs(Cons_Y);
1128 skip := conSkipLines;
1129 cbufLastLine(sp, ep);
1130 repeat
1131 putLine(sp, ep);
1132 if ty+CHeight <= 0 then break;
1133 until not cbufLineUp(sp, ep);
1134 end;
1136 procedure g_Console_Draw(MessagesOnly: Boolean = False);
1137 var
1138 CWidth, CHeight: Byte;
1139 mfW, mfH: Word;
1140 a, b, offset_y: Integer;
1141 begin
1142 e_TextureFontGetSize(gStdFont, CWidth, CHeight);
1144 if ChatTop and gChatShow then
1145 offset_y := CHeight
1146 else
1147 offset_y := 0;
1149 for a := 0 to High(MsgArray) do
1150 if MsgArray[a].Time > 0 then
1151 e_TextureFontPrintFmt(0, offset_y + CHeight * a, MsgArray[a].Msg, gStdFont, True);
1153 if MessagesOnly then Exit;
1155 if gChatShow then
1156 begin
1157 if ChatTop then
1158 offset_y := 0
1159 else
1160 offset_y := gScreenHeight - CHeight - 1;
1161 if gChatTeam then
1162 begin
1163 e_TextureFontPrintEx(0, offset_y, 'say team> ' + Line, gStdFont, 255, 255, 255, 1, True);
1164 e_TextureFontPrintEx((CPos + 9) * CWidth, offset_y, '_', gStdFont, 255, 255, 255, 1, True);
1165 end
1166 else
1167 begin
1168 e_TextureFontPrintEx(0, offset_y, 'say> ' + Line, gStdFont, 255, 255, 255, 1, True);
1169 e_TextureFontPrintEx((CPos + 4) * CWidth, offset_y, '_', gStdFont, 255, 255, 255, 1, True);
1170 end
1171 end;
1173 if not Cons_Shown then
1174 Exit;
1176 if gDebugMode then
1177 begin
1178 e_CharFont_GetSize(gMenuFont, DEBUG_STRING, mfW, mfH);
1179 a := (gScreenWidth - 2*mfW) div 2;
1180 b := Cons_Y + (Floor(gScreenHeight * ConsoleHeight) - 2 * mfH) div 2;
1181 e_CharFont_PrintEx(gMenuFont, a div 2, b div 2, DEBUG_STRING,
1182 _RGB(128, 0, 0), 2.0);
1183 end;
1185 e_DrawSize(ID, 0, Cons_Y, Round(ConsoleTrans * 255), False, False, gScreenWidth, Floor(gScreenHeight * ConsoleHeight));
1186 e_TextureFontPrint(0, Cons_Y + Floor(gScreenHeight * ConsoleHeight) - CHeight - 4, '> ' + Line, gStdFont);
1188 drawConsoleText();
1189 (*
1190 if ConsoleHistory <> nil then
1191 begin
1192 b := 0;
1193 if CHeight > 0 then
1194 if Length(ConsoleHistory) > (Floor(gScreenHeight * ConsoleHeight) div CHeight) - 1 then
1195 b := Length(ConsoleHistory) - (Floor(gScreenHeight * ConsoleHeight) div CHeight) + 1;
1197 b := Max(b-Offset, 0);
1198 d := Max(High(ConsoleHistory)-Offset, 0);
1200 c := 2;
1201 for a := d downto b do
1202 begin
1203 e_TextureFontPrintFmt(0, Floor(gScreenHeight * ConsoleHeight) - 4 - c * CHeight - Abs(Cons_Y), ConsoleHistory[a], gStdFont, True);
1204 c := c + 1;
1205 end;
1206 end;
1207 *)
1209 e_TextureFontPrint((CPos + 1) * CWidth, Cons_Y + Floor(gScreenHeight * ConsoleHeight) - 21, '_', gStdFont);
1210 end;
1212 procedure g_Console_Char(C: AnsiChar);
1213 begin
1214 if InputReady and (gConsoleShow or gChatShow) then
1215 begin
1216 Insert(C, Line, CPos);
1217 CPos := CPos + 1;
1218 end
1219 end;
1222 var
1223 tcomplist: array of AnsiString = nil;
1224 tcompidx: array of Integer = nil;
1226 procedure Complete ();
1227 var
1228 i, c: Integer;
1229 tused: Integer;
1230 ll, lpfx, cmd: AnsiString;
1231 begin
1232 if (Length(Line) = 0) then
1233 begin
1234 g_Console_Add('');
1235 for i := 0 to High(commands) do
1236 begin
1237 // hidden commands are hidden when cheats aren't enabled
1238 if commands[i].hidden and not conIsCheatsEnabled then continue;
1239 if (Length(commands[i].help) > 0) then
1240 begin
1241 g_Console_Add(' '+commands[i].cmd+' -- '+commands[i].help);
1242 end
1243 else
1244 begin
1245 g_Console_Add(' '+commands[i].cmd);
1246 end;
1247 end;
1248 exit;
1249 end;
1251 ll := LowerCase(Line);
1252 lpfx := '';
1254 if (Length(ll) > 1) and (ll[Length(ll)] = ' ') then
1255 begin
1256 ll := Copy(ll, 0, Length(ll)-1);
1257 for i := 0 to High(commands) do
1258 begin
1259 // hidden commands are hidden when cheats aren't enabled
1260 if commands[i].hidden and not conIsCheatsEnabled then continue;
1261 if (commands[i].cmd = ll) then
1262 begin
1263 if (Length(commands[i].help) > 0) then
1264 begin
1265 g_Console_Add(' '+commands[i].cmd+' -- '+commands[i].help);
1266 end;
1267 end;
1268 end;
1269 exit;
1270 end;
1272 // build completion list
1273 tused := 0;
1274 for i := 0 to High(commands) do
1275 begin
1276 // hidden commands are hidden when cheats aren't enabled
1277 if commands[i].hidden and not conIsCheatsEnabled then continue;
1278 cmd := commands[i].cmd;
1279 if (Length(cmd) >= Length(ll)) and (ll = Copy(cmd, 0, Length(ll))) then
1280 begin
1281 if (tused = Length(tcomplist)) then
1282 begin
1283 SetLength(tcomplist, Length(tcomplist)+128);
1284 SetLength(tcompidx, Length(tcompidx)+128);
1285 end;
1286 tcomplist[tused] := cmd;
1287 tcompidx[tused] := i;
1288 Inc(tused);
1289 if (Length(cmd) > Length(lpfx)) then lpfx := cmd;
1290 end;
1291 end;
1293 // get longest prefix
1294 for i := 0 to tused-1 do
1295 begin
1296 cmd := tcomplist[i];
1297 for c := 1 to Length(lpfx) do
1298 begin
1299 if (c > Length(cmd)) then break;
1300 if (cmd[c] <> lpfx[c]) then begin lpfx := Copy(lpfx, 0, c-1); break; end;
1301 end;
1302 end;
1304 if (tused = 0) then exit;
1306 if (tused = 1) then
1307 begin
1308 Line := tcomplist[0]+' ';
1309 CPos := Length(Line)+1;
1310 end
1311 else
1312 begin
1313 // has longest prefix?
1314 if (Length(lpfx) > Length(ll)) then
1315 begin
1316 Line := lpfx;
1317 CPos:= Length(Line)+1;
1318 end
1319 else
1320 begin
1321 g_Console_Add('');
1322 for i := 0 to tused-1 do
1323 begin
1324 if (Length(commands[tcompidx[i]].help) > 0) then
1325 begin
1326 g_Console_Add(' '+tcomplist[i]+' -- '+commands[tcompidx[i]].help);
1327 end
1328 else
1329 begin
1330 g_Console_Add(' '+tcomplist[i]);
1331 end;
1332 end;
1333 end;
1334 end;
1335 end;
1338 procedure g_Console_Control(K: Word);
1339 begin
1340 case K of
1341 IK_BACKSPACE:
1342 if (Length(Line) > 0) and (CPos > 1) then
1343 begin
1344 Delete(Line, CPos-1, 1);
1345 CPos := CPos-1;
1346 end;
1347 IK_DELETE:
1348 if (Length(Line) > 0) and (CPos <= Length(Line)) then
1349 Delete(Line, CPos, 1);
1350 IK_LEFT, IK_KPLEFT, VK_LEFT, JOY0_LEFT, JOY1_LEFT, JOY2_LEFT, JOY3_LEFT:
1351 if CPos > 1 then
1352 CPos := CPos - 1;
1353 IK_RIGHT, IK_KPRIGHT, VK_RIGHT, JOY0_RIGHT, JOY1_RIGHT, JOY2_RIGHT, JOY3_RIGHT:
1354 if CPos <= Length(Line) then
1355 CPos := CPos + 1;
1356 IK_RETURN, IK_KPRETURN, VK_OPEN, VK_FIRE, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK:
1357 begin
1358 if gConsoleShow then
1359 g_Console_Process(Line)
1360 else
1361 if gChatShow then
1362 begin
1363 if (Length(Line) > 0) and g_Game_IsNet then
1364 begin
1365 if gChatTeam then
1366 begin
1367 if g_Game_IsClient then
1368 MC_SEND_Chat(b_Text_Format(Line), NET_CHAT_TEAM)
1369 else
1370 MH_SEND_Chat('[' + gPlayer1Settings.name + ']: ' + b_Text_Format(Line),
1371 NET_CHAT_TEAM, gPlayer1Settings.Team);
1372 end
1373 else
1374 begin
1375 if g_Game_IsClient then
1376 MC_SEND_Chat(b_Text_Format(Line), NET_CHAT_PLAYER)
1377 else
1378 MH_SEND_Chat('[' + gPlayer1Settings.name + ']: ' + b_Text_Format(Line),
1379 NET_CHAT_PLAYER);
1380 end;
1381 end;
1383 Line := '';
1384 CPos := 1;
1385 gJustChatted := True;
1386 g_Console_Chat_Switch;
1387 InputReady := False;
1388 end;
1389 end;
1390 IK_TAB:
1391 if not gChatShow then
1392 Complete();
1393 IK_DOWN, IK_KPDOWN, VK_DOWN, JOY0_DOWN, JOY1_DOWN, JOY2_DOWN, JOY3_DOWN:
1394 if not gChatShow then
1395 if (CommandHistory <> nil) and
1396 (CmdIndex < Length(CommandHistory)) then
1397 begin
1398 if CmdIndex < Length(CommandHistory)-1 then
1399 CmdIndex := CmdIndex + 1;
1400 Line := CommandHistory[CmdIndex];
1401 CPos := Length(Line) + 1;
1402 end;
1403 IK_UP, IK_KPUP, VK_UP, JOY0_UP, JOY1_UP, JOY2_UP, JOY3_UP:
1404 if not gChatShow then
1405 if (CommandHistory <> nil) and
1406 (CmdIndex <= Length(CommandHistory)) then
1407 begin
1408 if CmdIndex > 0 then
1409 CmdIndex := CmdIndex - 1;
1410 Line := CommandHistory[CmdIndex];
1411 Cpos := Length(Line) + 1;
1412 end;
1413 IK_PAGEUP, IK_KPPAGEUP, VK_PREV, JOY0_PREV, JOY1_PREV, JOY2_PREV, JOY3_PREV: // PgUp
1414 if not gChatShow then Inc(conSkipLines);
1415 IK_PAGEDN, IK_KPPAGEDN, VK_NEXT, JOY0_NEXT, JOY1_NEXT, JOY2_NEXT, JOY3_NEXT: // PgDown
1416 if not gChatShow and (conSkipLines > 0) then Dec(conSkipLines);
1417 IK_HOME, IK_KPHOME:
1418 CPos := 1;
1419 IK_END, IK_KPEND:
1420 CPos := Length(Line) + 1;
1421 IK_A..IK_Z, IK_SPACE, IK_SHIFT, IK_RSHIFT, IK_CAPSLOCK, IK_LBRACKET, IK_RBRACKET,
1422 IK_SEMICOLON, IK_QUOTE, IK_BACKSLASH, IK_SLASH, IK_COMMA, IK_DOT, (*IK_EQUALS,*)
1423 IK_0, IK_1, IK_2, IK_3, IK_4, IK_5, IK_6, IK_7, IK_8, IK_9, IK_MINUS, IK_EQUALS:
1424 (* see TEXTINPUT event *)
1425 end
1426 end;
1428 function GetStr(var Str: AnsiString): AnsiString;
1429 var
1430 a, b: Integer;
1431 begin
1432 Result := '';
1433 if Str[1] = '"' then
1434 begin
1435 for b := 1 to Length(Str) do
1436 if (b = Length(Str)) or (Str[b+1] = '"') then
1437 begin
1438 Result := Copy(Str, 2, b-1);
1439 Delete(Str, 1, b+1);
1440 Str := Trim(Str);
1441 Exit;
1442 end;
1443 end;
1445 for a := 1 to Length(Str) do
1446 if (a = Length(Str)) or (Str[a+1] = ' ') then
1447 begin
1448 Result := Copy(Str, 1, a);
1449 Delete(Str, 1, a+1);
1450 Str := Trim(Str);
1451 Exit;
1452 end;
1453 end;
1455 function ParseString(Str: AnsiString): SSArray;
1456 begin
1457 Result := nil;
1459 Str := Trim(Str);
1461 if Str = '' then
1462 Exit;
1464 while Str <> '' do
1465 begin
1466 SetLength(Result, Length(Result)+1);
1467 Result[High(Result)] := GetStr(Str);
1468 end;
1469 end;
1471 procedure g_Console_Add (L: AnsiString; show: Boolean=false);
1473 procedure conmsg (s: AnsiString);
1474 var
1475 a: Integer;
1476 begin
1477 if length(s) = 0 then exit;
1478 for a := 0 to High(MsgArray) do
1479 begin
1480 with MsgArray[a] do
1481 begin
1482 if Time = 0 then
1483 begin
1484 Msg := s;
1485 Time := MsgTime;
1486 exit;
1487 end;
1488 end;
1489 end;
1490 for a := 0 to High(MsgArray)-1 do MsgArray[a] := MsgArray[a+1];
1491 with MsgArray[High(MsgArray)] do
1492 begin
1493 Msg := L;
1494 Time := MsgTime;
1495 end;
1496 end;
1498 var
1499 f: Integer;
1500 begin
1501 // put it to console
1502 cbufPut(L);
1503 if (length(L) = 0) or ((L[length(L)] <> #10) and (L[length(L)] <> #13)) then cbufPut(#10);
1505 // now show 'em out of console too
1506 show := show and gAllowConsoleMessages;
1507 if show and gShowMessages then
1508 begin
1509 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1510 while length(L) > 0 do
1511 begin
1512 f := Pos(#10, L);
1513 if f <= 0 then f := length(L)+1;
1514 conmsg(Copy(L, 1, f-1));
1515 Delete(L, 1, f);
1516 end;
1517 end;
1519 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1520 //ConsoleHistory[High(ConsoleHistory)] := L;
1522 (*
1523 {$IFDEF HEADLESS}
1524 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1525 {$ENDIF}
1526 *)
1527 end;
1530 var
1531 consolewriterLastWasEOL: Boolean = false;
1533 procedure consolewriter (constref buf; len: SizeUInt);
1534 var
1535 b: PByte;
1536 begin
1537 if (len < 1) then exit;
1538 b := PByte(@buf);
1539 consolewriterLastWasEOL := (b[len-1] = 13) or (b[len-1] = 10);
1540 while (len > 0) do
1541 begin
1542 if (b[0] <> 13) and (b[0] <> 10) then
1543 begin
1544 cbufPut(AnsiChar(b[0]));
1545 end
1546 else
1547 begin
1548 if (len > 1) and (b[0] = 13) then begin len -= 1; b += 1; end;
1549 cbufPut(#10);
1550 end;
1551 len -= 1;
1552 b += 1;
1553 end;
1554 end;
1557 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1558 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1559 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1560 procedure conwriteln (const s: AnsiString; show: Boolean=false);
1561 begin
1562 g_Console_Add(s, show);
1563 end;
1566 procedure conwritefln (const s: AnsiString; args: array of const; show: Boolean=false);
1567 begin
1568 if show then
1569 begin
1570 g_Console_Add(formatstrf(s, args), true);
1571 end
1572 else
1573 begin
1574 consolewriterLastWasEOL := false;
1575 formatstrf(s, args, consolewriter);
1576 if not consolewriterLastWasEOL then cbufPut(#10);
1577 end;
1578 end;
1581 procedure g_Console_Clear();
1582 begin
1583 //ConsoleHistory := nil;
1584 cbufClear();
1585 conSkipLines := 0;
1586 end;
1588 procedure AddToHistory(L: AnsiString);
1589 var
1590 len: Integer;
1591 begin
1592 len := Length(CommandHistory);
1594 if (len = 0) or
1595 (LowerCase(CommandHistory[len-1]) <> LowerCase(L)) then
1596 begin
1597 SetLength(CommandHistory, len+1);
1598 CommandHistory[len] := L;
1599 end;
1601 CmdIndex := Length(CommandHistory);
1602 end;
1604 function g_Console_CommandBlacklisted(C: AnsiString): Boolean;
1605 var
1606 Arr: SSArray;
1607 i: Integer;
1608 begin
1609 Result := True;
1611 Arr := nil;
1613 if Trim(C) = '' then
1614 Exit;
1616 Arr := ParseString(C);
1617 if Arr = nil then
1618 Exit;
1620 for i := 0 to High(Whitelist) do
1621 if Whitelist[i] = LowerCase(Arr[0]) then
1622 Result := False;
1623 end;
1625 procedure g_Console_Process(L: AnsiString; quiet: Boolean = False);
1626 var
1627 Arr: SSArray;
1628 i: Integer;
1629 begin
1630 Arr := nil;
1632 if Trim(L) = '' then
1633 Exit;
1635 conSkipLines := 0; // "unscroll"
1637 if L = 'goobers' then
1638 begin
1639 Line := '';
1640 CPos := 1;
1641 gCheats := true;
1642 g_Console_Add('Your memory serves you well.');
1643 exit;
1644 end;
1646 if not quiet then
1647 begin
1648 g_Console_Add('> '+L);
1649 Line := '';
1650 CPos := 1;
1651 end;
1653 Arr := ParseString(L);
1654 if Arr = nil then
1655 Exit;
1657 if commands = nil then
1658 Exit;
1660 if not quiet then
1661 AddToHistory(L);
1663 for i := 0 to High(commands) do
1664 begin
1665 if commands[i].cmd = LowerCase(Arr[0]) then
1666 begin
1667 if commands[i].action >= 0 then
1668 begin
1669 gPlayerAction[commands[i].player, commands[i].action] := commands[i].cmd[1] = '+';
1670 exit
1671 end;
1672 if assigned(commands[i].procEx) then
1673 begin
1674 commands[i].procEx(@commands[i], Arr);
1675 exit
1676 end;
1677 if assigned(commands[i].proc) then
1678 begin
1679 commands[i].proc(Arr);
1680 exit
1681 end
1682 end
1683 end;
1685 g_Console_Add(Format(_lc[I_CONSOLE_UNKNOWN], [Arr[0]]));
1686 end;
1689 function g_Console_Interactive: Boolean;
1690 begin
1691 Result := gConsoleShow
1692 end;
1694 procedure g_Console_BindKey (key: Integer; down: AnsiString; up: AnsiString = '');
1695 begin
1696 //e_LogWritefln('bind "%s" "%s" <%s>', [LowerCase(e_KeyNames[key]), cmd, key]);
1697 ASSERT(key >= 0);
1698 ASSERT(key < e_MaxInputKeys);
1699 if key > 0 then
1700 begin
1701 gInputBinds[key].down := ParseAlias(down);
1702 gInputBinds[key].up := ParseAlias(up);
1703 end;
1704 g_Console_WriteGameConfig();
1705 end;
1707 function g_Console_MatchBind (key: Integer; down: AnsiString; up: AnsiString = ''): Boolean;
1709 function EqualsCommandLists (a, b: SSArray): Boolean;
1710 var i, len: Integer;
1711 begin
1712 result := False;
1713 len := Length(a);
1714 if len = Length(b) then
1715 begin
1716 i := 0;
1717 while (i < len) and (a[i] = b[i]) do inc(i);
1718 if i >= len then
1719 result := True
1720 end
1721 end;
1723 begin
1724 ASSERT(key >= 0);
1725 ASSERT(key < e_MaxInputKeys);
1726 result := EqualsCommandLists(ParseAlias(down), gInputBinds[key].down) and EqualsCommandLists(ParseAlias(up), gInputBinds[key].up)
1727 end;
1729 function g_Console_FindBind (n: Integer; down: AnsiString; up: AnsiString = ''): Integer;
1730 var i: Integer;
1731 begin
1732 ASSERT(n >= 1);
1733 result := 0;
1734 if commands = nil then Exit;
1735 i := 0;
1736 while (n >= 1) and (i < e_MaxInputKeys) do
1737 begin
1738 if g_Console_MatchBind(i, down, up) then
1739 begin
1740 result := i;
1741 dec(n)
1742 end;
1743 inc(i)
1744 end;
1745 if n >= 1 then
1746 result := 0
1747 end;
1749 function g_Console_Action (action: Integer): Boolean;
1750 var i, len: Integer;
1751 begin
1752 ASSERT(action >= FIRST_ACTION);
1753 ASSERT(action <= LAST_ACTION);
1754 i := 0;
1755 len := Length(gPlayerAction);
1756 while (i < len) and (not gPlayerAction[i, action]) do inc(i);
1757 Result := i < len
1758 end;
1760 function BindsAllowed (key: Integer): Boolean;
1761 begin
1762 Result := False;
1763 if (not g_GUIGrabInput) and (key >= 0) and (key < e_MaxInputKeys) and ((gInputBinds[key].down <> nil) or (gInputBinds[key].up <> nil)) then
1764 begin
1765 if gChatShow then
1766 Result := g_Console_MatchBind(key, 'togglemenu') or
1767 g_Console_MatchBind(key, 'showkeyboard') or
1768 g_Console_MatchBind(key, 'hidekeyboard')
1769 else if gConsoleShow or (g_ActiveWindow <> nil) or (gGameSettings.GameType = GT_NONE) then
1770 Result := g_Console_MatchBind(key, 'togglemenu') or
1771 g_Console_MatchBind(key, 'toggleconsole') or
1772 g_Console_MatchBind(key, 'showkeyboard') or
1773 g_Console_MatchBind(key, 'hidekeyboard')
1774 else (* in game *)
1775 Result := True
1776 end
1777 end;
1779 procedure g_Console_ProcessBind (key: Integer; down: Boolean);
1780 var i: Integer;
1781 begin
1782 if BindsAllowed(key) then
1783 begin
1784 if down then
1785 for i := 0 to High(gInputBinds[key].down) do
1786 g_Console_Process(gInputBinds[key].down[i], True)
1787 else
1788 for i := 0 to High(gInputBinds[key].up) do
1789 g_Console_Process(gInputBinds[key].up[i], True)
1790 end;
1791 if down and not menu_toggled then
1792 KeyPress(key);
1793 menu_toggled := False
1794 end;
1796 procedure g_Console_ResetBinds;
1797 var i: Integer;
1798 begin
1799 for i := 0 to e_MaxInputKeys - 1 do
1800 g_Console_BindKey(i, '', '');
1802 g_Console_BindKey(IK_GRAVE, 'toggleconsole');
1803 g_Console_BindKey(IK_ESCAPE, 'togglemenu');
1804 g_Console_BindKey(IK_A, '+p1_moveleft', '-p1_moveleft');
1805 g_Console_BindKey(IK_D, '+p1_moveright', '-p1_moveright');
1806 g_Console_BindKey(IK_W, '+p1_lookup', '-p1_lookup');
1807 g_Console_BindKey(IK_S, '+p1_lookdown', '-p1_lookdown');
1808 g_Console_BindKey(IK_SPACE, '+p1_jump', '-p1_jump');
1809 g_Console_BindKey(IK_H, '+p1_attack', '-p1_attack');
1810 g_Console_BindKey(IK_J, '+p1_activate', '-p1_activate');
1811 g_Console_BindKey(IK_E, '+p1_weapnext', '-p1_weapnext');
1812 g_Console_BindKey(IK_Q, '+p1_weapprev', '-p1_weapprev');
1813 g_Console_BindKey(IK_ALT, '+p1_strafe', '-p1_strafe');
1814 g_Console_BindKey(IK_1, 'p1_weapon 1');
1815 g_Console_BindKey(IK_2, 'p1_weapon 2');
1816 g_Console_BindKey(IK_3, 'p1_weapon 3');
1817 g_Console_BindKey(IK_4, 'p1_weapon 4');
1818 g_Console_BindKey(IK_5, 'p1_weapon 5');
1819 g_Console_BindKey(IK_6, 'p1_weapon 6');
1820 g_Console_BindKey(IK_7, 'p1_weapon 7');
1821 g_Console_BindKey(IK_8, 'p1_weapon 8');
1822 g_Console_BindKey(IK_9, 'p1_weapon 9');
1823 g_Console_BindKey(IK_0, 'p1_weapon 10');
1824 g_Console_BindKey(IK_MINUS, 'p1_weapon 11');
1825 g_Console_BindKey(IK_T, 'togglechat');
1826 g_Console_BindKey(IK_Y, 'toggleteamchat');
1827 g_Console_BindKey(IK_F11, 'screenshot');
1828 g_Console_BindKey(IK_TAB, '+p1_scores', '-p1_scores');
1829 g_Console_BindKey(IK_PAUSE, 'pause');
1830 g_Console_BindKey(IK_F1, 'vote');
1832 (* for i := 0 to e_MaxJoys - 1 do *)
1833 for i := 0 to 1 do
1834 begin
1835 g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_LEFT), '+p' + IntToStr(i mod 2 + 1) + '_moveleft', '-p' + IntToStr(i mod 2 + 1) + '_moveleft');
1836 g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_RIGHT), '+p' + IntToStr(i mod 2 + 1) + '_moveright', '-p' + IntToStr(i mod 2 + 1) + '_moveright');
1837 g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_UP), '+p' + IntToStr(i mod 2 + 1) + '_lookup', '-p' + IntToStr(i mod 2 + 1) + '_lookup');
1838 g_Console_BindKey(e_JoyHatToKey(i, 0, HAT_DOWN), '+p' + IntToStr(i mod 2 + 1) + '_lookdown', '-p' + IntToStr(i mod 2 + 1) + '_lookdown');
1839 g_Console_BindKey(e_JoyButtonToKey(i, 2), '+p' + IntToStr(i mod 2 + 1) + '_jump', '-p' + IntToStr(i mod 2 + 1) + '_jump');
1840 g_Console_BindKey(e_JoyButtonToKey(i, 0), '+p' + IntToStr(i mod 2 + 1) + '_attack', '-p' + IntToStr(i mod 2 + 1) + '_attack');
1841 g_Console_BindKey(e_JoyButtonToKey(i, 3), '+p' + IntToStr(i mod 2 + 1) + '_activate', '-p' + IntToStr(i mod 2 + 1) + '_activate');
1842 g_Console_BindKey(e_JoyButtonToKey(i, 1), '+p' + IntToStr(i mod 2 + 1) + '_weapnext', '-p' + IntToStr(i mod 2 + 1) + '_weapnext');
1843 g_Console_BindKey(e_JoyButtonToKey(i, 4), '+p' + IntToStr(i mod 2 + 1) + '_weapprev', '-p' + IntToStr(i mod 2 + 1) + '_weapprev');
1844 g_Console_BindKey(e_JoyButtonToKey(i, 7), '+p' + IntToStr(i mod 2 + 1) + '_strafe', '-p' + IntToStr(i mod 2 + 1) + '_strafe');
1845 g_Console_BindKey(e_JoyButtonToKey(i, 10), 'togglemenu');
1846 end;
1848 g_Console_BindKey(VK_ESCAPE, 'togglemenu');
1849 g_Console_BindKey(VK_LSTRAFE, '+moveleft; +strafe', '-moveleft; -strafe');
1850 g_Console_BindKey(VK_RSTRAFE, '+moveright; +strafe', '-moveright; -strafe');
1851 g_Console_BindKey(VK_LEFT, '+moveleft', '-moveleft');
1852 g_Console_BindKey(VK_RIGHT, '+moveright', '-moveright');
1853 g_Console_BindKey(VK_UP, '+lookup', '-lookup');
1854 g_Console_BindKey(VK_DOWN, '+lookdown', '-lookdown');
1855 g_Console_BindKey(VK_JUMP, '+jump', '-jump');
1856 g_Console_BindKey(VK_FIRE, '+attack', '-attack');
1857 g_Console_BindKey(VK_OPEN, '+activate', '-activate');
1858 g_Console_BindKey(VK_NEXT, '+weapnext', '-weapnext');
1859 g_Console_BindKey(VK_PREV, '+weapprev', '-weapprev');
1860 g_Console_BindKey(VK_STRAFE, '+strafe', '-strafe');
1861 g_Console_BindKey(VK_0, 'weapon 1');
1862 g_Console_BindKey(VK_1, 'weapon 2');
1863 g_Console_BindKey(VK_2, 'weapon 3');
1864 g_Console_BindKey(VK_3, 'weapon 4');
1865 g_Console_BindKey(VK_4, 'weapon 5');
1866 g_Console_BindKey(VK_5, 'weapon 6');
1867 g_Console_BindKey(VK_6, 'weapon 7');
1868 g_Console_BindKey(VK_7, 'weapon 8');
1869 g_Console_BindKey(VK_8, 'weapon 9');
1870 g_Console_BindKey(VK_9, 'weapon 10');
1871 g_Console_BindKey(VK_A, 'weapon 11');
1872 g_Console_BindKey(VK_CHAT, 'togglechat');
1873 g_Console_BindKey(VK_TEAM, 'toggleteamchat');
1874 g_Console_BindKey(VK_CONSOLE, 'toggleconsole');
1875 g_Console_BindKey(VK_PRINTSCR, 'screenshot');
1876 g_Console_BindKey(VK_STATUS, '+scores', '-scores');
1877 g_Console_BindKey(VK_SHOWKBD, 'showkeyboard');
1878 g_Console_BindKey(VK_HIDEKBD, 'hidekeyboard');
1879 end;
1881 procedure g_Console_ReadConfig (filename: String);
1882 var f: TextFile; s: AnsiString; i, len: Integer;
1883 begin
1884 if FileExists(filename) then
1885 begin
1886 AssignFile(f, filename);
1887 Reset(f);
1888 while not EOF(f) do
1889 begin
1890 ReadLn(f, s);
1891 len := Length(s);
1892 if len > 0 then
1893 begin
1894 i := 1;
1895 (* skip spaces *)
1896 while (i <= len) and (s[i] <= ' ') do inc(i);
1897 (* skip comments *)
1898 if (i <= len) and ((s[i] <> '#') and ((i + 1 > len) or (s[i] <> '/') or (s[i + 1] <> '/'))) then
1899 g_Console_Process(s, True);
1900 end
1901 end;
1902 CloseFile(f);
1903 end
1904 end;
1906 procedure g_Console_WriteConfig (filename: String);
1907 var f: TextFile; i, j: Integer;
1908 begin
1909 AssignFile(f, filename);
1910 Rewrite(f);
1911 WriteLn(f, '// generated by doom2d, do not modify');
1912 WriteLn(f, 'unbindall');
1913 for i := 0 to e_MaxInputKeys - 1 do
1914 if (Length(gInputBinds[i].down) > 0) or (Length(gInputBinds[i].up) > 0) then
1915 begin
1916 Write(f, 'bind ', e_KeyNames[i], ' ', QuoteStr(GetCommandString(gInputBinds[i].down)));
1917 if Length(gInputBinds[i].down) = 0 then
1918 Write(f, '""');
1919 if Length(gInputBinds[i].up) > 0 then
1920 Write(f, ' ', QuoteStr(GetCommandString(gInputBinds[i].up)));
1921 WriteLn(f, '');
1922 end;
1923 for i := 0 to High(commands) do
1924 begin
1925 if not commands[i].cheat then
1926 begin
1927 if @commands[i].procEx = @boolVarHandler then
1928 begin
1929 if PBoolean(commands[i].ptr)^ then j := 1 else j := 0;
1930 WriteLn(f, commands[i].cmd, ' ', j)
1931 end
1932 else if @commands[i].procEx = @intVarHandler then
1933 begin
1934 WriteLn(f, commands[i].cmd, ' ', PInteger(commands[i].ptr)^)
1935 end
1936 else if @commands[i].procEx = @singleVarHandler then
1937 begin
1938 WriteLn(f, commands[i].cmd, ' ', PVarSingle(commands[i].ptr).val^:0:6)
1939 end
1940 else if @commands[i].procEx = @strVarHandler then
1941 begin
1942 if Length(PAnsiString(commands[i].ptr)^) = 0 then
1943 WriteLn(f, commands[i].cmd, ' ""')
1944 else
1945 WriteLn(f, commands[i].cmd, ' ', QuoteStr(PAnsiString(commands[i].ptr)^))
1946 end
1947 end
1948 end;
1949 CloseFile(f)
1950 end;
1952 procedure g_Console_WriteGameConfig;
1953 begin
1954 if gParsingBinds then
1955 Exit;
1956 g_Console_WriteConfig(GameDir + '/dfconfig.cfg');
1957 end;
1959 initialization
1960 conRegVar('chat_at_top', @ChatTop, 'draw chat at top border', 'draw chat at top border');
1961 conRegVar('console_height', @ConsoleHeight, 0.0, 1.0, 'set console size', 'set console size');
1962 conRegVar('console_trans', @ConsoleTrans, 0.0, 1.0, 'set console transparency', 'set console transparency');
1963 conRegVar('console_step', @ConsoleStep, 0.0, 1.0, 'set console animation speed', 'set console animation speed');
1964 {$IFDEF ANDROID}
1965 ChatTop := True;
1966 ConsoleHeight := 0.35;
1967 {$ELSE}
1968 ChatTop := False;
1969 ConsoleHeight := 0.5;
1970 {$ENDIF}
1971 ConsoleTrans := 0.1;
1972 ConsoleStep := 0.07;
1973 end.