commit 70fda5d8f7c687776adaa82c600bf60c3129d452
parent 8542a848638308b1bacbe4c85d796348a58be6ab
Author: anon <anon@example.com>
Date: Sat, 24 Oct 2026 11:15:27 +0000
Persist native Knowledge references in browser storage
Diffstat:
10 files changed, 354 insertions(+), 37 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -739,10 +739,20 @@ and unresolved indoor lifecycle are explicit in [flight](docs/vehicles.md#yalmah
Soldier/Militiaman, including injected mode bytes 1 and 141 with restoration.
See [player information](docs/character-info.md), `local/reference-debug/`
and `local/reference-research/mode.md`.
-- [ ] Persist Knowledge references in the browser using the original native
+- [x] Persist Knowledge references in the browser using the original native
format and save timing. Check: player references and their descriptions
- survive reload/reconnect and remain separate between characters. The verified
- Friends entry survives reload, but its source Knowledge reference disappears.
+ survive reload/reconnect and remain separate between characters. Native
+ `References.bin` now uses per-character browser storage. Requested updates
+ to an existing description save through the original serializer too, since
+ reload skips native shutdown. Hardware WASM checks cover creation, updated
+ text, page/browser/server restarts, same-origin character isolation and
+ native right-hold/Remove followed by reload. Native format/ABI regressions
+ and browser storage stages cover the new persistence boundaries. See
+ [Knowledge storage](docs/character-info.md#knowledge-storage).
+- [ ] Extend native Knowledge-file regressions. Check: item/NPC records,
+ 20/21-record load boundaries, 1024-byte text limits, truncated/invalid files
+ and failed writes follow the original parser and save behavior; loading
+ never accidentally saves or loses an already loaded prefix.
- [ ] Ignore one player. Check: the supported chat channels honor the saved
ignore entry and removing it restores delivery.
- [ ] Recover original channel flags, preferences and flood rules. Check: native
diff --git a/client/Makefile.linux b/client/Makefile.linux
@@ -172,6 +172,7 @@ test: build/linux/window build/linux/graphics build/linux/atoi build/linux/stric
./build/linux/native-input
./build/linux/team-header
./build/linux/character-reference
+ ./build/linux/reference-persistence
./build/linux/weapon-range
./build/linux/ip-training
./build/linux/fling-result
@@ -688,3 +689,9 @@ build/linux/character-reference: tests/character_reference.c game/ddr.dll/lifted
$(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@
test: build/linux/character-reference
+
+build/linux/reference-persistence: tests/reference_persistence.c game/or.dll/lifted-0000.c runtime/guest_msvcp.c runtime/guest_heap.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h runtime/guest_msvcp.h runtime/guest_heap.h
+ @mkdir -p $(@D)
+ $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -pthread -lm -o $@
+
+test: build/linux/reference-persistence
diff --git a/client/Makefile.wasm b/client/Makefile.wasm
@@ -236,3 +236,7 @@ build/wasm/inflate-fast.js: tests/inflate_fast.c game/bbr.dll/lifted-0044.c runt
build/wasm/character-reference.js: tests/character_reference.c game/ddr.dll/lifted-0030.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h
@mkdir -p $(@D)
$(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@
+
+build/wasm/reference-persistence.js: tests/reference_persistence.c game/or.dll/lifted-0000.c runtime/guest_msvcp.c runtime/guest_heap.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h runtime/guest_msvcp.h runtime/guest_heap.h
+ @mkdir -p $(@D)
+ $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@
diff --git a/client/game/or.dll/lifted-0000.c b/client/game/or.dll/lifted-0000.c
@@ -1833,6 +1833,10 @@ void sub_3F001A80(void) {
uint32_t _itail_tgt = 0;
RECOMP_REGS_LOCALS
RECOMP_ENTER(0x3F001A80u);
+#ifdef __EMSCRIPTEN__
+ /* The duplicate-text path reuses the save argument as its string length. */
+ int save_updated_reference = MEM8(esp + 12);
+#endif
L_3F001A80:
PUSH32(esp, ebp); /* 0x3F001A80: push ebp */
@@ -1954,16 +1958,7 @@ L_3F001B2D:
ecx = ebx; /* 0x3F001B42: mov ecx, ebx */
RECOMP_ICALL(MEM32(0x3F004008)); /* 0x3F001B44: call dword ptr [0x3f004008] */
RECOMP_FLAGS_IN();
- edx = MEM32(ebp + (-0x18)); /* 0x3F001B4A: mov edx, dword ptr [ebp - 0x18] */
- edi = POP32_VAL(esp); /* 0x3F001B4D: pop edi */
- esi = POP32_VAL(esp); /* 0x3F001B4E: pop esi */
- ebx = POP32_VAL(esp); /* 0x3F001B4F: pop ebx */
- eax = MEM32(edx + 0xC); /* 0x3F001B50: mov eax, dword ptr [edx + 0xc] */
- ecx = MEM32(ebp + (-0xC)); /* 0x3F001B53: mov ecx, dword ptr [ebp - 0xc] */
- MEM32(FS_BASE + (0)) = ecx; /* 0x3F001B56: mov dword ptr fs:[0], ecx */
- esp = ebp; /* 0x3F001B5D: mov esp, ebp */
- ebp = POP32_VAL(esp); /* 0x3F001B5F: pop ebp */
- RECOMP_FLAGS_OUT(); esp += 16; { RECOMP_REGS_OUT(); return; } /* 0x3F001B60: ret 0xc */
+ goto L_3F001BFF;
L_3F001B63:
/* test edi, edi */ /* 0x3F001B63: test edi, edi */
_flag_a = (uint32_t)(edi); _flag_b = (uint32_t)(edi);
@@ -2014,17 +2009,8 @@ L_3F001B93:
_flag_a = (uint32_t)(LO8(ecx)) << 24; _flag_b = (uint32_t)(1) << 24;
SET_LO8(ecx, LO8(ecx) + 1); /* 0x3F001BA5: inc cl */
_flag_k = FK_NARROW(FK_INC, 24);
- edi = POP32_VAL(esp); /* 0x3F001BA7: pop edi */
MEM8(eax + (-0x1)) = (uint8_t)(LO8(ecx)); /* 0x3F001BA8: mov byte ptr [eax - 1], cl */
- edx = MEM32(ebp + (-0x18)); /* 0x3F001BAB: mov edx, dword ptr [ebp - 0x18] */
- esi = POP32_VAL(esp); /* 0x3F001BAE: pop esi */
- ebx = POP32_VAL(esp); /* 0x3F001BAF: pop ebx */
- eax = MEM32(edx + 0xC); /* 0x3F001BB0: mov eax, dword ptr [edx + 0xc] */
- ecx = MEM32(ebp + (-0xC)); /* 0x3F001BB3: mov ecx, dword ptr [ebp - 0xc] */
- MEM32(FS_BASE + (0)) = ecx; /* 0x3F001BB6: mov dword ptr fs:[0], ecx */
- esp = ebp; /* 0x3F001BBD: mov esp, ebp */
- ebp = POP32_VAL(esp); /* 0x3F001BBF: pop ebp */
- RECOMP_FLAGS_OUT(); esp += 16; { RECOMP_REGS_OUT(); return; } /* 0x3F001BC0: ret 0xc */
+ goto L_3F001BFF;
L_3F001BC3:
PUSH32(esp, 1); /* 0x3F001BC3: push 1 */
PUSH32(esp, edi); /* 0x3F001BC5: push edi */
@@ -2064,6 +2050,14 @@ L_3F001BDF:
MEM32(ebx + 0x8) = eax; /* 0x3F001BF8: mov dword ptr [ebx + 8], eax */
MEM8(ecx + eax) = (uint8_t)(0); /* 0x3F001BFB: mov byte ptr [ecx + eax], 0 */
L_3F001BFF:
+#ifdef __EMSCRIPTEN__
+ /* Reloading a browser skips the game-prefs destructor that saves updates. */
+ if (save_updated_reference) {
+ ecx = MEM32(ebp + (-0x1C));
+ RECOMP_ICALL(0x3F002580u);
+ RECOMP_FLAGS_IN();
+ }
+#endif
edx = MEM32(ebp + (-0x18)); /* 0x3F001BFF: mov edx, dword ptr [ebp - 0x18] */
edi = POP32_VAL(esp); /* 0x3F001C02: pop edi */
esi = POP32_VAL(esp); /* 0x3F001C03: pop esi */
diff --git a/client/runtime/browser_host.c b/client/runtime/browser_host.c
@@ -15,7 +15,7 @@
char *ao_asset_base_url(void);
void ao_asset_manifest_js(em_proxying_ctx *context, void *request);
char *ao_asset_manifest_parse(const char *json);
-char *browser_icon_positions_directory(const char *base);
+char *browser_preferences_directory(const char *base);
static char *ao_asset_manifest(const char *base)
{
@@ -136,16 +136,19 @@ void browser_initialize(unsigned character_id)
assert(fclose(character_preferences) == 0);
assert(rename("Prefs/visitor.cfg", character_path) == 0);
- /* Keep first-run state and native icon positions across browser reloads. */
+ /* Keep native character preferences across browser reloads. */
backend_t persistent = wasmfs_create_opfs_backend();
assert(wasmfs_create_directory("/persistent", 0755, persistent) == 0);
- char *directory = browser_icon_positions_directory(base);
+ char *directory = browser_preferences_directory(base);
free(base);
assert(mkdir(directory, 0755) == 0 || errno == EEXIST);
char persistent_path[4096];
- for (int i = 0; i < 2; ++i) {
- snprintf(persistent_path, sizeof(persistent_path), "%s/%u.%s", directory, character_id, i == 0 ? "cfg" : "bin");
- snprintf(character_path, sizeof(character_path), "Prefs/localtest/Char%u/%s", character_id, i == 0 ? "Char.cfg" : "IconPositions.bin");
+ const struct { const char *name, *suffix; } files[] = {
+ {"Char.cfg", "cfg"}, {"IconPositions.bin", "bin"}, {"References.bin", "refs"},
+ };
+ for (unsigned i = 0; i < sizeof(files) / sizeof(files[0]); ++i) {
+ snprintf(persistent_path, sizeof(persistent_path), "%s/%u.%s", directory, character_id, files[i].suffix);
+ snprintf(character_path, sizeof(character_path), "Prefs/localtest/Char%u/%s", character_id, files[i].name);
int saved = open(persistent_path, O_CREAT | O_EXCL | O_WRONLY, 0600);
if (saved >= 0) {
FILE *original = fopen(character_path, "rb");
diff --git a/client/runtime/browser_host.js b/client/runtime/browser_host.js
@@ -1,6 +1,6 @@
addToLibrary({
- browser_icon_positions_directory__deps: ['$UTF8ToString', '$stringToNewUTF8'],
- browser_icon_positions_directory: base => stringToNewUTF8('/persistent/' + encodeURIComponent(UTF8ToString(base))),
+ browser_preferences_directory__deps: ['$UTF8ToString', '$stringToNewUTF8'],
+ browser_preferences_directory: base => stringToNewUTF8('/persistent/' + encodeURIComponent(UTF8ToString(base))),
$AOAssetRequest: async (url, options) => {
let delay = 1000;
for (;;) {
diff --git a/client/tests/browser_storage.c b/client/tests/browser_storage.c
@@ -115,6 +115,42 @@ static void icon_positions_survive_reload(unsigned character_id)
assert(fclose(file) == 0);
}
+static void references_survive_reload(unsigned character_id, int resume)
+{
+ char path[128];
+ snprintf(path, sizeof(path), "Prefs/localtest/Char%u/References.bin", character_id);
+ const unsigned char first[] = {0,0,3,235, 0,0,0,1, 0,0,0,0, 0,0,195,80, 0,0,0,53, 0,0,0,3, 'o','n','e'};
+ const unsigned char other[] = {0,0,3,235, 0,0,0,1, 0,0,0,0, 0,0,195,80, 0,0,0,54, 0,0,0,3, 't','w','o'};
+ const unsigned char empty[] = {0,0,3,235, 0,0,0,0};
+ int cleared = MAIN_THREAD_EM_ASM_INT({ return new URLSearchParams(location.search).has('empty'); });
+ const unsigned char *expected = cleared ? empty : character_id == 42 ? first : other;
+ size_t length = cleared ? sizeof(empty) : sizeof(first);
+ unsigned char actual[32] = {0};
+ FILE *file = fopen(path, "rb");
+ assert(file);
+
+ size_t size = fread(actual, 1, sizeof(actual), file);
+ assert(!ferror(file));
+ assert(fclose(file) == 0);
+
+ if (resume) {
+ assert(size == length && !memcmp(actual, expected, length));
+ } else {
+ assert(size == 0);
+ file = fopen(path, "wb");
+ assert(file && fwrite(expected, 1, length, file) == length);
+ assert(fclose(file) == 0);
+ }
+
+ /* Native deletion rewrites the file, including truncating old records. */
+ int clear = MAIN_THREAD_EM_ASM_INT({ return new URLSearchParams(location.search).has('clear'); });
+ if (clear) {
+ file = fopen(path, "wb");
+ assert(file && fwrite(empty, 1, sizeof(empty), file) == sizeof(empty));
+ assert(fclose(file) == 0);
+ }
+}
+
int main(void)
{
unsigned character_id = MAIN_THREAD_EM_ASM_INT({
@@ -144,6 +180,7 @@ int main(void)
}
preferences_use_canvas_dimensions();
icon_positions_survive_reload(character_id);
+ if (!pending) references_survive_reload(character_id, resume);
replace_occlusion_cache();
create_occlusion_cache();
read_across_asset_chunk();
@@ -152,4 +189,5 @@ int main(void)
puts("PASS: private preferences use the canvas dimensions");
puts("PASS: native first-run state and character preference edits persist");
puts("PASS: native icon positions use persistent browser storage");
+ puts("PASS: native references persist with character isolation and deletion");
}
diff --git a/client/tests/reference_persistence.c b/client/tests/reference_persistence.c
@@ -0,0 +1,201 @@
+#include "recomp_types.h"
+#include "guest_msvcp.h"
+#include <assert.h>
+
+void sub_3F001A80(void);
+void sub_3F002580(void);
+void sub_3F002C30(void);
+
+static unsigned save_count, written;
+enum input_kind { SHARED_TEXT, FROZEN_TEXT, SAME_OBJECT, INVALID_IDENTITY };
+static uint32_t file_object, error_handler;
+static unsigned char bytes[2048];
+
+/* Observe only File_t boundaries; actual OR decides the serialized fields. */
+static void permissions(void)
+{
+ assert(!strcmp((char *)ADDR(MEM32(g_esp + 4)), "Prefs/fixture/References.bin"));
+ assert(MEM32(g_esp + 8) == 0600);
+ g_eax = 0; g_edx = 0xdeadbeef; g_esp += 4;
+}
+
+static void file_ctor(void)
+{
+ assert(!strcmp((char *)ADDR(MEM32(g_esp + 4)), "Prefs/fixture/References.bin"));
+ file_object = g_ecx;
+ g_eax = file_object; g_edx = 0xdeadbeef; g_esp += 8;
+}
+
+static void set_handler(void)
+{
+ uint32_t previous = error_handler;
+ error_handler = MEM32(g_esp + 4);
+ g_eax = previous; g_edx = 0xdeadbeef; g_esp += 4;
+}
+
+static void file_open(void)
+{
+ assert(g_ecx == file_object && MEM32(g_esp + 4) == 2);
+ save_count++;
+ written = 0;
+ g_eax = 0; g_edx = 0xdeadbeef; g_esp += 8;
+}
+
+static void write_u32(void)
+{
+ assert(g_ecx == file_object && MEM32(g_esp + 8) == 0);
+ uint32_t value = MEM32(g_esp + 4);
+ assert(written + 4 <= sizeof(bytes));
+ bytes[written++] = value >> 24; bytes[written++] = value >> 16;
+ bytes[written++] = value >> 8; bytes[written++] = value;
+ g_eax = 0; g_edx = 0xdeadbeef; g_esp += 12;
+}
+
+static void write_bytes(void)
+{
+ assert(g_ecx == file_object);
+ unsigned length = MEM32(g_esp + 8);
+ assert(written + length <= sizeof(bytes));
+ if (length) memcpy(bytes + written, (void *)ADDR(MEM32(g_esp + 4)), length);
+ written += length;
+ g_eax = 0; g_edx = 0xdeadbeef; g_esp += 12;
+}
+
+static void file_dtor(void)
+{
+ assert(g_ecx == file_object);
+ g_eax = 0; g_edx = 0xdeadbeef; g_esp += 4;
+}
+
+recomp_func_t recomp_lookup(uint32_t address)
+{
+ switch (address) {
+ case 0x3f001a80: return sub_3F001A80;
+ case 0x3f002580: return sub_3F002580;
+ case 0x3f002c30: return sub_3F002C30;
+ case 0x70000000: return permissions;
+ case 0x70000004: return file_ctor;
+ case 0x70000008: return set_handler;
+ case 0x7000000c: return file_open;
+ case 0x70000010: return write_u32;
+ case 0x70000014: return write_bytes;
+ case 0x70000018: return file_dtor;
+ case 0x70000020: return guest_msvcp_lookup("?_Tidy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEX_N@Z");
+ case 0x70000024: return guest_msvcp_lookup("?_Grow@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAE_NI_N@Z");
+ case 0x70000028: return guest_msvcp_lookup("?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z");
+ default: fprintf(stderr, "unexpected replacement fixture call %08x\n", address); abort();
+ }
+}
+recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
+recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
+
+static void seed(void)
+{
+ memset((void *)ADDR(0x50000000), 0, 0x1000);
+ MEM32(0x50000004) = 0x50000200;
+ MEM32(0x50000008) = 8;
+ strcpy((char *)ADDR(0x5000000c), "Prefs/fixture/References.bin");
+ MEM32(0x50000204) = 0x50000300;
+ MEM32(0x50000208) = 0x50000340;
+ MEM32(0x50000210) = 1;
+ MEM32(0x50000300) = MEM32(0x50000304) = MEM32(0x50000308) = 0x50000380;
+ MEM8(0x50000315) = 1;
+ MEM8(0x50000355) = 1;
+ MEM32(0x50000380) = MEM32(0x50000388) = 0x50000340;
+ MEM32(0x50000384) = 0x50000300;
+ MEM32(0x5000038c) = 7;
+ MEM32(0x50000390) = 0x50000400;
+ MEM32(0x50000404) = 53019;
+ MEM32(0x50000408) = 7;
+ MEM32(0x5000040c) = 50000;
+ MEM32(0x50000410) = 50;
+ MEM32(0x5000041c) = 0x50000480;
+ guest_msvcp_assign_host(0x50000480, "before");
+ MEM32(0x50000600) = 50000;
+ MEM32(0x50000604) = 50;
+ save_count = written = 0;
+ error_handler = 0x12345678;
+ g_fs_base = 0x5000f000;
+ MEM32(g_fs_base) = 0x23456789;
+}
+
+static void release_string(uint32_t object)
+{
+ g_esp = 0x5000ff00; g_ecx = object;
+ guest_msvcp_lookup("??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ")();
+}
+
+static void test_replacement(const char *text, int save, enum input_kind kind)
+{
+ seed();
+ uint32_t input = kind == SAME_OBJECT ? 0x50000480 : 0x50000500;
+ if (kind != SAME_OBJECT) guest_msvcp_assign_host(input, text);
+ if (kind == FROZEN_TEXT) MEM8(MEM32(input + 4) - 1) = 255;
+ if (kind == INVALID_IDENTITY) MEM32(0x50000600) = MEM32(0x50000604) = 0;
+ const char *expected = kind == INVALID_IDENTITY || kind == SAME_OBJECT ? "before" : text;
+ unsigned expected_length = strlen(expected);
+ uint32_t input_data = MEM32(input + 4);
+ g_esp = 0x5000fe00; g_ecx = 0x50000000;
+ g_ebx = 0x12345678; g_esi = 0x23456789; g_edi = 0x3456789a; g_ebp = 0x456789ab;
+ MEM32(g_esp) = 0;
+ MEM32(g_esp + 4) = 0x50000600;
+ MEM32(g_esp + 8) = input;
+ MEM32(g_esp + 12) = save;
+
+ sub_3F001A80();
+
+ assert(g_eax == (kind == INVALID_IDENTITY ? 0 : 7));
+ assert(g_esp == 0x5000fe10 && MEM32(g_fs_base) == 0x23456789);
+ assert(g_ebx == 0x12345678 && g_esi == 0x23456789 && g_edi == 0x3456789a && g_ebp == 0x456789ab);
+ assert(MEM32(0x50000210) == 1 && MEM32(0x50000008) == 8);
+ assert(MEM32(0x5000038c) == 7 && MEM32(0x50000404) == 53019 && MEM32(0x50000408) == 7);
+ assert(MEM32(0x5000040c) == 50000 && MEM32(0x50000410) == 50);
+ assert(MEM32(0x50000488) == expected_length);
+ uint32_t result_data = MEM32(0x50000484);
+ if (expected_length) assert(!memcmp((void *)ADDR(result_data), expected, expected_length + 1));
+ if (kind == SHARED_TEXT && expected_length) {
+ assert(result_data == input_data && MEM8(result_data - 1) == 1);
+ }
+ unsigned expected_saves = save && kind != INVALID_IDENTITY;
+#ifndef __EMSCRIPTEN__
+ expected_saves = 0;
+#endif
+ assert(save_count == expected_saves);
+ if (save_count) {
+ const unsigned char prefix[] = {0,0,3,235, 0,0,0,1, 0,0,0,0, 0,0,195,80, 0,0,0,50};
+ assert(written == 24 + expected_length && !memcmp(bytes, prefix, sizeof(prefix)));
+ assert(bytes[20] == 0 && bytes[21] == 0 && bytes[22] == (expected_length >> 8) && bytes[23] == (expected_length & 255));
+ assert(!memcmp(bytes + 24, expected, expected_length));
+ assert(error_handler == 0x12345678);
+ }
+ release_string(0x50000480);
+ if (kind != SAME_OBJECT) release_string(input);
+}
+
+int main(void)
+{
+ assert(guest_map("reference replacement fixture", 0x50000000, 0x10000));
+ assert(guest_map("OR imports", 0x3f000000, 0x10000));
+ MEM32(0x3f004070) = 0x70000000;
+ MEM32(0x3f00406c) = 0x70000004;
+ MEM32(0x3f004074) = 0x70000008;
+ MEM32(0x3f004084) = 0x7000000c;
+ MEM32(0x3f00407c) = 0x70000010;
+ MEM32(0x3f004078) = 0x70000014;
+ MEM32(0x3f004080) = 0x70000018;
+ MEM32(0x3f004018) = 0x70000020;
+ MEM32(0x3f004030) = 0x70000024;
+ MEM32(0x3f004008) = 0x70000028;
+ MEM32(0x3f004010) = 0x5000b000; MEM32(0x5000b000) = 0xffffffff;
+ MEM32(0x3f004028) = 0x5000b100; MEM8(0x5000b0ff) = 255;
+ test_replacement("updated shared", 1, SHARED_TEXT);
+ test_replacement("deferred shared", 0, SHARED_TEXT);
+ test_replacement("", 1, SHARED_TEXT);
+ test_replacement("", 0, SHARED_TEXT);
+ test_replacement("frozen copied", 1, FROZEN_TEXT);
+ test_replacement("deferred copied", 0, FROZEN_TEXT);
+ test_replacement("", 1, SAME_OBJECT);
+ test_replacement("", 0, SAME_OBJECT);
+ test_replacement("ignored", 1, INVALID_IDENTITY);
+ puts("reference descriptions: shared, copied, empty and same-object saves, deferred loads, native bytes and ABI passed");
+}
diff --git a/docs/character-info.md b/docs/character-info.md
@@ -82,6 +82,44 @@ inspection needs further verification and reconstruction of the common hit
timeline; this feature does not introduce a fabricated stop or alternate
packet to hide it.
+## Knowledge storage
+
+The original OR `RefMan_t` owns Knowledge entries. OOR's
+`Preferences::OpenGamePrefs` 0x10001c40 constructs it with the character's
+`Prefs/<login>/Char<id>` path and a load limit of 20. The reference manager
+appends `References.bin`. DDR's Knowledge-view constructor loads that file;
+the window itself does not own shutdown persistence.
+
+OR `RefMan_t::Save` 0x10002580 writes big-endian u32 version 1003 and record
+count, then records ordered by their local reference IDs:
+
+| Subtype | Body, following the u32 subtype |
+| --- | --- |
+| 0, character | Source identity type/ID, text byte length, text bytes |
+| 1, item | Three u32 values passed to native `AddItemRef` |
+| 2, NPC | Source identity type/ID, two extra u32 values, text byte length, text bytes |
+
+Text has no terminating NUL and native reference strings retain at most 1024
+bytes. Local reference IDs are not serialized; loading rebuilds them from 1.
+The loader accepts an empty file, requires version 1003 for populated files,
+and loads at most the configured 20 records. That is a load limit, not a new
+server-side creation limit or an additional format version.
+
+New references and successful deletion already save immediately when requested.
+Replacing an existing character reference updates its description but normally
+waits for a later mutation or `Preferences::CloseGamePrefs`. Browser reloads
+skip that shutdown. The WASM build therefore calls the unchanged native Save
+after a requested description replacement too. All three string paths share
+this exit; the original save flag is captured before its stack slot is reused
+for text length. Load-time additions with save=false remain deferred.
+
+`browser_initialize` links the native file to `<character-id>.refs` beside the
+existing config and icon-position files in origin-private storage, under the
+server asset URL. The native serializer and loader read and write those bytes
+directly. Other preference files remain in memory. Complete original exports,
+matching snapshots and the save/loader evidence ledger are retained in
+`local/knowledge-research/persistence.md`.
+
## Verification
Go regressions cover exact native bytes, real world-socket dispatch, self and
@@ -136,8 +174,28 @@ descriptions and were restored after rendering. These are mode fault-injection
checks, not an end-to-end shop transaction test. The normal published bundle
contains no diagnostic tracing and produced no adapter or page errors.
-Knowledge references still disappear on browser reload; only the resulting
-Friends entry is durable. This remains tracked in TODO. Runtime artifacts and
-diagnostic commands are in `local/reference-smoke/`, `local/reference-debug/`
-and `local/reference-research/`. `mode.md` retains the original constructor,
+Reference-persistence regressions exercise the actual native duplicate search,
+Save and map iterator with the production string/heap adapters. Shared, copied,
+empty and same-object descriptions cover requested and deferred saves; invalid
+identities leave state unchanged. Assertions check exact native bytes, IDs,
+counts, sharing, exception-chain restoration and guest ABI. File operations are
+asserted sinks; separate browser storage stages check actual reloads, isolation
+between character IDs and truncation after deletion, alongside the existing
+config/icon-position tests. Native load error paths, item/NPC records and the
+20-record boundary need further automated coverage.
+
+Hardware Chromium checks created a player reference, reloaded its description,
+then changed that same character from level-1 Soldier to level-150 Engineer.
+The existing reference updated without duplication; its new text survived page,
+browser and preview-server restarts. Switching two characters in one browser
+profile kept their lists and files separate. Holding right over the icon and
+releasing over the radial menu's Remove reference action rewrote the first
+file to version 1003/count 0; reload retained the deletion and left the other
+character's reference bytes unchanged. The final bundle reported no adapter or
+page errors. Captured native files and decoded records are retained in
+`local/knowledge-smoke/`.
+
+Runtime artifacts and diagnostic commands are in `local/reference-smoke/`,
+`local/reference-debug/`, `local/knowledge-smoke/` and
+`local/reference-research/`. `mode.md` retains the original constructor,
mode-writer, renderer-caller and callback ABI evidence.
diff --git a/docs/inventory.md b/docs/inventory.md
@@ -157,8 +157,10 @@ change. Browser builds save that completed map immediately, since page reloads
skip the native shutdown destructor that ordinarily saves it.
`browser_initialize` in `client/runtime/browser_host.c` links this native binary
-file and `Char.cfg` to the browser's origin-private filesystem. The directory is
-keyed by the server asset URL; character ID selects the `.bin` and `.cfg` files.
+file, `Char.cfg` and `References.bin` to the browser's origin-private filesystem.
+The directory is keyed by the server asset URL; character ID selects the
+`.bin`, `.cfg` and `.refs` files. Knowledge storage is described in
+[player references](character-info.md#knowledge-storage).
Other preferences and occlusion caches keep their existing in-memory behavior.
Existing bytes are preserved. A missing icon-position file starts empty; a new
character config enables native first-run initialization with tips disabled.