-
Notifications
You must be signed in to change notification settings - Fork 0
/
swap_roster.py
58 lines (47 loc) · 2.35 KB
/
swap_roster.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
import argparse
import os
from re import fullmatch
from data import SLOT_OFFSETS
from roster import NEW_ROSTER
parser = argparse.ArgumentParser(
prog = 'Mario Kart 8 Roster Swapper (Wii U)',
description = 'Allows swapping characters around in the character roster.',
epilog = 'Source Code: https://www.github.com/Scutlet/mk8-roster-swapper'
)
parser.add_argument('-n', '--modname', help="The name of the mod", default="New Character Roster")
parser.add_argument('-d', '--description', help="Description of the mod", default="Modifies the character roster.")
def main():
args = parser.parse_args()
modname: str = args.modname
if (fullmatch(r'[A-Za-z0-9_\- ]+', modname) is None
or fullmatch(r' +', modname) is not None):
print(f"Invalid modname provided: <{modname}>. Modname can only contain letters, numbers, underscores, hyphens, or spaces, and cannot only contain spaces.")
exit(1)
os.makedirs(modname, exist_ok=True)
create_cemu_pack(os.path.join(modname, "rules.txt"), modname, args.description)
write_roster_patch(os.path.join(modname, "patch_roster.asm"))
print(f'Output written in "{os.path.abspath(modname)}"')
def create_cemu_pack(filepath: str, modname: str, description: str):
""" Creates a new CEMU graphics pack """
with open(filepath, 'w') as fl:
fl.write("[Definition]\n")
fl.write("titleIds = 000500001010ec00,000500001010ed00,000500001010eb00\n")
fl.write(f"name = {modname}\n")
fl.write(f'path = "Mario Kart 8/Mods/{modname}\n')
fl.write(f"description = {description}\n")
fl.write("version = 6\n")
def write_roster_patch(filepath: str):
""" Creates a new CEMU patch file """
with open(filepath, 'w') as fl:
fl.write("##################################################################\n")
fl.write("# Automatically generated by the Mario Kart 8 Roster Swapper\n")
fl.write("# See: https://www.github.com/Scutlet/mk8-roster-swapper\n")
fl.write("##################################################################\n")
fl.write("[swapCharacterSlots]\n")
fl.write("moduleMatches = 0xd09700ce\n")
# Patch the roster
for i, char in enumerate(NEW_ROSTER):
fl.write(SLOT_OFFSETS[i].generate_instruction(char))
fl.write("\n")
if __name__ == "__main__":
main()