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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<Project><PropertyGroup><Version>0.9.9</Version><AssemblyVersion>0.9.9.0</AssemblyVersion><FileVersion>0.9.9.0</FileVersion><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><TreatWarningsAsErrors>true</TreatWarningsAsErrors><PlatformTarget>x64</PlatformTarget><UseSharedCompilation>false</UseSharedCompilation></PropertyGroup></Project>
<Project><PropertyGroup><Version>1.0.0</Version><AssemblyVersion>1.0.0.0</AssemblyVersion><FileVersion>1.0.0.0</FileVersion><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><TreatWarningsAsErrors>true</TreatWarningsAsErrors><PlatformTarget>x64</PlatformTarget><UseSharedCompilation>false</UseSharedCompilation></PropertyGroup></Project>
34 changes: 23 additions & 11 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
# AzimuthRPC v0.9.9
# AzimuthRPC v1.0.0

Discord Rich Presence polish and car-detection diagnostics.
**Vehicle detection fix — first stable 1.x release.**

- "Loading Race" now appears **without a second line**: removes the generic "Forza Horizon 2 via Azimuth" state and prevents a stale car or speed from being shown while loading. This applies to both standalone EXE and native FH2ML DLL.
- The standalone log now records changes to a compact, privacy-conscious snapshot diagnostic: game UI mode, inferred activity, hook/telemetry status, event context and car ID parse result. No raw game-memory bytes are dumped.
- Car ID validation now reports a reason such as `empty`, `too-short`, `unterminated`, `invalid-character`, `missing-underscore`, or `ok` so users with missing vehicle names can provide actionable logs.
- Adds automated regression coverage for race-loading second-line suppression and snapshot diagnostics.
- Retains v0.9.8 standalone startup log fallback and the log folder shortcut, plus the v0.9.7 native startup diagnostics.
Thank you to the FH2 community testers who reproduced the missing-car issue and confirmed the PR #5 standalone test build resolves it in-game.

## Compatibility
## Fixed

Still targets FH2 Xbox One 1.0.0.64 through Azimuth. This release does **not** change memory offsets or claim confirmed compatibility with every Azimuth version or mod combination.
- Car detection could stop updating after changing vehicles or returning from a race while Discord and speed telemetry continued to work (`CarProbe=invalid-character`).
- The car ID reader previously treated `AudioEngine+0x278` as inline text only. It now also supports a guarded, MSVC-style heap-backed string candidate used when an identifier exceeds the short-string capacity.
- Failed reads no longer reuse a previously valid car name. Memory validation requires sensible pointer/size/capacity metadata, valid NUL-terminated ASCII IDs, and repeated consistent reads before publishing a heap ID.
- Tests cover long-to-long vehicle changes, returning to a short ID, unreadable or malformed memory, and changes while sampling.

## Collecting useful reports
## Available builds

Use `%LOCALAPPDATA%\AzimuthRPC\logs\AzimuthRPC.log` (or the standalone fallback `%TEMP%\AzimuthRPC\AzimuthRPC.log`). Include the **Snapshot diagnostic:** lines with your Azimuth version, other mods such as Extra Options, and whether you used the EXE or FH2ML DLL. Please review/redact any sensitive data before sharing.
- **AzimuthRPC.exe:** standalone Windows x64 application, with the community-tested fix.
- **FH2ML-AzimuthRPC-1.0.0.zip:** native mod package with the same guarded string reader. The reported live success was for the standalone EXE; native behavior and other mod combinations still warrant independent testing.

## Compatibility and diagnostics

Targets **Forza Horizon 2 Xbox One 1.0.0.64** through Azimuth. This release does **not** add new game memory offsets, require Extra Options, or include the experimental game-object method from PR #6.

The `CarProbe` diagnostic can show `ok` (inline), `ok-heap` (heap-backed), `heap-*` (guarded failure), or `invalid-character`. Report wrong or missing car names with the selected car, game/mod versions, and sanitized logs via [Issue #4](https://github.com/Refilewski/Azimuth-RPC/issues/4).

Please review logs before sharing them; they may include local paths. Standalone logs: `%LOCALAPPDATA%\AzimuthRPC\logs\AzimuthRPC.log` (fallback `%TEMP%\AzimuthRPC\AzimuthRPC.log`).

## Previous improvements

Includes v0.9.9 race-loading presence cleanup, car-probe diagnostics, startup logging and the supported location, speed and activity presence functionality.
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; MSVC-style small/heap string candidate | CONFIRMED short IDs; LIVE-REPORTED success for heap fallback in standalone 0.9.9 test build | 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 `invalid-character` car probes. The maintainer reports that the PR #5 standalone test build fixes the affected live sessions (18 October 2026); the precise object layout is still inferred rather than established from a complete live dump, and the FH2ML native DLL has not been separately confirmed in the reported test. It fails closed on invalid metadata, changed bytes or unreadable pointers. Continue testing other cars, race transitions and mod combinations.

## Mixer/UI registry

Expand Down
97 changes: 79 additions & 18 deletions native/FH2ML.AzimuthRPC/AzimuthRpcMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ constexpr std::uintptr_t kSimulationManagerVtableRva = 0x02C5FD70ull;
constexpr std::size_t kCarIdOffset = 0x278;
constexpr std::size_t kCarIdBytes = 64;
constexpr char kDiscordApplicationId[] = "1445162899315363924";
constexpr char kVersion[] = "0.9.9";
constexpr char kVersion[] = "1.0.0";
constexpr DWORD kDiscordReconnectMs = 5000;
constexpr DWORD kPresenceUpdateMs = 4000;
constexpr LONGLONG kMaxLogBytes = 2ll * 1024ll * 1024ll;
Expand Down Expand Up @@ -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<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 +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;
Expand Down
2 changes: 1 addition & 1 deletion native/FH2ML.AzimuthRPC/mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "azimuth-rpc",
"name": "AzimuthRPC",
"version": "0.9.9",
"version": "1.0.0",
"author": "Refilewski",
"entry": "AzimuthRPC.dll",
"enabled": true,
Expand Down
78 changes: 60 additions & 18 deletions src/AzimuthRPC.Core/Game/GameSnapshotReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<byte> bytes, out string status)
private static string? ReadCar(ReadOnlySpan<byte> 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)
{
Expand All @@ -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<byte> 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)
{
Expand Down
Loading
Loading