11#include "yaze_config.h"
16static bool g_library_initialized =
false;
20 if (g_library_initialized) {
25 g_library_initialized =
true;
30 if (!g_library_initialized) {
35 g_library_initialized =
false;
45 return "Unknown error";
47 return "Invalid argument";
49 return "File not found";
51 return "Memory allocation failed";
53 return "I/O operation failed";
55 return "Data corruption detected";
57 return "Component not initialized";
59 return "Unknown status code";
68 if (expected_version ==
nullptr) {
75 if (context ==
nullptr) {
79 if (!g_library_initialized) {
86 context->
rom =
nullptr;
89 if (rom_filename !=
nullptr && strlen(rom_filename) > 0) {
91 if (context->
rom ==
nullptr) {
101 if (context ==
nullptr) {
105 if (context->
rom !=
nullptr) {
107 context->
rom =
nullptr;
115 if (filename ==
nullptr || strlen(filename) == 0) {
119 auto internal_rom = std::make_unique<yaze::Rom>();
120 if (!internal_rom->LoadFromFile(filename).ok()) {
125 auto internal_game_data = std::make_unique<yaze::zelda3::GameData>();
127 if (!load_status.ok()) {
132 rom->filename = filename;
133 rom->impl = internal_rom.release();
134 rom->game_data = internal_game_data.release();
135 rom->data =
const_cast<uint8_t*
>(
static_cast<yaze::Rom*
>(rom->impl)->data());
136 rom->size =
static_cast<yaze::Rom*
>(rom->impl)->size();
138 rom->is_modified =
false;
143 if (rom ==
nullptr) {
147 if (rom->
impl !=
nullptr) {
161 if (rom ==
nullptr || filename ==
nullptr) {
165 if (rom->
impl ==
nullptr) {
171 .
backup =
true, .save_new =
false, .filename = filename});
186 bitmap.
data =
nullptr;
191 int palette_set,
int palette,
194 color_struct.
red = 0;
195 color_struct.
green = 0;
196 color_struct.
blue = 0;
204 color_struct = get_color.rom_color();
213 if (rom->
impl ==
nullptr) {
220 if (!internal_overworld->Load(internal_rom).ok()) {
225 overworld->
impl = internal_overworld;
227 for (
const auto& ow_map : internal_overworld->overworld_maps()) {
229 overworld->
maps[map_id]->
id = map_id;
236 if (rom->
impl ==
nullptr) {
245 int* message_count) {
246 if (rom ==
nullptr || messages ==
nullptr || message_count ==
nullptr) {
250 if (rom->
impl ==
nullptr) {
256 std::vector<yaze::editor::MessageData> message_data =
259 *message_count =
static_cast<int>(message_data.size());
262 for (
size_t i = 0; i < message_data.size(); ++i) {
263 const auto& msg = message_data[i];
264 (*messages)[i].
id = msg.ID;
265 (*messages)[i].rom_address = msg.Address;
266 (*messages)[i].length =
static_cast<uint16_t
>(msg.RawString.length());
269 (*messages)[i].raw_data =
new uint8_t[msg.Data.size()];
270 std::memcpy((*messages)[i].raw_data, msg.Data.data(), msg.Data.size());
272 (*messages)[i].parsed_text =
new char[msg.ContentsParsed.length() + 1];
274 std::memcpy((*messages)[i].parsed_text, msg.ContentsParsed.c_str(),
275 msg.ContentsParsed.length());
276 (*messages)[i].parsed_text[msg.ContentsParsed.length()] =
'\0';
278 (*messages)[i].is_compressed =
false;
279 (*messages)[i].encoding_type = 0;
281 }
catch (
const std::exception& e) {
292 if (bitmap !=
nullptr && bitmap->
data !=
nullptr) {
293 delete[] bitmap->
data;
294 bitmap->
data =
nullptr;
304 if (width <= 0 || height <= 0 ||
305 (bpp != 1 && bpp != 2 && bpp != 4 && bpp != 8)) {
309 bitmap.
width = width;
312 bitmap.
data =
new uint8_t[width * height]();
327 if (r !=
nullptr) *r =
static_cast<uint8_t
>(color.
red);
328 if (g !=
nullptr) *g =
static_cast<uint8_t
>(color.
green);
329 if (b !=
nullptr) *b =
static_cast<uint8_t
>(color.
blue);
334 if (rom_data ==
nullptr || size < 0x100000) {
345 return "US/North American";
363 return &zelda3_us_pointers;
365 return &zelda3_jp_pointers;
367 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)
Represents the full Overworld data, light and dark world.
yaze_status yaze_library_init()
Initialize the YAZE library.
int yaze_get_version_number()
Get the current YAZE version number.
const char * yaze_get_version_string()
Get the current YAZE version string.
yaze_status
Status codes returned by YAZE functions.
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.
yaze_status yaze_init(yaze_editor_context *context, const char *rom_filename)
Initialize a YAZE editor context.
const char * yaze_status_to_string(yaze_status status)
Convert a status code to a human-readable string.
void yaze_library_shutdown()
Shutdown the YAZE library.
@ YAZE_ERROR_FILE_NOT_FOUND
@ YAZE_ERROR_NOT_INITIALIZED
snes_color yaze_rgb_to_snes_color(uint8_t r, uint8_t g, uint8_t b)
Convert RGB888 color to SNES color.
yaze_bitmap yaze_load_bitmap(const char *filename)
Load a bitmap from file.
yaze_bitmap yaze_create_bitmap(int width, int height, uint8_t bpp)
Create an empty bitmap.
void yaze_free_bitmap(yaze_bitmap *bitmap)
Free bitmap data.
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_load_messages(const zelda3_rom *rom, zelda3_message **messages, int *message_count)
Load all text messages from ROM.
zelda3_overworld * yaze_load_overworld(const zelda3_rom *rom)
Load the overworld from ROM.
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.
const char * zelda3_version_to_string(zelda3_version version)
Get version name as string.
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.
zelda3_version zelda3_detect_version(const uint8_t *rom_data, size_t size)
Detect ROM version from header data.
@ ZELDA3_VERSION_RANDOMIZER
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.
#define YAZE_VERSION_NUMBER
#define YAZE_VERSION_STRING
std::vector< MessageData > ReadAllTextData(uint8_t *rom, int pos)
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.
zelda3_dungeon_room * yaze_load_all_rooms(const zelda3_rom *rom)
Yet Another Zelda3 Editor (YAZE) - Public C API.