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

View File

@@ -3,6 +3,8 @@
#include <stdlib.h>
#include "fs.h"
#include "unicode.h"
#include "minizip/unzip.h"
Result open_archives(void)
{
@@ -79,13 +81,13 @@ int get_number_entries(char *path)
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;
Result res = FSUSER_OpenFile(&file, archive, path, FS_OPEN_READ, 0);
if (R_FAILED(res)) return 0;
u32 size;
u64 size;
FSFILE_GetSize(file, &size);
buf = malloc(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)
{
fflush(stdout);
ssize_t len = strulen(zip_path, 0x106);
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;
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));
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);
unzReadCurrentFile(zip_handle, buf, file_size);
unzCloseCurrentFile(zip_handle);
} else {
puts("fileziprip");
}
unzClose(zip_handle);
@@ -125,10 +131,13 @@ u32 buf_to_file(u32 size, char *path, FS_Archive archive, char *buf)
{
Handle handle;
u32 bytes = 0;
FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_WRITE | FS_OPEN_CREATE, 0);
FSFILE_Write(handle, &bytes, 0, buf, size, FS_WRITE_FLUSH);
FSFILE_Close(handle);
return bytes;
Result res = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_WRITE, 0);
if (R_FAILED(res)) return res;
res = FSFILE_Write(handle, &bytes, 0, buf, size, FS_WRITE_FLUSH);
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)

View File

@@ -1,7 +1,11 @@
#include <stdlib.h>
#include <stdio.h>
#include <3ds.h>
#include <string.h>
#include "fs.h"
#include "themes.h"
#include "unicode.h"
int init_services(void)
{
@@ -30,11 +34,26 @@ int de_init_services(void)
int main(void)
{
init_services();
consoleInit(GFX_TOP, NULL);
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();
return 0;
}

View File

@@ -1,9 +1,13 @@
#include <3ds.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.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 *music;
@@ -13,46 +17,49 @@ Result single_install(theme* theme)
u32 music_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;
memset(&savedata_buf[0x13b8], 0, 8);
savedata_buf[0x13bd] = 3;
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);
// 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 {
u16 path[0x106];
memcpy(path, theme->path, 0x106);
u16 path[0x106] = {0};
memcpy(path, theme_to_install.path, 0x106 * sizeof(u16));
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)
{
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
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 {
u16 path[0x106];
memcpy(path, theme->path, 0x106);
u16 path[0x106] = {0};
memcpy(path, theme_to_install.path, 0x106 * sizeof(16));
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)
@@ -61,15 +68,17 @@ Result single_install(theme* theme)
music = calloc(1, 3371008);
} else if (size > 3371008) {
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);
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);
thememanage_buf[0x00] = 1;

View File

@@ -1,19 +1,20 @@
#include <stdlib.h>
#include <3ds.h>
#include <string.h>
#include "unicode.h"
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;
}
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);
utf16_to_utf8(data, zip_path, len);
utf16_to_utf8(data, input, len);
memcpy(&data[len], addition, strlen(addition));
utf8_to_utf16(input, data, len + strlen(addition));