Skip to content

Instantly share code, notes, and snippets.

@TheNathannator
Forked from NWPlayer123/WiiMap2GCMap.py
Last active February 18, 2024 02:49
Show Gist options
  • Save TheNathannator/9847eb1142d702d94ef9d6a491c048fa to your computer and use it in GitHub Desktop.
Save TheNathannator/9847eb1142d702d94ef9d6a491c048fa to your computer and use it in GitHub Desktop.
Converts Wii symbol maps (e.g. Kirby's Return to Dreamland) to GameCube symbol maps
import os
import sys
def sanitize(line):
line = line.strip()
line = line.replace("\t", " ")
for i in range(5):
line = line.replace(" ", " ")
return line.split(" ")
map_path = sys.argv[1]
(map_dir, map_name) = os.path.split(map_path)
converted_path = os.path.join(map_dir, map_name.lower().replace(".map", "_conv.map"))
symbol_map = open(map_path, "r").read()
symbol_map = symbol_map.replace("\r\n", "\n") #easier to work with
segments = symbol_map.split("\n\n\n")
converted_map = open(converted_path, "w")
comms = []
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], file = converted_map) #<section> section layout
print(lines[1][:-6], file = converted_map)
print(lines[2][:-8], file = converted_map)
print(lines[3][:-10], file = converted_map)
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()), file = converted_map)
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()), file = converted_map)
print("\n", file = converted_map)
else:
for line in lines:
print(line, file = converted_map)
if segments.index(segment) != (len(segments) - 1): #no EOF newlines
print(file = converted_map)
print(file = converted_map)
'''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