#parser #gamedev #ao-e2de

aoe2-probe

A rust library for editing aoe2scenario files from AoE2 DE

24 releases

0.3.0 Jul 9, 2023
0.2.20 May 22, 2023
0.2.18 Mar 19, 2023
0.2.17 Aug 28, 2022
0.1.1 Jul 27, 2022

#263 in Game dev

Download history 14/week @ 2024-02-15 43/week @ 2024-02-22 1/week @ 2024-02-29 1/week @ 2024-03-07 2/week @ 2024-03-14

51 downloads per month

GPL-3.0-or-later

160KB
4K SLoC

CircleCI Crates.io Crates.io GPL-3.0 licensed

What is aoe2-probe?

This is a rust library for editing aoe2scenario files from AoE2 DE.

WARNING

  • Due to the zlib implementation difference, the exported file cannot be as same as the imported file, while the content of files is constant(Don't worry, AoE2 DE still understand it).Backing up the original is always recommended.

Design Goals

  • Full ability to access every byte in aoe2scenario files.
  • Editing every bit with a reliable correctness check. todo!()
  • Provides constant API compatibility across game versions.

Getting Started

Under the directory ./examples/, you can find several simple showcases.

Import and export files:

use aoe2_probe::scenario::{Scenario, ExportFormat};

//Reading scenario content from the .aoe2scenario file
let scenario = Scenario::from_file("./resources/chapter_1.aoe2scenario").unwrap();
//saving content to a new .aoe2scenario file
scenario.to_file("./resources/temp.aoe2scenario", ExportFormat::AoE2Scenario);

Update attributes:

use aoe2_probe::scenario::Scenario;

//versio's structure definition can be found in the folder /src/prebuilt/ver1_46/versio.rs
let mut scenario = Scenario::from_file("./resources/chapter_1.aoe2scenario").unwrap();

let author = scenario.versio.get_by_path_mut("/file_header/creator_name");
//Update the creator name.
author.try_mut_str32().set_content("Arian");

Customize a structure:

//Define a score record
let mut root = PatchedMap::new();
root.push_back("score", Token::Int16(100));
root.push_back("name", Token::Str32(DynString::with_capacity(12, "anonymous")));

//serialize
root.to_le_vec();

//deserialize
root.from_le_vec();

Serialize/Deserialize to any formats that serde support:

let scenario = Scenario::from_file("./resources/chapter_3.aoe2scenario").unwrap();
let json = serde_json::to_string(&scenario.versio).unwrap();
println!("{}", json);

Run examples with the following command:

cargo run --example read_write

Every member of versio and itself implements fmt::Debug trait. Print them if you want to know more.

let scenario = Scenario::from_file("./resources/chapter_1.aoe2scenario").unwrap();
println!("{:?}", &scenario.versio())

Advanced examples can be found in misc-probe. Detailed information can be found in Docs.

Supports

Game version Supported status
ver.1.46 Supported
ver.1.47 Supported
ver.1.48 Supported
ver.1.49 Supported

Currently, only version 1.46 and newer will be firstly supported.

Libraries Used

  • miniz_oxide: Pure rust Rust replacement for the miniz deflate/zlib encoder/decoder using no unsafe code.
  • serde: Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.
  • serde_repr: This crate provides a derive macro to derive Serde's Serialize and Deserialize traits in a way that delegates to the underlying repr of a C-like enum.
  • linked-hash-map: A HashMap wrapper that holds key-value pairs in insertion order.
  • lazy-static: A macro for declaring lazily evaluated statics in Rust.
  • log: A lightweight logging facade.

Acknowledgment

This library is inspired by AoE2ScenarioParser and Trigger Craft

Dependencies

~1–1.8MB
~40K SLoC