Skip to content

Commit d12ffb2

Browse files
authored
Introduce Struct type (#1152)
* ObjectExplorer: Add `element_type_name` when exporting il2cpp_dump if it is an array For TDB >= 69 * RSZ: introduce `Struct` type when it is array of `Struct` Make `original_type` point to its element type rather than its own type for array-like object
1 parent defa629 commit d12ffb2

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

reversing/rsz/non-native-dumper.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def als(align, size):
4848
"GameObjectRef": als(8, 16),
4949
"Color": als(4, 4),
5050
"DateTime": als(8, 8),
51+
# Struct could have variable size and alignment depends on its element. So we set to (1, 1).
52+
"Struct": als(1, 1),
5153
# Enum could have variable size and alignment, so we fallback to its base type and never use it.
5254

5355
"Uint2": als(4, 8),
@@ -387,7 +389,9 @@ def generate_field_entries(il2cpp_dump, natives, key, il2cpp_entry, use_typedefs
387389
code = rsz_entry["code"]
388390
type = rsz_entry["type"]
389391

390-
if code == "Struct" and type in il2cpp_dump:
392+
if code == "Struct" and type in il2cpp_dump and rsz_entry.get("array", 0) != 1:
393+
# keep struct type data unpacked for backwards compatibility if it is not an array.
394+
391395
nested_entry, nested_str, i, struct_i = generate_field_entries(il2cpp_dump, natives, type, il2cpp_dump[type], use_typedefs, "STRUCT_" + name + "_", i, struct_i)
392396

393397
if len(nested_entry) > 0:
@@ -405,6 +409,20 @@ def generate_field_entries(il2cpp_dump, natives, key, il2cpp_entry, use_typedefs
405409
code = code_typedefs[code]
406410
else:
407411
code = "RSZ" + code
412+
413+
if rsz_entry["array"] == 1:
414+
array_type = il2cpp_dump[type]
415+
if array_type.get("element_type_name", None) is not None:
416+
type = array_type["element_type_name"]
417+
elif array_type.get("is_generic_type", False):
418+
array_element_types = [item["type"] for item in array_type["generic_arg_types"]]
419+
if len(array_element_types) == 1:
420+
type = array_element_types[0]
421+
else:
422+
print(f"Array type {type} has multiple element types: {array_element_types}")
423+
else:
424+
print(f"Array type {type} has no element type")
425+
408426

409427
'''
410428
if rsz_entry["array"] == True:

src/mods/tools/ObjectExplorer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,16 @@ void ObjectExplorer::generate_sdk() {
10831083
type_entry["is_generic_type"] = t.is_generic_type();
10841084
type_entry["is_generic_type_definition"] = t.is_generic_type_definition();
10851085

1086+
#if TDB_VER >= 71
1087+
if (tdef->element_typeid_TBD != 0) {
1088+
type_entry["element_type_name"] = init_type(il2cpp_dump, tdb, tdef->element_typeid_TBD)->full_name;
1089+
}
1090+
#elif TDB_VER >= 69
1091+
if (tdef->element_typeid != 0) {
1092+
type_entry["element_type_name"] = init_type(il2cpp_dump, tdb, tdef->element_typeid)->full_name;
1093+
}
1094+
#endif
1095+
10861096
if (auto gtd = t.get_generic_type_definition(); gtd != nullptr) {
10871097
type_entry["generic_type_definition"] = gtd->get_full_name();
10881098
}

0 commit comments

Comments
 (0)