From c07f14d1cf204d4cf5bf40b5fab2e6f658981f2d Mon Sep 17 00:00:00 2001 From: raicool Date: Tue, 15 Aug 2023 13:22:34 -0400 Subject: [PATCH] get cup id from file header instead of file name --- src/app.cpp | 26 ++++++++++++++------------ src/app.h | 2 +- src/common/alias.h | 28 ++++++++++++++++++---------- src/core/panel.cpp | 12 ++++++------ src/file/spotpass.cpp | 4 +++- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 669e369..045af75 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -41,14 +41,16 @@ int app::update() void app::open_spotpass_file() { const char* file_dir = open_file(); - uint8_t cup = filename_to_cup(std::filesystem::path(file_dir).filename().string().c_str()); + + spotpass* new_spotpass = new spotpass(); + uint8_t cup = new_spotpass->load(file_dir); + LOG_DEBUG("Cup = {}, file = {}", cup, std::filesystem::path(file_dir).filename().string().c_str()); + if (cup >= 0 && cup <= 8) { - if (spotpass_files[cup]) delete spotpass_files[cup]; - spotpass_files[cup] = new spotpass(); - spotpass_files[cup]->load(file_dir); - spotpass_files[cup]->cup_id = cup; + if (spotpass_files[cup - 1]) delete spotpass_files[cup - 1]; + spotpass_files[cup - 1] = new_spotpass; } else { @@ -67,20 +69,20 @@ void app::open_spotpass_folder() { auto file_name = file.path().filename(); - cup = filename_to_cup(file_name.string().c_str()); + spotpass* new_spotpass = new spotpass(); + cup = new_spotpass->load(file.path().string().c_str()); + LOG_DEBUG("Cup = {}, file = {}", cup, file_name.string().c_str()); - if (cup >= 0 && cup <= 8) + if (cup >= 1 && cup <= 8) { - if (spotpass_files[cup]) delete spotpass_files[cup]; - spotpass_files[cup] = new spotpass(); - spotpass_files[cup]->load(file.path().string().c_str()); - spotpass_files[cup]->cup_id = cup; + if (spotpass_files[cup - 1]) delete spotpass_files[cup - 1]; + spotpass_files[cup - 1] = new_spotpass; } } } app::~app() { - for (int i = 0; i < 8; i++) delete spotpass_files[i]; + for (int i = 0; i < 8; i++) if (spotpass_files[i]) delete spotpass_files[i]; } \ No newline at end of file diff --git a/src/app.h b/src/app.h index a876f08..a71d682 100644 --- a/src/app.h +++ b/src/app.h @@ -9,7 +9,7 @@ struct app window sdlwindow; texture texture_manager; - spotpass* spotpass_files[9]{ nullptr }; // 8 file managers for 8 different spotpass cups + spotpass* spotpass_files[8]{ nullptr }; // 8 file managers for 8 different spotpass cups void open_spotpass_file(); void open_spotpass_folder(); diff --git a/src/common/alias.h b/src/common/alias.h index 46122e7..1c1c569 100644 --- a/src/common/alias.h +++ b/src/common/alias.h @@ -4,34 +4,42 @@ // stores where each course is inside of cup file static const uint8_t cup_course_index[] = { - 2, // 0 - 4, // 1 - 3, // 2 - 2, // 3 + 1, // 4 4, // 5 3, // 6 1, // 7 + 1, // 8 4, // 9 2, // 10 3, // 11 + 1, // 12 4, // 13 2, // 14 3, // 15 + 3, // 16 1, // 17 4, // 18 3, // 19 + + 2, // 0 + 4, // 1 + 3, // 2 + 2, // 3 + 4, // 20 3, // 21 2, // 22 4, // 23 + 2, // 24 3, // 25 1, // 26 1, // 27 + 1, // 28 2, // 29 2, // 30 @@ -41,11 +49,11 @@ static const uint8_t cup_course_index[] = // course id for every course in each cup static const uint8_t cup_courses[8][4] = { - { 26, 29, 19, 20 }, // Shell Cup { 4, 3, 2, 5 }, // Mushroom Cup { 8, 0, 15, 1 }, // Flower Cup { 12, 14, 6, 9 }, // Star Cup { 7, 10, 11, 13 }, // Special Cup + { 26, 29, 19, 20 }, // Shell Cup { 28, 30, 16, 23 }, // Banana Cup { 27, 22, 25, 18 }, // Leaf Cup { 17, 24, 21, 31 } // Lightning Cup @@ -96,11 +104,11 @@ static const char* course_name[] = static const char* cup_name[] = { - "Shell Cup", // 0 - "Mushroom Cup", // 1 - "Flower Cup", // 2 - "Star Cup", // 3 - "Special Cup", // 4 + "Mushroom Cup", // 0 + "Flower Cup", // 1 + "Star Cup", // 2 + "Special Cup", // 3 + "Shell Cup", // 4 "Banana Cup", // 5 "Leaf Cup", // 6 "Lightning Cup" // 7 diff --git a/src/core/panel.cpp b/src/core/panel.cpp index e57818b..44c1996 100644 --- a/src/core/panel.cpp +++ b/src/core/panel.cpp @@ -36,7 +36,7 @@ void panel::render() if (ImGui::BeginMenu("Windows")) { - ImGui::CheckboxFlags("Cups List", &panel_flags, panels::PANEL_CUPS_LIST); + ImGui::CheckboxFlags("Cups List", &panel_flags, panels::PANEL_CUPS_LIST); ImGui::CheckboxFlags("Ghost List", &panel_flags, panels::PANEL_GHOST_LIST); ImGui::EndMenu(); } @@ -63,7 +63,7 @@ void panel::render() if (ImGui::BeginTabItem(cup_name[i])) { is_cup_selected = true; - cup = i; + cup = app_ptr->spotpass_files[i]->cup_id; items[0] = (char*)course_name[cup_courses[i][0]]; items[1] = (char*)course_name[cup_courses[i][1]]; @@ -80,13 +80,13 @@ void panel::render() static int idx = 0; if (is_cup_selected) { - if (ImGui::ListBox("Courses", &idx, items, 4, 4)) course = cup_courses[cup][idx]; + if (ImGui::ListBox("Courses", &idx, items, 4, 4)) course = cup_courses[cup - 1][idx]; ImGui::NewLine(); ImGui::Separator(); ImGui::NewLine(); if (ImGui::Button("Add Ghost")) { - if (app_ptr->spotpass_files[cup]->add_ghost(open_file()) == false) + if (app_ptr->spotpass_files[cup - 1]->add_ghost(open_file()) == false) { ImGui::PushID("Load Failed"); ImGui::OpenPopup("Load Failed"); @@ -121,9 +121,9 @@ void panel::render() if (ImGui::Begin("Ghost", 0, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDecoration)) { - if (app_ptr->spotpass_files[cup]) + if (app_ptr->spotpass_files[cup - 1]) { - spotpass& current_cup = *app_ptr->spotpass_files[cup]; + spotpass& current_cup = *app_ptr->spotpass_files[cup - 1]; ImGui::Spacing(); diff --git a/src/file/spotpass.cpp b/src/file/spotpass.cpp index c58ba3d..35f4090 100644 --- a/src/file/spotpass.cpp +++ b/src/file/spotpass.cpp @@ -9,7 +9,7 @@ uint8_t spotpass::load(const char* dir) { uint32_t offset = 0; uint32_t u32buffer = 0; - uint8_t buffer = 0; + uint8_t buffer = 0; file_directory = dir; @@ -35,6 +35,8 @@ uint8_t spotpass::load(const char* dir) ghosts.reserve(80); ghost_count = 0; + bin_read(&cup_id, spotpass_data, 0x2f); + for (int i = 0; i < 80; i++) { // each ghost inside of a spotpass file have a padding size of 0x2898