diff options
author | kipcode66 <kipcode66@gmail.com> | 2021-10-02 14:17:07 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-02 14:17:07 -0400 |
commit | 60e1313296846697b0221e38abbe025cf533897c (patch) | |
tree | c06d8b16787503e2d0b506b66e9f6dcf9fdaa454 | |
parent | cc2199daec548f535142f7c4649b765dcaed0b76 (diff) |
Hotfix wii (#51)0.4
* hotfix: deletion
* fixed wii
* added wii nand support
* updated submodules version
* fixed setWaterDropColor crash
* fixed bit indicator
* formating
* updated README.md
* updated submodules
* Fixed hook for wii
* clang forma
* formatting
* formatting
* formatting (final)
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md | 7 | ||||
m--------- | external/gcn_c | 0 | ||||
m--------- | external/libtp_c | 0 | ||||
-rw-r--r-- | include/utils/card.h | 20 | ||||
-rw-r--r-- | src/bit.cpp | 9 | ||||
-rw-r--r-- | src/corotdcheck.cpp | 30 | ||||
-rw-r--r-- | src/menus/actor_spawner_menu.cpp | 40 | ||||
-rw-r--r-- | src/menus/memfiles_menu.cpp | 27 | ||||
-rw-r--r-- | src/menus/settings_menu.cpp | 52 | ||||
-rw-r--r-- | src/save_manager.cpp | 17 | ||||
-rw-r--r-- | src/utils/card.cpp | 189 | ||||
-rw-r--r-- | src/utils/hook.cpp | 2 |
13 files changed, 229 insertions, 166 deletions
@@ -4,7 +4,7 @@ .SUFFIXES: #--------------------------------------------------------------------------------- ifeq ($(strip $(DEVKITPPC)),) -$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPro/devkitPPC) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPro/devkitPPC") endif PLATFORM := $(if $(PLATFORM),$(PLATFORM),GCN) @@ -24,11 +24,12 @@ cheats menu: - invincible // Makes Link invincible (no hurtbox, but can still take fall damage and drown) - invincible enemies // Makes some enemies invincible (infinite health) - moon jump // Hold R+A to moon jump -- door storage // Can walk through most objects/walls +- disable walls // Can walk through most objects/walls - super clawshot // Clawshot is long, fast, and can grab most things - unrestricted items // Link can use any item anywhere - transform anywhere // Link can transform into/from wolf anywhere - super spinner (TBD) // Spinner is very fast and can hover (not implemented yet) +- gale LJA (Wii only) // Link can yeet everywhere flags menu: - general flags // Toggle various general flags @@ -66,6 +67,7 @@ inventory menu: memory menu: - watches // Add memory watches to the screen - editor // Browse and edit the memory +- mem files // Basic custom save files. practice menu: - Load practice files* (supports popular Any%, 100%, and All Dungeons locations) @@ -88,12 +90,15 @@ settings menu: - menu position // Changes the position of various menus and tools from TPGZ - save card // Save settings to memory card - load card // Load settings from memory card +- delete card // Delete settings from memory card tools menu: - area reload // Use L+R+Start+A to reload current area - fast bonk recovery // Reduces bonk animation significantly - fast movement // Link's movement is much faster - gorge checker // Use L+Z to warp to Kakariko Gorge +- bit checker (Wii only) // Show when to press Home for BiT +- coro td checker // Show frame info when doing coro td - input viewer // Show current inputs - link debug info // Show Link's position, angle, and speed - no sinking in sand // Link won't sink in sand diff --git a/external/gcn_c b/external/gcn_c -Subproject 65dae72e1ee0ad38bdef3186e3e5991f9166436 +Subproject de3d9346e2601c34b1c5a51ced6493cd0c74eff diff --git a/external/libtp_c b/external/libtp_c -Subproject a9500da50d3cae4b0dd8efb634cc8fbb5619c61 +Subproject 6d8ea305a582d9b49d97d1a0da5697313fe23bd diff --git a/include/utils/card.h b/include/utils/card.h index 74540fb..4e74bda 100644 --- a/include/utils/card.h +++ b/include/utils/card.h @@ -1,19 +1,17 @@ #include "font.h" -#include "gcn_c/include/card.h" +#include "gcn_c/include/storage.h" #include "menu.h" extern bool inject_memfile_flag; namespace Utilities { -int32_t card_write(CardInfo* card_info, void* data, int32_t size, int32_t offset, - int32_t sector_size); -int32_t card_read(CardInfo* card_info, void* data, int32_t size, int32_t offset, - int32_t sector_size); -void store_mem_card(Card& card); -void store_memfile(Card& card); -void delete_mem_card(Card& card); -void delete_memfile(Card& card); -void load_mem_card(Card& card); -void load_memfile(Card& card); +int32_t storage_write(Storage* info, void* data, int32_t size, int32_t offset, int32_t sector_size); +int32_t storage_read(Storage* info, void* data, int32_t size, int32_t offset, int32_t sector_size); +void store_mem_card(Storage& card); +void store_memfile(Storage& card); +void delete_mem_card(Storage& card); +void delete_memfile(Storage& card); +void load_mem_card(Storage& card); +void load_memfile(Storage& card); void load_gz_card(bool& card_load); } // namespace Utilities
\ No newline at end of file diff --git a/src/bit.cpp b/src/bit.cpp index 13293e2..1b63ab9 100644 --- a/src/bit.cpp +++ b/src/bit.cpp @@ -6,9 +6,9 @@ #include "libtp_c/include/f_op/f_op_draw_tag.h" #include "libtp_c/include/f_op/f_op_scene_req.h" #include "libtp_c/include/msl_c/string.h" +#include "libtp_c/include/m_Do/m_Do_audio.h" #include "fifo_queue.h" #include "controller.h" -#include "fifo_queue.h" #include "fs.h" #include "font.h" @@ -19,6 +19,8 @@ #define BOOTS_TERM_VEL -300.0 #define TARGET_FRAME 28 +#define LAST_Y_GROUND_POS (*(float*)(tp_zelAudio.link_debug_ptr + 0x2f3c)) + bool inject_bit_flag = false; extern Font font; @@ -37,13 +39,14 @@ void set_camera_angle_position() { void run() { double dt = 0; - if (dComIfGp_getPlayer()) { + if (dComIfGp_getPlayer() && tp_zelAudio.link_debug_ptr) { const bool has_boots = (dComIfGp_getPlayer()->mNoResetFlg0 & 0x02) != 0; const double term_vel = has_boots ? BOOTS_TERM_VEL : NORMAL_TERM_VEL; const double acc = has_boots ? BOOTS_ACC : NORMAL_ACC; const double v_y1 = dComIfGp_getPlayer()->mSpeed.y; const double dist_from_last_ground = - (dComIfGp_getPlayer()->mCurrent.mPosition.y - dComIfGp_getPlayer()->field_0x33c8); + (dComIfGp_getPlayer()->mCurrent.mPosition.y - + LAST_Y_GROUND_POS); // dComIfGp_getPlayer()->field_0x33c8 // Calculate how many frames before reaching terminal velocity double dt_1 = (term_vel - v_y1) / acc; diff --git a/src/corotdcheck.cpp b/src/corotdcheck.cpp index 8b28718..32847cf 100644 --- a/src/corotdcheck.cpp +++ b/src/corotdcheck.cpp @@ -8,6 +8,21 @@ #include "libtp_c/include/SSystem/SComponent/c_counter.h" #include "libtp_c/include/f_op/f_op_scene_req.h" +#ifdef GCN_PLATFORM +#define ITEM_BUTTON_HELD_CHECK (!button_is_held(Pad::Y) || !button_is_held(Pad::X)) +#define ITEM_BUTTON_DOWN_CHECK (button_is_down(Pad::Y) || button_is_down(Pad::X)) +#define PAD Pad +#endif // GCN_PLATFORM +#ifdef WII_PLATFORM +#define ITEM_BUTTON_HELD_CHECK \ + (!button_is_held(Mote::B) || !button_is_held(Mote::DPAD_LEFT) || \ + !button_is_held(Mote::DPAD_RIGHT) || !button_is_held(Mote::DPAD_DOWN)) +#define ITEM_BUTTON_DOWN_CHECK \ + (button_is_down(Mote::B) || button_is_down(Mote::DPAD_LEFT) || \ + button_is_down(Mote::DPAD_RIGHT) || button_is_down(Mote::DPAD_DOWN)) +#define PAD Mote +#endif // WII_PLATFORM + namespace CoroTDChecker { using namespace Controller; @@ -24,7 +39,7 @@ void run() { start_timer = false; } - if (start_timer == false && button_is_down(Pad::A) && + if (start_timer == false && button_is_down(PAD::A) && tp_strcmp((const char*)g_dComIfG_gameInfo.play.mStartStage.mStage, "F_SP108") == 0) { start_timer = true; } @@ -34,24 +49,23 @@ void run() { if (current_counter < 20) { // went early - if (!got_it && (!button_is_held(Pad::Y) || !button_is_held(Pad::X)) && - (current_counter < 10) && (button_is_down(Pad::Y) || button_is_down(Pad::X))) { + if (!got_it && ITEM_BUTTON_HELD_CHECK && (current_counter < 10) && + ITEM_BUTTON_DOWN_CHECK) { int final_val = 10 - current_counter; tp_sprintf(buf, "%df early", final_val); FIFOQueue::push(buf, Queue, 0x0000FF00); } // got it - else if (!got_it && (!button_is_held(Pad::Y) || !button_is_held(Pad::X)) && - (current_counter == 10) && - (button_is_down(Pad::Y) || button_is_down(Pad::X))) { + else if (!got_it && ITEM_BUTTON_HELD_CHECK && (current_counter == 10) && + ITEM_BUTTON_DOWN_CHECK) { FIFOQueue::push("got it", Queue, 0x00CC0000); got_it = true; } // went late - else if (!got_it && (!button_is_held(Pad::Y) || !button_is_held(Pad::X)) && - current_counter > 10 && (button_is_down(Pad::Y) || button_is_down(Pad::X))) { + else if (!got_it && ITEM_BUTTON_HELD_CHECK && current_counter > 10 && + ITEM_BUTTON_DOWN_CHECK) { int final_val = current_counter - 10; tp_sprintf(buf, "%df late", final_val); FIFOQueue::push(buf, Queue, 0x99000000); diff --git a/src/menus/actor_spawner_menu.cpp b/src/menus/actor_spawner_menu.cpp index 4a6195d..5889c3c 100644 --- a/src/menus/actor_spawner_menu.cpp +++ b/src/menus/actor_spawner_menu.cpp @@ -9,6 +9,22 @@ #include "libtp_c/include/f_op/f_op_actor_mng.h" #define LINES 4 +#ifdef GCN_PLATFORM +#define CONTROLLER_RIGHT Controller::Pad::DPAD_RIGHT +#define CONTROLLER_LEFT Controller::Pad::DPAD_LEFT +#define CONTROLLER_UP Controller::Pad::DPAD_UP +#define CONTROLLER_DOWN Controller::Pad::DPAD_DOWN +#define CONTROLLER_SKIP_10 Controller::Pad::X +#define CONTROLLER_SKIP_MINUS_10 Controller::Pad::Y +#endif +#ifdef WII_PLATFORM +#define CONTROLLER_RIGHT Controller::Mote::DPAD_RIGHT +#define CONTROLLER_LEFT Controller::Mote::DPAD_LEFT +#define CONTROLLER_UP Controller::Mote::DPAD_UP +#define CONTROLLER_DOWN Controller::Mote::DPAD_DOWN +#define CONTROLLER_SKIP_10 Controller::Mote::ONE +#define CONTROLLER_SKIP_MINUS_10 Controller::Mote::TWO +#endif static Cursor cursor = {0, 0}; bool lock_cursor_y = false; @@ -78,25 +94,25 @@ void ActorSpawnMenu::render() { switch (cursor.y) { case ACTOR_ID_INDEX: { - if (Controller::button_is_pressed(Controller::Pad::DPAD_RIGHT)) { + if (Controller::button_is_pressed(CONTROLLER_RIGHT)) { actor_id++; - } else if (Controller::button_is_pressed(Controller::Pad::DPAD_LEFT)) { + } else if (Controller::button_is_pressed(CONTROLLER_LEFT)) { actor_id--; - } else if (Controller::button_is_pressed(Controller::Pad::X)) { + } else if (Controller::button_is_pressed(CONTROLLER_SKIP_10)) { actor_id += 10; - } else if (Controller::button_is_pressed(Controller::Pad::Y)) { + } else if (Controller::button_is_pressed(CONTROLLER_SKIP_MINUS_10)) { actor_id -= 10; } break; } case ACTOR_SUBTYPE_INDEX: { - if (Controller::button_is_pressed(Controller::Pad::DPAD_RIGHT)) { + if (Controller::button_is_pressed(CONTROLLER_RIGHT)) { actor_type++; - } else if (Controller::button_is_pressed(Controller::Pad::DPAD_LEFT)) { + } else if (Controller::button_is_pressed(CONTROLLER_LEFT)) { actor_type--; - } else if (Controller::button_is_pressed(Controller::Pad::X)) { + } else if (Controller::button_is_pressed(CONTROLLER_SKIP_10)) { actor_type += 10; - } else if (Controller::button_is_pressed(Controller::Pad::Y)) { + } else if (Controller::button_is_pressed(CONTROLLER_SKIP_MINUS_10)) { actor_type -= 10; } break; @@ -106,21 +122,21 @@ void ActorSpawnMenu::render() { char buf[9]; tp_sprintf(buf, "%08X", actor_params); if (params_selected) { - if (Controller::button_is_pressed(Controller::Pad::DPAD_RIGHT)) { + if (Controller::button_is_pressed(CONTROLLER_RIGHT)) { if (param_index == 7) { param_index = 0; } else if (param_index >= 0 && param_index < 8) { param_index++; } } - if (Controller::button_is_pressed(Controller::Pad::DPAD_LEFT)) { + if (Controller::button_is_pressed(CONTROLLER_LEFT)) { if (param_index == 0) { param_index = 7; } else if (param_index >= 0 && param_index < 8) { param_index--; } } - if (Controller::button_is_pressed(Controller::Pad::DPAD_UP)) { + if (Controller::button_is_pressed(CONTROLLER_UP)) { switch (param_index) { case 0: { actor_params += 0x10000000; @@ -156,7 +172,7 @@ void ActorSpawnMenu::render() { } } } - if (Controller::button_is_pressed(Controller::Pad::DPAD_DOWN)) { + if (Controller::button_is_pressed(CONTROLLER_DOWN)) { switch (param_index) { case 0: { actor_params -= 0x10000000; diff --git a/src/menus/memfiles_menu.cpp b/src/menus/memfiles_menu.cpp index fde22bb..50b73cc 100644 --- a/src/menus/memfiles_menu.cpp +++ b/src/menus/memfiles_menu.cpp @@ -1,6 +1,5 @@ #include "menus/memfiles_menu.h" #include "controller.h" -#include "gcn_c/include/card.h" #include "font.h" #include "utils/card.h" #include "libtp_c/include/msl_c/string.h" @@ -86,40 +85,48 @@ void MemfilesMenu::render() { if (current_input == SELECTION_BUTTON && a_held == false) { switch (cursor.y) { case MEMFILE_SAVE_INDEX: { - static Card card; + static Storage card; tp_sprintf(fileBuf, "tpgz_s%d", file_no); card.file_name = fileBuf; card.sector_size = SECTOR_SIZE; tp_sprintf(card.file_name_buffer, card.file_name); - card.card_result = CARDProbeEx(0, nullptr, &card.sector_size); - if (card.card_result == Ready) { +#ifndef WII_PLATFORM + card.result = CARDProbeEx(0, nullptr, &card.sector_size); + if (card.result == Ready) { Utilities::store_memfile(card); } +#endif // WII_PLATFORM + Utilities::store_memfile(card); save_delay = 20; break; } case MEMFILE_LOAD_INDEX: { - static Card card; + static Storage card; tp_sprintf(fileBuf, "tpgz_s%d", file_no); card.file_name = fileBuf; card.sector_size = SECTOR_SIZE; tp_sprintf(card.file_name_buffer, card.file_name); - card.card_result = CARDProbeEx(0, NULL, &card.sector_size); - if (card.card_result == Ready) { +#ifndef WII_PLATFORM + card.result = CARDProbeEx(0, NULL, &card.sector_size); + if (card.result == Ready) { Utilities::load_memfile(card); } +#endif // WII_PLATFORM break; } case MEMFILE_DELETE_INDEX: { - static Card card; + static Storage card; tp_sprintf(fileBuf, "tpgz_s%d", file_no); card.file_name = fileBuf; card.sector_size = SECTOR_SIZE; tp_sprintf(card.file_name_buffer, card.file_name); - card.card_result = CARDProbeEx(0, nullptr, &card.sector_size); - if (card.card_result == Ready) { +#ifndef WII_PLATFORM + card.result = CARDProbeEx(0, nullptr, &card.sector_size); + if (card.result == Ready) { Utilities::delete_memfile(card); } +#endif // WII_PLATFORM + Utilities::delete_memfile(card); save_delay = 20; break; } diff --git a/src/menus/settings_menu.cpp b/src/menus/settings_menu.cpp index 038cca2..6a57854 100644 --- a/src/menus/settings_menu.cpp +++ b/src/menus/settings_menu.cpp @@ -1,6 +1,5 @@ #include "menus/settings_menu.h" #include "controller.h" -#include "gcn_c/include/card.h" #include "libtp_c/include/msl_c/string.h" #include "utils/card.h" #include "utils/cursor.h" @@ -72,36 +71,45 @@ void SettingsMenu::render() { return; }; case SAVE_CARD_INDEX: { - static Card card; - card.file_name = "tpgz01"; - card.sector_size = SECTOR_SIZE; - tp_sprintf(card.file_name_buffer, card.file_name); - card.card_result = CARDProbeEx(0, nullptr, &card.sector_size); - if (card.card_result == Ready) { - Utilities::store_mem_card(card); + static Storage storage; + storage.file_name = "tpgz01"; + storage.sector_size = SECTOR_SIZE; + tp_sprintf(storage.file_name_buffer, storage.file_name); +#ifndef WII_PLATFORM + storage.result = CARDProbeEx(0, nullptr, &storage.sector_size); + if (storage.result == Ready) { + Utilities::store_mem_card(storage); } +#endif // WII_PLATFORM + Utilities::store_mem_card(storage); break; }; case LOAD_CARD_INDEX: { - static Card card; - card.file_name = "tpgz01"; - card.sector_size = SECTOR_SIZE; - tp_sprintf(card.file_name_buffer, card.file_name); - card.card_result = CARDProbeEx(0, NULL, &card.sector_size); - if (card.card_result == Ready) { - Utilities::load_mem_card(card); + static Storage storage; + storage.file_name = "tpgz01"; + storage.sector_size = SECTOR_SIZE; + tp_sprintf(storage.file_name_buffer, storage.file_name); +#ifndef WII_PLATFORM + storage.result = CARDProbeEx(0, NULL, &storage.sector_size); + if (storage.result == Ready) { + Utilities::load_mem_card(storage); } +#endif // WII_PLATFORM + Utilities::load_mem_card(storage); break; }; case DELETE_CARD_INDEX: { - static Card card; - card.file_name = "tpgz01"; - card.sector_size = SECTOR_SIZE; - tp_sprintf(card.file_name_buffer, card.file_name); - card.card_result = CARDProbeEx(0, nullptr, &card.sector_size); - if (card.card_result == Ready) { - Utilities::delete_mem_card(card); + static Storage storage; + storage.file_name = "tpgz01"; + storage.sector_size = SECTOR_SIZE; + tp_sprintf(storage.file_name_buffer, storage.file_name); +#ifndef WII_PLATFORM + storage.result = CARDProbeEx(0, nullptr, &storage.sector_size); + if (storage.result == Ready) { + Utilities::delete_mem_card(storage); } +#endif // WII_PLATFORM + Utilities::delete_mem_card(storage); break; }; case SWAP_EQUIPS_INDEX: { diff --git a/src/save_manager.cpp b/src/save_manager.cpp index a8fc30a..b2b71fe 100644 --- a/src/save_manager.cpp +++ b/src/save_manager.cpp @@ -75,6 +75,18 @@ void SaveManager::inject_default_during() { } #endif // add wii swap equip logic here later +#ifdef WII_PLATFORM + if (g_swap_equips_flag) { + uint8_t tmp = dComIfGs_getSelectItemIndex(SELECT_ITEM_LEFT); + uint8_t tmp_mix = dComIfGs_getMixItemIndex(SELECT_ITEM_LEFT); + + dComIfGs_setSelectItemIndex(SELECT_ITEM_LEFT, + dComIfGs_getSelectItemIndex(SELECT_ITEM_RIGHT)); + dComIfGs_setSelectItemIndex(SELECT_ITEM_RIGHT, tmp); + dComIfGs_setMixItemIndex(SELECT_ITEM_LEFT, dComIfGs_getMixItemIndex(SELECT_ITEM_RIGHT)); + dComIfGs_setMixItemIndex(SELECT_ITEM_RIGHT, tmp_mix); + } +#endif } void SaveManager::inject_default_after() {} @@ -159,10 +171,13 @@ void SaveManager::load_save_file(const char* fileName) { #define SET_WATER_DROP_COLOR_BL ((uint32_t*)0x800C3DD4) #endif +uint32_t setWaterDropColorInstr = 0x60000000; + void SaveManager::trigger_load() { // Loading hasn't started yet, run the before load function and initiate loading if (!tp_fopScnRq.isLoading && !gSaveManager.loading_initiated) { // Patch out setWaterDropColor call temporarily (prevents a crash in some scenarios) + setWaterDropColorInstr = *reinterpret_cast<uint32_t*>(SET_WATER_DROP_COLOR_BL); *reinterpret_cast<uint32_t*>(SET_WATER_DROP_COLOR_BL) = 0x60000000; // nop DCFlushRange((void*)(SET_WATER_DROP_COLOR_BL), sizeof(uint32_t)); ICInvalidateRange((void*)(SET_WATER_DROP_COLOR_BL), sizeof(uint32_t)); @@ -185,7 +200,7 @@ void SaveManager::trigger_load() { if (!tp_fopScnRq.isLoading) { // Patch back in setWaterDropColor call *reinterpret_cast<uint32_t*>(SET_WATER_DROP_COLOR_BL) = - 0x4BFFF55D; // bl daAlink_c::setWaterDropColor + setWaterDropColorInstr; // bl daAlink_c::setWaterDropColor DCFlushRange((void*)(SET_WATER_DROP_COLOR_BL), sizeof(uint32_t)); ICInvalidateRange((void*)(SET_WATER_DROP_COLOR_BL), sizeof(uint32_t)); diff --git a/src/utils/card.cpp b/src/utils/card.cpp index 45f0ff1..bf1ac25 100644 --- a/src/utils/card.cpp +++ b/src/utils/card.cpp @@ -19,21 +19,21 @@ namespace Utilities { /** * @brief Like CARDWrite, but allows for arbitrary sizes and offsets. */ -int32_t card_write(CardInfo* card_info, void* data, int32_t size, int32_t offset, - int32_t sector_size) { +int32_t storage_write(Storage* storage, void* data, int32_t size, int32_t offset, + int32_t sector_size) { uint8_t* buf = (uint8_t*)tp_memalign(-32, sector_size); int32_t result = Ready; int32_t read_bytes = 0; while (result == Ready && size > 0) { - result = CARDRead(card_info, buf, sector_size, (offset & ~(sector_size - 1))); + StorageRead(*storage, buf, sector_size, (offset & ~(sector_size - 1))); if (result != Ready) { break; } int32_t rem_size = sector_size - (offset & (sector_size - 1)); tp_memcpy(buf + (offset & (sector_size - 1)), (void*)((uint32_t)data + read_bytes), MIN(rem_size, size)); - result = CARDWrite(card_info, buf, sector_size, (offset & ~(sector_size - 1))); + StorageWrite(*storage, buf, sector_size, (offset & ~(sector_size - 1))); read_bytes += MIN(rem_size, size); size -= rem_size; offset += rem_size; @@ -45,14 +45,14 @@ int32_t card_write(CardInfo* card_info, void* data, int32_t size, int32_t offset /** * @brief Like CARDRead, but allows for arbitrary sizes and offsets. */ -int32_t card_read(CardInfo* card_info, void* data, int32_t size, int32_t offset, - int32_t sector_size) { +int32_t storage_read(Storage* storage, void* data, int32_t size, int32_t offset, + int32_t sector_size) { uint8_t* buf = (uint8_t*)tp_memalign(-32, sector_size); int32_t result = Ready; int32_t read_bytes = 0; while (result == Ready && size > 0) { - result = CARDRead(card_info, buf, sector_size, (offset & ~(sector_size - 1))); + StorageRead(*storage, buf, sector_size, (offset & ~(sector_size - 1))); if (result != Ready) { break; } @@ -122,7 +122,7 @@ void setup_save_file(GZSaveFile& save_file) { #undef set_entry } -int32_t read_save_file(CardInfo* card_info, GZSaveFile& save_file, int32_t sector_size) { +int32_t read_save_file(Storage* storage, GZSaveFile& save_file, int32_t sector_size) { int32_t result = Ready; #define assert_result(stmt) \ if ((result = (stmt)) != Ready) { \ @@ -131,22 +131,22 @@ int32_t read_save_file(CardInfo* card_info, GZSaveFile& save_file, int32_t secto uint32_t pos = 0; assert_result( - card_read(card_info, &save_file.header, sizeof(save_file.header), pos, sector_size)); + storage_read(storage, &save_file.header, sizeof(save_file.header), pos, sector_size)); pos += sizeof(save_file.header); if (save_file.header.version != GZ_SAVE_VERSION_NUMBER) { return -30; // Custom error code for "Version" (means a mismatch in the version number). } - assert_result(card_read(card_info, save_file.offsets, - save_file.header.entries * sizeof(save_file.offsets[0]), - save_file.header.offsetsLoc, sector_size)); - assert_result(card_read(card_info, save_file.sizes, - save_file.header.entries * sizeof(save_file.sizes[0]), - save_file.header.sizesLoc, sector_size)); + assert_result(storage_read(storage, save_file.offsets, + save_file.header.entries * sizeof(save_file.offsets[0]), + save_file.header.offsetsLoc, sector_size)); + assert_result(storage_read(storage, save_file.sizes, + save_file.header.entries * sizeof(save_file.sizes[0]), + save_file.header.sizesLoc, sector_size)); #define assert_read_entry(idx, ptr, size) \ if (idx < save_file.header.entries) { \ - assert_result(card_read(card_info, ptr, MIN(size, save_file.sizes[idx]), \ - save_file.offsets[idx], sector_size)); \ + assert_result(storage_read(storage, ptr, MIN(size, save_file.sizes[idx]), \ + save_file.offsets[idx], sector_size)); \ } assert_read_entry(SV_CHEATS_INDEX, save_file.data.CheatItems, sizeof(save_file.data.CheatItems)); @@ -170,149 +170,132 @@ int32_t read_save_file(CardInfo* card_info, GZSaveFile& save_file, int32_t secto return result; } -int32_t read_memfile(CardInfo* card_info, PositionData& posData, int32_t sector_size) { +int32_t read_memfile(Storage* storage, PositionData& posData, int32_t sector_size) { int32_t result = Ready; #define assert_result(stmt) \ if ((result = (stmt)) != Ready) { \ return result; \ } - assert_result(card_read(card_info, (void*)sTmpBuf, sizeof(dSv_info_c), 0, sector_size)); + assert_result(storage_read(storage, (void*)sTmpBuf, sizeof(dSv_info_c), 0, sector_size)); assert_result( - card_read(card_info, &posData, sizeof(posData), sizeof(dSv_info_c) + 1, sector_size)); + storage_read(storage, &posData, sizeof(posData), sizeof(dSv_info_c) + 1, sector_size)); #undef assert_result return result; } -void store_mem_card(Card& card) { -#ifndef WII_PLATFORM +void store_mem_card(Storage& storage) { GZSaveFile save_file; Utilities::setup_save_file(save_file); Utilities::store_save_layout(save_file.data); - uint32_t file_size = (uint32_t)(tp_ceil((double)sizeof(save_file) / (double)card.sector_size) * - card.sector_size); - card.card_result = CARDDelete(0, card.file_name_buffer); - card.card_result = CARDCreate(0, card.file_name_buffer, file_size, &card.card_info); - if (card.card_result == Ready || card.card_result == Exist) { - card.card_result = CARDOpen(0, card.file_name_buffer, &card.card_info); - if (card.card_result == Ready) { - card.card_result = Utilities::card_write(&card.card_info, &save_file, sizeof(save_file), - 0, card.sector_size); - if (card.card_result == Ready) { + uint32_t file_size = (uint32_t)( + tp_ceil((double)sizeof(save_file) / (double)storage.sector_size) * storage.sector_size); + storage.result = StorageDelete(0, storage.file_name_buffer); + storage.result = StorageCreate(0, storage.file_name_buffer, file_size, &storage.info); + if (storage.result == Ready || storage.result == Exist) { + storage.result = StorageOpen(0, storage.file_name_buffer, &storage.info, OPEN_MODE_RW); + if (storage.result == Ready) { + storage.result = Utilities::storage_write(&storage, &save_file, sizeof(save_file), 0, + storage.sector_size); + if (storage.result == Ready) { tp_osReport("saved card!"); FIFOQueue::push("saved card!", Queue); } else { tp_osReport("failed to save"); char buff[32]; - tp_sprintf(buff, "failed to save: %d", card.card_result); + tp_sprintf(buff, "failed to save: %d", storage.result); FIFOQueue::push(buff, Queue); } - card.card_result = CARDClose(&card.card_info); + storage.result = StorageClose(&storage.info); } } -#endif } -void store_memfile(Card& card) { -#ifndef WII_PLATFORM +void store_memfile(Storage& storage) { PositionData posData; posData.link = dComIfGp_getPlayer()->mCurrent.mPosition; posData.cam.target = tp_matrixInfo.matrix_info->target; posData.cam.pos = tp_matrixInfo.matrix_info->pos; posData.angle = dComIfGp_getPlayer()->mCollisionRot.mY; + uint32_t file_size = (uint32_t)( + tp_ceil((double)sizeof(dSv_info_c) / (double)storage.sector_size) * storage.sector_size); - uint32_t file_size = (uint32_t)(tp_ceil((double)sizeof(dSv_info_c) / (double)card.sector_size) * - card.sector_size); - - card.card_result = CARDDelete(0, card.file_name_buffer); - card.card_result = CARDCreate(0, card.file_name_buffer, file_size, &card.card_info); + storage.result = StorageDelete(0, storage.file_name_buffer); + storage.result = StorageCreate(0, storage.file_name_buffer, file_size, &storage.info); - if (card.card_result == Ready || card.card_result == Exist) { - card.card_result = CARDOpen(0, card.file_name_buffer, &card.card_info); - if (card.card_result == Ready) { + if (storage.result == Ready || storage.result == Exist) { + storage.result = StorageOpen(0, storage.file_name_buffer, &storage.info, OPEN_MODE_RW); + if (storage.result == Ready) { dComIfGs_putSave(g_dComIfG_gameInfo.info.mDan.mStageNo); + setReturnPlace(g_dComIfG_gameInfo.play.mStartStage.mStage, g_dComIfG_gameInfo.play.mEvent.field_0x12c, 0); - card.card_result = Utilities::card_write(&card.card_info, &g_dComIfG_gameInfo, - sizeof(dSv_info_c), 0, card.sector_size); - card.card_result = Utilities::card_write(&card.card_info, &posData, sizeof(posData), - sizeof(dSv_info_c) + 1, card.sector_size); - - if (card.card_result == Ready) { + storage.result = Utilities::storage_write(&storage, &g_dComIfG_gameInfo, + sizeof(dSv_info_c), 0, storage.sector_size); + storage.result = Utilities::storage_write(&storage, &posData, sizeof(posData), + sizeof(dSv_info_c) + 1, storage.sector_size); + if (storage.result == Ready) { FIFOQueue::push("saved memfile!", Queue); } else { char buff[32]; - tp_sprintf(buff, "failed to save: %d", card.card_result); + tp_sprintf(buff, "failed to save: %d", storage.result); FIFOQueue::push(buff, Queue); } - card.card_result = CARDClose(&card.card_info); + storage.result = StorageClose(&storage.info); } } -#endif } -void delete_mem_card(Card& card) { -#ifndef WII_PLATFORM - card.card_result = CARDDelete(0, card.file_name_buffer); - if (card.card_result == Ready) { +void delete_mem_card(Storage& storage) { + storage.result = StorageDelete(0, storage.file_name_buffer); + if (storage.result == Ready) { FIFOQueue::push("deleted card!", Queue); } else { char buff[32]; - tp_sprintf(buff, "failed to delete: %d", card.card_result); + tp_sprintf(buff, "failed to delete: %d", storage.result); FIFOQueue::push(buff, Queue); } -#endif } -void delete_memfile(Card& card) { -#ifndef WII_PLATFORM - card.card_result = CARDDelete(0, card.file_name_buffer); - if (card.card_result == Ready) { - tp_osReport("deleted memfile!"); +void delete_memfile(Storage& storage) { + storage.result = StorageDelete(0, storage.file_name_buffer); + if (storage.result == Ready) { FIFOQueue::push("deleted memfile!", Queue); } else { - tp_osReport("failed to delete"); char buff[32]; - tp_sprintf(buff, "failed to delete: %d", card.card_result); + tp_sprintf(buff, "failed to delete: %d", storage.result); FIFOQueue::push(buff, Queue); } -#endif } -void load_mem_card(Card& card) { -#ifndef WII_PLATFORM - card.card_result = CARDOpen(0, card.file_name_buffer, &card.card_info); - if (card.card_result == Ready) { +void load_mem_card(Storage& storage) { + storage.result = StorageOpen(0, storage.file_name_buffer, &storage.info, OPEN_MODE_RW); + if (storage.result == Ready) { GZSaveFile save_file; store_save_layout(save_file.data); - card.card_result = read_save_file(&card.card_info, save_file, card.sector_size); - if (card.card_result == Ready) { - tp_osReport("loaded card!"); + storage.result = read_save_file(&storage, save_file, storage.sector_size); + if (storage.result == Ready) { FIFOQueue::push("loaded card!", Queue); load_save_layout(save_file.data); SettingsMenu::initFont(); } else { - tp_osReport("failed to load"); char buff[32]; - tp_sprintf(buff, "failed to load: %d", card.card_result); + tp_sprintf(buff, "failed to load: %d", storage.result); FIFOQueue::push(buff, Queue); } - card.card_result = CARDClose(&card.card_info); + storage.result = StorageClose(&storage.info); } -#endif } -void load_memfile(Card& card) { -#ifndef WII_PLATFORM - card.card_result = CARDOpen(0, card.file_name_buffer, &card.card_info); - if (card.card_result == Ready) { +void load_memfile(Storage& storage) { + storage.result = StorageOpen(0, storage.file_name_buffer, &storage.info, OPEN_MODE_RW); + if (storage.result == Ready) { PositionData posData; - card.card_result = read_memfile(&card.card_info, posData, card.sector_size); - - if (card.card_result == Ready) { + storage.result = read_memfile(&storage, posData, storage.sector_size); + if (storage.result == Ready) { FIFOQueue::push("loaded memfile!", Queue); inject_memfile_flag = true; SaveManager::inject_default_before(); @@ -326,25 +309,37 @@ void load_memfile(Card& card) { MenuRendering::set_menu(MN_NONE_INDEX); } else { char buff[32]; - tp_sprintf(buff, "failed to load: %d", card.card_result); + tp_sprintf(buff, "failed to load: %d", storage.result); FIFOQueue::push(buff, Queue); } - card.card_result = CARDClose(&card.card_info); + storage.result = StorageClose(&storage.info); } -#endif } +#ifdef GCN_PLATFORM +#define FRAME_COUNT 200 +#define FILE_NAME "tpgz01" +#endif // GCN_PLATFORM +#ifdef WII_PLATFORM +#define FRAME_COUNT 500 +#define FILE_NAME "tpgz01.dat" +#endif // WII_PLATFORM + void load_gz_card(bool& card_load) { uint8_t frame_count = cCt_getFrameCount(); - if (card_load && frame_count > 200) { - static Card card; - card.file_name = "tpgz01"; - card.sector_size = SECTOR_SIZE; - tp_sprintf(card.file_name_buffer, (char*)card.file_name); - card.card_result = CARDProbeEx(0, NULL, &card.sector_size); - if (card.card_result == Ready) { - Utilities::load_mem_card(card); + if (card_load && frame_count > FRAME_COUNT) { + static Storage storage; + storage.file_name = FILE_NAME; + storage.sector_size = SECTOR_SIZE; + tp_sprintf(storage.file_name_buffer, (char*)storage.file_name); +#ifndef WII_PLATFORM + storage.result = CARDProbeEx(0, NULL, &storage.sector_size); + if (storage.result == Ready) { + Utilities::load_mem_card(storage); } +#else // WII_PLATFORM + Utilities::load_mem_card(storage); +#endif // WII_PLATFORM card_load = false; } diff --git a/src/utils/hook.cpp b/src/utils/hook.cpp index 621c01f..b66f36f 100644 --- a/src/utils/hook.cpp +++ b/src/utils/hook.cpp @@ -82,12 +82,14 @@ void drawHook(void* p1) { draw(); } +#ifdef PR_TEST void myExceptionCallbackHook(void) { ExceptionCallbackTrampoline(); *reinterpret_cast<uint32_t*>(CRASH_ADDRESS) = 1; DCFlushRange((void*)(CRASH_ADDRESS), sizeof(uint32_t)); ICInvalidateRange((void*)(CRASH_ADDRESS), sizeof(uint32_t)); } +#endif // PR_TEST uint32_t readControllerHook(uint16_t* p1) { auto returnValue = PADReadTrampoline(p1); |