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?
Replays are saved and stored in a special folder called "StarCraft II" in the user's Documents folder. If you disconnect from Battle.net while watching a replay you will be able to continue watching the replay until you exit the replay, where you will have to reconnect.
Replays are usually stored in the “\Maps\Replays” folder of StarCraft. Manually saved replays can be seen in this folder. The last played game is automatically saved as LastReplay.
In the Replay screen, right-click on the replay and select “Recover Game” in the context menu to take you to a Battle.net lobby. From this lobby you can invite the original players of the game.
Your savegames for the game can be found under [My Documents]\Starcraft II\Accounts....
The SC replay file is actually an MPQ archive file. This MPQ archive contains a few different files (like a .zip file).
Inside this archive are separate files for each of the types of data in the MPQ archive. (For example there is one file for game events and another for UI events).
There is a fair amount of documentation online about how to deal with MPQ files. Now, the individual files within the MPQ is a bit trickier.
If you want to get the information from the replay (who the players were and what map they played on) you can use these tools. (I'm assuming a Unix like web server).
1) Download and build libmpq and mpq-tools (https://libmpq.org/ )
2) Run the following scripts
You can run these from a system() call and then run a few split commands to get the players and the race.
Save this as info.sh. Run it like a command shell and pass in the replay file as an argument.
#!/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
Here is a ruby script. Save this as 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)]
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With