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
6 changes: 6 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ before the repository went public. They remain only in the maintainer's private
hashes elsewhere in these docs also point into that history, for example those of the frozen stub fixtures in
chapter 14. The fixture files themselves are in the tree.

Native tone registration findings and the isolated E..Z resource-preload design are tracked in
[tone implementation notes](agents/tones-notes.md#native-registration). Full shared-store reader integration
is deferred until its aliases and lifetime are mapped; playback retains the full-object apply path and reads
the stock per-player Tone Plan override properties. The editor's dynamic rows and viewport limit are recorded
in the [demo-first editor notes](agents/tones-notes.md#demo-first-editor-implementation).

## Find a topic

### Start with the model
Expand Down
4 changes: 4 additions & 0 deletions docs/NATIVE-FORMAT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ that it works.

## Why

The tone-slot loader implementation and static site evidence are recorded in
[tone research notes](agents/tones-notes.md). The writer fields are specified in
[Tone slots A through Z](release/NATIVE-FORMAT.md#tone-slots-a-through-z).

In the native format, the string order is positional throughout the package. The game cannot read this format
directly, so RS Extended Range translates it while loading. The result is stock records plus an internal
[extension block](architecture/extension-block.md) and internal manifest keys. Tools never write that internal form.
Expand Down
445 changes: 445 additions & 0 deletions docs/agents/tones-notes.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions docs/release/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

[README](../../README.md) · [Install](INSTALL.md) · [Settings](SETTINGS.md) · [Charting](CHARTING.md) · **Changelog**

## Unreleased

### Added

- Charts in the native format can use 26 tone slots, A through Z, plus Base. The game itself only has Base and A
through D. Tone changes to the new slots work like the stock ones. A test tool builds a chart with six tones and
20 tone changes from your own package.

## 1.0.0-beta.5

### Changed
Expand Down
40 changes: 40 additions & 0 deletions docs/release/NATIVE-FORMAT.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,46 @@ entry in the HSAN header file:
- Stock arrangements and arrangements without a `Tuning`, such as vocals, have no marker. All other fields
keep their stock meaning.

## Tone slots A through Z

A native arrangement can name up to 26 tone-change destinations, `Tone_A` through `Tone_Z`, plus its separate
`Tone_Base`. Put the extra names in the arrangement's `Attributes` next to the stock names:

```json
"Tone_Base": "clean",
"Tone_A": "clean",
"Tone_B": "crunch",
"Tone_C": "drive",
"Tone_D": "lead",
"Tone_E": "ambient",
"Tone_F": "fuzz"
```

Keep complete definitions in `Attributes.Tones` in the full manifest, as for stock tones. Each name must match
exactly one definition's `Key`, compared without case sensitivity. An unused slot may be absent or an empty
string. Names must fit in 255 UTF-8 bytes. Use the same slot names in the manifest JSON and its HSAN entry.
Do not write `RsxrToneSlots`: the loader generates that internal field from valid native attributes.

The SNG tone section retains its stock binary layout: a `u32` event count followed by records containing
`float32 time` and `u32 id`, eight bytes each. Raw IDs `0` through `25` mean A through Z. In particular, ID `5`
means F. Base is selected before the first event; it has no timeline ID. Times must be finite, nonnegative and
chronological. The game selects the last event strictly earlier than the current song time. There is no limit
of 26 changes: only the number of named destinations is limited.

Extra slots require both native manifest attributes and an `SNXR` chart, with at least one nonempty extra
slot E through Z. Stock arrangements and native arrangements without extra slots use stock tone handling.
A missing or ambiguous definition or an out-of-range ID is rejected and leaves the previous sound active.
The stock Tone Plan editor still shows Base and A through D; paging for E through Z is a follow-up.

To prepare a six-tone, 20-change demo from your own native package and six existing definitions, run:

```powershell
python tools/tone_demo.py SOURCE.psarc DEMO_rsxr_p.psarc --arrangement PERSISTENT_ID --keys KEY_A KEY_B KEY_C KEY_D KEY_E KEY_F
```

The first change is at 5 seconds, then every 3 seconds; `--start` and `--interval` change those times.
Choose times within your song and run the generator outside the game folder.

## Charts

The SNG wrapper is the plain-package wrapper. All its numeric values and the inflated body are little-endian.
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ nav:
- Code structure: docs/agents/code-structure.md
- Hook sites: docs/agents/hook-sites.md
- Docs and testing: docs/agents/docs-and-testing.md
- Tone slot research: docs/agents/tones-notes.md
20 changes: 19 additions & 1 deletion sites.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"pe_checksum": "0x00B13D7C",
"sites": [
{"id": "ToneRegister", "kind": "jmp", "length": 6, "pattern": "55 8B EC 83 EC 08 53 8B 5D 08 80 BB A6 05 00 00 01 56 57 0F 84 4F 03 00 00", "offset": 0, "expect": "55 8B EC 83 EC 08", "note": "CONFIRMED static 0x7E9AF0: stdcall(session), ret 4 at 0x7E9E5E. Wrap after stock Base/A..D registration requests native E..Z resources in an isolated mod store; never replaces the live manager store."},
{"id": "ToneRegisterCall", "kind": "callref", "pattern": "E8 72 D1 FE FF 8B 4D FC 85 C9 0F 84 E8 02 00 00", "offset": 0, "expect": "E8 72 D1 FE FF", "note": "CONFIRMED static 0x7E9B69 -> 0x7D6CE0: EAX player, stack(manager, owned definition, slot), ret 0Ch. Void resource registration; the private view maps extra slots without changing stock bounds/stride."},
{"id": "ToneResourceDestroy", "kind": "callref", "pattern": "E8 7E 07 00 00 83 C4 08 8D 46 08 E8 E3 3A 2B 00", "offset": 0, "expect": "E8 7E 07 00 00", "note": "CONFIRMED static 0x5A876D -> 0x5A8EF0: cdecl(record end, record begin); destroys nested resource vectors and frees game allocations. Used only on mod-owned registration records."},
{"id": "ToneLoad", "kind": "jmp", "length": 6, "pattern": "89 85 5C FC FF FF 85 C0 0F 84 76 01 00 00 8B C8", "offset": 0, "expect": "89 85 5C FC FF FF", "note": "CONFIRMED static 0x56774C: EAX Attributes.Tones; parent arrangement [EBP+0Ch] (resolve Attributes child), arrangement identity [EBP-3A0h]. Capture native E..Z definitions in side tables."},
{"id": "ToneAuto", "kind": "call", "pattern": "E8 ?? ?? ?? ?? 84 C0 0F 94 C3 85 FF 74 17 8D 47", "offset": 0, "expect": "E8 CE 52 0F 00", "note": "CONFIRMED static 0x464ADD: automatic tone lookup 0x559DB0, ESI session, stdcall(time, out id). Wrap preserves stock sessions; extended sessions own Base and A..Z."},
{"id": "ToneSetup", "kind": "call", "pattern": "E8 DC AB D7 FF 84 C0 74 0B C6 44 24 13 01 EB 09", "offset": 0, "expect": "E8 DC AB D7 FF", "note": "CONFIRMED static 0x7DF1CF: setup tone lookup, EBX session; stdcall(time, out id)."},
{"id": "ToneSeek", "kind": "call", "pattern": "E8 26 A9 D7 FF 84 C0 74 0F C6 44 24 13 01 EB 0D", "offset": 0, "expect": "E8 26 A9 D7 FF", "note": "CONFIRMED static 0x7DF485: refresh tone lookup, EBX session; stdcall(time, out id). Force path covered by ToneRefresh."},
{"id": "ToneResume", "kind": "call", "pattern": "E8 F4 D2 D6 FF 84 C0 74 0B C6 44 24 13 01 EB 09", "offset": 0, "expect": "E8 F4 D2 D6 FF", "note": "CONFIRMED static 0x7ECAB7: alternate session tone lookup, EBX session; stdcall(time, out id)."},
{"id": "ToneOverride", "kind": "call", "pattern": "E8 DD 51 0E 00 84 C0 74 0B C6 44 24 13 01 EB 09", "offset": 0, "expect": "E8 DD 51 0E 00", "note": "CONFIRMED static 0x474BCE: override tone lookup, EBX session; stdcall(time, out id)."},
{"id": "ToneRefresh", "kind": "jmp", "length": 6, "pattern": "55 8B EC 83 E4 F8 83 EC 34 A1 ?? ?? ?? ?? 33 C4 89 44 24 30 8A 45 0C 53 8B 5D 08 56 C7 44 24 10 00 00 00 00 80 BB 44 05 00 00 01 57", "offset": 0, "expect": "55 8B EC 83 E4 F8", "note": "CONFIRMED static 0x7DF400: stdcall(session, force), ret 8 at 0x7DF697. Wrap after force=true restores the native timeline selection after the stock Base refresh."},
{"id": "ToneApply", "kind": "callref", "pattern": "8B 45 08 8B 40 0C 8B 40 08 8B 0D ?? ?? ?? ?? 6A 03 50 51 E8 ?? ?? ?? ??", "offset": "0x13", "expect": "E8 F2 EA 36 00", "note": "CONFIRMED static 0x465259: full-object apply 0x7D3D50; ESI=&definition, stdcall(manager, player, 3). Never writes the stock registration grid."},
{"id": "ToneManager", "kind": "ref", "pattern": "8B 45 08 8B 40 0C 8B 40 08 8B 0D ?? ?? ?? ?? 6A 03 50 51 E8 ?? ?? ?? ??", "offset": "0xB", "expect": "2C 04 36 01", "note": "CONFIRMED static 0x465251: address of manager pointer 0x136042C used by stock full-object apply."},
{"id": "MenuMovieSetup", "kind": "jmp", "length": 6, "pattern": "55 8B EC 83 E4 F8 83 EC 14 56 8B F1 80 BE 21 01 00 00 00", "offset": 0, "expect": "55 8B EC 83 E4 F8", "note": "CONFIRMED 0xC167A0: remember menu movie and owner before setup; ECX = movie"},
{"id": "MenuLoadUpdate", "kind": "jmp", "length": 6, "pattern": "55 8B EC 83 E4 F8 83 EC 14 8B 45 08 53 8B 58 0C 83 C3 04", "offset": 0, "expect": "55 8B EC 83 E4 F8", "note": "CONFIRMED 0x59DB80: load-group update, stack argument = loader; game-thread movie retries"},
{"id": "MenuMovieResult", "kind": "jmp", "length": 5, "pattern": "8D 8E 8C 00 00 00 8D 71 10 8B C1 39 71 14 74 02 8B 01 3B 06 74 38 8B 55 08 6A 00 83 EC 08 8B C4 89 10 8B 55 0C 89 50 04 83 EC 18 8B C4 8D 50 10 89 02 89 50 14 8B 16 39 71 14 74 02 8B 09 52 51 E8 ?? ?? ?? ?? 8B 07 8B 50 3C 8B CF FF D2 5F 5E 8B E5 5D C2 08 00", "offset": "0x4E", "expect": "5F 5E 8B E5 5D", "note": "CONFIRMED 0xC19335: movie request epilogue after the asset locator call; AL = accepted, ESI = movie + 9Ch"},
Expand Down Expand Up @@ -687,6 +699,12 @@
{"id": "CMIX", "kind": "jmp", "length": 5, "pattern": "8D 04 52 03 C0 D9 94 81 90 08 00 00 8D 94 52 14 01 00 00 D9 94 81 94 08", "offset": "0x0", "expect": "8D 04 52 03 C0", "note": "CONFIRMED 00518CA4: native colour publication / bounded fallback"},
{"id": "CMINIT", "kind": "jmp", "length": 6, "pattern": "5F 8B C6 5B 8B E5 5D C3 CC CC CC CC CC CC CC CC CC CC CC 55 8B EC 56 8B", "offset": "0x0", "expect": "5F 8B C6 5B 8B E5", "note": "CONFIRMED 0051853D: native colour publication / bounded fallback"},
{"id": "CMBUILD", "kind": "jmp", "length": 6, "pattern": "FF 5E 5B 8B E5 5D C3 CC CC CC CC CC CC CC CC CC CC CC CC CC CC 55 8B EC 53", "offset": "0x1", "expect": "5E 5B 8B E5 5D C3", "note": "CONFIRMED 0051966C: native colour publication / bounded fallback"},
{"id": "CMFALL", "kind": "jmp", "length": 5, "pattern": "8B 44 95 E4 56 C7 45 E0 00 00 00 00 83 FA 06 73 5A 8B 35 8C F5 35 01 8B", "offset": "0x0", "expect": "8B 44 95 E4 56", "note": "CONFIRMED 0075835A: native colour publication / bounded fallback"}
{"id": "CMFALL", "kind": "jmp", "length": 5, "pattern": "8B 44 95 E4 56 C7 45 E0 00 00 00 00 83 FA 06 73 5A 8B 35 8C F5 35 01 8B", "offset": "0x0", "expect": "8B 44 95 E4 56", "note": "CONFIRMED 0075835A: native colour publication / bounded fallback"},
{"id": "TonePlanBuild", "kind": "call", "pattern": "E8 AF DE FF FF 85 C0 75 33 8B 16 8B 42", "offset": 0, "expect": "E8 AF DE FF FF", "note": "CONFIRMED static 0x0064bb4c: Wrap row construction with the selected Attributes marker and extra-slot mask; ret 8."},
{"id": "TonePlanField", "kind": "jmp", "pattern": "8D BC 04 48 01 00 00 C6 84 24 30 01 00 00 00", "offset": 0, "expect": "8D BC 04 48 01 00 00", "note": "CONFIRMED static 0x00649d12: Redirect only the manifest-field name view; original local strings and cleanup stay stock.", "length": 7},
{"id": "TonePlanExtension", "kind": "jmp", "pattern": "8D 84 04 C0 01 00 00 8D 48 10 89 44 24 44", "offset": 0, "expect": "8D 84 04 C0 01 00 00", "note": "CONFIRMED static 0x00649e60: Redirect only the slot-extension view; stock mappings, row fields and chooser identity consume it.", "length": 7},
{"id": "TonePlanBound", "kind": "jmp", "pattern": "83 F8 05 0F 8C 38 F1 FF FF", "offset": 0, "expect": "83 F8 05 0F 8C 38 F1 FF FF", "note": "CONFIRMED static 0x0064ab64: Native extra arrangements compare against 27 and branch to 0x649CA5; all other calls replay CMP 5/JL.", "length": 9},
{"id": "TonePlanEdit", "kind": "jmp", "pattern": "8D 4C 24 0C 51 B9 D8 50 1B 01 E8 1D 06 23 00", "offset": 0, "expect": "8D 4C 24 0C 51", "note": "CONFIRMED static 0x0064be44: Observe the valid ToneNameExtension at ESP+4Ch and ToneKey at ESP+94h before stock edit-list construction.", "length": 5},
{"id": "ToneContext", "kind": "ref", "pattern": "8B 0D CC 04 36 01 8B 49 14 50 8D 54 24 24", "offset": 2, "expect": "CC 04 36 01", "note": "CONFIRMED static 0x00464b9b: Resolve the player-context manager global used by stock Tone Plan override playback at 0x464BDD."}
]
}
11 changes: 10 additions & 1 deletion src/features/native/hooks.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// The three hooks that translate a native package (native.h) while the game loads it. Everything after them (the
// game, XB1, the N-slot chord data, the manifest readers of the tuner and C-lite) sees the current form only.
#include "features/native/native.h"
#include "features/tones/tones.h"
#include "model/nativemanifest.h"
#include "model/nativesng.h"
#include "platform/log.h"
Expand Down Expand Up @@ -117,7 +118,15 @@ extern "C" void __cdecl RsxrNative_OnJson(const char** cursor) {
// cannot be converted continues at the loader's own failure exit instead (the target of the `jne rel32` that ends 3
// bytes before the site; it destroys both streams and returns false), with the site's stack. Must not throw.
extern "C" __declspec(dllexport) void __cdecl Rsxr_Mid_XI1(RsxrMid::Context& c) {
if (RsxrNative_OnBody(RsxrMid::Dword(c.esp + 0x24), RsxrMid::Dword(c.esp + 0x2C))) {
const uint32_t buffer = RsxrMid::Dword(c.esp + 0x24);
const uint32_t size = RsxrMid::Dword(c.esp + 0x2C);
const bool native =
size >= 4 && Rsxr_SafeRead<uint32_t>(reinterpret_cast<const void*>(uintptr_t(buffer)), 0) == 0x52584E53u;
const bool accepted = RsxrNative_OnBody(buffer, size);

RsxrTones_SongLoaded(c.ebx, accepted && native);

if (accepted) {
return;
}

Expand Down
193 changes: 193 additions & 0 deletions src/features/tones/game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
// Game JSON operations and the stock full-object apply bridge. No registration grid writes.
#include "features/tones/game.h"
#include "features/tones/toneplan.h"
#include "model/gamestring.h"
#include "platform/midhook.h"
#include "platform/safecopy.h"
#include "platform/seh.h"
#include <windows.h>
#include <cstring>

extern "C" uintptr_t g_rsxr_tone_apply, g_rsxr_tone_manager, g_rsxr_tone_context;

namespace rsxrtones {
namespace {
using Unary = uint32_t(__thiscall*)(void*);
using Find = uint32_t(__thiscall*)(void*, const char*);

struct Bridge {
uint32_t definition = 0, esi = 0, ret = 0;
};

thread_local Bridge g_bridge;

void ApplyDone(RsxrMid::Context& c) {
c.esi = g_bridge.esi;
c.jump = g_bridge.ret;
}

RsxrMid::CallIn g_applyDone{&ApplyDone, RsxrMid::Mode::Full};

uint32_t Virtual(uint32_t object, size_t offset) {
const uint32_t address = Read(Read(object), offset);
if (!object || !address) {
return 0;
}

__try {
return reinterpret_cast<Unary>(address)(reinterpret_cast<void*>(object));
} __except (Rsxr_FaultFilter(GetExceptionCode())) {
return 0;
}
}

uint32_t Member(uint32_t object, const char* key, size_t offset = 0x14) {
const uint32_t address = Read(Read(object), offset);
if (!object || !address) {
return 0;
}

__try {
return reinterpret_cast<Find>(address)(reinterpret_cast<void*>(object), key);
} __except (Rsxr_FaultFilter(GetExceptionCode())) {
return 0;
}
}

// CONFIRMED: 0x7D3D64 reads [ESI]; ret 0Ch. Stack = manager, player, activation kind (stock uses 3).
void ApplyEntry(RsxrMid::Context& c) {
// The game's custom ABI takes ESI as input and leaves it untouched. Restore the C++ caller's ESI after ret 0Ch.
g_bridge.esi = c.esi;
g_bridge.ret = RsxrMid::Dword(c.esp);
const uint32_t done = static_cast<uint32_t>(g_applyDone.Entry());

if (!Rsxr_SafeStore(reinterpret_cast<void*>(uintptr_t(c.esp)), &done, sizeof done)) {
c.eax = 0;
RsxrMid::Ret(c, 12);
return;
}

c.esi = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&g_bridge.definition));
c.jump = static_cast<uint32_t>(g_rsxr_tone_apply);
}

RsxrMid::CallIn g_apply{&ApplyEntry, RsxrMid::Mode::Full, 12};
} // namespace

uint32_t Read(uint32_t base, size_t offset) {
return Rsxr_SafeRead<uint32_t>(reinterpret_cast<const void*>(uintptr_t(base)), offset);
}

uint32_t Attributes(uint32_t arrangement) {
// CONFIRMED: 0x889CA0 resolves an object member through virtual +18h, then +5Ch.
return Virtual(Member(arrangement, "Attributes", 0x18), 0x5C);
}

bool Name(uint32_t attributes, const char* key, char* text, size_t size) {
// CONFIRMED: manifest reader 0x8899F0 uses virtual +60h, then value+8 -> game string.
// +64h belongs to the automatic consumer's different JSON access path (0x465119).
const uint32_t value = Virtual(Member(attributes, key), 0x60);

return value && rsxr::ReadGameString(reinterpret_cast<const void*>(uintptr_t(Read(value, 8))), text, size);
}

bool Reference(uint32_t object, bool retain) {
const uint32_t address = Read(Read(object), retain ? 0 : 4);
if (!object || !address) {
return false;
}

__try {
reinterpret_cast<void(__thiscall*)(void*)>(address)(reinterpret_cast<void*>(object));
return true;
} __except (Rsxr_FaultFilter(GetExceptionCode())) {
return false;
}
}

uint32_t Definition(uint32_t collection, const char* key) {
// CONFIRMED: 0x7D3790 scans the JSON collection at +10h/+14h, unwraps each value through +34h,
// compares Key case-insensitively, then returns the canonical object through virtual +5Ch.
const uint32_t begin = Read(collection, 0x10), end = Read(collection, 0x14);
if (!begin || end < begin || (end - begin) % 4 || (end - begin) / 4 > 4096) {
return 0;
}

uint32_t result = 0;
bool matched = false;

for (uint32_t at = begin; at < end; at += 4) {
uint32_t node = Read(at);
const uint32_t wrapped = Virtual(node, 0x34);

if (wrapped) {
node = Read(Read(wrapped, 0xC), 8);

if (!node) {
node = Read(wrapped, 0x10);
}
}

char name[256]{};

if (!Name(node, "Key", name, sizeof name) || _stricmp(name, key)) {
continue;
}

if (matched) {
return 0; // ambiguous Key: refuse rather than choose a definition by collection order
}

matched = true;
result = Virtual(node, 0x5C);
}

return result && Reference(result, true) ? result : 0;
}

bool Apply(uint32_t object, uint32_t player) {
const uintptr_t entry = g_apply.Entry();
const uint32_t manager = Read(static_cast<uint32_t>(g_rsxr_tone_manager));
if (!entry || !g_applyDone.Entry() || !g_rsxr_tone_apply || !object || !manager || player >= 2) {
return false;
}

const Bridge previous = g_bridge;
bool applied = false;

g_bridge.definition = object;

__try {
applied = reinterpret_cast<uint8_t(__stdcall*)(uint32_t, uint32_t, uint32_t)>(entry)(manager, player, 3) != 0;
} __except (Rsxr_FaultFilter(GetExceptionCode())) {
applied = false;
}

g_bridge = previous;

return applied;
}

uint32_t Override(uint32_t player, uint32_t slot) {
const char* extension = SlotExtension(slot);
if (player >= 2 || !extension) {
return 0;
}

// CONFIRMED: 0x41B310 resolves CustomTone/<decimal player> from manager+14h's context at +20h.
// Stock playback 0x464BDD and registration 0x7E9B83 then resolve the slot member through +18h/+5Ch.
uint32_t context = Read(Read(Read(static_cast<uint32_t>(g_rsxr_tone_context)), 0x14), 0x20);

context = Virtual(Member(context, "CustomTone", 0x18), 0x5C);
const char playerKey[2] = {static_cast<char>('0' + player), 0};

context = Virtual(Member(context, playerKey, 0x18), 0x5C);
char property[64]{};

strcpy_s(property, "LAS_ToneCustomData_");
strcat_s(property, extension);
const uint32_t object = Virtual(Member(context, property, 0x18), 0x5C);

return object && Reference(object, true) ? object : 0;
}
} // namespace rsxrtones
Loading
Loading