Nani the fuck

This commit is contained in:
2017-08-09 08:39:33 -04:00
parent d337623bd0
commit 5fb9d86b62
9 changed files with 81 additions and 35 deletions

3
.gitignore vendored
View File

@@ -57,3 +57,6 @@ dkms.conf
# Build files # Build files
build/ build/
# Sublime stuff
.clang_complete

View File

@@ -40,7 +40,7 @@ INCLUDES := include
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
CFLAGS := -g -Wall -Wextra -Wno-pointer-sign -O2 -mword-relocations \ CFLAGS := -g -Wall -Wextra -Wno-pointer-sign -O2 -mword-relocations \
-fomit-frame-pointer -ffunction-sections \ -ffunction-sections \
$(ARCH) $(ARCH)
CFLAGS += $(INCLUDE) -DARM11 -D_3DS CFLAGS += $(INCLUDE) -DARM11 -D_3DS

View File

@@ -9,7 +9,7 @@ FS_Archive ArchiveThemeExt;
Result open_archives(void); Result open_archives(void);
int get_number_entries(char*); int get_number_entries(char*);
u32 file_to_buf(FS_Path path, char* buf); u64 file_to_buf(FS_Path path, FS_Archive archive, char* buf);
u32 zip_file_to_buf(char *file_name, u16 *zip_path, char *buf); u32 zip_file_to_buf(char *file_name, u16 *zip_path, char *buf);
u32 buf_to_file(u32 size, char *path, FS_Archive archive, char *buf); u32 buf_to_file(u32 size, char *path, FS_Archive archive, char *buf);
bool check_file_exists(char *path, FS_Archive archive); bool check_file_exists(char *path, FS_Archive archive);

View File

@@ -1,6 +1,8 @@
#ifndef THEMES_H #ifndef THEMES_H
#define THEMES_H #define THEMES_H
#include <3ds.h>
typedef struct { typedef struct {
u16 name[0x40]; u16 name[0x40];
u16 desc[0x80]; u16 desc[0x80];
@@ -11,6 +13,6 @@ typedef struct {
bool is_zip; bool is_zip;
} theme; } theme;
Result single_install(theme*); Result single_install(theme);
#endif #endif

View File

@@ -1,6 +1,9 @@
#ifndef UNICODE_H #ifndef UNICODE_H
#define UNICODE_H #define UNICODE_H
#include <3ds.h>
ssize_t strulen(u16*, ssize_t); ssize_t strulen(u16*, ssize_t);
void struacat(u16 *input, char *addition);
#endif #endif

View File

@@ -3,6 +3,8 @@
#include <stdlib.h> #include <stdlib.h>
#include "fs.h" #include "fs.h"
#include "unicode.h"
#include "minizip/unzip.h"
Result open_archives(void) Result open_archives(void)
{ {
@@ -79,13 +81,13 @@ int get_number_entries(char *path)
return count; return count;
} }
u32 file_to_buf(FS_Path path, FS_Archive archive, char* buf) u64 file_to_buf(FS_Path path, FS_Archive archive, char* buf)
{ {
Handle file; Handle file;
Result res = FSUSER_OpenFile(&file, archive, path, FS_OPEN_READ, 0); Result res = FSUSER_OpenFile(&file, archive, path, FS_OPEN_READ, 0);
if (R_FAILED(res)) return 0; if (R_FAILED(res)) return 0;
u32 size; u64 size;
FSFILE_GetSize(file, &size); FSFILE_GetSize(file, &size);
buf = malloc(size); buf = malloc(size);
FSFILE_Read(file, NULL, 0, buf, size); FSFILE_Read(file, NULL, 0, buf, size);
@@ -95,6 +97,7 @@ u32 file_to_buf(FS_Path path, FS_Archive archive, char* buf)
u32 zip_file_to_buf(char *file_name, u16 *zip_path, char *buf) u32 zip_file_to_buf(char *file_name, u16 *zip_path, char *buf)
{ {
fflush(stdout);
ssize_t len = strulen(zip_path, 0x106); ssize_t len = strulen(zip_path, 0x106);
u8 *path = calloc(sizeof(u8), len * 4); u8 *path = calloc(sizeof(u8), len * 4);
@@ -105,7 +108,8 @@ u32 zip_file_to_buf(char *file_name, u16 *zip_path, char *buf)
if (zip_handle == NULL) return 0; if (zip_handle == NULL) return 0;
u32 file_size = 0; u32 file_size = 0;
if (unzLocateFile(zip_handle, file_name, 0) == UNZ_OK) int status = unzLocateFile(zip_handle, file_name, 0);
if (status == UNZ_OK)
{ {
unz_file_info *file_info = malloc(sizeof(unz_file_info)); unz_file_info *file_info = malloc(sizeof(unz_file_info));
file_size = file_info->uncompressed_size; file_size = file_info->uncompressed_size;
@@ -114,6 +118,8 @@ u32 zip_file_to_buf(char *file_name, u16 *zip_path, char *buf)
unzOpenCurrentFile(zip_handle); unzOpenCurrentFile(zip_handle);
unzReadCurrentFile(zip_handle, buf, file_size); unzReadCurrentFile(zip_handle, buf, file_size);
unzCloseCurrentFile(zip_handle); unzCloseCurrentFile(zip_handle);
} else {
puts("fileziprip");
} }
unzClose(zip_handle); unzClose(zip_handle);
@@ -125,10 +131,13 @@ u32 buf_to_file(u32 size, char *path, FS_Archive archive, char *buf)
{ {
Handle handle; Handle handle;
u32 bytes = 0; u32 bytes = 0;
FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_WRITE | FS_OPEN_CREATE, 0); Result res = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_WRITE, 0);
FSFILE_Write(handle, &bytes, 0, buf, size, FS_WRITE_FLUSH); if (R_FAILED(res)) return res;
FSFILE_Close(handle); res = FSFILE_Write(handle, &bytes, 0, buf, size, FS_WRITE_FLUSH);
return bytes; if (R_FAILED(res)) return res;
res = FSFILE_Close(handle);
if (R_FAILED(res)) return res;
return 0;
} }
bool check_file_exists(char *path, FS_Archive archive) bool check_file_exists(char *path, FS_Archive archive)

View File

@@ -1,7 +1,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <3ds.h>
#include <string.h>
#include "fs.h" #include "fs.h"
#include "themes.h" #include "themes.h"
#include "unicode.h"
int init_services(void) int init_services(void)
{ {
@@ -30,11 +34,26 @@ int de_init_services(void)
int main(void) int main(void)
{ {
init_services(); init_services();
consoleInit(GFX_TOP, NULL);
int theme_count = get_number_entries("/Themes"); int theme_count = get_number_entries("/Themes");
theme** theme_list = calloc(theme_count, sizeof(theme*)); 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));
memcpy(theme->path, path, 262 * sizeof(u16));
theme->is_zip = true;
single_install(*theme);
free(theme_list); while(aptMainLoop())
{
hidScanInput();
u32 kDown = hidKeysDown();
if (kDown & KEY_START)
{
break;
}
}
de_init_services(); de_init_services();
return 0; return 0;
} }

View File

@@ -1,9 +1,13 @@
#include <3ds.h> #include <3ds.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "themes.h" #include "themes.h"
#include "unicode.h"
#include "fs.h"
Result single_install(theme* theme) Result single_install(theme theme_to_install)
{ {
char *body; char *body;
char *music; char *music;
@@ -13,46 +17,49 @@ Result single_install(theme* theme)
u32 music_size; u32 music_size;
u32 savedata_size; u32 savedata_size;
savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, savedata_buf) savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, savedata_buf);
savedata_buf[0x141b] = 0; savedata_buf[0x141b] = 0;
memset(&savedata_buf[0x13b8], 0, 8); memset(&savedata_buf[0x13b8], 0, 8);
savedata_buf[0x13bd] = 3; savedata_buf[0x13bd] = 3;
savedata_buf[0x13b8] = 0xff; savedata_buf[0x13b8] = 0xff;
buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf); Result res = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
printf("%li\n", res);
free(savedata_buf); free(savedata_buf);
// Open body cache file. Test if theme is zipped // Open body cache file. Test if theme is zipped
if (theme->is_zip) if (theme_to_install.is_zip)
{ {
body_size = zip_file_to_buf("body_lz.bin", theme->path, body); body_size = zip_file_to_buf("body_LZ.bin", theme_to_install.path, body);
} else { } else {
u16 path[0x106]; u16 path[0x106] = {0};
memcpy(path, theme->path, 0x106); memcpy(path, theme_to_install.path, 0x106 * sizeof(u16));
struacat(path, "/body_lz.bin"); struacat(path, "/body_lz.bin");
body_size = file_to_buf(path, body); body_size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, body);
} }
if (body_size == 0) if (body_size == 0)
{ {
free(body); free(body);
return MAKERESULT(RL_PERMANENT, RL_CANCELED, RL_APPLICATION, RD_NOT_FOUND); puts("bodyrip");
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
} }
if (check_file_exists("/BodyCache.bin", ArchiveThemeExt)) FSUSER_DeleteFile(ArchiveThemeExt, fsMakePath("/BodyCache.bin")); if (check_file_exists("/BodyCache.bin", ArchiveThemeExt)) FSUSER_DeleteFile(ArchiveThemeExt, fsMakePath(PATH_ASCII, "/BodyCache.bin"));
FSUSER_CreateFile(ArchiveThemeExt, fsMakePath(PATH_ASCII, "/BodyCache.bin"), 0, body_size);
u32 size = buf_to_file(body_size, "/BodyCache.bin", ArchiveThemeExt, body); // Write body data to file u32 size = buf_to_file(body_size, "/BodyCache.bin", ArchiveThemeExt, body); // Write body data to file
free(body); free(body);
if (size == 0) return MAKERESULT(RL_PERMANENT, RL_CANCELED, RL_APPLICATION, RD_NOT_FOUND); if (size == 0) return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
if (theme->is_zip) // Same as above but this time with bgm if (theme_to_install.is_zip) // Same as above but this time with bgm
{ {
music_size = zip_file_to_buf("bgm.bcstm", theme->path, music); music_size = zip_file_to_buf("bgm.bcstm", theme_to_install.path, music);
} else { } else {
u16 path[0x106]; u16 path[0x106] = {0};
memcpy(path, theme->path, 0x106); memcpy(path, theme_to_install.path, 0x106 * sizeof(16));
struacat(path, "/bgm.bcstm"); struacat(path, "/bgm.bcstm");
music_size = file_to_buf(path, music); music_size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, music);
} }
if (music_size == 0) if (music_size == 0)
@@ -61,15 +68,17 @@ Result single_install(theme* theme)
music = calloc(1, 3371008); music = calloc(1, 3371008);
} else if (size > 3371008) { } else if (size > 3371008) {
free(music); free(music);
return MAKERESULT(RL_PERMANENT, RL_CANCELED, RL_APPLICATION, RD_TOO_LARGE); puts("musicrip");
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
} }
if (check_file_exists("/BgmCache.bin", ArchiveThemeExt)) FSUSER_DeleteFile(ArchiveThemeExt, fsMakePath("/BgmCache.bin")); if (check_file_exists("/BgmCache.bin", ArchiveThemeExt)) FSUSER_DeleteFile(ArchiveThemeExt, fsMakePath(PATH_ASCII, "/BgmCache.bin"));
FSUSER_CreateFile(ArchiveThemeExt, fsMakePath(PATH_ASCII, "/BgmCache.bin"), 0, music_size);
size = buf_to_file(music_size, "/BgmCache.bin", ArchiveThemeExt, music); size = buf_to_file(music_size, "/BgmCache.bin", ArchiveThemeExt, music);
free(music); free(music);
if (size == 0) return MAKERESULT(RL_PERMANENT, RL_CANCELED, RL_APPLICATION, RD_NOT_FOUND); if (size == 0) return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
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_buf[0x00] = 1;

View File

@@ -1,19 +1,20 @@
#include <stdlib.h> #include <stdlib.h>
#include <3ds.h> #include <3ds.h>
#include <string.h>
#include "unicode.h" #include "unicode.h"
ssize_t strulen(u16 *input, ssize_t max_len) ssize_t strulen(u16 *input, ssize_t max_len)
{ {
for (int i = 0; i < max_len, i++) if (input[i] == 0) return i; for (int i = 0; i < max_len; i++) if (input[i] == 0) return i;
return max_len; return max_len;
} }
void strucat(u16 *input, char *addition) void struacat(u16 *input, char *addition)
{ {
ssize_t len = strulen(zip_path, 0x106); ssize_t len = strulen(input, 0x106);
u8 *data = calloc(sizeof(u8), len * 4); u8 *data = calloc(sizeof(u8), len * 4);
utf16_to_utf8(data, zip_path, len); utf16_to_utf8(data, input, len);
memcpy(&data[len], addition, strlen(addition)); memcpy(&data[len], addition, strlen(addition));
utf8_to_utf16(input, data, len + strlen(addition)); utf8_to_utf16(input, data, len + strlen(addition));