Giter Site home page Giter Site logo

rs-cache's Introduction

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 encoding to compress messages; this library contains a huffman implementation to decompress these messages.

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

For an instance that stays local to this thread you can simply use:

use rscache::Cache;

let cache = Cache::new("./data/osrs_cache").unwrap();

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

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

If you want to share the instance over multiple threads you can do so by wrapping it in an Arc

use rscache::Cache;
use std::sync::Arc;

let cache = Arc::new(Cache::new("./data/osrs_cache").unwrap());

let c = Arc::clone(&cache);
std::thread::spawn(move || {
    c.read(0, 10).unwrap();
});

std::thread::spawn(move || {
    cache.read(0, 10).unwrap();
});

The recommended usage would be to wrap it using once_cell making it the easiest way to access cache data from anywhere and at any time. No need for an Arc or a Mutex because Cache will always be Send & Sync.

use rscache::Cache;
use once_cell::sync::Lazy;

static CACHE: Lazy<Cache> = Lazy::new(|| {
    Cache::new("./data/osrs_cache").unwrap()
});

std::thread::spawn(move || {
    CACHE.read(0, 10).unwrap();
});

std::thread::spawn(move || {
    CACHE.read(0, 10).unwrap();
});

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.6"

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.

rs-cache's People

Contributors

jimvdl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

rs-cache's Issues

1.63 const mutex

In rust 1.63 Mutex::new, RwLock::new, and Condvar::new are all const. As well as releasing scoped threads.

Might be able to update the examples with the following:

  • No longer use the lazy_static workaround.
  • Use a scoped thread to get access to a cache instance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.