Skip to content

Commit

Permalink
create mii struct
Browse files Browse the repository at this point in the history
  • Loading branch information
raicool committed Aug 18, 2023
1 parent ea75b51 commit 2d72e47
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/file/ghost.h
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -19,4 +20,6 @@ struct ghost
uint8_t kart_id;
uint8_t tire_id;
uint8_t glider_id;

mii mii_data;
};
36 changes: 36 additions & 0 deletions src/file/mii.h
Original file line number Diff line number Diff line change
@@ -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];
};
26 changes: 14 additions & 12 deletions src/file/spotpass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,26 @@ uint8_t spotpass::load(const char* dir)

offset += 4;
bin_read<uint32_t>(&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<uint32_t>(&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<char>(mii_name, spotpass_data, offset, 0x14);
bin_read<char>(mii_name, spotpass_data, &offset, 0x14);
ghosts[ghost_count]->player_name = utf16be(mii_name, 0x14).c_str();

offset += 4;
bin_read<mii>(&ghosts[ghost_count]->mii_data, spotpass_data, offset);
ghost_count++;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/file/spotpass.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "mii.h"
#include "ghost.h"

struct spotpass
Expand All @@ -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);
Expand Down

0 comments on commit 2d72e47

Please sign in to comment.