7

I am interested in building a parser for my own enjoyment using PHP. What do I need to know? What suggestions would you have for me? How do I even open a Starcraft 2 replay using PHP?

4

3 回答 3

12

SC 重放文件实际上是一个 MPQ 存档文件。此 MPQ 存档包含几个不同的文件(如 .zip 文件)。

在此存档中,MPQ 存档中的每种数据类型都有单独的文件。(例如,一个文件用于游戏事件,另一个用于 UI 事件)。

网上有大量关于如何处理 MPQ 文件的文档。现在,MPQ 中的单个文件有点棘手。

如果您想从回放中获取信息(玩家是谁以及他们在哪张地图上玩过),您可以使用这些工具。(我假设一个类似 Unix 的 Web 服务器)。

1) 下载并构建 libmpq 和 mpq-tools ( https://libmpq.org/ )

2)运行以下脚本

您可以从 system() 调用运行这些,然后运行一些拆分命令来获取玩家和比赛。

将此保存为 info.sh。像命令 shell 一样运行它,并将重播文件作为参数传入。

#!/bin/bash

# Save this file as info.sh

# This extracts the individual files from the MPQ archive (the replay
# file)


mpq-extract -e $1 > /dev/null
cat file000000.xxx | strings | ruby info.rb

这是一个红宝石脚本。将此另存为 info.rb

# This *kinda* extracts the file info from a header file.  I don't
# really know how it works yet, so I'm just extracting strings.
#
# Save this file as info.rb

lines = STDIN.readlines
puts "%s:%s|%s:%s" % [(lines[0].strip), (lines[1].strip), (lines[2].strip), (lines[3].strip)]

希望这可以帮助!

于 2010-10-27T18:03:47.187 回答
2

看看http://code.google.com/p/phpsc2replay/

我认为这可能正是您正在寻找的。我当然希望我在一个月前找到它。

于 2010-11-27T05:50:29.657 回答
1

我如何使用 PHP 打开星际争霸 2 重播?

使用 PHP 的任何文件系统函数http://us.php.net/manual/en/ref.filesystem.php

由于大多数 SC2 重播的大小似乎都相当小,因此您可能会侥幸file_get_contents()将整个文件作为字符串检索。

于 2010-10-04T11:43:18.477 回答