1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//! # Uxie - Data fetching library for Pokemon Gen 4 Romhacking
//!
//! Named after the legendary Pokémon [Uxie](https://bulbapedia.bulbagarden.net/wiki/Uxie_(Pok%C3%A9mon)),
//! the "Being of Knowledge", this library provides unified access to ROM data from multiple sources:
//! DSPRE projects, decompilation sources (pokeplatinum/pokeheartgold), and raw binary files.
//!
//! Platinum is the primary target and has the most complete support. HGSS support
//! has improved substantially, but remains partial in some workflows.
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use uxie::{Workspace, RomHeader};
//!
//! // Auto-detect and open any supported project
//! let workspace = Workspace::open("path/to/project")?;
//!
//! // Resolve constants from any loaded header file
//! if let Some(value) = workspace.resolve_constant("ITEM_POKE_BALL") {
//! println!("Poké Ball ID: {}", value);
//! }
//!
//! // Read ROM header information
//! let header = RomHeader::open("path/to/header.bin")?;
//! println!("Game: {:?}", header.detect_game());
//! # Ok::<(), std::io::Error>(())
//! ```
//!
//! ## Core Features
//!
//! - **Smart Project Detection**: Automatically detects DSPRE projects, decompilation sources, and raw binaries; decomp family detection is based on project structure rather than folder names
//! - **Unified Symbol Resolution**: Parse C headers, enums, and defines with strict constant-expression evaluation
//! - **High Performance**: ~200ms to load 50,000+ symbols with parallel parsing and caching
//! - **Map Header Access**: Read map data across all Gen 4 games (Diamond, Pearl, Platinum, HeartGold, SoulSilver)
//! - **Script & Text Banks**: Bidirectional symbol resolution for game scripts and text archives
//! - **Format Agnostic**: Seamlessly handle binary formats (NARC, arm9.bin) and modern JSON/YAML sources
//!
//! ## Module Organization
//!
//! - [`workspace`]: High-level API for managing projects, symbols, scripts, and text banks
//! - [`rom_header`]: ROM header reading with auto-detection of game version and region
//! - [`c_parser`]: C header parsing with strict constant-expression evaluation (enums, defines, includes)
//! - [`map_header`]: Map header structures for all Gen 4 games
//! - [`provider`]: Trait-based data access for different project types
//! - [`event_file`] / [`encounter_file`]: Event and encounter data structures
//! - [`ds_rom`]: DSPRE and ds-rom-tool project structures
//! - [`narc`]: Nintendo Archive (NARC) file format reader
//! - [`game`]: Game version detection and family classification
//!
//! ## Examples
//!
//! ### Working with Decompilation Projects
//!
//! ```rust,no_run
//! use uxie::Workspace;
//!
//! let workspace = Workspace::open("path/to/pokeplatinum")?;
//!
//! // Access the symbol table
//! if let Some(val) = workspace.resolve_constant("FLAG_HIDE_RIVAL") {
//! println!("Flag value: {}", val);
//! }
//!
//! // Bidirectional script resolution
//! let script = "SetFlag FLAG_HIDE_RIVAL";
//! let resolved = workspace.resolve_script_symbols(script);
//! println!("{}", resolved); // "SetFlag 1234"
//! # Ok::<(), std::io::Error>(())
//! ```
//!
//! ### Parsing C Headers
//!
//! ```rust
//! use uxie::SymbolTable;
//!
//! let mut symbols = SymbolTable::new();
//! # let temp_dir = std::env::temp_dir();
//! # std::fs::create_dir_all(temp_dir.join("include")).ok();
//! # std::fs::write(temp_dir.join("include/constants.h"),
//! # "#define MAX_PARTY_SIZE 6\n#define ITEM_POKE_BALL 1\n")?;
//!
//! // Load all headers from a directory
//! symbols.load_headers_from_dir(temp_dir.join("include"))?;
//!
//! // Evaluate complex expressions
//! let value = symbols.evaluate_expression("(1 << 8) | 0xFF");
//! assert_eq!(value, Some(0x1FF));
//! # Ok::<(), std::io::Error>(())
//! ```
//!
//! ### Reading Map Headers
//!
//! ```rust,no_run
//! use uxie::{Arm9Provider, GameFamily, DataProvider};
//!
//! let provider = Arm9Provider::new(
//! "path/to/arm9.bin",
//! 0xE601C, // Platinum table offset
//! 559, // Header count
//! GameFamily::Platinum,
//! );
//!
//! let header = provider.get_map_header(0)?;
//! println!("Map 0 script file ID: {}", header.script_file_id());
//! # Ok::<(), std::io::Error>(())
//! ```
//!
//! ## Performance
//!
//! Uxie is optimized for high-throughput symbol resolution:
//!
//! - **~200ms**: Load 50,000+ symbols from pokeplatinum
//! - **< 1 microsecond**: Cached constant resolution (O(1) lookup)
//! - **< 5 microseconds**: Complex C expression evaluation
//! - **Parallel loading**: Multi-threaded header parsing via `rayon`
//! - **Smart caching**: Global canonical path cache and expression evaluation cache
//!
//! ## Supported Games
//!
//! | Game | Region Codes | Family |
//! |------|--------------|--------|
//! | Diamond | ADAE (US), ADAJ (JP), ADAP (EU) | DP |
//! | Pearl | APAE (US), APAJ (JP), APAP (EU) | DP |
//! | Platinum | CPUE (US), CPUJ (JP), CPUP (EU) | Platinum |
//! | HeartGold | IPKE (US), IPKJ (JP), IPKP (EU) | HGSS |
//! | SoulSilver | IPGE (US), IPGJ (JP), IPGP (EU) | HGSS |
//!
//! ## Design Philosophy
//!
//! Uxie bridges the gap between legacy binary ROM hacking tools and modern decompilation workflows:
//!
//! - **Universal Symbols**: Single namespace for C headers, assembly constants, and binary offsets
//! - **Toolchain Agnostic**: Works with DSPRE, ds-rom-tool, and decompilation projects
//! - **Format Fluidity**: Unified API regardless of source format (binary, YAML, JSON, C)
//! - **Zero Configuration**: Smart auto-detection for standard project structures
pub use c_parserSymbolTable;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Narc;
pub use ;
pub use ;
pub use RomHeader;
pub use ScriptTable;
pub use ;
pub use ;
pub use ;