From 97425f68aef4a8fc773a5ef6fb5bd61b51d40f71 Mon Sep 17 00:00:00 2001 From: Maide <34639600+Kelebek1@users.noreply.github.com> Date: Sat, 20 Nov 2021 03:17:33 +0000 Subject: [PATCH] m2ctx: Optionally return Player* for Player accesses (#446) * m2ctx * Rename --- tools/m2ctx.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tools/m2ctx.py b/tools/m2ctx.py index a095c2811c..16087885b3 100755 --- a/tools/m2ctx.py +++ b/tools/m2ctx.py @@ -7,6 +7,46 @@ script_dir = os.path.dirname(os.path.realpath(__file__)) root_dir = script_dir + "/../" src_dir = root_dir + "src/" +# Read through the processes context and replace whatever +def custom_replacements(output): + output = output.splitlines() + + i = 0 + while i < len(output): + line = output[i] + + ############### actorLists[2].first -> Player* ############### + if "typedef struct ActorListEntry " in line: + actorListText = "" + i += 1 + while not output[i].startswith("}"): + actorListText += output[i] + i += 1 + actorCats = [ + "actorSwitch", + "bg", + "player", + "explosive", + "npc", + "enemy", + "prop", + "itemAction", + "misc", + "boss", + "door", + "chest", + ] + actorList = [] + for x in range(12): + actorList.append(actorListText.replace("first;", f"{actorCats[x]};") + "\n") + if x == 2: + actorList[x] = actorList[x].replace("Actor*", "Player*") + elif "ActorListEntry actorList[12];" in line: + output[i] = "struct {\n" + "".join(actorList) + "};" + ######################################################## + + i += 1 + return "\n".join(output) def get_c_dir(dirname): for root, dirs, files in os.walk(src_dir): @@ -42,6 +82,8 @@ def main(): description="Creates a ctx.c file for mips2c. " "Output will be saved as oot/ctx.c") parser.add_argument('filepath', help="path of c file to be processed") + parser.add_argument("--custom", "-c", dest="custom", action="store_true", default=False, + help="Apply custom replacements to the output to help aid m2c output") args = parser.parse_args() if args.filepath: @@ -59,6 +101,9 @@ def main(): output = import_c_file(c_file_path) + if args.custom: + output = custom_replacements(output) + with open(os.path.join(root_dir, "ctx.c"), "w", encoding="UTF-8") as f: f.write(output)