6cd897c6d6992237ceedbab3105922cd0f5b2e65
1 (* Copyright (C) DooM 2D:Forever Developers
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.
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.
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/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 wadreader
; // for SArray
24 procedure g_Console_Init ();
25 procedure g_Console_Update ();
26 procedure g_Console_Draw ();
27 procedure g_Console_Switch ();
28 procedure g_Console_Char (C
: AnsiChar);
29 procedure g_Console_Control (K
: Word);
30 procedure g_Console_Process (L
: AnsiString; quiet
: Boolean=false);
31 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
32 procedure g_Console_Clear ();
33 function g_Console_CommandBlacklisted (C
: AnsiString): Boolean;
35 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
36 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
38 // <0: no arg; 0/1: true/false
39 function conGetBoolArg (p
: SArray
; idx
: Integer): Integer;
41 procedure g_Console_Chat_Switch (team
: Boolean=false);
43 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false); overload
;
44 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false); overload
;
46 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
47 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
51 gConsoleShow
: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
52 gChatShow
: Boolean = false;
53 gChatTeam
: Boolean = false;
54 gAllowConsoleMessages
: Boolean = true;
55 gChatEnter
: Boolean = true;
56 gJustChatted
: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
62 g_textures
, g_main
, e_graphics
, e_input
, g_game
,
63 SysUtils
, g_basic
, g_options
, Math
,
64 g_menu
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
, utils
;
70 TCmdProc
= procedure (p
: SArray
);
71 TCmdProcEx
= procedure (me
: PCommand
; p
: SArray
);
79 ptr
: Pointer; // various data
80 msg
: AnsiString; // message for var changes
94 MaxScriptRecursion
= 16;
96 DEBUG_STRING
= 'DEBUG MODE';
100 RecursionDepth
: Word = 0;
101 RecursionLimitHit
: Boolean = False;
103 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
106 //ConsoleHistory: SArray;
107 CommandHistory
: SArray
;
109 commands
: Array of TCommand
= nil;
110 Aliases
: Array of TAlias
= nil;
112 conSkipLines
: Integer = 0;
113 MsgArray
: Array [0..4] of record
119 // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
120 function conParseFloat (var res
: Single; const s
: AnsiString): Boolean;
129 while (slen
> 0) and (s
[slen
] <= ' ') do Dec(slen
);
130 while (pos
<= slen
) and (s
[pos
] <= ' ') do Inc(pos
);
131 if (pos
> slen
) then exit
;
132 if (slen
-pos
= 1) and (s
[pos
] = '.') then exit
; // single dot
134 while (pos
<= slen
) do
136 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
137 res
:= res
*10+Byte(s
[pos
])-48;
140 if (pos
<= slen
) then
143 if (s
[pos
] <> '.') then exit
;
145 while (pos
<= slen
) do
147 if (s
[pos
] < '0') or (s
[pos
] > '9') then break
;
149 res
+= frac
*(Byte(s
[pos
])-48);
153 if (pos
<= slen
) then exit
; // oops
158 // ////////////////////////////////////////////////////////////////////////// //
159 // <0: no arg; 0/1: true/false; 666: toggle
160 function conGetBoolArg (p
: SArray
; idx
: Integer): Integer;
162 if (idx
< 0) or (idx
> High(p
)) then begin result
:= -1; exit
; end;
164 if (p
[idx
] = '1') or (CompareText(p
[idx
], 'on') = 0) or (CompareText(p
[idx
], 'true') = 0) or
165 (CompareText(p
[idx
], 'tan') = 0) or (CompareText(p
[idx
], 'yes') = 0) then result
:= 1
166 else if (CompareText(p
[idx
], 'toggle') = 0) or (CompareText(p
[idx
], 'switch') = 0) or
167 (CompareText(p
[idx
], 't') = 0) then result
:= 666;
171 procedure boolVarHandler (me
: PCommand
; p
: SArray
);
172 procedure binaryFlag (var flag
: Boolean; msg
: AnsiString);
174 if (Length(p
) > 2) then
176 conwritefln('too many arguments to ''%s''', [p
[0]]);
180 case conGetBoolArg(p
, 1) of
182 0: if not me
.cheat
or conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
183 1: if not me
.cheat
or conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
184 666: if not me
.cheat
or conIsCheatsEnabled
then flag
:= not flag
else begin conwriteln('not available'); exit
; end;
186 if flag
then conwritefln('%s: tan', [msg
]) else conwritefln('%s: ona', [msg
]);
190 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
194 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false); overload
;
199 f
:= Length(commands
);
200 SetLength(commands
, f
+1);
202 cp
.cmd
:= LowerCase(conname
);
204 cp
.procEx
:= boolVarHandler
;
213 // ////////////////////////////////////////////////////////////////////////// //
215 PVarSingle
= ^TVarSingle
;
218 min
, max
, def
: Single; // default will be starting value
222 procedure singleVarHandler (me
: PCommand
; p
: SArray
);
228 if (Length(p
) > 2) then
230 conwritefln('too many arguments to ''%s''', [p
[0]]);
233 pv
:= PVarSingle(me
.ptr
);
234 if (Length(p
) = 2) then
236 if me
.cheat
and (not conIsCheatsEnabled
) then begin conwriteln('not available'); exit
; end;
237 if (CompareText(p
[1], 'default') = 0) or (CompareText(p
[1], 'def') = 0) or
238 (CompareText(p
[1], 'd') = 0) or (CompareText(p
[1], 'off') = 0) or
239 (CompareText(p
[1], 'ona') = 0) then
245 if not conParseFloat(nv
, p
[1]) then
247 conwritefln('%s: ''%s'' doesn''t look like a floating number', [p
[0], p
[1]]);
250 if (nv
< pv
.min
) then nv
:= pv
.min
;
251 if (nv
> pv
.max
) then nv
:= pv
.max
;
256 if (Length(msg
) = 0) then msg
:= p
[0] else msg
+= ':';
257 conwritefln('%s %s', [msg
, pv
.val
^]);
261 procedure conRegVar (const conname
: AnsiString; pvar
: PSingle; amin
, amax
: Single; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false); overload
;
267 GetMem(pv
, sizeof(pv
^));
272 f
:= Length(commands
);
273 SetLength(commands
, f
+1);
275 cp
.cmd
:= LowerCase(conname
);
277 cp
.procEx
:= singleVarHandler
;
286 // ////////////////////////////////////////////////////////////////////////// //
287 function GetStrACmd(var Str
: AnsiString): AnsiString;
292 for a
:= 1 to Length(Str
) do
293 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
295 Result
:= Copy(Str
, 1, a
);
302 function ParseAlias(Str
: AnsiString): SArray
;
313 SetLength(Result
, Length(Result
)+1);
314 Result
[High(Result
)] := GetStrACmd(Str
);
318 procedure ConsoleCommands(p
: SArray
);
324 cmd
:= LowerCase(p
[0]);
327 if cmd
= 'clear' then
329 //ConsoleHistory := nil;
333 for a
:= 0 to High(MsgArray
) do
341 if cmd
= 'clearhistory' then
342 CommandHistory
:= nil;
344 if cmd
= 'showhistory' then
345 if CommandHistory
<> nil then
348 for a
:= 0 to High(CommandHistory
) do
349 g_Console_Add(' '+CommandHistory
[a
]);
352 if cmd
= 'commands' then
355 g_Console_Add('commands list:');
356 for a
:= High(commands
) downto 0 do
358 if (Length(commands
[a
].help
) > 0) then
360 g_Console_Add(' '+commands
[a
].cmd
+' -- '+commands
[a
].help
);
364 g_Console_Add(' '+commands
[a
].cmd
);
370 g_Console_Add(TimeToStr(Now
), True);
373 g_Console_Add(DateToStr(Now
), True);
376 if Length(p
) > 1 then
378 if p
[1] = 'ololo' then
383 for a
:= 1 to High(p
) do
385 g_Console_Add(b_Text_Format(s
), True);
394 if ConsoleHistory <> nil then
396 if Length(P) > 1 then
399 s := GameDir+'/console.txt';
404 if IOResult <> 0 then
406 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
411 for a := 0 to High(ConsoleHistory) do
412 WriteLn(F, ConsoleHistory[a]);
415 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
424 if Length(p
) > 1 then
426 s
:= GameDir
+'/'+p
[1];
431 if IOResult
<> 0 then
433 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
437 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
442 if IOResult
<> 0 then
444 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
448 if Pos('#', s
) <> 1 then // script comment
450 // prevents endless loops
452 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
453 if not RecursionLimitHit
then
454 g_Console_Process(s
, True);
458 if (RecursionDepth
= 0) and RecursionLimitHit
then
460 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
461 RecursionLimitHit
:= False;
468 g_Console_Add('exec <script file>');
471 if cmd
= 'alias' then
473 // alias [alias_name] [commands]
474 if Length(p
) > 1 then
476 for a
:= 0 to High(Aliases
) do
477 if Aliases
[a
].name
= p
[1] then
479 if Length(p
) > 2 then
480 Aliases
[a
].commands
:= ParseAlias(p
[2])
482 for b
:= 0 to High(Aliases
[a
].commands
) do
483 g_Console_Add(Aliases
[a
].commands
[b
]);
486 SetLength(Aliases
, Length(Aliases
)+1);
488 Aliases
[a
].name
:= p
[1];
489 if Length(p
) > 2 then
490 Aliases
[a
].commands
:= ParseAlias(p
[2])
492 for b
:= 0 to High(Aliases
[a
].commands
) do
493 g_Console_Add(Aliases
[a
].commands
[b
]);
495 for a
:= 0 to High(Aliases
) do
496 if Aliases
[a
].commands
<> nil then
497 g_Console_Add(Aliases
[a
].name
);
503 if Length(p
) > 1 then
505 if Aliases
= nil then
507 for a
:= 0 to High(Aliases
) do
508 if Aliases
[a
].name
= p
[1] then
510 if Aliases
[a
].commands
<> nil then
512 // with this system proper endless loop detection seems either impossible
513 // or very dirty to implement, so let's have this instead
514 // prevents endless loops
515 for b
:= 0 to High(Aliases
[a
].commands
) do
518 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
519 if not RecursionLimitHit
then
520 g_Console_Process(Aliases
[a
].commands
[b
], True);
523 if (RecursionDepth
= 0) and RecursionLimitHit
then
525 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
526 RecursionLimitHit
:= False;
533 g_Console_Add('call <alias name>');
537 procedure WhitelistCommand(cmd
: AnsiString);
541 SetLength(Whitelist
, Length(Whitelist
)+1);
542 a
:= High(Whitelist
);
543 Whitelist
[a
] := LowerCase(cmd
);
546 procedure AddCommand(cmd
: AnsiString; proc
: TCmdProc
; ahelp
: AnsiString=''; ahidden
: Boolean=false; acheat
: Boolean=false);
551 SetLength(commands
, Length(commands
)+1);
554 cp
.cmd
:= LowerCase(cmd
);
558 cp
.hidden
:= ahidden
;
564 procedure g_Console_Init();
568 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
569 Cons_Y
:= -(gScreenHeight
div 2);
570 gConsoleShow
:= False;
575 for a
:= 0 to High(MsgArray
) do
582 AddCommand('clear', ConsoleCommands
, 'clear console');
583 AddCommand('clearhistory', ConsoleCommands
);
584 AddCommand('showhistory', ConsoleCommands
);
585 AddCommand('commands', ConsoleCommands
);
586 AddCommand('time', ConsoleCommands
);
587 AddCommand('date', ConsoleCommands
);
588 AddCommand('echo', ConsoleCommands
);
589 AddCommand('dump', ConsoleCommands
);
590 AddCommand('exec', ConsoleCommands
);
591 AddCommand('alias', ConsoleCommands
);
592 AddCommand('call', ConsoleCommands
);
594 AddCommand('d_window', DebugCommands
);
595 AddCommand('d_sounds', DebugCommands
);
596 AddCommand('d_frames', DebugCommands
);
597 AddCommand('d_winmsg', DebugCommands
);
598 AddCommand('d_monoff', DebugCommands
);
599 AddCommand('d_botoff', DebugCommands
);
600 AddCommand('d_monster', DebugCommands
);
601 AddCommand('d_health', DebugCommands
);
602 AddCommand('d_player', DebugCommands
);
603 AddCommand('d_joy', DebugCommands
);
605 AddCommand('p1_name', GameCVars
);
606 AddCommand('p2_name', GameCVars
);
607 AddCommand('p1_color', GameCVars
);
608 AddCommand('p2_color', GameCVars
);
609 AddCommand('r_showfps', GameCVars
);
610 AddCommand('r_showtime', GameCVars
);
611 AddCommand('r_showscore', GameCVars
);
612 AddCommand('r_showlives', GameCVars
);
613 AddCommand('r_showstat', GameCVars
);
614 AddCommand('r_showkillmsg', GameCVars
);
615 AddCommand('r_showspect', GameCVars
);
616 AddCommand('r_showping', GameCVars
);
617 AddCommand('g_gamemode', GameCVars
);
618 AddCommand('g_friendlyfire', GameCVars
);
619 AddCommand('g_weaponstay', GameCVars
);
620 AddCommand('g_allow_exit', GameCVars
);
621 AddCommand('g_allow_monsters', GameCVars
);
622 AddCommand('g_bot_vsmonsters', GameCVars
);
623 AddCommand('g_bot_vsplayers', GameCVars
);
624 AddCommand('g_scorelimit', GameCVars
);
625 AddCommand('g_timelimit', GameCVars
);
626 AddCommand('g_maxlives', GameCVars
);
627 AddCommand('g_warmuptime', GameCVars
);
628 AddCommand('net_interp', GameCVars
);
629 AddCommand('net_forceplayerupdate', GameCVars
);
630 AddCommand('net_predictself', GameCVars
);
631 AddCommand('sv_name', GameCVars
);
632 AddCommand('sv_passwd', GameCVars
);
633 AddCommand('sv_maxplrs', GameCVars
);
634 AddCommand('sv_public', GameCVars
);
635 AddCommand('sv_intertime', GameCVars
);
637 AddCommand('quit', GameCommands
);
638 AddCommand('exit', GameCommands
);
639 AddCommand('pause', GameCommands
);
640 AddCommand('endgame', GameCommands
);
641 AddCommand('restart', GameCommands
);
642 AddCommand('addbot', GameCommands
);
643 AddCommand('bot_add', GameCommands
);
644 AddCommand('bot_addlist', GameCommands
);
645 AddCommand('bot_addred', GameCommands
);
646 AddCommand('bot_addblue', GameCommands
);
647 AddCommand('bot_removeall', GameCommands
);
648 AddCommand('chat', GameCommands
);
649 AddCommand('teamchat', GameCommands
);
650 AddCommand('game', GameCommands
);
651 AddCommand('host', GameCommands
);
652 AddCommand('map', GameCommands
);
653 AddCommand('nextmap', GameCommands
);
654 AddCommand('endmap', GameCommands
);
655 AddCommand('goodbye', GameCommands
);
656 AddCommand('suicide', GameCommands
);
657 AddCommand('spectate', GameCommands
);
658 AddCommand('ready', GameCommands
);
659 AddCommand('kick', GameCommands
);
660 AddCommand('kick_id', GameCommands
);
661 AddCommand('ban', GameCommands
);
662 AddCommand('permban', GameCommands
);
663 AddCommand('ban_id', GameCommands
);
664 AddCommand('permban_id', GameCommands
);
665 AddCommand('unban', GameCommands
);
666 AddCommand('connect', GameCommands
);
667 AddCommand('disconnect', GameCommands
);
668 AddCommand('reconnect', GameCommands
);
669 AddCommand('say', GameCommands
);
670 AddCommand('tell', GameCommands
);
671 AddCommand('overtime', GameCommands
);
672 AddCommand('rcon_password', GameCommands
);
673 AddCommand('rcon', GameCommands
);
674 AddCommand('callvote', GameCommands
);
675 AddCommand('vote', GameCommands
);
676 AddCommand('clientlist', GameCommands
);
677 AddCommand('event', GameCommands
);
679 AddCommand('god', GameCheats
);
680 AddCommand('notarget', GameCheats
);
681 AddCommand('give', GameCheats
); // "exit" too ;-)
682 AddCommand('open', GameCheats
);
683 AddCommand('fly', GameCheats
);
684 AddCommand('noclip', GameCheats
);
685 AddCommand('speedy', GameCheats
);
686 AddCommand('jumpy', GameCheats
);
687 AddCommand('noreload', GameCheats
);
688 AddCommand('aimline', GameCheats
);
689 AddCommand('automap', GameCheats
);
691 WhitelistCommand('say');
692 WhitelistCommand('tell');
693 WhitelistCommand('overtime');
694 WhitelistCommand('ready');
695 WhitelistCommand('map');
696 WhitelistCommand('nextmap');
697 WhitelistCommand('endmap');
698 WhitelistCommand('restart');
699 WhitelistCommand('kick');
700 WhitelistCommand('ban');
702 WhitelistCommand('addbot');
703 WhitelistCommand('bot_add');
704 WhitelistCommand('bot_addred');
705 WhitelistCommand('bot_addblue');
706 WhitelistCommand('bot_removeall');
708 WhitelistCommand('g_gamemode');
709 WhitelistCommand('g_friendlyfire');
710 WhitelistCommand('g_weaponstay');
711 WhitelistCommand('g_allow_exit');
712 WhitelistCommand('g_allow_monsters');
713 WhitelistCommand('g_scorelimit');
714 WhitelistCommand('g_timelimit');
716 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
720 procedure g_Console_Update();
726 // Â ïðîöåññå îòêðûòèÿ:
727 if gConsoleShow
and (Cons_Y
< 0) then
729 Cons_Y
:= Cons_Y
+Step
;
732 // Â ïðîöåññå çàêðûòèÿ:
733 if (not gConsoleShow
) and
734 (Cons_Y
> -(gScreenHeight
div 2)) then
735 Cons_Y
:= Cons_Y
-Step
;
737 // Îêîí÷àòåëüíî îòêðûëàñü:
741 // Îêîí÷àòåëüíî çàêðûëàñü:
742 if Cons_Y
<= (-(gScreenHeight
div 2)) then
744 Cons_Y
:= -(gScreenHeight
div 2);
750 while a
<= High(MsgArray
) do
752 if MsgArray
[a
].Time
> 0 then
754 if MsgArray
[a
].Time
= 1 then
756 if a
< High(MsgArray
) then
758 for b
:= a
to High(MsgArray
)-1 do
759 MsgArray
[b
] := MsgArray
[b
+1];
761 MsgArray
[High(MsgArray
)].Time
:= 0;
767 Dec(MsgArray
[a
].Time
);
775 procedure drawConsoleText ();
777 CWidth
, CHeight
: Byte;
782 procedure putLine (sp
, ep
: LongWord);
791 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
792 if wdt
+cw
> gScreenWidth
-8 then break
;
793 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
797 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
798 // now print our part
806 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
807 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
820 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
821 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
822 skip
:= conSkipLines
;
823 cbufLastLine(sp
, ep
);
826 if ty
+CHeight
<= 0 then break
;
827 until not cbufLineUp(sp
, ep
);
830 procedure g_Console_Draw();
832 CWidth
, CHeight
: Byte;
836 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
838 for a
:= 0 to High(MsgArray
) do
839 if MsgArray
[a
].Time
> 0 then
840 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
843 if not Cons_Shown
then
849 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
850 gStdFont
, 255, 255, 255, 1, True);
851 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
852 gStdFont
, 255, 255, 255, 1, True);
856 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
857 gStdFont
, 255, 255, 255, 1, True);
858 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
859 gStdFont
, 255, 255, 255, 1, True);
867 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
868 a
:= (gScreenWidth
- 2*mfW
) div 2;
869 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
870 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
871 _RGB(128, 0, 0), 2.0);
874 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
875 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
879 if ConsoleHistory <> nil then
883 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
884 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
886 b := Max(b-Offset, 0);
887 d := Max(High(ConsoleHistory)-Offset, 0);
890 for a := d downto b do
892 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
899 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
902 procedure g_Console_Switch();
904 if gChatShow
then Exit
;
905 gConsoleShow
:= not gConsoleShow
;
909 procedure g_Console_Chat_Switch(Team
: Boolean = False);
911 if gConsoleShow
then Exit
;
912 if not g_Game_IsNet
then Exit
;
913 gChatShow
:= not gChatShow
;
921 procedure g_Console_Char(C
: AnsiChar);
923 if gChatShow
and (not gChatEnter
) then
925 Insert(C
, Line
, CPos
);
931 tcomplist
: array of AnsiString = nil;
932 tcompidx
: array of Integer = nil;
934 procedure Complete ();
938 ll
, lpfx
, cmd
: AnsiString;
940 if (Length(Line
) = 0) then
943 for i
:= 0 to High(commands
) do
945 if not commands
[i
].hidden
then
947 if (Length(commands
[i
].help
) > 0) then
949 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
953 g_Console_Add(' '+commands
[i
].cmd
);
960 ll
:= LowerCase(Line
);
963 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
965 ll
:= Copy(ll
, 0, Length(ll
)-1);
966 for i
:= 0 to High(commands
) do
968 if commands
[i
].hidden
then continue
;
969 if (commands
[i
].cmd
= ll
) then
971 if (Length(commands
[i
].help
) > 0) then
973 g_Console_Add(' '+commands
[i
].cmd
+' -- '+commands
[i
].help
);
980 // build completion list
982 for i
:= 0 to High(commands
) do
984 if commands
[i
].hidden
then continue
;
985 cmd
:= commands
[i
].cmd
;
986 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
988 if (tused
= Length(tcomplist
)) then
990 SetLength(tcomplist
, Length(tcomplist
)+128);
991 SetLength(tcompidx
, Length(tcompidx
)+128);
993 tcomplist
[tused
] := cmd
;
994 tcompidx
[tused
] := i
;
996 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
1000 // get longest prefix
1001 for i
:= 0 to tused
-1 do
1003 cmd
:= tcomplist
[i
];
1004 for c
:= 1 to Length(lpfx
) do
1006 if (c
> Length(cmd
)) then break
;
1007 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
1011 if (tused
= 0) then exit
;
1015 Line
:= tcomplist
[0]+' ';
1016 CPos
:= Length(Line
)+1;
1020 // has longest prefix?
1021 if (Length(lpfx
) > Length(ll
)) then
1024 CPos
:= Length(Line
)+1;
1029 for i
:= 0 to tused
-1 do
1031 if (Length(commands
[tcompidx
[i
]].help
) > 0) then
1033 g_Console_Add(' '+tcomplist
[i
]+' -- '+commands
[tcompidx
[i
]].help
);
1037 g_Console_Add(' '+tcomplist
[i
]);
1045 procedure g_Console_Control(K
: Word);
1049 if (Length(Line
) > 0) and (CPos
> 1) then
1051 Delete(Line
, CPos
-1, 1);
1055 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
1056 Delete(Line
, CPos
, 1);
1060 IK_RIGHT
, IK_KPRIGHT
:
1061 if CPos
<= Length(Line
) then
1063 IK_RETURN
, IK_KPRETURN
:
1066 g_Console_Process(Line
)
1070 if (Length(Line
) > 0) and g_Game_IsNet
then
1074 if g_Game_IsClient
then
1075 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
1077 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1078 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
1082 if g_Game_IsClient
then
1083 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
1085 MH_SEND_Chat('[' + gPlayer1Settings
.name
+ ']: ' + b_Text_Format(Line
),
1093 gJustChatted
:= True;
1097 if not gChatShow
then
1100 if not gChatShow
then
1101 if (CommandHistory
<> nil) and
1102 (CmdIndex
< Length(CommandHistory
)) then
1104 if CmdIndex
< Length(CommandHistory
)-1 then
1105 CmdIndex
:= CmdIndex
+ 1;
1106 Line
:= CommandHistory
[CmdIndex
];
1107 CPos
:= Length(Line
) + 1;
1110 if not gChatShow
then
1111 if (CommandHistory
<> nil) and
1112 (CmdIndex
<= Length(CommandHistory
)) then
1114 if CmdIndex
> 0 then
1115 CmdIndex
:= CmdIndex
- 1;
1116 Line
:= CommandHistory
[CmdIndex
];
1117 Cpos
:= Length(Line
) + 1;
1119 IK_PAGEUP
, IK_KPPAGEUP
: // PgUp
1120 if not gChatShow
then Inc(conSkipLines
);
1121 IK_PAGEDN
, IK_KPPAGEDN
: // PgDown
1122 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1126 CPos
:= Length(Line
) + 1;
1130 function GetStr(var Str
: AnsiString): AnsiString;
1135 if Str
[1] = '"' then
1137 for b
:= 1 to Length(Str
) do
1138 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1140 Result
:= Copy(Str
, 2, b
-1);
1141 Delete(Str
, 1, b
+1);
1147 for a
:= 1 to Length(Str
) do
1148 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1150 Result
:= Copy(Str
, 1, a
);
1151 Delete(Str
, 1, a
+1);
1157 function ParseString(Str
: AnsiString): SArray
;
1168 SetLength(Result
, Length(Result
)+1);
1169 Result
[High(Result
)] := GetStr(Str
);
1173 procedure g_Console_Add (L
: AnsiString; show
: Boolean=false);
1175 procedure conmsg (s
: AnsiString);
1179 if length(s
) = 0 then exit
;
1180 for a
:= 0 to High(MsgArray
) do
1192 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1193 with MsgArray
[High(MsgArray
)] do
1203 // put it to console
1205 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1207 // now show 'em out of console too
1208 show
:= show
and gAllowConsoleMessages
;
1209 if show
and gShowMessages
then
1211 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1212 while length(L
) > 0 do
1215 if f
<= 0 then f
:= length(L
)+1;
1216 conmsg(Copy(L
, 1, f
-1));
1221 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1222 //ConsoleHistory[High(ConsoleHistory)] := L;
1226 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1233 consolewriterLastWasEOL
: Boolean = false;
1235 procedure consolewriter (constref buf
; len
: SizeUInt
);
1239 if (len
< 1) then exit
;
1241 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1244 if (b
[0] <> 13) and (b
[0] <> 10) then
1246 cbufPut(AnsiChar(b
[0]));
1250 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1259 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1260 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1261 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1262 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1264 g_Console_Add(s
, show
);
1268 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1272 g_Console_Add(formatstrf(s
, args
), true);
1276 consolewriterLastWasEOL
:= false;
1277 formatstrf(s
, args
, consolewriter
);
1278 if not consolewriterLastWasEOL
then cbufPut(#10);
1283 procedure g_Console_Clear();
1285 //ConsoleHistory := nil;
1290 procedure AddToHistory(L
: AnsiString);
1294 len
:= Length(CommandHistory
);
1297 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1299 SetLength(CommandHistory
, len
+1);
1300 CommandHistory
[len
] := L
;
1303 CmdIndex
:= Length(CommandHistory
);
1306 function g_Console_CommandBlacklisted(C
: AnsiString): Boolean;
1315 if Trim(C
) = '' then
1318 Arr
:= ParseString(C
);
1322 for i
:= 0 to High(Whitelist
) do
1323 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1327 procedure g_Console_Process(L
: AnsiString; quiet
: Boolean = False);
1334 if Trim(L
) = '' then
1337 conSkipLines
:= 0; // "unscroll"
1339 if L
= 'goobers' then
1344 g_Console_Add('Your memory serves you well.');
1350 g_Console_Add('> '+L
);
1355 Arr
:= ParseString(L
);
1359 if commands
= nil then
1365 for i
:= 0 to High(commands
) do
1367 if commands
[i
].cmd
= LowerCase(Arr
[0]) then
1369 if assigned(commands
[i
].procEx
) then
1371 commands
[i
].procEx(@commands
[i
], Arr
);
1374 if assigned(commands
[i
].proc
) then
1376 commands
[i
].proc(Arr
);
1382 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));