# pret/pokeheartgold architecture

> Architecture diagram of the GitHub repository pret/pokeheartgold, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pret/pokeheartgold
- Repository: https://github.com/pret/pokeheartgold

## Overview

This repository is a work-in-progress disassembly of Pokémon HeartGold and SoulSilver, whose player-facing product is a pair of Pokémon game ROMs. A principal runtime path is player interaction in the field, where the script manager sets up and runs map scripts; those scripts can represent events and lead into game systems such as battles. The tree and excerpts also show battle control, storage, graphics, and several standalone activities. Evidence is uneven: unsampled capabilities are included where the tree supports them, but their runtime connections are not inferred.

Main entry points: [`src/battle/battle_controller_player.c`](https://github.com/pret/pokeheartgold/blob/master/src/battle/battle_controller_player.c) (Player battle control), [`src/script_manager.c`](https://github.com/pret/pokeheartgold/blob/master/src/script_manager.c) (Script manager), [`src/field/field_sprite_manager.c`](https://github.com/pret/pokeheartgold/blob/master/src/field/field_sprite_manager.c) (Field sprites), [`files/fielddata/script/scr_seq`](https://github.com/pret/pokeheartgold/tree/master/files/fielddata/script/scr_seq) (Map event scripts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_field["Field and events"]
  node_script_runtime["Script manager<br/>[script_manager.c]"]
  node_event_data["Map event scripts"]
  node_field_sprites["Field sprites"]
  node_map_props["Map props<br/>[map_prop_manager.c]"]
end

subgraph group_battle["Battle systems"]
  node_battle_controller["Player battle control"]
  node_battle_api["Battle interface"]
  node_battle_system["Battle state<br/>[battle.h]"]
end

subgraph group_activities["Game activities"]
  node_storage[("Pokémon storage")]
  node_pokedex["Pokédex<br/>[ov18_021E8BF4.c]"]
  node_pokeathlon["Pokéathlon"]
  node_voltorb["Voltorb Flip"]
  node_radio["Radio search show"]
  node_communication["Communication club"]
  node_credits["Credits<br/>[credits.c]"]
end

subgraph group_runtime["Runtime services"]
  node_touch["Touch input"]
  node_vram["VRAM transfers"]
  node_frontier_scripts["Frontier scripts"]
end

node_player(("Player"))

node_player -.->|"interacts with"| node_script_runtime
node_script_runtime -->|"loads scripts"| node_event_data
node_battle_controller -->|"uses battle state"| node_battle_system
node_battle_controller -->|"uses controller interface"| node_battle_api
node_field_sprites -.->|"transfers resources"| node_vram

click node_script_runtime "https://github.com/pret/pokeheartgold/blob/master/src/script_manager.c"
click node_event_data "https://github.com/pret/pokeheartgold/tree/master/files/fielddata/script/scr_seq"
click node_field_sprites "https://github.com/pret/pokeheartgold/blob/master/src/field/field_sprite_manager.c"
click node_map_props "https://github.com/pret/pokeheartgold/blob/master/src/field/map_prop_manager.c"
click node_battle_controller "https://github.com/pret/pokeheartgold/blob/master/src/battle/battle_controller_player.c"
click node_battle_api "https://github.com/pret/pokeheartgold/blob/master/include/battle/battle_controller.h"
click node_battle_system "https://github.com/pret/pokeheartgold/blob/master/include/battle/battle.h"
click node_storage "https://github.com/pret/pokeheartgold/blob/master/src/pokemon_storage_system.c"
click node_pokedex "https://github.com/pret/pokeheartgold/blob/master/src/application/pokedex/ov18_021E8BF4.c"
click node_pokeathlon "https://github.com/pret/pokeheartgold/blob/master/src/pokeathlon/pokeathlon_course.c"
click node_voltorb "https://github.com/pret/pokeheartgold/blob/master/src/voltorb_flip/voltorb_flip_tasks.c"
click node_radio "https://github.com/pret/pokeheartgold/blob/master/src/application/pokegear/radio/shows/pokemon_search_party.c"
click node_communication "https://github.com/pret/pokeheartgold/blob/master/src/overlay_03/communication_club.c"
click node_credits "https://github.com/pret/pokeheartgold/blob/master/src/credits/credits.c"
click node_touch "https://github.com/pret/pokeheartgold/blob/master/src/touch_hitbox_controller.c"
click node_vram "https://github.com/pret/pokeheartgold/blob/master/src/vram_transfer_manager.c"
click node_frontier_scripts "https://github.com/pret/pokeheartgold/blob/master/src/frontier/frontier_script_context.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_script_runtime,node_event_data,node_field_sprites,node_map_props toneBlue
class node_battle_controller,node_battle_api,node_battle_system toneAmber
class node_storage,node_pokedex,node_pokeathlon,node_voltorb,node_radio,node_communication,node_credits toneMint
class node_touch,node_vram,node_frontier_scripts toneRose
class node_player toneIndigo
```

## Components

### Field and events

- [Script manager](https://github.com/pret/pokeheartgold/blob/master/src/script_manager.c): `src/script_manager.c`
- [Map event scripts](https://github.com/pret/pokeheartgold/tree/master/files/fielddata/script/scr_seq): `files/fielddata/script/scr_seq`
- [Field sprites](https://github.com/pret/pokeheartgold/blob/master/src/field/field_sprite_manager.c): `src/field/field_sprite_manager.c`
- [Map props](https://github.com/pret/pokeheartgold/blob/master/src/field/map_prop_manager.c): `src/field/map_prop_manager.c`

### Battle systems

- [Player battle control](https://github.com/pret/pokeheartgold/blob/master/src/battle/battle_controller_player.c): `src/battle/battle_controller_player.c`
- [Battle interface](https://github.com/pret/pokeheartgold/blob/master/include/battle/battle_controller.h): `include/battle/battle_controller.h`
- [Battle state](https://github.com/pret/pokeheartgold/blob/master/include/battle/battle.h): `include/battle/battle.h`

### Game activities

- [Pokémon storage](https://github.com/pret/pokeheartgold/blob/master/src/pokemon_storage_system.c): `src/pokemon_storage_system.c`
- [Pokédex](https://github.com/pret/pokeheartgold/blob/master/src/application/pokedex/ov18_021E8BF4.c): `src/application/pokedex/ov18_021E8BF4.c`
- [Pokéathlon](https://github.com/pret/pokeheartgold/blob/master/src/pokeathlon/pokeathlon_course.c): `src/pokeathlon/pokeathlon_course.c`
- [Voltorb Flip](https://github.com/pret/pokeheartgold/blob/master/src/voltorb_flip/voltorb_flip_tasks.c): `src/voltorb_flip/voltorb_flip_tasks.c`
- [Radio search show](https://github.com/pret/pokeheartgold/blob/master/src/application/pokegear/radio/shows/pokemon_search_party.c): `src/application/pokegear/radio/shows/pokemon_search_party.c`
- [Communication club](https://github.com/pret/pokeheartgold/blob/master/src/overlay_03/communication_club.c): `src/overlay_03/communication_club.c`
- [Credits](https://github.com/pret/pokeheartgold/blob/master/src/credits/credits.c): `src/credits/credits.c`

### Runtime services

- [Touch input](https://github.com/pret/pokeheartgold/blob/master/src/touch_hitbox_controller.c): `src/touch_hitbox_controller.c`
- [VRAM transfers](https://github.com/pret/pokeheartgold/blob/master/src/vram_transfer_manager.c): `src/vram_transfer_manager.c`
- [Frontier scripts](https://github.com/pret/pokeheartgold/blob/master/src/frontier/frontier_script_context.c): `src/frontier/frontier_script_context.c`

### Other components

- **Player**

## Connections

- Player → Script manager: interacts with
- Script manager → Map event scripts: loads scripts (evidence: `src/script_manager.c`)
- Player battle control → Battle state: uses battle state (evidence: `src/battle/battle_controller_player.c`)
- Player battle control → Battle interface: uses controller interface (evidence: `src/battle/battle_controller_player.c`)
- Field sprites → VRAM transfers: transfers resources
