Crusader_Decomp/docs/rebuild-sharp/remorse-csharp-sdl3-rebuild-feasibility.md
Marco c956923bcd Add feasibility study for C# and SDL3 Crusader rebuild
- Document the technical feasibility of rebuilding Crusader using C#, .NET 10, and SDL3.
- Outline the executive summary, platform assessment, recommended architecture, and delivery plan.
- Define mod support and creator workflow, including debugging scope and principal risks.
- Establish clear milestones and gates for project phases, from technical spike to No Regret integration.
2026-10-12 17:27:19 +02:00

25 KiB

C# and SDL3 Crusader Rebuild Feasibility

  • Status: Feasibility study
  • Reviewed: 2026-10-12
  • Target: New cross-platform rebuild using C#, .NET 10, and SDL3
  • Release order: No Remorse first; No Regret after the first game is established

Executive Summary

A new Crusader rebuild in C# on .NET 10 with SDL3 is technically feasible for desktop Windows, Linux, and macOS. The retail data can remain user-provided input; the project can ship parsers, runtime code, tools, and original documentation without distributing game assets.

The main risk is not .NET or SDL3. It is the size of the game-runtime reconstruction and the distance between static analysis and verified behavior. The current live Ghidra project is the primary reverse-engineering authority and has nearly complete function coverage for No Remorse. Its current function bodies, disassembly, references, symbols, and data types should drive the implementation inventory. The older exported C is a secondary snapshot, not the source of truth. High function coverage does not mean every function's behavior is fully understood or runtime-verified. The new project should be an evidence-led C# implementation, not a mechanical translation of the old export.

Mod support is feasible, but it is several connected deliverables: a version-aware retail data loader, validated override/package system, mission entry and transition model, lossless asset tools, a USECODE authoring/rebuild path, and an integrated debugger. Loading replacement files is much easier than offering an author-friendly workflow for editing individual archive entries and creating new missions.

Recommendation: proceed with a short technical spike, then build a No Remorse vertical slice around a managed simulation core and a replaceable SDL3 host. Design the USECODE VM and debugger together from the start. Treat full No Remorse campaign coverage and creator-grade mission/script tools as separate acceptance gates. Add No Regret only after the shared runtime has variant boundaries and test fixtures in place.

What “Support” Should Mean

The name “No Remorse support” can describe very different products. Track these separately:

Level Meaning Feasibility
Data inspection Detect a supported retail install, parse archives, inspect/render maps and shapes High; good first proof of platform and format work
Playable vertical slice Start a retail scenario, run the real host simulation, move, interact through USECODE, and show resulting world changes Feasible; medium-to-high effort
Retail game support Menus, maps, processes, combat, inventory, scripted progression, saves, sound, movies, and campaign transitions Feasible as a long project; not established by a map viewer or one working mission
Mod-capable release Package and validate custom missions, graphics, and USECODE with clear compatibility and save rules Feasible, but requires authoring and packaging tools beyond runtime loaders

The first macro milestone should name which level is meant by “No Remorse support.” This study assumes the goal is a playable retail No Remorse game plus a documented initial mod workflow, not pixel-perfect DOS reproduction or an immediate full editor suite.

Evidence Baseline

The current repository provides a strong research base, but it is not a completed C# game engine. Use this evidence hierarchy for reverse-engineering decisions:

  • Primary static reference: the live Ghidra project for the exact target build. Inspect the active program's function body, disassembly, decompilation, callers/callees, xrefs, symbols, data types, and comments. The current project has nearly complete No Remorse function coverage, making it the best source for defining the implementation inventory. Confirm that the active Ghidra program matches the retail executable/data variant under study before carrying evidence into code.
  • Behavioral check: controlled runtime evidence. Use repeatable game traces and tests to challenge static interpretations, especially for indirect calls, scheduler timing, stateful scripts, and paths whose decompilation is ambiguous. Function presence or a descriptive name is not proof of complete semantics.
  • Secondary reference: the older exported C snapshot. It reports 2,984 function files, 9 fallback function files, 57 global buckets, and 15,403 global definitions, but is stale relative to ongoing live Ghidra analysis. Use it for navigation, historical comparison, and bulk text search. When it conflicts with the current database, re-check the function in live Ghidra; do not treat the old export as authoritative behavior. Its generated types, segmented-pointer expressions, calling conventions, and other artifacts also require interpretation before reuse. See the Windows rebuild roadmap.
  • Comparative references: existing decompilation notes and other implementations. Use these to find hypotheses and cross-check formats, not to overrule the current target's Ghidra evidence.
  • The existing rebuild is a C++/MSVC diagnostic and partial-port scaffold. Its current map-1 start and interaction evidence includes host-modeled paths; the roadmap explicitly records that original startup, scheduler, dispatcher, and presentation paths remain incomplete. A new C# solution should reuse the research and test cases, not count that scaffold as already-portable gameplay code.
  • The data set is usefully decomposed. The known retail files include FIXED.DAT, GLOB.FLX, SHAPES.FLX, GAMEPAL.PAL, ANIM.DAT, TYPEFLAG.DAT, EUSECODE.FLX, fonts, gumps, NPC tables, damage data, sound, and speech. FLEX archives and 16-byte fixed-map records have concrete parser footholds. See the ScummVM Crusader reference and map-rendering notes.
  • Normal No Remorse new-game startup selects map 1 and egg 0x1e in executable code. A custom map alone will not create a selectable mission; the rebuild needs its own explicit mission-entry contract. See first mission map selection.
  • USECODE is an event-driven VM coupled to the executable's variant-specific intrinsic table and current game state. The local archive/event interpretation still has an unresolved disagreement with ScummVM/Pentagram, and unknown record bytes must be preserved. Remorse and Regret intrinsic ordinals cannot be shared by assumption. See the USECODE format specification.
  • The retail Remorse debugger has substantial UI and break-state code, but the current evidence finds no normal writer/bootstrap for its debugger-state pointer. Regret retains stronger static bootstrap wiring, though runtime reachability remains to be confirmed. The new project should create a debugger over its own VM state rather than copy DOS far-pointer objects or rely on either retail debugger's activation path. See retail debugger entry options, break-state layout, and Regret debugger investigation.

Ghidra is the primary authority for static executable structure and the source of the port inventory, but names and decompiled bodies still carry different confidence levels. Keep the Ghidra program/build identity, address, evidence type (decompilation, disassembly, xref, or data/type analysis), confidence, and runtime-test status attached to each ported behavior. When an old export or external implementation disagrees, resolve the discrepancy against the active Ghidra target and record the result.

Platform and Runtime Assessment

.NET 10 and C#

.NET 10 is a reasonable base for a new desktop application targeting Windows, Linux, and macOS. Managed code is well suited to binary readers, validators, mod tooling, debugger models, and the large amount of stateful game logic. The core can use explicit fixed-width types and checked binary reads without inheriting the original segmented-memory model everywhere.

The project should preserve original widths where behavior depends on them, but represent runtime references as typed host identities rather than emulated far pointers unless a specific compatibility test requires the original representation. Use deterministic fixed simulation ticks; keep rendering time and wall-clock time separate. Avoid allocations in measured hot loops, but do not introduce unsafe code or manual memory management before profiling demonstrates a need.

Target desktop platforms first. Browser, mobile, consoles, and arbitrary CPU architectures are not automatic consequences of using .NET and SDL3. Native library packaging, filesystem case sensitivity, window/input differences, audio devices, and release signing still need platform-specific validation.

SDL3

SDL3 is a suitable host layer for windows, display, keyboard/gamepad input, audio output, timers, and presentation. It does not provide Crusader's map model, palette semantics, shape decoding, sprite ordering, USECODE VM, or mission system. Those remain project-owned and should be independent of SDL APIs.

The main technical spike should select and validate the C# binding and its native-library packaging on each intended desktop platform. Keep the binding behind a small platform interface so a binding update or host change does not touch game logic. Begin with a deterministic CPU-rendered palette path as the correctness reference; use SDL textures for presentation and only move palette expansion or composition to GPU shaders after image tests and profiling.

Keep these boundaries explicit in the solution, whether they become separate assemblies immediately or later:

Boundary Responsibilities
Game core Fixed-tick simulation, game state, item/process model, collision, mission state, deterministic event delivery; no SDL or OS calls
Content and formats Retail-version profiles, FLEX/raw archive readers, map/glob/shape/palette/metadata readers, bounds validation, lossless unknown-byte preservation
USECODE runtime Bytecode decoder, value model, call/event frames, variant-specific intrinsic registry, trace hooks, error reporting
SDL host Window, input mapping, audio device, frame presentation, host clock, user data paths
Presentation and camera Expanded viewport, zoom, world/screen transforms, and optional camera interpolation; no simulation-state mutation
Debugger Pause/step/breakpoint state, VM inspection model, source/disassembly panes, trace and intrinsic-call views
Mod and creator tools Manifest validation, archive inspection/rebuild, map and asset import/export, mission packaging, compatibility diagnostics

Define No Remorse and No Regret as explicit game profiles over shared systems. Profiles should own their accepted executable/data fingerprints, language/build identifiers, mission tables, global initialization, USECODE intrinsic maps, and known data differences. Do not scatter variant checks through generic parsers or let shared naming imply shared behavior.

Retail data roots should be opened read-only. Saves, caches, crash logs, extracted working files, and generated mods should go to separate user-selected or per-user writable locations. Tests should use synthetic fixtures by default, with opt-in local retail regressions; no retail data should be required to build the code or included in releases.

Optional Camera and Viewport Features

The checked-out ScummVM tree provides a concrete smooth-camera proof of concept: its smooth_camera option is registered in metaengine.cpp, selected by SnapProcess, and applied as elapsed-time easing in CameraProcess. Use it as behavioral evidence and a design reference, not as code to transplant across engine boundaries.

  • Expanded, zoomable viewport: support rendering a larger world area at high-resolution display sizes, with user-controlled zoom. ScummVM provides the expanded high-resolution viewport, but not zoom; zoom is new rebuild work. Treat expanded viewport coverage and zoom as distinct from higher-resolution source art. Keep the transform in presentation, preserve the indexed/palette rendering path, and test clipping, screen-to-world input conversion, and target selection at multiple viewport sizes and zoom levels. A view change must not change simulation coordinates or silently widen gameplay interaction rules.
  • Optional smooth camera lerping: retain the No Remorse snap/parity behavior as the default and offer time-based interpolation as an opt-in presentation setting. Interpolate camera state between simulation snapshots without changing fixed ticks, actor position, collision, or process scheduling. Snap or reset interpolation on map changes, teleports, and other discontinuities; test different render rates, pauses, edge clamping, and scripted camera moves.

Build the viewport transform with the renderer. Add smooth following when the playable movement slice has a verified camera target. Keep both features behind independent settings so expanded/zoomed viewing does not require smooth following.

Mod and Creator Workflow

Build mod support as a versioned content contract, not a directory scan with undocumented precedence. A package manifest should identify at least the mod ID/version, game and retail build, language, required files, entry mission, resource overrides, dependencies/conflicts, and a content hash. Mount order must be deterministic, and diagnostics must report which mod supplied each resolved resource.

Deliver mod capabilities in increasing order of risk:

  1. Validate a retail data root and inspect resolved files without modifying it.
  2. Allow complete-file replacement through loose files or a package, with explicit override order. Initially state clearly that this is replacement, not per-entry archive merging.
  3. Add map-level fixed/glob export and rebuild with a small custom-map launch route. Preserve unknown fields and reject invalid references before the game starts.
  4. Add shape/frame extraction and re-import, with palette and offset preservation and pixel-level round-trip tests.
  5. Add a USECODE source/bytecode authoring path only after unchanged archive round-trips are byte-identical and edited archives pass structural and runtime checks.
  6. Add mission packages that declare their starting map/egg or coordinates, transitions, required resources/scripts, and save compatibility identity.

The first custom mission should be a deliberately small test scenario that exercises a spawn, one transition, one custom graphic, and one USECODE-backed interaction. It should run without replacing the user's retail installation and produce actionable validation errors when files or references are missing.

Custom USECODE should be limited to the game VM's supported operations and each variant's registered intrinsics. A mod script cannot invent a native function that the engine does not implement. New engine capabilities belong in reviewed engine releases, not executable plug-ins supplied by content packages.

USECODE Debugger Scope

Implement the debugger model alongside the interpreter, even if the full UI arrives later. The first debugger should provide:

  • break, continue, instruction-step, step-over, and step-out at interpreter instruction boundaries;
  • breakpoints keyed by game profile, class/unit, event slot, and bytecode offset, with source-line breakpoints only when a reliable mapping exists;
  • current unit/event/PC, nested call and process frames, evaluation stack, locals/globals where their types are understood, and intrinsic-call arguments/results;
  • a trace of world-state mutations and a way to copy a deterministic execution trace into a regression fixture;
  • explicit unsupported-opcode, unavailable-source, and invalid-frame diagnostics rather than guessed values.

Remorse line-number bytecode metadata currently offers a stronger source-mapping basis than the inspected Regret corpus, which has no recovered LINE_NUMBER operations. The retail .unk file is a text sidecar for display, not executable source; generated Regret line rows must be marked synthetic. Watches and expression evaluation should wait until frame ownership, descriptors, and value lifetimes are proven. See the .unk format investigation.

Delivery Plan and Gates

Phase 0: Technical Spike

Validate the C# SDL3 binding and native deployment on Windows and at least one non-Windows desktop target. Read a user-selected retail data root without writes, parse a FLEX archive and a map, decode a small set of shapes, render a deterministic image, and exercise input/timing through the SDL host. Establish a versioned test fixture and a Ghidra-address-to-behavior evidence record.

Gate: the same managed core and scene tests run on both targets; retail files remain unchanged; the platform boundary contains all SDL calls. If binding packaging is painful, resolve that before building runtime systems on top of it.

Phase 1: No Remorse Data and Runtime Foundation

Implement validated format readers, palette/frame decoding, map/glob loading, the render-order path, fixed simulation tick, game-state ownership, and structured logging. Add format fixtures and image comparison tests. Keep any static-map preview labeled as a diagnostic, not gameplay.

Gate: a selected No Remorse retail profile loads known maps repeatedly, reports bad references safely, and produces stable images across supported hosts.

Phase 2: No Remorse Playable Slice

Port the smallest end-to-end behavior chain from the evidence: startup/spawn, actor ownership, input, scheduler tick, visible movement, item interaction, USECODE dispatch, and a world mutation. Build the VM trace and pause/step hooks during this phase so behavior is inspectable while it is being implemented.

Gate: a deterministic integration test drives a retail scenario through normal runtime paths and verifies state before/after interaction as well as rendered output. A host-only shortcut does not satisfy this gate.

Optional presentation gate: the renderer can expand and zoom the viewport without changing simulation or input semantics. After camera tracking is established, the user can enable smooth camera interpolation; tests verify stable behavior at different render rates and snapping across discontinuities. These options do not block the playable-slice gate.

Phase 3: Integrated Debugger and First Mod Layer

Add the debugger UI over the managed VM state and a manifest-based virtual resource layer. Start with whole-file replacements, deterministic precedence, mod ownership diagnostics, and a no-write validation command. Use the same debugger stepping and traces in automated tests.

Gate: a user can pause at a known Remorse instruction, step through a nested call, inspect supported state, and identify the exact mod/resource selected at runtime.

Phase 4: Custom Maps, Graphics, and Missions

Build map and shape round-trip tools, custom mission launch/transition metadata, and save compatibility checks. Add small authoring fixtures and test them both offline and in the game runtime. Keep generated files separate from retail inputs.

Gate: a packaged custom test mission starts, transitions, saves and reloads with the same mod set, and has one custom map element and one script-backed interaction.

Phase 5: No Remorse Retail Coverage and Release Hardening

Expand game flow, combat, inventory, NPC behavior, audio/media, save/load, and mission progression according to an evidence ledger. Add supported-build detection, crash reports, user data paths, release packaging, and Windows/Linux/macOS smoke tests. Do not claim whole-game support while major campaign paths are stand-ins.

Phase 6: No Regret

Add the Regret profile, intrinsic table, startup/global behavior, mission metadata, data variants, and game-specific regressions. Reuse shared engine code only where tests show the behavior is shared. Reassess debugger source mapping and bootstrap assumptions independently; the C# debugger itself need not reproduce the original activation mechanism. Passing this phase is a prerequisite for any Regret-derived options in No Remorse.

Phase 7: Optional No Regret Gameplay Backports

After Phase 6, add opt-in No Regret-style forward roll and unlimited weapon carrying to the No Remorse profile. Keep No Remorse behavior as the default: the forward roll is triggered by Ctrl+Forward only when the character controller can safely enter the required animation/state, and the existing weapon-capacity rule remains in effect unless the user enables the Regret-style option. Test both settings independently and together, including save/load and pickup/equip transitions.

Gate: the default profile passes existing No Remorse movement and inventory regressions unchanged. Each option is independently configurable, and enabled behavior is covered by controller/inventory tests plus a retail scenario where available.

Phase 8: Additive No Regret USECODE Extensions

Only after No Regret is integrated, expose selected Regret-derived USECODE capabilities to No Remorse as an optional extension set. Preserve the No Remorse intrinsic table and behavior; do not replace it with the Regret table or assume matching ordinals have matching meanings. Resolve collisions through explicit extension identities/aliases or reject ambiguous scripts, and only backport behavior that the shared runtime can support and test.

Gate: extension-disabled No Remorse scripts retain their existing semantics, while extension-enabled fixtures exercise each added capability. Existing intrinsic ordinals remain unchanged, and ambiguous or unsupported calls fail with actionable diagnostics.

Principal Risks and Controls

Risk Impact Control
Decompiled behavior is incomplete or misleading Gameplay bugs and rework Record address, variant, confidence, and test for each behavior; prefer executable traces and differential tests over guessed translations.
USECODE archive/VM assumptions are wrong Scripts fail or corrupt world state Preserve opaque bytes, build corpus tests, validate dispatch and intrinsic contracts per variant, and fail closed on unsupported operations.
Render output looks right while simulation is fake False progress claims Keep diagnostic tools separate; acceptance tests must exercise scheduler-owned mutable game state and actual event dispatch.
Modded saves load against changed content Lost or invalid state Store game build and ordered mod hashes in saves; reject or explicitly migrate mismatches.
Cross-platform path and native SDL differences Platform-specific failures Abstract host APIs, test case-sensitive paths, package native SDL per platform, and run CI plus real-device smoke tests.
Content tools damage retail data or lose unknown fields Irrecoverable user data and broken mods Open retail roots read-only, write to staging/output roots, preserve unknown bytes, and require round-trip tests before enabling edits.
Mod scripts request unsupported native behavior Unsafe expectations and incompatible packages Publish a versioned intrinsic capability list; prohibit arbitrary native plug-ins.
No Regret is assumed to be a data-only reskin Incorrect later milestone Keep separate profile tables and evidence; add the game only after Remorse regression infrastructure exists.
Expanded viewport changes targeting or input behavior Resolution-dependent gameplay regressions Keep rendering transforms separate from simulation; test input conversion and target eligibility across viewport sizes and zoom levels.
Regret-derived USECODE ordinals collide with Remorse meanings Existing scripts change behavior or extension calls become ambiguous Preserve the Remorse table, use explicit extension identities, and reject unresolved collisions.

Go/No-Go Recommendation

Authorize Phase 0 as a bounded spike, not a commitment to a full rewrite schedule. Proceed to the runtime foundation if it proves three things: the chosen SDL3 binding deploys cleanly on the target desktop platforms, the managed format/render pipeline can reproduce known retail scenes, and the project can express one Ghidra-backed behavior as a deterministic state-transition test.

Use a small No Remorse vertical slice to validate the architecture before promising full campaign coverage. Keep the debugger's execution model, data mod layer, and content tooling in the initial architecture, but gate their feature completeness separately. Start No Regret after the shared contracts are tested, not by copying Remorse tables and adjusting addresses.

Source Notes