Add unicode functions; fix really really dumb bug with theme installation from folder.

This commit is contained in:
2017-08-26 16:40:36 -04:00
parent ae42b9648c
commit 2654c1dfa7
5 changed files with 36 additions and 15 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <3ds.h>
#include <string.h>
#include <stdio.h>
#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);
}