Skip to content
This repository has been archived by the owner on Oct 29, 2022. It is now read-only.

Commit

Permalink
Added NH 2.x bootloader support.
Browse files Browse the repository at this point in the history
Added NH 2.x bootloader support.
  • Loading branch information
Rinnegatamante committed Dec 28, 2015
1 parent 329a2cb commit a34b5bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CFLAGS := -g -O2 -mword-relocations \

CFLAGS += $(INCLUDE) -DARM11 -D_3DS -DLODEPNG_NO_COMPILE_ENCODER -DLUA_C89_NUMBERS -DLIBCTRU_NO_DEPRECATION

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 -Wno-write-strings
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 -fpermissive -Wno-write-strings

ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
Expand Down
41 changes: 17 additions & 24 deletions source/luaSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
#include "include/luaplayer.h"
#include "include/graphics/Graphics.h"
#include "include/Archives.h"
/*#include "include/boot/descriptor.h"
extern "C"{
#include "include/boot/boot.h"
}*/

#define stringify(str) #str
#define VariableRegister(lua, value) do { lua_pushinteger(lua, value); lua_setglobal (lua, stringify(value)); } while(0)
Expand Down Expand Up @@ -852,17 +848,25 @@ static int lua_readsmdh(lua_State *L){
//Boot Func
extern void (*__system_retAddr)(void);
static Handle hbHandle;
static u32 argbuffer[0x100];
static u32 argbuffer_length = 0;
void (*callBootloader)(Handle hb, Handle file);
void (*setArgs)(u32* src, u32 length);
static void launchFile(void){ callBootloader(0x00000000, hbHandle); }
void (*callBootloader_2x)(Handle file, u32* argbuf, u32 arglength) = (void*)0x00100000;
static void launchFile_2x(void){ callBootloader_2x(hbHandle, argbuffer, argbuffer_length); }

static int lua_launch(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
if (argc != 1) return luaL_error(L, "wrong number of arguments");
#endif
const char* file = luaL_checkstring(L, 1);
HB_GetBootloaderAddresses((void**)&callBootloader, (void**)&setArgs);
if (isNinjhax2){
argbuffer[0] = 1;
snprintf((char*)&argbuffer[1], sizeof(argbuffer) - 4, "sdmc:%s", file);
argbuffer_length = 0x100;
}else HB_GetBootloaderAddresses((void**)&callBootloader, (void**)&setArgs);
fsExit();
fsInit();
FS_Archive sdmcArchive = (FS_Archive){0x9, (FS_Path){PATH_EMPTY, 1, (u8*)""}};
Expand All @@ -871,31 +875,20 @@ static int lua_launch(lua_State *L){
#ifndef SKIP_ERROR_HANDLING
if (ret) return luaL_error(L, "script doesn't exist.");
#endif
static u32 argbuffer[0x200];
argbuffer[0]=1;
snprintf((char*)&argbuffer[1], 0x200*4, "sdmc:%s", file);
setArgs(argbuffer, 0x200*4);
__system_retAddr = launchFile;
if (isNinjhax2) __system_retAddr = launchFile_2x;
else{
static u32 argbuffer_nh1[0x200];
argbuffer_nh1[0]=1;
snprintf((char*)&argbuffer_nh1[1], 0x200*4, "sdmc:%s", file);
setArgs(argbuffer_nh1, 0x200*4);
__system_retAddr = launchFile;
}
char string[20];
strcpy(string,"lpp_exit_0456432");
luaL_dostring(L, "collectgarbage()");
return luaL_error(L, string); // NOTE: This is a fake error
}

/*static int lua_launch(lua_State *L){ /* Future NH 2.x bootloader support
int argc = lua_gettop(L);
if (argc != 1) return luaL_error(L, "wrong number of arguments");
const char* file = luaL_checkstring(L, 1);
menuEntry_s me;
initMenuEntry(&me, (char*)file);
scanMenuEntry(&me);
bootApp(me.executablePath, &me.descriptor.executableMetadata, me.arg);
char string[20];
strcpy(string,"lpp_exit_0456432");
luaL_dostring(L, "collectgarbage()");
return luaL_error(L, string); // NOTE: This is a fake error
}*/

static int lua_listExtdata(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
Expand Down

0 comments on commit a34b5bf

Please sign in to comment.