diff --git a/docs/remorse-windows-rebuild-roadmap.md b/docs/remorse-windows-rebuild-roadmap.md index 548fb34..998383f 100644 --- a/docs/remorse-windows-rebuild-roadmap.md +++ b/docs/remorse-windows-rebuild-roadmap.md @@ -26,7 +26,7 @@ The immediate target is a fresh game on retail map 1 at the original starting te 5. **Real interaction:** implement one reachable map-1 usecode event through the original item find/grab, VM dispatch, and resulting world-state mutation. Demonstrate a repeatable before/input/after trace and visible effect; a script lookup or release-request counter is not an interaction. 6. **Acceptance:** launch the normal Windows executable with retail data, start map 1 at egg `0x1e`, move and interact without a diagnostic shortcut, and verify on-screen state plus a deterministic integration test. Keep absent combat, audio, menus, persistence, and broader missions listed as limitations, not silently simulated features. -Current blocker: the normal host window resolves egg `0x1e` from map 1 and places host item 1 at that retail record, then routes queued input through host controller and animation processes that mutate the same live item. These are tested host models, not calls through `Game_Start`, `Teleporter_CreateProcessDirect`, or the original kernel loop. A test using the production-equivalent item search at the egg spawn found one candidate and no eligible `use` event. The BOX_NS effect test therefore still uses a fixture origin; a reachable target and original item/event dispatch remain open. Nearby panel/card scripts also require additional VM, timer, selector, and world-state services. +Current blocker: the normal host window resolves egg `0x1e` from map 1 and places host item 1 at that retail record, then routes queued input through host controller and animation processes that mutate the same live item. Startup now models the constructor's clear-stasis waiter and schedules the same-map teleporter over two kernel scans, but these remain host models, not calls through `Game_Start`, `Teleporter_CreateProcessDirect`, or the original scheduler. The ordinary host tick now also scans ready `Gravity` processes through the live-item collision sweep and requests a redraw when a falling item moves, including while the avatar is idle; this is not original scheduler parity. Idle ticks also consume pending usecode frame mutations and wake the renderer, rather than waiting for another movement input. The production-equivalent item search at the egg spawn still finds one candidate and no eligible `use` event. A retail scan finds 218 map-1 use-eligible items; the nearest is `PANELNS` item 288 at `(2919, 1061, 48)`, frame 0, quality 6, map-array 134, at horizontal Manhattan distance 8,818 staged-coordinate units from spawn `(6399, 6399, 0)`. Its recovered handler exits on frame 0 and nonzero map-array. A nearby `CARD_NS` at staged `(2783, 1055, 40)` has frame 0 and `QLo=6`; its `SWITCH::ordinal21` path needs keycard 6 to authorize the visible frame-4 state, and the fresh-game host keycard set is empty. The nearest chest candidate is `CHEST_EW` map-source record 151 at staged `(1087, 2559, 0)`, frame 0, `QLo=5`, 9,152 horizontal units from spawn. Its handler calls `FREE.slot_2d` to test a same-family legal swap to shape `0x054b`, then animates frames 0 through 4 and dispatches `TRIGGER` if the swap succeeds. The host currently lacks that shape-swap service, and no collision route from spawn to this chest has been verified. The nearest frame-0 `BOX_NS` is 18,048 staged-coordinate units away. The BOX_NS effect test remains fixture-origin coverage; no reachable retail interaction or original item/event dispatch is established. ## Current Inputs @@ -505,7 +505,7 @@ python rebuild/remorse/tools/import_export_slice.py classes/Remorse/EntityDispat - **Build foundation:** `remorse_core`, the Windows game, MSVC/CMake build entry point, and focused CTest targets are in place. - **Retail data:** loaders cover the resources used by the current map, rendering, item, and USECODE slices. The preview renderer and Win32 window remain diagnostic infrastructure. - **Process and world state:** partial scheduler/process behavior, staged item placement/search, and selected item-cache operations are compiled and tested. The host does not yet run the original game loop or item runtime. -- **Teleporter startup slice:** live Ghidra evidence confirms `TeleporterProcess` is `0x36` bytes, with vtable `0x0f3a`, target map at `+0x32`, and egg ID at `+0x34`. The host kernel owns this typed process and models its same-map run by resolving a family-8/frame-1 destination whose quality low byte matches the requested ID, then moving item 1. Map loading now creates, runs, and retires this process using a local kernel. It does not port `Game_Start`, temporary-stasis wait, cross-map camera/NPC setup, collision/fall, sound, or original scheduler dispatch. +- **Teleporter startup slice:** live Ghidra evidence confirms `TeleporterProcess` is `0x36` bytes, with vtable `0x0f3a`, target map at `+0x32`, and egg ID at `+0x34`. The host kernel owns this typed process and models its same-map run by resolving a family-8/frame-1 destination whose quality low byte matches the requested ID, then moving item 1. It also models the `0x33`-byte clear-avatar-stasis process and one wait dependency: the first scheduler scan clears prior stasis, and the next runs and retires the teleporter. A retail regression verifies item 1 stays at the origin until the wait completes, then reaches egg `0x1e`. This is not the original `Process_WaitFor` linked-list implementation or `Game_Start`; cross-map camera/NPC setup, collision/fall, sound, and original scheduler dispatch remain unported. - **USECODE:** class/event parsing, a tested opcode subset, task lifecycle, and bounded `CreateFromSlotIndex` context construction are implemented. The window's use request now searches nearby item candidates, applies owner-row event selection, creates a context-backed task, and mirrors the context bytes into the process entry. A retail `BOX_NS` regression follows candidate search through context ownership and VM execution, checks six frame transitions and a rendered pixel change, then verifies output-pointer and allocation cleanup. This remains host-side dispatch with fixture-provided VM services, not original dispatcher parity or a verified interaction from the map-1 spawn. - **Runtime chunks:** the host now models the 0x16-byte `UProcess_1420_0000` record, bounded far-memory allocations for chunk/process buffers, the doubly linked loaded-process list, descriptor-pointer replacement/restoration, and zero-count eviction. Retail `EVENT` and `NPCTRIG` plus a two-node fixture cover load, reuse, release, reload, and unlink behavior. The host materializer reads archive-backed class bytes; parity with the original owner-resource callback and allocator remains unverified. @@ -515,9 +515,9 @@ After the first source-backed interaction, complete the original player/item loo ## Near-Term Next Actions -1. **Close the event path:** identify an eligible retail `use` target reachable from the original map-1 spawn. The exact production-equivalent search at egg `0x1e` currently returns one candidate and no eligible event. Then exercise movement to a real target, owner selection, context creation, and VM execution through supported runtime services, verifying a process/world-state effect. The BOX_NS regression verifies candidate-driven selection and visible frame output from a fixture origin only; it does not close this action or establish `Usecode_ItemCallEvent` parity. -2. **Integrate the map-1 loop:** port `Game_Start` (`1020:0000`) and the teleporter constructor/run lifecycle rather than host initialization; add the stasis wait, original target-map transition and item search, collision/fall, then move input and animation onto the recovered kernel loop. The current tests cover same-map egg resolution, shared item-1 mutation, and host input/scheduler behavior, not those binary lifecycle semantics or source draw-order/camera parity. Keep the normal window on the original path before calling the vertical slice accepted. +1. **Close the event path:** identify and reach an eligible retail `use` target from the original map-1 spawn. The exact production-equivalent search at egg `0x1e` still returns one candidate and no eligible event. Map-wide evidence includes the inactive/map-array `PANELNS`, a `CARD_NS` whose authorized state requires keycard 6, and a frame-0 `CHEST_EW` at staged `(1087, 2559, 0)` whose recovered handler attempts a legal shape swap to `0x054b` before animating. The host implements `Item.setShape` (`0x24`), but `FREE.slot_2d`'s family check, `Item.legal_create`, and temporary-item lifecycle are still missing; the chest's collision route is unverified. Next prove reachability and implement only the required recovered services, then exercise owner selection, context creation, VM execution, and a process/world-state effect. The BOX_NS regression still verifies candidate-driven selection and visible frame output from a fixture origin only; it does not close this action or establish `Usecode_ItemCallEvent` parity. +2. **Integrate the map-1 loop:** port `Game_Start` (`1020:0000`) and replace host initialization; the window now models the clear-stasis waiter and same-map teleporter over two scheduler scans, but does not implement the original wait lists or call chain. Next port the original target-map transition and item search, collision/fall, then move input and animation onto the recovered kernel loop. The current tests cover same-map egg resolution and the host stasis ordering, shared item-1 mutation, and host input/scheduler behavior, not binary lifecycle parity or source draw-order/camera behavior. Keep the normal window on the original path before calling the vertical slice accepted. ## Current Bottom Line -The host now materializes archive-backed USECODE chunks and builds tested 0x124-byte contexts with bounded source pointers and an initialized 0x82-byte call stack. Its window routes use-request candidates through owner-row selection into a context-backed task; the BOX_NS regression verifies VM-driven frame changes, rendered output, and cleanup, while a separate retail test confirms no eligible event at the original spawn. Retail egg selection and placement of item 1 are covered, the typed `TeleporterProcess` performs its tested same-map egg move, and a deterministic host input/tick test verifies that the item-owned animation process moves item 1. Original `Game_Start`, the full teleporter lifecycle, `Usecode_ItemCallEvent`/context-dispatch, owner-resource callback parity, a reachable retail interaction, and original loop/render parity remain incomplete. Whole-game and playable-game acceptance remain unmet. +The host now materializes archive-backed USECODE chunks and builds tested 0x124-byte contexts with bounded source pointers and an initialized 0x82-byte call stack. Its window routes use-request candidates through owner-row selection into a context-backed task; the BOX_NS regression verifies VM-driven frame changes, rendered output, and cleanup, while a separate retail test confirms no eligible event at the original spawn and identifies only guarded/far map-wide candidates so far. Retail egg selection and placement of item 1 are covered, and the typed `TeleporterProcess` now runs after the host-modelled clear-stasis wait in a scheduler-driven two-pass test. A deterministic host input/tick test still verifies that the item-owned animation process moves item 1. Original `Game_Start`, full `Process_WaitFor` parity, cross-map teleporter lifecycle, `Usecode_ItemCallEvent`/context-dispatch, owner-resource callback parity, a reachable retail interaction, and original loop/render parity remain incomplete. Whole-game and playable-game acceptance remain unmet. diff --git a/docs/usecode-event-avatar-stole-something-analysis.md b/docs/usecode-event-avatar-stole-something-analysis.md new file mode 100644 index 0000000..0763077 --- /dev/null +++ b/docs/usecode-event-avatar-stole-something-analysis.md @@ -0,0 +1,51 @@ +# `avatarStoleSomething` (`slot 0x13`) in Crusader + +## Conclusion + +The event name is inherited from Ultima's theft vocabulary, but Crusader's shipped usecode uses the slot mostly as an item-movement notification for environmental objects. The common handler records the passed item id in the running process's metadata under event type `0x022E`, then excludes the process. The inspected handlers do not accuse the avatar, raise an alarm, start combat, or otherwise implement a crime response. + +There are 23 non-empty slot-`0x13` bodies in the inspected Remorse corpus and 18 in Regret. They belong mainly to electrical walls, shock objects, lights, sliding walls, doors, and a sliding floor, rather than dialogue-oriented NPC classes. Two Remorse `MDOOR` handlers launch a door-component cleanup path; `SLIDEFLR` waits for a frame transition and a specific sound state. This makes `avatarStoleSomething` a useful repurposed hook for world-object bookkeeping and synchronization, despite its theft-oriented name. + +## Native dispatch contract + +Ghidra identifies `Item_AvatarStoleSomething` at `10a0:2fda` as intrinsic `0x0B1`. It checks whether the receiving item is an NPC; if so, it suppresses the event when that NPC is dead. Otherwise it calls `Usecode_ItemCallEvent` with mask `0x80000`, slot `UC_AvatarStoleSomething` (`0x13`), and the supplied word argument. The native wrapper therefore establishes the receiver, liveness filter, and payload, but does not itself test ownership or decide whether a move is a theft. + +The event signature is one word, and the Crusader handlers consistently treat it as an item reference. The corresponding ScummVM implementation describes the legacy outer trigger in `Item::movedByPlayer`: avatar-owned items are not stolen; otherwise, nearby living actors are notified with the moved item's id. That source helps explain the inherited label and dispatch convention, but it is cross-implementation evidence, not proof of every original NE movement call site. + +ScummVM's `item.h` has a stale comment calling this event 14; its implementation and converter table use `0x13`, matching the Remorse native dispatcher and the Crusader event table. Use `0x13` as the ordinal. + +## Corpus-wide pattern + +Every one of the 41 inspected Remorse and Regret handlers executes `set_info(0x022E, *(arg_06))` followed by `process_exclude()`. In the local VM model, opcode `0x77` routes those operands to process metadata as `(eventType, sourceItem)`, and `ProcessKernel::setProcessInfo` stores those fields on the running process. The strongest supported reading is therefore that each callback tags its process with event type `0x022E` and the item id that prompted the callback. + +No `get_info(0x022E)` reads were found in the inspected usecode exports. Treat `0x022E` as an opaque process-event tag; its higher-level consumer or meaning has not been established. In particular, the handlers do not show that this is a global theft flag or alarm state. + +The broad classes and variant structure are consistent across both games: + +- Remorse has 23 handlers: two WSHOCK, two EWALL, two ETWALL, eight L_* lights, two MDOOR, six SL_* sliding walls, and one SLIDEFLR. +- Regret has 18 handlers: two WSHOCK, two EWALL, eight L_* lights, and six SL_* sliding walls. +- Apart from MDOOR and SLIDEFLR, the handlers only set the process info and exclude the process; no speech, alarm, attack, or stolen-item punishment appears in their bodies. + +## Specialized handlers + +### MDOOR + +`MDOOR_E::avatarStoleSomething` and `MDOOR_N::avatarStoleSomething` both store the moved-item id under `0x022E`, exclude the current process, spawn `DOOR.slot_22` with that item id, and suspend while the child process runs. The east variant also creates two helper items, shapes `0x02F1` and `0x04CE`, at coordinates derived from the moved item before launching the door process; the north variant goes directly to the child process. + +There is an extraction discrepancy worth preserving: the simplified [Crusader_Decomp MDOOR_E pseudocode](../USECODE/EUSECODE_extracted/pseudocode/MDOOR_E/slot_13_avatarStoleSomething.txt) lists the helper locals but omits their create/position calls. Those calls are present in the [Remorse site-data export](../../crusader_map_viewer/map_renderer/site/data/usecode/remorse/EUSECODE/pseudocode/MDOOR_E/slot_13_avatarStoleSomething.txt) and the raw [Crusader usecode disassembly](../../crusader-disasm/crusader_disasm.txt) under `MDOOR_E::AvatarStoleSomething`. The helper-item detail above relies on those corroborating representations. + +`DOOR::ordinal22` (`0A06:0022`) records the passed item as process info type `0x0001`, reads its QLo and QHi values, scans door/roof-related shape sets, and iterates shape `0x04F8` candidates. It destroys candidates whose QLo matches both values from the passed item. The class's loop metadata is only partly reconstructed, so the exact roles of every scanned shape remain uncertain; the verified behavior is a quality-keyed search and removal of matching door-associated pieces. This is a concrete environmental cleanup path, not a social theft reaction. + +### SLIDEFLR + +`SLIDEFLR::avatarStoleSomething` first performs the common `0x022E` process-info write. If the passed item is at frame `9`, it polls every four ticks until the frame changes. It then polls every two ticks until sound effect `81` is playing for that item. The handler does not start the sound itself. Its visible role is to synchronize with an existing floor animation/audio transition. + +## Interpretation and limits + +The most defensible Crusader-specific description is **item-movement notification and environmental state coordination**. The payload identifies the moved item; ordinary handlers record that identity, while the MDOOR and SLIDEFLR variants use it to coordinate related world pieces. The event name describes its inherited origin better than its present scripted effects. + +This conclusion is about the authored handlers and the native per-receiver dispatcher. The exact condition that calls the dispatcher in the original executable is not established by this function alone. The ScummVM movement routine is useful corroboration for the legacy trigger, but should not be silently treated as a byte-for-byte native call-site proof. + +## Simplified explanation + +Think of slot `0x13` as: “An item just moved; here is its id.” Most Crusader objects simply record that id. A few doors and floors use it to clean up or synchronize related pieces. In practice, it behaves more like an environmental update hook than a theft alarm. \ No newline at end of file diff --git a/docs/usecode-event-slots-catalog.md b/docs/usecode-event-slots-catalog.md new file mode 100644 index 0000000..1b04337 --- /dev/null +++ b/docs/usecode-event-slots-catalog.md @@ -0,0 +1,183 @@ +# Crusader USECODE Event Slot Catalog + +**Status:** Evidence-backed working catalog; event names and signatures remain hints unless corroborated below. +**Scope:** Main local Remorse and Regret owner-loaded `EUSECODE.FLX` corpora. Demo, Japanese, and 1.01 variants are excluded from the counts. +**Last consolidated:** 2026-10-05 + +This companion expands the event-slot summary in the [USECODE format specification](./usecode-format-specification.md). It records the common event names, local body coverage, known native callers and source-port behavior, class-local higher slots, and targeted open questions. It complements the per-ordinal [intrinsic catalog](./usecode-intrinsics-catalog.md): an event slot selects a class callback; an intrinsic ordinal selects a native function from bytecode. + +## Reading the Evidence + +- **Body count** is the number of non-empty, derived class/slot body windows in the named local corpus. It is not a count of runtime executions, reachable objects, or call sites. +- **Zero bodies** means the scanned corpus has no non-empty body at that slot. It does not mean the executable cannot dispatch that slot. +- **Source label** means a converter/disassembler name. It is a navigation hint, not proof of one universal behavior. +- **Native route** means a direct caller of `Usecode_ItemCallEvent` was identified in the live Remorse `CRUSADER.EXE` Ghidra session. This is direct evidence for Remorse only; Regret's per-slot values below are corpus evidence, not a separate native-binary audit. +- **Class-local** means the same numeric slot can do different work in different classes. This is especially important above `0x1F`. +- Body byte ranges are inclusive sizes from `derived_body_length` in the extracted event index. They are useful for prioritization, not semantic evidence. + +## Dispatch Model + +The event ordinal is resolved in the selected class's event table. Bytecode class/event calls (`0x11`) and spawned class/event processes (`0x57`, `0x58`) carry a class id and slot; they do not call a globally named event function. A body can therefore be reached by a script even when there is no engine-native wrapper with that name. + +In the Remorse executable, `Usecode_ItemCallEvent` (`1420:0e3a`) checks a per-class event capability mask and passes the class id and `UC_*` event ordinal into the runtime context-creation path. The common native wrappers use bit masks corresponding to the low event ordinals (`1 << slot`). For example, the verified masks for `equip`, `unequip`, `combine`, `cast`, and `unhatch` are `0x0400`, `0x0800`, `0x1000`, `0x20000`, and `0x200000`. The dispatcher is shared machinery; an event-specific native caller and a non-empty class body are separate facts. + +The local extractor derives body windows from owner-loaded class records; its event-count/base-offset disagreement with ScummVM and Pentagram remains open. See [the format specification](./usecode-format-specification.md#33-event-countbase-offset-disagreement) and [round-trip IR notes](./usecode-roundtrip-ir.md). + +## Corpus Coverage + +| Variant | Non-empty bodies | Common slots with bodies | Higher populated slots | Highest observed body slot | +|---|---:|---:|---|---:| +| Remorse | 977 | 15 of 32 | Every slot `0x20..0x4B` (44 slots) | `0x4B` | +| Regret | 1,152 | 14 of 32 | Every slot `0x20..0x51` (50 slots) | `0x51` | + +The common-slot counts below come from the extracted `class_event_index.tsv` files under `USECODE/EUSECODE_extracted/` and `USECODE/REGRET/REGRET_USECODE_extracted/`. The higher-slot table adds per-slot body counts and byte-length ranges. Every common slot `0x00..0x1F` is listed, including zero-body slots; higher rows cover every slot with at least one body in either main corpus. + +## Common Slots `0x00..0x1F` + +The labels in the second column follow ScummVM's Crusader converter table where available. Pentagram's older Crusader converter retains `func*` placeholders for some names that can be corroborated by the native binary. Source-level argument lists are not assumed to be the exact USECODE body ABI. + +| Slot | Converter label / variant note | Remorse / Regret bodies | Evidence, current interpretation, and next investigation | +|---:|---|---:|---| +| `0x00` | `look()` | 1 / 0 | Remorse has one body; Regret has none. The native `Item_Look` route and ScummVM item-selection path identify this as inspection/looking. Inspect the sole body and its selected-item context; do not infer that all `look` interactions are script-backed. | +| `0x01` | `use()` | 66 / 80 | Main item-use/activation callback. Native `Item_Use` has two dispatcher call sites; ScummVM also invokes it from item selection and actor-use paths. This is the best-covered public interaction slot, but class behavior is intentionally heterogeneous. Trace selected examples from input through class selection and note any caller-supplied state. | +| `0x02` | `anim()` | 0 / 0 | Native `DList_AnimateShapes` calls `Item_Anim` for animation type 5; that branch invokes the event and performs no separate frame step. Both corpora lack bodies, so no script animation behavior is available there. ScummVM shares this path; Pentagram disables non-`use` Crusader callbacks. Find type-5 authored objects and check omitted builds. | +| `0x03` | `setActivity()` | 0 / 0 | Native `NPC_SetActivity` offers `UC_SetActivity` before `NPC_StartNextNPCActivityBehaviorProcess`; if dispatch is not handled, ordinary NPC activity behavior is started. The original Crusader route is real despite zero bodies. The name is inherited from the U8 event table, but no U8 event-`0x03` producer was found in the inspected source ports. Recover its argument layout and check the original U8 caller before claiming runtime inheritance. | +| `0x04` | `cachein()` | 22 / 35 | Native `Item_Cachein` dispatches only when a current map array exists. ScummVM's map-load path calls cache-in on items and actors. Best current meaning is map/cache-in initialization. Determine exact ordering relative to item registration and whether nested loads can re-enter it. | +| `0x05` | `hit(uword, word)` | 13 / 12 | Outgoing hit/attack callback. Collision handling calls `hit` on the mover/attacker with the other item id and hit-force value; `Item_Hit` is the native wrapper. Compare this with slot `0x06` to settle directionality and the hit-force calculation for each collision path. | +| `0x06` | `gotHit(uword, word)` | 197 / 248 | Incoming damage/collision reaction; it is the most widespread common handler. `Item_GetDamaged` is the native route, and ScummVM also calls it from collision and damage code. Separate collision notification from actual health damage; inspect callers that pass zero or packed damage-type values. | +| `0x07` | `hatch()` | 28 / 26 | Egg/spawn appearance callback. ScummVM's `Egg::hatch` is one-shot and returns the callback process id; native `Item_CallHatchEvent` is a direct route. Identify which class families are hatchable eggs versus other spawn initialization and record whether the event is synchronous or process-backed. | +| `0x08` | `schedule()` | 0 / 0 | Native `NPC_Schedule` checks liveness, may clear combat state outside the fast area, and dispatches `UC_Schedule` with a 32-bit time value (mask `0x0100`). The converter label omits that payload. With no body, the wrapper returns no usecode process. Resolve time units and determine whether other builds contain schedule scripts. | +| `0x09` | `release()` | 9 / 10 | Native `Item_Release` dispatches with no explicit event payload. ScummVM also calls release during movement/collision cleanup. The broad read is release/removal cleanup; trace all retail call sites to distinguish uncache, collision exit, and ownership transitions. | +| `0x0A` | `equip()`; Pentagram Crusader table says `func0A(sint16)` | 77 / 125 | Native `Item_Equip` dispatch is verified with mask `0x0400`. In Crusader it is generalized into mode application, arming, setup, and actor initialization, not just wearable equipment. See [the equipment-system analysis](./usecode-equipment-system.md). Next, classify parameterized versus no-parameter call sites and avoid translating every use as literal equipment. | +| `0x0B` | `unequip()`; Pentagram Crusader table says `func0B(sint16)` | 50 / 47 | Native `Item_Unequip` dispatch is verified with mask `0x0800`; scripts commonly disable, disarm, or reverse slot-`0x0A` behavior. See [the equipment-system analysis](./usecode-equipment-system.md). Compare matching class pairs and determine which native callers pass a related object id or mode. | +| `0x0C` | `combine()` | 0 / 0 | Native `Item_Combine` dispatch exists, but neither corpus has a slot body or direct `.combine()` class-event call. Remorse intrinsic `0x00CF` (`Item::I_setQAndCombine`) is used twice in `MISS1EGG::cachein`: it writes item quality, then attempts this event. The callback process id is discarded, so the event cannot gate that write. This is a notification hook, not the merge algorithm. See [the combine/cast/fast-area analysis](./usecode-event-slots-combine-cast-fast-area.md). | +| `0x0D` | `func0D` | 0 / 0 | No semantics or direct native dispatcher caller have been established. Preserve the raw slot. Search alternate corpora and native callsites, then inspect any class row before assigning a name. | +| `0x0E` | `calledFromAnim()` | 27 / 43 | ScummVM's animation tracker invokes this callback; it is an animation-originated event lane, not the same thing as `anim` (`0x02`). Determine the animation condition and payload at the original native call site and compare representative class bodies. | +| `0x0F` | `enterFastArea()` | 108 / 107 | Native item movement enters this path when crossing into a fast area. Corpus evidence points to authored proximity/activation regions for spawners, timers, and controllers, not a movement-speed modifier. See [the fast-area analysis](./usecode-event-slots-combine-cast-fast-area.md). Future work: establish exact boundary/flag behavior and per-class state transitions. | +| `0x10` | `leaveFastArea()` | 52 / 52 | Exit counterpart to `enterFastArea`; used by timers and controller classes to disarm or advance phase logic. It can be bypassed for camera-followed items, so do not assume every geometric exit fires the callback. Compare enter/leave pairs class by class. | +| `0x11` | `cast(uword)`; Pentagram Crusader table says `func11(sint16)` | 1 / 8 | Native `Item_Cast` dispatch is verified with mask `0x20000`. Crusader usecode uses this for scripted activation/dispatch, not a general spell system: Remorse's sole body is an avatar map/music hook; Regret has controller/keypad examples. See [the combine/cast/fast-area analysis](./usecode-event-slots-combine-cast-fast-area.md). Resolve the apparent argument-width/name difference against real callers. | +| `0x12` | `justMoved()` | 0 / 0 | Native `Item_JustMoved` dispatch exists. ScummVM calls it after an item is moved in the world or moved into a container. No local body is present, so the known paths have no authored callback in these corpora. Check whether this is a retained compatibility hook or used in omitted builds. | +| `0x13` | `avatarStoleSomething(uword)` | 23 / 18 | In Crusader, a moved-item notification used mainly by environmental classes: handlers tag process metadata with `0x022E` and the item id; MDOOR starts door-piece cleanup and SLIDEFLR synchronizes animation/audio. The native wrapper skips dead NPC receivers before dispatch. See [the detailed analysis](./usecode-event-avatar-stole-something-analysis.md). | +| `0x14` | `animGetHit()` | 0 / 0 | Native `Item_AnimGetHit` exists and accepts a word-sized native parameter, while the converter label shows no argument. Distinct from the general incoming-hit slot `0x06`; neither corpus has a body. Recover callers and determine whether the word identifies a hit animation, attacker, or mode. | +| `0x15` | Crusader `unhatch(word)`; U8 `guardianBark(word)`; Pentagram Crusader table says `func15` | 5 / 6 | Native `Item_CallUnhatchEvent` dispatch exists; ScummVM invokes it from Crusader egg unhatching. The local name `unhatch` is supported for Crusader, but the converter's `word` argument conflicts with the wrapper path that exposes no explicit event argument. Keep the U8 `guardianBark` label separate and recover the exact payload before documenting a signature. | +| `0x16` | `func16` | 0 / 0 | Unknown placeholder. No direct native dispatcher caller identified in the Remorse caller scan. Search the complete class tables and alternate builds; retain the numeric id unless a body or call path supplies evidence. | +| `0x17` | `func17` | 0 / 0 | Unknown placeholder. No direct native dispatcher caller identified in the Remorse caller scan. Search the complete class tables and alternate builds; retain the numeric id unless a body or call path supplies evidence. | +| `0x18` | `func18` | 0 / 0 | Unknown placeholder. No direct native dispatcher caller identified in the Remorse caller scan. Search the complete class tables and alternate builds; retain the numeric id unless a body or call path supplies evidence. | +| `0x19` | `func19` | 0 / 0 | Unknown placeholder. No direct native dispatcher caller identified in the Remorse caller scan. Search the complete class tables and alternate builds; retain the numeric id unless a body or call path supplies evidence. | +| `0x1A` | `func1A` | 0 / 0 | Unknown placeholder. No direct native dispatcher caller identified in the Remorse caller scan. Search the complete class tables and alternate builds; retain the numeric id unless a body or call path supplies evidence. | +| `0x1B` | `func1B` | 0 / 0 | Unknown placeholder. No direct native dispatcher caller identified in the Remorse caller scan. Search the complete class tables and alternate builds; retain the numeric id unless a body or call path supplies evidence. | +| `0x1C` | `func1C` | 0 / 0 | Unknown placeholder. No direct native dispatcher caller identified in the Remorse caller scan. Search the complete class tables and alternate builds; retain the numeric id unless a body or call path supplies evidence. | +| `0x1D` | `func1D` | 0 / 0 | Unknown placeholder. No direct native dispatcher caller identified in the Remorse caller scan. Search the complete class tables and alternate builds; retain the numeric id unless a body or call path supplies evidence. | +| `0x1E` | `func1E` | 0 / 0 | Unknown placeholder. No direct native dispatcher caller identified in the Remorse caller scan. Search the complete class tables and alternate builds; retain the numeric id unless a body or call path supplies evidence. | +| `0x1F` | `func1F` | 0 / 0 | Unknown placeholder. No direct native dispatcher caller identified in the Remorse caller scan. Search the complete class tables and alternate builds; retain the numeric id unless a body or call path supplies evidence. | + +### Native Event Routes Confirmed in Remorse + +The live Ghidra caller scan found direct `Usecode_ItemCallEvent` callers for every named common event except `0x0D` and `0x16..0x1F`. These are the direct dispatcher callsite addresses, not necessarily the containing function entry addresses: + +| Slot | Native caller | Dispatcher callsite(s) | +|---:|---|---| +| `0x00` | `Item_Look` | `10a0:25bb` | +| `0x01` | `Item_Use` | `10a0:26d9`, `10a0:26ff` | +| `0x02` | `Item_Anim` | `10a0:28f9` | +| `0x03` | `NPC_SetActivity` | `10e8:2bbc` | +| `0x04` | `Item_Cachein` | `10a0:2abd` | +| `0x05` | `Item_Hit` | `10a0:274a` | +| `0x06` | `Item_GetDamaged` | `10a0:287f` | +| `0x07` | `Item_CallHatchEvent` | `1090:0647` | +| `0x08` | `NPC_Schedule` | `10e8:30e7` | +| `0x09` | `Item_Release` | `10a0:2a20` | +| `0x0A` | `Item_Equip` | `10a0:2a53` | +| `0x0B` | `Item_Unequip` | `10a0:2a86` | +| `0x0C` | `Item_Combine` | `10a0:2aec` | +| `0x0E` | `Item_CalledFromAnim` | `10a0:2b1b` | +| `0x0F` | `Item_EnterFastArea` | `10a0:2d96` | +| `0x10` | `Item_LeaveFastArea` | `10a0:2f29` | +| `0x11` | `Item_Cast` | `10a0:2f5c` | +| `0x12` | `Item_JustMoved` | `10a0:2f8b` | +| `0x13` | `Item_AvatarStoleSomething` | `10a0:302d` | +| `0x14` | `Item_AnimGetHit` | `10a0:2fbe` | +| `0x15` | `Item_CallUnhatchEvent` | `1090:0676` | + +Absence from this direct caller scan is not proof of impossibility: scripts can dispatch class/slot pairs through bytecode, and generic VM paths may not have event-specific native wrapper names. The native caller scan was performed against Remorse only. + +## Higher Class-Local Slots + +No common event-name table provides stable semantics for these ordinals. The examples below are deliberately local to the named class; they do not name the slot globally. For rows without a specific example, the next step is to enumerate owning classes, trace bytecode call/spawn edges, then compare representative bodies within and across variants. + +| Slot | Remorse bodies (byte range) | Regret bodies (byte range) | Known class-local evidence / next investigation | +|---:|---:|---:|---| +| `0x20` | 67 (44-9919) | 70 (19-8200) | `TRIGGER.slot_20` is a widely reused controller fan-out entry; `TIMER`, `SPECIAL`, and other classes also use high slots as workers. `TRIGGER.slot_20` still has unresolved branches. Do not equate every slot-`0x20` body. | +| `0x21` | 38 (49-9901) | 35 (11-4943) | `SPECIAL.slot_21` is a phase/delay worker; environmental families also use it. Compare owner class and caller arguments before describing other bodies. | +| `0x22` | 18 (49-2581) | 18 (17-1134) | `SURCAMNS` / `SURCAMEW` slot `0x22` bodies are a repeated callback-family near-template. Compare exact bodies and x/y variants; do not promote the template label to a shared event meaning. | +| `0x23` | 14 (45-8823) | 15 (26-12307) | `DOOR.slot_23` is used in a destroyable-door helper path; `TRIGGER.slot_23` also has class-local phase cases. Separate same-ordinal bodies by class and callsite. | +| `0x24` | 12 (61-1626) | 12 (14-1136) | `TRIGGER.slot_24` appears in the movable-wall trigger family; its case-2 branch is currently a match scan. Inspect other owners independently. | +| `0x25` | 11 (55-1439) | 10 (15-995) | Class-local only in current evidence. Enumerate owners and caller tuples; preserve raw ids. | +| `0x26` | 9 (106-1743) | 8 (34-1141) | `TRIGGER.slot_26` has a documented match-scan branch. Other class bodies remain unclassified. | +| `0x27` | 8 (223-1560) | 7 (193-1088) | Class-local only in current evidence. Compare body families and caller arguments before assigning a name. | +| `0x28` | 8 (44-4328) | 7 (12-947) | Class-local only in current evidence. The broad body-size spread makes a single shared interpretation especially unsafe. | +| `0x29` | 8 (83-1716) | 7 (23-1199) | `TRIGGER.slot_29` participates in actor-key updates, including writes to mutable actor field `0x63`. Trace each subcommand and its matched-actor filters. | +| `0x2A` | 8 (96-1425) | 7 (49-997) | Class-local only in current evidence. Enumerate owners and distinguish direct calls from spawned worker processes. | +| `0x2B` | 8 (73-1785) | 7 (46-1292) | `TRIGGER.slot_2B` also participates in actor-key updates. Compare against slot `0x29` and identify exactly which branch mutates field `0x63`. | +| `0x2C` | 5 (79-278) | 6 (112-875) | Class-local only in current evidence; inspect the small owner set and caller payloads. | +| `0x2D` | 5 (264-764) | 6 (217-537) | `ITEM.slot_2D` checks nearby shape `0x04D0` objects and compares `QLo`; `MONSTER` also uses a high-slot worker. These are separate class semantics. | +| `0x2E` | 5 (106-392) | 6 (30-302) | Class-local only in current evidence; inspect owners and call chains. | +| `0x2F` | 3 (285-314) | 6 (168-818) | Class-local only in current evidence; inspect owners and call chains. | +| `0x30` | 3 (142-553) | 6 (53-303) | Class-local only in current evidence; inspect owners and call chains. | +| `0x31` | 3 (398-1048) | 4 (205-508) | Class-local only in current evidence; inspect owners and call chains. | +| `0x32` | 3 (181-767) | 4 (31-421) | Class-local only in current evidence; inspect owners and call chains. | +| `0x33` | 3 (49-1097) | 4 (98-424) | Class-local only in current evidence; inspect owners and call chains. | +| `0x34` | 3 (136-588) | 4 (29-325) | Class-local only in current evidence; inspect owners and call chains. | +| `0x35` | 3 (97-741) | 4 (32-328) | Class-local only in current evidence; inspect owners and call chains. | +| `0x36` | 3 (91-703) | 4 (150-386) | Class-local only in current evidence; inspect owners and call chains. | +| `0x37` | 3 (89-731) | 4 (174-389) | Class-local only in current evidence; inspect owners and call chains. | +| `0x38` | 3 (78-728) | 4 (168-397) | Class-local only in current evidence; inspect owners and call chains. | +| `0x39` | 3 (106-728) | 4 (144-397) | Class-local only in current evidence; inspect owners and call chains. | +| `0x3A` | 3 (96-804) | 4 (215-443) | Class-local only in current evidence; inspect owners and call chains. | +| `0x3B` | 3 (221-1087) | 4 (75-449) | Class-local only in current evidence; inspect owners and call chains. | +| `0x3C` | 3 (426-695) | 4 (14-389) | Class-local only in current evidence; inspect owners and call chains. | +| `0x3D` | 3 (67-333) | 4 (93-267) | Class-local only in current evidence; inspect owners and call chains. | +| `0x3E` | 3 (77-2359) | 4 (36-2204) | Class-local only in current evidence; inspect owners and call chains. | +| `0x3F` | 3 (61-2379) | 4 (36-2070) | Class-local only in current evidence; inspect owners and call chains. | +| `0x40` | 3 (174-430) | 4 (33-340) | Class-local only in current evidence; inspect owners and call chains. | +| `0x41` | 3 (89-386) | 4 (35-542) | Class-local only in current evidence; inspect owners and call chains. | +| `0x42` | 2 (231-386) | 4 (47-553) | Class-local only in current evidence; inspect owners and call chains. | +| `0x43` | 2 (87-244) | 4 (35-275) | Class-local only in current evidence; inspect owners and call chains. | +| `0x44` | 2 (109-231) | 4 (190-814) | Class-local only in current evidence; inspect owners and call chains. | +| `0x45` | 2 (301-1557) | 3 (205-1025) | Class-local only in current evidence; inspect owners and call chains. | +| `0x46` | 2 (280-1553) | 3 (31-1015) | Class-local only in current evidence; inspect owners and call chains. | +| `0x47` | 2 (301-426) | 3 (55-474) | Class-local only in current evidence; inspect owners and call chains. | +| `0x48` | 2 (280-534) | 2 (27-178) | Class-local only in current evidence; inspect owners and call chains. | +| `0x49` | 1 (1953-1953) | 2 (158-164) | Only one Remorse body and two short Regret bodies. Identify owners before comparing; a long Remorse body is not evidence of shared meaning. | +| `0x4A` | 1 (1553-1553) | 2 (49-274) | Only one Remorse body and two Regret bodies. Inspect the single-owner scripts and whether they are called from another high-slot worker. | +| `0x4B` | 1 (426-426) | 1 (450-450) | One body in each corpus; no shared semantic label. Compare exact class identity and callsites. | +| `0x4C` | 0 | 1 (274-274) | Regret-only body in the scanned corpora. Determine whether this is title-specific logic or a build/content difference. | +| `0x4D` | 0 | 1 (450-450) | Regret-only body in the scanned corpora. Determine whether this is title-specific logic or a build/content difference. | +| `0x4E` | 0 | 1 (296-296) | Regret-only body in the scanned corpora. Determine whether this is title-specific logic or a build/content difference. | +| `0x4F` | 0 | 1 (300-300) | Regret-only body in the scanned corpora. Determine whether this is title-specific logic or a build/content difference. | +| `0x50` | 0 | 1 (313-313) | Regret-only body in the scanned corpora. Determine whether this is title-specific logic or a build/content difference. | +| `0x51` | 0 | 1 (300-300) | Highest observed non-empty slot in Regret. Determine whether this is title-specific logic or a build/content difference. | + +The higher-slot examples above are backed by the generated pseudocode and event indexes, not by globally meaningful event names. Useful starting points include [map-viewer trigger links](./map_renderer/trigger-usecode-links.md), [the movable-wall investigation](./movable-wall-trigger-investigation.md), [the map spawner investigation](./map_1_spawners_targeted_investigation.md), and [the FLICTEST investigation](./usecode/flictest-investigation.md). `TRIGGER.slot_20`, for example, is a class-specific worker reached by scripts; it is not a universal VM event callback. + +## Investigation Queue + +1. Audit the omitted demo, Japanese, and 1.01 archives for zero-body common slots, especially `0x02`, `0x03`, `0x08`, `0x0C`, `0x12`, and `0x14`. +2. Recover original native callers and parameter layouts for `setActivity`, `schedule`, `animGetHit`, and `unhatch`; keep converter prototypes separate from observed stack arguments. +3. Search the Remorse binary and available Regret builds for direct native routes to `0x0D` and `0x16..0x1F`; lack of a current xref is not proof that generic bytecode dispatch rejects them. +4. Run the same native event-wrapper/caller audit against a live Regret executable. Current Ghidra caller evidence in this catalog is Remorse-only. +5. Generate a class-owner and bytecode call/spawn index for every high slot. Prioritize `0x20..0x2B`, where existing notes already show controller, timer, camera, door, and actor-key families. +6. For each high slot with only one or two bodies, inspect the complete body and its callers before deciding whether the slot is private helper code, a title-specific callback, or dead content. +7. Resolve the event-table count/base-offset conflict independently of event semantics; preserve raw rows and offsets while it remains open. + +## Source and Related Notes + +- [Central format specification](./usecode-format-specification.md) +- [Detailed intrinsic catalog](./usecode-intrinsics-catalog.md) +- [Equipment events](./usecode-equipment-system.md) +- [Combine, cast, and fast-area events](./usecode-event-slots-combine-cast-fast-area.md) +- [ScummVM Crusader converter event labels](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/convert/crusader/convert_usecode_crusader.h) +- [ScummVM item event dispatch and callers](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/world/item.cpp) +- [ScummVM egg callbacks](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/world/egg.cpp) +- [ScummVM scheduler callback](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/world/actors/scheduler_process.cpp) +- Pentagram comparison sources: `misc/pentagram/convert/crusader/ConvertUsecodeCrusader.h`, `misc/pentagram/convert/u8/ConvertUsecodeU8.h`, and `misc/pentagram/world/Item.cpp`. Pentagram's `Item::callUsecodeEvent` explicitly suppresses Crusader event execution except for `use`; treat that as a port limitation, not as original executable evidence. \ No newline at end of file diff --git a/docs/usecode-event-slots-combine-cast-fast-area.md b/docs/usecode-event-slots-combine-cast-fast-area.md index 2c72e99..1fb118b 100644 --- a/docs/usecode-event-slots-combine-cast-fast-area.md +++ b/docs/usecode-event-slots-combine-cast-fast-area.md @@ -4,7 +4,7 @@ This note checks whether the suspicious inherited event labels `combine` (`slot ## Summary -- `combine` survives in the inherited event vocabulary, but current shipped Crusader exports do **not** show any recovered `slot_0C` handler bodies. +- `combine` survives in the event vocabulary and has a live Remorse native dispatch path, but current shipped Crusader exports do **not** show any recovered `slot_0C` handler bodies. - `cast` is used in Crusader, but the live behaviors look like explicit scripted activation/dispatch lanes, not a classic RPG spell system. - `fast area` in Crusader is best read as an authored proximity/trigger region around an object or controller. Entering or leaving that region fires usecode callbacks. @@ -14,6 +14,10 @@ Primary evidence for this note comes from the generated pseudocode exports in `C ## `combine` (`slot 0x0C`) +### In simple terms + +Think of `combine` as an optional reaction hook, not a command to merge items: native code updates an item's Q (used here as its quantity) and may then ask the item's class script to handle slot `0x0C`. The native stack routine does the actual merging. The inspected Remorse scripts have no handler for this slot, so there is no extra usecode reaction and the native quantity or stack operation continues. + ### What is actually present - The inherited Crusader/U8 event table still names event `C` as `combine`. @@ -22,7 +26,17 @@ Primary evidence for this note comes from the generated pseudocode exports in `C - `remorse-101` - `remorse-demo` - `regret` -- The same exported pseudocode search also found **zero** `.combine(` callsites. +- The exported pseudocode search found **zero direct class-event `.combine(...)` callsites**. This does not mean the native event is never attempted: Remorse usecode calls the separate `Item::I_setQAndCombine` intrinsic twice in `MISS1EGG::cachein`. + +### What the Remorse executable does + +Ghidra identifies `10a0:0dd1` as the native handler for Remorse intrinsic `0x00CF`, `Item::I_setQAndCombine(Item *, int16 q)`. The body writes `q` into the item's quality field, calls `Item_Combine`, and returns; the intrinsic catalog counts two calls in one Remorse event body. In `MISS1EGG::cachein` (`class_id 0x090D`, slot `0x04`), both release and non-release branches create a `BA_41_CLIP`, set its quantity to `25` through this intrinsic, then continue moving the item into the avatar's inventory. + +`Item_Combine` (`10a0:2ad2`) is only a callback wrapper. It invokes `Usecode_ItemCallEvent` with mask `0x1000` and `UC_Combine` (slot `0x0C`), returning the created process id if the event is handled, otherwise `0`. Its only direct native caller in the Remorse xref scan is `Item_SetQAndCallCombineEvent` (`10a0:0dd1`). That helper ignores the returned process id and returns `void`; it neither waits for the callback nor uses it to approve or reject the quantity change. + +The actual item merge is performed by its caller. For example, `Item_TryStackItems` checks equal shape and quantity/reagent family (and equal frame for reagents), sums the quantities, then either updates one stack and destroys the other or caps one at `0x29A` and leaves the remainder on the second. It calls the quality-and-event helper during those updates. `Item_Create`, `NPC_UseOneShot`, and `NPC_CheckForEmptyAmmo` also use the helper for initial or changing weapon/ammo quantities. So slot `0x0C` is a post-quality-change notification hook in these paths, not the item-merging algorithm. + +The usecode intrinsic `0x00CF` is Remorse-specific: the Regret intrinsic catalog maps ordinal `0x00CF` to `Item::isOn`, not `Item::I_setQAndCombine`. Do not transfer this intrinsic number across games. ### What related behavior still exists @@ -32,7 +46,7 @@ Primary evidence for this note comes from the generated pseudocode exports in `C ### Best current read -`combine` should stay treated as a historical or compatibility label in the decompiler, not as a confirmed active Crusader event family. The name likely came forward from the inherited Ultima-style event vocabulary, while the shipped Crusader usecode corpus no longer exposes recovered slot-`0x0C` handlers. +`combine` is a confirmed native callback slot, but it has no recovered handler body in the inspected corpora. In Remorse, a real usecode intrinsic call sets an item's quantity and attempts the callback; because no class has a slot-`0x0C` body, there is no authored callback behavior in those archives. The intrinsic's quantity write and its caller's inventory/stack logic still proceed. A direct bytecode class/event call to slot `0x0C` would use ordinary class/slot dispatch; it would not implicitly combine two items. ## `cast` (`slot 0x11`) diff --git a/docs/usecode-format-specification.md b/docs/usecode-format-specification.md new file mode 100644 index 0000000..840df05 --- /dev/null +++ b/docs/usecode-format-specification.md @@ -0,0 +1,838 @@ +# Crusader USECODE Format and Runtime Specification + +**Status:** Evidence-backed working specification +**Scope:** Crusader: No Remorse and Crusader: No Regret USECODE archives, class records, event dispatch, bytecode, and runtime services +**Last consolidated:** 2026-10-05 + +This document is the central format reference for Crusader USECODE in this repository. It combines local retail-binary observations with the ScummVM and Pentagram implementations. It is deliberately explicit about confidence: a shared name or parser convention is not treated as proof of retail behavior when the local binary evidence disagrees. + +“Definitive” here means the current, auditable statement of what is known and what remains unsettled. It does **not** mean every opcode, intrinsic, or event has been semantically recovered. In particular, intrinsic numbers are game/build-specific, some opcode names conflict with observed parser behavior, and parts of class-event records remain unknown. + +## 1. What USECODE is + +USECODE is Crusader's object-oriented, event-driven bytecode system. A class has a set of numbered event slots. When the engine or another script dispatches an event, the runtime resolves the class and event slot to bytecode, constructs an interpreter/process context, and runs the event body. Scripts use VM operations for local/member/global data, arithmetic, branching, strings and lists, and process control. They access most game-world and presentation behavior through **intrinsics**: native functions supplied by the particular game executable. + +The complete behavior of a USECODE program is therefore the combination of: + +1. the archive and class/event records; +2. the bytecode and its VM semantics; +3. the executable's event-dispatch rules and intrinsic table; +4. the game data and current world/process state. + +Bytecode alone does not define the semantics of an intrinsic ordinal. Remorse and Regret must not be assumed to share the same intrinsic numbering or signatures. + +## 2. Evidence and terminology + +Use these terms when reading this specification and related analysis: + +- **Observed** — directly checked in local Crusader data, bytecode, or executable/runtime evidence. +- **Cross-implementation** — present in both ScummVM and Pentagram; strong evidence for intended format design, but not conclusive where it conflicts with local samples. +- **Name hint** — a label supplied by a converter, disassembler, or inferred table. It helps navigation but is not itself proof of behavior. +- **Unresolved** — competing interpretations or insufficient direct evidence. Preserve the raw value and do not silently choose one interpretation. +- **Intrinsic** — a native executable routine called by bytecode, selected by a numeric ordinal. +- **Event** — a class-local numbered callback. An event slot is not a globally unique function address. + +The strongest local format evidence is the owner-loaded `EUSECODE.FLX` extractor and sampled class records. The detailed evidence and outstanding count/base disagreement are in [usecode-roundtrip-ir.md](./usecode-roundtrip-ir.md). Tool implementation differences are compared in [usecode-tooling-comparison.md](./usecode-tooling-comparison.md). + +## 3. Archive and class organization + +### 3.1 `EUSECODE.FLX` + +The locally validated FLEX directory interpretation is: + +| Field | Current interpretation | +|---|---| +| Header area | `0x80` bytes | +| Entry count | Little-endian `u32` at file offset `0x54` | +| Entry directory | Begins at `0x80` | +| Directory row | 8 bytes: little-endian `u32 data_offset`, then little-endian `u32 declared_size` | +| Object index | Directory row index | +| Non-class objects | Object 0 and object 1 are not class records in the observed layout; object 1 supplies names | +| Class object | Object index `class_id + 2` | +| Class name | A 13-byte slot in object 1 at `4 + 13 * class_id`; name text ends at NUL or the slot boundary | + +These are structural interpretations of the Crusader file as used by the local extractor, not a claim that every FLEX file in other games has the same layout. The extractor validates table bounds and retains original records: [extract_eusecode_flx.py](../tools/extract_eusecode_flx.py). + +### 3.2 Class record and event table + +For owner-loaded Crusader class records sampled locally: + +- The class header is at least 20 bytes. +- Bytes `8..11` contain a little-endian `u32` used in deriving the event-table extent and code addressing. +- A 6-byte-per-slot event table begins at class-relative offset `+20`. +- Each row has the observed shape: + +| Row-relative bytes | Interpretation | +|---|---| +| `+0..+1` | Unknown little-endian word; retain as raw data | +| `+2..+5` | Little-endian `u32` event-code offset field | + +- A zero code-offset field is treated by local tooling as an absent event. +- Nonzero offsets are resolved to body windows using the class code-base anchor and the next greater nonzero event offset. The end of the final body is bounded by the class-record size. +- Event names are not stored as authoritative semantic names in the row; the slot number is the stable identifier. + +The exact meaning of the row's leading word has not been established. Do not discard or rewrite it when round-tripping data. + +### 3.3 Event-count/base-offset disagreement + +ScummVM and Pentagram both implement a Crusader class-base calculation that decrements the dword at bytes `8..11`, and an event-count formula equivalent to `(base_offset + 19) / 6`. They resolve an event's offset from `class + 20 + 6 * slot + 2`. + +That shared implementation is valuable evidence, but its event-count arithmetic does **not** fit the sampled owner-loaded records used by this repository. Locally observed dwords such as `0x00d4`, `0x00da`, and `0x00e6` yield clean event-table sizes when interpreted as the first code-byte offset: `(raw_dword - 20) / 6` gives 32, 33, and 35 rows, respectively. The decremented value then acts as a `code_base_minus_one` anchor, and the event offsets behave as 1-based displacements from that anchor. + +**Current local rule:** use bounds-checked event-table parsing derived from the raw owner-loaded class record; preserve both the raw bytes-8..11 dword and the derived anchor. Do not apply the shared ScummVM/Pentagram event-count formula blindly to these samples. The discrepancy and evidence are documented in [usecode-roundtrip-ir.md](./usecode-roundtrip-ir.md). + +**Ghidra cross-check (Remorse):** In the active `CRUSADER.EXE`, `Usecode_ItemCallEvent` (`1420:0e3a`) passes the class id and event ordinal into `EntityVmContext::CreateFromSlotIndex` (`1420:0eec`). The downstream `EntityVmRuntime` path materializes indexed owner/chunk records, including 6-byte runtime entries in `EnsureSlotChunkLoaded` (`1420:19fd`). This confirms class/event ordinal dispatch, but the inspected path consumes an already-indexed owner buffer and does not read the original `EUSECODE.FLX` bytes-8..11 field. It therefore does not decide between the competing archive event-count formulas; the local raw-record arithmetic remains the best fit for the sampled archives, and the formula disagreement remains open. + +### 3.4 Event body and byte order + +Integer operands in the observed Crusader bytecode are little-endian. The bytecode is a variable-length instruction stream; the opcode determines operand widths. Branch displacements are signed 16-bit relative offsets in the local decoders. Strings and body trailers require format-aware handling and must not be normalized through a lossy text conversion. + +The rebuild interpreter model in this repository starts executing at body offset `14` (`usecodeEventBytecodeOffset` in [usecode_vm.h](../rebuild/remorse/include/remorse/usecode_vm.h)). That is an implementation/runtime observation, not a substitute for parsing the event body framing. Analysis and round-trip tooling should preserve the complete body window, including prologue, debug metadata, and unknown trailing bytes. + +## 4. Event slots + +The event number is a class-local ordinal. The common event-name tables cover `0x00..0x1f`, but local class records also contain higher ordinals. The census below covers the main local `USECODE/EUSECODE.FLX` and `USECODE/REGRET/EUSECODE.FLX` corpora, not the demo, Japanese, or 1.01 variants. A count is the number of non-empty derived class/slot body windows, not dynamic executions; `0` means no body was found in that corpus, not that the engine lacks a dispatch route. + +For per-slot source labels, native callers, corpus coverage, class-local high-slot examples, and follow-up work, see the detailed [USECODE event slot catalog](./usecode-event-slots-catalog.md). + +| Slot | Common label | Remorse bodies | Regret bodies | Current Crusader interpretation | +|---:|---|---:|---:|---| +| `00` | `look` | 1 | 0 | Inspection/look callback. | +| `01` | `use` | 66 | 80 | Main object-use or activation callback. | +| `02` | `anim` | 0 | 0 | Native `Item_Anim` dispatch exists, but neither corpus has a body. | +| `03` | `setActivity` | 0 | 0 | Native `NPC_SetActivity` dispatch exists, but neither corpus has a body. | +| `04` | `cachein` | 22 | 35 | Object cache/load-in initialization callback. | +| `05` | `hit` | 13 | 12 | Outgoing hit/attack callback. Exact caller and parameter contract are class/runtime dependent. | +| `06` | `gotHit` | 197 | 248 | Incoming hit/damage reaction callback. | +| `07` | `hatch` | 28 | 26 | Spawn/appearance initialization callback. | +| `08` | `schedule` | 0 | 0 | Scheduled or periodic callback. | +| `09` | `release` | 9 | 10 | Release/cleanup callback. | +| `0A` | `equip` | 77 | 125 | Ghidra confirms the native `Item_Equip` route; scripts reuse it for applying modes, arming, setup, and actor initialization, not only wearable equipment. | +| `0B` | `unequip` | 50 | 47 | Ghidra confirms the native `Item_Unequip` route; scripts reuse it for disabling, disarming, or reversing state, not only removing wearable equipment. | +| `0C` | `combine` | 0 | 0 | Ghidra confirms an `Item_Combine` engine route, but neither inspected archive has a non-empty slot-`0C` body. | +| `0D` | `func0D` | 0 | 0 | Unknown. Preserve as an unnamed slot. | +| `0E` | `calledFromAnim` | 27 | 43 | Callback lane called from animation behavior. | +| `0F` | `enterFastArea` | 108 | 107 | Proximity/activation-region entry hook; local evidence supports trigger, spawner, and controller uses, not a movement-speed zone. | +| `10` | `leaveFastArea` | 52 | 52 | Proximity/activation-region exit hook. | +| `11` | `cast` | 1 | 8 | Ghidra confirms the native `Item_Cast` route; Crusader scripts use it for activation/dispatch, not a general spell system. | +| `12` | `justMoved` | 0 | 0 | Post-movement callback. | +| `13` | `avatarStoleSomething` | 23 | 18 | Player/avatar theft reaction hook. | +| `14` | `animGetHit` | 0 | 0 | Animation-specific hit-reaction callback. | +| `15` | `unhatch` | 5 | 6 | Ghidra has an `Item_CallUnhatchEvent` route; ScummVM's label is supported, while Pentagram's `func15` is a placeholder. | +| `16` | `func16` | 0 | 0 | Unknown. | +| `17` | `func17` | 0 | 0 | Unknown. | +| `18` | `func18` | 0 | 0 | Unknown. | +| `19` | `func19` | 0 | 0 | Unknown. | +| `1A` | `func1A` | 0 | 0 | Unknown. | +| `1B` | `func1B` | 0 | 0 | Unknown. | +| `1C` | `func1C` | 0 | 0 | Unknown. | +| `1D` | `func1D` | 0 | 0 | Unknown. | +| `1E` | `func1E` | 0 | 0 | Unknown. | +| `1F` | `func1F` | 0 | 0 | Unknown. | + +In Ghidra's Remorse `CRUSADER.EXE`, `Item_Equip`, `Item_Unequip`, `Item_Combine`, `Item_Cast`, and `Item_CallUnhatchEvent` dispatch `UC_Equip`, `UC_Unequip`, `UC_Combine`, `UC_Cast`, and `UC_Unhatch` through `Usecode_ItemCallEvent`. Their event masks (`0x400`, `0x800`, `0x1000`, `0x20000`, and `0x200000`) confirm ordinals `0x0A`, `0x0B`, `0x0C`, `0x11`, and `0x15`. This resolves Pentagram converter placeholders `func0A`, `func0B`, `func11`, and `func15` for those event names; raw ordinals remain the stable identifiers. + +**Zero-body slots with native routes (Remorse):** A zero census count means no callback body was found, not that the native engine lacks a caller. `DList_AnimateShapes` (`1190:183d`) calls `Item_Anim` (`10a0:28e2`) for animation type 5; `Item_Anim` passes `UC_Anim` with mask `0x4` to `Usecode_ItemCallEvent`. This animation-type branch only invokes the event and does not advance the frame itself, so with no slot-`0x02` body the branch has no usecode animation behavior to run. `NPC_SetActivity` (`10e8:2ba4`) similarly offers `UC_SetActivity` with mask `0x8`; if the dispatcher does not handle it, the function calls `NPC_StartNextNPCActivityBehaviorProcess` to start the ordinary activity behavior. Thus the empty slot-`0x03` rows leave that built-in fallback in control. + +The `anim()` and `setActivity()` names and ordinals are already present in Pentagram's and ScummVM's Ultima 8 event-name tables, and ScummVM's shared `Item` animation path also calls event `0x02`. That supports `anim` as inherited event machinery retained by Crusader. For `setActivity`, the name is inherited, and the original Crusader executable demonstrably dispatches it, but the inspected Ultima 8 runtime sources do not show a corresponding event-`0x03` producer; Pentagram's `Actor::I_cSetActivity` is a separate intrinsic, not that event. Whether the callback itself was live in the original Ultima 8 engine therefore remains unverified. Also, Pentagram's `Item::callUsecodeEvent` explicitly disables Crusader usecode events other than `use`; that is a limitation of that port and does not contradict the native Crusader call sites. Relevant source paths: `misc/scummvm/engines/ultima/ultima8/world/item.cpp`, `misc/scummvm/engines/ultima/ultima8/convert/u8/convert_usecode_u8.h`, `misc/pentagram/world/Item.cpp`, `misc/pentagram/world/actors/Actor.cpp`, and `misc/pentagram/convert/u8/ConvertUsecodeU8.h`. + +Outside the common table, the extracted Remorse corpus has non-empty body windows at every slot `0x20..0x4B` (44 ordinals), and Regret at every slot `0x20..0x51` (50 ordinals). These higher slots remain unnamed and class-specific; do not infer a common semantic label from the ordinal alone. + +### Event dispatch forms + +The observed bytecode includes class/event calls (`0x11`) and spawned class/event processes (`0x57`, `0x58`). The target is a class id plus event ordinal; the VM resolves the ordinal through that class's event table. Thus the same event ordinal can mean different behavior in different classes, and a decompiler's label does not prove the target row is present. + +The opcode called `FAR_ROUTINE_CALL` in the historical opcode-name list is decoded locally as this class/event dispatch. In Crusader, this is an event-number-based dispatch, not a call using a raw bytecode address. + +## 5. Bytecode instruction set + +The following inventory combines the historical opcode-name table copied from the Japanese No Remorse disassembly corpus with the local decoder's operand interpretations. It is the broadest recovered opcode vocabulary currently in this workspace, **not** a claim that all instructions have fully verified execution semantics in every build. + +Legend: + +- **Decoded locally** means the map-viewer/research parser recognizes the opcode and its current operand shape. +- **Name only / unresolved** means an opcode name exists in the historical table, but local decoding or semantics are absent, conflicting, or incomplete. +- The word “stack” below refers to the VM evaluation/temporary data model; exact ownership/lifetime rules for managed strings and list variants are not fully specified here. + +| Opcode | Historical name | Current behavior / status | +|---:|---|---| +| `00` | `ASSIGN_LOCAL_CHAR` | Pop/store byte-sized value to a BP-relative local. Decoded locally as `pop_local_byte`. | +| `01` | `ASSIGN_LOCAL_INT` | Pop/store word-sized value to a BP-relative local. | +| `02` | `ASSIGN_LOCAL_LONG` | Pop/store dword-sized value to a BP-relative local. | +| `03` | `ASSIGN_LOCAL_HUGE` | Pop/store an opaque-sized value to a BP-relative local; size is an operand. | +| `04` | `ASSIGN_MEMBER_CHAR` | Pop/store byte-sized value to a BP-relative member slot. | +| `05` | `ASSIGN_MEMBER_INT` | Pop/store word-sized value to a BP-relative member slot. | +| `06` | `ASSIGN_MEMBER_LONG` | Pop/store dword-sized value to a BP-relative member slot. | +| `07` | `ASSIGN_MEMBER_HUGE` | Pop/store an opaque-sized value to a BP-relative member slot; size is an operand. | +| `08` | `ASSIGN_RESULT` | Assign/pop the current result value. | +| `09` | `ASSIGN_ELEMENT` | Assign a list/aggregate element; operands include local offset, element size, and list-kind flag. | +| `0A` | `CHAR_CONSTANT` | Push byte immediate. | +| `0B` | `INT_CONSTANT` | Push little-endian 16-bit immediate. | +| `0C` | `LONG_CONSTANT` | Push little-endian 32-bit immediate. | +| `0D` | `STRING_CONSTANT` | Push length-prefixed/NUL-terminated string data; exact encoded-length convention should be preserved from raw bytes. | +| `0E` | `LIST_CONST` | Construct a list from element-size and count operands. | +| `0F` | `C_ROUTINE_CALL` | Call intrinsic/native routine. Operand shape locally: argument-byte count (`u8`), intrinsic ordinal (`u16`). | +| `10` | `NEAR_ROUTINE_CALL` | Call near routine at a `u16` body-relative offset. Full use and return convention not fully recovered. | +| `11` | `FAR_ROUTINE_CALL` | In Crusader, locally decoded as class id (`u16`) plus event slot (`u16`); performs class/event dispatch. | +| `12` | `TEMP_POP_INT` | Pop/store word result in VM temporary. | +| `13` | `TEMP_POP_LONG` | Pop/store dword result in VM temporary. | +| `14` | `ADD_INT` | Word/integer addition. | +| `15` | `ADD_LONG` | Dword/long addition. | +| `16` | `ADD_STRING` | String concatenation. | +| `17` | `ADD_LIST` | List concatenation/append operation. | +| `18` | `EXCLUSIVE_ADD_LIST` | Add list element(s) with uniqueness semantics; element size is an operand. | +| `19` | `EXCLUSIVE_ADD_STRING_LIST` | String-list variant of unique append. | +| `1A` | `SUB_STRING_LIST` | Remove matching string/list element(s); element size is an operand. | +| `1B` | `SUB_LIST` | Remove matching list element(s); element size is an operand. | +| `1C` | `SUBTRACT_INT` | Word/integer subtraction. | +| `1D` | `SUBTRACT_LONG` | Dword/long subtraction. | +| `1E` | `MULTIPLY_INT` | Word/integer multiplication. | +| `1F` | `MULTIPLY_LONG` | Dword/long multiplication. | +| `20` | `DIVIDE_INT` | Word/integer division. | +| `21` | `DIVIDE_LONG` | Dword/long division. | +| `22` | `MODULO_INT` | Word/integer modulo. | +| `23` | `MODULO_LONG` | Dword/long modulo. | +| `24` | `EQUALS_INT` | Word/integer equality comparison. | +| `25` | `EQUALS_LONG` | Dword/long equality comparison. | +| `26` | `EQUALS_STRING` | String equality comparison. | +| `27` | `EQUALS_HUGE` | Opaque/aggregate equality comparison; representation is not fully documented. | +| `28` | `LT_INT` | Integer less-than comparison. | +| `29` | `LT_LONG` | Dword less-than comparison. | +| `2A` | `LE_INT` | Integer less-than-or-equal comparison. | +| `2B` | `LE_LONG` | Dword less-than-or-equal comparison. | +| `2C` | `GT_INT` | Integer greater-than comparison. | +| `2D` | `GT_LONG` | Dword greater-than comparison. | +| `2E` | `GE_INT` | Integer greater-than-or-equal comparison. | +| `2F` | `GE_LONG` | Dword greater-than-or-equal comparison. | +| `30` | `NOT_INT` | Integer logical NOT. | +| `31` | `NOT_LONG` | Dword logical NOT. | +| `32` | `AND_INT` | Integer logical AND. | +| `33` | `AND_LONG` | Dword logical AND. | +| `34` | `OR_INT` | Integer logical OR. | +| `35` | `OR_LONG` | Dword logical OR. | +| `36` | `NE_INT` | Integer not-equal comparison. | +| `37` | `NE_LONG` | Dword not-equal comparison. | +| `38` | `IN_LIST` | Test list membership; local decoder reads element-size and list-kind operands. | +| `39` | `BIT_AND_INT` | Bitwise AND. | +| `3A` | `BIT_OR_INT` | Bitwise OR. | +| `3B` | `BIT_NOT_INT` | Bitwise NOT. | +| `3C` | `SHIFT_LEFT` | Left shift. | +| `3D` | `SHIFT_RIGHT` | Right shift. | +| `3E` | `BYTE_LOCAL_REFERENCE` | Push byte-sized BP-relative local. | +| `3F` | `INT_LOCAL_REFERENCE` | Push word-sized BP-relative local. | +| `40` | `LONG_LOCAL_REFERENCE` | Push dword-sized BP-relative local. | +| `41` | `STRING_LOCAL_REFERENCE` | Push local string reference. | +| `42` | `LIST_LOCAL_REFERENCE` | Push local list reference; element size is an operand. | +| `43` | `S_L_LOCAL_REFERENCE` | Push local special/string-list reference. | +| `44` | `LIST_ELEMENT_REF` | Push list element; local decoder reads element-size and list-kind operands. | +| `45` | `HUGE_LOCAL_REFERENCE` | Push opaque/aggregate local; two operand bytes are retained. | +| `46` | `BYTE_MEMBER_REFERENCE` | Push byte-sized BP-relative member. | +| `47` | `INT_MEMBER_REFERENCE` | Push word-sized BP-relative member. | +| `48` | `LONG_MEMBER_REFERENCE` | Push dword-sized BP-relative member. | +| `49` | `HUGE_MEMBER_REFERENCE` | Push opaque/aggregate BP-relative member. | +| `4A` | `THIS_REFERENCE` | Current “this” reference. Not fully modeled by the local decoder. | +| `4B` | `ADDRESS_OF` | Push address of a BP-relative local. | +| `4C` | `INDIRECT_REFERENCE` | Dereference pointer/reference for the specified byte size. | +| `4D` | `INDIRECT_ASSIGN` | Store indirectly through a pointer/reference for the specified byte size. | +| `4E` | `GLOBAL_DATA_REFERENCE` | Push global value by global id and size. | +| `4F` | `GLOBAL_DATA_ASSIGN` | Store global value by global id and size. | +| `50` | `RETURN` | Return from current routine/event. | +| `51` | `IF` | Conditional branch; local decoder represents it as `jne` with signed relative displacement. | +| `52` | `JUMP` | Unconditional relative branch. | +| `53` | `SUSPEND` | Yield/suspend the current process. | +| `54` | `IMPLIES` | Historical name; operand and runtime semantics unresolved. | +| `55` | `AND_IMPLIES` | Name present in historical table; not currently decoded locally. | +| `56` | `OR_IMPLIES` | Name present in historical table; not currently decoded locally. | +| `57` | `SPAWN` | Spawn a class/event process; operands include argument bytes, `this` size, class id, and slot. | +| `58` | `SPAWN_INLINE` | Spawn a class/event process using inline argument data; exact use of all operands remains partly unresolved. | +| `59` | `THIS_PID` | Push/current-process identifier. | +| `5A` | `INIT_ROUTINE` | Routine setup; local decoder reads local-byte count. | +| `5B` | `LINE_NUMBER` | Debug/source line marker (`u16`). | +| `5C` | `SYMBOL_INFO` | Debug/symbol metadata reference; includes a relative offset and fixed-width symbol text. Not ordinary executable flow in observed examples. | +| `5D` | `PUSH_RETURN_BYTE` | Push byte-sized return value. | +| `5E` | `PUSH_RETURN_INT` | Push word-sized return value. | +| `5F` | `PUSH_RETURN_LONG` | Push dword-sized return value. | +| `60` | `INT_TO_LONG` | Convert word to dword. | +| `61` | `LONG_TO_INT` | Convert dword to word. | +| `62` | `LOCAL_STRING_DELETE` | Release/delete BP-relative local string. | +| `63` | `LOCAL_STRING_LIST_DELETE` | Release/delete BP-relative local string-list. | +| `64` | `LOCAL_LIST_DELETE` | Release/delete BP-relative local list. | +| `65` | `STRING_REL_DELETE` | Release stack-relative string; local decoder reads an SP-relative displacement. | +| `66` | `LIST_REL_DELETE` | Release stack-relative list. | +| `67` | `STRING_LIST_REL_DELETE` | Release stack-relative string-list. | +| `68` | `COPY_STRING` | Copy/duplicate string value. | +| `69` | `STRING_ADDRESS` | Push address/reference for a BP-relative string. | +| `6A` | `CVT_POINTER_TO_STRING` | Convert pointer/reference to string. | +| `6B` | `CVT_STRING_TO_POINTER` | Convert string to pointer/reference. | +| `6C` | `PARAM_PID_CHANGE` | Change a process parameter; local operands include BP-relative location and copy-type byte. | +| `6D` | `RESULT` | Push process/routine result. | +| `6E` | `MOVE_SP` | Adjust stack pointer by an operand byte. | +| `6F` | `REL_ADDRESS_OF` | Push stack-relative address/reference. | +| `70` | `SEARCH` | Historical name conflicts with the local decoder's `loop` interpretation; unresolved. | +| `71` | `SEARCH_RECURSIVE` | Name present in historical table; not currently decoded locally. | +| `72` | `SEARCH_SURFACE` | Name present in historical table; not currently decoded locally. | +| `73` | `SEARCH_NEXT` | Historical name conflicts with local `loopnext`; unresolved. | +| `74` | `REAL_CHAR_CONSTANT` | Historical name conflicts with local `loopscr`; unresolved. | +| `75` | `FOREACH` | Iterate a list; local decoder reads BP-relative variable, element size, and relative branch. | +| `76` | `FOREACH_STRING` | Iterate a string-list variant; same broad local operand shape as `0x75`. | +| `77` | `SET_PROCESS` | Local decoder identifies this as `set_info`, a process/world notification operation. Exact native-side contract is engine-specific. | +| `78` | `PROCESS_EXCLUDE` | Exclude current process from a subsequent process operation/selection; exact lifecycle effects depend on runtime. | +| `79` | `GLOBAL_ADDRESS_OF` | Push address/reference of global id. | +| `7A` | `END` | End of event/body marker in local parser; bytes after it may be non-code trailing data and must be preserved. | +| `7B` | `REGRESS` | Historical name only; not currently decoded locally. | + +### Decoder coverage is not VM coverage + +The table records the combined opcode vocabulary, not a claim that every byte is executable in every Crusader version. Current parsers stop and preserve unknown/unsupported instruction bytes rather than guessing their lengths. The local C++ interpreter is explicitly partial; its enum/results and handlers should not be mistaken for a complete retail VM implementation. + +There are important known vocabulary mismatches: + +- The historical No Remorse opcode-name list calls `0x70..0x74` `SEARCH`, `SEARCH_RECURSIVE`, `SEARCH_SURFACE`, `SEARCH_NEXT`, and `REAL_CHAR_CONSTANT`. +- The current local decoder calls `0x70` `loop`, `0x73` `loopnext`, and `0x74` `loopscr`; it does not decode `0x71` or `0x72`. +- `0x55`, `0x56`, and `0x7B` have historical names but are not currently decoded by the local parser. + +Until direct runtime/disassembly evidence reconciles these, raw opcodes and operands are authoritative. Do not rewrite or compile these operations based only on a mnemonic. + +## 6. Intrinsics and native capabilities + +### 6.1 Call contract + +Opcode `0x0F` calls an intrinsic by ordinal. The local decoder reads: + +```text +u8 argument_byte_count +u16 intrinsic_ordinal +``` + +The argument-byte count is important evidence for call-site shape, but does not by itself recover parameter types, ownership, or return type. Intrinsic names/signatures shown by tools are metadata hints. The native implementation selected by the running executable is authoritative. + +### 6.2 Variant-specific tables + +Remorse and Regret have separate intrinsic tables. Do not copy a Regret ordinal name/signature into Remorse or vice versa without matching evidence. Development builds/versions may also differ. ScummVM's source separates the runtime tables (`remorse_intrinsics.h`, `regret_intrinsics.h`) from converter naming/signature hints (`convert_usecode_crusader.h`, `convert_usecode_regret.h`). Pentagram also has a Remorse runtime table, but local notes identify it as sparse/older. + +Current related artifacts: + +- [ScummVM Crusader converter names](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/convert/crusader/convert_usecode_crusader.h) +- [ScummVM Regret converter names](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/convert/crusader/convert_usecode_regret.h) +- [ScummVM Remorse runtime table](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/usecode/remorse_intrinsics.h) +- [ScummVM Regret runtime table](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/usecode/regret_intrinsics.h) +- [Detailed Remorse/Regret intrinsic catalog](./usecode-intrinsics-catalog.md) +- [Map-viewer generated intrinsic hint tables](../../crusader_map_viewer/map_renderer/src/lib/usecode-intrinsic-hints.generated.js) +- Local comparison and caveats: [usecode-tooling-comparison.md](./usecode-tooling-comparison.md) and [pentagram-crusader-reference.md](./pentagram-crusader-reference.md) + +The hint tables and converter names are useful for navigation, but they are not a complete substitute for validating the live executable's dispatch table and a representative call site. An intrinsic id with no current name hint remains a valid raw call, not necessarily an invalid opcode. +The hint tables and converter names are useful for navigation, but they are not a complete substitute for validating the live executable's dispatch table and a representative call site. An intrinsic id with no current name hint remains a valid raw call, not necessarily an invalid opcode. + +### Corpus census + +The raw `0x0F` call operands were counted from all non-empty derived event-body windows using the local parser and the variant-specific Remorse/Regret hint sets. The scan parsed 977 Remorse bodies and 1,152 Regret bodies with zero parser exceptions. + +| Variant | Non-empty bodies parsed | `0x0F` call sites | Distinct ordinals present | +|---|---:|---:|---| +| Remorse | 977 | 8,389 | 310 | +| Regret | 1,152 | 10,625 | 349 | + +| Intrinsic ordinal interval | Remorse bytecode | Regret bytecode | +|---|---|---| +| `0x0000..0x0135` | Used; all 310 ordinals observed | Used; all 310 ordinals observed | +| `0x0136..0x015C` | Not observed | Used; all 39 ordinals observed | + +Here, **used** means the raw ordinal occurs in a decoded intrinsic-call instruction; it does not assert runtime reachability or execution frequency. Ghidra's Remorse `Item_Equip` annotation identifies intrinsic ordinals `0x006`/`0x0B5`, and its `Item_Cast` annotation identifies `0x0E8`; their decompilations dispatch `UC_Equip` and `UC_Cast`, agreeing with ScummVM's Remorse runtime table. The local Remorse corpus also calls `0x134` and `0x135`, beyond Pentagram's 308-entry `RemorseIntrinsics` array configured in `GUIApp.cpp`. Treat that older sparse table's omissions as incomplete coverage, not proof that those calls are absent. Pentagram's converter intrinsic names are explicitly for Regret 1.21 and must not be used as Remorse mappings. Keep the raw ordinal authoritative and the selected variant's engine table as a naming hint; this Ghidra pass does not validate every intrinsic's semantics or Regret's native dispatch table. + +### Corpus ordinal name hints + +The inventory below lists each ordinal observed in either main corpus, using the ScummVM Remorse and Regret converter-name arrays linked above. Parenthesized argument lists are omitted for compactness. These are name hints, not verified native signatures or semantics; repeated labels at different ordinals remain distinct entries. `not scanned` means the ordinal is outside the Remorse corpus range counted above, not that Remorse's runtime rejects it. + +| Ordinal | Remorse name hint | Regret name hint | +|---|---|---| +| 0x0000 | byte World::I_getAlertActive | World::I_getAlertActive | +| 0x0001 | int16 Item::I_getFrame | Item::getFrame | +| 0x0002 | void Item::I_setFrame | Item::setFrame | +| 0x0003 | int16 Item::I_getMapArray | Item::getMapNum | +| 0x0004 | int16 Item::I_getStatus | Item::getStatus | +| 0x0005 | void Item::I_orStatus | Item::orStatus | +| 0x0006 | int16 Item::I_equip | Item::equip | +| 0x0007 | byte Item::I_isOnScreen | Item::isEntirelyOnScreen | +| 0x0008 | byte Actor::I_isNPC | Item::isNpc | +| 0x0009 | byte Item::I_getZ | Item::getZ | +| 0x000A | void Item::I_destroy | World::I_gameDifficulty | +| 0x000B | int16 Actor::I_GetNPCDataField0x63_00B | Item::getQLo | +| 0x000C | void Ultima8Engine::I_setAvatarInStasis | Item::destroy | +| 0x000D | byte Item::I_getDirToItem | Actor::I_getUnkByte | +| 0x000E | int16 Actor::I_turnToward | Item::getX | +| 0x000F | void I_playFlic | Item::getY | +| 0x0010 | int16 Item::I_getQLo | Item::playSfxCru | +| 0x0011 | int16 Actor::I_getMap | Item::getShape | +| 0x0012 | void MusicProcess:I_playMusic | Item::I_explode | +| 0x0013 | int16 Item::I_getX | UCMachine::I_rndRange | +| 0x0014 | int16 Item::I_getY | Item::legalCreateAtCoords | +| 0x0015 | void AudioProcess::I_playSFXCru | Item::andStatus | +| 0x0016 | int16 Item::I_getShape | World::I_getControlledNPCNum | +| 0x0017 | void Item::I_explode | Actor::I_getDir | +| 0x0018 | int16 UCMachine::I_rndRange | Actor::I_getLastAnimSet | +| 0x0019 | byte Item::I_legalCreateAtCoords | Item::I_fireWeapon | +| 0x001A | void Item::I_andStatus | Item::create | +| 0x001B | int16 World::I_getControlledNPCNum | Item::popToCoords | +| 0x001C | byte Actor::I_getDir | Actor::I_setDead | +| 0x001D | int16 Actor::I_getLastAnimSet | Item::push | +| 0x001E | int16 Item::I_fireWeapon | Item::I_getEtherealTop | +| 0x001F | byte Item::I_create | Item::getQLo | +| 0x0020 | void Item::I_popToCoords | Item::setQLo | +| 0x0021 | void Actor::I_setDead | Item::getQHi | +| 0x0022 | void Item::I_push | Item::setQHi | +| 0x0023 | int16 Item::I_getEtherealTop | Item::I_getClosestDirectionInRange | +| 0x0024 | void Item::I_setShape | Item::hurl | +| 0x0025 | void Item::I_touch | Item::getCY | +| 0x0026 | int16 Item::I_getQHi | Item::getCX | +| 0x0027 | int16 I_getClosestDirectionInRange | SpriteProcess::I_createSprite | +| 0x0028 | int16 Item::I_hurl | Item::setNpcNum | +| 0x0029 | int16 World::I_gameDifficulty | AudioProcess::I_playSFXCru | +| 0x002A | void AudioProcess::I_playAmbientSFXCru | Item::setShape | +| 0x002B | int16 Item::I_getQLo | Item::pop | +| 0x002C | byte Item::I_inFastArea | AudioProcess::I_stopSFXCru | +| 0x002D | void Item::I_setQHi | Item::isCompletelyOn | +| 0x002E | byte Item::I_legalMoveToPoint | Item::popToContainer | +| 0x002F | byte CurrentMap::I_canExistAtPoint | Actor::I_getHp | +| 0x0030 | void Item::I_pop | Actor::I_getMana | +| 0x0031 | void Item::I_andStatus | Item::getFamily | +| 0x0032 | void Item::I_receiveHit | Actor::destroyContents | +| 0x0033 | byte Actor::I_isBusy | AudioProcess::I_setVolumeForItemSFX | +| 0x0034 | int16 Item::I_getDirFromTo16 | Item::getDirToItem | +| 0x0035 | byte Actor::I_isKneeling | AudioProcess::I_isSfxPlayingForObject | +| 0x0036 | int16 Actor::I_doAnim | Item::I_getRangeIfVisible | +| 0x0037 | byte MainActor::I_addItemCru | AudioProcess::I_playSFXCru | +| 0x0038 | void AudioProcess::I_stopSFXCru | Item::andStatus | +| 0x0039 | byte Actor::I_isDead | Kernel::resetRef | +| 0x003A | byte AudioProcess::I_isSFXPlayingForObject | Item::touch | +| 0x003B | void Item::I_setQLo | Egg::getEggId | +| 0x003C | int16 Item::I_getItemFamily | MainActor::I_addItemCru | +| 0x003D | void Container::I_destroyContents | Actor::I_getMap | +| 0x003E | void Item::I_fallProbably_03E | Item::callEvent11 | +| 0x003F | int16 Egg::I_getEggId | CameraProcess::I_somethingAboutCameraUpdate | +| 0x0040 | void CameraProcess::I_moveTo | AudioProcess::I_stopSFXCru | +| 0x0041 | void CameraProcess::I_setCenterOn | Item::isOn | +| 0x0042 | byte Item::I_getRangeIfVisible | Item::getQHi | +| 0x0043 | void AudioProcess::I_playSFXCru | Item::isOn | +| 0x0044 | byte Item::I_IsOn | Item::getQHi | +| 0x0045 | int16 Item::I_getQHi | Item::isOn | +| 0x0046 | byte Item::I_IsOn | Item::getQHi | +| 0x0047 | int16 Item::I_getQHi | Item::isOn | +| 0x0048 | byte Item::I_IsOn | Item::getQHi | +| 0x0049 | int16 Item::I_getQHi | Item::isOn | +| 0x004A | byte Item::I_IsOn | Item::getQHi | +| 0x004B | int16 Item::I_getQHi | Item::isOn | +| 0x004C | byte Item::I_IsOn | Item::getQHi | +| 0x004D | int16 Item::I_getQHi | Actor::I_getCurrentActivityNo | +| 0x004E | byte Item::I_IsOn | Actor::isDead | +| 0x004F | int16 Item::I_getQHi | Actor::I_clrInCombat | +| 0x0050 | int16 Actor::I_getCurrentActivityNo | Actor::I_setDefaultActivity0 | +| 0x0051 | void Actor::I_clrInCombat | Actor::I_setDefaultActivity1 | +| 0x0052 | void Actor::I_setDefaultActivity0 | Actor::I_setDefaultActivity2 | +| 0x0053 | void Actor::I_setDefaultActivity1 | Actor::I_setActivity | +| 0x0054 | void Actor::I_setDefaultActivity2 | World::I_setControlledNPCNum | +| 0x0055 | void Actor::I_setActivity | Item::I_receiveHit | +| 0x0056 | void World::I_setControlledNPCNum | Game::I_isReleaseBuild | +| 0x0057 | int16 Item::I_getSurfaceWeight | MainActor::I_setMana | +| 0x0058 | byte Item::I_isCentreOn | Item::use | +| 0x0059 | void Item::I_setFrame | Item::setUnkEggType | +| 0x005A | int16 Actor::I_getLastAnimSet | MusicProcess::I_playMusic | +| 0x005B | byte Item::I_legalCreateAtPoint | Item::getSurfaceWeight | +| 0x005C | void Item::I_getPoint | Item::I_isCentreOn | +| 0x005D | void StatusGump::I_hideStatusGump | Item::setFrame | +| 0x005E | int16 MovieGump::I_playMovieOverlay | Actor::I_getLastAnimSet | +| 0x005F | void StatusGump::I_showStatusGump | Ultima8Engine::I_setAvatarInStasis | +| 0x0060 | void Actor::I_setDead | Actor::I_isBusy | +| 0x0061 | void Actor::I_create | Actor::I_getField0x13Flag2 | +| 0x0062 | void CameraProcess::I_somethingAboutCameraUpdate | Actor::I_doAnim | +| 0x0063 | void Actor::I_teleport | Item::legalCreateAtPoint | +| 0x0064 | void Item::I_getFootpad | Item::getPoint | +| 0x0065 | byte Item::I_isInNPC | Item::legalMoveToPoint | +| 0x0066 | int16 Item::I_getQLo | Item::fall | +| 0x0067 | int16 Item::I_getNPCNum | Item::hurl | +| 0x0068 | void Item::I_setNpcNum | Kernel::getNumProcesses | +| 0x0069 | void Item::I_andStatus | Item::getCY | +| 0x006A | void Item::I_move | U8Engine::I_isCfgAnimationOff | +| 0x006B | int16 Game::I_isViolenceEnabled | ResetKeyboardState | +| 0x006C | void Kernel::I_resetRef | MusicProcess::I_pauseMusic | +| 0x006D | int16 Item::I_getNPCNum | MovieGump::I_playMovieCutsceneRegret | +| 0x006E | void Item::I_andStatus | MusicProcess::I_unpauseMusic | +| 0x006F | byte Item::I_isCompletelyOn | Item::isInNpc | +| 0x0070 | byte Ultima8Engine::I_getCrusaderTeleporting | Ultima8Engine::I_setCruStasis | +| 0x0071 | void Ultima8Engine::I_setCrusaderTeleporting | Ultima8Engine::I_clrCruStasis | +| 0x0072 | void Ultima8Engine::I_setCruStasis | PaletteFaderProcess::I_jumpToColor | +| 0x0073 | void Actor::I_setDead | PaletteFaderProcess::I_fadeToGamePal | +| 0x0074 | void Ultima8Engine::I_clrCrusaderTeleporting | Actor::isDead | +| 0x0075 | void Ultima8Engine::I_clrCruStasis | Item::getNpcNum | +| 0x0076 | void AudioProcess::I_stopSFX | IntrinsicReturn0 | +| 0x0077 | int16 PaletteFaderProcess::I_fadeToBlack | Game::I_isViolenceEnabled | +| 0x0078 | void MainActor::I_clrKeycards | Item::unequip | +| 0x0079 | int16 MainActor::I_teleportToEgg | Item::andStatus | +| 0x007A | int16 PaletteFaderProcess::I_fadeToGamePal | Item::move | +| 0x007B | void Actor::I_clrImmortal | Ultima8Engine::I_getCrusaderTeleporting | +| 0x007C | int16 Actor::I_getHp | Ultima8Engine::I_setCrusaderTeleporting | +| 0x007D | void Actor::I_setActivity | Ultima8Engine::I_clrCrusaderTeleporting | +| 0x007E | int16 Item::I_getQuality | Actor::I_turnToward | +| 0x007F | void Item::I_setQuality | PaletteFaderProcess::I_fadeToBlack | +| 0x0080 | int16 Item::I_use | MainActor::I_clrKeycards | +| 0x0081 | int16 MainActor::I_getMaxEnergy | MusicProcess::I_stopMusic | +| 0x0082 | int16 Actor::I_getMana | PaletteFaderProcess::I_jumpToAllBlack | +| 0x0083 | void Actor::I_setMana | I_setUnkFlagA4 | +| 0x0084 | int16 Item::I_getQLo | I_clearUnkFlagA4 | +| 0x0085 | void Actor::I_setImmortal | MainActor::I_switchMap | +| 0x0086 | int16 CameraProcess::I_getCameraX | teleportToEgg | +| 0x0087 | int16 CameraProcess::I_getCameraY | PaletteFaderProcess::I_fadeToGamePal | +| 0x0088 | void Item::I_setMapArray | Actor::I_clrImmortal | +| 0x0089 | int16 Item::I_getNpcNum | Actor::I_setActivity | +| 0x008A | void Item::I_shoot | Item::getQuality | +| 0x008B | int16 Item::I_enterFastArea | Item::setQuality | +| 0x008C | void Item::I_setIsBroken | MainActor::I_getMaxEnergy | +| 0x008D | int16 Item::I_hurl | CameraProcess::I_moveTo | +| 0x008E | int16 Item::I_getNPCNum | Actor::I_setImmortal | +| 0x008F | void PaletteFaderProcess::I_jumpToAllBlack | Camera::getX | +| 0x0090 | void MusicProcess::I_stopMusic | Camera::getY | +| 0x0091 | void I_setSomeMovieGlobal | Item::setMapNum | +| 0x0092 | void I_playMovieCutsceneFullscreen | Item::getNpcNum | +| 0x0093 | void I_clearSomeMovieGlobal | Item::shoot | +| 0x0094 | void Game::I_playCredits | CameraProcess::I_setCenterOn | +| 0x0095 | byte Kernel::I_getCurrentKeyDown | Item::enterFastArea | +| 0x0096 | int16 MainActor::I_teleportToEgg | Item::setBroken | +| 0x0097 | void PaletteFaderProcess:I_jumpToGreyScale | Item::hurl | +| 0x0098 | void I_resetVargasShieldTo500 | Item::getNpcNum | +| 0x0099 | void Item::I_andStatus | Ultima8Engine::I_moveKeyDownRecently | +| 0x009A | void PaletteFaderProcess::I_jumpToNormalPalette | teleportToEgg | +| 0x009B | int16 PaletteFaderProcess::I_fadeToGamePal | Actor::I_createActor | +| 0x009C | int16 PaletteFaderProcess::I_fadeToGamePalWithParam | Actor::I_clrInCombat | +| 0x009D | int16 PaletteFaderProcess::I_fadeToBlack | PaletteFaderProcess::I_jumpToGreyScale | +| 0x009E | int16 PaletteFaderProcess::I_fadeToBlackWithParam | PaletteFaderProcess::I_jumpToNormalPalette | +| 0x009F | int16 PaletteFaderProcess::I_fadeToColor | CruStatusGump::I_showStatusGump | +| 0x00A0 | void Actor::I_setDead | Item::andStatus | +| 0x00A1 | int16 Item::I_getQLo | Item::getUnkEggType | +| 0x00A2 | int16 Item::I_getUnkEggType | Egg::setEggXRange | +| 0x00A3 | void Egg::I_setEggXRange | Item::setFrame | +| 0x00A4 | byte Item::I_overlaps | Item::overlaps | +| 0x00A5 | byte Item::I_isOn | Item::isOn | +| 0x00A6 | int16 I_getAnimationsEnabled | Item::getQHi | +| 0x00A7 | int16 Egg::I_getEggXRange | Actor::I_getLastAnimSet | +| 0x00A8 | void Actor::I_setDead | Item::getCY | +| 0x00A9 | void I_playMovieCutsceneFullscreen | CurrentMap::I_canExistAt | +| 0x00AA | void AudioProcess::I_playSFX | Item::isOn | +| 0x00AB | byte Actor::I_isFalling | Actor::isDead | +| 0x00AC | int16 Item::I_getFamilyOfType | Item::hurl | +| 0x00AD | int16 Item::I_getNPCNum | Item::I_inFastArea | +| 0x00AE | int16 Item::I_getQLo | Item::getQHi | +| 0x00AF | int16 Item::I_getQHi | Item::andStatus | +| 0x00B0 | int16 Item::I_unequip | Item::hurl | +| 0x00B1 | int16 Item::I_spawnUsecodeEvent0x13 | Item::andStatus | +| 0x00B2 | void Item::I_andStatus | Item::hurl | +| 0x00B3 | int32 I_getCurrentTimerTick | Item::andStatus | +| 0x00B4 | void Ultima8Engine::I_setAlertActive | Item::getDirToCoords | +| 0x00B5 | int16 Item::I_equip | MainActor::I_removeItem | +| 0x00B6 | void Ultima8Engine::I_clrAlertActive | I_updateInventoryUI | +| 0x00B7 | int16 Ultima8Engine::I_getAvatarInStasis | Item::getNpcNum | +| 0x00B8 | byte MainActor::I_addItemCru | Item::getCY | +| 0x00B9 | int16 Actor::I_getLastAnimSet | Item::isOn | +| 0x00BA | void Item::I_setQuality | Item::getFootpad | +| 0x00BB | byte CurrentMap::I_canExistAt | Actor::isDead | +| 0x00BC | byte Item::I_isOn | Actor::I_createActorCru | +| 0x00BD | int16 Item::I_hurl | Actor::I_setActivity | +| 0x00BE | int16 Item::I_getQHi | KeypadGump::I_showKeypad | +| 0x00BF | void Item::I_andStatus | Item::andStatus | +| 0x00C0 | int16 Item::I_hurl | ComputerGump::I_readComputer | +| 0x00C1 | void Item::I_andStatus | UCMachine::I_numToStr | +| 0x00C2 | int16 Item::I_hurl | IntrinsicReturn0 | +| 0x00C3 | void Item::I_andStatus | Actor::I_getDir | +| 0x00C4 | int16 KeypadGump::I_showKeypad | Item::getQHi | +| 0x00C5 | byte Item::I_isOn | Item::setQuality | +| 0x00C6 | void SpriteProcess::I_createSprite | Item::hurl | +| 0x00C7 | byte Item::I_getDirFromItem | Actor::I_addHp | +| 0x00C8 | int16 Item::I_hurl | CruHealerProcess::I_create | +| 0x00C9 | int16 Item::I_getQHi | Item::callEvent0A | +| 0x00CA | byte Actor::I_addHp | Item::setBroken | +| 0x00CB | void MainActor::I_switchMap | Item::isOn | +| 0x00CC | byte Actor::I_getInCombat | Actor::I_teleport | +| 0x00CD | void Actor::I_setActivity | Item::I_getDirFromTo16 | +| 0x00CE | int16 Game::I_isReleaseBuild | Item::getQHi | +| 0x00CF | void Item::I_setQAndCombine | Item::isOn | +| 0x00D0 | int16 Item::I_use | Actor::I_isInCombat | +| 0x00D1 | void AudioProcess:I_stopAllSFX | Actor::I_getNPCDataField0x4 | +| 0x00D2 | void I_playMovieCutscene | Actor::I_setCombatTactic | +| 0x00D3 | void I_clearKeyboardState | Actor::I_setDead | +| 0x00D4 | void I_playSFX | CameraProcess::I_getCameraY | +| 0x00D5 | int16 Item::I_use | Actor::I_getEquip | +| 0x00D6 | byte CameraProcess::I_getCameraZ | Actor::I_setEquip | +| 0x00D7 | int16 Actor::I_getLastAnimSet | Actor::I_getDefaultActivity0 | +| 0x00D8 | void Actor::I_setDead | Actor::I_getDefaultActivity1 | +| 0x00D9 | int16 Item::I_getQLo | Actor::I_getDefaultActivity2 | +| 0x00DA | void PaletteFaderProcess::I_setPalToAllGrey | Actor::I_getLastAnimSet | +| 0x00DB | void Actor::I_setActivity | Actor::I_isFalling | +| 0x00DC | byte Item::I_isOn | Item::getQLo | +| 0x00DD | int16 Actor::I_getLastActivityNo | Item::getQHi | +| 0x00DE | void Actor::I_setCombatTactic | Item::getNpcNum | +| 0x00DF | int16 Actor::I_getEquip | Item::I_setField0x81 | +| 0x00E0 | void Actor::I_setEquip | Item::hurl | +| 0x00E1 | int16 Actor::I_getDefaultActivity0 | Actor::I_setDead | +| 0x00E2 | int16 Actor::I_getDefaultActivity1 | Item::getQLo | +| 0x00E3 | int16 Actor::I_getDefaultActivity2 | Item::getCY | +| 0x00E4 | int16 Actor::I_getLastAnimSet | Item::getNpcNum | +| 0x00E5 | void Actor::I_setTarget | Item::hurl | +| 0x00E6 | void Actor::I_SetNPCDataField0x63_0E6 | Item::getNpcNum | +| 0x00E7 | void Actor::I_setDead | Item::hurl | +| 0x00E8 | int16 Item::I_cast | Item::getNpcNum | +| 0x00E9 | void Item::I_andStatus | Item::hurl | +| 0x00EA | int16 Item::I_getQLo | Item::getNpcNum | +| 0x00EB | int16 I_GetQOfAvatarInventoryItem0x4ed_0EB | Item::hurl | +| 0x00EC | void Item::I_popToEnd | Item::getNpcNum | +| 0x00ED | void Item::I_popToContainer | Item::hurl | +| 0x00EE | void BatteryChargerProcess::I_create | Item::getNpcNum | +| 0x00EF | int16 Kernel::I_getNumProcesses | Item::hurl | +| 0x00F0 | int16 Item::I_getQHi | Item::getNpcNum | +| 0x00F1 | byte Item::I_isOn | Item::hurl | +| 0x00F2 | void Actor::I_setActivity | Item::getNpcNum | +| 0x00F3 | int16 Item::I_getQHi | Item::hurl | +| 0x00F4 | int16 Item::I_getQ | Item::getNpcNum | +| 0x00F5 | void Item::I_setQ | Item::hurl | +| 0x00F6 | void CruHealer::I_create_0F6 | Item::getNpcNum | +| 0x00F7 | int16 Item::I_hurl | Item::andStatus | +| 0x00F8 | int16 Item::I_getNPCNum | Actor::I_setDead | +| 0x00F9 | int16 Item::I_hurl | Item::getQLo | +| 0x00FA | byte Item::I_isOn | Actor::I_setDead | +| 0x00FB | int16 Item::I_getQHi | Dtable::I_getMaxHPForNPC | +| 0x00FC | void Item::I_andStatus | Actor::I_setHP | +| 0x00FD | byte MainActor::I_hasKeycard | Item::getQLo | +| 0x00FE | void ComputerGump::I_readComputer | BatteryChargerProcess::I_create | +| 0x00FF | int16 UCMachine::I_numToStr | Item::hurl | +| 0x0100 | int16 Item::I_getNPCNum | Item::andStatus | +| 0x0101 | void Item::I_andStatus | Item::isOn | +| 0x0102 | int16 Item::I_getNPCNum | Actor::isDead | +| 0x0103 | byte Item::I_isCrusTypeNPC | Actor::I_setActivity | +| 0x0104 | void Item::I_andStatus | Item::getQHi | +| 0x0105 | int16 Item::I_getNPCNum | Actor::I_getLastAnimSet | +| 0x0106 | void Item::I_andStatus | Actor::I_setDead | +| 0x0107 | int16 Item::I_getNPCNum | Item::getQLo | +| 0x0108 | void Item::I_andStatus | Item::isOn | +| 0x0109 | int16 Item::I_getNPCNum | Item::getQHi | +| 0x010A | void Item::I_andStatus | Item::isOn | +| 0x010B | int16 Item::I_getNPCNum | Item::getQHi | +| 0x010C | void Item::I_andStatus | Item::hurl | +| 0x010D | int16 Item::I_getNPCNum | Item::getNpcNum | +| 0x010E | void Item::I_andStatus | Item::getCY | +| 0x010F | int16 Item::I_getNPCNum | Item::hurl | +| 0x0110 | void Item::I_andStatus | Item::isOn | +| 0x0111 | int16 Item::I_getNPCNum | MainActor::I_hasKeycard | +| 0x0112 | byte Actor::I_getDir | IntrinsicReturn0 | +| 0x0113 | int16 UCMachine::I_numToStr | Actor::isDead | +| 0x0114 | void Item::I_andStatus | Actor::I_clrImmortal | +| 0x0115 | int16 Item::I_getNPCNum | UCMachine::I_numToStr | +| 0x0116 | byte Item::I_fireDistance | Item::getQHi | +| 0x0117 | void Item::I_andStatus | Actor::I_setActivity | +| 0x0118 | int16 Item::I_hurl | Item::andStatus | +| 0x0119 | void Item::I_setIsBroken | Item::getNpcNum | +| 0x011A | void Item::I_andStatus | Item::andStatus | +| 0x011B | byte Item::I_getTypeFlag | Item::getNpcNum | +| 0x011C | int16 Item::I_getNPCNum | Item::I_isCrusTypeNPC | +| 0x011D | int16 Item::I_hurl | Item::andStatus | +| 0x011E | int16 Item::I_getCY | Item::getNpcNum | +| 0x011F | byte Item::I_getCZ | Item::AvatarStoleSomehting | +| 0x0120 | int16 Item::I_getCX | Item::andStatus | +| 0x0121 | byte Actor::I_getDir | Item::getNpcNum | +| 0x0122 | byte Actor::I_isDead | Item::getQ | +| 0x0123 | int16 Item::I_getNPCNum | Item::setQ | +| 0x0124 | int16 Actor::I_getLastAnimSet | Item::andStatus | +| 0x0125 | void Item::I_setQuality | Item::getNpcNum | +| 0x0126 | int16 UCMachine::I_numToStr | Item::andStatus | +| 0x0127 | byte Item::I_getDirToCoords | Item::getNpcNum | +| 0x0128 | void Item::I_andStatus | Item::andStatus | +| 0x0129 | int16 Item::I_getNPCNum | Item::getNpcNum | +| 0x012A | void Item::I_setIsBroken | Item::andStatus | +| 0x012B | int16 IItem::I_getCY | Item::getNpcNum | +| 0x012C | byte Item::I_isOn | Item::andStatus | +| 0x012D | void Item::I_getFootpadData | Item::getNpcNum | +| 0x012E | byte Actor::I_isDead | Actor::I_getDir | +| 0x012F | int16 Actor::I_createActorCru | Item::andStatus | +| 0x0130 | void Actor::I_clrImmortal | Item::getNpcNum | +| 0x0131 | void Actor::I_setActivity | Intrinsic0131 | +| 0x0132 | void Item::I_andStatus | Item::andStatus | +| 0x0133 | int16 Item::I_getQHi | Item::hurl | +| 0x0134 | void WeaselGump::I_showGump | Item::andStatus | +| 0x0135 | void Actor::I_setDead | Camera::getY | +| 0x0136 | not scanned | Camera::getZ | +| 0x0137 | not scanned | CruStatusGump::I_hideStatusGump | +| 0x0138 | not scanned | Actor::I_clrInCombat | +| 0x0139 | not scanned | Item::getTypeFlagCrusader | +| 0x013A | not scanned | Item::getNpcNum | +| 0x013B | not scanned | Item::hurl | +| 0x013C | not scanned | Item::getCY | +| 0x013D | not scanned | Item::getCZ | +| 0x013E | not scanned | Item::setFrame | +| 0x013F | not scanned | AudioProcess::I_playAmbientSFX | +| 0x0140 | not scanned | AudioProcess::I_isSFXPlaying | +| 0x0141 | not scanned | World::I_clrAlertActiveRegret | +| 0x0142 | not scanned | PaletteFaderProcess::I_fadeToGivenColor | +| 0x0143 | not scanned | Actor::isDead | +| 0x0144 | not scanned | Actor::I_setDead | +| 0x0145 | not scanned | Game::I_playCredits | +| 0x0146 | not scanned | PaletteFaderProcess::I_jumpToAllGrey | +| 0x0147 | not scanned | Item::I_getFamilyOfType | +| 0x0148 | not scanned | Item::getNpcNum | +| 0x0149 | not scanned | Item::getQLo | +| 0x014A | not scanned | Item::andStatus | +| 0x014B | not scanned | Ultima8Engine::getCurrentTimerTick | +| 0x014C | not scanned | World::I_setAlertActiveRegret | +| 0x014D | not scanned | Ultima8Engine::I_getAvatarInStasis | +| 0x014E | not scanned | MainActor::I_addItemCru | +| 0x014F | not scanned | Egg::getEggXRange | +| 0x0150 | not scanned | Actor::I_clrInCombat | +| 0x0151 | not scanned | PaletteFaderProcess::I_jumpToColor | +| 0x0152 | not scanned | Item::setFrame | +| 0x0153 | not scanned | UCMachine::I_numToStr | +| 0x0154 | not scanned | Actor::I_getDir | +| 0x0155 | not scanned | UCMachine::I_numToStr | +| 0x0156 | not scanned | Item::isOn | +| 0x0157 | not scanned | Actor::I_getDir | +| 0x0158 | not scanned | Actor::I_setDead | +| 0x0159 | not scanned | Item::getQHi | +| 0x015A | not scanned | Item::getQLo | +| 0x015B | not scanned | UCMachine::I_numToStr | +| 0x015C | not scanned | Actor::I_getDir | + +### 6.3 Capability families exposed through native calls + +Across the Crusader runtime tables and observed scripts, intrinsic calls expose or mediate capabilities in these broad families: + +- **Items and world objects:** read/write item properties; create, destroy, move, push/pop, grab, drop, and transfer objects; query shape/family/type, frame, status/quality/quantity, coordinates, map placement, overlap/reach, and containment. +- **Actors and combat:** query or set actor state and statistics, targets, direction, movement/activity, animation, hit/damage behavior, and combat state; create or teleport actors where the variant table provides the operation. +- **Processes and scheduling:** inspect process identifiers/results, spawn or coordinate work, suspend/yield, exclude processes, and schedule delayed/tick-driven behavior. +- **Map and trigger systems:** query/update eggs, trigger/controller state, map and coordinate relationships, enter/leave activation regions, and spawn or dispatch event-driven effects. +- **User interface and text:** interact with game UI, gumps, readable objects, prompts, or other presentation services where supported by that build's intrinsic table. +- **Graphics and camera:** camera movement/centering, sprite effects, palette transitions, fades, screen effects, and related presentation operations. +- **Audio and music:** play/stop sound effects and music, query sound state, or alter audio parameters where provided. +- **Time, randomness, and game state:** query or update selected game-time state, obtain random values, and access variant-specific flags or globals. +- **Global storage and VM-managed values:** read/write globals and use the VM's pointer/string/list support. A script-visible pointer is a VM/runtime reference, not an unrestricted host pointer. + +These are capabilities of the **bytecode plus the installed native table**, not all built-in bytecode instructions. A particular game version may leave an ordinal unused, map it differently, or implement it only in one variant. The table is not an operating-system API. + +### 6.4 Events versus intrinsics + +Event slots are script entry points. Intrinsics are native callable services. For example, an event handler can be invoked by the engine for `use`, and that handler can then call item or audio intrinsics. Do not conflate: + +- `equip` event slot `0x0A` with any specific intrinsic ordinal; +- event `cast` slot `0x11` with spellcasting; +- `spawn` opcode `0x57` with a native intrinsic; +- class/event dispatch opcode `0x11` with intrinsic call opcode `0x0F`. + +## 7. What scripts can do + +Subject to the event and intrinsic tables of the active game build, Crusader USECODE can: + +- implement class-specific callbacks and call other class/event handlers; +- branch, loop, compare, perform integer/dword arithmetic and bit operations; +- use local/member/global storage, references, indirect access, and result values; +- manipulate strings, lists, string-lists, and aggregate/“huge” values; +- create and control asynchronous processes, yield/suspend, and coordinate process results; +- use native game services to inspect and mutate items, actors, world state, UI, graphics, audio, timing, and trigger behavior; +- attach behavior to engine lifecycle, interaction, movement, hit, schedule, spawn, and proximity callbacks. + +This is an event/process scripting system integrated into the game engine. It can perform substantial gameplay logic because its intrinsic layer gives scripts access to native services. + +## 8. What the format alone cannot establish + +These are limits on what can safely be concluded from the file/bytecode representation, not absolute claims that a native executable could never provide the behavior: + +- **No intrinsic implementation from an ordinal alone.** The number, argument bytes, and optional converter name do not define the native routine's full behavior or guarantee the ordinal exists in another build. +- **No class behavior from a slot label alone.** A slot can be absent, empty, repurposed, or class-specific. Event-name tables are vocabulary hints. +- **No lossless source recovery from pseudocode alone.** Decompilation can omit exact operand encodings, opaque values, padding, symbol records, and trailers. Original bytes and offsets must be retained for exact round trips. +- **No settled meaning for every header/row field.** The leading word in each 6-byte event row and the count/base mismatch remain unresolved. +- **No settled semantics for all instructions.** The opcode-name list and local decoder disagree in places; unsupported/unknown opcodes cannot safely be skipped without a proven length rule. +- **No proof of arbitrary host/OS access.** The known model calls game-provided intrinsics. No general-purpose file/network/process/OS syscall interface is established by the bytecode specification. +- **No claim that each game feature is script-owned.** Engine code performs event selection, VM process management, native operations, and state transitions. A script can request native actions but does not necessarily implement those systems itself. +- **No inheritance or virtual-method guarantee.** The established call form names a class and event ordinal. Any higher-level inheritance/dispatch claim needs separate evidence. +- **No guarantee that all listed object-oriented concepts are source-language constructs.** Names such as “class,” “member,” and “routine” describe the compiled runtime representation; a complete original source language/compiler specification has not been recovered. + +## 9. Runtime execution model + +The most defensible high-level model is: + +1. The engine or another script selects a class and event slot. +2. Runtime class/event data resolves that slot to a code offset/body. +3. A usecode process/context is created with item and optional event/context parameters. +4. The interpreter executes variable-length bytecode against local/member/global state and a VM evaluation stack. +5. Bytecode may call another event, spawn a process, call an intrinsic, suspend/yield, or return/end. +6. The engine's process scheduler resumes suspended work and applies native/world side effects. + +The local `rebuild/remorse` model records process/context layout and partial opcode semantics in [usecode_vm.h](../rebuild/remorse/include/remorse/usecode_vm.h), [usecode_vm.cpp](../rebuild/remorse/src/usecode_vm.cpp), and [usecode_vm_tests.cpp](../rebuild/remorse/tests/usecode_vm_tests.cpp). Those are explicitly partial models; passing their tests proves the model's tested behavior, not full equivalence to every retail interpreter path. + +## 10. Remorse, Regret, and other version boundaries + +| Area | Shared evidence | Must remain variant-specific | +|---|---|---| +| Archive/class indexing | FLEX object indexing, class object at `class_id + 2`, 6-byte event rows, event ordinals | Exact class inventory and data bytes | +| Event vocabulary | Shared Crusader event-name table `0x00..0x1f` | Presence and behavior of each class/slot | +| Bytecode | Broad shared opcode vocabulary | Actual use, edge semantics, version-specific opcodes and compiler artifacts | +| Intrinsics | Same general native-call architecture | Ordinal-to-function map, signature, availability, return semantics | +| Debug/symbol data | Symbol and line records occur in bodies | Exact trailer layout and compiler/version details | +| Runtime | Process-based interpreter model | Context fields, startup globals, scheduler details, and implementation differences | + +**Remorse global-index conflict:** ScummVM's runtime source initializes global `0x003C` to avatar number `1`, while Pentagram's scratch dump for Remorse 1.01 starts at `0x003D`. The current Ghidra pass traced event dispatch and slot materialization, not a version-matched global initializer, so this remains unresolved and version-qualified. See [Pentagram's Crusader reference note](./pentagram-crusader-reference.md) for the competing evidence. + +Do not infer retail Remorse behavior solely from Regret samples, or vice versa. Demo, regional, and patched executables must likewise be recorded as separate evidence targets where their tables differ. + +## 11. Safe parsing and round-trip requirements + +Any parser, editor, or writer claiming to preserve Crusader USECODE should: + +1. preserve the original archive, entry order, sparse entries, class bytes, and unknown objects; +2. bounds-check FLEX offsets/sizes and class/event tables before reading; +3. preserve raw event-row bytes, including the unresolved leading word; +4. store raw event/body byte slices and the exact offsets used to derive them; +5. distinguish absent rows, valid zero-offset values, malformed rows, and unresolved layouts; +6. retain unsupported instruction bytes rather than discarding or guessing their lengths; +7. preserve debug/symbol data and bytes after `END`; +8. use the correct Remorse/Regret intrinsic hint table and retain the raw ordinal and argument-byte count regardless of naming; +9. require unchanged inputs to round-trip byte-for-byte before claiming a lossless format edit path; +10. write modified archives to a separate output and validate with an independent parser/runtime. + +The current product/editor path and remaining round-trip milestones are in [usecode-roundtrip-ir.md](./usecode-roundtrip-ir.md). The local proof-of-concept parser is [poc_crusader_usecode_parser.py](../tools/poc_crusader_usecode_parser.py); the user-facing map-viewer implementation is [usecode-decompiler.js](../../crusader_map_viewer/map_renderer/src/lib/usecode-decompiler.js). + +## 12. Primary references + +### Local evidence + +- [USECODE extractor](../tools/extract_eusecode_flx.py) +- [USECODE bytecode parser](../tools/poc_crusader_usecode_parser.py) +- [USECODE VM model](../rebuild/remorse/src/usecode_vm.cpp) +- [Round-trip and format evidence](./usecode-roundtrip-ir.md) +- [Pentagram/ScummVM comparison and local caveats](./usecode-tooling-comparison.md) +- [Pentagram reference investigation](./pentagram-crusader-reference.md) +- [Event-slot behavior notes](./usecode-event-slots-combine-cast-fast-area.md) +- [Equip/unequip event behavior](./usecode-equipment-system.md) + +### External implementation references + +- [ScummVM USECODE class/event interface](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/usecode/usecode.h) +- [ScummVM Crusader FLEX/class reader](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/usecode/usecode_flex.cpp) +- [ScummVM Crusader event-offset resolver](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/usecode/usecode.cpp) +- [ScummVM Crusader opcode/event/intrinsic converter tables](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/convert/crusader/convert_usecode_crusader.h) +- [Pentagram Crusader converter table](https://github.com/pentagram-u8/pentagram/blob/master/convert/crusader/ConvertUsecodeCrusader.h) +- [Pentagram Crusader FLEX/class reader](https://github.com/pentagram-u8/pentagram/blob/master/usecode/UsecodeFlex.cpp) +- [Pentagram Crusader FLEX/class reader](https://github.com/pentagram-u8/pentagram/blob/master/usecode/UsecodeFlex.cpp) +- [Pentagram Remorse runtime table](https://github.com/pentagram-u8/pentagram/blob/master/usecode/remorseintrinsics.h) +- [Pentagram Remorse table setup and entry count](https://github.com/pentagram-u8/pentagram/blob/master/kernel/GUIApp.cpp) + +External implementation links describe those projects' code and conventions. For local owner-loaded Crusader data, the raw samples and locally validated extraction rules in this repository take precedence wherever the implementations conflict. + +## 13. Open Mysteries for Investigation + +These questions have plausible, testable evidence paths. Keep results qualified by game, executable version, and archive; do not promote a shared-implementation convention to a Crusader fact without local confirmation. + +- [ ] **Class header and event-table extent:** Determine why ScummVM/Pentagram's event-count formula disagrees with sampled owner-loaded records. Compare bytes `8..11`, table boundaries, and code anchors across Remorse, Regret, demo, regional, and patched archives; verify any proposed formula against every class record. +- [ ] **Leading event-row word:** Establish what the unknown `u16` at the start of each six-byte row encodes. Correlate values with event presence, slot, class, and build, then trace any runtime or loader use before assigning meaning. +- [ ] **Event code-offset convention:** Confirm the `code_base_minus_one` and 1-based displacement interpretation, including zero offsets, duplicate or out-of-order offsets, and how the final body boundary is chosen. Check edge cases against raw class bytes and the runtime's indexed records. +- [ ] **Event-body framing:** Recover the fields and purpose of the 14-byte execution prefix, debug/symbol records, `END`, and trailing bytes. Compare bodies from multiple compiler/build variants and verify that parsing preserves all bytes while locating executable instructions correctly. +- [ ] **Unresolved call/process opcodes:** Determine the target and calling/return conventions of `0x10` (`NEAR_ROUTINE_CALL`), and the exact operand and inline-data layout of `0x58` (`SPAWN_INLINE`). Use representative bytecode call sites and the matching executable's interpreter paths. +- [ ] **Conflicting or undecoded opcodes:** Reconcile historical names and local decoder interpretations for `0x54..0x56`, `0x70..0x74`, and `0x7B`. Trace dispatch in each relevant retail interpreter and validate candidate instruction boundaries against real bodies; do not infer operand lengths from names. +- [ ] **VM value and stack semantics:** Specify ownership, lifetime, and representation for strings, lists, string-lists, references, and “huge” values; verify stack effects, result propagation, and cleanup behavior using interpreter code plus representative scripts, especially around suspend/return. +- [ ] **Intrinsic contracts by build:** Validate ordinal-to-native dispatch, argument types/order, return convention, and side effects independently for Remorse and Regret. Prioritize frequently used or ambiguously named ordinals, Remorse `0x134`/`0x135`, and Regret's native table, which is not validated here. +- [ ] **High event-slot meanings:** Identify behavior for class-local slots above `0x1F` (`0x20..0x4B` in Remorse and `0x20..0x51` in Regret). Cluster bodies by bytecode and class, then trace native callers and observed effects before proposing labels. +- [ ] **Event dispatch edge cases:** Determine how absent, empty, or unsupported event slots affect native fallbacks, and whether higher-level inheritance or virtual dispatch exists beyond the observed class-id/slot lookup. Trace callers and dispatcher behavior for representative slots, including `setActivity`. +- [ ] **Remorse global-index discrepancy:** Resolve whether global `0x003C` or `0x003D` holds the avatar number in each Remorse release. Inspect version-matched executable initialization and compare with the corresponding data/archive rather than relying on cross-version ScummVM/Pentagram notes. +- [ ] **Compiler and source-language model:** Establish which source-level constructs are actually supported by evidence, including class/member layout, routine calls, and any inheritance. Seek compiler-produced samples, symbol/debug metadata, or controlled runtime tests; keep representation terminology distinct from proven source-language features. diff --git a/docs/usecode-intrinsics-catalog.md b/docs/usecode-intrinsics-catalog.md new file mode 100644 index 0000000..06f6987 --- /dev/null +++ b/docs/usecode-intrinsics-catalog.md @@ -0,0 +1,396 @@ +# Crusader USECODE Intrinsic Catalog + +**Status:** Evidence-backed reference catalog; names/signatures remain implementation hints unless separately verified. +**Scope:** Main local Remorse and Regret owner-loaded bytecode corpora; demo, Japanese, and 1.01 corpora are excluded from usage counts. +**Last consolidated:** 2026-10-05 + +This companion holds the per-ordinal detail that would make the main [USECODE format specification](./usecode-format-specification.md) unwieldy: full converter prototypes, variant-specific mappings, and measured bytecode call shapes. It complements rather than replaces the main specification's aggregate census. + +## How to read the catalog + +Bytecode opcode `0x0F` stores an argument-byte count (`u8`) followed by an intrinsic ordinal (`u16`). The usage cells below report `call sites / event bodies / arg_bytes histogram`; histogram values are hexadecimal byte counts followed by their call-site frequencies. They describe decoded static call sites, not runtime reachability or execution frequency. + +`not scanned` means an ordinal lies outside that variant's measured corpus range; it is not equivalent to zero calls or a missing runtime function. A `0 / 0 / -` cell means the ordinal was inside the scanned range but no decoded calls were found. Each event body is counted at most once per ordinal, even if it calls that ordinal repeatedly. + +Converter prototypes are copied from the ScummVM converter-name arrays. Parameter lists are retained as published there, but remain hints: `arg_bytes` alone cannot establish parameter types, return values, ownership, or calling convention. `IntrinsicXXXX`, `IntrinsicReturn0`, and `UNUSEDIntXXX` are intentionally retained where the source has no better name. + +## Corpus and source evidence + +| Variant | Non-empty bodies parsed | Intrinsic calls | Distinct ordinals | Measured ordinal range | Converter-name entries | Unsupported/unknown stops | Parser exceptions | +|---|---:|---:|---:|---|---:|---:|---:| +| Remorse | 977 | 8,389 | 310 | 0x0000..0x0135 | 311 | 0 | 0 | +| Regret | 1,152 | 10,625 | 349 | 0x0000..0x015C | 350 | 0 | 0 | + +The corpus scan uses the local parser's decoded event-body windows and the map-viewer bytecode decoder. It agrees with the main specification's body/call/distinct-ordinal totals. The converter arrays include entries beyond one or both measured corpora; those extra source entries are listed below but receive `not scanned` usage cells when outside the relevant corpus range. + +Primary source arrays: [ScummVM Remorse converter names](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/convert/crusader/convert_usecode_crusader.h) and [ScummVM Regret converter names](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/convert/crusader/convert_usecode_regret.h). Runtime implementations are separate: [Remorse runtime table](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/usecode/remorse_intrinsics.h) and [Regret runtime table](https://github.com/scummvm/scummvm/blob/master/engines/ultima/ultima8/usecode/regret_intrinsics.h). + +Pentagram's Remorse table is sparse/older and is configured with 308 entries; that count is not a cap on local Remorse bytecode, which calls ordinals `0x0134` and `0x0135`. See [the local Pentagram comparison](./pentagram-crusader-reference.md). + +## Ordinal catalog + +Each row is one source ordinal. Repeated prototype labels are not deduplicated because the numeric ordinal is part of the callable identity. Converter-only tail entries are retained with `not scanned` usage. + +| Ordinal | Remorse converter prototype | Remorse calls / bodies / arg_bytes | Regret converter prototype | Regret calls / bodies / arg_bytes | +|---|---|---|---|---| +| 0x0000 | `byte World::I_getAlertActive(void)` | 17 / 14 / `0x00:17` | `World::I_getAlertActive()` | 25 / 20 / `0x00:25` | +| 0x0001 | `int16 Item::I_getFrame(Item *)` | 466 / 248 / `0x04:466` | `Item::getFrame(void)` | 566 / 378 / `0x04:566` | +| 0x0002 | `void Item::I_setFrame(Item *, frame)` | 98 / 41 / `0x06:98` | `Item::setFrame(uint16)` | 53 / 32 / `0x06:53` | +| 0x0003 | `int16 Item::I_getMapArray(Item *)` | 63 / 51 / `0x04:63` | `Item::getMapNum(void)` | 84 / 72 / `0x04:84` | +| 0x0004 | `int16 Item::I_getStatus(Item *)` | 149 / 134 / `0x04:149` | `Item::getStatus(void)` | 150 / 136 / `0x04:150` | +| 0x0005 | `void Item::I_orStatus(Item *, uint16 flags)` | 75 / 65 / `0x06:75` | `Item::orStatus(sint16)` | 84 / 72 / `0x06:84` | +| 0x0006 | `int16 Item::I_equip(6 bytes)` | 2 / 1 / `0x06:2` | `Item::equip(sint16)` | 10 / 2 / `0x06:10` | +| 0x0007 | `byte Item::I_isOnScreen(Item *)` | 23 / 14 / `0x04:23` | `Item::isEntirelyOnScreen()` | 50 / 36 / `0x04:50` | +| 0x0008 | `byte Actor::I_isNPC(Item *)` | 40 / 35 / `0x04:40` | `Item::isNpc(void)` | 48 / 36 / `0x04:48` | +| 0x0009 | `byte Item::I_getZ(Item *)` | 420 / 183 / `0x04:420` | `Item::getZ(void)` | 572 / 313 / `0x04:572` | +| 0x000A | `void Item::I_destroy(Item *)` | 206 / 128 / `0x04:206` | `World::I_gameDifficulty()` | 64 / 45 / `0x00:64` | +| 0x000B | `int16 Actor::I_GetNPCDataField0x63_00B(Actor *)` | 54 / 37 / `0x04:54` | `Item::getQLo(void)` | 8 / 3 / `0x04:8` | +| 0x000C | `void Ultima8Engine::I_setAvatarInStasis(int)` | 115 / 47 / `0x02:115` | `Item::destroy(void)` | 252 / 193 / `0x04:252` | +| 0x000D | `byte Item::I_getDirToItem(Item *, itemno)` | 38 / 21 / `0x06:38` | `Actor::I_getUnkByte()` | 77 / 60 / `0x04:77` | +| 0x000E | `int16 Actor::I_turnToward(Actor *, direction, dir_16)` | 74 / 38 / `0x08:74` | `Item::getX(void)` | 561 / 313 / `0x04:561` | +| 0x000F | `void I_playFlic(void), int16 I_playFlic(Item *, char *name, int16 sizex, int16 sizey)` | 407 / 31 / `0x0C:407` | `Item::getY(void)` | 561 / 313 / `0x04:561` | +| 0x0010 | `int16 Item::I_getQLo(Item *)` | 5 / 2 / `0x04:5` | `Item::playSfxCru()` | 710 / 327 / `0x06:710` | +| 0x0011 | `int16 Actor::I_getMap(4 bytes)` | 137 / 41 / `0x04:137` | `Item::getShape(void)` | 341 / 94 / `0x04:341` | +| 0x0012 | `void MusicProcess:I_playMusic(int trackno)` | 20 / 2 / `0x02:20` | `Item::I_explode()` | 81 / 54 / `0x08:81` | +| 0x0013 | `int16 Item::I_getX(Item *)` | 448 / 193 / `0x04:448` | `UCMachine::I_rndRange()` | 185 / 72 / `0x04:185` | +| 0x0014 | `int16 Item::I_getY(Item *)` | 446 / 193 / `0x04:446` | `Item::legalCreateAtCoords(uint16,uint16,uint16,uint16,uint16)` | 53 / 43 / `0x0E:53` | +| 0x0015 | `void AudioProcess::I_playSFXCru(Item *, uint16 sfxnum)` | 342 / 206 / `0x06:342` | `Item::andStatus(void)` | 1 / 1 / `0x06:1` | +| 0x0016 | `int16 Item::I_getShape(Item *)` | 289 / 94 / `0x04:289` | `World::I_getControlledNPCNum()` | 107 / 72 / `0x00:107` | +| 0x0017 | `void Item::I_explode(Item *, exptype, destroy_item)` | 74 / 45 / `0x08:74` | `Actor::I_getDir()` | 120 / 12 / `0x04:120` | +| 0x0018 | `int16 UCMachine::I_rndRange(uint16 x, uint16 y)` | 148 / 61 / `0x04:148` | `Actor::I_getLastAnimSet()` | 1 / 1 / `0x04:1` | +| 0x0019 | `byte Item::I_legalCreateAtCoords(Item *, int16 shapeno, int16 frame, int16 x, int16 y, int16 z)` | 12 / 7 / `0x0E:12` | `Item::I_fireWeapon()` | 93 / 21 / `0x10:93` | +| 0x001A | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Item::create(uint16,uint16)` | 312 / 118 / `0x08:312` | +| 0x001B | `int16 World::I_getControlledNPCNum()` | 67 / 42 / `0x00:67` | `Item::popToCoords(uint16,uint16,uint8)` | 405 / 210 / `0x0A:405` | +| 0x001C | `byte Actor::I_getDir(4 bytes)` | 136 / 22 / `0x04:136` | `Actor::I_setDead()` | 1 / 1 / `0x04:1` | +| 0x001D | `int16 Actor::I_getLastAnimSet(4 bytes)` | 2 / 2 / `0x04:2` | `Item::push(void)` | 199 / 137 / `0x04:199` | +| 0x001E | `int16 Item::I_fireWeapon(Item *, x, y, z, byte, int, byte)` | 18 / 6 / `0x10:18` | `Item::I_getEtherealTop()` | 29 / 9 / `0x00:29` | +| 0x001F | `byte Item::I_create(Item *, uint16 shapenum, uint16 framenum)` | 226 / 90 / `0x08:226` | `Item::getQLo(void)` | 192 / 103 / `0x04:192` | +| 0x0020 | `void Item::I_popToCoords(Item *, uint16 x, uint16 y, uint16 z)` | 310 / 144 / `0x0A:310` | `Item::setQLo(sint16)` | 147 / 101 / `0x06:147` | +| 0x0021 | `void Actor::I_setDead(4 bytes)` | 1 / 1 / `0x04:1` | `Item::getQHi(void)` | 4 / 4 / `0x04:4` | +| 0x0022 | `void Item::I_push(Item *)` | 131 / 74 / `0x04:131` | `Item::setQHi(sint16)` | 115 / 51 / `0x06:115` | +| 0x0023 | `int16 Item::I_getEtherealTop(void)` | 33 / 9 / `0x00:33` | `Item::I_getClosestDirectionInRange()` | 5 / 5 / `0x0E:5` | +| 0x0024 | `void Item::I_setShape(Item *, int16 shapeno)` | 147 / 87 / `0x06:147` | `Item::hurl(sint16,sint16,sint16,sint16)` | 2 / 2 / `0x0C:2` | +| 0x0025 | `void Item::I_touch(Item *)` | 64 / 34 / `0x04:64` | `Item::getCY(void)` | 2 / 1 / `0x04:2` | +| 0x0026 | `int16 Item::I_getQHi(Item *)` | 26 / 13 / `0x04:26` | `Item::getCX(void)` | 27 / 17 / `0x04:27` | +| 0x0027 | `int16 I_getClosestDirectionInRange(x1, y1, x2, y2, numdirs, mindir, maxdir)` | 5 / 5 / `0x0E:5` | `SpriteProcess::I_createSprite()` | 85 / 49 / `0x0E:85` | +| 0x0028 | `int16 Item::I_hurl(Item *,8 bytes)` | 2 / 2 / `0x0C:2` | `Item::setNpcNum(sint16)` | 45 / 29 / `0x06:45` | +| 0x0029 | `int16 World::I_gameDifficulty(void)` | 27 / 21 / `0x00:27` | `AudioProcess::I_playSFXCru()` | 75 / 70 / `0x06:75` | +| 0x002A | `void AudioProcess::I_playAmbientSFXCru(Item *, sndno)` | 74 / 70 / `0x06:74` | `Item::setShape()` | 176 / 140 / `0x06:176` | +| 0x002B | `int16 Item::I_getQLo(Item *)` | 39 / 17 / `0x04:39` | `Item::pop(void)` | 85 / 54 / `0x04:85` | +| 0x002C | `byte Item::I_inFastArea(Item *)` | 19 / 11 / `0x04:19` | `AudioProcess::I_stopSFXCru()` | 10 / 4 / `0x04:10` | +| 0x002D | `void Item::I_setQHi(Item *, uint16 qhi)` | 84 / 40 / `0x06:84` | `Item::isCompletelyOn(uint16)` | 7 / 7 / `0x06:7` | +| 0x002E | `byte Item::I_legalMoveToPoint(Item *, Point *, int16 force)` | 52 / 15 / `0x0C:52` | `Item::popToContainer(uint16)` | 58 / 4 / `0x06:58` | +| 0x002F | `byte CurrentMap::I_canExistAtPoint(int, int, shapeno, Point *)` | 2 / 1 / `0x0A:2` | `Actor::I_getHp()` | 29 / 23 / `0x04:29` | +| 0x0030 | `void Item::I_pop(Item *)` | 27 / 18 / `0x04:27` | `Actor::I_getMana()` | 18 / 6 / `0x04:18` | +| 0x0031 | `void Item::I_andStatus(Item *, uint16 status)` | 14 / 14 / `0x06:14` | `Item::getFamily(void)` | 35 / 13 / `0x04:35` | +| 0x0032 | `void Item::I_receiveHit(Item *, other, dir, damage, damagetype)` | 20 / 16 / `0x0C:20` | `Actor::destroyContents(void)` | 16 / 7 / `0x04:16` | +| 0x0033 | `byte Actor::I_isBusy(Actor *)` | 31 / 25 / `0x04:31` | `AudioProcess::I_setVolumeForItemSFX(uint16,uint16,byte)` | 3 / 3 / `0x08:3` | +| 0x0034 | `int16 Item::I_getDirFromTo16(x1, y1, x2, y2)` | 8 / 6 / `0x08:8` | `Item::getDirToItem(uint16)` | 3 / 3 / `0x06:3` | +| 0x0035 | `byte Actor::I_isKneeling(Actor *)` | 9 / 9 / `0x04:9` | `AudioProcess::I_isSfxPlayingForObject(Item *,uint sfxno)` | 24 / 13 / `0x06:24` | +| 0x0036 | `int16 Actor::I_doAnim(12 bytes)` | 110 / 33 / `0x0C:110` | `Item::I_getRangeIfVisible()` | 10 / 8 / `0x06:10` | +| 0x0037 | `byte MainActor::I_addItemCru(4 bytes)` | 8 / 6 / `0x04:8` | `AudioProcess::I_playSFXCru()` | 31 / 20 / `0x06:31` | +| 0x0038 | `void AudioProcess::I_stopSFXCru(Item *, int16 sndno)` | 57 / 47 / `0x06:57` | `Item::andStatus(void)` | 8 / 8 / `0x06:8` | +| 0x0039 | `byte Actor::I_isDead(Item *)` | 42 / 21 / `0x04:42` | `Kernel::resetRef(uint16,ProcessType)` | 31 / 31 / `0x04:31` | +| 0x003A | `byte AudioProcess::I_isSFXPlayingForObject(Item *, int16 unk)` | 31 / 22 / `0x06:31` | `Item::touch(void)` | 29 / 21 / `0x04:29` | +| 0x003B | `void Item::I_setQLo(Item *, int16 qlo)` | 86 / 59 / `0x06:86` | `Egg::getEggId(void)` | 45 / 31 / `0x04:45` | +| 0x003C | `int16 Item::I_getItemFamily(Item *)` | 24 / 11 / `0x04:24` | `MainActor::I_addItemCru()` | 62 / 25 / `0x04:62` | +| 0x003D | `void Container::I_destroyContents(Item *)` | 15 / 10 / `0x04:15` | `Actor::I_getMap()` | 102 / 42 / `0x04:102` | +| 0x003E | `void Item::I_fallProbably_03E(Item *)` | 22 / 15 / `0x04:22` | `Item::callEvent11(sint16)` | 17 / 16 / `0x06:17` | +| 0x003F | `int16 Egg::I_getEggId(Item *)` | 56 / 32 / `0x04:56` | `CameraProcess::I_somethingAboutCameraUpdate()` | 41 / 39 / `0x00:41` | +| 0x0040 | `void CameraProcess::I_moveTo(x, y, z)` | 42 / 16 / `0x08:42` | `AudioProcess::I_stopSFXCru()` | 61 / 47 / `0x06:61` | +| 0x0041 | `void CameraProcess::I_setCenterOn(objid)` | 7 / 6 / `0x02:7` | `Item::isOn(uint16)` | 1 / 1 / `0x06:1` | +| 0x0042 | `byte Item::I_getRangeIfVisible(Item *, otheritem)` | 4 / 4 / `0x06:4` | `Item::getQHi(void)` | 2 / 2 / `0x04:2` | +| 0x0043 | `void AudioProcess::I_playSFXCru(Item *, soundno)` | 33 / 18 / `0x06:33` | `Item::isOn(uint16)` | 1 / 1 / `0x06:1` | +| 0x0044 | `byte Item::I_IsOn(Item *, uint16 itemno)` | 2 / 1 / `0x06:2` | `Item::getQHi(void)` | 2 / 2 / `0x04:2` | +| 0x0045 | `int16 Item::I_getQHi(Item *)` | 1 / 1 / `0x04:1` | `Item::isOn(uint16)` | 1 / 1 / `0x06:1` | +| 0x0046 | `byte Item::I_IsOn(Item *, uint16 itemno))` | 1 / 1 / `0x06:1` | `Item::getQHi(void)` | 2 / 2 / `0x04:2` | +| 0x0047 | `int16 Item::I_getQHi(Item *)` | 2 / 2 / `0x04:2` | `Item::isOn(uint16)` | 1 / 1 / `0x06:1` | +| 0x0048 | `byte Item::I_IsOn(Item *, uint16 itemno)` | 1 / 1 / `0x06:1` | `Item::getQHi(void)` | 2 / 2 / `0x04:2` | +| 0x0049 | `int16 Item::I_getQHi(Item *)` | 2 / 2 / `0x04:2` | `Item::isOn(uint16)` | 1 / 1 / `0x06:1` | +| 0x004A | `byte Item::I_IsOn(Item *, uint16 itemno)` | 1 / 1 / `0x06:1` | `Item::getQHi(void)` | 2 / 2 / `0x04:2` | +| 0x004B | `int16 Item::I_getQHi(Item *)` | 2 / 2 / `0x04:2` | `Item::isOn(uint16)` | 1 / 1 / `0x06:1` | +| 0x004C | `byte Item::I_IsOn(Item *, uint16 itemno)` | 1 / 1 / `0x06:1` | `Item::getQHi(void)` | 43 / 15 / `0x04:43` | +| 0x004D | `int16 Item::I_getQHi(Item *)` | 2 / 2 / `0x04:2` | `Actor::I_getCurrentActivityNo()` | 14 / 8 / `0x04:14` | +| 0x004E | `byte Item::I_IsOn(Item *, uint16 itemno)` | 1 / 1 / `0x06:1` | `Actor::isDead(void)` | 5 / 3 / `0x04:5` | +| 0x004F | `int16 Item::I_getQHi(Item *)` | 31 / 11 / `0x04:31` | `Actor::I_clrInCombat()` | 2 / 1 / `0x04:2` | +| 0x0050 | `int16 Actor::I_getCurrentActivityNo(Actor *)` | 9 / 4 / `0x04:9` | `Actor::I_setDefaultActivity0()` | 14 / 14 / `0x06:14` | +| 0x0051 | `void Actor::I_clrInCombat(Actor *)` | 2 / 1 / `0x04:2` | `Actor::I_setDefaultActivity1()` | 16 / 16 / `0x06:16` | +| 0x0052 | `void Actor::I_setDefaultActivity0(Actor *, int)` | 8 / 7 / `0x06:8` | `Actor::I_setDefaultActivity2()` | 21 / 19 / `0x06:21` | +| 0x0053 | `void Actor::I_setDefaultActivity1(Actor *, int)` | 10 / 9 / `0x06:10` | `Actor::I_setActivity()` | 1 / 1 / `0x06:1` | +| 0x0054 | `void Actor::I_setDefaultActivity2(Actor *, int)` | 13 / 10 / `0x06:13` | `World::I_setControlledNPCNum()` | 9 / 5 / `0x02:9` | +| 0x0055 | `void Actor::I_setActivity(Actor *, int)` | 1 / 1 / `0x06:1` | `Item::I_receiveHit()` | 41 / 29 / `0x0C:41` | +| 0x0056 | `void World::I_setControlledNPCNum(int itemno)` | 6 / 6 / `0x02:6` | `Game::I_isReleaseBuild()` | 1 / 1 / `0x00:1` | +| 0x0057 | `int16 Item::I_getSurfaceWeight(Item *)` | 17 / 10 / `0x04:17` | `MainActor::I_setMana()` | 13 / 8 / `0x06:13` | +| 0x0058 | `byte Item::I_isCentreOn(Item *, uint16 other)` | 13 / 12 / `0x06:13` | `Item::use(void)` | 7 / 5 / `0x04:7` | +| 0x0059 | `void Item::I_setFrame(Item *, frame)` | 555 / 208 / `0x06:555` | `Item::setUnkEggType(sint16)` | 5 / 1 / `0x06:5` | +| 0x005A | `int16 Actor::I_getLastAnimSet(4 bytes)` | 1 / 1 / `0x04:1` | `MusicProcess::I_playMusic()` | 2 / 2 / `0x02:2` | +| 0x005B | `byte Item::I_legalCreateAtPoint(Item *, int16 shape, int16 frame, Point *)` | 6 / 4 / `0x0C:6` | `Item::getSurfaceWeight(void)` | 25 / 13 / `0x04:25` | +| 0x005C | `void Item::I_getPoint(Item *, Point *)` | 1 / 1 / `0x08:1` | `Item::I_isCentreOn()` | 18 / 14 / `0x06:18` | +| 0x005D | `void StatusGump::I_hideStatusGump(void)` | 11 / 3 / `0x00:11` | `Item::setFrame(uint16)` | 261 / 135 / `0x06:261` | +| 0x005E | `int16 MovieGump::I_playMovieOverlay(uint32, char *, int16 a, int16 b)` | 40 / 6 / `0x0C:40` | `Actor::I_getLastAnimSet()` | 3 / 3 / `0x04:3` | +| 0x005F | `void StatusGump::I_showStatusGump(void)` | 9 / 5 / `0x00:9` | `Ultima8Engine::I_setAvatarInStasis()` | 74 / 40 / `0x02:74` | +| 0x0060 | `void Actor::I_setDead(4 bytes)` | 5 / 1 / `0x04:5` | `Actor::I_isBusy()` | 22 / 19 / `0x04:22` | +| 0x0061 | `void Actor::I_create(8 bytes)` | 12 / 7 / `0x08:12` | `Actor::I_getField0x13Flag2()` | 18 / 17 / `0x04:18` | +| 0x0062 | `void CameraProcess::I_somethingAboutCameraUpdate(void)` | 38 / 25 / `0x00:38` | `Actor::I_doAnim()` | 163 / 44 / `0x0C:163` | +| 0x0063 | `void Actor::I_teleport(12 bytes)` | 12 / 8 / `0x0C:12` | `Item::legalCreateAtPoint(uint16,uint16,WorldPoint&)` | 11 / 9 / `0x0C:11` | +| 0x0064 | `void Item::I_getFootpad(Item *, uint *, uint *, uint *)` | 1 / 1 / `0x10:1` | `Item::getPoint(WorldPoint&)` | 3 / 3 / `0x08:3` | +| 0x0065 | `byte Item::I_isInNPC(Item *)` | 1 / 1 / `0x04:1` | `Item::legalMoveToPoint(WorldPoint&,uint16,uint16)` | 55 / 16 / `0x0C:55` | +| 0x0066 | `int16 Item::I_getQLo(Item *)` | 21 / 12 / `0x04:21` | `Item::fall(void)` | 32 / 23 / `0x04:32` | +| 0x0067 | `int16 Item::I_getNPCNum(Item *)` | 1 / 1 / `0x04:1` | `Item::hurl(sint16,sint16,sint16,sint16)` | 1 / 1 / `0x0C:1` | +| 0x0068 | `void Item::I_setNpcNum(Item *, uint16 npcnum)` | 19 / 14 / `0x06:19` | `Kernel::getNumProcesses(uint16,ProcessType)` | 27 / 26 / `0x04:27` | +| 0x0069 | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Item::getCY(void)` | 1 / 1 / `0x04:1` | +| 0x006A | `void Item::I_move(Item *, int16 x, int16 y, uint16 z)` | 10 / 7 / `0x0A:10` | `U8Engine::I_isCfgAnimationOff()` | 21 / 9 / `0x00:21` | +| 0x006B | `int16 Game::I_isViolenceEnabled(void)` | 13 / 13 / `0x00:13` | `ResetKeyboardState()` | 13 / 13 / `0x00:13` | +| 0x006C | `void Kernel::I_resetRef(int16, int16)` | 21 / 21 / `0x04:21` | `MusicProcess::I_pauseMusic()` | 7 / 6 / `0x00:7` | +| 0x006D | `int16 Item::I_getNPCNum(Item *)` | 2 / 2 / `0x04:2` | `MovieGump::I_playMovieCutsceneRegret()` | 169 / 19 / `0x06:169` | +| 0x006E | `void Item::I_andStatus(Item *, uint16 status)` | 4 / 4 / `0x06:4` | `MusicProcess::I_unpauseMusic()` | 6 / 6 / `0x00:6` | +| 0x006F | `byte Item::I_isCompletelyOn(Item *, uint16 other)` | 6 / 6 / `0x06:6` | `Item::isInNpc(void)` | 2 / 2 / `0x04:2` | +| 0x0070 | `byte Ultima8Engine::I_getCrusaderTeleporting(void)` | 8 / 8 / `0x00:8` | `Ultima8Engine::I_setCruStasis()` | 8 / 8 / `0x00:8` | +| 0x0071 | `void Ultima8Engine::I_setCrusaderTeleporting(void)` | 2 / 2 / `0x00:2` | `Ultima8Engine::I_clrCruStasis()` | 17 / 14 / `0x00:17` | +| 0x0072 | `void Ultima8Engine::I_setCruStasis(void)` | 5 / 5 / `0x00:5` | `PaletteFaderProcess::I_jumpToColor()` | 5 / 5 / `0x06:5` | +| 0x0073 | `void Actor::I_setDead(4 bytes)` | 1 / 1 / `0x04:1` | `PaletteFaderProcess::I_fadeToGamePal()` | 19 / 19 / `0x02:19` | +| 0x0074 | `void Ultima8Engine::I_clrCrusaderTeleporting(void)` | 13 / 9 / `0x00:13` | `Actor::isDead(void)` | 14 / 11 / `0x04:14` | +| 0x0075 | `void Ultima8Engine::I_clrCruStasis(void)` | 5 / 5 / `0x00:5` | `Item::getNpcNum(void)` | 3 / 3 / `0x04:3` | +| 0x0076 | `void AudioProcess::I_stopSFX(Item *)` | 6 / 3 / `0x04:6` | `IntrinsicReturn0` | 3 / 3 / `0x08:3` | +| 0x0077 | `int16 PaletteFaderProcess::I_fadeToBlack(void)` | 9 / 6 / `0x00:9` | `Game::I_isViolenceEnabled()` | 18 / 18 / `0x00:18` | +| 0x0078 | `void MainActor::I_clrKeycards(void)` | 2 / 2 / `0x00:2` | `Item::unequip(sint16)` | 23 / 17 / `0x06:23` | +| 0x0079 | `int16 MainActor::I_teleportToEgg(int, int, int)` | 6 / 5 / `0x06:6` | `Item::andStatus(void)` | 4 / 4 / `0x06:4` | +| 0x007A | `int16 PaletteFaderProcess::I_fadeToGamePal(void)` | 10 / 6 / `0x00:10` | `Item::move(uint16,uint16,uint8)` | 7 / 5 / `0x0A:7` | +| 0x007B | `void Actor::I_clrImmortal(Actor *)` | 3 / 3 / `0x04:3` | `Ultima8Engine::I_getCrusaderTeleporting()` | 13 / 10 / `0x00:13` | +| 0x007C | `int16 Actor::I_getHp(Actor *)` | 11 / 11 / `0x04:11` | `Ultima8Engine::I_setCrusaderTeleporting()` | 12 / 12 / `0x00:12` | +| 0x007D | `void Actor::I_setActivity(Actor *, int)` | 2 / 2 / `0x06:2` | `Ultima8Engine::I_clrCrusaderTeleporting()` | 17 / 16 / `0x00:17` | +| 0x007E | `int16 Item::I_getQuality(Item *)` | 10 / 7 / `0x04:10` | `Actor::I_turnToward()` | 53 / 30 / `0x08:53` | +| 0x007F | `void Item::I_setQuality(Item *, int)` | 1 / 1 / `0x06:1` | `PaletteFaderProcess::I_fadeToBlack()` | 10 / 5 / `0x00:10` | +| 0x0080 | `int16 Item::I_use(Item *)` | 1 / 1 / `0x04:1` | `MainActor::I_clrKeycards()` | 3 / 3 / `0x00:3` | +| 0x0081 | `int16 MainActor::I_getMaxEnergy(Actor *)` | 6 / 1 / `0x04:6` | `MusicProcess::I_stopMusic()` | 9 / 8 / `0x00:9` | +| 0x0082 | `int16 Actor::I_getMana(Actor *)` | 5 / 2 / `0x04:5` | `PaletteFaderProcess::I_jumpToAllBlack()` | 35 / 25 / `0x00:35` | +| 0x0083 | `void Actor::I_setMana(Actor *, int)` | 5 / 3 / `0x06:5` | `I_setUnkFlagA4()` | 21 / 16 / `0x00:21` | +| 0x0084 | `int16 Item::I_getQLo(Item *)` | 16 / 3 / `0x04:16` | `I_clearUnkFlagA4()` | 20 / 15 / `0x00:20` | +| 0x0085 | `void Actor::I_setImmortal(Actor *)` | 6 / 5 / `0x04:6` | `MainActor::I_switchMap(int16)` | 4 / 3 / `0x02:4` | +| 0x0086 | `int16 CameraProcess::I_getCameraX(void)` | 3 / 2 / `0x00:3` | `teleportToEgg(sint16,int,uint8)` | 6 / 5 / `0x06:6` | +| 0x0087 | `int16 CameraProcess::I_getCameraY(void)` | 3 / 2 / `0x00:3` | `PaletteFaderProcess::I_fadeToGamePal()` | 6 / 5 / `0x00:6` | +| 0x0088 | `void Item::I_setMapArray(Item *, uint16 maparray)` | 10 / 10 / `0x06:10` | `Actor::I_clrImmortal()` | 5 / 5 / `0x04:5` | +| 0x0089 | `int16 Item::I_getNpcNum(Item *)` | 8 / 1 / `0x04:8` | `Actor::I_setActivity()` | 3 / 2 / `0x06:3` | +| 0x008A | `void Item::I_shoot(Item *, Point3 *, int speed, int gravity)` | 2 / 2 / `0x0C:2` | `Item::getQuality(void)` | 9 / 6 / `0x04:9` | +| 0x008B | `int16 Item::I_enterFastArea(Item *)` | 9 / 3 / `0x04:9` | `Item::setQuality(sint16)` | 1 / 1 / `0x06:1` | +| 0x008C | `void Item::I_setIsBroken(Item *)` | 3 / 2 / `0x04:3` | `MainActor::I_getMaxEnergy()` | 7 / 2 / `0x04:7` | +| 0x008D | `int16 Item::I_hurl(Item *,8 bytes)` | 1 / 1 / `0x0C:1` | `CameraProcess::I_moveTo(x,y,z)` | 29 / 15 / `0x08:29` | +| 0x008E | `int16 Item::I_getNPCNum(Item *)` | 1 / 1 / `0x04:1` | `Actor::I_setImmortal()` | 6 / 6 / `0x04:6` | +| 0x008F | `void PaletteFaderProcess::I_jumpToAllBlack(void)` | 26 / 14 / `0x00:26` | `Camera::getX(void)` | 4 / 4 / `0x00:4` | +| 0x0090 | `void MusicProcess::I_stopMusic(void)` | 4 / 4 / `0x00:4` | `Camera::getY(void)` | 1 / 1 / `0x00:1` | +| 0x0091 | `void I_setSomeMovieGlobal(void)` | 12 / 8 / `0x00:12` | `Item::setMapNum(sint16)` | 20 / 20 / `0x06:20` | +| 0x0092 | `void I_playMovieCutsceneFullscreen(char *)` | 1 / 1 / `0x0C:1` | `Item::getNpcNum(void)` | 7 / 1 / `0x04:7` | +| 0x0093 | `void I_clearSomeMovieGlobal(void)` | 11 / 7 / `0x00:11` | `Item::shoot(WorldPoint&,sint16,sint16)` | 2 / 2 / `0x0C:2` | +| 0x0094 | `void Game::I_playCredits(void)` | 3 / 3 / `0x00:3` | `CameraProcess::I_setCenterOn()` | 2 / 1 / `0x02:2` | +| 0x0095 | `byte Kernel::I_getCurrentKeyDown(void)` | 5 / 3 / `0x00:5` | `Item::enterFastArea(void)` | 8 / 2 / `0x04:8` | +| 0x0096 | `int16 MainActor::I_teleportToEgg(int, int)` | 2 / 2 / `0x04:2` | `Item::setBroken()` | 5 / 4 / `0x04:5` | +| 0x0097 | `void PaletteFaderProcess:I_jumpToGreyScale(void)` | 8 / 6 / `0x00:8` | `Item::hurl(sint16,sint16,sint16,sint16)` | 1 / 1 / `0x0C:1` | +| 0x0098 | `void I_resetVargasShieldTo500(void)` | 1 / 1 / `0x00:1` | `Item::getNpcNum(void)` | 5 / 1 / `0x04:5` | +| 0x0099 | `void Item::I_andStatus(Item *, uint16 status)` | 5 / 5 / `0x06:5` | `Ultima8Engine::I_moveKeyDownRecently()` | 3 / 3 / `0x00:3` | +| 0x009A | `void PaletteFaderProcess::I_jumpToNormalPalette(void)` | 12 / 7 / `0x00:12` | `teleportToEgg(sint16,uint8)` | 3 / 2 / `0x04:3` | +| 0x009B | `int16 PaletteFaderProcess::I_fadeToGamePal(nsteps)` | 4 / 4 / `0x02:4` | `Actor::I_createActor()` | 9 / 9 / `0x08:9` | +| 0x009C | `int16 PaletteFaderProcess::I_fadeToGamePalWithParam(nsteps, unk)` | 1 / 1 / `0x04:1` | `Actor::I_clrInCombat()` | 2 / 1 / `0x04:2` | +| 0x009D | `int16 PaletteFaderProcess::I_fadeToBlack(nsteps)` | 1 / 1 / `0x02:1` | `PaletteFaderProcess::I_jumpToGreyScale()` | 5 / 5 / `0x00:5` | +| 0x009E | `int16 PaletteFaderProcess::I_fadeToBlackWithParam(nsteps, unk)` | 1 / 1 / `0x04:1` | `PaletteFaderProcess::I_jumpToNormalPalette()` | 5 / 4 / `0x00:5` | +| 0x009F | `int16 PaletteFaderProcess::I_fadeToColor(r, g, b, nsteps, unk)` | 2 / 2 / `0x0A:2` | `CruStatusGump::I_showStatusGump()` | 8 / 8 / `0x00:8` | +| 0x00A0 | `void Actor::I_setDead(Actor *)` | 1 / 1 / `0x04:1` | `Item::andStatus(void)` | 9 / 9 / `0x06:9` | +| 0x00A1 | `int16 Item::I_getQLo(Item *)` | 10 / 5 / `0x04:10` | `Item::getUnkEggType(void)` | 8 / 2 / `0x04:8` | +| 0x00A2 | `int16 Item::I_getUnkEggType(Item *)` | 8 / 2 / `0x04:8` | `Egg::setEggXRange(uint16)` | 8 / 2 / `0x06:8` | +| 0x00A3 | `void Egg::I_setEggXRange(Egg *, int)` | 8 / 2 / `0x06:8` | `Item::setFrame(uint16)` | 462 / 206 / `0x06:462` | +| 0x00A4 | `byte Item::I_overlaps(Item *, uint16 unk)` | 14 / 13 / `0x06:14` | `Item::overlaps(uint16)` | 17 / 16 / `0x06:17` | +| 0x00A5 | `byte Item::I_isOn(Item *, itemno)` | 3 / 3 / `0x06:3` | `Item::isOn(uint16)` | 3 / 3 / `0x06:3` | +| 0x00A6 | `int16 I_getAnimationsEnabled(void)` | 16 / 7 / `0x00:16` | `Item::getQHi(void)` | 4 / 4 / `0x04:4` | +| 0x00A7 | `int16 Egg::I_getEggXRange(Egg *)` | 1 / 1 / `0x04:1` | `Actor::I_getLastAnimSet()` | 1 / 1 / `0x04:1` | +| 0x00A8 | `void Actor::I_setDead(Actor *)` | 2 / 2 / `0x04:2` | `Item::getCY(void)` | 4 / 2 / `0x04:4` | +| 0x00A9 | `void I_playMovieCutsceneFullscreen(char *)` | 17 / 6 / `0x0C:17` | `CurrentMap::I_canExistAt()` | 23 / 6 / `0x08:23` | +| 0x00AA | `void AudioProcess::I_playSFX(2 bytes)` | 7 / 4 / `0x02:7` | `Item::isOn(uint16)` | 1 / 1 / `0x06:1` | +| 0x00AB | `byte Actor::I_isFalling(Actor *)` | 2 / 2 / `0x04:2` | `Actor::isDead(void)` | 3 / 1 / `0x04:3` | +| 0x00AC | `int16 Item::I_getFamilyOfType(Item *)` | 1 / 1 / `0x02:1` | `Item::hurl(sint16,sint16,sint16,sint16)` | 1 / 1 / `0x0C:1` | +| 0x00AD | `int16 Item::I_getNPCNum(Item *)` | 2 / 2 / `0x04:2` | `Item::I_inFastArea()` | 16 / 8 / `0x04:16` | +| 0x00AE | `int16 Item::I_getQLo(Item *)` | 40 / 21 / `0x04:40` | `Item::getQHi(void)` | 10 / 6 / `0x04:10` | +| 0x00AF | `int16 Item::I_getQHi(Item *)` | 4 / 4 / `0x04:4` | `Item::andStatus(void)` | 1 / 1 / `0x06:1` | +| 0x00B0 | `int16 Item::I_unequip(6 bytes)` | 11 / 11 / `0x06:11` | `Item::hurl(sint16,sint16,sint16,sint16)` | 1 / 1 / `0x0C:1` | +| 0x00B1 | `int16 Item::I_spawnUsecodeEvent0x13(Item *, 2 bytes)` | 13 / 7 / `0x06:13` | `Item::andStatus(void)` | 1 / 1 / `0x06:1` | +| 0x00B2 | `void Item::I_andStatus(Item *, uint16 status)` | 5 / 5 / `0x06:5` | `Item::hurl(sint16,sint16,sint16,sint16)` | 1 / 1 / `0x0C:1` | +| 0x00B3 | `int32 I_getCurrentTimerTick(void)` | 3 / 1 / `0x00:3` | `Item::andStatus(void)` | 9 / 6 / `0x06:9` | +| 0x00B4 | `void Ultima8Engine::I_setAlertActive(void)` | 1 / 1 / `0x00:1` | `Item::getDirToCoords(uint16,uint16)` | 1 / 1 / `0x08:1` | +| 0x00B5 | `int16 Item::I_equip(6 bytes)` | 18 / 12 / `0x06:18` | `MainActor::I_removeItem(uint16)` | 4 / 4 / `0x02:4` | +| 0x00B6 | `void Ultima8Engine::I_clrAlertActive(void)` | 7 / 2 / `0x00:7` | `I_updateInventoryUI()` | 9 / 8 / `0x00:9` | +| 0x00B7 | `int16 Ultima8Engine::I_getAvatarInStasis(void)` | 1 / 1 / `0x00:1` | `Item::getNpcNum(void)` | 2 / 2 / `0x04:2` | +| 0x00B8 | `byte MainActor::I_addItemCru(4 bytes)` | 25 / 13 / `0x04:25` | `Item::getCY(void)` | 8 / 1 / `0x04:8` | +| 0x00B9 | `int16 Actor::I_getLastAnimSet(4 bytes)` | 5 / 2 / `0x04:5` | `Item::isOn(uint16)` | 2 / 2 / `0x06:2` | +| 0x00BA | `void Item::I_setQuality(Item *, int)` | 4 / 3 / `0x06:4` | `Item::getFootpad(sint16&,sint16&,sint16&)` | 2 / 2 / `0x10:2` | +| 0x00BB | `byte CurrentMap::I_canExistAt(int shapeno, word x, word y, byte z)` | 17 / 5 / `0x08:17` | `Actor::isDead(void)` | 23 / 16 / `0x04:23` | +| 0x00BC | `byte Item::I_isOn(Item *, itemno)` | 1 / 1 / `0x06:1` | `Actor::I_createActorCru()` | 2 / 1 / `0x06:2` | +| 0x00BD | `int16 Item::I_hurl(Item *,8 bytes)` | 1 / 1 / `0x0C:1` | `Actor::I_setActivity()` | 48 / 17 / `0x06:48` | +| 0x00BE | `int16 Item::I_getQHi(Item *)` | 14 / 10 / `0x04:14` | `KeypadGump::I_showKeypad()` | 3 / 2 / `0x02:3` | +| 0x00BF | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Item::andStatus(void)` | 4 / 3 / `0x06:4` | +| 0x00C0 | `int16 Item::I_hurl(Item *,8 bytes)` | 1 / 1 / `0x0C:1` | `ComputerGump::I_readComputer()` | 25 / 3 / `0x04:25` | +| 0x00C1 | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `UCMachine::I_numToStr()` | 1 / 1 / `0x02:1` | +| 0x00C2 | `int16 Item::I_hurl(Item *,8 bytes)` | 1 / 1 / `0x0C:1` | `IntrinsicReturn0` | 1 / 1 / `0x08:1` | +| 0x00C3 | `void Item::I_andStatus(Item *, uint16 status)` | 11 / 7 / `0x06:11` | `Actor::I_getDir()` | 56 / 15 / `0x04:56` | +| 0x00C4 | `int16 KeypadGump::I_showKeypad(int targetCode)` | 2 / 2 / `0x02:2` | `Item::getQHi(void)` | 12 / 12 / `0x04:12` | +| 0x00C5 | `byte Item::I_isOn(Item *, itemno)` | 1 / 1 / `0x06:1` | `Item::setQuality(sint16)` | 4 / 3 / `0x06:4` | +| 0x00C6 | `void SpriteProcess::I_createSprite(word, word, word, word, uword, uword, ubyte)` | 22 / 8 / `0x0E:22` | `Item::hurl(sint16,sint16,sint16,sint16)` | 4 / 3 / `0x0C:4` | +| 0x00C7 | `byte Item::I_getDirFromItem(Item *, itemno)` | 1 / 1 / `0x06:1` | `Actor::I_addHp()` | 1 / 1 / `0x06:1` | +| 0x00C8 | `int16 Item::I_hurl(Item *,8 bytes)` | 6 / 4 / `0x0C:6` | `CruHealerProcess::I_create()` | 1 / 1 / `0x00:1` | +| 0x00C9 | `int16 Item::I_getQHi(Item *)` | 9 / 7 / `0x04:9` | `Item::callEvent0A(sint16)` | 18 / 12 / `0x06:18` | +| 0x00CA | `byte Actor::I_addHp(Actor *, int)` | 1 / 1 / `0x06:1` | `Item::setBroken()` | 7 / 5 / `0x04:7` | +| 0x00CB | `void MainActor::I_switchMap(int16 mapnum)` | 3 / 2 / `0x02:3` | `Item::isOn(uint16)` | 2 / 2 / `0x06:2` | +| 0x00CC | `byte Actor::I_getInCombat(Actor *)` | 8 / 3 / `0x04:8` | `Actor::I_teleport()` | 3 / 3 / `0x0C:3` | +| 0x00CD | `void Actor::I_setActivity(Actor *, int)` | 2 / 2 / `0x06:2` | `Item::I_getDirFromTo16()` | 4 / 3 / `0x08:4` | +| 0x00CE | `int16 Game::I_isReleaseBuild(void)` | 3 / 3 / `0x00:3` | `Item::getQHi(void)` | 12 / 10 / `0x04:12` | +| 0x00CF | `void Item::I_setQAndCombine(Item *, int16 q)` | 2 / 1 / `0x06:2` | `Item::isOn(uint16)` | 1 / 1 / `0x06:1` | +| 0x00D0 | `int16 Item::I_use(Item *)` | 1 / 1 / `0x04:1` | `Actor::I_isInCombat()` | 4 / 2 / `0x04:4` | +| 0x00D1 | `void AudioProcess:I_stopAllSFX(void)` | 1 / 1 / `0x00:1` | `Actor::I_getNPCDataField0x4()` | 16 / 5 / `0x04:16` | +| 0x00D2 | `void I_playMovieCutscene(int *item,char *flicname,word sizex,word sizey)` | 1 / 1 / `0x0E:1` | `Actor::I_setCombatTactic()` | 3 / 1 / `0x06:3` | +| 0x00D3 | `void I_clearKeyboardState(void)` | 4 / 4 / `0x00:4` | `Actor::I_setDead())` | 1 / 1 / `0x04:1` | +| 0x00D4 | `void I_playSFX(2 bytes)` | 1 / 1 / `0x02:1` | `CameraProcess::I_getCameraY()` | 1 / 1 / `0x00:1` | +| 0x00D5 | `int16 Item::I_use(Item *)` | 2 / 1 / `0x04:2` | `Actor::I_getEquip()` | 3 / 1 / `0x06:3` | +| 0x00D6 | `byte CameraProcess::I_getCameraZ(void)` | 2 / 1 / `0x00:2` | `Actor::I_setEquip()` | 2 / 1 / `0x08:2` | +| 0x00D7 | `int16 Actor::I_getLastAnimSet(4 bytes)` | 1 / 1 / `0x04:1` | `Actor::I_getDefaultActivity0()` | 1 / 1 / `0x04:1` | +| 0x00D8 | `void Actor::I_setDead(4 bytes)` | 1 / 1 / `0x04:1` | `Actor::I_getDefaultActivity1()` | 1 / 1 / `0x04:1` | +| 0x00D9 | `int16 Item::I_getQLo(Item *)` | 26 / 12 / `0x04:26` | `Actor::I_getDefaultActivity2()` | 1 / 1 / `0x04:1` | +| 0x00DA | `void PaletteFaderProcess::I_setPalToAllGrey(void)` | 3 / 2 / `0x00:3` | `Actor::I_getLastAnimSet()` | 12 / 4 / `0x04:12` | +| 0x00DB | `void Actor::I_setActivity(Actor *, int)` | 13 / 5 / `0x06:13` | `Actor::I_isFalling()` | 2 / 2 / `0x04:2` | +| 0x00DC | `byte Item::I_isOn(Item *, itemno)` | 1 / 1 / `0x06:1` | `Item::getQLo(void)` | 5 / 4 / `0x04:5` | +| 0x00DD | `int16 Actor::I_getLastActivityNo(Actor *)` | 16 / 5 / `0x04:16` | `Item::getQHi(void)` | 33 / 23 / `0x04:33` | +| 0x00DE | `void Actor::I_setCombatTactic(Actor *, int)` | 3 / 1 / `0x06:3` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x00DF | `int16 Actor::I_getEquip(6 bytes)` | 3 / 1 / `0x06:3` | `Item::I_setField0x81()` | 4 / 4 / `0x06:4` | +| 0x00E0 | `void Actor::I_setEquip(8 bytes)` | 2 / 1 / `0x08:2` | `Item::hurl(sint16,sint16,sint16,sint16)` | 10 / 4 / `0x0C:10` | +| 0x00E1 | `int16 Actor::I_getDefaultActivity0(Actor *)` | 1 / 1 / `0x04:1` | `Actor::I_setDead()` | 3 / 1 / `0x04:3` | +| 0x00E2 | `int16 Actor::I_getDefaultActivity1(Actor *)` | 1 / 1 / `0x04:1` | `Item::getQLo(void)` | 15 / 13 / `0x04:15` | +| 0x00E3 | `int16 Actor::I_getDefaultActivity2(Actor *)` | 1 / 1 / `0x04:1` | `Item::getCY(void)` | 10 / 10 / `0x04:10` | +| 0x00E4 | `int16 Actor::I_getLastAnimSet(4 bytes)` | 1 / 1 / `0x04:1` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x00E5 | `void Actor::I_setTarget(Actor *, uint16 target)` | 2 / 1 / `0x06:2` | `Item::hurl(sint16,sint16,sint16,sint16)` | 2 / 1 / `0x0C:2` | +| 0x00E6 | `void Actor::I_SetNPCDataField0x63_0E6(Actor *, int)` | 4 / 4 / `0x06:4` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x00E7 | `void Actor::I_setDead(4 bytes)` | 2 / 1 / `0x04:2` | `Item::hurl(sint16,sint16,sint16,sint16)` | 2 / 1 / `0x0C:2` | +| 0x00E8 | `int16 Item::I_cast(6 bytes)` | 2 / 2 / `0x06:2` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x00E9 | `void Item::I_andStatus(Item *, uint16 status)` | 11 / 11 / `0x06:11` | `Item::hurl(sint16,sint16,sint16,sint16)` | 2 / 1 / `0x0C:2` | +| 0x00EA | `int16 Item::I_getQLo(Item *)` | 145 / 51 / `0x04:145` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x00EB | `int16 I_GetQOfAvatarInventoryItem0x4ed_0EB(void)` | 2 / 2 / `0x00:2` | `Item::hurl(sint16,sint16,sint16,sint16)` | 2 / 1 / `0x0C:2` | +| 0x00EC | `void Item::I_popToEnd(Item*, int)` | 1 / 1 / `0x06:1` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x00ED | `void Item::I_popToContainer(Item*, int)` | 40 / 5 / `0x06:40` | `Item::hurl(sint16,sint16,sint16,sint16)` | 2 / 1 / `0x0C:2` | +| 0x00EE | `void BatteryChargerProcess::I_create(void)` | 2 / 2 / `0x00:2` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x00EF | `int16 Kernel::I_getNumProcesses(int, int)` | 4 / 4 / `0x04:4` | `Item::hurl(sint16,sint16,sint16,sint16)` | 2 / 1 / `0x0C:2` | +| 0x00F0 | `int16 Item::I_getQHi(Item *)` | 8 / 8 / `0x04:8` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x00F1 | `byte Item::I_isOn(Item *, itemno)` | 1 / 1 / `0x06:1` | `Item::hurl(sint16,sint16,sint16,sint16)` | 2 / 1 / `0x0C:2` | +| 0x00F2 | `void Actor::I_setActivity(Actor *, int)` | 41 / 6 / `0x06:41` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x00F3 | `int16 Item::I_getQHi(Item *)` | 7 / 5 / `0x04:7` | `Item::hurl(sint16,sint16,sint16,sint16)` | 2 / 1 / `0x0C:2` | +| 0x00F4 | `int16 Item::I_getQ(Item *)` | 7 / 7 / `0x04:7` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x00F5 | `void Item::I_setQ(Item *, uint16 q)` | 8 / 8 / `0x06:8` | `Item::hurl(sint16,sint16,sint16,sint16)` | 2 / 1 / `0x0C:2` | +| 0x00F6 | `void CruHealer::I_create_0F6(void)` | 1 / 1 / `0x00:1` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x00F7 | `int16 Item::I_hurl(Item *,8 bytes)` | 1 / 1 / `0x0C:1` | `Item::andStatus(void)` | 8 / 8 / `0x06:8` | +| 0x00F8 | `int16 Item::I_getNPCNum(Item *)` | 3 / 3 / `0x04:3` | `Actor::I_setDead()` | 1 / 1 / `0x04:1` | +| 0x00F9 | `int16 Item::I_hurl(Item *,8 bytes)` | 2 / 1 / `0x0C:2` | `Item::getQLo(void)` | 1 / 1 / `0x04:1` | +| 0x00FA | `byte Item::I_isOn(Item *, itemno)` | 1 / 1 / `0x06:1` | `Actor::I_setDead()` | 1 / 1 / `0x04:1` | +| 0x00FB | `int16 Item::I_getQHi(Item *)` | 17 / 12 / `0x04:17` | `Dtable::I_getMaxHPForNPC()` | 1 / 1 / `0x04:1` | +| 0x00FC | `void Item::I_andStatus(Item *, uint16 status)` | 3 / 3 / `0x06:3` | `Actor::I_setHP()` | 1 / 1 / `0x06:1` | +| 0x00FD | `byte MainActor::I_hasKeycard(int)` | 1 / 1 / `0x02:1` | `Item::getQLo(void)` | 36 / 19 / `0x04:36` | +| 0x00FE | `void ComputerGump::I_readComputer(char *)` | 2 / 2 / `0x04:2` | `BatteryChargerProcess::I_create()` | 1 / 1 / `0x00:1` | +| 0x00FF | `int16 UCMachine::I_numToStr(int16 num)` | 12 / 1 / `0x02:12` | `Item::hurl(sint16,sint16,sint16,sint16)` | 1 / 1 / `0x0C:1` | +| 0x0100 | `int16 Item::I_getNPCNum(Item *)` | 1 / 1 / `0x04:1` | `Item::andStatus(void)` | 5 / 5 / `0x06:5` | +| 0x0101 | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Item::isOn(uint16)` | 1 / 1 / `0x06:1` | +| 0x0102 | `int16 Item::I_getNPCNum(Item *)` | 4 / 3 / `0x04:4` | `Actor::isDead(void)` | 2 / 2 / `0x04:2` | +| 0x0103 | `byte Item::I_isCrusTypeNPC(uint16 shapenum)` | 11 / 3 / `0x02:11` | `Actor::I_setActivity()` | 1 / 1 / `0x06:1` | +| 0x0104 | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Item::getQHi(void)` | 9 / 8 / `0x04:9` | +| 0x0105 | `int16 Item::I_getNPCNum(Item *)` | 1 / 1 / `0x04:1` | `Actor::I_getLastAnimSet()` | 1 / 1 / `0x04:1` | +| 0x0106 | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Actor::I_setDead()` | 1 / 1 / `0x04:1` | +| 0x0107 | `int16 Item::I_getNPCNum(Item *)` | 2 / 2 / `0x04:2` | `Item::getQLo(void)` | 113 / 35 / `0x04:113` | +| 0x0108 | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Item::isOn(uint16)` | 1 / 1 / `0x06:1` | +| 0x0109 | `int16 Item::I_getNPCNum(Item *)` | 2 / 2 / `0x04:2` | `Item::getQHi(void)` | 2 / 2 / `0x04:2` | +| 0x010A | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Item::isOn(uint16)` | 1 / 1 / `0x06:1` | +| 0x010B | `int16 Item::I_getNPCNum(Item *)` | 2 / 2 / `0x04:2` | `Item::getQHi(void)` | 6 / 5 / `0x04:6` | +| 0x010C | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Item::hurl(sint16,sint16,sint16,sint16)` | 1 / 1 / `0x0C:1` | +| 0x010D | `int16 Item::I_getNPCNum(Item *)` | 2 / 2 / `0x04:2` | `Item::getNpcNum(void)` | 3 / 3 / `0x04:3` | +| 0x010E | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Item::getCY(void)` | 1 / 1 / `0x04:1` | +| 0x010F | `int16 Item::I_getNPCNum(Item *)` | 2 / 2 / `0x04:2` | `Item::hurl(sint16,sint16,sint16,sint16)` | 2 / 1 / `0x0C:2` | +| 0x0110 | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Item::isOn(uint16)` | 1 / 1 / `0x06:1` | +| 0x0111 | `int16 Item::I_getNPCNum(Item *)` | 2 / 2 / `0x04:2` | `MainActor::I_hasKeycard()` | 1 / 1 / `0x02:1` | +| 0x0112 | `byte Actor::I_getDir(Actor *)` | 3 / 3 / `0x04:3` | `IntrinsicReturn0` | 1 / 1 / `0x08:1` | +| 0x0113 | `int16 UCMachine::I_numToStr(int16 num)` | 9 / 1 / `0x02:9` | `Actor::isDead(void)` | 9 / 5 / `0x04:9` | +| 0x0114 | `void Item::I_andStatus(Item *, uint16 status)` | 2 / 2 / `0x06:2` | `Actor::I_clrImmortal()` | 4 / 4 / `0x04:4` | +| 0x0115 | `int16 Item::I_getNPCNum(Item *)` | 3 / 2 / `0x04:3` | `UCMachine::I_numToStr()` | 13 / 1 / `0x02:13` | +| 0x0116 | `byte Item::I_fireDistance(14 bytes)` | 2 / 1 / `0x0E:2` | `Item::getQHi(void)` | 41 / 27 / `0x04:41` | +| 0x0117 | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Actor::I_setActivity()` | 46 / 8 / `0x06:46` | +| 0x0118 | `int16 Item::I_hurl(Item *,8 bytes)` | 8 / 1 / `0x0C:8` | `Item::andStatus(void)` | 2 / 2 / `0x06:2` | +| 0x0119 | `void Item::I_setIsBroken(Item *)` | 1 / 1 / `0x04:1` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x011A | `void Item::I_andStatus(Item *, uint16 status)` | 1 / 1 / `0x06:1` | `Item::andStatus(void)` | 1 / 1 / `0x06:1` | +| 0x011B | `byte Item::I_getTypeFlag(Item *, uint16 shift)` | 1 / 1 / `0x06:1` | `Item::getNpcNum(void)` | 4 / 3 / `0x04:4` | +| 0x011C | `int16 Item::I_getNPCNum(Item *)` | 1 / 1 / `0x04:1` | `Item::I_isCrusTypeNPC()` | 11 / 3 / `0x02:11` | +| 0x011D | `int16 Item::I_hurl(Item *,8 bytes)` | 1 / 1 / `0x0C:1` | `Item::andStatus(void)` | 1 / 1 / `0x06:1` | +| 0x011E | `int16 Item::I_getCY(Item *)` | 1 / 1 / `0x04:1` | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x011F | `byte Item::I_getCZ(Item *)` | 2 / 2 / `0x04:2` | `Item::AvatarStoleSomehting(uint16)` | 13 / 7 / `0x06:13` | +| 0x0120 | `int16 Item::I_getCX(Item *)` | 9 / 2 / `0x04:9` | `Item::andStatus(void)` | 1 / 1 / `0x06:1` | +| 0x0121 | `byte Actor::I_getDir(4 bytes)` | 2 / 2 / `0x04:2` | `Item::getNpcNum(void)` | 2 / 2 / `0x04:2` | +| 0x0122 | `byte Actor::I_isDead(Item *)` | 2 / 1 / `0x04:2` | `Item::getQ(void)` | 6 / 6 / `0x04:6` | +| 0x0123 | `int16 Item::I_getNPCNum(Item *)` | 1 / 1 / `0x04:1` | `Item::setQ(uint)` | 6 / 6 / `0x06:6` | +| 0x0124 | `int16 Actor::I_getLastAnimSet(4 bytes)` | 8 / 1 / `0x04:8` | `Item::andStatus(void)` | 1 / 1 / `0x06:1` | +| 0x0125 | `void Item::I_setQuality(Item *, int)` | 4 / 1 / `0x06:4` | `Item::getNpcNum(void)` | 2 / 2 / `0x04:2` | +| 0x0126 | `int16 UCMachine::I_numToStr(int16 num)` | 32 / 2 / `0x02:32` | `Item::andStatus(void)` | 1 / 1 / `0x06:1` | +| 0x0127 | `byte Item::I_getDirToCoords(Item *, uin16 x, uint16 y)` | 1 / 1 / `0x08:1` | `Item::getNpcNum(void)` | 2 / 2 / `0x04:2` | +| 0x0128 | `void Item::I_andStatus(Item *, uint16 status)` | 2 / 2 / `0x06:2` | `Item::andStatus(void)` | 1 / 1 / `0x06:1` | +| 0x0129 | `int16 Item::I_getNPCNum(Item *)` | 2 / 2 / `0x04:2` | `Item::getNpcNum(void)` | 2 / 2 / `0x04:2` | +| 0x012A | `void Item::I_setIsBroken(Item *)` | 1 / 1 / `0x04:1` | `Item::andStatus(void)` | 1 / 1 / `0x06:1` | +| 0x012B | `int16 IItem::I_getCY(Item *)` | 8 / 1 / `0x04:8` | `Item::getNpcNum(void)` | 2 / 2 / `0x04:2` | +| 0x012C | `byte Item::I_isOn(Item *, itemno)` | 1 / 1 / `0x06:1` | `Item::andStatus(void)` | 1 / 1 / `0x06:1` | +| 0x012D | `void Item::I_getFootpadData(Item *, uint *, uint *, uint *)` | 2 / 2 / `0x10:2` | `Item::getNpcNum(void)` | 2 / 2 / `0x04:2` | +| 0x012E | `byte Actor::I_isDead(Item *)` | 2 / 2 / `0x04:2` | `Actor::I_getDir()` | 3 / 3 / `0x04:3` | +| 0x012F | `int16 Actor::I_createActorCru(Item *, uint16 other_itemno)` | 2 / 1 / `0x06:2` | `Item::andStatus(void)` | 2 / 2 / `0x06:2` | +| 0x0130 | `void Actor::I_clrImmortal(Actor *)` | 2 / 2 / `0x04:2` | `Item::getNpcNum(void)` | 2 / 1 / `0x04:2` | +| 0x0131 | `void Actor::I_setActivity(Actor *, int)` | 3 / 2 / `0x06:3` | `Intrinsic0131()` | 2 / 1 / `0x0E:2` | +| 0x0132 | `void Item::I_andStatus(Item *, int16 status)` | 2 / 2 / `0x06:2` | `Item::andStatus(void)` | 1 / 1 / `0x06:1` | +| 0x0133 | `int16 Item::I_getQHi(Item *)` | 5 / 1 / `0x04:5` | `Item::hurl(sint16,sint16,sint16,sint16)` | 8 / 1 / `0x0C:8` | +| 0x0134 | `void WeaselGump::I_showGump(uint16 param)` | 2 / 1 / `0x02:2` | `Item::andStatus(void)` | 2 / 2 / `0x06:2` | +| 0x0135 | `void Actor::I_setDead(Actor *)` | 3 / 3 / `0x04:3` | `Camera::getY(void)` | 2 / 2 / `0x00:2` | +| 0x0136 | `void UNUSEDInt136()` | not scanned | `Camera::getZ(void)` | 2 / 2 / `0x00:2` | +| 0x0137 | not in converter table | not scanned | `CruStatusGump::I_hideStatusGump()` | 5 / 5 / `0x00:5` | +| 0x0138 | not in converter table | not scanned | `Actor::I_clrInCombat()` | 2 / 1 / `0x04:2` | +| 0x0139 | not in converter table | not scanned | `Item::getTypeFlagCrusader(sint16)` | 1 / 1 / `0x06:1` | +| 0x013A | not in converter table | not scanned | `Item::getNpcNum(void)` | 1 / 1 / `0x04:1` | +| 0x013B | not in converter table | not scanned | `Item::hurl(sint16,sint16,sint16,sint16)` | 1 / 1 / `0x0C:1` | +| 0x013C | not in converter table | not scanned | `Item::getCY(void)` | 1 / 1 / `0x04:1` | +| 0x013D | not in converter table | not scanned | `Item::getCZ(void)` | 2 / 2 / `0x04:2` | +| 0x013E | not in converter table | not scanned | `Item::setFrame(uint16)` | 41 / 11 / `0x06:41` | +| 0x013F | not in converter table | not scanned | `AudioProcess::I_playAmbientSFX()` | 11 / 8 / `0x02:11` | +| 0x0140 | not in converter table | not scanned | `AudioProcess::I_isSFXPlaying()` | 2 / 2 / `0x02:2` | +| 0x0141 | not in converter table | not scanned | `World::I_clrAlertActiveRegret()` | 2 / 2 / `0x00:2` | +| 0x0142 | not in converter table | not scanned | `PaletteFaderProcess::I_fadeToGivenColor()` | 2 / 2 / `0x0A:2` | +| 0x0143 | not in converter table | not scanned | `Actor::isDead(void)` | 8 / 8 / `0x04:8` | +| 0x0144 | not in converter table | not scanned | `Actor::I_setDead()` | 3 / 3 / `0x04:3` | +| 0x0145 | not in converter table | not scanned | `Game::I_playCredits()` | 6 / 6 / `0x00:6` | +| 0x0146 | not in converter table | not scanned | `PaletteFaderProcess::I_jumpToAllGrey()` | 2 / 2 / `0x00:2` | +| 0x0147 | not in converter table | not scanned | `Item::I_getFamilyOfType()` | 1 / 1 / `0x02:1` | +| 0x0148 | not in converter table | not scanned | `Item::getNpcNum(void)` | 2 / 2 / `0x04:2` | +| 0x0149 | not in converter table | not scanned | `Item::getQLo(void)` | 33 / 13 / `0x04:33` | +| 0x014A | not in converter table | not scanned | `Item::andStatus(void)` | 2 / 2 / `0x06:2` | +| 0x014B | not in converter table | not scanned | `Ultima8Engine::getCurrentTimerTick()` | 3 / 1 / `0x00:3` | +| 0x014C | not in converter table | not scanned | `World::I_setAlertActiveRegret()` | 1 / 1 / `0x00:1` | +| 0x014D | not in converter table | not scanned | `Ultima8Engine::I_getAvatarInStasis()` | 1 / 1 / `0x00:1` | +| 0x014E | not in converter table | not scanned | `MainActor::I_addItemCru()` | 1 / 1 / `0x04:1` | +| 0x014F | not in converter table | not scanned | `Egg::getEggXRange(void)` | 1 / 1 / `0x04:1` | +| 0x0150 | not in converter table | not scanned | `Actor::I_clrInCombat()` | 2 / 1 / `0x04:2` | +| 0x0151 | not in converter table | not scanned | `PaletteFaderProcess::I_jumpToColor()` | 2 / 2 / `0x06:2` | +| 0x0152 | not in converter table | not scanned | `Item::setFrame(uint16)` | 9 / 8 / `0x06:9` | +| 0x0153 | not in converter table | not scanned | `UCMachine::I_numToStr()` | 9 / 1 / `0x02:9` | +| 0x0154 | not in converter table | not scanned | `Actor::I_getDir()` | 3 / 2 / `0x04:3` | +| 0x0155 | not in converter table | not scanned | `UCMachine::I_numToStr()` | 9 / 1 / `0x02:9` | +| 0x0156 | not in converter table | not scanned | `Item::isOn(uint16)` | 2 / 1 / `0x06:2` | +| 0x0157 | not in converter table | not scanned | `Actor::I_getDir()` | 6 / 2 / `0x04:6` | +| 0x0158 | not in converter table | not scanned | `Actor::I_setDead()` | 1 / 1 / `0x04:1` | +| 0x0159 | not in converter table | not scanned | `Item::getQHi(void)` | 2 / 2 / `0x04:2` | +| 0x015A | not in converter table | not scanned | `Item::getQLo(void)` | 1 / 1 / `0x04:1` | +| 0x015B | not in converter table | not scanned | `UCMachine::I_numToStr()` | 12 / 1 / `0x02:12` | +| 0x015C | not in converter table | not scanned | `Actor::I_getDir()` | 3 / 1 / `0x04:3` | +| 0x015D | not in converter table | not scanned | `Intrinsic015D()` | not scanned | + +## Evidence and limits + +- The bytecode scan establishes that a raw ordinal and argument-byte count occur at a static call site. It does not prove that a path executes in a retail playthrough. +- Converter prototypes can be imprecise, stale, or inconsistent across variants. Similar labels in both columns do not prove matching native behavior or ABI. +- Ghidra's Remorse `Item_Equip` annotations identify ordinals `0x0006` and `0x00B5`; `Item_Cast` identifies `0x00E8`. The native wrappers route these through `Usecode_ItemCallEvent` as `UC_Equip` and `UC_Cast`, corroborating those Remorse runtime mappings. +- Regret's native dispatch table was not independently verified in the referenced Ghidra pass. Treat Regret converter entries as naming/signature hints pending runtime cross-checks. +- The local Remorse bytecode includes `0x0134` and `0x0135`, beyond Pentagram's configured 308-entry sparse runtime table. This is a version/source coverage difference, not evidence that those bytecode calls are invalid. +- The current census is limited to the main local corpora. Variant/version-specific re-scans should be added as separately labeled columns or sections, not blended into these counts. + +For archive parsing, opcode details, event dispatch, and broad capability families, see the [main format specification](./usecode-format-specification.md). diff --git a/docs/usecode-pentagram-ghidra-path.md b/docs/usecode-pentagram-ghidra-path.md index 0d0a53c..d91f3c6 100644 --- a/docs/usecode-pentagram-ghidra-path.md +++ b/docs/usecode-pentagram-ghidra-path.md @@ -10,6 +10,12 @@ The goal is not to make Ghidra decompile Crusader USECODE as if it were x86 imme - replace Pentagram's older Crusader container/header assumptions with the owner-loaded class and slot model already verified in the binary and extractor - emit a lossless IR that can drive both human-readable USECODE output and future Ghidra annotations +## Product Development Direction + +The user-facing USECODE editor/decompiler/recompiler should be developed in the newer map-viewer decompiler at [usecode-decompiler.js](../../crusader_map_viewer/map_renderer/src/lib/usecode-decompiler.js), not by growing the Python proof of concept into a separate authoring tool. The map-viewer decompiler already has the newer structured rendering work and is the implementation to improve toward editable source, compilation, archive rebuilding, and in-game validation. + +The `tools/poc_crusader_usecode_parser.py` workflow below remains useful for reproducing byte-level analysis, generating comparison artifacts, and feeding verified evidence into the map-viewer implementation. It is not the intended end-user editing or recompilation workflow. + ## What To Reuse From Pentagram Useful directly: @@ -92,7 +98,7 @@ The first Ghidra-side use should be comments, bookmarks, and cross-reference not Do not try to map the bytecode into a full processor module first. -## Proof-Of-Concept Parser +## Proof-Of-Concept Parser And Evidence Workflow Tool path: @@ -109,10 +115,10 @@ Current deliberate limits: - no full intrinsic name table yet - no synthetic control-flow graph yet -- no recompilation path yet +- no recompilation path in this proof-of-concept tool - no Ghidra importer yet -That keeps the parser useful without pretending the VM is fully solved. +That keeps the parser useful without pretending the VM is fully solved. Continue the product-facing decompiler/editor/compiler work in the map viewer; keep this parser as an evidence source and independent cross-check. ## Canonical Ghidra Annotation Import Path diff --git a/docs/usecode-roundtrip-ir.md b/docs/usecode-roundtrip-ir.md index 3050ca4..46753da 100644 --- a/docs/usecode-roundtrip-ir.md +++ b/docs/usecode-roundtrip-ir.md @@ -1,4 +1,4 @@ -# USECODE Round-Trip IR Plan +# USECODE Decompiler/Recompiler Roadmap ## Purpose @@ -6,6 +6,61 @@ This note records the current evidence-backed path from Crusader USECODE bytes t It is intentionally conservative. ScummVM gives strong external anchors for the container layout, class/event numbering, and intrinsic naming, but it is not a symbol map for the DOS binary and it is not a ready-made round-trip compiler. +## Current Status + +There is a useful but incomplete decompilation pipeline; there is not yet a USECODE recompiler in this workspace. + +### Development Home + +The primary product path for the USECODE editor/decompiler/recompiler is the newer map-viewer decompiler in the adjacent `crusader_map_viewer` repository, especially [usecode-decompiler.js](../../crusader_map_viewer/map_renderer/src/lib/usecode-decompiler.js) and its regression suite at `map_renderer/scripts/test-usecode-structuring.mjs`. Continue developing that implementation into the user-facing tool: improve its decompilation, then add safe source/IR editing, compilation, and archive rebuilding there. + +Do not grow `tools/poc_crusader_usecode_parser.py` into a competing editor/compiler. Keep this repository's extractor, corpus, Python parser, and reverse-engineering notes as evidence sources, fixture generators, and cross-checks for the map-viewer implementation. The `rebuild/remorse` runtime model is also separate; it is not the product path for authoring or recompiling scripts. + +Implemented: + +- `tools/extract_eusecode_flx.py` extracts and indexes the owner-loaded FLEX/USECODE data, class headers, event rows, and derived body ranges. It also generates family reports and regression baselines. +- `tools/poc_crusader_usecode_parser.py` produces per-slot JSON IR, byte-oriented listings, script-like output, and pseudocode. It preserves raw instruction bytes when decoding stops and has focused Python structuring tests. +- The map-viewer decompiler already has newer structured-control-flow rendering and JavaScript regression tests. Treat that code as the primary implementation to improve; it currently does not provide the complete editable-source and recompilation path. +- `rebuild/remorse` contains a runtime/archive model and interpreter work. It does not currently provide a USECODE source assembler or archive writer. + +Not implemented yet: + +- A complete archive/class-level editable source format and editor workflow. The map viewer now has an initial versioned per-event JSON source-document prototype, but it is not yet a complete editing contract. +- A deterministic writer that rebuilds class records and FLEX archives. +- An end-to-end test proving a modified compiled script runs correctly in Remorse or Regret. + +The existing JSON and pseudocode outputs are analysis artifacts, not yet a supported edit-and-recompile format. Full VM semantic recovery is not a prerequisite for the first round-trip milestone: unknown bytes can remain opaque, provided their positions and any affected offsets are preserved or safely relocated. + +## Milestones To Reach A Working In-Game Round Trip + +Treat these as acceptance gates, not merely research topics. Keep Remorse and Regret variant-specific data separate where formats or intrinsic tables differ. + +- [x] **M0 — Extract and index the source data.** Enumerate archive entries, class names/ids, raw headers, event rows, and body windows with bounds checks. Existing extractor outputs and repeated-family regression data cover this foundation. +- [x] **M1 — Produce useful per-body decompilation artifacts.** Emit a machine-readable per-slot representation plus readable listing/pseudocode, and retain undecoded bytes instead of silently discarding them. Existing parsers/renderers provide these initial views; continue improving the map-viewer renderer as the primary decompiler. +- [ ] **M2 — Freeze a versioned, lossless editable IR/source contract in the map viewer.** Versioned archive and per-event snapshots now preserve exact bytes, class/event/body offsets, variant identity, and name-hint provenance; the per-event v2 overlay supports guarded fixed-width immediate edits. JSON parse/serialize equality and no-op byte restoration are tested on both game archives, with per-event coverage for Remorse (`TRIGGER` slot `0x20`) and Regret (`BRIDGE` slot `0x22`). Extend and test the overlay for the edit operations the editor will expose, then connect the contract to the editor-facing workflow before closing the milestone. +- [ ] **M3 — Turn the map-viewer decompiler into an editor and bounded compiler/assembler.** Add a user-facing way to edit source or structured IR; encode supported instructions and operands; resolve labels and relative branches; preserve opaque regions only when edits cannot invalidate their encoding or location. Reject unsupported/ambiguous edits with actionable errors. +- [ ] **M4 — Rebuild class records and FLEX archives from the map-viewer workflow.** Recalculate code offsets, event rows, class-size/header fields, entry lengths/offsets, and affected metadata while preserving ordering, sparse ids, untouched entries, and unknown bytes. Keep original inputs unchanged and write to a separate output. +- [ ] **M5 — Prove binary round trips and edit behavior with automated tests in the map-viewer path.** Require byte-for-byte identity for unchanged files and classes; add edited fixtures covering immediate-width changes, branch movement, strings, debug/local trailers, opaque opcodes, and both game variants. Reopen rebuilt outputs with an independent parser. +- [ ] **M6 — Validate modified output in the game.** Start with a controlled, low-risk script change in a disposable game copy. Verify the intended behavior in game, check load/startup paths, and confirm unrelated scripts and archives still work. Repeat for each supported variant. +- [ ] **M7 — Make the workflow repeatable for modders.** Provide documented commands, input/output safety checks, clear diagnostics, a supported-feature matrix, and a regression corpus so a user can decompile, edit, rebuild, and validate without manual binary surgery. + +**Final objective is met only when M2–M7 pass:** an unchanged archive round-trips exactly, a supported script edit compiles into a rebuilt archive, and the modified game exhibits the intended behavior without breaking the target build. + +The M2–M5 implementation and user workflow belong in the map-viewer USECODE decompiler/editor. This repository should continue supplying validated samples and independent checks, not a second end-user authoring pipeline. + +### Versioned Source Snapshot Contract + +The map-viewer currently has two complementary JSON snapshot forms: + +- `crusader-usecode-archive-source` v1 stores the complete original FLEX file once as canonical base64, its byte length and SHA-256, the FLEX entry directory, and derived class/event/body index records. +- `crusader-usecode-source` v2 stores one selected class/event view, including the exact original class bytes, six-byte event row, body bytes, game variant, descriptive decompilation IR, and an edit overlay. + +The archive document owns the authoritative untouched source bytes. Directory records refer to exact byte positions in those bytes: event-table and body offsets are recorded both relative to their class and relative to the archive. Class names carry provenance (`owner_name_table` or `generated_fallback`); event labels explicitly carry hint provenance. The per-event document uses lowercase hex for preserved class/event/body byte slices; the archive document uses base64 for the single complete source archive. Archive SHA-256 and body SHA-1 values detect accidental mismatch; neither is a replacement for byte comparison. + +For both forms, raw bytes and offsets are authoritative. Decoded instructions, intrinsic/event names, parsed strings, local/debug symbols, and field tags are descriptive metadata; the raw source still owns exact encoding, terminators, trailers, and unknown data. The v2 per-event overlay is separate from the immutable baseline and currently supports only guarded replacement of fixed-width `push_byte_immediate`, `push_word_immediate`, and `push_dword_immediate` operands. Each change is anchored to the original body digest, instruction offset, exact original instruction bytes, and original operand value, with width/range checks. An edited-IR preview applies these operands for rendering but explicitly retains the original raw bytes; it is not compiled output. Unsupported edit kinds must be rejected rather than silently approximated. + +Tests currently verify JSON parse/serialize equality and exact byte restoration for real Remorse and Regret archives, plus consistency checks tying event/body metadata and immediate-edit overlays back to the preserved bytes. M2 remains open until overlays cover the intended editor operations (including strings and structured/debug metadata) and are connected to an editor-facing workflow. The overlay is not yet applied to rebuilt bytecode. + ## Externally Anchored Pieces ### Container and class layout @@ -30,7 +85,7 @@ ScummVM also makes one implementation choice explicit that matters for the curre ### Binary-side validation against owner-loaded classes -The first direct local validation pass against sampled owner-loaded EUSECODE class records now splits the ScummVM model into two parts: one part is confirmed, and one part still needs reconciliation. +Direct local validation against sampled owner-loaded EUSECODE class records confirms the archive/class indexing and event-table structure, while narrowing the remaining disagreement to the interpretation of the header count/base arithmetic. Confirmed on sampled records (`EVENT`, `NPCTRIG`, `SURCAMNS`, `JELYHACK`, `REE_BOOT`, `SURCAMEW`, `SFXTRIG`): @@ -115,25 +170,24 @@ The first script IR should preserve exact recompilation inputs before it tries t ## Current Parser Views -The current proof-of-concept parser now emits three complementary views for a single class/slot body: +The Python proof-of-concept parser emits complementary research views for a single class/slot body. They are reference artifacts for the map-viewer product path, not a declaration that the map viewer already consumes this JSON as its editor/compiler format: -- JSON IR: the authoritative machine-facing output for tooling and any future assembler. +- JSON IR: the machine-facing output for current research tools and a candidate schema source for the future editable map-viewer IR. - Flat text listing: a byte-faithful decode with offsets, raw bytes, and trailer sections. - Script view: a more readable block-labeled decompilation with locals, labels, and stack-VM statements. - Pseudocode view: a higher-level decompilation that tries to collapse common compare ladders and stack expressions into programming-language-like control flow. -The script and pseudocode views are intentionally descriptive rather than authoritative. They are meant to help read bodies like `NPCTRIG 0x0A` or `EVENT 0x0A` without losing the exact JSON IR that a round-trip compiler will need. +The script and pseudocode views are intentionally descriptive rather than authoritative. They help inspect bodies like `NPCTRIG 0x0A` or `EVENT 0x0A`; the map-viewer implementation still needs a formally specified lossless editable representation before any compiler can rely on it. -## Deferred Readability Follow-Ups +## Current Decompiler Boundary -Keep these parser-facing readability tasks for later while the current focus stays on broad pseudocode export and class-family understanding: +The parser/renderer is a readability layer over partially decoded bytecode, not a semantic source-of-truth. Structured `if`/loop/switch output and intrinsic/event labels are helpful, but should not be used to regenerate bytes until the compiler contract and instruction encodings are specified. -1. Replace unresolved `class_XXXX_slot_YY` call labels with behavior-backed names where the compiled/runtime evidence is strong enough. -2. Replace placeholder argument names such as `arg_06` with semantic names inferred from stable usage patterns. -3. Detect more control-flow shapes beyond compare ladders, especially simple loops and early-return guards. -4. Collapse common spawn/setup idioms into more domain-specific statements when the stack pattern is consistent. -5. Run the pseudocode renderer across larger families like `EVENT`, `_BOOT`, and `SURCAM*` and tighten the heuristics where they still leak VM structure. -6. Add small behavior-level comments only where they help explain gameplay meaning rather than VM mechanics. +Remaining decompiler work should be driven by concrete corpus failures and semantic regressions, rather than the old open-ended readability list. In particular: + +- Keep unresolved calls, locals, and event labels neutral unless binary evidence supports stronger names. +- Grow opcode and operand coverage using known-good fixtures, with exact raw-byte preservation for unsupported forms. +- Track control-flow rendering gaps as decompiler issues, independently from compiler/round-trip milestones. ### Unit of decompilation @@ -767,43 +821,21 @@ For the current owner-loaded EUSECODE and round-trip IR work, the safest reversi - If the divisibility or bounds checks fail, keep the class opaque and preserve raw bytes rather than forcing a guessed event count. - `tools/extract_eusecode_flx.py` now implements this rule directly for the current owner-loaded EUSECODE work and emits `class_layout_index.tsv` plus `class_event_index.tsv` so raw header/event rows can be consumed by later IR tooling without re-deriving the arithmetic from prose. -## Remaining Binary-Side Gaps - -The main blockers for a real round-trip compiler are still on the binary side: +## Open Format And Runtime Questions - The meaning of the first two bytes in each 6-byte Crusader event record is still unverified. -- The exact provenance of ScummVM's current `get_class_event_count()` arithmetic is still unverified; current local evidence says the owner-loaded/raw records fit `raw_u32_at_8_11 = first_code_byte_offset`, while the ScummVM count formula appears sign-shifted relative to that layout. +- The exact provenance of ScummVM's `get_class_event_count()` arithmetic is still unverified; local owner-loaded records fit `raw_u32_at_8_11 = first_code_byte_offset`, while the ScummVM count formula appears sign-shifted relative to that layout. Preserve raw fields and use the locally validated bounds rule for now. - The upstream writer for selector local `[BP-0x32]` in the `000d:ebe3` sequencer is still unresolved. -- The full control-flow opcode set and branch encoding are not yet recovered. +- The full control-flow opcode set and branch encoding are not yet recovered. This limits safe semantic edits, but does not prevent a first opaque-preserving, bounded assembler. - The exact on-disk source format behind `entity_vm_runtime_owner_resource_create` is still not identified. - No direct descriptor-family to slot-mask mapping is proven yet. - Callback/eventTrigger descriptors still do not have a callback-specific opcode family. -## Best Current Path +These questions matter for deeper semantic decompilation and broader editing support. They are not all gates for a byte-preserving no-op round trip; the compiler milestones above define the required acceptance tests. -The strongest present path to a usable compiler/decompiler is: +## Historical Decompiler Work (completed milestones; not a current task list) -1. Parse classes/events exactly as ScummVM does. -2. Keep the class/object indexing and event-entry layout from ScummVM, but use the conservative local event-count rule above for owner-loaded/raw class parsing until a main USECODE sample proves otherwise. -3. Decompile only the proven operator families into structured IR. -4. Preserve unknown bytes verbatim in place. -5. Attach ScummVM event and intrinsic names as hints, not as truth. -6. Recompile by rebuilding the original class header and event table layout first, then re-emitting decoded and opaque ops together. - -That gets to a reversible editor sooner than waiting for a full semantic VM recovery. - -## **Recent Research (2026-03-26)** - -- **Root Cause:**: The structuring pass left forward/back-edge loops and counted-loop headers detached in fallback output, which produced unstructured pseudocode for some bodies (notably BART slot 0x0F). -- **Renderer Fixes:**: Added a conservative loop-lifting helper and a restricted infinite-loop lift in the partial fallback renderer to fold loops into structured blocks where safe. See the modified renderer at [tools/poc_crusader_usecode_parser.py](tools/poc_crusader_usecode_parser.py). -- **Validator Added:**: A lightweight pseudocode syntax/label validator was added to detect brace mismatches and missing goto/label targets before exporting pseudocode. -- **Tests:**: Added and adjusted unit tests in [tools/tests/test_usecode_structuring.py](tools/tests/test_usecode_structuring.py) to guard loop-lifting behavior and fallback conservatism. -- **Corpus Validation:**: Ran a corpus-wide render+validator pass over 977 decoded bodies; result: `TOTAL_BODIES=977, FAILURES=0` (no syntax/label failures). -- **Real-World Output:**: Regenerated the BART pseudocode file — [USECODE/EUSECODE_extracted/pseudocode/BART/slot_0F_enterFastArea.txt](USECODE/EUSECODE_extracted/pseudocode/BART/slot_0F_enterFastArea.txt) now shows an outer `while(true)` with nested structured branches and counted loops instead of detached labels. -- **Scope & Safety:**: Fully-structured renderer remains conservative; the loop-lifting helper is reused where safe. The outer infinite-loop lift was narrowed to partial fallback after tests revealed regressions when it was too broad. -- **Remaining Semantic Gap:**: Expression/comparison operand polarity still needs correction (some counted-loop conditions show inverted comparisons). Next work: fix operand ordering in the expression builder so loop headers reflect correct comparison direction. -- **Next Steps:**: (1) Implement compare-direction fix in the expression builder and add small semantic regression tests, (2) re-run unit tests and a corpus-wide render+validate sweep, (3) regenerate affected pseudocode files for inspection. -- **Files of Interest:**: [tools/poc_crusader_usecode_parser.py](tools/poc_crusader_usecode_parser.py), [tools/tests/test_usecode_structuring.py](tools/tests/test_usecode_structuring.py), [USECODE/EUSECODE_extracted/pseudocode/BART/slot_0F_enterFastArea.txt](USECODE/EUSECODE_extracted/pseudocode/BART/slot_0F_enterFastArea.txt). +The 2026-03-26 renderer pass added conservative loop lifting, a syntax/label validator, and corpus export checks (the then-current export contained 977 bodies). Subsequent work corrected comparison/branch semantics and added further renderer regressions; the comparison-polarity action item from that pass is closed. ## **Recent Renderer Work (2026-03-31)** @@ -811,7 +843,7 @@ That gets to a reversible editor sooner than waiting for a full semantic VM reco - **VM Semantics Fix:**: The JS renderer in [src/lib/usecode-decompiler.js](k:/ghidra/crusader_map_viewer/map_renderer/src/lib/usecode-decompiler.js) now follows the Pentagram/ScummVM VM for two core cases: opcode `0x24 cmp` is equality, not inequality, and opcode `0x51 IF` is a relative branch on false, not on true. - **Readability Impact:**: False branches are now emitted with the negated high-level condition, so the existing structurer can recover counted loops as `while (counter <= limit)` instead of the previously inverted `while (counter > limit)` pattern. - **Regression Coverage:**: Added a focused renderer-side regression script at [scripts/test-usecode-structuring.mjs](k:/ghidra/crusader_map_viewer/map_renderer/scripts/test-usecode-structuring.mjs) to guard one equality-based selector case and one counted-loop case. -- **Next Steps:**: Rebuild a fresh renderer usecode cache and inspect representative families like `BART`, `_BOOT`, and `EVENT` for any remaining cases where other compare producers still leak VM-oriented phrasing. +The follow-up work below continued across the representative families; treat any remaining renderer gaps as corpus-specific issues, not as an open task to rebuild that cache. ## **Recent Renderer Work (2026-04-01)** @@ -833,7 +865,6 @@ That gets to a reversible editor sooner than waiting for a full semantic VM reco - **Renderer Fixes:**: [src/lib/usecode-decompiler.js](k:/ghidra/crusader_map_viewer/map_renderer/src/lib/usecode-decompiler.js) now lifts `create_list` into list literals such as `[item]` and `append_list` into list concatenation expressions instead of leaving raw comment placeholders. That closes the common temporary-worklist patterns in bridge/trigger/free scripts where the old output showed `/* create_list */` and `/* append_list */` immediately before an assignment. - **False-Branch Fix:**: The same renderer pass now treats compound boolean expressions conservatively when inverting Crusader's `0x51` false-branch. For simple comparisons it still flips the operator directly, but for composed `&&` / `||` expressions it now emits a whole-expression negation rather than corrupting the leftmost compare. This fixes the broken `BRO_BOOT.slot_0F` entry test that previously rendered as `global[0x001f] != 2 || global[0x001f] == 3 ...` even though the bytecode is a plain OR-chain of equality compares. - **Selector Readability:**: Long same-selector equality ladders that share one join target now render as `switch (...)` blocks when every branch is a simple equality case. The immediate real-data win is [BRO_BOOT/slot_0A_equip.txt](k:/ghidra/crusader_map_viewer/map_renderer/.cache/usecode/remorse/EUSECODE/pseudocode/BRO_BOOT/slot_0A_equip.txt), whose repeated `global[0x001f] == N` movie dispatch chain now decompiles as a switch instead of six `else if` arms. -- **BRO_BOOT Structuring Impact:**: With the compound-condition fix in place, [BRO_BOOT/slot_0F_enterFastArea.txt](k:/ghidra/crusader_map_viewer/map_renderer/.cache/usecode/remorse/EUSECODE/pseudocode/BRO_BOOT/slot_0F_enterFastArea.txt) is expected to collapse into one structured `if/else` around the two `SPANEL` scans plus the trailing infinite animation loop, instead of keeping `entry:` / `block_0454`-style fallbacks. - **Regression Coverage:**: [scripts/test-usecode-structuring.mjs](k:/ghidra/crusader_map_viewer/map_renderer/scripts/test-usecode-structuring.mjs) now adds synthetic regressions for list-literal lifting, compound false-branch negation, and switch rendering, plus real-data regressions for `BRO_BOOT.slot_0A` and `BRO_BOOT.slot_0F`. ## **Recent Renderer Work (2026-04-02, CHANGER selector close)** diff --git a/docs/usecode-tool-improvement-plan.md b/docs/usecode-tool-improvement-plan.md index 8911ccd..2f438cf 100644 --- a/docs/usecode-tool-improvement-plan.md +++ b/docs/usecode-tool-improvement-plan.md @@ -1,42 +1,40 @@ -# USECODE Tool Improvement Plan +# USECODE Map-Viewer Decompiler/Editor Plan ## Purpose -This note turns the earlier tooling comparison into a concrete improvement plan for the local parser/decompiler. +This note turns the tooling comparison into an implementation plan for the map-viewer USECODE decompiler/editor. -The intent is not to copy Pentagram or `crusader-disasm` wholesale. The intent is to extract the parts that are genuinely useful for the current workspace toolchain: +The primary development target is the newer map-viewer implementation at [usecode-decompiler.js](../../crusader_map_viewer/map_renderer/src/lib/usecode-decompiler.js), with regressions in `map_renderer/scripts/test-usecode-structuring.mjs`. It should grow into the actual user-facing tool for decompiling, editing, and recompiling USECODE. -- `tools/poc_crusader_usecode_parser.py` -- `tools/export_usecode_pseudocode.py` -- the extracted owner-loaded corpus under `USECODE/EUSECODE_extracted/` +The local Python parser/exporter and `USECODE/EUSECODE_extracted/` corpus are supporting research infrastructure: use them for byte-level evidence, fixtures, and independent output comparisons. Do not build a competing end-user editor/compiler in those tools. + +The intent is not to copy Pentagram or `crusader-disasm` wholesale. Extract their useful opcode, operand, and metadata evidence and apply it to the map-viewer implementation. ## Short version -The most useful next upgrades are: +The most useful next upgrades in the map-viewer implementation are: -1. make the decoder tables more authoritative -2. decode loop/selector idioms into real structured searches -3. improve intrinsic naming and signatures -4. distinguish code from trailers more rigorously -5. add corpus-level pattern clustering and family annotations -6. keep strengthening the runtime bridge back into the retail binary +1. keep strengthening opcode/operand and control-flow coverage +2. preserve a lossless, editable IR alongside readable pseudocode +3. add a source/IR editing workflow +4. build an assembler and deterministic class/FLEX archive writer +5. validate untouched and modified output, including in-game behavior ## Current status -Implemented in the current local parser/exporter batch: +Existing work to build on: -- first evidence-backed class/slot aliasing for spawned or called helpers, so common wrappers now render with class names and known slot names such as `FREE.waitNTimerTicks(...)` instead of raw `class_0A0C_slot_32(...)` -- first real loop-selector decoding for the common `nearby_items(...)` family/shape searches used by alarm and trigger bodies -- structured rendering now upgrades the simpler selector loops to real `for item in nearby_items(...)` output instead of raw `loopscr` comment runs -- a second common selector family now renders as readable `selector_0x42(arg0=..., arg1=..., arg2=..., origin=...)` signatures, and the simpler back-edge cases upgrade to `for ... in selector_0x42(...)` instead of raw `loopscr 0x42` comment runs -- full corpus export regenerated through `tools/export_usecode_pseudocode.py`, so the checked-in pseudocode corpus matches the improved renderer +- the map-viewer decompiler already structures a growing set of branches, loops, selectors, list operations, and switch-like dispatches, with focused JavaScript regression tests +- versioned `crusader-usecode-archive-source` v1 and per-event `crusader-usecode-source` v2 JSON snapshots preserve original archive/class/event/body bytes; the per-event overlay validates guarded fixed-width immediate edits and can produce a clearly labeled edited-IR preview, while broader edit support, editor integration, and compilation remain open +- the workspace Python parser/exporter supplies per-slot byte-backed IR, pseudocode, extracted corpus data, and comparison fixtures +- both sources provide useful evidence, but neither currently completes the edit → compile → rebuild → in-game validation loop -Still open after this batch: +Still required in the map-viewer product path: -- broader selector mini-language coverage beyond the common `nearby_items(...)` forms and the currently opaque but readable `selector_0x42(...)` fallback -- more wrapper aliasing than the currently verified `FREE.waitNTimerTicks` seed entry -- a more authoritative opcode metadata table instead of the current mixed declarative/heuristic decoder -- corpus-level clustering/index outputs feeding back into inline annotations +- improve semantic and structural decompilation based on concrete corpus failures +- formalize the lossless editable format and connect it to an editor experience +- implement compilation, relocation/offset updates, and safe archive rebuilding +- add byte-identical round-trip, edit-regression, and Remorse/Regret runtime tests ## Priority 1: Authoritative opcode metadata @@ -50,11 +48,11 @@ From Pentagram and `crusader-disasm`: ### Why it matters -The current parser already decodes enough to produce readable pseudocode, but some opcodes are still treated more heuristically than declaratively. That is fine for proof-of-concept output, but it becomes fragile once more control-flow and loop idioms are added. +The map-viewer decompiler already produces readable structured output for a growing subset, but opcode semantics and operand formats still need evidence-backed coverage. Heuristic rendering must remain distinct from the lossless representation used by the future compiler. ### Concrete change -Move the per-opcode knowledge into a single explicit table describing: +Move the map-viewer per-opcode knowledge into a single explicit table describing: - mnemonic - stack effect where known @@ -80,13 +78,13 @@ From the older disassembly corpus: ### Why it matters -Right now the parser preserves loop selector bytes faithfully, but readable pseudocode still shows comments like `loopscr value_u8=0x40` instead of the underlying search semantics. +The map-viewer already renders several common selector forms. Remaining selector forms should be added there as evidence and regression cases are established; keep unknown forms visible rather than guessing semantics. That is the main reason scripts like `ALARMHAT` still read as partially machine-shaped even though the overall behavior is already understandable. ### Concrete change -Introduce a small loop-selector IR layer so common loop forms render as something closer to: +Extend the map-viewer loop-selector IR so supported forms render as something closer to: ```text for item in nearby_items(shape=0x04D0, origin=arg_06): @@ -162,7 +160,7 @@ From Pentagram's symbol-info/debug-symbol handling: The JELYHACK pass already showed how important this is. Tiny scripts are easy to misread if post-`ret` metadata gets rendered as live code. -The current parser now avoids that in readable pseudocode, but the boundary logic should become a first-class part of the IR rather than a readability-only safeguard. +The current renderers avoid some of these misclassifications, but the map-viewer IR/compiler path must make code and trailer boundaries first-class so edits cannot accidentally treat metadata as executable bytes. ### Concrete change @@ -224,7 +222,7 @@ From the local repo workflow rather than directly from Pentagram: ### Why it matters -The parser is strongest when its readable output can be tied back to the compiled loader and sequencer. That keeps the decompiler grounded instead of drifting into pure script aesthetics. +The map-viewer decompiler is strongest when its readable output can be tied back to the compiled loader and sequencer. Keep those runtime anchors attached as evidence, without letting them replace the lossless byte representation needed for compilation. ### Concrete change @@ -245,16 +243,17 @@ Expand the export and annotation path so pseudocode/index output can carry verif ## Suggested implementation order -1. stabilize opcode metadata tables -2. formalize trailer parsing in IR -3. implement first real loop-selector decoder for common `shape` and `family` searches -4. add intrinsic metadata with confidence levels -5. add corpus clustering/index helpers -6. extend runtime-anchor export/import integration +1. Continue improving the map-viewer decoder, operand model, control-flow structuring, and trailer handling against extracted fixtures. +2. Keep each semantic or rendering improvement covered by focused and real-corpus regressions in the map-viewer test suite. +3. Define the map-viewer's versioned, lossless editable IR and source/editor experience; retain raw bytes and provenance for unsupported instructions. +4. Implement a bounded assembler, label/branch resolution, and deterministic class/FLEX archive rebuild in the same product path. +5. Prove byte-identical output for unchanged inputs, then test supported edits and reject unsafe edits clearly. +6. Run controlled Remorse and Regret game tests before declaring a supported round-trip workflow. ## What not to do yet -- Do not chase full round-tripping first. Readability is still the higher-value frontier. +- Do not treat readable pseudocode as compilable source or let the Python proof of concept become a second editor/compiler. +- Do not stop at readability: the intended outcome is an editor/decompiler/recompiler that produces working in-game USECODE. - Do not mass-promote intrinsic or event names from Pentagram or the old disasm corpus without current-binary support. - Do not try to solve every loop/selector form before landing the small repeated set that already appears across the alarm and trigger families. diff --git a/docs/usecode-tooling-comparison.md b/docs/usecode-tooling-comparison.md index dc2d4f5..2bfd6cd 100644 --- a/docs/usecode-tooling-comparison.md +++ b/docs/usecode-tooling-comparison.md @@ -2,11 +2,12 @@ ## Purpose -This note compares three different USECODE-facing tool lines now in use around the Crusader work: +This note compares four different USECODE-facing tool lines now in use around the Crusader work: 1. Pentagram's built-in Crusader usecode converter/disassembler 2. the local `crusader-disasm` corpus and helper scripts -3. the current workspace parser/decompiler in `tools/poc_crusader_usecode_parser.py` +3. the workspace research parser/decompiler in `tools/poc_crusader_usecode_parser.py` +4. the newer map-viewer decompiler in `crusader_map_viewer/map_renderer` The goal is not to rank them abstractly. The goal is to state what each one is actually good at, what assumptions it bakes in, and why the current local parser had to diverge. @@ -16,7 +17,9 @@ Pentagram is a game-engine-side disassembler/converter with generic Crusader hoo `crusader-disasm` is mostly a generated disassembly corpus plus small maintenance scripts that mine or preserve information from that corpus. -Our current parser is the first tool in this workspace that is explicitly built around the validated owner-loaded `EUSECODE.FLX` structure recovered from the retail binary and then pushed further into readable pseudocode export. +The Python parser is the research/reference pipeline built around the validated owner-loaded `EUSECODE.FLX` structure recovered from the retail binary. + +The map-viewer decompiler is the primary product-development path. Continue improving it into the actual USECODE editor, decompiler, and recompiler; do not build a parallel user-facing editor/compiler around the Python proof of concept. ## Pentagram: what it does @@ -155,7 +158,7 @@ So this is again a maintenance aid around a text corpus, not a first-principles In practice, `crusader-disasm` has been most useful as a vocabulary/evidence source, not as the final tool we run to generate the readable corpus. -## Our current parser/decompiler: what it does differently +## Workspace research parser/decompiler: what it does differently The current local tool line is centered on: @@ -260,7 +263,21 @@ So the best current workflow is still hybrid: - use Pentagram for structural/reference behavior - use `crusader-disasm` for opcode vocabulary and corpus evidence -- use the local parser for validated owner-loaded extraction, IR, pseudocode, and batch readability export +- use the local parser/extractor for validated owner-loaded data, research IR, fixtures, and independent pseudocode comparisons +- use the map-viewer decompiler as the primary implementation and future user-facing USECODE editor/compiler + +## Map-viewer decompiler: primary development target + +The newer implementation lives in `crusader_map_viewer/map_renderer`, principally in `src/lib/usecode-decompiler.js`, with renderer regressions in `scripts/test-usecode-structuring.mjs`. Its later control-flow, loop, list, selector, and switch rendering work makes it the right foundation for the user-facing editor/decompiler. + +It is not yet a recompiler. Development should continue there to: + +- improve decompilation against the extracted corpus and binary evidence +- add a stable, lossless editable source/IR representation and editor workflow +- implement a bounded assembler and deterministic class/FLEX archive rebuild +- prove unchanged byte-identical round trips and validate edited output in both games + +The Python parser and extracted artifacts remain valuable as independent evidence, fixtures, and comparison outputs. They should inform and test the map-viewer decompiler, not become a competing product path. ## Best current summary @@ -268,9 +285,11 @@ Pentagram is a converter/disassembler. `crusader-disasm` is a disassembly corpus with helper scripts. -Our script is the first repo-local tool that is explicitly trying to be a readable decompiler over the validated extracted `EUSECODE` corpus. +The Python parser is the research tool that established readable decompilation over the validated extracted `EUSECODE` corpus. -That is why the current parser looks less like a classic disassembler and more like a layered RE workbench: +The map-viewer decompiler is where the actual editor/decompiler/recompiler should be built. + +The research parser remains a layered RE workbench: - extractor-backed local format understanding - structured IR @@ -279,4 +298,4 @@ That is why the current parser looks less like a classic disassembler and more l - batch corpus export - runtime-annotation hints tied to the current Crusader notes -The tradeoff is that our current script is newer and more heuristic. It is better at producing something a human can read across the whole corpus, but it is not yet as mature or as battle-tested at raw opcode coverage as the older reference tools. \ No newline at end of file +The tradeoff is that the research parser is newer and more heuristic. It helps produce human-readable corpus output and acts as a cross-check, while the map-viewer implementation still needs the editing, compilation, and archive-writing stages required for a working in-game round trip. \ No newline at end of file diff --git a/rebuild/remorse/include/remorse/entity_dispatch_entry.h b/rebuild/remorse/include/remorse/entity_dispatch_entry.h index 7a3eadc..f6c8956 100644 --- a/rebuild/remorse/include/remorse/entity_dispatch_entry.h +++ b/rebuild/remorse/include/remorse/entity_dispatch_entry.h @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace remorse { @@ -56,6 +57,11 @@ struct TeleporterProcessEntry { u8 extra[0x04]; } CR_PACKED; +struct ClearAvatarInStasisProcessEntry { + EntityDispatchEntryBase base; + u8 extra[0x01]; +} CR_PACKED; + struct AnimPrimitiveProcessEntry { EntityDispatchEntryBase base; u8 extra[0x29]; @@ -82,6 +88,9 @@ struct EntityDispatchEntryRuntimeState { } CR_PACKED; CR_PACK_POP +static_assert(sizeof(ClearAvatarInStasisProcessEntry) == 0x33, + "Clear-avatar-stasis process size must match allocation evidence"); + static_assert(sizeof(EntityDispatchEntryBase) == 0x32, "EntityDispatchEntryBase size must match allocation evidence"); static_assert(sizeof(StandProcessEntry) == 0x42, "StandProcessEntry size must match allocation evidence"); static_assert(sizeof(GravityProcessEntry) == 0x42, "GravityProcessEntry size must match allocation evidence"); @@ -127,6 +136,10 @@ public: ControllerProcessEntry* createControllerProcess(u8 activeGroup, u16 (&groupCounts)[32]); TeleporterProcessEntry* createTeleporterProcess(u8 activeGroup, u16 mapNumber, u16 teleportId, u16 (&groupCounts)[32]); + TeleporterProcessEntry* createTeleporterProcess(u8 activeGroup, u16 mapNumber, u16 teleportId, + u16 (&groupCounts)[32], bool doStasis, bool avatarTeleporting, bool& avatarInStasis); + bool runClearAvatarInStasisProcess(u16 processId, bool& avatarInStasis, + u16 (&groupCounts)[32]); AnimPrimitiveProcessEntry* createAnimPrimitiveProcess(u8 activeGroup, u16 itemNumber, u16 animationNumber, u8 direction, const AnimationClip& clip, u16 (&groupCounts)[32]); EntityVmContextProcessEntry* createUsecodeProcess(u8 activeGroup, u16 (&groupCounts)[32]); @@ -172,6 +185,8 @@ public: std::size_t capacity() const; private: + ClearAvatarInStasisProcessEntry* createClearAvatarInStasisProcess(u8 activeGroup, + bool& avatarInStasis, u16 (&groupCounts)[32]); void releaseOwnedProcess(u16 id); void refreshItemPresence(u16 itemNumber); void refreshItemProcessType(u16 itemNumber, u16 eventType); @@ -183,12 +198,14 @@ private: std::vector> ownedGravityProcesses_; std::vector> ownedAnimPrimitiveProcesses_; std::vector> ownedTeleporterProcesses_; + std::vector> ownedClearAvatarInStasisProcesses_; std::vector> ownedUsecodeProcesses_; std::unique_ptr systemTimerProcess_; std::unique_ptr keyboardProcess_; std::unique_ptr keyDaemonProcess_; std::unique_ptr controllerProcess_; std::vector keyboardSubscriberIds_; + std::vector> processWaits_; std::array pendingKeyEvents_{}; u8 nextKeyEventOffset_ = 0; u8 keyEventOffset_ = 0; @@ -255,6 +272,11 @@ public: u16 currentMapNumber, const std::vector& shapes); }; +class ClearAvatarInStasisProcess { +public: + static constexpr u16 vtableOffset = 0x0f5e; +}; + class KeyboardProcess { public: static bool handleKeyEvent(KeyboardProcessEntry& process, u16 selector, u16 filter, diff --git a/rebuild/remorse/include/remorse/fixed_map.h b/rebuild/remorse/include/remorse/fixed_map.h index ca1ecc7..0bd6737 100644 --- a/rebuild/remorse/include/remorse/fixed_map.h +++ b/rebuild/remorse/include/remorse/fixed_map.h @@ -132,6 +132,7 @@ public: std::optional> hatchGlobEgg(u16 eggItemNumber, const GlobObject& glob, const std::vector& shapes); bool isGlobHatched(u16 eggItemNumber) const; + bool setItemShape(u16 itemNumber, u16 shape); bool setItemFrame(u16 itemNumber, u8 frame); bool moveItem(u16 itemNumber, u16 x, u16 y, u8 z); std::optional> grabItem(u16 itemNumber, const std::vector& shapes, diff --git a/rebuild/remorse/src/entity_dispatch_entry.cpp b/rebuild/remorse/src/entity_dispatch_entry.cpp index c813b00..ea1c5c6 100644 --- a/rebuild/remorse/src/entity_dispatch_entry.cpp +++ b/rebuild/remorse/src/entity_dispatch_entry.cpp @@ -195,6 +195,44 @@ TeleporterProcessEntry* ProcessKernel::createTeleporterProcess(u8 activeGroup, u return result; } +TeleporterProcessEntry* ProcessKernel::createTeleporterProcess(u8 activeGroup, u16 mapNumber, + u16 teleportId, u16 (&groupCounts)[32], bool doStasis, bool avatarTeleporting, + bool& avatarInStasis) +{ + auto* teleporter = createTeleporterProcess(activeGroup, mapNumber, teleportId, groupCounts); + if (doStasis && !avatarTeleporting) { + auto* clearStasis = createClearAvatarInStasisProcess(activeGroup, avatarInStasis, groupCounts); + processWaits_.emplace_back(readLe16(teleporter->base, 0x02), + readLe16(clearStasis->base, 0x02)); + } + return teleporter; +} + +ClearAvatarInStasisProcessEntry* ProcessKernel::createClearAvatarInStasisProcess(u8 activeGroup, + bool& avatarInStasis, u16 (&groupCounts)[32]) +{ + if (processes_.size() == 1020 && std::find(processes_.begin(), processes_.end(), nullptr) == processes_.end()) { + throw std::overflow_error("process table exhausted"); + } + if (std::find(processes_.begin(), processes_.end(), nullptr) == processes_.end()) { + processes_.reserve(processes_.size() + 30); + allocationSizes_.reserve(allocationSizes_.size() + 30); + processNames_.reserve(processNames_.size() + 30); + } + ownedClearAvatarInStasisProcesses_.reserve(ownedClearAvatarInStasisProcesses_.size() + 1); + auto process = std::make_unique(); + EntityDispatchEntry::initBase(&process->base, activeGroup, groupCounts); + writeLe16(process->base, 0x00, ClearAvatarInStasisProcess::vtableOffset); + process->extra[0] = avatarInStasis ? 1 : 0; + avatarInStasis = true; + setLastAllocationSize(sizeof(ClearAvatarInStasisProcessEntry)); + const u16 id = addProcess(process->base); + processNames_[id] = "ClearAvatarInStasis"; + ClearAvatarInStasisProcessEntry* result = process.get(); + ownedClearAvatarInStasisProcesses_.push_back(std::move(process)); + return result; +} + bool TeleporterProcess::run(const TeleporterProcessEntry& process, LiveFixedMapItems& items, u16 currentMapNumber, const std::vector& shapes) { @@ -211,6 +249,27 @@ bool TeleporterProcess::run(const TeleporterProcessEntry& process, LiveFixedMapI return destination && items.teleportAvatar(*destination, static_cast(targetMap)); } +bool ProcessKernel::runClearAvatarInStasisProcess(u16 processId, bool& avatarInStasis, + u16 (&groupCounts)[32]) +{ + EntityDispatchEntryBase* entry = processAt(processId); + const auto ownedProcess = std::find_if(ownedClearAvatarInStasisProcesses_.begin(), + ownedClearAvatarInStasisProcesses_.end(), [entry](const auto& process) { + return &process->base == entry; + }); + if (entry == nullptr || readLe16(*entry, 0x00) != ClearAvatarInStasisProcess::vtableOffset || + ownedProcess == ownedClearAvatarInStasisProcesses_.end()) { + return false; + } + const auto* process = reinterpret_cast(entry); + if (process->extra[0] == 0) { + avatarInStasis = false; + } + entry->bytes[0x18] |= 0x04; + terminateProcess(processId, groupCounts); + return true; +} + EntityVmContextProcessEntry* ProcessKernel::createUsecodeProcess(u8 activeGroup, u16 (&groupCounts)[32]) { @@ -690,6 +749,9 @@ void ProcessKernel::clearProcessSlot(u16 id) if (id >= processes_.size()) { throw std::out_of_range("process ID outside table"); } + processWaits_.erase(std::remove_if(processWaits_.begin(), processWaits_.end(), [id](const auto& wait) { + return wait.first == id || wait.second == id; + }), processWaits_.end()); processes_[id] = nullptr; allocationSizes_[id] = 0; processNames_[id] = nullptr; @@ -723,6 +785,13 @@ void ProcessKernel::releaseOwnedProcess(u16 id) ownedTeleporterProcesses_.erase(teleporter); return; } + const auto clearAvatarInStasis = std::find_if(ownedClearAvatarInStasisProcesses_.begin(), + ownedClearAvatarInStasisProcesses_.end(), + [entry](const auto& process) { return &process->base == entry; }); + if (clearAvatarInStasis != ownedClearAvatarInStasisProcesses_.end()) { + ownedClearAvatarInStasisProcesses_.erase(clearAvatarInStasis); + return; + } const auto usecode = std::find_if(ownedUsecodeProcesses_.begin(), ownedUsecodeProcesses_.end(), [entry](const auto& process) { return &process->base == entry; }); if (usecode != ownedUsecodeProcesses_.end()) { @@ -771,6 +840,9 @@ void ProcessKernel::terminateProcess(u16 id, u16 (&groupCounts)[32]) const bool ownedTeleporterProcess = std::any_of(ownedTeleporterProcesses_.begin(), ownedTeleporterProcesses_.end(), [entry](const auto& process) { return &process->base == entry; }); + const bool ownedClearAvatarInStasisProcess = std::any_of(ownedClearAvatarInStasisProcesses_.begin(), + ownedClearAvatarInStasisProcesses_.end(), + [entry](const auto& process) { return &process->base == entry; }); if (itemNumber != 0 && (stand == ownedStandProcesses_.end() && !ownedItemProcess && !ownedGravityProcess && !ownedAnimationProcess && !ownedUsecodeProcess || id < 3 || readLe16(*entry, 0x24) != 0 || readLe16(*entry, 0x26) != 0 || @@ -778,7 +850,7 @@ void ProcessKernel::terminateProcess(u16 id, u16 (&groupCounts)[32]) throw std::logic_error("item process child cleanup is not ported"); } if (stand == ownedStandProcesses_.end() && !ownedGravityProcess && !ownedAnimationProcess && - !ownedUsecodeProcess && !ownedTeleporterProcess && + !ownedUsecodeProcess && !ownedTeleporterProcess && !ownedClearAvatarInStasisProcess && std::none_of(ownedProcesses_.begin(), ownedProcesses_.end(), [entry](const auto& process) { return process.get() == entry; })) { throw std::logic_error("external process ownership is not ported"); @@ -923,7 +995,21 @@ void ProcessKernel::scanRunnableProcesses(u8 activeGroup, void (*run)(EntityDisp try { for (std::size_t id = 0; id < processes_.size(); ++id) { EntityDispatchEntryBase* entry = processes_[id]; - if (entry != nullptr && (readLe16(*entry, 0x16) & 0x08) == 0) { + bool waitingForProcess = false; + if (entry != nullptr) { + const u16 processId = readLe16(*entry, 0x02); + const auto wait = std::find_if(processWaits_.begin(), processWaits_.end(), + [processId](const auto& candidate) { return candidate.first == processId; }); + if (wait != processWaits_.end()) { + const EntityDispatchEntryBase* target = processAt(wait->second); + waitingForProcess = target != nullptr && + (readLe16(*target, 0x16) & 0x08) == 0; + if (!waitingForProcess) { + processWaits_.erase(wait); + } + } + } + if (entry != nullptr && !waitingForProcess && (readLe16(*entry, 0x16) & 0x08) == 0) { if ((readLe16(*entry, 0x18) & 0x1000) != 0) { const u32 sleepStart = readLe16(*entry, 0x0a) | (static_cast(readLe16(*entry, 0x0c)) << 16); const u32 sleepLength = readLe16(*entry, 0x0e) | (static_cast(readLe16(*entry, 0x10)) << 16); diff --git a/rebuild/remorse/src/fixed_map.cpp b/rebuild/remorse/src/fixed_map.cpp index e419081..539458e 100644 --- a/rebuild/remorse/src/fixed_map.cpp +++ b/rebuild/remorse/src/fixed_map.cpp @@ -854,6 +854,18 @@ bool LiveFixedMapItems::isGlobHatched(u16 eggItemNumber) const return eggItemNumber < hatchedGlobIds_.size() && hatchedGlobIds_[eggItemNumber]; } +bool LiveFixedMapItems::setItemShape(u16 itemNumber, u16 shape) +{ + const auto item = std::find_if(items_.begin(), items_.end(), [itemNumber](const auto& candidate) { + return candidate.itemNumber == itemNumber; + }); + if (item == items_.end()) { + return false; + } + item->data.shape = shape; + return true; +} + bool LiveFixedMapItems::setItemFrame(u16 itemNumber, u8 frame) { const auto item = std::find_if(items_.begin(), items_.end(), [itemNumber](const auto& candidate) { diff --git a/rebuild/remorse/src/windowed_game_main.cpp b/rebuild/remorse/src/windowed_game_main.cpp index 10f9be6..b19a0ea 100644 --- a/rebuild/remorse/src/windowed_game_main.cpp +++ b/rebuild/remorse/src/windowed_game_main.cpp @@ -299,8 +299,16 @@ void runUsecodeTasks(AppState& state) const auto* item = app.liveItems ? app.liveItems->findItem(*itemNumber) : nullptr; return item ? std::optional{item->data.mapNumber} : std::nullopt; } + if (ordinal == 0x24 && argumentBytes == 6) { + const remorse::u16 shape = static_cast(arguments[4] | + (static_cast(arguments[5]) << 8)); + if (!app.liveItems || !app.liveItems->setItemShape(*itemNumber, shape)) { + return std::nullopt; + } + app.usecodeWorldMutationPending = true; + return remorse::u16{0}; + } if (ordinal == 0x59 && argumentBytes == 6) { - std::lock_guard lock(app.sceneMutex); const remorse::u8 frame = static_cast(arguments[4] | (static_cast(arguments[5]) << 8)); if (!app.liveItems || !app.liveItems->setItemFrame(*itemNumber, frame)) { @@ -526,15 +534,51 @@ void loadSceneAsync(HWND window, AppState& state) for (int reservedSlot = 0; reservedSlot < 3; ++reservedSlot) { teleporterKernel.createProcess(1, teleporterGroupCounts); } + bool avatarInStasis = false; auto* teleporter = teleporterKernel.createTeleporterProcess(1, - static_cast(state.mapIndex), 0x1e, teleporterGroupCounts); + static_cast(state.mapIndex), 0x1e, teleporterGroupCounts, + true, false, avatarInStasis); const remorse::u16 processId = static_cast(teleporter->base.bytes[2] | (static_cast(teleporter->base.bytes[3]) << 8)); - const bool teleported = remorse::TeleporterProcess::run(*teleporter, liveItems, - static_cast(state.mapIndex), *shapeTypes); - teleporter->base.bytes[0x18] |= 4; - teleporterKernel.terminateProcess(processId, teleporterGroupCounts); - if (!teleported) { + struct StartupContext { + remorse::ProcessKernel& kernel; + remorse::LiveFixedMapItems& items; + const std::vector& shapes; + remorse::u16 (&groupCounts)[32]; + bool& avatarInStasis; + remorse::u16 mapNumber; + bool teleported = false; + bool valid = true; + } startup{teleporterKernel, liveItems, *shapeTypes, teleporterGroupCounts, + avatarInStasis, static_cast(state.mapIndex)}; + const auto runStartupProcess = [](remorse::EntityDispatchEntryBase& entry, + void* opaque) { + auto& context = *static_cast(opaque); + const remorse::u16 processId = static_cast(entry.bytes[2] | + (static_cast(entry.bytes[3]) << 8)); + if (processId < 3) return; + const remorse::u16 vtable = static_cast(entry.bytes[0] | + (static_cast(entry.bytes[1]) << 8)); + if (vtable == remorse::ClearAvatarInStasisProcess::vtableOffset) { + context.valid = context.kernel.runClearAvatarInStasisProcess(processId, + context.avatarInStasis, context.groupCounts); + } else if (vtable == remorse::TeleporterProcess::vtableOffset) { + const auto& teleporterProcess = + *reinterpret_cast(&entry); + context.teleported = remorse::TeleporterProcess::run(teleporterProcess, + context.items, context.mapNumber, context.shapes); + entry.bytes[0x18] |= 4; + context.kernel.terminateProcess(processId, context.groupCounts); + } else { + context.valid = false; + } + }; + for (unsigned pass = 0; pass < 2 && teleporterKernel.processAt(processId) != nullptr; + ++pass) { + teleporterKernel.scanRunnableProcesses(1, runStartupProcess, &startup); + } + if (!startup.valid || !startup.teleported || avatarInStasis || + teleporterKernel.processAt(processId) != nullptr) { setLoadFailure(state, L"The teleporter process could not resolve its map and egg destination."); PostMessageW(window, sceneReadyMessage, 0, 0); return; @@ -968,6 +1012,7 @@ void updatePlayer(HWND window, AppState& state) runUsecodeTasks(state); const auto movement = state.controllerMovement.request(); state.diagnosticKernel.deliverSystemTimerEvent(); + bool gravityMoved = false; if (state.diagnostics) { const bool wasSleeping = (state.diagnosticStand->base.bytes[0x19] & 0x10) != 0; const remorse::u32 previousSleepStart = standSleepStart(*state.diagnosticStand); @@ -1016,8 +1061,13 @@ void updatePlayer(HWND window, AppState& state) if (wasSleeping && standSleepStart(*state.diagnosticStand) != previousSleepStart) { ++state.standWakeCount; } + } else if (state.liveItems) { + gravityMoved = state.diagnosticKernel.scanResolvedGravity( + state.diagnosticKernel.activeGroup(), *state.liveItems, state.shapeTypes, + remorse::calculateFastAreaRange(avatarWorld(state)), 1, + state.diagnosticKernel.systemTimerTick(), state.diagnosticGroupCounts) != 0; } - changed = changed || state.diagnostics; + changed = changed || state.diagnostics || gravityMoved; if (movement.animation == 0) { if (state.animationProcessId != 0) { auto* process = state.diagnosticKernel.processAt(state.animationProcessId); @@ -1028,6 +1078,13 @@ void updatePlayer(HWND window, AppState& state) changed = changed || state.playerAnimation != 0 || state.playerFrame != 0; state.playerAnimation = 0; state.playerFrame = 0; + const bool usecodeMutation = state.usecodeWorldMutationPending; + state.usecodeWorldMutationPending = false; + changed = changed || usecodeMutation; + if (state.renderThread.joinable() && (gravityMoved || usecodeMutation)) { + state.renderRequested = true; + state.renderWake.notify_one(); + } continue; } @@ -1078,7 +1135,7 @@ void updatePlayer(HWND window, AppState& state) *state.liveItems, *state.renderer, remorse::calculateFastAreaRange(avatarWorld(state))); const bool usecodeMutation = state.usecodeWorldMutationPending; state.usecodeWorldMutationPending = false; - if (state.renderThread.joinable() && (moved || hatched || usecodeMutation)) { + if (state.renderThread.joinable() && (moved || hatched || usecodeMutation || gravityMoved)) { state.renderRequested = true; state.renderWake.notify_one(); } diff --git a/rebuild/remorse/tests/fixed_map_tests.cpp b/rebuild/remorse/tests/fixed_map_tests.cpp index f4b84a2..b91f2bf 100644 --- a/rebuild/remorse/tests/fixed_map_tests.cpp +++ b/rebuild/remorse/tests/fixed_map_tests.cpp @@ -180,6 +180,11 @@ int main() liveKernel.createProcess(1, liveGroups); } assert(!liveItems.findItem(0x106) && !liveItems.moveItem(0x106, 0, 0, 0)); + const auto originalShape = liveItems.findItem(0x100)->data.shape; + assert(liveItems.setItemShape(0x100, 0x1234)); + assert(liveItems.findItem(0x100)->data.shape == 0x1234 && blockItems[0].data.shape == originalShape); + assert(!liveItems.setItemShape(0x106, 0)); + assert(liveItems.setItemShape(0x100, originalShape)); assert(!liveItems.moveItem(0x100, 0x8000, 0, 0)); assert(liveItems.moveItem(0x100, 768, 511, 81)); assert(liveItems.findItem(0x100)->data.x == 768 && blockItems[0].data.x == 511); diff --git a/rebuild/remorse/tests/flex_archive_tests.cpp b/rebuild/remorse/tests/flex_archive_tests.cpp index 64a41ff..40b4316 100644 --- a/rebuild/remorse/tests/flex_archive_tests.cpp +++ b/rebuild/remorse/tests/flex_archive_tests.cpp @@ -250,14 +250,48 @@ int main() for (int reservedSlot = 0; reservedSlot < 3; ++reservedSlot) { teleporterKernel.createProcess(1, teleporterGroups); } - auto* teleporterProcess = teleporterKernel.createTeleporterProcess(1, 1, 0x1e, teleporterGroups); + bool avatarInStasis = false; + auto* teleporterProcess = teleporterKernel.createTeleporterProcess(1, 1, 0x1e, + teleporterGroups, true, false, avatarInStasis); const remorse::u16 teleporterProcessId = static_cast( teleporterProcess->base.bytes[2] | (static_cast(teleporterProcess->base.bytes[3]) << 8)); + assert(avatarInStasis && teleporterKernel.allocationSizeAt(4) == 0x33 && + teleporterKernel.processAt(4)->bytes[0] == 0x5e && + teleporterKernel.processAt(4)->bytes[1] == 0x0f); assert(!remorse::TeleporterProcess::run(*teleporterProcess, spawnSearchWorld, 2, *typeFlags)); assert(spawnSearchWorld.findItem(1)->data.x == 0 && spawnSearchWorld.findItem(1)->data.y == 0); - assert(remorse::TeleporterProcess::run(*teleporterProcess, spawnSearchWorld, 1, *typeFlags)); - teleporterProcess->base.bytes[0x18] |= 4; - teleporterKernel.terminateProcess(teleporterProcessId, teleporterGroups); + struct TeleporterPassContext { + remorse::ProcessKernel& kernel; + remorse::LiveFixedMapItems& items; + const std::vector& shapes; + remorse::u16 (&groupCounts)[32]; + bool& avatarInStasis; + bool teleported = false; + } teleporterPass{teleporterKernel, spawnSearchWorld, *typeFlags, teleporterGroups, avatarInStasis}; + const auto runTeleporterPass = [](remorse::EntityDispatchEntryBase& entry, void* opaque) { + auto& context = *static_cast(opaque); + const remorse::u16 processId = static_cast(entry.bytes[2] | + (static_cast(entry.bytes[3]) << 8)); + if (processId < 3) return; + const remorse::u16 vtable = static_cast(entry.bytes[0] | + (static_cast(entry.bytes[1]) << 8)); + if (vtable == remorse::ClearAvatarInStasisProcess::vtableOffset) { + assert(context.kernel.runClearAvatarInStasisProcess(processId, + context.avatarInStasis, context.groupCounts)); + } else if (vtable == remorse::TeleporterProcess::vtableOffset) { + const auto& process = *reinterpret_cast(&entry); + context.teleported = remorse::TeleporterProcess::run(process, context.items, 1, + context.shapes); + entry.bytes[0x18] |= 4; + context.kernel.terminateProcess(processId, context.groupCounts); + } + }; + teleporterKernel.scanRunnableProcesses(1, runTeleporterPass, &teleporterPass); + assert(!avatarInStasis && !teleporterPass.teleported && + teleporterKernel.processAt(teleporterProcessId) == &teleporterProcess->base && + spawnSearchWorld.findItem(1)->data.x == 0 && spawnSearchWorld.findItem(1)->data.y == 0); + teleporterKernel.scanRunnableProcesses(1, runTeleporterPass, &teleporterPass); + assert(teleporterPass.teleported); assert(teleporterKernel.processAt(teleporterProcessId) == nullptr && teleporterKernel.allocationSizeAt(teleporterProcessId) == 0 && teleporterGroups[1] == 3); assert(spawnEgg->recordIndex < fixedMap->entries.size());