Compare commits
243 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69e0edffb4 | ||
|
|
ba08ab9108 | ||
|
|
ec91703bdf | ||
| 1418c2bc8d | |||
| b2c4afdc05 | |||
| 79afaca01d | |||
|
|
3ef2092dc2 | ||
| 11113bbc07 | |||
| 7182fd9078 | |||
| e613a525a5 | |||
|
|
a563683d32 | ||
| 0420b23fbf | |||
| c3e09adcb2 | |||
| 4669f13d05 | |||
| 80dd00933b | |||
|
|
bb18085413 | ||
| 29233eadfb | |||
| e40cd00754 | |||
| 7abf989de8 | |||
| 2ed3d8b34d | |||
| 01e7f89a9a | |||
| df4f6a8736 | |||
| 4fdfad0c0a | |||
|
|
74509d75db | ||
|
|
bb1e0ac872 | ||
|
|
d426143eaf | ||
| b2374deaf5 | |||
| d79a96fd75 | |||
| c2edc50750 | |||
| 8e876d027b | |||
| f8fba122ac | |||
| e09c33f0e8 | |||
| 8f676eafae | |||
| 77138530ed | |||
| 9860dec103 | |||
| 1a01ba502f | |||
| df4c81c96d | |||
| 30833995d1 | |||
| b0db54e71a | |||
| 4d9cde01c4 | |||
|
|
8c42a23eeb | ||
|
|
970b3c9749 | ||
| 7035c416cf | |||
| e498b3f24a | |||
|
|
610b21463d | ||
|
|
016e7fd738 | ||
|
|
082b6f8f61 | ||
| 20f3c503ad | |||
| eae7a2250e | |||
| 22492339a6 | |||
| 9b098f6935 | |||
|
|
3c55868183 | ||
|
|
a43cbcca74 | ||
|
|
546d459696 | ||
| d1f3dbf06b | |||
| cdf30f3bea | |||
| c6b6f560be | |||
| 64d65417fa | |||
| b19343e238 | |||
| ecf9dc63ce | |||
| 7e2191ad86 | |||
|
|
d037691418 | ||
| 6b89496566 | |||
|
|
36ca676c99 | ||
|
|
67fc17dddf | ||
|
|
3fa73ee291 | ||
|
|
ae417f8f86 | ||
|
|
adccc70cca | ||
|
|
b66ca12039 | ||
|
|
4a56a883fa | ||
|
|
9ebfe387a0 | ||
|
|
806d0033de | ||
|
|
4c053bb447 | ||
|
|
1ed6c46644 | ||
|
|
e22d09ba54 | ||
|
|
a0c16a64ec | ||
|
|
a1e7ed9924 | ||
|
|
7f7fdc010a | ||
|
|
b81a9aaa4c | ||
|
|
6ba1ef111e | ||
|
|
0500b24431 | ||
|
|
83071d3734 | ||
|
|
4e2bea53c1 | ||
|
|
0da2594251 | ||
|
|
c5dc7448e4 | ||
|
|
999b764c26 | ||
|
|
18cb5c616f | ||
|
|
3f2e4c03f3 | ||
|
|
163e12d38a | ||
| 02c3e617ae | |||
|
|
6161874d07 | ||
|
|
cea9b8655a | ||
|
|
7745530764 | ||
|
|
0bab0f6700 | ||
|
|
38ab370cf1 | ||
|
|
5cea6c8df4 | ||
|
|
e4e0118c1a | ||
|
|
accdaaed2a | ||
|
|
3fb90e8197 | ||
|
|
aba2cd5f18 | ||
|
|
e5ea18e81a | ||
|
|
4720a49923 | ||
|
|
7871225999 | ||
|
|
1e5d09e85a | ||
|
|
a647494306 | ||
|
|
c801e28523 | ||
|
|
c9e1420a00 | ||
|
|
bc2f4ec581 | ||
|
|
9592d76c2c | ||
|
|
a266203a92 | ||
|
|
17afdbaae2 | ||
|
|
f6d7446eba | ||
|
|
c49129d408 | ||
|
|
f9a2ae5190 | ||
|
|
573b7d35e6 | ||
| a2b6eb94e4 | |||
|
|
95ff2dd3ba | ||
|
|
1c2e562dd6 | ||
|
|
9cb13f6be1 | ||
| 6a51b4eae5 | |||
| 14d9e99b7d | |||
| 36e8104dbb | |||
| 6bafa6a22e | |||
|
|
408b2903f2 | ||
| fbca873f52 | |||
| d1a821edf5 | |||
| a4532b0f3d | |||
|
|
f819f9d452 | ||
| 2c2c7f4b33 | |||
| b75d1acb21 | |||
| e8d0a2eb27 | |||
| f4217888ce | |||
|
|
d358dd134e | ||
|
|
ca9da9d297 | ||
|
|
71a4cde22e | ||
|
|
f7404cf162 | ||
|
|
ef774ce0b4 | ||
|
|
193feedf25 | ||
|
|
ddfc39db56 | ||
| 9e378b5059 | |||
| 312fbd5fbf | |||
| d3e1b746cd | |||
|
|
09de17729b | ||
| 9dc3f4c533 | |||
| 0d1ab5ed95 | |||
|
|
c40696e982 | ||
|
|
aa3a00cedc | ||
|
|
89c8a4fae2 | ||
| 5fd86bf7af | |||
| 90d316bd06 | |||
|
|
6d65770840 | ||
|
|
71ecdd9aa5 | ||
|
|
db8f9e81e8 | ||
| 83887bcb8e | |||
| fa37bcec99 | |||
| 1c3e8809f6 | |||
|
|
3dad4e2a67 | ||
|
|
403453c3fc | ||
| fe58e2d938 | |||
|
|
c28b794349 | ||
| d2b83659ea | |||
| 8189264908 | |||
| 5bb98a7fe2 | |||
| 305c55e6b2 | |||
| cb6f90adc7 | |||
| 7beb9b72db | |||
|
|
8e43bb1a74 | ||
| 4dbc71489f | |||
|
|
8022ed1682 | ||
| 5520ec2b2f | |||
| f2aa7420df | |||
| 05b56b1aa1 | |||
|
|
cac2450fde | ||
|
|
1c24d08eef | ||
|
|
24b12023ca | ||
|
|
9ccc705046 | ||
| 95d8808a73 | |||
|
|
6c2f09147f | ||
|
|
7b1d6f9860 | ||
|
|
6f7c2489d5 | ||
|
|
38e70df17b | ||
|
|
ad6117404f | ||
|
|
47de3eb171 | ||
|
|
02c1aab3f3 | ||
|
|
cd69aa7ef7 | ||
|
|
a2b5788fe8 | ||
|
|
5090da114f | ||
|
|
f01e347b17 | ||
|
|
82f6e073ce | ||
|
|
ed94610d0f | ||
|
|
fbbb4f590d | ||
|
|
d2e65d1edc | ||
|
|
fd7e932df3 | ||
|
|
b2e81528af | ||
|
|
f5dd25369a | ||
|
|
fc9d0be42e | ||
|
|
c6f3af7350 | ||
| 642b9f9c13 | |||
| 10b130b416 | |||
|
|
f65b32c90c | ||
|
|
841773d9e4 | ||
|
|
a764ea9bed | ||
|
|
45349a4ba3 | ||
|
|
c85d9d978d | ||
|
|
db0804af3b | ||
|
|
310c92bee2 | ||
|
|
b59e5fc078 | ||
|
|
6eabfc84ab | ||
|
|
cb88c7e2dc | ||
|
|
b72f266e40 | ||
|
|
f261f152c9 | ||
|
|
2848cade74 | ||
|
|
05d3ac73c0 | ||
|
|
a92db32d67 | ||
|
|
78bdb0d738 | ||
|
|
23c98a4ed1 | ||
|
|
15be473684 | ||
|
|
fb18dce177 | ||
|
|
adf2a50143 | ||
|
|
0f27cb1259 | ||
|
|
c1ef601c2f | ||
|
|
7c3ca57e07 | ||
|
|
0818389752 | ||
|
|
6be1b5e217 | ||
|
|
d937ae1716 | ||
|
|
ab4ead03b5 | ||
|
|
026bb367bc | ||
|
|
5c52b475ce | ||
|
|
32116aa8ed | ||
|
|
f01793321e | ||
|
|
3cfbf3c35b | ||
|
|
36106b72f2 | ||
|
|
1d95f47840 | ||
|
|
204d5e8a85 | ||
|
|
6c3fdbaf31 | ||
|
|
b5c78cf68b | ||
| 24810a48ad | |||
|
|
5d2119344a | ||
|
|
492ea13ef6 | ||
|
|
f99f744000 | ||
| 4fb10029bb | |||
| 7644974705 | |||
|
|
b7379af2f3 |
39
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Found a bug? Report it here
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Description**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**Steps to reproduce**
|
||||||
|
***If you cannot reproduce the bug, please describe what you were doing in as much detail as possible***
|
||||||
|
*If you were scanning using the QR scanner, ensure you include a link to the theme you were attempting to download.*
|
||||||
|
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
Add screenshots of any error screens you encountered. Bug reports without screenshots will take longer to solve, so we recommend you get some!
|
||||||
|
|
||||||
|
|
||||||
|
**Crash dumps**
|
||||||
|
If your bug causes a crash in Luma3DS, please upload any crash dumps generated. You can find these in `SD:/luma/dumps/armX` (`X = 9 or 11`) with the name Luma3DS's exception handlers give you.
|
||||||
|
|
||||||
|
|
||||||
|
**System information**
|
||||||
|
*System model* e.g. new3DS XL
|
||||||
|
|
||||||
|
*System firmware version* e.g. 11.14.0 (this can be found in the System Settings applet by default)
|
||||||
|
|
||||||
|
*Anemone3DS version* e.g. v2.2.0 (found in the bottom-left of Anemone3DS)
|
||||||
|
|
||||||
|
*Luma3DS version* e.g. v10.2.1 (found in the menu when you hold Select on boot)
|
||||||
|
|
||||||
|
|
||||||
|
**If you are not on the [latest version of Anemone3DS](https://github.com/astronautlevel2/Anemone3DS/releases/latest), your bug report will likely be closed. Ensure the bug occurs in the latest build!**
|
||||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
1
.gitignore
vendored
@@ -58,6 +58,7 @@ dkms.conf
|
|||||||
# Build files
|
# Build files
|
||||||
build/
|
build/
|
||||||
out/
|
out/
|
||||||
|
romfs/
|
||||||
|
|
||||||
# Sublime stuff
|
# Sublime stuff
|
||||||
.clang_complete
|
.clang_complete
|
||||||
|
|||||||
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
|||||||
[submodule "source/pp2d"]
|
|
||||||
path = source/pp2d
|
|
||||||
url = https://github.com/BernardoGiordano/pp2d.git
|
|
||||||
24
CONTRIBUTORS.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Main Contributors
|
||||||
|
* Alex Taber ([@astronautlevel2](https://github.com/astronautlevel2))
|
||||||
|
* Théo B. ([@LiquidFenrir](https://github.com/LiquidFenrir))
|
||||||
|
* Dawid Eckert ([@daedreth](https://github.com/daedreth))
|
||||||
|
* Dylan G. ([@helloman892](https://github.com/helloman892))
|
||||||
|
* Nils P. ([@ZetaDesigns](https://github.com/ZetaDesigns))
|
||||||
|
* Matt Kenny ([@KennLDN](https://github.com/KennLDN))
|
||||||
|
|
||||||
|
# Minor Contributors
|
||||||
|
* Nic ([@Wizzrobes](https://github.com/Wizzrobes))
|
||||||
|
* [@saibotu](https://github.com/saibotu)
|
||||||
|
* Jeremy Postelnek ([@TurtleP](https://github.com/TurtleP))
|
||||||
|
* [@FrozenChen](https://github.com/FrozenChen)
|
||||||
|
* Luís Marques ([@luigoalma](https://github.com/luigoalma))
|
||||||
|
* [@uyuiyu](https://github.com/uyuiyu)
|
||||||
|
* Guillaume Gérard ([@GreatWizard](https://github.com/GreatWizard))
|
||||||
|
* Joel ([@joel16](https://github.com/joel16))
|
||||||
|
* [@thedax](https://github.com/thedax)
|
||||||
|
* [@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
|
||||||
204
Makefile
@@ -9,18 +9,43 @@ endif
|
|||||||
TOPDIR ?= $(CURDIR)
|
TOPDIR ?= $(CURDIR)
|
||||||
include $(DEVKITARM)/3ds_rules
|
include $(DEVKITARM)/3ds_rules
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# TARGET is the name of the output
|
||||||
|
# BUILD is the directory where object files & intermediate files will be placed
|
||||||
|
# SOURCES is a list of directories containing source code
|
||||||
|
# DATA is a list of directories containing data files
|
||||||
|
# INCLUDES is a list of directories containing header files
|
||||||
|
# GRAPHICS is a list of directories containing graphics files
|
||||||
|
# GFXBUILD is the directory where converted graphics files will be placed
|
||||||
|
# If set to $(BUILD), it will statically link in the converted
|
||||||
|
# files as if they were data files.
|
||||||
|
#
|
||||||
|
# NO_SMDH: if set to anything, no SMDH file is generated.
|
||||||
|
# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
|
||||||
|
# APP_TITLE is the name of the app stored in the SMDH file (Optional)
|
||||||
|
# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
|
||||||
|
# APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
|
||||||
|
# ICON is the filename of the icon (.png), relative to the project folder.
|
||||||
|
# If not set, it attempts to use one of the following (in this order):
|
||||||
|
# - <Project name>.png
|
||||||
|
# - icon.png
|
||||||
|
# - <libctru folder>/default_icon.png
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
# Your values.
|
# Your values.
|
||||||
APP_TITLE := Anemone3DS
|
APP_TITLE := Anemone3DS
|
||||||
APP_DESCRIPTION := A complete themeing tool for the 3DS
|
APP_DESCRIPTION := A complete theming tool for the 3DS
|
||||||
APP_AUTHOR := astronautlevel and daedreth
|
APP_AUTHOR := Anemone3DS Team
|
||||||
|
|
||||||
|
|
||||||
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
|
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
|
||||||
OUTDIR := out
|
OUTDIR := out
|
||||||
BUILD := build
|
BUILD := build
|
||||||
SOURCES := source source/pp2d/pp2d source/minizip source/quirc
|
SOURCES := source source/quirc
|
||||||
INCLUDES := include
|
INCLUDES := include
|
||||||
ROMFS := romfs
|
ROMFS := romfs
|
||||||
|
GRAPHICS := assets
|
||||||
|
GFXBUILD := $(ROMFS)/gfx
|
||||||
|
|
||||||
|
|
||||||
# Path to the files
|
# Path to the files
|
||||||
@@ -33,17 +58,28 @@ BANNER_IMAGE := meta/banner.png
|
|||||||
RSF_PATH := meta/app.rsf
|
RSF_PATH := meta/app.rsf
|
||||||
|
|
||||||
# If left blank, makerom will use the default Homebrew logo
|
# If left blank, makerom will use the default Homebrew logo
|
||||||
LOGO :=
|
LOGO := meta/logo.bin
|
||||||
|
|
||||||
|
|
||||||
# If left blank, makerom will use default values (0xff3ff and CTR-P-CTAP, respectively)
|
# If left blank, makerom will use default values (0xff3ff and CTR-P-CTAP, respectively)
|
||||||
# Be careful if UNIQUE_ID is the same as other apps: it will overwrite the previously installed one
|
# Be careful if UNIQUE_ID is the same as other apps: it will overwrite the previously installed one
|
||||||
UNIQUE_ID := 0xAFEN
|
UNIQUE_ID := 0xBAFE0
|
||||||
PRODUCT_CODE := CTR-P-ANEM
|
PRODUCT_CODE := CTR-P-ANEM
|
||||||
|
|
||||||
# Don't really need to change this
|
# Don't really need to change this
|
||||||
ICON_FLAGS := nosavebackups,visible
|
ICON_FLAGS := nosavebackups,visible
|
||||||
|
|
||||||
|
ifeq ($(strip $(NOGIT)),)
|
||||||
|
VERSION := $(shell git describe --tags --match v[0-9]* --abbrev=7 | sed 's/-[0-9]*-g/-/')
|
||||||
|
VERSION_MAJOR := $(shell echo $(VERSION) | cut -c2- | cut -f1 -d- | cut -f1 -d.)
|
||||||
|
VERSION_MINOR := $(shell echo $(VERSION) | cut -c2- | cut -f1 -d- | cut -f2 -d.)
|
||||||
|
VERSION_BUILD := $(shell echo $(VERSION) | cut -c2- | cut -f1 -d- | cut -f3 -d.)
|
||||||
|
|
||||||
|
ifeq ($(strip $(VERSION_BUILD)),)
|
||||||
|
VERSION_BUILD := 0
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# options for code generation
|
# options for code generation
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
@@ -53,22 +89,24 @@ CFLAGS := -g -Wall -Wextra -O2 -mword-relocations \
|
|||||||
-ffunction-sections \
|
-ffunction-sections \
|
||||||
$(ARCH)
|
$(ARCH)
|
||||||
|
|
||||||
revision := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/')
|
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`
|
||||||
CFLAGS += $(INCLUDE) -DARM11 -D_3DS -D_GNU_SOURCE -DVERSION="\"$(revision)\""
|
ifneq ($(strip $(CITRA_MODE)),)
|
||||||
|
CFLAGS += -DCITRA_MODE
|
||||||
|
endif
|
||||||
|
|
||||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
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 := -lcitro3d -lctrud -lm -lz
|
LIBS := `arm-none-eabi-pkg-config --libs libcurl vorbisidec libarchive jansson libpng` -lcitro2d -lcitro3d -lctru -lm
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# list of directories containing libraries, this must be the top level containing
|
# list of directories containing libraries, this must be the top level containing
|
||||||
# include and lib
|
# include and lib
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
LIBDIRS := $(CTRULIB) $(DEVKITPRO)/portlibs/armv6k
|
LIBDIRS := $(CTRULIB) $(PORTLIBS)
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
@@ -82,6 +120,7 @@ export OUTPUT := $(CURDIR)/$(OUTDIR)/$(TARGET)
|
|||||||
export TOPDIR := $(CURDIR)
|
export TOPDIR := $(CURDIR)
|
||||||
|
|
||||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||||
|
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) \
|
||||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||||
|
|
||||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||||
@@ -91,6 +130,7 @@ CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
|||||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||||
PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
|
PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
|
||||||
SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
|
SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
|
||||||
|
GFXFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.t3s)))
|
||||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
@@ -107,9 +147,30 @@ else
|
|||||||
endif
|
endif
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
#---------------------------------------------------------------------------------
|
||||||
|
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_BIN := $(addsuffix .o,$(BINFILES)) \
|
||||||
$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
|
$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
|
||||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
$(addsuffix .o,$(T3XFILES))
|
||||||
|
|
||||||
|
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
|
||||||
|
|
||||||
|
export HFILES := $(PICAFILES:.v.pica=_shbin.h) $(SHLISTFILES:.shlist=_shbin.h) \
|
||||||
|
$(addsuffix .h,$(subst .,_,$(BINFILES))) \
|
||||||
|
$(GFXFILES:.t3s=.h)
|
||||||
|
|
||||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||||
@@ -117,6 +178,8 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
|||||||
|
|
||||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||||
|
|
||||||
|
export _3DSXDEPS := $(if $(NO_SMDH),,$(OUTPUT).smdh)
|
||||||
|
|
||||||
ifeq ($(strip $(ICON)),)
|
ifeq ($(strip $(ICON)),)
|
||||||
icons := $(wildcard *.png)
|
icons := $(wildcard *.png)
|
||||||
ifneq (,$(findstring $(TARGET).png,$(icons)))
|
ifneq (,$(findstring $(TARGET).png,$(icons)))
|
||||||
@@ -138,53 +201,24 @@ ifneq ($(ROMFS),)
|
|||||||
export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
|
export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: $(BUILD) clean all
|
.PHONY: all clean
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
all: 3dsx cia
|
|
||||||
|
|
||||||
3dsx: $(BUILD) $(OUTPUT).3dsx
|
|
||||||
|
|
||||||
cia : $(BUILD) $(OUTPUT).cia
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
$(BUILD):
|
|
||||||
@mkdir -p $(OUTDIR)
|
|
||||||
@[ -d "$@" ] || mkdir -p "$@"
|
|
||||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
clean:
|
|
||||||
@echo clean ...
|
|
||||||
@rm -fr $(BUILD) $(OUTDIR)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
ifeq ($(strip $(NO_SMDH)),)
|
|
||||||
$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh
|
|
||||||
else
|
|
||||||
$(OUTPUT).3dsx : $(OUTPUT).elf
|
|
||||||
endif
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
MAKEROM ?= makerom
|
MAKEROM ?= makerom
|
||||||
|
|
||||||
MAKEROM_ARGS := -elf "$(OUTPUT).elf" -rsf "$(RSF_PATH)" -banner "$(BUILD)/banner.bnr" -icon "$(BUILD)/icon.icn" -DAPP_TITLE="$(APP_TITLE)" -DAPP_PRODUCT_CODE="$(PRODUCT_CODE)" -DAPP_UNIQUE_ID="$(UNIQUE_ID)"
|
MAKEROM_ARGS := -elf "$(OUTPUT).elf" -rsf "$(RSF_PATH)" -banner "$(BUILD)/banner.bnr" -icon "$(BUILD)/icon.icn" -DAPP_TITLE="$(APP_TITLE)" -DAPP_PRODUCT_CODE="$(PRODUCT_CODE)" -DAPP_UNIQUE_ID="$(UNIQUE_ID)"
|
||||||
|
|
||||||
#ifneq ($(strip $(ROMFS)),)
|
ifeq ($(strip $(NOGIT)),)
|
||||||
# MAKEROM_ARGS += -romfs "$(BUILD)/romfs.bin"
|
MAKEROM_ARGS += -major $(VERSION_MAJOR) -minor $(VERSION_MINOR) -micro $(VERSION_BUILD)
|
||||||
#endif
|
endif
|
||||||
|
|
||||||
ifneq ($(strip $(LOGO)),)
|
ifneq ($(strip $(LOGO)),)
|
||||||
MAKEROM_ARGS += -logo "$(LOGO)"
|
MAKEROM_ARGS += -logo "$(LOGO)"
|
||||||
endif
|
endif
|
||||||
|
ifneq ($(strip $(ROMFS)),)
|
||||||
ifeq ($(strip $(ROMFS)),)
|
MAKEROM_ARGS += -DAPP_ROMFS="$(ROMFS)"
|
||||||
$(OUTPUT).cia: $(OUTPUT).elf $(BUILD)/banner.bnr $(BUILD)/icon.icn
|
|
||||||
$(MAKEROM) -f cia -o "$@" -target t -exefslogo $(MAKEROM_ARGS)
|
|
||||||
else
|
|
||||||
$(OUTPUT).cia: $(OUTPUT).elf $(BUILD)/banner.bnr $(BUILD)/icon.icn
|
|
||||||
$(MAKEROM) -f cia -o "$@" -target t -exefslogo $(MAKEROM_ARGS)
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
BANNERTOOL ?= bannertool
|
BANNERTOOL ?= bannertool
|
||||||
|
|
||||||
ifeq ($(suffix $(BANNER_IMAGE)),.cgfx)
|
ifeq ($(suffix $(BANNER_IMAGE)),.cgfx)
|
||||||
@@ -199,57 +233,75 @@ else
|
|||||||
BANNER_AUDIO_ARG := -a
|
BANNER_AUDIO_ARG := -a
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(BUILD)/banner.bnr : $(BANNER_IMAGE) $(BANNER_AUDIO)
|
#---------------------------------------------------------------------------------
|
||||||
$(BANNERTOOL) makebanner $(BANNER_IMAGE_ARG) "$(BANNER_IMAGE)" $(BANNER_AUDIO_ARG) "$(BANNER_AUDIO)" -o "$@"
|
all: $(BUILD) $(GFXBUILD) $(DEPSDIR) $(ROMFS_T3XFILES) $(T3XHFILES) $(OUTDIR)
|
||||||
|
@$(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) 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)
|
||||||
|
|
||||||
$(BUILD)/icon.icn : $(APP_ICON)
|
$(BUILD):
|
||||||
$(BANNERTOOL) makesmdh -s "$(APP_TITLE)" -l "$(APP_DESCRIPTION)" -p "$(APP_AUTHOR)" -i "$(APP_ICON)" -f "$(ICON_FLAGS)" -o "$@"
|
@mkdir -p $@
|
||||||
|
|
||||||
|
ifneq ($(GFXBUILD),$(BUILD))
|
||||||
|
$(GFXBUILD):
|
||||||
|
@mkdir -p $@
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq ($(DEPSDIR),$(BUILD))
|
||||||
|
$(DEPSDIR):
|
||||||
|
@mkdir -p $@
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
@mkdir -p $@
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
clean:
|
||||||
|
$(SILENTMSG) clean ...
|
||||||
|
@rm -fr $(BUILD) $(GFXBUILD) $(DEPSDIR) $(OUTDIR)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
$(GFXBUILD)/%.t3x $(BUILD)/%.h : %.t3s
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@tex3ds -i $< -H $(BUILD)/$*.h -d $(DEPSDIR)/$*.d -o $(GFXBUILD)/$*.t3x
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
else
|
else
|
||||||
|
|
||||||
DEPENDS := $(OFILES:.o=.d)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# main targets
|
# main targets
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
$(OUTPUT).3dsx : $(OUTPUT).elf $(_3DSXDEPS)
|
||||||
|
|
||||||
|
$(OFILES_SOURCES) : $(HFILES)
|
||||||
|
|
||||||
$(OUTPUT).elf : $(OFILES)
|
$(OUTPUT).elf : $(OFILES)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# you need a rule like this for each extension you use as binary data
|
# you need a rule like this for each extension you use as binary data
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
%.bin.o : %.bin
|
%.bin.o %_bin.h : %.bin
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
@echo $(notdir $<)
|
@echo $(notdir $<)
|
||||||
@$(bin2o)
|
@$(bin2o)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# rules for assembling GPU shaders
|
.PRECIOUS : %.t3x %.shbin
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
define shader-as
|
%.t3x.o %_t3x.h : %.t3x
|
||||||
$(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@)))
|
#---------------------------------------------------------------------------------
|
||||||
picasso -o $(CURBIN) $1
|
$(SILENTMSG) $(notdir $<)
|
||||||
bin2s $(CURBIN) | $(AS) -o $@
|
$(bin2o)
|
||||||
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
|
|
||||||
endef
|
|
||||||
|
|
||||||
%.shbin.o : %.v.pica %.g.pica
|
#---------------------------------------------------------------------------------
|
||||||
@echo $(notdir $^)
|
%.shbin.o %_shbin.h : %.shbin
|
||||||
@$(call shader-as,$^)
|
#---------------------------------------------------------------------------------
|
||||||
|
$(SILENTMSG) $(notdir $<)
|
||||||
|
$(bin2o)
|
||||||
|
|
||||||
%.shbin.o : %.v.pica
|
-include $(DEPSDIR)/*.d
|
||||||
@echo $(notdir $<)
|
|
||||||
@$(call shader-as,$<)
|
|
||||||
|
|
||||||
%.shbin.o : %.shlist
|
|
||||||
@echo $(notdir $<)
|
|
||||||
@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file)))
|
|
||||||
|
|
||||||
-include $(DEPENDS)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------------
|
||||||
endif
|
endif
|
||||||
|
|||||||
40
README.md
@@ -1,33 +1,39 @@
|
|||||||

|

|
||||||
|
|
||||||
A Theme and Splashscreen Manager for the Nintendo3DS, written in C.
|
A Theme and Splashscreen Manager for the Nintendo 3DS, written in C.
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
* zlib, which can be retrieved from the [3ds_portlibs](https://github.com/devkitPro/3ds_portlibs).
|
* Make, Git and PKG-Config
|
||||||
* [makerom](https://github.com/profi200/Project_CTR) and [bannertool](https://github.com/Steveice10/buildtools), which can be retrieved from [SteveIce10's](https://github.com/Steveice10) buildtools repo. These must be added to your PATH.
|
* devkitARM, which can be installed following the instructions [here](https://devkitpro.org/wiki/Getting_Started).
|
||||||
* [pp2d](https://github.com/BernardoGiordano/pp2d), which is included in the repo if you do a git clone --recursive.
|
* jansson, libvorbisidec, libpng, and libarchive, which can be retrieved from [devkitPro pacman](https://devkitpro.org/viewtopic.php?f=13&t=8702).
|
||||||
* Git needs to be on your PATH, if building in a non-*nix environment.
|
* 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.
|
||||||
|
|
||||||
# Building
|
# Building
|
||||||
First of all, make sure devkitPRO is properly installed and added to the PATH.
|
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 type: `git clone https://github.com/astronautlevel2/Anemone3DS/ --recursive`.
|
After that, open the directory you want to clone the repo into, and execute
|
||||||
Instructions for installing zlib can be found on the [3ds_portlibs repo](https://github.com/devkitPro/3ds_portlibs) (its easy, just run `make` and `make install-zlib`). After also 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 files will be in `/out/`.
|
`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.
|
||||||
|
|
||||||
|
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/`.
|
||||||
|
|
||||||
# License
|
# License
|
||||||
This project is licensed under the GNU GPLv3. See LICENSE.md for details. Additional terms 7b and 7c apply to this project.
|
This project is licensed under the GNU GPLv3. See LICENSE.md for details. Additional terms 7b and 7c apply to this project.
|
||||||
|
|
||||||
# Credits
|
# Credits
|
||||||
The following people contributed to Anemone3DS in some way. Without these people, Anemone3DS wouldn't exist, or wouldn't be as good as it is:
|
The following people contributed to Anemone3DS in some way. Without these people, Anemone3DS wouldn't exist, or wouldn't be as good as it is: [CONTRIBUTORS.md](CONTRIBUTORS.md)
|
||||||
* [Daedreth](https://github.com/daedreth), who wrote the initial implementation of theme application code and SMDH parsing.
|
|
||||||
* [LiquidFenrir](https://github.com/LiquidFenrir), who refactored a lot of my messy GUI code and wrote the image preview from zip code, as well as the icon code.
|
|
||||||
* [Sono](https://github.com/MarcuzD), who wrote the BCSTM playback code.
|
|
||||||
* [Kenn (mattkenster)](https://github.com/mattkenster), for designing the GUI, a number of sprites used in the application, and drawing the banner and icon.
|
|
||||||
|
|
||||||
Special thanks go to these people who, while not directly contributing, helped immensely:
|
Most of the icons under `romfs` are from the site [icons8.com](https://icons8.com) and are licensed under the [CC-BY-NC-SA](https://creativecommons.org/licenses/by-nc-sa/3.0/)
|
||||||
|
|
||||||
|
Special thanks go to these people who, whilst not directly contributing, helped immensely:
|
||||||
* [Rinnegatamante](https://github.com/Rinnegatamante), whose code served as reference on theme installation.
|
* [Rinnegatamante](https://github.com/Rinnegatamante), whose code served as reference on theme installation.
|
||||||
|
* [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.
|
||||||
* 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).
|
* [MrCheeze](https://github.com/MrCheeze) and [AntiMach](https://github.com/AntiMach) whose GYTB and ABE code served as a reference on badge management
|
||||||
* the maintainers for all used libraries, including ctrulib, zlib, citro3d, pp2d, quirc and minizip.
|
* [Tobid7](https://github.com/tobid7) whose BCSTM-Player project served as a reference on the BCSTM format
|
||||||
* all the people who helped keep me going and motivated me to work. This includes, but is definitely not limited to:
|
* 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).
|
||||||
|
* 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/arrow_down.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
assets/arrow_left.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
assets/arrow_right.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
BIN
assets/back.png
Normal file
|
After Width: | Height: | Size: 606 B |
BIN
assets/badge.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
assets/battery0.png
Normal file
|
After Width: | Height: | Size: 498 B |
BIN
assets/battery1.png
Normal file
|
After Width: | Height: | Size: 303 B |
BIN
assets/battery2.png
Normal file
|
After Width: | Height: | Size: 319 B |
BIN
assets/battery3.png
Normal file
|
After Width: | Height: | Size: 323 B |
BIN
assets/battery4.png
Normal file
|
After Width: | Height: | Size: 323 B |
BIN
assets/battery5.png
Normal file
|
After Width: | Height: | Size: 323 B |
BIN
assets/bgm_only.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/browse.png
Normal file
|
After Width: | Height: | Size: 654 B |
|
Before Width: | Height: | Size: 806 B After Width: | Height: | Size: 806 B |
BIN
assets/dump.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/exit.png
Normal file
|
After Width: | Height: | Size: 390 B |
BIN
assets/install.png
Normal file
|
After Width: | Height: | Size: 404 B |
BIN
assets/installed.png
Normal file
|
After Width: | Height: | Size: 579 B |
BIN
assets/menu.png
Normal file
|
After Width: | Height: | Size: 179 B |
BIN
assets/no_home.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
assets/preview.png
Normal file
|
After Width: | Height: | Size: 307 B |
BIN
assets/qr.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
assets/select.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
assets/shuffle.png
Normal file
|
After Width: | Height: | Size: 658 B |
BIN
assets/shuffle_no_bgm.png
Normal file
|
After Width: | Height: | Size: 511 B |
BIN
assets/sort.png
Normal file
|
After Width: | Height: | Size: 291 B |
29
assets/sprites.t3s
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
--atlas -f rgba8888 -z auto
|
||||||
|
arrow_up.png
|
||||||
|
arrow_down.png
|
||||||
|
arrow_left.png
|
||||||
|
arrow_right.png
|
||||||
|
battery0.png
|
||||||
|
battery1.png
|
||||||
|
battery2.png
|
||||||
|
battery3.png
|
||||||
|
battery4.png
|
||||||
|
battery5.png
|
||||||
|
browse.png
|
||||||
|
charging.png
|
||||||
|
install.png
|
||||||
|
exit.png
|
||||||
|
installed.png
|
||||||
|
menu.png
|
||||||
|
no_home.png
|
||||||
|
preview.png
|
||||||
|
select.png
|
||||||
|
shuffle.png
|
||||||
|
shuffle_no_bgm.png
|
||||||
|
sort.png
|
||||||
|
start.png
|
||||||
|
qr.png
|
||||||
|
bgm_only.png
|
||||||
|
back.png
|
||||||
|
dump.png
|
||||||
|
badge.png
|
||||||
BIN
assets/start.png
Normal file
|
After Width: | Height: | Size: 494 B |
42
include/badges.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Anemone3DS
|
* This file is part of Anemone3DS
|
||||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -29,11 +29,25 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
bool qr_mode;
|
typedef struct {
|
||||||
|
u16 * camera_buffer;
|
||||||
|
|
||||||
void init_qr(void);
|
Handle event_stop;
|
||||||
void exit_qr(void);
|
Thread cam_thread, ui_thread;
|
||||||
void take_picture(void);
|
|
||||||
Result http_get(char *url, char *path);
|
|
||||||
|
|
||||||
#endif
|
LightEvent event_cam_info, event_ui_info;
|
||||||
|
|
||||||
|
CondVar cond;
|
||||||
|
LightLock mut;
|
||||||
|
u32 num_readers_active;
|
||||||
|
bool writer_waiting;
|
||||||
|
bool writer_active;
|
||||||
|
|
||||||
|
bool any_update;
|
||||||
|
|
||||||
|
struct quirc * context;
|
||||||
|
} qr_data;
|
||||||
|
|
||||||
|
bool init_qr(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
52
include/colors.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* 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 COLORS_H
|
||||||
|
#define COLORS_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
typedef u32 Color;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
COLOR_BACKGROUND, //silver-y black
|
||||||
|
COLOR_ACCENT,
|
||||||
|
COLOR_WHITE_BACKGROUND,
|
||||||
|
COLOR_WHITE_ACCENT,
|
||||||
|
COLOR_CURSOR,
|
||||||
|
COLOR_BLACK,
|
||||||
|
COLOR_RED_BACKGROUND,
|
||||||
|
COLOR_RED_ACCENT,
|
||||||
|
COLOR_YELLOW,
|
||||||
|
|
||||||
|
COLOR_AMOUNT,
|
||||||
|
} Colors_e;
|
||||||
|
|
||||||
|
extern Color colors[COLOR_AMOUNT];
|
||||||
|
void init_colors(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Anemone3DS
|
* This file is part of Anemone3DS
|
||||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -28,39 +28,62 @@
|
|||||||
#define COMMON_H
|
#define COMMON_H
|
||||||
|
|
||||||
#include <3ds.h>
|
#include <3ds.h>
|
||||||
|
#include <citro3d.h>
|
||||||
|
#include <citro2d.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define THEMES_PATH "/Themes/"
|
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
|
||||||
#define SPLASHES_PATH "/Splashes/"
|
#define POS() DEBUG("%s (line %d)...\n", __func__, __LINE__)
|
||||||
|
|
||||||
#define SINGLE_INSTALL 0
|
#define DEBUGPOS(...) do {\
|
||||||
#define SHUFFLE_INSTALL 1
|
POS(); \
|
||||||
#define BGM_INSTALL 2
|
DEBUG(__VA_ARGS__); \
|
||||||
#define UNINSTALL 3
|
} while(0)
|
||||||
#define DOWNLOADING 3
|
|
||||||
|
|
||||||
#define ERROR 0
|
static inline int min(const int a, const int b)
|
||||||
#define WARNING 1
|
{
|
||||||
static const int THEMES_PER_SCREEN = 4;
|
return a > b ? b : a;
|
||||||
|
}
|
||||||
|
static inline int max(const int a, const int b)
|
||||||
|
{
|
||||||
|
return a < b ? b : a;
|
||||||
|
}
|
||||||
|
|
||||||
bool homebrew;
|
#define FASTSCROLL_WAIT 1e8
|
||||||
bool splash_mode;
|
|
||||||
|
|
||||||
enum TextureID {
|
#define BETWEEN(min, x, max) (min < x && x < max)
|
||||||
TEXTURE_FONT_RESERVED = 0, //used by pp2d for the font
|
|
||||||
TEXTURE_ARROW,
|
|
||||||
TEXTURE_SHUFFLE,
|
|
||||||
TEXTURE_BATTERY_1,
|
|
||||||
TEXTURE_BATTERY_2,
|
|
||||||
TEXTURE_BATTERY_3,
|
|
||||||
TEXTURE_BATTERY_4,
|
|
||||||
TEXTURE_BATTERY_5,
|
|
||||||
TEXTURE_BATTERY_CHARGE,
|
|
||||||
TEXTURE_QR,
|
|
||||||
TEXTURE_PREVIEW,
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
typedef enum {
|
||||||
|
MODE_THEMES = 0,
|
||||||
|
MODE_SPLASHES,
|
||||||
|
|
||||||
|
MODE_AMOUNT,
|
||||||
|
} EntryMode;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
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_h[MODE_AMOUNT];
|
||||||
|
extern const int entry_size[MODE_AMOUNT];
|
||||||
|
extern bool quit;
|
||||||
|
extern bool dspfirm;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
50
include/config.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
11
include/conversion.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#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
|
||||||
169
include/draw.h
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Anemone3DS
|
* This file is part of Anemone3DS
|
||||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,18 +27,165 @@
|
|||||||
#ifndef DRAW_H
|
#ifndef DRAW_H
|
||||||
#define DRAW_H
|
#define DRAW_H
|
||||||
|
|
||||||
#include "themes.h"
|
#include "common.h"
|
||||||
#include "splashes.h"
|
#include "loading.h"
|
||||||
#include "camera.h"
|
#include "colors.h"
|
||||||
|
|
||||||
|
#define MAX_LINES 10
|
||||||
|
|
||||||
|
typedef enum InstallType_e {
|
||||||
|
INSTALL_LOADING_THEMES,
|
||||||
|
INSTALL_LOADING_SPLASHES,
|
||||||
|
INSTALL_LOADING_ICONS,
|
||||||
|
|
||||||
|
INSTALL_SPLASH,
|
||||||
|
INSTALL_SPLASH_DELETE,
|
||||||
|
|
||||||
|
INSTALL_SINGLE,
|
||||||
|
INSTALL_SHUFFLE,
|
||||||
|
INSTALL_BGM,
|
||||||
|
INSTALL_NO_BGM,
|
||||||
|
|
||||||
|
INSTALL_DOWNLOAD,
|
||||||
|
INSTALL_CHECKING_DOWNLOAD,
|
||||||
|
INSTALL_ENTRY_DELETE,
|
||||||
|
|
||||||
|
INSTALL_LOADING_REMOTE_THEMES,
|
||||||
|
INSTALL_LOADING_REMOTE_SPLASHES,
|
||||||
|
INSTALL_LOADING_REMOTE_BADGES,
|
||||||
|
INSTALL_LOADING_REMOTE_PREVIEW,
|
||||||
|
INSTALL_LOADING_REMOTE_BGM,
|
||||||
|
|
||||||
|
INSTALL_DUMPING_THEME,
|
||||||
|
INSTALL_DUMPING_ALL_THEMES,
|
||||||
|
INSTALL_DUMPING_BADGES,
|
||||||
|
INSTALL_BADGES,
|
||||||
|
|
||||||
|
INSTALL_NONE,
|
||||||
|
} InstallType;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
// InstallType text
|
||||||
|
TEXT_INSTALL_LOADING_THEMES,
|
||||||
|
TEXT_INSTALL_LOADING_SPLASHES,
|
||||||
|
TEXT_INSTALL_LOADING_ICONS,
|
||||||
|
|
||||||
|
TEXT_INSTALL_SPLASH,
|
||||||
|
TEXT_INSTALL_SPLASH_DELETE,
|
||||||
|
|
||||||
|
TEXT_INSTALL_SINGLE,
|
||||||
|
TEXT_INSTALL_SHUFFLE,
|
||||||
|
TEXT_INSTALL_BGM,
|
||||||
|
TEXT_INSTALL_NO_BGM,
|
||||||
|
|
||||||
|
TEXT_INSTALL_DOWNLOAD,
|
||||||
|
TEXT_INSTALL_CHECKING_DOWNLOAD,
|
||||||
|
TEXT_INSTALL_ENTRY_DELETE,
|
||||||
|
|
||||||
|
TEXT_INSTALL_LOADING_REMOTE_THEMES,
|
||||||
|
TEXT_INSTALL_LOADING_REMOTE_SPLASHES,
|
||||||
|
TEXT_INSTALL_LOADING_REMOTE_BADGES,
|
||||||
|
TEXT_INSTALL_LOADING_REMOTE_PREVIEW,
|
||||||
|
TEXT_INSTALL_LOADING_REMOTE_BGM,
|
||||||
|
|
||||||
|
TEXT_INSTALL_DUMPING_THEME,
|
||||||
|
TEXT_INSTALL_DUMPING_ALL_THEMES,
|
||||||
|
TEXT_INSTALL_DUMPING_BADGES,
|
||||||
|
TEXT_INSTALL_BADGES,
|
||||||
|
|
||||||
|
// Other text
|
||||||
|
TEXT_VERSION,
|
||||||
|
|
||||||
|
TEXT_THEME_MODE,
|
||||||
|
TEXT_SPLASH_MODE,
|
||||||
|
|
||||||
|
TEXT_NO_THEME_FOUND,
|
||||||
|
TEXT_NO_SPLASH_FOUND,
|
||||||
|
|
||||||
|
TEXT_DOWNLOAD_FROM_QR,
|
||||||
|
|
||||||
|
TEXT_SWITCH_TO_SPLASHES,
|
||||||
|
TEXT_SWITCH_TO_THEMES,
|
||||||
|
|
||||||
|
TEXT_OR_START_TO_QUIT,
|
||||||
|
|
||||||
|
TEXT_BY_AUTHOR,
|
||||||
|
TEXT_SELECTED,
|
||||||
|
TEXT_SELECTED_SHORT,
|
||||||
|
|
||||||
|
TEXT_THEMEPLAZA_THEME_MODE,
|
||||||
|
TEXT_THEMEPLAZA_SPLASH_MODE,
|
||||||
|
TEXT_THEMEPLAZA_BADGE_MODE,
|
||||||
|
|
||||||
|
TEXT_SEARCH,
|
||||||
|
TEXT_PAGE,
|
||||||
|
|
||||||
|
TEXT_ERROR_QUIT,
|
||||||
|
TEXT_ERROR_CONTINUE,
|
||||||
|
|
||||||
|
TEXT_CONFIRM_YES_NO,
|
||||||
|
|
||||||
|
TEXT_AMOUNT
|
||||||
|
} Text;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ERROR_LEVEL_ERROR,
|
||||||
|
ERROR_LEVEL_WARNING,
|
||||||
|
} ErrorLevel;
|
||||||
|
|
||||||
|
#define BUTTONS_START_Y 130
|
||||||
|
#define BUTTONS_STEP 22
|
||||||
|
#define BUTTONS_INFO_LINES 4
|
||||||
|
#define BUTTONS_INFO_COLUNMNS 2
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BUTTONS_Y_INFO = BUTTONS_START_Y+5,
|
||||||
|
|
||||||
|
BUTTONS_Y_LINE_1 = BUTTONS_START_Y + BUTTONS_STEP*1,
|
||||||
|
BUTTONS_Y_LINE_2 = BUTTONS_START_Y + BUTTONS_STEP*2,
|
||||||
|
BUTTONS_Y_LINE_3 = BUTTONS_START_Y + BUTTONS_STEP*3,
|
||||||
|
BUTTONS_Y_LINE_4 = BUTTONS_START_Y + BUTTONS_STEP*4,
|
||||||
|
|
||||||
|
BUTTONS_X_LEFT = 20,
|
||||||
|
BUTTONS_X_RIGHT = 200,
|
||||||
|
BUTTONS_X_MAX = 380,
|
||||||
|
} ButtonPos;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char * info_line;
|
||||||
|
const char * instructions[BUTTONS_INFO_LINES][BUTTONS_INFO_COLUNMNS];
|
||||||
|
} Instructions_s;
|
||||||
|
|
||||||
|
extern C3D_RenderTarget * top;
|
||||||
|
extern C3D_RenderTarget * bottom;
|
||||||
|
extern C2D_TextBuf staticBuf, dynamicBuf;
|
||||||
|
|
||||||
|
extern C2D_Text text[TEXT_AMOUNT];
|
||||||
|
|
||||||
void init_screens(void);
|
void init_screens(void);
|
||||||
void exit_screens(void);
|
void exit_screens(void);
|
||||||
|
|
||||||
void draw_themext_error(void);
|
void start_frame(void);
|
||||||
|
void end_frame(void);
|
||||||
|
void set_screen(C3D_RenderTarget * screen);
|
||||||
|
|
||||||
|
void throw_error(const char * error, ErrorLevel level);
|
||||||
|
bool draw_confirm(const char * conf_msg, Entry_List_s * list, DrawMode draw_mode);
|
||||||
|
|
||||||
|
void draw_preview(C2D_Image preview, int preview_offset, float preview_scale);
|
||||||
|
|
||||||
|
void draw_install(InstallType type);
|
||||||
|
void draw_loading_bar(u32 current, u32 max, InstallType type);
|
||||||
|
|
||||||
|
void draw_text(float x, float y, float z, float scaleX, float scaleY, Color color, const char * text);
|
||||||
|
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_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_theme_install(int install_type);
|
void draw_grid_interface(Entry_List_s * list, Instructions_s instructions, int extra_mode);
|
||||||
void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_theme, bool preview_mode, int shuffle_theme_count);
|
void draw_interface(Entry_List_s * list, Instructions_s instructions, DrawMode draw_mode);
|
||||||
void draw_splash_install(int install_type);
|
bool draw_confirm_no_interface(const char *conf_msg);
|
||||||
void draw_splash_interface(Splash_s *splashes_list, int splash_count, int selected_splash, bool preview_mode);
|
|
||||||
void throw_error(char* error, int error_type);
|
#endif
|
||||||
#endif
|
|
||||||
|
|||||||
106
include/entries_list.h
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
49
include/fs.h
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Anemone3DS
|
* This file is part of Anemone3DS
|
||||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -28,18 +28,49 @@
|
|||||||
#define FS_H
|
#define FS_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "badges.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
FS_Archive ArchiveSD;
|
#define ILLEGAL_CHARS "><\"?;:/\\+,.|[=]*\n\r"
|
||||||
FS_Archive ArchiveHomeExt;
|
|
||||||
FS_Archive ArchiveThemeExt;
|
|
||||||
|
|
||||||
|
extern FS_Archive ArchiveSD;
|
||||||
|
extern FS_Archive ArchiveHomeExt;
|
||||||
|
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);
|
||||||
|
|
||||||
u64 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_file_to_buf(char *file_name, u16 *zip_path, char **buf);
|
u32 zip_memory_to_buf(const 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 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);
|
||||||
|
|
||||||
Result buf_to_file(u32 size, char *path, FS_Archive archive, char *buf);
|
Result buf_to_file(u32 size, FS_Path path, FS_Archive archive, char * buf);
|
||||||
void remake_file(char *path, FS_Archive archive, u32 size);
|
Result zero_handle_memeasy(Handle handle);
|
||||||
|
void remake_file(FS_Path path, FS_Archive archive, u32 size);
|
||||||
|
void save_zip_to_sd(char * filename, u32 size, char * buf, RemoteMode 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
|
||||||
|
|||||||
80
include/loading.h
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* 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 LOADING_H
|
||||||
|
#define LOADING_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "entries_list.h"
|
||||||
|
#include "music.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 {
|
||||||
|
ICONS_ABOVE = 0,
|
||||||
|
ICONS_VISIBLE,
|
||||||
|
ICONS_UNDER,
|
||||||
|
|
||||||
|
ICONS_OFFSET_AMOUNT,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u8 _padding1[4 + 2 + 2];
|
||||||
|
|
||||||
|
u16 name[0x40];
|
||||||
|
u16 desc[0x80];
|
||||||
|
u16 author[0x40];
|
||||||
|
|
||||||
|
u8 _padding2[0x2000 - 0x200 + 0x30 + 0x8];
|
||||||
|
u16 small_icon[24 * 24];
|
||||||
|
|
||||||
|
u16 big_icon[48 * 48];
|
||||||
|
} Icon_s;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void ** thread_arg;
|
||||||
|
volatile bool run_thread;
|
||||||
|
} Thread_Arg_s;
|
||||||
|
|
||||||
|
void copy_texture_data(C3D_Tex * texture, const u16 * src, const Entry_Icon_s * current_icon);
|
||||||
|
void parse_smdh(Icon_s * icon, Entry_s * entry, const u16 * fallback_name);
|
||||||
|
|
||||||
|
|
||||||
|
bool load_preview_from_buffer(char * row_pointers, u32 size, C2D_Image * preview_image, int * preview_offset, int height);
|
||||||
|
bool load_preview(const Entry_List_s * list, C2D_Image * preview_image, int * preview_offset);
|
||||||
|
void free_preview(C2D_Image preview_image);
|
||||||
|
Result load_audio(const 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 handle_scrolling(Entry_List_s * list);
|
||||||
|
void load_icons_thread(void * void_arg);
|
||||||
|
|
||||||
|
#endif
|
||||||
88
include/music.h
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* 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 MUSIC_H
|
||||||
|
#define MUSIC_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "fs.h"
|
||||||
|
#include "unicode.h"
|
||||||
|
|
||||||
|
#include <tremor/ivorbisfile.h>
|
||||||
|
#include <tremor/ivorbiscodec.h>
|
||||||
|
|
||||||
|
#define BUFFER_COUNT 8
|
||||||
|
#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 {
|
||||||
|
OggVorbis_File vf;
|
||||||
|
ndspWaveBuf wave_buf[2];
|
||||||
|
float mix[12];
|
||||||
|
u8 buf_pos;
|
||||||
|
long data_read;
|
||||||
|
char * filebuf;
|
||||||
|
u32 filesize;
|
||||||
|
|
||||||
|
volatile bool stop;
|
||||||
|
Thread playing_thread;
|
||||||
|
} audio_ogg_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
|
||||||
74
include/remote.h
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* 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 REMOTE_H
|
||||||
|
#define REMOTE_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "draw.h"
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#define THEMEPLAZA_BASE_URL "http://themeplaza.art"
|
||||||
|
#define THEMEPLAZA_API_URL "/api/anemone/v1"
|
||||||
|
#define THEMEPLAZA_BASE_API_URL THEMEPLAZA_BASE_URL THEMEPLAZA_API_URL
|
||||||
|
|
||||||
|
#define THEMEPLAZA_PAGE_FORMAT THEMEPLAZA_BASE_API_URL "/list?page=%" JSON_INTEGER_FORMAT "&category=%i&query=%s"
|
||||||
|
#define THEMEPLAZA_JSON_PAGE_COUNT "pages"
|
||||||
|
#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_NOT_FOUND "No items found"
|
||||||
|
|
||||||
|
|
||||||
|
#define THEMEPLAZA_DOWNLOAD_FORMAT THEMEPLAZA_BASE_URL "/download/%" JSON_INTEGER_FORMAT
|
||||||
|
#define THEMEPLAZA_PREVIEW_FORMAT THEMEPLAZA_DOWNLOAD_FORMAT "/preview"
|
||||||
|
#define THEMEPLAZA_BGM_FORMAT THEMEPLAZA_DOWNLOAD_FORMAT "/bgm"
|
||||||
|
#define THEMEPLAZA_ICON_FORMAT THEMEPLAZA_DOWNLOAD_FORMAT "/preview/icon"
|
||||||
|
#define THEMEPLAZA_SMDH_FORMAT THEMEPLAZA_DOWNLOAD_FORMAT "/smdh"
|
||||||
|
|
||||||
|
#define CACHE_PATH_FORMAT "/3ds/" APP_TITLE "/cache/%" JSON_INTEGER_FORMAT
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *result_buf;
|
||||||
|
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
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Anemone3DS
|
* This file is part of Anemone3DS
|
||||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -28,25 +28,11 @@
|
|||||||
#define SPLASHES_H
|
#define SPLASHES_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "loading.h"
|
||||||
|
|
||||||
typedef struct{
|
void splash_delete(void);
|
||||||
u16 name[0x40];
|
void splash_install(const Entry_s * splash);
|
||||||
u16 desc[0x80];
|
|
||||||
u16 author[0x40];
|
|
||||||
|
|
||||||
u32 placeholder_color;
|
void splash_check_installed(void * void_arg);
|
||||||
ssize_t icon_id;
|
|
||||||
|
|
||||||
u16 path[0x106];
|
|
||||||
bool is_zip;
|
|
||||||
} Splash_s;
|
|
||||||
|
|
||||||
Splash_s *splashes_list;
|
|
||||||
int splash_count;
|
|
||||||
|
|
||||||
Result get_splashes(Splash_s** splashes_list, int *splash_count);
|
|
||||||
void splash_install(Splash_s splash_to_install);
|
|
||||||
void splash_delete();
|
|
||||||
void load_splash_preview(Splash_s *splash);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Anemone3DS
|
* This file is part of Anemone3DS
|
||||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -28,32 +28,57 @@
|
|||||||
#define THEMES_H
|
#define THEMES_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "loading.h"
|
||||||
|
|
||||||
|
#define MAX_SHUFFLE_THEMES 10
|
||||||
|
|
||||||
|
enum ThemeInstall {
|
||||||
|
THEME_INSTALL_SHUFFLE = BIT(0),
|
||||||
|
THEME_INSTALL_BODY = BIT(1),
|
||||||
|
THEME_INSTALL_BGM = BIT(2),
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u16 name[0x40];
|
u32 index;
|
||||||
u16 desc[0x80];
|
u8 dlc_tid_low_bits;
|
||||||
u16 author[0x40];
|
u8 type;
|
||||||
|
u16 unk;
|
||||||
u32 placeholder_color;
|
} ThemeEntry_s;
|
||||||
ssize_t icon_id;
|
|
||||||
|
|
||||||
bool has_preview;
|
|
||||||
int preview_offset;
|
|
||||||
|
|
||||||
u16 path[0x106];
|
|
||||||
bool is_zip;
|
|
||||||
|
|
||||||
bool in_shuffle;
|
|
||||||
} Theme_s;
|
|
||||||
|
|
||||||
Theme_s * themes_list;
|
typedef struct {
|
||||||
int theme_count;
|
u8 _padding1[0x13b8];
|
||||||
|
ThemeEntry_s theme_entry;
|
||||||
|
ThemeEntry_s shuffle_themes[MAX_SHUFFLE_THEMES];
|
||||||
|
u8 shuffle_seedA[0xb];
|
||||||
|
u8 shuffle;
|
||||||
|
u8 shuffle_seedB[0xa];
|
||||||
|
} SaveData_dat_s;
|
||||||
|
|
||||||
void load_theme_preview(Theme_s *theme);
|
typedef struct {
|
||||||
Result get_themes(Theme_s **themes_list, int *theme_count);
|
u32 unk1;
|
||||||
void del_theme(u16 *path);
|
u32 unk2;
|
||||||
Result single_install(Theme_s theme);
|
u32 body_size;
|
||||||
Result shuffle_install(Theme_s *themes_list, int theme_count);
|
u32 music_size;
|
||||||
Result bgm_install(Theme_s bgm_to_install);
|
u32 unk3;
|
||||||
|
u32 unk4;
|
||||||
|
u32 dlc_theme_content_index;
|
||||||
|
u32 use_theme_cache;
|
||||||
|
|
||||||
#endif
|
u8 _padding1[0x338 - 8 * sizeof(u32)];
|
||||||
|
|
||||||
|
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES];
|
||||||
|
u32 shuffle_music_sizes[MAX_SHUFFLE_THEMES];
|
||||||
|
} ThemeManage_bin_s;
|
||||||
|
|
||||||
|
Result theme_install(Entry_s * theme);
|
||||||
|
Result no_bgm_install(Entry_s * theme);
|
||||||
|
Result bgm_install(Entry_s * theme);
|
||||||
|
|
||||||
|
Result shuffle_install(const Entry_List_s * themes);
|
||||||
|
|
||||||
|
Result dump_current_theme(void);
|
||||||
|
Result dump_all_themes(void);
|
||||||
|
|
||||||
|
void themes_check_installed(void * void_arg);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
200
include/ui_strings.h
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Anemone3DS
|
* This file is part of Anemone3DS
|
||||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -29,9 +29,10 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
ssize_t strulen(const u16*, ssize_t);
|
void replace_chars(u16 *input, char *remove, u16 with);
|
||||||
void struacat(u16 *input, const char *addition);
|
size_t strulen(const u16 *, ssize_t);
|
||||||
void printu(u16 *input);
|
void struacat(u16 * input, const char * addition);
|
||||||
u16 *strucat(u16 *destination, const u16 *source);
|
void printu(u16 * input);
|
||||||
|
size_t strucat(u16 * destination, const u16 * source);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
88
include/urls.h
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
BasicInfo:
|
BasicInfo:
|
||||||
Title : "Anemone3DS"
|
Title : $(APP_TITLE)
|
||||||
CompanyCode : "00"
|
CompanyCode : "00"
|
||||||
ProductCode : "CTR-P-ANEM"
|
ProductCode : $(APP_PRODUCT_CODE)
|
||||||
ContentType : Application
|
ContentType : Application
|
||||||
Logo : Homebrew # Nintendo / Licensed / Distributed / iQue / iQueForSystem
|
Logo : Homebrew # Nintendo / Licensed / Distributed / iQue / iQueForSystem
|
||||||
|
|
||||||
TitleInfo:
|
TitleInfo:
|
||||||
UniqueId : 0xAFEN
|
UniqueId : $(APP_UNIQUE_ID)
|
||||||
|
|
||||||
Category : Application
|
Category : Application
|
||||||
|
|
||||||
CardInfo:
|
CardInfo:
|
||||||
@@ -34,7 +35,7 @@ SystemControlInfo:
|
|||||||
StackSize: 0x40000
|
StackSize: 0x40000
|
||||||
|
|
||||||
RomFs:
|
RomFs:
|
||||||
RootPath : romfs
|
RootPath : $(APP_ROMFS)
|
||||||
|
|
||||||
# DO NOT EDIT BELOW HERE OR PROGRAMS WILL NOT LAUNCH (most likely)
|
# DO NOT EDIT BELOW HERE OR PROGRAMS WILL NOT LAUNCH (most likely)
|
||||||
|
|
||||||
|
|||||||
BIN
meta/banner.png
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 149 KiB |
BIN
meta/logo.bin
Normal file
|
Before Width: | Height: | Size: 443 B |
|
Before Width: | Height: | Size: 271 B |
|
Before Width: | Height: | Size: 272 B |
|
Before Width: | Height: | Size: 272 B |
|
Before Width: | Height: | Size: 272 B |
|
Before Width: | Height: | Size: 466 B |
762
source/badges.c
Normal file
@@ -0,0 +1,762 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
569
source/camera.c
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Anemone3DS
|
* This file is part of Anemone3DS
|
||||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,254 +27,403 @@
|
|||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
|
||||||
#include "quirc/quirc.h"
|
#include "quirc/quirc.h"
|
||||||
|
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "themes.h"
|
#include "loading.h"
|
||||||
#include "pp2d/pp2d/pp2d.h"
|
#include "remote.h"
|
||||||
|
#include "ui_strings.h"
|
||||||
|
|
||||||
u32 transfer_size;
|
#include <archive.h>
|
||||||
Handle event;
|
#include <archive_entry.h>
|
||||||
struct quirc* context;
|
|
||||||
|
|
||||||
void init_qr(void)
|
static void start_read(qr_data * data)
|
||||||
{
|
{
|
||||||
camInit();
|
LightLock_Lock(&data->mut);
|
||||||
CAMU_SetSize(SELECT_OUT1_OUT2, SIZE_CTR_TOP_LCD, CONTEXT_A);
|
while(data->writer_waiting || data->writer_active)
|
||||||
CAMU_SetOutputFormat(SELECT_OUT1_OUT2, OUTPUT_RGB_565, CONTEXT_A);
|
{
|
||||||
CAMU_SetFrameRate(SELECT_OUT1_OUT2, FRAME_RATE_10);
|
CondVar_WaitTimeout(&data->cond, &data->mut, 1000000);
|
||||||
|
}
|
||||||
|
|
||||||
CAMU_SetNoiseFilter(SELECT_OUT1_OUT2, true);
|
AtomicIncrement(&data->num_readers_active);
|
||||||
CAMU_SetAutoExposure(SELECT_OUT1_OUT2, true);
|
LightLock_Unlock(&data->mut);
|
||||||
CAMU_SetAutoWhiteBalance(SELECT_OUT1_OUT2, true);
|
}
|
||||||
CAMU_SetTrimming(PORT_CAM1, false);
|
static void stop_read(qr_data * data)
|
||||||
CAMU_SetTrimming(PORT_CAM2, false);
|
{
|
||||||
|
LightLock_Lock(&data->mut);
|
||||||
|
AtomicDecrement(&data->num_readers_active);
|
||||||
|
if(data->num_readers_active == 0)
|
||||||
|
{
|
||||||
|
CondVar_Signal(&data->cond);
|
||||||
|
}
|
||||||
|
LightLock_Unlock(&data->mut);
|
||||||
|
}
|
||||||
|
static void start_write(qr_data * data)
|
||||||
|
{
|
||||||
|
LightLock_Lock(&data->mut);
|
||||||
|
data->writer_waiting = true;
|
||||||
|
|
||||||
CAMU_GetMaxBytes(&transfer_size, 400, 240);
|
while(data->num_readers_active)
|
||||||
CAMU_SetTransferBytes(PORT_BOTH, transfer_size, 400, 240);
|
{
|
||||||
|
CondVar_WaitTimeout(&data->cond, &data->mut, 1000000);
|
||||||
|
}
|
||||||
|
|
||||||
CAMU_Activate(SELECT_OUT1_OUT2);
|
data->writer_waiting = false;
|
||||||
event = 0;
|
data->writer_active = true;
|
||||||
|
|
||||||
CAMU_ClearBuffer(PORT_BOTH);
|
LightLock_Unlock(&data->mut);
|
||||||
CAMU_SynchronizeVsyncTiming(SELECT_OUT1, SELECT_OUT2);
|
}
|
||||||
CAMU_StartCapture(PORT_BOTH);
|
static void stop_write(qr_data * data)
|
||||||
|
{
|
||||||
|
LightLock_Lock(&data->mut);
|
||||||
|
|
||||||
context = quirc_new();
|
data->writer_active = false;
|
||||||
quirc_resize(context, 400, 240);
|
CondVar_Broadcast(&data->cond);
|
||||||
|
|
||||||
|
LightLock_Unlock(&data->mut);
|
||||||
}
|
}
|
||||||
|
|
||||||
void exit_qr(void)
|
static void capture_cam_thread(void * arg)
|
||||||
{
|
{
|
||||||
CAMU_StopCapture(PORT_BOTH);
|
qr_data * data = (qr_data *) arg;
|
||||||
|
|
||||||
|
Handle cam_events[3] = {0};
|
||||||
|
cam_events[0] = data->event_stop;
|
||||||
|
|
||||||
|
u32 transferUnit;
|
||||||
|
const u32 bufsz = 400 * 240 * sizeof(u16);
|
||||||
|
u16 * buffer = linearAlloc(bufsz);
|
||||||
|
|
||||||
|
camInit();
|
||||||
|
CAMU_SetSize(SELECT_OUT1, SIZE_CTR_TOP_LCD, CONTEXT_A);
|
||||||
|
CAMU_SetOutputFormat(SELECT_OUT1, OUTPUT_RGB_565, CONTEXT_A);
|
||||||
|
CAMU_SetFrameRate(SELECT_OUT1, FRAME_RATE_30);
|
||||||
|
CAMU_SetNoiseFilter(SELECT_OUT1, true);
|
||||||
|
CAMU_SetAutoExposure(SELECT_OUT1, true);
|
||||||
|
CAMU_SetAutoWhiteBalance(SELECT_OUT1, true);
|
||||||
|
CAMU_Activate(SELECT_OUT1);
|
||||||
|
CAMU_GetBufferErrorInterruptEvent(&cam_events[2], PORT_CAM1);
|
||||||
|
CAMU_SetTrimming(PORT_CAM1, false);
|
||||||
|
CAMU_GetMaxBytes(&transferUnit, 400, 240);
|
||||||
|
CAMU_SetTransferBytes(PORT_CAM1, transferUnit, 400, 240);
|
||||||
|
CAMU_ClearBuffer(PORT_CAM1);
|
||||||
|
CAMU_SetReceiving(&cam_events[1], buffer, PORT_CAM1, bufsz, transferUnit);
|
||||||
|
CAMU_StartCapture(PORT_CAM1);
|
||||||
|
|
||||||
|
bool cancel = false;
|
||||||
|
|
||||||
|
while (!cancel)
|
||||||
|
{
|
||||||
|
s32 index = 0;
|
||||||
|
svcWaitSynchronizationN(&index, cam_events, 3, false, U64_MAX);
|
||||||
|
switch(index) {
|
||||||
|
case 0:
|
||||||
|
DEBUG("Cancel event received\n");
|
||||||
|
cancel = true;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
svcCloseHandle(cam_events[1]);
|
||||||
|
cam_events[1] = 0;
|
||||||
|
|
||||||
|
start_write(data);
|
||||||
|
memcpy(data->camera_buffer, buffer, bufsz);
|
||||||
|
data->any_update = true;
|
||||||
|
stop_write(data);
|
||||||
|
|
||||||
|
CAMU_SetReceiving(&cam_events[1], buffer, PORT_CAM1, bufsz, transferUnit);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
svcCloseHandle(cam_events[1]);
|
||||||
|
cam_events[1] = 0;
|
||||||
|
|
||||||
|
CAMU_ClearBuffer(PORT_CAM1);
|
||||||
|
CAMU_SetReceiving(&cam_events[1], buffer, PORT_CAM1, bufsz, transferUnit);
|
||||||
|
CAMU_StartCapture(PORT_CAM1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CAMU_StopCapture(PORT_CAM1);
|
||||||
|
|
||||||
|
bool busy = false;
|
||||||
|
while(R_SUCCEEDED(CAMU_IsBusy(&busy, PORT_CAM1)) && busy) {
|
||||||
|
svcSleepThread(1000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
CAMU_ClearBuffer(PORT_CAM1);
|
||||||
CAMU_Activate(SELECT_NONE);
|
CAMU_Activate(SELECT_NONE);
|
||||||
camExit();
|
camExit();
|
||||||
quirc_destroy(context);
|
|
||||||
|
linearFree(buffer);
|
||||||
|
for(int i = 1; i < 3; i++)
|
||||||
|
{
|
||||||
|
if(cam_events[i] != 0) {
|
||||||
|
svcCloseHandle(cam_events[i]);
|
||||||
|
cam_events[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LightEvent_Signal(&data->event_cam_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void scan_qr(u16 *buf)
|
static void update_ui(void * arg)
|
||||||
|
{
|
||||||
|
qr_data * data = (qr_data *) arg;
|
||||||
|
C3D_Tex tex;
|
||||||
|
|
||||||
|
static const Tex3DS_SubTexture subt3x = { 400, 240, 0.0f, 1.0f, 400.0f/512.0f, 1.0f - (240.0f/256.0f) };
|
||||||
|
C3D_TexInit(&tex, 512, 256, GPU_RGB565);
|
||||||
|
|
||||||
|
C3D_TexSetFilter(&tex, GPU_LINEAR, GPU_LINEAR);
|
||||||
|
|
||||||
|
while(svcWaitSynchronization(data->event_stop, 2 * 1000 * 1000ULL) == 0x09401BFE) // timeout of 2ms occured, still have 14 for copy and render
|
||||||
|
{
|
||||||
|
draw_base_interface();
|
||||||
|
|
||||||
|
// Untiled texture loading code adapted from FBI
|
||||||
|
start_read(data);
|
||||||
|
if(data->any_update)
|
||||||
|
{
|
||||||
|
for(u32 y = 0; y < 240; y++) {
|
||||||
|
const u32 srcPos = y * 400;
|
||||||
|
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)));
|
||||||
|
|
||||||
|
((u16 *)tex.data)[dstPos] = data->camera_buffer[srcPos + x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data->any_update = false;
|
||||||
|
}
|
||||||
|
stop_read(data);
|
||||||
|
|
||||||
|
C2D_DrawImageAt((C2D_Image){ &tex, &subt3x }, 0.0f, 0.0f, 0.4f, NULL, 1.0f, 1.0f);
|
||||||
|
|
||||||
|
set_screen(bottom);
|
||||||
|
draw_text_center(GFX_BOTTOM, 4, 0.5, 0.5, 0.5, colors[COLOR_WHITE_ACCENT], language.camera.quit);
|
||||||
|
end_frame();
|
||||||
|
}
|
||||||
|
|
||||||
|
C3D_TexDelete(&tex);
|
||||||
|
LightEvent_Signal(&data->event_ui_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool start_capture_cam(qr_data * data)
|
||||||
|
{
|
||||||
|
if((data->cam_thread = threadCreate(capture_cam_thread, data, 0x10000, 0x1A, 1, false)) == NULL)
|
||||||
|
{
|
||||||
|
throw_error(language.camera.thread_error, ERROR_LEVEL_ERROR);
|
||||||
|
LightEvent_Signal(&data->event_cam_info);
|
||||||
|
LightEvent_Signal(&data->event_ui_info);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if((data->ui_thread = threadCreate(update_ui, data, 0x10000, 0x1A, 1, false)) == NULL)
|
||||||
|
{
|
||||||
|
LightEvent_Signal(&data->event_ui_info);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(context, &w, &h);
|
start_read(data);
|
||||||
|
for (int y = 0; y < h; y++) {
|
||||||
for (ssize_t x = 0; x < w; x++)
|
const int actual_y = y * w;
|
||||||
{
|
for (int x = 0; x < w; x++) {
|
||||||
for (ssize_t y = 0; y < h; y++)
|
const int actual_off = actual_y + x;
|
||||||
{
|
const u16 px = data->camera_buffer[actual_off];
|
||||||
u16 px = buf[y * 400 + x];
|
image[actual_off] = (u8)(((((px >> 11) & 0x1F) << 3) + (((px >> 5) & 0x3F) << 2) + ((px & 0x1F) << 3)) / 3);
|
||||||
image[y * w + x] = (u8)(((((px >> 11) & 0x1F) << 3) + (((px >> 5) & 0x3F) << 2) + ((px & 0x1F) << 3)) / 3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stop_read(data);
|
||||||
|
|
||||||
quirc_end(context);
|
quirc_end(data->context);
|
||||||
|
if(quirc_count(data->context) > 0)
|
||||||
if (quirc_count(context) > 0)
|
|
||||||
{
|
{
|
||||||
struct quirc_code code;
|
struct quirc_code code;
|
||||||
struct quirc_data data;
|
quirc_extract(data->context, 0, &code);
|
||||||
quirc_extract(context, 0, &code);
|
if (!quirc_decode(&code, scan_data))
|
||||||
if (!quirc_decode(&code, &data))
|
|
||||||
{
|
{
|
||||||
qr_mode = false;
|
return true;
|
||||||
|
|
||||||
http_get((char*)data.payload, splash_mode ? "/Splashes/" : "/Themes/");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void take_picture(void)
|
static void start_qr(qr_data * data)
|
||||||
{
|
{
|
||||||
u16 *buf = malloc(sizeof(u16) * 400 * 240 * 4);
|
svcCreateEvent(&data->event_stop, RESET_STICKY);
|
||||||
if (buf == NULL) return;
|
LightEvent_Init(&data->event_cam_info, RESET_STICKY);
|
||||||
CAMU_SetReceiving(&event, buf, PORT_CAM1, 240 * 400 * 2, transfer_size);
|
LightEvent_Init(&data->event_ui_info, RESET_STICKY);
|
||||||
svcWaitSynchronization(event, U64_MAX);
|
LightLock_Init(&data->mut);
|
||||||
svcCloseHandle(event);
|
CondVar_Init(&data->cond);
|
||||||
pp2d_begin_draw(GFX_TOP);
|
|
||||||
u32 *rgba8_buf = malloc(240 * 400 * sizeof(u32));
|
|
||||||
if (rgba8_buf == NULL) return;
|
|
||||||
for (int i = 0; i < 240 * 400; i++)
|
|
||||||
{
|
|
||||||
rgba8_buf[i] = RGB565_TO_ABGR8(buf[i]);
|
|
||||||
}
|
|
||||||
pp2d_load_texture_memory(TEXTURE_QR, rgba8_buf, 400, 240);
|
|
||||||
pp2d_draw_texture(TEXTURE_QR, 0, 0);
|
|
||||||
pp2d_draw_rectangle(0, 216, 400, 24, RGBA8(55, 122, 168, 255));
|
|
||||||
pp2d_draw_text_center(GFX_TOP, 220, 0.5, 0.5, RGBA8(255, 255, 255, 255), "Press \uE005 To Quit");
|
|
||||||
pp2d_draw_rectangle(0, 0, 400, 24, RGBA8(55, 122, 168, 255));
|
|
||||||
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, RGBA8(255, 255, 255, 255), "Press \uE004 To Scan");
|
|
||||||
pp2d_end_draw();
|
|
||||||
free(rgba8_buf);
|
|
||||||
pp2d_free_texture(TEXTURE_QR);
|
|
||||||
hidScanInput();
|
|
||||||
u32 kDown = hidKeysDown();
|
|
||||||
if (kDown & KEY_L)
|
|
||||||
{
|
|
||||||
CAMU_StopCapture(PORT_BOTH);
|
|
||||||
CAMU_Activate(SELECT_NONE);
|
|
||||||
scan_qr(buf);
|
|
||||||
CAMU_Activate(SELECT_OUT1_OUT2);
|
|
||||||
CAMU_StartCapture(PORT_BOTH);
|
|
||||||
}
|
|
||||||
if (kDown & KEY_R)
|
|
||||||
{
|
|
||||||
exit_qr();
|
|
||||||
qr_mode = false;
|
|
||||||
}
|
|
||||||
free(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
data->cam_thread = NULL;
|
||||||
Putting this in camera because I'm too lazy to make a network.c
|
data->ui_thread = NULL;
|
||||||
This'll probably get refactored later
|
data->any_update = false;
|
||||||
*/
|
|
||||||
Result http_get(char *url, char *path)
|
data->context = quirc_new();
|
||||||
|
quirc_resize(data->context, 400, 240);
|
||||||
|
data->camera_buffer = calloc(1, 400 * 240 * sizeof(u16));
|
||||||
|
}
|
||||||
|
static void exit_qr(qr_data * data)
|
||||||
{
|
{
|
||||||
Result ret;
|
svcSignalEvent(data->event_stop);
|
||||||
httpcContext context;
|
|
||||||
char *new_url = NULL;
|
|
||||||
u32 status_code;
|
|
||||||
u32 content_size = 0;
|
|
||||||
u32 read_size = 0;
|
|
||||||
u32 size = 0;
|
|
||||||
u8 *buf;
|
|
||||||
u8 *last_buf;
|
|
||||||
|
|
||||||
do {
|
LightEvent_Wait(&data->event_ui_info);
|
||||||
ret = httpcOpenContext(&context, HTTPC_METHOD_GET, url, 1);
|
LightEvent_Clear(&data->event_ui_info);
|
||||||
ret = httpcSetSSLOpt(&context, SSLCOPT_DisableVerify); // should let us do https
|
if(data->ui_thread != NULL)
|
||||||
ret = httpcSetKeepAlive(&context, HTTPC_KEEPALIVE_ENABLED);
|
|
||||||
ret = httpcAddRequestHeaderField(&context, "User-Agent", "Anemone3DS/1.1.0");
|
|
||||||
ret = httpcAddRequestHeaderField(&context, "Connection", "Keep-Alive");
|
|
||||||
draw_theme_install(DOWNLOADING);
|
|
||||||
ret = httpcBeginRequest(&context);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
httpcCloseContext(&context);
|
|
||||||
if (new_url != NULL) free(new_url);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = httpcGetResponseStatusCode(&context, &status_code);
|
|
||||||
if(ret!=0){
|
|
||||||
httpcCloseContext(&context);
|
|
||||||
if(new_url!=NULL) free(new_url);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((status_code >= 301 && status_code <= 303) || (status_code >= 307 && status_code <= 308))
|
|
||||||
{
|
|
||||||
if (new_url == NULL) new_url = malloc(0x1000);
|
|
||||||
ret = httpcGetResponseHeader(&context, "Location", new_url, 0x1000);
|
|
||||||
url = new_url;
|
|
||||||
httpcCloseContext(&context);
|
|
||||||
}
|
|
||||||
} while ((status_code >= 301 && status_code <= 303) || (status_code >= 307 && status_code <= 308));
|
|
||||||
|
|
||||||
if (status_code != 200)
|
|
||||||
{
|
{
|
||||||
httpcCloseContext(&context);
|
threadJoin(data->ui_thread, U64_MAX);
|
||||||
if (new_url != NULL) free(new_url);
|
threadFree(data->ui_thread);
|
||||||
return ret;
|
data->ui_thread = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = httpcGetDownloadSizeState(&context, NULL, &content_size);
|
LightEvent_Wait(&data->event_cam_info);
|
||||||
if (ret != 0)
|
LightEvent_Clear(&data->event_cam_info);
|
||||||
|
if(data->cam_thread != NULL)
|
||||||
{
|
{
|
||||||
httpcCloseContext(&context);
|
threadJoin(data->cam_thread, U64_MAX);
|
||||||
if (new_url != NULL) free(new_url);
|
threadFree(data->cam_thread);
|
||||||
return ret;
|
data->cam_thread = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = malloc(0x1000);
|
free(data->camera_buffer);
|
||||||
if (buf == NULL)
|
data->camera_buffer = NULL;
|
||||||
{
|
svcCloseHandle(data->event_stop);
|
||||||
httpcCloseContext(&context);
|
data->event_stop = 0;
|
||||||
free(new_url);
|
}
|
||||||
return -2;
|
|
||||||
}
|
bool init_qr(void)
|
||||||
|
{
|
||||||
char *content_disposition = malloc(1024);
|
qr_data data;
|
||||||
ret = httpcGetResponseHeader(&context, "Content-Disposition", content_disposition, 1024);
|
|
||||||
if (ret != 0)
|
memset(&data, 0, sizeof(data));
|
||||||
{
|
|
||||||
free(content_disposition);
|
start_qr(&data);
|
||||||
free(new_url);
|
|
||||||
free(buf);
|
struct quirc_data * scan_data = calloc(1, sizeof(struct quirc_data));
|
||||||
}
|
const bool ready = start_capture_cam(&data);
|
||||||
|
bool finished = !ready;
|
||||||
char *filename;
|
|
||||||
filename = strtok(content_disposition, "\"");
|
while(!finished)
|
||||||
filename = strtok(NULL, "\"");
|
{
|
||||||
|
hidScanInput();
|
||||||
char *illegal_characters = "\"?;:/\\+";
|
if (hidKeysDown() & (KEY_R | KEY_B | KEY_TOUCH))
|
||||||
for (size_t i = 0; i < strlen(filename); i++)
|
{
|
||||||
{
|
break;
|
||||||
for (size_t n = 0; n < strlen(illegal_characters); n++)
|
}
|
||||||
{
|
|
||||||
if (filename[i] == illegal_characters[n])
|
finished = update_qr(&data, scan_data);
|
||||||
{
|
svcSleepThread(50 * 1000 * 1000ULL); // only scan every 50ms
|
||||||
filename[i] = '-';
|
}
|
||||||
}
|
|
||||||
}
|
exit_qr(&data);
|
||||||
}
|
|
||||||
|
bool success = false;
|
||||||
do {
|
if(finished && ready)
|
||||||
ret = httpcDownloadData(&context, buf + size, 0x1000, &read_size);
|
{
|
||||||
size += read_size;
|
draw_install(INSTALL_DOWNLOAD);
|
||||||
|
char * zip_buf = NULL;
|
||||||
if (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING)
|
char * filename = NULL;
|
||||||
{
|
u32 zip_size;
|
||||||
last_buf = buf;
|
|
||||||
buf = realloc(buf, size + 0x1000);
|
Result res = http_get((char*)scan_data->payload, &filename, &zip_buf, &zip_size, INSTALL_DOWNLOAD, "application/zip; application/x-zip-compressed");
|
||||||
if (buf == NULL)
|
if (R_FAILED(res))
|
||||||
{
|
{
|
||||||
httpcCloseContext(&context);
|
free(filename);
|
||||||
free(last_buf);
|
free(zip_buf);
|
||||||
return ret;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
else if (R_DESCRIPTION(res) == RD_NO_DATA || R_DESCRIPTION(res) == RD_CANCEL_REQUESTED)
|
||||||
} while (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING);
|
{
|
||||||
|
free(filename);
|
||||||
last_buf = buf;
|
return true;
|
||||||
buf = realloc(buf, size);
|
}
|
||||||
if (buf == NULL)
|
|
||||||
{
|
if(zip_size != 0)
|
||||||
httpcCloseContext(&context);
|
{
|
||||||
free(last_buf);
|
draw_install(INSTALL_CHECKING_DOWNLOAD);
|
||||||
return -1;
|
|
||||||
}
|
struct archive * a = archive_read_new();
|
||||||
|
archive_read_support_format_zip(a);
|
||||||
char path_to_file[0x106] = {0};
|
|
||||||
strcpy(path_to_file, path);
|
int r = archive_read_open_memory(a, zip_buf, zip_size);
|
||||||
strcat(path_to_file, filename);
|
archive_read_free(a);
|
||||||
remake_file(path_to_file, ArchiveSD, size);
|
|
||||||
buf_to_file(size, path_to_file, ArchiveSD, (char*)buf);
|
if(r == ARCHIVE_OK)
|
||||||
|
{
|
||||||
if (splash_mode) get_splashes(&splashes_list, &splash_count);
|
RemoteMode mode = REMOTE_MODE_AMOUNT;
|
||||||
else get_themes(&themes_list, &theme_count);
|
|
||||||
|
char * buf = NULL;
|
||||||
exit_qr();
|
do {
|
||||||
|
if(zip_memory_to_buf("body_LZ.bin", zip_buf, zip_size, &buf) != 0)
|
||||||
return 0;
|
{
|
||||||
|
mode = REMOTE_MODE_THEMES;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
buf = NULL;
|
||||||
|
if(zip_memory_to_buf("splash.bin", zip_buf, zip_size, &buf) != 0)
|
||||||
|
{
|
||||||
|
mode = REMOTE_MODE_SPLASHES;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
buf = NULL;
|
||||||
|
if(zip_memory_to_buf("splashbottom.bin", zip_buf, zip_size, &buf) != 0)
|
||||||
|
{
|
||||||
|
mode = REMOTE_MODE_SPLASHES;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(false);
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
buf = NULL;
|
||||||
|
|
||||||
|
if(mode != REMOTE_MODE_AMOUNT)
|
||||||
|
{
|
||||||
|
save_zip_to_sd(filename, zip_size, zip_buf, mode);
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool badge = draw_confirm_no_interface(language.camera.badge_question);
|
||||||
|
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
|
||||||
|
{
|
||||||
|
throw_error(language.camera.file_not_zip, ERROR_LEVEL_WARNING);
|
||||||
|
}
|
||||||
|
free(zip_buf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw_error(language.camera.download_failed, ERROR_LEVEL_WARNING);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(scan_data);
|
||||||
|
quirc_destroy(data.context);
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
42
source/colors.c
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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 "colors.h"
|
||||||
|
|
||||||
|
Color colors[COLOR_AMOUNT] = {0};
|
||||||
|
|
||||||
|
void init_colors(void)
|
||||||
|
{
|
||||||
|
colors[COLOR_BACKGROUND] = config.background_color;
|
||||||
|
colors[COLOR_ACCENT] = config.accent_color;
|
||||||
|
colors[COLOR_WHITE_BACKGROUND] = config.white_color_background;
|
||||||
|
colors[COLOR_WHITE_ACCENT] = config.white_color_accent;
|
||||||
|
colors[COLOR_CURSOR] = config.cursor_color;
|
||||||
|
colors[COLOR_BLACK] = config.black_color;
|
||||||
|
colors[COLOR_RED_BACKGROUND] = config.red_color_background;
|
||||||
|
colors[COLOR_RED_ACCENT] = config.red_color_accent;
|
||||||
|
colors[COLOR_YELLOW] = config.yellow_color;
|
||||||
|
}
|
||||||
247
source/config.c
Normal file
@@ -0,0 +1,247 @@
|
|||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
318
source/conversion.c
Normal file
@@ -0,0 +1,318 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
1054
source/draw.c
231
source/entries_list.c
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
/*
|
||||||
|
* 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++;
|
||||||
|
}
|
||||||
651
source/fs.c
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Anemone3DS
|
* This file is part of Anemone3DS
|
||||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,23 +27,68 @@
|
|||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
|
#include "draw.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
|
#include "ui_strings.h"
|
||||||
|
#include "remote.h"
|
||||||
|
|
||||||
#include "minizip/unzip.h"
|
#include <archive.h>
|
||||||
|
#include <archive_entry.h>
|
||||||
|
|
||||||
int filename_compare(__attribute__((unused)) unzFile file, const char *current_filename, const char *filename)
|
FS_Archive ArchiveSD;
|
||||||
|
FS_Archive ArchiveHomeExt;
|
||||||
|
FS_Archive ArchiveThemeExt;
|
||||||
|
FS_Archive ArchiveBadgeExt;
|
||||||
|
|
||||||
|
Result createExtSaveData(u32 extdataID)
|
||||||
{
|
{
|
||||||
return strcasecmp(current_filename, filename);
|
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)
|
||||||
{
|
{
|
||||||
romfsInit();
|
romfsInit();
|
||||||
u8 regionCode;
|
u8 regionCode;
|
||||||
u32 archive1;
|
u32 archive1;
|
||||||
u32 archive2;
|
u32 archive2;
|
||||||
|
|
||||||
Result retValue;
|
Result res = 0;
|
||||||
|
|
||||||
FS_Path home;
|
FS_Path home;
|
||||||
FS_Path theme;
|
FS_Path theme;
|
||||||
@@ -63,121 +108,571 @@ 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);
|
||||||
retValue = FSUSER_OpenArchive(&ArchiveSD, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""));
|
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, main_paths[REMOTE_MODE_SPLASHES]), FS_ATTRIBUTE_DIRECTORY);
|
||||||
if(R_FAILED(retValue)) return retValue;
|
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);
|
|
||||||
|
|
||||||
u32 homeMenuPath[3] = {MEDIATYPE_SD, archive2, 0};
|
u32 homeMenuPath[3] = {MEDIATYPE_SD, archive2, 0};
|
||||||
home.type = PATH_BINARY;
|
home.type = PATH_BINARY;
|
||||||
home.size = 0xC;
|
home.size = 0xC;
|
||||||
home.data = homeMenuPath;
|
home.data = homeMenuPath;
|
||||||
retValue = FSUSER_OpenArchive(&ArchiveHomeExt, ARCHIVE_EXTDATA, home);
|
if(R_FAILED(res = FSUSER_OpenArchive(&ArchiveHomeExt, ARCHIVE_EXTDATA, home))) return res;
|
||||||
if(R_FAILED(retValue)) return retValue;
|
|
||||||
|
|
||||||
u32 themePath[3] = {MEDIATYPE_SD, archive1, 0};
|
u32 themePath[3] = {MEDIATYPE_SD, archive1, 0};
|
||||||
theme.type = PATH_BINARY;
|
theme.type = PATH_BINARY;
|
||||||
theme.size = 0xC;
|
theme.size = 0xC;
|
||||||
theme.data = themePath;
|
theme.data = themePath;
|
||||||
retValue = FSUSER_OpenArchive(&ArchiveThemeExt, ARCHIVE_EXTDATA, theme);
|
if(R_FAILED(res = FSUSER_OpenArchive(&ArchiveThemeExt, ARCHIVE_EXTDATA, theme))) return res;
|
||||||
if(R_FAILED(retValue)) return retValue;
|
|
||||||
|
|
||||||
Handle test_handle;
|
Handle test_handle;
|
||||||
retValue = FSUSER_OpenFile(&test_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/ThemeManage.bin"), FS_OPEN_READ, 0);
|
if(R_FAILED(res = FSUSER_OpenFile(&test_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/ThemeManage.bin"), FS_OPEN_READ, 0))) return res;
|
||||||
if(R_FAILED(retValue)) return retValue;
|
|
||||||
FSFILE_Close(test_handle);
|
FSFILE_Close(test_handle);
|
||||||
|
|
||||||
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 retValue;
|
Result 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(ArchiveThemeExt))) return res;
|
||||||
|
if(R_FAILED(res = FSUSER_CloseArchive(ArchiveBadgeExt))) return res;
|
||||||
|
|
||||||
retValue = FSUSER_CloseArchive(ArchiveSD);
|
|
||||||
if(R_FAILED(retValue)) return retValue;
|
|
||||||
retValue = FSUSER_CloseArchive(ArchiveHomeExt);
|
|
||||||
if(R_FAILED(retValue)) return retValue;
|
|
||||||
retValue = FSUSER_CloseArchive(ArchiveThemeExt);
|
|
||||||
if(R_FAILED(retValue)) return retValue;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 file_to_buf(FS_Path path, FS_Archive archive, char** buf)
|
Result load_parental_controls(Parental_Restrictions_s *restrictions)
|
||||||
|
{
|
||||||
|
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 = FSUSER_OpenFile(&file, archive, path, FS_OPEN_READ, 0);
|
Result res = 0;
|
||||||
if (R_FAILED(res)) return 0;
|
if (R_FAILED(res = FSUSER_OpenFile(&file, archive, path, FS_OPEN_READ, 0)))
|
||||||
|
{
|
||||||
|
DEBUG("file_to_buf failed - 0x%08lx\n", res);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
u64 size;
|
u64 size;
|
||||||
FSFILE_GetSize(file, &size);
|
FSFILE_GetSize(file, &size);
|
||||||
*buf = calloc(1, size);
|
if(size != 0)
|
||||||
FSFILE_Read(file, NULL, 0, *buf, size);
|
|
||||||
FSFILE_Close(file);
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf)
|
|
||||||
{
|
|
||||||
ssize_t len = strulen(zip_path, 0x106);
|
|
||||||
|
|
||||||
u8 *path = calloc(sizeof(u8), len * 4);
|
|
||||||
utf16_to_utf8(path, zip_path, len * 4);
|
|
||||||
|
|
||||||
unzFile zip_handle = unzOpen((char*)path);
|
|
||||||
|
|
||||||
if (zip_handle == NULL) return 0;
|
|
||||||
u32 file_size = 0;
|
|
||||||
|
|
||||||
int status = unzLocateFile(zip_handle, file_name, filename_compare);
|
|
||||||
if (status == UNZ_OK)
|
|
||||||
{
|
{
|
||||||
unz_file_info *file_info = malloc(sizeof(unz_file_info));
|
*buf = calloc(1, size);
|
||||||
unzGetCurrentFileInfo(zip_handle, file_info, NULL, 0, NULL, 0, NULL, 0);
|
if (*buf == NULL)
|
||||||
file_size = file_info->uncompressed_size;
|
{
|
||||||
*buf = calloc(1, file_size);
|
DEBUG("Error allocating buffer - out of memory??\n");
|
||||||
unzOpenCurrentFile(zip_handle);
|
return 0;
|
||||||
unzReadCurrentFile(zip_handle, *buf, file_size);
|
}
|
||||||
unzCloseCurrentFile(zip_handle);
|
FSFILE_Read(file, NULL, 0, *buf, size);
|
||||||
unzClose(zip_handle);
|
|
||||||
|
|
||||||
free(path);
|
|
||||||
free(file_info);
|
|
||||||
return file_size;
|
|
||||||
} else {
|
|
||||||
free(path);
|
|
||||||
puts("fileziprip");
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
FSFILE_Close(file);
|
||||||
|
return (u32)size;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result buf_to_file(u32 size, char *path, FS_Archive archive, char *buf)
|
s16 for_each_file_zip(u16 *zip_path, u32 (*zip_iter_callback)(char *filebuf, u64 file_size, const char *name, void *userdata), void *userdata)
|
||||||
{
|
{
|
||||||
Handle handle;
|
struct archive *a = archive_read_new();
|
||||||
Result res = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_WRITE, 0);
|
archive_read_support_format_zip(a);
|
||||||
if (R_FAILED(res)) return res;
|
|
||||||
res = FSFILE_Write(handle, NULL, 0, buf, size, FS_WRITE_FLUSH);
|
ssize_t len = strulen(zip_path, 0x106);
|
||||||
if (R_FAILED(res)) return res;
|
char * path = calloc(len, sizeof(u16));
|
||||||
res = FSFILE_Close(handle);
|
utf16_to_utf8((u8 *)path, zip_path, len * sizeof(u16));
|
||||||
if (R_FAILED(res)) return res;
|
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;
|
||||||
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void remake_file(char *path, FS_Archive archive, u32 size)
|
static u32 zip_to_buf(struct archive * a, const char * file_name, char ** buf)
|
||||||
|
{
|
||||||
|
struct archive_entry * entry;
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
u64 file_size = 0;
|
||||||
|
|
||||||
|
while(!found && archive_read_next_header(a, &entry) == ARCHIVE_OK)
|
||||||
|
{
|
||||||
|
found = !strcasecmp(archive_entry_pathname(entry), file_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(found)
|
||||||
|
{
|
||||||
|
file_size = archive_entry_size(entry);
|
||||||
|
*buf = calloc(file_size, sizeof(char));
|
||||||
|
archive_read_data(a, *buf, file_size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DEBUG("Couldn't find file in zip\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
archive_read_free(a);
|
||||||
|
|
||||||
|
return (u32)file_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 zip_memory_to_buf(const char * file_name, void * zip_memory, size_t zip_size, char ** buf)
|
||||||
|
{
|
||||||
|
struct archive * a = archive_read_new();
|
||||||
|
archive_read_support_format_zip(a);
|
||||||
|
|
||||||
|
int r = archive_read_open_memory(a, zip_memory, zip_size);
|
||||||
|
if(r != ARCHIVE_OK)
|
||||||
|
{
|
||||||
|
DEBUG("Invalid zip being opened from memory\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return zip_to_buf(a, file_name, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 zip_file_to_buf(const char * file_name, const u16 * zip_path, char ** buf)
|
||||||
|
{
|
||||||
|
ssize_t len = strulen(zip_path, 0x106);
|
||||||
|
char * path = calloc(len, sizeof(u16));
|
||||||
|
utf16_to_utf8((u8 *)path, zip_path, len * sizeof(u16));
|
||||||
|
|
||||||
|
struct archive * a = archive_read_new();
|
||||||
|
archive_read_support_format_zip(a);
|
||||||
|
|
||||||
|
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 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return zip_to_buf(a, file_name, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result buf_to_file(u32 size, FS_Path path, FS_Archive archive, char * buf)
|
||||||
{
|
{
|
||||||
Handle handle;
|
Handle handle;
|
||||||
if (R_SUCCEEDED(FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_READ, 0)))
|
Result res = 0;
|
||||||
|
if (R_FAILED(res = FSUSER_OpenFile(&handle, archive, path, FS_OPEN_WRITE, 0))) return res;
|
||||||
|
if (R_FAILED(res = FSFILE_Write(handle, NULL, 0, buf, size, FS_WRITE_FLUSH))) return res;
|
||||||
|
if (R_FAILED(res = FSFILE_Close(handle))) return res;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 decompress_lz_file(FS_Path file_name, FS_Archive archive, char ** buf)
|
||||||
|
{
|
||||||
|
Handle handle;
|
||||||
|
Result res = 0;
|
||||||
|
if (R_FAILED(res = FSUSER_OpenFile(&handle, archive, file_name, FS_OPEN_READ, 0))) {
|
||||||
|
DEBUG("%lu\n", res);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
u64 size;
|
||||||
|
FSFILE_GetSize(handle, &size);
|
||||||
|
|
||||||
|
char * temp_buf = NULL;
|
||||||
|
|
||||||
|
if(size != 0)
|
||||||
|
{
|
||||||
|
temp_buf = calloc(1, size);
|
||||||
|
FSFILE_Read(handle, NULL, 0, temp_buf, size);
|
||||||
|
}
|
||||||
|
FSFILE_Close(handle);
|
||||||
|
|
||||||
|
if (temp_buf[0] != 0x11) {
|
||||||
|
free(temp_buf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 output_size = temp_buf[1] | ((temp_buf[2] << 8) & 0xFF00) | ((temp_buf[3] << 16) & 0xFF0000);
|
||||||
|
printf("%ld\n", output_size);
|
||||||
|
|
||||||
|
|
||||||
|
*buf = calloc(1, output_size);
|
||||||
|
|
||||||
|
u32 pos = 4;
|
||||||
|
u32 cur_written = 0;
|
||||||
|
u8 counter = 0;
|
||||||
|
u8 mask = 0;
|
||||||
|
|
||||||
|
while (cur_written < output_size)
|
||||||
|
{
|
||||||
|
if (counter == 0) // read mask
|
||||||
|
{
|
||||||
|
mask = temp_buf[pos++];
|
||||||
|
counter++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((mask >> (8 - counter)) & 0x01) // compressed block
|
||||||
|
{
|
||||||
|
int len = 0;
|
||||||
|
int disp = 0;
|
||||||
|
switch (temp_buf[pos] >> 4)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
len = temp_buf[pos++] << 4;
|
||||||
|
len |= temp_buf[pos] >> 4;
|
||||||
|
len += 0x11;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
len = (temp_buf[pos++] & 0x0F) << 12;
|
||||||
|
len |= temp_buf[pos++] << 4;
|
||||||
|
len |= temp_buf[pos] >> 4;
|
||||||
|
len += 0x111;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
len = (temp_buf[pos] >> 4) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
disp = (temp_buf[pos++] & 0x0F) << 8;
|
||||||
|
disp |= temp_buf[pos++];
|
||||||
|
|
||||||
|
for (int i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
*(*buf + cur_written + i) = *(*buf + cur_written - disp - 1 + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
cur_written += len;
|
||||||
|
}
|
||||||
|
else // byte literal
|
||||||
|
{
|
||||||
|
*(*buf + cur_written) = temp_buf[pos++];
|
||||||
|
cur_written++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (++counter > 8) counter = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
free(temp_buf);
|
||||||
|
|
||||||
|
return cur_written;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is an awful algorithm to "compress" LZ11 data.
|
||||||
|
// We do this instead of actual LZ11 compression because of time -
|
||||||
|
// LZ11 requires a lot of mem searching which is painfully slow on 3DS.
|
||||||
|
// This process is nearly instant but means the resulting file is actually larger
|
||||||
|
// than the input file. I don't think this is a problem as the only file we compress like this
|
||||||
|
// is the theme data installed to extdata in some rare cases, which means only 1 file at most
|
||||||
|
// is ever compressed like this. I don't think 400 KB is that big a sacrifice for probably
|
||||||
|
// half a minute or so of time save - I may change my mind on this in the future, especially
|
||||||
|
// if i figure out a dynamic programming algorithm which ends up being significantly
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
char * output_buf = calloc(1, size * 2);
|
||||||
|
u32 output_size = 0;
|
||||||
|
u32 mask_pos = 0;
|
||||||
|
u32 bytes_processed = 0;
|
||||||
|
u8 counter = 0;
|
||||||
|
|
||||||
|
if (output_buf == NULL) return 0;
|
||||||
|
|
||||||
|
// Set header data for the LZ11 file - 0x11 is version (LZ11), next 3 bytes are size
|
||||||
|
output_buf[0] = 0x11;
|
||||||
|
output_buf[3] = (size & 0xFF0000) >> 16;
|
||||||
|
output_buf[2] = (size & 0xFF00) >> 8;
|
||||||
|
output_buf[1] = (size & 0xFF);
|
||||||
|
|
||||||
|
output_size += 4;
|
||||||
|
|
||||||
|
while (bytes_processed < size)
|
||||||
|
{
|
||||||
|
if (counter == 0)
|
||||||
|
{
|
||||||
|
mask_pos = output_size++;
|
||||||
|
output_buf[mask_pos] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
output_buf[output_size++] = in_buf[bytes_processed++];
|
||||||
|
|
||||||
|
if (++counter == 8) counter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf_to_file(output_size, path, archive, output_buf);
|
||||||
|
free(output_buf);
|
||||||
|
|
||||||
|
return output_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void remake_file(FS_Path path, FS_Archive archive, u32 size)
|
||||||
|
{
|
||||||
|
Handle handle;
|
||||||
|
if (R_SUCCEEDED(FSUSER_OpenFile(&handle, archive, path, FS_OPEN_READ, 0)))
|
||||||
{
|
{
|
||||||
FSFILE_Close(handle);
|
FSFILE_Close(handle);
|
||||||
FSUSER_DeleteFile(archive, fsMakePath(PATH_ASCII, path));
|
FSUSER_DeleteFile(archive, path);
|
||||||
}
|
}
|
||||||
FSUSER_CreateFile(archive, fsMakePath(PATH_ASCII, path), 0, size);
|
Result res = FSUSER_CreateFile(archive, path, 0, size);
|
||||||
}
|
DEBUG("Remake file res: 0x%08lx\n", res);
|
||||||
|
char * buf = calloc(size, 1);
|
||||||
|
if (buf == NULL)
|
||||||
|
{
|
||||||
|
DEBUG("out of memory - not overwriting file?\n");
|
||||||
|
} else {
|
||||||
|
buf_to_file(size, path, archive, buf);
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result zero_handle_memeasy(Handle handle)
|
||||||
|
{
|
||||||
|
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)user;
|
||||||
|
|
||||||
|
*ppMessage = language.fs.illegal_input;
|
||||||
|
if(strpbrk(text, ILLEGAL_CHARS))
|
||||||
|
{
|
||||||
|
DEBUG("illegal filename: %s\n", text);
|
||||||
|
return SWKBD_CALLBACK_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SWKBD_CALLBACK_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
static char path_to_file[32761]; // FAT32 paths can be quite long.
|
||||||
|
const int max_chars = 250;
|
||||||
|
char new_filename[max_chars + 5]; // .zip + \0
|
||||||
|
renamed:
|
||||||
|
char * curr_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
|
||||||
|
char * illegal_char = curr_filename;
|
||||||
|
while ((illegal_char = strpbrk(illegal_char, ILLEGAL_CHARS)))
|
||||||
|
{
|
||||||
|
DEBUG("Illegal char found in filename: %c\n", *illegal_char);
|
||||||
|
if (*illegal_char == '.')
|
||||||
|
{
|
||||||
|
// skip initial . (this is allowed)
|
||||||
|
if (illegal_char == curr_filename)
|
||||||
|
continue;
|
||||||
|
// skip extension delimiter
|
||||||
|
if (strpbrk(illegal_char + 1, ".") == NULL)
|
||||||
|
{
|
||||||
|
illegal_char++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*illegal_char = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG("Checking extension\n");
|
||||||
|
// ensure the extension is .zip
|
||||||
|
char * extension = strrchr(path_to_file, '.');
|
||||||
|
if (extension == NULL || strcmp(extension, ".zip"))
|
||||||
|
strcat(path_to_file, ".zip");
|
||||||
|
|
||||||
|
DEBUG("path: %s\n", path_to_file);
|
||||||
|
u16 utf16path[0x106] = {0};
|
||||||
|
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
|
||||||
|
// to overwrite or change name (or exit)
|
||||||
|
Result res = FSUSER_CreateFile(ArchiveSD, path, 0, size);
|
||||||
|
if (R_FAILED(res))
|
||||||
|
{
|
||||||
|
if (res == (long)0xC82044BE)
|
||||||
|
{
|
||||||
|
DEBUG("File already exists\n");
|
||||||
|
|
||||||
|
SwkbdState swkbd;
|
||||||
|
|
||||||
|
swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 3, max_chars / 2);
|
||||||
|
swkbdSetHintText(&swkbd, language.fs.new_or_overwrite);
|
||||||
|
swkbdSetFeatures(&swkbd, SWKBD_PREDICTIVE_INPUT | SWKBD_DARKEN_TOP_SCREEN);
|
||||||
|
|
||||||
|
swkbdSetButton(&swkbd, SWKBD_BUTTON_LEFT, language.fs.cancel, false);
|
||||||
|
swkbdSetButton(&swkbd, SWKBD_BUTTON_MIDDLE, language.fs.overwrite, false);
|
||||||
|
swkbdSetButton(&swkbd, SWKBD_BUTTON_RIGHT, language.fs.rename, true);
|
||||||
|
swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY_NOTBLANK, SWKBD_FILTER_CALLBACK, -1);
|
||||||
|
swkbdSetFilterCallback(&swkbd, &fat32filter, NULL);
|
||||||
|
|
||||||
|
SwkbdButton button = swkbdInputText(&swkbd, new_filename, max_chars);
|
||||||
|
|
||||||
|
switch (button)
|
||||||
|
{
|
||||||
|
case SWKBD_BUTTON_RIGHT:
|
||||||
|
DEBUG("Renaming to %s\n", new_filename);
|
||||||
|
strcat(new_filename, ".zip");
|
||||||
|
filename = new_filename;
|
||||||
|
goto renamed;
|
||||||
|
case SWKBD_BUTTON_MIDDLE:
|
||||||
|
// we good
|
||||||
|
DEBUG("Overwriting %s\n", filename);
|
||||||
|
break;
|
||||||
|
case SWKBD_BUTTON_LEFT:
|
||||||
|
// do nothing
|
||||||
|
DEBUG("File rename cancelled\n");
|
||||||
|
return;
|
||||||
|
case SWKBD_BUTTON_NONE:
|
||||||
|
DEBUG("SWKBD broke wtf??? :- %x\n", swkbdGetResult(&swkbd));
|
||||||
|
return throw_error(language.fs.swkbd_fail, ERROR_LEVEL_WARNING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (res == (long)0xC86044D2)
|
||||||
|
{
|
||||||
|
DEBUG("SD card is full\n");
|
||||||
|
return throw_error(language.fs.sd_full, ERROR_LEVEL_WARNING);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DEBUG("error: %lx\n", res);
|
||||||
|
return throw_error(language.fs.fs_error, ERROR_LEVEL_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG("Saving to SD: %s\n", path_to_file);
|
||||||
|
remake_file(path, ArchiveSD, size);
|
||||||
|
buf_to_file(size, path, ArchiveSD, buf);
|
||||||
|
}
|
||||||
|
|||||||
513
source/loading.c
Normal file
@@ -0,0 +1,513 @@
|
|||||||
|
/*
|
||||||
|
* 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 "loading.h"
|
||||||
|
#include "fs.h"
|
||||||
|
#include "unicode.h"
|
||||||
|
#include "music.h"
|
||||||
|
#include "draw.h"
|
||||||
|
#include "conversion.h"
|
||||||
|
#include "ui_strings.h"
|
||||||
|
|
||||||
|
#include <png.h>
|
||||||
|
|
||||||
|
void copy_texture_data(C3D_Tex * texture, const u16 * src, const Entry_Icon_s * current_icon)
|
||||||
|
{
|
||||||
|
// pointer to rgb565, offset by the number of rows and columns specified by current_icon
|
||||||
|
// (reminder that this is z order curve storage)
|
||||||
|
u16 * dest = ((u16 *)texture->data) + (current_icon->y * texture->width) + (current_icon->x * 8);
|
||||||
|
for (int j = 0; j < 48; j += 8)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
if(icon == NULL)
|
||||||
|
{
|
||||||
|
memcpy(entry->name, fallback_name, 0x80);
|
||||||
|
utf8_to_utf16(entry->desc, (u8 *)"No description", 0x100);
|
||||||
|
utf8_to_utf16(entry->author, (u8 *)"Unknown author", 0x80);
|
||||||
|
entry->placeholder_color = C2D_Color32(rand() % 255, rand() % 255, rand() % 255, 255);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(entry->name, icon->name, 0x40 * sizeof(u16));
|
||||||
|
memcpy(entry->desc, icon->desc, 0x80 * sizeof(u16));
|
||||||
|
memcpy(entry->author, icon->author, 0x40 * sizeof(u16));
|
||||||
|
entry->placeholder_color = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Icon_s * load_entry_icon(const Entry_s * entry)
|
||||||
|
{
|
||||||
|
char * info_buffer = NULL;
|
||||||
|
u32 size = load_data("/info.smdh", entry, &info_buffer);
|
||||||
|
if(size != sizeof(Icon_s))
|
||||||
|
{
|
||||||
|
free(info_buffer);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (Icon_s *)info_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_icons_first(Entry_List_s * list, bool silent)
|
||||||
|
{
|
||||||
|
if(list == NULL || list->entries == NULL) return;
|
||||||
|
|
||||||
|
if(!silent)
|
||||||
|
draw_install(INSTALL_LOADING_ICONS);
|
||||||
|
|
||||||
|
int starti = 0, endi = 0;
|
||||||
|
|
||||||
|
if(list->entries_count <= list->entries_loaded * ICONS_OFFSET_AMOUNT)
|
||||||
|
{
|
||||||
|
DEBUG("small load\n");
|
||||||
|
// if the list is one that doesnt need swapping, load everything at once
|
||||||
|
endi = list->entries_count;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DEBUG("extended load\n");
|
||||||
|
// otherwise, load around to prepare for swapping
|
||||||
|
starti = list->scroll - list->entries_loaded * ICONS_VISIBLE;
|
||||||
|
endi = starti + list->entries_loaded * ICONS_OFFSET_AMOUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int entry_i = starti, icon_i = 0; entry_i < endi; ++entry_i, ++icon_i)
|
||||||
|
{
|
||||||
|
if(!silent)
|
||||||
|
draw_loading_bar(icon_i, endi-starti, INSTALL_LOADING_ICONS);
|
||||||
|
|
||||||
|
int offset = entry_i;
|
||||||
|
if(offset < 0)
|
||||||
|
offset += list->entries_count;
|
||||||
|
if(offset >= list->entries_count)
|
||||||
|
offset -= list->entries_count;
|
||||||
|
|
||||||
|
Entry_s * const current_entry = &list->entries[offset];
|
||||||
|
Icon_s * const smdh = 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) {
|
||||||
|
int i, j;
|
||||||
|
Entry_Icon_s tmp;
|
||||||
|
for (i = 0, j = sz; i < j; i++, j--) {
|
||||||
|
memcpy(&tmp, &a[i], sizeof(Entry_Icon_s));
|
||||||
|
memcpy(&a[i], &a[j], sizeof(Entry_Icon_s));
|
||||||
|
memcpy(&a[j], &tmp, sizeof(Entry_Icon_s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rotate(Entry_Icon_s array[], int size, int amt) {
|
||||||
|
if (amt < 0)
|
||||||
|
amt = size + amt;
|
||||||
|
reverse(array, size-amt-1);
|
||||||
|
reverse(array+size-amt, amt-1);
|
||||||
|
reverse(array, size-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_scrolling(Entry_List_s * list)
|
||||||
|
{
|
||||||
|
// Scroll the menu up or down if the selected theme is out of its bounds
|
||||||
|
//----------------------------------------------------------------
|
||||||
|
if(list->entries_count > list->entries_loaded)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
list->scroll = 0;
|
||||||
|
}
|
||||||
|
else if(list->selected_entry == list->previous_selected+1 && list->selected_entry == list->scroll+list->entries_loaded)
|
||||||
|
{
|
||||||
|
change = 1;
|
||||||
|
}
|
||||||
|
else if(list->selected_entry == list->previous_selected-1 && list->selected_entry == list->scroll-1)
|
||||||
|
{
|
||||||
|
change = -1;
|
||||||
|
}
|
||||||
|
else if(list->selected_entry == list->previous_selected+list->entries_loaded)
|
||||||
|
{
|
||||||
|
change = list->entries_loaded;
|
||||||
|
}
|
||||||
|
else if(list->selected_entry == list->previous_selected-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;
|
||||||
|
|
||||||
|
if(list->scroll < 0)
|
||||||
|
list->scroll = 0;
|
||||||
|
else if(list->scroll > list->entries_count - list->entries_loaded)
|
||||||
|
list->scroll = list->entries_count - list->entries_loaded;
|
||||||
|
|
||||||
|
if(!change)
|
||||||
|
list->previous_selected = list->selected_entry;
|
||||||
|
else
|
||||||
|
list->previous_selected += change;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool load_icons(Entry_List_s * current_list, Handle mutex)
|
||||||
|
{
|
||||||
|
if(current_list == NULL || current_list->entries == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
handle_scrolling(current_list);
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
#define SIGN(x) (x > 0 ? 1 : ((x < 0) ? -1 : 0))
|
||||||
|
|
||||||
|
int delta = current_list->scroll - current_list->previous_scroll;
|
||||||
|
if(abs(delta) >= current_list->entries_count - current_list->entries_loaded * (ICONS_OFFSET_AMOUNT-1))
|
||||||
|
delta = -SIGN(delta) * (current_list->entries_count - abs(delta));
|
||||||
|
|
||||||
|
int starti = current_list->scroll;
|
||||||
|
int endi = starti + abs(delta);
|
||||||
|
|
||||||
|
if(delta < 0)
|
||||||
|
{
|
||||||
|
endi -= abs(delta) + 1;
|
||||||
|
starti += abs(delta) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ctr = 0;
|
||||||
|
Entry_s ** const entries = calloc(abs(delta), sizeof(Entry_s *));
|
||||||
|
int * const indexes = calloc(abs(delta), sizeof(int));
|
||||||
|
bool released = false;
|
||||||
|
|
||||||
|
Entry_Icon_s * const icons = current_list->icons_info;
|
||||||
|
|
||||||
|
for(int i = starti; i != endi; i++, ctr++)
|
||||||
|
{
|
||||||
|
int index = 0;
|
||||||
|
int offset = i;
|
||||||
|
|
||||||
|
rotate(icons, ICONS_OFFSET_AMOUNT * current_list->entries_loaded, -SIGN(delta));
|
||||||
|
|
||||||
|
if(delta > 0)
|
||||||
|
{
|
||||||
|
index = current_list->entries_loaded * ICONS_OFFSET_AMOUNT - delta + i - starti;
|
||||||
|
offset += current_list->entries_loaded * ICONS_UNDER - delta;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index = 0 - delta - 1 + i - starti;
|
||||||
|
offset -= current_list->entries_loaded * ICONS_VISIBLE;
|
||||||
|
i -= 2; //i-- twice to counter the i++, needed only for this case
|
||||||
|
}
|
||||||
|
|
||||||
|
if(offset < 0)
|
||||||
|
offset += current_list->entries_count;
|
||||||
|
if(offset >= current_list->entries_count)
|
||||||
|
offset -= current_list->entries_count;
|
||||||
|
|
||||||
|
entries[ctr] = ¤t_list->entries[offset];
|
||||||
|
indexes[ctr] = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef SIGN
|
||||||
|
|
||||||
|
if(abs(delta) <= current_list->entries_loaded)
|
||||||
|
{
|
||||||
|
svcReleaseMutex(mutex);
|
||||||
|
released = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
svcSleepThread(1e7);
|
||||||
|
starti = 0;
|
||||||
|
endi = abs(delta);
|
||||||
|
for(int i = starti; i < endi; i++)
|
||||||
|
{
|
||||||
|
Entry_s * const current_entry = entries[i];
|
||||||
|
const int index = indexes[i];
|
||||||
|
const Entry_Icon_s * const current_icon = &icons[index];
|
||||||
|
|
||||||
|
Icon_s * const smdh = load_entry_icon(current_entry);
|
||||||
|
if(smdh != NULL)
|
||||||
|
{
|
||||||
|
if(current_entry->placeholder_color == 0)
|
||||||
|
parse_smdh(smdh, current_entry, current_entry->path + strlen(current_list->loading_path));
|
||||||
|
copy_texture_data(¤t_list->icons_texture, smdh->big_icon, current_icon);
|
||||||
|
free(smdh);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!released && i > endi/2)
|
||||||
|
{
|
||||||
|
svcReleaseMutex(mutex);
|
||||||
|
released = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(entries);
|
||||||
|
free(indexes);
|
||||||
|
|
||||||
|
current_list->previous_scroll = current_list->scroll;
|
||||||
|
|
||||||
|
return released;
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_icons_thread(void * void_arg)
|
||||||
|
{
|
||||||
|
Thread_Arg_s * arg = (Thread_Arg_s *)void_arg;
|
||||||
|
Handle mutex = *(Handle *)arg->thread_arg[1];
|
||||||
|
do {
|
||||||
|
svcWaitSynchronization(mutex, U64_MAX);
|
||||||
|
Entry_List_s * const current_list = *(Entry_List_s ** volatile)arg->thread_arg[0];
|
||||||
|
const bool released = load_icons(current_list, mutex);
|
||||||
|
if(!released)
|
||||||
|
svcReleaseMutex(mutex);
|
||||||
|
} while(arg->run_thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool load_preview_from_buffer(char * row_pointers, u32 size, C2D_Image * preview_image, int * preview_offset, int height)
|
||||||
|
{
|
||||||
|
int width = (uint32_t)((size / 4) / height);
|
||||||
|
float tex_height = height > 512.0f ? 1024.0f : 512.0f;
|
||||||
|
|
||||||
|
free_preview(*preview_image);
|
||||||
|
|
||||||
|
C3D_Tex * tex = malloc(sizeof(C3D_Tex));
|
||||||
|
preview_image->tex = tex;
|
||||||
|
|
||||||
|
Tex3DS_SubTexture * subt3x = malloc(sizeof(Tex3DS_SubTexture));
|
||||||
|
subt3x->width = width;
|
||||||
|
subt3x->height = height;
|
||||||
|
subt3x->left = 0.0f;
|
||||||
|
subt3x->top = 1.0f;
|
||||||
|
subt3x->right = width/512.0f;
|
||||||
|
subt3x->bottom = 1.0-(height/tex_height);
|
||||||
|
preview_image->subtex = subt3x;
|
||||||
|
|
||||||
|
C3D_TexInit(preview_image->tex, 512, tex_height, GPU_RGBA8);
|
||||||
|
|
||||||
|
memset(preview_image->tex->data, 0, preview_image->tex->size);
|
||||||
|
|
||||||
|
for(int j = 0; j < height; j++) {
|
||||||
|
png_bytep row = (png_bytep)(row_pointers + (width * 4 * j));
|
||||||
|
for(int i = 0; i < width; i++) {
|
||||||
|
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;
|
||||||
|
|
||||||
|
memcpy(preview_image->tex->data + dst, px, sizeof(u32));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*preview_offset = (width - TOP_SCREEN_WIDTH) / 2;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static u16 previous_path_preview[0x106] = {0};
|
||||||
|
bool load_preview(const Entry_List_s * list, C2D_Image * preview_image, int * preview_offset)
|
||||||
|
{
|
||||||
|
if(list->entries == NULL) return false;
|
||||||
|
|
||||||
|
const Entry_s * entry = &list->entries[list->selected_entry];
|
||||||
|
|
||||||
|
if(!memcmp(&previous_path_preview, &entry->path, 0x106 * sizeof(u16))) return true;
|
||||||
|
|
||||||
|
char * preview_buffer = NULL;
|
||||||
|
u32 size = load_data("/preview.png", entry, &preview_buffer);
|
||||||
|
u32 height = 480;
|
||||||
|
|
||||||
|
if(size)
|
||||||
|
{
|
||||||
|
if (!(size = png_to_abgr(&preview_buffer, size, &height)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
free(preview_buffer);
|
||||||
|
|
||||||
|
const int top_size = TOP_SCREEN_WIDTH * SCREEN_HEIGHT * SCREEN_COLOR_DEPTH;
|
||||||
|
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);
|
||||||
|
free(preview_buffer);
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
// mark the new preview as loaded for optimisation
|
||||||
|
memcpy(&previous_path_preview, &entry->path, 0x106 * sizeof(u16));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_preview(C2D_Image preview)
|
||||||
|
{
|
||||||
|
if(preview.tex)
|
||||||
|
C3D_TexDelete(preview.tex);
|
||||||
|
free(preview.tex);
|
||||||
|
free((Tex3DS_SubTexture *)preview.subtex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the audio struct
|
||||||
|
Result load_audio(const 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);
|
||||||
|
if (audio->filesize == 0) {
|
||||||
|
free(audio);
|
||||||
|
DEBUG("<load_audio> File not found!\n");
|
||||||
|
return MAKERESULT(RL_FATAL, RS_NOTFOUND, RM_APPLICATION, RD_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
ndspChnSetInterp(0, NDSP_INTERP_LINEAR);
|
||||||
|
ndspChnSetMix(0, audio->mix); // See mix comment above
|
||||||
|
|
||||||
|
FILE * file = fmemopen(audio->filebuf, audio->filesize, "rb");
|
||||||
|
DEBUG("<load_audio> Filesize: %ld\n", audio->filesize);
|
||||||
|
if(file != NULL)
|
||||||
|
{
|
||||||
|
int e = ov_open(file, &audio->vf, NULL, 0);
|
||||||
|
if (e < 0)
|
||||||
|
{
|
||||||
|
DEBUG("<load_audio> Vorbis: %d\n", e);
|
||||||
|
free(audio->filebuf);
|
||||||
|
free(audio);
|
||||||
|
fclose(file);
|
||||||
|
return MAKERESULT(RL_FATAL, RS_INVALIDARG, RM_APPLICATION, RD_NO_DATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
vorbis_info * vi = ov_info(&audio->vf, -1);
|
||||||
|
ndspChnSetRate(0, vi->rate);// Set sample rate to what's read from the ogg file
|
||||||
|
if (vi->channels == 2) {
|
||||||
|
DEBUG("<load_audio> Using stereo\n");
|
||||||
|
ndspChnSetFormat(0, NDSP_FORMAT_STEREO_PCM16); // 2 channels == Stereo
|
||||||
|
} else {
|
||||||
|
DEBUG("<load_audio> Invalid number of channels\n");
|
||||||
|
free(audio->filebuf);
|
||||||
|
free(audio);
|
||||||
|
fclose(file);
|
||||||
|
return MAKERESULT(RL_FATAL, RS_INVALIDARG, RM_APPLICATION, RD_NO_DATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
audio->wave_buf[0].nsamples = audio->wave_buf[1].nsamples = vi->rate / 4; // 4 bytes per sample, samples = rate (bytes) / 4
|
||||||
|
audio->wave_buf[0].status = audio->wave_buf[1].status = NDSP_WBUF_DONE; // Used in play to stop from writing to current buffer
|
||||||
|
audio->wave_buf[0].data_vaddr = linearAlloc(BUF_TO_READ); // Most vorbis packets should only be 4 KB at most (?) Possibly dangerous assumption
|
||||||
|
audio->wave_buf[1].data_vaddr = linearAlloc(BUF_TO_READ);
|
||||||
|
DEBUG("<load_audio> Success!\n");
|
||||||
|
return MAKERESULT(RL_SUCCESS, RS_SUCCESS, RM_APPLICATION, RD_SUCCESS);
|
||||||
|
} else {
|
||||||
|
free(audio->filebuf);
|
||||||
|
free(audio);
|
||||||
|
DEBUG("<load_audio> fmemopen failed!\n");
|
||||||
|
return MAKERESULT(RL_FATAL, RS_NOTFOUND, RM_APPLICATION, RD_NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
1271
source/main.c
@@ -1,137 +0,0 @@
|
|||||||
/* crypt.h -- base code for traditional PKWARE encryption
|
|
||||||
Version 1.01e, February 12th, 2005
|
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
|
||||||
Modifications for Info-ZIP crypting
|
|
||||||
Copyright (C) 2003 Terry Thorsen
|
|
||||||
|
|
||||||
This code is a modified version of crypting code in Info-ZIP distribution
|
|
||||||
|
|
||||||
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
|
|
||||||
|
|
||||||
See the Info-ZIP LICENSE file version 2000-Apr-09 or later for terms of use
|
|
||||||
which also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
|
|
||||||
|
|
||||||
The encryption/decryption parts of this source code (as opposed to the
|
|
||||||
non-echoing password parts) were originally written in Europe. The
|
|
||||||
whole source package can be freely distributed, including from the USA.
|
|
||||||
(Prior to January 2000, re-export from the US was a violation of US law.)
|
|
||||||
|
|
||||||
This encryption code is a direct transcription of the algorithm from
|
|
||||||
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
|
||||||
file (appnote.txt) is distributed with the PKZIP program (even in the
|
|
||||||
version without encryption capabilities).
|
|
||||||
|
|
||||||
If you don't need crypting in your application, just define symbols
|
|
||||||
NOCRYPT and NOUNCRYPT.
|
|
||||||
|
|
||||||
Mar 8th, 2016 - Lucio Cosmo
|
|
||||||
Fixed support for 64bit builds for archives with "PKWARE" password.
|
|
||||||
Changed long, unsigned long, unsigned to unsigned int in
|
|
||||||
access functions to crctables and pkeys
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define CRC32(c, b) ((*(pcrc_32_tab+(((unsigned int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* Return the next byte in the pseudo-random sequence
|
|
||||||
*/
|
|
||||||
static int decrypt_byte(unsigned int* pkeys)
|
|
||||||
{
|
|
||||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
|
||||||
* unpredictable manner on 16-bit systems; not a problem
|
|
||||||
* with any known compiler so far, though */
|
|
||||||
|
|
||||||
temp = ((unsigned int)(*(pkeys+2)) & 0xffff) | 2;
|
|
||||||
return (unsigned int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* Update the encryption keys with the next byte of plain text
|
|
||||||
*/
|
|
||||||
static int update_keys(unsigned int* pkeys,const unsigned int* pcrc_32_tab,int c)
|
|
||||||
{
|
|
||||||
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
|
||||||
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
|
||||||
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
|
||||||
{
|
|
||||||
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
|
||||||
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* Initialize the encryption keys and the random header according to
|
|
||||||
* the given password.
|
|
||||||
*/
|
|
||||||
static void init_keys(const char* passwd,unsigned int* pkeys,const unsigned int* pcrc_32_tab)
|
|
||||||
{
|
|
||||||
*(pkeys+0) = 305419896L;
|
|
||||||
*(pkeys+1) = 591751049L;
|
|
||||||
*(pkeys+2) = 878082192L;
|
|
||||||
while (*passwd != 0)
|
|
||||||
{
|
|
||||||
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
|
||||||
passwd++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define zdecode(pkeys,pcrc_32_tab,c) \
|
|
||||||
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys)))
|
|
||||||
|
|
||||||
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
|
||||||
(t=decrypt_byte(pkeys), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
|
||||||
|
|
||||||
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
|
||||||
|
|
||||||
#define RAND_HEAD_LEN 12
|
|
||||||
/* "last resort" source for second part of crypt seed pattern */
|
|
||||||
# ifndef ZCR_SEED2
|
|
||||||
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
|
||||||
# endif
|
|
||||||
|
|
||||||
static int crypthead(const char* passwd, /* password string */
|
|
||||||
unsigned char* buf, /* where to write header */
|
|
||||||
int bufSize,
|
|
||||||
unsigned int* pkeys,
|
|
||||||
const unsigned int* pcrc_32_tab,
|
|
||||||
unsigned int crcForCrypting)
|
|
||||||
{
|
|
||||||
int n; /* index in random header */
|
|
||||||
int t; /* temporary */
|
|
||||||
int c; /* random byte */
|
|
||||||
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
|
||||||
static unsigned calls = 0; /* ensure different random header each time */
|
|
||||||
|
|
||||||
if (bufSize < RAND_HEAD_LEN)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
|
||||||
* output of rand() to get less predictability, since rand() is
|
|
||||||
* often poorly implemented.
|
|
||||||
*/
|
|
||||||
if (++calls == 1)
|
|
||||||
{
|
|
||||||
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
|
||||||
}
|
|
||||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
|
||||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
|
||||||
{
|
|
||||||
c = (rand() >> 7) & 0xff;
|
|
||||||
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
|
||||||
}
|
|
||||||
/* Encrypt random header (last two bytes is high word of crc) */
|
|
||||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
|
||||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
|
||||||
{
|
|
||||||
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
|
|
||||||
}
|
|
||||||
buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
|
|
||||||
buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,380 +0,0 @@
|
|||||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
|
||||||
part of the MiniZip project
|
|
||||||
|
|
||||||
Copyright (C) 1998-2010 Gilles Vollant
|
|
||||||
http://www.winimage.com/zLibDll/minizip.html
|
|
||||||
Modifications for Zip64 support
|
|
||||||
Copyright (C) 2009-2010 Mathias Svensson
|
|
||||||
http://result42.com
|
|
||||||
|
|
||||||
This program is distributed under the terms of the same license as zlib.
|
|
||||||
See the accompanying LICENSE file for the full text of the license.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//taken and adapted from https://stackoverflow.com/a/13492589
|
|
||||||
|
|
||||||
// save diagnostic state
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
|
|
||||||
// turn off the specific warning. Can also use "-Wall"
|
|
||||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "ioapi.h"
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
# define snprintf _snprintf
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
/* In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions */
|
|
||||||
# define FOPEN_FUNC(filename, mode) fopen(filename, mode)
|
|
||||||
# define FTELLO_FUNC(stream) ftello(stream)
|
|
||||||
# define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
|
|
||||||
#else
|
|
||||||
# define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
|
|
||||||
# define FTELLO_FUNC(stream) ftello64(stream)
|
|
||||||
# define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
|
|
||||||
#ifndef SEEK_CUR
|
|
||||||
# define SEEK_CUR 1
|
|
||||||
#endif
|
|
||||||
#ifndef SEEK_END
|
|
||||||
# define SEEK_END 2
|
|
||||||
#endif
|
|
||||||
#ifndef SEEK_SET
|
|
||||||
# define SEEK_SET 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
|
|
||||||
{
|
|
||||||
if (pfilefunc->zfile_func64.zopen64_file != NULL)
|
|
||||||
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
|
|
||||||
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
voidpf call_zopendisk64 OF((const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, int number_disk, int mode))
|
|
||||||
{
|
|
||||||
if (pfilefunc->zfile_func64.zopendisk64_file != NULL)
|
|
||||||
return (*(pfilefunc->zfile_func64.zopendisk64_file)) (pfilefunc->zfile_func64.opaque,filestream,number_disk,mode);
|
|
||||||
return (*(pfilefunc->zopendisk32_file))(pfilefunc->zfile_func64.opaque,filestream,number_disk,mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
|
|
||||||
{
|
|
||||||
uLong offsetTruncated;
|
|
||||||
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
|
||||||
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
|
|
||||||
offsetTruncated = (uLong)offset;
|
|
||||||
if (offsetTruncated != offset)
|
|
||||||
return -1;
|
|
||||||
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
|
|
||||||
{
|
|
||||||
uLong tell_uLong;
|
|
||||||
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
|
||||||
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
|
|
||||||
tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
|
|
||||||
if ((tell_uLong) == 0xffffffff)
|
|
||||||
return (ZPOS64_T)-1;
|
|
||||||
return tell_uLong;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
|
|
||||||
{
|
|
||||||
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
|
|
||||||
p_filefunc64_32->zfile_func64.zopendisk64_file = NULL;
|
|
||||||
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
|
|
||||||
p_filefunc64_32->zopendisk32_file = p_filefunc32->zopendisk_file;
|
|
||||||
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
|
||||||
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
|
|
||||||
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
|
|
||||||
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
|
|
||||||
p_filefunc64_32->zfile_func64.zseek64_file = NULL;
|
|
||||||
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
|
|
||||||
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
|
||||||
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
|
|
||||||
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
|
|
||||||
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
|
|
||||||
static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
|
||||||
static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
|
|
||||||
static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
|
|
||||||
static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
|
|
||||||
static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
|
|
||||||
static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
FILE *file;
|
|
||||||
int filenameLength;
|
|
||||||
void *filename;
|
|
||||||
} FILE_IOPOSIX;
|
|
||||||
|
|
||||||
static voidpf file_build_ioposix(FILE *file, const char *filename)
|
|
||||||
{
|
|
||||||
FILE_IOPOSIX *ioposix = NULL;
|
|
||||||
if (file == NULL)
|
|
||||||
return NULL;
|
|
||||||
ioposix = (FILE_IOPOSIX*)malloc(sizeof(FILE_IOPOSIX));
|
|
||||||
ioposix->file = file;
|
|
||||||
ioposix->filenameLength = strlen(filename) + 1;
|
|
||||||
ioposix->filename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
|
||||||
strncpy(ioposix->filename, filename, ioposix->filenameLength);
|
|
||||||
return (voidpf)ioposix;
|
|
||||||
}
|
|
||||||
|
|
||||||
static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
|
|
||||||
{
|
|
||||||
FILE* file = NULL;
|
|
||||||
const char* mode_fopen = NULL;
|
|
||||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
|
|
||||||
mode_fopen = "rb";
|
|
||||||
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
|
||||||
mode_fopen = "r+b";
|
|
||||||
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
|
||||||
mode_fopen = "wb";
|
|
||||||
|
|
||||||
if ((filename != NULL) && (mode_fopen != NULL))
|
|
||||||
{
|
|
||||||
file = fopen(filename, mode_fopen);
|
|
||||||
return file_build_ioposix(file, filename);
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
|
|
||||||
{
|
|
||||||
FILE* file = NULL;
|
|
||||||
const char* mode_fopen = NULL;
|
|
||||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
|
|
||||||
mode_fopen = "rb";
|
|
||||||
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
|
||||||
mode_fopen = "r+b";
|
|
||||||
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
|
||||||
mode_fopen = "wb";
|
|
||||||
|
|
||||||
if ((filename != NULL) && (mode_fopen != NULL))
|
|
||||||
{
|
|
||||||
file = FOPEN_FUNC((const char*)filename, mode_fopen);
|
|
||||||
return file_build_ioposix(file, (const char*)filename);
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
static voidpf ZCALLBACK fopendisk64_file_func (voidpf opaque, voidpf stream, int number_disk, int mode)
|
|
||||||
{
|
|
||||||
FILE_IOPOSIX *ioposix = NULL;
|
|
||||||
char *diskFilename = NULL;
|
|
||||||
voidpf ret = NULL;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
if (stream == NULL)
|
|
||||||
return NULL;
|
|
||||||
ioposix = (FILE_IOPOSIX*)stream;
|
|
||||||
diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
|
||||||
strncpy(diskFilename, ioposix->filename, ioposix->filenameLength);
|
|
||||||
for (i = ioposix->filenameLength - 1; i >= 0; i -= 1)
|
|
||||||
{
|
|
||||||
if (diskFilename[i] != '.')
|
|
||||||
continue;
|
|
||||||
snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02d", number_disk + 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i >= 0)
|
|
||||||
ret = fopen64_file_func(opaque, diskFilename, mode);
|
|
||||||
free(diskFilename);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static voidpf ZCALLBACK fopendisk_file_func (voidpf opaque, voidpf stream, int number_disk, int mode)
|
|
||||||
{
|
|
||||||
FILE_IOPOSIX *ioposix = NULL;
|
|
||||||
char *diskFilename = NULL;
|
|
||||||
voidpf ret = NULL;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
if (stream == NULL)
|
|
||||||
return NULL;
|
|
||||||
ioposix = (FILE_IOPOSIX*)stream;
|
|
||||||
diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
|
||||||
strncpy(diskFilename, ioposix->filename, ioposix->filenameLength);
|
|
||||||
for (i = ioposix->filenameLength - 1; i >= 0; i -= 1)
|
|
||||||
{
|
|
||||||
if (diskFilename[i] != '.')
|
|
||||||
continue;
|
|
||||||
snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02d", number_disk + 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i >= 0)
|
|
||||||
ret = fopen_file_func(opaque, diskFilename, mode);
|
|
||||||
free(diskFilename);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
|
|
||||||
{
|
|
||||||
FILE_IOPOSIX *ioposix = NULL;
|
|
||||||
uLong ret;
|
|
||||||
if (stream == NULL)
|
|
||||||
return -1;
|
|
||||||
ioposix = (FILE_IOPOSIX*)stream;
|
|
||||||
ret = (uLong)fread(buf, 1, (size_t)size, ioposix->file);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
|
|
||||||
{
|
|
||||||
FILE_IOPOSIX *ioposix = NULL;
|
|
||||||
uLong ret;
|
|
||||||
if (stream == NULL)
|
|
||||||
return -1;
|
|
||||||
ioposix = (FILE_IOPOSIX*)stream;
|
|
||||||
ret = (uLong)fwrite(buf, 1, (size_t)size, ioposix->file);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
|
|
||||||
{
|
|
||||||
FILE_IOPOSIX *ioposix = NULL;
|
|
||||||
long ret = -1;
|
|
||||||
if (stream == NULL)
|
|
||||||
return ret;
|
|
||||||
ioposix = (FILE_IOPOSIX*)stream;
|
|
||||||
ret = ftell(ioposix->file);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
|
|
||||||
{
|
|
||||||
FILE_IOPOSIX *ioposix = NULL;
|
|
||||||
ZPOS64_T ret = -1;
|
|
||||||
if (stream == NULL)
|
|
||||||
return ret;
|
|
||||||
ioposix = (FILE_IOPOSIX*)stream;
|
|
||||||
ret = FTELLO_FUNC(ioposix->file);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
|
|
||||||
{
|
|
||||||
FILE_IOPOSIX *ioposix = NULL;
|
|
||||||
int fseek_origin = 0;
|
|
||||||
long ret = 0;
|
|
||||||
|
|
||||||
if (stream == NULL)
|
|
||||||
return -1;
|
|
||||||
ioposix = (FILE_IOPOSIX*)stream;
|
|
||||||
|
|
||||||
switch (origin)
|
|
||||||
{
|
|
||||||
case ZLIB_FILEFUNC_SEEK_CUR:
|
|
||||||
fseek_origin = SEEK_CUR;
|
|
||||||
break;
|
|
||||||
case ZLIB_FILEFUNC_SEEK_END:
|
|
||||||
fseek_origin = SEEK_END;
|
|
||||||
break;
|
|
||||||
case ZLIB_FILEFUNC_SEEK_SET:
|
|
||||||
fseek_origin = SEEK_SET;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (fseek(ioposix->file, offset, fseek_origin) != 0)
|
|
||||||
ret = -1;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
|
|
||||||
{
|
|
||||||
FILE_IOPOSIX *ioposix = NULL;
|
|
||||||
int fseek_origin = 0;
|
|
||||||
long ret = 0;
|
|
||||||
|
|
||||||
if (stream == NULL)
|
|
||||||
return -1;
|
|
||||||
ioposix = (FILE_IOPOSIX*)stream;
|
|
||||||
|
|
||||||
switch (origin)
|
|
||||||
{
|
|
||||||
case ZLIB_FILEFUNC_SEEK_CUR:
|
|
||||||
fseek_origin = SEEK_CUR;
|
|
||||||
break;
|
|
||||||
case ZLIB_FILEFUNC_SEEK_END:
|
|
||||||
fseek_origin = SEEK_END;
|
|
||||||
break;
|
|
||||||
case ZLIB_FILEFUNC_SEEK_SET:
|
|
||||||
fseek_origin = SEEK_SET;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(FSEEKO_FUNC(ioposix->file, offset, fseek_origin) != 0)
|
|
||||||
ret = -1;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
|
|
||||||
{
|
|
||||||
FILE_IOPOSIX *ioposix = NULL;
|
|
||||||
int ret = -1;
|
|
||||||
if (stream == NULL)
|
|
||||||
return ret;
|
|
||||||
ioposix = (FILE_IOPOSIX*)stream;
|
|
||||||
if (ioposix->filename != NULL)
|
|
||||||
free(ioposix->filename);
|
|
||||||
ret = fclose(ioposix->file);
|
|
||||||
free(ioposix);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
|
|
||||||
{
|
|
||||||
FILE_IOPOSIX *ioposix = NULL;
|
|
||||||
int ret = -1;
|
|
||||||
if (stream == NULL)
|
|
||||||
return ret;
|
|
||||||
ioposix = (FILE_IOPOSIX*)stream;
|
|
||||||
ret = ferror(ioposix->file);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fill_fopen_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
|
|
||||||
{
|
|
||||||
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
|
||||||
pzlib_filefunc_def->zopendisk_file = fopendisk_file_func;
|
|
||||||
pzlib_filefunc_def->zread_file = fread_file_func;
|
|
||||||
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
|
||||||
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
|
||||||
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
|
||||||
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
|
||||||
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
|
||||||
pzlib_filefunc_def->opaque = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
|
|
||||||
{
|
|
||||||
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
|
|
||||||
pzlib_filefunc_def->zopendisk64_file = fopendisk64_file_func;
|
|
||||||
pzlib_filefunc_def->zread_file = fread_file_func;
|
|
||||||
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
|
||||||
pzlib_filefunc_def->ztell64_file = ftell64_file_func;
|
|
||||||
pzlib_filefunc_def->zseek64_file = fseek64_file_func;
|
|
||||||
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
|
||||||
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
|
||||||
pzlib_filefunc_def->opaque = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// turn the warnings back on
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
@@ -1,158 +0,0 @@
|
|||||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
|
||||||
part of the MiniZip project
|
|
||||||
|
|
||||||
Copyright (C) 1998-2010 Gilles Vollant
|
|
||||||
http://www.winimage.com/zLibDll/minizip.html
|
|
||||||
Modifications for Zip64 support
|
|
||||||
Copyright (C) 2009-2010 Mathias Svensson
|
|
||||||
http://result42.com
|
|
||||||
|
|
||||||
This program is distributed under the terms of the same license as zlib.
|
|
||||||
See the accompanying LICENSE file for the full text of the license.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _ZLIBIOAPI64_H
|
|
||||||
#define _ZLIBIOAPI64_H
|
|
||||||
|
|
||||||
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
|
|
||||||
# ifndef __USE_FILE_OFFSET64
|
|
||||||
# define __USE_FILE_OFFSET64
|
|
||||||
# endif
|
|
||||||
# ifndef __USE_LARGEFILE64
|
|
||||||
# define __USE_LARGEFILE64
|
|
||||||
# endif
|
|
||||||
# ifndef _LARGEFILE64_SOURCE
|
|
||||||
# define _LARGEFILE64_SOURCE
|
|
||||||
# endif
|
|
||||||
# ifndef _FILE_OFFSET_BIT
|
|
||||||
# define _FILE_OFFSET_BIT 64
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <zlib.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define fopen64 fopen
|
|
||||||
#define ftello64 ftell
|
|
||||||
#define fseeko64 fseek
|
|
||||||
|
|
||||||
/* a type choosen by DEFINE */
|
|
||||||
#ifdef HAVE_64BIT_INT_CUSTOM
|
|
||||||
typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
|
|
||||||
#else
|
|
||||||
# ifdef HAVE_STDINT_H
|
|
||||||
# include "stdint.h"
|
|
||||||
typedef uint64_t ZPOS64_T;
|
|
||||||
# else
|
|
||||||
# if defined(_MSC_VER) || defined(__BORLANDC__)
|
|
||||||
typedef unsigned __int64 ZPOS64_T;
|
|
||||||
# else
|
|
||||||
typedef unsigned long long int ZPOS64_T;
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
|
||||||
#define ZLIB_FILEFUNC_SEEK_END (2)
|
|
||||||
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
|
||||||
|
|
||||||
#define ZLIB_FILEFUNC_MODE_READ (1)
|
|
||||||
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
|
||||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
|
||||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
|
||||||
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
|
||||||
|
|
||||||
#ifndef ZCALLBACK
|
|
||||||
# if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || \
|
|
||||||
defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
|
||||||
# define ZCALLBACK CALLBACK
|
|
||||||
# else
|
|
||||||
# define ZCALLBACK
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
|
|
||||||
typedef voidpf (ZCALLBACK *opendisk_file_func) OF((voidpf opaque, voidpf stream, int number_disk, int mode));
|
|
||||||
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
|
||||||
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
|
||||||
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
|
|
||||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
|
||||||
|
|
||||||
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
|
|
||||||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
|
||||||
|
|
||||||
/* here is the "old" 32 bits structure structure */
|
|
||||||
typedef struct zlib_filefunc_def_s
|
|
||||||
{
|
|
||||||
open_file_func zopen_file;
|
|
||||||
opendisk_file_func zopendisk_file;
|
|
||||||
read_file_func zread_file;
|
|
||||||
write_file_func zwrite_file;
|
|
||||||
tell_file_func ztell_file;
|
|
||||||
seek_file_func zseek_file;
|
|
||||||
close_file_func zclose_file;
|
|
||||||
testerror_file_func zerror_file;
|
|
||||||
voidpf opaque;
|
|
||||||
} zlib_filefunc_def;
|
|
||||||
|
|
||||||
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
|
|
||||||
typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
|
|
||||||
typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
|
|
||||||
typedef voidpf (ZCALLBACK *opendisk64_file_func)OF((voidpf opaque, voidpf stream, int number_disk, int mode));
|
|
||||||
|
|
||||||
typedef struct zlib_filefunc64_def_s
|
|
||||||
{
|
|
||||||
open64_file_func zopen64_file;
|
|
||||||
opendisk64_file_func zopendisk64_file;
|
|
||||||
read_file_func zread_file;
|
|
||||||
write_file_func zwrite_file;
|
|
||||||
tell64_file_func ztell64_file;
|
|
||||||
seek64_file_func zseek64_file;
|
|
||||||
close_file_func zclose_file;
|
|
||||||
testerror_file_func zerror_file;
|
|
||||||
voidpf opaque;
|
|
||||||
} zlib_filefunc64_def;
|
|
||||||
|
|
||||||
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
|
||||||
void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
|
|
||||||
|
|
||||||
/* now internal definition, only for zip.c and unzip.h */
|
|
||||||
typedef struct zlib_filefunc64_32_def_s
|
|
||||||
{
|
|
||||||
zlib_filefunc64_def zfile_func64;
|
|
||||||
open_file_func zopen32_file;
|
|
||||||
opendisk_file_func zopendisk32_file;
|
|
||||||
tell_file_func ztell32_file;
|
|
||||||
seek_file_func zseek32_file;
|
|
||||||
} zlib_filefunc64_32_def;
|
|
||||||
|
|
||||||
#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
|
|
||||||
#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
|
|
||||||
/*#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))*/
|
|
||||||
/*#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))*/
|
|
||||||
#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
|
|
||||||
#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
|
|
||||||
|
|
||||||
voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
|
|
||||||
voidpf call_zopendisk64 OF((const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, int number_disk, int mode));
|
|
||||||
long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
|
|
||||||
ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
|
|
||||||
|
|
||||||
void fill_zlib_filefunc64_32_def_from_filefunc32 OF((zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32));
|
|
||||||
|
|
||||||
#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
|
|
||||||
#define ZOPENDISK64(filefunc,filestream,diskn,mode) (call_zopendisk64((&(filefunc)),(filestream),(diskn),(mode)))
|
|
||||||
#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
|
|
||||||
#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,202 +0,0 @@
|
|||||||
/* ioapi_mem.h -- IO base function header for compress/uncompress .zip
|
|
||||||
files using zlib + zip or unzip API
|
|
||||||
|
|
||||||
This version of ioapi is designed to access memory rather than files.
|
|
||||||
We do use a region of memory to put data in to and take it out of. We do
|
|
||||||
not have auto-extending buffers and do not inform anyone else that the
|
|
||||||
data has been written. It is really intended for accessing a zip archive
|
|
||||||
embedded in an application such that I can write an installer with no
|
|
||||||
external files. Creation of archives has not been attempted, although
|
|
||||||
parts of the framework are present.
|
|
||||||
|
|
||||||
Based on Unzip ioapi.c version 0.22, May 19th, 2003
|
|
||||||
|
|
||||||
Copyright (C) 1998-2003 Gilles Vollant
|
|
||||||
(C) 2003 Justin Fletcher
|
|
||||||
|
|
||||||
This file is under the same license as the Unzip tool it is distributed
|
|
||||||
with.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//taken and adapted from https://stackoverflow.com/a/13492589
|
|
||||||
|
|
||||||
// save diagnostic state
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
|
|
||||||
// turn off the specific warning. Can also use "-Wall"
|
|
||||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "zlib.h"
|
|
||||||
#include "ioapi.h"
|
|
||||||
|
|
||||||
#include "ioapi_mem.h"
|
|
||||||
|
|
||||||
#ifndef IOMEM_BUFFERSIZE
|
|
||||||
# define IOMEM_BUFFERSIZE (64 * 1024)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
voidpf ZCALLBACK fopen_mem_func (opaque, filename, mode)
|
|
||||||
voidpf opaque;
|
|
||||||
const char* filename;
|
|
||||||
int mode;
|
|
||||||
{
|
|
||||||
ourmemory_t *mem = (ourmemory_t *)opaque;
|
|
||||||
if (mem == NULL)
|
|
||||||
return NULL; /* Mem structure passed in was null */
|
|
||||||
|
|
||||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
|
||||||
{
|
|
||||||
if (mem->grow)
|
|
||||||
{
|
|
||||||
mem->size = IOMEM_BUFFERSIZE;
|
|
||||||
mem->base = (char *)malloc(mem->size);
|
|
||||||
}
|
|
||||||
|
|
||||||
mem->limit = 0; /* When writing we start with 0 bytes written */
|
|
||||||
}
|
|
||||||
else
|
|
||||||
mem->limit = mem->size;
|
|
||||||
|
|
||||||
mem->cur_offset = 0;
|
|
||||||
|
|
||||||
return mem;
|
|
||||||
}
|
|
||||||
|
|
||||||
voidpf ZCALLBACK fopendisk_mem_func (opaque, stream, number_disk, mode)
|
|
||||||
voidpf opaque;
|
|
||||||
voidpf stream;
|
|
||||||
int number_disk;
|
|
||||||
int mode;
|
|
||||||
{
|
|
||||||
/* Not used */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
uLong ZCALLBACK fread_mem_func (opaque, stream, buf, size)
|
|
||||||
voidpf opaque;
|
|
||||||
voidpf stream;
|
|
||||||
void* buf;
|
|
||||||
uLong size;
|
|
||||||
{
|
|
||||||
ourmemory_t *mem = (ourmemory_t *)stream;
|
|
||||||
|
|
||||||
if (size > mem->size - mem->cur_offset)
|
|
||||||
size = mem->size - mem->cur_offset;
|
|
||||||
|
|
||||||
memcpy(buf, mem->base + mem->cur_offset, size);
|
|
||||||
mem->cur_offset += size;
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uLong ZCALLBACK fwrite_mem_func (opaque, stream, buf, size)
|
|
||||||
voidpf opaque;
|
|
||||||
voidpf stream;
|
|
||||||
const void* buf;
|
|
||||||
uLong size;
|
|
||||||
{
|
|
||||||
ourmemory_t *mem = (ourmemory_t *)stream;
|
|
||||||
char *newbase = NULL;
|
|
||||||
uLong newmemsize = 0;
|
|
||||||
|
|
||||||
if (size > mem->size - mem->cur_offset)
|
|
||||||
{
|
|
||||||
if (mem->grow)
|
|
||||||
{
|
|
||||||
newmemsize = mem->size;
|
|
||||||
if (size < IOMEM_BUFFERSIZE)
|
|
||||||
newmemsize += IOMEM_BUFFERSIZE;
|
|
||||||
else
|
|
||||||
newmemsize += size;
|
|
||||||
newbase = (char *)malloc(newmemsize);
|
|
||||||
memcpy(newbase, mem->base, mem->size);
|
|
||||||
free(mem->base);
|
|
||||||
mem->base = newbase;
|
|
||||||
mem->size = newmemsize;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
size = mem->size - mem->cur_offset;
|
|
||||||
}
|
|
||||||
memcpy(mem->base + mem->cur_offset, buf, size);
|
|
||||||
mem->cur_offset += size;
|
|
||||||
if (mem->cur_offset > mem->limit)
|
|
||||||
mem->limit = mem->cur_offset;
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
long ZCALLBACK ftell_mem_func (opaque, stream)
|
|
||||||
voidpf opaque;
|
|
||||||
voidpf stream;
|
|
||||||
{
|
|
||||||
ourmemory_t *mem = (ourmemory_t *)stream;
|
|
||||||
return mem->cur_offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
long ZCALLBACK fseek_mem_func (opaque, stream, offset, origin)
|
|
||||||
voidpf opaque;
|
|
||||||
voidpf stream;
|
|
||||||
uLong offset;
|
|
||||||
int origin;
|
|
||||||
{
|
|
||||||
ourmemory_t *mem = (ourmemory_t *)stream;
|
|
||||||
uLong new_pos;
|
|
||||||
switch (origin)
|
|
||||||
{
|
|
||||||
case ZLIB_FILEFUNC_SEEK_CUR:
|
|
||||||
new_pos = mem->cur_offset + offset;
|
|
||||||
break;
|
|
||||||
case ZLIB_FILEFUNC_SEEK_END:
|
|
||||||
new_pos = mem->limit + offset;
|
|
||||||
break;
|
|
||||||
case ZLIB_FILEFUNC_SEEK_SET:
|
|
||||||
new_pos = offset;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_pos > mem->size)
|
|
||||||
return 1; /* Failed to seek that far */
|
|
||||||
mem->cur_offset = new_pos;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ZCALLBACK fclose_mem_func (opaque, stream)
|
|
||||||
voidpf opaque;
|
|
||||||
voidpf stream;
|
|
||||||
{
|
|
||||||
/* Even with grow = 1, caller must always free() memory */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ZCALLBACK ferror_mem_func (opaque, stream)
|
|
||||||
voidpf opaque;
|
|
||||||
voidpf stream;
|
|
||||||
{
|
|
||||||
/* We never return errors */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fill_memory_filefunc (pzlib_filefunc_def, ourmem)
|
|
||||||
zlib_filefunc_def* pzlib_filefunc_def;
|
|
||||||
ourmemory_t *ourmem;
|
|
||||||
{
|
|
||||||
pzlib_filefunc_def->zopen_file = fopen_mem_func;
|
|
||||||
pzlib_filefunc_def->zopendisk_file = fopendisk_mem_func;
|
|
||||||
pzlib_filefunc_def->zread_file = fread_mem_func;
|
|
||||||
pzlib_filefunc_def->zwrite_file = fwrite_mem_func;
|
|
||||||
pzlib_filefunc_def->ztell_file = ftell_mem_func;
|
|
||||||
pzlib_filefunc_def->zseek_file = fseek_mem_func;
|
|
||||||
pzlib_filefunc_def->zclose_file = fclose_mem_func;
|
|
||||||
pzlib_filefunc_def->zerror_file = ferror_mem_func;
|
|
||||||
pzlib_filefunc_def->opaque = ourmem;
|
|
||||||
}
|
|
||||||
|
|
||||||
// turn the warnings back on
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
/* ioapi_mem.h -- IO base function header for compress/uncompress .zip
|
|
||||||
files using zlib + zip or unzip API
|
|
||||||
|
|
||||||
This version of ioapi is designed to access memory rather than files.
|
|
||||||
We do use a region of memory to put data in to and take it out of.
|
|
||||||
|
|
||||||
Copyright (C) 1998-2003 Gilles Vollant
|
|
||||||
(C) 2003 Justin Fletcher
|
|
||||||
|
|
||||||
This program is distributed under the terms of the same license as zlib.
|
|
||||||
See the accompanying LICENSE file for the full text of the license.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _IOAPI_MEM_H
|
|
||||||
#define _IOAPI_MEM_H
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "zlib.h"
|
|
||||||
#include "ioapi.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
voidpf ZCALLBACK fopen_mem_func OF((voidpf opaque,const char* filename,int mode));
|
|
||||||
voidpf ZCALLBACK fopendisk_mem_func OF((voidpf opaque, voidpf stream, int number_disk, int mode));
|
|
||||||
uLong ZCALLBACK fread_mem_func OF((voidpf opaque,voidpf stream,void* buf,uLong size));
|
|
||||||
uLong ZCALLBACK fwrite_mem_func OF((voidpf opaque,voidpf stream,const void* buf,uLong size));
|
|
||||||
long ZCALLBACK ftell_mem_func OF((voidpf opaque,voidpf stream));
|
|
||||||
long ZCALLBACK fseek_mem_func OF((voidpf opaque,voidpf stream,uLong offset,int origin));
|
|
||||||
int ZCALLBACK fclose_mem_func OF((voidpf opaque,voidpf stream));
|
|
||||||
int ZCALLBACK ferror_mem_func OF((voidpf opaque,voidpf stream));
|
|
||||||
|
|
||||||
typedef struct ourmemory_s {
|
|
||||||
char *base; /* Base of the region of memory we're using */
|
|
||||||
uLong size; /* Size of the region of memory we're using */
|
|
||||||
uLong limit; /* Furthest we've written */
|
|
||||||
uLong cur_offset; /* Current offset in the area */
|
|
||||||
int grow; /* Growable memory buffer */
|
|
||||||
} ourmemory_t;
|
|
||||||
|
|
||||||
void fill_memory_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def, ourmemory_t *ourmem));
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,320 +0,0 @@
|
|||||||
/* unzip.h -- IO for uncompress .zip files using zlib
|
|
||||||
Version 1.1, February 14h, 2010
|
|
||||||
part of the MiniZip project
|
|
||||||
|
|
||||||
Copyright (C) 1998-2010 Gilles Vollant
|
|
||||||
http://www.winimage.com/zLibDll/minizip.html
|
|
||||||
Modifications of Unzip for Zip64
|
|
||||||
Copyright (C) 2007-2008 Even Rouault
|
|
||||||
Modifications for Zip64 support on both zip and unzip
|
|
||||||
Copyright (C) 2009-2010 Mathias Svensson
|
|
||||||
http://result42.com
|
|
||||||
|
|
||||||
This program is distributed under the terms of the same license as zlib.
|
|
||||||
See the accompanying LICENSE file for the full text of the license.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _UNZ_H
|
|
||||||
#define _UNZ_H
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _ZLIB_H
|
|
||||||
#include <zlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _ZLIBIOAPI_H
|
|
||||||
#include "ioapi.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_BZIP2
|
|
||||||
#include "bzlib.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define Z_BZIP2ED 12
|
|
||||||
|
|
||||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
|
||||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
|
||||||
from (void*) without cast */
|
|
||||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
|
||||||
typedef unzFile__ *unzFile;
|
|
||||||
#else
|
|
||||||
typedef voidp unzFile;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define UNZ_OK (0)
|
|
||||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
|
||||||
#define UNZ_ERRNO (Z_ERRNO)
|
|
||||||
#define UNZ_EOF (0)
|
|
||||||
#define UNZ_PARAMERROR (-102)
|
|
||||||
#define UNZ_BADZIPFILE (-103)
|
|
||||||
#define UNZ_INTERNALERROR (-104)
|
|
||||||
#define UNZ_CRCERROR (-105)
|
|
||||||
|
|
||||||
/* tm_unz contain date/time info */
|
|
||||||
typedef struct tm_unz_s
|
|
||||||
{
|
|
||||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
|
||||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
|
||||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
|
||||||
uInt tm_mday; /* day of the month - [1,31] */
|
|
||||||
uInt tm_mon; /* months since January - [0,11] */
|
|
||||||
uInt tm_year; /* years - [1980..2044] */
|
|
||||||
} tm_unz;
|
|
||||||
|
|
||||||
/* unz_global_info structure contain global data about the ZIPfile
|
|
||||||
These data comes from the end of central dir */
|
|
||||||
typedef struct unz_global_info64_s
|
|
||||||
{
|
|
||||||
ZPOS64_T number_entry; /* total number of entries in the central dir on this disk */
|
|
||||||
uLong number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/
|
|
||||||
uLong size_comment; /* size of the global comment of the zipfile */
|
|
||||||
} unz_global_info64;
|
|
||||||
|
|
||||||
typedef struct unz_global_info_s
|
|
||||||
{
|
|
||||||
uLong number_entry; /* total number of entries in the central dir on this disk */
|
|
||||||
uLong number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/
|
|
||||||
uLong size_comment; /* size of the global comment of the zipfile */
|
|
||||||
} unz_global_info;
|
|
||||||
|
|
||||||
/* unz_file_info contain information about a file in the zipfile */
|
|
||||||
typedef struct unz_file_info64_s
|
|
||||||
{
|
|
||||||
uLong version; /* version made by 2 bytes */
|
|
||||||
uLong version_needed; /* version needed to extract 2 bytes */
|
|
||||||
uLong flag; /* general purpose bit flag 2 bytes */
|
|
||||||
uLong compression_method; /* compression method 2 bytes */
|
|
||||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
|
||||||
uLong crc; /* crc-32 4 bytes */
|
|
||||||
ZPOS64_T compressed_size; /* compressed size 8 bytes */
|
|
||||||
ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
|
|
||||||
uLong size_filename; /* filename length 2 bytes */
|
|
||||||
uLong size_file_extra; /* extra field length 2 bytes */
|
|
||||||
uLong size_file_comment; /* file comment length 2 bytes */
|
|
||||||
|
|
||||||
uLong disk_num_start; /* disk number start 2 bytes */
|
|
||||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
|
||||||
uLong external_fa; /* external file attributes 4 bytes */
|
|
||||||
|
|
||||||
tm_unz tmu_date;
|
|
||||||
ZPOS64_T disk_offset;
|
|
||||||
uLong size_file_extra_internal;
|
|
||||||
} unz_file_info64;
|
|
||||||
|
|
||||||
typedef struct unz_file_info_s
|
|
||||||
{
|
|
||||||
uLong version; /* version made by 2 bytes */
|
|
||||||
uLong version_needed; /* version needed to extract 2 bytes */
|
|
||||||
uLong flag; /* general purpose bit flag 2 bytes */
|
|
||||||
uLong compression_method; /* compression method 2 bytes */
|
|
||||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
|
||||||
uLong crc; /* crc-32 4 bytes */
|
|
||||||
uLong compressed_size; /* compressed size 4 bytes */
|
|
||||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
|
||||||
uLong size_filename; /* filename length 2 bytes */
|
|
||||||
uLong size_file_extra; /* extra field length 2 bytes */
|
|
||||||
uLong size_file_comment; /* file comment length 2 bytes */
|
|
||||||
|
|
||||||
uLong disk_num_start; /* disk number start 2 bytes */
|
|
||||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
|
||||||
uLong external_fa; /* external file attributes 4 bytes */
|
|
||||||
|
|
||||||
tm_unz tmu_date;
|
|
||||||
uLong disk_offset;
|
|
||||||
} unz_file_info;
|
|
||||||
|
|
||||||
/***************************************************************************/
|
|
||||||
/* Opening and close a zip file */
|
|
||||||
|
|
||||||
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
|
||||||
extern unzFile ZEXPORT unzOpen64 OF((const void *path));
|
|
||||||
/* Open a Zip file.
|
|
||||||
|
|
||||||
path should contain the full pathname (by example, on a Windows XP computer
|
|
||||||
"c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip".
|
|
||||||
return NULL if zipfile cannot be opened or doesn't exist
|
|
||||||
return unzFile handle if no error
|
|
||||||
|
|
||||||
NOTE: The "64" function take a const void* pointer, because the path is just the value passed to the
|
|
||||||
open64_file_func callback. Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
|
|
||||||
is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* does not describe the reality */
|
|
||||||
|
|
||||||
extern unzFile ZEXPORT unzOpen2 OF((const char *path, zlib_filefunc_def* pzlib_filefunc_def));
|
|
||||||
/* Open a Zip file, like unzOpen, but provide a set of file low level API for read/write operations */
|
|
||||||
extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, zlib_filefunc64_def* pzlib_filefunc_def));
|
|
||||||
/* Open a Zip file, like unz64Open, but provide a set of file low level API for read/write 64-bit operations */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzClose OF((unzFile file));
|
|
||||||
/* Close a ZipFile opened with unzOpen. If there is files inside the .Zip opened with unzOpenCurrentFile,
|
|
||||||
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
|
||||||
|
|
||||||
return UNZ_OK if there is no error */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, unz_global_info *pglobal_info));
|
|
||||||
extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, unz_global_info64 *pglobal_info));
|
|
||||||
/* Write info about the ZipFile in the *pglobal_info structure.
|
|
||||||
|
|
||||||
return UNZ_OK if no error */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file, char *comment, uLong comment_size));
|
|
||||||
/* Get the global comment string of the ZipFile, in the comment buffer.
|
|
||||||
|
|
||||||
uSizeBuf is the size of the szComment buffer.
|
|
||||||
return the number of byte copied or an error code <0 */
|
|
||||||
|
|
||||||
/***************************************************************************/
|
|
||||||
/* Reading the content of the current zipfile, you can open it, read data from it, and close it
|
|
||||||
(you can close it before reading all the file) */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
|
||||||
/* Open for reading data the current file in the zipfile.
|
|
||||||
|
|
||||||
return UNZ_OK if no error */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, const char* password));
|
|
||||||
/* Open for reading data the current file in the zipfile.
|
|
||||||
password is a crypting password
|
|
||||||
|
|
||||||
return UNZ_OK if no error */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, int* method, int* level, int raw));
|
|
||||||
/* Same as unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
|
||||||
if raw==1 *method will receive method of compression, *level will receive level of compression
|
|
||||||
|
|
||||||
NOTE: you can set level parameter as NULL (if you did not want known level,
|
|
||||||
but you CANNOT set method parameter as NULL */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, int* method, int* level, int raw, const char* password));
|
|
||||||
/* Same as unzOpenCurrentFile, but takes extra parameter password for encrypted files */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file, voidp buf, unsigned len));
|
|
||||||
/* Read bytes from the current file (opened by unzOpenCurrentFile)
|
|
||||||
buf contain buffer where data must be copied
|
|
||||||
len the size of buf.
|
|
||||||
|
|
||||||
return the number of byte copied if somes bytes are copied
|
|
||||||
return 0 if the end of file was reached
|
|
||||||
return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, unz_file_info *pfile_info, char *filename,
|
|
||||||
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size));
|
|
||||||
extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, unz_file_info64 *pfile_info, char *filename,
|
|
||||||
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size));
|
|
||||||
/* Get Info about the current file
|
|
||||||
|
|
||||||
pfile_info if != NULL, the *pfile_info structure will contain somes info about the current file
|
|
||||||
filename if != NULL, the file name string will be copied in filename
|
|
||||||
filename_size is the size of the filename buffer
|
|
||||||
extrafield if != NULL, the extra field information from the central header will be copied in to
|
|
||||||
extrafield_size is the size of the extraField buffer
|
|
||||||
comment if != NULL, the comment string of the file will be copied in to
|
|
||||||
comment_size is the size of the comment buffer */
|
|
||||||
|
|
||||||
extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, voidp buf, unsigned len));
|
|
||||||
/* Read extra field from the current file (opened by unzOpenCurrentFile)
|
|
||||||
This is the local-header version of the extra field (sometimes, there is
|
|
||||||
more info in the local-header version than in the central-header)
|
|
||||||
|
|
||||||
if buf == NULL, it return the size of the local extra field
|
|
||||||
if buf != NULL, len is the size of the buffer, the extra header is copied in buf.
|
|
||||||
|
|
||||||
return number of bytes copied in buf, or (if <0) the error code */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
|
||||||
/* Close the file in zip opened with unzOpenCurrentFile
|
|
||||||
|
|
||||||
return UNZ_CRCERROR if all the file was read but the CRC is not good */
|
|
||||||
|
|
||||||
/***************************************************************************/
|
|
||||||
/* Browse the directory of the zipfile */
|
|
||||||
|
|
||||||
typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2);
|
|
||||||
typedef int (*unzIteratorFunction)(unzFile file);
|
|
||||||
typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename,
|
|
||||||
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size);
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
|
||||||
/* Set the current file of the zipfile to the first file.
|
|
||||||
|
|
||||||
return UNZ_OK if no error */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGoToFirstFile2 OF((unzFile file, unz_file_info64 *pfile_info, char *filename,
|
|
||||||
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size));
|
|
||||||
/* Set the current file of the zipfile to the first file and retrieves the current info on success.
|
|
||||||
Not as seek intensive as unzGoToFirstFile + unzGetCurrentFileInfo.
|
|
||||||
|
|
||||||
return UNZ_OK if no error */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
|
||||||
/* Set the current file of the zipfile to the next file.
|
|
||||||
|
|
||||||
return UNZ_OK if no error
|
|
||||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGoToNextFile2 OF((unzFile file, unz_file_info64 *pfile_info, char *filename,
|
|
||||||
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size));
|
|
||||||
/* Set the current file of the zipfile to the next file and retrieves the current
|
|
||||||
info on success. Does less seeking around than unzGotoNextFile + unzGetCurrentFileInfo.
|
|
||||||
|
|
||||||
return UNZ_OK if no error
|
|
||||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzLocateFile OF((unzFile file, const char *filename, unzFileNameComparer filename_compare_func));
|
|
||||||
/* Try locate the file szFileName in the zipfile. For custom filename comparison pass in comparison function.
|
|
||||||
|
|
||||||
return UNZ_OK if the file is found (it becomes the current file)
|
|
||||||
return UNZ_END_OF_LIST_OF_FILE if the file is not found */
|
|
||||||
|
|
||||||
/***************************************************************************/
|
|
||||||
/* Raw access to zip file */
|
|
||||||
|
|
||||||
typedef struct unz_file_pos_s
|
|
||||||
{
|
|
||||||
uLong pos_in_zip_directory; /* offset in zip file directory */
|
|
||||||
uLong num_of_file; /* # of file */
|
|
||||||
} unz_file_pos;
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGetFilePos OF((unzFile file, unz_file_pos* file_pos));
|
|
||||||
extern int ZEXPORT unzGoToFilePos OF((unzFile file, unz_file_pos* file_pos));
|
|
||||||
|
|
||||||
typedef struct unz64_file_pos_s
|
|
||||||
{
|
|
||||||
ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
|
|
||||||
ZPOS64_T num_of_file; /* # of file */
|
|
||||||
} unz64_file_pos;
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGetFilePos64 OF((unzFile file, unz64_file_pos* file_pos));
|
|
||||||
extern int ZEXPORT unzGoToFilePos64 OF((unzFile file, const unz64_file_pos* file_pos));
|
|
||||||
|
|
||||||
extern uLong ZEXPORT unzGetOffset OF((unzFile file));
|
|
||||||
extern ZPOS64_T ZEXPORT unzGetOffset64 OF((unzFile file));
|
|
||||||
/* Get the current file offset */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzSetOffset OF((unzFile file, uLong pos));
|
|
||||||
extern int ZEXPORT unzSetOffset64 OF((unzFile file, ZPOS64_T pos));
|
|
||||||
/* Set the current file offset */
|
|
||||||
|
|
||||||
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
|
||||||
extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
|
|
||||||
/* return current position in uncompressed data */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzseek OF((unzFile file, z_off_t offset, int origin));
|
|
||||||
extern int ZEXPORT unzseek64 OF((unzFile file, ZPOS64_T offset, int origin));
|
|
||||||
/* Seek within the uncompressed data if compression method is storage */
|
|
||||||
|
|
||||||
extern int ZEXPORT unzeof OF((unzFile file));
|
|
||||||
/* return 1 if the end of file was reached, 0 elsewhere */
|
|
||||||
|
|
||||||
/***************************************************************************/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* _UNZ_H */
|
|
||||||
379
source/music.c
Normal file
@@ -0,0 +1,379 @@
|
|||||||
|
/*
|
||||||
|
* 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 "music.h"
|
||||||
|
#include "loading.h"
|
||||||
|
|
||||||
|
// BCSTM Player adapted from BCSTM-Player by tobid7
|
||||||
|
// https://github.com/NPI-D7/BCSTM-Player/blob/main/source/bcstm.hpp
|
||||||
|
|
||||||
|
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;
|
||||||
|
DEBUG("<update_audio> Audio Size: %ld\n", size);
|
||||||
|
if (audio->wave_buf[audio->buf_pos].status == NDSP_WBUF_DONE) // only run if the current selected buffer has already finished playing
|
||||||
|
{
|
||||||
|
DEBUG("<update_audio> Attempting ov_read\n");
|
||||||
|
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
|
||||||
|
DEBUG("<update_audio> ov_read successful\n");
|
||||||
|
|
||||||
|
if (read <= 0) // EoF or error
|
||||||
|
{
|
||||||
|
ov_clear(&audio->vf);
|
||||||
|
if (read == 0) // EoF
|
||||||
|
{
|
||||||
|
ov_open(fmemopen(audio->filebuf, audio->filesize, "rb"), &audio->vf, NULL, 0); // Reopen file. Don't need to reinit channel stuff since it's all the same as before
|
||||||
|
} else // Error :(
|
||||||
|
{
|
||||||
|
DEBUG("<update_audio> Vorbis play error: %ld\n", read);
|
||||||
|
ndspChnReset(0);
|
||||||
|
return MAKERESULT(RL_FATAL, RS_INVALIDARG, RM_APPLICATION, RD_NO_DATA);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
audio->data_read += read;
|
||||||
|
if (read == size) {
|
||||||
|
audio->data_read = 0;
|
||||||
|
ndspChnWaveBufAdd(0, &audio->wave_buf[audio->buf_pos]); // Add buffer to ndsp
|
||||||
|
audio->buf_pos = 1 - audio->buf_pos; // switch to other buffer to load and prepare it while the current one is playing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return MAKERESULT(RL_SUCCESS, RS_SUCCESS, RM_APPLICATION, RD_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void thread_audio_ogg(void * data) {
|
||||||
|
audio_ogg_s * audio = (audio_ogg_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) {
|
||||||
|
update_audio(audio);
|
||||||
|
}
|
||||||
|
for (u8 i = 0; i < audio->channel_count; ++i)
|
||||||
|
{
|
||||||
|
ndspChnWaveBufClear(audio->channel[i]);
|
||||||
|
ndspChnReset(audio->channel[i]);
|
||||||
|
audio->active_channels &= ~(1 << audio->channel[i]);
|
||||||
|
for (u8 j = 0; j < BUFFER_COUNT; ++j) {
|
||||||
|
linearFree(audio->buffer_data[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
*audio_ptr = NULL;
|
||||||
|
}
|
||||||
@@ -117,7 +117,7 @@ static const uint8_t gf256_log[256] = {
|
|||||||
0x74, 0xd6, 0xf4, 0xea, 0xa8, 0x50, 0x58, 0xaf
|
0x74, 0xd6, 0xf4, 0xea, 0xa8, 0x50, 0x58, 0xaf
|
||||||
};
|
};
|
||||||
|
|
||||||
const static struct galois_field gf256 = {
|
static const struct galois_field gf256 = {
|
||||||
.p = 255,
|
.p = 255,
|
||||||
.log = gf256_log,
|
.log = gf256_log,
|
||||||
.exp = gf256_exp
|
.exp = gf256_exp
|
||||||
@@ -576,10 +576,11 @@ static quirc_decode_error_t codestream_ecc(struct quirc_data *data,
|
|||||||
&quirc_version_db[data->version];
|
&quirc_version_db[data->version];
|
||||||
const struct quirc_rs_params *sb_ecc = &ver->ecc[data->ecc_level];
|
const struct quirc_rs_params *sb_ecc = &ver->ecc[data->ecc_level];
|
||||||
struct quirc_rs_params lb_ecc;
|
struct quirc_rs_params lb_ecc;
|
||||||
int bc = ver->data_bytes / sb_ecc->bs;
|
const int lb_count =
|
||||||
|
(ver->data_bytes - sb_ecc->bs * sb_ecc->ns) / (sb_ecc->bs + 1);
|
||||||
|
const int bc = lb_count + sb_ecc->ns;
|
||||||
|
const int ecc_offset = sb_ecc->dw * bc + lb_count;
|
||||||
int dst_offset = 0;
|
int dst_offset = 0;
|
||||||
int lb_count = ver->data_bytes - bc * sb_ecc->bs;
|
|
||||||
int small_dw_total = bc * sb_ecc->dw;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
memcpy(&lb_ecc, sb_ecc, sizeof(lb_ecc));
|
memcpy(&lb_ecc, sb_ecc, sizeof(lb_ecc));
|
||||||
@@ -588,22 +589,16 @@ static quirc_decode_error_t codestream_ecc(struct quirc_data *data,
|
|||||||
|
|
||||||
for (i = 0; i < bc; i++) {
|
for (i = 0; i < bc; i++) {
|
||||||
uint8_t *dst = ds->data + dst_offset;
|
uint8_t *dst = ds->data + dst_offset;
|
||||||
const struct quirc_rs_params *ecc = sb_ecc;
|
const struct quirc_rs_params *ecc =
|
||||||
|
(i < sb_ecc->ns) ? sb_ecc : &lb_ecc;
|
||||||
|
const int num_ec = ecc->bs - ecc->dw;
|
||||||
quirc_decode_error_t err;
|
quirc_decode_error_t err;
|
||||||
int j = 0;
|
int j;
|
||||||
int k;
|
|
||||||
|
|
||||||
for (k = 0; k < sb_ecc->dw; k++)
|
for (j = 0; j < ecc->dw; j++)
|
||||||
dst[j++] = ds->raw[k * bc + i];
|
dst[j] = ds->raw[j * bc + i];
|
||||||
|
for (j = 0; j < num_ec; j++)
|
||||||
if (i + lb_count >= bc) {
|
dst[ecc->dw + j] = ds->raw[ecc_offset + j * bc + i];
|
||||||
dst[j++] = ds->raw[small_dw_total + i - lb_count];
|
|
||||||
ecc = &lb_ecc;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (k = 0; k < sb_ecc->bs - sb_ecc->dw; k++)
|
|
||||||
dst[j++] = ds->raw[small_dw_total + lb_count + i +
|
|
||||||
k * bc];
|
|
||||||
|
|
||||||
err = correct_block(dst, ecc);
|
err = correct_block(dst, ecc);
|
||||||
if (err)
|
if (err)
|
||||||
@@ -729,10 +724,10 @@ static quirc_decode_error_t decode_alpha(struct quirc_data *data,
|
|||||||
int bits = 13;
|
int bits = 13;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
if (data->version < 7)
|
if (data->version < 10)
|
||||||
bits = 9;
|
bits = 9;
|
||||||
else if (data->version < 11)
|
else if (data->version < 27)
|
||||||
bits = 10;
|
bits = 11;
|
||||||
|
|
||||||
count = take_bits(ds, bits);
|
count = take_bits(ds, bits);
|
||||||
if (data->payload_len + count + 1 > QUIRC_MAX_PAYLOAD)
|
if (data->payload_len + count + 1 > QUIRC_MAX_PAYLOAD)
|
||||||
@@ -795,12 +790,18 @@ static quirc_decode_error_t decode_kanji(struct quirc_data *data,
|
|||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
int d = take_bits(ds, 13);
|
int d = take_bits(ds, 13);
|
||||||
|
int msB = d / 0xc0;
|
||||||
|
int lsB = d % 0xc0;
|
||||||
|
int intermediate = (msB << 8) | lsB;
|
||||||
uint16_t sjw;
|
uint16_t sjw;
|
||||||
|
|
||||||
if (d + 0x8140 >= 0x9ffc)
|
if (intermediate + 0x8140 <= 0x9ffc) {
|
||||||
sjw = d + 0x8140;
|
/* bytes are in the range 0x8140 to 0x9FFC */
|
||||||
else
|
sjw = intermediate + 0x8140;
|
||||||
sjw = d + 0xc140;
|
} else {
|
||||||
|
/* bytes are in the range 0xE040 to 0xEBBF */
|
||||||
|
sjw = intermediate + 0xc140;
|
||||||
|
}
|
||||||
|
|
||||||
data->payload[data->payload_len++] = sjw >> 8;
|
data->payload[data->payload_len++] = sjw >> 8;
|
||||||
data->payload[data->payload_len++] = sjw & 0xff;
|
data->payload[data->payload_len++] = sjw & 0xff;
|
||||||
@@ -873,7 +874,7 @@ static quirc_decode_error_t decode_payload(struct quirc_data *data,
|
|||||||
done:
|
done:
|
||||||
|
|
||||||
/* Add nul terminator to all payloads */
|
/* Add nul terminator to all payloads */
|
||||||
if (data->payload_len >= sizeof(data->payload))
|
if (data->payload_len >= (int) sizeof(data->payload))
|
||||||
data->payload_len--;
|
data->payload_len--;
|
||||||
data->payload[data->payload_len] = 0;
|
data->payload[data->payload_len] = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -98,8 +99,8 @@ static void perspective_map(const double *c,
|
|||||||
double x = (c[0]*u + c[1]*v + c[2]) / den;
|
double x = (c[0]*u + c[1]*v + c[2]) / den;
|
||||||
double y = (c[3]*u + c[4]*v + c[5]) / den;
|
double y = (c[3]*u + c[4]*v + c[5]) / den;
|
||||||
|
|
||||||
ret->x = rint(x);
|
ret->x = (int) rint(x);
|
||||||
ret->y = rint(y);
|
ret->y = (int) rint(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void perspective_unmap(const double *c,
|
static void perspective_unmap(const double *c,
|
||||||
@@ -121,233 +122,113 @@ static void perspective_unmap(const double *c,
|
|||||||
* Span-based floodfill routine
|
* Span-based floodfill routine
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define FLOOD_FILL_MAX_DEPTH 128
|
||||||
|
|
||||||
typedef void (*span_func_t)(void *user_data, int y, int left, int right);
|
typedef void (*span_func_t)(void *user_data, int y, int left, int right);
|
||||||
|
|
||||||
#if 0 // recursive flood fill
|
static void flood_fill_seed(struct quirc *q, int x, int y, int from, int to,
|
||||||
|
span_func_t func, void *user_data,
|
||||||
#define FLOOD_FILL_MAX_DEPTH 4096
|
int depth)
|
||||||
|
|
||||||
struct flood_fill_params{
|
|
||||||
struct quirc *q;
|
|
||||||
int from;
|
|
||||||
int to;
|
|
||||||
span_func_t func;
|
|
||||||
void *user_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct flood_fill_params ffp;
|
|
||||||
|
|
||||||
static void flood_fill_rec(int x, int y, int depth)
|
|
||||||
{
|
{
|
||||||
int left = x;
|
int left = x;
|
||||||
int right = x;
|
int right = x;
|
||||||
int i;
|
int i;
|
||||||
quirc_pixel_t *row = ffp.q->pixels + y * ffp.q->w;
|
quirc_pixel_t *row = q->pixels + y * q->w;
|
||||||
|
|
||||||
if (!depth)
|
if (depth >= FLOOD_FILL_MAX_DEPTH)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (left > 0 && row[left - 1] == ffp.from)
|
while (left > 0 && row[left - 1] == from)
|
||||||
left--;
|
left--;
|
||||||
|
|
||||||
while (right < ffp.q->w - 1 && row[right + 1] == ffp.from)
|
while (right < q->w - 1 && row[right + 1] == from)
|
||||||
right++;
|
right++;
|
||||||
|
|
||||||
/* Fill the extent */
|
/* Fill the extent */
|
||||||
for (i = left; i <= right; i++)
|
for (i = left; i <= right; i++)
|
||||||
row[i] = ffp.to;
|
row[i] = to;
|
||||||
|
|
||||||
if (ffp.func)
|
if (func)
|
||||||
ffp.func(ffp.user_data, y, left, right);
|
func(user_data, y, left, right);
|
||||||
|
|
||||||
/* Seed new flood-fills */
|
/* Seed new flood-fills */
|
||||||
if (y > 0) {
|
if (y > 0) {
|
||||||
row = ffp.q->pixels + (y - 1) * ffp.q->w;
|
row = q->pixels + (y - 1) * q->w;
|
||||||
|
|
||||||
for (i = left; i <= right; i++)
|
for (i = left; i <= right; i++)
|
||||||
if (row[i] == ffp.from)
|
if (row[i] == from)
|
||||||
flood_fill_rec(i, y - 1, depth - 1);
|
flood_fill_seed(q, i, y - 1, from, to,
|
||||||
|
func, user_data, depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y < ffp.q->h - 1) {
|
if (y < q->h - 1) {
|
||||||
row = ffp.q->pixels + (y + 1) * ffp.q->w;
|
row = q->pixels + (y + 1) * q->w;
|
||||||
|
|
||||||
for (i = left; i <= right; i++)
|
for (i = left; i <= right; i++)
|
||||||
if (row[i] == ffp.from)
|
if (row[i] == from)
|
||||||
flood_fill_rec(i, y + 1, depth - 1);
|
flood_fill_seed(q, i, y + 1, from, to,
|
||||||
|
func, user_data, depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flood_fill_seed(struct quirc *q, int x, int y, int from, int to,
|
|
||||||
span_func_t func, void *user_data)
|
|
||||||
{
|
|
||||||
ffp.q = q;
|
|
||||||
ffp.from = from;
|
|
||||||
ffp.to = to;
|
|
||||||
ffp.func = func;
|
|
||||||
ffp.user_data = user_data;
|
|
||||||
|
|
||||||
flood_fill_rec(x, y, FLOOD_FILL_MAX_DEPTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else // stacked flood fill
|
|
||||||
|
|
||||||
#define FILL_STACK_CHUNK_SIZE 0x400
|
|
||||||
|
|
||||||
struct fill_stack_chunk{
|
|
||||||
int x[FILL_STACK_CHUNK_SIZE];
|
|
||||||
int y[FILL_STACK_CHUNK_SIZE];
|
|
||||||
struct fill_stack_chunk *prev;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct fill_stack{
|
|
||||||
struct fill_stack_chunk *last_chunk;
|
|
||||||
int index;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void fill_stack_init(struct fill_stack *s){
|
|
||||||
s->last_chunk = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int fill_stack_is_empty(struct fill_stack *s){
|
|
||||||
return s->last_chunk == NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fill_stack_push(struct fill_stack *s, int x, int y){
|
|
||||||
struct fill_stack_chunk *c;
|
|
||||||
if(s->last_chunk != NULL && s->index < FILL_STACK_CHUNK_SIZE - 1){
|
|
||||||
c = s->last_chunk;
|
|
||||||
s->index++;
|
|
||||||
}else{
|
|
||||||
c = (struct fill_stack_chunk*)malloc(sizeof(struct fill_stack_chunk));
|
|
||||||
if(c == NULL){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
c->prev = s->last_chunk;
|
|
||||||
s->last_chunk = c;
|
|
||||||
s->index = 0;
|
|
||||||
}
|
|
||||||
c->x[s->index] = x;
|
|
||||||
c->y[s->index] = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fill_stack_pop(struct fill_stack *s, int *px, int *py){
|
|
||||||
struct fill_stack_chunk *c = s->last_chunk;
|
|
||||||
if(c == NULL){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*px = c->x[s->index];
|
|
||||||
*py = c->y[s->index];
|
|
||||||
if(s->index > 0){
|
|
||||||
s->index--;
|
|
||||||
}else{
|
|
||||||
s->last_chunk = c->prev;
|
|
||||||
s->index = FILL_STACK_CHUNK_SIZE - 1;
|
|
||||||
free(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void flood_fill_seed(struct quirc *q, int start_x, int start_y, int from, int to,
|
|
||||||
span_func_t func, void *user_data)
|
|
||||||
{
|
|
||||||
struct fill_stack s;
|
|
||||||
fill_stack_init(&s);
|
|
||||||
fill_stack_push(&s, start_x, start_y);
|
|
||||||
|
|
||||||
do{
|
|
||||||
int x = 0, y = 0;
|
|
||||||
fill_stack_pop(&s, &x, &y);
|
|
||||||
|
|
||||||
int left = x, right = x, i;
|
|
||||||
quirc_pixel_t *row = q->pixels + y * q->w;
|
|
||||||
|
|
||||||
while (left > 0 && row[left - 1] == from)
|
|
||||||
left--;
|
|
||||||
|
|
||||||
while (right < q->w - 1 && row[right + 1] == from)
|
|
||||||
right++;
|
|
||||||
|
|
||||||
/* Fill the extent */
|
|
||||||
for (i = left; i <= right; i++)
|
|
||||||
row[i] = to;
|
|
||||||
|
|
||||||
if (func)
|
|
||||||
func(user_data, y, left, right);
|
|
||||||
|
|
||||||
/* Seed new flood-fills */
|
|
||||||
if (y > 0) {
|
|
||||||
row = q->pixels + (y - 1) * q->w;
|
|
||||||
|
|
||||||
for (i = left; i <= right; i++)
|
|
||||||
if (row[i] == from)
|
|
||||||
fill_stack_push(&s, i, y - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y < q->h - 1) {
|
|
||||||
row = q->pixels + (y + 1) * q->w;
|
|
||||||
|
|
||||||
for (i = left; i <= right; i++)
|
|
||||||
if (row[i] == from)
|
|
||||||
fill_stack_push(&s, i, y + 1);
|
|
||||||
}
|
|
||||||
}while(!fill_stack_is_empty(&s));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Adaptive thresholding
|
* Adaptive thresholding
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define THRESHOLD_S_DEN 8
|
static uint8_t otsu(const struct quirc *q)
|
||||||
#define THRESHOLD_T 5
|
|
||||||
|
|
||||||
static void threshold(struct quirc *q)
|
|
||||||
{
|
{
|
||||||
int x, y;
|
int numPixels = q->w * q->h;
|
||||||
int avg_w = 0;
|
|
||||||
int avg_u = 0;
|
|
||||||
int threshold_s = q->w / THRESHOLD_S_DEN;
|
|
||||||
quirc_pixel_t *row = q->pixels;
|
|
||||||
|
|
||||||
for (y = 0; y < q->h; y++) {
|
// Calculate histogram
|
||||||
int row_average[q->w];
|
const int HISTOGRAM_SIZE = 256;
|
||||||
|
unsigned int histogram[HISTOGRAM_SIZE];
|
||||||
memset(row_average, 0, sizeof(row_average));
|
memset(histogram, 0, (HISTOGRAM_SIZE) * sizeof(unsigned int));
|
||||||
|
uint8_t* ptr = q->image;
|
||||||
for (x = 0; x < q->w; x++) {
|
int length = numPixels;
|
||||||
int w, u;
|
while (length--) {
|
||||||
|
uint8_t value = *ptr++;
|
||||||
if (y & 1) {
|
histogram[value]++;
|
||||||
w = x;
|
|
||||||
u = q->w - 1 - x;
|
|
||||||
} else {
|
|
||||||
w = q->w - 1 - x;
|
|
||||||
u = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
avg_w = (avg_w * (threshold_s - 1)) /
|
|
||||||
threshold_s + row[w];
|
|
||||||
avg_u = (avg_u * (threshold_s - 1)) /
|
|
||||||
threshold_s + row[u];
|
|
||||||
|
|
||||||
row_average[w] += avg_w;
|
|
||||||
row_average[u] += avg_u;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (x = 0; x < q->w; x++) {
|
|
||||||
if (row[x] < row_average[x] *
|
|
||||||
(100 - THRESHOLD_T) / (200 * threshold_s))
|
|
||||||
row[x] = QUIRC_PIXEL_BLACK;
|
|
||||||
else
|
|
||||||
row[x] = QUIRC_PIXEL_WHITE;
|
|
||||||
}
|
|
||||||
|
|
||||||
row += q->w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate weighted sum of histogram values
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < HISTOGRAM_SIZE; ++i) {
|
||||||
|
sum += i * histogram[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute threshold
|
||||||
|
int sumB = 0;
|
||||||
|
int q1 = 0;
|
||||||
|
double max = 0;
|
||||||
|
uint8_t threshold = 0;
|
||||||
|
for (int i = 0; i < HISTOGRAM_SIZE; ++i) {
|
||||||
|
// Weighted background
|
||||||
|
q1 += histogram[i];
|
||||||
|
if (q1 == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Weighted foreground
|
||||||
|
const int q2 = numPixels - q1;
|
||||||
|
if (q2 == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
sumB += i * histogram[i];
|
||||||
|
const double m1 = (double)sumB / q1;
|
||||||
|
const double m2 = ((double)sum - sumB) / q2;
|
||||||
|
const double m1m2 = m1 - m2;
|
||||||
|
const double variance = m1m2 * m1m2 * q1 * q2;
|
||||||
|
if (variance >= max) {
|
||||||
|
threshold = i;
|
||||||
|
max = variance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void area_count(void *user_data, int y, int left, int right)
|
static void area_count(void *user_data, int y, int left, int right)
|
||||||
{
|
{
|
||||||
|
(void)y;
|
||||||
((struct quirc_region *)user_data)->count += right - left + 1;
|
((struct quirc_region *)user_data)->count += right - left + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +261,7 @@ static int region_code(struct quirc *q, int x, int y)
|
|||||||
box->seed.y = y;
|
box->seed.y = y;
|
||||||
box->capstone = -1;
|
box->capstone = -1;
|
||||||
|
|
||||||
flood_fill_seed(q, x, y, pixel, region, area_count, box);
|
flood_fill_seed(q, x, y, pixel, region, area_count, box, 0);
|
||||||
|
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
@@ -450,7 +331,7 @@ static void find_region_corners(struct quirc *q,
|
|||||||
psd.scores[0] = -1;
|
psd.scores[0] = -1;
|
||||||
flood_fill_seed(q, region->seed.x, region->seed.y,
|
flood_fill_seed(q, region->seed.x, region->seed.y,
|
||||||
rcode, QUIRC_PIXEL_BLACK,
|
rcode, QUIRC_PIXEL_BLACK,
|
||||||
find_one_corner, &psd);
|
find_one_corner, &psd, 0);
|
||||||
|
|
||||||
psd.ref.x = psd.corners[0].x - psd.ref.x;
|
psd.ref.x = psd.corners[0].x - psd.ref.x;
|
||||||
psd.ref.y = psd.corners[0].y - psd.ref.y;
|
psd.ref.y = psd.corners[0].y - psd.ref.y;
|
||||||
@@ -468,7 +349,7 @@ static void find_region_corners(struct quirc *q,
|
|||||||
|
|
||||||
flood_fill_seed(q, region->seed.x, region->seed.y,
|
flood_fill_seed(q, region->seed.x, region->seed.y,
|
||||||
QUIRC_PIXEL_BLACK, rcode,
|
QUIRC_PIXEL_BLACK, rcode,
|
||||||
find_other_corners, &psd);
|
find_other_corners, &psd, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void record_capstone(struct quirc *q, int ring, int stone)
|
static void record_capstone(struct quirc *q, int ring, int stone)
|
||||||
@@ -541,7 +422,7 @@ static void finder_scan(struct quirc *q, int y)
|
|||||||
{
|
{
|
||||||
quirc_pixel_t *row = q->pixels + y * q->w;
|
quirc_pixel_t *row = q->pixels + y * q->w;
|
||||||
int x;
|
int x;
|
||||||
int last_color;
|
int last_color = 0;
|
||||||
int run_length = 0;
|
int run_length = 0;
|
||||||
int run_count = 0;
|
int run_count = 0;
|
||||||
int pb[5];
|
int pb[5];
|
||||||
@@ -887,7 +768,7 @@ static int fitness_all(const struct quirc *q, int index)
|
|||||||
|
|
||||||
/* Check alignment patterns */
|
/* Check alignment patterns */
|
||||||
ap_count = 0;
|
ap_count = 0;
|
||||||
while (info->apat[ap_count])
|
while ((ap_count < QUIRC_MAX_ALIGNMENT) && info->apat[ap_count])
|
||||||
ap_count++;
|
ap_count++;
|
||||||
|
|
||||||
for (i = 1; i + 1 < ap_count; i++) {
|
for (i = 1; i + 1 < ap_count; i++) {
|
||||||
@@ -973,7 +854,7 @@ static void rotate_capstone(struct quirc_capstone *cap,
|
|||||||
struct quirc_point copy[4];
|
struct quirc_point copy[4];
|
||||||
int j;
|
int j;
|
||||||
int best = 0;
|
int best = 0;
|
||||||
int best_score = 0;
|
int best_score = INT_MAX;
|
||||||
|
|
||||||
for (j = 0; j < 4; j++) {
|
for (j = 0; j < 4; j++) {
|
||||||
struct quirc_point *p = &cap->corners[j];
|
struct quirc_point *p = &cap->corners[j];
|
||||||
@@ -1081,10 +962,10 @@ static void record_qr_grid(struct quirc *q, int a, int b, int c)
|
|||||||
|
|
||||||
flood_fill_seed(q, reg->seed.x, reg->seed.y,
|
flood_fill_seed(q, reg->seed.x, reg->seed.y,
|
||||||
qr->align_region, QUIRC_PIXEL_BLACK,
|
qr->align_region, QUIRC_PIXEL_BLACK,
|
||||||
NULL, NULL);
|
NULL, NULL, 0);
|
||||||
flood_fill_seed(q, reg->seed.x, reg->seed.y,
|
flood_fill_seed(q, reg->seed.x, reg->seed.y,
|
||||||
QUIRC_PIXEL_BLACK, qr->align_region,
|
QUIRC_PIXEL_BLACK, qr->align_region,
|
||||||
find_leftmost_to_line, &psd);
|
find_leftmost_to_line, &psd, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1190,17 +1071,18 @@ static void test_grouping(struct quirc *q, int i)
|
|||||||
test_neighbours(q, i, &hlist, &vlist);
|
test_neighbours(q, i, &hlist, &vlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pixels_setup(struct quirc *q)
|
static void pixels_setup(struct quirc *q, uint8_t threshold)
|
||||||
{
|
{
|
||||||
if (sizeof(*q->image) == sizeof(*q->pixels)) {
|
if (QUIRC_PIXEL_ALIAS_IMAGE) {
|
||||||
q->pixels = (quirc_pixel_t *)q->image;
|
q->pixels = (quirc_pixel_t *)q->image;
|
||||||
} else {
|
}
|
||||||
int x, y;
|
|
||||||
for (y = 0; y < q->h; y++) {
|
uint8_t* source = q->image;
|
||||||
for (x = 0; x < q->w; x++) {
|
quirc_pixel_t* dest = q->pixels;
|
||||||
q->pixels[y * q->w + x] = q->image[y * q->w + x];
|
int length = q->w * q->h;
|
||||||
}
|
while (length--) {
|
||||||
}
|
uint8_t value = *source++;
|
||||||
|
*dest++ = (value < threshold) ? QUIRC_PIXEL_BLACK : QUIRC_PIXEL_WHITE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1222,8 +1104,8 @@ void quirc_end(struct quirc *q)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
pixels_setup(q);
|
uint8_t threshold = otsu(q);
|
||||||
threshold(q);
|
pixels_setup(q, threshold);
|
||||||
|
|
||||||
for (i = 0; i < q->h; i++)
|
for (i = 0; i < q->h; i++)
|
||||||
finder_scan(q, i);
|
finder_scan(q, i);
|
||||||
|
|||||||
@@ -36,34 +36,73 @@ struct quirc *quirc_new(void)
|
|||||||
|
|
||||||
void quirc_destroy(struct quirc *q)
|
void quirc_destroy(struct quirc *q)
|
||||||
{
|
{
|
||||||
if (q->image)
|
free(q->image);
|
||||||
free(q->image);
|
/* q->pixels may alias q->image when their type representation is of the
|
||||||
if (sizeof(*q->image) != sizeof(*q->pixels))
|
same size, so we need to be careful here to avoid a double free */
|
||||||
|
if (!QUIRC_PIXEL_ALIAS_IMAGE)
|
||||||
free(q->pixels);
|
free(q->pixels);
|
||||||
|
|
||||||
free(q);
|
free(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
int quirc_resize(struct quirc *q, int w, int h)
|
int quirc_resize(struct quirc *q, int w, int h)
|
||||||
{
|
{
|
||||||
uint8_t *new_image = realloc(q->image, w * h);
|
uint8_t *image = NULL;
|
||||||
|
quirc_pixel_t *pixels = NULL;
|
||||||
|
|
||||||
if (!new_image)
|
/*
|
||||||
return -1;
|
* XXX: w and h should be size_t (or at least unsigned) as negatives
|
||||||
|
* values would not make much sense. The downside is that it would break
|
||||||
|
* both the API and ABI. Thus, at the moment, let's just do a sanity
|
||||||
|
* check.
|
||||||
|
*/
|
||||||
|
if (w < 0 || h < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
if (sizeof(*q->image) != sizeof(*q->pixels)) {
|
/*
|
||||||
size_t new_size = w * h * sizeof(quirc_pixel_t);
|
* alloc a new buffer for q->image. We avoid realloc(3) because we want
|
||||||
quirc_pixel_t *new_pixels = realloc(q->pixels, new_size);
|
* on failure to be leave `q` in a consistant, unmodified state.
|
||||||
if (!new_pixels)
|
*/
|
||||||
return -1;
|
image = calloc(w, h);
|
||||||
q->pixels = new_pixels;
|
if (!image)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
/* compute the "old" (i.e. currently allocated) and the "new"
|
||||||
|
(i.e. requested) image dimensions */
|
||||||
|
size_t olddim = q->w * q->h;
|
||||||
|
size_t newdim = w * h;
|
||||||
|
size_t min = (olddim < newdim ? olddim : newdim);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* copy the data into the new buffer, avoiding (a) to read beyond the
|
||||||
|
* old buffer when the new size is greater and (b) to write beyond the
|
||||||
|
* new buffer when the new size is smaller, hence the min computation.
|
||||||
|
*/
|
||||||
|
(void)memcpy(image, q->image, min);
|
||||||
|
|
||||||
|
/* alloc a new buffer for q->pixels if needed */
|
||||||
|
if (!QUIRC_PIXEL_ALIAS_IMAGE) {
|
||||||
|
pixels = calloc(newdim, sizeof(quirc_pixel_t));
|
||||||
|
if (!pixels)
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
q->image = new_image;
|
/* alloc succeeded, update `q` with the new size and buffers */
|
||||||
q->w = w;
|
q->w = w;
|
||||||
q->h = h;
|
q->h = h;
|
||||||
|
free(q->image);
|
||||||
|
q->image = image;
|
||||||
|
if (!QUIRC_PIXEL_ALIAS_IMAGE) {
|
||||||
|
free(q->pixels);
|
||||||
|
q->pixels = pixels;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
/* NOTREACHED */
|
||||||
|
fail:
|
||||||
|
free(image);
|
||||||
|
free(pixels);
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int quirc_count(const struct quirc *q)
|
int quirc_count(const struct quirc *q)
|
||||||
@@ -84,7 +123,7 @@ static const char *const error_table[] = {
|
|||||||
|
|
||||||
const char *quirc_strerror(quirc_decode_error_t err)
|
const char *quirc_strerror(quirc_decode_error_t err)
|
||||||
{
|
{
|
||||||
if (err >= 0 && err < sizeof(error_table) / sizeof(error_table[0]))
|
if (err < sizeof(error_table) / sizeof(error_table[0]))
|
||||||
return error_table[err];
|
return error_table[err];
|
||||||
|
|
||||||
return "Unknown error";
|
return "Unknown error";
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
struct quirc;
|
struct quirc;
|
||||||
|
|
||||||
/* Obtain the library version string. */
|
/* Obtain the library version string. */
|
||||||
@@ -117,7 +121,7 @@ struct quirc_code {
|
|||||||
* is a bitmask giving the actual values of cells. If the cell
|
* is a bitmask giving the actual values of cells. If the cell
|
||||||
* at (x, y) is black, then the following bit is set:
|
* at (x, y) is black, then the following bit is set:
|
||||||
*
|
*
|
||||||
* cell_bitmap[i << 3] & (1 << (i & 7))
|
* cell_bitmap[i >> 3] & (1 << (i & 7))
|
||||||
*
|
*
|
||||||
* where i = (y * size) + x.
|
* where i = (y * size) + x.
|
||||||
*/
|
*/
|
||||||
@@ -162,4 +166,8 @@ void quirc_extract(const struct quirc *q, int index,
|
|||||||
quirc_decode_error_t quirc_decode(const struct quirc_code *code,
|
quirc_decode_error_t quirc_decode(const struct quirc_code *code,
|
||||||
struct quirc_data *data);
|
struct quirc_data *data);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -32,8 +32,10 @@
|
|||||||
#define QUIRC_PERSPECTIVE_PARAMS 8
|
#define QUIRC_PERSPECTIVE_PARAMS 8
|
||||||
|
|
||||||
#if QUIRC_MAX_REGIONS < UINT8_MAX
|
#if QUIRC_MAX_REGIONS < UINT8_MAX
|
||||||
|
#define QUIRC_PIXEL_ALIAS_IMAGE 1
|
||||||
typedef uint8_t quirc_pixel_t;
|
typedef uint8_t quirc_pixel_t;
|
||||||
#elif QUIRC_MAX_REGIONS < UINT16_MAX
|
#elif QUIRC_MAX_REGIONS < UINT16_MAX
|
||||||
|
#define QUIRC_PIXEL_ALIAS_IMAGE 0
|
||||||
typedef uint16_t quirc_pixel_t;
|
typedef uint16_t quirc_pixel_t;
|
||||||
#else
|
#else
|
||||||
#error "QUIRC_MAX_REGIONS > 65534 is not supported"
|
#error "QUIRC_MAX_REGIONS > 65534 is not supported"
|
||||||
@@ -98,9 +100,9 @@ struct quirc {
|
|||||||
#define QUIRC_MAX_ALIGNMENT 7
|
#define QUIRC_MAX_ALIGNMENT 7
|
||||||
|
|
||||||
struct quirc_rs_params {
|
struct quirc_rs_params {
|
||||||
int bs; /* Block size */
|
int bs; /* Small block size */
|
||||||
int dw; /* Data words */
|
int dw; /* Small data words */
|
||||||
int ce; /* Correctable errors */
|
int ns; /* Number of small blocks */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct quirc_version_info {
|
struct quirc_version_info {
|
||||||
|
|||||||
@@ -22,400 +22,400 @@ const struct quirc_version_info quirc_version_db[QUIRC_MAX_VERSION + 1] = {
|
|||||||
.data_bytes = 26,
|
.data_bytes = 26,
|
||||||
.apat = {0},
|
.apat = {0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 26, .dw = 16, .ce = 4},
|
{.bs = 26, .dw = 16, .ns = 1},
|
||||||
{.bs = 26, .dw = 19, .ce = 2},
|
{.bs = 26, .dw = 19, .ns = 1},
|
||||||
{.bs = 26, .dw = 9, .ce = 8},
|
{.bs = 26, .dw = 9, .ns = 1},
|
||||||
{.bs = 26, .dw = 13, .ce = 6}
|
{.bs = 26, .dw = 13, .ns = 1}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 2 */
|
{ /* Version 2 */
|
||||||
.data_bytes = 44,
|
.data_bytes = 44,
|
||||||
.apat = {6, 18, 0},
|
.apat = {6, 18, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 44, .dw = 28, .ce = 8},
|
{.bs = 44, .dw = 28, .ns = 1},
|
||||||
{.bs = 44, .dw = 34, .ce = 4},
|
{.bs = 44, .dw = 34, .ns = 1},
|
||||||
{.bs = 44, .dw = 16, .ce = 14},
|
{.bs = 44, .dw = 16, .ns = 1},
|
||||||
{.bs = 44, .dw = 22, .ce = 11}
|
{.bs = 44, .dw = 22, .ns = 1}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 3 */
|
{ /* Version 3 */
|
||||||
.data_bytes = 70,
|
.data_bytes = 70,
|
||||||
.apat = {6, 22, 0},
|
.apat = {6, 22, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 70, .dw = 44, .ce = 13},
|
{.bs = 70, .dw = 44, .ns = 1},
|
||||||
{.bs = 70, .dw = 55, .ce = 7},
|
{.bs = 70, .dw = 55, .ns = 1},
|
||||||
{.bs = 35, .dw = 13, .ce = 11},
|
{.bs = 35, .dw = 13, .ns = 2},
|
||||||
{.bs = 35, .dw = 17, .ce = 9}
|
{.bs = 35, .dw = 17, .ns = 2}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 4 */
|
{ /* Version 4 */
|
||||||
.data_bytes = 100,
|
.data_bytes = 100,
|
||||||
.apat = {6, 26, 0},
|
.apat = {6, 26, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 50, .dw = 32, .ce = 9},
|
{.bs = 50, .dw = 32, .ns = 2},
|
||||||
{.bs = 100, .dw = 80, .ce = 10},
|
{.bs = 100, .dw = 80, .ns = 1},
|
||||||
{.bs = 25, .dw = 9, .ce = 8},
|
{.bs = 25, .dw = 9, .ns = 4},
|
||||||
{.bs = 50, .dw = 24, .ce = 13}
|
{.bs = 50, .dw = 24, .ns = 2}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 5 */
|
{ /* Version 5 */
|
||||||
.data_bytes = 134,
|
.data_bytes = 134,
|
||||||
.apat = {6, 30, 0},
|
.apat = {6, 30, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 67, .dw = 43, .ce = 12},
|
{.bs = 67, .dw = 43, .ns = 2},
|
||||||
{.bs = 134, .dw = 108, .ce = 13},
|
{.bs = 134, .dw = 108, .ns = 1},
|
||||||
{.bs = 33, .dw = 11, .ce = 11},
|
{.bs = 33, .dw = 11, .ns = 2},
|
||||||
{.bs = 33, .dw = 15, .ce = 9}
|
{.bs = 33, .dw = 15, .ns = 2}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 6 */
|
{ /* Version 6 */
|
||||||
.data_bytes = 172,
|
.data_bytes = 172,
|
||||||
.apat = {6, 34, 0},
|
.apat = {6, 34, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 43, .dw = 27, .ce = 8},
|
{.bs = 43, .dw = 27, .ns = 4},
|
||||||
{.bs = 86, .dw = 68, .ce = 9},
|
{.bs = 86, .dw = 68, .ns = 2},
|
||||||
{.bs = 43, .dw = 15, .ce = 14},
|
{.bs = 43, .dw = 15, .ns = 4},
|
||||||
{.bs = 43, .dw = 19, .ce = 12}
|
{.bs = 43, .dw = 19, .ns = 4}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 7 */
|
{ /* Version 7 */
|
||||||
.data_bytes = 196,
|
.data_bytes = 196,
|
||||||
.apat = {6, 22, 38, 0},
|
.apat = {6, 22, 38, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 49, .dw = 31, .ce = 9},
|
{.bs = 49, .dw = 31, .ns = 4},
|
||||||
{.bs = 98, .dw = 78, .ce = 10},
|
{.bs = 98, .dw = 78, .ns = 2},
|
||||||
{.bs = 39, .dw = 13, .ce = 13},
|
{.bs = 39, .dw = 13, .ns = 4},
|
||||||
{.bs = 32, .dw = 14, .ce = 9}
|
{.bs = 32, .dw = 14, .ns = 2}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 8 */
|
{ /* Version 8 */
|
||||||
.data_bytes = 242,
|
.data_bytes = 242,
|
||||||
.apat = {6, 24, 42, 0},
|
.apat = {6, 24, 42, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 60, .dw = 38, .ce = 11},
|
{.bs = 60, .dw = 38, .ns = 2},
|
||||||
{.bs = 121, .dw = 97, .ce = 12},
|
{.bs = 121, .dw = 97, .ns = 2},
|
||||||
{.bs = 40, .dw = 14, .ce = 13},
|
{.bs = 40, .dw = 14, .ns = 4},
|
||||||
{.bs = 40, .dw = 18, .ce = 11}
|
{.bs = 40, .dw = 18, .ns = 4}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 9 */
|
{ /* Version 9 */
|
||||||
.data_bytes = 292,
|
.data_bytes = 292,
|
||||||
.apat = {6, 26, 46, 0},
|
.apat = {6, 26, 46, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 58, .dw = 36, .ce = 11},
|
{.bs = 58, .dw = 36, .ns = 3},
|
||||||
{.bs = 146, .dw = 116, .ce = 15},
|
{.bs = 146, .dw = 116, .ns = 2},
|
||||||
{.bs = 36, .dw = 12, .ce = 12},
|
{.bs = 36, .dw = 12, .ns = 4},
|
||||||
{.bs = 36, .dw = 16, .ce = 10}
|
{.bs = 36, .dw = 16, .ns = 4}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 10 */
|
{ /* Version 10 */
|
||||||
.data_bytes = 346,
|
.data_bytes = 346,
|
||||||
.apat = {6, 28, 50, 0},
|
.apat = {6, 28, 50, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 69, .dw = 43, .ce = 13},
|
{.bs = 69, .dw = 43, .ns = 4},
|
||||||
{.bs = 86, .dw = 68, .ce = 9},
|
{.bs = 86, .dw = 68, .ns = 2},
|
||||||
{.bs = 43, .dw = 15, .ce = 14},
|
{.bs = 43, .dw = 15, .ns = 6},
|
||||||
{.bs = 43, .dw = 19, .ce = 12}
|
{.bs = 43, .dw = 19, .ns = 6}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 11 */
|
{ /* Version 11 */
|
||||||
.data_bytes = 404,
|
.data_bytes = 404,
|
||||||
.apat = {6, 30, 54, 0},
|
.apat = {6, 30, 54, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 80, .dw = 50, .ce = 15},
|
{.bs = 80, .dw = 50, .ns = 1},
|
||||||
{.bs = 101, .dw = 81, .ce = 10},
|
{.bs = 101, .dw = 81, .ns = 4},
|
||||||
{.bs = 36, .dw = 12, .ce = 12},
|
{.bs = 36, .dw = 12, .ns = 3},
|
||||||
{.bs = 50, .dw = 22, .ce = 14}
|
{.bs = 50, .dw = 22, .ns = 4}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 12 */
|
{ /* Version 12 */
|
||||||
.data_bytes = 466,
|
.data_bytes = 466,
|
||||||
.apat = {6, 32, 58, 0},
|
.apat = {6, 32, 58, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 58, .dw = 36, .ce = 11},
|
{.bs = 58, .dw = 36, .ns = 6},
|
||||||
{.bs = 116, .dw = 92, .ce = 12},
|
{.bs = 116, .dw = 92, .ns = 2},
|
||||||
{.bs = 42, .dw = 14, .ce = 14},
|
{.bs = 42, .dw = 14, .ns = 7},
|
||||||
{.bs = 46, .dw = 20, .ce = 14}
|
{.bs = 46, .dw = 20, .ns = 4}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 13 */
|
{ /* Version 13 */
|
||||||
.data_bytes = 532,
|
.data_bytes = 532,
|
||||||
.apat = {6, 34, 62, 0},
|
.apat = {6, 34, 62, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 59, .dw = 37, .ce = 11},
|
{.bs = 59, .dw = 37, .ns = 8},
|
||||||
{.bs = 133, .dw = 107, .ce = 13},
|
{.bs = 133, .dw = 107, .ns = 4},
|
||||||
{.bs = 33, .dw = 11, .ce = 11},
|
{.bs = 33, .dw = 11, .ns = 12},
|
||||||
{.bs = 44, .dw = 20, .ce = 12}
|
{.bs = 44, .dw = 20, .ns = 8}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 14 */
|
{ /* Version 14 */
|
||||||
.data_bytes = 581,
|
.data_bytes = 581,
|
||||||
.apat = {6, 26, 46, 66, 0},
|
.apat = {6, 26, 46, 66, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 65, .dw = 41, .ce = 12},
|
{.bs = 64, .dw = 40, .ns = 4},
|
||||||
{.bs = 109, .dw = 87, .ce = 11},
|
{.bs = 145, .dw = 115, .ns = 3},
|
||||||
{.bs = 36, .dw = 12, .ce = 12},
|
{.bs = 36, .dw = 12, .ns = 11},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 36, .dw = 16, .ns = 11}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 15 */
|
{ /* Version 15 */
|
||||||
.data_bytes = 655,
|
.data_bytes = 655,
|
||||||
.apat = {6, 26, 48, 70, 0},
|
.apat = {6, 26, 48, 70, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 65, .dw = 41, .ce = 12},
|
{.bs = 65, .dw = 41, .ns = 5},
|
||||||
{.bs = 109, .dw = 87, .ce = 11},
|
{.bs = 109, .dw = 87, .ns = 5},
|
||||||
{.bs = 36, .dw = 12, .ce = 12},
|
{.bs = 36, .dw = 12, .ns = 11},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 5}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 16 */
|
{ /* Version 16 */
|
||||||
.data_bytes = 733,
|
.data_bytes = 733,
|
||||||
.apat = {6, 26, 50, 74, 0},
|
.apat = {6, 26, 50, 74, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 73, .dw = 45, .ce = 14},
|
{.bs = 73, .dw = 45, .ns = 7},
|
||||||
{.bs = 122, .dw = 98, .ce = 12},
|
{.bs = 122, .dw = 98, .ns = 5},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 3},
|
||||||
{.bs = 43, .dw = 19, .ce = 12}
|
{.bs = 43, .dw = 19, .ns = 15}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 17 */
|
{ /* Version 17 */
|
||||||
.data_bytes = 815,
|
.data_bytes = 815,
|
||||||
.apat = {6, 30, 54, 78, 0},
|
.apat = {6, 30, 54, 78, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 74, .dw = 46, .ce = 14},
|
{.bs = 74, .dw = 46, .ns = 10},
|
||||||
{.bs = 135, .dw = 107, .ce = 14},
|
{.bs = 135, .dw = 107, .ns = 1},
|
||||||
{.bs = 42, .dw = 14, .ce = 14},
|
{.bs = 42, .dw = 14, .ns = 2},
|
||||||
{.bs = 50, .dw = 22, .ce = 14}
|
{.bs = 50, .dw = 22, .ns = 1}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 18 */
|
{ /* Version 18 */
|
||||||
.data_bytes = 901,
|
.data_bytes = 901,
|
||||||
.apat = {6, 30, 56, 82, 0},
|
.apat = {6, 30, 56, 82, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 69, .dw = 43, .ce = 13},
|
{.bs = 69, .dw = 43, .ns = 9},
|
||||||
{.bs = 150, .dw = 120, .ce = 15},
|
{.bs = 150, .dw = 120, .ns = 5},
|
||||||
{.bs = 42, .dw = 14, .ce = 14},
|
{.bs = 42, .dw = 14, .ns = 2},
|
||||||
{.bs = 50, .dw = 22, .ce = 14}
|
{.bs = 50, .dw = 22, .ns = 17}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 19 */
|
{ /* Version 19 */
|
||||||
.data_bytes = 991,
|
.data_bytes = 991,
|
||||||
.apat = {6, 30, 58, 86, 0},
|
.apat = {6, 30, 58, 86, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 70, .dw = 44, .ce = 13},
|
{.bs = 70, .dw = 44, .ns = 3},
|
||||||
{.bs = 141, .dw = 113, .ce = 14},
|
{.bs = 141, .dw = 113, .ns = 3},
|
||||||
{.bs = 39, .dw = 13, .ce = 13},
|
{.bs = 39, .dw = 13, .ns = 9},
|
||||||
{.bs = 47, .dw = 21, .ce = 13}
|
{.bs = 47, .dw = 21, .ns = 17}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 20 */
|
{ /* Version 20 */
|
||||||
.data_bytes = 1085,
|
.data_bytes = 1085,
|
||||||
.apat = {6, 34, 62, 90, 0},
|
.apat = {6, 34, 62, 90, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 67, .dw = 41, .ce = 13},
|
{.bs = 67, .dw = 41, .ns = 3},
|
||||||
{.bs = 135, .dw = 107, .ce = 14},
|
{.bs = 135, .dw = 107, .ns = 3},
|
||||||
{.bs = 43, .dw = 15, .ce = 14},
|
{.bs = 43, .dw = 15, .ns = 15},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 15}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 21 */
|
{ /* Version 21 */
|
||||||
.data_bytes = 1156,
|
.data_bytes = 1156,
|
||||||
.apat = {6, 28, 50, 72, 92, 0},
|
.apat = {6, 28, 50, 72, 92, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 68, .dw = 42, .ce = 13},
|
{.bs = 68, .dw = 42, .ns = 17},
|
||||||
{.bs = 144, .dw = 116, .ce = 14},
|
{.bs = 144, .dw = 116, .ns = 4},
|
||||||
{.bs = 46, .dw = 16, .ce = 15},
|
{.bs = 46, .dw = 16, .ns = 19},
|
||||||
{.bs = 50, .dw = 22, .ce = 14}
|
{.bs = 50, .dw = 22, .ns = 17}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 22 */
|
{ /* Version 22 */
|
||||||
.data_bytes = 1258,
|
.data_bytes = 1258,
|
||||||
.apat = {6, 26, 50, 74, 98, 0},
|
.apat = {6, 26, 50, 74, 98, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 74, .dw = 46, .ce = 14},
|
{.bs = 74, .dw = 46, .ns = 17},
|
||||||
{.bs = 139, .dw = 111, .ce = 14},
|
{.bs = 139, .dw = 111, .ns = 2},
|
||||||
{.bs = 37, .dw = 13, .ce = 12},
|
{.bs = 37, .dw = 13, .ns = 34},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 7}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 23 */
|
{ /* Version 23 */
|
||||||
.data_bytes = 1364,
|
.data_bytes = 1364,
|
||||||
.apat = {6, 30, 54, 78, 102, 0},
|
.apat = {6, 30, 54, 78, 102, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 75, .dw = 47, .ce = 14},
|
{.bs = 75, .dw = 47, .ns = 4},
|
||||||
{.bs = 151, .dw = 121, .ce = 15},
|
{.bs = 151, .dw = 121, .ns = 4},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 16},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 11}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 24 */
|
{ /* Version 24 */
|
||||||
.data_bytes = 1474,
|
.data_bytes = 1474,
|
||||||
.apat = {6, 28, 54, 80, 106, 0},
|
.apat = {6, 28, 54, 80, 106, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 73, .dw = 45, .ce = 14},
|
{.bs = 73, .dw = 45, .ns = 6},
|
||||||
{.bs = 147, .dw = 117, .ce = 15},
|
{.bs = 147, .dw = 117, .ns = 6},
|
||||||
{.bs = 46, .dw = 16, .ce = 15},
|
{.bs = 46, .dw = 16, .ns = 30},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 11}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 25 */
|
{ /* Version 25 */
|
||||||
.data_bytes = 1588,
|
.data_bytes = 1588,
|
||||||
.apat = {6, 32, 58, 84, 110, 0},
|
.apat = {6, 32, 58, 84, 110, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 75, .dw = 47, .ce = 14},
|
{.bs = 75, .dw = 47, .ns = 8},
|
||||||
{.bs = 132, .dw = 106, .ce = 13},
|
{.bs = 132, .dw = 106, .ns = 8},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 22},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 7}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 26 */
|
{ /* Version 26 */
|
||||||
.data_bytes = 1706,
|
.data_bytes = 1706,
|
||||||
.apat = {6, 30, 58, 86, 114, 0},
|
.apat = {6, 30, 58, 86, 114, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 74, .dw = 46, .ce = 14},
|
{.bs = 74, .dw = 46, .ns = 19},
|
||||||
{.bs = 142, .dw = 114, .ce = 14},
|
{.bs = 142, .dw = 114, .ns = 10},
|
||||||
{.bs = 46, .dw = 16, .ce = 15},
|
{.bs = 46, .dw = 16, .ns = 33},
|
||||||
{.bs = 50, .dw = 22, .ce = 14}
|
{.bs = 50, .dw = 22, .ns = 28}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 27 */
|
{ /* Version 27 */
|
||||||
.data_bytes = 1828,
|
.data_bytes = 1828,
|
||||||
.apat = {6, 34, 62, 90, 118, 0},
|
.apat = {6, 34, 62, 90, 118, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 73, .dw = 45, .ce = 14},
|
{.bs = 73, .dw = 45, .ns = 22},
|
||||||
{.bs = 152, .dw = 122, .ce = 15},
|
{.bs = 152, .dw = 122, .ns = 8},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 12},
|
||||||
{.bs = 53, .dw = 23, .ce = 15}
|
{.bs = 53, .dw = 23, .ns = 8}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 28 */
|
{ /* Version 28 */
|
||||||
.data_bytes = 1921,
|
.data_bytes = 1921,
|
||||||
.apat = {6, 26, 50, 74, 98, 122, 0},
|
.apat = {6, 26, 50, 74, 98, 122, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 73, .dw = 45, .ce = 14},
|
{.bs = 73, .dw = 45, .ns = 3},
|
||||||
{.bs = 147, .dw = 117, .ce = 15},
|
{.bs = 147, .dw = 117, .ns = 3},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 11},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 4}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 29 */
|
{ /* Version 29 */
|
||||||
.data_bytes = 2051,
|
.data_bytes = 2051,
|
||||||
.apat = {6, 30, 54, 78, 102, 126, 0},
|
.apat = {6, 30, 54, 78, 102, 126, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 73, .dw = 45, .ce = 14},
|
{.bs = 73, .dw = 45, .ns = 21},
|
||||||
{.bs = 146, .dw = 116, .ce = 15},
|
{.bs = 146, .dw = 116, .ns = 7},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 19},
|
||||||
{.bs = 73, .dw = 45, .ce = 14}
|
{.bs = 53, .dw = 23, .ns = 1}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 30 */
|
{ /* Version 30 */
|
||||||
.data_bytes = 2185,
|
.data_bytes = 2185,
|
||||||
.apat = {6, 26, 52, 78, 104, 130, 0},
|
.apat = {6, 26, 52, 78, 104, 130, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 75, .dw = 47, .ce = 14},
|
{.bs = 75, .dw = 47, .ns = 19},
|
||||||
{.bs = 145, .dw = 115, .ce = 15},
|
{.bs = 145, .dw = 115, .ns = 5},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 23},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 15}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 31 */
|
{ /* Version 31 */
|
||||||
.data_bytes = 2323,
|
.data_bytes = 2323,
|
||||||
.apat = {6, 30, 56, 82, 108, 134, 0},
|
.apat = {6, 30, 56, 82, 108, 134, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 74, .dw = 46, .ce = 14},
|
{.bs = 74, .dw = 46, .ns = 2},
|
||||||
{.bs = 145, .dw = 115, .ce = 15},
|
{.bs = 145, .dw = 115, .ns = 13},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 23},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 42}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 32 */
|
{ /* Version 32 */
|
||||||
.data_bytes = 2465,
|
.data_bytes = 2465,
|
||||||
.apat = {6, 34, 60, 86, 112, 138, 0},
|
.apat = {6, 34, 60, 86, 112, 138, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 74, .dw = 46, .ce = 14},
|
{.bs = 74, .dw = 46, .ns = 10},
|
||||||
{.bs = 145, .dw = 115, .ce = 15},
|
{.bs = 145, .dw = 115, .ns = 17},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 19},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 10}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 33 */
|
{ /* Version 33 */
|
||||||
.data_bytes = 2611,
|
.data_bytes = 2611,
|
||||||
.apat = {6, 30, 58, 96, 114, 142, 0},
|
.apat = {6, 30, 58, 86, 114, 142, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 74, .dw = 46, .ce = 14},
|
{.bs = 74, .dw = 46, .ns = 14},
|
||||||
{.bs = 145, .dw = 115, .ce = 15},
|
{.bs = 145, .dw = 115, .ns = 17},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 11},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 29}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 34 */
|
{ /* Version 34 */
|
||||||
.data_bytes = 2761,
|
.data_bytes = 2761,
|
||||||
.apat = {6, 34, 62, 90, 118, 146, 0},
|
.apat = {6, 34, 62, 90, 118, 146, 0},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 74, .dw = 46, .ce = 14},
|
{.bs = 74, .dw = 46, .ns = 14},
|
||||||
{.bs = 145, .dw = 115, .ce = 15},
|
{.bs = 145, .dw = 115, .ns = 13},
|
||||||
{.bs = 46, .dw = 16, .ce = 15},
|
{.bs = 46, .dw = 16, .ns = 59},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 44}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 35 */
|
{ /* Version 35 */
|
||||||
.data_bytes = 2876,
|
.data_bytes = 2876,
|
||||||
.apat = {6, 30, 54, 78, 102, 126, 150},
|
.apat = {6, 30, 54, 78, 102, 126, 150},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 75, .dw = 47, .ce = 14},
|
{.bs = 75, .dw = 47, .ns = 12},
|
||||||
{.bs = 151, .dw = 121, .ce = 15},
|
{.bs = 151, .dw = 121, .ns = 12},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 22},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 39}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 36 */
|
{ /* Version 36 */
|
||||||
.data_bytes = 3034,
|
.data_bytes = 3034,
|
||||||
.apat = {6, 24, 50, 76, 102, 128, 154},
|
.apat = {6, 24, 50, 76, 102, 128, 154},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 75, .dw = 47, .ce = 14},
|
{.bs = 75, .dw = 47, .ns = 6},
|
||||||
{.bs = 151, .dw = 121, .ce = 15},
|
{.bs = 151, .dw = 121, .ns = 6},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 2},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 46}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 37 */
|
{ /* Version 37 */
|
||||||
.data_bytes = 3196,
|
.data_bytes = 3196,
|
||||||
.apat = {6, 28, 54, 80, 106, 132, 158},
|
.apat = {6, 28, 54, 80, 106, 132, 158},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 74, .dw = 46, .ce = 14},
|
{.bs = 74, .dw = 46, .ns = 29},
|
||||||
{.bs = 152, .dw = 122, .ce = 15},
|
{.bs = 152, .dw = 122, .ns = 17},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 24},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 49}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 38 */
|
{ /* Version 38 */
|
||||||
.data_bytes = 3362,
|
.data_bytes = 3362,
|
||||||
.apat = {6, 32, 58, 84, 110, 136, 162},
|
.apat = {6, 32, 58, 84, 110, 136, 162},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 74, .dw = 46, .ce = 14},
|
{.bs = 74, .dw = 46, .ns = 13},
|
||||||
{.bs = 152, .dw = 122, .ce = 15},
|
{.bs = 152, .dw = 122, .ns = 4},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 42},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 48}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 39 */
|
{ /* Version 39 */
|
||||||
.data_bytes = 3532,
|
.data_bytes = 3532,
|
||||||
.apat = {6, 26, 54, 82, 110, 138, 166},
|
.apat = {6, 26, 54, 82, 110, 138, 166},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 75, .dw = 47, .ce = 14},
|
{.bs = 75, .dw = 47, .ns = 40},
|
||||||
{.bs = 147, .dw = 117, .ce = 15},
|
{.bs = 147, .dw = 117, .ns = 20},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 10},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 43}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ /* Version 40 */
|
{ /* Version 40 */
|
||||||
.data_bytes = 3706,
|
.data_bytes = 3706,
|
||||||
.apat = {6, 30, 58, 86, 114, 142, 170},
|
.apat = {6, 30, 58, 86, 114, 142, 170},
|
||||||
.ecc = {
|
.ecc = {
|
||||||
{.bs = 75, .dw = 47, .ce = 14},
|
{.bs = 75, .dw = 47, .ns = 18},
|
||||||
{.bs = 148, .dw = 118, .ce = 15},
|
{.bs = 148, .dw = 118, .ns = 19},
|
||||||
{.bs = 45, .dw = 15, .ce = 15},
|
{.bs = 45, .dw = 15, .ns = 20},
|
||||||
{.bs = 54, .dw = 24, .ce = 15}
|
{.bs = 54, .dw = 24, .ns = 34}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
1367
source/remote.c
Normal file
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Anemone3DS
|
* This file is part of Anemone3DS
|
||||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -26,245 +26,106 @@
|
|||||||
#include "splashes.h"
|
#include "splashes.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "themes.h"
|
|
||||||
#include "pp2d/pp2d/pp2d.h"
|
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
|
#include "ui_strings.h"
|
||||||
|
|
||||||
void load_splash_preview(Splash_s *splash)
|
void splash_delete(void)
|
||||||
{
|
|
||||||
//free the previously loaded preview. wont do anything if there wasnt one
|
|
||||||
pp2d_free_texture(TEXTURE_PREVIEW);
|
|
||||||
|
|
||||||
char *preview_buffer = NULL;
|
|
||||||
u64 size = 0;
|
|
||||||
if (!(splash->is_zip))
|
|
||||||
{
|
|
||||||
u16 path_to_preview[0x106] = {0};
|
|
||||||
strucat(path_to_preview, splash->path);
|
|
||||||
struacat(path_to_preview, "/preview.png");
|
|
||||||
size = file_to_buf(fsMakePath(PATH_UTF16, path_to_preview), ArchiveSD, &preview_buffer);
|
|
||||||
} else {
|
|
||||||
size = zip_file_to_buf("preview.png", splash->path, &preview_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!size)
|
|
||||||
{
|
|
||||||
free(preview_buffer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
u8 * image = NULL;
|
|
||||||
unsigned int width = 0, height = 0;
|
|
||||||
|
|
||||||
int result = lodepng_decode32(&image, &width, &height, (u8*)preview_buffer, size);
|
|
||||||
if (result == 0) // no error
|
|
||||||
{
|
|
||||||
for (u32 i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
for (u32 j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
u32 p = (i + j*width) * 4;
|
|
||||||
|
|
||||||
u8 r = *(u8*)(image + p);
|
|
||||||
u8 g = *(u8*)(image + p + 1);
|
|
||||||
u8 b = *(u8*)(image + p + 2);
|
|
||||||
u8 a = *(u8*)(image + p + 3);
|
|
||||||
|
|
||||||
*(image + p) = a;
|
|
||||||
*(image + p + 1) = b;
|
|
||||||
*(image + p + 2) = g;
|
|
||||||
*(image + p + 3) = r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pp2d_load_texture_memory(TEXTURE_PREVIEW, image, (u32)width, (u32)height);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(image);
|
|
||||||
free(preview_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void parse_smdh(Splash_s *splash, ssize_t textureID, u16 *splash_name)
|
|
||||||
{
|
|
||||||
char *info_buffer = NULL;
|
|
||||||
u64 size = 0;
|
|
||||||
if (!(splash->is_zip))
|
|
||||||
{
|
|
||||||
u16 path_to_smdh[0x106] = {0};
|
|
||||||
strucat(path_to_smdh, splash->path);
|
|
||||||
struacat(path_to_smdh, "/info.smdh");
|
|
||||||
|
|
||||||
size = file_to_buf(fsMakePath(PATH_UTF16, path_to_smdh), ArchiveSD, &info_buffer);
|
|
||||||
} else {
|
|
||||||
size = zip_file_to_buf("info.smdh", splash->path, &info_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!size)
|
|
||||||
{
|
|
||||||
free(info_buffer);
|
|
||||||
memset(splash->name, 0, 0x80);
|
|
||||||
memset(splash->desc, 0, 0x100);
|
|
||||||
memset(splash->author, 0, 0x80);
|
|
||||||
memcpy(splash->name, splash_name, 0x80);
|
|
||||||
utf8_to_utf16(splash->desc, (u8*)"No description", 0x100);
|
|
||||||
utf8_to_utf16(splash->author, (u8*)"Unknown author", 0x80);
|
|
||||||
splash->placeholder_color = RGBA8(rand() % 255, rand() % 255, rand() % 255, 255);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(splash->name, info_buffer + 0x08, 0x80);
|
|
||||||
memcpy(splash->desc, info_buffer + 0x88, 0x100);
|
|
||||||
memcpy(splash->author, info_buffer + 0x188, 0x80);
|
|
||||||
|
|
||||||
u16 *icon_data = malloc(0x1200);
|
|
||||||
memcpy(icon_data, info_buffer + 0x24C0, 0x1200);
|
|
||||||
|
|
||||||
const u32 width = 48, height = 48;
|
|
||||||
u32 *image = malloc(width*height*sizeof(u32));
|
|
||||||
|
|
||||||
for (u32 x = 0; x < width; x++)
|
|
||||||
{
|
|
||||||
for (u32 y = 0; y < height; y++)
|
|
||||||
{
|
|
||||||
unsigned int dest_pixel = (x + y*width);
|
|
||||||
unsigned int source_pixel = (((y >> 3) * (width >> 3) + (x >> 3)) << 6) + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3));
|
|
||||||
|
|
||||||
u8 r = ((icon_data[source_pixel] >> 11) & 0b11111) << 3;
|
|
||||||
u8 g = ((icon_data[source_pixel] >> 5) & 0b111111) << 2;
|
|
||||||
u8 b = (icon_data[source_pixel] & 0b11111) << 3;
|
|
||||||
u8 a = 0xFF;
|
|
||||||
|
|
||||||
image[dest_pixel] = (r << 24) | (g << 16) | (b << 8) | a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pp2d_load_texture_memory(textureID, (u8*)image, (u32)width, (u32)height);
|
|
||||||
splash->icon_id = textureID;
|
|
||||||
|
|
||||||
free(image);
|
|
||||||
free(icon_data);
|
|
||||||
free(info_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result get_splashes(Splash_s** splashes_list, int *splash_count)
|
|
||||||
{
|
|
||||||
Result res = 0;
|
|
||||||
Handle dir_handle;
|
|
||||||
res = FSUSER_OpenDirectory(&dir_handle, ArchiveSD, fsMakePath(PATH_ASCII, SPLASHES_PATH));
|
|
||||||
if (R_FAILED(res))
|
|
||||||
return res;
|
|
||||||
|
|
||||||
if (*splashes_list != NULL)
|
|
||||||
{
|
|
||||||
free(*splashes_list);
|
|
||||||
*splashes_list = NULL;
|
|
||||||
*splash_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 entries_read = 1;
|
|
||||||
while (entries_read)
|
|
||||||
{
|
|
||||||
FS_DirectoryEntry entry = {0};
|
|
||||||
res = FSDIR_Read(dir_handle, &entries_read, 1, &entry);
|
|
||||||
if (R_FAILED(res) || entries_read == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!(entry.attributes & FS_ATTRIBUTE_DIRECTORY) && strcmp(entry.shortExt, "ZIP"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
*splash_count += entries_read;
|
|
||||||
*splashes_list= realloc(*splashes_list, (*splash_count) * sizeof(Splash_s));
|
|
||||||
if (splashes_list == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
Splash_s *current_splash = &(*splashes_list)[*splash_count-1];
|
|
||||||
memset(current_splash, 0, sizeof(Splash_s));
|
|
||||||
|
|
||||||
u16 splash_path[0x106]= {0};
|
|
||||||
struacat(splash_path, SPLASHES_PATH);
|
|
||||||
strucat(splash_path, entry.name);
|
|
||||||
|
|
||||||
char pathchar[0x106] = {0};
|
|
||||||
utf16_to_utf8((u8*) pathchar, splash_path, 0x106);
|
|
||||||
|
|
||||||
memcpy(current_splash->path, splash_path, 0x106 * sizeof(u16));
|
|
||||||
current_splash->is_zip = !strcmp(entry.shortExt, "ZIP");
|
|
||||||
|
|
||||||
ssize_t iconID = TEXTURE_PREVIEW + theme_count + *splash_count;
|
|
||||||
parse_smdh(current_splash, iconID, entry.name);
|
|
||||||
}
|
|
||||||
FSDIR_Close(dir_handle);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void splash_delete()
|
|
||||||
{
|
{
|
||||||
remove("/luma/splash.bin");
|
remove("/luma/splash.bin");
|
||||||
remove("/luma/splashbottom.bin");
|
remove("/luma/splashbottom.bin");
|
||||||
}
|
}
|
||||||
|
|
||||||
void splash_install(Splash_s splash_to_install)
|
void splash_install(const Entry_s * splash)
|
||||||
{
|
{
|
||||||
char *screen_buf = NULL;
|
char *screen_buf = NULL;
|
||||||
u32 size = 0;
|
|
||||||
if (splash_to_install.is_zip)
|
u32 size = load_data("/splash.bin", splash, &screen_buf);
|
||||||
|
if(size != 0)
|
||||||
{
|
{
|
||||||
size = zip_file_to_buf("splash.bin", splash_to_install.path, &screen_buf);
|
remake_file(fsMakePath(PATH_ASCII, "/luma/splash.bin"), ArchiveSD, size);
|
||||||
if (size)
|
buf_to_file(size, fsMakePath(PATH_ASCII, "/luma/splash.bin"), ArchiveSD, screen_buf);
|
||||||
{
|
|
||||||
remake_file("/luma/splash.bin", ArchiveSD, sizeof(screen_buf));
|
|
||||||
buf_to_file(size, "/luma/splash.bin", ArchiveSD, screen_buf);
|
|
||||||
free(screen_buf);
|
|
||||||
screen_buf = NULL;
|
|
||||||
size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size = zip_file_to_buf("splashbottom.bin", splash_to_install.path, &screen_buf);
|
|
||||||
if (size)
|
|
||||||
{
|
|
||||||
remake_file("/luma/splashbottom.bin", ArchiveSD, sizeof(screen_buf));
|
|
||||||
buf_to_file(size, "/luma/splashbottom.bin", ArchiveSD, screen_buf);
|
|
||||||
free(screen_buf);
|
|
||||||
screen_buf = NULL;
|
|
||||||
size = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
u16 path[0x106] = {0};
|
|
||||||
memcpy(path, splash_to_install.path, 0x106 * sizeof(u16));
|
|
||||||
struacat(path, "/splash.bin");
|
|
||||||
size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &screen_buf);
|
|
||||||
if (size)
|
|
||||||
{
|
|
||||||
remake_file("/luma/splash.bin", ArchiveSD, sizeof(screen_buf));
|
|
||||||
buf_to_file(size, "/luma/splash.bin", ArchiveSD, screen_buf);
|
|
||||||
free(screen_buf);
|
|
||||||
screen_buf = NULL;
|
|
||||||
size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(path, splash_to_install.path, 0x106 * sizeof(u16));
|
|
||||||
struacat(path, "/splashbottom.bin");
|
|
||||||
size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &screen_buf);
|
|
||||||
if (size)
|
|
||||||
{
|
|
||||||
remake_file("/luma/splashbottom.bin", ArchiveSD, sizeof(screen_buf));
|
|
||||||
buf_to_file(size, "/luma/splashbottom.bin", ArchiveSD, screen_buf);
|
|
||||||
free(screen_buf);
|
|
||||||
screen_buf = NULL;
|
|
||||||
size = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *config_buf;
|
u32 bottom_size = load_data("/splashbottom.bin", splash, &screen_buf);
|
||||||
size = file_to_buf(fsMakePath(PATH_ASCII, "/luma/config.bin"), ArchiveSD, &config_buf);
|
if(bottom_size != 0)
|
||||||
if (size)
|
|
||||||
{
|
{
|
||||||
if (config_buf[0xC] == 0)
|
remake_file(fsMakePath(PATH_ASCII, "/luma/splashbottom.bin"), ArchiveSD, bottom_size);
|
||||||
|
buf_to_file(bottom_size, fsMakePath(PATH_ASCII, "/luma/splashbottom.bin"), ArchiveSD, screen_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(size == 0 && bottom_size == 0)
|
||||||
|
{
|
||||||
|
throw_error(language.splashes.no_splash_found, ERROR_LEVEL_WARNING);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char *config_buf;
|
||||||
|
size = file_to_buf(fsMakePath(PATH_ASCII, "/luma/config.bin"), ArchiveSD, &config_buf);
|
||||||
|
if(size)
|
||||||
{
|
{
|
||||||
free(config_buf);
|
if(config_buf[0xC] == 0)
|
||||||
throw_error("WARNING: Splashes are disabled in Luma Config", WARNING);
|
{
|
||||||
|
free(config_buf);
|
||||||
|
throw_error(language.splashes.splash_disabled, ERROR_LEVEL_WARNING);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void splash_check_installed(void * void_arg)
|
||||||
|
{
|
||||||
|
Thread_Arg_s * arg = (Thread_Arg_s *)void_arg;
|
||||||
|
Entry_List_s * list = (Entry_List_s *)arg->thread_arg;
|
||||||
|
if(list == NULL || list->entries == NULL) return;
|
||||||
|
|
||||||
|
#ifndef CITRA_MODE
|
||||||
|
char * top_buf = NULL;
|
||||||
|
u32 top_size = file_to_buf(fsMakePath(PATH_ASCII, "/luma/splash.bin"), ArchiveSD, &top_buf);
|
||||||
|
char * bottom_buf = NULL;
|
||||||
|
u32 bottom_size = file_to_buf(fsMakePath(PATH_ASCII, "/luma/splashbottom.bin"), ArchiveSD, &bottom_buf);
|
||||||
|
|
||||||
|
if(!top_size && !bottom_size)
|
||||||
|
{
|
||||||
|
free(top_buf);
|
||||||
|
free(bottom_buf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HASH_SIZE_BYTES 256/8
|
||||||
|
u8 top_hash[HASH_SIZE_BYTES] = {0};
|
||||||
|
FSUSER_UpdateSha256Context(top_buf, top_size, top_hash);
|
||||||
|
free(top_buf);
|
||||||
|
top_buf = NULL;
|
||||||
|
u8 bottom_hash[HASH_SIZE_BYTES] = {0};
|
||||||
|
FSUSER_UpdateSha256Context(bottom_buf, bottom_size, bottom_hash);
|
||||||
|
free(bottom_buf);
|
||||||
|
bottom_buf = NULL;
|
||||||
|
|
||||||
|
for(int i = 0; i < list->entries_count && arg->run_thread; i++)
|
||||||
|
{
|
||||||
|
Entry_s * splash = &list->entries[i];
|
||||||
|
top_size = load_data("/splash.bin", splash, &top_buf);
|
||||||
|
bottom_size = load_data("/splashbottom.bin", splash, &bottom_buf);
|
||||||
|
|
||||||
|
if(!top_size && !bottom_size)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 splash_top_hash[HASH_SIZE_BYTES] = {0};
|
||||||
|
FSUSER_UpdateSha256Context(top_buf, top_size, splash_top_hash);
|
||||||
|
free(top_buf);
|
||||||
|
top_buf = NULL;
|
||||||
|
u8 splash_bottom_hash[HASH_SIZE_BYTES] = {0};
|
||||||
|
FSUSER_UpdateSha256Context(bottom_buf, bottom_size, splash_bottom_hash);
|
||||||
|
free(bottom_buf);
|
||||||
|
bottom_buf = NULL;
|
||||||
|
|
||||||
|
if(!memcmp(splash_bottom_hash, bottom_hash, HASH_SIZE_BYTES) && !memcmp(splash_top_hash, top_hash, HASH_SIZE_BYTES))
|
||||||
|
{
|
||||||
|
splash->installed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
1148
source/themes.c
2097
source/ui_strings.c
Normal file
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Anemone3DS
|
* This file is part of Anemone3DS
|
||||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -26,38 +26,53 @@
|
|||||||
|
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
|
|
||||||
ssize_t strulen(const u16 *input, ssize_t max_len)
|
void replace_chars(u16 *input, char *remove, u16 with)
|
||||||
|
{
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
ssize_t len = strulen(input, 0x106);
|
const ssize_t len = strulen(input, 0x106);
|
||||||
for (u16 i = len; i < strlen(addition) + len; i++)
|
const u16 stop_at = strlen(addition);
|
||||||
|
for (u16 i = 0; i < stop_at; i++)
|
||||||
{
|
{
|
||||||
input[i] = addition[i - len];
|
input[i + len] = addition[i];
|
||||||
}
|
}
|
||||||
input[strlen(addition) + len] = 0;
|
input[stop_at + 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);
|
||||||
printf("%ls\n", buf);
|
char cbuf[0x106];
|
||||||
|
sprintf(cbuf, "%ls\n", buf);
|
||||||
|
DEBUG(cbuf);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 *strucat(u16 *destination, const u16 *source)
|
size_t strucat(u16 * destination, const u16 * source)
|
||||||
{
|
{
|
||||||
ssize_t dest_len = strulen(destination, 0x106);
|
size_t dest_len = strulen(destination, 0x106);
|
||||||
|
|
||||||
ssize_t source_len = strulen(source, 0x106);
|
size_t source_len = strulen(source, 0x106);
|
||||||
|
|
||||||
memcpy(&destination[dest_len], source, source_len * sizeof(u16));
|
memcpy(&destination[dest_len], source, source_len * sizeof(u16));
|
||||||
return destination;
|
destination[min(dest_len + source_len, 0x106 - 1)] = 0;
|
||||||
|
return source_len;
|
||||||
}
|
}
|
||||||