From 2654c1dfa720ff79b27d7fecb5367bac1a1ebec0 Mon Sep 17 00:00:00 2001 From: Alex Taber Date: Sat, 26 Aug 2017 16:40:36 -0400 Subject: [PATCH] Add unicode functions; fix really really dumb bug with theme installation from folder. --- Makefile | 2 +- include/unicode.h | 3 ++- source/main.c | 8 ++++---- source/themes.c | 16 +++++++++++++--- source/unicode.c | 22 ++++++++++++++++------ 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index f730cca..164b883 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ INCLUDES := include ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft CFLAGS := -g -Wall -Wextra -Wno-pointer-sign -O2 -mword-relocations \ - -ffunction-sections \ + -fomit-frame-pointer -ffunction-sections \ $(ARCH) CFLAGS += $(INCLUDE) -DARM11 -D_3DS diff --git a/include/unicode.h b/include/unicode.h index a6fe435..96f6547 100644 --- a/include/unicode.h +++ b/include/unicode.h @@ -4,6 +4,7 @@ #include <3ds.h> ssize_t strulen(u16*, ssize_t); -void struacat(u16 *input, char *addition); +void struacat(u16 *input, const char *addition); +void printu(u16 *input); #endif \ No newline at end of file diff --git a/source/main.c b/source/main.c index 23d61b3..ac14b38 100644 --- a/source/main.c +++ b/source/main.c @@ -27,7 +27,7 @@ int de_init_services(void) hidExit(); fsExit(); ptmSysmExit(); - // close_archives(); // TODO: Implement + close_archives(); return 0; } @@ -39,15 +39,15 @@ int main(void) int theme_count = get_number_entries("/Themes"); theme *theme = calloc(1, sizeof(theme)); u16 path[262] = {0}; - utf8_to_utf16(path, (u8*)"/Themes/[11115] Saber Lily by kiss7938.zip", 262 * sizeof(u16)); + utf8_to_utf16(path, (u8*)"/Themes/Saber Lily", 262 * sizeof(u16)); memcpy(theme->path, path, 262 * sizeof(u16)); - theme->is_zip = true; - single_install(*theme); + theme->is_zip = false; while(aptMainLoop()) { hidScanInput(); u32 kDown = hidKeysDown(); + if (kDown & KEY_A) single_install(*theme); if (kDown & KEY_START) { close_archives(); diff --git a/source/themes.c b/source/themes.c index 51ac3ab..fe6ccb3 100644 --- a/source/themes.c +++ b/source/themes.c @@ -7,6 +7,11 @@ #include "unicode.h" #include "fs.h" +int scan_themes(theme **themes) +{ + +} + Result single_install(theme theme_to_install) { char *body; @@ -17,17 +22,18 @@ Result single_install(theme theme_to_install) u32 music_size; u32 savedata_size; + printf("Writing SaveData.dat...\n"); + 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; u32 size = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf); - printf("Savedata size: %lu\n", savedata_size); - printf("Return: %lx\n", size); free(savedata_buf); // Open body cache file. Test if theme is zipped + printf("Writing BodyCache.bin...\n"); if (theme_to_install.is_zip) { body_size = zip_file_to_buf("body_LZ.bin", theme_to_install.path, &body); @@ -50,12 +56,13 @@ Result single_install(theme theme_to_install) if (size == 0) return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND); + printf("Writing BgmCache.bin...\n"); if (theme_to_install.is_zip) // Same as above but this time with bgm { music_size = zip_file_to_buf("bgm.bcstm", theme_to_install.path, &music); } else { u16 path[0x106] = {0}; - memcpy(path, theme_to_install.path, 0x106 * sizeof(16)); + memcpy(path, theme_to_install.path, 0x106 * sizeof(u16)); struacat(path, "/bgm.bcstm"); music_size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &music); } @@ -75,6 +82,7 @@ Result single_install(theme theme_to_install) if (size == 0) return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND); + printf("Writing ThemeManage.bin...\n"); file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf); thememanage_buf[0x00] = 1; thememanage_buf[0x01] = 0; @@ -102,5 +110,7 @@ Result single_install(theme theme_to_install) size = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf); free(thememanage_buf); + printf("Done!\n"); + return 0; } \ No newline at end of file diff --git a/source/unicode.c b/source/unicode.c index 9f3965d..8897b62 100644 --- a/source/unicode.c +++ b/source/unicode.c @@ -1,6 +1,7 @@ #include #include <3ds.h> #include +#include #include "unicode.h" @@ -10,13 +11,22 @@ ssize_t strulen(u16 *input, ssize_t max_len) return max_len; } -void struacat(u16 *input, char *addition) +void struacat(u16 *input, const char *addition) { ssize_t len = strulen(input, 0x106); - u8 *data = calloc(sizeof(u8), len * 4); - utf16_to_utf8(data, input, len); + for (u16 i = len; i < strlen(addition) + len; i++) + { + input[i] = addition[i - len]; + } + input[strlen(addition) + len] = 0; +} - memcpy(&data[len], addition, strlen(addition)); - utf8_to_utf16(input, data, len + strlen(addition)); - free(data); +void printu(u16 *input) +{ + ssize_t in_len = strulen(input, 0x106); + ssize_t buf_len = in_len + 1; // Plus 1 for proper null termination + wchar_t *buf = calloc(buf_len, sizeof(wchar_t)); + for (u16 i = 0; i < buf_len; i++) buf[i] = input[i]; + printf("%ls\n", buf); + free(buf); } \ No newline at end of file