Generated stubs: the build links into a Linux executable that runs as far as src/ goes
source_tree.py writes generated-src/stubs.cpp: every function, vtable slot and import src/ has not taken over, defined as a stub that prints 'Reached <name> <address>, not reconstructed yet' and stops. CMake builds src/*.cpp + stubs into the isaac executable, so each run names the next function to curate. src/main.cpp hands over to the game's IsaacMain. Classes with only parameterised constructors get a defaulted one, so stub constructors of their holders compile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9d4d4f5c64
commit
2b108ca729
5 files changed
+25103
-2
No files matched your search
+3
-1
@@ -37,8 +37,10 @@ target_compile_definitions(simdjson PUBLIC SIMDJSON_EXCEPTIONS=0)
|
||||
|
||||
# The curated game: src/*.cpp, written on top of the declarations generated-src/classes.h holds for every class.
|
||||
# generated-src/'s own bodies stay out until they compile (scripts/source_tree.py --check reports how many do).
|
||||
# generated-src/stubs.cpp defines everything not curated yet as a stub that stops the game where it is reached, so the
|
||||
# executable always links and runs exactly as far as src/ goes.
|
||||
file(GLOB SOURCES CONFIGURE_DEPENDS src/*.cpp)
|
||||
add_library(isaac STATIC ${SOURCES})
|
||||
add_executable(isaac ${SOURCES} generated-src/stubs.cpp)
|
||||
target_include_directories(isaac PRIVATE src)
|
||||
target_include_directories(isaac SYSTEM PRIVATE generated-src)
|
||||
target_link_libraries(isaac PRIVATE SDL3::SDL3-static lua simdjson)
|
||||
@@ -762,6 +762,7 @@ struct Vector {
|
||||
uint8_t operator_eq(Vector *other); // 00a10600
|
||||
uint8_t operator_ne(Vector *other); // 00a10630
|
||||
Vector * __unm(Vector *outResult); // 00a10660
|
||||
Vector() = default;
|
||||
|
||||
float x;
|
||||
float y;
|
||||
@@ -803,6 +804,7 @@ struct AnimationState {
|
||||
int NextEventTrigger(uint8_t *eventName); // 0040af10
|
||||
AnimationState * copy_assign(AnimationState *other); // 0040bbf0
|
||||
int GetAnimationLength(); // 00440e30
|
||||
AnimationState() = default;
|
||||
|
||||
ANM2* _animation;
|
||||
AnimationData* _animData;
|
||||
@@ -865,6 +867,7 @@ struct ANM2 {
|
||||
static void LoadDeliriumForm(ANM2 *sprite, int type, int variant, uint8_t isReloadAnm2); // 004a5d10
|
||||
static void copy_animation_to(ANM2 *source, ANM2 *dest); // 0078b3b0
|
||||
void update_appear_then_idle(); // 00837210
|
||||
ANM2() = default;
|
||||
|
||||
std_string _filename;
|
||||
std_string _animDefaultName;
|
||||
@@ -2300,6 +2303,7 @@ LAYOUT32(sizeof(ColorParams) == 0x3a);
|
||||
|
||||
struct ColorQuad {
|
||||
ColorQuad(KColor *color); // 00a10c00
|
||||
ColorQuad() = default;
|
||||
};
|
||||
|
||||
|
||||
@@ -5436,6 +5440,7 @@ struct FormattedText {
|
||||
static void split_lines(uint8_t *text, void *lines); // 00a55ef0
|
||||
static void split_lines_utf16(short *text, void *outLines); // 00a56060
|
||||
static void parse(uint8_t *text, uint32_t maxWidth, void *outLines, void *measureFn, void *userData); // 00a56350
|
||||
FormattedText() = default;
|
||||
};
|
||||
|
||||
|
||||
@@ -5967,6 +5972,7 @@ struct KColor {
|
||||
KColor * set_from_argb_signed(uint32_t argb); // 00a0f610
|
||||
KColor(float red, float green, float blue, float alpha); // 00a0f690
|
||||
static void hsl_to_rgb(KColor *out, KColor *in); // 00a0fb60
|
||||
KColor() = default;
|
||||
|
||||
float _red;
|
||||
float _green;
|
||||
@@ -7464,6 +7470,7 @@ struct BufferedStream : KAGE::Filesys::BufferedStreamBase {
|
||||
uint8_t rebuffer(); // 00a57fc0
|
||||
BufferedStream(int bufferSize); // 00a58040
|
||||
static void seek_base2(int param_1, int param_2); // 00a58270
|
||||
BufferedStream() = default;
|
||||
|
||||
uint8_t _pad_0x28[0x4];
|
||||
};
|
||||
@@ -8153,6 +8160,7 @@ namespace KAGE::Network::Multiplayer {
|
||||
struct ConstLobby {
|
||||
virtual ~ConstLobby(); // 00a28230 slot 0 ::FUN_00a28230
|
||||
ConstLobby(void *lobbyPtr, void *lobbyCtrl); // 00a28360
|
||||
ConstLobby() = default;
|
||||
|
||||
uint8_t _pad_0x4[0x8];
|
||||
};
|
||||
@@ -8164,6 +8172,7 @@ struct Lobby : KAGE::Network::Multiplayer::ConstLobby {
|
||||
void * get_member(void *outProfile, uint32_t index); // 00a284d0
|
||||
void get_members(void *outMembers, uint8_t isIncludeLocalUser); // 00a285f0
|
||||
Lobby(void *other); // 00a72740
|
||||
Lobby() = default;
|
||||
};
|
||||
}
|
||||
LAYOUT32(sizeof(KAGE::Network::Multiplayer::Lobby) == 0xc);
|
||||
@@ -8365,6 +8374,7 @@ struct SmartPointer {
|
||||
void * operator_assign(void *other); // 0040c3b0
|
||||
SmartPointer(void *image); // 0040c4a0
|
||||
void reset(void *image); // 0040c7f0
|
||||
SmartPointer() = default;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9218,6 +9228,7 @@ struct LevelGenerator {
|
||||
struct LevelGenerator_Room {
|
||||
LevelGenerator_Room * constructor(uint32_t column, uint32_t line, uint32_t shape); // 007381b0
|
||||
LevelGenerator_Room(void *other); // 007507d0
|
||||
LevelGenerator_Room() = default;
|
||||
};
|
||||
|
||||
|
||||
@@ -9262,6 +9273,7 @@ LAYOUT32(offsetof(LobbySettings, _password) == 0x30);
|
||||
|
||||
struct LootList {
|
||||
LootList(void *other); // 006c20e0
|
||||
LootList() = default;
|
||||
};
|
||||
|
||||
|
||||
@@ -10549,6 +10561,7 @@ struct MessagePopup {
|
||||
static void add_blank_footer(uint8_t *headerText, uint8_t *messageText, void *popup); // 009c3b70
|
||||
static void add_ok_button(uint8_t *text, void *popupDesc); // 009c3c30
|
||||
static void add_yes_no_buttons(uint8_t *message, void *popup); // 009c3d10
|
||||
MessagePopup() = default;
|
||||
};
|
||||
|
||||
|
||||
@@ -10647,6 +10660,7 @@ struct NetInputDevice : KAGE::Input::InputDeviceBase {
|
||||
static uint8_t is_input_ready(uint8_t param_1, int *param_2); // 00901cb0
|
||||
uint8_t ProcessInputMessage(void *message, void *messageRefCount); // 00902010
|
||||
static void broadcast_frame_input(uint32_t param_1); // 00902950
|
||||
NetInputDevice() = default;
|
||||
};
|
||||
// NetInputDevice: deleting destructor says 0x18, below its layout 0x370 (ICF-shared destructor?)
|
||||
|
||||
@@ -10834,6 +10848,7 @@ LAYOUT32(offsetof(PathFinder, _evadeMovementCountdown) == 0x73c);
|
||||
|
||||
struct PathNode {
|
||||
PathNode(void *other); // 007e48b0
|
||||
PathNode() = default;
|
||||
};
|
||||
|
||||
|
||||
@@ -11574,6 +11589,7 @@ struct Shader {
|
||||
|
||||
struct Shape {
|
||||
Shape(void *other); // 0042f850
|
||||
Shape() = default;
|
||||
};
|
||||
|
||||
|
||||
@@ -11618,6 +11634,7 @@ struct SoundManager {
|
||||
|
||||
struct SourceQuad : DestinationQuad {
|
||||
SourceQuad(void *source); // 00a11210
|
||||
SourceQuad() = default;
|
||||
|
||||
int _coordinateSpace;
|
||||
};
|
||||
@@ -11794,6 +11811,7 @@ LAYOUT32(offsetof(TearParams, _tearHeight) == 0x50);
|
||||
|
||||
struct TemporaryEffect {
|
||||
TemporaryEffect(ItemConfig_Item *item); // 00435f80
|
||||
TemporaryEffect() = default;
|
||||
|
||||
ItemConfig_Item* _item;
|
||||
int _count;
|
||||
@@ -13009,6 +13027,7 @@ struct string {
|
||||
void push_back(uint8_t c); // 0059c4c0
|
||||
static int find_last_of(uint8_t *data, uint32_t size, uint32_t position, uint8_t *chars, uint32_t count); // 006523e0
|
||||
static void append_reversed(uint8_t *param_1, uint8_t *param_2); // 007de660
|
||||
string() = default;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13436,6 +13455,7 @@ struct _Exception {
|
||||
virtual char * FUN_00a8a070(char *param_1); // 00a8a070 slot 2 ::FUN_00a8a070
|
||||
_Exception(uint32_t param_1, uint32_t param_2, uint32_t param_3); // 00aab3e0
|
||||
static void _setInternalMessage(uint8_t *param_1, uint8_t *param_2, int param_3); // 00aab470
|
||||
_Exception() = default;
|
||||
|
||||
uint8_t _pad_0x4[0x18];
|
||||
};
|
||||
|
||||
+25046
File diff suppressed because it is too large.
Load diff
+27
-1
@@ -5,6 +5,8 @@
|
||||
# <out>/<class>.cpp that class's method bodies as decompiled; Ghidra's Class::method(obj, args) calls become
|
||||
# ((Class *)(obj))->Class::method(args) (a direct call, as in the binary)
|
||||
# A function src/ took over (a curated file with its address in a comment, // 0040ed50) is declared but not emitted.
|
||||
# <out>/stubs.cpp every function, vtable slot and import src/ has not taken over, defined as a stub that stops the
|
||||
# game where it is reached: src/ + stubs.cpp link into a game that runs as far as curation goes
|
||||
# Targets 64-bit Linux. The original 32-bit layout is kept as LAYOUT32 asserts, checked with -m32.
|
||||
# --check compiles every .cpp for x86_64, reports how many methods compile and how many raw offset accesses remain
|
||||
# (each one is a 64-bit hazard until it becomes a named field).
|
||||
@@ -357,7 +359,8 @@ def width_of(typ, depth=0): # bytes of a field type: primitives, laid-out clas
|
||||
return None
|
||||
|
||||
|
||||
done, order, used, canon, defined = {}, [], set(), {}, {} # defined: address -> the declaration its body is defined with
|
||||
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
|
||||
parent = base.get(cls) if base.get(cls) in names else None
|
||||
@@ -412,6 +415,7 @@ def class_emit(cls, stack=()):
|
||||
if sig and sig[0] == cls and not decl.startswith('virtual ~') and decl.endswith(f'({", ".join(sig[4])});' if 'override' not in decl else f'({", ".join(sig[4])}) override;'):
|
||||
defined[addr] = decl
|
||||
decls.append(f' {decl} // {addr:08x} slot {i}' + (f' {sig[0]}::{sig[1]}' if sig and sig[0] != cls else ''))
|
||||
stubs.append((cls, decl, addr))
|
||||
slotAddrs = set(slots)
|
||||
for addr, (_, method, ret, cc, params) in methods.get(cls, []):
|
||||
key = (method, ', '.join(params))
|
||||
@@ -420,7 +424,10 @@ def class_emit(cls, stack=()):
|
||||
if not decl: continue
|
||||
seen.add(key); used.update(sig_types(ret, params)); defined[addr] = decl.strip()
|
||||
decls.append(decl + f' // {addr:08x}')
|
||||
stubs.append((cls, decl, addr))
|
||||
if cls in POINTER_LIKE: lines = [f' GHIDRA_POINTER_LIKE({shortName})']
|
||||
constructors = [d for d in decls if re.match(rf'\s+{shortName}\(', d)]
|
||||
if constructors and not any(re.match(rf'\s+{shortName}\(\)', d) for d in constructors): decls.append(f' {shortName}() = default;') # members still need one
|
||||
nested = [c.rpartition('::')[2] for c in names if c.rpartition('::')[0] == cls]
|
||||
body = '\n'.join([f' struct {n};' for n in sorted(nested)] + decls + ([''] if decls and lines else []) + lines)
|
||||
head = f'struct {cls if isNested else shortName}' + (f' : {parent}' if parent else '')
|
||||
@@ -443,6 +450,7 @@ for addr, (cls, method, ret, cc, params, thisParam, _) in sorted(funcs.items()):
|
||||
freeSeen.add((cls, method))
|
||||
if thisParam: params = [re.sub(r'\bthis$', 'self', thisParam)] + params
|
||||
free[cls].append(f'{ret} {method}({", ".join(params)}); // {addr:08x}')
|
||||
stubs.append((cls, f'{ret} {method}({", ".join(params)});', addr))
|
||||
used.update(sig_types(ret, params))
|
||||
# Ghidra enums and typedefs the code names (each enum constant once: they share one scope)
|
||||
aliases, constants = [], set()
|
||||
@@ -479,12 +487,14 @@ for line in open(dumpDir + '/data.tsv', errors='replace') if os.path.exists(dump
|
||||
if count > 1 and not width_of(typ): typ, count = 'undefined', int(length) # an array of a type with no layout: bytes
|
||||
used.update(type_names(typ))
|
||||
globalDecls.append(f'extern {typ} {name}' + (f'[{count}]' if count > 1 else '') + ';')
|
||||
if typ.endswith('*') or typ in PRIMITIVE or typ in PRELUDE_TYPES: dataStubs.append(f'{typ} {name}' + (f'[{count}]' if count > 1 else '') + '{};')
|
||||
for line in open(dumpDir + '/externals.tsv', errors='replace') if os.path.exists(dumpDir + '/externals.tsv') else []:
|
||||
cols = line.rstrip('\n').split('\t')
|
||||
match = not line.startswith('#') and len(cols) == 3 and CALLING.match(cols[2])
|
||||
if not match or not IDENT.match(match['name']) or match['name'] in taken or re.search(r'[<(]', match['ret'] + match['params']): continue
|
||||
taken.add(match['name']); used.update(sig_types(match['ret'], [p for p in match['params'].split(',') if p.strip()]))
|
||||
globalDecls.append(f'{match["ret"]} {match["name"]}({re.sub(r"\bthis\b", "self", match["params"])}); // {cols[0]}')
|
||||
stubs.append(('', f'{match["ret"]} {match["name"]}({re.sub(r"\bthis\b", "self", match["params"])});', None))
|
||||
labels = sorted({m for f in funcs.values() for m in re.findall(r'\b(LAB_[0-9a-f]+|register0x[0-9a-f]+|_?DAT_[0-9a-f]+|PTR_\w+_[0-9a-f]{8})\b', f[6])} - taken) # auto labels data.tsv lacks
|
||||
globalDecls += [f'extern {"code" if n.startswith("LAB_") else "undefined4"} {n};' for n in labels]
|
||||
forward = sorted(t for t in used | {c for c in done if '::' not in c} if '::' not in t and t not in PRELUDE_TYPES and t not in enums and t not in typedefs and t not in STD_NAMES)
|
||||
@@ -520,6 +530,22 @@ for cls in [c for c in done if not LIBRARY.match(c)]:
|
||||
files[cls] = path
|
||||
os.makedirs(os.path.dirname(f'{outDir}/{path}') or outDir, exist_ok=True)
|
||||
open(f'{outDir}/{path}', 'w').write(generated_rename(''.join(parts)))
|
||||
def stub_define(owner, decl, addr): # a declaration as a definition that stops the game where it is reached
|
||||
text = re.sub(r'\s*override(?=;)', '', re.sub(r'^\s*(virtual|static) ', '', decl.strip())).rstrip(';')
|
||||
name = re.search(r'(~?\w+)\(', text).group(1)
|
||||
for part in re.findall(r'[^,()]+', text[:text.index('(')].rsplit(None, 1)[0] if ' ' in text[:text.index('(')] else '') + re.findall(r'[^,()]+', text[text.index('(') + 1:]):
|
||||
base = part.strip().rsplit(None, 1)[0] if ' ' in part.strip() and '*' not in part else part.strip()
|
||||
if '*' not in part and base in incomplete: return '' # a by-value type with no layout cannot be defined yet
|
||||
label = (f'{owner}::' if owner else '') + name + (f' {addr:08x}' if addr else '')
|
||||
return text.replace(name + '(', (f'{owner}::' if owner else '') + name + '(', 1) + f' {{ generated_stub("{label}"); }}\n'
|
||||
incomplete = {t for t in forward if t not in done}
|
||||
stubText = ''.join(stub_define(o, d, a) for o, d, a in stubs if a not in curated)
|
||||
with open(outDir + '/stubs.cpp', 'w') as o:
|
||||
o.write(generated_rename('// Generated by scripts/source_tree.py: every function src/ has not taken over yet, as a stub that stops the game\n'
|
||||
'// where it is reached, so a build runs exactly as far as the curated code goes.\n#include "classes.h"\n\n'
|
||||
'[[noreturn]] static void generated_stub(const char* name)\n{\n fprintf(stderr, "Reached %s, not reconstructed yet\\n", name);\n exit(1);\n}\n\n'
|
||||
+ '\n'.join(dataStubs) + '\n\n' + stubText))
|
||||
|
||||
print(f'source_tree: {len(curated)} functions taken over by src/, {len(done)} classes, {sum(1 for c in done if size.get(c))} sized, {sum(len(v) for v in methods.values())} methods,'
|
||||
f' {sum(len(s) for s in spans.values())} bodies in {len(files)} .cpp files')
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "classes.h"
|
||||
|
||||
// The Linux entry point hands over to the game's own main.
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
return IsaacMain(argc, (uint8_t**)argv);
|
||||
}
|
||||
Reference in new issue
Block a user