Skip to content

Commit

Permalink
Let non RTTI structs have their own headers
Browse files Browse the repository at this point in the history
  • Loading branch information
bwrsandman committed Sep 17, 2024
1 parent 7b770cc commit 3ee13e3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
55 changes: 31 additions & 24 deletions scripts/headers/bw1_decomp_gen/generate_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from functions import FuncPtr, DefinedFunctionPrototype
from vftable import Vftable
from utils import partition, extract_type_name
from vanilla_filepaths import map_projects_to_object_files
from vanilla_filepaths import map_projects_to_object_files, get_object_file_base_names


def find_methods(function_db: list[dict]) -> tuple[dict[str, DefinedFunctionPrototype], dict[str, DefinedFunctionPrototype], set[DefinedFunctionPrototype]]:
Expand Down Expand Up @@ -59,12 +59,14 @@ def find_methods(function_db: list[dict]) -> tuple[dict[str, DefinedFunctionProt

class_method_look_up, class_static_method_look_up, remainder_functions = find_methods(db['functions'])

object_file_base_names = get_object_file_base_names()

# Do some selecting
(
vftables,
bases,
vftable_function_prototypes,
rtti_classes,
header_structs,
rtti_helper_unions,
enums,
list_and_nodes,
Expand All @@ -73,7 +75,7 @@ def find_methods(function_db: list[dict]) -> tuple[dict[str, DefinedFunctionProt
lambda x: type(x) is Struct and (x.name.endswith('Vftable') or x.name.startswith('vt_')),
lambda x: type(x) is Union and x.name.endswith('Base'),
lambda x: type(x) is FuncPtr and ('Vftable__' in x.name or x.name.startswith('vt_')),
lambda x: type(x) is Struct and x.members and x.members[0].name in ["vftable", "super", "base"],
lambda x: type(x) is Struct and ((x.members and x.members[0].name in ["vftable", "super", "base"]) or x.name in object_file_base_names),
lambda x: type(x) is Union and x.name.endswith('Base'),
lambda x: type(x) is Enum,
lambda x: type(x) is Struct and x.name.startswith("LHLinkedList") or x.name.startswith("LHLinkedNode") or x.name.endswith("List") or x.name.endswith("ListNode"),
Expand All @@ -95,37 +97,42 @@ def find_methods(function_db: list[dict]) -> tuple[dict[str, DefinedFunctionProt
for t in bases:
helper_base_map[t.name.removesuffix('Base')] = t


def get_path(name):
stem = name
# For things like GBaseInfo
if name[0] == 'G' and name[1].isupper():
stem = name[1:]
for project, object_files in projects_and_files.items():
if stem +".obj" in object_files:
break
else:
raise RuntimeError(f"Need to add guessed path for {name} in vanilla_filepaths.py")
return Path(project) / f"{stem}.h"

local_header_import_map: dict[str, str] = {}
header_map: dict[Path, Header] = {}
for t in rtti_classes:
for t in header_structs:
try:
vftable = vftable_map.get(t.name)
name = t.name
# For things like GBaseInfo
if t.name[0] == 'G' and t.name[1].isupper():
name = t.name[1:]
for project, object_files in projects_and_files.items():
if name +".obj" in object_files:
break
else:
raise RuntimeError(f"Need to add guessed path for {t.name} in vanilla_filepaths.py")
path = Path(project) / f"{name}.h"
path = get_path(t.name)
includes: list[Header.Include] = []
virtual_method_names = [i.name for i in vftable.members] if vftable else []

header = header_map.get(path)
structs: list[Struct] = header.structs if header is not None else []
if vftable:
structs.append(vftable)
if t.name in helper_base_map:
structs.append(helper_base_map[t.name])
structs.append(RTTIClass(t, vftable_address_look_up, virtual_method_names, class_method_look_up, class_static_method_look_up))

if t.members and t.members[0].name in ["vftable", "super", "base"]:
vftable = vftable_map.get(t.name)
virtual_method_names = [i.name for i in vftable.members] if vftable else []
if vftable:
structs.append(vftable)
if t.name in helper_base_map:
structs.append(helper_base_map[t.name])
new_struct = RTTIClass(t, vftable_address_look_up, virtual_method_names, class_method_look_up, class_static_method_look_up)
else:
new_struct = t
structs.append(new_struct)
for s in structs:
local_header_import_map[s.decorated_name] = path
header = Header(path, includes, structs, local_header_import_map)
header_map[path] = header

except RuntimeError as e:
print(e, file=sys.stderr)

Expand Down
6 changes: 5 additions & 1 deletion scripts/headers/bw1_decomp_gen/vanilla_filepaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@
BWPath(r"C:\dev\Libs\LIONHEAD\LHMultiplayer\VER4.0\LHSocket.h"),
BWPath(r"C:\dev\Libs\LIONHEAD\LHMultiplayer\VER4.0\LHSocketTCP.h"),

BWPath(r"C:\Dev\Libs\lionhead\lhlib\VER5.0\Name.h"),

BWPath(r"C:\DEV\LIBS\LHALL\RELEASED\HEADERS\RPFollow.h"),
BWPath(r"C:\DEV\LIBS\LHALL\RELEASED\HEADERS\Heap.h"),

Expand Down Expand Up @@ -700,7 +702,6 @@ def get_project_paths() -> set[BWPath]:
return set(debug_release_stripped)



def map_projects_to_object_files() -> dict[BWPath, set[BWPath]]:
projects = defaultdict(set)
project_paths = get_project_paths()
Expand All @@ -710,3 +711,6 @@ def map_projects_to_object_files() -> dict[BWPath, set[BWPath]]:
if filtered_path in project_paths:
projects[filtered_path].add(object_file)
return dict(projects)

def get_object_file_base_names() -> set[str]:
return {i.stem for i in dev_filepaths}

0 comments on commit 3ee13e3

Please sign in to comment.