From a98a58eb4edb8f36e4394d047dd4fad14eb56092 Mon Sep 17 00:00:00 2001 From: The Gears of Progress Date: Sun, 12 Oct 2025 16:41:48 -0400 Subject: [PATCH] Final finishing touches --- include/debug_mode.h | 4 +-- include/pccs/Gen3Pokemon.h | 2 +- include/save_data_manager.h | 1 + source/rom_data.cpp | 18 ++++++++----- source/save_data_manager.cpp | 50 +++++++++++++++++++++++++++++++++--- source/script_array.cpp | 2 +- 6 files changed, 63 insertions(+), 14 deletions(-) diff --git a/include/debug_mode.h b/include/debug_mode.h index bfdcb7a..753096e 100644 --- a/include/debug_mode.h +++ b/include/debug_mode.h @@ -1,14 +1,14 @@ #ifndef DEBUG_MODE_H #define DEBUG_MODE_H -#define VERSION "v1.2.0b" +#define VERSION "v1.2.0" #define PTGB_BUILD_LANGUAGE 2 #define DEBUG_MODE true #define PRINT_LINK_DATA (true && DEBUG_MODE) #define INSTANT_TEXT_SPEED (false && DEBUG_MODE) -#define IGNORE_GAME_PAK (true && DEBUG_MODE) +#define IGNORE_GAME_PAK (false && DEBUG_MODE) #define IGNORE_GAME_PAK_SPRITES (true && DEBUG_MODE) #define IGNORE_LINK_CABLE (true && DEBUG_MODE) #define IGNORE_MG_E4_FLAGS (true && DEBUG_MODE) diff --git a/include/pccs/Gen3Pokemon.h b/include/pccs/Gen3Pokemon.h index a3afd29..63910d3 100644 --- a/include/pccs/Gen3Pokemon.h +++ b/include/pccs/Gen3Pokemon.h @@ -22,7 +22,7 @@ public: Nature internalNature; Gender internalGender; int internalSize; - u32 internalAbility; + int internalAbility; protected: // These store the data bytes diff --git a/include/save_data_manager.h b/include/save_data_manager.h index a94744e..3885bda 100644 --- a/include/save_data_manager.h +++ b/include/save_data_manager.h @@ -29,4 +29,5 @@ bool get_tutorial_flag(); void set_tutorial_flag(bool value); void initalize_save_data(); int get_dex_completion(int gen, bool include_mythicals); +bool check_can_save(); #endif diff --git a/source/rom_data.cpp b/source/rom_data.cpp index 755da4d..ceceb81 100644 --- a/source/rom_data.cpp +++ b/source/rom_data.cpp @@ -3,6 +3,7 @@ #include "pokemon_party.h" #include "pokemon_data.h" #include "text_engine.h" +#include "save_data_manager.h" #include "gba_rom_values/gba_rom_values.h" #include "libraries/nanoprintf/nanoprintf.h" #include "gba_rom_values_eng_lz10_bin.h" @@ -20,8 +21,7 @@ bool rom_data::load_rom() u8 rom_list_buffer[2048]; u32 rom_list_size; const u8 *compressed_rom_list; - const u8* cur; - + const u8 *cur; if (IGNORE_GAME_PAK) { @@ -38,7 +38,7 @@ bool rom_data::load_rom() version = (*(vu8 *)(0x80000BC)); } - switch(language) + switch (language) { case LANG_JPN: compressed_rom_list = gba_rom_values_jpn_lz10_bin; @@ -62,13 +62,19 @@ bool rom_data::load_rom() return false; // Unsupported language } + // Game looks good, let's make sure it can save. + /*if (!check_can_save()) + { + return false; + }*/ + // byte 2-4 of the compressed data store the decompressed size - rom_list_size = compressed_rom_list[1] | (compressed_rom_list[2] << 8) | (compressed_rom_list[3] << 16); - LZ77UnCompWram(compressed_rom_list, rom_list_buffer); + rom_list_size = compressed_rom_list[1] | (compressed_rom_list[2] << 8) | (compressed_rom_list[3] << 16); + LZ77UnCompWram(compressed_rom_list, rom_list_buffer); cur = rom_list_buffer; - while(cur < rom_list_buffer + rom_list_size) + while (cur < rom_list_buffer + rom_list_size) { const ROM_DATA *rom_values = reinterpret_cast(cur); if (rom_values->is_valid && rom_values->gamecode == gamecode && diff --git a/source/save_data_manager.cpp b/source/save_data_manager.cpp index 45acf73..d6c99c3 100644 --- a/source/save_data_manager.cpp +++ b/source/save_data_manager.cpp @@ -6,7 +6,6 @@ #include "pokemon_data.h" #include "libraries/Pokemon-Gen3-to-Gen-X/include/save.h" - byte save_data_array[SAVE_DATA_SIZE]; void load_custom_save_data() @@ -70,14 +69,57 @@ void initalize_save_data() write_custom_save_data(); } -int get_dex_completion(int gen, bool include_mythicals){ +int get_dex_completion(int gen, bool include_mythicals) +{ int stop = (gen == 1 ? 151 : 251); int start = (gen == 1 ? 1 : 152); int count = 0; - for (int i = start; i < stop + include_mythicals; i++){ - if (is_caught(i)){ + for (int i = start; i < stop + include_mythicals; i++) + { + if (is_caught(i)) + { count++; } } return count; +} + +bool check_can_save() +{ + byte data_buffer[8] = {}; + byte test_buffer[8] = {0xC7, 0xCF, 0xCA, 0xCA, 0xBF, 0xCE, 0xA4, 0xBE}; + + // Copy the current bytes and save them to the data buffer, and replace them with the test_buffer + copy_save_to_ram(HALL_OF_FAME + 0x1000, &global_memory_buffer[0], 0x1000); + for (int i = 0; i < 8; i++) + { + data_buffer[i] = global_memory_buffer[HOF_SECTION + i]; + global_memory_buffer[HOF_SECTION + i] = test_buffer[i]; + } + erase_sector(HALL_OF_FAME + 0x1000); + copy_ram_to_save(&global_memory_buffer[0], HALL_OF_FAME + 0x1000, 0x1000); + + // Overwrite the data in the global memory buffer to make sure that it isn't still there when testing + for (int i = 0; i < 8; i++) + { + global_memory_buffer[HOF_SECTION + i] = 0; + } + + // Grab the data again and verify it saved correctly + copy_save_to_ram(HALL_OF_FAME + 0x1000, &global_memory_buffer[0], 0x1000); + for (int i = 0; i < 8; i++) + { + if (global_memory_buffer[HOF_SECTION + i] != test_buffer[i]) + { + // Did not save correctly, return false + return false; + } + // Set the byte in the memory buffer back in preperation for saving it back again + global_memory_buffer[HOF_SECTION + i] = data_buffer[i]; + } + + // Everything saved correctly, save the data back + erase_sector(HALL_OF_FAME + 0x1000); + copy_ram_to_save(&global_memory_buffer[0], HALL_OF_FAME + 0x1000, 0x1000); + return true; } \ No newline at end of file diff --git a/source/script_array.cpp b/source/script_array.cpp index cb735f9..0fbc0ce 100644 --- a/source/script_array.cpp +++ b/source/script_array.cpp @@ -438,7 +438,7 @@ const script_obj_params transfer_script_params[SCRIPT_SIZE] = { { .conditional_index = COND_IS_HOENN_RS, .next_if_true = DIA_SEND_FRIEND_HOENN_RS, - .next_if_false = DIA_SEND_FRIEND_KANTO + .next_if_false = COND_IS_HOENN_E }, // COND_IS_FRLGE {