Crate idx[][src]

Expand description

A high-speed, efficient library for reading IDX-formatted RuneScape 2 caches. IDX attempts to establish an efficient and reliable means of reading IDX-formatted RuneScape 2 caches for the Rust ecosystem. As the data being read from these formats is copyrighted by Jagex, I will under no circumstance provide a test cache or any other cache. Should you seek to acquire a cache from somewhere, the OpenRS2 Archive is a good place to look.

To accomplish the goal of providing a clean and easy-to-use solution for reading IDX-formatted caches, IDX provides the following:

  • A data model that closely resembles the internal structure of the idx files, once parsed.
  • APIs for retrieving raw file data, implementing definition parsers, and finally definition providers, which work in conjunction with definition parsers.
  • Additionally, as part of IDX’s development, a [specialized buffer] was created that can perform all the necessary reads and writes to interact with the RuneScape cache, and even packets within the RS protocol.

Quick Start with IDX

IDX is fairly straightforward and simple to use. Your entry point, and the first necessary step, is generating a Cache instance for use with your File and Definition providers.

Below is a quick and easy example for setting up a basic system.

use idx::*;
use idx::util::*;
use databuffer::DataBuffer;
 
#[derive(Default)]
struct DummyDefinition {
    some_value: u8
}
 
//Implement our definition parser for our DummyDefinition
impl DefParser for DummyDefinition {
    fn parse_buff(buffer: DataBuffer) -> Self {
       let mut def = DummyDefinition::default();

       let opcode: u8;

       loop {
           opcode = buffer.read_u8();

           match opcode {
               0 -> break,
               1 -> def.some_value = buffer.read_u8()
           }
       }

       return def;
   }
}
 
fn main() {
    let cache = CacheBuilder::new()
                .with_path("/path/to/cache")
                .with_base_filename("main_file_cache") //this is the default value
                .calculate_crc32(true) //this is the default value
                .build();
 
    let data_provider = FileProvider::from(&cache);
    data_provider.index(19).archive(&1);
 
    let mut data: DataBuffer = data_provider.request(&0); //This will return a DataBuffer containing the data from File 0, Archive 1, Index 19.
 
    let dummy_def_provider = DefProvider::<DummyDefinition>::with(cache, 1); //Makes a DefProvider using the cache, the Dummy Definition parser we defined above, and set for index 1.
    let definition = dummy_def_provider.get_def(&3, &1); //returns the parsed definition from file 1 of archive 3.
}

See file provider docs for more information on the FileProvider.

See definition provider docs for more information on DefProvider and DefParser.

IDX will cache the raw data for all files read during runtime, to prevent repeat file operations.

You can clear this data at any time by invoking the clear_raw_data() method of your cache. Alternatively, you can get the IdxContainer for an individual archive and call its clear_filedata() method.

The Definition Provider will also automatically cache previously-parsed definitions, to prevent unnecessary parsing.

Modules

Structs

The Cache struct is the top-level representation of the cache itself, all data within the cache is accessed via this struct.