13#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";
72 if (expected_version ==
nullptr) {
79 if (context ==
nullptr) {
83 if (!g_library_initialized) {
90 context->
rom =
nullptr;
93 if (rom_filename !=
nullptr && strlen(rom_filename) > 0) {
95 if (context->
rom ==
nullptr) {
105 if (context ==
nullptr) {
109 if (context->
rom !=
nullptr) {
111 context->
rom =
nullptr;
119 if (filename ==
nullptr || strlen(filename) == 0) {
123 auto internal_rom = std::make_unique<yaze::Rom>();
124 if (!internal_rom->LoadFromFile(filename).ok()) {
129 rom->filename = filename;
130 rom->impl = internal_rom.release();
131 rom->data =
const_cast<uint8_t*
>(
static_cast<yaze::Rom*
>(rom->impl)->data());
132 rom->size =
static_cast<yaze::Rom*
>(rom->impl)->size();
134 rom->is_modified =
false;
139 if (rom ==
nullptr) {
143 if (rom->
impl !=
nullptr) {
152 if (rom ==
nullptr || filename ==
nullptr) {
156 if (rom->
impl ==
nullptr) {
162 .
backup =
true, .save_new =
false, .filename = filename});
177 bitmap.
data =
nullptr;
182 int palette_set,
int palette,
185 color_struct.
red = 0;
186 color_struct.
green = 0;
187 color_struct.
blue = 0;
194 ->palette(palette)[color];
195 color_struct = get_color.rom_color();
204 if (rom->
impl ==
nullptr) {
210 if (!internal_overworld->Load(internal_rom).ok()) {
215 overworld->
impl = internal_overworld;
217 for (
const auto& ow_map : internal_overworld->overworld_maps()) {
219 overworld->
maps[map_id]->
id = map_id;
226 if (rom->
impl ==
nullptr) {
235 int* message_count) {
236 if (rom ==
nullptr || messages ==
nullptr || message_count ==
nullptr) {
240 if (rom->
impl ==
nullptr) {
246 std::vector<yaze::editor::MessageData> message_data =
249 *message_count =
static_cast<int>(message_data.size());
252 for (
size_t i = 0; i < message_data.size(); ++i) {
253 const auto& msg = message_data[i];
254 (*messages)[i].
id = msg.ID;
255 (*messages)[i].rom_address = msg.Address;
256 (*messages)[i].length =
static_cast<uint16_t
>(msg.RawString.length());
259 (*messages)[i].raw_data =
new uint8_t[msg.Data.size()];
260 std::memcpy((*messages)[i].raw_data, msg.Data.data(), msg.Data.size());
262 (*messages)[i].parsed_text =
new char[msg.ContentsParsed.length() + 1];
264 std::memcpy((*messages)[i].parsed_text, msg.ContentsParsed.c_str(), msg.ContentsParsed.length());
265 (*messages)[i].parsed_text[msg.ContentsParsed.length()] =
'\0';
267 (*messages)[i].is_compressed =
false;
268 (*messages)[i].encoding_type = 0;
270 }
catch (
const std::exception& e) {
281 if (bitmap !=
nullptr && bitmap->
data !=
nullptr) {
282 delete[] bitmap->
data;
283 bitmap->
data =
nullptr;
293 if (width <= 0 || height <= 0 ||
294 (bpp != 1 && bpp != 2 && bpp != 4 && bpp != 8)) {
298 bitmap.
width = width;
301 bitmap.
data =
new uint8_t[width * height]();
317 *r =
static_cast<uint8_t
>(color.
red);
319 *g =
static_cast<uint8_t
>(color.
green);
321 *b =
static_cast<uint8_t
>(color.
blue);
326 if (rom_data ==
nullptr || size < 0x100000) {
337 return "US/North American";
355 return &zelda3_us_pointers;
357 return &zelda3_jp_pointers;
359 return &zelda3_us_pointers;
The Rom class is used to load, save, and modify Rom data.
auto palette_group() const
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.
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.
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[]
SNES color in 15-bit RGB format (BGR555)
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.