13#include "yaze_config.h"
23static bool g_library_initialized =
false;
27 if (g_library_initialized) {
32 g_library_initialized =
true;
37 if (!g_library_initialized) {
42 g_library_initialized =
false;
50 return "Unknown error";
52 return "Invalid argument";
54 return "File not found";
56 return "Memory allocation failed";
58 return "I/O operation failed";
60 return "Data corruption detected";
62 return "Component not initialized";
64 return "Unknown status code";
77 if (expected_version ==
nullptr) {
84 if (context ==
nullptr) {
88 if (!g_library_initialized) {
95 context->
rom =
nullptr;
98 if (rom_filename !=
nullptr && strlen(rom_filename) > 0) {
100 if (context->
rom ==
nullptr) {
110 if (context ==
nullptr) {
114 if (context->
rom !=
nullptr) {
116 context->
rom =
nullptr;
124 if (filename ==
nullptr || strlen(filename) == 0) {
128 auto internal_rom = std::make_unique<yaze::Rom>();
129 if (!internal_rom->LoadFromFile(filename).ok()) {
134 auto internal_game_data = std::make_unique<yaze::zelda3::GameData>();
137 if (!load_status.ok()) {
143 rom->impl = internal_rom.release();
144 rom->game_data = internal_game_data.release();
145 rom->
data =
const_cast<uint8_t*
>(
static_cast<yaze::Rom*
>(rom->impl)->data());
148 rom->is_modified =
false;
153 if (rom ==
nullptr) {
157 if (rom->impl !=
nullptr) {
158 delete static_cast<yaze::Rom*
>(rom->impl);
162 if (rom->game_data !=
nullptr) {
164 rom->game_data =
nullptr;
171 if (rom ==
nullptr || filename ==
nullptr) {
175 if (rom->impl ==
nullptr) {
179 auto* internal_rom =
static_cast<yaze::Rom*
>(rom->impl);
181 .
backup =
true, .save_new =
false, .filename = filename});
187 rom->is_modified =
false;
196 bitmap.
data =
nullptr;
201 int palette_set,
int palette,
204 color_struct.
red = 0;
205 color_struct.
green = 0;
206 color_struct.
blue = 0;
208 if (rom->game_data) {
214 color_struct = get_color.rom_color();
223 if (rom->impl ==
nullptr) {
229 auto internal_overworld =
231 if (!internal_overworld->Load(internal_rom).ok()) {
236 overworld->
impl = internal_overworld;
238 for (
const auto& ow_map : internal_overworld->overworld_maps()) {
240 overworld->
maps[map_id]->
id = map_id;
248 if (room_count !=
nullptr) {
251 if (rom ==
nullptr || rom->impl ==
nullptr) {
255 constexpr int kRoomCount = 256;
257 for (
int i = 0; i < kRoomCount; ++i) {
258 rooms[i].
id =
static_cast<uint16_t
>(i);
260 if (room_count !=
nullptr) {
261 *room_count = kRoomCount;
267 int* message_count) {
268 if (rom ==
nullptr || messages ==
nullptr || message_count ==
nullptr) {
272 if (rom->impl ==
nullptr) {
275 if (rom->
data ==
nullptr ||
281 const int scan_end =
static_cast<int>(std::min<uint64_t>(
282 rom->
size,
static_cast<uint64_t
>(std::numeric_limits<int>::max())));
283 std::vector<yaze::editor::MessageData> message_data =
287 *message_count =
static_cast<int>(message_data.size());
290 for (
size_t i = 0; i < message_data.size(); ++i) {
291 const auto& msg = message_data[i];
292 (*messages)[i].
id = msg.ID;
293 (*messages)[i].rom_address = msg.Address;
294 (*messages)[i].length =
static_cast<uint16_t
>(msg.RawString.length());
297 (*messages)[i].raw_data =
new uint8_t[msg.Data.size()];
298 std::memcpy((*messages)[i].raw_data, msg.Data.data(), msg.Data.size());
300 (*messages)[i].parsed_text =
new char[msg.ContentsParsed.length() + 1];
302 std::memcpy((*messages)[i].parsed_text, msg.ContentsParsed.c_str(),
303 msg.ContentsParsed.length());
304 (*messages)[i].parsed_text[msg.ContentsParsed.length()] =
'\0';
306 (*messages)[i].is_compressed = msg.Data.size() != msg.DataParsed.size();
307 (*messages)[i].encoding_type = 1;
309 }
catch (
const std::exception& e) {
320 if (bitmap !=
nullptr && bitmap->
data !=
nullptr) {
321 delete[] bitmap->
data;
322 bitmap->
data =
nullptr;
332 if (width <= 0 || height <= 0 ||
333 (bpp != 1 && bpp != 2 && bpp != 4 && bpp != 8)) {
337 bitmap.
width = width;
340 bitmap.
data =
new uint8_t[width * height]();
356 *r =
static_cast<uint8_t
>(color.
red);
358 *g =
static_cast<uint8_t
>(color.
green);
360 *b =
static_cast<uint8_t
>(color.
blue);
370 return &zelda3_us_pointers;
372 return &zelda3_jp_pointers;
374 return &zelda3_us_pointers;
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
absl::Status SaveToFile(const SaveSettings &settings)
struct zelda3_overworld_map zelda3_overworld_map
Overworld map data.
struct zelda3_overworld zelda3_overworld
Complete overworld data.
void yaze_unload_rom(zelda3_rom *rom)
Unload and free ROM data.
zelda3_rom * yaze_load_rom(const char *filename)
Load a ROM file.
int yaze_save_rom(zelda3_rom *rom, const char *filename)
Save ROM to file.
struct zelda3_rom zelda3_rom
ROM data structure.
zelda3_version
Different versions of the game supported by YAZE.
const zelda3_version_pointers * zelda3_get_version_pointers(zelda3_version version)
Get version-specific pointers.
#define YAZE_VERSION_NUMBER
#define YAZE_VERSION_STRING
std::vector< MessageData > ReadAllTextData(uint8_t *rom, int pos, int max_pos, bool allow_bank_switch)
constexpr const char * kPaletteGroupAddressesKeys[]
absl::Status LoadGameData(Rom &rom, GameData &data, const LoadOptions &options)
Loads all Zelda3-specific game data from a generic ROM.
SNES color in 15-bit RGB format (BGR555)
PaletteGroup * get_group(const std::string &group_name)
auto palette(int i) const
gfx::PaletteGroupMap palette_groups
const char * error_message
Complete dungeon room data.
In-game text message data.
zelda3_overworld_map ** maps
ROM data pointers for different game versions.
snes_color yaze_rgb_to_snes_color(uint8_t r, uint8_t g, uint8_t b)
Convert RGB888 color to SNES color.
zelda3_overworld * yaze_load_overworld(const zelda3_rom *rom)
Load the overworld from ROM.
yaze_bitmap yaze_load_bitmap(const char *filename)
Load a bitmap from file.
void yaze_library_shutdown()
Shutdown the YAZE library.
yaze_bitmap yaze_create_bitmap(int width, int height, uint8_t bpp)
Create an empty bitmap.
bool yaze_check_version_compatibility(const char *expected_version)
Check if the current YAZE version is compatible with the expected version.
yaze_status yaze_shutdown(yaze_editor_context *context)
Shutdown and clean up a YAZE editor context.
zelda3_dungeon_room * yaze_load_all_rooms(const zelda3_rom *rom, int *room_count)
Load all dungeon rooms from ROM.
yaze_status yaze_init(yaze_editor_context *context, const char *rom_filename)
Initialize a YAZE editor context.
int yaze_get_version_number()
Get the current YAZE version number.
snes_color yaze_get_color_from_paletteset(const zelda3_rom *rom, int palette_set, int palette, int color)
Get a color from a palette set.
const char * yaze_get_version_string()
Get the current YAZE version string.
void yaze_free_bitmap(yaze_bitmap *bitmap)
Free bitmap data.
yaze_status yaze_load_messages(const zelda3_rom *rom, zelda3_message **messages, int *message_count)
Load all text messages from ROM.
void yaze_snes_color_to_rgb(snes_color color, uint8_t *r, uint8_t *g, uint8_t *b)
Convert SNES color to RGB888.
yaze_status yaze_library_init()
Initialize the YAZE library.
const char * yaze_status_to_string(yaze_status status)
Convert a status code to a human-readable string.
Public YAZE API umbrella header.
Core initialization and editor context for the YAZE public API.
Status codes and error helpers for the YAZE public API.
yaze_status
Status codes returned by YAZE functions.
@ YAZE_ERROR_FILE_NOT_FOUND
@ YAZE_ERROR_NOT_INITIALIZED
The Legend of Zelda: A Link to the Past - Data Structures and Constants.