-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildloader.py
120 lines (99 loc) · 4.1 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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", "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):
rvl_sdk_path = "PetariHeaders/RVL_SDK/include"
trk_path = "PetariHeaders/MetroTRK/include"
runtime_path = "PetariHeaders/Runtime/include"
msl_c_path = "PetariHeaders/MSL_C/include"
facelib_path = "PetariHeaders/RVLFaceLib/include"
jsystem_path = "PetariHeaders/JSystem/include"
nw4r_path = "PetariHeaders/nw4r/include"
# 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"
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 loader -i Petari/ -I- -i PetariHeaders/include -i {facelib_path} -i {rvl_sdk_path} -I- -i {trk_path} -I- -i {runtime_path} " \
f"-I- -i {msl_c_path} -I- -i {jsystem_path} -I- -i {nw4r_path} -i include -D{region} " \
f"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="RMG{getregionletter(region)}" />
<options>
<section name="Syati Loader">
<option name="Super Mario Galaxy">
<choice name="Enabled">
<patch id="syati" />
</choice>
</option>
</section>
</options>
<patch id="syati">
{loaderPatches}
<file disc="/CustomCode/CustomCode_USA.bin" external="CustomCode_USA.bin" create="true" />
</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)