Files
2026-07-09 07:40:42 +02:00

45 lines
2.3 KiB
C++

// engine_structs.h - recovered engine data-structure layouts
//
// Structs are recovered from field-access offsets observed in the disassembly (radare2). Field names
// are mechanical (field_<offset>); only the offsets/sizes are asserted - semantic meaning is inferred
// separately and only when there is evidence. Do NOT assume purpose from these names.
#pragma once
#include <cstdint>
namespace titan {
// struct_unknown_1 - IDENTIFIED (was "unknown state struct"): this is the engine's custom
// **small-string-optimized String** class. The sub_1fe*/sub_1f7*/sub_200*
// cluster are its methods. Evidence:
// * sub_1fe43c zero-inits it -> an empty inline string (null at the inline buffer).
// * sub_1f7160 tests `field_4 + 1 < 9` (i.e. length < 8) -> the **SSO discriminant**.
// * fcn_001f712c (data accessor) returns `isSSO ? &field_8 : *(char**)&field_8`.
// * fcn_00200064 uses `field_4` as the **length** in a memcmp-based match.
// So: field_4 = length; field_8 = the inline SSO buffer OR (when length>=8) a heap `char*`.
//
// ARCH-INDEPENDENT model (function-matching, not byte-matching). The original 32-bit binary unions
// the heap pointer with the inline buffer at +0x08; on arm64 a pointer is 8 bytes, so we model that
// union with correct widths (a truncated int32 pointer would crash on 64-bit). field_0/field_4 keep
// their offsets; the SSO union replaces the +0x08.. bytes. The inline buffer is sized generously
// (holds the original's short strings; only `length < 8` ever uses it - see titan_string_is_sso).
struct struct_unknown_1 {
int32_t field_0; // +0x00 capacity/flags (role TBD; zeroed at init)
int32_t field_4; // +0x04 **length** (chars)
union {
char* heap; // heap buffer when length >= 8
char sso[16]; // inline characters when length < 8
};
};
// String helpers (functional model). isSSO/data() mirror sub_1f7160 / fcn_001f712c exactly.
inline bool titan_string_is_sso(const struct_unknown_1* s) { return s->field_4 < 8; }
inline char* titan_string_data(struct_unknown_1* s) {
return titan_string_is_sso(s) ? s->sso : s->heap;
}
inline const char* titan_string_data(const struct_unknown_1* s) {
return titan_string_is_sso(s) ? s->sso : s->heap;
}
inline int titan_string_length(const struct_unknown_1* s) { return s->field_4; }
} // namespace titan