mirror of
https://github.com/Fledge68/WiiFlow_Lite.git
synced 2024-12-25 19:31:58 +01:00
b47b04629f
returns to wiiflow using the wiiflow loader channel if enabled, added option to disable this too, return_to_wiiflow in HOMEBREW section in wiiflow.ini -added possibility to start movies via MplayerCE, use this ini: http://dl.dropbox.com/u/25620767/mplayerce.ini
139 lines
2.8 KiB
C++
139 lines
2.8 KiB
C++
#include <gccore.h>
|
|
#include <ogcsys.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <ogc/machine/processor.h>
|
|
#include <vector>
|
|
#include <string>
|
|
#include "smartptr.hpp"
|
|
#include "gecko.h"
|
|
|
|
#define EXECUTE_ADDR ((u8 *) 0x92000000)
|
|
#define BOOTER_ADDR ((u8 *) 0x93000000)
|
|
#define ARGS_ADDR ((u8 *) 0x93200000)
|
|
|
|
using namespace std;
|
|
|
|
extern const u8 app_booter_bin[];
|
|
extern const u32 app_booter_bin_size;
|
|
|
|
extern const u8 stub_bin[];
|
|
extern const u32 stub_bin_size;
|
|
|
|
typedef void (*entrypoint) (void);
|
|
extern "C" { void __exception_closeall(); }
|
|
|
|
static u8 *homebrewbuffer = EXECUTE_ADDR;
|
|
static u32 homebrewsize = 0;
|
|
static vector<string> Arguments;
|
|
|
|
bool IsDollZ (u8 *buff)
|
|
{
|
|
u8 dollz_stamp[] = {0x3C};
|
|
int dollz_offs = 0x100;
|
|
|
|
int ret = memcmp (&buff[dollz_offs], dollz_stamp, sizeof(dollz_stamp));
|
|
if (ret == 0)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
void AddBootArgument(const char * argv)
|
|
{
|
|
string arg(argv);
|
|
Arguments.push_back(arg);
|
|
}
|
|
|
|
int LoadHomebrew(const char *filepath)
|
|
{
|
|
if(!filepath)
|
|
return -1;
|
|
|
|
FILE *file = fopen(filepath ,"rb");
|
|
if(!file)
|
|
return -2;
|
|
|
|
fseek(file, 0, SEEK_END);
|
|
u32 filesize = ftell(file);
|
|
rewind(file);
|
|
|
|
fread(homebrewbuffer, 1, filesize, file);
|
|
fclose(file);
|
|
|
|
homebrewsize += filesize;
|
|
return 1;
|
|
}
|
|
|
|
static int SetupARGV(struct __argv * args)
|
|
{
|
|
if(!args)
|
|
return -1;
|
|
|
|
bzero(args, sizeof(struct __argv));
|
|
args->argvMagic = ARGV_MAGIC;
|
|
|
|
u32 argc = 0;
|
|
u32 position = 0;
|
|
u32 stringlength = 1;
|
|
|
|
/** Append Arguments **/
|
|
for(u32 i = 0; i < Arguments.size(); i++)
|
|
stringlength += Arguments[i].size()+1;
|
|
|
|
args->length = stringlength;
|
|
//! Put the argument into mem2 too, to avoid overwriting it
|
|
args->commandLine = (char *) ARGS_ADDR + sizeof(struct __argv);
|
|
|
|
/** Append Arguments **/
|
|
for(u32 i = 0; i < Arguments.size(); i++)
|
|
{
|
|
strcpy(&args->commandLine[position], Arguments[i].c_str());
|
|
position += Arguments[i].size() + 1;
|
|
argc++;
|
|
}
|
|
|
|
args->argc = argc;
|
|
|
|
args->commandLine[args->length - 1] = '\0';
|
|
args->argv = &args->commandLine;
|
|
args->endARGV = args->argv + 1;
|
|
|
|
Arguments.clear();
|
|
|
|
return 0;
|
|
}
|
|
|
|
int BootHomebrew(bool wiiflow_stub)
|
|
{
|
|
struct __argv args;
|
|
if (!IsDollZ(homebrewbuffer))
|
|
SetupARGV(&args);
|
|
|
|
memcpy(BOOTER_ADDR, app_booter_bin, app_booter_bin_size);
|
|
DCFlushRange(BOOTER_ADDR, app_booter_bin_size);
|
|
|
|
entrypoint entry = (entrypoint)BOOTER_ADDR;
|
|
|
|
memmove(ARGS_ADDR, &args, sizeof(args));
|
|
DCFlushRange(ARGS_ADDR, sizeof(args) + args.length);
|
|
|
|
if(wiiflow_stub)
|
|
{
|
|
/* Clear low mem - the hard way :P */
|
|
memset((void*)0x80000000, 0, 0x4000);
|
|
|
|
/* Copy stub into memory */
|
|
memcpy((void*)0x80001800, stub_bin, stub_bin_size);
|
|
DCFlushRange((void*)0x80001800, stub_bin_size);
|
|
}
|
|
|
|
/* Shutdown IOS subsystems */
|
|
u32 level = IRQ_Disable();
|
|
__IOS_ShutdownSubsystems();
|
|
__exception_closeall();
|
|
entry();
|
|
IRQ_Restore(level);
|
|
return 0;
|
|
}
|