mirror of https://github.com/zeldaret/mm.git
m2ctx: Optionally return Player* for Player accesses (#446)
* m2ctx * Rename
This commit is contained in:
parent
48a5116389
commit
97425f68ae
|
@ -7,6 +7,46 @@ script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
root_dir = script_dir + "/../"
|
root_dir = script_dir + "/../"
|
||||||
src_dir = root_dir + "src/"
|
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):
|
def get_c_dir(dirname):
|
||||||
for root, dirs, files in os.walk(src_dir):
|
for root, dirs, files in os.walk(src_dir):
|
||||||
|
@ -42,6 +82,8 @@ def main():
|
||||||
description="Creates a ctx.c file for mips2c. "
|
description="Creates a ctx.c file for mips2c. "
|
||||||
"Output will be saved as oot/ctx.c")
|
"Output will be saved as oot/ctx.c")
|
||||||
parser.add_argument('filepath', help="path of c file to be processed")
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.filepath:
|
if args.filepath:
|
||||||
|
@ -59,6 +101,9 @@ def main():
|
||||||
|
|
||||||
output = import_c_file(c_file_path)
|
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:
|
with open(os.path.join(root_dir, "ctx.c"), "w", encoding="UTF-8") as f:
|
||||||
f.write(output)
|
f.write(output)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue