Created
March 28, 2019 04:22
-
-
Save NWPlayer123/36f01fa560177c3ceb666f99ebbb2321 to your computer and use it in GitHub Desktop.
Converts Wii symbol maps (e.g. Kirby's Return to Dreamland) to GameCube symbol maps
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
def sanitize(line): | |
line = line.strip() | |
line = line.replace("\t", " ") | |
for i in range(5): | |
line = line.replace(" ", " ") | |
return line.split(" ") | |
symbol_map = open("iuk1.MAP", "rb").read() | |
symbol_map = symbol_map.replace("\r\n", "\n") #easier to work with | |
segments = symbol_map.split("\n\n\n") | |
comms = [] | |
print #newline before .init | |
for segment in segments: | |
lines = segment.strip().split("\n") #first section has newline, strip() | |
if "section layout" in lines[0]: #section I can parse | |
segname = lines[0].split(" ")[0] | |
print(lines[0]) #<section> section layout | |
print(lines[1][:-6]) | |
print(lines[2][:-8]) | |
print(lines[3][:-10]) | |
if len(lines) > 4: #has entries | |
for line in lines[4:]: | |
if line.strip().startswith("00"): | |
line = sanitize(line) | |
line.pop(3) #new variable | |
if "(entry" in line: | |
comm = line[7:] | |
else: | |
comm = line[5:] | |
if len(comm) == 2: | |
if "/" in comm[1] or "\\" in comm[1]: | |
comm[1] = comm[1].split("/")[-1] | |
comm[1] = comm[1].split("\\")[-1] | |
else: | |
comm.append("") | |
if comm not in comms: | |
comms.append(comm) #debug | |
if not "(entry" in line: | |
for i in range(3): | |
line[i] = int(line[i], 16) | |
line[3] = int(line[3]) | |
print(" %08x %06x %08x %2d %s \t%s" % (line[0], line[1], line[2], line[3], line[4], " ".join(comm).rstrip())) | |
else: | |
for i in range(3): | |
line[i] = int(line[i], 16) | |
print(" %08x %06x %08x %s %s %s %s \t%s" % (line[0], line[1], line[2], line[3], line[4], line[5], line[6], " ".join(comm).rstrip())) | |
print("\n") | |
else: | |
for line in lines: | |
print(line) | |
if segments.index(segment) != (len(segments) - 1): #no EOF newlines | |
'''comms.sort(key=lambda x: x[1]) | |
comms.sort(key=lambda x: x[0]) | |
for comm in comms: | |
print(" ".join(comm))''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment