Refactor USECODE tooling documentation and enhance map-viewer decompiler
- Updated the USECODE Tool Improvement Plan to focus on the map-viewer decompiler/editor, emphasizing its role as the primary development target for USECODE editing and recompilation. - Revised the tooling comparison document to include the newer map-viewer decompiler, clarifying its purpose and distinguishing it from the Python parser. - Introduced a new ClearAvatarInStasisProcessEntry structure in the entity dispatch entry header, along with related process creation and execution logic in the ProcessKernel. - Implemented the setItemShape method in LiveFixedMapItems to allow dynamic shape updates for items. - Enhanced the teleporter process to handle avatar stasis and integrated it into the game main loop, ensuring proper process management and state handling. - Added tests for the new functionality, including shape setting and teleporter process behavior, to ensure correctness and stability.
This commit is contained in:
parent
0771c86043
commit
6d4972933f
17 changed files with 1868 additions and 114 deletions
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue