From 2d72e4732255ba9401b979e21f23b4b18ac1a55f Mon Sep 17 00:00:00 2001 From: raicool Date: Fri, 18 Aug 2023 10:27:13 -0400 Subject: [PATCH] create mii struct --- src/app.cpp | 2 ++ src/file/ghost.h | 3 +++ src/file/mii.h | 36 ++++++++++++++++++++++++++++++++++++ src/file/spotpass.cpp | 26 ++++++++++++++------------ src/file/spotpass.h | 2 ++ 5 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 src/file/mii.h diff --git a/src/app.cpp b/src/app.cpp index dc92bfb..aa0408f 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -63,6 +63,8 @@ void app::open_spotpass_folder() uint8_t cup = 0; const char* folder_dir = open_folder(); + if (!folder_dir) return; + for (const std::filesystem::directory_entry& file : std::filesystem::recursive_directory_iterator(folder_dir)) { auto file_name = file.path().filename(); diff --git a/src/file/ghost.h b/src/file/ghost.h index 1af88c6..760fd2c 100644 --- a/src/file/ghost.h +++ b/src/file/ghost.h @@ -1,5 +1,6 @@ #pragma once +struct mii; struct ghost { uint32_t file_offset = 0; //< where ghost's data starts in spotpass file (if applicable) @@ -19,4 +20,6 @@ struct ghost uint8_t kart_id; uint8_t tire_id; uint8_t glider_id; + + mii mii_data; }; \ No newline at end of file diff --git a/src/file/mii.h b/src/file/mii.h new file mode 100644 index 0000000..0d4a3f8 --- /dev/null +++ b/src/file/mii.h @@ -0,0 +1,36 @@ +#pragma once + +enum character_set_t +{ + JPN_USA_EUR, + CHN, + KOR, + TWN, +}; + +enum console_t +{ + WII, + DS, + N3DS, + WIIU_SWITCH, +}; + +struct mii +{ + char version; + char : 0; + bool copy : 1; + char name_profanity : 1; + char region : 2; + char character_set : 2; + char : 0; + char page_idx : 2; + char slot_idx : 2; + char : 0; + char console : 3; + char : 0; + unsigned long sys_id; + + char data[0x3c]; +}; \ No newline at end of file diff --git a/src/file/spotpass.cpp b/src/file/spotpass.cpp index 5bcbe92..5c9db40 100644 --- a/src/file/spotpass.cpp +++ b/src/file/spotpass.cpp @@ -53,24 +53,26 @@ uint8_t spotpass::load(const char* dir) offset += 4; bin_read(&u32buffer, spotpass_data, &offset); - ghosts[ghost_count]->fp_flag = (u32buffer >> 27) & 0x01; - ghosts[ghost_count]->finished_ms = (u32buffer >> 14) & 0x3ff; - ghosts[ghost_count]->finished_sec = (u32buffer >> 7) & 0x7f; - ghosts[ghost_count]->finished_min = (u32buffer >> 0) & 0x7f; - + ghosts[ghost_count]->finished_min = (u32buffer >> 0) & 0x7f; // 7 bit + ghosts[ghost_count]->finished_sec = (u32buffer >> 7) & 0x7f; // 7 bit + ghosts[ghost_count]->finished_ms = (u32buffer >> 14) & 0x3ff; // 10 bit + ghosts[ghost_count]->fp_flag = (u32buffer >> 27) & 0x01; // 1 bit + offset += 12; - // do some bit manipulation magic to get character and kart config bin_read(&u32buffer, spotpass_data, offset); - ghosts[ghost_count]->course_id = (u32buffer >> 0) & 0x3f; - ghosts[ghost_count]->character_id = (u32buffer >> 6) & 0x0f; - ghosts[ghost_count]->kart_id = (u32buffer >> 11) & 0x0f; - ghosts[ghost_count]->tire_id = (u32buffer >> 16) & 0x0f; - ghosts[ghost_count]->glider_id = (u32buffer >> 20) & 0x0f; + ghosts[ghost_count]->course_id = (u32buffer >> 0) & 0x3f; // 6 bit + ghosts[ghost_count]->character_id = (u32buffer >> 6) & 0x0f; // 5 bit + ghosts[ghost_count]->kart_id = (u32buffer >> 11) & 0x0f; // 5 bit + ghosts[ghost_count]->tire_id = (u32buffer >> 16) & 0x0f; // 4 bit + ghosts[ghost_count]->glider_id = (u32buffer >> 20) & 0x0f; // 4 bit offset += 4; char mii_name[0x14]; - bin_read(mii_name, spotpass_data, offset, 0x14); + bin_read(mii_name, spotpass_data, &offset, 0x14); ghosts[ghost_count]->player_name = utf16be(mii_name, 0x14).c_str(); + + offset += 4; + bin_read(&ghosts[ghost_count]->mii_data, spotpass_data, offset); ghost_count++; } } diff --git a/src/file/spotpass.h b/src/file/spotpass.h index 5f10c85..ec4155d 100644 --- a/src/file/spotpass.h +++ b/src/file/spotpass.h @@ -1,5 +1,6 @@ #pragma once +#include "mii.h" #include "ghost.h" struct spotpass @@ -15,6 +16,7 @@ struct spotpass uint8_t load(const char* dir); void reload(); + void overwrite_ghost(uint32_t offset, const char* ghost_directory); void delete_ghost(ghost* _ghost); bool add_ghost(const char* ghost_directory);