aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 7f4c6e2167034a597faa60a6e86661e9b0d1eca4
parent 41111979b149ea7c755fefb8ec9c0d3ed06b8067
Author: anon <anon@example.com>
Date:   Wed, 21 Oct 2026 15:44:07 +0000

Fix client freeze when interacting with NPCs

Diffstat:
Mclient/runtime/guest_rtti.c | 19+++++++++++++++++++
Mclient/tests/rtti.c | 42+++++++++++++++++++++++++++++++++++++++++-
2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/client/runtime/guest_rtti.c b/client/runtime/guest_rtti.c @@ -25,6 +25,24 @@ static void type_info_equal(void) g_esp += 8; /* type_info::operator== is thiscall. */ } +static void runtime_typeid(void) +{ + uint32_t input = MEM32(g_esp + 4); + if (!input) { + fprintf(stderr, "Guest RTTI bad_typeid exception is not implemented\n"); + abort(); + } + + /* Every polymorphic subobject's locator identifies its complete object type. */ + const struct rtti_locator *locator = (const void *)ADDR(MEM32(MEM32(input) - 4)); + if (locator->signature) { + fprintf(stderr, "Unsupported guest RTTI metadata version\n"); + abort(); + } + g_eax = locator->type; + g_esp += 4; /* __RTtypeid is cdecl. */ +} + static uint32_t base_address(uint32_t object, const struct rtti_base *descriptor) { uint32_t result = object + descriptor->offset; @@ -96,6 +114,7 @@ static void dynamic_cast(void) recomp_func_t guest_rtti_lookup(const char *name) { if (!strcmp(name, "__RTDynamicCast")) return dynamic_cast; + if (!strcmp(name, "__RTtypeid")) return runtime_typeid; if (!strcmp(name, "??8type_info@@QBEHABV0@@Z")) return type_info_equal; return NULL; } diff --git a/client/tests/rtti.c b/client/tests/rtti.c @@ -8,6 +8,7 @@ #define MEM32(a) (*(uint32_t *)(uintptr_t)(a)) #define ADDR(a) ((void *)(uintptr_t)(a)) static void *(__cdecl *native_cast)(void *, int, void *, void *, int); +static void *(__cdecl *native_typeid)(void *); #else #include "guest_rtti.h" #endif @@ -186,6 +187,42 @@ static void type_info_equality_uses_names(void) } } +static void typeid_returns_the_complete_object_type(void) +{ + const unsigned offsets[] = {0, 24, 40}; + for (unsigned i = 0; i < 3; ++i) { + layout(0, 0, offsets[i]); + MEM32(0x50005010) = 0; + if (i == 2) { + MEM32(0x50005004) = 32; + MEM32(0x50005008) = 4; + MEM32(0x50007024) = 8; + } + uint32_t input = 0x50007000 + offsets[i]; +#ifndef _WIN32 + g_esp = 0x5000ff00; + MEM32(g_esp + 4) = input; + g_ecx = 567; g_edx = 678; + g_ebx = 123; g_esi = 234; g_edi = 345; g_ebp = 456; + recomp_func_t function = guest_rtti_lookup("__RTtypeid"); + assert(function); +#endif + +#ifdef _WIN32 + uint32_t result = (uintptr_t)native_typeid((void *)(uintptr_t)input); +#else + function(); + uint32_t result = g_eax; +#endif + + assert(result == 0x50001000); +#ifndef _WIN32 + assert(g_esp == 0x5000ff04 && MEM32(g_esp) == input); + assert(g_ebx == 123 && g_esi == 234 && g_edi == 345 && g_ebp == 456); +#endif + } +} + static void unrelated_private_base_allows_public_vehicle_casts(void) { type(9, ".?AVNPCVehicle_t@@"); @@ -241,6 +278,8 @@ int main(void) assert(VirtualAlloc((void *)0x50000000, 0x30000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) == (void *)0x50000000); native_cast = (void *)GetProcAddress(LoadLibraryA("msvcrt.dll"), "__RTDynamicCast"); assert(native_cast); + native_typeid = (void *)GetProcAddress(LoadLibraryA("msvcrt.dll"), "__RTtypeid"); + assert(native_typeid); #else assert(guest_map("RTTI fixture", 0x50000000, 0x30000)); #endif @@ -257,8 +296,9 @@ int main(void) vfptr_and_construction_displacements_adjust_the_complete_object(); shared_virtual_source_matches_both_target_branches(); type_info_equality_uses_names(); + typeid_returns_the_complete_object_type(); unrelated_private_base_allows_public_vehicle_casts(); metadata_records_span_guest_pages(); - puts("RTTI: public multiple/virtual inheritance, unrelated private bases, repeated bases, cross-DLL names, type_info equality, null/failure and ABI passed"); + puts("RTTI: public multiple/virtual inheritance, unrelated private bases, repeated bases, cross-DLL names, type_info equality, typeid, null/failure and ABI passed"); return 0; }