Cursebreaker Parser
A Rust library for parsing and managing game data from the Cursebreaker game. This crate provides tools to extract, load, and query game data from Unity scenes and XML files.
Overview
Cursebreaker Parser is designed to:
- Parse Unity scenes and extract game objects using the unity-parser library
- Load game data from XML files (Items, NPCs, Quests, Harvestables, Loot tables)
- Provide in-memory databases for efficient querying of game data
- Serialize game data to SQL format for database storage
Features
- Item Database: Load and query items with support for filtering by ID, category, slot, and other attributes
- NPC Database: Manage NPC data including stats, levels, animations, and quest markers
- Quest Database: Handle quest definitions, phases, and rewards
- Harvestable Database: Track harvestable resources and their drop tables
- Loot Database: Manage loot tables and drop configurations
- XML Parsing: Robust XML parsing with error handling
- SQL Export: Prepare data for SQL database insertion
Binaries
The project provides multiple binaries to handle different parsing tasks. This allows you to run only the parts you need, avoiding long load times for unnecessary operations.
Available Binaries
-
xml-parser - Loads game data from XML files and populates the SQLite database
- Fast execution
- Run this when XML files change
cargo run --bin xml-parser -
scene-parser - Parses Unity scenes and extracts game objects
- Slow execution (Unity project initialization)
- Run this when scene files change
cargo run --bin scene-parser -
image-parser - Processes minimap tiles
- Slow execution (image processing and compression)
- Run this when minimap images change
cargo run --bin image-parser -
cursebreaker-parser - All-in-one binary (runs all parsers)
- Slowest execution (runs everything)
- Use when you need to regenerate the entire database
cargo run --bin cursebreaker-parser # or simply cargo run
Building for Production
Build specific binaries for release:
cargo build --release --bin xml-parser
cargo build --release --bin scene-parser
cargo build --release --bin image-parser
The compiled binaries will be in target/release/.
Usage
Loading Items from XML
use cursebreaker_parser::ItemDatabase;
// Load all items from XML
let item_db = ItemDatabase::load_from_xml("Data/XMLs/Items/Items.xml")?;
println!("Loaded {} items", item_db.len());
// Get item by ID
if let Some(item) = item_db.get_by_id(150) {
println!("Found: {}", item.name);
}
// Query items by category
let weapons = item_db.get_by_category("bow");
println!("Found {} bows", weapons.len());
// Query items by slot
let consumables = item_db.get_by_slot("consumable");
for item in consumables {
println!("Consumable: {}", item.name);
}
Preparing Data for SQL
use cursebreaker_parser::ItemDatabase;
let item_db = ItemDatabase::load_from_xml("Data/XMLs/Items/Items.xml")?;
// Prepare data for SQL insertion
// Returns Vec<(id, name, json_data)>
let sql_data = item_db.prepare_for_sql();
for (id, name, json) in sql_data.iter().take(5) {
println!("INSERT INTO items VALUES ({}, '{}', '{}')", id, name, json);
}
Project Structure
cursebreaker-parser/
├── src/
│ ├── lib.rs # Library entry point and public API
│ ├── main.rs # Main binary (all-in-one parser)
│ ├── bin/ # Separate parser binaries
│ │ ├── xml-parser.rs # XML parsing only
│ │ ├── scene-parser.rs # Unity scene parsing only
│ │ └── image-parser.rs # Image processing only
│ ├── xml_parser.rs # XML parsing utilities
│ ├── image_processor.rs # Image processing utilities
│ ├── item_loader.rs # Item loading logic
│ ├── databases/ # Database implementations
│ │ ├── item_database.rs
│ │ ├── npc_database.rs
│ │ ├── quest_database.rs
│ │ ├── harvestable_database.rs
│ │ ├── loot_database.rs
│ │ └── minimap_database.rs
│ └── types/ # Type definitions
│ ├── cursebreaker/ # Game-specific types (Items, NPCs, Quests, etc.)
│ └── monobehaviours/ # Unity MonoBehaviour types
├── examples/ # Example usage
├── migrations/ # Database migrations
├── Cargo.toml # Package configuration
└── XML_PARSING.md # XML parsing documentation
Dependencies
- unity-parser: For parsing Unity scene files
- quick-xml: XML parsing
- serde: Serialization/deserialization
- serde_json: JSON support
- serde_yaml: YAML support
- sparsey: ECS (Entity Component System) support
- diesel: Optional SQL database support
- thiserror: Error handling
Building
# Build the library
cargo build
# Run tests
cargo test
# Build with SQL support
cargo build --features diesel
Documentation
For detailed XML parsing information, see XML_PARSING.md.
Generate API documentation:
cargo doc --open