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.
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.
- 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
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.
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.
for item in nearby_items(shape=0x04D0, origin=arg_06):
```
or:
```text
for candidate in nearby_items(family=6, origin=arg_06):
```
The first target is not full generality. The first target is the set of repeated loop forms already seen in:
-`NPCTRIG`
-`ALARMHAT`
-`ALARMBOX`
-`ALRMTRIG`
- nearby environmental families
### Expected payoff
- much better readability for object-searching scripts
- better gameplay interpretation of trigger/controller classes
- a cleaner path to naming common search idioms
## Priority 3: Better intrinsic naming and signatures
### What to borrow
From Pentagram and `crusader-disasm`:
- historical intrinsic names
- text-mined call arities and stack cleanup behavior
- rough prototype guesses from the older corpus tools
### Why it matters
Readable pseudocode is bottlenecked less by control flow now and more by anonymous calls like `Intrinsic0007()` or generic placeholders like `class_0A18_slot_20(...)`.
The older tool lines already contain partial information that can improve this materially, as long as it is treated as hint-quality evidence rather than rename authority.
### Concrete change
Build a local intrinsic metadata table with confidence levels:
-`verified`
-`strong hint`
-`weak hint`
Populate it from:
- Pentagram tables
-`usecode_opcodes.txt`
- mined `calli`/`add sp` patterns from `crusader_disasm.txt`
- current repo notes where compiled-side names are already justified
### Expected payoff
- more readable pseudocode
- safer future promotion of intrinsic names
- less confusion between Remorse-only, Regret-only, and cross-game vocabulary
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.
- fewer false positives when mining repeated code bodies
## Priority 5: Corpus-level pattern clustering
### What to borrow
From the `crusader-disasm` corpus mindset:
- treat the full body set as a searchable evidence base, not only as isolated scripts
### Why it matters
The JELYHACK result was only obvious after repeated-body comparison showed it was a small shared stub. The same strategy can keep the decompiler honest elsewhere.
### Concrete change
Add corpus analysis helpers that cluster or index:
- exact repeated bodies
- normalized repeated bodies
- repeated loop-selector templates
- repeated spawn/call templates by class and slot
Those results should feed back into readable annotations like:
-`shared interaction stub`
-`alarm-family controller template`
-`common trigger setup pattern`
### Expected payoff
- faster triage of interesting scripts
- better distinction between generic templates and unique gameplay logic
- fewer overinterpretations of tiny bodies
## Priority 6: Stronger runtime bridge and import path
### What to borrow
From the local repo workflow rather than directly from Pentagram:
- the current runtime anchors already recorded in `runtime_vm_ir.tsv`
- the Ghidra-side annotation path planned in the USECODE notes
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.
- 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.
## Current best next step
The most leverage is in loop-selector decoding.
That is the place where the older tools still give us directly reusable structure and where the current readable output most obviously needs another step forward.