diff --git a/src/game/g_console.pas b/src/game/g_console.pas
index e0f401deeade15964e5c93c103ecebfa6065088c..3bceba1c742bcdf4a8fbb877e38a1ebe170a9a5f 100644 (file)
--- a/src/game/g_console.pas
+++ b/src/game/g_console.pas
procedure g_Console_Chat_Switch (team: Boolean=false);
-procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false); overload;
-procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false); overload;
+procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
+procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
+
+// poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
+function conParseFloat (var res: Single; const s: AnsiString): Boolean;
var
end;
+// poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
+function conParseFloat (var res: Single; const s: AnsiString): Boolean;
+var
+ pos: Integer = 1;
+ frac: Single = 1;
+ slen: Integer;
+begin
+ result := false;
+ res := 0;
+ slen := Length(s);
+ while (slen > 0) and (s[slen] <= ' ') do Dec(slen);
+ while (pos <= slen) and (s[pos] <= ' ') do Inc(pos);
+ if (pos > slen) then exit;
+ if (slen-pos = 1) and (s[pos] = '.') then exit; // single dot
+ // integral part
+ while (pos <= slen) do
+ begin
+ if (s[pos] < '0') or (s[pos] > '9') then break;
+ res := res*10+Byte(s[pos])-48;
+ Inc(pos);
+ end;
+ if (pos <= slen) then
+ begin
+ // must be a dot
+ if (s[pos] <> '.') then exit;
+ Inc(pos);
+ while (pos <= slen) do
+ begin
+ if (s[pos] < '0') or (s[pos] > '9') then break;
+ frac := frac/10;
+ res += frac*(Byte(s[pos])-48);
+ Inc(pos);
+ end;
+ end;
+ if (pos <= slen) then exit; // oops
+ result := true;
+end;
+
+
// ////////////////////////////////////////////////////////////////////////// //
// <0: no arg; 0/1: true/false; 666: toggle
function conGetBoolArg (p: SArray; idx: Integer): Integer;
begin
case conGetBoolArg(p, 1) of
-1: begin end;
- 0: if conIsCheatsEnabled then flag := false else begin conwriteln('not available'); exit; end;
- 1: if conIsCheatsEnabled then flag := true else begin conwriteln('not available'); exit; end;
- 666: if conIsCheatsEnabled then flag := not flag else begin conwriteln('not available'); exit; end;
+ 0: if not me.cheat or conIsCheatsEnabled then flag := false else begin conwriteln('not available'); exit; end;
+ 1: if not me.cheat or conIsCheatsEnabled then flag := true else begin conwriteln('not available'); exit; end;
+ 666: if not me.cheat or conIsCheatsEnabled then flag := not flag else begin conwriteln('not available'); exit; end;
end;
- if flag then conwritefln('%s: tan', [msg]) else conwritefln('%s: ona', [msg]);
+ if (Length(msg) = 0) then msg := p[0] else msg += ':';
+ if flag then conwritefln('%s tan', [msg]) else conwritefln('%s ona', [msg]);
end;
end;
begin
end;
-procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false); overload;
+procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
var
f: Integer;
cp: PCommand;
cp.proc := nil;
cp.procEx := boolVarHandler;
cp.help := ahelp;
- cp.hidden := false;
+ cp.hidden := ahidden;
cp.ptr := pvar;
cp.msg := amsg;
cp.cheat := acheat;
procedure singleVarHandler (me: PCommand; p: SArray);
- // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks
- function parseFloat (var res: Single; const s: AnsiString): Boolean;
- var
- pos: Integer = 1;
- frac: Single = 1;
- slen: Integer;
- begin
- result := false;
- res := 0;
- slen := Length(s);
- while (slen > 0) and (s[slen] <= ' ') do Dec(slen);
- while (pos <= slen) and (s[pos] <= ' ') do Inc(pos);
- if (pos > slen) then exit;
- if (slen-pos = 1) and (s[pos] = '.') then exit; // single dot
- // integral part
- while (pos <= slen) do
- begin
- if (s[pos] < '0') or (s[pos] > '9') then break;
- res := res*10+Byte(s[pos])-48;
- Inc(pos);
- end;
- if (pos <= slen) then
- begin
- // must be a dot
- if (s[pos] <> '.') then exit;
- Inc(pos);
- while (pos <= slen) do
- begin
- if (s[pos] < '0') or (s[pos] > '9') then break;
- frac := frac/10;
- res += frac*(Byte(s[pos])-48);
- Inc(pos);
- end;
- end;
- if (pos <= slen) then exit; // oops
- result := true;
- end;
var
pv: PVarSingle;
nv: Single;
begin
if (Length(p) > 2) then
begin
- conwritefln('too many arguments to ''%s''', [p[0]]);
+ conwritefln('too many arguments to ''%s''', [me.cmd]);
exit;
end;
pv := PVarSingle(me.ptr);
if (Length(p) = 2) then
begin
- if not conIsCheatsEnabled then begin conwriteln('not available'); exit; end;
+ if me.cheat and (not conIsCheatsEnabled) then begin conwriteln('not available'); exit; end;
if (CompareText(p[1], 'default') = 0) or (CompareText(p[1], 'def') = 0) or
(CompareText(p[1], 'd') = 0) or (CompareText(p[1], 'off') = 0) or
(CompareText(p[1], 'ona') = 0) then
end
else
begin
- if not parseFloat(nv, p[1]) then
+ if not conParseFloat(nv, p[1]) then
begin
- conwritefln('%s: ''%s'' doesn''t look like a floating number', [p[0], p[1]]);
+ conwritefln('%s: ''%s'' doesn''t look like a floating number', [me.cmd, p[1]]);
exit;
end;
if (nv < pv.min) then nv := pv.min;
end;
end;
msg := me.msg;
- if (Length(msg) = 0) then msg := p[0] else msg += ':';
+ if (Length(msg) = 0) then msg := me.cmd else msg += ':';
conwritefln('%s %s', [msg, pv.val^]);
end;
-procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false); overload;
+procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload;
var
f: Integer;
cp: PCommand;
cp.proc := nil;
cp.procEx := singleVarHandler;
cp.help := ahelp;
- cp.hidden := false;
+ cp.hidden := ahidden;
cp.ptr := pv;
cp.msg := amsg;
cp.cheat := acheat;
cp.cheat := acheat;
end;
+
+procedure segfault (p: SArray);
+var
+ pp: PByte = nil;
+begin
+ pp^ := 0;
+end;
+
+
procedure g_Console_Init();
var
a: Integer;
Time := 0;
end;
+ AddCommand('segfault', segfault, 'make segfault');
+
AddCommand('clear', ConsoleCommands, 'clear console');
AddCommand('clearhistory', ConsoleCommands);
AddCommand('showhistory', ConsoleCommands);
g_Console_Add('');
for i := 0 to High(commands) do
begin
- if not commands[i].hidden then
+ // hidden commands are hidden when cheats aren't enabled
+ if commands[i].hidden and not conIsCheatsEnabled then continue;
+ if (Length(commands[i].help) > 0) then
begin
- if (Length(commands[i].help) > 0) then
- begin
- g_Console_Add(' '+commands[i].cmd+' -- '+commands[i].help);
- end
- else
- begin
- g_Console_Add(' '+commands[i].cmd);
- end;
+ g_Console_Add(' '+commands[i].cmd+' -- '+commands[i].help);
+ end
+ else
+ begin
+ g_Console_Add(' '+commands[i].cmd);
end;
end;
exit;
ll := Copy(ll, 0, Length(ll)-1);
for i := 0 to High(commands) do
begin
- if commands[i].hidden then continue;
+ // hidden commands are hidden when cheats aren't enabled
+ if commands[i].hidden and not conIsCheatsEnabled then continue;
if (commands[i].cmd = ll) then
begin
if (Length(commands[i].help) > 0) then
tused := 0;
for i := 0 to High(commands) do
begin
- if commands[i].hidden then continue;
+ // hidden commands are hidden when cheats aren't enabled
+ if commands[i].hidden and not conIsCheatsEnabled then continue;
cmd := commands[i].cmd;
if (Length(cmd) >= Length(ll)) and (ll = Copy(cmd, 0, Length(ll))) then
begin
g_Console_Add(Format(_lc[I_CONSOLE_UNKNOWN], [Arr[0]]));
end;
+
end.