Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/OFFSETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
185 changes: 165 additions & 20 deletions native/FH2ML.AzimuthRPC/AzimuthRpcMod.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <windows.h>
#include "FH2ML.h"
#include "LocationResolver.h"
#include "CarObjectProbe.h"
#include <tlhelp32.h>

#include <algorithm>
Expand All @@ -13,6 +14,7 @@
#include <cstdio>
#include <cstring>
#include <string>
#include <unordered_map>
#include <type_traits>
#include <vector>

Expand Down Expand Up @@ -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{};
Expand Down Expand Up @@ -429,52 +432,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<std::uintptr_t>(pointer)))
{
reason = "heap-invalid-pointer";
return false;
}

std::size_t length = 0;
while (length < kCarIdBytes && raw[kCarIdOffset + length] != 0)
++length;
std::array<std::uint8_t, 128> first{}, second{};
std::array<std::uint8_t, 32> fieldAfter{};
const std::size_t count = static_cast<std::size_t>(length) + 1;
if (!ReadBytes(static_cast<std::uintptr_t>(pointer), first.data(), count) ||
!ReadBytes(static_cast<std::uintptr_t>(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<std::size_t>(length)] != 0)
{
reason = "heap-unterminated";
return false;
}

if (length == 0)
bool underscore = false;
for (std::size_t i = 0; i < static_cast<std::size_t>(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<const char*>(first.data()),
static_cast<std::size_t>(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<unsigned int>(c));
std::snprintf(detail, sizeof(detail), "invalid-char@%zu=0x%02X",
i, static_cast<unsigned int>(c));
reason = detail;
return false;
}
}

value.assign(reinterpret_cast<const char*>(raw + kCarIdOffset), length);
value.assign(reinterpret_cast<const char*>(field), inlineLength);
if (value.find('_') == std::string::npos)
{
reason = "missing-underscore";
Expand Down Expand Up @@ -682,7 +746,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;
Expand Down Expand Up @@ -719,18 +783,19 @@ 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))
{
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;
}
}

Expand Down Expand Up @@ -1114,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<DWORD>(sizeof(value)));
return length == 1 && value[0] == '1';
}

DWORD WINAPI RpcThread(LPVOID)
{
Sleep(1000);
Expand All @@ -1124,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<std::uint32_t, std::string> modelNames;
std::uint32_t candidateModel = 0;
std::string candidateName;
const std::int64_t sessionStart =
static_cast<std::int64_t>(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))
Expand Down Expand Up @@ -1183,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)
{
Expand Down
2 changes: 1 addition & 1 deletion native/FH2ML.AzimuthRPC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading