papermario/tools/substitute2.py
Maide 8fbdc83055
area_dgb (#254)
* area_arn/arn_02

* Signed StoryProgress enum

* arn_03

* Update scripts

* arn_04

* fix kmr

* Broken for Ethan

* Commiting before maybe breaking everything

* Fix star rod

* Add funcs

* arn_05

* arn_07

* arn_08/arn_09

* Cleanup prototypes

* arn_11/12/13

* Cleanup

* Cleanup

* Review

* Add npc flag

* Comments

* dgb_01

* dgb_02

* dgb_03

* dgb_04

* Fixup commented functions

* dgb_05

* dgb_06

* dgb_07

* dgb_08

* dgb_09

* dgb_10

* dgb_11

* dgb_12

* dgb_15

* dgb_13

* dgb_14

* dgb_16

* dgb_17

* dgb_18

* Dumb newlines

* Replacing some funcs, scared I'll break everything to commit NOW!

* More

* More

* More

* a

* b

* c

* d

* e

* f

* remove asm

* Move newlines
2021-04-09 02:42:36 +09:00

82 lines
2.6 KiB
Python

from pathlib import Path
FUNC=""" script->varTable[0] = 0;
if ((D_8010EBB0.unk_00 != 0) && (D_8010EBB0.unk_03 == 3)) {
script->varTable[0] = 1;
}
return ApiStatus_DONE2;
}""".splitlines()
NEW_FUNC_NAME = f"UnkFunc24"
NEW_INCLUDE = f"#include \"world/common/{NEW_FUNC_NAME}.inc.c\""
RENAMED = []
def parse_folder(path):
for entry in path.iterdir():
if entry.is_dir():
parse_folder(entry)
continue
if not "area" in str(entry):
continue
area_name = entry.parts[3]
fd = entry.read_text().splitlines()
i = 0
while i < len(fd):
if (i+2 < len(fd) and
fd[i].startswith("INCLUDE_ASM") and
fd[i+1] == "/*"):
for func, test in zip(fd[i+3:], FUNC):
if func != test:
break
else:
print(f"Found a match in {entry}: {fd[i]}")
#print("\n".join(fd[i:i+3+len(FUNC)+1]))
#print("\n".join(fd))
include_path = Path("src/world/common/") / (NEW_FUNC_NAME + ".inc.c")
if not include_path.is_file():
name_start = fd[i+2].find("N(")
name_end = fd[i+2].find("(",name_start+2)
new_file_name = fd[i+2][:name_start] + "N(" + NEW_FUNC_NAME + ")" + fd[i+2][name_end:]
new_fd = ["#include \"common.h\"",
"#include \"map.h\"",
"",
new_file_name,
]
new_fd.extend(FUNC)
include_path.write_text("\n".join(new_fd))
old_func_name = fd[i].split(",")[2].strip().replace(");", "")
RENAMED.append({"name":old_func_name, "area":area_name})
fd = fd[:i] + [NEW_INCLUDE] + fd[i+3+len(FUNC)+1:]
if fd[-1] != "":
fd.append("")
entry.write_text("\n".join(fd))
break
i += 1
parse_folder(Path("src/world"))
def do_renames(path):
for entry in path.iterdir():
if entry.is_dir():
do_renames(entry)
continue
fd = entry.read_text()
for rename in RENAMED:
if rename["name"] in fd:
fd = fd.replace(rename["name"], f"{rename['area']}_{NEW_FUNC_NAME}")
entry.write_text(fd)
do_renames(Path("ver/us/asm"))