mirror of
https://github.com/zeldaret/mm.git
synced 2026-05-30 08:56:25 -04:00
6069a1585f
* Match Player_GetHeight * Another bunch * Fix merge conflict * rename Gfx_DrawDListXlu * add WEEROR * Actor_Spawn * almost Actor_SpawnTransitionActors and Actor_Delete * A bunch of small actors * More renames * format * Some Player renames * a few more * import data * run formatter * func_800B7170 * whoops * Fix merge issues * Whoops 2 * func_800B83BC and func_800B83F8 * Actor_IsActorFacingPlayerAndWithinRange * add some prototypes * match Actor_UpdateBgCheckInfo * func_800B7678 * mark Actor_SpawnAsChildAndCutscene as non_matching * Actor_Draw * Update is chaotic * 2 new matches * func_800BC8B8 * Another bunch * function renames * run formatter * cleanup * remove unnecesary casts * add missing sfx * Fix renames * fix merge * func_800BF7CC * small bunch * another bunch * func_800BE184 non_matching * two more * split z_cheap_proc * Another bunch * another bunch * a few and a non matching * yeee * a * Actor_DrawAll non_equivalent * Actor_RecordUndrawnActor * i don't know what to put in this commit message * func_800B4B50 non matching * func_800B42F8 non matching * func_800B5040 * func_800B5814 non_equiv * func_800B6584 * func_800B6608 * func_800B6680 * func_800B7E04 * func_800B8118 * func_800b9170 * , * func_800BC4EC * func_800BA6FC * func_800BA798 * func_800BA8B8 * Actor_LoadOverlay * small cleanup * func_800BB2D0 * meh * func_800BBAC0 * func_800BC270 * func_800B5208 non matching * Fix warnings * meh * rename some ActorShadow_ functions * fairy * Flags_ * fix warnings * format * Actor_PickUp and family * func_800B8E58 * match Actor_RemoveFromCategory * another bit of docs * Match func_800B86C8 * And another bit * rename Player_GetRunSpeedLimit * func_800B9E84 * func_800BE63C * func_800BB8EC * match func_800B5814 * match func_800B9334 * cleanup * fix conflicts: first pass * another fix * actorfixer fix * fix conflicts * func_800BE680 non_equivalent * Improve func_800BE680 a bit * func_800BE680 equivalent (?) * func_800BE680 equivalent * Actor_UpdateActor equivalent * format * use some ExchangeItemID enum values * Some more cleaning * more cleanup * More name stealing from OoT * match func_800B82EC * match func_800B9D1C and a bit of cleanup * Add ACTOR_FLAGS placeholders * Renames and match func_800BE184 * last pass of name stealing * format * fix conflicts * more cleanup * more cleanup * cleanup and OVERLAY_RELOCATION_OFFSET macro * Remove prototypes of obviously internal-only functions, update variable names, forward declare where necessary, remove all `param_\d`s * remove newlines * minor rename * Use ACTOR_FLAGS in z_actor * Match func_800BE3D0 * Rename movement functions * Document Actor_CalcOffsetOrientedToDrawRotation * velX -> horizontalSpeed * A bit of documentation for actor movement functions * format * Fix merge issues * format * Format * Fix renames * fix warnings * fix conflicts * review :D * Update src/overlays/actors/ovl_En_Ma4/z_en_ma4.c Co-authored-by: Derek Hensley <hensley.derek58@gmail.com> * Fix * format * Actor_SpawnSetupActors * engineer review * Update src/code/z_actor.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * A bunch of Engineer's reviews * more Engineer's review * a * whoops * run actorfixer * c'mon * 😮💨 * whoops * warning * More engineer's review * run format * I'm dumb * a * match func_800BE680 * Match Actor_DrawZTarget * Match Actor_SpawnAsChildAndCutscene, fix non-equivalent in Actor_UpdateActor * Fix merge issue * format * update actor * Steal a bit of @Thar0 documentation from OoT's z_message * Run actorfixer * Fix renames * Match func_800B4B50 thanks to @hensldm * Improve ActorShadow_DrawFeet thanks to @hensldm * whoops * Actor_PlaySfxAtProjectedPos * Actor_UpdateActor matched by @hensldm * Match func_800BA2FC by @hensldm * Match Actor_SpawnTransitionActors by @hensldm * Match func_800BB604 by @hensldm * Match Actor_DrawAll by @hensldm * ActorShadow_DrawFeet by @hensldm * Actor_UpdateAll by @hensldm * Match func_800BCCDC by @engineer124 * Small Actor_PlaySfxAtPos by @engineer124 * ACTOR_FLAGS_ALL and a bit of cleanup * Add invisible comment * Small docs pass * Fix merge * Engineer's review * format lol * Actor_DrawDoorLock docs * Actor_SpawnShieldParticlesMetal * fix merge issues * sActorFaultClient * fix * commit message * Run actorfixer.py && format.sh * Fix warnings * fixes * format * bss * Update include/functions.h Co-authored-by: Derek Hensley <hensley.derek58@gmail.com> * Address review * Fix merge issues, format and such * fix merge issues * Add ACTORCAT_MAX * actorList -> actorLists * Fix merge issues * format * Enable WERROR on jenkinsfile * Fix merge * Use object symbols * address review * format * review * fix merge issues * fix * VRAM_PTR_SIZE, small cleanup and format * review Co-authored-by: Elliptic Ellipsis <elliptic.ellipsis@gmail.com> Co-authored-by: Derek Hensley <hensley.derek58@gmail.com> Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> Co-authored-by: engineer124 <engineer124engineer124@gmail.com>
113 lines
3.8 KiB
Python
Executable File
113 lines
3.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import argparse, os, subprocess, sys
|
|
from pathlib import Path
|
|
|
|
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 actorLists[ACTORCAT_MAX];" 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):
|
|
for directory in dirs:
|
|
if directory == dirname:
|
|
return os.path.join(root, directory)
|
|
|
|
|
|
def get_c_file(directory):
|
|
for root, dirs, files in os.walk(directory):
|
|
for file in files:
|
|
if file.endswith(".c") and "data" not in file:
|
|
return file
|
|
|
|
|
|
def import_c_file(in_file):
|
|
in_file = os.path.relpath(in_file, root_dir)
|
|
cpp_command = ["gcc", "-E", "-P", "-Iinclude", "-Iassets", "-Isrc", "-undef", "-D__sgi", "-D_LANGUAGE_C",
|
|
"-DNON_MATCHING", "-D_Static_assert(x, y)=", "-D__attribute__(x)=", in_file]
|
|
try:
|
|
return subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8")
|
|
except subprocess.CalledProcessError:
|
|
print(
|
|
"Failed to preprocess input file, when running command:\n"
|
|
+ cpp_command,
|
|
file=sys.stderr,
|
|
)
|
|
sys.exit(1)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(usage="./m2ctx.py path/to/file.c or ./m2ctx.py (from an actor or gamestate's asm dir)",
|
|
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:
|
|
c_file_path = args.filepath
|
|
print("Using file: {}".format(c_file_path))
|
|
else:
|
|
this_dir = Path.cwd()
|
|
c_dir_path = get_c_dir(this_dir.name)
|
|
if c_dir_path is None:
|
|
sys.exit(
|
|
"Cannot find appropriate c file dir. In argumentless mode, run this script from the c file's corresponding asm dir.")
|
|
c_file = get_c_file(c_dir_path)
|
|
c_file_path = os.path.join(c_dir_path, c_file)
|
|
print("Using file: {}".format(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:
|
|
f.write(output)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|