# mgz
Age of Empires II recorded game parsing and summarization in Python 3.
## Supported Versions
- Age of Kings (`.mgl`)
- The Conquerors (`.mgx`)
- Userpatch 1.4 (`.mgz`)
- Userpatch 1.5 (`.mgz`)
- HD Edition >= 4.6 (`.aoe2record`)
- Definitive Edition (`.aoe2record`)
## Architecture
The core functionality of `mgz` is a parser that produces a Python data structure based on a recorded game file. It also offers abstracted representations that make it easier to use the data.
### Parsers
`mgz` offers two parsers, `fast` and `full`. The `fast` parser skips data that is rarely needed, while the `full` parser tries to parse as much as possible. Naturally, the `fast` parser is faster than the `full` parser.
### Abstractions
Abstractions take parser output as input and return an object with normalized data that is easier to use for most cases. There are two abstractions available, `summary` and `model`. The `summary` abstraction attempts to expose the maximum amount of usable data. The `model` abstraction is more limited but automatically performs more lookups.
## Support
| Version | model | summary | fast (header) | fast (body) | full (header) | full (body) |
| --- | :-: | :-: | :-: | :-: | :-: | :-: |
| Age of Kings (`.mgl`) | | ✓ | | ✓ | ✓ | |
| The Conquerors (`.mgx`) | | ✓ | | ✓ | ✓ | |
| Userpatch <= 1.4 (`.mgz`) | | ✓ | | ✓ | ✓ | ✓ |
| Userpatch 1.5 (`.mgz`) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| HD Edition >= 4.6 | | ✓ | | ✓ | ✓ | ✓ |
| HD Edition 5.8 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Definitive Edition <= 13.34 (`.aoe2record`) | | ✓ | | ✓ | ✓ | ✓ |
| Definitive Edition > 13.34 (`.aoe2record`) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
## Examples
### Full Parser
```python
import os
from mgz import header, body
with open('/path/to/file', 'rb') as data:
eof = os.fstat(data.fileno()).st_size
header.parse_stream(data)
body.meta.parse_stream(data)
while data.tell() < eof:
body.operation.parse_stream(data)
```
#### Full Parser (header) + Fast Parser (body)
```python
import os
from mgz import header, fast
with open('/path/to/file', 'rb') as data:
eof = os.fstat(data.fileno()).st_size
header.parse_stream(data)
fast.meta(data)
while data.tell() < eof:
fast.operation(data)
```
### Summary
```python
from mgz.summary import Summary
with open('/path/to/file', 'rb') as data:
s = Summary(data)
s.get_map()
s.get_platform()
# ... etc
```
### Model
```python
from mgz.model import parse_match
with open('/path/to/file', 'rb') as data:
match = parse_match(data)
match.map.name
match.file.perspective.number
# ... etc
```
## To JSON
```python
import json
from mgz.model import parse_match, serialize
with open('/path/to/file', 'rb') as h:
match = parse_match(h)
print(json.dumps(serialize(match), indent=2))
```
## Frequently Asked Questions
**Q:** Where are the end-of-game achievements/statistics?
**A:** In the `postgame` action, available only from Userpatch version.
**Q:** How can I tell the number of resources/kills/etc at a certain point?
**A:** You can't, without replaying the match in-game.
**Q:** How does a recorded game file work?
**A:** The first portion (the `header`) is a snapshot of the initial game state. The second portion (the `body`) is a list of moves made by players. The game loads the header, then applies each move to mutate the state according to the game rules.
**Q:** How can I install this package?
**A:** `pip install mgz`
## Contribution
- Pull requests & patches welcome
## Resources
- aoc-mgx-format: https://github.com/stefan-kolb/aoc-mgx-format
- recage: https://github.com/goto-bus-stop/recage
- recanalyst: http://sourceforge.net/p/recanalyst/
- genie-rs: https://github.com/SiegeEngineers/genie-rs/tree/default/crates/genie-rec
- bari-mgx-format: https://web.archive.org/web/20090215065209/http://members.at.infoseek.co.jp/aocai/mgx_format.html
PyPI 官网下载 | mgz-1.7.0.tar.gz
版权申诉
21 浏览量
2022-01-13
05:18:54
上传
评论
收藏 59KB GZ 举报
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
最新资源
- 基于thinkphp5和layui的JTimer秒级定时任务管理设计源码
- 基于JavaScript语言Web项目图书管理系统(源代码+md说明文档)-计算机专业精品前端课程设计
- VTable 是 VisActor 可视化体系中的表格组件库,基于可视化渲染引擎 VRender 进行封装
- 基于Java的 android百度图像识别API开发的车型识别APK
- 基于Vue的轻量级开源工业物联网持续集成平台管理端设计源码
- 基于python+百度语音识别API, 读取视频文件,将视频中的语音转换成文字输出
- 斯沃数控仿真软件7.2版数控加工中心车床铣床编程仿真模拟教程斯沃系统手册凯恩帝100T
- 腾讯云 Web 超级播放器 JS 引用库
- 19道MySQL分库分表高频题整理(附答案背诵版).md
- 基于PyQt5做界面,使用百度文字识别API接口来实现识别图片中的文字,可以采用截图和浏览图片文件方式进行
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈