4 releases

new 0.1.3 Dec 17, 2024
0.1.2 Dec 16, 2024
0.1.1 Dec 15, 2024
0.1.0 Dec 14, 2024

#518 in Parser implementations

Download history 387/week @ 2024-12-12

387 downloads per month

MIT license

145KB
4K SLoC

mgx

mgx is a parser for Age of Empires II recorded games.

Supported version

  • AoK(.mgl)
  • AoC 1.0(.mgx)
  • AoC 1.0c(.mgx)
  • Userpatch 1.5 or earlier(.mgz)

Note: mgx doesn't support game records of HD/DE versions.

Usage(as a binary)

# mgx --help

A parser for Age of Empires II recorded games.

Usage: mgx [OPTIONS] <RECORD_PATH>

Arguments:
  <RECORD_PATH>  Path to the record file. Only AoK(.mgl)/AoC(.mgx)/UP1.5(.mgz) are supported

Options:
  -m <MAP>               Generate a map image as a .png image. Rotated 45° counterclockwise and change height to 50% to get a in-game look
  -j, --json             Dump game info into a JSON string
      --zh               Use Chinese language for output
      --header <HEADER>  Dump header section to specified file
      --body <BODY>      Dump body section to specified file
  -h, --help             Print help
  -V, --version          Print version

Usage(as a library)

Parse from a buffer if you need more control over the parsing.
Create a Record manually and pass it to a Parser. Extracted data will persists in the Record even if the Parser returns an error. mgx::from_file() will result in nothing if any error occurs.

Parse a file directly

let filename = "path-to-test-record.mgx";
let (mut rec, parser) = mgx::from_file(filename).unwrap();

// See src/record.rs for more available fields
println!(" Version: {:?}", rec.ver.unwrap());

// Generate a map image as a .png image.   
// Rotated 45° counterclockwise and change height to 50% to get a in-game look.
mgx::draw_map(&rec, &parser, &format!("{}.png", filename)).unwrap();

// Encoding of in game strings are guessed from instructions, may not be correct. `GBK` is used as a fallback.
println!("Encoding: {:?}", rec.detect_encoding().unwrap());

// .convert_encoding() calls .detect_encoding() first.
rec.convert_encoding();

// Some info like civilizations are stored as numeric raw data, `.translate()` converts these to human-readable strings. Only "zh"/"en" are supported now.
rec.translate();

// Dump comprehensive info into a JSON string. Check `null` values before using them.   
// This method calls .convert_encoding() first.
println!("{:?}", rec.dump_json().unwrap());

Parse a memory buffer

use mgx::{Parser, Record};

let mut buffer = Vec::new();

// Prepare filename and last_modified manually
let mut record = Record::new(filename, buffer.len(), last_modified);

// Parsing process won't start until `parse_to()` is called.
let mut parser = Parser::new(buffer).unwrap();
parser.parse_to(&mut record)?;

References

Dependencies

~16MB
~377K SLoC