Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc21e4d24b | ||
|
|
9a51667546 |
@@ -17,8 +17,3 @@
|
|||||||
* Joel ([@joel16](https://github.com/joel16))
|
* Joel ([@joel16](https://github.com/joel16))
|
||||||
* [@thedax](https://github.com/thedax)
|
* [@thedax](https://github.com/thedax)
|
||||||
* [@Wryyyong](https://github.com/Wryyyong)
|
* [@Wryyyong](https://github.com/Wryyyong)
|
||||||
|
|
||||||
# Translation Contributors
|
|
||||||
* [@cooolgamer](https://github.com/cooolgamer/) for French
|
|
||||||
* Arth ([@iveurne](https://github.com/iveurne)) for Portugese
|
|
||||||
* [@Tristanabs](https://github.com/Tristanabs) and Angelpro09_xd for Spanish
|
|
||||||
|
|||||||
85
Makefile
@@ -90,7 +90,6 @@ CFLAGS := -g -Wall -Wextra -O2 -mword-relocations \
|
|||||||
$(ARCH)
|
$(ARCH)
|
||||||
|
|
||||||
CFLAGS += $(INCLUDE) -D__3DS__ -D_GNU_SOURCE -DVERSION="\"$(VERSION)\"" -DUSER_AGENT="\"$(APP_TITLE)/$(VERSION)\"" -DAPP_TITLE="\"$(APP_TITLE)\""
|
CFLAGS += $(INCLUDE) -D__3DS__ -D_GNU_SOURCE -DVERSION="\"$(VERSION)\"" -DUSER_AGENT="\"$(APP_TITLE)/$(VERSION)\"" -DAPP_TITLE="\"$(APP_TITLE)\""
|
||||||
CFLAGS += `arm-none-eabi-pkg-config --cflags-only-other libcurl vorbisidec libarchive jansson libpng`
|
|
||||||
ifneq ($(strip $(CITRA_MODE)),)
|
ifneq ($(strip $(CITRA_MODE)),)
|
||||||
CFLAGS += -DCITRA_MODE
|
CFLAGS += -DCITRA_MODE
|
||||||
endif
|
endif
|
||||||
@@ -100,7 +99,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
|||||||
ASFLAGS := -g $(ARCH)
|
ASFLAGS := -g $(ARCH)
|
||||||
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||||
|
|
||||||
LIBS := `arm-none-eabi-pkg-config --libs libcurl vorbisidec libarchive jansson libpng` -lcitro2d -lcitro3d -lctru -lm
|
LIBS := -lpng -lvorbisidec -logg -larchive -ljansson -lcitro2d -lcitro3d -lctrud -lm -lz
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# list of directories containing libraries, this must be the top level containing
|
# list of directories containing libraries, this must be the top level containing
|
||||||
@@ -147,24 +146,13 @@ else
|
|||||||
endif
|
endif
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
export T3XFILES := $(GFXFILES:.t3s=.t3x)
|
||||||
ifeq ($(GFXBUILD),$(BUILD))
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export T3XFILES := $(GFXFILES:.t3s=.t3x)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
else
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export ROMFS_T3XFILES := $(patsubst %.t3s, $(GFXBUILD)/%.t3x, $(GFXFILES))
|
|
||||||
export T3XHFILES := $(patsubst %.t3s, $(BUILD)/%.h, $(GFXFILES))
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
endif
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||||
|
|
||||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) \
|
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) \
|
||||||
$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
|
$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
|
||||||
$(addsuffix .o,$(T3XFILES))
|
$(if $(filter $(BUILD),$(GFXBUILD)),$(addsuffix .o,$(T3XFILES)))
|
||||||
|
|
||||||
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
|
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
|
||||||
|
|
||||||
@@ -234,38 +222,17 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
all: $(BUILD) $(GFXBUILD) $(DEPSDIR) $(ROMFS_T3XFILES) $(T3XHFILES) $(OUTDIR)
|
all:
|
||||||
|
@mkdir -p $(BUILD) $(GFXBUILD) $(OUTDIR)
|
||||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||||
@$(BANNERTOOL) makebanner $(BANNER_IMAGE_ARG) "$(BANNER_IMAGE)" $(BANNER_AUDIO_ARG) "$(BANNER_AUDIO)" -o "$(BUILD)/banner.bnr"
|
@$(BANNERTOOL) makebanner $(BANNER_IMAGE_ARG) "$(BANNER_IMAGE)" $(BANNER_AUDIO_ARG) "$(BANNER_AUDIO)" -o "$(BUILD)/banner.bnr"
|
||||||
@$(BANNERTOOL) makesmdh -s "$(APP_TITLE)" -l "$(APP_DESCRIPTION)" -p "$(APP_AUTHOR)" -i "$(APP_ICON)" -f "$(ICON_FLAGS)" -o "$(BUILD)/icon.icn"
|
@$(BANNERTOOL) makesmdh -s "$(APP_TITLE)" -l "$(APP_DESCRIPTION)" -p "$(APP_AUTHOR)" -i "$(APP_ICON)" -f "$(ICON_FLAGS)" -o "$(BUILD)/icon.icn"
|
||||||
$(MAKEROM) -f cia -o "$(OUTPUT).cia" -target t -exefslogo $(MAKEROM_ARGS)
|
$(MAKEROM) -f cia -o "$(OUTPUT).cia" -target t -exefslogo $(MAKEROM_ARGS)
|
||||||
|
|
||||||
$(BUILD):
|
|
||||||
@mkdir -p $@
|
|
||||||
|
|
||||||
ifneq ($(GFXBUILD),$(BUILD))
|
|
||||||
$(GFXBUILD):
|
|
||||||
@mkdir -p $@
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq ($(DEPSDIR),$(BUILD))
|
|
||||||
$(DEPSDIR):
|
|
||||||
@mkdir -p $@
|
|
||||||
endif
|
|
||||||
|
|
||||||
$(OUTDIR):
|
|
||||||
@mkdir -p $@
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
clean:
|
clean:
|
||||||
$(SILENTMSG) clean ...
|
@echo clean ...
|
||||||
@rm -fr $(BUILD) $(GFXBUILD) $(DEPSDIR) $(OUTDIR)
|
@rm -fr $(BUILD) $(GFXBUILD) $(OUTDIR)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
$(GFXBUILD)/%.t3x $(BUILD)/%.h : %.t3s
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
@echo $(notdir $<)
|
|
||||||
@tex3ds -i $< -H $(BUILD)/$*.h -d $(DEPSDIR)/$*.d -o $(GFXBUILD)/$*.t3x
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
else
|
else
|
||||||
@@ -288,18 +255,42 @@ $(OUTPUT).elf : $(OFILES)
|
|||||||
@$(bin2o)
|
@$(bin2o)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
.PRECIOUS : %.t3x %.shbin
|
.PRECIOUS : %.t3x
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
%.t3x.o %_t3x.h : %.t3x
|
%.t3x.o %_t3x.h : %.t3x
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
$(SILENTMSG) $(notdir $<)
|
@$(bin2o)
|
||||||
$(bin2o)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
%.shbin.o %_shbin.h : %.shbin
|
# rules for assembling GPU shaders
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
$(SILENTMSG) $(notdir $<)
|
define shader-as
|
||||||
$(bin2o)
|
$(eval CURBIN := $*.shbin)
|
||||||
|
$(eval DEPSFILE := $(DEPSDIR)/$*.shbin.d)
|
||||||
|
echo "$(CURBIN).o: $< $1" > $(DEPSFILE)
|
||||||
|
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
|
||||||
|
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
|
||||||
|
echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
|
||||||
|
picasso -o $(CURBIN) $1
|
||||||
|
bin2s $(CURBIN) | $(AS) -o $*.shbin.o
|
||||||
|
endef
|
||||||
|
|
||||||
|
%.shbin.o %_shbin.h : %.v.pica %.g.pica
|
||||||
|
@echo $(notdir $^)
|
||||||
|
@$(call shader-as,$^)
|
||||||
|
|
||||||
|
%.shbin.o %_shbin.h : %.v.pica
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(call shader-as,$<)
|
||||||
|
|
||||||
|
%.shbin.o %_shbin.h : %.shlist
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)$(file)))
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.t3x %.h : %.t3s
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@tex3ds -i $< -H $*.h -d $*.d -o $(TOPDIR)/$(GFXBUILD)/$*.t3x
|
||||||
|
|
||||||
-include $(DEPSDIR)/*.d
|
-include $(DEPSDIR)/*.d
|
||||||
|
|
||||||
|
|||||||
17
README.md
@@ -1,9 +1,8 @@
|
|||||||

|

|
||||||
|
|
||||||
A Theme and Splashscreen Manager for the Nintendo 3DS, written in C.
|
A Theme and Splashscreen Manager for the Nintendo 3DS, written in C.\
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
* Make, Git and PKG-Config
|
|
||||||
* devkitARM, which can be installed following the instructions [here](https://devkitpro.org/wiki/Getting_Started).
|
* devkitARM, which can be installed following the instructions [here](https://devkitpro.org/wiki/Getting_Started).
|
||||||
* jansson, libvorbisidec, libpng, and libarchive, which can be retrieved from [devkitPro pacman](https://devkitpro.org/viewtopic.php?f=13&t=8702).
|
* jansson, libvorbisidec, libpng, and libarchive, which can be retrieved from [devkitPro pacman](https://devkitpro.org/viewtopic.php?f=13&t=8702).
|
||||||
* A recent build of [makerom](https://github.com/profi200/Project_CTR) and the latest release of [bannertool](https://github.com/Steveice10/bannertool). These must be added to your PATH.
|
* A recent build of [makerom](https://github.com/profi200/Project_CTR) and the latest release of [bannertool](https://github.com/Steveice10/bannertool). These must be added to your PATH.
|
||||||
@@ -11,8 +10,8 @@ A Theme and Splashscreen Manager for the Nintendo 3DS, written in C.
|
|||||||
# Building
|
# Building
|
||||||
First of all, make sure devkitARM is properly installed - `$DEVKITPRO` and `$DEVKITARM` should be set to `/opt/devkitpro` and `$DEVKITPRO/devkitARM`, respectively.
|
First of all, make sure devkitARM is properly installed - `$DEVKITPRO` and `$DEVKITARM` should be set to `/opt/devkitpro` and `$DEVKITPRO/devkitARM`, respectively.
|
||||||
After that, open the directory you want to clone the repo into, and execute
|
After that, open the directory you want to clone the repo into, and execute
|
||||||
`git clone https://git.ataber.pw.com/ash/Anemone3DS` (or any other cloning method).
|
`git clone https://github.com/astronautlevel2/Anemone3DS` (or any other cloning method).
|
||||||
To install the prerequisite libraries, begin by ensuring devkitPro pacman (and the base install group, `3ds-dev`) is installed, and then install the dkP packages `3ds-jansson`, `3ds-libvorbisidec`, `3ds-libpng`, `3ds-lz4`, `3ds-libarchive` and `3ds-curl` using `[sudo] [dkp-]pacman -S <package-name>`. System wide packages `make`, `git` and `pkg-config` are also needed.
|
To install the prerequisite libraries, begin by ensuring devkitPro pacman (and the base install group, `3ds-dev`) is installed, and then install the dkP packages `3ds-jansson`, `3ds-libvorbisidec`, `3ds-libpng`, and `3ds-libarchive` using `[sudo] [dkp-]pacman -S <package-name>`.
|
||||||
|
|
||||||
After adding [makerom](https://github.com/profi200/Project_CTR) and [bannertool](https://github.com/Steveice10/buildtools) to your PATH, just enter your directory and run `make`. All built binaries will be in `/out/`.
|
After adding [makerom](https://github.com/profi200/Project_CTR) and [bannertool](https://github.com/Steveice10/buildtools) to your PATH, just enter your directory and run `make`. All built binaries will be in `/out/`.
|
||||||
|
|
||||||
@@ -29,11 +28,9 @@ Special thanks go to these people who, whilst not directly contributing, helped
|
|||||||
* [SteveIce10](https://github.com/SteveIce10), whose QR code in FBI was essential.
|
* [SteveIce10](https://github.com/SteveIce10), whose QR code in FBI was essential.
|
||||||
* [BernardoGiordano](https://github.com/BernardoGiordano) for making pp2d, and being super responsive to feature requests and just general help.
|
* [BernardoGiordano](https://github.com/BernardoGiordano) for making pp2d, and being super responsive to feature requests and just general help.
|
||||||
* [yellows8](https://github.com/yellows8) for his home menu extdump tool, which was invaluable in debugging.
|
* [yellows8](https://github.com/yellows8) for his home menu extdump tool, which was invaluable in debugging.
|
||||||
* [MrCheeze](https://github.com/MrCheeze) and [AntiMach](https://github.com/AntiMach) whose GYTB and ABE code served as a reference on badge management
|
* the folks on #dev of Nintendo Homebrew, who helped with unicode shenanigans (especially [Stary2001](https://github.com/Stary2001), [Fenrir](https://github.com/FenrirWolf), and DanielKO).
|
||||||
* [Tobid7](https://github.com/tobid7) whose BCSTM-Player project served as a reference on the BCSTM format
|
* the maintainers for all used libraries, including but not limited to ctrulib, zlib, citro3d, pp2d, and quirc.
|
||||||
* The folks on #dev of Nintendo Homebrew, who helped with unicode shenanigans (especially [Stary2001](https://github.com/Stary2001), [Fenrir](https://github.com/FenrirWolf), and DanielKO).
|
* all the people who helped keep me going and motivated me to work. This includes, but is definitely not limited to:
|
||||||
* The maintainers for all used libraries, including but not limited to ctrulib, libarchive, citro3d, citro2d, and quirc. An especially big thanks to the devkitPro team for maintaining a phenomenal toolchain.
|
|
||||||
* All the people who helped keep me going and motivated me to work. This includes, but is definitely not limited to:
|
|
||||||
|
|
||||||
+ The members of the [Nintendo Homebrew Discord](https://discord.gg/C29hYvh)
|
+ The members of the [Nintendo Homebrew Discord](https://discord.gg/C29hYvh)
|
||||||
+ The members of the __Secret Shack Service Discord__
|
+ The members of the __Secret Shack Service Discord__
|
||||||
|
|||||||
BIN
assets/back.png
|
Before Width: | Height: | Size: 606 B |
BIN
assets/badge.png
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 404 B After Width: | Height: | Size: 404 B |
BIN
assets/dump.png
|
Before Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 179 B After Width: | Height: | Size: 179 B |
|
Before Width: | Height: | Size: 3.0 KiB |
BIN
assets/qr.png
|
Before Width: | Height: | Size: 4.4 KiB |
@@ -11,19 +11,13 @@ battery4.png
|
|||||||
battery5.png
|
battery5.png
|
||||||
browse.png
|
browse.png
|
||||||
charging.png
|
charging.png
|
||||||
install.png
|
download.png
|
||||||
exit.png
|
exit.png
|
||||||
installed.png
|
installed.png
|
||||||
menu.png
|
list.png
|
||||||
no_home.png
|
|
||||||
preview.png
|
preview.png
|
||||||
select.png
|
select.png
|
||||||
shuffle.png
|
shuffle.png
|
||||||
shuffle_no_bgm.png
|
shuffle_no_bgm.png
|
||||||
sort.png
|
sort.png
|
||||||
start.png
|
start.png
|
||||||
qr.png
|
|
||||||
bgm_only.png
|
|
||||||
back.png
|
|
||||||
dump.png
|
|
||||||
badge.png
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Anemone3DS
|
|
||||||
* Copyright (C) 2016-2024 Contributors in CONTRIBUTORS.md
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BADGES_H
|
|
||||||
#define BADGES_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "fs.h"
|
|
||||||
#include "conversion.h"
|
|
||||||
#include "unicode.h"
|
|
||||||
|
|
||||||
#define MAX_BADGE 1000
|
|
||||||
#define BADGE_DATA_SIZE 0xF4DF80
|
|
||||||
#define BADGE_MNG_SIZE 0xD4A8
|
|
||||||
|
|
||||||
Result install_badges(void);
|
|
||||||
Result extract_badges(void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u16 * camera_buffer;
|
u16* camera_buffer;
|
||||||
|
|
||||||
Handle event_stop;
|
Handle event_stop;
|
||||||
Thread cam_thread, ui_thread;
|
Thread cam_thread, ui_thread;
|
||||||
@@ -45,7 +45,7 @@ typedef struct {
|
|||||||
|
|
||||||
bool any_update;
|
bool any_update;
|
||||||
|
|
||||||
struct quirc * context;
|
struct quirc* context;
|
||||||
} qr_data;
|
} qr_data;
|
||||||
|
|
||||||
bool init_qr(void);
|
bool init_qr(void);
|
||||||
|
|||||||
@@ -28,19 +28,16 @@
|
|||||||
#define COLORS_H
|
#define COLORS_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
typedef u32 Color;
|
typedef u32 Color;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
COLOR_BACKGROUND, //silver-y black
|
COLOR_BACKGROUND, //silver-y black
|
||||||
COLOR_ACCENT,
|
COLOR_ACCENT,
|
||||||
COLOR_WHITE_BACKGROUND,
|
COLOR_WHITE,
|
||||||
COLOR_WHITE_ACCENT,
|
|
||||||
COLOR_CURSOR,
|
COLOR_CURSOR,
|
||||||
COLOR_BLACK,
|
COLOR_BLACK,
|
||||||
COLOR_RED_BACKGROUND,
|
COLOR_RED,
|
||||||
COLOR_RED_ACCENT,
|
|
||||||
COLOR_YELLOW,
|
COLOR_YELLOW,
|
||||||
|
|
||||||
COLOR_AMOUNT,
|
COLOR_AMOUNT,
|
||||||
|
|||||||
@@ -38,24 +38,12 @@
|
|||||||
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
|
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
|
||||||
#define POS() DEBUG("%s (line %d)...\n", __func__, __LINE__)
|
#define POS() DEBUG("%s (line %d)...\n", __func__, __LINE__)
|
||||||
|
|
||||||
#define DEBUGPOS(...) do {\
|
#define DEBUGPOS(...) \
|
||||||
POS(); \
|
POS(); \
|
||||||
DEBUG(__VA_ARGS__); \
|
DEBUG(__VA_ARGS__)
|
||||||
} while(0)
|
|
||||||
|
|
||||||
static inline int min(const int a, const int b)
|
|
||||||
{
|
|
||||||
return a > b ? b : a;
|
|
||||||
}
|
|
||||||
static inline int max(const int a, const int b)
|
|
||||||
{
|
|
||||||
return a < b ? b : a;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define FASTSCROLL_WAIT 1e8
|
#define FASTSCROLL_WAIT 1e8
|
||||||
|
|
||||||
#define BETWEEN(min, x, max) (min < x && x < max)
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MODE_THEMES = 0,
|
MODE_THEMES = 0,
|
||||||
MODE_SPLASHES,
|
MODE_SPLASHES,
|
||||||
@@ -63,23 +51,7 @@ typedef enum {
|
|||||||
MODE_AMOUNT,
|
MODE_AMOUNT,
|
||||||
} EntryMode;
|
} EntryMode;
|
||||||
|
|
||||||
typedef enum {
|
extern const char * main_paths[MODE_AMOUNT];
|
||||||
DRAW_MODE_LIST = 0,
|
|
||||||
DRAW_MODE_INSTALL,
|
|
||||||
DRAW_MODE_EXTRA,
|
|
||||||
|
|
||||||
DRAW_MODE_AMOUNT,
|
|
||||||
} DrawMode;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
REMOTE_MODE_THEMES = 0,
|
|
||||||
REMOTE_MODE_SPLASHES,
|
|
||||||
REMOTE_MODE_BADGES,
|
|
||||||
|
|
||||||
REMOTE_MODE_AMOUNT,
|
|
||||||
} RemoteMode;
|
|
||||||
|
|
||||||
extern const char * main_paths[REMOTE_MODE_AMOUNT];
|
|
||||||
extern const int entries_per_screen_v[MODE_AMOUNT];
|
extern const int entries_per_screen_v[MODE_AMOUNT];
|
||||||
extern const int entries_per_screen_h[MODE_AMOUNT];
|
extern const int entries_per_screen_h[MODE_AMOUNT];
|
||||||
extern const int entry_size[MODE_AMOUNT];
|
extern const int entry_size[MODE_AMOUNT];
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Anemone3DS
|
|
||||||
* Copyright (C) 2016-2024 Contributors in CONTRIBUTORS.md
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONFIG_H
|
|
||||||
#define CONFIG_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "fs.h"
|
|
||||||
#include <jansson.h>
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
u32 accent_color;
|
|
||||||
u32 background_color;
|
|
||||||
u32 white_color_background;
|
|
||||||
u32 white_color_accent;
|
|
||||||
u32 cursor_color;
|
|
||||||
u32 black_color;
|
|
||||||
u32 red_color_background;
|
|
||||||
u32 red_color_accent;
|
|
||||||
u32 yellow_color;
|
|
||||||
} Config_s;
|
|
||||||
|
|
||||||
extern Config_s config;
|
|
||||||
|
|
||||||
void load_config(void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#ifndef CONVERISON_H
|
|
||||||
#define CONVERISON_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
size_t bin_to_abgr(char ** bufp, size_t size);
|
|
||||||
size_t png_to_abgr(char ** bufp, size_t size, u32 *height);
|
|
||||||
int pngToRGB565(char *png_buf, u64 fileSize, u16 *rgb_buf_64x64, u8 *alpha_buf_64x64, u16 *rgb_buf_32x32, u8 *alpha_buf_32x32, bool set_icon);
|
|
||||||
int rgb565ToPngFile(char *filename, u16 *rgb_buf, u8 *alpha_buf, int width, int height);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#define MAX_LINES 10
|
#define MAX_LINES 10
|
||||||
|
|
||||||
typedef enum InstallType_e {
|
typedef enum {
|
||||||
INSTALL_LOADING_THEMES,
|
INSTALL_LOADING_THEMES,
|
||||||
INSTALL_LOADING_SPLASHES,
|
INSTALL_LOADING_SPLASHES,
|
||||||
INSTALL_LOADING_ICONS,
|
INSTALL_LOADING_ICONS,
|
||||||
@@ -52,14 +52,11 @@ typedef enum InstallType_e {
|
|||||||
|
|
||||||
INSTALL_LOADING_REMOTE_THEMES,
|
INSTALL_LOADING_REMOTE_THEMES,
|
||||||
INSTALL_LOADING_REMOTE_SPLASHES,
|
INSTALL_LOADING_REMOTE_SPLASHES,
|
||||||
INSTALL_LOADING_REMOTE_BADGES,
|
|
||||||
INSTALL_LOADING_REMOTE_PREVIEW,
|
INSTALL_LOADING_REMOTE_PREVIEW,
|
||||||
INSTALL_LOADING_REMOTE_BGM,
|
INSTALL_LOADING_REMOTE_BGM,
|
||||||
|
|
||||||
INSTALL_DUMPING_THEME,
|
INSTALL_DUMPING_THEME,
|
||||||
INSTALL_DUMPING_ALL_THEMES,
|
INSTALL_DUMPING_ALL_THEMES,
|
||||||
INSTALL_DUMPING_BADGES,
|
|
||||||
INSTALL_BADGES,
|
|
||||||
|
|
||||||
INSTALL_NONE,
|
INSTALL_NONE,
|
||||||
} InstallType;
|
} InstallType;
|
||||||
@@ -84,14 +81,11 @@ typedef enum {
|
|||||||
|
|
||||||
TEXT_INSTALL_LOADING_REMOTE_THEMES,
|
TEXT_INSTALL_LOADING_REMOTE_THEMES,
|
||||||
TEXT_INSTALL_LOADING_REMOTE_SPLASHES,
|
TEXT_INSTALL_LOADING_REMOTE_SPLASHES,
|
||||||
TEXT_INSTALL_LOADING_REMOTE_BADGES,
|
|
||||||
TEXT_INSTALL_LOADING_REMOTE_PREVIEW,
|
TEXT_INSTALL_LOADING_REMOTE_PREVIEW,
|
||||||
TEXT_INSTALL_LOADING_REMOTE_BGM,
|
TEXT_INSTALL_LOADING_REMOTE_BGM,
|
||||||
|
|
||||||
TEXT_INSTALL_DUMPING_THEME,
|
TEXT_INSTALL_DUMPING_THEME,
|
||||||
TEXT_INSTALL_DUMPING_ALL_THEMES,
|
TEXT_INSTALL_DUMPING_ALL_THEMES,
|
||||||
TEXT_INSTALL_DUMPING_BADGES,
|
|
||||||
TEXT_INSTALL_BADGES,
|
|
||||||
|
|
||||||
// Other text
|
// Other text
|
||||||
TEXT_VERSION,
|
TEXT_VERSION,
|
||||||
@@ -115,7 +109,6 @@ typedef enum {
|
|||||||
|
|
||||||
TEXT_THEMEPLAZA_THEME_MODE,
|
TEXT_THEMEPLAZA_THEME_MODE,
|
||||||
TEXT_THEMEPLAZA_SPLASH_MODE,
|
TEXT_THEMEPLAZA_SPLASH_MODE,
|
||||||
TEXT_THEMEPLAZA_BADGE_MODE,
|
|
||||||
|
|
||||||
TEXT_SEARCH,
|
TEXT_SEARCH,
|
||||||
TEXT_PAGE,
|
TEXT_PAGE,
|
||||||
@@ -156,8 +149,8 @@ typedef struct {
|
|||||||
const char * instructions[BUTTONS_INFO_LINES][BUTTONS_INFO_COLUNMNS];
|
const char * instructions[BUTTONS_INFO_LINES][BUTTONS_INFO_COLUNMNS];
|
||||||
} Instructions_s;
|
} Instructions_s;
|
||||||
|
|
||||||
extern C3D_RenderTarget * top;
|
extern C3D_RenderTarget* top;
|
||||||
extern C3D_RenderTarget * bottom;
|
extern C3D_RenderTarget* bottom;
|
||||||
extern C2D_TextBuf staticBuf, dynamicBuf;
|
extern C2D_TextBuf staticBuf, dynamicBuf;
|
||||||
|
|
||||||
extern C2D_Text text[TEXT_AMOUNT];
|
extern C2D_Text text[TEXT_AMOUNT];
|
||||||
@@ -169,10 +162,10 @@ void start_frame(void);
|
|||||||
void end_frame(void);
|
void end_frame(void);
|
||||||
void set_screen(C3D_RenderTarget * screen);
|
void set_screen(C3D_RenderTarget * screen);
|
||||||
|
|
||||||
void throw_error(const char * error, ErrorLevel level);
|
void throw_error(const char* error, ErrorLevel level);
|
||||||
bool draw_confirm(const char * conf_msg, Entry_List_s * list, DrawMode draw_mode);
|
bool draw_confirm(const char* conf_msg, Entry_List_s* list);
|
||||||
|
|
||||||
void draw_preview(C2D_Image preview, int preview_offset, float preview_scale);
|
void draw_preview(C2D_Image preview, int preview_offset);
|
||||||
|
|
||||||
void draw_install(InstallType type);
|
void draw_install(InstallType type);
|
||||||
void draw_loading_bar(u32 current, u32 max, InstallType type);
|
void draw_loading_bar(u32 current, u32 max, InstallType type);
|
||||||
@@ -181,11 +174,9 @@ void draw_text(float x, float y, float z, float scaleX, float scaleY, Color colo
|
|||||||
void draw_text_wrap(float x, float y, float z, float scaleX, float scaleY, Color color, const char * text, float max_width);
|
void draw_text_wrap(float x, float y, float z, float scaleX, float scaleY, Color color, const char * text, float max_width);
|
||||||
void draw_text_wrap_scaled(float x, float y, float z, Color color, const char * text, float max_scale, float min_scale, float max_width);
|
void draw_text_wrap_scaled(float x, float y, float z, Color color, const char * text, float max_scale, float min_scale, float max_width);
|
||||||
void draw_text_center(gfxScreen_t target, float y, float z, float scaleX, float scaleY, Color color, const char * text);
|
void draw_text_center(gfxScreen_t target, float y, float z, float scaleX, float scaleY, Color color, const char * text);
|
||||||
void draw_home(u64 start_time, u64 cur_time);
|
|
||||||
|
|
||||||
void draw_base_interface(void);
|
void draw_base_interface(void);
|
||||||
void draw_grid_interface(Entry_List_s * list, Instructions_s instructions, int extra_mode);
|
void draw_grid_interface(Entry_List_s* list, Instructions_s instructions);
|
||||||
void draw_interface(Entry_List_s * list, Instructions_s instructions, DrawMode draw_mode);
|
void draw_interface(Entry_List_s* list, Instructions_s instructions);
|
||||||
bool draw_confirm_no_interface(const char *conf_msg);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Anemone3DS
|
|
||||||
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ENTRIES_LIST_H
|
|
||||||
#define ENTRIES_LIST_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include <jansson.h>
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
SORT_NONE,
|
|
||||||
|
|
||||||
SORT_NAME,
|
|
||||||
SORT_AUTHOR,
|
|
||||||
SORT_PATH,
|
|
||||||
} SortMode;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
u16 path[0x106];
|
|
||||||
bool is_zip;
|
|
||||||
bool in_shuffle;
|
|
||||||
bool no_bgm_shuffle;
|
|
||||||
bool installed;
|
|
||||||
u32 placeholder_color; // doubles as not-info-loaded when == 0
|
|
||||||
|
|
||||||
json_int_t tp_download_id;
|
|
||||||
u16 name[0x41];
|
|
||||||
u16 desc[0x81];
|
|
||||||
u16 author[0x41];
|
|
||||||
} Entry_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Tex3DS_SubTexture subtex;
|
|
||||||
u16 x, y;
|
|
||||||
} Entry_Icon_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Entry_s * entries;
|
|
||||||
int entries_count;
|
|
||||||
int entries_capacity;
|
|
||||||
|
|
||||||
C3D_Tex icons_texture;
|
|
||||||
Entry_Icon_s * icons_info;
|
|
||||||
|
|
||||||
int previous_scroll;
|
|
||||||
int scroll;
|
|
||||||
|
|
||||||
int previous_selected;
|
|
||||||
int selected_entry;
|
|
||||||
|
|
||||||
int shuffle_count;
|
|
||||||
|
|
||||||
EntryMode mode;
|
|
||||||
int entries_per_screen_v; // rows of entries on 1 screen
|
|
||||||
int entries_per_screen_h; // columns of entries on 1 screen
|
|
||||||
int entries_loaded; // amount of entries on 1 screen
|
|
||||||
int entry_size; // size in pixels of an entry icon
|
|
||||||
|
|
||||||
SortMode current_sort;
|
|
||||||
|
|
||||||
json_int_t tp_current_page;
|
|
||||||
json_int_t tp_page_count;
|
|
||||||
char * tp_search;
|
|
||||||
const char * loading_path;
|
|
||||||
} Entry_List_s;
|
|
||||||
|
|
||||||
void sort_by_name(Entry_List_s * list);
|
|
||||||
void sort_by_author(Entry_List_s * list);
|
|
||||||
void sort_by_filename(Entry_List_s * list);
|
|
||||||
|
|
||||||
void delete_entry(Entry_s * entry, bool is_file);
|
|
||||||
// assumes list has been memset to 0
|
|
||||||
typedef enum InstallType_e InstallType;
|
|
||||||
Result load_entries(const char * loading_path, Entry_List_s * list, const InstallType loading_screen);
|
|
||||||
u32 load_data(const char * filename, const Entry_s * entry, char ** buf);
|
|
||||||
C2D_Image get_icon_at(Entry_List_s * list, size_t index);
|
|
||||||
|
|
||||||
// assumes list doesn't have any elements yet
|
|
||||||
void list_init_capacity(Entry_List_s * list, const int init_capacity);
|
|
||||||
// assumes list has been inited with a non zero capacity
|
|
||||||
ssize_t list_add_entry(Entry_List_s * list);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
41
include/fs.h
@@ -28,49 +28,24 @@
|
|||||||
#define FS_H
|
#define FS_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "badges.h"
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#define ILLEGAL_CHARS "><\"?;:/\\+,.|[=]*\n\r"
|
#define ILLEGAL_CHARS "><\"?;:/\\+,.|[=]"
|
||||||
|
|
||||||
extern FS_Archive ArchiveSD;
|
extern FS_Archive ArchiveSD;
|
||||||
extern FS_Archive ArchiveHomeExt;
|
extern FS_Archive ArchiveHomeExt;
|
||||||
extern FS_Archive ArchiveThemeExt;
|
extern FS_Archive ArchiveThemeExt;
|
||||||
extern FS_Archive ArchiveBadgeExt;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
u32 enable : 1;
|
|
||||||
u32 browser: 1;
|
|
||||||
u32 stereoscopic : 1;
|
|
||||||
u32 media_share : 1;
|
|
||||||
u32 online : 1;
|
|
||||||
u32 streetpass : 1;
|
|
||||||
u32 friends : 1;
|
|
||||||
u32 dsdownload : 1;
|
|
||||||
u32 shopping : 1;
|
|
||||||
u32 videos : 1;
|
|
||||||
u32 miiverse : 1;
|
|
||||||
u32 post : 1;
|
|
||||||
u32 null : 19;
|
|
||||||
u32 coppa : 1;
|
|
||||||
} Parental_Restrictions_s;
|
|
||||||
|
|
||||||
Result init_sd(void);
|
|
||||||
Result open_archives(void);
|
Result open_archives(void);
|
||||||
Result open_badge_extdata(void);
|
|
||||||
Result close_archives(void);
|
Result close_archives(void);
|
||||||
Result load_parental_controls(Parental_Restrictions_s *restrictions);
|
|
||||||
|
|
||||||
u32 file_to_buf(FS_Path path, FS_Archive archive, char ** buf);
|
u32 file_to_buf(FS_Path path, FS_Archive archive, char** buf);
|
||||||
u32 zip_memory_to_buf(const char * file_name, void * zip_memory, size_t zip_size, char ** buf);
|
u32 zip_memory_to_buf(char *file_name, void * zip_memory, size_t zip_size, char ** buf);
|
||||||
u32 zip_file_to_buf(const char * file_name, const u16 * zip_path, char ** buf);
|
u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf);
|
||||||
u32 decompress_lz_file(FS_Path file_name, FS_Archive archive, char ** buf);
|
u32 decompress_lz_file(FS_Path file_name, FS_Archive archive, char **buf);
|
||||||
u32 compress_lz_file_fast(FS_Path path, FS_Archive archive, char * in_buf, u32 size);
|
u32 compress_lz_file_fast(FS_Path path, FS_Archive archive, char *in_buf, u32 size);
|
||||||
|
|
||||||
Result buf_to_file(u32 size, FS_Path path, FS_Archive archive, char * buf);
|
Result buf_to_file(u32 size, FS_Path path, FS_Archive archive, char *buf);
|
||||||
Result zero_handle_memeasy(Handle handle);
|
|
||||||
void remake_file(FS_Path path, FS_Archive archive, u32 size);
|
void remake_file(FS_Path path, FS_Archive archive, u32 size);
|
||||||
void save_zip_to_sd(char * filename, u32 size, char * buf, RemoteMode mode);
|
void save_zip_to_sd(char * filename, u32 size, char * buf, EntryMode mode);
|
||||||
s16 for_each_file_zip(u16 *zip_path, u32 (*zip_iter_callback)(char *filebuf, u64 file_size, const char *name, void *userdata), void *userdata);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
166
include/instructions.h
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Anemone3DS
|
||||||
|
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INSTRUCTIONS_H
|
||||||
|
#define INSTRUCTIONS_H
|
||||||
|
|
||||||
|
#include "draw.h"
|
||||||
|
#include "colors.h"
|
||||||
|
|
||||||
|
Instructions_s normal_instructions[MODE_AMOUNT] = {
|
||||||
|
{
|
||||||
|
.info_line = NULL,
|
||||||
|
.instructions = {
|
||||||
|
{
|
||||||
|
"\uE000 Hold to install",
|
||||||
|
"\uE001 Queue shuffle theme"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"\uE002 Hold for more",
|
||||||
|
"\uE003 Preview theme"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"\uE004 Switch to splashes",
|
||||||
|
"\uE005 Scan QR code"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Exit",
|
||||||
|
"Delete from SD"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.info_line = NULL,
|
||||||
|
.instructions = {
|
||||||
|
{
|
||||||
|
"\uE000 Install splash",
|
||||||
|
"\uE001 Delete installed splash"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"\uE002 Hold for more",
|
||||||
|
"\uE003 Preview splash"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"\uE004 Switch to themes",
|
||||||
|
"\uE005 Scan QR code"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Exit",
|
||||||
|
"Delete from SD"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Instructions_s install_instructions = {
|
||||||
|
.info_line = "Release \uE000 to cancel or hold \uE006 and release \uE000 to install",
|
||||||
|
.instructions = {
|
||||||
|
{
|
||||||
|
"\uE079 Normal install",
|
||||||
|
"\uE07A Shuffle install"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"\uE07B BGM-only install",
|
||||||
|
"\uE07C No-BGM install"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Exit",
|
||||||
|
NULL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Instructions_s extra_instructions[3] = {
|
||||||
|
{
|
||||||
|
.info_line = "Release \uE002 to cancel or hold \uE006 and release \uE002 to sort",
|
||||||
|
.instructions = {
|
||||||
|
{
|
||||||
|
"\uE079 Sort by name",
|
||||||
|
"\uE07A Sort by author"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"\uE07B Sort by filename",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Exit",
|
||||||
|
NULL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.info_line = "Release \uE002 to cancel or hold \uE006 and release \uE002 to do stuff",
|
||||||
|
.instructions = {
|
||||||
|
{
|
||||||
|
"\uE079 Jump in the list",
|
||||||
|
"\uE07A Reload broken icons"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"\uE07B Browse ThemePlaza",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"\uE004 Sorting menu",
|
||||||
|
"\uE005 Dumping menu"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Exit",
|
||||||
|
NULL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.info_line = "Release \uE002 to cancel or hold \uE006 and release \uE002 to dump",
|
||||||
|
.instructions = {
|
||||||
|
{
|
||||||
|
"\uE079 Dump Current Theme",
|
||||||
|
"\uE07A Dump All Themes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Exit",
|
||||||
|
NULL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -28,16 +28,9 @@
|
|||||||
#define LOADING_H
|
#define LOADING_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "entries_list.h"
|
|
||||||
#include "music.h"
|
#include "music.h"
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
|
|
||||||
// These values assume a horizontal orientation
|
|
||||||
#define TOP_SCREEN_WIDTH 400
|
|
||||||
#define BOTTOM_SCREEN_WIDTH 320
|
|
||||||
#define SCREEN_HEIGHT 240
|
|
||||||
#define SCREEN_COLOR_DEPTH 4
|
|
||||||
|
|
||||||
enum ICON_IDS_OFFSET {
|
enum ICON_IDS_OFFSET {
|
||||||
ICONS_ABOVE = 0,
|
ICONS_ABOVE = 0,
|
||||||
ICONS_VISIBLE,
|
ICONS_VISIBLE,
|
||||||
@@ -46,6 +39,14 @@ enum ICON_IDS_OFFSET {
|
|||||||
ICONS_OFFSET_AMOUNT,
|
ICONS_OFFSET_AMOUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SORT_NONE,
|
||||||
|
|
||||||
|
SORT_NAME,
|
||||||
|
SORT_AUTHOR,
|
||||||
|
SORT_PATH,
|
||||||
|
} SortMode;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u8 _padding1[4 + 2 + 2];
|
u8 _padding1[4 + 2 + 2];
|
||||||
|
|
||||||
@@ -54,27 +55,76 @@ typedef struct {
|
|||||||
u16 author[0x40];
|
u16 author[0x40];
|
||||||
|
|
||||||
u8 _padding2[0x2000 - 0x200 + 0x30 + 0x8];
|
u8 _padding2[0x2000 - 0x200 + 0x30 + 0x8];
|
||||||
u16 small_icon[24 * 24];
|
u16 small_icon[24*24];
|
||||||
|
|
||||||
u16 big_icon[48 * 48];
|
u16 big_icon[48*48];
|
||||||
} Icon_s;
|
} Icon_s;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u16 name[0x41];
|
||||||
|
u16 desc[0x81];
|
||||||
|
u16 author[0x41];
|
||||||
|
|
||||||
|
u32 placeholder_color;
|
||||||
|
|
||||||
|
u16 path[0x106];
|
||||||
|
bool is_zip;
|
||||||
|
|
||||||
|
bool in_shuffle;
|
||||||
|
bool no_bgm_shuffle;
|
||||||
|
bool installed;
|
||||||
|
|
||||||
|
json_int_t tp_download_id;
|
||||||
|
} Entry_s;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Entry_s * entries;
|
||||||
|
int entries_count;
|
||||||
|
|
||||||
|
C2D_Image ** icons;
|
||||||
|
|
||||||
|
int previous_scroll;
|
||||||
|
int scroll;
|
||||||
|
|
||||||
|
int previous_selected;
|
||||||
|
int selected_entry;
|
||||||
|
|
||||||
|
int shuffle_count;
|
||||||
|
|
||||||
|
EntryMode mode;
|
||||||
|
int entries_per_screen_v;
|
||||||
|
int entries_per_screen_h;
|
||||||
|
int entries_loaded;
|
||||||
|
int entry_size;
|
||||||
|
|
||||||
|
SortMode current_sort;
|
||||||
|
|
||||||
|
json_int_t tp_current_page;
|
||||||
|
json_int_t tp_page_count;
|
||||||
|
char * tp_search;
|
||||||
|
} Entry_List_s;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void ** thread_arg;
|
void ** thread_arg;
|
||||||
volatile bool run_thread;
|
volatile bool run_thread;
|
||||||
} Thread_Arg_s;
|
} Thread_Arg_s;
|
||||||
|
|
||||||
void copy_texture_data(C3D_Tex * texture, const u16 * src, const Entry_Icon_s * current_icon);
|
C2D_Image * loadTextureIcon(Icon_s *icon);
|
||||||
void parse_smdh(Icon_s * icon, Entry_s * entry, const u16 * fallback_name);
|
void parse_smdh(Icon_s *icon, Entry_s * entry, const u16 * fallback_name);
|
||||||
|
|
||||||
|
void sort_by_name(Entry_List_s * list);
|
||||||
|
void sort_by_author(Entry_List_s * list);
|
||||||
|
void sort_by_filename(Entry_List_s * list);
|
||||||
|
|
||||||
bool load_preview_from_buffer(char * row_pointers, u32 size, C2D_Image * preview_image, int * preview_offset, int height);
|
void delete_entry(Entry_s * entry, bool is_file);
|
||||||
bool load_preview(const Entry_List_s * list, C2D_Image * preview_image, int * preview_offset);
|
Result load_entries(const char * loading_path, Entry_List_s * list);
|
||||||
|
bool load_preview_from_buffer(void * buf, u32 size, C2D_Image * preview_image, int * preview_offset);
|
||||||
|
bool load_preview(Entry_List_s list, C2D_Image * preview_image, int * preview_offset);
|
||||||
void free_preview(C2D_Image preview_image);
|
void free_preview(C2D_Image preview_image);
|
||||||
Result load_audio(const Entry_s *, audio_s *);
|
Result load_audio(Entry_s, audio_s *);
|
||||||
Result load_audio_ogg(const Entry_s * entry, audio_ogg_s * audio);
|
|
||||||
void load_icons_first(Entry_List_s * current_list, bool silent);
|
void load_icons_first(Entry_List_s * current_list, bool silent);
|
||||||
void handle_scrolling(Entry_List_s * list);
|
void handle_scrolling(Entry_List_s * list);
|
||||||
void load_icons_thread(void * void_arg);
|
void load_icons_thread(void * void_arg);
|
||||||
|
u32 load_data(char * filename, Entry_s entry, char ** buf);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -34,37 +34,7 @@
|
|||||||
#include <tremor/ivorbisfile.h>
|
#include <tremor/ivorbisfile.h>
|
||||||
#include <tremor/ivorbiscodec.h>
|
#include <tremor/ivorbiscodec.h>
|
||||||
|
|
||||||
#define BUFFER_COUNT 8
|
#define BUF_TO_READ 48000 // How much data should be buffered at a time
|
||||||
#define BUF_TO_READ 48000 // How much data should be buffered at a time for ogg
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char *music_buf;
|
|
||||||
size_t music_size;
|
|
||||||
size_t cursor;
|
|
||||||
u32 last_time;
|
|
||||||
bool is_little_endian;
|
|
||||||
bool is_looping;
|
|
||||||
u32 info_offset;
|
|
||||||
u32 data_offset;
|
|
||||||
u8 channel_count;
|
|
||||||
u32 sample_rate;
|
|
||||||
u32 loop_start;
|
|
||||||
u32 loop_end;
|
|
||||||
u32 num_blocks;
|
|
||||||
u32 block_size;
|
|
||||||
u32 block_samples;
|
|
||||||
u32 last_block_samples;
|
|
||||||
u32 last_block_size;
|
|
||||||
u32 current_block;
|
|
||||||
unsigned short adpcm_coefs[2][16];
|
|
||||||
ndspWaveBuf wave_buf[2][BUFFER_COUNT];
|
|
||||||
ndspAdpcmData adpcm_data[2][2];
|
|
||||||
unsigned short channel[2];
|
|
||||||
unsigned int active_channels;
|
|
||||||
u8 *buffer_data[2][BUFFER_COUNT];
|
|
||||||
volatile bool stop;
|
|
||||||
Thread playing_thread;
|
|
||||||
} audio_s;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OggVorbis_File vf;
|
OggVorbis_File vf;
|
||||||
@@ -72,17 +42,13 @@ typedef struct {
|
|||||||
float mix[12];
|
float mix[12];
|
||||||
u8 buf_pos;
|
u8 buf_pos;
|
||||||
long data_read;
|
long data_read;
|
||||||
char * filebuf;
|
char *filebuf;
|
||||||
u32 filesize;
|
u32 filesize;
|
||||||
|
|
||||||
volatile bool stop;
|
volatile bool stop;
|
||||||
Thread playing_thread;
|
Handle finished;
|
||||||
} audio_ogg_s;
|
} audio_s;
|
||||||
|
|
||||||
void play_audio(audio_s *);
|
void play_audio(audio_s *);
|
||||||
void stop_audio(audio_s **);
|
|
||||||
|
|
||||||
void play_audio_ogg(audio_ogg_s *);
|
|
||||||
void stop_audio_ogg(audio_ogg_s **);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -39,12 +39,6 @@
|
|||||||
#define THEMEPLAZA_JSON_PAGE_COUNT "pages"
|
#define THEMEPLAZA_JSON_PAGE_COUNT "pages"
|
||||||
#define THEMEPLAZA_JSON_PAGE_IDS "items"
|
#define THEMEPLAZA_JSON_PAGE_IDS "items"
|
||||||
|
|
||||||
#define THEMEPLAZA_QUERY_ENTRY_INFO THEMEPLAZA_BASE_API_URL "/query?item_id=%" JSON_INTEGER_FORMAT
|
|
||||||
#define THEMEPLAZA_JSON_TITLE "title"
|
|
||||||
#define THEMEPLAZA_JSON_AUTHOR "author"
|
|
||||||
#define THEMEPLAZA_JSON_DESC "description"
|
|
||||||
#define THEMEPLAZA_JSON_SUCCESS "success"
|
|
||||||
|
|
||||||
#define THEMEPLAZA_JSON_ERROR_MESSAGE "message"
|
#define THEMEPLAZA_JSON_ERROR_MESSAGE "message"
|
||||||
#define THEMEPLAZA_JSON_ERROR_MESSAGE_NOT_FOUND "No items found"
|
#define THEMEPLAZA_JSON_ERROR_MESSAGE_NOT_FOUND "No items found"
|
||||||
|
|
||||||
@@ -57,18 +51,7 @@
|
|||||||
|
|
||||||
#define CACHE_PATH_FORMAT "/3ds/" APP_TITLE "/cache/%" JSON_INTEGER_FORMAT
|
#define CACHE_PATH_FORMAT "/3ds/" APP_TITLE "/cache/%" JSON_INTEGER_FORMAT
|
||||||
|
|
||||||
typedef struct {
|
bool themeplaza_browser(EntryMode mode);
|
||||||
char *result_buf;
|
Result http_get(const char *url, char ** filename, char ** buf, u32 * size, InstallType install_type, const char * acceptable_mime_types);
|
||||||
size_t result_written;
|
|
||||||
size_t result_sz;
|
|
||||||
} curl_data;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char *filename;
|
|
||||||
char *mime_type;
|
|
||||||
} curl_header;
|
|
||||||
|
|
||||||
bool themeplaza_browser(RemoteMode mode);
|
|
||||||
Result http_get(const char * url, char ** filename, char ** buf, u32 * size, InstallType install_type, const char * acceptable_mime_types);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
#include "loading.h"
|
#include "loading.h"
|
||||||
|
|
||||||
void splash_delete(void);
|
void splash_delete(void);
|
||||||
void splash_install(const Entry_s * splash);
|
void splash_install(Entry_s splash);
|
||||||
|
|
||||||
void splash_check_installed(void * void_arg);
|
void splash_check_installed(void * void_arg);
|
||||||
|
|
||||||
|
|||||||
@@ -64,17 +64,17 @@ typedef struct {
|
|||||||
u32 dlc_theme_content_index;
|
u32 dlc_theme_content_index;
|
||||||
u32 use_theme_cache;
|
u32 use_theme_cache;
|
||||||
|
|
||||||
u8 _padding1[0x338 - 8 * sizeof(u32)];
|
u8 _padding1[0x338 - 8*sizeof(u32)];
|
||||||
|
|
||||||
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES];
|
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES];
|
||||||
u32 shuffle_music_sizes[MAX_SHUFFLE_THEMES];
|
u32 shuffle_music_sizes[MAX_SHUFFLE_THEMES];
|
||||||
} ThemeManage_bin_s;
|
} ThemeManage_bin_s;
|
||||||
|
|
||||||
Result theme_install(Entry_s * theme);
|
Result theme_install(Entry_s theme);
|
||||||
Result no_bgm_install(Entry_s * theme);
|
Result no_bgm_install(Entry_s theme);
|
||||||
Result bgm_install(Entry_s * theme);
|
Result bgm_install(Entry_s theme);
|
||||||
|
|
||||||
Result shuffle_install(const Entry_List_s * themes);
|
Result shuffle_install(Entry_List_s themes);
|
||||||
|
|
||||||
Result dump_current_theme(void);
|
Result dump_current_theme(void);
|
||||||
Result dump_all_themes(void);
|
Result dump_all_themes(void);
|
||||||
|
|||||||
@@ -1,200 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Anemone3DS
|
|
||||||
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef UISTRINGS_H
|
|
||||||
#define UISTRINGS_H
|
|
||||||
|
|
||||||
#include "colors.h"
|
|
||||||
#include "draw.h"
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *quit;
|
|
||||||
const char *thread_error;
|
|
||||||
const char *zip_not_theme_splash;
|
|
||||||
const char *file_not_zip;
|
|
||||||
const char *download_failed;
|
|
||||||
const char *badge_question;
|
|
||||||
} Camera_Strings_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *theme_mode;
|
|
||||||
const char *splash_mode;
|
|
||||||
const char *no_themes;
|
|
||||||
const char *no_splashes;
|
|
||||||
const char *qr_download;
|
|
||||||
const char *switch_splashes;
|
|
||||||
const char *switch_themes;
|
|
||||||
const char *quit;
|
|
||||||
const char *by;
|
|
||||||
const char *selected;
|
|
||||||
const char *sel;
|
|
||||||
const char *tp_theme_mode;
|
|
||||||
const char *tp_splash_mode;
|
|
||||||
const char *tp_badge_mode;
|
|
||||||
const char *search;
|
|
||||||
const char *page;
|
|
||||||
const char *err_quit;
|
|
||||||
const char *warn_continue;
|
|
||||||
const char *yes_no;
|
|
||||||
const char *load_themes;
|
|
||||||
const char *load_splash;
|
|
||||||
const char *load_icons;
|
|
||||||
const char *install_splash;
|
|
||||||
const char *delete_splash;
|
|
||||||
const char *install_theme;
|
|
||||||
const char *install_shuffle;
|
|
||||||
const char *install_bgm;
|
|
||||||
const char *install_no_bgm;
|
|
||||||
const char *downloading;
|
|
||||||
const char *checking_dl;
|
|
||||||
const char *delete_sd;
|
|
||||||
const char *download_themes;
|
|
||||||
const char *download_splashes;
|
|
||||||
const char *download_badges;
|
|
||||||
const char *download_preview;
|
|
||||||
const char *download_bgm;
|
|
||||||
const char *dump_single;
|
|
||||||
const char *dump_all_official;
|
|
||||||
const char *dump_badges;
|
|
||||||
const char *install_badges;
|
|
||||||
float start_pos;
|
|
||||||
const char *shuffle;
|
|
||||||
} Draw_Strings_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *illegal_input;
|
|
||||||
const char *new_or_overwrite;
|
|
||||||
const char *cancel;
|
|
||||||
const char *overwrite;
|
|
||||||
const char *rename;
|
|
||||||
const char *swkbd_fail;
|
|
||||||
const char *sd_full;
|
|
||||||
const char *fs_error;
|
|
||||||
} FS_Strings_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *no_preview;
|
|
||||||
} Loading_Strings_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *position_too_big;
|
|
||||||
const char *position_zero;
|
|
||||||
const char *jump_q;
|
|
||||||
const char *cancel;
|
|
||||||
const char *jump;
|
|
||||||
const char *no_theme_extdata;
|
|
||||||
const char *loading_qr;
|
|
||||||
const char *no_wifi;
|
|
||||||
const char *qr_homebrew;
|
|
||||||
const char *camera_broke;
|
|
||||||
const char *too_many_themes;
|
|
||||||
const char *not_enough_themes;
|
|
||||||
const char *uninstall_confirm;
|
|
||||||
const char *delete_confirm;
|
|
||||||
} Main_Strings_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *no_results;
|
|
||||||
const char *check_wifi;
|
|
||||||
const char *new_page_big;
|
|
||||||
const char *new_page_zero;
|
|
||||||
const char *jump_page;
|
|
||||||
const char *cancel;
|
|
||||||
const char *jump;
|
|
||||||
const char *tags;
|
|
||||||
const char *search;
|
|
||||||
const char *parental_fail;
|
|
||||||
const char *zip_not_found;
|
|
||||||
const char *generic_httpc_error;
|
|
||||||
const char *http303_tp;
|
|
||||||
const char *http303;
|
|
||||||
const char *http404;
|
|
||||||
const char *http_err_url;
|
|
||||||
const char *http_errcode_generic;
|
|
||||||
const char *http401;
|
|
||||||
const char *http403;
|
|
||||||
const char *http407;
|
|
||||||
const char *http414;
|
|
||||||
const char *http418;
|
|
||||||
const char *http426;
|
|
||||||
const char *http451;
|
|
||||||
const char *http500;
|
|
||||||
const char *http502;
|
|
||||||
const char *http503;
|
|
||||||
const char *http504;
|
|
||||||
const char *http_unexpected;
|
|
||||||
} Remote_Strings_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *no_splash_found;
|
|
||||||
const char *splash_disabled;
|
|
||||||
} Splashes_Strings_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *no_body_found;
|
|
||||||
const char *mono_warn;
|
|
||||||
const char *illegal_char;
|
|
||||||
const char *name_folder;
|
|
||||||
const char *cancel;
|
|
||||||
const char *done;
|
|
||||||
} Themes_Strings_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *extdata_locked;
|
|
||||||
} Badge_Strings_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Instructions_s normal_instructions[MODE_AMOUNT];
|
|
||||||
Instructions_s install_instructions;
|
|
||||||
Instructions_s extra_instructions[3];
|
|
||||||
Camera_Strings_s camera;
|
|
||||||
Draw_Strings_s draw;
|
|
||||||
FS_Strings_s fs;
|
|
||||||
Loading_Strings_s loading;
|
|
||||||
Main_Strings_s main;
|
|
||||||
Remote_Strings_s remote;
|
|
||||||
Instructions_s remote_instructions[REMOTE_MODE_AMOUNT];
|
|
||||||
Instructions_s remote_extra_instructions[3];
|
|
||||||
Splashes_Strings_s splashes;
|
|
||||||
Themes_Strings_s themes;
|
|
||||||
Badge_Strings_s badges;
|
|
||||||
} Language_s;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
LANGUAGE_EN,
|
|
||||||
|
|
||||||
LANGUAGE_AMOUNT,
|
|
||||||
} Language_Name;
|
|
||||||
|
|
||||||
Language_s init_strings(CFG_Language lang);
|
|
||||||
extern Language_s language;
|
|
||||||
|
|
||||||
// fetches the system language through CFGU_GetSystemLanguage
|
|
||||||
// and returns the appropriate CFG_Language enum value
|
|
||||||
CFG_Language get_system_language(void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -29,10 +29,9 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
void replace_chars(u16 *input, char *remove, u16 with);
|
ssize_t strulen(const u16*, ssize_t);
|
||||||
size_t strulen(const u16 *, ssize_t);
|
void struacat(u16 *input, const char *addition);
|
||||||
void struacat(u16 * input, const char * addition);
|
void printu(u16 *input);
|
||||||
void printu(u16 * input);
|
u16 *strucat(u16 *destination, const u16 *source);
|
||||||
size_t strucat(u16 * destination, const u16 * source);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Anemone3DS
|
|
||||||
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static char from_hex(char c)
|
|
||||||
{
|
|
||||||
return isdigit(c) ? c - '0' : tolower(c) - 'a' + 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char to_hex(char code)
|
|
||||||
{
|
|
||||||
static char hex[] = "0123456789abcdef";
|
|
||||||
return hex[code & 15];
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure caller frees
|
|
||||||
char * url_escape(char * url)
|
|
||||||
{
|
|
||||||
char * ptr = url;
|
|
||||||
char * buf = malloc(3 * strlen(url) + 1);
|
|
||||||
char * ptr_buf = buf;
|
|
||||||
|
|
||||||
while (*ptr)
|
|
||||||
{
|
|
||||||
if (isalnum((int)*ptr) || strchr("-_.~", *ptr))
|
|
||||||
*ptr_buf++ = *ptr;
|
|
||||||
else if (*ptr == ' ')
|
|
||||||
*ptr_buf++ = '+';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*ptr_buf++ = '%';
|
|
||||||
*ptr_buf++ = to_hex(*ptr >> 4);
|
|
||||||
*ptr_buf++ = to_hex(*ptr & 15);
|
|
||||||
}
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
*ptr_buf = '\0';
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure caller frees
|
|
||||||
char * url_unescape(char * url)
|
|
||||||
{
|
|
||||||
char * ptr = url;
|
|
||||||
char * buf = malloc(strlen(url) + 1);
|
|
||||||
char * ptr_buf = buf;
|
|
||||||
|
|
||||||
while (*ptr)
|
|
||||||
{
|
|
||||||
if (*ptr == '%')
|
|
||||||
{
|
|
||||||
if (ptr[1] && ptr[2])
|
|
||||||
{
|
|
||||||
*ptr_buf++ = from_hex(ptr[1]) << 4 | from_hex(ptr[2]);
|
|
||||||
ptr += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (*ptr == '+')
|
|
||||||
*ptr_buf++ = ' ';
|
|
||||||
else
|
|
||||||
*ptr_buf++ = *ptr;
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
*ptr_buf = '\0';
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
BIN
meta/logo.bin
762
source/badges.c
@@ -1,762 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Anemone3DS
|
|
||||||
* Copyright (C) 2016-2024 Contributors in CONTRIBUTORS.md
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Badge implementation adapted from GYTB by MrCheeze and ABE by AntiMach
|
|
||||||
// https://github.com/AntiMach/advanced-badge-editor
|
|
||||||
// https://github.com/MrCheeze/GYTB
|
|
||||||
|
|
||||||
#include "badges.h"
|
|
||||||
#include "draw.h"
|
|
||||||
#include "ui_strings.h"
|
|
||||||
|
|
||||||
Handle badgeDataHandle;
|
|
||||||
char *badgeMngBuffer;
|
|
||||||
u16 *rgb_buf_64x64;
|
|
||||||
u16 *rgb_buf_32x32;
|
|
||||||
u8 *alpha_buf_64x64;
|
|
||||||
u8 *alpha_buf_32x32;
|
|
||||||
u64 progress_finish;
|
|
||||||
u64 progress_status;
|
|
||||||
|
|
||||||
void remove_exten(u16 *filename)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < strulen(filename, 0x8A); ++i)
|
|
||||||
{
|
|
||||||
if (filename[i] == '.')
|
|
||||||
{
|
|
||||||
filename[i] = 0x00;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 getShortcut(char *filename)
|
|
||||||
{
|
|
||||||
u64 shortcut = 0xFFFFFFFFFFFFFFFF;
|
|
||||||
char *p1 = strchr(filename, '.');
|
|
||||||
|
|
||||||
if (p1 == NULL) return shortcut;
|
|
||||||
++p1;
|
|
||||||
|
|
||||||
char *p2 = strchr(p1, '.');
|
|
||||||
if (p2 == NULL) return shortcut;
|
|
||||||
if (p2-p1 != 8) return shortcut;
|
|
||||||
|
|
||||||
unsigned int lowpath;
|
|
||||||
if (sscanf(p1, "%08x", &lowpath) != 1) return shortcut;
|
|
||||||
|
|
||||||
shortcut = 0x0004001000000000 + lowpath;
|
|
||||||
DEBUG("Shortcut %16llx found for %s\n", shortcut, filename);
|
|
||||||
return shortcut;
|
|
||||||
}
|
|
||||||
|
|
||||||
int install_badge_generic(char *file_buf, u64 file_size, u16 *name, int *badge_count, int set_id)
|
|
||||||
{
|
|
||||||
int badges_in_image = pngToRGB565(file_buf, file_size, rgb_buf_64x64, alpha_buf_64x64, rgb_buf_32x32, alpha_buf_32x32, false);
|
|
||||||
|
|
||||||
char utf8_name[512] = {0};
|
|
||||||
utf16_to_utf8((u8 *) utf8_name, name, 0x8A);
|
|
||||||
u64 shortcut = getShortcut(utf8_name);
|
|
||||||
int badges_installed = 0;
|
|
||||||
|
|
||||||
for (int badge = 0; badge < badges_in_image && *badge_count < 1000; ++badge)
|
|
||||||
{
|
|
||||||
remove_exten(name);
|
|
||||||
for (int j = 0; j < 16; ++j) // Copy name for all 16 languages
|
|
||||||
{
|
|
||||||
FSFILE_Write(badgeDataHandle, NULL, 0x35E80 + *badge_count * 16 * 0x8A + j * 0x8A, name, 0x8A, 0);
|
|
||||||
}
|
|
||||||
FSFILE_Write(badgeDataHandle, NULL, 0x318F80 + *badge_count * 0x2800, rgb_buf_64x64 + badge * 64 * 64, 64 * 64 * 2, 0);
|
|
||||||
FSFILE_Write(badgeDataHandle, NULL, 0x31AF80 + *badge_count * 0x2800, alpha_buf_64x64 + badge * 64 * 64/2, 64 * 64/2, 0);
|
|
||||||
FSFILE_Write(badgeDataHandle, NULL, 0xCDCF80 + *badge_count * 0xA00, rgb_buf_32x32 + badge * 32 * 32, 32 * 32 * 2, 0);
|
|
||||||
FSFILE_Write(badgeDataHandle, NULL, 0xCDD780 + *badge_count * 0xA00, alpha_buf_32x32 + badge * 32 * 32/2, 32 * 32/2, 0);
|
|
||||||
|
|
||||||
int badge_id = *badge_count + 1;
|
|
||||||
memcpy(badgeMngBuffer + 0x3E8 + *badge_count * 0x28 + 0x4, &badge_id, 4);
|
|
||||||
memcpy(badgeMngBuffer + 0x3E8 + *badge_count * 0x28 + 0x8, &set_id, 4);
|
|
||||||
memcpy(badgeMngBuffer + 0x3E8 + *badge_count*0x28 + 0xC, badge_count, 2);
|
|
||||||
badgeMngBuffer[0x3E8 + *badge_count*0x28 + 0x12] = 255; // Quantity Low
|
|
||||||
badgeMngBuffer[0x3E8 + *badge_count*0x28 + 0x13] = 255; // Quantity High
|
|
||||||
|
|
||||||
memcpy(badgeMngBuffer + 0x3E8 + *badge_count*0x28 + 0x18, &shortcut, 8);
|
|
||||||
memcpy(badgeMngBuffer + 0x3E8 + *badge_count*0x28 + 0x20, &shortcut, 8); // u64 shortcut[2], not sure what second is for
|
|
||||||
|
|
||||||
badgeMngBuffer[0x358 + *badge_count/8] |= 1 << (*badge_count % 8); // enabled badges bitfield
|
|
||||||
badges_installed++;
|
|
||||||
|
|
||||||
*badge_count += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return badges_installed;
|
|
||||||
}
|
|
||||||
|
|
||||||
int install_badge_png(FS_Path badge_path, FS_DirectoryEntry badge_file, int *badge_count, int set_id)
|
|
||||||
{
|
|
||||||
u64 res;
|
|
||||||
char *file_buf = NULL;
|
|
||||||
res = file_to_buf(badge_path, ArchiveSD, &file_buf);
|
|
||||||
if (res != badge_file.fileSize)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int badges = install_badge_generic(file_buf, badge_file.fileSize, badge_file.name, badge_count, set_id);
|
|
||||||
free(file_buf);
|
|
||||||
return badges;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int *badge_count;
|
|
||||||
int set_id;
|
|
||||||
int installed;
|
|
||||||
} zip_userdata;
|
|
||||||
|
|
||||||
u32 zip_callback(char *file_buf, u64 file_size, const char *name, void *userdata)
|
|
||||||
{
|
|
||||||
progress_finish += 1;
|
|
||||||
zip_userdata *data = (zip_userdata *) userdata;
|
|
||||||
u16 *utf16_name = calloc(strlen(name), sizeof(u16));
|
|
||||||
utf8_to_utf16(utf16_name, (u8 *) name, strlen(name));
|
|
||||||
data->installed += install_badge_generic(file_buf, file_size, utf16_name, data->badge_count, data->set_id);
|
|
||||||
free(utf16_name);
|
|
||||||
progress_status += 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int install_badge_zip(u16 *path, int *badge_count, int set_id)
|
|
||||||
{
|
|
||||||
zip_userdata data = {0};
|
|
||||||
data.set_id = set_id;
|
|
||||||
data.badge_count = badge_count;
|
|
||||||
for_each_file_zip(path, zip_callback, &data);
|
|
||||||
|
|
||||||
return data.installed;
|
|
||||||
}
|
|
||||||
|
|
||||||
int install_badge_dir(FS_DirectoryEntry set_dir, int *badge_count, int set_id)
|
|
||||||
{
|
|
||||||
Result res;
|
|
||||||
Handle folder;
|
|
||||||
int start_idx = *badge_count;
|
|
||||||
char *icon_buf = NULL;
|
|
||||||
int icon_size = 0;
|
|
||||||
|
|
||||||
FS_DirectoryEntry *badge_files = calloc(1024, sizeof(FS_DirectoryEntry));
|
|
||||||
u16 path[512] = {0};
|
|
||||||
u16 set_icon[17] = {0};
|
|
||||||
utf8_to_utf16(set_icon, (u8 *) "_seticon.png", 16);
|
|
||||||
struacat(path, main_paths[REMOTE_MODE_BADGES]);
|
|
||||||
strucat(path, set_dir.name);
|
|
||||||
res = FSUSER_OpenDirectory(&folder, ArchiveSD, fsMakePath(PATH_UTF16, path));
|
|
||||||
if (R_FAILED(res))
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
u32 entries_read;
|
|
||||||
res = FSDIR_Read(folder, &entries_read, 1024, badge_files);
|
|
||||||
int badges_in_set = 0;
|
|
||||||
progress_finish += entries_read;
|
|
||||||
for (u32 i = 0; i < entries_read && *badge_count < 1000; ++i)
|
|
||||||
{
|
|
||||||
if (!strcmp(badge_files[i].shortExt, "PNG"))
|
|
||||||
{
|
|
||||||
memset(path, 0, 512 * sizeof(u16));
|
|
||||||
struacat(path, main_paths[REMOTE_MODE_BADGES]);
|
|
||||||
strucat(path, set_dir.name);
|
|
||||||
struacat(path, "/");
|
|
||||||
strucat(path, badge_files[i].name);
|
|
||||||
if (!memcmp(set_icon, badge_files[i].name, 16))
|
|
||||||
{
|
|
||||||
DEBUG("Found set icon for folder set %d\n", set_id);
|
|
||||||
icon_size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &icon_buf);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
badges_in_set += install_badge_png(fsMakePath(PATH_UTF16, path), badge_files[i], badge_count, set_id);
|
|
||||||
} else if (!strcmp(badge_files[i].shortExt, "ZIP"))
|
|
||||||
{
|
|
||||||
memset(path, 0, 512 * sizeof(u16));
|
|
||||||
struacat(path, main_paths[REMOTE_MODE_BADGES]);
|
|
||||||
strucat(path, set_dir.name);
|
|
||||||
struacat(path, "/");
|
|
||||||
strucat(path, badge_files[i].name);
|
|
||||||
badges_in_set += install_badge_zip(path, badge_count, set_id);
|
|
||||||
}
|
|
||||||
progress_status += 1;
|
|
||||||
draw_loading_bar(progress_status, progress_finish, INSTALL_BADGES);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!badges_in_set)
|
|
||||||
{
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
int set_index = set_id - 1;
|
|
||||||
u32 total_count = 0xFFFF * badges_in_set;
|
|
||||||
for (int i = 0; i < 16; ++i)
|
|
||||||
{
|
|
||||||
FSFILE_Write(badgeDataHandle, NULL, set_index * 0x8A0 + i * 0x8A, set_dir.name, strulen(set_dir.name, 0x45) * 2 + 2, 0);
|
|
||||||
}
|
|
||||||
badgeMngBuffer[0x3D8 + set_index/8] |= 0 << (set_index % 8);
|
|
||||||
|
|
||||||
memset(badgeMngBuffer + 0xA028 + set_index * 0x30, 0xFF, 8);
|
|
||||||
badgeMngBuffer[0xA028 + 0xC + set_index * 0x30] = 0x10; // bytes 13 and 14 are 0x2710
|
|
||||||
badgeMngBuffer[0xA028 + 0xD + set_index * 0x30] = 0x27;
|
|
||||||
memcpy(badgeMngBuffer + 0xA028 + 0x10 + set_index * 0x30, &set_id, 4);
|
|
||||||
memcpy(badgeMngBuffer + 0xA028 + 0x14 + set_index * 0x30, &set_index, 4);
|
|
||||||
memset(badgeMngBuffer + 0xA028 + 0x18 + set_index * 0x30, 0xFF, 4);
|
|
||||||
memcpy(badgeMngBuffer + 0xA028 + 0x1C + set_index * 0x30, &badges_in_set, 4);
|
|
||||||
memcpy(badgeMngBuffer + 0xA028 + 0x20 + set_index * 0x30, &total_count, 4);
|
|
||||||
memcpy(badgeMngBuffer + 0xA028 + 0x24 + set_index * 0x30, &start_idx, 4);
|
|
||||||
|
|
||||||
int icon = pngToRGB565(icon_buf, icon_size, rgb_buf_64x64, alpha_buf_64x64, rgb_buf_32x32, alpha_buf_32x32, true);
|
|
||||||
|
|
||||||
if (icon == 0)
|
|
||||||
{
|
|
||||||
DEBUG("Falling back on default icon\n");
|
|
||||||
if (icon_buf) free(icon_buf);
|
|
||||||
FILE *fp = fopen("romfs:/hb_set.png", "rb");
|
|
||||||
fseek(fp, 0L, SEEK_END);
|
|
||||||
icon_size = ftell(fp);
|
|
||||||
icon_buf = malloc(icon_size);
|
|
||||||
fseek(fp, 0L, SEEK_SET);
|
|
||||||
fread(icon_buf, 1, icon_size, fp);
|
|
||||||
fclose(fp);
|
|
||||||
pngToRGB565(icon_buf, icon_size, rgb_buf_64x64, alpha_buf_64x64, rgb_buf_32x32, alpha_buf_32x32, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(icon_buf);
|
|
||||||
FSFILE_Write(badgeDataHandle, NULL, 0x250F80 + set_index * 0x2000, rgb_buf_64x64, 64 * 64 * 2, 0);
|
|
||||||
badgeMngBuffer[0x3D8 + set_index/8] |= 0 << (set_index % 8);
|
|
||||||
end:
|
|
||||||
free(badge_files);
|
|
||||||
FSDIR_Close(folder);
|
|
||||||
return badges_in_set;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct set_node_s {
|
|
||||||
u32 set_id;
|
|
||||||
u32 set_index;
|
|
||||||
struct set_node_s *next;
|
|
||||||
} SetNode;
|
|
||||||
|
|
||||||
u32 get_set_index(SetNode *head, u32 set_id)
|
|
||||||
{
|
|
||||||
SetNode *cursor = head;
|
|
||||||
while (cursor != NULL)
|
|
||||||
{
|
|
||||||
if (cursor->set_id == set_id)
|
|
||||||
return cursor->set_index;
|
|
||||||
cursor = cursor->next;
|
|
||||||
}
|
|
||||||
return 0xFFFFFFFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
void free_list(SetNode *head)
|
|
||||||
{
|
|
||||||
SetNode *cursor = head;
|
|
||||||
while (cursor)
|
|
||||||
{
|
|
||||||
SetNode *next = cursor->next;
|
|
||||||
free(cursor);
|
|
||||||
cursor = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SetNode * extract_sets(char *badgeMngBuffer, Handle backupDataHandle)
|
|
||||||
{
|
|
||||||
u32 setCount = *((u32 *) (badgeMngBuffer + 0x4));
|
|
||||||
|
|
||||||
if (!setCount) // GYTB? make unknown set
|
|
||||||
{
|
|
||||||
u16 set_path[256] = {0};
|
|
||||||
struacat(set_path, "/3ds/" APP_TITLE "/BadgeBackups/Unknown Set");
|
|
||||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_UTF16, set_path), FS_ATTRIBUTE_DIRECTORY);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetNode *head = calloc(1, sizeof(SetNode));
|
|
||||||
SetNode *cursor = head;
|
|
||||||
|
|
||||||
u16 *icon_rgb_buf = malloc(64 * 64 * 2);
|
|
||||||
u8 *icon_alpha_buf = malloc(64 * 64 * 0.5);
|
|
||||||
|
|
||||||
for (u32 i = 0; i < setCount; ++i)
|
|
||||||
{
|
|
||||||
memcpy(&(cursor->set_id), &badgeMngBuffer[0xA028 + 0x30 * i + 0x10], 4);
|
|
||||||
memcpy(&(cursor->set_index), &badgeMngBuffer[0xA028 + 0x30 * i + 0x14], 4);
|
|
||||||
|
|
||||||
if (cursor->set_id != 0xEFBE) // 0xEFBE is GYTB Set ID; GYTB doesn't properly create sets, so skip
|
|
||||||
{
|
|
||||||
DEBUG("Processing icon for set %lu at index %lu\n", cursor->set_id, cursor->set_index);
|
|
||||||
u16 utf16SetName[0x46] = {0};
|
|
||||||
FSFILE_Read(backupDataHandle, NULL, cursor->set_index * 16 * 0x8A, utf16SetName, 0x8A);
|
|
||||||
replace_chars(utf16SetName, ILLEGAL_CHARS, u'-');
|
|
||||||
u16 set_path[256] = {0};
|
|
||||||
struacat(set_path, "/3ds/" APP_TITLE "/BadgeBackups/");
|
|
||||||
size_t set_name_len = strucat(set_path, utf16SetName);
|
|
||||||
if (!set_name_len)
|
|
||||||
{
|
|
||||||
struacat(set_path, "Unknown Set");
|
|
||||||
}
|
|
||||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_UTF16, set_path), FS_ATTRIBUTE_DIRECTORY);
|
|
||||||
memset(icon_alpha_buf, 255, 64 * 64 * 0.5);
|
|
||||||
FSFILE_Read(backupDataHandle, NULL, 0x250F80 + cursor->set_index * 0x2000, icon_rgb_buf, 0x2000);
|
|
||||||
char filename[256] = {0};
|
|
||||||
utf16_to_utf8((u8 *) filename, set_path, 256);
|
|
||||||
strcat(filename, "/_seticon.png");
|
|
||||||
DEBUG("%s\n", filename);
|
|
||||||
rgb565ToPngFile(filename, icon_rgb_buf, icon_alpha_buf, 48, 48);
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor->next = calloc(1, sizeof(SetNode));
|
|
||||||
cursor = cursor->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(icon_rgb_buf);
|
|
||||||
free(icon_alpha_buf);
|
|
||||||
|
|
||||||
return head;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result extract_badges(void)
|
|
||||||
{
|
|
||||||
DEBUG("Dumping installed badges...\n");
|
|
||||||
char *badgeMngBuffer = NULL;
|
|
||||||
u32 size = file_to_buf(fsMakePath(PATH_ASCII, "/BadgeMngFile.dat"), ArchiveBadgeExt, &badgeMngBuffer);
|
|
||||||
DEBUG("%lu bytes read\n", size);
|
|
||||||
|
|
||||||
Result res = 0;
|
|
||||||
SetNode *head;
|
|
||||||
Handle backupDataHandle;
|
|
||||||
u16 *badge_rgb_buf = malloc(64 * 64 * 2);
|
|
||||||
u8 *badge_alpha_buf = malloc(64 * 64 * 0.5);
|
|
||||||
u32 badge_count = 0;
|
|
||||||
memcpy(&badge_count, badgeMngBuffer + 0x8, 4);
|
|
||||||
DEBUG("%lu badges found\n", badge_count);
|
|
||||||
if (badge_count > 0)
|
|
||||||
{
|
|
||||||
res = FSUSER_OpenFile(&backupDataHandle, ArchiveBadgeExt, fsMakePath(PATH_ASCII, "/BadgeData.dat"), FS_OPEN_READ, 0);
|
|
||||||
if (R_FAILED(res))
|
|
||||||
{
|
|
||||||
free(badgeMngBuffer);
|
|
||||||
free(badge_rgb_buf);
|
|
||||||
free(badge_alpha_buf);
|
|
||||||
char err_string[128] = {0};
|
|
||||||
sprintf(err_string, language.badges.extdata_locked, res);
|
|
||||||
throw_error(err_string, ERROR_LEVEL_WARNING);
|
|
||||||
DEBUG("backupDataHandle open failed\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
head = extract_sets(badgeMngBuffer, backupDataHandle);
|
|
||||||
} else {
|
|
||||||
free(badgeMngBuffer);
|
|
||||||
free(badge_rgb_buf);
|
|
||||||
free(badge_alpha_buf);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
for (u32 i = 0; i < badge_count; ++i)
|
|
||||||
{
|
|
||||||
u32 badgeId;
|
|
||||||
memcpy(&badgeId, badgeMngBuffer + 0x3E8 + i * 0x28 + 0x4, 4);
|
|
||||||
u32 badgeSetId;
|
|
||||||
memcpy(&badgeSetId, badgeMngBuffer + 0x3E8 + i * 0x28 + 0x8, 4);
|
|
||||||
u16 badgeSubId;
|
|
||||||
memcpy(&badgeSubId, badgeMngBuffer + 0x3E8 + i * 0x28 + 0xE, 2);
|
|
||||||
u32 shortcut;
|
|
||||||
memcpy(&shortcut, badgeMngBuffer + 0x3E8 + i * 0x28 + 0x18, 4);
|
|
||||||
|
|
||||||
char filename[512] = {0};
|
|
||||||
|
|
||||||
u16 utf16Name[0x46] = {0};
|
|
||||||
FSFILE_Read(backupDataHandle, NULL, 0x35E80 + i * 16 * 0x8A, utf16Name, 0x8A);
|
|
||||||
replace_chars(utf16Name, ILLEGAL_CHARS, u'-');
|
|
||||||
char utf8Name[256] = {0};
|
|
||||||
res = utf16_to_utf8((u8 *) utf8Name, utf16Name, 256);
|
|
||||||
|
|
||||||
char dir[256] = "/3ds/" APP_TITLE "/BadgeBackups/";
|
|
||||||
if (badgeSetId != 0xEFBE) // 0xEFBE is GYTB Set ID; GYTB doesn't properly create sets, so skip
|
|
||||||
{
|
|
||||||
u32 set_index = get_set_index(head, badgeSetId);
|
|
||||||
if (set_index == 0xFFFFFFFF) {
|
|
||||||
sprintf(dir, "/3ds/" APP_TITLE "/BadgeBackups/Unknown Set");
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
u16 utf16SetName[0x46] = {0};
|
|
||||||
FSFILE_Read(backupDataHandle, NULL, set_index * 16 * 0x8A, utf16SetName, 0x8A);
|
|
||||||
replace_chars(utf16SetName, ILLEGAL_CHARS, u'-');
|
|
||||||
char utf8SetName[128] = {0};
|
|
||||||
res = utf16_to_utf8((u8 *) utf8SetName, utf16SetName, 128);
|
|
||||||
if (!res)
|
|
||||||
strncpy(utf8SetName, "Unknown Set", 128);
|
|
||||||
DEBUG("UTF-8 Set Name: %s; ID: %lx\n", utf8SetName, badgeSetId);
|
|
||||||
sprintf(dir, "/3ds/" APP_TITLE "/BadgeBackups/%s", utf8SetName);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
sprintf(dir, "/3ds/" APP_TITLE "/BadgeBackups/Unknown Set");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shortcut == 0xFFFFFFFF)
|
|
||||||
{
|
|
||||||
sprintf(filename, "%s/%s.%lx.%x.png", dir, utf8Name, badgeId, badgeSubId);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
sprintf(filename, "%s/%s.%08lx.%lx.%x.png", dir, utf8Name, shortcut, badgeId, badgeSubId);
|
|
||||||
}
|
|
||||||
DEBUG("Dump filename: %s\n", filename);
|
|
||||||
|
|
||||||
FSFILE_Read(backupDataHandle, NULL, 0x318F80 + i * 0x2800, badge_rgb_buf, 0x2000);
|
|
||||||
FSFILE_Read(backupDataHandle, NULL, 0x318F80 + i * 0x2800 + 0x2000, badge_alpha_buf, 0x800);
|
|
||||||
rgb565ToPngFile(filename, badge_rgb_buf, badge_alpha_buf, 64, 64);
|
|
||||||
draw_loading_bar(i + 1, badge_count, INSTALL_DUMPING_BADGES);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(badgeMngBuffer);
|
|
||||||
free(badge_rgb_buf);
|
|
||||||
free(badge_alpha_buf);
|
|
||||||
free_list(head);
|
|
||||||
FSFILE_Close(backupDataHandle);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result backup_badges_fast(void)
|
|
||||||
{
|
|
||||||
char *badgeMng = NULL;
|
|
||||||
|
|
||||||
DEBUG("writing badge data: making files...\n");
|
|
||||||
char mng_path[128] = "/3ds/" APP_TITLE "/BadgeMngFile.dat";
|
|
||||||
char data_path[128] = "/3ds/" APP_TITLE "/BadgeData.dat";
|
|
||||||
DEBUG("mng_path: %s, data_path: %s\n", mng_path, data_path);
|
|
||||||
|
|
||||||
Handle dataHandle = 0;
|
|
||||||
Handle sdHandle = 0;
|
|
||||||
|
|
||||||
DEBUG("loading existing badge mng file...\n");
|
|
||||||
u32 mngRead = file_to_buf(fsMakePath(PATH_ASCII, "/BadgeMngFile.dat"), ArchiveBadgeExt, &badgeMng);
|
|
||||||
DEBUG("loading existing badge data file\n");
|
|
||||||
Result res = FSUSER_OpenFile(&dataHandle, ArchiveBadgeExt, fsMakePath(PATH_ASCII, "/BadgeData.dat"), FS_OPEN_READ, 0);
|
|
||||||
if (mngRead != BADGE_MNG_SIZE || R_FAILED(res))
|
|
||||||
{
|
|
||||||
char err_string[128] = {0};
|
|
||||||
sprintf(err_string, language.badges.extdata_locked, res);
|
|
||||||
throw_error(err_string, ERROR_LEVEL_WARNING);
|
|
||||||
if (badgeMng) free(badgeMng);
|
|
||||||
if (dataHandle) FSFILE_Close(dataHandle);
|
|
||||||
FSFILE_Close(sdHandle);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
remake_file(fsMakePath(PATH_ASCII, mng_path), ArchiveSD, BADGE_MNG_SIZE);
|
|
||||||
|
|
||||||
FSUSER_CreateFile(ArchiveSD, fsMakePath(PATH_ASCII, data_path), 0, BADGE_DATA_SIZE);
|
|
||||||
FSUSER_OpenFile(&sdHandle, ArchiveSD, fsMakePath(PATH_ASCII, data_path), FS_OPEN_WRITE, 0);
|
|
||||||
|
|
||||||
DEBUG("writing badge data: writing BadgeMngFile...\n");
|
|
||||||
res = buf_to_file(mngRead, fsMakePath(PATH_ASCII, mng_path), ArchiveSD, badgeMng);
|
|
||||||
if (R_FAILED(res))
|
|
||||||
{
|
|
||||||
DEBUG("Failed to write badgemngfile: 0x%08lx\n", res);
|
|
||||||
free(badgeMng);
|
|
||||||
FSFILE_Close(dataHandle);
|
|
||||||
FSFILE_Close(sdHandle);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
DEBUG("writing badge data: writing badgedata...\n");
|
|
||||||
char *buf = malloc(0x10000);
|
|
||||||
u64 size = BADGE_DATA_SIZE;
|
|
||||||
u64 cur = 0;
|
|
||||||
while (size > 0)
|
|
||||||
{
|
|
||||||
u32 read = 0;
|
|
||||||
res = FSFILE_Read(dataHandle, &read, cur, buf, min(0x10000, size));
|
|
||||||
res = FSFILE_Write(sdHandle, NULL, cur, buf, read, FS_WRITE_FLUSH);
|
|
||||||
size -= read;
|
|
||||||
cur += read;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(badgeMng);
|
|
||||||
free(buf);
|
|
||||||
FSFILE_Close(dataHandle);
|
|
||||||
FSFILE_Close(sdHandle);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result install_badges(void)
|
|
||||||
{
|
|
||||||
Handle handle = 0;
|
|
||||||
Handle folder = 0;
|
|
||||||
Result res = 0;
|
|
||||||
draw_loading_bar(0, 1, INSTALL_BADGES);
|
|
||||||
{
|
|
||||||
char testpath[128] = "/3ds/" APP_TITLE "/BadgeData.dat";
|
|
||||||
if (R_FAILED(res = FSUSER_OpenFile(&handle, ArchiveSD, fsMakePath(PATH_ASCII, testpath), FS_OPEN_READ, 0)))
|
|
||||||
{
|
|
||||||
if (R_SUMMARY(res) == RS_NOTFOUND)
|
|
||||||
{
|
|
||||||
res = backup_badges_fast();
|
|
||||||
if (R_FAILED(res)) return res;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
DEBUG("????: 0x%08lx\n", res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (handle) FSFILE_Close(handle);
|
|
||||||
|
|
||||||
DEBUG("Initializing ACT\n");
|
|
||||||
res = actInit(true);
|
|
||||||
if (R_FAILED(res))
|
|
||||||
{
|
|
||||||
DEBUG("actInit() failed!\n");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG("Initializing ACT\n");
|
|
||||||
res = ACT_Initialize(0xB0502C8, 0, 0);
|
|
||||||
if (R_FAILED(res))
|
|
||||||
{
|
|
||||||
DEBUG("ACT_Initialize failed! %08lx\n", res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG("Getting NNID\n");
|
|
||||||
u32 nnidNum = 0xFFFFFFFF;
|
|
||||||
res = ACT_GetAccountInfo(&nnidNum, sizeof(nnidNum), ACT_DEFAULT_ACCOUNT, INFO_TYPE_PRINCIPAL_ID);
|
|
||||||
if (R_FAILED(res))
|
|
||||||
{
|
|
||||||
DEBUG("ACT_GetAccountInfo failed! %08lx\n", res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
DEBUG("NNID found: 0x%08lx\n", nnidNum);
|
|
||||||
|
|
||||||
badgeMngBuffer = NULL;
|
|
||||||
badgeDataHandle = 0;
|
|
||||||
rgb_buf_64x64 = NULL;
|
|
||||||
rgb_buf_32x32 = NULL;
|
|
||||||
alpha_buf_64x64 = NULL;
|
|
||||||
alpha_buf_32x32 = NULL;
|
|
||||||
|
|
||||||
DEBUG("Opening badge directory\n");
|
|
||||||
FS_DirectoryEntry *badge_files = calloc(1024, sizeof(FS_DirectoryEntry));
|
|
||||||
res = FSUSER_OpenDirectory(&folder, ArchiveSD, fsMakePath(PATH_ASCII, main_paths[REMOTE_MODE_BADGES]));
|
|
||||||
if (R_FAILED(res))
|
|
||||||
{
|
|
||||||
DEBUG("Failed to open folder: %lx\n", res);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 entries_read;
|
|
||||||
res = FSDIR_Read(folder, &entries_read, 1024, badge_files);
|
|
||||||
DEBUG("%lu files found\n", entries_read);
|
|
||||||
rgb_buf_64x64 = malloc(12*6*64*64*2); //12x6 badges in sheet max, 64x64 pixel badges, 2 bytes per RGB data
|
|
||||||
alpha_buf_64x64 = malloc(12*6*64*64/2); //Same thing, but 2 pixels of alpha data per byte
|
|
||||||
rgb_buf_32x32 = malloc(12*6*32*32*2); //Same thing, but 32x32
|
|
||||||
alpha_buf_32x32 = malloc(12*6*32*32/2);
|
|
||||||
res = FSUSER_OpenFile(&badgeDataHandle, ArchiveBadgeExt, fsMakePath(PATH_ASCII, "/BadgeData.dat"), FS_OPEN_WRITE, 0);
|
|
||||||
badgeMngBuffer = calloc(1, BADGE_MNG_SIZE);
|
|
||||||
|
|
||||||
if (!rgb_buf_64x64)
|
|
||||||
{
|
|
||||||
DEBUG("rgb_buf_64x64 alloc failed\n");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!alpha_buf_64x64)
|
|
||||||
{
|
|
||||||
DEBUG("alpha_buf_64x64 alloc failed\n");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rgb_buf_32x32)
|
|
||||||
{
|
|
||||||
DEBUG("rgb_buf_32x32 alloc failed\n");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!alpha_buf_32x32)
|
|
||||||
{
|
|
||||||
DEBUG("alpha_buf_32x32 alloc failed\n");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (R_FAILED(res))
|
|
||||||
{
|
|
||||||
badgeDataHandle = 0;
|
|
||||||
char err_string[128] = {0};
|
|
||||||
sprintf(err_string, language.badges.extdata_locked, res);
|
|
||||||
throw_error(err_string, ERROR_LEVEL_WARNING);
|
|
||||||
DEBUG("badgeDataHandle open failed\n");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!badgeMngBuffer)
|
|
||||||
{
|
|
||||||
DEBUG("badgeMngBuffer alloc failed\n");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
zero_handle_memeasy(badgeDataHandle);
|
|
||||||
|
|
||||||
int badge_count = 0;
|
|
||||||
int set_count = 0;
|
|
||||||
int default_set = 0;
|
|
||||||
int default_set_count = 0;
|
|
||||||
int default_idx = 0;
|
|
||||||
|
|
||||||
progress_finish = entries_read + 12;
|
|
||||||
progress_status = 12;
|
|
||||||
draw_loading_bar(progress_status, progress_finish, INSTALL_BADGES);
|
|
||||||
for (u32 i = 0; i < entries_read && badge_count < 1000; ++i)
|
|
||||||
{
|
|
||||||
if (!strcmp(badge_files[i].shortExt, "PNG"))
|
|
||||||
{
|
|
||||||
if (default_set == 0)
|
|
||||||
{
|
|
||||||
set_count += 1;
|
|
||||||
default_set = set_count;
|
|
||||||
default_idx = badge_count;
|
|
||||||
}
|
|
||||||
u16 path[0x512] = {0};
|
|
||||||
struacat(path, main_paths[REMOTE_MODE_BADGES]);
|
|
||||||
strucat(path, badge_files[i].name);
|
|
||||||
default_set_count += install_badge_png(fsMakePath(PATH_UTF16, path), badge_files[i], &badge_count, default_set);
|
|
||||||
} else if (!strcmp(badge_files[i].shortExt, "ZIP"))
|
|
||||||
{
|
|
||||||
if (default_set == 0)
|
|
||||||
{
|
|
||||||
set_count += 1;
|
|
||||||
default_set = set_count;
|
|
||||||
}
|
|
||||||
u16 path[0x512] = {0};
|
|
||||||
struacat(path, main_paths[REMOTE_MODE_BADGES]);
|
|
||||||
strucat(path, badge_files[i].name);
|
|
||||||
|
|
||||||
default_set_count += install_badge_zip(path, &badge_count, default_set);
|
|
||||||
} else if (badge_files[i].attributes & FS_ATTRIBUTE_DIRECTORY)
|
|
||||||
{
|
|
||||||
set_count += 1;
|
|
||||||
u32 count = install_badge_dir(badge_files[i], &badge_count, set_count);
|
|
||||||
if (count == 0)
|
|
||||||
set_count -= 1;
|
|
||||||
}
|
|
||||||
progress_status += 1;
|
|
||||||
draw_loading_bar(progress_status, progress_finish, INSTALL_BADGES);
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG("Badges installed - doing metadata\n");
|
|
||||||
if (default_set != 0)
|
|
||||||
{
|
|
||||||
int default_index = default_set - 1;
|
|
||||||
u32 total_count = 0xFFFF * default_set_count;
|
|
||||||
for (int i = 0; i < 16; ++i)
|
|
||||||
{
|
|
||||||
u16 name[0x8A/2] = {0};
|
|
||||||
utf8_to_utf16(name, (u8 *) "Other Badges", 0x8A);
|
|
||||||
FSFILE_Write(badgeDataHandle, NULL, default_index * 0x8A0 + i * 0x8A, &name, strulen(name, 0x45) * 2, 0);
|
|
||||||
}
|
|
||||||
badgeMngBuffer[0x3D8 + default_index/8] |= 1 << (default_index % 8);
|
|
||||||
|
|
||||||
memset(badgeMngBuffer + 0xA028 + default_index * 0x30, 0xFF, 8);
|
|
||||||
badgeMngBuffer[0xA028 + 0xC + default_index * 0x30] = 0x10; // bytes 13 and 14 are 0x2710
|
|
||||||
badgeMngBuffer[0xA028 + 0xD + default_index * 0x30] = 0x27;
|
|
||||||
memcpy(badgeMngBuffer + 0xA028 + 0x10 + default_index * 0x30, &default_set, 4);
|
|
||||||
memcpy(badgeMngBuffer + 0xA028 + 0x14 + default_index * 0x30, &default_index, 4);
|
|
||||||
memset(badgeMngBuffer + 0xA028 + 0x18 + default_index * 0x30, 0xFF, 4);
|
|
||||||
memcpy(badgeMngBuffer + 0xA028 + 0x1C + default_index * 0x30, &default_set_count, 4);
|
|
||||||
memcpy(badgeMngBuffer + 0xA028 + 0x20 + default_index * 0x30, &total_count, 4);
|
|
||||||
memcpy(badgeMngBuffer + 0xA028 + 0x24 + default_index * 0x30, &default_idx, 4);
|
|
||||||
|
|
||||||
FILE *fp = fopen("romfs:/anemone_set.png", "rb");
|
|
||||||
fseek(fp, 0L, SEEK_END);
|
|
||||||
ssize_t size = ftell(fp);
|
|
||||||
char *icon_buf = malloc(size);
|
|
||||||
fseek(fp, 0L, SEEK_SET);
|
|
||||||
fread(icon_buf, 1, size, fp);
|
|
||||||
fclose(fp);
|
|
||||||
pngToRGB565(icon_buf, size, rgb_buf_64x64, alpha_buf_64x64, rgb_buf_32x32, alpha_buf_32x32, true);
|
|
||||||
free(icon_buf);
|
|
||||||
FSFILE_Write(badgeDataHandle, NULL, 0x250F80 + default_index * 0x2000, rgb_buf_64x64, 64 * 64 * 2, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
FSFILE_Flush(badgeDataHandle);
|
|
||||||
|
|
||||||
u32 total_badges = 0xFFFF * badge_count; // Quantity * unique badges?
|
|
||||||
|
|
||||||
badgeMngBuffer[0x4] = set_count; // badge set count
|
|
||||||
memcpy(badgeMngBuffer + 0x8, &badge_count, 4);
|
|
||||||
badgeMngBuffer[0x10] = 0xFF; // Selected Set - 0xFFFFFFFF is all badges
|
|
||||||
badgeMngBuffer[0x11] = 0xFF;
|
|
||||||
badgeMngBuffer[0x12] = 0xFF;
|
|
||||||
badgeMngBuffer[0x13] = 0xFF;
|
|
||||||
memcpy(badgeMngBuffer + 0x18, &total_badges, 4);
|
|
||||||
memcpy(badgeMngBuffer + 0x1C, &nnidNum, 4);
|
|
||||||
|
|
||||||
for (int i = set_count; i < 100; ++i) // default values for remaining sets
|
|
||||||
{
|
|
||||||
memset(badgeMngBuffer + 0xA028 + 0x30 * i, 0xFF, 0x8);
|
|
||||||
memset(badgeMngBuffer + 0xA028 + 0x30 * i + 0x8, 0x00, 0x4);
|
|
||||||
badgeMngBuffer[0xA028 + 0x30 * i + 0xC] = 0x10;
|
|
||||||
badgeMngBuffer[0xA028 + 0x30 * i + 0xD] = 0x27;
|
|
||||||
memset(badgeMngBuffer + 0xA028 + 0x30 * i + 0xE, 0x0, 0x2);
|
|
||||||
memset(badgeMngBuffer + 0xA028 + 0x30 * i + 0x10, 0xFF, 0xC);
|
|
||||||
memset(badgeMngBuffer + 0xA028 + 0x30 * i + 0x1C, 0x00, 0x8);
|
|
||||||
memset(badgeMngBuffer + 0xA028 + 0x30 * i + 0x24, 0xFF, 0x4);
|
|
||||||
memset(badgeMngBuffer + 0xA028 + 0x30 * i + 0x28, 0x00, 0x8);
|
|
||||||
}
|
|
||||||
|
|
||||||
res = FSUSER_OpenFile(&handle, ArchiveBadgeExt, fsMakePath(PATH_ASCII, "/BadgeMngFile.dat"), FS_OPEN_READ, 0);
|
|
||||||
if (res == 0)
|
|
||||||
{
|
|
||||||
FSFILE_Read(handle, NULL, 0xB2E8, badgeMngBuffer+0xB2E8, 360 * 0x18);
|
|
||||||
FSFILE_Close(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
res = buf_to_file(BADGE_MNG_SIZE, fsMakePath(PATH_ASCII, "/BadgeMngFile.dat"), ArchiveBadgeExt, badgeMngBuffer);
|
|
||||||
if (res)
|
|
||||||
{
|
|
||||||
DEBUG("Error writing badge manage data! %lx\n", res);
|
|
||||||
char err_string[128] = {0};
|
|
||||||
sprintf(err_string, language.badges.extdata_locked, res);
|
|
||||||
throw_error(err_string, ERROR_LEVEL_WARNING);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
end:
|
|
||||||
actExit();
|
|
||||||
if (rgb_buf_64x64) free(rgb_buf_64x64);
|
|
||||||
if (alpha_buf_64x64) free(alpha_buf_64x64);
|
|
||||||
if (rgb_buf_32x32) free(rgb_buf_32x32);
|
|
||||||
if (alpha_buf_32x32) free(alpha_buf_32x32);
|
|
||||||
if (handle) FSFILE_Close(handle);
|
|
||||||
if (folder) FSDIR_Close(folder);
|
|
||||||
if (badgeDataHandle) FSFILE_Close(badgeDataHandle);
|
|
||||||
if (badgeMngBuffer) free(badgeMngBuffer);
|
|
||||||
if (badge_files) free(badge_files);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
@@ -32,12 +32,11 @@
|
|||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "loading.h"
|
#include "loading.h"
|
||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
#include "ui_strings.h"
|
|
||||||
|
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
#include <archive_entry.h>
|
#include <archive_entry.h>
|
||||||
|
|
||||||
static void start_read(qr_data * data)
|
static void start_read(qr_data *data)
|
||||||
{
|
{
|
||||||
LightLock_Lock(&data->mut);
|
LightLock_Lock(&data->mut);
|
||||||
while(data->writer_waiting || data->writer_active)
|
while(data->writer_waiting || data->writer_active)
|
||||||
@@ -48,7 +47,7 @@ static void start_read(qr_data * data)
|
|||||||
AtomicIncrement(&data->num_readers_active);
|
AtomicIncrement(&data->num_readers_active);
|
||||||
LightLock_Unlock(&data->mut);
|
LightLock_Unlock(&data->mut);
|
||||||
}
|
}
|
||||||
static void stop_read(qr_data * data)
|
static void stop_read(qr_data *data)
|
||||||
{
|
{
|
||||||
LightLock_Lock(&data->mut);
|
LightLock_Lock(&data->mut);
|
||||||
AtomicDecrement(&data->num_readers_active);
|
AtomicDecrement(&data->num_readers_active);
|
||||||
@@ -58,7 +57,7 @@ static void stop_read(qr_data * data)
|
|||||||
}
|
}
|
||||||
LightLock_Unlock(&data->mut);
|
LightLock_Unlock(&data->mut);
|
||||||
}
|
}
|
||||||
static void start_write(qr_data * data)
|
static void start_write(qr_data *data)
|
||||||
{
|
{
|
||||||
LightLock_Lock(&data->mut);
|
LightLock_Lock(&data->mut);
|
||||||
data->writer_waiting = true;
|
data->writer_waiting = true;
|
||||||
@@ -73,7 +72,7 @@ static void start_write(qr_data * data)
|
|||||||
|
|
||||||
LightLock_Unlock(&data->mut);
|
LightLock_Unlock(&data->mut);
|
||||||
}
|
}
|
||||||
static void stop_write(qr_data * data)
|
static void stop_write(qr_data *data)
|
||||||
{
|
{
|
||||||
LightLock_Lock(&data->mut);
|
LightLock_Lock(&data->mut);
|
||||||
|
|
||||||
@@ -83,16 +82,16 @@ static void stop_write(qr_data * data)
|
|||||||
LightLock_Unlock(&data->mut);
|
LightLock_Unlock(&data->mut);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void capture_cam_thread(void * arg)
|
static void capture_cam_thread(void *arg)
|
||||||
{
|
{
|
||||||
qr_data * data = (qr_data *) arg;
|
qr_data *data = (qr_data *) arg;
|
||||||
|
|
||||||
Handle cam_events[3] = {0};
|
Handle cam_events[3] = {0};
|
||||||
cam_events[0] = data->event_stop;
|
cam_events[0] = data->event_stop;
|
||||||
|
|
||||||
u32 transferUnit;
|
u32 transferUnit;
|
||||||
const u32 bufsz = 400 * 240 * sizeof(u16);
|
const u32 bufsz = 400 * 240 * sizeof(u16);
|
||||||
u16 * buffer = linearAlloc(bufsz);
|
u16 *buffer = linearAlloc(bufsz);
|
||||||
|
|
||||||
camInit();
|
camInit();
|
||||||
CAMU_SetSize(SELECT_OUT1, SIZE_CTR_TOP_LCD, CONTEXT_A);
|
CAMU_SetSize(SELECT_OUT1, SIZE_CTR_TOP_LCD, CONTEXT_A);
|
||||||
@@ -168,9 +167,9 @@ static void capture_cam_thread(void * arg)
|
|||||||
LightEvent_Signal(&data->event_cam_info);
|
LightEvent_Signal(&data->event_cam_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_ui(void * arg)
|
static void update_ui(void *arg)
|
||||||
{
|
{
|
||||||
qr_data * data = (qr_data *) arg;
|
qr_data* data = (qr_data*) arg;
|
||||||
C3D_Tex tex;
|
C3D_Tex tex;
|
||||||
|
|
||||||
static const Tex3DS_SubTexture subt3x = { 400, 240, 0.0f, 1.0f, 400.0f/512.0f, 1.0f - (240.0f/256.0f) };
|
static const Tex3DS_SubTexture subt3x = { 400, 240, 0.0f, 1.0f, 400.0f/512.0f, 1.0f - (240.0f/256.0f) };
|
||||||
@@ -191,7 +190,7 @@ static void update_ui(void * arg)
|
|||||||
for(u32 x = 0; x < 400; x++) {
|
for(u32 x = 0; x < 400; x++) {
|
||||||
const u32 dstPos = ((((y >> 3) * (512 >> 3) + (x >> 3)) << 6) + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3)));
|
const u32 dstPos = ((((y >> 3) * (512 >> 3) + (x >> 3)) << 6) + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3)));
|
||||||
|
|
||||||
((u16 *)tex.data)[dstPos] = data->camera_buffer[srcPos + x];
|
((u16*)tex.data)[dstPos] = data->camera_buffer[srcPos + x];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data->any_update = false;
|
data->any_update = false;
|
||||||
@@ -201,7 +200,7 @@ static void update_ui(void * arg)
|
|||||||
C2D_DrawImageAt((C2D_Image){ &tex, &subt3x }, 0.0f, 0.0f, 0.4f, NULL, 1.0f, 1.0f);
|
C2D_DrawImageAt((C2D_Image){ &tex, &subt3x }, 0.0f, 0.0f, 0.4f, NULL, 1.0f, 1.0f);
|
||||||
|
|
||||||
set_screen(bottom);
|
set_screen(bottom);
|
||||||
draw_text_center(GFX_BOTTOM, 4, 0.5, 0.5, 0.5, colors[COLOR_WHITE_ACCENT], language.camera.quit);
|
draw_text_center(GFX_BOTTOM, 4, 0.5, 0.5, 0.5, colors[COLOR_WHITE], "Press \uE005 To Quit");
|
||||||
end_frame();
|
end_frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,11 +208,11 @@ static void update_ui(void * arg)
|
|||||||
LightEvent_Signal(&data->event_ui_info);
|
LightEvent_Signal(&data->event_ui_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool start_capture_cam(qr_data * data)
|
static bool start_capture_cam(qr_data *data)
|
||||||
{
|
{
|
||||||
if((data->cam_thread = threadCreate(capture_cam_thread, data, 0x10000, 0x1A, 1, false)) == NULL)
|
if((data->cam_thread = threadCreate(capture_cam_thread, data, 0x10000, 0x1A, 1, false)) == NULL)
|
||||||
{
|
{
|
||||||
throw_error(language.camera.thread_error, ERROR_LEVEL_ERROR);
|
throw_error("Capture cam thread creation failed\nPlease report this to the developers", ERROR_LEVEL_ERROR);
|
||||||
LightEvent_Signal(&data->event_cam_info);
|
LightEvent_Signal(&data->event_cam_info);
|
||||||
LightEvent_Signal(&data->event_ui_info);
|
LightEvent_Signal(&data->event_ui_info);
|
||||||
return false;
|
return false;
|
||||||
@@ -226,11 +225,11 @@ static bool start_capture_cam(qr_data * data)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool update_qr(qr_data * data, struct quirc_data * scan_data)
|
static bool update_qr(qr_data *data, struct quirc_data* scan_data)
|
||||||
{
|
{
|
||||||
int w;
|
int w;
|
||||||
int h;
|
int h;
|
||||||
u8 * image = (u8 *)quirc_begin(data->context, &w, &h);
|
u8 *image = (u8*) quirc_begin(data->context, &w, &h);
|
||||||
|
|
||||||
start_read(data);
|
start_read(data);
|
||||||
for (int y = 0; y < h; y++) {
|
for (int y = 0; y < h; y++) {
|
||||||
@@ -257,7 +256,7 @@ static bool update_qr(qr_data * data, struct quirc_data * scan_data)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void start_qr(qr_data * data)
|
static void start_qr(qr_data *data)
|
||||||
{
|
{
|
||||||
svcCreateEvent(&data->event_stop, RESET_STICKY);
|
svcCreateEvent(&data->event_stop, RESET_STICKY);
|
||||||
LightEvent_Init(&data->event_cam_info, RESET_STICKY);
|
LightEvent_Init(&data->event_cam_info, RESET_STICKY);
|
||||||
@@ -273,7 +272,7 @@ static void start_qr(qr_data * data)
|
|||||||
quirc_resize(data->context, 400, 240);
|
quirc_resize(data->context, 400, 240);
|
||||||
data->camera_buffer = calloc(1, 400 * 240 * sizeof(u16));
|
data->camera_buffer = calloc(1, 400 * 240 * sizeof(u16));
|
||||||
}
|
}
|
||||||
static void exit_qr(qr_data * data)
|
static void exit_qr(qr_data *data)
|
||||||
{
|
{
|
||||||
svcSignalEvent(data->event_stop);
|
svcSignalEvent(data->event_stop);
|
||||||
|
|
||||||
@@ -309,7 +308,7 @@ bool init_qr(void)
|
|||||||
|
|
||||||
start_qr(&data);
|
start_qr(&data);
|
||||||
|
|
||||||
struct quirc_data * scan_data = calloc(1, sizeof(struct quirc_data));
|
struct quirc_data* scan_data = calloc(1, sizeof(struct quirc_data));
|
||||||
const bool ready = start_capture_cam(&data);
|
const bool ready = start_capture_cam(&data);
|
||||||
bool finished = !ready;
|
bool finished = !ready;
|
||||||
|
|
||||||
@@ -334,8 +333,7 @@ bool init_qr(void)
|
|||||||
char * zip_buf = NULL;
|
char * zip_buf = NULL;
|
||||||
char * filename = NULL;
|
char * filename = NULL;
|
||||||
u32 zip_size;
|
u32 zip_size;
|
||||||
|
Result res = http_get((char*)scan_data->payload, &filename, &zip_buf, &zip_size, INSTALL_DOWNLOAD, "application/zip");
|
||||||
Result res = http_get((char*)scan_data->payload, &filename, &zip_buf, &zip_size, INSTALL_DOWNLOAD, "application/zip; application/x-zip-compressed");
|
|
||||||
if (R_FAILED(res))
|
if (R_FAILED(res))
|
||||||
{
|
{
|
||||||
free(filename);
|
free(filename);
|
||||||
@@ -352,7 +350,7 @@ bool init_qr(void)
|
|||||||
{
|
{
|
||||||
draw_install(INSTALL_CHECKING_DOWNLOAD);
|
draw_install(INSTALL_CHECKING_DOWNLOAD);
|
||||||
|
|
||||||
struct archive * a = archive_read_new();
|
struct archive *a = archive_read_new();
|
||||||
archive_read_support_format_zip(a);
|
archive_read_support_format_zip(a);
|
||||||
|
|
||||||
int r = archive_read_open_memory(a, zip_buf, zip_size);
|
int r = archive_read_open_memory(a, zip_buf, zip_size);
|
||||||
@@ -360,13 +358,13 @@ bool init_qr(void)
|
|||||||
|
|
||||||
if(r == ARCHIVE_OK)
|
if(r == ARCHIVE_OK)
|
||||||
{
|
{
|
||||||
RemoteMode mode = REMOTE_MODE_AMOUNT;
|
EntryMode mode = MODE_AMOUNT;
|
||||||
|
|
||||||
char * buf = NULL;
|
char * buf = NULL;
|
||||||
do {
|
do {
|
||||||
if(zip_memory_to_buf("body_LZ.bin", zip_buf, zip_size, &buf) != 0)
|
if(zip_memory_to_buf("body_LZ.bin", zip_buf, zip_size, &buf) != 0)
|
||||||
{
|
{
|
||||||
mode = REMOTE_MODE_THEMES;
|
mode = MODE_THEMES;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,7 +372,7 @@ bool init_qr(void)
|
|||||||
buf = NULL;
|
buf = NULL;
|
||||||
if(zip_memory_to_buf("splash.bin", zip_buf, zip_size, &buf) != 0)
|
if(zip_memory_to_buf("splash.bin", zip_buf, zip_size, &buf) != 0)
|
||||||
{
|
{
|
||||||
mode = REMOTE_MODE_SPLASHES;
|
mode = MODE_SPLASHES;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,7 +380,7 @@ bool init_qr(void)
|
|||||||
buf = NULL;
|
buf = NULL;
|
||||||
if(zip_memory_to_buf("splashbottom.bin", zip_buf, zip_size, &buf) != 0)
|
if(zip_memory_to_buf("splashbottom.bin", zip_buf, zip_size, &buf) != 0)
|
||||||
{
|
{
|
||||||
mode = REMOTE_MODE_SPLASHES;
|
mode = MODE_SPLASHES;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,33 +389,25 @@ bool init_qr(void)
|
|||||||
free(buf);
|
free(buf);
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
|
|
||||||
if(mode != REMOTE_MODE_AMOUNT)
|
if(mode != MODE_AMOUNT)
|
||||||
{
|
{
|
||||||
save_zip_to_sd(filename, zip_size, zip_buf, mode);
|
save_zip_to_sd(filename, zip_size, zip_buf, mode);
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool badge = draw_confirm_no_interface(language.camera.badge_question);
|
throw_error("Zip downloaded is neither\na splash nor a theme.", ERROR_LEVEL_WARNING);
|
||||||
if (badge)
|
|
||||||
{
|
|
||||||
save_zip_to_sd(filename, zip_size, zip_buf, REMOTE_MODE_BADGES);
|
|
||||||
// don't set success since we don't need to reload lists for badge zips
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
throw_error(language.camera.zip_not_theme_splash, ERROR_LEVEL_WARNING);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw_error(language.camera.file_not_zip, ERROR_LEVEL_WARNING);
|
throw_error("File downloaded isn't a zip.", ERROR_LEVEL_WARNING);
|
||||||
}
|
}
|
||||||
free(zip_buf);
|
free(zip_buf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw_error(language.camera.download_failed, ERROR_LEVEL_WARNING);
|
throw_error("Download failed.", ERROR_LEVEL_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(filename);
|
free(filename);
|
||||||
|
|||||||
@@ -30,13 +30,11 @@ Color colors[COLOR_AMOUNT] = {0};
|
|||||||
|
|
||||||
void init_colors(void)
|
void init_colors(void)
|
||||||
{
|
{
|
||||||
colors[COLOR_BACKGROUND] = config.background_color;
|
colors[COLOR_BACKGROUND] = C2D_Color32(35, 28, 32, 255); //silver-y black
|
||||||
colors[COLOR_ACCENT] = config.accent_color;
|
colors[COLOR_ACCENT] = C2D_Color32(12, 58, 111, 255);
|
||||||
colors[COLOR_WHITE_BACKGROUND] = config.white_color_background;
|
colors[COLOR_WHITE] = C2D_Color32(255, 255, 255, 255);
|
||||||
colors[COLOR_WHITE_ACCENT] = config.white_color_accent;
|
colors[COLOR_CURSOR] = C2D_Color32(200, 200, 200, 255);
|
||||||
colors[COLOR_CURSOR] = config.cursor_color;
|
colors[COLOR_BLACK] = C2D_Color32(0, 0, 0, 255);
|
||||||
colors[COLOR_BLACK] = config.black_color;
|
colors[COLOR_RED] = C2D_Color32(229, 66, 66, 255);
|
||||||
colors[COLOR_RED_BACKGROUND] = config.red_color_background;
|
colors[COLOR_YELLOW] = C2D_Color32(239, 220, 11, 255);
|
||||||
colors[COLOR_RED_ACCENT] = config.red_color_accent;
|
|
||||||
colors[COLOR_YELLOW] = config.yellow_color;
|
|
||||||
}
|
}
|
||||||
247
source/config.c
@@ -1,247 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Anemone3DS
|
|
||||||
* Copyright (C) 2016-2024 Contributors in CONTRIBUTORS.md
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
Config_s config;
|
|
||||||
|
|
||||||
void load_config(void)
|
|
||||||
{
|
|
||||||
Handle test_handle;
|
|
||||||
Result res;
|
|
||||||
memset(&config, 0, sizeof(Config_s));
|
|
||||||
char *json_buf = NULL;
|
|
||||||
u32 json_len = file_to_buf(fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE "/config.json"), ArchiveSD, &json_buf);
|
|
||||||
if (json_len)
|
|
||||||
{
|
|
||||||
json_error_t error;
|
|
||||||
json_t *root = json_loadb(json_buf, json_len, 0, &error);
|
|
||||||
if (root)
|
|
||||||
{
|
|
||||||
const char *key;
|
|
||||||
json_t *value;
|
|
||||||
json_object_foreach(root, key, value)
|
|
||||||
{
|
|
||||||
if (json_is_array(value) && !strcmp(key, "Accent Color") && json_array_size(value) == 4)
|
|
||||||
{
|
|
||||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
|
||||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
|
||||||
{
|
|
||||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
|
||||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
|
||||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
|
||||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
|
||||||
|
|
||||||
config.accent_color = C2D_Color32(r, g, b, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (json_is_array(value) && !strcmp(key, "Background Color") && json_array_size(value) == 4)
|
|
||||||
{
|
|
||||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
|
||||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
|
||||||
{
|
|
||||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
|
||||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
|
||||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
|
||||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
|
||||||
|
|
||||||
config.background_color = C2D_Color32(r, g, b, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (json_is_array(value) && !strcmp(key, "White Color Background") && json_array_size(value) == 4)
|
|
||||||
{
|
|
||||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
|
||||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
|
||||||
{
|
|
||||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
|
||||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
|
||||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
|
||||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
|
||||||
|
|
||||||
config.white_color_background = C2D_Color32(r, g, b, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (json_is_array(value) && !strcmp(key, "White Color Accent") && json_array_size(value) == 4)
|
|
||||||
{
|
|
||||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
|
||||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
|
||||||
{
|
|
||||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
|
||||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
|
||||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
|
||||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
|
||||||
|
|
||||||
config.white_color_accent = C2D_Color32(r, g, b, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (json_is_array(value) && !strcmp(key, "Cursor Color") && json_array_size(value) == 4)
|
|
||||||
{
|
|
||||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
|
||||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
|
||||||
{
|
|
||||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
|
||||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
|
||||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
|
||||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
|
||||||
|
|
||||||
config.cursor_color = C2D_Color32(r, g, b, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (json_is_array(value) && !strcmp(key, "Black Color") && json_array_size(value) == 4)
|
|
||||||
{
|
|
||||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
|
||||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
|
||||||
{
|
|
||||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
|
||||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
|
||||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
|
||||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
|
||||||
|
|
||||||
config.black_color = C2D_Color32(r, g, b, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (json_is_array(value) && !strcmp(key, "Red Color Background") && json_array_size(value) == 4)
|
|
||||||
{
|
|
||||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
|
||||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
|
||||||
{
|
|
||||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
|
||||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
|
||||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
|
||||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
|
||||||
|
|
||||||
config.red_color_background = C2D_Color32(r, g, b, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (json_is_array(value) && !strcmp(key, "Red Color Accent") && json_array_size(value) == 4)
|
|
||||||
{
|
|
||||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
|
||||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
|
||||||
{
|
|
||||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
|
||||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
|
||||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
|
||||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
|
||||||
|
|
||||||
config.red_color_accent = C2D_Color32(r, g, b, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (json_is_array(value) && !strcmp(key, "Yellow Color") && json_array_size(value) == 4)
|
|
||||||
{
|
|
||||||
if (json_is_integer(json_array_get(value, 0)) && json_is_integer(json_array_get(value, 1))
|
|
||||||
&& json_is_integer(json_array_get(value, 2)) && json_is_integer(json_array_get(value, 3)))
|
|
||||||
{
|
|
||||||
u8 r = min(255, json_integer_value(json_array_get(value, 0)));
|
|
||||||
u8 g = min(255, json_integer_value(json_array_get(value, 1)));
|
|
||||||
u8 b = min(255, json_integer_value(json_array_get(value, 2)));
|
|
||||||
u8 a = min(255, json_integer_value(json_array_get(value, 3)));
|
|
||||||
|
|
||||||
config.yellow_color = C2D_Color32(r, g, b, a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (json_is_string(value) && !strcmp(key, "Themes Path"))
|
|
||||||
{
|
|
||||||
bool need_slash = json_string_value(value)[strlen(json_string_value(value)) - 1] != '/';
|
|
||||||
char *theme_path = calloc(1, strlen(json_string_value(value)) + 1 + (need_slash ? 1 : 0));
|
|
||||||
memcpy(theme_path, json_string_value(value), strlen(json_string_value(value)));
|
|
||||||
if (need_slash) theme_path[strlen(json_string_value(value))] = '/';
|
|
||||||
if (R_SUCCEEDED(res = FSUSER_OpenDirectory(&test_handle, ArchiveSD, fsMakePath(PATH_ASCII, theme_path))))
|
|
||||||
{
|
|
||||||
main_paths[REMOTE_MODE_THEMES] = theme_path;
|
|
||||||
FSDIR_Close(test_handle);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
DEBUG("Failed test - reverting to default. Err 0x%08lx\n", res);
|
|
||||||
free(theme_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (json_is_string(value) && !strcmp(key, "Splashes Path"))
|
|
||||||
{
|
|
||||||
bool need_slash = json_string_value(value)[strlen(json_string_value(value)) - 1] != '/';
|
|
||||||
char *splash_path = calloc(1, strlen(json_string_value(value)) + 1 + (need_slash ? 1 : 0));
|
|
||||||
memcpy(splash_path, json_string_value(value), strlen(json_string_value(value)));
|
|
||||||
if (need_slash) splash_path[strlen(json_string_value(value))] = '/';
|
|
||||||
if (R_SUCCEEDED(res = FSUSER_OpenDirectory(&test_handle, ArchiveSD, fsMakePath(PATH_ASCII, splash_path))))
|
|
||||||
{
|
|
||||||
main_paths[REMOTE_MODE_SPLASHES] = splash_path;
|
|
||||||
FSDIR_Close(test_handle);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
DEBUG("Failed test - reverting to default. Err 0x%08lx\n", res);
|
|
||||||
free(splash_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (json_is_string(value) && !strcmp(key, "Badges Path"))
|
|
||||||
{
|
|
||||||
bool need_slash = json_string_value(value)[strlen(json_string_value(value)) - 1] != '/';
|
|
||||||
char *badge_path = calloc(1, strlen(json_string_value(value)) + 1 + (need_slash ? 1 : 0));
|
|
||||||
memcpy(badge_path, json_string_value(value), strlen(json_string_value(value)));
|
|
||||||
if (need_slash) badge_path[strlen(json_string_value(value))] = '/';
|
|
||||||
if (R_SUCCEEDED(res = FSUSER_OpenDirectory(&test_handle, ArchiveSD, fsMakePath(PATH_ASCII, badge_path))))
|
|
||||||
{
|
|
||||||
main_paths[REMOTE_MODE_BADGES] = badge_path;
|
|
||||||
FSDIR_Close(test_handle);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
DEBUG("Failed test - reverting to default. Err 0x%08lx\n", res);
|
|
||||||
free(badge_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
DEBUG(error.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (config.accent_color == 0)
|
|
||||||
config.accent_color = C2D_Color32(12, 58, 111, 255);
|
|
||||||
|
|
||||||
if (config.background_color == 0)
|
|
||||||
config.background_color = C2D_Color32(35, 28, 32, 255); //silver-y black
|
|
||||||
|
|
||||||
if (config.white_color_background == 0)
|
|
||||||
config.white_color_background = C2D_Color32(255, 255, 255, 255);
|
|
||||||
|
|
||||||
if (config.white_color_accent == 0)
|
|
||||||
config.white_color_accent = C2D_Color32(255, 255, 255, 255);
|
|
||||||
|
|
||||||
if (config.cursor_color == 0)
|
|
||||||
config.cursor_color = C2D_Color32(200, 200, 200, 255);
|
|
||||||
|
|
||||||
if (config.black_color == 0)
|
|
||||||
config.black_color = C2D_Color32(0, 0, 0, 255);
|
|
||||||
|
|
||||||
if (config.red_color_background == 0)
|
|
||||||
config.red_color_background = C2D_Color32(229, 66, 66, 255);
|
|
||||||
|
|
||||||
if (config.red_color_accent == 0)
|
|
||||||
config.red_color_accent = C2D_Color32(229, 66, 66, 255);
|
|
||||||
|
|
||||||
if (config.yellow_color == 0)
|
|
||||||
config.yellow_color = C2D_Color32(239, 220, 11, 255);
|
|
||||||
|
|
||||||
if (json_buf) free(json_buf);
|
|
||||||
}
|
|
||||||
@@ -1,318 +0,0 @@
|
|||||||
#include "conversion.h"
|
|
||||||
#include "draw.h"
|
|
||||||
|
|
||||||
#include <png.h>
|
|
||||||
|
|
||||||
// don't be fooled - this function always expects 64x64 input buffers. Width/height only
|
|
||||||
// control output resolution
|
|
||||||
int rgb565ToPngFile(char *filename, u16 *rgb_buf, u8 *alpha_buf, int width, int height)
|
|
||||||
{
|
|
||||||
FILE *fp = fopen(filename, "wb");
|
|
||||||
u8 *image = malloc(64 * 64 * 4);
|
|
||||||
if (!image) return -1;
|
|
||||||
|
|
||||||
int i, x, y, r, g, b, a;
|
|
||||||
|
|
||||||
for (i = 0; i < 64 * 64; ++i)
|
|
||||||
{
|
|
||||||
r = (rgb_buf[i] & 0xF800) >> 11;
|
|
||||||
g = (rgb_buf[i] & 0x07E0) >> 5;
|
|
||||||
b = (rgb_buf[i] & 0x001F);
|
|
||||||
a = (alpha_buf[i/2] >> (4*(i%2))) & 0x0F;
|
|
||||||
|
|
||||||
r = round(r * 255.0 / 31.0);
|
|
||||||
g = round(g * 255.0 / 63.0);
|
|
||||||
b = round(b * 255.0 / 31.0);
|
|
||||||
a = a * 0x11;
|
|
||||||
x = 8*((i/64)%8) + (((i%64)&0x01) >> 0) + (((i%64)&0x04) >> 1) + (((i%64)&0x10) >> 2);
|
|
||||||
y = 8*(i/512) + (((i%64)&0x02) >> 1) + (((i%64)&0x08) >> 2) + (((i%64)&0x20) >> 3);
|
|
||||||
image[y * 64 * 4 + x * 4 + 0] = r;
|
|
||||||
image[y * 64 * 4 + x * 4 + 1] = g;
|
|
||||||
image[y * 64 * 4 + x * 4 + 2] = b;
|
|
||||||
image[y * 64 * 4 + x * 4 + 3] = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
|
||||||
png_infop info = png_create_info_struct(png);
|
|
||||||
setjmp(png_jmpbuf(png));
|
|
||||||
png_init_io(png, fp);
|
|
||||||
png_set_IHDR(png, info, width, height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
|
||||||
png_write_info(png, info);
|
|
||||||
png_bytep row = malloc(4 * width * sizeof(png_byte));
|
|
||||||
for (y = 0; y < height; ++y)
|
|
||||||
{
|
|
||||||
for (x = 0; x < width; ++x)
|
|
||||||
{
|
|
||||||
row[x * 4 + 0] = image[(y * 64 + x) * 4 + 0];
|
|
||||||
row[x * 4 + 1] = image[(y * 64 + x) * 4 + 1];
|
|
||||||
row[x * 4 + 2] = image[(y * 64 + x) * 4 + 2];
|
|
||||||
row[x * 4 + 3] = image[(y * 64 + x) * 4 + 3];
|
|
||||||
}
|
|
||||||
|
|
||||||
png_write_row(png, row);
|
|
||||||
}
|
|
||||||
|
|
||||||
png_write_end(png, info);
|
|
||||||
png_free_data(png, info, PNG_FREE_ALL, -1);
|
|
||||||
png_destroy_write_struct(&png, NULL);
|
|
||||||
free(row);
|
|
||||||
free(image);
|
|
||||||
fflush(fp);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pngToRGB565(char *png_buf, u64 fileSize, u16 *rgb_buf_64x64, u8 *alpha_buf_64x64, u16 *rgb_buf_32x32, u8 *alpha_buf_32x32, bool set_icon)
|
|
||||||
{
|
|
||||||
if (png_buf == NULL) return 0;
|
|
||||||
if (fileSize < 8 || png_sig_cmp((png_bytep) png_buf, 0, 8))
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 *buf = (u32 *) png_buf;
|
|
||||||
FILE *fp = fmemopen(buf, fileSize, "rb");
|
|
||||||
png_bytep *row_pointers = NULL;
|
|
||||||
|
|
||||||
png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
|
||||||
png_infop info = png_create_info_struct(png);
|
|
||||||
|
|
||||||
png_init_io(png, fp);
|
|
||||||
png_read_info(png, info);
|
|
||||||
|
|
||||||
u32 width = png_get_image_width(png, info);
|
|
||||||
u32 height = png_get_image_height(png, info);
|
|
||||||
png_byte color_type = png_get_color_type(png, info);
|
|
||||||
png_byte bit_depth = png_get_bit_depth(png, info);
|
|
||||||
|
|
||||||
if (set_icon && (width != 48 || height != 48))
|
|
||||||
{
|
|
||||||
DEBUG("Invalid set icon?\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!set_icon && (width < 64 || height < 64 || width % 64 != 0 || height % 64 != 0 || width > 12 * 64 || height > 6 * 64))
|
|
||||||
{
|
|
||||||
DEBUG("Invalid png found...\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bit_depth == 16)
|
|
||||||
png_set_strip_16(png);
|
|
||||||
|
|
||||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
|
||||||
png_set_palette_to_rgb(png);
|
|
||||||
|
|
||||||
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
|
||||||
png_set_expand_gray_1_2_4_to_8(png);
|
|
||||||
|
|
||||||
if (png_get_valid(png, info, PNG_INFO_tRNS))
|
|
||||||
png_set_tRNS_to_alpha(png);
|
|
||||||
|
|
||||||
if (color_type == PNG_COLOR_TYPE_RGB ||
|
|
||||||
color_type == PNG_COLOR_TYPE_GRAY ||
|
|
||||||
color_type == PNG_COLOR_TYPE_PALETTE)
|
|
||||||
png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
|
|
||||||
|
|
||||||
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
|
||||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
|
||||||
png_set_gray_to_rgb(png);
|
|
||||||
|
|
||||||
png_read_update_info(png, info);
|
|
||||||
|
|
||||||
u32 x, y, r, g, b, a;
|
|
||||||
|
|
||||||
memset(alpha_buf_64x64, 0, 12*6*64*64/2);
|
|
||||||
memset(alpha_buf_32x32, 0, 12*6*32*32/2);
|
|
||||||
|
|
||||||
row_pointers = malloc(sizeof(png_bytep) * height);
|
|
||||||
for (y = 0; y < height; y++)
|
|
||||||
{
|
|
||||||
row_pointers[y] = (png_byte *) malloc(png_get_rowbytes(png, info));
|
|
||||||
}
|
|
||||||
|
|
||||||
png_read_image(png, row_pointers);
|
|
||||||
|
|
||||||
png_destroy_read_struct(&png, &info, NULL);
|
|
||||||
|
|
||||||
if (fp) fclose(fp);
|
|
||||||
for (y = 0; y < height; ++y)
|
|
||||||
{
|
|
||||||
png_bytep row = row_pointers[y];
|
|
||||||
for (x = 0; x < width; ++x)
|
|
||||||
{
|
|
||||||
png_bytep px = &(row[x * 4]);
|
|
||||||
r = px[0] >> 3;
|
|
||||||
g = px[1] >> 2;
|
|
||||||
b = px[2] >> 3;
|
|
||||||
a = px[3] >> 4;
|
|
||||||
|
|
||||||
// rgb565 conversion code adapted from GYTB
|
|
||||||
int rgb565_index = 8*64*((y/8)%8) | 64*((x/8)%8) | 32*((y/4)%2) | 16*((x/4)%2) | 8*((y/2)%2) | 4*((x/2)%2) | 2*(y%2) | (x%2);
|
|
||||||
rgb565_index |= 64*64*(height/64)*(x/64) + 64*64*(y/64); // account for multiple badges from 1 image
|
|
||||||
rgb_buf_64x64[rgb565_index] = (r << 11) | (g << 5) | b;
|
|
||||||
alpha_buf_64x64[rgb565_index / 2] |= a << (4 * (x % 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (y = 0; y < height; y += 2)
|
|
||||||
{
|
|
||||||
png_bytep row = row_pointers[y];
|
|
||||||
png_bytep nextrow = row_pointers[y+1];
|
|
||||||
for (x = 0; x < width; x += 2)
|
|
||||||
{
|
|
||||||
png_bytep px1 = &(row[x * 4]);
|
|
||||||
png_bytep px2 = &(nextrow[x * 4]);
|
|
||||||
png_bytep px3 = &(row[(x + 1) * 4]);
|
|
||||||
png_bytep px4 = &(nextrow[(x + 1) * 4]);
|
|
||||||
r = (px1[0] + px2[0] + px3[0] + px4[0]) >> 5;
|
|
||||||
g = (px1[1] + px2[1] + px3[1] + px4[1]) >> 4;
|
|
||||||
b = (px1[2] + px2[2] + px3[2] + px4[2]) >> 5;
|
|
||||||
a = (px1[3] + px2[3] + px3[3] + px4[3]) >> 6;
|
|
||||||
int x2 = x/2;
|
|
||||||
int y2 = y/2;
|
|
||||||
|
|
||||||
int rgb565_index = 4*64*((y2/8)%4) | 64*((x2/8)%4) | 32*((y2/4)%2) | 16*((x2/4)%2) | 8*((y2/2)%2) | 4*((x2/2)%2) | 2*(y2%2) | (x2%2);
|
|
||||||
rgb565_index |= 32*32*(height/64)*(x/64) + 32*32*(y/64);
|
|
||||||
|
|
||||||
rgb_buf_32x32[rgb565_index] = (r << 11) | (g << 5) | b;
|
|
||||||
alpha_buf_32x32[rgb565_index / 2] |= a << (4 * (x2%2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
|
||||||
{
|
|
||||||
free(row_pointers[y]);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(row_pointers);
|
|
||||||
if (!set_icon)
|
|
||||||
return (height/64)*(width/64);
|
|
||||||
else
|
|
||||||
return (height/48)*(width/48);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rotate_agbr_counterclockwise(char ** bufp, size_t size, size_t width)
|
|
||||||
{
|
|
||||||
uint32_t * buf = (uint32_t*)*bufp;
|
|
||||||
uint32_t * out = malloc(size);
|
|
||||||
|
|
||||||
size_t pixel_count = (size/4);
|
|
||||||
size_t height = pixel_count/width;
|
|
||||||
|
|
||||||
for (uint32_t h = 0; h < height; ++h)
|
|
||||||
{
|
|
||||||
for (uint32_t w = 0; w < width; ++w)
|
|
||||||
{
|
|
||||||
size_t buf_index = (w + (h * width));
|
|
||||||
size_t out_index = (height * (width-1)) - (height * w) + h;
|
|
||||||
|
|
||||||
out[out_index] = buf[buf_index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(*bufp);
|
|
||||||
*bufp = (char*)out;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t bin_to_abgr(char ** bufp, size_t size)
|
|
||||||
{
|
|
||||||
size_t out_size = (size / 3) * 4;
|
|
||||||
char* buf = malloc(out_size);
|
|
||||||
|
|
||||||
for (size_t i = 0, j = 0; i < size; i+=3, j+=4)
|
|
||||||
{
|
|
||||||
(buf+j)[0] = 0xFF; // A
|
|
||||||
(buf+j)[1] = (*bufp+i)[0]; // B
|
|
||||||
(buf+j)[2] = (*bufp+i)[1]; // G
|
|
||||||
(buf+j)[3] = (*bufp+i)[2]; // R
|
|
||||||
}
|
|
||||||
free(*bufp);
|
|
||||||
*bufp = buf;
|
|
||||||
|
|
||||||
// splash screens contain the raw framebuffer to put on the screen
|
|
||||||
// because the screens are mounted at a 90 degree angle we also need to rotate
|
|
||||||
// the output
|
|
||||||
rotate_agbr_counterclockwise(bufp, out_size, 240);
|
|
||||||
|
|
||||||
return out_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t png_to_abgr(char ** bufp, size_t size, u32 *height)
|
|
||||||
{
|
|
||||||
size_t out_size = 0;
|
|
||||||
if(size < 8 || png_sig_cmp((png_bytep)*bufp, 0, 8))
|
|
||||||
{
|
|
||||||
throw_error("Invalid preview.png", ERROR_LEVEL_WARNING);
|
|
||||||
return out_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t * buf = (uint32_t*)*bufp;
|
|
||||||
|
|
||||||
FILE * fp = fmemopen(buf, size, "rb");;
|
|
||||||
png_bytep * row_pointers = NULL;
|
|
||||||
|
|
||||||
png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
|
||||||
png_infop info = png_create_info_struct(png);
|
|
||||||
|
|
||||||
png_init_io(png, fp);
|
|
||||||
png_read_info(png, info);
|
|
||||||
|
|
||||||
u32 width = png_get_image_width(png, info);
|
|
||||||
*height = png_get_image_height(png, info);
|
|
||||||
|
|
||||||
png_byte color_type = png_get_color_type(png, info);
|
|
||||||
png_byte bit_depth = png_get_bit_depth(png, info);
|
|
||||||
|
|
||||||
// Read any color_type into 8bit depth, ABGR format.
|
|
||||||
// See http://www.libpng.org/pub/png/libpng-manual.txt
|
|
||||||
|
|
||||||
if(bit_depth == 16)
|
|
||||||
png_set_strip_16(png);
|
|
||||||
|
|
||||||
if(color_type == PNG_COLOR_TYPE_PALETTE)
|
|
||||||
png_set_palette_to_rgb(png);
|
|
||||||
|
|
||||||
// PNG_COLOR_TYPE_GRAY_ALPHA is always 8 or 16bit depth.
|
|
||||||
if(color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
|
||||||
png_set_expand_gray_1_2_4_to_8(png);
|
|
||||||
|
|
||||||
if(png_get_valid(png, info, PNG_INFO_tRNS))
|
|
||||||
png_set_tRNS_to_alpha(png);
|
|
||||||
|
|
||||||
// These color_type don't have an alpha channel then fill it with 0xff.
|
|
||||||
if(color_type == PNG_COLOR_TYPE_RGB ||
|
|
||||||
color_type == PNG_COLOR_TYPE_GRAY ||
|
|
||||||
color_type == PNG_COLOR_TYPE_PALETTE)
|
|
||||||
png_set_add_alpha(png, 0xFF, PNG_FILLER_BEFORE);
|
|
||||||
|
|
||||||
if(color_type == PNG_COLOR_TYPE_GRAY ||
|
|
||||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
|
||||||
png_set_gray_to_rgb(png);
|
|
||||||
|
|
||||||
//output ABGR
|
|
||||||
png_set_bgr(png);
|
|
||||||
png_set_swap_alpha(png);
|
|
||||||
|
|
||||||
png_read_update_info(png, info);
|
|
||||||
|
|
||||||
row_pointers = malloc(sizeof(png_bytep) * *height);
|
|
||||||
out_size = sizeof(u32) * (width * *height);
|
|
||||||
u32 * out = malloc(out_size);
|
|
||||||
for(u32 y = 0; y < *height; y++)
|
|
||||||
{
|
|
||||||
row_pointers[y] = (png_bytep)(out + (width * y));
|
|
||||||
}
|
|
||||||
|
|
||||||
png_read_image(png, row_pointers);
|
|
||||||
|
|
||||||
png_destroy_read_struct(&png, &info, NULL);
|
|
||||||
|
|
||||||
if (fp) fclose(fp);
|
|
||||||
if (row_pointers) free(row_pointers);
|
|
||||||
|
|
||||||
free(*bufp);
|
|
||||||
*bufp = (char*)out;
|
|
||||||
|
|
||||||
return out_size;
|
|
||||||
}
|
|
||||||
339
source/draw.c
@@ -27,14 +27,13 @@
|
|||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
#include "ui_strings.h"
|
|
||||||
|
|
||||||
#include "sprites.h"
|
#include "sprites.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
C3D_RenderTarget * top;
|
C3D_RenderTarget* top;
|
||||||
C3D_RenderTarget * bottom;
|
C3D_RenderTarget* bottom;
|
||||||
C2D_TextBuf staticBuf, dynamicBuf;
|
C2D_TextBuf staticBuf, dynamicBuf;
|
||||||
static C2D_TextBuf widthBuf;
|
static C2D_TextBuf widthBuf;
|
||||||
|
|
||||||
@@ -47,12 +46,6 @@ static const char * mode_switch_char[MODE_AMOUNT] = {
|
|||||||
"T",
|
"T",
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *remote_mode_switch_char[REMOTE_MODE_AMOUNT] = {
|
|
||||||
"T",
|
|
||||||
"S",
|
|
||||||
"B",
|
|
||||||
};
|
|
||||||
|
|
||||||
void init_screens(void)
|
void init_screens(void)
|
||||||
{
|
{
|
||||||
init_colors();
|
init_colors();
|
||||||
@@ -84,60 +77,56 @@ void init_screens(void)
|
|||||||
|
|
||||||
C2D_TextParse(&text[TEXT_VERSION], staticBuf, VERSION);
|
C2D_TextParse(&text[TEXT_VERSION], staticBuf, VERSION);
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_THEME_MODE], staticBuf, language.draw.theme_mode);
|
C2D_TextParse(&text[TEXT_THEME_MODE], staticBuf, "Theme mode");
|
||||||
C2D_TextParse(&text[TEXT_SPLASH_MODE], staticBuf, language.draw.splash_mode);
|
C2D_TextParse(&text[TEXT_SPLASH_MODE], staticBuf, "Splash mode");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_NO_THEME_FOUND], staticBuf, language.draw.no_themes);
|
C2D_TextParse(&text[TEXT_NO_THEME_FOUND], staticBuf, "No theme found");
|
||||||
C2D_TextParse(&text[TEXT_NO_SPLASH_FOUND], staticBuf, language.draw.no_splashes);
|
C2D_TextParse(&text[TEXT_NO_SPLASH_FOUND], staticBuf, "No splash found");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_DOWNLOAD_FROM_QR], staticBuf, language.draw.qr_download);
|
C2D_TextParse(&text[TEXT_DOWNLOAD_FROM_QR], staticBuf, "Press \uE005 to download from QR");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_SWITCH_TO_SPLASHES], staticBuf, language.draw.switch_splashes);
|
C2D_TextParse(&text[TEXT_SWITCH_TO_SPLASHES], staticBuf, "Or \uE004 to switch to splashes");
|
||||||
C2D_TextParse(&text[TEXT_SWITCH_TO_THEMES], staticBuf, language.draw.switch_themes);
|
C2D_TextParse(&text[TEXT_SWITCH_TO_THEMES], staticBuf, "Or \uE004 to switch to themes");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_OR_START_TO_QUIT], staticBuf, language.draw.quit);
|
C2D_TextParse(&text[TEXT_OR_START_TO_QUIT], staticBuf, "Or to quit");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_BY_AUTHOR], staticBuf, language.draw.by);
|
C2D_TextParse(&text[TEXT_BY_AUTHOR], staticBuf, "By ");
|
||||||
C2D_TextParse(&text[TEXT_SELECTED], staticBuf, language.draw.selected);
|
C2D_TextParse(&text[TEXT_SELECTED], staticBuf, "Selected:");
|
||||||
C2D_TextParse(&text[TEXT_SELECTED_SHORT], staticBuf, language.draw.sel);
|
C2D_TextParse(&text[TEXT_SELECTED_SHORT], staticBuf, "Sel.:");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_THEMEPLAZA_THEME_MODE], staticBuf, language.draw.tp_theme_mode);
|
C2D_TextParse(&text[TEXT_THEMEPLAZA_THEME_MODE], staticBuf, "ThemePlaza Theme mode");
|
||||||
C2D_TextParse(&text[TEXT_THEMEPLAZA_SPLASH_MODE], staticBuf, language.draw.tp_splash_mode);
|
C2D_TextParse(&text[TEXT_THEMEPLAZA_SPLASH_MODE], staticBuf, "ThemePlaza Splash mode");
|
||||||
C2D_TextParse(&text[TEXT_THEMEPLAZA_BADGE_MODE], staticBuf, language.draw.tp_badge_mode);
|
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_SEARCH], staticBuf, language.draw.search);
|
C2D_TextParse(&text[TEXT_SEARCH], staticBuf, "Search...");
|
||||||
C2D_TextParse(&text[TEXT_PAGE], staticBuf, language.draw.page);
|
C2D_TextParse(&text[TEXT_PAGE], staticBuf, "Page:");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_ERROR_QUIT], staticBuf, language.draw.err_quit);
|
C2D_TextParse(&text[TEXT_ERROR_QUIT], staticBuf, "Press \uE000 to quit.");
|
||||||
C2D_TextParse(&text[TEXT_ERROR_CONTINUE], staticBuf, language.draw.warn_continue);
|
C2D_TextParse(&text[TEXT_ERROR_CONTINUE], staticBuf, "Press \uE000 to continue.");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_CONFIRM_YES_NO], staticBuf, language.draw.yes_no);
|
C2D_TextParse(&text[TEXT_CONFIRM_YES_NO], staticBuf, "\uE000 Yes \uE001 No");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_LOADING_THEMES], staticBuf, language.draw.load_themes);
|
C2D_TextParse(&text[TEXT_INSTALL_LOADING_THEMES], staticBuf, "Loading themes, please wait...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_LOADING_SPLASHES], staticBuf, language.draw.load_splash);
|
C2D_TextParse(&text[TEXT_INSTALL_LOADING_SPLASHES], staticBuf, "Loading splashes, please wait...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_LOADING_ICONS], staticBuf, language.draw.load_icons);
|
C2D_TextParse(&text[TEXT_INSTALL_LOADING_ICONS], staticBuf, "Loading icons, please wait...");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_SPLASH], staticBuf, language.draw.install_splash);
|
C2D_TextParse(&text[TEXT_INSTALL_SPLASH], staticBuf, "Installing a splash...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_SPLASH_DELETE], staticBuf, language.draw.delete_splash);
|
C2D_TextParse(&text[TEXT_INSTALL_SPLASH_DELETE], staticBuf, "Deleting installed splash...");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_SINGLE], staticBuf, language.draw.install_theme);
|
C2D_TextParse(&text[TEXT_INSTALL_SINGLE], staticBuf, "Installing a single theme...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_SHUFFLE], staticBuf, language.draw.install_shuffle);
|
C2D_TextParse(&text[TEXT_INSTALL_SHUFFLE], staticBuf, "Installing shuffle themes...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_BGM], staticBuf, language.draw.install_bgm);
|
C2D_TextParse(&text[TEXT_INSTALL_BGM], staticBuf, "Installing BGM-only theme...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_NO_BGM], staticBuf, language.draw.install_no_bgm);
|
C2D_TextParse(&text[TEXT_INSTALL_NO_BGM], staticBuf, "Installing theme without BGM...");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_DOWNLOAD], staticBuf, language.draw.downloading);
|
C2D_TextParse(&text[TEXT_INSTALL_DOWNLOAD], staticBuf, "Downloading...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_CHECKING_DOWNLOAD], staticBuf, language.draw.checking_dl);
|
C2D_TextParse(&text[TEXT_INSTALL_CHECKING_DOWNLOAD], staticBuf, "Checking downloaded file...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_ENTRY_DELETE], staticBuf, language.draw.delete_sd);
|
C2D_TextParse(&text[TEXT_INSTALL_ENTRY_DELETE], staticBuf, "Deleting from SD...");
|
||||||
|
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_LOADING_REMOTE_THEMES], staticBuf, language.draw.download_themes);
|
C2D_TextParse(&text[TEXT_INSTALL_LOADING_REMOTE_THEMES], staticBuf, "Downloading theme list, please wait...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_LOADING_REMOTE_SPLASHES], staticBuf, language.draw.download_splashes);
|
C2D_TextParse(&text[TEXT_INSTALL_LOADING_REMOTE_SPLASHES], staticBuf, "Downloading splash list, please wait...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_LOADING_REMOTE_BADGES], staticBuf, language.draw.download_badges);
|
C2D_TextParse(&text[TEXT_INSTALL_LOADING_REMOTE_PREVIEW], staticBuf, "Downloading preview, please wait...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_LOADING_REMOTE_PREVIEW], staticBuf, language.draw.download_preview);
|
C2D_TextParse(&text[TEXT_INSTALL_LOADING_REMOTE_BGM], staticBuf, "Downloading BGM, please wait...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_LOADING_REMOTE_BGM], staticBuf, language.draw.download_bgm);
|
C2D_TextParse(&text[TEXT_INSTALL_DUMPING_THEME], staticBuf, "Dumping theme, please wait...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_DUMPING_THEME], staticBuf, language.draw.dump_single);
|
C2D_TextParse(&text[TEXT_INSTALL_DUMPING_ALL_THEMES], staticBuf, "Dumping official themes, please wait...");
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_DUMPING_ALL_THEMES], staticBuf, language.draw.dump_all_official);
|
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_DUMPING_BADGES], staticBuf, language.draw.dump_badges);
|
|
||||||
C2D_TextParse(&text[TEXT_INSTALL_BADGES], staticBuf, language.draw.install_badges);
|
|
||||||
|
|
||||||
for(int i = 0; i < TEXT_AMOUNT; i++)
|
for(int i = 0; i < TEXT_AMOUNT; i++)
|
||||||
C2D_TextOptimize(&text[i]);
|
C2D_TextOptimize(&text[i]);
|
||||||
@@ -173,25 +162,11 @@ void end_frame(void)
|
|||||||
C3D_FrameEnd(0);
|
C3D_FrameEnd(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_image_tint(int image_id, float x, float y, C2D_ImageTint tint)
|
|
||||||
{
|
|
||||||
C2D_DrawImageAt(C2D_SpriteSheetGetImage(spritesheet, image_id), x, y, 0.6f, &tint, 1.0f, 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void draw_image(int image_id, float x, float y)
|
static void draw_image(int image_id, float x, float y)
|
||||||
{
|
{
|
||||||
C2D_DrawImageAt(C2D_SpriteSheetGetImage(spritesheet, image_id), x, y, 0.6f, NULL, 1.0f, 1.0f);
|
C2D_DrawImageAt(C2D_SpriteSheetGetImage(spritesheet, image_id), x, y, 0.6f, NULL, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_home(u64 start_time, u64 cur_time)
|
|
||||||
{
|
|
||||||
float time_sec = (cur_time - start_time)/1000.0f;
|
|
||||||
float alpha = fmin(-1.333f * time_sec * time_sec + 2.666f * time_sec, 1.0f); // Quadratic regression to create fade effect
|
|
||||||
C2D_ImageTint tint = {};
|
|
||||||
C2D_AlphaImageTint(&tint, alpha);
|
|
||||||
C2D_DrawImageAt(C2D_SpriteSheetGetImage(spritesheet, sprites_no_home_idx), (320-64)/2, (240-64)/2, 1.0f, &tint, 1.0f, 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void get_text_dimensions(const char * text, float scaleX, float scaleY, float * width, float * height)
|
static void get_text_dimensions(const char * text, float scaleX, float scaleY, float * width, float * height)
|
||||||
{
|
{
|
||||||
C2D_Text c2d_text;
|
C2D_Text c2d_text;
|
||||||
@@ -276,10 +251,10 @@ void draw_base_interface(void)
|
|||||||
C2D_TextParse(&minutes, dynamicBuf, string_minutes);
|
C2D_TextParse(&minutes, dynamicBuf, string_minutes);
|
||||||
C2D_TextOptimize(&minutes);
|
C2D_TextOptimize(&minutes);
|
||||||
|
|
||||||
C2D_DrawText(&hours, C2D_WithColor, 7, 2, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE_ACCENT]);
|
C2D_DrawText(&hours, C2D_WithColor, 7, 2, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE]);
|
||||||
if(tm.tm_sec % 2 == 1)
|
if(tm.tm_sec % 2 == 1)
|
||||||
C2D_DrawText(&separator, C2D_WithColor, 28, 1, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE_ACCENT]);
|
C2D_DrawText(&separator, C2D_WithColor, 28, 1, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE]);
|
||||||
C2D_DrawText(&minutes, C2D_WithColor, 34, 2, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE_ACCENT]);
|
C2D_DrawText(&minutes, C2D_WithColor, 34, 2, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE]);
|
||||||
|
|
||||||
#ifndef CITRA_MODE
|
#ifndef CITRA_MODE
|
||||||
u8 battery_charging = 0;
|
u8 battery_charging = 0;
|
||||||
@@ -296,21 +271,21 @@ void draw_base_interface(void)
|
|||||||
|
|
||||||
C2D_DrawRectSolid(0, 0, 0.5f, 320, 24, colors[COLOR_ACCENT]);
|
C2D_DrawRectSolid(0, 0, 0.5f, 320, 24, colors[COLOR_ACCENT]);
|
||||||
C2D_DrawRectSolid(0, 216, 0.5f, 320, 24, colors[COLOR_ACCENT]);
|
C2D_DrawRectSolid(0, 216, 0.5f, 320, 24, colors[COLOR_ACCENT]);
|
||||||
C2D_DrawText(&text[TEXT_VERSION], C2D_WithColor, 7, 219, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE_ACCENT]);
|
C2D_DrawText(&text[TEXT_VERSION], C2D_WithColor, 7, 219, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE]);
|
||||||
|
|
||||||
set_screen(top);
|
set_screen(top);
|
||||||
}
|
}
|
||||||
|
|
||||||
void throw_error(const char * error, ErrorLevel level)
|
void throw_error(const char* error, ErrorLevel level)
|
||||||
{
|
{
|
||||||
Text bottom_text = TEXT_AMOUNT;
|
Text bottom_text = TEXT_AMOUNT;
|
||||||
Color text_color = COLOR_WHITE_BACKGROUND;
|
Color text_color = COLOR_WHITE;
|
||||||
|
|
||||||
switch(level)
|
switch(level)
|
||||||
{
|
{
|
||||||
case ERROR_LEVEL_ERROR:
|
case ERROR_LEVEL_ERROR:
|
||||||
bottom_text = TEXT_ERROR_QUIT;
|
bottom_text = TEXT_ERROR_QUIT;
|
||||||
text_color = COLOR_RED_BACKGROUND;
|
text_color = COLOR_RED;
|
||||||
break;
|
break;
|
||||||
case ERROR_LEVEL_WARNING:
|
case ERROR_LEVEL_WARNING:
|
||||||
bottom_text = TEXT_ERROR_CONTINUE;
|
bottom_text = TEXT_ERROR_CONTINUE;
|
||||||
@@ -327,22 +302,22 @@ void throw_error(const char * error, ErrorLevel level)
|
|||||||
|
|
||||||
draw_base_interface();
|
draw_base_interface();
|
||||||
draw_text_center(GFX_TOP, 100, 0.5f, 0.6f, 0.6f, colors[text_color], error);
|
draw_text_center(GFX_TOP, 100, 0.5f, 0.6f, 0.6f, colors[text_color], error);
|
||||||
draw_c2d_text_center(GFX_TOP, 170, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE_BACKGROUND], &text[bottom_text]);
|
draw_c2d_text_center(GFX_TOP, 170, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE], &text[bottom_text]);
|
||||||
end_frame();
|
end_frame();
|
||||||
|
|
||||||
if(kDown & KEY_A) break;
|
if(kDown & KEY_A) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool draw_confirm(const char * conf_msg, Entry_List_s * list, DrawMode draw_mode)
|
bool draw_confirm(const char* conf_msg, Entry_List_s* list)
|
||||||
{
|
{
|
||||||
while(aptMainLoop())
|
while(aptMainLoop())
|
||||||
{
|
{
|
||||||
Instructions_s instructions = {0};
|
Instructions_s instructions = {0};
|
||||||
draw_interface(list, instructions, draw_mode);
|
draw_interface(list, instructions);
|
||||||
set_screen(top);
|
set_screen(top);
|
||||||
draw_text_center(GFX_TOP, BUTTONS_Y_LINE_1, 0.5f, 0.7f, 0.7f, colors[COLOR_YELLOW], conf_msg);
|
draw_text_center(GFX_TOP, BUTTONS_Y_LINE_1, 0.5f, 0.7f, 0.7f, colors[COLOR_YELLOW], conf_msg);
|
||||||
draw_c2d_text_center(GFX_TOP, BUTTONS_Y_LINE_3, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE_BACKGROUND], &text[TEXT_CONFIRM_YES_NO]);
|
draw_c2d_text_center(GFX_TOP, BUTTONS_Y_LINE_3, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE], &text[TEXT_CONFIRM_YES_NO]);
|
||||||
end_frame();
|
end_frame();
|
||||||
|
|
||||||
hidScanInput();
|
hidScanInput();
|
||||||
@@ -354,31 +329,13 @@ bool draw_confirm(const char * conf_msg, Entry_List_s * list, DrawMode draw_mode
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool draw_confirm_no_interface(const char *conf_msg)
|
void draw_preview(C2D_Image preview, int preview_offset)
|
||||||
{
|
|
||||||
while(aptMainLoop())
|
|
||||||
{
|
|
||||||
draw_base_interface();
|
|
||||||
draw_text_center(GFX_TOP, 100, 0.5f, 0.7f, 0.7f, colors[COLOR_YELLOW], conf_msg);
|
|
||||||
draw_c2d_text_center(GFX_TOP, 170, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE_BACKGROUND], &text[TEXT_CONFIRM_YES_NO]);
|
|
||||||
end_frame();
|
|
||||||
|
|
||||||
hidScanInput();
|
|
||||||
u32 kDown = hidKeysDown();
|
|
||||||
if(kDown & KEY_A) return true;
|
|
||||||
if(kDown & KEY_B) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw_preview(C2D_Image preview, int preview_offset, float preview_scale)
|
|
||||||
{
|
{
|
||||||
start_frame();
|
start_frame();
|
||||||
set_screen(top);
|
set_screen(top);
|
||||||
C2D_DrawImageAt(preview, -preview_offset, 0, 0.5f, NULL, preview_scale, preview_scale);
|
C2D_DrawImageAt(preview, -preview_offset, 0, 0.5f, NULL, 1.0f, 1.0f);
|
||||||
set_screen(bottom);
|
set_screen(bottom);
|
||||||
C2D_DrawImageAt(preview, -(preview_offset+40), -240, 0.5f, NULL, preview_scale, preview_scale);
|
C2D_DrawImageAt(preview, -(preview_offset+40), -240, 0.5f, NULL, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_install_handler(InstallType type)
|
static void draw_install_handler(InstallType type)
|
||||||
@@ -386,7 +343,7 @@ static void draw_install_handler(InstallType type)
|
|||||||
if(type != INSTALL_NONE)
|
if(type != INSTALL_NONE)
|
||||||
{
|
{
|
||||||
C2D_Text * install_text = &text[type];
|
C2D_Text * install_text = &text[type];
|
||||||
draw_c2d_text_center(GFX_TOP, 120.0f, 0.5f, 0.8f, 0.8f, colors[COLOR_WHITE_BACKGROUND], install_text);
|
draw_c2d_text_center(GFX_TOP, 120.0f, 0.5f, 0.8f, 0.8f, colors[COLOR_WHITE], install_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +359,7 @@ void draw_loading_bar(u32 current, u32 max, InstallType type)
|
|||||||
draw_base_interface();
|
draw_base_interface();
|
||||||
draw_install_handler(type);
|
draw_install_handler(type);
|
||||||
set_screen(bottom);
|
set_screen(bottom);
|
||||||
double percent = 100 * ((double)current / (double)max);
|
double percent = 100*((double)current/(double)max);
|
||||||
u32 width = (u32)percent;
|
u32 width = (u32)percent;
|
||||||
width *= 2;
|
width *= 2;
|
||||||
C2D_DrawRectSolid(60-1, 110-1, 0.5f, 200+2, 20+2, colors[COLOR_CURSOR]);
|
C2D_DrawRectSolid(60-1, 110-1, 0.5f, 200+2, 20+2, colors[COLOR_CURSOR]);
|
||||||
@@ -413,7 +370,7 @@ void draw_loading_bar(u32 current, u32 max, InstallType type)
|
|||||||
static void draw_instructions(Instructions_s instructions)
|
static void draw_instructions(Instructions_s instructions)
|
||||||
{
|
{
|
||||||
if(instructions.info_line != NULL)
|
if(instructions.info_line != NULL)
|
||||||
draw_text_center(GFX_TOP, BUTTONS_Y_INFO, 0.5, 0.55, 0.55, colors[COLOR_WHITE_BACKGROUND], instructions.info_line);
|
draw_text_center(GFX_TOP, BUTTONS_Y_INFO, 0.5, 0.55, 0.55, colors[COLOR_WHITE], instructions.info_line);
|
||||||
|
|
||||||
const int y_lines[BUTTONS_INFO_LINES-1] = {
|
const int y_lines[BUTTONS_INFO_LINES-1] = {
|
||||||
BUTTONS_Y_LINE_1,
|
BUTTONS_Y_LINE_1,
|
||||||
@@ -424,20 +381,20 @@ static void draw_instructions(Instructions_s instructions)
|
|||||||
for(int i = 0; i < BUTTONS_INFO_LINES-1; i++)
|
for(int i = 0; i < BUTTONS_INFO_LINES-1; i++)
|
||||||
{
|
{
|
||||||
if(instructions.instructions[i][0] != NULL)
|
if(instructions.instructions[i][0] != NULL)
|
||||||
draw_text_wrap_scaled(BUTTONS_X_LEFT, y_lines[i], 0.5, colors[COLOR_WHITE_BACKGROUND], instructions.instructions[i][0], 0.6, 0, BUTTONS_X_RIGHT-2);
|
draw_text_wrap_scaled(BUTTONS_X_LEFT, y_lines[i], 0.5, colors[COLOR_WHITE], instructions.instructions[i][0], 0.6, 0, BUTTONS_X_RIGHT-2);
|
||||||
if(instructions.instructions[i][1] != NULL)
|
if(instructions.instructions[i][1] != NULL)
|
||||||
draw_text_wrap_scaled(BUTTONS_X_RIGHT, y_lines[i], 0.5, colors[COLOR_WHITE_BACKGROUND], instructions.instructions[i][1], 0.6, 0, BUTTONS_X_MAX-2);
|
draw_text_wrap_scaled(BUTTONS_X_RIGHT, y_lines[i], 0.5, colors[COLOR_WHITE], instructions.instructions[i][1], 0.6, 0, BUTTONS_X_MAX-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
C2D_ImageTint white_tint;
|
C2D_ImageTint white_tint;
|
||||||
C2D_PlainImageTint(&white_tint, colors[COLOR_WHITE_BACKGROUND], 1.0f);
|
C2D_PlainImageTint(&white_tint, colors[COLOR_WHITE], 1.0f);
|
||||||
|
|
||||||
const char * start_line = instructions.instructions[BUTTONS_INFO_LINES-1][0];
|
const char * start_line = instructions.instructions[BUTTONS_INFO_LINES-1][0];
|
||||||
if(start_line != NULL)
|
if(start_line != NULL)
|
||||||
{
|
{
|
||||||
C2D_SpriteSetPos(&sprite_start, BUTTONS_X_LEFT-10, BUTTONS_Y_LINE_4 + 3);
|
C2D_SpriteSetPos(&sprite_start, BUTTONS_X_LEFT-10, BUTTONS_Y_LINE_4 + 3);
|
||||||
C2D_DrawSpriteTinted(&sprite_start, &white_tint);
|
C2D_DrawSpriteTinted(&sprite_start, &white_tint);
|
||||||
draw_text_wrap_scaled(BUTTONS_X_LEFT+26, BUTTONS_Y_LINE_4, 0.5, colors[COLOR_WHITE_BACKGROUND], start_line, 0.6, 0, BUTTONS_X_RIGHT-2);
|
draw_text_wrap_scaled(BUTTONS_X_LEFT+26, BUTTONS_Y_LINE_4, 0.5, colors[COLOR_WHITE], start_line, 0.6, 0, BUTTONS_X_RIGHT-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * select_line = instructions.instructions[BUTTONS_INFO_LINES-1][1];
|
const char * select_line = instructions.instructions[BUTTONS_INFO_LINES-1][1];
|
||||||
@@ -445,7 +402,7 @@ static void draw_instructions(Instructions_s instructions)
|
|||||||
{
|
{
|
||||||
C2D_SpriteSetPos(&sprite_select, BUTTONS_X_RIGHT-10, BUTTONS_Y_LINE_4 + 3);
|
C2D_SpriteSetPos(&sprite_select, BUTTONS_X_RIGHT-10, BUTTONS_Y_LINE_4 + 3);
|
||||||
C2D_DrawSpriteTinted(&sprite_select, &white_tint);
|
C2D_DrawSpriteTinted(&sprite_select, &white_tint);
|
||||||
draw_text_wrap_scaled(BUTTONS_X_RIGHT+26, BUTTONS_Y_LINE_4, 0.5, colors[COLOR_WHITE_BACKGROUND], select_line, 0.6, 0, BUTTONS_X_MAX-2);
|
draw_text_wrap_scaled(BUTTONS_X_RIGHT+26, BUTTONS_Y_LINE_4, 0.5, colors[COLOR_WHITE], select_line, 0.6, 0, BUTTONS_X_MAX-2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,13 +433,13 @@ void draw_text_wrap(float x, float y, float z, float scaleX, float scaleY, Color
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((consumed = decode_utf8(&codepoint, (unsigned char *)text)) == -1)
|
if((consumed = decode_utf8(&codepoint, (unsigned char*)text)) == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
float character_width = scaleX * (fontGetCharWidthInfo(NULL, fontGlyphIndexFromCodePoint(NULL, codepoint))->charWidth);
|
float character_width = scaleX * (fontGetCharWidthInfo(NULL, fontGlyphIndexFromCodePoint(NULL, codepoint))->charWidth);
|
||||||
if((current_width += character_width) > max_width)
|
if((current_width += character_width) > max_width)
|
||||||
{
|
{
|
||||||
char * last_space = NULL;
|
char* last_space = NULL;
|
||||||
for(int i = idx; i >= 0; i--)
|
for(int i = idx; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if(result[i] == ' ')
|
if(result[i] == ' ')
|
||||||
@@ -532,33 +489,32 @@ void draw_text_wrap_scaled(float x, float y, float z, Color color, const char *
|
|||||||
static void draw_entry_info(Entry_s * entry)
|
static void draw_entry_info(Entry_s * entry)
|
||||||
{
|
{
|
||||||
char author[0x41] = {0};
|
char author[0x41] = {0};
|
||||||
utf16_to_utf8((u8 *)author, entry->author, 0x40);
|
utf16_to_utf8((u8*)author, entry->author, 0x40);
|
||||||
draw_c2d_text(20, 35, 0.5, 0.5, 0.5, colors[COLOR_WHITE_BACKGROUND], &text[TEXT_BY_AUTHOR]);
|
draw_c2d_text(20, 35, 0.5, 0.5, 0.5, colors[COLOR_WHITE], &text[TEXT_BY_AUTHOR]);
|
||||||
float width = 0;
|
float width = 0;
|
||||||
C2D_TextGetDimensions(&text[TEXT_BY_AUTHOR], 0.5, 0.5, &width, NULL);
|
C2D_TextGetDimensions(&text[TEXT_BY_AUTHOR], 0.5, 0.5, &width, NULL);
|
||||||
draw_text(20+width, 35, 0.5, 0.5, 0.5, colors[COLOR_WHITE_BACKGROUND], author);
|
draw_text(20+width, 35, 0.5, 0.5, 0.5, colors[COLOR_WHITE], author);
|
||||||
|
|
||||||
char title[0x41] = {0};
|
char title[0x41] = {0};
|
||||||
utf16_to_utf8((u8 *)title, entry->name, 0x40);
|
utf16_to_utf8((u8*)title, entry->name, 0x40);
|
||||||
draw_text(20, 50, 0.5, 0.7, 0.7, colors[COLOR_WHITE_BACKGROUND], title);
|
draw_text(20, 50, 0.5, 0.7, 0.7, colors[COLOR_WHITE], title);
|
||||||
|
|
||||||
char description[0x81] = {0};
|
char description[0x81] = {0};
|
||||||
utf16_to_utf8((u8 *)description, entry->desc, 0x80);
|
utf16_to_utf8((u8*)description, entry->desc, 0x80);
|
||||||
draw_text_wrap(20, 70, 0.5, 0.5, 0.5, colors[COLOR_WHITE_BACKGROUND], description, 363);
|
draw_text_wrap(20, 70, 0.5, 0.5, 0.5, colors[COLOR_WHITE], description, 363);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_grid_interface(Entry_List_s * list, Instructions_s instructions, int extra_mode)
|
void draw_grid_interface(Entry_List_s* list, Instructions_s instructions)
|
||||||
{
|
{
|
||||||
draw_base_interface();
|
draw_base_interface();
|
||||||
EntryMode current_mode = list->mode;
|
EntryMode current_mode = list->mode;
|
||||||
|
|
||||||
C2D_Text * mode_string[REMOTE_MODE_AMOUNT] = {
|
C2D_Text* mode_string[MODE_AMOUNT] = {
|
||||||
&text[TEXT_THEMEPLAZA_THEME_MODE],
|
&text[TEXT_THEMEPLAZA_THEME_MODE],
|
||||||
&text[TEXT_THEMEPLAZA_SPLASH_MODE],
|
&text[TEXT_THEMEPLAZA_SPLASH_MODE],
|
||||||
&text[TEXT_THEMEPLAZA_BADGE_MODE],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
draw_c2d_text_center(GFX_TOP, 4, 0.5f, 0.5f, 0.5f, colors[COLOR_WHITE_ACCENT], mode_string[current_mode]);
|
draw_c2d_text_center(GFX_TOP, 4, 0.5f, 0.5f, 0.5f, colors[COLOR_WHITE], mode_string[current_mode]);
|
||||||
|
|
||||||
draw_instructions(instructions);
|
draw_instructions(instructions);
|
||||||
|
|
||||||
@@ -568,22 +524,16 @@ void draw_grid_interface(Entry_List_s * list, Instructions_s instructions, int e
|
|||||||
|
|
||||||
set_screen(bottom);
|
set_screen(bottom);
|
||||||
|
|
||||||
draw_c2d_text(7, 3, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE_ACCENT], &text[TEXT_SEARCH]);
|
draw_c2d_text(7, 3, 0.5f, 0.6f, 0.6f, colors[COLOR_WHITE], &text[TEXT_SEARCH]);
|
||||||
|
|
||||||
C2D_ImageTint accent_tint;
|
draw_image(sprites_list_idx, 320-96, 0);
|
||||||
C2D_PlainImageTint(&accent_tint, colors[COLOR_WHITE_ACCENT], 1.0f);
|
draw_image(sprites_exit_idx, 320-72, 0);
|
||||||
|
draw_image(sprites_preview_idx, 320-48, 0);
|
||||||
|
|
||||||
draw_image_tint(sprites_back_idx, 320-96, 0, accent_tint);
|
draw_text(320-24+2.5, -3, 0.6, 1.0f, 0.9f, colors[COLOR_WHITE], mode_switch_char[!current_mode]);
|
||||||
draw_image_tint(sprites_exit_idx, 320-72, 0, accent_tint);
|
|
||||||
draw_image_tint(sprites_preview_idx, 320-48, 0, accent_tint);
|
|
||||||
|
|
||||||
draw_text(320-24+2.5, -3, 0.6, 1.0f, 0.9f, colors[COLOR_WHITE_ACCENT], remote_mode_switch_char[current_mode]);
|
draw_image(sprites_arrow_left_idx, 3, 114);
|
||||||
|
draw_image(sprites_arrow_right_idx, 308, 114);
|
||||||
C2D_ImageTint background_tint;
|
|
||||||
C2D_PlainImageTint(&background_tint, colors[COLOR_WHITE_BACKGROUND], 1.0f);
|
|
||||||
|
|
||||||
draw_image_tint(sprites_arrow_left_idx, 3, 114, background_tint);
|
|
||||||
draw_image_tint(sprites_arrow_right_idx, 308, 114, background_tint);
|
|
||||||
|
|
||||||
for(int i = list->scroll; i < (list->entries_loaded + list->scroll); i++)
|
for(int i = list->scroll; i < (list->entries_loaded + list->scroll); i++)
|
||||||
{
|
{
|
||||||
@@ -592,7 +542,7 @@ void draw_grid_interface(Entry_List_s * list, Instructions_s instructions, int e
|
|||||||
current_entry = &list->entries[i];
|
current_entry = &list->entries[i];
|
||||||
|
|
||||||
char name[0x41] = {0};
|
char name[0x41] = {0};
|
||||||
utf16_to_utf8((u8 *)name, current_entry->name, 0x40);
|
utf16_to_utf8((u8*)name, current_entry->name, 0x40);
|
||||||
|
|
||||||
int vertical_offset = 0;
|
int vertical_offset = 0;
|
||||||
int horizontal_offset = i - list->scroll;
|
int horizontal_offset = i - list->scroll;
|
||||||
@@ -604,16 +554,18 @@ void draw_grid_interface(Entry_List_s * list, Instructions_s instructions, int e
|
|||||||
vertical_offset += 24;
|
vertical_offset += 24;
|
||||||
horizontal_offset += 16;
|
horizontal_offset += 16;
|
||||||
|
|
||||||
|
// theoretically impossible to have no icon when from the api
|
||||||
if(current_entry->placeholder_color == 0)
|
/*
|
||||||
|
if(!current_entry->placeholder_color)
|
||||||
{
|
{
|
||||||
const C2D_Image image = get_icon_at(list, i);
|
*/
|
||||||
C2D_DrawImageAt(image, horizontal_offset, vertical_offset, 0.5f, NULL, 1.0f, 1.0f);
|
C2D_Image * image = list->icons[i];
|
||||||
|
C2D_DrawImageAt(*image, horizontal_offset, vertical_offset, 0.5f, NULL, 1.0f, 1.0f);
|
||||||
|
/*
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
C2D_DrawRectSolid(horizontal_offset, vertical_offset, 0.5f, list->entry_size, list->entry_size, current_entry->placeholder_color);
|
C2D_DrawRectSolid(horizontal_offset, vertical_offset, 0.5f, list->entry_size, list->entry_size, current_entry->placeholder_color);
|
||||||
}
|
*/
|
||||||
|
|
||||||
if(i == selected_entry)
|
if(i == selected_entry)
|
||||||
{
|
{
|
||||||
@@ -624,11 +576,6 @@ void draw_grid_interface(Entry_List_s * list, Instructions_s instructions, int e
|
|||||||
C2D_DrawRectSolid(horizontal_offset+list->entry_size-border_width, vertical_offset, 0.5f, border_width, list->entry_size, colors[COLOR_CURSOR]);
|
C2D_DrawRectSolid(horizontal_offset+list->entry_size-border_width, vertical_offset, 0.5f, border_width, list->entry_size, colors[COLOR_CURSOR]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extra_mode)
|
|
||||||
{
|
|
||||||
C2D_DrawRectSolid(0, 24, 0.6f, 320, 240-48, C2D_Color32(0, 0, 0, 128));
|
|
||||||
}
|
|
||||||
|
|
||||||
char entries_count_str[0x20] = {0};
|
char entries_count_str[0x20] = {0};
|
||||||
sprintf(entries_count_str, "/%" JSON_INTEGER_FORMAT, list->tp_page_count);
|
sprintf(entries_count_str, "/%" JSON_INTEGER_FORMAT, list->tp_page_count);
|
||||||
@@ -636,35 +583,32 @@ void draw_grid_interface(Entry_List_s * list, Instructions_s instructions, int e
|
|||||||
float width = 0;
|
float width = 0;
|
||||||
get_text_dimensions(entries_count_str, 0.6, 0.6, &width, NULL);
|
get_text_dimensions(entries_count_str, 0.6, 0.6, &width, NULL);
|
||||||
x -= width;
|
x -= width;
|
||||||
draw_text(x, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE_ACCENT], entries_count_str);
|
draw_text(x, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE], entries_count_str);
|
||||||
|
|
||||||
char selected_entry_str[0x20] = {0};
|
char selected_entry_str[0x20] = {0};
|
||||||
sprintf(selected_entry_str, "%" JSON_INTEGER_FORMAT, list->tp_current_page);
|
sprintf(selected_entry_str, "%" JSON_INTEGER_FORMAT, list->tp_current_page);
|
||||||
get_text_dimensions(selected_entry_str, 0.6, 0.6, &width, NULL);
|
get_text_dimensions(selected_entry_str, 0.6, 0.6, &width, NULL);
|
||||||
x -= width;
|
x -= width;
|
||||||
draw_text(x, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE_ACCENT], selected_entry_str);
|
draw_text(x, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE], selected_entry_str);
|
||||||
|
|
||||||
draw_c2d_text(176, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE_ACCENT], &text[TEXT_PAGE]);
|
draw_c2d_text(176, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE], &text[TEXT_PAGE]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_interface(Entry_List_s * list, Instructions_s instructions, DrawMode draw_mode)
|
void draw_interface(Entry_List_s* list, Instructions_s instructions)
|
||||||
{
|
{
|
||||||
draw_base_interface();
|
draw_base_interface();
|
||||||
EntryMode current_mode = list->mode;
|
EntryMode current_mode = list->mode;
|
||||||
|
|
||||||
C2D_Text * mode_string[MODE_AMOUNT] = {
|
C2D_Text* mode_string[MODE_AMOUNT] = {
|
||||||
&text[TEXT_THEME_MODE],
|
&text[TEXT_THEME_MODE],
|
||||||
&text[TEXT_SPLASH_MODE],
|
&text[TEXT_SPLASH_MODE],
|
||||||
};
|
};
|
||||||
|
|
||||||
C2D_ImageTint accent_tint;
|
draw_c2d_text_center(GFX_TOP, 4, 0.5f, 0.5f, 0.5f, colors[COLOR_WHITE], mode_string[current_mode]);
|
||||||
C2D_PlainImageTint(&accent_tint, colors[COLOR_WHITE_ACCENT], 1.0f);
|
|
||||||
|
|
||||||
draw_c2d_text_center(GFX_TOP, 4, 0.5f, 0.5f, 0.5f, colors[COLOR_WHITE_ACCENT], mode_string[current_mode]);
|
if(list->entries == NULL)
|
||||||
|
|
||||||
if(list->entries == NULL || list->entries_count == 0)
|
|
||||||
{
|
{
|
||||||
C2D_Text * mode_found_string[MODE_AMOUNT] = {
|
C2D_Text* mode_found_string[MODE_AMOUNT] = {
|
||||||
&text[TEXT_NO_THEME_FOUND],
|
&text[TEXT_NO_THEME_FOUND],
|
||||||
&text[TEXT_NO_SPLASH_FOUND],
|
&text[TEXT_NO_SPLASH_FOUND],
|
||||||
};
|
};
|
||||||
@@ -672,7 +616,7 @@ void draw_interface(Entry_List_s * list, Instructions_s instructions, DrawMode d
|
|||||||
draw_c2d_text_center(GFX_TOP, 80, 0.5f, 0.7f, 0.7f, colors[COLOR_YELLOW], mode_found_string[current_mode]);
|
draw_c2d_text_center(GFX_TOP, 80, 0.5f, 0.7f, 0.7f, colors[COLOR_YELLOW], mode_found_string[current_mode]);
|
||||||
draw_c2d_text_center(GFX_TOP, 110, 0.5f, 0.7f, 0.7f, colors[COLOR_YELLOW], &text[TEXT_DOWNLOAD_FROM_QR]);
|
draw_c2d_text_center(GFX_TOP, 110, 0.5f, 0.7f, 0.7f, colors[COLOR_YELLOW], &text[TEXT_DOWNLOAD_FROM_QR]);
|
||||||
|
|
||||||
C2D_Text * mode_switch_string[MODE_AMOUNT] = {
|
C2D_Text* mode_switch_string[MODE_AMOUNT] = {
|
||||||
&text[TEXT_SWITCH_TO_SPLASHES],
|
&text[TEXT_SWITCH_TO_SPLASHES],
|
||||||
&text[TEXT_SWITCH_TO_THEMES],
|
&text[TEXT_SWITCH_TO_THEMES],
|
||||||
};
|
};
|
||||||
@@ -682,18 +626,20 @@ void draw_interface(Entry_List_s * list, Instructions_s instructions, DrawMode d
|
|||||||
|
|
||||||
C2D_ImageTint yellow_tint;
|
C2D_ImageTint yellow_tint;
|
||||||
C2D_PlainImageTint(&yellow_tint, colors[COLOR_YELLOW], 1.0f);
|
C2D_PlainImageTint(&yellow_tint, colors[COLOR_YELLOW], 1.0f);
|
||||||
C2D_SpriteSetPos(&sprite_start, language.draw.start_pos, 173);
|
C2D_SpriteSetPos(&sprite_start, 162, 173);
|
||||||
C2D_SpriteSetScale(&sprite_start, 1.25f, 1.4f);
|
C2D_SpriteSetScale(&sprite_start, 1.25f, 1.4f);
|
||||||
C2D_DrawSpriteTinted(&sprite_start, &yellow_tint);
|
C2D_DrawSpriteTinted(&sprite_start, &yellow_tint);
|
||||||
C2D_SpriteSetScale(&sprite_start, 1.0f, 1.0f);
|
C2D_SpriteSetScale(&sprite_start, 1.0f, 1.0f);
|
||||||
|
|
||||||
set_screen(bottom);
|
set_screen(bottom);
|
||||||
|
|
||||||
draw_image_tint(sprites_qr_idx, 320-96, 0, accent_tint);
|
draw_image(sprites_sort_idx, 320-144, 0);
|
||||||
draw_image_tint(sprites_browse_idx, 320-72, 0, accent_tint);
|
draw_image(sprites_download_idx, 320-120, 0);
|
||||||
draw_image_tint(sprites_exit_idx, 320-48, 0, accent_tint);
|
draw_image(sprites_browse_idx, 320-96, 0);
|
||||||
|
draw_image(sprites_exit_idx, 320-72, 0);
|
||||||
|
draw_image(sprites_preview_idx, 320-48, 0);
|
||||||
|
|
||||||
draw_text(320-24+2.5, -3, 0.6, 1.0f, 0.9f, colors[COLOR_WHITE_ACCENT], mode_switch_char[!current_mode]);
|
draw_text(320-24+2.5, -3, 0.6, 1.0f, 0.9f, colors[COLOR_WHITE], mode_switch_char[!current_mode]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -709,49 +655,25 @@ void draw_interface(Entry_List_s * list, Instructions_s instructions, DrawMode d
|
|||||||
if(current_mode == MODE_THEMES)
|
if(current_mode == MODE_THEMES)
|
||||||
{
|
{
|
||||||
char * shuffle_count_string = NULL;
|
char * shuffle_count_string = NULL;
|
||||||
asprintf(&shuffle_count_string, language.draw.shuffle, list->shuffle_count);
|
asprintf(&shuffle_count_string, "Shuffle: %i/10", list->shuffle_count);
|
||||||
draw_text(30, 3, 0.6, 0.6, 0.6f, list->shuffle_count <= 10 && list->shuffle_count >= 2 ? colors[COLOR_WHITE_ACCENT] : colors[COLOR_RED_ACCENT], shuffle_count_string);
|
draw_text(7, 3, 0.6, 0.6, 0.6f, list->shuffle_count <= 10 && list->shuffle_count >= 2 ? colors[COLOR_WHITE] : colors[COLOR_RED], shuffle_count_string);
|
||||||
free(shuffle_count_string);
|
free(shuffle_count_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (draw_mode == DRAW_MODE_LIST)
|
draw_image(sprites_sort_idx, 320-144, 0);
|
||||||
{
|
draw_image(sprites_download_idx, 320-120, 0);
|
||||||
draw_image_tint(sprites_install_idx, 320-120, 0, accent_tint);
|
draw_image(sprites_browse_idx, 320-96, 0);
|
||||||
draw_image_tint(sprites_qr_idx, 320-96, 0, accent_tint);
|
draw_image(sprites_exit_idx, 320-72, 0);
|
||||||
draw_image_tint(sprites_exit_idx, 320-72, 0, accent_tint);
|
draw_image(sprites_preview_idx, 320-48, 0);
|
||||||
draw_image_tint(sprites_preview_idx, 320-48, 0, accent_tint);
|
|
||||||
draw_text(320-24+2.5, -3, 0.6, 1.0f, 0.9f, colors[COLOR_WHITE_ACCENT], mode_switch_char[!current_mode]);
|
draw_text(320-24+2.5, -3, 0.6, 1.0f, 0.9f, colors[COLOR_WHITE], mode_switch_char[!current_mode]);
|
||||||
draw_image_tint(sprites_menu_idx, 2, 0, accent_tint);
|
|
||||||
if (current_mode == MODE_THEMES)
|
|
||||||
{
|
|
||||||
draw_image_tint(sprites_shuffle_idx, 320-144, 0, accent_tint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (draw_mode == DRAW_MODE_INSTALL)
|
|
||||||
{
|
|
||||||
draw_image_tint(sprites_install_idx, 320-24, 0, accent_tint);
|
|
||||||
draw_image_tint(sprites_shuffle_idx, 320-48, 0, accent_tint);
|
|
||||||
draw_image_tint(sprites_shuffle_no_bgm_idx, 320-72, 0, accent_tint);
|
|
||||||
draw_image_tint(sprites_bgm_only_idx, 320-96, 0, accent_tint);
|
|
||||||
draw_image_tint(sprites_back_idx, 2, 0, accent_tint);
|
|
||||||
} else if (draw_mode == DRAW_MODE_EXTRA)
|
|
||||||
{
|
|
||||||
draw_image_tint(sprites_browse_idx, 320-24, 0, accent_tint);
|
|
||||||
draw_image_tint(sprites_dump_idx, 320-48, 0, accent_tint);
|
|
||||||
draw_image_tint(sprites_sort_idx, 320-72, 0, accent_tint);
|
|
||||||
draw_image_tint(sprites_badge_idx, 320-96, 0, accent_tint);
|
|
||||||
draw_image_tint(sprites_back_idx, 2, 0, accent_tint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show arrows if there are themes out of bounds
|
// Show arrows if there are themes out of bounds
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
if(list->scroll > 0)
|
if(list->scroll > 0)
|
||||||
draw_image_tint(sprites_arrow_up_idx, 141, 220, accent_tint);
|
draw_image(sprites_arrow_up_idx, 152, 4);
|
||||||
if(list->scroll + list->entries_loaded < list->entries_count)
|
if(list->scroll + list->entries_loaded < list->entries_count)
|
||||||
draw_image_tint(sprites_arrow_down_idx, 157, 220, accent_tint);
|
draw_image(sprites_arrow_down_idx, 152, 220);
|
||||||
|
|
||||||
for(int i = list->scroll; i < (list->entries_loaded + list->scroll); i++)
|
for(int i = list->scroll; i < (list->entries_loaded + list->scroll); i++)
|
||||||
{
|
{
|
||||||
@@ -760,7 +682,7 @@ void draw_interface(Entry_List_s * list, Instructions_s instructions, DrawMode d
|
|||||||
current_entry = &list->entries[i];
|
current_entry = &list->entries[i];
|
||||||
|
|
||||||
char name[0x41] = {0};
|
char name[0x41] = {0};
|
||||||
utf16_to_utf8((u8 *)name, current_entry->name, 0x40);
|
utf16_to_utf8((u8*)name, current_entry->name, 0x40);
|
||||||
|
|
||||||
int vertical_offset = i - list->scroll;
|
int vertical_offset = i - list->scroll;
|
||||||
int horizontal_offset = 0;
|
int horizontal_offset = 0;
|
||||||
@@ -768,7 +690,7 @@ void draw_interface(Entry_List_s * list, Instructions_s instructions, DrawMode d
|
|||||||
vertical_offset *= list->entry_size;
|
vertical_offset *= list->entry_size;
|
||||||
vertical_offset += 24;
|
vertical_offset += 24;
|
||||||
|
|
||||||
u32 font_color = colors[COLOR_WHITE_BACKGROUND];
|
u32 font_color = colors[COLOR_WHITE];
|
||||||
|
|
||||||
if(i == selected_entry)
|
if(i == selected_entry)
|
||||||
{
|
{
|
||||||
@@ -798,17 +720,14 @@ void draw_interface(Entry_List_s * list, Instructions_s instructions, DrawMode d
|
|||||||
C2D_DrawSpriteTinted(&sprite_installed, &tint);
|
C2D_DrawSpriteTinted(&sprite_installed, &tint);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(current_entry->placeholder_color == 0)
|
if(!current_entry->placeholder_color)
|
||||||
{
|
{
|
||||||
C2D_Image image;
|
C2D_Image * image = NULL;
|
||||||
if(list->entries_count > list->entries_loaded * ICONS_OFFSET_AMOUNT)
|
if(list->entries_count > list->entries_loaded*ICONS_OFFSET_AMOUNT)
|
||||||
{
|
image = list->icons[ICONS_VISIBLE*list->entries_loaded + (i - list->scroll)];
|
||||||
const int offset_to_visible_icons = ICONS_VISIBLE * list->entries_loaded;
|
|
||||||
image = get_icon_at(list, offset_to_visible_icons + (i - list->scroll));
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
image = get_icon_at(list, i);
|
image = list->icons[i];
|
||||||
C2D_DrawImageAt(image, horizontal_offset, vertical_offset, 0.5f, NULL, 1.0f, 1.0f);
|
C2D_DrawImageAt(*image, horizontal_offset, vertical_offset, 0.5f, NULL, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -822,20 +741,16 @@ void draw_interface(Entry_List_s * list, Instructions_s instructions, DrawMode d
|
|||||||
float width = 0;
|
float width = 0;
|
||||||
get_text_dimensions(entries_count_str, 0.6, 0.6, &width, NULL);
|
get_text_dimensions(entries_count_str, 0.6, 0.6, &width, NULL);
|
||||||
x -= width;
|
x -= width;
|
||||||
draw_text(x, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE_ACCENT], entries_count_str);
|
draw_text(x, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE], entries_count_str);
|
||||||
|
|
||||||
char selected_entry_str[0x20] = {0};
|
char selected_entry_str[0x20] = {0};
|
||||||
sprintf(selected_entry_str, "%i", selected_entry + 1);
|
sprintf(selected_entry_str, "%i", selected_entry + 1);
|
||||||
get_text_dimensions(selected_entry_str, 0.6, 0.6, &width, NULL);
|
get_text_dimensions(selected_entry_str, 0.6, 0.6, &width, NULL);
|
||||||
x -= width;
|
x -= width;
|
||||||
draw_text(x, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE_ACCENT], selected_entry_str);
|
draw_text(x, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE], selected_entry_str);
|
||||||
|
|
||||||
if(list->entries_count < 10000)
|
if(list->entries_count < 10000)
|
||||||
draw_c2d_text(176, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE_ACCENT], &text[TEXT_SELECTED]);
|
draw_c2d_text(176, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE], &text[TEXT_SELECTED]);
|
||||||
else
|
else
|
||||||
draw_c2d_text(176, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE_ACCENT], &text[TEXT_SELECTED_SHORT]);
|
draw_c2d_text(176, 219, 0.5, 0.6, 0.6, colors[COLOR_WHITE], &text[TEXT_SELECTED_SHORT]);
|
||||||
if(draw_mode != DRAW_MODE_LIST)
|
|
||||||
{
|
|
||||||
C2D_DrawRectSolid(0, 24, 1.0f, 320, 240-48, C2D_Color32(0, 0, 0, 128));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,231 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Anemone3DS
|
|
||||||
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
||||||
* * Requiring preservation of specified reasonable legal notices or
|
|
||||||
* author attributions in that material or in the Appropriate Legal
|
|
||||||
* Notices displayed by works containing it.
|
|
||||||
* * Prohibiting misrepresentation of the origin of that material,
|
|
||||||
* or requiring that modified versions of such material be marked in
|
|
||||||
* reasonable ways as different from the original version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "entries_list.h"
|
|
||||||
#include "loading.h"
|
|
||||||
#include "draw.h"
|
|
||||||
#include "fs.h"
|
|
||||||
#include "unicode.h"
|
|
||||||
|
|
||||||
void delete_entry(Entry_s * entry, bool is_file)
|
|
||||||
{
|
|
||||||
if(is_file)
|
|
||||||
FSUSER_DeleteFile(ArchiveSD, fsMakePath(PATH_UTF16, entry->path));
|
|
||||||
else
|
|
||||||
FSUSER_DeleteDirectoryRecursively(ArchiveSD, fsMakePath(PATH_UTF16, entry->path));
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 load_data(const char * filename, const Entry_s * entry, char ** buf)
|
|
||||||
{
|
|
||||||
if(entry->is_zip)
|
|
||||||
{
|
|
||||||
return zip_file_to_buf(filename + 1, entry->path, buf); //the first character will always be '/' because of the other case
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
u16 path[0x106] = {0};
|
|
||||||
strucat(path, entry->path);
|
|
||||||
struacat(path, filename);
|
|
||||||
|
|
||||||
return file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
C2D_Image get_icon_at(Entry_List_s * list, size_t index)
|
|
||||||
{
|
|
||||||
return (C2D_Image){
|
|
||||||
.tex = &list->icons_texture,
|
|
||||||
.subtex = &list->icons_info[index].subtex,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static int compare_entries_base(const Entry_s * const a, const Entry_s * const b)
|
|
||||||
{
|
|
||||||
// entry->placeholder_color == 0 means it is not filled (no name, author, description)
|
|
||||||
// if a is filled and b is filled, return == 0
|
|
||||||
// if a is not filled and b is not filled, return == 0
|
|
||||||
// if a is not filled, return < 0
|
|
||||||
// if b is an unfilled entry, return > 0
|
|
||||||
return ((int)(a->placeholder_color != 0)) - ((int)(b->placeholder_color != 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef int (*sort_comparator)(const void *, const void *);
|
|
||||||
static int compare_entries_by_name(const void * a, const void * b)
|
|
||||||
{
|
|
||||||
const Entry_s * const entry_a = (const Entry_s *)a;
|
|
||||||
const Entry_s * const entry_b = (const Entry_s *)b;
|
|
||||||
const int base = compare_entries_base(entry_a, entry_b);
|
|
||||||
if(base)
|
|
||||||
return base;
|
|
||||||
|
|
||||||
return memcmp(entry_a->name, entry_b->name, 0x40 * sizeof(u16));
|
|
||||||
}
|
|
||||||
static int compare_entries_by_author(const void * a, const void * b)
|
|
||||||
{
|
|
||||||
const Entry_s * const entry_a = (const Entry_s *)a;
|
|
||||||
const Entry_s * const entry_b = (const Entry_s *)b;
|
|
||||||
const int base = compare_entries_base(entry_a, entry_b);
|
|
||||||
if(base)
|
|
||||||
return base;
|
|
||||||
|
|
||||||
return memcmp(entry_a->author, entry_b->author, 0x40 * sizeof(u16));
|
|
||||||
}
|
|
||||||
static int compare_entries_by_filename(const void * a, const void * b)
|
|
||||||
{
|
|
||||||
const Entry_s * const entry_a = (const Entry_s *)a;
|
|
||||||
const Entry_s * const entry_b = (const Entry_s *)b;
|
|
||||||
const int base = compare_entries_base(entry_a, entry_b);
|
|
||||||
if(base)
|
|
||||||
return base;
|
|
||||||
|
|
||||||
return memcmp(entry_a->path, entry_b->path, 0x106 * sizeof(u16));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sort_list(Entry_List_s * list, sort_comparator compare_entries)
|
|
||||||
{
|
|
||||||
if(list->entries != NULL && list->entries != NULL)
|
|
||||||
qsort(list->entries, list->entries_count, sizeof(Entry_s), compare_entries); //alphabet sort
|
|
||||||
}
|
|
||||||
|
|
||||||
void sort_by_name(Entry_List_s * list)
|
|
||||||
{
|
|
||||||
sort_list(list, compare_entries_by_name);
|
|
||||||
list->current_sort = SORT_NAME;
|
|
||||||
}
|
|
||||||
void sort_by_author(Entry_List_s * list)
|
|
||||||
{
|
|
||||||
sort_list(list, compare_entries_by_author);
|
|
||||||
list->current_sort = SORT_AUTHOR;
|
|
||||||
}
|
|
||||||
void sort_by_filename(Entry_List_s * list)
|
|
||||||
{
|
|
||||||
sort_list(list, compare_entries_by_filename);
|
|
||||||
list->current_sort = SORT_PATH;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define LOADING_DIR_ENTRIES_COUNT 16
|
|
||||||
static FS_DirectoryEntry loading_dir_entries[LOADING_DIR_ENTRIES_COUNT];
|
|
||||||
Result load_entries(const char * loading_path, Entry_List_s * list, const InstallType loading_screen)
|
|
||||||
{
|
|
||||||
Handle dir_handle;
|
|
||||||
Result res = FSUSER_OpenDirectory(&dir_handle, ArchiveSD, fsMakePath(PATH_ASCII, loading_path));
|
|
||||||
if(R_FAILED(res))
|
|
||||||
{
|
|
||||||
DEBUG("Failed to open folder: %s\n", loading_path);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
list_init_capacity(list, LOADING_DIR_ENTRIES_COUNT);
|
|
||||||
|
|
||||||
u32 entries_read = LOADING_DIR_ENTRIES_COUNT;
|
|
||||||
while(entries_read == LOADING_DIR_ENTRIES_COUNT)
|
|
||||||
{
|
|
||||||
res = FSDIR_Read(dir_handle, &entries_read, LOADING_DIR_ENTRIES_COUNT, loading_dir_entries);
|
|
||||||
if(R_FAILED(res))
|
|
||||||
break;
|
|
||||||
|
|
||||||
for(u32 i = 0; i < entries_read; ++i)
|
|
||||||
{
|
|
||||||
const FS_DirectoryEntry * const dir_entry = &loading_dir_entries[i];
|
|
||||||
const bool is_zip = !strcmp(dir_entry->shortExt, "ZIP");
|
|
||||||
if(!(dir_entry->attributes & FS_ATTRIBUTE_DIRECTORY) && !is_zip)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const ssize_t new_entry_index = list_add_entry(list);
|
|
||||||
if(new_entry_index < 0)
|
|
||||||
{
|
|
||||||
// out of memory: still allow use of currently loaded entries.
|
|
||||||
// Many things might die, depending on the heap layout after
|
|
||||||
entries_read = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entry_s * const current_entry = &list->entries[new_entry_index];
|
|
||||||
memset(current_entry, 0, sizeof(Entry_s));
|
|
||||||
struacat(current_entry->path, loading_path);
|
|
||||||
strucat(current_entry->path, dir_entry->name);
|
|
||||||
current_entry->is_zip = is_zip;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FSDIR_Close(dir_handle);
|
|
||||||
|
|
||||||
list->loading_path = loading_path;
|
|
||||||
const int loading_bar_ticks = list->entries_count / 10;
|
|
||||||
|
|
||||||
for(int i = 0, j = 0; i < list->entries_count; ++i)
|
|
||||||
{
|
|
||||||
// replaces (i % loading_bar_ticks) == 0
|
|
||||||
if(++j >= loading_bar_ticks)
|
|
||||||
{
|
|
||||||
j = 0;
|
|
||||||
draw_loading_bar(i, list->entries_count, loading_screen);
|
|
||||||
}
|
|
||||||
Entry_s * const current_entry = &list->entries[i];
|
|
||||||
char * buf = NULL;
|
|
||||||
u32 buflen = load_data("/info.smdh", current_entry, &buf);
|
|
||||||
parse_smdh(buflen == sizeof(Icon_s) ? (Icon_s *)buf : NULL, current_entry, current_entry->path + strlen(loading_path));
|
|
||||||
free(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void list_init_capacity(Entry_List_s * list, const int init_capacity)
|
|
||||||
{
|
|
||||||
list->entries = malloc(init_capacity * sizeof(Entry_s));
|
|
||||||
list->entries_capacity = init_capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define LIST_CAPACITY_THRESHOLD 512
|
|
||||||
ssize_t list_add_entry(Entry_List_s * list)
|
|
||||||
{
|
|
||||||
if(list->entries_count == list->entries_capacity)
|
|
||||||
{
|
|
||||||
int next_capacity = list->entries_capacity;
|
|
||||||
// expand by doubling until we hit LIST_CAPACITY_THRESHOLD
|
|
||||||
// then simply increment by that, to have less extra space leftover
|
|
||||||
if(next_capacity < LIST_CAPACITY_THRESHOLD)
|
|
||||||
{
|
|
||||||
next_capacity *= 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
next_capacity += LIST_CAPACITY_THRESHOLD;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entry_s * const new_list = realloc(list->entries, next_capacity * sizeof(Entry_s));
|
|
||||||
if(new_list == NULL)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
list->entries = new_list;
|
|
||||||
list->entries_capacity = next_capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
return list->entries_count++;
|
|
||||||
}
|
|
||||||
288
source/fs.c
@@ -29,8 +29,6 @@
|
|||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
#include "ui_strings.h"
|
|
||||||
#include "remote.h"
|
|
||||||
|
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
#include <archive_entry.h>
|
#include <archive_entry.h>
|
||||||
@@ -38,48 +36,6 @@
|
|||||||
FS_Archive ArchiveSD;
|
FS_Archive ArchiveSD;
|
||||||
FS_Archive ArchiveHomeExt;
|
FS_Archive ArchiveHomeExt;
|
||||||
FS_Archive ArchiveThemeExt;
|
FS_Archive ArchiveThemeExt;
|
||||||
FS_Archive ArchiveBadgeExt;
|
|
||||||
|
|
||||||
Result createExtSaveData(u32 extdataID)
|
|
||||||
{
|
|
||||||
u8 null_smdh[0x36C0] = {0};
|
|
||||||
Handle *handle = fsGetSessionHandle();
|
|
||||||
|
|
||||||
u32 *cmdbuf = getThreadCommandBuffer();
|
|
||||||
|
|
||||||
u32 directory_limit = 1000;
|
|
||||||
u32 file_limit = 1000;
|
|
||||||
|
|
||||||
cmdbuf[0] = 0x08300182;
|
|
||||||
cmdbuf[1] = MEDIATYPE_SD;
|
|
||||||
cmdbuf[2] = extdataID;
|
|
||||||
cmdbuf[3] = 0;
|
|
||||||
cmdbuf[4] = 0x36C0;
|
|
||||||
cmdbuf[5] = directory_limit;
|
|
||||||
cmdbuf[6] = file_limit;
|
|
||||||
cmdbuf[7] = (0x36C0 << 4) | 0xA;
|
|
||||||
cmdbuf[8] = (u32)&null_smdh;
|
|
||||||
|
|
||||||
Result ret = 0;
|
|
||||||
if ((ret = svcSendSyncRequest(*handle)))
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
return cmdbuf[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
Result init_sd(void)
|
|
||||||
{
|
|
||||||
Result res;
|
|
||||||
if(R_FAILED(res = FSUSER_OpenArchive(&ArchiveSD, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, "")))) return res;
|
|
||||||
load_config();
|
|
||||||
|
|
||||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds"), FS_ATTRIBUTE_DIRECTORY);
|
|
||||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE), FS_ATTRIBUTE_DIRECTORY);
|
|
||||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE "/cache"), FS_ATTRIBUTE_DIRECTORY);
|
|
||||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE "/BadgeBackups"), FS_ATTRIBUTE_DIRECTORY);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result open_archives(void)
|
Result open_archives(void)
|
||||||
{
|
{
|
||||||
@@ -108,18 +64,18 @@ Result open_archives(void)
|
|||||||
archive1 = 0x000002ce;
|
archive1 = 0x000002ce;
|
||||||
archive2 = 0x00000098;
|
archive2 = 0x00000098;
|
||||||
break;
|
break;
|
||||||
case 5:
|
|
||||||
archive1 = 0x000002cf;
|
|
||||||
archive2 = 0x000000a9;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
archive1 = 0x00;
|
archive1 = 0x00;
|
||||||
archive2 = 0x00;
|
archive2 = 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, main_paths[REMOTE_MODE_THEMES]), FS_ATTRIBUTE_DIRECTORY);
|
if(R_FAILED(res = FSUSER_OpenArchive(&ArchiveSD, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, "")))) return res;
|
||||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, main_paths[REMOTE_MODE_SPLASHES]), FS_ATTRIBUTE_DIRECTORY);
|
|
||||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, main_paths[REMOTE_MODE_BADGES]), FS_ATTRIBUTE_DIRECTORY);
|
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/Themes"), FS_ATTRIBUTE_DIRECTORY);
|
||||||
|
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/Splashes"), FS_ATTRIBUTE_DIRECTORY);
|
||||||
|
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds"), FS_ATTRIBUTE_DIRECTORY);
|
||||||
|
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE), FS_ATTRIBUTE_DIRECTORY);
|
||||||
|
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/3ds/" APP_TITLE "/cache"), FS_ATTRIBUTE_DIRECTORY);
|
||||||
|
|
||||||
u32 homeMenuPath[3] = {MEDIATYPE_SD, archive2, 0};
|
u32 homeMenuPath[3] = {MEDIATYPE_SD, archive2, 0};
|
||||||
home.type = PATH_BINARY;
|
home.type = PATH_BINARY;
|
||||||
@@ -140,77 +96,6 @@ Result open_archives(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result open_badge_extdata()
|
|
||||||
{
|
|
||||||
Handle test_handle;
|
|
||||||
FS_Path badge;
|
|
||||||
|
|
||||||
Result res = 0;
|
|
||||||
|
|
||||||
u32 badgePath[3] = {MEDIATYPE_SD, 0x000014d1, 0};
|
|
||||||
badge.type = PATH_BINARY;
|
|
||||||
badge.size = 0xC;
|
|
||||||
|
|
||||||
badge.data = badgePath;
|
|
||||||
if(R_FAILED(res = FSUSER_OpenArchive(&ArchiveBadgeExt, ARCHIVE_EXTDATA, badge)))
|
|
||||||
{
|
|
||||||
if (R_SUMMARY(res) == RS_NOTFOUND)
|
|
||||||
{
|
|
||||||
DEBUG("Extdata not found - creating\n");
|
|
||||||
createExtSaveData(0x000014d1);
|
|
||||||
FSUSER_OpenArchive(&ArchiveBadgeExt, ARCHIVE_EXTDATA, badge);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
DEBUG("Unknown extdata error\n");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (R_FAILED(res = FSUSER_OpenFile(&test_handle, ArchiveBadgeExt, fsMakePath(PATH_ASCII, "/BadgeData.dat"), FS_OPEN_READ, 0)))
|
|
||||||
{
|
|
||||||
if (R_SUMMARY(res) == RS_NOTFOUND)
|
|
||||||
{
|
|
||||||
FSUSER_CreateFile(ArchiveBadgeExt, fsMakePath(PATH_ASCII, "/BadgeData.dat"), 0, BADGE_DATA_SIZE);
|
|
||||||
FSUSER_OpenFile(&test_handle, ArchiveBadgeExt, fsMakePath(PATH_ASCII, "/BadgeData.dat"), FS_OPEN_WRITE, 0);
|
|
||||||
FSFILE_Flush(test_handle);
|
|
||||||
}
|
|
||||||
DEBUG("Error 0x%08ld opening BadgeData.dat, retrying\n", res);
|
|
||||||
}
|
|
||||||
FSFILE_Close(test_handle);
|
|
||||||
|
|
||||||
if(R_FAILED(res = FSUSER_OpenFile(&test_handle, ArchiveBadgeExt, fsMakePath(PATH_ASCII, "/BadgeMngFile.dat"), FS_OPEN_READ, 0)))
|
|
||||||
{
|
|
||||||
DEBUG("Error 0x%08ld opening BadgeMngFile.dat, retrying\n", res);
|
|
||||||
if (R_SUMMARY(res) == RS_NOTFOUND)
|
|
||||||
{
|
|
||||||
remake_file(fsMakePath(PATH_ASCII, "/BadgeMngFile.dat"), ArchiveBadgeExt, BADGE_MNG_SIZE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FSFILE_Close(test_handle);
|
|
||||||
|
|
||||||
char tp_path[0x106] = {0};
|
|
||||||
sprintf(tp_path, "%sThemePlaza Badges", main_paths[REMOTE_MODE_BADGES]);
|
|
||||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, tp_path), FS_ATTRIBUTE_DIRECTORY);
|
|
||||||
strcat(tp_path, "/_seticon.png");
|
|
||||||
|
|
||||||
if(R_FAILED(res = FSUSER_OpenFile(&test_handle, ArchiveSD, fsMakePath(PATH_ASCII, tp_path), FS_OPEN_READ, 0)))
|
|
||||||
{
|
|
||||||
FILE *fp = fopen("romfs:/tp_set.png", "rb");
|
|
||||||
fseek(fp, 0L, SEEK_END);
|
|
||||||
ssize_t size = ftell(fp);
|
|
||||||
char *icon_buf = malloc(size);
|
|
||||||
fseek(fp, 0L, SEEK_SET);
|
|
||||||
fread(icon_buf, 1, size, fp);
|
|
||||||
fclose(fp);
|
|
||||||
remake_file(fsMakePath(PATH_ASCII, tp_path), ArchiveSD, size);
|
|
||||||
buf_to_file(size, fsMakePath(PATH_ASCII, tp_path), ArchiveSD, icon_buf);
|
|
||||||
DEBUG("res: 0x%08lx\n", res);
|
|
||||||
free(icon_buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result close_archives(void)
|
Result close_archives(void)
|
||||||
{
|
{
|
||||||
Result res;
|
Result res;
|
||||||
@@ -218,87 +103,30 @@ Result close_archives(void)
|
|||||||
if(R_FAILED(res = FSUSER_CloseArchive(ArchiveSD))) return res;
|
if(R_FAILED(res = FSUSER_CloseArchive(ArchiveSD))) return res;
|
||||||
if(R_FAILED(res = FSUSER_CloseArchive(ArchiveHomeExt))) return res;
|
if(R_FAILED(res = FSUSER_CloseArchive(ArchiveHomeExt))) return res;
|
||||||
if(R_FAILED(res = FSUSER_CloseArchive(ArchiveThemeExt))) return res;
|
if(R_FAILED(res = FSUSER_CloseArchive(ArchiveThemeExt))) return res;
|
||||||
if(R_FAILED(res = FSUSER_CloseArchive(ArchiveBadgeExt))) return res;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result load_parental_controls(Parental_Restrictions_s *restrictions)
|
u32 file_to_buf(FS_Path path, FS_Archive archive, char** buf)
|
||||||
{
|
|
||||||
char parental_data[0xC0] = {0};
|
|
||||||
Result res;
|
|
||||||
|
|
||||||
if (R_FAILED(res = CFGU_GetConfigInfoBlk2(0xC0, 0x000C0000, &parental_data))) return res;
|
|
||||||
memcpy(restrictions, parental_data, 4);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 file_to_buf(FS_Path path, FS_Archive archive, char ** buf)
|
|
||||||
{
|
{
|
||||||
Handle file;
|
Handle file;
|
||||||
Result res = 0;
|
Result res = 0;
|
||||||
if (R_FAILED(res = FSUSER_OpenFile(&file, archive, path, FS_OPEN_READ, 0)))
|
if (R_FAILED(res = FSUSER_OpenFile(&file, archive, path, FS_OPEN_READ, 0))) return 0;
|
||||||
{
|
|
||||||
DEBUG("file_to_buf failed - 0x%08lx\n", res);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 size;
|
u64 size;
|
||||||
FSFILE_GetSize(file, &size);
|
FSFILE_GetSize(file, &size);
|
||||||
if(size != 0)
|
if(size != 0)
|
||||||
{
|
{
|
||||||
*buf = calloc(1, size);
|
*buf = calloc(1, size);
|
||||||
if (*buf == NULL)
|
|
||||||
{
|
|
||||||
DEBUG("Error allocating buffer - out of memory??\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
FSFILE_Read(file, NULL, 0, *buf, size);
|
FSFILE_Read(file, NULL, 0, *buf, size);
|
||||||
}
|
}
|
||||||
FSFILE_Close(file);
|
FSFILE_Close(file);
|
||||||
return (u32)size;
|
return (u32)size;
|
||||||
}
|
}
|
||||||
|
|
||||||
s16 for_each_file_zip(u16 *zip_path, u32 (*zip_iter_callback)(char *filebuf, u64 file_size, const char *name, void *userdata), void *userdata)
|
static u32 zip_to_buf(struct archive *a, char *file_name, char ** buf)
|
||||||
{
|
{
|
||||||
struct archive *a = archive_read_new();
|
|
||||||
archive_read_support_format_zip(a);
|
|
||||||
|
|
||||||
ssize_t len = strulen(zip_path, 0x106);
|
|
||||||
char * path = calloc(len, sizeof(u16));
|
|
||||||
utf16_to_utf8((u8 *)path, zip_path, len * sizeof(u16));
|
|
||||||
DEBUG("Attempting to open zip %s\n", path);
|
|
||||||
|
|
||||||
int r = archive_read_open_filename(a, path, 0x4000);
|
|
||||||
free(path);
|
|
||||||
if(r != ARCHIVE_OK)
|
|
||||||
{
|
|
||||||
DEBUG("Invalid zip being opened\n");
|
|
||||||
char path[0x128] = {0};
|
|
||||||
utf16_to_utf8((u8 *) path, zip_path, 0x128);
|
|
||||||
DEBUG("%s\n", path);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct archive_entry *entry;
|
struct archive_entry *entry;
|
||||||
u64 file_size = 0;
|
|
||||||
while (archive_read_next_header(a, &entry) == ARCHIVE_OK)
|
|
||||||
{
|
|
||||||
file_size = archive_entry_size(entry);
|
|
||||||
char *buf = calloc(file_size, sizeof(char));
|
|
||||||
archive_read_data(a, buf, file_size);
|
|
||||||
zip_iter_callback(buf, file_size, archive_entry_pathname(entry), userdata);
|
|
||||||
free(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
archive_read_free(a);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static u32 zip_to_buf(struct archive * a, const char * file_name, char ** buf)
|
|
||||||
{
|
|
||||||
struct archive_entry * entry;
|
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
u64 file_size = 0;
|
u64 file_size = 0;
|
||||||
@@ -324,9 +152,9 @@ static u32 zip_to_buf(struct archive * a, const char * file_name, char ** buf)
|
|||||||
return (u32)file_size;
|
return (u32)file_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 zip_memory_to_buf(const char * file_name, void * zip_memory, size_t zip_size, char ** buf)
|
u32 zip_memory_to_buf(char *file_name, void * zip_memory, size_t zip_size, char ** buf)
|
||||||
{
|
{
|
||||||
struct archive * a = archive_read_new();
|
struct archive *a = archive_read_new();
|
||||||
archive_read_support_format_zip(a);
|
archive_read_support_format_zip(a);
|
||||||
|
|
||||||
int r = archive_read_open_memory(a, zip_memory, zip_size);
|
int r = archive_read_open_memory(a, zip_memory, zip_size);
|
||||||
@@ -339,13 +167,13 @@ u32 zip_memory_to_buf(const char * file_name, void * zip_memory, size_t zip_size
|
|||||||
return zip_to_buf(a, file_name, buf);
|
return zip_to_buf(a, file_name, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 zip_file_to_buf(const char * file_name, const u16 * zip_path, char ** buf)
|
u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf)
|
||||||
{
|
{
|
||||||
ssize_t len = strulen(zip_path, 0x106);
|
ssize_t len = strulen(zip_path, 0x106);
|
||||||
char * path = calloc(len, sizeof(u16));
|
char *path = calloc(sizeof(char), len*sizeof(u16));
|
||||||
utf16_to_utf8((u8 *)path, zip_path, len * sizeof(u16));
|
utf16_to_utf8((u8*)path, zip_path, len*sizeof(u16));
|
||||||
|
|
||||||
struct archive * a = archive_read_new();
|
struct archive *a = archive_read_new();
|
||||||
archive_read_support_format_zip(a);
|
archive_read_support_format_zip(a);
|
||||||
|
|
||||||
int r = archive_read_open_filename(a, path, 0x4000);
|
int r = archive_read_open_filename(a, path, 0x4000);
|
||||||
@@ -353,16 +181,13 @@ u32 zip_file_to_buf(const char * file_name, const u16 * zip_path, char ** buf)
|
|||||||
if(r != ARCHIVE_OK)
|
if(r != ARCHIVE_OK)
|
||||||
{
|
{
|
||||||
DEBUG("Invalid zip being opened\n");
|
DEBUG("Invalid zip being opened\n");
|
||||||
char path[0x128] = {0};
|
|
||||||
utf16_to_utf8((u8 *) path, zip_path, 0x128);
|
|
||||||
DEBUG("%s\n", path);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return zip_to_buf(a, file_name, buf);
|
return zip_to_buf(a, file_name, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result buf_to_file(u32 size, FS_Path path, FS_Archive archive, char * buf)
|
Result buf_to_file(u32 size, FS_Path path, FS_Archive archive, char *buf)
|
||||||
{
|
{
|
||||||
Handle handle;
|
Handle handle;
|
||||||
Result res = 0;
|
Result res = 0;
|
||||||
@@ -372,7 +197,7 @@ Result buf_to_file(u32 size, FS_Path path, FS_Archive archive, char * buf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 decompress_lz_file(FS_Path file_name, FS_Archive archive, char ** buf)
|
u32 decompress_lz_file(FS_Path file_name, FS_Archive archive, char **buf)
|
||||||
{
|
{
|
||||||
Handle handle;
|
Handle handle;
|
||||||
Result res = 0;
|
Result res = 0;
|
||||||
@@ -383,7 +208,7 @@ u32 decompress_lz_file(FS_Path file_name, FS_Archive archive, char ** buf)
|
|||||||
u64 size;
|
u64 size;
|
||||||
FSFILE_GetSize(handle, &size);
|
FSFILE_GetSize(handle, &size);
|
||||||
|
|
||||||
char * temp_buf = NULL;
|
char *temp_buf = NULL;
|
||||||
|
|
||||||
if(size != 0)
|
if(size != 0)
|
||||||
{
|
{
|
||||||
@@ -477,9 +302,9 @@ u32 decompress_lz_file(FS_Path file_name, FS_Archive archive, char ** buf)
|
|||||||
// if i figure out a dynamic programming algorithm which ends up being significantly
|
// if i figure out a dynamic programming algorithm which ends up being significantly
|
||||||
// faster. Otherwise, I think this is probably a fine implementation.
|
// faster. Otherwise, I think this is probably a fine implementation.
|
||||||
|
|
||||||
u32 compress_lz_file_fast(FS_Path path, FS_Archive archive, char * in_buf, u32 size)
|
u32 compress_lz_file_fast(FS_Path path, FS_Archive archive, char *in_buf, u32 size)
|
||||||
{
|
{
|
||||||
char * output_buf = calloc(1, size * 2);
|
char *output_buf = calloc(1, size * 2);
|
||||||
u32 output_size = 0;
|
u32 output_size = 0;
|
||||||
u32 mask_pos = 0;
|
u32 mask_pos = 0;
|
||||||
u32 bytes_processed = 0;
|
u32 bytes_processed = 0;
|
||||||
@@ -522,41 +347,17 @@ void remake_file(FS_Path path, FS_Archive archive, u32 size)
|
|||||||
FSFILE_Close(handle);
|
FSFILE_Close(handle);
|
||||||
FSUSER_DeleteFile(archive, path);
|
FSUSER_DeleteFile(archive, path);
|
||||||
}
|
}
|
||||||
Result res = FSUSER_CreateFile(archive, path, 0, size);
|
FSUSER_CreateFile(archive, path, 0, size);
|
||||||
DEBUG("Remake file res: 0x%08lx\n", res);
|
char *buf = calloc(size, 1);
|
||||||
char * buf = calloc(size, 1);
|
buf_to_file(size, path, archive, buf);
|
||||||
if (buf == NULL)
|
free(buf);
|
||||||
{
|
|
||||||
DEBUG("out of memory - not overwriting file?\n");
|
|
||||||
} else {
|
|
||||||
buf_to_file(size, path, archive, buf);
|
|
||||||
free(buf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result zero_handle_memeasy(Handle handle)
|
static SwkbdCallbackResult fat32filter(void *user, const char **ppMessage, const char *text, size_t textlen)
|
||||||
{
|
|
||||||
u64 size = 0;
|
|
||||||
u64 cur = 0;
|
|
||||||
FSFILE_GetSize(handle, &size);
|
|
||||||
char *zero_buf = calloc(1, 0x10000);
|
|
||||||
while (size > 0x10000)
|
|
||||||
{
|
|
||||||
FSFILE_Write(handle, NULL, cur, &zero_buf, 0x10000, 0);
|
|
||||||
cur += 0x10000;
|
|
||||||
size -= 0x10000;
|
|
||||||
}
|
|
||||||
FSFILE_Write(handle, NULL, cur, &zero_buf, size, 0);
|
|
||||||
free(zero_buf);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SwkbdCallbackResult fat32filter(void * user, const char ** ppMessage, const char * text, size_t textlen)
|
|
||||||
{
|
{
|
||||||
(void)textlen;
|
(void)textlen;
|
||||||
(void)user;
|
(void)user;
|
||||||
|
*ppMessage = "Input must not contain:\n" ILLEGAL_CHARS;
|
||||||
*ppMessage = language.fs.illegal_input;
|
|
||||||
if(strpbrk(text, ILLEGAL_CHARS))
|
if(strpbrk(text, ILLEGAL_CHARS))
|
||||||
{
|
{
|
||||||
DEBUG("illegal filename: %s\n", text);
|
DEBUG("illegal filename: %s\n", text);
|
||||||
@@ -567,26 +368,16 @@ static SwkbdCallbackResult fat32filter(void * user, const char ** ppMessage, con
|
|||||||
}
|
}
|
||||||
|
|
||||||
// assumes the input buffer is a ZIP. if it isn't, why are you calling this?
|
// assumes the input buffer is a ZIP. if it isn't, why are you calling this?
|
||||||
void save_zip_to_sd(char * filename, u32 size, char * buf, RemoteMode mode)
|
void save_zip_to_sd(char * filename, u32 size, char * buf, EntryMode mode)
|
||||||
{
|
{
|
||||||
static char path_to_file[32761]; // FAT32 paths can be quite long.
|
static char path_to_file[32761]; // FAT32 paths can be quite long.
|
||||||
const int max_chars = 250;
|
const int max_chars = 250;
|
||||||
char new_filename[max_chars + 5]; // .zip + \0
|
char new_filename[max_chars + 5]; // .zip + \0
|
||||||
renamed:
|
renamed:
|
||||||
char * curr_filename;
|
sprintf(path_to_file, "%s%s", main_paths[mode], filename);
|
||||||
if (mode == REMOTE_MODE_BADGES)
|
|
||||||
{
|
|
||||||
sprintf(path_to_file, "%sThemePlaza Badges/%s", main_paths[REMOTE_MODE_BADGES], filename);
|
|
||||||
DEBUG("Remote mode badges! Saving to %s/\n", path_to_file);
|
|
||||||
curr_filename = path_to_file + strlen(main_paths[REMOTE_MODE_BADGES]) + strlen("ThemePlaza Badges/");
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
sprintf(path_to_file, "%s%s", main_paths[mode], filename);
|
|
||||||
curr_filename = path_to_file + strlen(main_paths[mode]);
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG("Filtering out illegal chars...\n");
|
|
||||||
// filter out characters illegal in FAT32 filenames
|
// filter out characters illegal in FAT32 filenames
|
||||||
|
char * curr_filename = strrchr(path_to_file, '/') + 1;
|
||||||
char * illegal_char = curr_filename;
|
char * illegal_char = curr_filename;
|
||||||
while ((illegal_char = strpbrk(illegal_char, ILLEGAL_CHARS)))
|
while ((illegal_char = strpbrk(illegal_char, ILLEGAL_CHARS)))
|
||||||
{
|
{
|
||||||
@@ -606,16 +397,13 @@ renamed:
|
|||||||
*illegal_char = '-';
|
*illegal_char = '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("Checking extension\n");
|
|
||||||
// ensure the extension is .zip
|
// ensure the extension is .zip
|
||||||
char * extension = strrchr(path_to_file, '.');
|
char * extension = strrchr(path_to_file, '.');
|
||||||
if (extension == NULL || strcmp(extension, ".zip"))
|
if (extension == NULL || strcmp(extension, ".zip"))
|
||||||
strcat(path_to_file, ".zip");
|
strcat(path_to_file, ".zip");
|
||||||
|
|
||||||
DEBUG("path: %s\n", path_to_file);
|
DEBUG("path: %s\n", path_to_file);
|
||||||
u16 utf16path[0x106] = {0};
|
FS_Path path = fsMakePath(PATH_ASCII, path_to_file);
|
||||||
utf8_to_utf16(utf16path, (u8 *) path_to_file, 0x106);
|
|
||||||
FS_Path path = fsMakePath(PATH_UTF16, utf16path);
|
|
||||||
|
|
||||||
// check if file already exists, and if it does, prompt the user
|
// check if file already exists, and if it does, prompt the user
|
||||||
// to overwrite or change name (or exit)
|
// to overwrite or change name (or exit)
|
||||||
@@ -629,12 +417,12 @@ renamed:
|
|||||||
SwkbdState swkbd;
|
SwkbdState swkbd;
|
||||||
|
|
||||||
swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 3, max_chars / 2);
|
swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 3, max_chars / 2);
|
||||||
swkbdSetHintText(&swkbd, language.fs.new_or_overwrite);
|
swkbdSetHintText(&swkbd, "Choose a new filename or tap Overwrite");
|
||||||
swkbdSetFeatures(&swkbd, SWKBD_PREDICTIVE_INPUT | SWKBD_DARKEN_TOP_SCREEN);
|
swkbdSetFeatures(&swkbd, SWKBD_PREDICTIVE_INPUT | SWKBD_DARKEN_TOP_SCREEN);
|
||||||
|
|
||||||
swkbdSetButton(&swkbd, SWKBD_BUTTON_LEFT, language.fs.cancel, false);
|
swkbdSetButton(&swkbd, SWKBD_BUTTON_LEFT, "Cancel", false);
|
||||||
swkbdSetButton(&swkbd, SWKBD_BUTTON_MIDDLE, language.fs.overwrite, false);
|
swkbdSetButton(&swkbd, SWKBD_BUTTON_MIDDLE, "Overwrite", false);
|
||||||
swkbdSetButton(&swkbd, SWKBD_BUTTON_RIGHT, language.fs.rename, true);
|
swkbdSetButton(&swkbd, SWKBD_BUTTON_RIGHT, "Rename", true);
|
||||||
swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY_NOTBLANK, SWKBD_FILTER_CALLBACK, -1);
|
swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY_NOTBLANK, SWKBD_FILTER_CALLBACK, -1);
|
||||||
swkbdSetFilterCallback(&swkbd, &fat32filter, NULL);
|
swkbdSetFilterCallback(&swkbd, &fat32filter, NULL);
|
||||||
|
|
||||||
@@ -657,18 +445,18 @@ renamed:
|
|||||||
return;
|
return;
|
||||||
case SWKBD_BUTTON_NONE:
|
case SWKBD_BUTTON_NONE:
|
||||||
DEBUG("SWKBD broke wtf??? :- %x\n", swkbdGetResult(&swkbd));
|
DEBUG("SWKBD broke wtf??? :- %x\n", swkbdGetResult(&swkbd));
|
||||||
return throw_error(language.fs.swkbd_fail, ERROR_LEVEL_WARNING);
|
return throw_error("???\nTry a USB keyboard", ERROR_LEVEL_WARNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (res == (long)0xC86044D2)
|
else if (res == (long)0xC86044D2)
|
||||||
{
|
{
|
||||||
DEBUG("SD card is full\n");
|
DEBUG("SD card is full\n");
|
||||||
return throw_error(language.fs.sd_full, ERROR_LEVEL_WARNING);
|
return throw_error("SD card is full.\nDelete some themes to make space.", ERROR_LEVEL_WARNING);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUG("error: %lx\n", res);
|
DEBUG("error: %lx\n", res);
|
||||||
return throw_error(language.fs.fs_error, ERROR_LEVEL_ERROR);
|
return throw_error("FS Error:\nGet a new SD card.", ERROR_LEVEL_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
550
source/loading.c
@@ -29,53 +29,197 @@
|
|||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
#include "music.h"
|
#include "music.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "conversion.h"
|
|
||||||
#include "ui_strings.h"
|
|
||||||
|
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
|
|
||||||
void copy_texture_data(C3D_Tex * texture, const u16 * src, const Entry_Icon_s * current_icon)
|
void delete_entry(Entry_s * entry, bool is_file)
|
||||||
{
|
{
|
||||||
// pointer to rgb565, offset by the number of rows and columns specified by current_icon
|
if(is_file)
|
||||||
// (reminder that this is z order curve storage)
|
FSUSER_DeleteFile(ArchiveSD, fsMakePath(PATH_UTF16, entry->path));
|
||||||
u16 * dest = ((u16 *)texture->data) + (current_icon->y * texture->width) + (current_icon->x * 8);
|
else
|
||||||
for (int j = 0; j < 48; j += 8)
|
FSUSER_DeleteDirectoryRecursively(ArchiveSD, fsMakePath(PATH_UTF16, entry->path));
|
||||||
{
|
|
||||||
memcpy(dest, src, 48 * 8 * sizeof(u16));
|
|
||||||
src += 48 * 8;
|
|
||||||
dest += texture->width * 8;
|
|
||||||
}
|
|
||||||
GSPGPU_InvalidateDataCache(texture->data, texture->size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_smdh(Icon_s * icon, Entry_s * entry, const u16 * fallback_name)
|
u32 load_data(char * filename, Entry_s entry, char ** buf)
|
||||||
{
|
{
|
||||||
|
if(entry.is_zip)
|
||||||
|
{
|
||||||
|
return zip_file_to_buf(filename+1, entry.path, buf); //the first character will always be '/' because of the other case
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
u16 path[0x106] = {0};
|
||||||
|
strucat(path, entry.path);
|
||||||
|
struacat(path, filename);
|
||||||
|
|
||||||
|
return file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function taken and adapted from https://github.com/BernardoGiordano/Checkpoint/blob/master/3ds/source/title.cpp
|
||||||
|
C2D_Image * loadTextureIcon(Icon_s *icon)
|
||||||
|
{
|
||||||
|
if(icon == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
C2D_Image * image = calloc(1, sizeof(C2D_Image));
|
||||||
|
C3D_Tex* tex = malloc(sizeof(C3D_Tex));
|
||||||
|
static const Tex3DS_SubTexture subt3x = { 48, 48, 0.0f, 48/64.0f, 48/64.0f, 0.0f };
|
||||||
|
image->tex = tex;
|
||||||
|
image->subtex = &subt3x;
|
||||||
|
C3D_TexInit(image->tex, 64, 64, GPU_RGB565);
|
||||||
|
|
||||||
|
u16* dest = (u16*)image->tex->data + (64-48)*64;
|
||||||
|
u16* src = icon->big_icon;
|
||||||
|
for (int j = 0; j < 48; j += 8)
|
||||||
|
{
|
||||||
|
memcpy(dest, src, 48*8*sizeof(u16));
|
||||||
|
src += 48*8;
|
||||||
|
dest += 64*8;
|
||||||
|
}
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_smdh(Icon_s *icon, Entry_s * entry, const u16 * fallback_name)
|
||||||
|
{
|
||||||
|
|
||||||
if(icon == NULL)
|
if(icon == NULL)
|
||||||
{
|
{
|
||||||
memcpy(entry->name, fallback_name, 0x80);
|
memcpy(entry->name, fallback_name, 0x80);
|
||||||
utf8_to_utf16(entry->desc, (u8 *)"No description", 0x100);
|
utf8_to_utf16(entry->desc, (u8*)"No description", 0x100);
|
||||||
utf8_to_utf16(entry->author, (u8 *)"Unknown author", 0x80);
|
utf8_to_utf16(entry->author, (u8*)"Unknown author", 0x80);
|
||||||
entry->placeholder_color = C2D_Color32(rand() % 255, rand() % 255, rand() % 255, 255);
|
entry->placeholder_color = C2D_Color32(rand() % 255, rand() % 255, rand() % 255, 255);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(entry->name, icon->name, 0x40 * sizeof(u16));
|
|
||||||
memcpy(entry->desc, icon->desc, 0x80 * sizeof(u16));
|
memcpy(entry->name, icon->name, 0x40*sizeof(u16));
|
||||||
memcpy(entry->author, icon->author, 0x40 * sizeof(u16));
|
memcpy(entry->desc, icon->desc, 0x80*sizeof(u16));
|
||||||
entry->placeholder_color = 0;
|
memcpy(entry->author, icon->author, 0x40*sizeof(u16));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Icon_s * load_entry_icon(const Entry_s * entry)
|
static C2D_Image * load_entry_icon(Entry_s entry)
|
||||||
{
|
{
|
||||||
char * info_buffer = NULL;
|
char *info_buffer = NULL;
|
||||||
u32 size = load_data("/info.smdh", entry, &info_buffer);
|
u64 size = load_data("/info.smdh", entry, &info_buffer);
|
||||||
if(size != sizeof(Icon_s))
|
if(!size) return NULL;
|
||||||
|
|
||||||
|
Icon_s * smdh = (Icon_s *)info_buffer;
|
||||||
|
C2D_Image* out = loadTextureIcon(smdh);
|
||||||
|
free(info_buffer);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef int (*sort_comparator)(const void *, const void *);
|
||||||
|
static int compare_entries_by_name(const void * a, const void * b)
|
||||||
|
{
|
||||||
|
Entry_s *entry_a = (Entry_s *)a;
|
||||||
|
Entry_s *entry_b = (Entry_s *)b;
|
||||||
|
|
||||||
|
return memcmp(entry_a->name, entry_b->name, 0x40*sizeof(u16));
|
||||||
|
}
|
||||||
|
static int compare_entries_by_author(const void * a, const void * b)
|
||||||
|
{
|
||||||
|
Entry_s *entry_a = (Entry_s *)a;
|
||||||
|
Entry_s *entry_b = (Entry_s *)b;
|
||||||
|
|
||||||
|
return memcmp(entry_a->author, entry_b->author, 0x40*sizeof(u16));
|
||||||
|
}
|
||||||
|
static int compare_entries_by_filename(const void * a, const void * b)
|
||||||
|
{
|
||||||
|
Entry_s *entry_a = (Entry_s *)a;
|
||||||
|
Entry_s *entry_b = (Entry_s *)b;
|
||||||
|
|
||||||
|
return memcmp(entry_a->path, entry_b->path, 0x106*sizeof(u16));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sort_list(Entry_List_s * list, sort_comparator compare_entries)
|
||||||
|
{
|
||||||
|
if(list->entries != NULL && list->entries != NULL)
|
||||||
|
qsort(list->entries, list->entries_count, sizeof(Entry_s), compare_entries); //alphabet sort
|
||||||
|
}
|
||||||
|
|
||||||
|
void sort_by_name(Entry_List_s * list)
|
||||||
|
{
|
||||||
|
sort_list(list, compare_entries_by_name);
|
||||||
|
list->current_sort = SORT_NAME;
|
||||||
|
}
|
||||||
|
void sort_by_author(Entry_List_s * list)
|
||||||
|
{
|
||||||
|
sort_list(list, compare_entries_by_author);
|
||||||
|
list->current_sort = SORT_AUTHOR;
|
||||||
|
}
|
||||||
|
void sort_by_filename(Entry_List_s * list)
|
||||||
|
{
|
||||||
|
sort_list(list, compare_entries_by_filename);
|
||||||
|
list->current_sort = SORT_PATH;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result load_entries(const char * loading_path, Entry_List_s * list)
|
||||||
|
{
|
||||||
|
Handle dir_handle;
|
||||||
|
Result res = FSUSER_OpenDirectory(&dir_handle, ArchiveSD, fsMakePath(PATH_ASCII, loading_path));
|
||||||
|
if(R_FAILED(res))
|
||||||
{
|
{
|
||||||
free(info_buffer);
|
DEBUG("Failed to open folder: %s\n", loading_path);
|
||||||
return NULL;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (Icon_s *)info_buffer;
|
u32 entries_read = 1;
|
||||||
|
|
||||||
|
while(entries_read)
|
||||||
|
{
|
||||||
|
FS_DirectoryEntry dir_entry = {0};
|
||||||
|
res = FSDIR_Read(dir_handle, &entries_read, 1, &dir_entry);
|
||||||
|
if(R_FAILED(res) || entries_read == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(!(dir_entry.attributes & FS_ATTRIBUTE_DIRECTORY) && strcmp(dir_entry.shortExt, "ZIP"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
u16 path[0x106] = {0};
|
||||||
|
struacat(path, loading_path);
|
||||||
|
strucat(path, dir_entry.name);
|
||||||
|
char * buf = NULL;
|
||||||
|
|
||||||
|
if (!strcmp(dir_entry.shortExt, "ZIP"))
|
||||||
|
{
|
||||||
|
zip_file_to_buf("info.smdh", path, &buf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const ssize_t len = strulen(path, 0x106);
|
||||||
|
struacat(path, "/info.smdh");
|
||||||
|
file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &buf);
|
||||||
|
memset(&path[len], 0, (0x106 - len) * sizeof(u16));
|
||||||
|
}
|
||||||
|
|
||||||
|
list->entries_count++;
|
||||||
|
Entry_s * new_list = realloc(list->entries, list->entries_count * sizeof(Entry_s));
|
||||||
|
if(new_list == NULL)
|
||||||
|
{
|
||||||
|
// out of memory: still allow use of currently loaded entries.
|
||||||
|
// Many things might die, depending on the heap layout after
|
||||||
|
list->entries_count--;
|
||||||
|
free(buf);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
list->entries = new_list;
|
||||||
|
|
||||||
|
Entry_s * current_entry = &(list->entries[list->entries_count-1]);
|
||||||
|
memset(current_entry, 0, sizeof(Entry_s));
|
||||||
|
parse_smdh((Icon_s *)buf, current_entry, dir_entry.name);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
memcpy(current_entry->path, path, 0x106 * sizeof(u16));
|
||||||
|
current_entry->is_zip = !strcmp(dir_entry.shortExt, "ZIP");
|
||||||
|
}
|
||||||
|
|
||||||
|
FSDIR_Close(dir_handle);
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_icons_first(Entry_List_s * list, bool silent)
|
void load_icons_first(Entry_List_s * list, bool silent)
|
||||||
@@ -87,7 +231,7 @@ void load_icons_first(Entry_List_s * list, bool silent)
|
|||||||
|
|
||||||
int starti = 0, endi = 0;
|
int starti = 0, endi = 0;
|
||||||
|
|
||||||
if(list->entries_count <= list->entries_loaded * ICONS_OFFSET_AMOUNT)
|
if(list->entries_count <= list->entries_loaded*ICONS_OFFSET_AMOUNT)
|
||||||
{
|
{
|
||||||
DEBUG("small load\n");
|
DEBUG("small load\n");
|
||||||
// if the list is one that doesnt need swapping, load everything at once
|
// if the list is one that doesnt need swapping, load everything at once
|
||||||
@@ -97,44 +241,40 @@ void load_icons_first(Entry_List_s * list, bool silent)
|
|||||||
{
|
{
|
||||||
DEBUG("extended load\n");
|
DEBUG("extended load\n");
|
||||||
// otherwise, load around to prepare for swapping
|
// otherwise, load around to prepare for swapping
|
||||||
starti = list->scroll - list->entries_loaded * ICONS_VISIBLE;
|
starti = list->scroll - list->entries_loaded*ICONS_VISIBLE;
|
||||||
endi = starti + list->entries_loaded * ICONS_OFFSET_AMOUNT;
|
endi = starti + list->entries_loaded*ICONS_OFFSET_AMOUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int entry_i = starti, icon_i = 0; entry_i < endi; ++entry_i, ++icon_i)
|
list->icons = calloc(endi-starti, sizeof(C2D_Image*));
|
||||||
|
|
||||||
|
C2D_Image ** icons = list->icons;
|
||||||
|
|
||||||
|
for(int i = starti; i < endi; i++)
|
||||||
{
|
{
|
||||||
if(!silent)
|
if(!silent)
|
||||||
draw_loading_bar(icon_i, endi-starti, INSTALL_LOADING_ICONS);
|
draw_loading_bar(i - starti, endi-starti, INSTALL_LOADING_ICONS);
|
||||||
|
|
||||||
int offset = entry_i;
|
int offset = i;
|
||||||
if(offset < 0)
|
if(offset < 0)
|
||||||
offset += list->entries_count;
|
offset += list->entries_count;
|
||||||
if(offset >= list->entries_count)
|
if(offset >= list->entries_count)
|
||||||
offset -= list->entries_count;
|
offset -= list->entries_count;
|
||||||
|
|
||||||
Entry_s * const current_entry = &list->entries[offset];
|
Entry_s current_entry = list->entries[offset];
|
||||||
Icon_s * const smdh = load_entry_icon(current_entry);
|
icons[i-starti] = load_entry_icon(current_entry);
|
||||||
if(smdh != NULL)
|
|
||||||
{
|
|
||||||
if(current_entry->placeholder_color == 0)
|
|
||||||
parse_smdh(smdh, current_entry, current_entry->path + strlen(list->loading_path));
|
|
||||||
copy_texture_data(&list->icons_texture, smdh->big_icon, &list->icons_info[icon_i]);
|
|
||||||
free(smdh);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reverse(Entry_Icon_s a[], int sz) {
|
static void reverse(C2D_Image * a[], int sz) {
|
||||||
int i, j;
|
int i, j;
|
||||||
Entry_Icon_s tmp;
|
|
||||||
for (i = 0, j = sz; i < j; i++, j--) {
|
for (i = 0, j = sz; i < j; i++, j--) {
|
||||||
memcpy(&tmp, &a[i], sizeof(Entry_Icon_s));
|
C2D_Image * tmp = a[i];
|
||||||
memcpy(&a[i], &a[j], sizeof(Entry_Icon_s));
|
a[i] = a[j];
|
||||||
memcpy(&a[j], &tmp, sizeof(Entry_Icon_s));
|
a[j] = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rotate(Entry_Icon_s array[], int size, int amt) {
|
static void rotate(C2D_Image * array[], int size, int amt) {
|
||||||
if (amt < 0)
|
if (amt < 0)
|
||||||
amt = size + amt;
|
amt = size + amt;
|
||||||
reverse(array, size-amt-1);
|
reverse(array, size-amt-1);
|
||||||
@@ -148,48 +288,47 @@ void handle_scrolling(Entry_List_s * list)
|
|||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
if(list->entries_count > list->entries_loaded)
|
if(list->entries_count > list->entries_loaded)
|
||||||
{
|
{
|
||||||
int change = 0;
|
for(int i = 0; i < list->entries_count; i++)
|
||||||
|
{
|
||||||
|
int change = 0;
|
||||||
|
|
||||||
if(list->entries_count > list->entries_loaded * 2 && list->previous_scroll < list->entries_loaded && list->selected_entry >= list->entries_count - list->entries_loaded)
|
if(list->entries_count > list->entries_loaded*2 && list->previous_scroll < list->entries_loaded && list->selected_entry >= list->entries_count - list->entries_loaded)
|
||||||
{
|
{
|
||||||
list->scroll = list->entries_count - list->entries_loaded;
|
list->scroll = list->entries_count - list->entries_loaded;
|
||||||
}
|
}
|
||||||
else if(list->entries_count > list->entries_loaded * 2 && list->selected_entry < list->entries_loaded && list->previous_selected >= list->entries_count - list->entries_loaded)
|
else if(list->entries_count > list->entries_loaded*2 && list->selected_entry < list->entries_loaded && list->previous_selected >= list->entries_count - list->entries_loaded)
|
||||||
{
|
{
|
||||||
list->scroll = 0;
|
list->scroll = 0;
|
||||||
}
|
}
|
||||||
else if(list->selected_entry == list->previous_selected+1 && list->selected_entry == list->scroll+list->entries_loaded)
|
else if(list->selected_entry == list->previous_selected+1 && list->selected_entry == list->scroll+list->entries_loaded)
|
||||||
{
|
{
|
||||||
change = 1;
|
change = 1;
|
||||||
}
|
}
|
||||||
else if(list->selected_entry == list->previous_selected-1 && list->selected_entry == list->scroll-1)
|
else if(list->selected_entry == list->previous_selected-1 && list->selected_entry == list->scroll-1)
|
||||||
{
|
{
|
||||||
change = -1;
|
change = -1;
|
||||||
}
|
}
|
||||||
else if(list->selected_entry == list->previous_selected+list->entries_loaded)
|
else if(list->selected_entry == list->previous_selected+list->entries_loaded || list->selected_entry >= list->scroll + list->entries_loaded)
|
||||||
{
|
{
|
||||||
change = list->entries_loaded;
|
change = list->entries_loaded;
|
||||||
}
|
}
|
||||||
else if(list->selected_entry == list->previous_selected-list->entries_loaded)
|
else if(list->selected_entry == list->previous_selected-list->entries_loaded || list->selected_entry < list->scroll)
|
||||||
{
|
{
|
||||||
change = -list->entries_loaded;
|
change = -list->entries_loaded;
|
||||||
}
|
}
|
||||||
else if(list->selected_entry >= list->scroll + list->entries_loaded || list->selected_entry < list->scroll)
|
|
||||||
{
|
|
||||||
change = list->selected_entry - list->scroll;
|
|
||||||
}
|
|
||||||
|
|
||||||
list->scroll += change;
|
list->scroll += change;
|
||||||
|
|
||||||
if(list->scroll < 0)
|
if(list->scroll < 0)
|
||||||
list->scroll = 0;
|
list->scroll = 0;
|
||||||
else if(list->scroll > list->entries_count - list->entries_loaded)
|
else if(list->scroll > list->entries_count - list->entries_loaded)
|
||||||
list->scroll = list->entries_count - list->entries_loaded;
|
list->scroll = list->entries_count - list->entries_loaded;
|
||||||
|
|
||||||
if(!change)
|
if(!change)
|
||||||
list->previous_selected = list->selected_entry;
|
list->previous_selected = list->selected_entry;
|
||||||
else
|
else
|
||||||
list->previous_selected += change;
|
list->previous_selected += change;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
}
|
}
|
||||||
@@ -201,13 +340,13 @@ static bool load_icons(Entry_List_s * current_list, Handle mutex)
|
|||||||
|
|
||||||
handle_scrolling(current_list);
|
handle_scrolling(current_list);
|
||||||
|
|
||||||
if(current_list->entries_count <= current_list->entries_loaded * ICONS_OFFSET_AMOUNT || current_list->previous_scroll == current_list->scroll)
|
if(current_list->entries_count <= current_list->entries_loaded*ICONS_OFFSET_AMOUNT || current_list->previous_scroll == current_list->scroll)
|
||||||
return false; // return if the list is one that doesnt need swapping, or if nothing changed
|
return false; // return if the list is one that doesnt need swapping, or if nothing changed
|
||||||
|
|
||||||
#define SIGN(x) (x > 0 ? 1 : ((x < 0) ? -1 : 0))
|
#define SIGN(x) (x > 0 ? 1 : ((x < 0) ? -1 : 0))
|
||||||
|
|
||||||
int delta = current_list->scroll - current_list->previous_scroll;
|
int delta = current_list->scroll - current_list->previous_scroll;
|
||||||
if(abs(delta) >= current_list->entries_count - current_list->entries_loaded * (ICONS_OFFSET_AMOUNT-1))
|
if(abs(delta) >= current_list->entries_count - current_list->entries_loaded*(ICONS_OFFSET_AMOUNT-1))
|
||||||
delta = -SIGN(delta) * (current_list->entries_count - abs(delta));
|
delta = -SIGN(delta) * (current_list->entries_count - abs(delta));
|
||||||
|
|
||||||
int starti = current_list->scroll;
|
int starti = current_list->scroll;
|
||||||
@@ -220,28 +359,28 @@ static bool load_icons(Entry_List_s * current_list, Handle mutex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ctr = 0;
|
int ctr = 0;
|
||||||
Entry_s ** const entries = calloc(abs(delta), sizeof(Entry_s *));
|
Entry_s ** entries = calloc(abs(delta), sizeof(Entry_s *));
|
||||||
int * const indexes = calloc(abs(delta), sizeof(int));
|
int * indexes = calloc(abs(delta), sizeof(int));
|
||||||
bool released = false;
|
bool released = false;
|
||||||
|
|
||||||
Entry_Icon_s * const icons = current_list->icons_info;
|
C2D_Image ** icons = current_list->icons;
|
||||||
|
|
||||||
for(int i = starti; i != endi; i++, ctr++)
|
for(int i = starti; i != endi; i++, ctr++)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int offset = i;
|
int offset = i;
|
||||||
|
|
||||||
rotate(icons, ICONS_OFFSET_AMOUNT * current_list->entries_loaded, -SIGN(delta));
|
rotate(icons, ICONS_OFFSET_AMOUNT*current_list->entries_loaded, -1*SIGN(delta));
|
||||||
|
|
||||||
if(delta > 0)
|
if(delta > 0)
|
||||||
{
|
{
|
||||||
index = current_list->entries_loaded * ICONS_OFFSET_AMOUNT - delta + i - starti;
|
index = current_list->entries_loaded*ICONS_OFFSET_AMOUNT - delta + i - starti;
|
||||||
offset += current_list->entries_loaded * ICONS_UNDER - delta;
|
offset += current_list->entries_loaded*ICONS_UNDER - delta;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
index = 0 - delta - 1 + i - starti;
|
index = 0 - delta - 1 + i - starti;
|
||||||
offset -= current_list->entries_loaded * ICONS_VISIBLE;
|
offset -= current_list->entries_loaded*ICONS_VISIBLE;
|
||||||
i -= 2; //i-- twice to counter the i++, needed only for this case
|
i -= 2; //i-- twice to counter the i++, needed only for this case
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +395,7 @@ static bool load_icons(Entry_List_s * current_list, Handle mutex)
|
|||||||
|
|
||||||
#undef SIGN
|
#undef SIGN
|
||||||
|
|
||||||
if(abs(delta) <= current_list->entries_loaded)
|
if(abs(delta) < 4)
|
||||||
{
|
{
|
||||||
svcReleaseMutex(mutex);
|
svcReleaseMutex(mutex);
|
||||||
released = true;
|
released = true;
|
||||||
@@ -267,19 +406,19 @@ static bool load_icons(Entry_List_s * current_list, Handle mutex)
|
|||||||
endi = abs(delta);
|
endi = abs(delta);
|
||||||
for(int i = starti; i < endi; i++)
|
for(int i = starti; i < endi; i++)
|
||||||
{
|
{
|
||||||
Entry_s * const current_entry = entries[i];
|
Entry_s * current_entry = entries[i];
|
||||||
const int index = indexes[i];
|
int index = indexes[i];
|
||||||
const Entry_Icon_s * const current_icon = &icons[index];
|
|
||||||
|
|
||||||
Icon_s * const smdh = load_entry_icon(current_entry);
|
C2D_Image * image = icons[index];
|
||||||
if(smdh != NULL)
|
if (icons[index] != NULL)
|
||||||
{
|
{
|
||||||
if(current_entry->placeholder_color == 0)
|
C3D_TexDelete(image->tex);
|
||||||
parse_smdh(smdh, current_entry, current_entry->path + strlen(current_list->loading_path));
|
free(image->tex);
|
||||||
copy_texture_data(¤t_list->icons_texture, smdh->big_icon, current_icon);
|
free(image);
|
||||||
free(smdh);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
icons[index] = load_entry_icon(*current_entry);
|
||||||
|
|
||||||
if(!released && i > endi/2)
|
if(!released && i > endi/2)
|
||||||
{
|
{
|
||||||
svcReleaseMutex(mutex);
|
svcReleaseMutex(mutex);
|
||||||
@@ -299,23 +438,92 @@ void load_icons_thread(void * void_arg)
|
|||||||
{
|
{
|
||||||
Thread_Arg_s * arg = (Thread_Arg_s *)void_arg;
|
Thread_Arg_s * arg = (Thread_Arg_s *)void_arg;
|
||||||
Handle mutex = *(Handle *)arg->thread_arg[1];
|
Handle mutex = *(Handle *)arg->thread_arg[1];
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
svcWaitSynchronization(mutex, U64_MAX);
|
svcWaitSynchronization(mutex, U64_MAX);
|
||||||
Entry_List_s * const current_list = *(Entry_List_s ** volatile)arg->thread_arg[0];
|
volatile Entry_List_s * current_list = *(volatile Entry_List_s **)arg->thread_arg[0];
|
||||||
const bool released = load_icons(current_list, mutex);
|
bool released = load_icons((Entry_List_s *)current_list, mutex);
|
||||||
if(!released)
|
if(!released)
|
||||||
svcReleaseMutex(mutex);
|
svcReleaseMutex(mutex);
|
||||||
} while(arg->run_thread);
|
}
|
||||||
|
while(arg->run_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool load_preview_from_buffer(char * row_pointers, u32 size, C2D_Image * preview_image, int * preview_offset, int height)
|
bool load_preview_from_buffer(void * buf, u32 size, C2D_Image * preview_image, int * preview_offset)
|
||||||
{
|
{
|
||||||
int width = (uint32_t)((size / 4) / height);
|
if(size < 8 || png_sig_cmp(buf, 0, 8))
|
||||||
float tex_height = height > 512.0f ? 1024.0f : 512.0f;
|
{
|
||||||
|
throw_error("Invalid preview.png", ERROR_LEVEL_WARNING);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
png_infop info = png_create_info_struct(png);
|
||||||
|
|
||||||
|
if(setjmp(png_jmpbuf(png)))
|
||||||
|
{
|
||||||
|
png_destroy_read_struct(&png, &info, NULL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE * fp = fmemopen(buf, size, "rb");
|
||||||
|
|
||||||
|
png_init_io(png, fp);
|
||||||
|
png_read_info(png, info);
|
||||||
|
|
||||||
|
int width = png_get_image_width(png, info);
|
||||||
|
int height = png_get_image_height(png, info);
|
||||||
|
|
||||||
|
png_byte color_type = png_get_color_type(png, info);
|
||||||
|
png_byte bit_depth = png_get_bit_depth(png, info);
|
||||||
|
|
||||||
|
// Read any color_type into 8bit depth, ABGR format.
|
||||||
|
// See http://www.libpng.org/pub/png/libpng-manual.txt
|
||||||
|
|
||||||
|
if(bit_depth == 16)
|
||||||
|
png_set_strip_16(png);
|
||||||
|
|
||||||
|
if(color_type == PNG_COLOR_TYPE_PALETTE)
|
||||||
|
png_set_palette_to_rgb(png);
|
||||||
|
|
||||||
|
// PNG_COLOR_TYPE_GRAY_ALPHA is always 8 or 16bit depth.
|
||||||
|
if(color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||||
|
png_set_expand_gray_1_2_4_to_8(png);
|
||||||
|
|
||||||
|
if(png_get_valid(png, info, PNG_INFO_tRNS))
|
||||||
|
png_set_tRNS_to_alpha(png);
|
||||||
|
|
||||||
|
// These color_type don't have an alpha channel then fill it with 0xff.
|
||||||
|
if(color_type == PNG_COLOR_TYPE_RGB ||
|
||||||
|
color_type == PNG_COLOR_TYPE_GRAY ||
|
||||||
|
color_type == PNG_COLOR_TYPE_PALETTE)
|
||||||
|
png_set_add_alpha(png, 0xFF, PNG_FILLER_BEFORE);
|
||||||
|
|
||||||
|
if(color_type == PNG_COLOR_TYPE_GRAY ||
|
||||||
|
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||||
|
png_set_gray_to_rgb(png);
|
||||||
|
|
||||||
|
//output ABGR
|
||||||
|
png_set_bgr(png);
|
||||||
|
png_set_swap_alpha(png);
|
||||||
|
|
||||||
|
png_read_update_info(png, info);
|
||||||
|
|
||||||
|
png_bytep * row_pointers = malloc(sizeof(png_bytep) * height);
|
||||||
|
for(int y = 0; y < height; y++) {
|
||||||
|
row_pointers[y] = (png_byte*)malloc(png_get_rowbytes(png,info));
|
||||||
|
}
|
||||||
|
|
||||||
|
png_read_image(png, row_pointers);
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
png_destroy_read_struct(&png, &info, NULL);
|
||||||
|
|
||||||
|
|
||||||
free_preview(*preview_image);
|
free_preview(*preview_image);
|
||||||
|
|
||||||
C3D_Tex * tex = malloc(sizeof(C3D_Tex));
|
C3D_Tex* tex = malloc(sizeof(C3D_Tex));
|
||||||
preview_image->tex = tex;
|
preview_image->tex = tex;
|
||||||
|
|
||||||
Tex3DS_SubTexture * subt3x = malloc(sizeof(Tex3DS_SubTexture));
|
Tex3DS_SubTexture * subt3x = malloc(sizeof(Tex3DS_SubTexture));
|
||||||
@@ -324,109 +532,58 @@ bool load_preview_from_buffer(char * row_pointers, u32 size, C2D_Image * preview
|
|||||||
subt3x->left = 0.0f;
|
subt3x->left = 0.0f;
|
||||||
subt3x->top = 1.0f;
|
subt3x->top = 1.0f;
|
||||||
subt3x->right = width/512.0f;
|
subt3x->right = width/512.0f;
|
||||||
subt3x->bottom = 1.0-(height/tex_height);
|
subt3x->bottom = 1.0-(height/512.0f);
|
||||||
preview_image->subtex = subt3x;
|
preview_image->subtex = subt3x;
|
||||||
|
|
||||||
C3D_TexInit(preview_image->tex, 512, tex_height, GPU_RGBA8);
|
C3D_TexInit(preview_image->tex, 512, 512, GPU_RGBA8);
|
||||||
|
|
||||||
memset(preview_image->tex->data, 0, preview_image->tex->size);
|
memset(preview_image->tex->data, 0, preview_image->tex->size);
|
||||||
|
|
||||||
for(int j = 0; j < height; j++) {
|
for(int j = 0; j < height; j++) {
|
||||||
png_bytep row = (png_bytep)(row_pointers + (width * 4 * j));
|
png_bytep row = row_pointers[j];
|
||||||
for(int i = 0; i < width; i++) {
|
for(int i = 0; i < width; i++) {
|
||||||
png_bytep px = &(row[i * 4]);
|
png_bytep px = &(row[i * 4]);
|
||||||
u32 dst = ((((j >> 3) * (512 >> 3) + (i >> 3)) << 6) + ((i & 1) | ((j & 1) << 1) | ((i & 2) << 1) | ((j & 2) << 2) | ((i & 4) << 2) | ((j & 4) << 3))) * 4;
|
u32 dst = ((((j >> 3) * (512 >> 3) + (i >> 3)) << 6) + ((i & 1) | ((j & 1) << 1) | ((i & 2) << 1) | ((j & 2) << 2) | ((i & 4) << 2) | ((j & 4) << 3))) * 4;
|
||||||
|
|
||||||
memcpy(preview_image->tex->data + dst, px, sizeof(u32));
|
memcpy(preview_image->tex->data + dst, px, sizeof(u32));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(row_pointers[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
*preview_offset = (width - TOP_SCREEN_WIDTH) / 2;
|
free(row_pointers);
|
||||||
|
|
||||||
|
*preview_offset = (width-400)/2;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u16 previous_path_preview[0x106] = {0};
|
static u16 previous_path_preview[0x106] = {0};
|
||||||
bool load_preview(const Entry_List_s * list, C2D_Image * preview_image, int * preview_offset)
|
bool load_preview(Entry_List_s list, C2D_Image * preview_image, int * preview_offset)
|
||||||
{
|
{
|
||||||
if(list->entries == NULL) return false;
|
if(list.entries == NULL) return false;
|
||||||
|
|
||||||
const Entry_s * entry = &list->entries[list->selected_entry];
|
Entry_s entry = list.entries[list.selected_entry];
|
||||||
|
|
||||||
if(!memcmp(&previous_path_preview, &entry->path, 0x106 * sizeof(u16))) return true;
|
if(!memcmp(&previous_path_preview, &entry.path, 0x106*sizeof(u16))) return true;
|
||||||
|
|
||||||
char * preview_buffer = NULL;
|
char *preview_buffer = NULL;
|
||||||
u32 size = load_data("/preview.png", entry, &preview_buffer);
|
u64 size = load_data("/preview.png", entry, &preview_buffer);
|
||||||
u32 height = 480;
|
|
||||||
|
|
||||||
if(size)
|
if(!size)
|
||||||
{
|
|
||||||
if (!(size = png_to_abgr(&preview_buffer, size, &height)))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
free(preview_buffer);
|
free(preview_buffer);
|
||||||
|
throw_error("No preview found.", ERROR_LEVEL_WARNING);
|
||||||
const int top_size = TOP_SCREEN_WIDTH * SCREEN_HEIGHT * SCREEN_COLOR_DEPTH;
|
return false;
|
||||||
const int out_size = top_size * 2;
|
|
||||||
|
|
||||||
char * rgba_buffer = malloc(out_size);
|
|
||||||
memset(rgba_buffer, 0, out_size);
|
|
||||||
bool found_splash = false;
|
|
||||||
|
|
||||||
// try to assembly a preview from the splash screens
|
|
||||||
size = load_data("/splash.bin", entry, &preview_buffer);
|
|
||||||
if (size)
|
|
||||||
{
|
|
||||||
found_splash = true;
|
|
||||||
bin_to_abgr(&preview_buffer, size);
|
|
||||||
|
|
||||||
memcpy(rgba_buffer, preview_buffer, top_size);
|
|
||||||
free(preview_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
size = load_data("/splashbottom.bin", entry, &preview_buffer);
|
|
||||||
if (size)
|
|
||||||
{
|
|
||||||
found_splash = true;
|
|
||||||
bin_to_abgr(&preview_buffer, size);
|
|
||||||
|
|
||||||
const int buffer_width = TOP_SCREEN_WIDTH * SCREEN_COLOR_DEPTH;
|
|
||||||
const int bottom_buffer_width = BOTTOM_SCREEN_WIDTH * SCREEN_COLOR_DEPTH;
|
|
||||||
const int bottom_centered_offset = (TOP_SCREEN_WIDTH - BOTTOM_SCREEN_WIDTH) / 2;
|
|
||||||
|
|
||||||
// Store the bottom splash screen under the top splash and centered
|
|
||||||
for (int i = 0; i < SCREEN_HEIGHT; ++i)
|
|
||||||
memcpy(
|
|
||||||
rgba_buffer + top_size + (buffer_width * i) + (bottom_centered_offset * SCREEN_COLOR_DEPTH),
|
|
||||||
preview_buffer + (bottom_buffer_width * i),
|
|
||||||
bottom_buffer_width
|
|
||||||
);
|
|
||||||
|
|
||||||
free(preview_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found_splash)
|
|
||||||
{
|
|
||||||
free(rgba_buffer);
|
|
||||||
throw_error(language.loading.no_preview, ERROR_LEVEL_WARNING);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
size = out_size;
|
|
||||||
preview_buffer = rgba_buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ret = load_preview_from_buffer(preview_buffer, size, preview_image, preview_offset, height);
|
bool ret = load_preview_from_buffer(preview_buffer, size, preview_image, preview_offset);
|
||||||
free(preview_buffer);
|
free(preview_buffer);
|
||||||
|
|
||||||
if(ret)
|
if(ret)
|
||||||
{
|
{
|
||||||
// mark the new preview as loaded for optimisation
|
// mark the new preview as loaded for optimisation
|
||||||
memcpy(&previous_path_preview, &entry->path, 0x106 * sizeof(u16));
|
memcpy(&previous_path_preview, &entry.path, 0x106*sizeof(u16));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -437,27 +594,11 @@ void free_preview(C2D_Image preview)
|
|||||||
if(preview.tex)
|
if(preview.tex)
|
||||||
C3D_TexDelete(preview.tex);
|
C3D_TexDelete(preview.tex);
|
||||||
free(preview.tex);
|
free(preview.tex);
|
||||||
free((Tex3DS_SubTexture *)preview.subtex);
|
free((Tex3DS_SubTexture*)preview.subtex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the audio struct
|
// Initialize the audio struct
|
||||||
Result load_audio(const Entry_s * entry, audio_s * audio)
|
Result load_audio(Entry_s entry, audio_s *audio)
|
||||||
{
|
|
||||||
audio->music_size = load_data("/bgm.bcstm", entry, &audio->music_buf);
|
|
||||||
if (audio->music_size == 0) {
|
|
||||||
free(audio);
|
|
||||||
DEBUG("<load_audio> File not found!\n");
|
|
||||||
return MAKERESULT(RL_FATAL, RS_NOTFOUND, RM_APPLICATION, RD_NOT_FOUND);
|
|
||||||
}
|
|
||||||
audio->cursor = 0;
|
|
||||||
audio->last_time = 0;
|
|
||||||
audio->current_block = 0;
|
|
||||||
audio->stop = false;
|
|
||||||
audio->active_channels = 0;
|
|
||||||
return MAKERESULT(RL_SUCCESS, RS_SUCCESS, RM_APPLICATION, RD_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result load_audio_ogg(const Entry_s * entry, audio_ogg_s * audio)
|
|
||||||
{
|
{
|
||||||
audio->filesize = load_data("/bgm.ogg", entry, &audio->filebuf);
|
audio->filesize = load_data("/bgm.ogg", entry, &audio->filebuf);
|
||||||
if (audio->filesize == 0) {
|
if (audio->filesize == 0) {
|
||||||
@@ -467,11 +608,12 @@ Result load_audio_ogg(const Entry_s * entry, audio_ogg_s * audio)
|
|||||||
}
|
}
|
||||||
|
|
||||||
audio->mix[0] = audio->mix[1] = 1.0f; // Determines volume for the 12 (?) different outputs. See http://smealum.github.io/ctrulib/channel_8h.html#a30eb26f1972cc3ec28370263796c0444
|
audio->mix[0] = audio->mix[1] = 1.0f; // Determines volume for the 12 (?) different outputs. See http://smealum.github.io/ctrulib/channel_8h.html#a30eb26f1972cc3ec28370263796c0444
|
||||||
|
svcCreateEvent(&audio->finished, RESET_STICKY);
|
||||||
|
|
||||||
ndspChnSetInterp(0, NDSP_INTERP_LINEAR);
|
ndspChnSetInterp(0, NDSP_INTERP_LINEAR);
|
||||||
ndspChnSetMix(0, audio->mix); // See mix comment above
|
ndspChnSetMix(0, audio->mix); // See mix comment above
|
||||||
|
|
||||||
FILE * file = fmemopen(audio->filebuf, audio->filesize, "rb");
|
FILE *file = fmemopen(audio->filebuf, audio->filesize, "rb");
|
||||||
DEBUG("<load_audio> Filesize: %ld\n", audio->filesize);
|
DEBUG("<load_audio> Filesize: %ld\n", audio->filesize);
|
||||||
if(file != NULL)
|
if(file != NULL)
|
||||||
{
|
{
|
||||||
@@ -485,7 +627,7 @@ Result load_audio_ogg(const Entry_s * entry, audio_ogg_s * audio)
|
|||||||
return MAKERESULT(RL_FATAL, RS_INVALIDARG, RM_APPLICATION, RD_NO_DATA);
|
return MAKERESULT(RL_FATAL, RS_INVALIDARG, RM_APPLICATION, RD_NO_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
vorbis_info * vi = ov_info(&audio->vf, -1);
|
vorbis_info *vi = ov_info(&audio->vf, -1);
|
||||||
ndspChnSetRate(0, vi->rate);// Set sample rate to what's read from the ogg file
|
ndspChnSetRate(0, vi->rate);// Set sample rate to what's read from the ogg file
|
||||||
if (vi->channels == 2) {
|
if (vi->channels == 2) {
|
||||||
DEBUG("<load_audio> Using stereo\n");
|
DEBUG("<load_audio> Using stereo\n");
|
||||||
@@ -510,4 +652,4 @@ Result load_audio_ogg(const Entry_s * entry, audio_ogg_s * audio)
|
|||||||
DEBUG("<load_audio> fmemopen failed!\n");
|
DEBUG("<load_audio> fmemopen failed!\n");
|
||||||
return MAKERESULT(RL_FATAL, RS_NOTFOUND, RM_APPLICATION, RD_NOT_FOUND);
|
return MAKERESULT(RL_FATAL, RS_NOTFOUND, RM_APPLICATION, RD_NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
719
source/main.c
328
source/music.c
@@ -27,34 +27,8 @@
|
|||||||
#include "music.h"
|
#include "music.h"
|
||||||
#include "loading.h"
|
#include "loading.h"
|
||||||
|
|
||||||
// BCSTM Player adapted from BCSTM-Player by tobid7
|
// Play a given audio struct
|
||||||
// https://github.com/NPI-D7/BCSTM-Player/blob/main/source/bcstm.hpp
|
Result update_audio(audio_s *audio)
|
||||||
|
|
||||||
u32 read32(char *music_buf, size_t *cursor)
|
|
||||||
{
|
|
||||||
u32 ret;
|
|
||||||
memcpy(&ret, music_buf + *cursor, 4);
|
|
||||||
*cursor += 4;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
u16 read16(char *music_buf, size_t *cursor)
|
|
||||||
{
|
|
||||||
u16 ret;
|
|
||||||
memcpy(&ret, music_buf + *cursor, 2);
|
|
||||||
*cursor += 2;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
u8 read8(char *music_buf, size_t *cursor)
|
|
||||||
{
|
|
||||||
u8 ret;
|
|
||||||
memcpy(&ret, music_buf + *cursor, 1);
|
|
||||||
*cursor += 1;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result update_audio_ogg(audio_ogg_s * audio)
|
|
||||||
{
|
{
|
||||||
u32 size = audio->wave_buf[audio->buf_pos].nsamples * 4 - audio->data_read;
|
u32 size = audio->wave_buf[audio->buf_pos].nsamples * 4 - audio->data_read;
|
||||||
DEBUG("<update_audio> Audio Size: %ld\n", size);
|
DEBUG("<update_audio> Audio Size: %ld\n", size);
|
||||||
@@ -62,7 +36,7 @@ Result update_audio_ogg(audio_ogg_s * audio)
|
|||||||
{
|
{
|
||||||
DEBUG("<update_audio> Attempting ov_read\n");
|
DEBUG("<update_audio> Attempting ov_read\n");
|
||||||
int bitstream;
|
int bitstream;
|
||||||
u32 read = ov_read(&audio->vf, (char *)audio->wave_buf[audio->buf_pos].data_vaddr + audio->data_read, size, &bitstream); // read 1 vorbis packet into wave buffer
|
u32 read = ov_read(&audio->vf, (char*)audio->wave_buf[audio->buf_pos].data_vaddr + audio->data_read, size, &bitstream); // read 1 vorbis packet into wave buffer
|
||||||
DEBUG("<update_audio> ov_read successful\n");
|
DEBUG("<update_audio> ov_read successful\n");
|
||||||
|
|
||||||
if (read <= 0) // EoF or error
|
if (read <= 0) // EoF or error
|
||||||
@@ -90,290 +64,22 @@ Result update_audio_ogg(audio_ogg_s * audio)
|
|||||||
return MAKERESULT(RL_SUCCESS, RS_SUCCESS, RM_APPLICATION, RD_SUCCESS);
|
return MAKERESULT(RL_SUCCESS, RS_SUCCESS, RM_APPLICATION, RD_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void thread_audio_ogg(void * data) {
|
void thread_audio(void* data) {
|
||||||
audio_ogg_s * audio = (audio_ogg_s *)data;
|
audio_s *audio = (audio_s*)data;
|
||||||
while(!audio->stop) {
|
|
||||||
update_audio_ogg(audio);
|
|
||||||
}
|
|
||||||
ndspChnWaveBufClear(0);
|
|
||||||
ndspChnReset(0);
|
|
||||||
ov_clear(&audio->vf);
|
|
||||||
free(audio->filebuf);
|
|
||||||
linearFree((void *)audio->wave_buf[0].data_vaddr);
|
|
||||||
linearFree((void *)audio->wave_buf[1].data_vaddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void play_audio_ogg(audio_ogg_s * audio) {
|
|
||||||
audio->playing_thread = threadCreate(thread_audio_ogg, audio, 0x1000, 0x3F, 1, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void stop_audio_ogg(audio_ogg_s ** audio_ptr) {
|
|
||||||
audio_ogg_s * audio = *audio_ptr;
|
|
||||||
if(audio->playing_thread)
|
|
||||||
{
|
|
||||||
audio->stop = true;
|
|
||||||
threadJoin(audio->playing_thread, U64_MAX);
|
|
||||||
threadFree(audio->playing_thread);
|
|
||||||
}
|
|
||||||
free(audio);
|
|
||||||
*audio_ptr = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
u16 type;
|
|
||||||
u32 target;
|
|
||||||
} bcstm_reference;
|
|
||||||
|
|
||||||
int init_audio(audio_s *audio)
|
|
||||||
{
|
|
||||||
u32 magic = read32(audio->music_buf, &audio->cursor);
|
|
||||||
DEBUG("Loading music, music_size: %d, magic: 0x%08lx\n", audio->music_size, magic);
|
|
||||||
audio->is_little_endian = read16(audio->music_buf, &audio->cursor) == 0xFEFF;
|
|
||||||
audio->info_offset = 0;
|
|
||||||
audio->data_offset = 0;
|
|
||||||
|
|
||||||
if (magic != 0x4D545343) // CSTM
|
|
||||||
{
|
|
||||||
free(audio->music_buf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio->cursor = 0x10;
|
|
||||||
u16 sbc = read16(audio->music_buf, &audio->cursor);
|
|
||||||
audio->cursor += 2;
|
|
||||||
|
|
||||||
for (u16 i = 0; i < sbc; ++i)
|
|
||||||
{
|
|
||||||
u16 sec = read16(audio->music_buf, &audio->cursor);
|
|
||||||
audio->cursor += 2;
|
|
||||||
u32 off = read32(audio->music_buf, &audio->cursor);
|
|
||||||
audio->cursor += 4;
|
|
||||||
DEBUG("Reading sbc: %04x, %08lx\n", sec, off);
|
|
||||||
if (sec == 0x4000) // Info block
|
|
||||||
audio->info_offset = off;
|
|
||||||
if (sec == 0x4002) // Data block
|
|
||||||
audio->data_offset = off;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG("Info offset: 0x%08lx, data offset: 0x%08lx\n", audio->info_offset, audio->data_offset);
|
|
||||||
|
|
||||||
if (audio->data_offset == 0 || audio->info_offset == 0)
|
|
||||||
{
|
|
||||||
free(audio->music_buf);
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio->cursor = audio->info_offset + 0x20;
|
|
||||||
|
|
||||||
if (read8(audio->music_buf, &audio->cursor) != 2) // Encoding - 2 is DSP_ADPCM
|
|
||||||
{
|
|
||||||
free(audio->music_buf);
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
|
|
||||||
audio->is_looping = read8(audio->music_buf, &audio->cursor);
|
|
||||||
audio->channel_count = read8(audio->music_buf, &audio->cursor);
|
|
||||||
|
|
||||||
if (audio->channel_count > 2)
|
|
||||||
{
|
|
||||||
free(audio->music_buf);
|
|
||||||
return -4;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG("Channel count: %d, is looping: %d\n", audio->channel_count, audio->is_looping);
|
|
||||||
|
|
||||||
audio->cursor = audio->info_offset + 0x24;
|
|
||||||
audio->sample_rate = read32(audio->music_buf, &audio->cursor);
|
|
||||||
u32 _loop_pos = read32(audio->music_buf, &audio->cursor);
|
|
||||||
u32 _loop_end = read32(audio->music_buf, &audio->cursor);
|
|
||||||
audio->num_blocks = read32(audio->music_buf, &audio->cursor);
|
|
||||||
audio->block_size = read32(audio->music_buf, &audio->cursor);
|
|
||||||
audio->block_samples = read32(audio->music_buf, &audio->cursor);
|
|
||||||
audio->cursor += 4;
|
|
||||||
audio->last_block_samples = read32(audio->music_buf, &audio->cursor);
|
|
||||||
audio->last_block_size = read32(audio->music_buf, &audio->cursor);
|
|
||||||
|
|
||||||
DEBUG("sample_rate: %lu, loop_start: %lu, loop_end: %lu, num_blocks: %lu, block_size: %lu, block_samples: %lu, last_block_samples: %lu, last_block_size: %lu\n",
|
|
||||||
audio->sample_rate, _loop_pos, _loop_end, audio->num_blocks, audio->block_size, audio->block_samples, audio->last_block_samples, audio->last_block_size);
|
|
||||||
|
|
||||||
audio->loop_start = _loop_pos / audio->block_samples;
|
|
||||||
audio->loop_end = (_loop_end % audio->block_samples ? audio->num_blocks : _loop_end / audio->block_samples);
|
|
||||||
|
|
||||||
while (read32(audio->music_buf, &audio->cursor) != 0x4102); // find channel info header
|
|
||||||
audio->cursor -= 4;
|
|
||||||
u32 start_table = audio->cursor - 4;
|
|
||||||
bcstm_reference channel_refs[2] = {0};
|
|
||||||
for (u8 i = 0; i < audio->channel_count; ++i)
|
|
||||||
{
|
|
||||||
DEBUG("Processing channel_ref at %08x...\n", audio->cursor);
|
|
||||||
channel_refs[i].type = read16(audio->music_buf, &audio->cursor);
|
|
||||||
audio->cursor += 2;
|
|
||||||
channel_refs[i].target = start_table + read32(audio->music_buf, &audio->cursor);
|
|
||||||
DEBUG("Type: %04x; Target: %08lx\n", channel_refs[i].type, channel_refs[i].target);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (u8 i = 0; i < audio->channel_count; ++i)
|
|
||||||
{
|
|
||||||
audio->cursor = channel_refs[i].target;
|
|
||||||
if (read16(audio->music_buf, &audio->cursor) != 0x300) continue; // Bad bcstm - channel info != DSP ADPCM info
|
|
||||||
audio->cursor += 2;
|
|
||||||
audio->cursor += read32(audio->music_buf, &audio->cursor) - 8;
|
|
||||||
memcpy(audio->adpcm_coefs[i], audio->music_buf + audio->cursor, sizeof(unsigned short) * 16);
|
|
||||||
audio->cursor += sizeof(unsigned short) * 16;
|
|
||||||
memcpy(&(audio->adpcm_data[i][0]), audio->music_buf + audio->cursor, sizeof(ndspAdpcmData));
|
|
||||||
audio->cursor += sizeof(ndspAdpcmData);
|
|
||||||
memcpy(&(audio->adpcm_data[i][1]), audio->music_buf + audio->cursor, sizeof(ndspAdpcmData));
|
|
||||||
audio->cursor += sizeof(ndspAdpcmData);
|
|
||||||
audio->cursor += 2; // skip padding
|
|
||||||
}
|
|
||||||
|
|
||||||
audio->cursor = audio->data_offset + 0x20;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int start_play(audio_s *audio) {
|
|
||||||
audio->current_block = 0;
|
|
||||||
for (u8 i = 0; i < audio->channel_count; ++i)
|
|
||||||
{
|
|
||||||
audio->channel[i] = 0;
|
|
||||||
while (audio->channel[i] < 24 && ((audio->active_channels >> audio->channel[i]) & 1)) {
|
|
||||||
audio->channel[i]++;
|
|
||||||
}
|
|
||||||
if (audio->channel[i] == 24) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
audio->active_channels |= 1 << audio->channel[i];
|
|
||||||
ndspChnWaveBufClear(audio->channel[i]);
|
|
||||||
|
|
||||||
static float mix[16];
|
|
||||||
ndspChnSetFormat(audio->channel[i], NDSP_FORMAT_ADPCM | NDSP_3D_SURROUND_PREPROCESSED);
|
|
||||||
ndspChnSetRate(audio->channel[i], audio->sample_rate);
|
|
||||||
|
|
||||||
if (audio->channel_count == 1)
|
|
||||||
{
|
|
||||||
mix[0] = mix[1] = 0.5f;
|
|
||||||
} else if (audio->channel_count == 2)
|
|
||||||
{
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
mix[0] = 0.8f;
|
|
||||||
mix[1] = 0.0f;
|
|
||||||
mix[2] = 0.2f;
|
|
||||||
mix[3] = 0.0f;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
mix[0] = 0.0f;
|
|
||||||
mix[1] = 0.8f;
|
|
||||||
mix[2] = 0.0f;
|
|
||||||
mix[3] = 0.2f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ndspChnSetMix(audio->channel[i], mix);
|
|
||||||
ndspChnSetAdpcmCoefs(audio->channel[i], audio->adpcm_coefs[i]);
|
|
||||||
|
|
||||||
for (u8 j = 0; j < BUFFER_COUNT; ++j)
|
|
||||||
{
|
|
||||||
memset(&(audio->wave_buf[i][j]), 0, sizeof(ndspWaveBuf));
|
|
||||||
audio->wave_buf[i][j].status = NDSP_WBUF_DONE;
|
|
||||||
audio->buffer_data[i][j] = linearAlloc(audio->block_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fill_buffers(audio_s *audio)
|
|
||||||
{
|
|
||||||
DEBUG("Filling buffers...\n");
|
|
||||||
for (u8 bufIndex = 0; bufIndex < BUFFER_COUNT; ++bufIndex)
|
|
||||||
{
|
|
||||||
if (audio->wave_buf[0][bufIndex].status != NDSP_WBUF_DONE) continue;
|
|
||||||
if (audio->channel_count == 2 && audio->wave_buf[1][bufIndex].status != NDSP_WBUF_DONE) continue;
|
|
||||||
|
|
||||||
if (audio->is_looping && audio->current_block == audio->loop_end)
|
|
||||||
{
|
|
||||||
audio->current_block = audio->loop_start;
|
|
||||||
audio->cursor = audio->data_offset + 0x20 + audio->block_size * audio->channel_count * audio->loop_start;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!audio->is_looping && audio->current_block == audio->loop_end)
|
|
||||||
{
|
|
||||||
audio->stop = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (u8 channelIndex = 0; channelIndex < audio->channel_count; ++channelIndex)
|
|
||||||
{
|
|
||||||
ndspWaveBuf *buf = &(audio->wave_buf[channelIndex][bufIndex]);
|
|
||||||
memset(buf, 0, sizeof(ndspWaveBuf));
|
|
||||||
buf->data_adpcm = audio->buffer_data[channelIndex][bufIndex];
|
|
||||||
memcpy(buf->data_adpcm, audio->music_buf + audio->cursor, (audio->current_block == audio->num_blocks - 1) ? audio->last_block_size : audio->block_size);
|
|
||||||
audio->cursor += (audio->current_block == audio->num_blocks - 1) ? audio->last_block_size : audio->block_size;
|
|
||||||
DSP_FlushDataCache(buf->data_adpcm, audio->block_size);
|
|
||||||
|
|
||||||
if (audio->current_block == 0)
|
|
||||||
buf->adpcm_data = &(audio->adpcm_data[channelIndex][0]);
|
|
||||||
else if (audio->current_block == audio->loop_start)
|
|
||||||
buf->adpcm_data = &(audio->adpcm_data[channelIndex][1]);
|
|
||||||
|
|
||||||
if (audio->current_block == audio->num_blocks - 1)
|
|
||||||
buf->nsamples = audio->last_block_samples;
|
|
||||||
else
|
|
||||||
buf->nsamples = audio->block_samples;
|
|
||||||
|
|
||||||
ndspChnWaveBufAdd(audio->channel[channelIndex], buf);
|
|
||||||
}
|
|
||||||
audio->current_block++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Play a given audio struct
|
|
||||||
void update_audio(audio_s * audio)
|
|
||||||
{
|
|
||||||
u32 current_time = svcGetSystemTick();
|
|
||||||
if (current_time - audio->last_time > 1e8)
|
|
||||||
{
|
|
||||||
fill_buffers(audio);
|
|
||||||
audio->last_time = current_time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void thread_audio(void * data) {
|
|
||||||
audio_s * audio = (audio_s *)data;
|
|
||||||
int res = init_audio(audio);
|
|
||||||
if (res < 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
start_play(audio);
|
|
||||||
while(!audio->stop) {
|
while(!audio->stop) {
|
||||||
update_audio(audio);
|
update_audio(audio);
|
||||||
}
|
}
|
||||||
for (u8 i = 0; i < audio->channel_count; ++i)
|
free(audio->filebuf);
|
||||||
{
|
ov_clear(&audio->vf);
|
||||||
ndspChnWaveBufClear(audio->channel[i]);
|
linearFree((void*)audio->wave_buf[0].data_vaddr);
|
||||||
ndspChnReset(audio->channel[i]);
|
linearFree((void*)audio->wave_buf[1].data_vaddr);
|
||||||
audio->active_channels &= ~(1 << audio->channel[i]);
|
while (audio->wave_buf[0].status != NDSP_WBUF_DONE || audio->wave_buf[1].status != NDSP_WBUF_DONE) svcSleepThread(1e7);
|
||||||
for (u8 j = 0; j < BUFFER_COUNT; ++j) {
|
svcSignalEvent(audio->finished);
|
||||||
linearFree(audio->buffer_data[i][j]);
|
svcSleepThread(1e8);
|
||||||
}
|
svcCloseHandle(audio->finished);
|
||||||
}
|
|
||||||
free(audio->music_buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
void play_audio(audio_s * audio) {
|
|
||||||
audio->playing_thread = threadCreate(thread_audio, audio, 0x1000, 0x3F, 1, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void stop_audio(audio_s ** audio_ptr) {
|
|
||||||
audio_s * audio = *audio_ptr;
|
|
||||||
if(audio->playing_thread)
|
|
||||||
{
|
|
||||||
audio->stop = true;
|
|
||||||
threadJoin(audio->playing_thread, U64_MAX);
|
|
||||||
threadFree(audio->playing_thread);
|
|
||||||
}
|
|
||||||
free(audio);
|
free(audio);
|
||||||
*audio_ptr = NULL;
|
}
|
||||||
|
|
||||||
|
void play_audio(audio_s *audio) {
|
||||||
|
threadCreate(thread_audio, audio, 0x1000, 0x3F, 1, true);
|
||||||
}
|
}
|
||||||
|
|||||||
753
source/remote.c
@@ -27,7 +27,6 @@
|
|||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "ui_strings.h"
|
|
||||||
|
|
||||||
void splash_delete(void)
|
void splash_delete(void)
|
||||||
{
|
{
|
||||||
@@ -35,7 +34,7 @@ void splash_delete(void)
|
|||||||
remove("/luma/splashbottom.bin");
|
remove("/luma/splashbottom.bin");
|
||||||
}
|
}
|
||||||
|
|
||||||
void splash_install(const Entry_s * splash)
|
void splash_install(Entry_s splash)
|
||||||
{
|
{
|
||||||
char *screen_buf = NULL;
|
char *screen_buf = NULL;
|
||||||
|
|
||||||
@@ -55,7 +54,7 @@ void splash_install(const Entry_s * splash)
|
|||||||
|
|
||||||
if(size == 0 && bottom_size == 0)
|
if(size == 0 && bottom_size == 0)
|
||||||
{
|
{
|
||||||
throw_error(language.splashes.no_splash_found, ERROR_LEVEL_WARNING);
|
throw_error("No splash.bin or splashbottom.bin found.\nIs this a splash?", ERROR_LEVEL_WARNING);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -66,7 +65,7 @@ void splash_install(const Entry_s * splash)
|
|||||||
if(config_buf[0xC] == 0)
|
if(config_buf[0xC] == 0)
|
||||||
{
|
{
|
||||||
free(config_buf);
|
free(config_buf);
|
||||||
throw_error(language.splashes.splash_disabled, ERROR_LEVEL_WARNING);
|
throw_error("WARNING: Splashes are disabled in Luma Config", ERROR_LEVEL_WARNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,8 +103,8 @@ void splash_check_installed(void * void_arg)
|
|||||||
for(int i = 0; i < list->entries_count && arg->run_thread; i++)
|
for(int i = 0; i < list->entries_count && arg->run_thread; i++)
|
||||||
{
|
{
|
||||||
Entry_s * splash = &list->entries[i];
|
Entry_s * splash = &list->entries[i];
|
||||||
top_size = load_data("/splash.bin", splash, &top_buf);
|
top_size = load_data("/splash.bin", *splash, &top_buf);
|
||||||
bottom_size = load_data("/splashbottom.bin", splash, &bottom_buf);
|
bottom_size = load_data("/splashbottom.bin", *splash, &bottom_buf);
|
||||||
|
|
||||||
if(!top_size && !bottom_size)
|
if(!top_size && !bottom_size)
|
||||||
{
|
{
|
||||||
@@ -128,4 +127,4 @@ void splash_check_installed(void * void_arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
311
source/themes.c
@@ -28,31 +28,29 @@
|
|||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "ui_strings.h"
|
|
||||||
|
|
||||||
#define BODY_CACHE_SIZE 0x150000
|
#define BODY_CACHE_SIZE 0x150000
|
||||||
#define BGM_MAX_SIZE 0x337000
|
#define BGM_MAX_SIZE 0x337000
|
||||||
|
|
||||||
static Result install_theme_internal(const Entry_List_s * themes, int installmode)
|
static Result install_theme_internal(Entry_List_s themes, int installmode)
|
||||||
{
|
{
|
||||||
Result res = 0;
|
Result res = 0;
|
||||||
char * music = NULL;
|
char* music = NULL;
|
||||||
u32 music_size = 0;
|
u32 music_size = 0;
|
||||||
u32 shuffle_music_sizes[MAX_SHUFFLE_THEMES] = {0};
|
u32 shuffle_music_sizes[MAX_SHUFFLE_THEMES] = {0};
|
||||||
char * body = NULL;
|
char* body = NULL;
|
||||||
u32 body_size = 0;
|
u32 body_size = 0;
|
||||||
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES] = {0};
|
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES] = {0};
|
||||||
bool mono_audio = false;
|
|
||||||
|
|
||||||
if(installmode & THEME_INSTALL_SHUFFLE)
|
if(installmode & THEME_INSTALL_SHUFFLE)
|
||||||
{
|
{
|
||||||
if(themes->shuffle_count < 2)
|
if(themes.shuffle_count < 2)
|
||||||
{
|
{
|
||||||
DEBUG("not enough themes selected for shuffle\n");
|
DEBUG("not enough themes selected for shuffle\n");
|
||||||
return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_COMMON, RD_INVALID_SELECTION);
|
return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_COMMON, RD_INVALID_SELECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(themes->shuffle_count > MAX_SHUFFLE_THEMES)
|
if(themes.shuffle_count > MAX_SHUFFLE_THEMES)
|
||||||
{
|
{
|
||||||
DEBUG("too many themes selected for shuffle\n");
|
DEBUG("too many themes selected for shuffle\n");
|
||||||
return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_COMMON, RD_INVALID_SELECTION);
|
return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_COMMON, RD_INVALID_SELECTION);
|
||||||
@@ -61,7 +59,6 @@ static Result install_theme_internal(const Entry_List_s * themes, int installmod
|
|||||||
char * padded = NULL;
|
char * padded = NULL;
|
||||||
|
|
||||||
int shuffle_count = 0;
|
int shuffle_count = 0;
|
||||||
draw_loading_bar(shuffle_count, themes->shuffle_count + 1, INSTALL_SHUFFLE);
|
|
||||||
Handle body_cache_handle;
|
Handle body_cache_handle;
|
||||||
|
|
||||||
if(installmode & THEME_INSTALL_BODY)
|
if(installmode & THEME_INSTALL_BODY)
|
||||||
@@ -70,20 +67,20 @@ static Result install_theme_internal(const Entry_List_s * themes, int installmod
|
|||||||
FSUSER_OpenFile(&body_cache_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/BodyCache_rd.bin"), FS_OPEN_WRITE, 0);
|
FSUSER_OpenFile(&body_cache_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/BodyCache_rd.bin"), FS_OPEN_WRITE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < themes->entries_count; i++)
|
for(int i = 0; i < themes.entries_count; i++)
|
||||||
{
|
{
|
||||||
const Entry_s * current_theme = &themes->entries[i];
|
Entry_s * current_theme = &themes.entries[i];
|
||||||
|
|
||||||
if(current_theme->in_shuffle)
|
if(current_theme->in_shuffle)
|
||||||
{
|
{
|
||||||
if(installmode & THEME_INSTALL_BODY)
|
if(installmode & THEME_INSTALL_BODY)
|
||||||
{
|
{
|
||||||
body_size = load_data("/body_LZ.bin", current_theme, &body);
|
body_size = load_data("/body_LZ.bin", *current_theme, &body);
|
||||||
if(body_size == 0)
|
if(body_size == 0)
|
||||||
{
|
{
|
||||||
free(body);
|
free(body);
|
||||||
DEBUG("body not found\n");
|
DEBUG("body not found\n");
|
||||||
throw_error(language.themes.no_body_found, ERROR_LEVEL_WARNING);
|
throw_error("No body_LZ.bin found - is this a theme?", ERROR_LEVEL_WARNING);
|
||||||
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
|
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +108,7 @@ static Result install_theme_internal(const Entry_List_s * themes, int installmod
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
music_size = load_data("/bgm.bcstm", current_theme, &music);
|
music_size = load_data("/bgm.bcstm", *current_theme, &music);
|
||||||
|
|
||||||
if(music_size > BGM_MAX_SIZE)
|
if(music_size > BGM_MAX_SIZE)
|
||||||
{
|
{
|
||||||
@@ -119,14 +116,6 @@ static Result install_theme_internal(const Entry_List_s * themes, int installmod
|
|||||||
DEBUG("bgm too big\n");
|
DEBUG("bgm too big\n");
|
||||||
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
|
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (music_size > 0)
|
|
||||||
{
|
|
||||||
if (music[0x62] == 1)
|
|
||||||
{
|
|
||||||
mono_audio = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shuffle_music_sizes[shuffle_count] = music_size;
|
shuffle_music_sizes[shuffle_count] = music_size;
|
||||||
@@ -150,7 +139,6 @@ static Result install_theme_internal(const Entry_List_s * themes, int installmod
|
|||||||
}
|
}
|
||||||
|
|
||||||
shuffle_count++;
|
shuffle_count++;
|
||||||
draw_loading_bar(shuffle_count, themes->shuffle_count + 1, INSTALL_SHUFFLE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +162,7 @@ static Result install_theme_internal(const Entry_List_s * themes, int installmod
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const Entry_s * current_theme = &themes->entries[themes->selected_entry];
|
Entry_s current_theme = themes.entries[themes.selected_entry];
|
||||||
|
|
||||||
if(installmode & THEME_INSTALL_BODY)
|
if(installmode & THEME_INSTALL_BODY)
|
||||||
{
|
{
|
||||||
@@ -183,7 +171,7 @@ static Result install_theme_internal(const Entry_List_s * themes, int installmod
|
|||||||
{
|
{
|
||||||
free(body);
|
free(body);
|
||||||
DEBUG("body not found\n");
|
DEBUG("body not found\n");
|
||||||
throw_error(language.themes.no_body_found, ERROR_LEVEL_WARNING);
|
throw_error("No body_LZ.bin found - is this a theme?", ERROR_LEVEL_WARNING);
|
||||||
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
|
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,18 +193,13 @@ static Result install_theme_internal(const Entry_List_s * themes, int installmod
|
|||||||
|
|
||||||
if (music_size != 0)
|
if (music_size != 0)
|
||||||
{
|
{
|
||||||
if (music[0x62] == 1)
|
|
||||||
{
|
|
||||||
mono_audio = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
remake_file(fsMakePath(PATH_ASCII, "/BgmCache.bin"), ArchiveThemeExt, BGM_MAX_SIZE);
|
remake_file(fsMakePath(PATH_ASCII, "/BgmCache.bin"), ArchiveThemeExt, BGM_MAX_SIZE);
|
||||||
res = buf_to_file(music_size, fsMakePath(PATH_ASCII, "/BgmCache.bin"), ArchiveThemeExt, music);
|
res = buf_to_file(music_size, fsMakePath(PATH_ASCII, "/BgmCache.bin"), ArchiveThemeExt, music);
|
||||||
free(music);
|
free(music);
|
||||||
|
|
||||||
char * body_buf = NULL;
|
char *body_buf = NULL;
|
||||||
u32 uncompressed_size = decompress_lz_file(fsMakePath(PATH_ASCII, "/BodyCache.bin"), ArchiveThemeExt, &body_buf);
|
u32 uncompressed_size = decompress_lz_file(fsMakePath(PATH_ASCII, "/BodyCache.bin"), ArchiveThemeExt, &body_buf);
|
||||||
if (body_buf != NULL && body_buf[5] != 1)
|
if (body_buf[5] != 1)
|
||||||
{
|
{
|
||||||
installmode |= THEME_INSTALL_BODY;
|
installmode |= THEME_INSTALL_BODY;
|
||||||
body_buf[5] = 1;
|
body_buf[5] = 1;
|
||||||
@@ -236,7 +219,7 @@ static Result install_theme_internal(const Entry_List_s * themes, int installmod
|
|||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
char * thememanage_buf = NULL;
|
char* thememanage_buf = NULL;
|
||||||
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
|
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
|
||||||
ThemeManage_bin_s * theme_manage = (ThemeManage_bin_s *)thememanage_buf;
|
ThemeManage_bin_s * theme_manage = (ThemeManage_bin_s *)thememanage_buf;
|
||||||
|
|
||||||
@@ -273,17 +256,17 @@ static Result install_theme_internal(const Entry_List_s * themes, int installmod
|
|||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
char * savedata_buf = NULL;
|
char* savedata_buf = NULL;
|
||||||
u32 savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf);
|
u32 savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf);
|
||||||
SaveData_dat_s * savedata = (SaveData_dat_s *)savedata_buf;
|
SaveData_dat_s* savedata = (SaveData_dat_s*)savedata_buf;
|
||||||
|
|
||||||
memset(&savedata->theme_entry, 0, sizeof(ThemeEntry_s));
|
memset(&savedata->theme_entry, 0, sizeof(ThemeEntry_s));
|
||||||
|
|
||||||
savedata->shuffle = (installmode & THEME_INSTALL_SHUFFLE) ? 1 : 0;
|
savedata->shuffle = (installmode & THEME_INSTALL_SHUFFLE) ? 1 : 0;
|
||||||
memset(savedata->shuffle_themes, 0, sizeof(ThemeEntry_s) * MAX_SHUFFLE_THEMES);
|
memset(savedata->shuffle_themes, 0, sizeof(ThemeEntry_s)*MAX_SHUFFLE_THEMES);
|
||||||
if(installmode & THEME_INSTALL_SHUFFLE)
|
if(installmode & THEME_INSTALL_SHUFFLE)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < themes->shuffle_count; i++)
|
for(int i = 0; i < themes.shuffle_count; i++)
|
||||||
{
|
{
|
||||||
savedata->shuffle_themes[i].type = 3;
|
savedata->shuffle_themes[i].type = 3;
|
||||||
savedata->shuffle_themes[i].index = i;
|
savedata->shuffle_themes[i].index = i;
|
||||||
@@ -302,53 +285,50 @@ static Result install_theme_internal(const Entry_List_s * themes, int installmod
|
|||||||
free(savedata_buf);
|
free(savedata_buf);
|
||||||
if(R_FAILED(res)) return res;
|
if(R_FAILED(res)) return res;
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
if (mono_audio)
|
|
||||||
{
|
|
||||||
throw_error(language.themes.mono_warn, ERROR_LEVEL_WARNING);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result theme_install(Entry_s * theme)
|
inline Result theme_install(Entry_s theme)
|
||||||
{
|
{
|
||||||
Entry_List_s list = {0};
|
Entry_List_s list = {0};
|
||||||
list.entries_count = 1;
|
list.entries_count = 1;
|
||||||
list.entries = theme;
|
list.entries = &theme;
|
||||||
list.selected_entry = 0;
|
list.selected_entry = 0;
|
||||||
return install_theme_internal(&list, THEME_INSTALL_BODY | THEME_INSTALL_BGM);
|
return install_theme_internal(list, THEME_INSTALL_BODY | THEME_INSTALL_BGM);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result bgm_install(Entry_s * theme)
|
inline Result bgm_install(Entry_s theme)
|
||||||
{
|
{
|
||||||
Entry_List_s list = {0};
|
Entry_List_s list = {0};
|
||||||
list.entries_count = 1;
|
list.entries_count = 1;
|
||||||
list.entries = theme;
|
list.entries = &theme;
|
||||||
list.selected_entry = 0;
|
list.selected_entry = 0;
|
||||||
return install_theme_internal(&list, THEME_INSTALL_BGM);
|
return install_theme_internal(list, THEME_INSTALL_BGM);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result no_bgm_install(Entry_s * theme)
|
inline Result no_bgm_install(Entry_s theme)
|
||||||
{
|
{
|
||||||
Entry_List_s list = {0};
|
Entry_List_s list = {0};
|
||||||
list.entries_count = 1;
|
list.entries_count = 1;
|
||||||
list.entries = theme;
|
list.entries = &theme;
|
||||||
list.selected_entry = 0;
|
list.selected_entry = 0;
|
||||||
return install_theme_internal(&list, THEME_INSTALL_BODY);
|
return install_theme_internal(list, THEME_INSTALL_BODY);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result shuffle_install(const Entry_List_s * themes)
|
inline Result shuffle_install(Entry_List_s themes)
|
||||||
{
|
{
|
||||||
return install_theme_internal(themes, THEME_INSTALL_SHUFFLE | THEME_INSTALL_BODY | THEME_INSTALL_BGM);
|
return install_theme_internal(themes, THEME_INSTALL_SHUFFLE | THEME_INSTALL_BODY | THEME_INSTALL_BGM);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SwkbdCallbackResult
|
static SwkbdCallbackResult
|
||||||
dir_name_callback(void * data, const char ** ppMessage, const char * text, size_t textlen)
|
dir_name_callback(void *data, const char ** ppMessage, const char * text, size_t textlen)
|
||||||
{
|
{
|
||||||
(void)textlen;
|
(void)textlen;
|
||||||
(void)data;
|
(void)data;
|
||||||
if(strpbrk(text, "><\"?;:/\\+,.|[=]"))
|
if(strpbrk(text, "><\"?;:/\\+,.|[=]"))
|
||||||
{
|
{
|
||||||
*ppMessage = language.themes.illegal_char;
|
*ppMessage = "Illegal character used.";
|
||||||
return SWKBD_CALLBACK_CONTINUE;
|
return SWKBD_CALLBACK_CONTINUE;
|
||||||
}
|
}
|
||||||
return SWKBD_CALLBACK_OK;
|
return SWKBD_CALLBACK_OK;
|
||||||
@@ -362,10 +342,10 @@ Result dump_current_theme(void)
|
|||||||
SwkbdState swkbd;
|
SwkbdState swkbd;
|
||||||
|
|
||||||
swkbdInit(&swkbd, SWKBD_TYPE_WESTERN, 2, max_chars);
|
swkbdInit(&swkbd, SWKBD_TYPE_WESTERN, 2, max_chars);
|
||||||
swkbdSetHintText(&swkbd, language.themes.name_folder);
|
swkbdSetHintText(&swkbd, "Name of output folder");
|
||||||
|
|
||||||
swkbdSetButton(&swkbd, SWKBD_BUTTON_LEFT, language.themes.cancel, false);
|
swkbdSetButton(&swkbd, SWKBD_BUTTON_LEFT, "Cancel", false);
|
||||||
swkbdSetButton(&swkbd, SWKBD_BUTTON_RIGHT, language.themes.done, true);
|
swkbdSetButton(&swkbd, SWKBD_BUTTON_RIGHT, "Done", true);
|
||||||
swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY_NOTBLANK, 0, max_chars);
|
swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY_NOTBLANK, 0, max_chars);
|
||||||
swkbdSetFilterCallback(&swkbd, dir_name_callback, NULL);
|
swkbdSetFilterCallback(&swkbd, dir_name_callback, NULL);
|
||||||
|
|
||||||
@@ -378,18 +358,18 @@ Result dump_current_theme(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
u16 path[0x107] = { 0 };
|
u16 path[0x107] = { 0 };
|
||||||
struacat(path, main_paths[REMOTE_MODE_THEMES]);
|
struacat(path, "/themes/");
|
||||||
struacat(path, output_dir);
|
struacat(path, output_dir);
|
||||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_UTF16, path), FS_ATTRIBUTE_DIRECTORY);
|
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_UTF16, path), FS_ATTRIBUTE_DIRECTORY);
|
||||||
|
|
||||||
char * thememanage_buf = NULL;
|
char *thememanage_buf = NULL;
|
||||||
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
|
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
|
||||||
ThemeManage_bin_s * theme_manage = (ThemeManage_bin_s *)thememanage_buf;
|
ThemeManage_bin_s * theme_manage = (ThemeManage_bin_s *)thememanage_buf;
|
||||||
u32 theme_size = theme_manage->body_size;
|
u32 theme_size = theme_manage->body_size;
|
||||||
u32 bgm_size = theme_manage->music_size;
|
u32 bgm_size = theme_manage->music_size;
|
||||||
free(thememanage_buf);
|
free(thememanage_buf);
|
||||||
|
|
||||||
char * temp_buf = NULL;
|
char *temp_buf = NULL;
|
||||||
file_to_buf(fsMakePath(PATH_ASCII, "/BodyCache.bin"), ArchiveThemeExt, &temp_buf);
|
file_to_buf(fsMakePath(PATH_ASCII, "/BodyCache.bin"), ArchiveThemeExt, &temp_buf);
|
||||||
u16 path_output[0x107] = { 0 };
|
u16 path_output[0x107] = { 0 };
|
||||||
memcpy(path_output, path, 0x107);
|
memcpy(path_output, path, 0x107);
|
||||||
@@ -407,7 +387,7 @@ Result dump_current_theme(void)
|
|||||||
free(temp_buf);
|
free(temp_buf);
|
||||||
temp_buf = NULL;
|
temp_buf = NULL;
|
||||||
|
|
||||||
char * smdh_file = calloc(1, 0x36c0);
|
char *smdh_file = calloc(1, 0x36c0);
|
||||||
smdh_file[0] = 0x53; // SMDH magic
|
smdh_file[0] = 0x53; // SMDH magic
|
||||||
smdh_file[1] = 0x4d;
|
smdh_file[1] = 0x4d;
|
||||||
smdh_file[2] = 0x44;
|
smdh_file[2] = 0x44;
|
||||||
@@ -465,24 +445,18 @@ Result dump_all_themes(void)
|
|||||||
case CFG_REGION_EUR:
|
case CFG_REGION_EUR:
|
||||||
low_id = 0x00009800;
|
low_id = 0x00009800;
|
||||||
break;
|
break;
|
||||||
case CFG_REGION_KOR:
|
|
||||||
low_id = 0x0000a900;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * region_arr[7] = {
|
const char* region_arr[4] = {
|
||||||
"JPN",
|
"JPN",
|
||||||
"USA",
|
"USA",
|
||||||
"EUR",
|
"EUR",
|
||||||
"AUS",
|
"AUS",
|
||||||
"CHN",
|
|
||||||
"KOR",
|
|
||||||
"TWN",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * language_arr[12] = {
|
const char* language_arr[12] = {
|
||||||
"jp",
|
"jp",
|
||||||
"en",
|
"en",
|
||||||
"fr",
|
"fr",
|
||||||
@@ -501,14 +475,14 @@ Result dump_all_themes(void)
|
|||||||
if(R_FAILED(res))
|
if(R_FAILED(res))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
Icon_s * smdh_data = calloc(1, sizeof(Icon_s));
|
Icon_s* smdh_data = calloc(1, sizeof(Icon_s));
|
||||||
smdh_data->_padding1[0] = 0x53; // SMDH magic
|
smdh_data->_padding1[0] = 0x53; // SMDH magic
|
||||||
smdh_data->_padding1[1] = 0x4d;
|
smdh_data->_padding1[1] = 0x4d;
|
||||||
smdh_data->_padding1[2] = 0x44;
|
smdh_data->_padding1[2] = 0x44;
|
||||||
smdh_data->_padding1[3] = 0x48;
|
smdh_data->_padding1[3] = 0x48;
|
||||||
|
|
||||||
utf8_to_utf16(smdh_data->author, (u8 *)"Nintendo", 0x40);
|
utf8_to_utf16(smdh_data->author, (u8*)"Nintendo", 0x40);
|
||||||
utf8_to_utf16(smdh_data->desc, (u8 *)"Official theme. For personal use only. Do not redistribute.", 0x80);
|
utf8_to_utf16(smdh_data->desc, (u8*)"Official theme. For personal use only. Do not redistribute.", 0x80);
|
||||||
|
|
||||||
for(u32 dlc_index = 0; dlc_index <= 0xFF; ++dlc_index)
|
for(u32 dlc_index = 0; dlc_index <= 0xFF; ++dlc_index)
|
||||||
{
|
{
|
||||||
@@ -526,12 +500,11 @@ Result dump_all_themes(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
AM_ContentInfo * contentInfos = calloc(count, sizeof(AM_ContentInfo));
|
AM_ContentInfo* contentInfos = calloc(count, sizeof(AM_ContentInfo));
|
||||||
u32 readcount = 0;
|
u32 readcount = 0;
|
||||||
res = AMAPP_ListDLCContentInfos(&readcount, MEDIATYPE_SD, titleId, count, 0, contentInfos);
|
res = AMAPP_ListDLCContentInfos(&readcount, MEDIATYPE_SD, titleId, count, 0, contentInfos);
|
||||||
if(R_FAILED(res))
|
if(R_FAILED(res))
|
||||||
{
|
{
|
||||||
free(contentInfos);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -576,107 +549,109 @@ Result dump_all_themes(void)
|
|||||||
char contentinfoarchive_path[40] = {0};
|
char contentinfoarchive_path[40] = {0};
|
||||||
sprintf(contentinfoarchive_path, "meta:/ContentInfoArchive_%s_%s.bin", region_arr[regionCode], language_arr[language]);
|
sprintf(contentinfoarchive_path, "meta:/ContentInfoArchive_%s_%s.bin", region_arr[regionCode], language_arr[language]);
|
||||||
|
|
||||||
FILE * fh = fopen(contentinfoarchive_path, "rb");
|
FILE* fh = fopen(contentinfoarchive_path, "rb");
|
||||||
|
|
||||||
if(fh != NULL)
|
for(u32 i = 0; i < readcount; ++i)
|
||||||
{
|
{
|
||||||
for(u32 i = 0; i < readcount; ++i)
|
if(i == 0) continue;
|
||||||
|
AM_ContentInfo* content = &contentInfos[i];
|
||||||
|
if((content->flags & (AM_CONTENT_DOWNLOADED | AM_CONTENT_OWNED)) == (AM_CONTENT_DOWNLOADED | AM_CONTENT_OWNED))
|
||||||
{
|
{
|
||||||
if(i == 0) continue;
|
long off = 0x8 + 0xC8 * i;
|
||||||
AM_ContentInfo * content = &contentInfos[i];
|
fseek(fh, off, SEEK_SET);
|
||||||
if((content->flags & (AM_CONTENT_DOWNLOADED | AM_CONTENT_OWNED)) == (AM_CONTENT_DOWNLOADED | AM_CONTENT_OWNED))
|
char content_data[0xc8] = {0};
|
||||||
|
fread(content_data, 1, 0xc8, fh);
|
||||||
|
u32 extra_index = 0;
|
||||||
|
memcpy(&extra_index, content_data + 0xC0, 4);
|
||||||
|
|
||||||
|
metadataPath[1] = content->index;
|
||||||
|
|
||||||
|
Handle theme_fh;
|
||||||
|
res = FSUSER_OpenFile(&theme_fh, ncch_archive, metadata_path, FS_OPEN_READ, 0);
|
||||||
|
if(R_FAILED(res))
|
||||||
{
|
{
|
||||||
long off = 0x8 + 0xC8 * i;
|
DEBUG("theme open romfs error: %08lx\n", res);
|
||||||
fseek(fh, off, SEEK_SET);
|
fclose(fh);
|
||||||
char content_data[0xc8] = {0};
|
free(contentInfos);
|
||||||
fread(content_data, 1, 0xc8, fh);
|
romfsUnmount("meta");
|
||||||
u32 extra_index = 0;
|
FSUSER_CloseArchive(ncch_archive);
|
||||||
memcpy(&extra_index, content_data + 0xC0, 4);
|
free(contentInfos);
|
||||||
|
break;
|
||||||
metadataPath[1] = content->index;
|
|
||||||
|
|
||||||
Handle theme_fh;
|
|
||||||
res = FSUSER_OpenFile(&theme_fh, ncch_archive, metadata_path, FS_OPEN_READ, 0);
|
|
||||||
if(R_FAILED(res))
|
|
||||||
{
|
|
||||||
DEBUG("theme open romfs error: %08lx\n", res);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
romfsMountFromFile(theme_fh, 0, "theme");
|
|
||||||
|
|
||||||
char themename[0x41] = {0};
|
|
||||||
memcpy(themename, content_data, 0x40);
|
|
||||||
char * illegal_char = themename;
|
|
||||||
while ((illegal_char = strpbrk(illegal_char, ILLEGAL_CHARS)))
|
|
||||||
{
|
|
||||||
*illegal_char = '-';
|
|
||||||
}
|
|
||||||
|
|
||||||
char path[0x107] = { 0 };
|
|
||||||
sprintf(path, "%sDump-%02lx-%ld-%s", main_paths[REMOTE_MODE_THEMES], dlc_index, extra_index, themename);
|
|
||||||
DEBUG("theme folder to create: %s\n", path);
|
|
||||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, path), FS_ATTRIBUTE_DIRECTORY);
|
|
||||||
|
|
||||||
memset(smdh_data->name, 0, sizeof(smdh_data->name));
|
|
||||||
utf8_to_utf16(smdh_data->name, (u8 *)(content_data + 0), 0x40);
|
|
||||||
|
|
||||||
FILE * theme_file = fopen("theme:/body_LZ.bin", "rb");
|
|
||||||
if(theme_file)
|
|
||||||
{
|
|
||||||
fseek(theme_file, 0, SEEK_END);
|
|
||||||
long theme_size = ftell(theme_file);
|
|
||||||
fseek(theme_file, 0, SEEK_SET);
|
|
||||||
char * theme_data = malloc(theme_size);
|
|
||||||
fread(theme_data, 1, theme_size, theme_file);
|
|
||||||
fclose(theme_file);
|
|
||||||
|
|
||||||
char themepath[0x107] = {0};
|
|
||||||
sprintf(themepath, "%s/body_LZ.bin", path);
|
|
||||||
remake_file(fsMakePath(PATH_ASCII, themepath), ArchiveSD, theme_size);
|
|
||||||
buf_to_file(theme_size, fsMakePath(PATH_ASCII, themepath), ArchiveSD, theme_data);
|
|
||||||
free(theme_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE * bgm_file = fopen("theme:/bgm.bcstm", "rb");
|
|
||||||
if(bgm_file)
|
|
||||||
{
|
|
||||||
fseek(bgm_file, 0, SEEK_END);
|
|
||||||
long bgm_size = ftell(bgm_file);
|
|
||||||
fseek(bgm_file, 0, SEEK_SET);
|
|
||||||
char * bgm_data = malloc(bgm_size);
|
|
||||||
fread(bgm_data, 1, bgm_size, bgm_file);
|
|
||||||
fclose(bgm_file);
|
|
||||||
|
|
||||||
char bgmpath[0x107] = {0};
|
|
||||||
sprintf(bgmpath, "%s/bgm.bcstm", path);
|
|
||||||
remake_file(fsMakePath(PATH_ASCII, bgmpath), ArchiveSD, bgm_size);
|
|
||||||
buf_to_file(bgm_size, fsMakePath(PATH_ASCII, bgmpath), ArchiveSD, bgm_data);
|
|
||||||
free(bgm_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
romfsUnmount("theme");
|
|
||||||
char icondatapath[0x107] = {0};
|
|
||||||
sprintf(icondatapath, "meta:/icons/%ld.icn", extra_index);
|
|
||||||
FILE * iconfile = fopen(icondatapath, "rb");
|
|
||||||
fread(smdh_data->big_icon, 1, sizeof(smdh_data->big_icon), iconfile);
|
|
||||||
fclose(iconfile);
|
|
||||||
|
|
||||||
strcat(path, "/info.smdh");
|
|
||||||
remake_file(fsMakePath(PATH_ASCII, path), ArchiveSD, 0x36c0);
|
|
||||||
buf_to_file(0x36c0, fsMakePath(PATH_ASCII, path), ArchiveSD, (char *)smdh_data);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fh);
|
romfsMountFromFile(theme_fh, 0, "theme");
|
||||||
fh = NULL;
|
|
||||||
|
char themename[0x41] = {0};
|
||||||
|
memcpy(themename, content_data, 0x40);
|
||||||
|
char * illegal_char = themename;
|
||||||
|
while ((illegal_char = strpbrk(illegal_char, ILLEGAL_CHARS)))
|
||||||
|
{
|
||||||
|
*illegal_char = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
char path[0x107] = { 0 };
|
||||||
|
sprintf(path, "/Themes/Dump-%02lx-%ld-%s", dlc_index, extra_index, themename);
|
||||||
|
DEBUG("theme folder to create: %s\n", path);
|
||||||
|
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, path), FS_ATTRIBUTE_DIRECTORY);
|
||||||
|
|
||||||
|
memset(smdh_data->name, 0, sizeof(smdh_data->name));
|
||||||
|
utf8_to_utf16(smdh_data->name, (u8*)(content_data + 0), 0x40);
|
||||||
|
|
||||||
|
FILE* theme_file = fopen("theme:/body_LZ.bin", "rb");
|
||||||
|
if(theme_file)
|
||||||
|
{
|
||||||
|
fseek(theme_file, 0, SEEK_END);
|
||||||
|
long theme_size = ftell(theme_file);
|
||||||
|
fseek(theme_file, 0, SEEK_CUR);
|
||||||
|
char* theme_data = malloc(theme_size);
|
||||||
|
fread(theme_data, 1, theme_size, theme_file);
|
||||||
|
fclose(theme_file);
|
||||||
|
|
||||||
|
char themepath[0x107] = {0};
|
||||||
|
sprintf(themepath, "%s/body_LZ.bin", path);
|
||||||
|
remake_file(fsMakePath(PATH_ASCII, themepath), ArchiveSD, theme_size);
|
||||||
|
buf_to_file(theme_size, fsMakePath(PATH_ASCII, themepath), ArchiveSD, theme_data);
|
||||||
|
free(theme_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE* bgm_file = fopen("theme:/bgm.bcstm", "rb");
|
||||||
|
if(bgm_file)
|
||||||
|
{
|
||||||
|
fseek(bgm_file, 0, SEEK_END);
|
||||||
|
long bgm_size = ftell(bgm_file);
|
||||||
|
fseek(bgm_file, 0, SEEK_CUR);
|
||||||
|
char* bgm_data = malloc(bgm_size);
|
||||||
|
fread(bgm_data, 1, bgm_size, bgm_file);
|
||||||
|
fclose(bgm_file);
|
||||||
|
|
||||||
|
char bgmpath[0x107] = {0};
|
||||||
|
sprintf(bgmpath, "%s/bgm.bcstm", path);
|
||||||
|
remake_file(fsMakePath(PATH_ASCII, bgmpath), ArchiveSD, bgm_size);
|
||||||
|
buf_to_file(bgm_size, fsMakePath(PATH_ASCII, bgmpath), ArchiveSD, bgm_data);
|
||||||
|
free(bgm_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
romfsUnmount("theme");
|
||||||
|
char icondatapath[0x107] = {0};
|
||||||
|
sprintf(icondatapath, "meta:/icons/%ld.icn", extra_index);
|
||||||
|
FILE* iconfile = fopen(icondatapath, "rb");
|
||||||
|
fread(smdh_data->big_icon, 1, sizeof(smdh_data->big_icon), iconfile);
|
||||||
|
fclose(iconfile);
|
||||||
|
|
||||||
|
strcat(path, "/info.smdh");
|
||||||
|
remake_file(fsMakePath(PATH_ASCII, path), ArchiveSD, 0x36c0);
|
||||||
|
buf_to_file(0x36c0, fsMakePath(PATH_ASCII, path), ArchiveSD, (char*)smdh_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(fh);
|
||||||
|
fh = NULL;
|
||||||
free(contentInfos);
|
free(contentInfos);
|
||||||
contentInfos = NULL;
|
contentInfos = NULL;
|
||||||
|
|
||||||
romfsUnmount("meta");
|
romfsUnmount("meta");
|
||||||
// don't need to close the file opened for the metadata, romfsUnmount took ownership
|
// don't need to close the file opened for the metadata, romfsUnmount took ownership
|
||||||
FSUSER_CloseArchive(ncch_archive);
|
FSUSER_CloseArchive(ncch_archive);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(smdh_data);
|
free(smdh_data);
|
||||||
@@ -691,25 +666,25 @@ void themes_check_installed(void * void_arg)
|
|||||||
if(list == NULL || list->entries == NULL) return;
|
if(list == NULL || list->entries == NULL) return;
|
||||||
|
|
||||||
#ifndef CITRA_MODE
|
#ifndef CITRA_MODE
|
||||||
char * savedata_buf = NULL;
|
char* savedata_buf = NULL;
|
||||||
u32 savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf);
|
u32 savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf);
|
||||||
if(!savedata_size) return;
|
if(!savedata_size) return;
|
||||||
SaveData_dat_s * savedata = (SaveData_dat_s *)savedata_buf;
|
SaveData_dat_s* savedata = (SaveData_dat_s*)savedata_buf;
|
||||||
bool shuffle = savedata->shuffle;
|
bool shuffle = savedata->shuffle;
|
||||||
free(savedata_buf);
|
free(savedata_buf);
|
||||||
|
|
||||||
#define HASH_SIZE_BYTES 256/8
|
#define HASH_SIZE_BYTES 256/8
|
||||||
u8 body_hash[MAX_SHUFFLE_THEMES][HASH_SIZE_BYTES];
|
u8 body_hash[MAX_SHUFFLE_THEMES][HASH_SIZE_BYTES];
|
||||||
memset(body_hash, 0, MAX_SHUFFLE_THEMES * HASH_SIZE_BYTES);
|
memset(body_hash, 0, MAX_SHUFFLE_THEMES*HASH_SIZE_BYTES);
|
||||||
|
|
||||||
char * thememanage_buf = NULL;
|
char* thememanage_buf = NULL;
|
||||||
u32 theme_manage_size = file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
|
u32 theme_manage_size = file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
|
||||||
if(!theme_manage_size) return;
|
if(!theme_manage_size) return;
|
||||||
ThemeManage_bin_s * theme_manage = (ThemeManage_bin_s *)thememanage_buf;
|
ThemeManage_bin_s * theme_manage = (ThemeManage_bin_s *)thememanage_buf;
|
||||||
|
|
||||||
u32 single_body_size = theme_manage->body_size;
|
u32 single_body_size = theme_manage->body_size;
|
||||||
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES] = {0};
|
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES] = {0};
|
||||||
memcpy(shuffle_body_sizes, theme_manage->shuffle_body_sizes, sizeof(u32) * MAX_SHUFFLE_THEMES);
|
memcpy(shuffle_body_sizes, theme_manage->shuffle_body_sizes, sizeof(u32)*MAX_SHUFFLE_THEMES);
|
||||||
free(thememanage_buf);
|
free(thememanage_buf);
|
||||||
|
|
||||||
if(shuffle)
|
if(shuffle)
|
||||||
@@ -720,7 +695,7 @@ void themes_check_installed(void * void_arg)
|
|||||||
|
|
||||||
for(int i = 0; i < MAX_SHUFFLE_THEMES; i++)
|
for(int i = 0; i < MAX_SHUFFLE_THEMES; i++)
|
||||||
{
|
{
|
||||||
FSUSER_UpdateSha256Context(body_buf + BODY_CACHE_SIZE * i, shuffle_body_sizes[i], body_hash[i]);
|
FSUSER_UpdateSha256Context(body_buf + BODY_CACHE_SIZE*i, shuffle_body_sizes[i], body_hash[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(body_buf);
|
free(body_buf);
|
||||||
@@ -741,7 +716,7 @@ void themes_check_installed(void * void_arg)
|
|||||||
{
|
{
|
||||||
Entry_s * theme = &list->entries[i];
|
Entry_s * theme = &list->entries[i];
|
||||||
char * theme_body = NULL;
|
char * theme_body = NULL;
|
||||||
u32 theme_body_size = load_data("/body_LZ.bin", theme, &theme_body);
|
u32 theme_body_size = load_data("/body_LZ.bin", *theme, &theme_body);
|
||||||
if(!theme_body_size) return;
|
if(!theme_body_size) return;
|
||||||
|
|
||||||
u8 theme_body_hash[HASH_SIZE_BYTES];
|
u8 theme_body_hash[HASH_SIZE_BYTES];
|
||||||
|
|||||||
2097
source/ui_strings.c
@@ -26,53 +26,40 @@
|
|||||||
|
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
|
|
||||||
void replace_chars(u16 *input, char *remove, u16 with)
|
ssize_t strulen(const u16 *input, ssize_t max_len)
|
||||||
{
|
|
||||||
for (u16 *cursor = input; *cursor != '\0'; cursor++)
|
|
||||||
{
|
|
||||||
if (strchr(remove, (char) (*cursor & 0xFF)))
|
|
||||||
{
|
|
||||||
*cursor = with;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t strulen(const 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 struacat(u16 * input, const char * addition)
|
void struacat(u16 *input, const char *addition)
|
||||||
{
|
{
|
||||||
const ssize_t len = strulen(input, 0x106);
|
ssize_t len = strulen(input, 0x106);
|
||||||
const u16 stop_at = strlen(addition);
|
for (u16 i = len; i < strlen(addition) + len; i++)
|
||||||
for (u16 i = 0; i < stop_at; i++)
|
|
||||||
{
|
{
|
||||||
input[i + len] = addition[i];
|
input[i] = addition[i - len];
|
||||||
}
|
}
|
||||||
input[stop_at + len] = 0;
|
input[strlen(addition) + len] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printu(u16 * input)
|
void printu(u16 *input)
|
||||||
{
|
{
|
||||||
ssize_t in_len = strulen(input, 0x106);
|
ssize_t in_len = strulen(input, 0x106);
|
||||||
ssize_t buf_len = in_len + 1; // Plus 1 for proper null termination
|
ssize_t buf_len = in_len + 1; // Plus 1 for proper null termination
|
||||||
wchar_t * buf = calloc(buf_len, sizeof(wchar_t));
|
wchar_t *buf = calloc(buf_len, sizeof(wchar_t));
|
||||||
utf16_to_utf32((u32 *)buf, input, buf_len);
|
utf16_to_utf32((u32*)buf, input, buf_len);
|
||||||
char cbuf[0x106];
|
char cbuf[0x106];
|
||||||
sprintf(cbuf, "%ls\n", buf);
|
sprintf(cbuf, "%ls\n", buf);
|
||||||
DEBUG(cbuf);
|
DEBUG(cbuf);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t strucat(u16 * destination, const u16 * source)
|
u16 *strucat(u16 *destination, const u16 *source)
|
||||||
{
|
{
|
||||||
size_t dest_len = strulen(destination, 0x106);
|
ssize_t dest_len = strulen(destination, 0x106);
|
||||||
|
|
||||||
size_t source_len = strulen(source, 0x106);
|
ssize_t source_len = strulen(source, 0x106);
|
||||||
|
|
||||||
memcpy(&destination[dest_len], source, source_len * sizeof(u16));
|
memcpy(&destination[dest_len], source, source_len * sizeof(u16));
|
||||||
destination[min(dest_len + source_len, 0x106 - 1)] = 0;
|
return destination;
|
||||||
return source_len;
|
|
||||||
}
|
}
|
||||||