[][src]Crate rscache

Utilities for RuneScape cache interaction.

Currently only supports the OSRS cache but RS3 support is in the works.

Features

The following features are currently provided:

Quick Start

A possible use case of this utility is to read data from the RuneScape cache and send them to the client during the update protocol. The example listed below quickly shows how you can pass the index_id and the archive_id to the cache and get the correct data to send to the client.

use rscache::{ Cache, CacheError, LinkedListExt };
 
fn process_update(packet: UpdatePacket, stream: &mut TcpStream) -> Result<(), CacheError> {
    // read the specified archive from the given index to an owned vector.
    let buffer = cache.read(packet.index_id, packet.archive_id)?.to_vec();
     
    // ... format buffer.
 
    // send formatted_buffer to client.
    stream.write_all(&formatted_buffer)?;
 
    Ok(())
}

In the above example the data that was read from the cache is transformed into a vector of bytes. You can also use the LinkedList<&[u8]> to iter() over the data_blocks instead of making the bytes owned.

let buffer = cache.read(packet.index_id, packet.archive_id)?;
 
for data_block in buffer.iter() {
    // data_block contains 512 byte slices that directly link into the MainData buffer.
    // this can be useful when creating a new formatted buffer.
}

Loaders & Definitions

Every loader works exactly the same. It has a new(cache: &Cache) function to parse and cache the definitions and it contains a load(id: u16) to fetch the definition that corresponds to the given id.

Supported definitions:

These definitions contain fields that can be looked up for a certain item/npc. i.e. you need to know if a certain item is stackable or members only the ItemDefinition struct contains that information.

Example

use rscache::ItemLoader;
 
let item_loader = ItemLoader::new(&cache)?;
 
// magic logs id = 1513
let magic_logs = item_loader.load(1513);
 
match magic_logs {
    Some(item_def) => {
        assert_eq!("Magic logs", item_def.name);
        assert!(!item_def.stackable);
        assert!(item_def.members_only);
    },
    None => (),
}

Modules

codec

Provides two functions to encode/decode buffers.

Structs

Cache

Main struct which provides basic cache utilities and interactions.

Checksum

Used to check the validity of the cache.

ItemDefinition

Contains all the information about a certain item fetched from the cache through the ItemLoader.

ItemLoader

Caches all the item definitions that were loaded.

NpcDefinition

Contains all the information about a certain npc fetched from the cache through the NpcLoader.

NpcLoader

Caches all the npc definitions that were loaded.

Enums

CacheError
CompressionError
ReadError

Traits

LinkedListExt

Adds extensions onto the std collection: LinkedList<T>.

ReadExt

Adds easy byte reading onto a Read instance.