Optimize romfs size and cheat loading times

This commit is contained in:
BernardoGiordano 2019-04-25 11:29:12 +02:00
parent 527047fe53
commit c20627632d
4 changed files with 40 additions and 9 deletions

View file

@ -88,13 +88,13 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lcitro2d -lcitro3d -lctru -lm
LIBS := -lbz2 -lcitro2d -lcitro3d -lctru -lm
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(CTRULIB)
LIBDIRS := $(CTRULIB) $(PORTLIBS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
@ -187,7 +187,7 @@ ifeq ($(OS),Windows_NT)
else
@cd $(SHARKIVE) && python3 joiner.py 3ds
endif
@cd $(SHARKIVE)/$(BUILD) && mv 3ds.json ../../3ds/$(ROMFS)/$(CHEATS)/$(CHEATS).json
@cd $(SHARKIVE)/$(BUILD) && mv 3ds.json.bz2 ../../3ds/$(ROMFS)/$(CHEATS)/$(CHEATS).json.bz2
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile $(OUTPUT).3dsx
@bannertool makebanner -i "$(BANNER_IMAGE)" -a "$(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

View file

@ -30,6 +30,7 @@
#include <3ds.h>
#include <sys/stat.h>
#include <stdio.h>
#include <bzlib.h>
#include "json.hpp"
#include "gui.hpp"
#include "main.hpp"

View file

@ -35,11 +35,41 @@ void CheatManager::init(void)
{
Gui::updateButtons();
std::string path = io::fileExists("/3ds/Checkpoint/cheats.json") ? "/3ds/Checkpoint/cheats.json" : "romfs:/cheats/cheats.json";
FILE* in = fopen(path.c_str(), "rt");
mCheats = nlohmann::json::parse(in, nullptr, false);
fclose(in);
mLoaded = true;
if (io::fileExists("/3ds/Checkpoint/cheats.json"))
{
const std::string path = "/3ds/Checkpoint/cheats.json";
FILE* in = fopen(path.c_str(), "rt");
mCheats = nlohmann::json::parse(in, nullptr, false);
fclose(in);
mLoaded = true;
}
else
{
const std::string path = "romfs:/cheats/cheats.json.bz2";
// load compressed archive in memory
FILE* f = fopen(path.c_str(), "rb");
if (f != NULL)
{
fseek(f, 0, SEEK_END);
u32 size = ftell(f);
unsigned int destLen = 2*1024*1024;
char* s = new char[size];
char* d = new char[destLen]();
rewind(f);
fread(s, 1, size, f);
int r = BZ2_bzBuffToBuffDecompress(d, &destLen, s, size, 0, 0);
if (r == BZ_OK)
{
mCheats = nlohmann::json::parse(d);
mLoaded = true;
}
delete[] s;
delete[] d;
}
}
Gui::updateButtons();
}

@ -1 +1 @@
Subproject commit 850d27f3fe4a99d9626cd7b05d32d04f571ee20d
Subproject commit 50790584d1b83e37d4629411df47140dab805e02