Overview
This skill enables an AI agent to execute, debug, and validate the Dispel Game File Extractor (dispel-extractor) during implementation. It provides structured workflows for running the extractor, patching game files, and understanding its architecture.
Purpose
- Automate the execution of
dispel-extractor during development.
- Validate file parsing, extraction, and output generation.
- Patch (modify) game files from JSON for modding purposes.
- Provide debugging support for format compliance and error handling.
- Ensure adherence to the project's legal guidelines.
Build
bash
1cargo build --release
Common Commands
bash
1# Extract game files to JSON (auto-detects type by filename)
2cargo run -- extract -i <file> [-o <output.json>] [--pretty]
3cargo run -- extract -i fixtures/Dispel/CharacterInGame/WeaponItem.db
4cargo run -- extract -i fixtures/Dispel/MonsterInGame/Monster.db -o monsters.json
5cargo run -- extract -i fixtures/Dispel/Map/cat1.map --pretty
6
7# Extract with type override (for ambiguous files)
8cargo run -- extract -i unknown_file --type weapons
9
10# Patch game files from JSON
11cargo run -- patch -i <input.json> -t <target-file> [--in-place] [--dry-run] [--no-backup]
12cargo run -- patch -i weapons.json -t weaponItem.db --in-place
13cargo run -- patch -i monsters.json -t Monster.db --dry-run
14
15# Validate JSON against file format
16cargo run -- validate -i <input.json> --type <type> [--verbose]
17cargo run -- validate -i weapons.json --type weapons
18
19# List supported file types
20cargo run -- list
21cargo run -- list --format json
22cargo run -- list --filter monster
23
24# Get JSON schema for a file type (AI-friendly)
25cargo run -- schema --type weapons
26
27# Get record template for a file type
28cargo run -- template --type weapons [--pretty]
29
30# Map operations
31cargo run -- map tiles <input.gtl> [--output <dir>]
32cargo run -- map atlas <input.gtl> <output.png>
33cargo run -- map render --map <map> --btl <btl> --gtl <gtl> --output <output>
34cargo run -- map from-db --map-id <id> --gtl-atlas <path> --btl-atlas <path> --output <out>
35cargo run -- map to-db --database <db> --map <map.file>
36cargo run -- map to-json --input <map.file> [--output <out.json>] [--pretty]
37cargo run -- map sprites <input.map> [--output <dir>]
38
39# Database operations
40cargo run -- database import <game_path> <db_path>
41cargo run -- database dialog-texts <game_path> <db_path>
42cargo run -- database maps <game_path> <db_path>
43
44# Sprite extraction
45cargo run -- sprite <input.spr>
46cargo run -- sprite <input.spr> --mode animation
47cargo run -- sprite <input.spr> --info
48
49# Extract sprite info via unified extract command (auto-detected by .spr extension)
50cargo run -- extract -i <input.spr> [--pretty]
51
52# Audio conversion
53cargo run -- sound <input.snf> <output.wav>
54
55# Test
56cargo run -- test --message "hello"
Deprecated Commands
The ref command is deprecated but still works with a migration hint:
bash
1# Old (deprecated, shows hint)
2cargo run -- ref weapons fixtures/Dispel/CharacterInGame/weaponItem.db
3
4# New (preferred)
5cargo run -- extract -i fixtures/Dispel/CharacterInGame/weaponItem.db --type weapons
Architecture
Command Pattern (src/commands/mod.rs)
All commands implement the Command trait:
rust
1pub trait Command: Send + Sync {
2 fn execute(&self) -> Result<(), Box<dyn Error>>;
3 fn name(&self) -> &'static str;
4 fn description(&self) -> &'static str;
5}
A CommandFactory provides dependency injection for creating commands.
Module Structure
| Module | Purpose |
|---|
src/commands/mod.rs | Command trait and factory |
src/commands/unified.rs | Extract and Patch commands (unified reference file handling) |
src/commands/registry.rs | File type registry with auto-detection (filename-based) |
src/commands/info.rs | List, Validate, Schema, Template commands |
src/commands/map.rs | Map parsing, rendering, and JSON export (MapSubcommand enum) |
src/commands/database.rs | SQLite import/export (DatabaseSubcommand enum) |
src/commands/sprite.rs | SPR sprite parsing |
src/commands/sound.rs | SNF to WAV conversion |
src/map/ | Binary map format parsing, rendering, JSON serialization |
src/references/ | Game reference file parsers (with Extractor trait: read_file + save_file) |
src/queries/ | SQL templates for database operations |
Maps: .map, .gtl (ground tiles), .btl (building tiles)
Sprites: .spr (static or animated)
Audio: .snf (raw PCM)
Reference Files: .ini, .db, .ref, .dlg, .pgp, .scr
Supported Reference File Types (31 total)
| Type Key | Extensions | Description | Patchable |
|---|
all_maps | .ini | Master map list | Yes |
map_ini | .ini | Map properties | Yes |
extra_ini | .ini | Interactive object types | Yes |
event_ini | .ini | Script/event mappings | Yes |
monster_ini | .ini | Monster visual refs | Yes |
npc_ini | .ini | NPC visual refs | Yes |
wave_ini | .ini | Audio/SNF references | Yes |
weapons | .db | Weapons & armor | Yes |
monsters | .db | Monster stats | Yes |
magic | .db | Magic spells | Yes |
store | .db | Shop inventories | Yes |
misc_item | .db | Generic items | Yes |
heal_item | .db | Consumables | Yes |
event_item | .db | Quest items | Yes |
edit_item | .db | Modifiable items | Yes |
party_level | .db | EXP tables | Yes |
party_ini | .db | Party NPC metadata | Yes |
chdata | .db | Character data | Yes |
party_ref | .ref | Character definitions | Yes |
draw_item | .ref | Map placements | Yes |
npc_ref | .ref | NPC placements | Yes |
monster_ref | .ref | Monster placements | Yes |
extra_ref | .ref | Special object placements | Yes |
event_npc_ref | .ref | Event-specific NPC placements | Yes |
dialog | .dlg | Dialogue scripts | Yes |
dialog_text | .pgp | Dialogue text packages | Yes |
quest | .scr | Quest definitions | Yes |
message | .scr | Game messages | Yes |
map_file | .map | Map geometry, sprites, events, tiles | No |
gtl | .gtl | Ground tile layer | No |
btl | .btl | Building tile layer | No |
sprite | .spr | Sprite/animation file | No |
Auto-Detection
File types are detected by filename (case-insensitive). For example:
WeaponItem.db → weapons
Monster.db → monsters
Store.db → store
cat1.map → map_file
cat1.gtl → gtl
PartyRef.ref → party_ref
Use --type <key> to override auto-detection.
Adding New Features
Adding a new reference parser
- Create parser struct in
src/references/ implementing Extractor trait (read_file + save_file)
- Add
Deserialize derive to the struct (required for patch support)
- Add entry to
FILE_TYPES in src/commands/registry.rs with DetectKind for auto-detection
- Add SQL templates in
src/queries/ (optional, for database import)
- No changes needed in
main.rs — the registry handles routing automatically
Adding a new map subcommand
- Add variant to
MapCommands enum in src/main.rs
- Add variant to
MapSubcommand in src/commands/map.rs
- Implement in
src/map/ modules
- Wire up in
main.rs match statement
- Add entry to
FILE_TYPES in src/commands/registry.rs
- Use
patch_not_supported as the patch_fn
- Implement a custom
extract_fn that returns serde_json::Value
Testing
Error Handling
| Error | Recovery |
|---|
| File not found | Check input path |
| Invalid format | Compare with known-good files |
| Parse error | Check binary structure against format docs |
| Database error | Check SQL syntax in src/queries/ |
| JSON validation error | Check field types against schema |
| Patch file type mismatch | Use --type flag to override auto-detection |
| Patch not supported | File type is extract-only (e.g., .map, .gtl, .btl) |
References
- Extractor CLI:
cargo run -- --help
- File Formats:
docs/file_formats.md
- Cross-Reference Guide: CROSS_REFERENCES.md
- INI Files:
- Database Files:
Legal Compliance Checklist
See AGENTS.md for full guidelines.