Files
jak-project/scripts/update-goal-src.py
T
Tyler Wilding 5f1ed7ab60 decomp: decompile *-obs files (#856)
* decomp: mostly finish `cam-master`

* decomp/scripts: lots of work in cam-states

* stash

* Merge remote-tracking branch 'water111/master' into decomp/camera-master

Updated submodule third-party/googletest

* decompiler: Add support for non power of 2 offsets for inline arr access

* decomp: mostly finish `cam-states` need to fix a macro issue

* blocked: `cam-master` decompiler crash when adding casts

* decomp: finish `cam-states-dbg`

* decomp: mostly finish `pov-camera` with the exception of joint-related code

* decomp: `cam-debug` finished decompiling, no way does this compile yet though

* decomp: considerable work done in `cam-layout`

* decomp: `cam-layout` almost done!

* decomp: `pov-camera` finished, TC tests will fail for now

* decomp: working on resolving issues

* decomp: cam-layout decompiling

* fixing more issues in cam-master...one event handler remains

* skip problematic function in `cam-master` for now

* gsrc: update res macros

* decomp: finish `cam-states`

* decomp: giving up on `cam-debug`

* tests: allow skipping state handlers in ref tests

* decomp: working through cam-layout bugs

* decomp: allow for shifting non-integers

* decomp: finalize `cam-layout` and `cam-master`

* decomp: finalize `cam-states`

* cleanup: bi-annual formatting of the casting files

* formatting

* decomp: start working on beach-obs

* blocked: `beach-obs` mostly finished, but handle cast issues and unknown `prebind` func signature

* blocked: `villagep-obs` done, `s6` not being referred to as `self`

* decomp: finish `citadel-obs`

* decomp: finish `darkcave-obs`

* blocked: need to allow `hud-h` to decompile properly (#f as static pointer)

* decomp: finish `jungle-obs`

* decomp: finish `village-obs`

* blocked: `misty-obs` handle cast issues

* decomp: finish `village2-obs`

* decomp: 1 function left in `swamp-obs`, particle related -- maybe we know now?

* decomp: finish `swamp-obs`

* blocked: `maincave-obs` handle casts

* decomp: finish `sunken-obs`

* blocked: `rolling-obs` handle casts and hud-parts

* decomp: finish `firecanyon-obs`

* decomp: finish `ogre-obs`

* blocked: `village3-obs` gives up type analysis!

* blocked: `snow-obs` has hud-parts and handle casts code

* decomp: finish `snow-flutflut-obs`

* blocked: `lavatube-obs` has s6-1 issue

* blocked: `title-obs` handle cast issues

* fixed post merge problems

* decomp: finish `jungleb-obs`

* blocked: `training-obs` has `s6-1` issue

* fix type consistency

* scripts: Extend update script to handle the game-text-id enum as well

* git: Update git attributes to effectively halve PR burden

* fixed `sound-play-by-name` signature

* fix particle definitions in firecanyon-obs

* fix func signature in racer-states

* update ref tests

* tests: update current ref tests

* tests: add `joint` to ref-tests

* tests: add `process-drawable` to ref-tests

* updated gsrc

* add back manual fix

* address most feedback, update source files

* get rid of forward declarations in `darkcave-obs`

Co-authored-by: ManDude <7569514+ManDude@users.noreply.github.com>
2021-11-05 21:29:32 -04:00

149 lines
4.1 KiB
Python

## Given a list of files(comma delimited), decompile it, then place it under the specified placeholder (if it exists)
## if the placeholder doesn't exist, error out
## the placeholder is `;; DECOMP BEGINS`
from jak1_file_list import file_list
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--files")
args = parser.parse_args()
files = args.files.split(",")
throw_error = False
# files in this list have manual modifications in in code block
# sometimes these modifications don't prevent a compiler error
# and are easy to commit
#
# if you know of / add such a modification, you should append to this
# list, it will remind you such a file was touched by making a root file
# that will be picked up by git to shame you
files_with_modifications = [
"target-util",
"ambient",
"viewer",
"sunken-obs"
]
for file in files:
if file in files_with_modifications:
file_name = "{}.manual_restore_reminder".format(file)
with open(file_name, 'w') as fp:
pass
disasm_path = "./decompiler_out/jak1/{}_disasm.gc".format(file)
if not os.path.exists(disasm_path):
print("{} doesn't exist!".format(disasm_path))
throw_error = True
continue
src_path = ""
for f in file_list:
if f[2] != 3:
continue
if f[0] == file:
src_path = f[4]
break
if not os.path.exists("./goal_src/{}".format(src_path)):
print("{} couldn't find in /goal_src!".format(file))
throw_error = True
continue
file_path = "./goal_src/{}/{}.gc".format(src_path, file)
new_lines = []
with open(file_path) as f:
lines = f.readlines()
found_placeholder = False
for line in lines:
if ";; decomp begins" in line.lower():
found_placeholder = True
new_lines.append(line.upper())
break
new_lines.append(line)
if found_placeholder == False:
print("No placeholder found in {}, skipping".format(file_path))
throw_error = True
continue
# finally...update the file
lines_to_ignore = [
";;-*-Lisp-*-",
"(in-package goal)",
";; definition",
";; INFO:",
";; failed to figure",
";; Used lq/sq"
]
def skippable_line(line):
for prefix in lines_to_ignore:
if line.startswith(prefix):
return True
return False
with open(disasm_path) as f:
lines = f.readlines()
in_inspect_method = False
for i, line in enumerate(lines):
# strip inspect methods
if line.startswith("(defmethod inspect") or (line.startswith("(defmethod") and (i + 1 < len(lines) and "inspect" in lines[i+1])):
in_inspect_method = True
continue
if in_inspect_method and line == "\n":
in_inspect_method = False
elif in_inspect_method:
continue
# strip comments we dont care about
if skippable_line(line):
continue
# otherwise, add it to the file
new_lines.append(line)
# write the damn thing
os.remove(file_path)
with open(file_path, "w") as f:
f.writelines(new_lines)
print("Copied - {}!".format(file))
print("Copying game-text-id enum")
begin_str = ";; GAME-TEXT-ID ENUM BEGINS"
end_str = ";; GAME-TEXT-ID ENUM ENDS"
enum_lines = []
with open('./decompiler/config/all-types.gc') as f:
lines = f.readlines()
found_enum = False
for line in lines:
if found_enum and end_str in line:
break
if found_enum:
enum_lines.append(line)
if begin_str in line:
found_enum = True
new_texth_lines = []
with open('goal_src/engine/ui/text-h.gc') as f:
lines = f.readlines()
found_enum = False
for line in lines:
if begin_str in line:
found_enum = True
new_texth_lines.append(begin_str + "\n")
new_texth_lines += enum_lines
new_texth_lines.append(end_str + "\n")
continue
if end_str in line:
found_enum = False
continue
if found_enum:
continue
new_texth_lines.append(line)
os.remove('goal_src/engine/ui/text-h.gc')
with open('goal_src/engine/ui/text-h.gc', "w") as f:
f.writelines(new_texth_lines)
print("game-text-id enum updated!")
if throw_error:
exit(1)