小编lic*_*eng的帖子

解析帝国时代的游戏记录文件(.mgx)

我是过时的帝国时代II(AoE)游戏的粉丝.我想用Python编写AoE游戏记录(.mgx文件)的解析器.

我在GitHub上做了一些搜索并发现了很少的项目,最有用的是aoc-mgx格式,它提供.mgx游戏记录文件的一些细节.

这是问题所在:

根据参考文献,.mgx文件的结构如下:

| header_len(4byte int)| next_pos(4byte int)| header_data | ...... |

十六进制数据的mgx格式的字节顺序是小端.

header_len存储Header部分的数据长度(header_len + next_post + header_data)

header_data存储我需要的有用信息,但它用zlib压缩

我试图用zlib模块解压缩header_data中的数据,如下所示:

import struct
import zlib

with open('test.mgx', "rb") as fp:
    # read the header_len bytes and covert it to a int reprents length of Header part
    header_len = struct.unpack("<i", fp.read(4))[0]

    # read next_pos (this is not important for me)
    next_pos = struct.unpack("<i", fp.read(4))[0]

    # then I …
Run Code Online (Sandbox Code Playgroud)

python binaryfiles zlib inflate

8
推荐指数
1
解决办法
932
查看次数

标签 统计

binaryfiles ×1

inflate ×1

python ×1

zlib ×1