Pokémon Platinum Decompilation Tools
repository·main·Indexed 18 days ago
https://github.com/pret/pokeplatinumTools and documentation to assist in the decompilation of Pokémon Platinum. Includes the m2ctx tool for generating decomp.me context files, the nitroarc C library and CLI for Nitro Archive (NARC) manipulation, and NitroBTX for NSBTX texture files. Provides technical specifications for the game's map subsystems, 2D rendering architecture, VRAM management, and 3D rendering abstraction layers including Easy3D and Easy3DObject.
What's inside pokeplatinum
- NitroBTX is a program designed to dump and create NDS NSBTX files. It is primarily used for handling texture data within the NDS format.
Overview of Data Processing Tools
mainThe project uses a suite of custom compiler tools located in
tools/dataprocto convert plain-text data files (primarily JSON) into game-ready binary data. These tools use a common interface defined inlib/dataproc.cfor querying data markup and providing validation and error reporting.Key shared infrastructure used by these tools includes:
- Parsing C enums and preprocessor definitions from headers into lookup tables.
- Generating output C header files using
.templatefiles. - Creating output NARC files via
libnitroarc. - Writing dependency files at runtime to ensure correct build ordering.
Move Data File Format Overview
mainThe
moveprocbuild tool consumes move data organized into subdirectories underres/moves/<name>. Each move directory must contain three specific files to define its metadata, visual animation, and battle logic:data.json: Contains internal metadata such as stats, type, flags, and text.anim.s: An assembly script defining the move's animation in battles and contests.script.s: An assembly script defining the move's execution logic during battle.
Trainer Data File Format Overview
mainThetrainerprocbuild tool consumes trainer data from JSON files located atres/trainers/data/<name>.json. Each file represents a single trainer and contains metadata for the trainer and their Pokémon party. These fields are mapped to structs defined ininclude/struct_defs/trainer_data.h.Understand the map-related subsystems in PokePlatinum
mainThe map system in PokePlatinum is composed of several interacting subsystems that allow the game to render a seamless world. Key components include:
- Maps: 2D grids of 32x32 tiles.
- Map Headers: Metadata structures associated with specific map IDs containing information like music, map names, and cycling permissions.
- Map Matrices: 2D arrays of maps that form playable areas (e.g., the 30x30 overworld matrix), enabling dynamic loading/unloading as the player moves.
- Areas: Collections of maps that share the same textures and map prop models.
- Map Objects: Entities placed on maps, such as the player or NPCs.
- Map Props: 3D models placed on maps, such as buildings or furniture.
- BDHC: A subsystem providing terrain height data used for collision detection and map object height calculations.
For technical details on specific subsystems, refer to the following documentation files:
maps.md: General map overview.bdhc.md: BDHC subsystem and height information.loading_maps.md: Map loading processes.file_format_specifications.md: Technical data structures and file formats.dynamic_map_features.md: Dynamic map features system.
What is the BDHC subsystem?
mainThe BDHC subsystem is used to calculate terrain height for collision detection and to enable 3D height in an otherwise 2D movement system. This data is stored alongside individual maps.
Coordinate System:
- 2D points are represented by $(x, z)$ coordinates.
- The game uses a right-hand rule coordinate system where the Y axis points upwards (representing height).
In-Game Trade Data File Format
mainThenpctradeprocbuild tool consumes in-game trade data via JSON files located atres/npc_trades/<name>.json. Each file represents a single NPC trade event and contains metadata for both the trade event and the Pokémon being received. These JSON fields are mapped directly onto theNPCTradeMonstruct defined ininclude/overlay006/npc_trade.h.Configure Trainer Dialogue Messages
mainThe
messagesarray defines dialogue spoken during battle. Each entry requires atype(fromenum TrainerMessageType, e.g.,TRMSG_PRE_BATTLE,TRMSG_DEFEAT,TRMSG_POST_BATTLE,TRMSG_REMATCH) and anen_USfield.en_UScan be a singlestringor anarray of stringsfor multi-line messages.- Use the
garbagekey instead ofen_USto represent padding present in the retail ROM.
Understand the Dynamic Map Features system
mainDynamic map features allow map layouts to change based on player input. The system relies on two types of data:
- Dynamic map features data (runtime data): Specific to a feature and only available during runtime (e.g., instances of map props used for movable platforms).
- Persisted map features data (persisted data): A 32-byte buffer in the save file used to store state that must survive a save/load cycle (e.g., the position of a platform).
Important Constraints:
- Only one dynamic map feature can be active at any given time across all loaded maps.
- Because of this restriction, the system is primarily used in dungeons or small map matrices (usually 1x1) rather than the overworld.
- This system is intended for layout changes; it does not include simple obstacles like movable boulders or breakable rocks.
Group maps with Areas
mainAn Area is a grouping mechanism for maps. While a map can only belong to one area, a map matrix can contain multiple areas.
Purpose of Areas: Areas group rendering resources that are common to multiple maps to optimize loading. When entering a map within an area, the following are loaded:
- 3D models of map props
- Textures of map props
- Animation data of map props
- Textures of map models
- Lighting configuration
Understand the 2D Rendering and VRAM architecture
mainThe Nintendo DS 2D rendering system uses a layered approach with 8 total layers split across the Main and Sub screens (indices
0through3for each display).Rendering relies on a 656 KB VRAM chunk divided into 9 banks:
- Four 128 KB banks
- One 64 KB bank
- One 32 KB bank
- Three 16 KB banks
Key Constraints:
- The 2D and 3D engines cannot access the same bank concurrently.
- The ARM7 co-processor can only access two of the four 128 KB banks.
- Sprite graphics cannot be stored in the specific section of VRAM used for these banks.
- The main screen cannot access the third 16 KB bank.
Map Data and Map Props
mainThe Map Data archive contains the heavy assets required for rendering and interaction:
- Tile Attributes: Dictates collision and tile behavior (e.g., tall grass, water, trash cans).
- Base 3D Model: Stored in an
NSBMDcontainer. - BDHC Data: Height information.
- Map Props: Instances of 3D models placed on the map. Each prop instance includes:
- 3D model identifier
- Position
- Rotation
- Scale