# Pentagram-Derived USECODE Parser And Ghidra Path
## Purpose
This note turns the earlier feasibility assessment into a concrete workflow.
The goal is not to make Ghidra decompile Crusader USECODE as if it were x86 immediately. The goal is to build one trustworthy bridge layer first:
- reuse Pentagram's Crusader opcode decoding where it is still valid
- 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
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.
- the opcode tokenization model from `convert/Convert.h`
- the disassembly-oriented mnemonic layout from `tools/disasm/Disasm.cpp`
- the Crusader event ordinal table from `convert/crusader/ConvertUsecodeCrusader.h`
Useful only as hints:
- intrinsic names and signatures
- old event-name labels for still-unresolved higher ordinals
Not safe to reuse unchanged:
- Pentagram's Crusader header reader
- any assumption that its old `maxOffset` / `externTable` / `fixupTable` structure matches the owner-loaded EUSECODE class bodies now validated in the extractor and DOS binary
- the partial Node-based decompiler path as if it were a general Crusader decompiler
## Verified Local Model To Use Instead
The proof-of-concept parser should be grounded in the existing local artifacts, not in Pentagram's old header logic.
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.
`POC USECODE body anchor: NPCTRIG slot 0x0A -> body 0x00DA..0x024F, raw word 0x013E, 5 local/debug rows after ret, parsed via tools/poc_crusader_usecode_parser.py`