-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildloader.py
106 lines (86 loc) · 3.2 KB
/
buildloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import shutil
import subprocess
import sys
from pathlib import Path
def err(message: str):
print(f"Error: {message}")
sys.exit(1)
def dep(path, name):
path = Path(path)
if not os.path.exists(path):
err(f"{name} not found!")
return path
def prepare_bin():
if os.path.exists("bin"):
shutil.rmtree("bin")
os.makedirs("bin")
REGIONS = ["PAL", "USA", "JPN", "TWN", "KOR"]
LETTERS = ['P', 'E', 'J', 'W', 'K']
MWCCEPPC = dep("deps/CodeWarrior/mwcceppc.exe" if sys.platform == "win32" else "deps/CodeWarrior/mwcceppc", "CodeWarrior compiler")
KAMEK = dep("deps/Kamek/Kamek.exe", "Kamek linker")
SYMBOLS = dep("symbols", "Symbols folder")
def getregionletter(region: str):
for i in range(0, len(REGIONS)):
reg = REGIONS[i]
if region == reg:
return LETTERS[i]
def build(region: str, outputPath: str, buildFullXML: bool):
compile_cmd = f"{MWCCEPPC} -c -Cpp_exceptions off -nodefaults -proc gekko -fp hard -lang=c++ -O4,s -inline on " \
f"-rtti off -sdata 0 -sdata2 0 -align powerpc -func_align 4 -str pool -enum int -DGEKKO " \
f"-i include -I- -i loader -D{region} loader/loader.cpp -o loader/loader.o"
kamek_cmd = f"{KAMEK} loader/loader.o -static=0x80001800 -externals={SYMBOLS}/{region}.txt " \
f"-output-riiv={outputPath}/riivo_{region}.xml " \
f"-output-kamek={outputPath}/Loader{getregionletter(region)}.bin " \
f"-output-dolphin={outputPath}/Dolphin{getregionletter(region)}.ini"
print(f"Building target {region}!")
if os.path.exists(f"deps/{region}.dol"):
kamek_cmd += f" -input-dol=deps/{region}.dol -output-dol=bin/{region}.dol"
if subprocess.call(compile_cmd, shell=True) != 0:
err("Compiling failed.")
if subprocess.call(kamek_cmd, shell=True) != 0:
err("Linking failed.")
if buildFullXML:
loaderPatches = open(f"{outputPath}/riivo_{region}.xml", "r").read()
fullXMLBody = f"""<wiidisc version="1">
<id game="SB4{getregionletter(region)}" />
<options>
<section name="Syati Loader">
<option name="Super Mario Galaxy 2">
<choice name="Enabled">
<patch id="syati" />
</choice>
</option>
</section>
</options>
<patch id="syati">
{loaderPatches}
</patch>
</wiidisc>"""
open(f"{outputPath}/riivo_{region}.xml", "w").write(fullXMLBody)
print("Done!")
if __name__ == '__main__':
isNextArgOutput = False
buildFullXML = False
outputPath = ""
region = ""
for currentArg in sys.argv:
if (currentArg == "buildloader.py"):
continue
if (isNextArgOutput):
outputPath = currentArg
isNextArgOutput = False
elif (currentArg == "-o"):
isNextArgOutput = True
elif (currentArg == "--full-xml"):
buildFullXML = True
else:
region = currentArg
if region not in REGIONS:
print("Did not specify a (valid) target region, building all targets!")
prepare_bin()
for region in REGIONS:
build(region, outputPath or "loader/", buildFullXML)
else:
prepare_bin()
build(region, outputPath or "loader/", buildFullXML)