# RSCacheParser RSCacheParser as the name implies is a record made to parse information from certain files that are part of the OSRS cache. - preferences.dat is where most client settings are stored. - preferences2.dat I have no idea? some values in address 00000020 seem to change after some times has passed randomly. (related to 6h log maybe!?!?) - random.dat in the user home directory seems to be a random identifier generated the first time you open a client if it doesn't exist. while it exists, it seems to never change unless the user deletes it. ```{note} For more information check this file: https://github.com/open-osrs/runelite/blob/dd4478eff7d90fcb3e85584171d5836809eb150a/runescape-client/src/main/java/ClientPreferences.java ``` - - - ## TRSCacheParser Type responsible for handling osrs cache parsing. - - - ## RSCacheParser.Setup ```pascal procedure TRSCacheParser.Setup(); ``` Internal method responsible for setting up the {ref}`TRSCacheParser`. This is automatically called for you on the {ref}`RSCacheParser variable`. - - - ## Preferences This section is about reading the game preferences that get cached. There's 2 preferences files: - `jagexcache/oldschool/LIVE/preferences.dat` - `jagexcache/oldschool/LIVE/preferences2.dat` The second file is actually not used for anything at the moment but the first one specifically has a lot of useful client information, things such as: - Brightness level - Roofs state - Window mode (fixed or resizable) - Sound volumes - ... All this information is stored in binary, but with the following methods you can read it easily and this is very useful because you can do things like: - Check brightness level without opening the options gametab nor the display tab. - Know if the roofs are hidden, this is something that can break scripts big time and is notoriously hard to know with color alone. - - - ### RSCacheParser.ReadPreference ```pascal function TRSCacheParser.ReadPreference(pref: Integer = 1): TByteArray; ``` Internal method to returns the bytes of the preferences file. Returns the bytes of the preferences file which can only be 1 or 2. It's also useful for debugging Example: ```pascal WriteLn RSCacheParser.ReadPreference(1); ``` - - - ### RSCacheParser.CountOptions ```pascal function TRSCacheParser.CountOptions(bytes: TByteArray = []): Integer; ``` Returns the number of options saved in the cache. Only used for debugging, you probably don't need this at all. This is not very useful, AFAIK there's only 2 possible values for this: 0 and 11. 0 is only if you haven't accepted the EULA in the client. Example: ```pascal WriteLn RSCacheParser.CountOptions(); ``` - - - ### RSCacheParser.RoofsHidden ```pascal function TRSCacheParser.RoofsHidden(bytes: TByteArray = []): Boolean; ``` Returns whether the roofs are hidden or not. Example: ```pascal WriteLn RSCacheParser.RoofsHidden(); ``` - - - ### RSCacheParser.LoginMusicDisabled ```pascal function TRSCacheParser.LoginMusicDisabled(bytes: TByteArray = []): Boolean; ``` Checks if the music is enabled on the login screen. Example: ```pascal WriteLn RSCacheParser.LoginMusicDisabled(); ``` - - - ### RSCacheParser.WindowMode ```pascal function TRSCacheParser.WindowMode(bytes: TByteArray = []): Integer; ``` Returns 1 for fixed mode and 2 for resizable mode. Resizable modern and resizable classic make no difference here. Example: ```pascal WriteLn RSCacheParser.WindowMode(); ``` - - - ### RSCacheParser.CountAuthenticators ```pascal function TRSCacheParser.CountAuthenticators(bytes: TByteArray = []): Integer; ``` Internal helper method that 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 how many bytes we have to skip to continue reading the preferences file. Example: ```pascal WriteLn RSCacheParser.CountAuthenticators(); ``` - - - ### RSCacheParser.GetAuthenticators ```pascal function TRSCacheParser.GetAuthenticators(): TStringArray; ``` No real use other than debugging. Returns each authenticator saved in a TStringArray. Each string is 8 bytes like mentioned in {ref}`RSCacheParser.CountAuthenticators` documentation. Also, you can't just use this to login as someone, don't bother trying. Example: ```pascal WriteLn RSCacheParser.GetAuthenticators(); ``` - - - ### RSCacheParser.GetUsernameIndex ```pascal function TRSCacheParser.GetUsernameIndex(bytes: TByteArray = []): Integer; ``` Internal helper function that returns byte index where the saved username starts. This is required because depending on whether we have authenticators saved or not, the bytes shift like mentioned in {ref}`RSCacheParser.CountAuthenticators`. - - - ### RSCacheParser.GetUsername ```pascal function TRSCacheParser.GetUsername(bytes: TByteArray = []): String; ``` Returns the saved username in the osrs cache. This is the username you clicked to save on the client when logging in. Example: ```pascal WriteLn RSCacheParser.GetUsername(); ``` - - - ### RSCacheParser.UsernameEndIndex ```pascal function TRSCacheParser.UsernameEndIndex(bytes: TByteArray = []): Int32; ``` Internal helper function used to get the index of the byte of where the username ends. We can know the index of the byte by know where it starts with {ref}`RSCacheParser.GetUsernameIndex` and iterating all next bytes until we find one that is `0` which marks the end of the username. This is required so we can keep reading the preferences file. - - - ### RSCacheParser.LoginHideUsername ```pascal function TRSCacheParser.LoginHideUsername(bytes: TByteArray = []): Boolean; ``` Returns true or false if we have the username hidden on the loginscreen. Example: ```pascal WriteLn RSCacheParser.LoginHideUsername(); ``` - - - ### RSCacheParser.Brightness ```pascal function TRSCacheParser.Brightness(bytes: TByteArray = []): Integer; ``` Returns the brightness value converted to a 0-100 value (the value in cache is between 50-100 in a byte format). Example: ```pascal WriteLn RSCacheParser.Brightness(); ``` - - - ### RSCacheParser.MusicVolume ```pascal function TRSCacheParser.MusicVolume(bytes: TByteArray = []): Integer; ``` Returns the music volume value converted to a 0-100 value. Example: ```pascal WriteLn RSCacheParser.MusicVolume(); ``` - - - ### RSCacheParser.SoundEffectsVolume ```pascal function TRSCacheParser.SoundEffectsVolume(bytes: TByteArray = []): Integer; ``` Returns the sound effects volume value converted to a 0-100 value. Example: ```pascal WriteLn RSCacheParser.SoundEffectsVolume(); ``` - - - ### RSCacheParser.AreaSoundVolume ```pascal function TRSCacheParser.AreaSoundVolume(bytes: TByteArray = []): Integer; ``` Returns the area sound volume value converted to a 0-100 value. Example: ```pascal WriteLn RSCacheParser.AreaSoundVolume(); ``` - - - ### RSCacheParser.Field1247 ```pascal function TRSCacheParser.Field1247(bytes: TByteArray = []): Integer; ``` I have absolutely no idea what this is. It's supposedly something, but AFAIK it's always 0. Example: ```pascal WriteLn RSCacheParser.Field1247(); ``` - - - ## RSCacheParser Indices This section is dedicated at reading the cache `idx` files. This has no use yet and might not be working properly but does seem like it is. There's very little resources online about this but some useful ones can be found here: - [OSRSBox](https://www.osrsbox.com/osrs-cache/) - [OpenRS](https://github.com/kfricilone/OpenRS/tree/master/source/net/openrs/cache) `idx` files are basically pointers to data on the `main_file_cache.dat2` where pretty much all the game cache information is stored. An `idx` file will tell you where on that file the data you want is, and it's size. - - - ### RSCacheParser.ReadMediumInt ```pascal function TRSCacheParser.ReadMediumInt(const bytes: TByteArray; offset: Integer): Integer; ``` Internal helper method to partially read a sector of an `idx` file that are stored in big endian format. - - - ### RSCacheParser.DecodeIndexSector ```pascal function TRSCacheParser.DecodeIndexSector(const bytes: TByteArray; offset: Integer): TIndexData; ``` Internal helper method to read a sector of an `idx` file. `idx` files are split into "sectors" of 6 bytes each. Each sector contains information about: - size of the data this sector points to - where that data starts. - - - ### RSCacheParser.ReadIdx ```pascal function TRSCacheParser.ReadIdx(idx: Integer): TIndex; ``` Read an `idx` file and return it's information as a `TIndex`. Example: ```pascal WriteLn RSCacheParser.ReadIndex(255); ``` - - - ## RSCacheParser variable Global {ref}`TRSCacheParser` variable.