From 3597c3513a1c7efec8b56e7220e01ad3ac49ba64 Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 17:57:11 +0200 Subject: [PATCH 01/11] Handle guarded heap-backed car IDs in standalone snapshots --- .../Game/GameSnapshotReader.cs | 78 ++++++++++++++----- 1 file changed, 60 insertions(+), 18 deletions(-) diff --git a/src/AzimuthRPC.Core/Game/GameSnapshotReader.cs b/src/AzimuthRPC.Core/Game/GameSnapshotReader.cs index addfdb0..e755944 100644 --- a/src/AzimuthRPC.Core/Game/GameSnapshotReader.cs +++ b/src/AzimuthRPC.Core/Game/GameSnapshotReader.cs @@ -29,7 +29,7 @@ public GameSnapshot Capture(ulong gameBase, bool supportedBuild) var raw = frame.Read(audio, 0x2C0); if (raw is null) return GameSnapshot.Unavailable("Audio/vehicle snapshot read failed"); var ui = UiModeReader.ReadSnapshot(gameBase, true, frame.Read); - string? car = ReadCar(raw.AsSpan(0x278, 64), out string carProbeStatus); + string? car = ReadCar(raw.AsSpan(0x278, 64), checked(audio + 0x278), frame, out string carProbeStatus); if (car != _lastCarId) { _lastCarId = car; _displayName = FriendlyCarName(car); } float mph = F32(raw, 0x90); float? speed = float.IsFinite(mph) && mph >= 0 && mph <= 400 ? mph : null; @@ -67,8 +67,51 @@ private static WorldPresence VehiclePresence(UiMode mode, string? car, VehicleSt float x = F32(data, offset), y = F32(data, offset + 4), z = F32(data, offset + 8); return float.IsFinite(x) && float.IsFinite(y) && float.IsFinite(z) && MathF.Abs(x) <= bound && MathF.Abs(y) <= bound && MathF.Abs(z) <= bound ? new Vector3(x, y, z) : null; } - private static string? ReadCar(ReadOnlySpan bytes, out string status) + private static string? ReadCar(ReadOnlySpan bytes, ulong fieldAddress, PointerSnapshot frame, out string status) { + // Candidate MSVC std::string (32-byte object): 16-byte buffer/pointer, + // followed by 64-bit size and capacity. Short IDs remain inline. + // This is a guarded fallback, not yet a live-validated FH2 layout. + ulong length = BinaryPrimitives.ReadUInt64LittleEndian(bytes[16..]); + ulong capacity = BinaryPrimitives.ReadUInt64LittleEndian(bytes[24..]); + if (length is >= 16 and <= 127 && capacity >= length && capacity <= 4096) + { + ulong pointer = BinaryPrimitives.ReadUInt64LittleEndian(bytes); + if (!MemoryRead.Pointer(pointer)) + { + status = "heap-invalid-pointer"; + return null; + } + + byte[]? first = frame.Read(pointer, (int)length + 1); + byte[]? second = frame.Read(pointer, (int)length + 1); + byte[]? currentField = frame.Read(fieldAddress, 32); + if (first is null || second is null) + { + status = "heap-unreadable"; + return null; + } + if (!first.AsSpan().SequenceEqual(second) || currentField is null || + !bytes[..32].SequenceEqual(currentField)) + { + status = "heap-changed"; + return null; + } + if (first[(int)length] != 0) + { + status = "heap-unterminated"; + return null; + } + if (!ValidCarId(first.AsSpan(0, (int)length))) + { + status = "heap-invalid-id"; + return null; + } + + status = "ok-heap"; + return Encoding.ASCII.GetString(first, 0, (int)length); + } + int end = bytes.IndexOf((byte)0); if (end < 0 || end > 63) { @@ -85,26 +128,25 @@ private static WorldPresence VehiclePresence(UiMode mode, string? car, VehicleSt status = "too-short"; return null; } - for (int i = 0; i < end; i++) - { - byte b = bytes[i]; - if (!((b >= 'A' && b <= 'Z') || - (b >= 'a' && b <= 'z') || - (b >= '0' && b <= '9') || b == '_')) - { - status = "invalid-character"; - return null; - } - } - - string value = Encoding.ASCII.GetString(bytes[..end]); - if (!value.Contains('_')) + if (!ValidCarId(bytes[..end])) { - status = "missing-underscore"; + status = "invalid-character"; return null; } + status = "ok"; - return value; + return Encoding.ASCII.GetString(bytes[..end]); + } + + private static bool ValidCarId(ReadOnlySpan bytes) + { + if (bytes.Length < 5 || !bytes.Contains((byte)'_')) return false; + foreach (byte b in bytes) + if (!((b >= 'A' && b <= 'Z') || + (b >= 'a' && b <= 'z') || + (b >= '0' && b <= '9') || b == '_')) + return false; + return true; } private static string? FriendlyCarName(string? raw) { From 32415bb8cbbc1cefc2213eb6e892d046b8bba686 Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 17:57:58 +0200 Subject: [PATCH 02/11] Decode heap-backed vehicle IDs safely in FH2ML DLL --- native/FH2ML.AzimuthRPC/AzimuthRpcMod.cpp | 95 +++++++++++++++++++---- 1 file changed, 78 insertions(+), 17 deletions(-) diff --git a/native/FH2ML.AzimuthRPC/AzimuthRpcMod.cpp b/native/FH2ML.AzimuthRPC/AzimuthRpcMod.cpp index d0865fb..56656b0 100644 --- a/native/FH2ML.AzimuthRPC/AzimuthRpcMod.cpp +++ b/native/FH2ML.AzimuthRPC/AzimuthRpcMod.cpp @@ -429,52 +429,113 @@ std::string AsciiBytes(const std::uint8_t* data, const std::size_t size) return result; } -bool ReadCarId(const std::uint8_t* raw, std::string& value, std::string& reason) +bool ReadCarId(const std::uint8_t* raw, const std::uintptr_t audio, + std::string& value, std::string& reason) { value.clear(); reason.clear(); + const std::uint8_t* field = raw + kCarIdOffset; + + // Candidate MSVC std::string with a heap-backed buffer for IDs longer + // than 15 bytes. Short IDs use the existing inline ASCII decoder. + // This guarded layout is not yet live-validated across mod combinations. + std::uint64_t pointer = 0, length = 0, capacity = 0; + std::memcpy(&pointer, field, sizeof(pointer)); + std::memcpy(&length, field + 16, sizeof(length)); + std::memcpy(&capacity, field + 24, sizeof(capacity)); + if (length >= 16 && length <= 127 && capacity >= length && capacity <= 4096) + { + if (!IsPointer(static_cast(pointer))) + { + reason = "heap-invalid-pointer"; + return false; + } - std::size_t length = 0; - while (length < kCarIdBytes && raw[kCarIdOffset + length] != 0) - ++length; + std::array first{}, second{}; + std::array fieldAfter{}; + const std::size_t count = static_cast(length) + 1; + if (!ReadBytes(static_cast(pointer), first.data(), count) || + !ReadBytes(static_cast(pointer), second.data(), count)) + { + reason = "heap-unreadable"; + return false; + } + if (!ReadBytes(audio + kCarIdOffset, fieldAfter.data(), fieldAfter.size()) || + std::memcmp(field, fieldAfter.data(), fieldAfter.size()) != 0 || + std::memcmp(first.data(), second.data(), count) != 0) + { + reason = "heap-changed"; + return false; + } + if (first[static_cast(length)] != 0) + { + reason = "heap-unterminated"; + return false; + } - if (length == 0) + bool underscore = false; + for (std::size_t i = 0; i < static_cast(length); ++i) + { + const unsigned char c = first[i]; + underscore |= c == '_'; + if (!((c >= 'A' && c <= 'Z') || + (c >= 'a' && c <= 'z') || + (c >= '0' && c <= '9') || + c == '_')) + { + reason = "heap-invalid-id"; + return false; + } + } + if (!underscore) + { + reason = "heap-invalid-id"; + return false; + } + + value.assign(reinterpret_cast(first.data()), + static_cast(length)); + reason = "ok-heap"; + return true; + } + + std::size_t inlineLength = 0; + while (inlineLength < kCarIdBytes && field[inlineLength] != 0) + ++inlineLength; + + if (inlineLength == 0) { reason = "empty"; return false; } - if (length < 5) + if (inlineLength < 5) { reason = "too-short"; return false; } - if (length >= kCarIdBytes) + if (inlineLength >= kCarIdBytes) { reason = "unterminated"; return false; } - for (std::size_t i = 0; i < length; ++i) + for (std::size_t i = 0; i < inlineLength; ++i) { - const unsigned char c = raw[kCarIdOffset + i]; + const unsigned char c = field[i]; if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_')) { char detail[64]{}; - std::snprintf( - detail, - sizeof(detail), - "invalid-char@%zu=0x%02X", - i, - static_cast(c)); + std::snprintf(detail, sizeof(detail), "invalid-char@%zu=0x%02X", + i, static_cast(c)); reason = detail; return false; } } - value.assign(reinterpret_cast(raw + kCarIdOffset), length); + value.assign(reinterpret_cast(field), inlineLength); if (value.find('_') == std::string::npos) { reason = "missing-underscore"; @@ -682,7 +743,7 @@ Snapshot CaptureSnapshot(const std::uintptr_t gameBase) std::string car; std::string carReason; - const bool carParsed = ReadCarId(raw.data(), car, carReason); + const bool carParsed = ReadCarId(raw.data(), audio, car, carReason); if (carParsed) { snapshot.carRaw = car; From 7fcf5980b1719c191b7939edb8e7b20f66b3b5e9 Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 17:58:44 +0200 Subject: [PATCH 03/11] Cover dynamic long and short car switching with synthetic tests --- tests/AzimuthRPC.Core.Tests/Program.cs | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tests/AzimuthRPC.Core.Tests/Program.cs b/tests/AzimuthRPC.Core.Tests/Program.cs index 06dc892..91e3d47 100644 --- a/tests/AzimuthRPC.Core.Tests/Program.cs +++ b/tests/AzimuthRPC.Core.Tests/Program.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Numerics; using System.Text.Json; +using System.Text; using AzimuthRPC; using AzimuthRPC.Tests; @@ -63,6 +64,72 @@ var s when s.StartsWith("worldmap_") => UiMode.WorldMap, Check(!reader.Capture(gameBase, true).Attached, "Changing root published a mixed snapshot"); }); } +Test("Car IDs survive heap string / inline changes and never reuse stale IDs", () => +{ + var memory = new FixtureMemory(); + var fixture = captures.First(c => c.Label == "free-roam-stopped"); + foreach (var block in fixture.Memory()) memory.Blocks.Add(block.Key, block.Value); + var audio = memory.Blocks[SyntheticFixture.Audio]; + var reader = new GameSnapshotReader(memory); + const ulong heapA = 0x7500000000, heapB = 0x7600000000; + + void PutHeap(string id, ulong address) + { + Check(id.Length >= 16 && id.Length <= 127); + audio.AsSpan(0x278, 64).Clear(); + BinaryPrimitives.WriteUInt64LittleEndian(audio.AsSpan(0x278), address); + BinaryPrimitives.WriteUInt64LittleEndian(audio.AsSpan(0x288), (ulong)id.Length); + BinaryPrimitives.WriteUInt64LittleEndian(audio.AsSpan(0x290), (ulong)Math.Max(31, id.Length)); + memory.Blocks[address] = Encoding.ASCII.GetBytes(id + "\0"); + } + void PutShort(string id) + { + Check(id.Length >= 5 && id.Length <= 15); + audio.AsSpan(0x278, 64).Clear(); + Encoding.ASCII.GetBytes(id + "\0").CopyTo(audio, 0x278); + BinaryPrimitives.WriteUInt64LittleEndian(audio.AsSpan(0x288), (ulong)id.Length); + BinaryPrimitives.WriteUInt64LittleEndian(audio.AsSpan(0x290), 15); + } + + PutHeap("HON_CivicTypeR_2015", heapA); + var first = reader.Capture(SyntheticFixture.GameBase, true); + Check(first.Car.RawId == "HON_CivicTypeR_2015" && first.CarProbeStatus == "ok-heap", + "Long MSVC string should resolve via guarded heap pointer"); + + PutHeap("BMW_M3Coupe_2010", heapB); + var switched = reader.Capture(SyntheticFixture.GameBase, true); + Check(switched.Car.RawId == "BMW_M3Coupe_2010" && switched.CarProbeStatus == "ok-heap", + "Second long car should replace first"); + + PutShort("TOY_SupraRZ_98"); + var shortCar = reader.Capture(SyntheticFixture.GameBase, true); + Check(shortCar.Car.RawId == "TOY_SupraRZ_98" && shortCar.CarProbeStatus == "ok", + "Short car should switch back to inline encoding"); + + PutHeap("HON_CivicTypeR_2015", heapA); + memory.Blocks.Remove(heapA); + var unreadable = reader.Capture(SyntheticFixture.GameBase, true); + Check(unreadable.Attached && unreadable.Car.RawId is null && unreadable.CarProbeStatus == "heap-unreadable", + "Unreadable heap must not reuse a previous valid car"); + + PutHeap("HON_CivicTypeR_2015", heapA); + memory.Blocks[heapA][0] = (byte)'!'; + var malformed = reader.Capture(SyntheticFixture.GameBase, true); + Check(malformed.Car.RawId is null && malformed.CarProbeStatus == "heap-invalid-id", + "Malformed pointer payload must be rejected"); + + PutHeap("HON_CivicTypeR_2015", heapA); + int heapReads = 0; + memory.BeforeRead = (address, size) => + { + if (address == heapA && ++heapReads == 2) + memory.Blocks[heapA][0] = (byte)'A'; + }; + var racing = reader.Capture(SyntheticFixture.GameBase, true); + Check(racing.Car.RawId is null && racing.CarProbeStatus == "heap-changed", + "Heap changing during a snapshot must not publish a mixed ID"); +}); + Test("Unsupported and overflowing bases fail without reads", () => { using var memory = new FixtureMemory(); var reader = new GameSnapshotReader(memory); From cf92fcaf7021a95034a94940544d0e0019e81bc8 Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 17:59:05 +0200 Subject: [PATCH 04/11] Document experimental heap-backed car ID fallback and validation limits --- docs/OFFSETS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/OFFSETS.md b/docs/OFFSETS.md index 2b339d7..9e10276 100644 --- a/docs/OFFSETS.md +++ b/docs/OFFSETS.md @@ -23,10 +23,10 @@ Mapped headers must match file identity. Preferred base is tried first, then eli | Position XYZ | +0xA0/A4/A8; AudioEngine | three float32 world coordinates | CONFIRMED captured / LIKELY world semantics; motion controls; high field/medium complete semantics | Finite, each abs<=100000; no region inference | | Position mirror | +0x190/194/198; AudioEngine | three float32 | CONFIRMED duplicate; captured comparisons; high | Same bound; component differences<=1.5 used by fallback | | Velocity | +0x170/174/178; AudioEngine | Vector3, likely m/s | CONFIRMED captured / LIKELY units; stopped/moving correlation; high field/medium units | Finite each abs<=500; length*3.6 finite<=1000km/h | -| Car raw ID | +0x278; AudioEngine | inline ASCII string | CONFIRMED; TOY_SupraRZ_98/LAM_Huracan_15 captures; high | Length5..63, alphanumeric/underscore and includes underscore; not a state detector | +| Car raw ID | +0x278; AudioEngine | observed inline ASCII; possible MSVC small-string/heap representation | CONFIRMED short IDs only; **EXPERIMENTAL** heap fallback | Inline length5..63; for possible heap strings, validate 64-bit size/capacity/pointer at +0x288/+0x290/+0x278, read at most 128 bytes with double-read guards; not a state detector | | UI registry | +0x630; AudioEngine | pointer64 | CONFIRMED; captured pointer traversal; high | Exact canonical aligned pointer; stable chain | -Friendly-name fallback is formatting, not an authoritative car database. CarIn and AudioObjectCar are separate findings. +Friendly-name fallback is formatting, not an authoritative car database. CarIn and AudioObjectCar are separate findings. The MSVC heap-string decoding path was added to address reports of `invalid-character` car probes, but **no live dump has yet confirmed** that FH2 uses this object layout in the affected sessions. It fails closed on invalid metadata, changed bytes or unreadable pointers; validate against live car swaps before treating this as a production-proven fix. ## Mixer/UI registry From 807fa455883d5ec8db722c3d5c947f717093b450 Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 18:22:15 +0200 Subject: [PATCH 05/11] Add experimental read-only Extra Options local car model probe --- native/FH2ML.AzimuthRPC/CarObjectProbe.h | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 native/FH2ML.AzimuthRPC/CarObjectProbe.h diff --git a/native/FH2ML.AzimuthRPC/CarObjectProbe.h b/native/FH2ML.AzimuthRPC/CarObjectProbe.h new file mode 100644 index 0000000..80af032 --- /dev/null +++ b/native/FH2ML.AzimuthRPC/CarObjectProbe.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +// Experimental FH2 1.0.0.64 in-process reader, based on the local-car path +// used by Extra Options. Never call from DllMain. Disabled by default. +enum class CarObjectProbeStatus : std::uint32_t +{ + Ok, + NoGameManager, + NoPlayer, + NoCar, + InvalidCarVtable, + InvalidModelId, + UnsafeRelease, + Fault, +}; + +struct CarObjectProbeResult +{ + CarObjectProbeStatus status{CarObjectProbeStatus::NoGameManager}; + std::uint32_t modelId{}; +}; + +// These native game calls are NOT established as thread-safe. +// Caller MUST require explicit developer opt-in and only a validated game PE. +// The probe is non-patching, but it still invokes game methods. +CarObjectProbeResult ProbeCurrentCarObject(std::uintptr_t gameBase) noexcept; + +const char* CarObjectProbeStatusName(CarObjectProbeStatus status) noexcept; From 2ed493f143073ecba4664aff5d86cfed2f5ef861 Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 18:22:22 +0200 Subject: [PATCH 06/11] Add experimental read-only Extra Options local car model probe --- native/FH2ML.AzimuthRPC/CarObjectProbe.cpp | 149 +++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 native/FH2ML.AzimuthRPC/CarObjectProbe.cpp diff --git a/native/FH2ML.AzimuthRPC/CarObjectProbe.cpp b/native/FH2ML.AzimuthRPC/CarObjectProbe.cpp new file mode 100644 index 0000000..d86cf9c --- /dev/null +++ b/native/FH2ML.AzimuthRPC/CarObjectProbe.cpp @@ -0,0 +1,149 @@ +#include "CarObjectProbe.h" + +#include +#include +#include + +namespace +{ +constexpr std::uintptr_t kPlayerManagerRva = 0x034ABA60; +constexpr std::uintptr_t kGetLocalPlayerRva = 0x0021E0C0; +constexpr std::uintptr_t kGetPlayerCarRva = 0x002DA060; +constexpr std::uintptr_t kPlayerCarVtableRva = 0x02C5CB80; +constexpr std::uintptr_t kModelIdOffset = 0x118; +constexpr std::uintptr_t kReleaseSlot = 0x18; +constexpr std::uintptr_t kGameCodeLimitRva = 0x01DCC000; +constexpr std::uint32_t kMaximumPlausibleModelId = 10000; + +using GetLocalPlayerFn = void* (*)(void*, int); +using GetPlayerCarFn = void* (*)(void*, void**); +using ReleaseFn = void (*)(void*); + +bool ReadMemory(const std::uintptr_t address, void* destination, const SIZE_T bytes) noexcept +{ + if (address < 0x10000 || destination == nullptr || bytes == 0) + return false; + SIZE_T read = 0; + return ReadProcessMemory(GetCurrentProcess(), + reinterpret_cast(address), + destination, bytes, &read) != FALSE && + read == bytes; +} + +bool ValidPointer(const std::uintptr_t pointer) noexcept +{ + return pointer >= 0x10000 && + pointer <= 0x00007FFFFFFFE000ull && + (pointer & 7ull) == 0; +} + +bool ReadPointer(const std::uintptr_t address, std::uintptr_t& value) noexcept +{ + value = 0; + return ReadMemory(address, &value, sizeof(value)) && ValidPointer(value); +} + +bool SafeGameCode(const std::uintptr_t base, const std::uintptr_t address) noexcept +{ + return address >= base + 0x1000 && address < base + kGameCodeLimitRva; +} + +// There are no objects needing C++ unwinding in this SEH boundary. +// Game methods might still be thread-dependent. On any fault, the caller +// permanently disables further probes for this session. +CarObjectProbeResult ProbeInsideSeh(const std::uintptr_t base) noexcept +{ + CarObjectProbeResult result{}; + __try + { + std::uintptr_t manager = 0; + if (!ReadPointer(base + kPlayerManagerRva, manager)) + { + result.status = CarObjectProbeStatus::NoGameManager; + return result; + } + + auto getPlayer = reinterpret_cast(base + kGetLocalPlayerRva); + void* player = getPlayer(reinterpret_cast(manager), 0); + if (!ValidPointer(reinterpret_cast(player))) + { + result.status = CarObjectProbeStatus::NoPlayer; + return result; + } + + void* car = nullptr; + auto getCar = reinterpret_cast(base + kGetPlayerCarRva); + getCar(player, &car); + const auto address = reinterpret_cast(car); + if (!ValidPointer(address)) + { + result.status = CarObjectProbeStatus::NoCar; + return result; + } + + std::uintptr_t vtable = 0; + const bool validType = ReadPointer(address, vtable) && + vtable == base + kPlayerCarVtableRva; + std::uintptr_t releaseMethod = 0; + const bool canRelease = validType && + ReadPointer(vtable + kReleaseSlot, releaseMethod) && + SafeGameCode(base, releaseMethod); + + std::uint32_t modelId = 0; + const bool modelRead = validType && + ReadMemory(address + kModelIdOffset, + &modelId, sizeof(modelId)); + + // GetPlayerCar returns an owned reference. Never return without + // releasing a reference when its verified virtual release method exists. + if (canRelease) + { + auto release = reinterpret_cast(releaseMethod); + release(car); + } + else + { + result.status = validType ? CarObjectProbeStatus::UnsafeRelease + : CarObjectProbeStatus::InvalidCarVtable; + return result; + } + + if (!modelRead || modelId == 0 || modelId > kMaximumPlausibleModelId) + { + result.status = CarObjectProbeStatus::InvalidModelId; + return result; + } + result.status = CarObjectProbeStatus::Ok; + result.modelId = modelId; + } + __except (EXCEPTION_EXECUTE_HANDLER) + { + result.status = CarObjectProbeStatus::Fault; + result.modelId = 0; + } + return result; +} +} // namespace + +CarObjectProbeResult ProbeCurrentCarObject(const std::uintptr_t gameBase) noexcept +{ + if (!ValidPointer(gameBase) || gameBase > UINTPTR_MAX - kPlayerManagerRva) + return {CarObjectProbeStatus::NoGameManager, 0}; + return ProbeInsideSeh(gameBase); +} + +const char* CarObjectProbeStatusName(const CarObjectProbeStatus status) noexcept +{ + switch (status) + { + case CarObjectProbeStatus::Ok: return "ok"; + case CarObjectProbeStatus::NoGameManager: return "no-manager"; + case CarObjectProbeStatus::NoPlayer: return "no-player"; + case CarObjectProbeStatus::NoCar: return "no-car"; + case CarObjectProbeStatus::InvalidCarVtable: return "invalid-vtable"; + case CarObjectProbeStatus::InvalidModelId: return "invalid-model-id"; + case CarObjectProbeStatus::UnsafeRelease: return "unsafe-release"; + case CarObjectProbeStatus::Fault: return "fault"; + } + return "unknown"; +} From bf308e66bd4ac0bdc839c1f10b198d83a751abaa Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 18:23:03 +0200 Subject: [PATCH 07/11] Validate game method address without pointer-alignment assumption --- native/FH2ML.AzimuthRPC/CarObjectProbe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/FH2ML.AzimuthRPC/CarObjectProbe.cpp b/native/FH2ML.AzimuthRPC/CarObjectProbe.cpp index d86cf9c..7af0568 100644 --- a/native/FH2ML.AzimuthRPC/CarObjectProbe.cpp +++ b/native/FH2ML.AzimuthRPC/CarObjectProbe.cpp @@ -86,7 +86,7 @@ CarObjectProbeResult ProbeInsideSeh(const std::uintptr_t base) noexcept vtable == base + kPlayerCarVtableRva; std::uintptr_t releaseMethod = 0; const bool canRelease = validType && - ReadPointer(vtable + kReleaseSlot, releaseMethod) && + ReadMemory(vtable + kReleaseSlot, &releaseMethod,\n sizeof(releaseMethod)) && SafeGameCode(base, releaseMethod); std::uint32_t modelId = 0; From bee22df10986bb2412bbeb14637cfc34763cda8f Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 18:23:11 +0200 Subject: [PATCH 08/11] Compile optional local-car object probe into native DLL --- native/FH2ML.AzimuthRPC/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/FH2ML.AzimuthRPC/CMakeLists.txt b/native/FH2ML.AzimuthRPC/CMakeLists.txt index 8a7b6e2..219ad8a 100644 --- a/native/FH2ML.AzimuthRPC/CMakeLists.txt +++ b/native/FH2ML.AzimuthRPC/CMakeLists.txt @@ -3,7 +3,7 @@ project(AzimuthRPCMod LANGUAGES CXX) if(NOT WIN32 OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8) message(FATAL_ERROR "AzimuthRPC requires Windows x64") endif() -add_library(AzimuthRPCMod SHARED AzimuthRpcMod.cpp LocationResolver.cpp) +add_library(AzimuthRPCMod SHARED AzimuthRpcMod.cpp LocationResolver.cpp CarObjectProbe.cpp) target_include_directories(AzimuthRPCMod PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/fh2ml-sdk") target_compile_features(AzimuthRPCMod PRIVATE cxx_std_20) target_compile_definitions(AzimuthRPCMod PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX UNICODE _UNICODE) From ee44c05b63373f365d08e9cf7a95d11de1e097c0 Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 18:23:59 +0200 Subject: [PATCH 09/11] Integrate opt-in in-process current-car model probe with fail-closed fallback --- native/FH2ML.AzimuthRPC/AzimuthRpcMod.cpp | 90 ++++++++++++++++++++++- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/native/FH2ML.AzimuthRPC/AzimuthRpcMod.cpp b/native/FH2ML.AzimuthRPC/AzimuthRpcMod.cpp index 56656b0..731f858 100644 --- a/native/FH2ML.AzimuthRPC/AzimuthRpcMod.cpp +++ b/native/FH2ML.AzimuthRPC/AzimuthRpcMod.cpp @@ -1,6 +1,7 @@ #include #include "FH2ML.h" #include "LocationResolver.h" +#include "CarObjectProbe.h" #include #include @@ -13,6 +14,7 @@ #include #include #include +#include #include #include @@ -74,6 +76,7 @@ struct Snapshot std::uintptr_t gameBase{}; UiMode uiMode{UiMode::Unknown}; bool inWorld{}; + bool telemetryConsistent{}; std::string carRaw; std::string carDisplay; float speedKmh{}; @@ -780,7 +783,6 @@ Snapshot CaptureSnapshot(const std::uintptr_t gameBase) snapshot.uiMode = ReadUiMode(gameBase, audio, raw); if (snapshot.uiMode == UiMode::Unknown && - !snapshot.carRaw.empty() && mirrorsMatch && snapshot.hasSpeed && FiniteVec(velocity, 500.0f)) @@ -788,10 +790,12 @@ Snapshot CaptureSnapshot(const std::uintptr_t gameBase) const float velocityKmh = Length(velocity) * 3.6f; if (std::isfinite(velocityKmh) && velocityKmh <= 1000.0f) { - snapshot.inWorld = + snapshot.telemetryConsistent = (snapshot.speedKmh <= 3.0f && velocityKmh <= 5.0f) || std::fabs(snapshot.speedKmh - velocityKmh) <= std::max(10.0f, snapshot.speedKmh * 0.15f); + snapshot.inWorld = !snapshot.carRaw.empty() && + snapshot.telemetryConsistent; } } @@ -1175,6 +1179,16 @@ std::string Fingerprint(const Snapshot& snapshot) return BuildDetails(snapshot) + "\n" + BuildState(snapshot); } +bool ExperimentalCarObjectEnabled() +{ + char value[8]{}; + const DWORD length = GetEnvironmentVariableA( + "AZIMUTH_RPC_EXPERIMENTAL_CAR_OBJECT", + value, + static_cast(sizeof(value))); + return length == 1 && value[0] == '1'; +} + DWORD WINAPI RpcThread(LPVOID) { Sleep(1000); @@ -1185,11 +1199,20 @@ DWORD WINAPI RpcThread(LPVOID) ULONGLONG lastPresenceUpdate = 0; std::uint64_t nonce = 0; std::string lastFingerprint; + bool experimentalCarProbe = ExperimentalCarObjectEnabled(); + bool carProbeQuarantined = false; + std::string lastCarObjectStatus; + std::unordered_map modelNames; + std::uint32_t candidateModel = 0; + std::string candidateName; const std::int64_t sessionStart = static_cast(std::time(nullptr)); Trace(std::string("AzimuthRPC ") + kVersion + " FH2ML native worker started"); Trace("Log file: %LOCALAPPDATA%\\AzimuthRPC\\logs\\AzimuthRPC.log"); + Trace(experimentalCarProbe + ? "EXPERIMENTAL local-car object calls ENABLED: game functions called on RPC worker thread (not established thread-safe)" + : "EXPERIMENTAL local-car object calls disabled (opt in via AZIMUTH_RPC_EXPERIMENTAL_CAR_OBJECT=1)"); LogLoadedModules(); while (!g_stop.load(std::memory_order_relaxed)) @@ -1244,7 +1267,68 @@ DWORD WINAPI RpcThread(LPVOID) if (now - lastPresenceUpdate >= kPresenceUpdateMs) { lastPresenceUpdate = now; - const Snapshot snapshot = CaptureSnapshot(gameBase); + Snapshot snapshot = CaptureSnapshot(gameBase); + if (snapshot.valid && experimentalCarProbe && !carProbeQuarantined) + { + // These *native game calls* are a gated research option only. + // No vtables, executable bytes or Extra Options hooks are patched. + const CarObjectProbeResult probe = ProbeCurrentCarObject(gameBase); + const std::string status = + std::string(CarObjectProbeStatusName(probe.status)) + + (probe.status == CarObjectProbeStatus::Ok + ? " model-id=" + std::to_string(probe.modelId) + : std::string()); + if (status != lastCarObjectStatus) + { + Trace("Local car object: " + status); + lastCarObjectStatus = status; + } + + if (probe.status == CarObjectProbeStatus::Fault || + probe.status == CarObjectProbeStatus::UnsafeRelease || + probe.status == CarObjectProbeStatus::InvalidCarVtable) + { + carProbeQuarantined = true; + Trace("EXPERIMENTAL local-car probe quarantined for session after unsafe result"); + } + else if (probe.status == CarObjectProbeStatus::Ok) + { + if (!snapshot.carRaw.empty()) + { + // Only learn a name after two consecutive observations + // of the same model+text pairing (car swaps can race). + if (candidateModel == probe.modelId && + candidateName == snapshot.carDisplay) + { + modelNames[probe.modelId] = snapshot.carDisplay; + } + else + { + candidateModel = probe.modelId; + candidateName = snapshot.carDisplay; + } + } + else + { + const auto existing = modelNames.find(probe.modelId); + snapshot.carDisplay = existing != modelNames.end() + ? existing->second + : "Vehicle model #" + std::to_string(probe.modelId); + // Do not claim this was an AudioEngine raw car ID. + snapshot.inWorld = snapshot.telemetryConsistent; + } + } + else if (probe.status == CarObjectProbeStatus::NoCar || + probe.status == CarObjectProbeStatus::NoPlayer) + { + // Current-car signal takes precedence over stale audio. + snapshot.carRaw.clear(); + snapshot.carDisplay.clear(); + snapshot.inWorld = false; + candidateModel = 0; + candidateName.clear(); + } + } if (snapshot.valid) { From 7d910c9b670c5adcc2c934c7f9c78f07dc95646b Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 18:24:46 +0200 Subject: [PATCH 10/11] Document Extra Options car getter opt-in, limits and live test matrix --- native/FH2ML.AzimuthRPC/README.md | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/native/FH2ML.AzimuthRPC/README.md b/native/FH2ML.AzimuthRPC/README.md index 09ac333..03062b9 100644 --- a/native/FH2ML.AzimuthRPC/README.md +++ b/native/FH2ML.AzimuthRPC/README.md @@ -102,3 +102,57 @@ from `GetGameModule()`. It does not scan the process address space for the game. The vendored FH2ML SDK header is licensed separately under MIT; see `fh2ml-sdk/LICENSE`. + +## Experimental current-car detection (Extra Options method) + +This development-only build has an **opt-in, in-process** vehicle probe based on +[RokkuDayo's Extra Options](https://github.com/RokkuDayo/ForzaHorizon2_ExtraOptions) +`GetLocalPlayer -> GetPlayerCar` design. The known FH2 1.0.0.64 RVAs are: + +- `PlayerManager` root: `0x34ABA60` +- `GetLocalPlayer`: `0x21E0C0` +- `GetPlayerCar`: `0x2DA060` +- expected car-object vtable: `0x2C5CB80` +- observed numeric model ID: `car + 0x118` + +This uses **game functions** on AzimuthRPC's existing worker thread. +Their thread-safety has **not** been validated. The feature is disabled by +default and is **not a production car-detection fix**. Do not recommend it +to general users until live behavior has been verified. It does not patch +the Extra Options vehicle-update hook or any game code. + +For developer-controlled testing only, set the following environment +variable *before launching Azimuth/FH2ML*: + +```powershell +$env:AZIMUTH_RPC_EXPERIMENTAL_CAR_OBJECT = '1' +# Launch Azimuth from the same shell so the environment is inherited. +``` + +Unset it or set a different value to revert to the previous car reader. + +**Fail-closed rules:** accept only the supported FH2 PE, validate the +player-car vtable and pointer, read the numeric ID with a guarded read, +release the owned car reference via the verified vtable method, and stop +probing for the session on unsafe release, unexpected vtable or a caught +access violation. No stale model name is recycled when the local player +has no car. A valid numeric ID can provide fallback presence +`Vehicle model #1234` if the AudioEngine text cannot be decoded. +When two consecutive samples report the same model ID and a valid +AudioEngine name, the matching friendly name is remembered in memory +for later failed string reads. This is **learned from runtime observation**, +not an authoritative numeric-ID-to-name database; it can be wrong if +the text field lags a vehicle change. + +Watch the log for `Local car object: ok model-id=...` and compare it +with the actual selected car before and after several garage, free-roam, +Extra Options and race transitions. Report crashes, wrong car names, +unreleased references, or logs showing `fault`, `unsafe-release`, +`invalid-vtable`; leave the feature OFF if anything looks wrong. +The probe does not exist in the standalone C# EXE because the standalone +process cannot safely call these in-process game methods. + +**Research to finish:** confirm on the game thread that the car getter +lifetime and field `car + 0x118` are valid, add a proper host game-thread +callback if FH2ML grows one, and validate a numeric-ID-to-`MediaName` +source. Until then, do not merge this branch into a production release. From 1822bfc0681dcf19ecd9ddc19182bb915b163726 Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 18:27:40 +0200 Subject: [PATCH 11/11] Fix malformed newline in native car probe release validation --- native/FH2ML.AzimuthRPC/CarObjectProbe.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/native/FH2ML.AzimuthRPC/CarObjectProbe.cpp b/native/FH2ML.AzimuthRPC/CarObjectProbe.cpp index 7af0568..66136e3 100644 --- a/native/FH2ML.AzimuthRPC/CarObjectProbe.cpp +++ b/native/FH2ML.AzimuthRPC/CarObjectProbe.cpp @@ -86,7 +86,8 @@ CarObjectProbeResult ProbeInsideSeh(const std::uintptr_t base) noexcept vtable == base + kPlayerCarVtableRva; std::uintptr_t releaseMethod = 0; const bool canRelease = validType && - ReadMemory(vtable + kReleaseSlot, &releaseMethod,\n sizeof(releaseMethod)) && + ReadMemory(vtable + kReleaseSlot, &releaseMethod, + sizeof(releaseMethod)) && SafeGameCode(base, releaseMethod); std::uint32_t modelId = 0;