This tool scans the supported local X1/X2/X3 USA ROMs and creates an address-backed porting packet for each original type-3 object ID. A packet combines identification, compressed/decompressed graphics, palette variants, sprite assemblies, composed sheets and recovered 65C816 code for AI-assisted C# conversion.
This standalone .NET 9 console project exposes a reusable public API in XSharp.Tools.Enemies. It has no package or project dependencies. It needs no Python, GUI, emulator, graphics driver or audio device. The identification catalog is embedded in the assembly. Input ROMs are supplied locally and are not distributed with the program.
dotnet run --project EnemyExtractor/EnemyExtractor.csproj -- `
--rom 'C:\path\to\Megaman X (USA).sfc' `
--rom 'C:\path\to\Megaman X2 (USA).sfc' `
--rom 'C:\path\to\Megaman X3 (USA).sfc' `
--output "$env:TEMP\xsharp-enemy-packets"
Repeat --rom to batch games. The default scans object IDs 01..6A, matching the range used by MegaED X’s property scanner. These are object IDs, including aliases, bosses, stage objects and unused entries. The result is not a count of distinct common enemies. All input ROMs are validated before output is created. A 512-byte copier header is removed before revision identification; unknown revisions and expanded/modified ROMs are rejected rather than assigned guessed pointers.
For a focused packet or deeper code exploration:
dotnet run --project EnemyExtractor/EnemyExtractor.csproj -- `
--rom 'C:\path\to\Megaman X (USA).sfc' `
--ids 1D,34,35 `
--instruction-limit 8192 --call-depth 2 --all-palettes `
--output "$env:TEMP\xsharp-selected-enemies"
Use a dedicated output directory. All selected game subdirectories must be absent or empty; existing packets are never overwritten or mixed with a later export. For another run, choose a fresh output directory. The final manifest hashes each packet’s artifacts, so the validator detects modified exports. An interrupted export must be repeated in an empty directory. ROMs and generated packets are local inputs/outputs and are not committed by the extraction tool. Only one revision of each game can appear in a batch.
Progress goes to stderr and the final JSON summary to stdout. Exit codes are 0 for completion, 1 for input/extraction failure, 2 for missing required arguments and 130 for cancellation with Ctrl+C. Completion can include per-packet diagnostics and does not imply every resource or code path is resolved.
For reviewed X1 terrain actor2B artwork, an independent export mode reads the original compressed graphics and sprite assemblies directly:
dotnet run --project EnemyExtractor -- --rom 'C:\ROMs\Megaman X (USA).sfc' `
--x1-terrain-art --output "$env:TEMP\x1-terrain-art"
It creates a17-cell RGBA X1TerrainDebris.png and an accompanying
X1TerrainDebris.art.json provenance receipt. Stage resource bindings select
the source palettes, including distinct palettes for the shared Armadillo,
Mammoth and Octopus fragment graphics. The exporter rejects unknown revisions,
ambiguous palette bindings, missing tiles and empty/oversized assemblies. This
mode must be used alone with one ROM and its own output directory. The reusable
API is X1TerrainArtExporter.Export(RomImage.Load(romPath), outputDirectory).
It neither launches an emulator nor assumes that injected terrain has caused
its graphics to be loaded into native VRAM. See
docs/development/player-armors.md for the runtime controller and capture scope.
Create a Windows console executable that runs from any working directory with the .NET 9 runtime installed:
dotnet publish EnemyExtractor/EnemyExtractor.csproj -c Release -r win-x64 `
--self-contained false -p:PublishSingleFile=true -o artifacts/EnemyExtractor
./artifacts/EnemyExtractor/EnemyExtractor.exe --help
Use --self-contained true to include the runtime, or another .NET-supported runtime identifier for a different host. The implementation uses portable managed I/O and PNG compression; only Windows execution has been verified locally.
Other C# programs can reference EnemyExtractor.csproj and invoke the service directly:
using XSharp.Tools.Enemies;
using var cancellation = new CancellationTokenSource();
var result = new EnemyExtractorService().Extract(
new ExtractionOptions(
RomPaths: new[] { @"C:\ROMs\Megaman X (USA).sfc" },
OutputDirectory: @"C:\Exports\xsharp-enemies",
EventIds: new[] { 0x1D, 0x34 },
InstructionLimit: 8192,
CallDepth: 2,
AllPalettes: true),
progress: Console.Error.WriteLine,
cancellationToken: cancellation.Token);
RomImage, GraphicsDecoder, SpriteExtractor, Cpu65816 and PngWriter expose the individual stages too. ROM bus addresses and file offsets remain separate. RomImage accepts only the supported revisions; synthetic unit-test images cannot bypass this through the public API. Cancellation is checked between games and objects; code recovery and sheet generation have explicit budgets. Use --source-root <repository> to include existing C# implementation candidates in the game catalogs.
Native audio-call research can run without extracting any graphics:
dotnet run --project EnemyExtractor -c Release -- --rom '<original USA ROM>' --sound-calls --ids 2F,57 --call-depth 1 --instruction-limit 8192 --output calls.json
Omit --ids to inspect 01..6A. This mode defaults to call depth zero; increase it
explicitly when following shared helpers. NativeSoundInspector.InspectEntry and
InspectObject expose the same portable API. Output retains queue addresses,
nearby decoded instructions/widths, adjacent constant hints, ROM SHA1, recovery
coverage and diagnostics. A constant immediately before a call is not data-flow
proof; a recovered graph can overapproximate dispatch tables, and absence of a
call is not proof of silence. Child/projectile pools, indirect helpers and resource
overlays still need separate semantic review. This tool does not translate AI or
automatically wire sounds. Source ROMs remain read-only.
Use --sound-pool enemy-projectile for the separate hostile-projectile dispatcher:
dotnet run --project EnemyExtractor -c Release -- --rom '<original USA ROM>' --sound-calls --sound-pool enemy-projectile --ids 0A,17,22 --output projectile-calls.json
NativeSoundInspector.InspectEnemyProjectile exposes this pool through the API.
The supported revision tables are X1 80:F793, X2 80:FA37 and X3 80:F8D8, each with
51 slots (00..32); the default CLI selection omits alias slot 00. Each result
retains its pool, pointer table and trampoline, so a numeric ID cannot silently
be mistaken for the enemy or common-effect dispatcher. For example, X3 common
effect 2D allocated by 02:D859 is a different role from enemy-projectile 2D.
Immediate returns and invalid trampolines retain diagnostics rather than a
silence claim. Queue-call context and adjacent constants still need semantic
review, including identifying which allocator the firing actor actually calls.
The extraction API and packet schema are intended to be reusable by HunterBaseStudio. Palette/tile decoding, sprite composition, revision-pinned pointers, contextual object names and code listings can support asset browsing and original-game analysis in that editor. Keep these data-processing stages independent of XSharp’s game loop, content modules, rendering and audio. HunterBaseStudio can consume the service or exported packets; any future shared library should preserve the same validation and provenance boundaries. The integration itself remains to be implemented and tested. Code-recovery diagnostics must remain visible to consumers, since extracted listings do not certify complete behavior.
batch.json summarizes each game. Its catalog.json lists object IDs, names/aliases, packet paths, code/graphics coverage, diagnostics and optional source-code candidates found with --source-root. Candidate status distinguishes an empty class from an implementation that still needs parity review. A nonempty class is not automatically considered complete.
Each packet can contain:
| File | Meaning |
|---|---|
manifest.json |
ROM hash, object IDs/names, source addresses, resource contexts, provisional destination project, diagnostics and artifact hashes |
tiles.4bpp |
Exact decompressed SNES graphics bytes |
palette-NNNN.bgr555 |
Original sixteen-color palette bytes |
tiles-NNNN.png |
Decoded 8x8 tile atlas for a palette |
assembly.json |
Sprite part positions, tile numbers, sizes and flip flags for each recovered image |
sprites-NNNN.png |
Composed sprite sheet with transparent palette index zero |
sprites-NNNN.json |
Sheet rectangles, original origins and missing-tile diagnostics |
logic.asm |
Recovered 65C816 listing, including bytes, file offsets and M/X-width variants |
logic.json |
Entry point, decoded instruction records, direct calls, indexed table candidates and unresolved assumptions |
PORTING.md |
A concrete conversion task for the packet and its target C# content project |
The default exports the first recovered palette binding and records all known stage/load-set bindings. --all-palettes emits each recovered variant. Palette selectors are word offsets, not byte IDs. Graphics ID zero is valid; load-set pointer arrays stop at their structural boundary before resource records. A diagnostic grayscale atlas is explicitly marked when no palette binding was found. Nonzero per-part palette selectors are recorded for contextual review; composites use the selected base palette. Missing tiles require contextual graphics loads. Partial final tiles remain intact in tiles.4bpp; only complete tiles are composed. Sprite frame-list bounds come from the next distinct assembly-table pointer and remain subject to semantic review. Frame-list order does not establish animation timing; the original logic and animation commands determine it.
The graphics, palette, sprite-offset and stage resource formats follow the existing MegaEDXCore port and the original MegaED X, with the expanded tables and identification UI from rbrummett’s fork. The relevant upstream files are MMXCore.cpp, RenderED.cpp and MegaED X.cpp. catalog.json records the SHA-256 of the exact local reference file used to import names and IDs; it does not claim that local file is byte-identical to current upstream.
| Game | Normalized ROM SHA-1 | Sprite mapping | Graphics table | Type-3 logic dispatch |
|---|---|---|---|---|
| X1 | 449A00631208FBCC8D58209E66D0D488674B7FB1 |
86:A5E4 |
86:F6F7 |
80:F8F3 |
| X2 | 637079014421563283CDED6AEAA0604597B2E33C |
86:A34D |
86:F9FF |
80:FB8E |
| X3 | B226F7EC59283B05C1E276E2F433893F45027CAC |
86:E28E |
86:F730 |
80:FA2F |
The X1/X2 logic table locations also appear in the commented property-pointer table in MegaED X. The X3 dispatch address was verified from the local ROM’s LDA $0A / ASL / TAX / JMP (table,X) path and its JSL trampolines. Palette/resource pointers are retained separately from code entry points. A sprite assembly is graphical composition data; it does not identify the enemy’s assembly-language behavior by itself.
Names can be contextual. For example, X3 ID 29 is labeled Ice de Voux or Iwan de Voux depending on context. The upstream-derived X2 list also contains 1D7 for Flame Bursts, which cannot be a byte-sized event ID; this is preserved as a catalog diagnostic rather than silently changed to D7. The airborne Sine Faller mapping is an explicit XSharp override because MegaED X labels its special-event spawner separately.
The five-byte sprite record supplies resource/damage-table and initial health/
contact metadata, not an immutable gameplay contract. Object initialization can
overwrite it: X3 Blady’s record contains health 9, but $07:859A..859D sets its
runtime health to 16. Keep the extracted record intact and document runtime
overrides separately with the controlling code. See the revision-pinned
control notes and
projectile/helper source register.
The decoder covers all 256 opcodes and tracks accumulator/index widths through REP/SEP and PHP/PLP paths. Branch alternatives and direct calls are followed within explicit instruction/depth budgets. Indexed tables are followed only when a bounded extent can be inferred. Unknown status restoration, indirect jumps, call-return width assumptions and budget limits are recorded in logic.json.
All recovered code currently has coverage: requires-review. The analysis does not establish complete function boundaries, stack behavior, data-bank/direct-page context, callee M/X summaries, relocated RAM code or all computed control flow. Exact ROM bytes remain the authority. Do not translate a guessed instruction boundary as confirmed game logic; resolve it with the original code context or an execution trace.
The next stage uses each PORTING.md packet to convert the behavior into a C# state/motion model and an engine adapter. Destination projects are the six game content modules. Boss labels route to boss projects. Unclassified IDs have a provisional common-enemy destination and must be classified before a factory is enabled. Empty C# placeholders and image extraction do not count as completed enemy implementations. No external AI API is called and no generated placeholder is automatically wired into gameplay.
For each translated enemy, preserve fixed-point arithmetic, branch signs, frame boundaries, RNG consumption, spawn limits, collision effects and damage transitions. Keep simulation code independent of rendering/audio. Add headless motion/lifecycle tests and compare controlled original-game traces before reporting 1:1 behavior. The exporter supplies the material for that work; the semantic conversion and validation remain active implementation work.
Unit checks cover opcode decoding/widths, branches, bounded indirect dispatch, unknown modes, malformed compression, overlapping LZ references, all four bitplanes, palette scale, sprite flips/large-tile stride/origins, missing tiles, PNG checksums and contextual catalog entries:
dotnet test EnemyExtractor.Tests/EnemyExtractor.Tests.csproj
Cross-check a real extracted game against the existing independent C# MegaED X decompressor and the source ROM:
dotnet run --project tools/EnemyPort.Validation/EnemyPort.Validation.csproj -- `
'C:\path\to\Megaman X (USA).sfc' "$env:TEMP\xsharp-enemy-packets\x1"
Repeat for X2/X3 and their packet subdirectories. This checks graphics bytes against CompressionCore.GFXRLE, palette bytes against ROM addresses, decoded instruction byte spans against the ROM and every artifact checksum. Matching byte spans establishes integrity, not the semantic correctness of every decoded control-flow path.
Test a published console with a local X1 ROM:
pwsh -File tools/Test-EnemyExtractor.ps1 `
-Extractor artifacts/EnemyExtractor/EnemyExtractor.exe `
-X1Rom 'C:\path\to\Megaman X (USA).sfc'
This checks exit codes, revision/ID/duplicate-game rejection before output, copier-header normalization, deterministic packets across repeated/headered exports, all-palette mode and existing-output protection. It retains test artifacts in a new temporary directory for inspection and invokes no engine runtime.
The local C# trilogy run scanned 318 object IDs and emitted 318 tile/sprite-sheet sets. The independent comparison passed for 106 graphics streams per game, 301 palettes and 290,578 decoded byte spans. The 39 automated tests cover individual stages, malformed inputs and actual console error paths without ROM files or engine dependencies. Some packet diagnostics still require contextual resource or code analysis; these counts do not certify enemy implementations or complete logic extraction.
--packets <root> --recipe <json> --output <Assets/Enemies> exports curated
body/attack/projectile sequences without loading a ROM, renderer or audio device.
The API is RuntimeArtExporter.Export. Recipes preserve native assembly pivots
and palette colors, reject missing tiles and verify the packet SHA256 hashes.
Animation timing and behavior conversion remain explicit authoring work. See
the functional content roster.
For reviewed contextual composition, add one exact original --rom. Recipes can
specify TileBias, ContextLevel and ContextLoadSet (or ContextLevel: -2 to
search existing load contexts). TransparentTiles explicitly documents assumed
transparent missing padding; recovered pixels are never replaced by that option.
Context selection and transparent padding are authoring decisions, not proof of
native VRAM equivalence. Alternate palette bindings require --all-palettes
during packet extraction. The runtime export remains independent of the host.
Runtime art recipes may explicitly select AssemblyId, GraphicsId and
PaletteIndex for subtype variants. These overrides require the packet’s exact
ROM revision and recompose the original frame geometry from that ROM. For example,
X1 object 2D defaults to M-501 assembly 4C/resource 4B/palette EA; its Bone subtype
instead selects assembly 4B/resource 4A/palette E8 in $87:A11C. The shared packet
name alone does not distinguish these variants. Palette indices are word offsets.
--rom <local.sfc> --animation-assembly <hex> --animation-count N --output <json>
extracts reviewed selector pointers and reached duration/flags/frame scripts,
including relative loop words. NativeAnimationExtractor.Extract is the reusable
C# API. Its X1/X2/X3 directories are revision-pinned; the output retains ROM SHA1
and byte segments. This is data extraction, not AI translation. Selector count is
an explicit reviewed input, rather than an inferred universal table boundary.
The engine reads optional Actor.animations.json sidecars independently of the
graphics JSON, so art re-exports preserve control metadata. Native shape, muzzle
or vector tables can be retained as additional reviewed byte segments. See the
direct control notes.
This is an optional previous prototype, used for the first Creeper milestone. It is not required by the current workflow and is not being expanded for the remaining roster: extraction supplies the original material, and enemy logic is adapted directly to C#. See the direct X1 adaptations.
--rom <local.sfc> --transpile <reviewed-controller.json> --output <controller.cs>
now emits bounded C# object procedures from the pinned ROM. This is an initial,
fail-closed instruction subset with explicit data-bank, width, code/data bounds
and shared-service contracts, rather than automatic whole-game conversion.
It rejects unknown instructions/services and emits source addresses, original
bytes and hashes. The C# generator itself has no engine/render/audio dependency.
See native conversion and Creeper evidence for the reproducible command, all 104 tracked actors, controlled opcode tests and the distinction between generated control and completed runtime parity.
X1 player rider graphics can use X1DynamicTileTable in a runtime art recipe.
X1DynamicSpriteTiles extracts the raw per-frame DMA uploads used by Ride Armor
rider assembly 6A (table 85:A8A5), including zero-upload residency. This is separate
from compressed graphics ID 00. See the reviewed source.
Static frame export replays preceding descriptors in canonical forward frame
order: punch frames 4/5 retain frame 3’s tiles, rather than reverting to idle.
This helper is not an arbitrary animation-history/VRAM emulator.
X2 decompressed object frame uploads can use X2DynamicTileTable in a runtime
art recipe. X2DynamicSpriteTiles.ForFrame reads the reviewed bank-05 descriptor
format used by $08:C9B8, applies uploads from a decompressed graphics resource,
and retains preceding uploads for zero-descriptor frames. This helper currently
models the reviewed page-zero layout, independently of the engine or emulator.
It rejects source banks other than 7F and partial-tile transfers.
Static export replays descriptors in canonical forward frame order. It does not
emulate arbitrary animation history, DMA timing or unrelated VRAM producers.
The Pararoid center recipe
uses resource 1F, group 23, palette 0030 and table 05:A523. Extract packet ID 14
first, then pass its packet root, this recipe and the same pinned X2 ROM to the
runtime art export command. The center’s object tile bank begins at byte C000;
the nearby decorative components use E000. The source record
retains the observed WRAM/VRAM bindings and transfer hashes.
X3 ordinary armor capsules have a standalone art extraction mode:
dotnet run --project EnemyExtractor -- --rom XSharp/Assets/ROMs/ZeroIsJegue.mmx --x3-capsule-art --output XSharp.Assets.X3/Capsules
It exports seven PNG/JSON pairs: blue/pink capsule bodies, the hologram, and
all four30-image part overlays. The renderer selects assembly directories8D..90
through actor16; the98 stored in actor10 is not a two-image assembly override.
Each overlay combines its dynamic part upload (graphics94..97) with shared
graphics98. X3StageSpriteUploads reads the source scatter layout at08:D7C9:
resource98 copies eight tiles to96..103 and seven to112..118. Treating those
fifteen tiles as a continuous range silently loses effect frames. Missing tiles
are rejected before any atlas is written. JSON records palettes, source revision,
frame origins/rectangles and upload provenance. The data-only X3 package embeds
these resources under Capsules/X3/; the engine needs no ROM to read them.
This command does not implement capsule dialogue, admission, collision or timing,
and its selected palette composition is not an original-game screenshot comparison.