158 lines
18 KiB
Markdown
158 lines
18 KiB
Markdown
|
|
# Japanese No Remorse USECODE Debugger Feasibility
|
||
|
|
|
||
|
|
**Status:** Static feasibility assessment; no executable bytes changed
|
||
|
|
**Target:** Japanese Win32 `/ja/CRUSADER.EXE` in the active Ghidra project
|
||
|
|
**Reviewed:** 2026-10-11
|
||
|
|
|
||
|
|
## Executive Assessment
|
||
|
|
|
||
|
|
Adding a useful USECODE debugger to the Japanese build is technically feasible, but it is a JP-specific port or extension, not a hidden feature that can be switched on by copying the No Regret bootstrapper. The Japanese executable has ordinary USECODE execution and some useful metadata, but the recovered image does not contain the classic debugger's break-state object, interpreter record lifecycle, UI, or debugger event handlers.
|
||
|
|
|
||
|
|
The practical ratings are:
|
||
|
|
|
||
|
|
| Approach | Feasibility | Assessment |
|
||
|
|
|---|---|---|
|
||
|
|
| Copy DOS No Remorse/No Regret debugger machine code into the JP PE | Very low | The sources are 16-bit DOS NE programs; JP is a flat 32-bit Win32 PE. Segmented pointers, calling conventions, allocators, file access, and the UI framework do not match. This is not a binary transplant. |
|
||
|
|
| Use the existing Windows native debugger on the JP process | High for machine-code debugging | Ghidra/x32dbg can stop and inspect native instructions, including the USECODE interpreter. This does not provide USECODE line breakpoints, unit-aware frames, watches, or a game debugger UI. |
|
||
|
|
| Build a small JP trace/break prototype | Feasible, moderate | Add or externally orchestrate hooks at interpreter boundaries; begin with current unit/event, bytecode offset, opcode, and stop/continue. This is the recommended first implementation target. |
|
||
|
|
| Port the complete in-game debugger | Feasible in principle, high effort and risk | Requires a new JP runtime-state layer, validated source mapping, break/step integration, watch semantics, and a UI path. No plugin ABI or existing JP debugger frontend has been recovered. |
|
||
|
|
|
||
|
|
**Recommendation:** time-box a runtime instrumentation spike before writing a full debugger. Prove that a real JP interpreter invocation can be identified, paused at a stable bytecode boundary, resumed without state corruption, and associated with its live unit/event/frame. Use an external controller first; add an in-game UI only after that contract is demonstrated.
|
||
|
|
|
||
|
|
## What The JP Executable Has
|
||
|
|
|
||
|
|
The active Ghidra project reports the open domain file as `/ja/CRUSADER.EXE`; the image is the flat Win32 build, not either DOS NE executable. The existing JP investigation records its PE image base as `0x00400000` and its SHA-256 as `037b7d2be829048a1b305eae15e7f78be72329af80425cc32e2f5fcee0ba5231`. Keep any future patcher tied to that exact build fingerprint.
|
||
|
|
|
||
|
|
USECODE runs through `UsecodeProcess_Create` (`004671b0`), `UsecodeProcess_Run` (`00467304`), and the large opcode dispatcher `UsecodeProcess_NextOpcode` (`0042ddc8`). The process factory installs the ordinary process callback table; the recovered table does not expose a debugger callback or break-state global.
|
||
|
|
|
||
|
|
### Process Lifecycle And Spawn Paths (2026-10-11)
|
||
|
|
|
||
|
|
The primary process callback entries at `004803d4` cover ordinary scheduling and lifecycle work. `UsecodeProcess_Run` (`00467304`) is the run slot; `00458980` and `00458990` are termination callbacks. `004680f0` performs cleanup, `00467360` releases a value for an incomplete process, `00467448` restores process state, `00467380` serializes it, and `004672fc` is a thunk that returns the process resource at `+0x34`. The `00467448` and `00467380` callbacks use shared Windows file helpers `004262f8` (`ReadFile`) and `0042637c` (`WriteFile`), rebuilding runtime pointers around the instruction cursor and stack/frame fields. `004059d0` and `004059e0` are one-byte `RET` stubs.
|
||
|
|
|
||
|
|
The word at `004803fc` (`00466de0`) begins a resource-object vtable used by `FUN_00466d60`, which installs `004803fc` as that object's vptr; `00466de0` is its destructor/release path. The following pointer at `00480400` (`0046a940`) is not another confirmed process callback. It is referenced as adjacent type/registration data from `0046eb7b`, and `0046a940` itself is constructor-like: it allocates and initializes a separate `0x11e`-sized object. The exact descriptor format and object's role remain open. None of the confirmed process lifecycle paths tests a source line or breakpoint.
|
||
|
|
|
||
|
|
The dispatcher retains both process-spawn opcodes. Token-name pointer slots map `T_SPAWN` to opcode `0x57` and `T_SPAWN_INLINE` to `0x58`; their dispatcher cases at `0042feaf` and `0042ffce` each call `UsecodeProcess_Create` (`004671b0`). A third creation path, now named `usecode_start_event_process_if_enabled` (`004670b0`), resolves a unit/event, checks its event mask, and creates a process for eligible events. `item_create_from_shape_id` calls it for shape-dependent initialization events. This confirms that ordinary event dispatch and nested/child process creation survive, not debugger stepping or a debugger-owned child-context stack.
|
||
|
|
|
||
|
|
The JP dispatcher retains two USECODE metadata opcodes, but their recovered handlers do not implement debugger control:
|
||
|
|
|
||
|
|
- Opcode `0x5b` (`T_LINE_NUMBER`, token pointer at `0047b900`, name at `00480e94`) is handled at `0042dfaa`. It advances the USECODE cursor by two operand bytes and returns to dispatch; it does not retain the line value, update a current-line field, or test a breakpoint. A new hook could capture the operand, but its mapping to display rows is not verified.
|
||
|
|
- Opcode `0x5c` (`T_SYMBOL_INFO`, token pointer at `0047b904`, name at `00480ea2`) is handled at `0042dfbd`. It skips a two-byte field and a nine-byte inline name record. When `DAT_00482ad0` is nonzero, it sends the name to the shared output helper (`00445520`) using `"<%s>\n"`; it does not push a debugger current-entry record or preserve a frame for inspection.
|
||
|
|
- The same `DAT_00482ad0` condition gates generic opcode-name output at `0042dea3`, using the token-name table. The current data-use scan found these reads but no writer. This is trace-style output, not an interactive debugger surface.
|
||
|
|
|
||
|
|
These handlers are useful hook locations because they expose a line operand and symbol activity during normal interpretation. They do not establish a complete source map or retain the state needed for source-level stops, stepping, watches, or frame inspection. The separate `T_SUSPEND` runtime operation is not connected to the line-number handler in the recovered path.
|
||
|
|
|
||
|
|
### Line-Related String Matches That Are Not USECODE Debugging
|
||
|
|
|
||
|
|
The broad string search also found halt/error text, but its references lead to the media-player error path rather than the USECODE VM:
|
||
|
|
|
||
|
|
- `"Halted file %s\\nline %d"` (`00425230`) and `"Halted file %s\\nline %d\\n%s"` (`00425247`) are used by `00425050` and `00425084`. These are one-shot fatal-report handlers that call the message formatter and then `win32_shutdown_message_loop`.
|
||
|
|
- `"player halted on line %d"` (`00457060`) is passed by `004562f8` with source label `player.h` and line `0x1e`. `"Error in %s, line %ld. %s\\n"` (`00457082`) is used by `00454f08`, whose surrounding code parses RIFF/AVI chunks. These are media-player diagnostics, not USECODE line stops.
|
||
|
|
|
||
|
|
They are recorded here to prevent interpreting a text match for “halted” or “line” as evidence of a USECODE debugger.
|
||
|
|
|
||
|
|
## What Is Missing
|
||
|
|
|
||
|
|
The JP function and string searches found no classic debugger function family or characteristic prompt bundle. In particular, the following pieces recovered in the DOS builds have no JP equivalent in the analyzed path:
|
||
|
|
|
||
|
|
- A break-state object with breakpoint slots, current line, step flags, and a current-entry stack.
|
||
|
|
- Interpreter-side line update, current-entry push/copy, and return/unwind operations.
|
||
|
|
- A debugger-owned UI/event subsystem for source display, breakpoints, watches, inspection, and global editing.
|
||
|
|
- A bootstrap that allocates and publishes debugger state, and a callback that opens the UI when a break condition fires.
|
||
|
|
|
||
|
|
The absence is bounded evidence, not proof that no encoded or dynamically registered helper exists. The stronger finding is behavioral: the known JP process and opcode paths do not perform the classic break-state lifecycle.
|
||
|
|
|
||
|
|
### UI Surface Search (2026-10-11)
|
||
|
|
|
||
|
|
The active `/ja/CRUSADER.EXE` program was searched again for both debugger-specific UI and ordinary game UI markers. This separates two questions that should not be conflated:
|
||
|
|
|
||
|
|
- **Classic USECODE debugger/editor UI:** no debugger menus, source/watch panes, or debugger command surface were recovered.
|
||
|
|
- **Ordinary game UI:** the JP executable still contains generic Gump and event-dispatch infrastructure. Its presence does not establish that a debugger UI survived.
|
||
|
|
|
||
|
|
The targeted function-name searches for `usecode`, `gump`, `NewGump`, `dialog`, `menu`, `conversation`, `speech`, and `intrinsic` returned only the known general USECODE functions for the `usecode` query (`UsecodeProcess_Create`, `UsecodeProcess_NextOpcode`, `UsecodeProcess_Run`, `Usecode_FreeList`, `Usecode_FreeVal`, and `usecode_reference_table_decrement_refcount`). The other queries returned no named functions. This is bounded by current Ghidra function names; it does not classify every unnamed function.
|
||
|
|
|
||
|
|
Targeted decoded-string searches returned no matches for the classic debugger vocabulary: `Watch what?`, `Inspect what?`, `Goto Line`, `Breakpoints`, `Global name`, `Search for`, `FILE NOT FOUND`, `step`, `break`, and `source`. The `debug` search returned only `Debugging mode ON.\n\r` at `00466af9`, `-debug` at `004811d2`, and the imported `DebugBreak` name at `00496734`. The `usecode` search returned `usecode` at `0047be40` and `eusecode.flx` at `0047be90`.
|
||
|
|
|
||
|
|
There is positive evidence for generic game UI, not for the debugger frontend:
|
||
|
|
|
||
|
|
- `GUMPS.FLX` occurs at `00466a9b`; `.\\gumpshap.c` and `.\\newgump.c` source markers and `Bad NewGumpId [%04X]` occur in the executable.
|
||
|
|
- The `Bad NewGumpId` diagnostic is referenced by `FUN_0044cb44` and `FUN_0044d614`, called from the broader `FUN_0041ccc8` dispatch path. The recovered code traverses and validates generic Gump objects; it is not a debugger-owned menu or pane.
|
||
|
|
- The only `dialog` string-filter hits were imported Windows APIs `DialogBoxParamA` and `EndDialog`, not debugger prompts. The presence of those imports alone does not identify a game debugger UI.
|
||
|
|
|
||
|
|
**Conclusion:** it is not accurate to say that the JP executable has no UI or no Gump code. It is accurate, with the current search coverage, to say that no classic USECODE debugger/editor UI has been found. This pass did not prove which JP USECODE intrinsics can invoke ordinary Gump/dialog UI, and it does not rule out encoded/localized or unnamed debugger remnants. The opcode `0x5b`/`0x5c` behavior remains the stronger functional evidence that the classic debugger lifecycle is absent from the recovered JP interpreter path.
|
||
|
|
|
||
|
|
### Source and support files
|
||
|
|
|
||
|
|
The inspected Japanese `USECODE` directory contains `JUSECODE.FLX` and `UNKDS.DAT`; the scan found no loose per-unit `.unk` files. `UNKDS.DAT` is 66 bytes in this installation. Its internal role remains unresolved, and the recovered older debugger path opens it separately from the source viewer. It is not the per-unit text listing expected by the classic debugger.
|
||
|
|
|
||
|
|
The classic source pane constructs `<unit>.unk`, loads it as line-oriented text, and indexes its lines. Even if a debugger frontend were ported, the JP build would need either authentic JP listings or generated JP-specific display files. Western Remorse/Regret generated listings cannot be assumed to match JP names, bytecode, or line semantics. A source file improves display and navigation; it does not create executable state or make `RUN` interpret that text.
|
||
|
|
|
||
|
|
## Why The No Regret Bootstrap Does Not Solve This
|
||
|
|
|
||
|
|
No Regret is a useful behavioral reference, not a plug-in component. Its recovered `usecode_debugger_bootstrap_init` (`1398:0000`) allocates support objects, creates a break-state object, stores it in `1480:712c/712e`, and replaces the base vtable with a frontend-aware vtable. Its interpreter hook also contains the line, current-entry, child-context, and unwind handlers.
|
||
|
|
|
||
|
|
However, the bootstrap has no recovered normal caller. In the tested ordinary session, the debugger global remained null. A statically present writer is not proof that startup executes it. Separately, forcing the modal UI or loading a generated `.unk` does not synthesize a valid current interpreter entry: the debugger's `RUN` command resumes the live interpreter rather than executing the displayed text, and an invalid/missing current-entry record can still crash the path.
|
||
|
|
|
||
|
|
That distinction is even more important for JP. The JP build is not just missing No Regret's bootstrap call; its recovered interpreter handlers do not implement the producer/consumer lifecycle that bootstrap expects. Porting only the constructor would create state that JP's VM never updates.
|
||
|
|
|
||
|
|
## Implementation Choices
|
||
|
|
|
||
|
|
### 1. Native process debugging
|
||
|
|
|
||
|
|
Use Ghidra's native debugger or x32dbg to break in `UsecodeProcess_NextOpcode`, inspect the process/context objects, and follow the `0x5b`/`0x5c` paths. This is the lowest-risk way to discover live unit, event, cursor, and frame fields. It provides machine-level debugging and is a prerequisite for the options below, not USECODE source-level parity.
|
||
|
|
|
||
|
|
### 2. JP trace and controlled break prototype
|
||
|
|
|
||
|
|
Add the smallest possible interpreter instrumentation, or drive equivalent breakpoints from an external controller. Record at least process identity, unit/class, event, bytecode offset, opcode, and the `0x5b` operand where present. Add stop/continue at an instruction boundary only after confirming register, stack, and scheduler behavior at that point.
|
||
|
|
|
||
|
|
Keep the first controller outside the game's UI. This avoids having to recreate the DOS Gump interface before the VM state contract is known. A later UI can present the trace and break controls over a local IPC or debugger-agent connection.
|
||
|
|
|
||
|
|
### 3. Full JP in-game debugger
|
||
|
|
|
||
|
|
A full port would need JP-native implementations for:
|
||
|
|
|
||
|
|
1. A debugger session object and safe lifecycle attached to each active USECODE process/context.
|
||
|
|
2. Unit/event identity and a balanced frame stack across calls, child processes, returns, suspension, and resumption.
|
||
|
|
3. Line/bytecode mapping, breakpoints, break-next, single-step, step-over, and resume semantics.
|
||
|
|
4. A source/listing loader and JP-specific generated or authentic per-unit listings.
|
||
|
|
5. Watch/inspect expression evaluation over JP values, frames, globals, and intrinsic results.
|
||
|
|
6. A frontend built on the JP UI framework or an external debugger window, plus a safe bridge to the emulation/game thread.
|
||
|
|
|
||
|
|
Do not begin with watch/inspect or a full UI. Those features depend on runtime value ownership and descriptor semantics, which the current JP evidence does not close.
|
||
|
|
|
||
|
|
## Binary Modification Constraints
|
||
|
|
|
||
|
|
JP's flat PE layout is easier to reason about than the DOS NE segment/fixup model, but that does not make arbitrary injection safe. No general plugin ABI or JP-specific patcher is established. Existing DOS NE patch definitions and offsets are inapplicable.
|
||
|
|
|
||
|
|
Any actual code experiment should use a separate writable copy of the fingerprinted JP executable, preserve the original file, and be reversible. A detour must preserve the original instruction boundaries, registers, flags, stack state, and execution timing. Prefer an external debugger breakpoint for the initial runtime investigation. Do not patch or save changes into the currently loaded reference executable or Ghidra program.
|
||
|
|
|
||
|
|
## Recommended Spike And Gates
|
||
|
|
|
||
|
|
Start with a bounded 1-2 week investigation, not a full feature commitment:
|
||
|
|
|
||
|
|
1. Attach to an unmodified JP game and capture one real USECODE event through `UsecodeProcess_NextOpcode`; identify the active unit/event, process object, source cursor, and frame/value context.
|
||
|
|
2. Trace the `0x5b` and `0x5c` cases on real data. Establish what their operands mean in JP and whether unit names and offsets can be associated with a class/event listing.
|
||
|
|
3. Set an external native breakpoint at a chosen opcode boundary, resume the game, and verify that the same process continues correctly. Check nested calls and at least one return/yield transition before claiming reliable stepping.
|
||
|
|
4. Generate a JP-specific listing only after source identity and line-offset rules are established. Label synthetic rows as synthetic; do not imply original source-line fidelity.
|
||
|
|
5. Decide whether the first usable debugger is an external trace/break UI or a game-integrated frontend. Estimate the full port only after the runtime snapshot and mapping gates pass.
|
||
|
|
|
||
|
|
### Go/no-go criteria
|
||
|
|
|
||
|
|
Proceed toward a source-aware debugger if the spike can reliably recover a live unit/event/bytecode position, stop and resume without corrupting scheduler state, and maintain a coherent frame across nested execution. If the line operand or symbol metadata is not sufficient for source mapping, a bytecode-offset debugger is still viable, but should be scoped and named accordingly.
|
||
|
|
|
||
|
|
Treat watches, global editing, and source-line breakpoints as later milestones. They require validated JP frame/value semantics and should not be advertised based only on the DOS debugger's menu behavior.
|
||
|
|
|
||
|
|
## Evidence And Limits
|
||
|
|
|
||
|
|
This assessment combines the active Ghidra target check, a live disassembly of `0042df90..0042e020`, the 2026-10-11 targeted function-name/string/UI-resource search, and the existing JP debugger, dispatch, USECODE-resource, No Regret, and `.unk` investigations listed below. Program bytes were not changed. No live JP game session was captured for this assessment, so pause/resume behavior, runtime frame fields, loader behavior for generated JP listings, and the meaning of `UNKDS.DAT` remain open.
|
||
|
|
|
||
|
|
The negative function/string searches do not prove absolute absence. They do show that the currently recovered JP interpreter/runtime does not contain the classic debugger lifecycle. The feasibility conclusion is therefore: **a JP-specific debugger extension is possible; direct reuse of the DOS debugger is not; first prove the live VM state contract before committing to a complete UI or watch system.**
|
||
|
|
|
||
|
|
## Related Investigations
|
||
|
|
|
||
|
|
- [Japanese hidden debugger investigation](jp-remorse-hidden-debugger-investigation.md)
|
||
|
|
- [Japanese USECODE dispatch analysis](usecode-jp-dispatch-analysis.md)
|
||
|
|
- [Japanese Windows debugging](jp-remorse-windows-debugging.md)
|
||
|
|
- [Japanese Windows modding feasibility](jp-remorse-windows-modding-feasibility.md)
|
||
|
|
- [No Regret hidden debugger investigation](regret-hidden-debugger-investigation.md)
|
||
|
|
- [USECODE `.unk` format](usecode-unk-format.md)
|
||
|
|
- [Standalone USECODE debugger proposal](standalone-usecode-debugger.md)
|