mirror of
https://github.com/astronautlevel2/Anemone3DS.git
synced 2026-01-24 08:42:43 -05:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 26d8c283b3 | |||
| 4ceac06f0c | |||
| 337693ca13 | |||
| 8ba1fed5d7 | |||
|
|
d99f1c97a0 | ||
|
|
1a1b3e25b0 | ||
| c92c20d4e8 | |||
| ef456c7e9e | |||
| 1103885baf | |||
| 5564ffe31b | |||
| 97ab2307f8 | |||
|
|
47c64828a4 | ||
| d3aa231c3f | |||
|
|
3fb86c80be | ||
|
|
67566330a5 | ||
| 68805337bf | |||
|
|
416cca88d3 | ||
| 2be3bde64d | |||
| c46c5ff8cb | |||
|
|
6b5b391d7b | ||
|
|
dc1cbda232 | ||
|
|
e63a4066a1 | ||
| 2e71fc5954 | |||
| 778e1a8331 | |||
| 0871f4f30b | |||
| 62f4356a17 | |||
|
|
3e2c5994ca |
2
Makefile
2
Makefile
@@ -49,7 +49,7 @@ ICON_FLAGS := nosavebackups,visible
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
|
||||
|
||||
CFLAGS := -g -Wall -Wextra -mword-relocations \
|
||||
CFLAGS := -g -Wall -Wextra -O2 -mword-relocations \
|
||||
-ffunction-sections \
|
||||
$(ARCH)
|
||||
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
struct quirc* context;
|
||||
u16 *buf;
|
||||
bool qr_mode;
|
||||
|
||||
void init_qr(void);
|
||||
|
||||
@@ -46,6 +46,9 @@
|
||||
#define WARNING 1
|
||||
static const int THEMES_PER_SCREEN = 4;
|
||||
|
||||
bool homebrew;
|
||||
bool splash_mode;
|
||||
|
||||
enum TextureID {
|
||||
TEXTURE_FONT_RESERVED = 0, //used by pp2d for the font
|
||||
TEXTURE_ARROW,
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
void init_screens(void);
|
||||
void exit_screens(void);
|
||||
|
||||
void draw_themext_error(void);
|
||||
void draw_base_interface(void);
|
||||
void draw_qr(void);
|
||||
void draw_theme_install(int install_type);
|
||||
void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_theme, bool preview_mode, int shuffle_theme_count);
|
||||
void draw_splash_install(int install_type);
|
||||
|
||||
@@ -30,12 +30,23 @@
|
||||
#include "common.h"
|
||||
|
||||
typedef struct{
|
||||
u16 name[0x106];
|
||||
u16 top_path[0x106];
|
||||
u16 bottom_path[0x106];
|
||||
u16 name[0x40];
|
||||
u16 desc[0x80];
|
||||
u16 author[0x40];
|
||||
|
||||
u32 placeholder_color;
|
||||
ssize_t icon_id;
|
||||
|
||||
u16 path[0x106];
|
||||
bool is_zip;
|
||||
} Splash_s;
|
||||
|
||||
Splash_s *splashes_list;
|
||||
int splash_count;
|
||||
|
||||
Result get_splashes(Splash_s** splashes_list, int *splash_count);
|
||||
void splash_install(Splash_s splash_to_install);
|
||||
void splash_delete();
|
||||
void load_splash_preview(Splash_s *splash);
|
||||
|
||||
#endif
|
||||
@@ -51,7 +51,7 @@ int theme_count;
|
||||
|
||||
void load_theme_preview(Theme_s *theme);
|
||||
Result get_themes(Theme_s **themes_list, int *theme_count);
|
||||
void add_theme(Theme_s **themes_list, int *theme_count, char *path, char *filename);
|
||||
void del_theme(u16 *path);
|
||||
Result single_install(Theme_s theme);
|
||||
Result shuffle_install(Theme_s *themes_list, int theme_count);
|
||||
Result bgm_install(Theme_s bgm_to_install);
|
||||
|
||||
103
source/camera.c
103
source/camera.c
@@ -30,20 +30,34 @@
|
||||
#include "draw.h"
|
||||
#include "fs.h"
|
||||
#include "themes.h"
|
||||
#include "pp2d/pp2d/pp2d.h"
|
||||
|
||||
u32 transfer_size;
|
||||
Handle event;
|
||||
struct quirc* context;
|
||||
|
||||
void init_qr(void)
|
||||
{
|
||||
camInit();
|
||||
CAMU_SetSize(SELECT_OUT1_OUT2, SIZE_CTR_TOP_LCD, CONTEXT_A);
|
||||
CAMU_SetOutputFormat(SELECT_OUT1_OUT2, OUTPUT_RGB_565, CONTEXT_A);
|
||||
CAMU_SetFrameRate(SELECT_OUT1_OUT2, FRAME_RATE_10);
|
||||
|
||||
CAMU_SetNoiseFilter(SELECT_OUT1_OUT2, true);
|
||||
CAMU_SetAutoExposure(SELECT_OUT1_OUT2, true);
|
||||
CAMU_SetAutoWhiteBalance(SELECT_OUT1_OUT2, true);
|
||||
|
||||
CAMU_SetTrimming(PORT_CAM1, false);
|
||||
CAMU_SetTrimming(PORT_CAM2, false);
|
||||
|
||||
buf = malloc(sizeof(u16) * 400 * 240 * 2);
|
||||
CAMU_GetMaxBytes(&transfer_size, 400, 240);
|
||||
CAMU_SetTransferBytes(PORT_BOTH, transfer_size, 400, 240);
|
||||
|
||||
CAMU_Activate(SELECT_OUT1_OUT2);
|
||||
event = 0;
|
||||
|
||||
CAMU_ClearBuffer(PORT_BOTH);
|
||||
CAMU_SynchronizeVsyncTiming(SELECT_OUT1, SELECT_OUT2);
|
||||
CAMU_StartCapture(PORT_BOTH);
|
||||
|
||||
context = quirc_new();
|
||||
quirc_resize(context, 400, 240);
|
||||
@@ -51,27 +65,83 @@ void init_qr(void)
|
||||
|
||||
void exit_qr(void)
|
||||
{
|
||||
CAMU_StopCapture(PORT_BOTH);
|
||||
CAMU_Activate(SELECT_NONE);
|
||||
camExit();
|
||||
quirc_destroy(context);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void scan_qr(u16 *buf)
|
||||
{
|
||||
int w;
|
||||
int h;
|
||||
|
||||
u8 *image = (u8*) quirc_begin(context, &w, &h);
|
||||
|
||||
for (ssize_t x = 0; x < w; x++)
|
||||
{
|
||||
for (ssize_t y = 0; y < h; y++)
|
||||
{
|
||||
u16 px = buf[y * 400 + x];
|
||||
image[y * w + x] = (u8)(((((px >> 11) & 0x1F) << 3) + (((px >> 5) & 0x3F) << 2) + ((px & 0x1F) << 3)) / 3);
|
||||
}
|
||||
}
|
||||
|
||||
quirc_end(context);
|
||||
|
||||
if (quirc_count(context) > 0)
|
||||
{
|
||||
struct quirc_code code;
|
||||
struct quirc_data data;
|
||||
quirc_extract(context, 0, &code);
|
||||
if (!quirc_decode(&code, &data))
|
||||
{
|
||||
qr_mode = false;
|
||||
|
||||
http_get((char*)data.payload, splash_mode ? "/Splashes/" : "/Themes/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void take_picture(void)
|
||||
{
|
||||
u32 transfer_size;
|
||||
Handle cam_handle = 0;
|
||||
CAMU_GetMaxBytes(&transfer_size, 400, 240);
|
||||
CAMU_SetTransferBytes(PORT_BOTH, transfer_size, 400, 240);
|
||||
CAMU_Activate(SELECT_OUT1_OUT2);
|
||||
CAMU_ClearBuffer(PORT_BOTH);
|
||||
CAMU_SynchronizeVsyncTiming(SELECT_OUT1, SELECT_OUT2);
|
||||
CAMU_StartCapture(PORT_BOTH);
|
||||
CAMU_SetReceiving(&cam_handle, buf, PORT_CAM1, 400 * 240 * 2, transfer_size);
|
||||
svcWaitSynchronization(cam_handle, U64_MAX);
|
||||
u16 *buf = malloc(sizeof(u16) * 400 * 240 * 4);
|
||||
if (buf == NULL) return;
|
||||
CAMU_SetReceiving(&event, buf, PORT_CAM1, 240 * 400 * 2, transfer_size);
|
||||
svcWaitSynchronization(event, U64_MAX);
|
||||
svcCloseHandle(event);
|
||||
pp2d_begin_draw(GFX_TOP);
|
||||
u32 *rgba8_buf = malloc(240 * 400 * sizeof(u32));
|
||||
if (rgba8_buf == NULL) return;
|
||||
for (int i = 0; i < 240 * 400; i++)
|
||||
{
|
||||
rgba8_buf[i] = RGB565_TO_ABGR8(buf[i]);
|
||||
}
|
||||
pp2d_load_texture_memory(TEXTURE_QR, rgba8_buf, 400, 240);
|
||||
pp2d_draw_texture(TEXTURE_QR, 0, 0);
|
||||
pp2d_draw_rectangle(0, 216, 400, 24, RGBA8(55, 122, 168, 255));
|
||||
pp2d_draw_text_center(GFX_TOP, 220, 0.5, 0.5, RGBA8(255, 255, 255, 255), "Press \uE005 To Quit");
|
||||
pp2d_draw_rectangle(0, 0, 400, 24, RGBA8(55, 122, 168, 255));
|
||||
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, RGBA8(255, 255, 255, 255), "Press \uE004 To Scan");
|
||||
pp2d_end_draw();
|
||||
free(rgba8_buf);
|
||||
pp2d_free_texture(TEXTURE_QR);
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
if (kDown & KEY_L)
|
||||
{
|
||||
CAMU_StopCapture(PORT_BOTH);
|
||||
svcCloseHandle(cam_handle);
|
||||
CAMU_Activate(PORT_NONE);
|
||||
CAMU_Activate(SELECT_NONE);
|
||||
scan_qr(buf);
|
||||
CAMU_Activate(SELECT_OUT1_OUT2);
|
||||
CAMU_StartCapture(PORT_BOTH);
|
||||
}
|
||||
if (kDown & KEY_R)
|
||||
{
|
||||
exit_qr();
|
||||
qr_mode = false;
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -201,7 +271,8 @@ Result http_get(char *url, char *path)
|
||||
remake_file(path_to_file, ArchiveSD, size);
|
||||
buf_to_file(size, path_to_file, ArchiveSD, (char*)buf);
|
||||
|
||||
add_theme(&themes_list, &theme_count, path_to_file, filename);
|
||||
if (splash_mode) get_splashes(&splashes_list, &splash_count);
|
||||
else get_themes(&themes_list, &theme_count);
|
||||
|
||||
exit_qr();
|
||||
|
||||
|
||||
122
source/draw.c
122
source/draw.c
@@ -25,12 +25,14 @@
|
||||
*/
|
||||
|
||||
#include "draw.h"
|
||||
#include "common.h"
|
||||
|
||||
#include "pp2d/pp2d/pp2d.h"
|
||||
#include "quirc/quirc.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
|
||||
enum Colors {
|
||||
COLOR_BACKGROUND = ABGR8(255, 32, 28, 35), //silver-y black
|
||||
COLOR_ACCENT = RGBA8(55, 122, 168, 255),
|
||||
@@ -66,55 +68,9 @@ void exit_screens(void)
|
||||
static int theme_vertical_scroll = 0;
|
||||
static int splash_vertical_scroll = 0;
|
||||
|
||||
void draw_qr(void)
|
||||
void draw_themext_error(void)
|
||||
{
|
||||
pp2d_begin_draw(GFX_TOP);
|
||||
pp2d_free_texture(TEXTURE_QR);
|
||||
take_picture();
|
||||
u32 *rgba8_buf = malloc(240 * 400 * sizeof(u32));
|
||||
for (int i = 0; i < 240 * 400; i++)
|
||||
{
|
||||
rgba8_buf[i] = RGB565_TO_RGBA8(buf[i]);
|
||||
u8 *byte_pointer = (u8*)&rgba8_buf[i];
|
||||
u8 r = *(byte_pointer+3);
|
||||
u8 g = *(byte_pointer+2);
|
||||
u8 b = *(byte_pointer+1);
|
||||
u8 a = *(byte_pointer);
|
||||
rgba8_buf[i] = RGBA8(r, g, b, a);
|
||||
}
|
||||
pp2d_load_texture_memory(TEXTURE_QR, rgba8_buf, 400, 240);
|
||||
pp2d_draw_texture(TEXTURE_QR, 0, 0);
|
||||
free(rgba8_buf);
|
||||
pp2d_end_draw();
|
||||
|
||||
int w;
|
||||
int h;
|
||||
|
||||
u8 *image = (u8*) quirc_begin(context, &w, &h);
|
||||
|
||||
for (ssize_t x = 0; x < w; x++)
|
||||
{
|
||||
for (ssize_t y = 0; y < h; y++)
|
||||
{
|
||||
u16 px = buf[y * 400 + x];
|
||||
image[y * w + x] = (u8)(((((px >> 11) & 0x1F) << 3) + (((px >> 5) & 0x3F) << 2) + ((px & 0x1F) << 3)) / 3);
|
||||
}
|
||||
}
|
||||
|
||||
quirc_end(context);
|
||||
|
||||
if (quirc_count(context) > 0)
|
||||
{
|
||||
struct quirc_code code;
|
||||
struct quirc_data data;
|
||||
quirc_extract(context, 0, &code);
|
||||
if (!quirc_decode(&code, &data))
|
||||
{
|
||||
qr_mode = false;
|
||||
|
||||
http_get((char*)data.payload, "/Themes/");
|
||||
}
|
||||
}
|
||||
throw_error("Theme extdata does not exist\nSet a default theme from the home menu", ERROR);
|
||||
}
|
||||
|
||||
void draw_base_interface(void)
|
||||
@@ -145,13 +101,36 @@ void draw_base_interface(void)
|
||||
pp2d_draw_on(GFX_TOP);
|
||||
}
|
||||
void throw_error(char* error, int error_type) {
|
||||
draw_base_interface();
|
||||
|
||||
switch (error_type) {
|
||||
case ERROR:
|
||||
pp2d_draw_text(70, 120, 0.8, 0.8, COLOR_RED, error);
|
||||
break;
|
||||
while (aptMainLoop())
|
||||
{
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
draw_base_interface();
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.6, 0.6, COLOR_RED, error);
|
||||
pp2d_draw_wtext_center(GFX_TOP, 150, 0.6, 0.6, COLOR_WHITE, L"Press \uE000 to shut down.");
|
||||
pp2d_end_draw();
|
||||
if (kDown & KEY_A) {
|
||||
if (homebrew)
|
||||
APT_HardwareResetAsync();
|
||||
else {
|
||||
srvPublishToSubscriber(0x202, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
case WARNING:
|
||||
pp2d_draw_text(70, 120, 0.8, 0.8, COLOR_YELLOW, error);
|
||||
while (aptMainLoop())
|
||||
{
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
draw_base_interface();
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.6, 0.6, COLOR_YELLOW, error);
|
||||
pp2d_draw_wtext_center(GFX_TOP, 150, 0.6, 0.6, COLOR_WHITE, L"Press \uE000 to continue.");
|
||||
pp2d_end_draw();
|
||||
if (kDown & KEY_A) break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
pp2d_end_draw();
|
||||
@@ -184,8 +163,10 @@ void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_t
|
||||
|
||||
if (themes_list == NULL)
|
||||
{
|
||||
pp2d_begin_draw(GFX_TOP);
|
||||
pp2d_draw_text_center(GFX_TOP, 100, 1, 1, COLOR_WHITE, "NO THEMES FOUND");
|
||||
draw_base_interface();
|
||||
pp2d_draw_text_center(GFX_TOP, 80, 0.7, 0.7, COLOR_YELLOW, "No themes found!");
|
||||
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_YELLOW, "Press \uE005 to download from QR");
|
||||
pp2d_draw_text_center(GFX_TOP, 140, 0.7, 0.7, COLOR_YELLOW, "Or \uE045 to quit");
|
||||
pp2d_end_draw();
|
||||
return;
|
||||
}
|
||||
@@ -303,23 +284,39 @@ void draw_splash_interface(Splash_s *splashes_list, int splash_count, int select
|
||||
{
|
||||
if (splashes_list == NULL)
|
||||
{
|
||||
pp2d_begin_draw(GFX_TOP);
|
||||
pp2d_draw_text_center(GFX_TOP, 100, 1, 1, COLOR_WHITE, "NO SPLASHES FOUND");
|
||||
draw_base_interface();
|
||||
pp2d_draw_text_center(GFX_TOP, 80, 0.7, 0.7, COLOR_YELLOW, "No splashes found!");
|
||||
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_YELLOW, "Press \uE005 to download from QR");
|
||||
pp2d_draw_text_center(GFX_TOP, 140, 0.7, 0.7, COLOR_YELLOW, "Or \uE045 to quit");
|
||||
pp2d_end_draw();
|
||||
return;
|
||||
}
|
||||
|
||||
Splash_s current_splash = splashes_list[selected_splash];
|
||||
|
||||
if (preview_mode)
|
||||
{
|
||||
// TODO: Splash Previews
|
||||
pp2d_begin_draw(GFX_TOP);
|
||||
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 0, 0, 400, 240);
|
||||
pp2d_draw_on(GFX_BOTTOM);
|
||||
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 40, 240, 320, 240);
|
||||
} else {
|
||||
draw_base_interface();
|
||||
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, "Splash mode");
|
||||
wchar_t title[0x40] = {0};
|
||||
utf16_to_utf32((u32*)title, current_splash.name, 0x40);
|
||||
pp2d_draw_wtext_wrap(20, 30, 0.7, 0.7, COLOR_WHITE, 380, title);
|
||||
wchar_t author[0x40] = {0};
|
||||
utf16_to_utf32((u32*)author, current_splash.author, 0x40);
|
||||
pp2d_draw_text(20, 50, 0.5, 0.5, COLOR_WHITE, "By: ");
|
||||
pp2d_draw_wtext_wrap(44, 50, 0.5, 0.5, COLOR_WHITE, 380, author);
|
||||
wchar_t description[0xa6] = {0};
|
||||
utf16_to_utf32((u32*)description, current_splash.desc, 0xb0);
|
||||
pp2d_draw_wtext_wrap(20, 65, 0.5, 0.5, COLOR_WHITE, 363, description);
|
||||
|
||||
pp2d_draw_wtext_center(GFX_TOP, 180, 0.7, 0.7, COLOR_WHITE, L"\uE000 Install Splash \uE004 Switch to Themes");
|
||||
pp2d_draw_wtext_center(GFX_TOP, 210, 0.7, 0.7, COLOR_WHITE, L"\uE002 Delete current Splash");
|
||||
pp2d_draw_wtext_center(GFX_TOP, 150, 0.7, 0.7, COLOR_WHITE, L"\uE003 Preview Splash \uE005 Scan QRCode");
|
||||
pp2d_draw_wtext(130, 120, 0.6, 0.6, COLOR_WHITE, L"");
|
||||
|
||||
pp2d_draw_on(GFX_BOTTOM);
|
||||
for (int i = 0; i < splash_count; i++) {
|
||||
if (splash_count <= THEMES_PER_SCREEN)
|
||||
@@ -356,7 +353,12 @@ void draw_splash_interface(Splash_s *splashes_list, int splash_count, int select
|
||||
font_color = COLOR_BLACK;
|
||||
pp2d_draw_rectangle(0, 24 + vertical_offset, 320, 48, COLOR_CURSOR);
|
||||
}
|
||||
pp2d_draw_wtext(15, 40 + vertical_offset, 0.55, 0.55, font_color, name);
|
||||
pp2d_draw_wtext(54, 40 + vertical_offset, 0.55, 0.55, font_color, name);
|
||||
|
||||
if (!current_splash.placeholder_color)
|
||||
pp2d_draw_texture(current_splash.icon_id, 0, 24 + vertical_offset);
|
||||
else
|
||||
pp2d_draw_rectangle(0, 24 + vertical_offset, 48, 48, current_splash.placeholder_color);
|
||||
}
|
||||
}
|
||||
pp2d_end_draw();
|
||||
|
||||
16
source/fs.c
16
source/fs.c
@@ -38,7 +38,7 @@ int filename_compare(__attribute__((unused)) unzFile file, const char *current_f
|
||||
|
||||
Result open_archives(void)
|
||||
{
|
||||
|
||||
romfsInit();
|
||||
u8 regionCode;
|
||||
u32 archive1;
|
||||
u32 archive2;
|
||||
@@ -68,9 +68,13 @@ Result open_archives(void)
|
||||
archive2 = 0x00;
|
||||
}
|
||||
|
||||
|
||||
retValue = FSUSER_OpenArchive(&ArchiveSD, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""));
|
||||
if(R_FAILED(retValue)) return retValue;
|
||||
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/Themes"), FS_ATTRIBUTE_DIRECTORY);
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/Splashes"), FS_ATTRIBUTE_DIRECTORY);
|
||||
|
||||
u32 homeMenuPath[3] = {MEDIATYPE_SD, archive2, 0};
|
||||
home.type = PATH_BINARY;
|
||||
home.size = 0xC;
|
||||
@@ -85,7 +89,11 @@ Result open_archives(void)
|
||||
retValue = FSUSER_OpenArchive(&ArchiveThemeExt, ARCHIVE_EXTDATA, theme);
|
||||
if(R_FAILED(retValue)) return retValue;
|
||||
|
||||
romfsInit();
|
||||
Handle test_handle;
|
||||
retValue = FSUSER_OpenFile(&test_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/ThemeManage.bin"), FS_OPEN_READ, 0);
|
||||
if(R_FAILED(retValue)) return retValue;
|
||||
FSFILE_Close(test_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -111,7 +119,7 @@ u64 file_to_buf(FS_Path path, FS_Archive archive, char** buf)
|
||||
|
||||
u64 size;
|
||||
FSFILE_GetSize(file, &size);
|
||||
*buf = malloc(size);
|
||||
*buf = calloc(1, size);
|
||||
FSFILE_Read(file, NULL, 0, *buf, size);
|
||||
FSFILE_Close(file);
|
||||
return size;
|
||||
@@ -135,7 +143,7 @@ u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf)
|
||||
unz_file_info *file_info = malloc(sizeof(unz_file_info));
|
||||
unzGetCurrentFileInfo(zip_handle, file_info, NULL, 0, NULL, 0, NULL, 0);
|
||||
file_size = file_info->uncompressed_size;
|
||||
*buf = malloc(file_size);
|
||||
*buf = calloc(1, file_size);
|
||||
unzOpenCurrentFile(zip_handle);
|
||||
unzReadCurrentFile(zip_handle, *buf, file_size);
|
||||
unzCloseCurrentFile(zip_handle);
|
||||
|
||||
@@ -33,14 +33,15 @@
|
||||
#include <time.h>
|
||||
|
||||
int __stacksize__ = 64 * 1024;
|
||||
Result archive_result;
|
||||
|
||||
int init_services(void)
|
||||
{
|
||||
cfguInit();
|
||||
ptmuInit();
|
||||
httpcInit(0);
|
||||
open_archives();
|
||||
bool homebrew = true;
|
||||
archive_result = open_archives();
|
||||
homebrew = true;
|
||||
if (!envIsHomebrew())
|
||||
{
|
||||
homebrew = false;
|
||||
@@ -79,8 +80,8 @@ int main(void)
|
||||
free(themes_list);
|
||||
themes_list = NULL;
|
||||
}
|
||||
int splash_count = 0;
|
||||
Splash_s *splashes_list = NULL;
|
||||
splash_count = 0;
|
||||
splashes_list = NULL;
|
||||
res = get_splashes(&splashes_list, &splash_count);
|
||||
if (R_FAILED(res))
|
||||
{
|
||||
@@ -89,7 +90,7 @@ int main(void)
|
||||
splashes_list = NULL;
|
||||
}
|
||||
|
||||
bool splash_mode = false;
|
||||
splash_mode = false;
|
||||
int selected_splash = 0;
|
||||
int selected_theme = 0;
|
||||
int previously_selected = 0;
|
||||
@@ -104,7 +105,7 @@ int main(void)
|
||||
|
||||
if (qr_mode)
|
||||
{
|
||||
draw_qr();
|
||||
take_picture();
|
||||
} else if (!splash_mode)
|
||||
{
|
||||
draw_theme_interface(themes_list, theme_count, selected_theme, preview_mode, shuffle_theme_count);
|
||||
@@ -123,9 +124,17 @@ int main(void)
|
||||
else if (kDown & KEY_L)
|
||||
{
|
||||
splash_mode = !splash_mode;
|
||||
} else if (kDown & KEY_R)
|
||||
}
|
||||
|
||||
if (R_FAILED(archive_result) && !splash_mode)
|
||||
{
|
||||
if (splash_mode || preview_mode) {
|
||||
draw_themext_error();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (kDown & KEY_R)
|
||||
{
|
||||
if (preview_mode) {
|
||||
continue;
|
||||
} else {
|
||||
qr_mode = !qr_mode;
|
||||
@@ -149,11 +158,17 @@ int main(void)
|
||||
if (kDown & KEY_Y)
|
||||
{
|
||||
if (!preview_mode)
|
||||
{
|
||||
if (!splash_mode)
|
||||
{
|
||||
if (!current_theme->has_preview)
|
||||
load_theme_preview(current_theme);
|
||||
|
||||
preview_mode = current_theme->has_preview;
|
||||
} else {
|
||||
load_splash_preview(current_splash);
|
||||
preview_mode = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
preview_mode = false;
|
||||
@@ -185,6 +200,9 @@ int main(void)
|
||||
draw_theme_install(SINGLE_INSTALL);
|
||||
single_install(*current_theme);
|
||||
}
|
||||
//these two are here just so I don't forget how to implement them - HM
|
||||
//del_theme(current_theme->path);
|
||||
//get_themes(&themes_list, &theme_count);
|
||||
}
|
||||
|
||||
else if (kDown & KEY_B)
|
||||
|
||||
Submodule source/pp2d updated: 77d7b18ec9...ee6216513a
@@ -26,6 +26,126 @@
|
||||
#include "splashes.h"
|
||||
#include "unicode.h"
|
||||
#include "fs.h"
|
||||
#include "themes.h"
|
||||
#include "pp2d/pp2d/pp2d.h"
|
||||
#include "draw.h"
|
||||
|
||||
void load_splash_preview(Splash_s *splash)
|
||||
{
|
||||
//free the previously loaded preview. wont do anything if there wasnt one
|
||||
pp2d_free_texture(TEXTURE_PREVIEW);
|
||||
|
||||
char *preview_buffer = NULL;
|
||||
u64 size = 0;
|
||||
if (!(splash->is_zip))
|
||||
{
|
||||
u16 path_to_preview[0x106] = {0};
|
||||
strucat(path_to_preview, splash->path);
|
||||
struacat(path_to_preview, "/preview.png");
|
||||
size = file_to_buf(fsMakePath(PATH_UTF16, path_to_preview), ArchiveSD, &preview_buffer);
|
||||
} else {
|
||||
size = zip_file_to_buf("preview.png", splash->path, &preview_buffer);
|
||||
}
|
||||
|
||||
if (!size)
|
||||
{
|
||||
free(preview_buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
u8 * image = NULL;
|
||||
unsigned int width = 0, height = 0;
|
||||
|
||||
int result = lodepng_decode32(&image, &width, &height, (u8*)preview_buffer, size);
|
||||
if (result == 0) // no error
|
||||
{
|
||||
for (u32 i = 0; i < width; i++)
|
||||
{
|
||||
for (u32 j = 0; j < height; j++)
|
||||
{
|
||||
u32 p = (i + j*width) * 4;
|
||||
|
||||
u8 r = *(u8*)(image + p);
|
||||
u8 g = *(u8*)(image + p + 1);
|
||||
u8 b = *(u8*)(image + p + 2);
|
||||
u8 a = *(u8*)(image + p + 3);
|
||||
|
||||
*(image + p) = a;
|
||||
*(image + p + 1) = b;
|
||||
*(image + p + 2) = g;
|
||||
*(image + p + 3) = r;
|
||||
}
|
||||
}
|
||||
|
||||
pp2d_load_texture_memory(TEXTURE_PREVIEW, image, (u32)width, (u32)height);
|
||||
}
|
||||
|
||||
free(image);
|
||||
free(preview_buffer);
|
||||
}
|
||||
|
||||
|
||||
static void parse_smdh(Splash_s *splash, ssize_t textureID, u16 *splash_name)
|
||||
{
|
||||
char *info_buffer = NULL;
|
||||
u64 size = 0;
|
||||
if (!(splash->is_zip))
|
||||
{
|
||||
u16 path_to_smdh[0x106] = {0};
|
||||
strucat(path_to_smdh, splash->path);
|
||||
struacat(path_to_smdh, "/info.smdh");
|
||||
|
||||
size = file_to_buf(fsMakePath(PATH_UTF16, path_to_smdh), ArchiveSD, &info_buffer);
|
||||
} else {
|
||||
size = zip_file_to_buf("info.smdh", splash->path, &info_buffer);
|
||||
}
|
||||
|
||||
if (!size)
|
||||
{
|
||||
free(info_buffer);
|
||||
memset(splash->name, 0, 0x80);
|
||||
memset(splash->desc, 0, 0x100);
|
||||
memset(splash->author, 0, 0x80);
|
||||
memcpy(splash->name, splash_name, 0x80);
|
||||
utf8_to_utf16(splash->desc, (u8*)"No description", 0x100);
|
||||
utf8_to_utf16(splash->author, (u8*)"Unknown author", 0x80);
|
||||
splash->placeholder_color = RGBA8(rand() % 255, rand() % 255, rand() % 255, 255);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(splash->name, info_buffer + 0x08, 0x80);
|
||||
memcpy(splash->desc, info_buffer + 0x88, 0x100);
|
||||
memcpy(splash->author, info_buffer + 0x188, 0x80);
|
||||
|
||||
u16 *icon_data = malloc(0x1200);
|
||||
memcpy(icon_data, info_buffer + 0x24C0, 0x1200);
|
||||
|
||||
const u32 width = 48, height = 48;
|
||||
u32 *image = malloc(width*height*sizeof(u32));
|
||||
|
||||
for (u32 x = 0; x < width; x++)
|
||||
{
|
||||
for (u32 y = 0; y < height; y++)
|
||||
{
|
||||
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));
|
||||
|
||||
u8 r = ((icon_data[source_pixel] >> 11) & 0b11111) << 3;
|
||||
u8 g = ((icon_data[source_pixel] >> 5) & 0b111111) << 2;
|
||||
u8 b = (icon_data[source_pixel] & 0b11111) << 3;
|
||||
u8 a = 0xFF;
|
||||
|
||||
image[dest_pixel] = (r << 24) | (g << 16) | (b << 8) | a;
|
||||
}
|
||||
}
|
||||
|
||||
pp2d_load_texture_memory(textureID, (u8*)image, (u32)width, (u32)height);
|
||||
splash->icon_id = textureID;
|
||||
|
||||
free(image);
|
||||
free(icon_data);
|
||||
free(info_buffer);
|
||||
}
|
||||
|
||||
Result get_splashes(Splash_s** splashes_list, int *splash_count)
|
||||
{
|
||||
@@ -35,6 +155,13 @@ Result get_splashes(Splash_s** splashes_list, int *splash_count)
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
if (*splashes_list != NULL)
|
||||
{
|
||||
free(*splashes_list);
|
||||
*splashes_list = NULL;
|
||||
*splash_count = 0;
|
||||
}
|
||||
|
||||
u32 entries_read = 1;
|
||||
while (entries_read)
|
||||
{
|
||||
@@ -43,7 +170,7 @@ Result get_splashes(Splash_s** splashes_list, int *splash_count)
|
||||
if (R_FAILED(res) || entries_read == 0)
|
||||
break;
|
||||
|
||||
if (!(entry.attributes & FS_ATTRIBUTE_DIRECTORY))
|
||||
if (!(entry.attributes & FS_ATTRIBUTE_DIRECTORY) && strcmp(entry.shortExt, "ZIP"))
|
||||
continue;
|
||||
|
||||
*splash_count += entries_read;
|
||||
@@ -54,59 +181,90 @@ Result get_splashes(Splash_s** splashes_list, int *splash_count)
|
||||
Splash_s *current_splash = &(*splashes_list)[*splash_count-1];
|
||||
memset(current_splash, 0, sizeof(Splash_s));
|
||||
|
||||
u16 splash_path[0x106] = {0};
|
||||
u16 splash_path[0x106]= {0};
|
||||
struacat(splash_path, SPLASHES_PATH);
|
||||
strucat(splash_path, entry.name);
|
||||
u16 top_path[0x106] = {0};
|
||||
memcpy(top_path, splash_path, 0x106);
|
||||
struacat(top_path, "/splash.bin");
|
||||
u16 bottom_path[0x106] = {0};
|
||||
memcpy(bottom_path, splash_path, 0x106);
|
||||
struacat(bottom_path, "/splashbottom.bin");
|
||||
|
||||
char *temp_buf = NULL;
|
||||
u32 bytes = file_to_buf(fsMakePath(PATH_UTF16, top_path), ArchiveSD, &temp_buf);
|
||||
if (!bytes)
|
||||
{
|
||||
memset(top_path, 0, 0x106 * sizeof(u16));
|
||||
}
|
||||
free(temp_buf);
|
||||
temp_buf = NULL;
|
||||
bytes = file_to_buf(fsMakePath(PATH_UTF16, bottom_path), ArchiveSD, &temp_buf);
|
||||
if (!bytes)
|
||||
{
|
||||
memset(bottom_path, 0, 0x106 * sizeof(u16));
|
||||
}
|
||||
free(temp_buf);
|
||||
memcpy(current_splash->name, entry.name, 0x106);
|
||||
memcpy(current_splash->top_path, top_path, 0x106);
|
||||
memcpy(current_splash->bottom_path, bottom_path, 0x106);
|
||||
char pathchar[0x106] = {0};
|
||||
utf16_to_utf8((u8*) pathchar, splash_path, 0x106);
|
||||
|
||||
memcpy(current_splash->path, splash_path, 0x106 * sizeof(u16));
|
||||
current_splash->is_zip = !strcmp(entry.shortExt, "ZIP");
|
||||
|
||||
ssize_t iconID = TEXTURE_PREVIEW + theme_count + *splash_count;
|
||||
parse_smdh(current_splash, iconID, entry.name);
|
||||
}
|
||||
FSDIR_Close(dir_handle);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void splash_delete()
|
||||
{
|
||||
remove("/luma/splash.bin");
|
||||
remove("/luma/splashbottom.bin");
|
||||
}
|
||||
|
||||
void splash_install(Splash_s splash_to_install)
|
||||
{
|
||||
char *screen_buf;
|
||||
u32 size = file_to_buf(fsMakePath(PATH_UTF16, splash_to_install.top_path), ArchiveSD, &screen_buf);
|
||||
char *screen_buf = NULL;
|
||||
u32 size = 0;
|
||||
if (splash_to_install.is_zip)
|
||||
{
|
||||
size = zip_file_to_buf("splash.bin", splash_to_install.path, &screen_buf);
|
||||
if (size)
|
||||
{
|
||||
remake_file("/luma/splash.bin", ArchiveSD, size);
|
||||
remake_file("/luma/splash.bin", ArchiveSD, sizeof(screen_buf));
|
||||
buf_to_file(size, "/luma/splash.bin", ArchiveSD, screen_buf);
|
||||
free(screen_buf);
|
||||
screen_buf = NULL;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
size = file_to_buf(fsMakePath(PATH_UTF16, splash_to_install.bottom_path), ArchiveSD, &screen_buf);
|
||||
size = zip_file_to_buf("splashbottom.bin", splash_to_install.path, &screen_buf);
|
||||
if (size)
|
||||
{
|
||||
remake_file("/luma/splashbottom.bin", ArchiveSD, size);
|
||||
remake_file("/luma/splashbottom.bin", ArchiveSD, sizeof(screen_buf));
|
||||
buf_to_file(size, "/luma/splashbottom.bin", ArchiveSD, screen_buf);
|
||||
free(screen_buf);
|
||||
screen_buf = NULL;
|
||||
size = 0;
|
||||
}
|
||||
} else {
|
||||
u16 path[0x106] = {0};
|
||||
memcpy(path, splash_to_install.path, 0x106 * sizeof(u16));
|
||||
struacat(path, "/splash.bin");
|
||||
size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &screen_buf);
|
||||
if (size)
|
||||
{
|
||||
remake_file("/luma/splash.bin", ArchiveSD, sizeof(screen_buf));
|
||||
buf_to_file(size, "/luma/splash.bin", ArchiveSD, screen_buf);
|
||||
free(screen_buf);
|
||||
screen_buf = NULL;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
memcpy(path, splash_to_install.path, 0x106 * sizeof(u16));
|
||||
struacat(path, "/splashbottom.bin");
|
||||
size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &screen_buf);
|
||||
if (size)
|
||||
{
|
||||
remake_file("/luma/splashbottom.bin", ArchiveSD, sizeof(screen_buf));
|
||||
buf_to_file(size, "/luma/splashbottom.bin", ArchiveSD, screen_buf);
|
||||
free(screen_buf);
|
||||
screen_buf = NULL;
|
||||
size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
char *config_buf;
|
||||
size = file_to_buf(fsMakePath(PATH_ASCII, "/luma/config.bin"), ArchiveSD, &config_buf);
|
||||
if (size)
|
||||
{
|
||||
if (config_buf[0xC] == 0)
|
||||
{
|
||||
free(config_buf);
|
||||
throw_error("WARNING: Splashes are disabled in Luma Config", WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,7 +158,15 @@ Result get_themes(Theme_s **themes_list, int *theme_count)
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
if (*themes_list != NULL) //used for QR reading and also for theme deletion
|
||||
{
|
||||
free(*themes_list);
|
||||
*themes_list = NULL;
|
||||
*theme_count = 0;
|
||||
}
|
||||
|
||||
u32 entries_read = 1;
|
||||
|
||||
while (entries_read)
|
||||
{
|
||||
FS_DirectoryEntry entry = {0};
|
||||
@@ -196,25 +204,18 @@ Result get_themes(Theme_s **themes_list, int *theme_count)
|
||||
return res;
|
||||
}
|
||||
|
||||
void add_theme(Theme_s **themes_list, int *theme_count, char *path, char *filename)
|
||||
void del_theme(u16 *path)
|
||||
{
|
||||
*theme_count += 1;
|
||||
*themes_list = realloc(*themes_list, (*theme_count) * sizeof(Theme_s));
|
||||
|
||||
Theme_s *current_theme = &(*themes_list)[*theme_count - 1];
|
||||
memset(current_theme, 0, sizeof(Theme_s));
|
||||
|
||||
u16 theme_path[0x106] = {0};
|
||||
utf8_to_utf16(theme_path, (u8*)path, 0x106);
|
||||
|
||||
u16 ufilename[0x106] = {0};
|
||||
utf8_to_utf16(ufilename, (u8*)filename, 0x106);
|
||||
|
||||
memcpy(current_theme->path, theme_path, 0x106 * sizeof(u16));
|
||||
current_theme->is_zip = true;
|
||||
|
||||
ssize_t iconID = TEXTURE_PREVIEW + *theme_count;
|
||||
parse_smdh(current_theme, iconID, ufilename);
|
||||
Handle dir_handle;
|
||||
Result res = FSUSER_OpenDirectory(&dir_handle, ArchiveSD, fsMakePath(PATH_UTF16, path));
|
||||
if (R_SUCCEEDED(res))
|
||||
{
|
||||
FSDIR_Close(dir_handle);
|
||||
FSUSER_DeleteDirectoryRecursively(ArchiveSD, fsMakePath(PATH_UTF16, path));
|
||||
} else
|
||||
{
|
||||
FSUSER_DeleteFile(ArchiveSD, fsMakePath(PATH_UTF16, path));
|
||||
}
|
||||
}
|
||||
|
||||
Result bgm_install(Theme_s bgm_to_install)
|
||||
|
||||
Reference in New Issue
Block a user