Created
March 17, 2013 02:51
-
-
Save Muon/5179346 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
header = struct.Struct("<5s58s256s256s6s") | |
playerinfo1 = struct.Struct("<64sH") | |
playerinfo2 = struct.Struct("<256s4I48s") | |
def modify_scn(filename, changes): | |
with open(filename, "rb+") as scn: | |
data = scn.read() | |
offset = 0 | |
magic, unknown1, music_path, scenario_monitor_path, unknown2 = header.unpack_from(data, offset) | |
assert magic == b"CHSCN" | |
offset += header.size | |
for i in range(15): | |
# Need to read this in two parts, as struct does not handle length-prefixed | |
# strings. | |
name, desclen = playerinfo1.unpack_from(data, offset) | |
offset += playerinfo1.size | |
desc = data[offset:offset + desclen] | |
offset += desclen | |
skin_path, unknown3, start_lc, unknown4, start_qp, unknown5 = playerinfo2.unpack_from(data, offset) | |
if start_lc > 0 and changes.start_lc is not None: | |
start_lc = changes.start_lc | |
if start_qp > 0 and changes.start_qp is not None: | |
start_qp = changes.start_qp | |
scn.seek(offset) | |
scn.write(playerinfo2.pack(skin_path, unknown3, start_lc, unknown4, start_qp, unknown5)) | |
offset += playerinfo2.size | |
if __name__ == "__main__": | |
from optparse import OptionParser | |
parser = OptionParser(description="Modify information in Achron .scn files", | |
usage="usage: %prog [options] FILE [FILE ...]") | |
parser.add_option("--start-lc", dest="start_lc", type="int", | |
help="set all the players' starting LC", metavar="LC") | |
parser.add_option("--start-qp", dest="start_qp", type="int", | |
help="set all the players' starting QP", metavar="QP") | |
options, args = parser.parse_args() | |
for arg in args: | |
modify_scn(arg, options) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment