Crate mgx

Source
Expand description

§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)?;
record.convert_encoding();
record.translate();

§References

Structs§

Chat
Information of a chat message. Lobby chats don’t have time. Field player is not implemented yet
DebugInfo
Debug information used by the parser
Parser
Recorded game parser. Used to parse recorded game file
Player
Information of a player
Record
Store information of this game extracted from the recorded game. Most fields will be None if not present in the recorded game or exception occurs during parsing

Enums§

Version
Version of the recorded game

Functions§

draw_map
Generate minimap from map data. Save it to savename.png
from_file
Parse a recorded game file into a Record and Parser. Game info can be accessed from Record