Skip to content

A Rust library and CLI for reading and writing RPGMaker XP and RPGMaker VX archives.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

nathaniel-daniel/rgssad-rs

Repository files navigation

rgssad-rs

A Rust library for reading and writing RPGMaker XP and RPGMaker VX archives from Rust. This currently includes support for "rgssad" and "rgss2a" files.

Note that there is currently no support for RPGMaker VX Ace "rgss3a" files. Through superficially similar, the internal structure of the file format is very different from prior versions. Allowing these files to be parsed with the same interface would greatly increase code complexity. In the future, support for these files may be added via another Rgss3aReader type.

Example

use std::io::Read;

const ARCHIVE_PATH: &str = "Game.rgssad";

fn main() {
    // In a real app, you don't need to buffer.
    // You just need any object that implements Read + Seek.
    let file = std::fs::read(ARCHIVE_PATH).expect("failed to open archive");
    let file = std::io::Cursor::new(file);
    let mut reader = rgssad::Reader::new(file);
    reader.read_header().expect("failed to read header");

    // Read entire archive into Vec.
    let mut files = Vec::new();
    while let Some(mut file) = reader.read_file().expect("failed to read file") {
        let mut buffer = Vec::new();
        file.read_to_end(&mut buffer).expect("failed to read file");
        files.push((file.name().to_string(), buffer));
    }

    // Write all files into new archive.
    let mut new_file = Vec::new();
    let mut writer = rgssad::Writer::new(&mut new_file);
    writer.write_header().expect("failed to write header");
    for (file_name, file_data) in files.iter() {
        writer
            .write_entry(
                file_name,
                u32::try_from(file_data.len()).expect("file data too large"),
                &**file_data,
            )
            .expect("failed to write file");
    }
    writer.finish().expect("failed to finish");

    // Get the inner archive byte vec, so that we can compare it with the new archive.
    let file = reader.into_inner();

    // The old archive and new archive are byte-for-byte equivalent.
    assert!(&new_file == file.get_ref());
}

Features

Name Description
tokio Enable the tokio wrappers for use in async code.

Docs

Master: https://nathaniel-daniel.github.io/rgssad-rs/rgssad/

CLI

This repository also contains a small CLI to unpack and repack these archives.

Installing

This small CLI may be installed with the following:

cargo install --force --git https://github.com/nathaniel-daniel/rgssad-rs

Usage

Unpacking may be done with the following:

rgssad-cli unpack path-to-archive.rgssad -o path-to-output-directory

Packing may be done with the following:

rgssad-cli pack path-to-directory path-to-new-archive.rgssad

Testing

Currently, only rgssad has tests; the CLI is not tested. Tests may be run with the following command:

cargo test

Use the following command to test the tokio wrappers:

cargo test --features=tokio

Try it Online

You can test an online version of this library at https://nathaniel-daniel.github.io/rgssad-online-viewer/

File Format

See FileFormat

Related Projects

The following sources may be helpful to confirm the correctness of this implementation.

License

Licensed under either of

at your option.

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

A Rust library and CLI for reading and writing RPGMaker XP and RPGMaker VX archives.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published