yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
agent_pretraining.cc
Go to the documentation of this file.
2
3#include "absl/strings/str_format.h"
4#include "app/rom.h"
6
7namespace yaze {
8namespace cli {
9namespace agent {
10
11std::vector<AgentPretraining::KnowledgeModule> AgentPretraining::GetModules() {
12 return {
13 {"rom_structure", GetRomStructureKnowledge(nullptr), true},
14 {"hex_analysis", GetHexAnalysisKnowledge(), true},
15 {"map_editing", GetMapEditingKnowledge(), true},
16 {"tool_usage", GetToolUsageExamples(), true},
17 };
18}
19
21 return R"(
22# ALTTP ROM Structure Deep Dive
23
24## Memory Map
25- 0x00000-0x07FFF: Header + Low ROM
26- 0x08000-0x0FFFF: Character data
27- 0x10000-0x1FFFF: Overworld maps
28- 0x1C800-0x1D7FF: Overworld tile16 data
29- 0x20000-0x2FFFF: Dungeon rooms (296 rooms)
30- 0xDE6C8-0xDEDC7: Overworld palettes
31- 0xDD308-0xDD3C7: Dungeon palettes
32
33## Overworld Structure
34- 64 maps (0x00-0x3F): Light world + Dark world
35- Each map: 32x32 tiles (1024 tile16s)
36- Tile16 address = 0x1C800 + (tile_id * 8 bytes)
37- Map data stored compressed
38
39## Dungeon Structure
40- 296 rooms total (0x00-0x127)
41- Room header: 14 bytes
42- Sprite data: 3 bytes per sprite, up to 16 sprites
43- Layer 1/2 separate data
44- Object encoding: Layer/Size/X/Y format
45
46## Palette System
47- 8 groups, 8 palettes per group
48- 16 colors per palette (SNES 555 format)
49- $0000-$7FFF range (5 bits per R/G/B channel)
50- Conversion: RGB8 = (SNES_val & 0x1F) << 3
51
52## Critical Addresses
53- Sprite sheets: 0x80000+
54- Entrance table: 0x02C000
55- Item table: 0x0DC800
56- Text data: 0x0E0000+
57)";
58}
59
61 return R"(
62# Hex Data Analysis Patterns
63
64## Pattern Recognition
65
66### Sprite Data (3-byte pattern)
67- Byte 0: Sprite ID (0x00-0xFF)
68- Byte 1: X position in room
69- Byte 2: Y position in room
70- Example: "09 48 56" = Sprite 0x09 at (72, 86)
71
72### Tile16 Structure (8 bytes)
73- Bytes 0-1: Top-left tile8
74- Bytes 2-3: Top-right tile8
75- Bytes 4-5: Bottom-left tile8
76- Bytes 6-7: Bottom-right tile8
77- Format: tile8_id (lower byte) + properties (upper byte)
78
79### Pointers (Little Endian)
80- 2-byte pointer: Low byte first, high byte second
81- Example: "00 1C" = 0x1C00 (address 0x001C00)
82- SNES addressing: Add bank byte for 24-bit
83
84## Search Strategies
85
86### Finding Unused Space
87- Pattern: "FF FF FF FF" (often unused)
88- Pattern: "00 00 00 00" (zeroed regions)
89
90### Finding Sprite Definitions
91- Search for known sprite IDs
92- Look for X/Y coordinate patterns (0x00-0x1F typical range)
93
94### Finding Compressed Data
95- Look for compression headers (0xE0-0xFF often signify compression)
96- Data density changes (sparse vs dense byte values)
97)";
98}
99
101 return R"(
102# Map Editing Workflow with Test Harness
103
104## Tile Placement Flow
1051. Parse natural language: "Place water tile at (5, 7)"
1062. Tool chain:
107 a. overworld-find-tile to get water tile ID
108 b. Calculate screen coordinates from game coords
109 c. Generate GUI action: Click(overworld_canvas, x, y)
110 d. Generate GUI action: SelectTile(tile_id)
111 e. Generate GUI action: Click(target_x, target_y)
112
113## Coordinate Systems
114- Game coords: Tile-based (0-31 for 32x32 map)
115- Screen coords: Pixel-based, depends on zoom/scroll
116- Conversion: screen_x = game_x * tile_size * zoom + canvas_offset_x
117
118## GUI Automation Best Practices
119- Always wait for UI updates (Wait(100ms) between actions)
120- Assert widget states before clicking
121- Screenshot before/after for verification
122- Use widget discovery to find exact IDs
123
124## Proposal System Integration
125- Read-only tools: Execute directly
126- Write operations: Submit as proposal first
127- Wait for approval before proceeding
128- Show user what will change (diff view)
129)";
130}
131
132std::string AgentPretraining::GetToolUsageExamples() {
133 return R"(
134# Tool Usage Examples & Chaining
135
136## Example 1: Find and Analyze Sprites
137User: "What enemies are in Hyrule Castle?"
138Tool chain:
1391. resource-search --type=dungeon --query=hyrule
1402. dungeon-list-sprites --dungeon=hyrule_castle
1413. resource-list --type=sprite (to get sprite names)
142Result: "Hyrule Castle (dungeon 0) has 3 guards (sprite 0x41), 2 knights..."
143
144## Example 2: Palette Investigation
145User: "What colors are used for grass?"
146Tool chain:
1471. overworld-find-tile --tile_id=0x20 (grass tile)
1482. palette-get-colors --group=0 --palette=0
1493. palette-analyze --type=palette --id=0/0
150Result: "Grass uses palette 0/0 with colors: light green #98FB98..."
151
152## Example 3: Hex Pattern Search
153User: "Find all chests in the ROM"
154Tool chain:
1551. hex-search --pattern="20 ?? ??" (chest object code 0x20)
1562. For each match, hex-read context bytes
1573. Parse room numbers from addresses
158Result: "Found 50 chests across 30 rooms..."
159
160## Example 4: Complex Edit Planning
161User: "Add a new enemy to room 5"
162Steps:
1631. dungeon-describe-room --room_id=5 (check current sprites)
1642. resource-list --type=sprite (available enemies)
1653. todo-create --title="Add sprite to room 5" --steps="find_sprite,get_coords,write_data"
1664. hex-read --address=<room_5_sprite_addr> (check free slots)
1675. Submit proposal with hex-write
168)";
169}
170
171std::string AgentPretraining::GeneratePretrainingPrompt(Rom* rom) {
172 std::string prompt = "# Agent Pre-Training Session\n\n";
173 prompt += "You are being initialized with deep knowledge about this ROM.\n\n";
174
175 if (rom && rom->is_loaded()) {
176 prompt += absl::StrFormat("## Current ROM: %s\n", rom->title());
177 prompt += absl::StrFormat("Size: %zu bytes\n", rom->size());
178 prompt += absl::StrFormat("Type: %s\n\n", rom->is_expanded() ? "Expanded" : "Vanilla");
179 }
180
181 for (const auto& module : GetModules()) {
182 prompt += absl::StrFormat("## Module: %s\n", module.name);
183 prompt += module.content;
184 prompt += "\n---\n\n";
185 }
186
187 prompt += R"(
188## Your Capabilities After Training
189
190You now understand:
191✓ ROM memory layout and addressing
192✓ How to chain tools for complex analysis
193✓ Hex pattern recognition and data structures
194✓ GUI automation for map editing
195✓ Proposal system for safe ROM modification
196
197**Test your knowledge**: When I ask about sprites, dungeons, or tiles,
198use multiple tools in one response to give comprehensive answers.
199)";
200
201 return prompt;
202}
203
204} // namespace agent
205} // namespace cli
206} // namespace yaze
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
static std::vector< KnowledgeModule > GetModules()
Load all pre-training modules.
static std::string GetHexAnalysisKnowledge()
Get hex data analysis patterns.
static std::string GetMapEditingKnowledge()
Get map editing workflow.
static std::string GetRomStructureKnowledge(Rom *rom)
Get ROM structure explanation.
static std::string GetToolUsageExamples()
Get tool usage examples.
Main namespace for the application.
Treasure chest.
Definition zelda.h:424