From 27138a664bbc2478edcf0e1965ee2f29876aa98f Mon Sep 17 00:00:00 2001 From: Torwent Date: Fri, 26 Jul 2024 20:09:29 +0200 Subject: [PATCH] fix(RSCacheParser): Now reads cache from RuneLite if that's the client being used --- utils/cacheparser.simba | 339 ++++++++++++++++++++-------------------- 1 file changed, 173 insertions(+), 166 deletions(-) diff --git a/utils/cacheparser.simba b/utils/cacheparser.simba index 8fe20729..d9dcc448 100644 --- a/utils/cacheparser.simba +++ b/utils/cacheparser.simba @@ -16,18 +16,20 @@ For more information check this file: https://github.com/open-osrs/runelite/blob {$ENDIF} (* -## type RSCacheParser +## type TRSCacheParser ```pascal -type RSCacheParser = record(TSRLBaseRecord) class var - Disabled: Boolean; - Directory: String; - Preferences: String; - Preferences2: String; -end; +type + TRSCacheParser = record(TSRLBaseRecord) + Disabled: Boolean; + Directory: String; + Preferences: String; + Preferences2: String; + end; ``` Type responsible for handling osrs cache parsing. *) -type RSCacheParser = record(TSRLBaseRecord) class var +type + TRSCacheParser = record(TSRLBaseRecord) Disabled: Boolean; Directory: String; Preferences: String; @@ -37,104 +39,122 @@ type RSCacheParser = record(TSRLBaseRecord) class var (* ## RSCacheParser.Setup ```pascal -procedure RSCacheParser.Setup(); static; +procedure TRSCacheParser.Setup(); ``` - Internal method called automatically simply by including WaspLib. *) -procedure RSCacheParser.Setup(); static; +procedure TRSCacheParser.Setup(); var - dir: String; + dir, base: String; {$IFDEF WINDOWS} winDirs: TStringArray; {$ENDIF} begin - {$IFDEF WINDOWS} - winDirs := [ - GetEnvironmentVariable('ONEDRIVE'), - GetEnvironmentVariable('USERPROFILE'), - GetEnvironmentVariable('HOMEPATH') - ]; + base := 'jagexcache' + DirectorySeparator + 'oldschool' + DirectorySeparator + 'LIVE' + DirectorySeparator; - for dir in winDirs do - begin - dir += DirectorySeparator + 'jagexcache' + DirectorySeparator; - dir += 'oldschool' + DirectorySeparator + 'LIVE' + DirectorySeparator; - if DirectoryExists(dir) then - Break; - end; - {$ELSE} - dir := GetEnvironmentVariable('HOME'); - dir += DirectorySeparator + 'jagexcache' + DirectorySeparator; - dir += 'oldschool' + DirectorySeparator + 'LIVE' + DirectorySeparator; - {$ENDIF} + case RSClient.GetCurrentClient() of + ERSClient.LEGACY: + begin + {$IFDEF WINDOWS} + winDirs := [ + GetEnvironmentVariable('ONEDRIVE'), + GetEnvironmentVariable('USERPROFILE'), + GetEnvironmentVariable('HOMEPATH') + ]; + + for dir in winDirs do + begin + dir += DirectorySeparator + base; + if DirectoryExists(dir) then Break; + end; + {$ELSE} + dir := GetEnvironmentVariable('HOME') + DirectorySeparator + base; + {$ENDIF} + + if DirectoryExists(dir) then + Self.Directory := dir + else + Self.Disabled := True; + end; - if DirectoryExists(dir) then - RSCacheParser.Directory := dir - else - RSCacheParser.Disabled := True; + ERSClient.RUNELITE: + begin + + dir := + {$IFDEF WINDOWS} + GetEnvironmentVariable('USERPROFILE') + {$ELSE} + GetEnvironmentVariable('HOME') + {$ENDIF} + DirectorySeparator + '.runelite' + DirectorySeparator + base ; + + if DirectoryExists(dir) then + Self.Directory := dir + else + Self.Disabled := True; + end; + + else + Self.Disabled := True; + end; end; (* ## RSCacheParser.GetPreference ```pascal -function RSCacheParser.GetPreference(prefNumber: Int32 = 1): String; static; +function TRSCacheParser.GetPreference(prefNumber: Int32 = 1): String; ``` - Read the preference file specified. *) -function RSCacheParser.GetPreference(prefNumber: Int32 = 1): String; static; +function TRSCacheParser.GetPreference(prefNumber: Int32 = 1): String; begin case prefNumber of - 1: Result := ReadFileContents(RSCacheParser.Directory + 'preferences.dat'); - 2: Result := ReadFileContents(RSCacheParser.Directory + 'preferences2.dat'); + 1: Result := ReadFileContents(Self.Directory + 'preferences.dat'); + 2: Result := ReadFileContents(Self.Directory + 'preferences2.dat'); end; if Result = '' then - RSCacheParser.Disabled := True; + Self.Disabled := True; end; (* ## RSCacheParser.Update ```pascal -function RSCacheParser.Update(): Boolean; static; +function TRSCacheParser.Update(): Boolean; ``` - Method to check if the cache files were updated. *) -function RSCacheParser.Update(prefNumber: Int32 = 0): Boolean; static; +function TRSCacheParser.Update(prefNumber: Int32 = 0): Boolean; var tmp1, tmp2: String; begin case prefNumber of 1: begin - tmp1 := RSCacheParser.GetPreference(1); - Result := RSCacheParser.Preferences <> tmp1; + tmp1 := Self.GetPreference(1); + Result := Self.Preferences <> tmp1; end; 2: begin - tmp2 := RSCacheParser.GetPreference(2); - Result := RSCacheParser.Preferences2 <> tmp2; + tmp2 := Self.GetPreference(2); + Result := Self.Preferences2 <> tmp2; end; 0: begin - tmp1 := RSCacheParser.GetPreference(1); - tmp2 := RSCacheParser.GetPreference(2); - Result := (RSCacheParser.Preferences <> tmp1) or - (RSCacheParser.Preferences2 <> tmp2); + tmp1 := Self.GetPreference(1); + tmp2 := Self.GetPreference(2); + Result := (Self.Preferences <> tmp1) or (Self.Preferences2 <> tmp2); end; end; if Result then begin case prefNumber of - 1: RSCacheParser.Preferences := tmp1; - 2: RSCacheParser.Preferences2 := tmp2; + 1: Self.Preferences := tmp1; + 2: Self.Preferences2 := tmp2; 0: begin - RSCacheParser.Preferences := tmp1; - RSCacheParser.Preferences2 := tmp2; + Self.Preferences := tmp1; + Self.Preferences2 := tmp2; end; end; end; @@ -143,9 +163,8 @@ end; (* ## RSCacheParser.GetHexString ```pascal -function RSCacheParser.GetHexString(prefNumber: Int32 = 1): String; static; +function TRSCacheParser.GetHexString(prefNumber: Int32 = 1): String; ``` - Print the cache files as a hex string. Example: @@ -153,16 +172,16 @@ Example: WriteLn RSCacheParser.GetHexString(1); ``` *) -function RSCacheParser.GetHexString(prefNumber: Int32 = 1): String; static; +function TRSCacheParser.GetHexString(prefNumber: Int32 = 1): String; var pref, final, tmp: String; i: Int32; begin - RSCacheParser.Update(); + Self.Update(); case prefNumber of - 1: pref := RSCacheParser.Preferences; - 2: pref := RSCacheParser.Preferences2; + 1: pref := Self.Preferences; + 2: pref := Self.Preferences2; else Exit; end; @@ -182,9 +201,8 @@ end; (* ## RSCacheParser.Print ```pascal -procedure RSCacheParser.Print(prefNumber: Int32 = 0); static; +procedure TRSCacheParser.Print(prefNumber: Int32 = 0); ``` - Print the cache files as strings. This is only useful for debugging purposes. Example: @@ -192,25 +210,24 @@ Example: RSCacheParser.Print(); ``` *) -procedure RSCacheParser.Print(prefNumber: Int32 = 0); static; +procedure TRSCacheParser.Print(prefNumber: Int32 = 0); begin - RSCacheParser.Update(); + Self.Update(); if prefNumber = 0 then begin - WriteLn RSCacheParser.GetHexString(1); - WriteLn RSCacheParser.GetHexString(2); + WriteLn Self.GetHexString(1); + WriteLn Self.GetHexString(2); end else - WriteLn RSCacheParser.GetHexString(prefNumber); + WriteLn Self.GetHexString(prefNumber); end; (* ## RSCacheParser.GetOptionsAmount ```pascal -function RSCacheParser.GetOptionsAmount(): Int32; static; +function TRSCacheParser.GetOptionsAmount(): Int32; ``` - Returns the number of options saved in the cache. This is not very useful, AFAIK there's only 2 possible values for this: 0 and 10. 0 is only if you haven't accepted the EULA in the client. @@ -219,20 +236,19 @@ Example: WriteLn RSCacheParser.GetOptionsAmount(); ``` *) -function RSCacheParser.GetOptionsAmount(): Int32; static; +function TRSCacheParser.GetOptionsAmount(): Int32; begin - RSCacheParser.Update(); + Self.Update(); - if Length(RSCacheParser.Preferences) >= 1 then - Result := Int32(RSCacheParser.Preferences[1]); + if Length(Self.Preferences) >= 1 then + Result := Int32(Self.Preferences[1]); end; (* ## RSCacheParser.RoofsHidden ```pascal -function RSCacheParser.RoofsHidden(): Boolean; static; +function TRSCacheParser.RoofsHidden(): Boolean; ``` - Checks if the roofs are hidden. Example: @@ -240,19 +256,18 @@ Example: WriteLn RSCacheParser.RoofsHidden(); ``` *) -function RSCacheParser.RoofsHidden(): Boolean; static; +function TRSCacheParser.RoofsHidden(): Boolean; begin - RSCacheParser.Update(); - if Length(RSCacheParser.Preferences) >= 2 then - Result := Boolean(RSCacheParser.Preferences[2]); + Self.Update(); + if Length(Self.Preferences) >= 2 then + Result := Boolean(Self.Preferences[2]); end; (* ## RSCacheParser.TitleMusicDisabled ```pascal -function RSCacheParser.TitleMusicDisabled(): Boolean; static; +function TRSCacheParser.TitleMusicDisabled(): Boolean; ``` - Checks if the music is enabled in the login screen. Example: @@ -260,19 +275,18 @@ Example: WriteLn RSCacheParser.TitleMusicDisabled(); ``` *) -function RSCacheParser.TitleMusicDisabled(): Boolean; static; +function TRSCacheParser.TitleMusicDisabled(): Boolean; begin - RSCacheParser.Update(); - if Length(RSCacheParser.Preferences) >= 3 then - Result := Boolean(RSCacheParser.Preferences[3]); + Self.Update(); + if Length(Self.Preferences) >= 3 then + Result := Boolean(Self.Preferences[3]); end; (* ## RSCacheParser.WindowMode ```pascal -function RSCacheParser.WindowMode(): Int32; static; +function TRSCacheParser.WindowMode(): Int32; ``` - Returns 1 for fixed mode and 2 for resizable mode. Resizable modern and resizable classic make no difference here. Example: @@ -280,19 +294,18 @@ Example: WriteLn RSCacheParser.WindowMode(); ``` *) -function RSCacheParser.WindowMode(): Int32; static; +function TRSCacheParser.WindowMode(): Int32; begin - RSCacheParser.Update(); - if Length(RSCacheParser.Preferences) >= 4 then - Result := Int32(RSCacheParser.Preferences[4]); + Self.Update(); + if Length(Self.Preferences) >= 4 then + Result := Int32(Self.Preferences[4]); end; (* ## RSCacheParser.GetAuthenticatorAmount ```pascal -function RSCacheParser.GetAuthenticatorAmount(): Int32; static; +function TRSCacheParser.GetAuthenticatorAmount(): Int32; ``` - Returns the number of authenticators saved for the next 30 days. If this is more than 0, you will have 8 bytes for each of the saved authenticators. This is important to know so we know where the saved username starts if we have saved authenticators. @@ -301,19 +314,18 @@ Example: WriteLn RSCacheParser.GetAuthenticatorAmount(); ``` *) -function RSCacheParser.GetAuthenticatorAmount(): Int32; static; +function TRSCacheParser.GetAuthenticatorAmount(): Int32; begin - RSCacheParser.Update(); - if Length(RSCacheParser.Preferences) >= 5 then - Result := Int32(RSCacheParser.Preferences[5]); + Self.Update(); + if Length(Self.Preferences) >= 5 then + Result := Int32(Self.Preferences[5]); end; (* ## RSCacheParser.GetAuthenticators ```pascal -function RSCacheParser.GetAuthenticators(): TStringArray; static; +function TRSCacheParser.GetAuthenticators(): TStringArray; ``` - Returns each authenticator saved in a TStringArray. Each string is 8 bytes like mentioned in RSCacheParser.GetAuthenticatorAmount() documentation. Example: @@ -321,22 +333,22 @@ Example: WriteLn RSCacheParser.GetAuthenticators(); ``` *) -function RSCacheParser.GetAuthenticators(): TStringArray; static; +function TRSCacheParser.GetAuthenticators(): TStringArray; var i, j, savedAuths: Int32; str: String; begin - RSCacheParser.Update(); - savedAuths := RSCacheParser.GetAuthenticatorAmount(); + Self.Update(); + savedAuths := Self.GetAuthenticatorAmount(); if savedAuths = 0 then Exit; for i := 0 to savedAuths - 1 do begin - if Length(RSCacheParser.Preferences) >= (13 + i * 8) then + if Length(Self.Preferences) >= (13 + i * 8) then begin for j := (6 + i * 8) to (13 + i * 8) do - str += RSCacheParser.Preferences[j]; + str += Self.Preferences[j]; Result += str; str := ''; end; @@ -346,23 +358,21 @@ end; (* ## RSCacheParser.GetUsernameIndex ```pascal -function RSCacheParser.GetUsernameIndex(): Int32; static; +function TRSCacheParser.GetUsernameIndex(): Int32; ``` - Internal function that returns byte index where the username starts. This is required because depending on wether we have authenticators saved or not, the bytes shift. *) -function RSCacheParser.GetUsernameIndex(): Int32; static; +function TRSCacheParser.GetUsernameIndex(): Int32; begin - Result := 6 + RSCacheParser.GetAuthenticatorAmount() * 8; + Result := 6 + Self.GetAuthenticatorAmount() * 8; end; (* ## RSCacheParser.GetUsername ```pascal -function RSCacheParser.GetUsername(): String; static; +function TRSCacheParser.GetUsername(): String; ``` - Returns the saved username in the osrs cache. This is the username you clicked to save on the client when logging in. Example: @@ -370,33 +380,32 @@ Example: WriteLn RSCacheParser.GetUsername(); ``` *) -function RSCacheParser.GetUsername(): String; static; +function TRSCacheParser.GetUsername(): String; var i: Int32; begin - for i := RSCacheParser.GetUsernameIndex() to Length(RSCacheParser.Preferences) do + for i := Self.GetUsernameIndex() to Length(Self.Preferences) do begin - if Byte(RSCacheParser.Preferences[i]) = 0 then + if Byte(Self.Preferences[i]) = 0 then Break; - Result += RSCacheParser.Preferences[i]; + Result += Self.Preferences[i]; end; end; (* ## RSCacheParser.UsernameEndIndex ```pascal -function RSCacheParser.UsernameEndIndex(): Int32; static; +function TRSCacheParser.UsernameEndIndex(): Int32; ``` - Internal function used to get the index of the byte of where the username ends. *) -function RSCacheParser.UsernameEndIndex(): Int32; static; +function TRSCacheParser.UsernameEndIndex(): Int32; var i: Int32; begin - for i := RSCacheParser.GetUsernameIndex() to Length(RSCacheParser.Preferences) do + for i := Self.GetUsernameIndex() to Length(Self.Preferences) do begin - if Byte(RSCacheParser.Preferences[i]) = 0 then + if Byte(Self.Preferences[i]) = 0 then Break; end; Result := i + 1; @@ -405,9 +414,8 @@ end; (* ## RSCacheParser.HideUsername ```pascal -function RSCacheParser.HideUsername(): Boolean; static; +function TRSCacheParser.HideUsername(): Boolean; ``` - Returns true or false if we have the username hidden. Example: @@ -415,17 +423,16 @@ Example: WriteLn RSCacheParser.HideUsername(); ``` *) -function RSCacheParser.HideUsername(): Boolean; static; +function TRSCacheParser.HideUsername(): Boolean; begin - Result := Boolean(RSCacheParser.Preferences[RSCacheParser.UsernameEndIndex()]); + Result := Boolean(Self.Preferences[Self.UsernameEndIndex()]); end; (* ## RSCacheParser.Brightness ```pascal -function RSCacheParser.Brightness(): Int32; static; +function TRSCacheParser.Brightness(): Int32; ``` - Returns the brightness value converted to a 0-100 value. Example: @@ -433,21 +440,20 @@ Example: WriteLn RSCacheParser.Brightness(); ``` *) -function RSCacheParser.Brightness(): Int32; static; +function TRSCacheParser.Brightness(): Int32; var i: Int32; begin - i := RSCacheParser.UsernameEndIndex() + 1; - if Length(RSCacheParser.Preferences) >= i then - Result := (Int32(RSCacheParser.Preferences[i]) - 100) * -2; + i := Self.UsernameEndIndex() + 1; + if Length(Self.Preferences) >= i then + Result := (Int32(Self.Preferences[i]) - 100) * -2; end; (* ## RSCacheParser.MusicVolume ```pascal -function RSCacheParser.MusicVolume(): Int32; static; +function TRSCacheParser.MusicVolume(): Int32; ``` - Returns the music volume value converted to a 0-100 value. Example: @@ -455,21 +461,20 @@ Example: WriteLn RSCacheParser.MusicVolume(); ``` *) -function RSCacheParser.MusicVolume(): Int32; static; +function TRSCacheParser.MusicVolume(): Int32; var i: Int32; begin - i := RSCacheParser.UsernameEndIndex() + 2; - if Length(RSCacheParser.Preferences) >= i then - Result := Round(Int32(RSCacheParser.Preferences[i]) / 2.55); + i := Self.UsernameEndIndex() + 2; + if Length(Self.Preferences) >= i then + Result := Round(Int32(Self.Preferences[i]) / 2.55); end; (* ## RSCacheParser.SoundEffectsVolume ```pascal -function RSCacheParser.SoundEffectsVolume(): Int32; static; +function TRSCacheParser.SoundEffectsVolume(): Int32; ``` - Returns the sound effects volume value converted to a 0-100 value. Example: @@ -477,21 +482,20 @@ Example: WriteLn RSCacheParser.SoundEffectsVolume(); ``` *) -function RSCacheParser.SoundEffectsVolume(): Int32; static; +function TRSCacheParser.SoundEffectsVolume(): Int32; var i: Int32; begin - i := RSCacheParser.UsernameEndIndex() + 3; - if Length(RSCacheParser.Preferences) >= i then - Result := Round(Int32(RSCacheParser.Preferences[i]) / 1.27); + i := Self.UsernameEndIndex() + 3; + if Length(Self.Preferences) >= i then + Result := Round(Int32(Self.Preferences[i]) / 1.27); end; (* ## RSCacheParser.AreaSoundVolume ```pascal -function RSCacheParser.AreaSoundVolume(): Int32; static; +function TRSCacheParser.AreaSoundVolume(): Int32; ``` - Returns the area sound volume value converted to a 0-100 value. Example: @@ -499,21 +503,20 @@ Example: WriteLn RSCacheParser.AreaSoundVolume(); ``` *) -function RSCacheParser.AreaSoundVolume(): Int32; static; +function TRSCacheParser.AreaSoundVolume(): Int32; var i: Int32; begin - i := RSCacheParser.UsernameEndIndex() + 4; - if Length(RSCacheParser.Preferences) >= i then - Result := Round(Int32(RSCacheParser.Preferences[i]) / 1.27); + i := Self.UsernameEndIndex() + 4; + if Length(Self.Preferences) >= i then + Result := Round(Int32(Self.Preferences[i]) / 1.27); end; (* ## RSCacheParser.Field1247 ```pascal -function RSCacheParser.Field1247(): Int32; static; +function TRSCacheParser.Field1247(): Int32; ``` - I have absolutely no idea what this is. It's supposedly something, but AFAIK it's always 0. Example: @@ -521,21 +524,20 @@ Example: WriteLn RSCacheParser.Field1247(); ``` *) -function RSCacheParser.Field1247(): Int32; static; +function TRSCacheParser.Field1247(): Int32; var i: Int32; begin - i := RSCacheParser.UsernameEndIndex() + 5; - if Length(RSCacheParser.Preferences) >= i then - Result := Int32(RSCacheParser.Preferences[i]); + i := Self.UsernameEndIndex() + 5; + if Length(Self.Preferences) >= i then + Result := Int32(Self.Preferences[i]); end; (* ## RSCacheParser.DisplayFPS ```pascal -function RSCacheParser.DisplayFPS(): Boolean; static; +function TRSCacheParser.DisplayFPS(): Boolean; ``` - Returns true/false if we have Display FPS enabled. Display FPS can be enabled by typing ::displayfps in game. @@ -544,21 +546,20 @@ Example: WriteLn RSCacheParser.DisplayFPS(); ``` *) -function RSCacheParser.DisplayFPS(): Boolean; static; +function TRSCacheParser.DisplayFPS(): Boolean; var i: Int32; begin - i := RSCacheParser.UsernameEndIndex() + 6; - if Length(RSCacheParser.Preferences) >= i then - Result := Boolean(RSCacheParser.Preferences[i]); + i := Self.UsernameEndIndex() + 6; + if Length(Self.Preferences) >= i then + Result := Boolean(Self.Preferences[i]); end; (* ## RSCacheParser.Field1238 ```pascal -function RSCacheParser.Field1238(): Int32; static; +function TRSCacheParser.Field1238(): Int32; ``` - I have absolutely no idea what this is. It's supposedly something, but AFAIK it's always 0. Example: @@ -566,15 +567,21 @@ Example: WriteLn RSCacheParser.Field1238(); ``` *) -function RSCacheParser.Field1238(): Int32; static; +function TRSCacheParser.Field1238(): Int32; var i: Int32; begin - i := RSCacheParser.UsernameEndIndex() + 7; - if Length(RSCacheParser.Preferences) >= i then - Result := Int32(RSCacheParser.Preferences[i]); + i := Self.UsernameEndIndex() + 7; + if Length(Self.Preferences) >= i then + Result := Int32(Self.Preferences[i]); end; +var + RSCacheParser: TRSCacheParser; + +procedure TSRL.Setup(); override; begin + inherited; + RSCacheParser.Setup(); end;