Skip to content

Commit

Permalink
Improve code, correct patcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanquitas committed Feb 12, 2017
1 parent 37dc726 commit 370e149
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 102 deletions.
20 changes: 8 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ endif
FONZD = 0
PABLOMK7 = 0
EXTENDEDMODE = 0
DEBUG = 0

ifeq ($(EXTENDEDMODE), 1)
ifeq ($(FONZD), 1)
NAME := BootNTRSelector-Mode-3-FONZD-Banner
endif

ifeq ($(PABLOMK7), 1)
else
NAME := BootNTRSelector-Mode3-PabloMK7-Banner
endif
else
ifeq ($(FONZD), 1)
NAME := BootNTRSelector-FONZD-Banner
endif

ifeq ($(PABLOMK7), 1)
else
NAME := BootNTRSelector-PabloMK7-Banner
endif
endif
Expand All @@ -46,7 +43,7 @@ LIBRARIES := citro3d ctru png z m

VERSION_MAJOR := 2
VERSION_MINOR := 7
VERSION_MICRO := 1
VERSION_MICRO := 2



Expand All @@ -57,7 +54,9 @@ BUILD_FLAGS_CC := -g -Wall -Wno-strict-aliasing -O3 -mword-relocations \
-DAPP_VERSION_MAJOR=${VERSION_MAJOR} \
-DAPP_VERSION_MINOR=${VERSION_MINOR} \
-DAPP_VERSION_REVISION=${VERSION_MICRO} \
-DEXTENDEDMODE=${EXTENDEDMODE}
-DEXTENDEDMODE=${EXTENDEDMODE} \
-DDEBUGMODE=${DEBUG}

BUILD_FLAGS_CXX := $(COMMON_FLAGS) -std=gnu++11
RUN_FLAGS :=

Expand Down Expand Up @@ -109,17 +108,14 @@ ifeq ($(TARGET),3DS)
BANNER_AUDIO := resources/audio.wav
ifeq ($(FONZD), 1)
BANNER_IMAGE := resources/FonzD_banner.cgfx
endif
ifeq ($(PABLOMK7), 1)
else
BANNER_IMAGE := resources/PabloMK7_banner.cgfx
endif
ifeq ($(EXTENDEDMODE), 1)
ICON := resources/iconM3.png
else
ICON := resources/icon.png
endif

LOGO :=
endif

# INTERNAL #
Expand Down
5 changes: 5 additions & 0 deletions source/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ void configInit(void)
{
config_t *config;
Handle fsuHandle;
bool isNew3DS = false;;


srvGetServiceHandle(&fsuHandle, "fs:USER");
FSUSER_Initialize(fsuHandle);
APT_CheckNew3DS(&isNew3DS);

memset(&g_ntrConfig, 0, sizeof(g_ntrConfig));
memset(&g_bnConfig, 0, sizeof(g_bnConfig));
Expand All @@ -131,6 +134,8 @@ void configInit(void)
bnConfig = &g_bnConfig;
ntrConfig->fsUserHandle = fsuHandle;
g_bnConfig.isMode3 = EXTENDEDMODE;
g_bnConfig.isDebug = DEBUGMODE;
g_bnConfig.isNew3DS = isNew3DS;

config = (config_t *)calloc(1, sizeof(config_t));
if (!config) goto error;
Expand Down
2 changes: 2 additions & 0 deletions source/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ typedef struct bootNtrConfig_s
config_t *config;
bool checkForUpdate;
bool isMode3;
bool isDebug;
bool isNew3DS;
} bootNtrConfig_t;

void configInit(void);
Expand Down
27 changes: 23 additions & 4 deletions source/firstLaunchMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ static void setFiles(void)
else
newAppTop(COLOR_LIMEGREEN, SKINNY, "Creating directory: Success");
updateUI();
}
}

if (!fileExists(bnConfig->config->pluginPath + 5))
{
newAppTop(COLOR_BLANK, SKINNY, "%s, doesn't exist", bnConfig->config->pluginPath);
Expand All @@ -349,7 +350,8 @@ static void setFiles(void)
newAppTop(COLOR_BLANK, SKINNY, "Setting up 3.2...");
updateUI();
ret = loadAndPatch(V32);
removeAppTop();
if (!bnConfig->isDebug)
removeAppTop();
if (ret)
newAppTop(COLOR_SALMON, SKINNY, "Setting up 3.2... Error.");
else
Expand All @@ -359,7 +361,8 @@ static void setFiles(void)
newAppTop(COLOR_BLANK, SKINNY, "Setting up 3.3...");
updateUI();
ret = loadAndPatch(V33);
removeAppTop();
if (!bnConfig->isDebug)
removeAppTop();
if (ret)
newAppTop(COLOR_SALMON, SKINNY, "Setting up 3.3... Error.");
else
Expand All @@ -369,13 +372,29 @@ static void setFiles(void)
newAppTop(COLOR_BLANK, SKINNY, "Setting up 3.4...");
updateUI();
ret = loadAndPatch(V34);
removeAppTop();
if (!bnConfig->isDebug)
removeAppTop();
if (ret)
newAppTop(COLOR_SALMON, SKINNY, "Setting up 3.4... Error.");
else
newAppTop(COLOR_LIMEGREEN, SKINNY, "Setting up 3.4... Done.");
updateUI();

if (!bnConfig->isNew3DS)
{
newAppTop(COLOR_BLANK, SKINNY, "Setting up 3.4 unpatched...");
updateUI();
ret = loadAndPatch(V34);
if (!bnConfig->isDebug)
removeAppTop();
if (ret)
newAppTop(COLOR_SALMON, SKINNY, "Setting up 3.4 unpatched... Error.");
else
newAppTop(COLOR_LIMEGREEN, SKINNY, "Setting up 3.4... Done.");
updateUI();
}


newAppTop(COLOR_LIMEGREEN, 0, "Finished");
updateUI();
clearTop(1);
Expand Down
22 changes: 10 additions & 12 deletions source/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,24 @@
#include "graphics.h"
#include "mysvcs.h"

#define TIMER 3

#if EXTENDEDMODE

#if EXTENDEDMODE

#define TIMER 1
#if FONZD_BANNER
#define CIA_VERSION "BootNTRSelector-Mode3-FONZD-Banner.cia"
#endif

#if PABLOMK7_BANNER
#define CIA_VERSION "BootNTRSelector-Mode3-PabloMK7-Banner.cia"
#define CIA_VERSION "BootNTRSelector-Mode3-FONZD-Banner.cia"
#else
#define CIA_VERSION "BootNTRSelector-Mode3-PabloMK7-Banner.cia"
#endif

#else
#define TIMER 3

#if FONZD_BANNER
#define CIA_VERSION "BootNTRSelector-FONZD-Banner.cia"
#endif

#if PABLOMK7_BANNER
#define CIA_VERSION "BootNTRSelector-PabloMK7-Banner.cia"
#define CIA_VERSION "BootNTRSelector-FONZD-Banner.cia"
#else
#define CIA_VERSION "BootNTRSelector-PabloMK7-Banner.cia"
#endif

#endif
Expand Down
98 changes: 42 additions & 56 deletions source/mainMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,15 @@
#include <time.h>

extern bootNtrConfig_t *bnConfig;
#if EXTENDEDMODE == 0

static button_t *V32Button;
static button_t *V33Button;
static button_t *V34Button;
static sprite_t *desiredVersionSprite;
static sprite_t *tinyButtonBGSprite;
#endif
static sprite_t *pressExitSprite;
static bool userTouch = false;

#if EXTENDEDMODE

void initMainMenu(void)
{
newSpriteFromPNG(&pressExitSprite, "romfs:/sprites/textSprites/pressBExit.png");

setSpritePos(pressExitSprite, 180.0f, 217.0f);

changeBottomFooter(pressExitSprite);
}

void exitMainMenu(void)
{
deleteSprite(pressExitSprite);
}

#else

void selectVersion(u32 mode)
{
V32Button->disable(V32Button);
Expand All @@ -57,46 +38,54 @@ void selectVersion(u32 mode)

void initMainMenu(void)
{
sprite_t *sprite;
if (!bnConfig->isMode3)
{
sprite_t *sprite;

newSpriteFromPNG(&desiredVersionSprite, "romfs:/sprites/textSprites/touchDesiredVersion.png");
newSpriteFromPNG(&tinyButtonBGSprite, "romfs:/sprites/tinyButtonBackground.png");

setSpritePos(desiredVersionSprite, 34.0f, 7.0f);

changeBottomHeader(desiredVersionSprite);

newSpriteFromPNG(&sprite, "romfs:/sprites/textSprites/32Version.png");
V32Button = newButton(11.0f, 35.0f, selectVersion, 1, tinyButtonBGSprite, sprite);
newSpriteFromPNG(&sprite, "romfs:/sprites/textSprites/33Version.png");
V33Button = newButton(11.0f, 94.0f, selectVersion, 2, tinyButtonBGSprite, sprite);
newSpriteFromPNG(&sprite, "romfs:/sprites/textSprites/34Version.png");
V34Button = newButton(11.0f, 152.0f, selectVersion, 3, tinyButtonBGSprite, sprite);

V32Button->show(V32Button);
V33Button->show(V33Button);
V34Button->show(V34Button);
addBottomObject(V32Button);
addBottomObject(V33Button);
addBottomObject(V34Button);
}

newSpriteFromPNG(&desiredVersionSprite, "romfs:/sprites/textSprites/touchDesiredVersion.png");
newSpriteFromPNG(&tinyButtonBGSprite, "romfs:/sprites/tinyButtonBackground.png");
newSpriteFromPNG(&pressExitSprite, "romfs:/sprites/textSprites/pressBExit.png");

setSpritePos(desiredVersionSprite, 34.0f, 7.0f);
setSpritePos(pressExitSprite, 180.0f, 217.0f);

changeBottomFooter(pressExitSprite);
changeBottomHeader(desiredVersionSprite);

newSpriteFromPNG(&sprite, "romfs:/sprites/textSprites/32Version.png");
V32Button = newButton(11.0f, 35.0f, selectVersion, 1, tinyButtonBGSprite, sprite);
newSpriteFromPNG(&sprite, "romfs:/sprites/textSprites/33Version.png");
V33Button = newButton(11.0f, 94.0f, selectVersion, 2, tinyButtonBGSprite, sprite);
newSpriteFromPNG(&sprite, "romfs:/sprites/textSprites/34Version.png");
V34Button = newButton(11.0f, 152.0f, selectVersion, 3, tinyButtonBGSprite, sprite);

V32Button->show(V32Button);
V33Button->show(V33Button);
V34Button->show(V34Button);
addBottomObject(V32Button);
addBottomObject(V33Button);
addBottomObject(V34Button);
changeBottomFooter(pressExitSprite);

}

void exitMainMenu(void)
{
destroyButton(V32Button);
destroyButton(V33Button);
destroyButton(V34Button);
deleteSprite(tinyButtonBGSprite);
deleteSprite(desiredVersionSprite);
if (!bnConfig->isMode3)
{
destroyButton(V32Button);
destroyButton(V33Button);
destroyButton(V34Button);
deleteSprite(tinyButtonBGSprite);
deleteSprite(desiredVersionSprite);
}

deleteSprite(pressExitSprite);
}

#endif



static const char * versionString[] =
{
Expand All @@ -114,7 +103,7 @@ int mainMenu(void)
bool noTimer;

waitAllKeysReleased();
if (!bnConfig->config->flags) noTimer = true;
if (!bnConfig->isMode3 && !bnConfig->config->flags) noTimer = true;
else noTimer = false;
appInfoDisableAutoUpdate();
if (!noTimer)
Expand All @@ -125,22 +114,17 @@ int mainMenu(void)
updateUI();
}
keys = 0;
#if EXTENDEDMODE
while (1)
#else

while (userTouch == false)
#endif
{
keys = hidKeysDown() | hidKeysHeld();
if (keys == (KEY_L | KEY_R | KEY_X | KEY_DUP)) goto dumpMode;
#if EXTENDEDMODE == 0
if (keys)
if (keys && !bnConfig->isMode3)
{
noTimer = true;
removeAppStatus();
updateUI();
}
#endif
if (abort_and_exit()) goto abort;
if (!noTimer)
{
Expand All @@ -162,9 +146,11 @@ int mainMenu(void)
appInfoEnableAutoUpdate();
newAppStatus(DEFAULT_COLOR, CENTER | TINY | SKINNY, "Loading %s ...", versionString[bnConfig->versionToLaunch]);
return (1);

abort:
appInfoEnableAutoUpdate();
return (0);

dumpMode:
removeAppStatus();
appInfoEnableAutoUpdate();
Expand Down
15 changes: 9 additions & 6 deletions source/ntr_launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@ u32 loadNTRBin(void)
u32 ret;
char path[0x100];

static const char *ntrVersionStrings[3] =
static const char *ntrVersionStrings[4] =
{
"ntr_3_2.bin",
"ntr_3_3.bin",
"ntr_3_4.bin"
"ntr_3_4.bin",
"ntr_3_4u.bin"
};

if (bnConfig->versionToLaunch == V32)
strJoin(path, "/", "ntr.bin");
else if (bnConfig->isMode3 && !bnConfig->isNew3DS)
strJoin(path, bnConfig->config->binariesPath + 5, ntrVersionStrings[3]);
else
strJoin(path, bnConfig->config->binariesPath + 5, ntrVersionStrings[bnConfig->versionToLaunch]);

Expand Down Expand Up @@ -159,9 +162,9 @@ Result bnBootNTR(void)

// Free temp buffer
linearFree(linearAddress);
#if DEBUG
ntrConfig->ShowDbgFunc = (u32)showDbg;
#endif

if (bnConfig->isDebug)
ntrConfig->ShowDbgFunc = (u32)showDbg;
// Load NTR
ret = bnLoadAndExecuteNTR();
check_third(ret, LOAD_FAILED);
Expand Down Expand Up @@ -239,4 +242,4 @@ void launchNTRDumpMode(void)
ntrConfig->ShowDbgFunc = (u32)printDumpLog;
copyRemoteMemory(CURRENT_PROCESS_HANDLE, (u32)buffer, CURRENT_PROCESS_HANDLE, (u32)buffer + 0x10, 0x10);
bnLoadAndExecuteNTR();
}
}
Loading

0 comments on commit 370e149

Please sign in to comment.