Skip to content

Commit

Permalink
Only allow fs_localmount to be set from the command line, use a commo…
Browse files Browse the repository at this point in the history
…n change function for such cvars.
  • Loading branch information
BranDougherty committed Jul 26, 2022
1 parent 9f07596 commit 055d2a6
Showing 1 changed file with 6 additions and 48 deletions.
54 changes: 6 additions & 48 deletions shared/Cvar.pas
Expand Up @@ -198,11 +198,11 @@ function killlimitChange(Cvar: TStringCvar; NewValue: Integer): Boolean;

{$PUSH}
{$WARN 5024 OFF : Parameter "$1" not used}
function fs_portableChange(Cvar: TCvarBase; NewValue: Boolean): Boolean;
function CommandLineOnlyChange(Cvar: TCvarBase; NewValue: Boolean): Boolean;
begin
if (UserDirectory <> '') or (BaseDirectory <> '') then
begin
Cvar.FErrorMessage := 'fs_portable must be set from the command line';
Cvar.FErrorMessage := Cvar.Name + ' must be set from the command line';
Result := False;
Exit;
end;
Expand All @@ -211,48 +211,6 @@ function fs_portableChange(Cvar: TCvarBase; NewValue: Boolean): Boolean;
end;
{$POP}

function fs_basepathChange(Cvar: TCvarBase; NewValue: String): Boolean;
begin
if BaseDirectory <> '' then
begin
Cvar.FErrorMessage := 'fs_basepath must be set from the command line';
Result := False;
Exit;
end;

if DirectoryExists(NewValue) then
begin
BaseDirectory := IncludeTrailingPathDelimiter(NewValue);
Result := True;
end
else
begin
Cvar.FErrorMessage := 'The specified path does not exist';
Result := False;
end;
end;

function fs_userpathChange(Cvar: TCvarBase; NewValue: String): Boolean;
begin
if UserDirectory <> '' then
begin
Cvar.FErrorMessage := 'fs_userpath must be set from the command line';
Result := False;
Exit;
end;

if DirectoryExists(NewValue) then
begin
UserDirectory := IncludeTrailingPathDelimiter(NewValue);
Result := True;
end
else
begin
Cvar.FErrorMessage := 'The specified path does not exist';
Result := False;
end;
end;

function sv_gravityChange(Cvar: TCvarBase; NewValue: Single): Boolean;
begin
Cvar := Cvar;
Expand Down Expand Up @@ -760,11 +718,11 @@ procedure CvarInit();
{$ENDIF}
{$ENDIF}

fs_localmount := TBooleanCvar.Add('fs_localmount', 'Mount game directory as game mod', False, False, [CVAR_CLIENT, CVAR_INITONLY], nil);
fs_localmount := TBooleanCvar.Add('fs_localmount', 'Mount game directory as game mod', False, False, [CVAR_CLIENT, CVAR_INITONLY], @CommandLineOnlyChange);
fs_mod := TStringCvar.Add('fs_mod', 'File name of mod placed in mods directory (without .smod extension)', '', '', [CVAR_INITONLY], nil, 0, 255);
fs_portable := TBooleanCvar.Add('fs_portable', 'Enables portable mode', False, False, [CVAR_CLIENT, CVAR_INITONLY], @fs_portableChange);
fs_basepath := TStringCvar.Add('fs_basepath', 'Path to base game directory', '', '', [CVAR_INITONLY], @fs_basepathChange, 0, 255);
fs_userpath := TStringCvar.Add('fs_userpath', 'Path to user game directory', '', '', [CVAR_INITONLY], @fs_userpathChange, 0, 255);
fs_portable := TBooleanCvar.Add('fs_portable', 'Enables portable mode', False, False, [CVAR_CLIENT, CVAR_INITONLY], @CommandLineOnlyChange);
fs_basepath := TStringCvar.Add('fs_basepath', 'Path to base game directory', '', '', [CVAR_INITONLY], @CommandLineOnlyChange, 0, 255);
fs_userpath := TStringCvar.Add('fs_userpath', 'Path to user game directory', '', '', [CVAR_INITONLY], @CommandLineOnlyChange, 0, 255);

demo_autorecord := TBooleanCvar.Add('demo_autorecord', 'Auto record demos', False, False, [], nil);

Expand Down

0 comments on commit 055d2a6

Please sign in to comment.