Skip to content

Commit

Permalink
- added automatic RPX fimport section parsing (big thanks to n1ghty f…
Browse files Browse the repository at this point in the history
…or providing the code for it) - added automatic pre-loading of RPLs to memory that are required during RPX linking (fimport section) - fix in default XML struct to use the RPX name from SD card - added print of XML values used for game on launch - added print of RPX/RPLs on launch and the memory they are pre-loaded (if at all than size is > 0)
  • Loading branch information
dimok789 committed Nov 18, 2015
1 parent 398773e commit e1d054f
Show file tree
Hide file tree
Showing 20 changed files with 2,558 additions and 135 deletions.
2 changes: 0 additions & 2 deletions installer/kernel_patches.S
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ KernelPatches:
lis r4, 0x48AE
ori r4, r4, 0x105A
stw r4, 0(r3)
eieio
isync

# memory barrier
eieio
Expand Down
2 changes: 1 addition & 1 deletion src/common/common.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef COMMON_H
#define COMMON_H

#define LOADIINE_VERSION "v3.0"
#define LOADIINE_VERSION "v4.0"
#define IS_USING_MII_MAKER 1

/* Loadiine common paths */
Expand Down
9 changes: 9 additions & 0 deletions src/common/fs_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,14 @@ typedef struct
char name[FS_MAX_ENTNAME_SIZE];
} FSDirEntry;

/* Async callback definition */
typedef void (*FSAsyncCallback)(void *pClient, void *pCmd, int result, void *context);
typedef struct
{
FSAsyncCallback userCallback;
void *userContext;
void *ioMsgQueue;
} FSAsyncParams;

#endif /* FS_DEFS_H */

88 changes: 36 additions & 52 deletions src/fs/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,10 @@ static int is_gamefile(const char *path) {
}

/* Note : no need to check everything, it is faster this way */
if (new_path[0] != '/') return 0;
if (new_path[1] != 'v' && new_path[1] != 'V') return 0;
// if (new_path[2] != 'o') return 0;
// if (new_path[3] != 'l') return 0;
// if (new_path[4] != '/') return 0;
if (new_path[5] != 'c' && new_path[5] != 'C') return 0;
// if (new_path[6] != 'o') return 0;
// if (new_path[7] != 'n') return 0;
// if (new_path[8] != 't') return 0;
// if (new_path[9] != 'e') return 0;
// if (new_path[10] != 'n') return 0;
if (new_path[11] != 't' && new_path[11] != 'T') return 0;
if (strncasecmp(new_path, "/vol/content", 12) == 0)
return 1;

return 1;
return 0;
}
static int is_savefile(const char *path) {

Expand All @@ -94,18 +84,10 @@ static int is_savefile(const char *path) {
new_path[len++] = *path++;
}

/* Note : no need to check everything, it is faster this way */
if (new_path[0] != '/') return 0;
// if (new_path[1] != 'v' && new_path[1] != 'V') return 0;
// if (new_path[2] != 'o') return 0;
// if (new_path[3] != 'l') return 0;
if (new_path[4] != '/') return 0;
if (new_path[5] != 's' && new_path[5] != 'S') return 0;
// if (new_path[6] != 'a') return 0;
// if (new_path[7] != 'v') return 0;
if (new_path[8] != 'e' && new_path[8] != 'E') return 0;
if (strncasecmp(new_path, "/vol/save", 9) == 0)
return 1;

return 1;
return 0;
}

static void compute_new_path(char* new_path, const char* path, int len, int is_save) {
Expand All @@ -119,6 +101,11 @@ static void compute_new_path(char* new_path, const char* path, int len, int is_s
if(path[0] != '/')
path_offset = -1;

// some games are doing /vol/content/./....
if(path[13 + path_offset] == '.' && path[14 + path_offset] == '/') {
path_offset += 2;
}

if (!is_save) {
n = strlcpy(new_path, bss.mount_base, sizeof(bss.mount_base));

Expand Down Expand Up @@ -273,7 +260,7 @@ DECL(int, FSDelClient, void *pClient) {
/* *****************************************************************************
* Replacement functions
* ****************************************************************************/
DECL(int, FSGetStat, void *pClient, void *pCmd, const char *path, void *stats, int error) {
DECL(int, FSGetStat, FSClient *pClient, FSCmdBlock *pCmd, const char *path, FSStat *stats, FSRetFlag error) {
int client = GetCurClient(pClient);
if (client != -1) {
// log
Expand Down Expand Up @@ -316,7 +303,7 @@ DECL(int, FSGetStatAsync, void *pClient, void *pCmd, const char *path, void *sta
return real_FSGetStatAsync(pClient, pCmd, path, stats, error, asyncParams);
}

DECL(int, FSOpenFile, void *pClient, void *pCmd, const char *path, const char *mode, int *handle, int error) {
DECL(FSStatus, FSOpenFile, FSClient *pClient, FSCmdBlock *pCmd, const char *path, const char *mode, int *handle, FSRetFlag error) {
/*
int client = GetCurClient(pClient);
if (client != -1) {
Expand Down Expand Up @@ -359,7 +346,7 @@ DECL(int, FSOpenFileAsync, void *pClient, void *pCmd, const char *path, const ch
return real_FSOpenFileAsync(pClient, pCmd, path, mode, handle, error, asyncParams);
}

DECL(int, FSOpenDir, void *pClient, void* pCmd, const char *path, int *handle, int error) {
DECL(int, FSOpenDir, FSClient *pClient, FSCmdBlock* pCmd, const char *path, int *handle, FSRetFlag error) {
int client = GetCurClient(pClient);
if (client != -1) {
// log
Expand Down Expand Up @@ -399,7 +386,7 @@ DECL(int, FSOpenDirAsync, void *pClient, void* pCmd, const char *path, int *hand
return real_FSOpenDirAsync(pClient, pCmd, path, handle, error, asyncParams);
}

DECL(int, FSChangeDir, void *pClient, void *pCmd, char *path, int error) {
DECL(FSStatus, FSChangeDir, FSClient *pClient, FSCmdBlock *pCmd, const char *path, FSRetFlag error) {
int client = GetCurClient(pClient);
if (client != -1) {
// log
Expand Down Expand Up @@ -440,7 +427,7 @@ DECL(int, FSChangeDirAsync, void *pClient, void *pCmd, const char *path, int err
}

// only for saves on sdcard
DECL(int, FSMakeDir, void *pClient, void *pCmd, const char *path, int error) {
DECL(FSStatus, FSMakeDir, FSClient *pClient, FSCmdBlock *pCmd, const char *path, FSRetFlag error) {
int client = GetCurClient(pClient);
if (client != -1) {
// log
Expand Down Expand Up @@ -1070,29 +1057,26 @@ const struct fs_magic_t {
// Dynamic RPL loading functions
MAKE_MAGIC(OSDynLoad_Acquire, 0x38A00000),
#if (USE_EXTRA_LOG_FUNCTIONS == 1)
MAKE_MAGIC(OSDynLoad_GetModuleName),
MAKE_MAGIC(OSDynLoad_IsModuleLoaded),
#endif

// Log functions
#if (USE_EXTRA_LOG_FUNCTIONS == 1)
MAKE_MAGIC(FSCloseFile_log),
MAKE_MAGIC(FSCloseDir_log),
MAKE_MAGIC(FSFlushFile_log),
MAKE_MAGIC(FSGetErrorCodeForViewer_log),
MAKE_MAGIC(FSGetLastError_log),
MAKE_MAGIC(FSGetPosFile_log),
MAKE_MAGIC(FSGetStatFile_log),
MAKE_MAGIC(FSIsEof_log),
MAKE_MAGIC(FSReadDir_log),
MAKE_MAGIC(FSReadFile_log),
MAKE_MAGIC(FSReadFileWithPos_log),
MAKE_MAGIC(FSSetPosFile_log),
MAKE_MAGIC(FSSetStateChangeNotification_log),
MAKE_MAGIC(FSTruncateFile_log),
MAKE_MAGIC(FSWriteFile_log),
MAKE_MAGIC(FSWriteFileWithPos_log),
MAKE_MAGIC(FSGetVolumeState_log),
MAKE_MAGIC(OSDynLoad_GetModuleName, 0x9421FFD0),
MAKE_MAGIC(OSDynLoad_IsModuleLoaded, 0x38A00001),

MAKE_MAGIC(FSCloseFile_log, 0x7C0802A6),
MAKE_MAGIC(FSCloseDir_log, 0x7C0802A6),
MAKE_MAGIC(FSFlushFile_log, 0x7C0802A6),
MAKE_MAGIC(FSGetErrorCodeForViewer_log, 0x9421FEF8),
MAKE_MAGIC(FSGetLastError_log, 0x7C0802A6),
MAKE_MAGIC(FSGetPosFile_log, 0x9421FFD8),
MAKE_MAGIC(FSGetStatFile_log, 0x9421FFD8),
MAKE_MAGIC(FSIsEof_log, 0x7C0802A6),
MAKE_MAGIC(FSReadDir_log, 0x9421FFD8),
MAKE_MAGIC(FSReadFile_log, 0x9421FFC8),
MAKE_MAGIC(FSReadFileWithPos_log, 0x9421FFC0),
MAKE_MAGIC(FSSetPosFile_log, 0x9421FFD8),
MAKE_MAGIC(FSSetStateChangeNotification_log, 0x7C0802A6),
MAKE_MAGIC(FSTruncateFile_log, 0x7C0802A6),
MAKE_MAGIC(FSWriteFile_log, 0x9421FFC8),
MAKE_MAGIC(FSWriteFileWithPos_log, 0x9421FFC0),
MAKE_MAGIC(FSGetVolumeState_log, 0x7C0802A6),
#endif
};

Expand Down
17 changes: 1 addition & 16 deletions src/fs/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,13 @@
#define _FS_H_

#include "../common/fs_defs.h"
#include "fs_functions.h"

extern void GX2WaitForVsync(void);

/* OS stuff */
extern void DCFlushRange(const void *p, unsigned int s);

/* SDCard functions */
extern FSStatus FSGetMountSource(void *pClient, void *pCmd, FSSourceType type, FSMountSource *source, FSRetFlag errHandling);
extern FSStatus FSMount(void *pClient, void *pCmd, FSMountSource *source, char *target, uint bytes, FSRetFlag errHandling);
extern FSStatus FSReadFile(FSClient *pClient, FSCmdBlock *pCmd, void *buffer, int size, int count, int fd, FSFlag flag, FSRetFlag errHandling);
extern void FSInitCmdBlock(FSCmdBlock *pCmd);
extern FSStatus FSCloseFile(FSClient *pClient, FSCmdBlock *pCmd, int fd, int error);

/* Async callback definition */
typedef void (*FSAsyncCallback)(void *pClient, void *pCmd, int result, void *context);
typedef struct
{
FSAsyncCallback userCallback;
void *userContext;
void *ioMsgQueue;
} FSAsyncParams;

/* Forward declarations */
#define MAX_CLIENT 32

Expand Down
25 changes: 25 additions & 0 deletions src/fs/fs_functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef __FS_FUNCTIONS_H_
#define __FS_FUNCTIONS_H_

#include "../common/fs_defs.h"

/* FS Functions */
extern FSStatus FSInit(void);
extern FSStatus FSAddClient(FSClient *pClient, FSRetFlag errHandling);
extern void FSInitCmdBlock(FSCmdBlock *pCmd);
extern FSStatus FSGetMountSource(FSClient *pClient, FSCmdBlock *pCmd, FSSourceType type, FSMountSource *source, FSRetFlag errHandling);
extern FSStatus FSMount(FSClient *pClient, FSCmdBlock *pCmd, FSMountSource *source, const char *target, uint32_t bytes, FSRetFlag errHandling);
extern FSStatus FSUnmount(FSClient *pClient, FSCmdBlock *pCmd, const char *target, FSRetFlag errHandling);
extern FSStatus FSOpenDir(FSClient *pClient, FSCmdBlock *pCmd, const char *path, int *dh, FSRetFlag errHandling);
extern FSStatus FSReadDir(FSClient *pClient, FSCmdBlock *pCmd, int dh, FSDirEntry *dir_entry, FSRetFlag errHandling);
extern FSStatus FSRewindDir(FSClient *pClient, FSCmdBlock *pCmd, int dh, FSRetFlag errHandling);
extern FSStatus FSOpenFile(FSClient *pClient, FSCmdBlock *pCmd, const char *path, const char *mode, int *fd, FSRetFlag errHandling);
extern FSStatus FSReadFile(FSClient *pClient, FSCmdBlock *pCmd, void *buffer, int size, int count, int fd, FSFlag flag, FSRetFlag errHandling);
extern FSStatus FSChangeDir(FSClient *pClient, FSCmdBlock *pCmd, const char *path, FSRetFlag errHandling);
extern FSStatus FSMakeDir(FSClient *pClient, FSCmdBlock *pCmd, const char *path, FSRetFlag errHandling);
extern FSStatus FSCloseDir(FSClient *pClient, FSCmdBlock *pCmd, int dh, FSRetFlag errHandling);
extern FSStatus FSCloseFile(FSClient *pClient, FSCmdBlock *pCmd, int fd, FSRetFlag errHandling);
extern FSStatus FSGetStat(FSClient *pClient, FSCmdBlock *pCmd, const char *path, FSStat *stats, FSRetFlag errHandling);


#endif // __FS_FUNCTIONS_H_
5 changes: 2 additions & 3 deletions src/kernel/kernel_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ void my_PrepareTitle(CosAppXmlInfo *xmlKernelInfo)
asm volatile("eieio; isync");


//! TODO: add Smash Bros IDs for the check?
// check for Mii Maker ID (region independent check)
if(GAME_LAUNCHED && (xmlKernelInfo->title_id & 0xFFFFFFFFFFFFF0FF) == 0x000500101004A000)
// check for Mii Maker RPX or Smash Bros RPX when we started (region independent check)
if(GAME_LAUNCHED && ((strncasecmp("ffl_app.rpx", xmlKernelInfo->rpx_name, FS_MAX_ENTNAME_SIZE) == 0) || (strncasecmp("cross_f.rpx", xmlKernelInfo->rpx_name, FS_MAX_ENTNAME_SIZE) == 0)))
{
//! Copy all data from the parsed XML info
strlcpy(xmlKernelInfo->rpx_name, cosAppXmlInfoStruct.rpx_name, sizeof(cosAppXmlInfoStruct.rpx_name));
Expand Down
1 change: 1 addition & 0 deletions src/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ PROVIDE(FSRollbackQuotaAsync = 0x0106bb50);

/* FS methods - not replaced */
PROVIDE(FSReadDir = 0x0106f780);
PROVIDE(FSRewindDir = 0x0106F7F0);
PROVIDE(FSReadFile = 0x106f108);
PROVIDE(FSCloseFile = 0x106f088);
PROVIDE(FSCloseDir = 0x0106f700);
Expand Down
Loading

0 comments on commit e1d054f

Please sign in to comment.