Less magic numbers, and centralized theme install function. (#103)

* less magic numbers

* part 2: installing themes

* fix simple theme install
that wasnt such a good idea

* fix shuffle count

* fix shuffle theme install

* change padding name
This commit is contained in:
LiquidFenrir
2017-12-05 17:29:31 +01:00
committed by GitHub
parent 6be1b5e217
commit 0818389752
5 changed files with 259 additions and 328 deletions

View File

@@ -29,6 +29,19 @@
#include "common.h" #include "common.h"
typedef struct {
u8 _padding1[4 + 2 + 2];
u16 name[0x40];
u16 desc[0x80];
u16 author[0x40];
u8 _padding2[0x2000 - 0x200 + 0x30 + 0x8];
u16 small_icon[24*24];
u16 big_icon[48*48];
} Icon_s;
typedef struct { typedef struct {
u16 name[0x41]; u16 name[0x41];
u16 desc[0x81]; u16 desc[0x81];

View File

@@ -30,11 +30,51 @@
#include "common.h" #include "common.h"
#include "loading.h" #include "loading.h"
#define MAX_SHUFFLE_THEMES 10
enum ThemeInstall {
THEME_INSTALL_SHUFFLE = BIT(0),
THEME_INSTALL_BODY = BIT(1),
THEME_INSTALL_BGM = BIT(2),
};
typedef struct {
u32 index;
u8 dlc_tid_low_bits;
u8 type;
u16 unk;
} ThemeEntry_s;
typedef struct {
u8 _padding1[0x13b8];
ThemeEntry_s theme_entry;
ThemeEntry_s shuffle_themes[MAX_SHUFFLE_THEMES];
u8 _padding2[0xb];
bool shuffle;
} SaveData_dat_s;
typedef struct {
u32 unk1;
u32 unk2;
u32 body_size;
u32 music_size;
u32 unk3;
u32 unk4;
u32 dlc_theme_content_index;
u32 use_theme_cache;
u8 _padding1[0x338 - 8*sizeof(u32)];
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES];
u32 shuffle_music_sizes[MAX_SHUFFLE_THEMES];
} ThemeManage_bin_s;
void delete_theme(Entry_s theme); void delete_theme(Entry_s theme);
Result theme_install(Entry_s theme); Result theme_install(Entry_s theme);
Result no_bgm_install(Entry_s theme); Result no_bgm_install(Entry_s theme);
Result bgm_install(Entry_s theme);
Result shuffle_install(Entry_s* themes_list, int themes_count); Result shuffle_install(Entry_List_s themes);
Result bgm_install(Entry_s bgm_to_install);
#endif #endif

View File

@@ -51,6 +51,7 @@ static void parse_smdh(Entry_s * entry, const ssize_t textureID, const u16 * fal
char *info_buffer = NULL; char *info_buffer = NULL;
u64 size = load_data("/info.smdh", *entry, &info_buffer); u64 size = load_data("/info.smdh", *entry, &info_buffer);
Icon_s * smdh = (Icon_s *)info_buffer;
if(!size) if(!size)
{ {
@@ -62,13 +63,9 @@ static void parse_smdh(Entry_s * entry, const ssize_t textureID, const u16 * fal
return; return;
} }
memcpy(entry->name, info_buffer + 0x08, 0x80); memcpy(entry->name, smdh->name, 0x40*sizeof(u16));
memcpy(entry->desc, info_buffer + 0x88, 0x100); memcpy(entry->desc, smdh->desc, 0x80*sizeof(u16));
memcpy(entry->author, info_buffer + 0x188, 0x80); memcpy(entry->author, smdh->author, 0x40*sizeof(u16));
u16 *icon_data = malloc(0x1200);
memcpy(icon_data, info_buffer + 0x24C0, 0x1200);
free(info_buffer);
const u32 width = 48, height = 48; const u32 width = 48, height = 48;
u32 *image = malloc(width*height*sizeof(u32)); u32 *image = malloc(width*height*sizeof(u32));
@@ -80,11 +77,11 @@ static void parse_smdh(Entry_s * entry, const ssize_t textureID, const u16 * fal
unsigned int dest_pixel = (x + y*width); unsigned int dest_pixel = (x + y*width);
unsigned int source_pixel = (((y >> 3) * (width >> 3) + (x >> 3)) << 6) + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3)); unsigned int source_pixel = (((y >> 3) * (width >> 3) + (x >> 3)) << 6) + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3));
image[dest_pixel] = RGB565_TO_ABGR8(icon_data[source_pixel]); image[dest_pixel] = RGB565_TO_ABGR8(smdh->big_icon[source_pixel]);
} }
} }
free(icon_data); free(info_buffer);
pp2d_load_texture_memory(textureID, (u8*)image, (u32)width, (u32)height); pp2d_load_texture_memory(textureID, (u8*)image, (u32)width, (u32)height);
free(image); free(image);

View File

@@ -245,8 +245,9 @@ int main(void)
if(current_list->shuffle_count > 0) if(current_list->shuffle_count > 0)
{ {
draw_install(INSTALL_SHUFFLE); draw_install(INSTALL_SHUFFLE);
shuffle_install(current_list->entries, current_list->entries_count); Result res = shuffle_install(*current_list);
current_list->shuffle_count = 0; if(R_FAILED(res)) DEBUG("shuffle install result: %lx\n", res);
else current_list->shuffle_count = 0;
} }
else else
{ {

View File

@@ -29,7 +29,8 @@
#include "fs.h" #include "fs.h"
#include "draw.h" #include "draw.h"
#define BGM_MAX_SIZE 3371008 #define BODY_CACHE_SIZE 0x150000
#define BGM_MAX_SIZE 0x337000
void delete_theme(Entry_s theme) void delete_theme(Entry_s theme)
{ {
@@ -45,344 +46,223 @@ void delete_theme(Entry_s theme)
} }
} }
Result bgm_install(Entry_s bgm_to_install) static Result install_theme_internal(Entry_List_s themes, int installmode)
{ {
char *savedata_buf; Result res = 0;
char *thememanage_buf;
char *music;
u32 music_size = 0;
u32 savedata_size;
savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf);
savedata_buf[0x141b] = 0;
memset(&savedata_buf[0x13b8], 0, 8);
savedata_buf[0x13bd] = 3;
savedata_buf[0x13b8] = 0xff;
Result result = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
free(savedata_buf);
if(R_FAILED(result)) return result;
music_size = load_data("/bgm.bcstm", bgm_to_install, &music);
if(music_size == 0)
{
music = calloc(1, BGM_MAX_SIZE);
} else if(music_size > BGM_MAX_SIZE) {
free(music);
puts("musicrip");
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
}
result = buf_to_file(music_size == 0 ? BGM_MAX_SIZE : music_size, "/BgmCache.bin", ArchiveThemeExt, music);
free(music);
if(R_FAILED(result)) return result;
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
thememanage_buf[0x00] = 1;
thememanage_buf[0x01] = 0;
thememanage_buf[0x02] = 0;
thememanage_buf[0x03] = 0;
thememanage_buf[0x04] = 0;
thememanage_buf[0x05] = 0;
thememanage_buf[0x06] = 0;
thememanage_buf[0x07] = 0;
u32 *music_size_location = (u32*)(&thememanage_buf[0xC]);
*music_size_location = music_size;
thememanage_buf[0x10] = 0xFF;
thememanage_buf[0x14] = 0x01;
thememanage_buf[0x18] = 0xFF;
thememanage_buf[0x1D] = 0x02;
memset(&thememanage_buf[0x338], 0, 4);
memset(&thememanage_buf[0x340], 0, 4);
memset(&thememanage_buf[0x360], 0, 4);
memset(&thememanage_buf[0x368], 0, 4);
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
free(thememanage_buf);
if(R_FAILED(result)) return result;
return 0;
}
// Install a single theme
Result theme_install(Entry_s theme)
{
char *body = NULL;
char* music = NULL; char* music = NULL;
char *savedata_buf = NULL;
char *thememanage_buf = NULL;
u32 body_size = 0;
u32 music_size = 0; u32 music_size = 0;
u32 savedata_size = 0; u32 shuffle_music_sizes[MAX_SHUFFLE_THEMES] = {0};
char* body = NULL;
u32 body_size = 0;
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES] = {0};
savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf); if(installmode & THEME_INSTALL_SHUFFLE)
DEBUGPOS("savedata: %p, %lx\n", savedata_buf, savedata_size); {
savedata_buf[0x141b] = 0; if(themes.shuffle_count > MAX_SHUFFLE_THEMES)
memset(&savedata_buf[0x13b8], 0, 8); {
savedata_buf[0x13bd] = 3; DEBUG("too many themes selected for shuffle\n");
savedata_buf[0x13b8] = 0xff; return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_COMMON, RD_INVALID_SELECTION);
Result result = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf); }
free(savedata_buf);
if(R_FAILED(result)) return result; int shuffle_count = 0;
Handle body_cache_handle;
// Open body cache file. if(installmode & THEME_INSTALL_BODY)
body_size = load_data("/body_LZ.bin", theme, &body); {
remake_file("/BodyCache_rd.bin", ArchiveThemeExt, BODY_CACHE_SIZE * MAX_SHUFFLE_THEMES);
FSUSER_OpenFile(&body_cache_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/BodyCache_rd.bin"), FS_OPEN_WRITE, 0);
}
for(int i = 0; i < themes.entries_count; i++)
{
Entry_s * current_theme = &themes.entries[i];
if(current_theme->in_shuffle)
{
if(installmode & THEME_INSTALL_BODY)
{
body_size = load_data("/body_LZ.bin", *current_theme, &body);
if(body_size == 0) if(body_size == 0)
{ {
free(body); free(body);
DEBUGPOS("bodyrip"); DEBUG("body not found\n");
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND); return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
} }
result = buf_to_file(body_size, "/BodyCache.bin", ArchiveThemeExt, body); // Write body data to file shuffle_body_sizes[shuffle_count] = body_size;
FSFILE_Write(body_cache_handle, NULL, BODY_CACHE_SIZE * shuffle_count, body, body_size, FS_WRITE_FLUSH);
free(body); free(body);
}
if(R_FAILED(result)) return result; if(installmode & THEME_INSTALL_BGM)
{
music_size = load_data("/bgm.bcstm", theme, &music); char bgm_cache_path[26] = {0};
sprintf(bgm_cache_path, "/BgmCache_%.2i.bin", shuffle_count);
if(music_size == 0) music_size = load_data("/bgm.bcstm", *current_theme, &music);
if(music_size > BGM_MAX_SIZE)
{ {
music = calloc(1, BGM_MAX_SIZE);
} else if(music_size > BGM_MAX_SIZE) {
free(music); free(music);
DEBUGPOS("musicrip"); DEBUG("bgm too big\n");
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE); return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
} }
result = buf_to_file(music_size == 0 ? BGM_MAX_SIZE : music_size, "/BgmCache.bin", ArchiveThemeExt, music); shuffle_music_sizes[shuffle_count] = music_size;
remake_file(bgm_cache_path, ArchiveThemeExt, BGM_MAX_SIZE);
buf_to_file(music_size, bgm_cache_path, ArchiveThemeExt, music);
free(music); free(music);
}
if(R_FAILED(result)) return result; current_theme->in_shuffle = false;
shuffle_count++;
}
}
if(installmode & THEME_INSTALL_BGM)
{
for(int i = shuffle_count; i < MAX_SHUFFLE_THEMES; i++)
{
char bgm_cache_path[26] = {0};
sprintf(bgm_cache_path, "/BgmCache_%.2i.bin", i);
remake_file(bgm_cache_path, ArchiveThemeExt, BGM_MAX_SIZE);
}
}
if(installmode & THEME_INSTALL_BODY)
{
FSFILE_Close(body_cache_handle);
}
}
else
{
Entry_s current_theme = themes.entries[themes.selected_entry];
if(installmode & THEME_INSTALL_BODY)
{
body_size = load_data("/body_LZ.bin", current_theme, &body);
if(body_size == 0)
{
free(body);
DEBUG("body not found\n");
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
}
res = buf_to_file(body_size, "/BodyCache.bin", ArchiveThemeExt, body); // Write body data to file
free(body);
if(R_FAILED(res)) return res;
}
if(installmode & THEME_INSTALL_BGM)
{
music_size = load_data("/bgm.bcstm", current_theme, &music);
if(music_size > BGM_MAX_SIZE)
{
free(music);
DEBUG("bgm too big\n");
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
}
res = buf_to_file(music_size, "/BgmCache.bin", ArchiveThemeExt, music);
free(music);
if(R_FAILED(res)) return res;
}
}
//----------------------------------------
char* thememanage_buf = NULL;
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf); file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
thememanage_buf[0x00] = 1; ThemeManage_bin_s * theme_manage = (ThemeManage_bin_s *)thememanage_buf;
thememanage_buf[0x01] = 0;
thememanage_buf[0x02] = 0;
thememanage_buf[0x03] = 0;
thememanage_buf[0x04] = 0;
thememanage_buf[0x05] = 0;
thememanage_buf[0x06] = 0;
thememanage_buf[0x07] = 0;
u32 *body_size_location = (u32*)(&thememanage_buf[0x8]); theme_manage->unk1 = 1;
u32 *music_size_location = (u32*)(&thememanage_buf[0xC]); theme_manage->unk2 = 0;
*body_size_location = body_size;
*music_size_location = music_size;
thememanage_buf[0x10] = 0xFF; if(installmode & THEME_INSTALL_SHUFFLE)
thememanage_buf[0x14] = 0x01; {
thememanage_buf[0x18] = 0xFF; theme_manage->music_size = 0;
thememanage_buf[0x1D] = 0x02; theme_manage->body_size = 0;
memset(&thememanage_buf[0x338], 0, 4); for(int i = 0; i < MAX_SHUFFLE_THEMES; i++)
memset(&thememanage_buf[0x340], 0, 4); {
memset(&thememanage_buf[0x360], 0, 4); theme_manage->shuffle_body_sizes[i] = shuffle_body_sizes[i];
memset(&thememanage_buf[0x368], 0, 4); theme_manage->shuffle_music_sizes[i] = shuffle_music_sizes[i];
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf); }
}
else
{
if(installmode & THEME_INSTALL_BGM)
theme_manage->music_size = music_size;
if(installmode & THEME_INSTALL_BODY)
theme_manage->body_size = body_size;
}
theme_manage->unk3 = 0xFF;
theme_manage->unk4 = 1;
theme_manage->dlc_theme_content_index = 0xFF;
theme_manage->use_theme_cache = 0x0200;
res = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
free(thememanage_buf); free(thememanage_buf);
if(R_FAILED(res)) return res;
//----------------------------------------
if(R_FAILED(result)) return result; //----------------------------------------
char* savedata_buf = NULL;
u32 savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf);
SaveData_dat_s* savedata = (SaveData_dat_s*)savedata_buf;
memset(&savedata->theme_entry, 0, sizeof(ThemeEntry_s));
savedata->theme_entry.type = 3;
savedata->theme_entry.index = 0xff;
savedata->shuffle = (installmode & THEME_INSTALL_SHUFFLE);
if(installmode & THEME_INSTALL_SHUFFLE)
{
memset(savedata->shuffle_themes, 0, sizeof(ThemeEntry_s)*MAX_SHUFFLE_THEMES);
for(int i = 0; i < themes.shuffle_count; i++)
{
savedata->shuffle_themes[i].type = 3;
savedata->shuffle_themes[i].index = i;
}
}
res = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
free(savedata_buf);
if(R_FAILED(res)) return res;
//----------------------------------------
return 0; return 0;
} }
Result theme_install(Entry_s theme)
{
Entry_List_s list = {0};
list.entries_count = 1;
list.entries = &theme;
list.selected_entry = 0;
return install_theme_internal(list, THEME_INSTALL_BODY | THEME_INSTALL_BGM);
}
Result bgm_install(Entry_s theme)
{
Entry_List_s list = {0};
list.entries_count = 1;
list.entries = &theme;
list.selected_entry = 0;
return install_theme_internal(list, THEME_INSTALL_BGM);
}
Result no_bgm_install(Entry_s theme) Result no_bgm_install(Entry_s theme)
{ {
char *body = NULL; Entry_List_s list = {0};
char *savedata_buf = NULL; list.entries_count = 1;
char *thememanage_buf = NULL; list.entries = &theme;
u32 body_size = 0; list.selected_entry = 0;
u32 savedata_size = 0; return install_theme_internal(list, THEME_INSTALL_BODY);
}
savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf); Result shuffle_install(Entry_List_s themes)
DEBUGPOS("savedata: %p, %lx\n", savedata_buf, savedata_size);
savedata_buf[0x141b] = 0;
memset(&savedata_buf[0x13b8], 0, 8);
savedata_buf[0x13bd] = 3;
savedata_buf[0x13b8] = 0xff;
Result result = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
free(savedata_buf);
if(R_FAILED(result)) return result;
// Open body cache file.
body_size = load_data("/body_LZ.bin", theme, &body);
if(body_size == 0)
{ {
free(body); return install_theme_internal(themes, THEME_INSTALL_SHUFFLE | THEME_INSTALL_BODY | THEME_INSTALL_BGM);
DEBUGPOS("bodyrip");
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
}
result = buf_to_file(body_size, "/BodyCache.bin", ArchiveThemeExt, body); // Write body data to file
free(body);
if(R_FAILED(result)) return result;
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
thememanage_buf[0x00] = 1;
thememanage_buf[0x01] = 0;
thememanage_buf[0x02] = 0;
thememanage_buf[0x03] = 0;
thememanage_buf[0x04] = 0;
thememanage_buf[0x05] = 0;
thememanage_buf[0x06] = 0;
thememanage_buf[0x07] = 0;
u32 *body_size_location = (u32*)(&thememanage_buf[0x8]);
*body_size_location = body_size;
thememanage_buf[0x10] = 0xFF;
thememanage_buf[0x14] = 0x01;
thememanage_buf[0x18] = 0xFF;
thememanage_buf[0x1D] = 0x02;
memset(&thememanage_buf[0x338], 0, 4);
memset(&thememanage_buf[0x340], 0, 4);
memset(&thememanage_buf[0x360], 0, 4);
memset(&thememanage_buf[0x368], 0, 4);
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
free(thememanage_buf);
if(R_FAILED(result)) return result;
return 0;
}
Result shuffle_install(Entry_s* themes_list, int themes_count)
{
u8 count = 0;
Entry_s *shuffle_themes[10] = {0};
u32 body_sizes[10] = {0};
u32 bgm_sizes[10] = {0};
for (int i = 0; i < themes_count; i++)
{
if (count > 10) return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_COMMON, RD_INVALID_SELECTION);
if (themes_list[i].in_shuffle)
{
shuffle_themes[count++] = &themes_list[i];
themes_list[i].in_shuffle = false;
}
}
for (int i = 0; i < count; i++)
{
printu(shuffle_themes[i]->name);
}
char *savedata_buf;
u32 size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf);
if (size == 0)
{
return MAKERESULT(RL_USAGE, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
}
savedata_buf[0x141b] = 1;
memset(&savedata_buf[0x13b8], 0, 8);
savedata_buf[0x13bd] = 3;
savedata_buf[0x13b8] = 0xff;
for(int i = 0; i < 10; i++)
{
memset(&savedata_buf[0x13c0 + 0x8 * i], 0, 8); // clear any existing theme structure. 8 is the length of the theme structure, so 8 * i is the pos of the current one
if(count > i) // if we are still installing themes...
{
savedata_buf[0x13c0 + (8 * i)] = i; // index
savedata_buf[0x13c0 + (8 * i) + 5] = 3; // persistence (?)
}
}
Result result = buf_to_file(size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
free(savedata_buf);
if(R_FAILED(result)) return result;
remake_file("/BodyCache_rd.bin", ArchiveThemeExt, 0x150000 * 10); // Enough space for 10 theme files
Handle body_cache_handle;
FSUSER_OpenFile(&body_cache_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/BodyCache_rd.bin"), FS_OPEN_WRITE, 0);
for(int i = 0; i < count; i++)
{
Entry_s * current_theme = shuffle_themes[i];
char * body_buf = NULL;
u32 body_size = load_data("/body_LZ.bin", *current_theme, &body_buf);
body_sizes[i] = body_size;
FSFILE_Write(body_cache_handle, NULL, 0x150000 * i, body_buf, body_size, FS_WRITE_FLUSH);
free(body_buf);
}
FSFILE_Close(body_cache_handle);
for(int i = 0; i < 10; i++)
{
char bgm_cache_path[17] = {0};
sprintf(bgm_cache_path, "/BgmCache_%.2i.bin", i);
remake_file(bgm_cache_path, ArchiveThemeExt, BGM_MAX_SIZE);
if(count > i)
{
Entry_s * current_theme = shuffle_themes[i];
char *music_buf = NULL;
u32 music_size = music_size = load_data("/bgm.bcstm", *current_theme, &music_buf);
if(!music_size)
{
char *empty = calloc(1, BGM_MAX_SIZE);
buf_to_file(BGM_MAX_SIZE, bgm_cache_path, ArchiveThemeExt, empty);
bgm_sizes[i] = 0;
free(empty);
continue;
}
bgm_sizes[i] = music_size;
buf_to_file(music_size, bgm_cache_path, ArchiveThemeExt, music_buf);
free(music_buf);
} else {
char *empty = calloc(1, BGM_MAX_SIZE);
buf_to_file(BGM_MAX_SIZE, bgm_cache_path, ArchiveThemeExt, empty);
bgm_sizes[i] = 0;
free(empty);
}
}
char *thememanage_buf;
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
thememanage_buf[0x00] = 1; // Unknown, normally 0x1 with size of 4
thememanage_buf[0x01] = 0;
thememanage_buf[0x02] = 0;
thememanage_buf[0x03] = 0;
thememanage_buf[0x04] = 0; // Unknown, normally 0 with size of 4
thememanage_buf[0x05] = 0;
thememanage_buf[0x06] = 0;
thememanage_buf[0x07] = 0;
thememanage_buf[0x10] = 0xFF; // Unknown
thememanage_buf[0x14] = 0x01; // Unkown
thememanage_buf[0x18] = 0xFF; // DLC theme index - 0xFF indicates no DLC theme
thememanage_buf[0x1D] = 0x02; // Unknown, usually 0x200 to indicate theme-cache is being used
u32 *bodysizeloc = (u32*) (&thememanage_buf[0x08]); // Set non-shuffle theme sizes to 0
u32 *bgmsizeloc = (u32*) (&thememanage_buf[0x0C]);
*bodysizeloc = (u32) 0;
*bgmsizeloc = (u32) 0;
for(int i = 0; i < 10; i++)
{
bodysizeloc = (u32*) (&thememanage_buf[0x338 + (4 * i)]); // body size info for shuffle themes starts at 0x338 and is 4 bytes for each theme
bgmsizeloc = (u32*) (&thememanage_buf[0x360 + (4 * i)]); // same thing for bgm but starting at 0x360
*bodysizeloc = body_sizes[i]; // We don't need to check if we've already installed all the themes because all sizes initialized to 0
*bgmsizeloc = bgm_sizes[i];
}
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
free(thememanage_buf);
if(R_FAILED(result)) return result;
return MAKERESULT(RL_SUCCESS, RS_SUCCESS, RM_COMMON, RD_SUCCESS);
} }