aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 55221305f42639a8369c32b25295a780d266f707
parent 2cd836b42e068e5f80483a7316ee2f441bef8c2a
Author: anon <anon@example.com>
Date:   Fri, 23 Oct 2026 13:13:11 +0000

Restore native starter actions and persist first-run preferences

Diffstat:
MTODO.md | 6+++---
Mclient/runtime/browser_host.c | 42++++++++++++++++++++++--------------------
Mclient/tests/browser_storage.c | 16++++++++++++++--
Mdocs/client-behavior.md | 3+++
Mdocs/inventory.md | 37+++++++++++++++++++++++++++++++------
5 files changed, 73 insertions(+), 31 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -275,11 +275,11 @@ checks are recorded in [treatment kits](docs/treatment-kit.md). reconnect and are rendered consistently to another player. - [ ] Grant one profession's starter loadout. Check: a new character receives the expected items once; reconnecting does not grant another set. -- [ ] Populate a new player's action bar with the default actions. Check: a +- [x] Populate a new player's action bar with the default actions. Check: a fresh character's native action bar contains the appropriate starter actions on first login; reconnecting preserves the layout and existing player edits. - Check the existing shortcut/preferences initialization and loading paths: - earlier test characters appeared to have defaults, so this may be a regression. + The native first-run flag and icon-position map persist together; see + [starter shortcuts and native preferences](docs/inventory.md#native-visual-order). ## Shops diff --git a/client/runtime/browser_host.c b/client/runtime/browser_host.c @@ -114,7 +114,7 @@ void browser_initialize(unsigned character_id) } } free(manifest); - /* Each browser visitor starts with character tips disabled. */ + /* Seed native first-run preferences; persistent character files take precedence. */ char character_path[128]; snprintf(character_path, sizeof(character_path), "Prefs/localtest/Char%u", character_id); assert(mkdir(character_path, 0755) == 0 || errno == EEXIST); @@ -132,35 +132,37 @@ void browser_initialize(unsigned character_id) assert(!ferror(original)); fclose(original); } - fputs("IsFirstTime 0\nIsTipEnabled 0\n", character_preferences); + fputs("IsFirstTime 1\nIsTipEnabled 0\n", character_preferences); assert(fclose(character_preferences) == 0); assert(rename("Prefs/visitor.cfg", character_path) == 0); - /* Keep the native icon-position file across reloads without persisting caches. */ + /* Keep first-run state and native icon positions 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); free(base); assert(mkdir(directory, 0755) == 0 || errno == EEXIST); char persistent_path[4096]; - snprintf(persistent_path, sizeof(persistent_path), "%s/%u.bin", directory, character_id); + 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"); + int saved = open(persistent_path, O_CREAT | O_EXCL | O_WRONLY, 0600); + if (saved >= 0) { + FILE *original = fopen(character_path, "rb"); + if (original) { + unsigned char buffer[8192]; + size_t size; + while ((size = fread(buffer, 1, sizeof(buffer), original))) + assert(write(saved, buffer, size) == (ssize_t)size); + assert(!ferror(original)); + fclose(original); + } else assert(errno == ENOENT); + assert(close(saved) == 0); + } else assert(errno == EEXIST); + assert(unlink(character_path) == 0 || errno == ENOENT); + assert(symlink(persistent_path, character_path) == 0); + } free(directory); - snprintf(character_path, sizeof(character_path), "Prefs/localtest/Char%u/IconPositions.bin", character_id); - int saved = open(persistent_path, O_CREAT | O_EXCL | O_WRONLY, 0600); - if (saved >= 0) { - FILE *original = fopen(character_path, "rb"); - if (original) { - unsigned char buffer[8192]; - size_t size; - while ((size = fread(buffer, 1, sizeof(buffer), original))) - assert(write(saved, buffer, size) == (ssize_t)size); - assert(!ferror(original)); - fclose(original); - } else assert(errno == ENOENT); - assert(close(saved) == 0); - } else assert(errno == EEXIST); - assert(unlink(character_path) == 0 || errno == ENOENT); - assert(symlink(persistent_path, character_path) == 0); /* Start the guest with the viewport size, including nonstandard aspect ratios. */ int width, height; diff --git a/client/tests/browser_storage.c b/client/tests/browser_storage.c @@ -129,7 +129,19 @@ int main(void) char content[128] = {0}; assert(fread(content, 1, sizeof(content) - 1, preferences) == 29); fclose(preferences); - assert(!strcmp(content, "IsFirstTime 0\nIsTipEnabled 0\n")); + int resume = MAIN_THREAD_EM_ASM_INT({ + return new URLSearchParams(location.search).has('resume'); + }); + assert(!strcmp(content, resume ? "IsFirstTime 0\nIsTipEnabled 1\n" : "IsFirstTime 1\nIsTipEnabled 0\n")); + int pending = MAIN_THREAD_EM_ASM_INT({ + return new URLSearchParams(location.search).has('pending'); + }); + if (!resume && !pending) { + preferences = fopen(path, "w"); + assert(preferences); + assert(fputs("IsFirstTime 0\nIsTipEnabled 1\n", preferences) >= 0); + assert(fclose(preferences) == 0); + } preferences_use_canvas_dimensions(); icon_positions_survive_reload(character_id); replace_occlusion_cache(); @@ -138,6 +150,6 @@ int main(void) puts("PASS: browser occlusion caches preserve assets and support writes"); puts("PASS: asset reads preserve bytes across the 1 MiB boundary"); puts("PASS: private preferences use the canvas dimensions"); - puts("PASS: visitor preferences disable first-run tutorials and tips"); + puts("PASS: native first-run state and character preference edits persist"); puts("PASS: native icon positions use persistent browser storage"); } diff --git a/docs/client-behavior.md b/docs/client-behavior.md @@ -94,6 +94,9 @@ than character stats or a server setting: - `IsTipEnabled`: per-character preference (type 2), read by ddr.dll at `0x1008c743`. Setting it to 0 disables character tips. - `IsFirstTime`: per-character preference (type 2), read at `0x100778d2`. + It initializes the level-1 toolbar's starter actions, then saves itself as 0. + Disabling it to suppress tutorials also suppresses those actions; tips can + instead be disabled independently with `IsTipEnabled`. - `ShowTipOfTheDay`: login preference (type 1), read at `0x1001278c`. For account `localtest` and character 1, these are stored in diff --git a/docs/inventory.md b/docs/inventory.md @@ -133,12 +133,37 @@ Its logical server slot remains unchanged. 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 only this native -binary file to the browser's origin-private filesystem. The directory is keyed -by the server asset URL and the filename by character ID. Other preferences and -occlusion caches keep their existing in-memory behavior. Existing icon-position -bytes are preserved; a missing file starts empty. Native loads and saves use the -same file format and the same logical item identities. +`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. +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. +Native loads and saves use the same formats and logical identities. + +The native toolbar initializer in ddr.dll at `0x100777a0` reads `IsFirstTime`. +For a level below 2, it adds action identities `(57008,49573)`, `(57008,49571)`, +`(57008,49577)` and `(57008,49576)` at positions 0..3, and `(57008,82212)` at +position 9. It then saves `IsFirstTime=0`. Persisting this flag lets the native +client initialize once and retain subsequent edits, including an intentionally +empty bar. Toolbar mutation notification `0x10077cd0` already saves the native +icon-position file; the browser does not need a separate shortcut format or +replacement initializer. + +The native icons are Start Combat, Use, Walk/Run, Sit/Stand and Exit. Browser +storage regression checks cover pending first-run setup, completed setup, +preference edits, reloads and isolation between two character IDs. WASM controls +activated Sit/Stand, moved Start Combat from slot 1 to slot 5, and retained that +layout after page, browser and server restarts with identical saved +icon-position bytes. A fresh second +character received the original five actions independently. + +Original ddr.dll SHA-256 is +`3c937161de8f690351c3c08e158431417cee9ced77a41b677e7123b61a8c9883`. +Retained first-run evidence is +`ev_6dd9f9797d1dd2ff426e5a988a917a058b1855e99c21933907d9b26c63e895bc`; +toolbar save notification is +`ev_4ca35e96918f1117cc583f02ac4bb2af9571f1e9afc36a8bb9a0010359a8c345`. The native fixture moved one pistol from visual cell 0 to cell 8, then verified cell 8 after page reload and a server restart. Its server ID, QL, logical slot