Curation round 3: Lua engine, Manager, sound, menus, cutscenes, rooms, item pools, saves; boots past LuaEngine::Init
Seven agents took over LuaEngine (the mod API registration deferred), the rest of Manager (LoadConfigs, fonts, render surfaces, Update/Render), MusicManager/SFXManager, MenuManager with the title/save/game menus, Cutscene/NightmareScene/ Backdrop, RoomConfig (src/rooms ported and retired) with ItemPool, and PersistentGameData (the original binary save format) with InfoDisplay. An integration pass moved call sites to the new APIs, declared the taken-over free functions, fixed two data.cpp crashes (an empty children array, null attribute strings), and made the generator keep a header's own name where a prototype names another address. Clean build (0 warnings with -Wall -Wextra). build/isaac runs the game's Lua scripts (without the mod API yet) and stops at reload_resource_paths. 901 functions taken over, boot path 204/615. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a7061306fa
commit
ddf913f304
137 files changed
+12684
-50687
No files matched your search
+22
-17
@@ -154,8 +154,9 @@ def fields_load():
|
||||
|
||||
|
||||
def functions_load(): # address -> (Class, method, return type, calling convention, params without this, this param, body)
|
||||
funcs = {}
|
||||
funcs, headers = {}, {}
|
||||
for chunk in open(dumpDir + '/all.c', errors='replace').read().split('\n//@@ ')[1:]:
|
||||
headers[int(chunk.split(None, 1)[0], 16)] = chunk.split('\n', 1)[0].split(None, 1)[-1]
|
||||
head, _, rest = chunk.partition('\n{\n')
|
||||
block = head.strip().split('\n\n')[-1] # the last paragraph before '{' (comments can hold or lose '*/')
|
||||
match = CALLING.match(' '.join(block.split())) # Ghidra wraps long signatures
|
||||
@@ -164,6 +165,10 @@ def functions_load(): # address -> (Class, method, return type, calling conven
|
||||
params = [p.strip() for p in match['params'].split(',') if p.strip() and p.strip() != 'void']
|
||||
thisParam = params.pop(0) if match['cc'] == '__thiscall' and params else None
|
||||
funcs[int(chunk.split(None, 1)[0], 16)] = (cls, method, match['ret'].strip(), match['cc'] or '', params, thisParam, rest[:rest.rfind('\n}')])
|
||||
claimed = set(headers.values())
|
||||
for addr, f in funcs.items(): # a stale prototype naming another function's address takes its own header's name
|
||||
name = f'{f[0]}::{f[1]}' if f[0] else f[1]
|
||||
if headers[addr] != name and name in claimed: funcs[addr] = headers[addr].rpartition('::')[::2] + f[2:]
|
||||
return funcs
|
||||
|
||||
|
||||
@@ -362,7 +367,7 @@ done, order, used, canon, defined = {}, [], set(), {}, {}
|
||||
stubs, dataStubs = [], [] # (owner, declaration, address): everything src/ has not taken over, defined as a stub # defined: address -> the declaration its body is defined with
|
||||
def class_emit(cls, stack=()):
|
||||
if cls in done or cls in stack or cls in PRELUDE_TYPES: return
|
||||
if cls in curatedClasses: return # declared by src/, only forward-declared here
|
||||
if cls in curatedClasses or cls.rpartition('::')[0] in curatedClasses: return # declared by src/ (a nested class with its outer one), only forward-declared here
|
||||
parent = base.get(cls) if base.get(cls) in names and base.get(cls) not in curatedClasses else None # a src/ parent stays bytes
|
||||
if parent: class_emit(parent, stack + (cls,))
|
||||
namespace, _, shortName = cls.rpartition('::')
|
||||
@@ -446,6 +451,19 @@ def curated_classes_load(): # src/ defines these itself: top-level classes, an
|
||||
found |= set(re.findall(r'^(?:struct|class) (\w+)\b[^;]*$', NAMESPACE_BLOCK.sub('', text), re.M))
|
||||
return found
|
||||
curatedClasses = curated_classes_load()
|
||||
def curated_load(): # addresses src/ took over: the one starting a comment, and every one in a (a, b, c to d) list on it
|
||||
found, addresses = set(), sorted(funcs)
|
||||
for root, _, files_ in os.walk(srcDir):
|
||||
for name in [f for f in files_ if f.endswith(('.cpp', '.h'))]:
|
||||
for comment in re.findall(r'//(.*)', open(os.path.join(root, name), errors='replace').read()):
|
||||
lists = re.findall(r'\(((?:[0-9a-f]{8}(?:\s*(?:,|to)\s*)?)+)\)', comment)
|
||||
lead = re.match(r'\s*([0-9a-f]{8})\b', comment)
|
||||
for item in lists + ([lead[1]] if lead else []):
|
||||
for low, high in re.findall(r'([0-9a-f]{8})(?:\s*to\s*([0-9a-f]{8}))?', item):
|
||||
high = high or low
|
||||
found |= {a for a in addresses if int(low, 16) <= a <= int(high, 16)} | {int(low, 16)}
|
||||
return found
|
||||
curated = curated_load()
|
||||
for c in sorted(names): class_emit(c)
|
||||
intrinsics = sorted({m.group(1) + m.group(2) for f in funcs.values() for m in INTRINSIC.finditer(f[6])})
|
||||
def intrinsic_define(name): # CONCAT412: x=4, y=12; ZEXT1632: x=16, y=32 (a leading 12/16 is a two-digit size)
|
||||
@@ -457,7 +475,7 @@ def intrinsic_define(name): # CONCAT412: x=4, y=12; ZEXT1632: x=16, y=32 (a le
|
||||
# Everything that is not a method of a class above: free functions (FUN_ too) and namespace functions, as declared
|
||||
free, freeSeen = collections.defaultdict(list), set()
|
||||
for addr, (cls, method, ret, cc, params, thisParam, _) in sorted(funcs.items()):
|
||||
if cls in done or cls in curatedClasses or not IDENT.match(method) or (cls and not QUALIFIED.match(cls)) or (cls, method) in freeSeen or (not cls and method in STD_NAMES): continue
|
||||
if addr in curated or cls in done or cls in curatedClasses or (cls or '').rpartition('::')[0] in curatedClasses or not IDENT.match(method) or (cls and not QUALIFIED.match(cls)) or (cls, method) in freeSeen or (not cls and method in STD_NAMES): continue
|
||||
freeSeen.add((cls, method))
|
||||
if thisParam: params = [re.sub(r'\bthis$', 'self', thisParam)] + params
|
||||
free[cls].append(f'{ret} {method}({", ".join(params)}); // {addr:08x}')
|
||||
@@ -520,19 +538,6 @@ with open(outDir + '/classes.h', 'w') as o:
|
||||
# One .cpp per class: each body under the declaration it was declared with; a renamed `this` gets an alias.
|
||||
members = {f'{f[0]}::{f[1]}' for f in funcs.values() if f[3] == '__thiscall' and f[0] in done}
|
||||
spans, files = collections.defaultdict(list), {}
|
||||
def curated_load(): # addresses src/ took over: the one starting a comment, and every one in a (a, b, c to d) list on it
|
||||
found, addresses = set(), sorted(funcs)
|
||||
for root, _, files_ in os.walk(srcDir):
|
||||
for name in [f for f in files_ if f.endswith(('.cpp', '.h'))]:
|
||||
for comment in re.findall(r'//(.*)', open(os.path.join(root, name), errors='replace').read()):
|
||||
lists = re.findall(r'\(((?:[0-9a-f]{8}(?:\s*(?:,|to)\s*)?)+)\)', comment)
|
||||
lead = re.match(r'\s*([0-9a-f]{8})\b', comment)
|
||||
for item in lists + ([lead[1]] if lead else []):
|
||||
for low, high in re.findall(r'([0-9a-f]{8})(?:\s*to\s*([0-9a-f]{8}))?', item):
|
||||
high = high or low
|
||||
found |= {a for a in addresses if int(low, 16) <= a <= int(high, 16)} | {int(low, 16)}
|
||||
return found
|
||||
curated = curated_load()
|
||||
for cls in [c for c in done if not LIBRARY.match(c)]:
|
||||
parts, line = ['#include "classes.h"\n'], 2
|
||||
for addr, (_, method, ret, cc, params) in methods.get(cls, []):
|
||||
@@ -563,7 +568,7 @@ def stub_define(owner, decl, addr): # a declaration as a definition that stops
|
||||
incomplete = {t for t in forward if t not in done} | {c for c in curatedClasses if '::' in c}
|
||||
srcText = ''.join(open(os.path.join(root, n), errors='replace').read() for root, _, names_ in os.walk(srcDir) for n in names_ if n.endswith('.cpp'))
|
||||
def stub_wanted(owner, decl, addr, isSlot=False): # a vtable slot of a generated class keeps its stub unless src/ defines that very method
|
||||
if owner in curatedClasses: return False
|
||||
if owner in curatedClasses or (owner or '').rpartition('::')[0] in curatedClasses: return False
|
||||
if addr not in curated: return True
|
||||
return isSlot and f'{owner.rpartition("::")[2]}::{re.search(r"(~?\w+)\(", decl).group(1)}(' not in srcText
|
||||
stubText = ''.join(stub_define(o, d, a) for o, d, a, *slot in stubs if stub_wanted(o, d, a, *slot))
|
||||
|
||||
Reference in new issue
Block a user