#runescape #osrs #rs3

rs-cache

A read-only, high-level, virtual file API for the RuneScape cache

32 releases (7 breaking)

Uses new Rust 2021

0.8.2 Feb 5, 2022
0.7.5 Nov 10, 2021
0.4.2 May 29, 2021
0.3.3 Nov 12, 2020
0.1.1 Feb 28, 2020

#17 in Games

Download history 73/week @ 2022-01-28 21/week @ 2022-02-04 10/week @ 2022-02-11 33/week @ 2022-02-18 2/week @ 2022-02-25 70/week @ 2022-03-11 130/week @ 2022-03-18 1/week @ 2022-04-01 13/week @ 2022-04-08 2/week @ 2022-04-15 33/week @ 2022-04-22 230/week @ 2022-04-29 212/week @ 2022-05-06 545/week @ 2022-05-13

1,020 downloads per month

MIT license

130KB
3K SLoC

rs-cache

Build API Crate dependency status OSRS Version RS3 Version

A read-only, high-level, virtual file API for the RuneScape cache.

This crate provides high performant data reads into the Oldschool RuneScape and RuneScape 3 cache file systems. It can read the necessary data to synchronize the client's cache with the server. There are also some loaders that give access to definitions from the cache such as items or npcs.

For read-heavy workloads, a writer can be used to prevent continuous buffer allocations. By default every read will allocate a writer with the correct capacity.

RuneScape's chat system uses huffman coding to compress messages. In order to decompress them this library has a Huffman implementation.

When a RuneScape client sends game packets the id's are encoded and can be decoded with the IsaacRand implementation. These id's are encoded by the client in a predictable random order which can be reversed if the server has its own IsaacRand with the same encoder/decoder keys. These keys are sent by the client on login and are user specific. It will only send encoded packet id's if the packets are game packets.

Note that this crate is still evolving; both OSRS & RS3 are not fully supported/implemented and will probably contain bugs or miss core features. If you require features or find bugs consider opening an issue.

Useful links:
        Releases
        Documentation
        Examples

Safety

In order to read bytes in a high performant way the cache uses memmap2. This can be unsafe because of its potential for Undefined Behaviour when the underlying file is subsequently modified, in or out of process. Using Mmap here is safe because the RuneScape cache is a read-only binary file system. The map will remain valid even after the File is dropped, it's completely independent of the File used to create it. Therefore, the use of unsafe is not propagated outwards. When the Cache is dropped memory will be subsequently unmapped.

Features

The cache's protocol defaults to OSRS. In order to use the RS3 protocol you can enable the rs3 feature flag. A lot of types derive serde's Serialize and Deserialize. The serde feature flag can be used to enable (de)serialization on any compatible types.

Quick Start

use rscache::Cache;

fn main() -> Result<(), rscache::Error> {
    let cache = Cache::new("./data/osrs_cache")?;

    let index_id = 2; // Config index.
    let archive_id = 10; // Archive containing item definitions.

    let buffer = cache.read(index_id, archive_id)?;

    Ok(())
}

The osrs specifications and rs3 specifications documents contain a detailed description of the design of the corresponding cache for educational purposes. Both documents are still a work in progress and are possibly incomplete.

Integration tests are running on Oldschool RuneScape version 180, which you can run at any time because the cache is included in the ./data/osrs_cache directory. RS3 Integration tests are running on version 904. The RS3 cache is too large to include on GitHub.

This crate is marked as experimental. I will implement additional features once I need them for my own project. If you require a certain feature feel free to open an issue.

Usage

Add this to your Cargo.toml:

[dependencies]
rs-cache = "0.8"

Examples can be found in the examples directory which include both update protocols.

Acknowledgements

The following sources aided with the development of this crate:
        OpenRS
        RuneLite
        OSRS Cache Parsing Blog
        RSMod
        Librsfs
        OSRSBox
        Jagex-Store-5
        Matrix 876

License

rs-cache is distributed under the terms of the MIT license.

See LICENSE for details.

Dependencies

~2.5–3.5MB
~65K SLoC