Coder Social home page Coder Social logo

nathaniel-daniel / rgssad-rs Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 1.2 MB

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

Home Page: https://nathaniel-daniel.github.io/rgssad-rs/rgssad/

License: Apache License 2.0

Rust 99.76% Makefile 0.24%
rgssad rust rpgmakervx rpgmakerxp rpg-maker rpg-maker-vx rpg-maker-xp

rgssad-rs's Introduction

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 entries = Vec::new();
    while let Some(mut entry) = reader.read_entry().expect("failed to read entry") {
        let mut buffer = Vec::new();
        entry.read_to_end(&mut buffer).expect("failed to read file");
        entries.push((entry.file_name().to_string(), buffer));
    }

    // Write all entries into new archive.
    let mut new_file = Vec::new();
    let mut writer = rgssad::Writer::new(&mut new_file)
        .write_header()
        .expect("failed to write header");
    for (file_name, file_data) in entries.iter() {
        writer
            .write_entry(
                file_name,
                u32::try_from(file_data.len()).expect("file data too large"),
                &**file_data,
            )
            .expect("failed to write entry");
    }
    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.

rgssad-rs's People

Contributors

dependabot[bot] avatar nathaniel-daniel avatar

Stargazers

 avatar

Watchers

 avatar

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.