Added new macros for FS and overlay access.

Now the plugin don't need to use the INITIALIZE_PLUGIN hook for fs and overlay access, but use the WUPS_FS_ACCESS()/WUPS_ALLOW_OVERLAY() macro.
This commit is contained in:
Maschell 2018-02-25 15:18:52 +01:00
parent 6ab6e0532a
commit 1024338498
14 changed files with 94 additions and 79 deletions

View File

@ -121,6 +121,8 @@ extern "C" int Menu_Main(int argc, char **argv) {
} }
if(result == APPLICATION_CLOSE_APPLY) { if(result == APPLICATION_CLOSE_APPLY) {
CallHook(WUPS_LOADER_HOOK_INIT_FS);
CallHook(WUPS_LOADER_HOOK_INIT_OVERLAY);
CallHook(WUPS_LOADER_HOOK_INIT_PLUGIN); CallHook(WUPS_LOADER_HOOK_INIT_PLUGIN);
DEBUG_FUNCTION_LINE("Loading the system menu.\n"); DEBUG_FUNCTION_LINE("Loading the system menu.\n");
DeInit(); DeInit();

View File

@ -31,9 +31,6 @@ struct rpl_handling {
const char rplname[15]; const char rplname[15];
u32 handle; u32 handle;
}; };
#define FUNCTION_PATCHER_METHOD_STORE_SIZE 7
#define STATIC_FUNCTION 0 #define STATIC_FUNCTION 0
#define DYNAMIC_FUNCTION 1 #define DYNAMIC_FUNCTION 1

View File

@ -64,21 +64,27 @@ void CallHookEx(wups_loader_hook_type_t hook_type, s32 plugin_index_needed) {
// Adding arguments! // Adding arguments!
if(func_ptr != NULL) { if(func_ptr != NULL) {
if(hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN) { if(hook_type == WUPS_LOADER_HOOK_INIT_FS) {
wups_loader_init_plugin_args_t args; wups_loader_init_fs_args_t args;
args.fs_wrapper.open_repl = (const void*)&open; args.open_repl = (const void*)&open;
args.fs_wrapper.close_repl = (const void*)&close; args.close_repl = (const void*)&close;
args.fs_wrapper.write_repl = (const void*)&write; args.write_repl = (const void*)&write;
args.fs_wrapper.read_repl = (const void*)&read; args.read_repl = (const void*)&read;
args.fs_wrapper.lseek_repl = (const void*)&lseek; args.lseek_repl = (const void*)&lseek;
args.fs_wrapper.stat_repl = (const void*)&stat; args.stat_repl = (const void*)&stat;
args.fs_wrapper.fstat_repl = (const void*)&fstat; args.fstat_repl = (const void*)&fstat;
args.fs_wrapper.opendir_repl = (const void*)&opendir; args.opendir_repl = (const void*)&opendir;
args.fs_wrapper.closedir_repl = (const void*)&closedir; args.closedir_repl = (const void*)&closedir;
args.fs_wrapper.readdir_repl = (const void*)&readdir; args.readdir_repl = (const void*)&readdir;
((void (*)(wups_loader_init_fs_args_t))((unsigned int*)func_ptr) )(args);
} else if(hook_type == WUPS_LOADER_HOOK_INIT_OVERLAY) {
wups_loader_init_overlay_args_t args;
args.overlayfunction_ptr = (const void*)&overlay_helper; args.overlayfunction_ptr = (const void*)&overlay_helper;
((void (*)(wups_loader_init_plugin_args_t))((unsigned int*)func_ptr) )(args); ((void (*)(wups_loader_init_overlay_args_t))((unsigned int*)func_ptr) )(args);
} else if(hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN) {
((void (*)(void))((unsigned int*)func_ptr) )();
} else if(hook_type == WUPS_LOADER_HOOK_DEINIT_PLUGIN) { } else if(hook_type == WUPS_LOADER_HOOK_DEINIT_PLUGIN) {
((void (*)(void))((unsigned int*)func_ptr) )(); ((void (*)(void))((unsigned int*)func_ptr) )();
} else if(hook_type == WUPS_LOADER_HOOK_STARTING_APPLICATION) { } else if(hook_type == WUPS_LOADER_HOOK_STARTING_APPLICATION) {

View File

@ -16,6 +16,15 @@ WUPS_PLUGIN_VERSION("v1.0");
WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_AUTHOR("Maschell");
WUPS_PLUGIN_LICENSE("BSD"); WUPS_PLUGIN_LICENSE("BSD");
/**
Add this to one of your projects file to have access to SD/USB.
**/
WUPS_FS_ACCESS()
/**
Add this to one of your projects file to be able to create overlays.
**/
WUPS_ALLOW_OVERLAY()
/** /**
All of this defines can be used in ANY file. All of this defines can be used in ANY file.
It's possible to split it up into multiple files. It's possible to split it up into multiple files.
@ -26,7 +35,6 @@ WUPS_PLUGIN_LICENSE("BSD");
Get's called ONCE when the loader exits, but BEFORE the ON_APPLICATION_START gets called or functions are overridden. Get's called ONCE when the loader exits, but BEFORE the ON_APPLICATION_START gets called or functions are overridden.
**/ **/
INITIALIZE_PLUGIN(){ INITIALIZE_PLUGIN(){
// Initializes overlay and fs features in the background.
InitOSFunctionPointers(); InitOSFunctionPointers();
InitSocketFunctionPointers(); InitSocketFunctionPointers();

View File

@ -15,14 +15,13 @@ WUPS_PLUGIN_VERSION("v1.0");
WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_AUTHOR("Maschell");
WUPS_PLUGIN_LICENSE("GPL"); WUPS_PLUGIN_LICENSE("GPL");
// We want access to the SDCard!
WUPS_FS_ACCESS()
#define SD_PATH "sd:" #define SD_PATH "sd:"
#define WIIU_PATH "/wiiu" #define WIIU_PATH "/wiiu"
#define DEFAULT_HID_TO_VPAD_PATH SD_PATH WIIU_PATH "/apps/hidtovpad" #define DEFAULT_HID_TO_VPAD_PATH SD_PATH WIIU_PATH "/apps/hidtovpad"
INITIALIZE_PLUGIN(){
// Needed for SD access
}
DEINITIALIZE_PLUGIN(){ DEINITIALIZE_PLUGIN(){
//CursorDrawer::destroyInstance(); //CursorDrawer::destroyInstance();
ControllerPatcher::DeInit(); ControllerPatcher::DeInit();

View File

@ -11,7 +11,6 @@ WUPS_PLUGIN_VERSION("v1.0");
WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_AUTHOR("Maschell");
WUPS_PLUGIN_LICENSE("GPL"); WUPS_PLUGIN_LICENSE("GPL");
ON_APPLICATION_START(args) { ON_APPLICATION_START(args) {
InitOSFunctionPointers(); InitOSFunctionPointers();
InitSocketFunctionPointers(); InitSocketFunctionPointers();

View File

@ -37,9 +37,10 @@ WUPS_PLUGIN_VERSION("v0.1");
WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_AUTHOR("Maschell");
WUPS_PLUGIN_LICENSE("GPL"); WUPS_PLUGIN_LICENSE("GPL");
INITIALIZE_PLUGIN(){ /*
// To init the overlay and FS To be able to create overlays
} */
WUPS_ALLOW_OVERLAY()
/* Entry point */ /* Entry point */
ON_APPLICATION_START(args){ ON_APPLICATION_START(args){
@ -52,5 +53,5 @@ ON_APPLICATION_START(args){
log_init(); log_init();
DEBUG_FUNCTION_LINE("OVERLAY TEST INIT DONE.\n"); DEBUG_FUNCTION_LINE("OVERLAYTEST INIT DONE.\n");
} }

View File

@ -20,9 +20,7 @@ WUPS_PLUGIN_VERSION("v1.0");
WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_AUTHOR("Maschell");
WUPS_PLUGIN_LICENSE("GPL"); WUPS_PLUGIN_LICENSE("GPL");
INITIALIZE_PLUGIN(){ WUPS_FS_ACCESS()
// Initializes overlay and fs features in the background.
}
ON_APPLICATION_START(args) { ON_APPLICATION_START(args) {
InitOSFunctionPointers(); InitOSFunctionPointers();

View File

@ -43,6 +43,7 @@ WUPS_PLUGIN_VERSION("v1.0");
WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_AUTHOR("Maschell");
WUPS_PLUGIN_LICENSE("GPL"); WUPS_PLUGIN_LICENSE("GPL");
WUPS_FS_ACCESS()
u32 SplashScreen(s32 time,s32 combotime); u32 SplashScreen(s32 time,s32 combotime);

View File

@ -21,19 +21,17 @@ static void * new_readdir_ptr __attribute__((section(".data"))) = NULL;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void WUPS_InitFS(wups_loader_init_plugin_args_t* args){ void WUPS_InitFS(wups_loader_init_fs_args_t args){
if(args != NULL){ new_open_ptr = (void*) args.open_repl;
new_open_ptr = (void*) args->fs_wrapper.open_repl; new_close_ptr = (void*) args.close_repl;
new_close_ptr = (void*) args->fs_wrapper.close_repl; new_write_ptr = (void*) args.write_repl;
new_write_ptr = (void*) args->fs_wrapper.write_repl; new_read_ptr = (void*) args.read_repl;
new_read_ptr = (void*) args->fs_wrapper.read_repl; new_lseek_ptr = (void*) args.lseek_repl;
new_lseek_ptr = (void*) args->fs_wrapper.lseek_repl; new_stat_ptr = (void*) args.stat_repl;
new_stat_ptr = (void*) args->fs_wrapper.stat_repl; new_fstat_ptr = (void*) args.fstat_repl;
new_fstat_ptr = (void*) args->fs_wrapper.fstat_repl; new_opendir_ptr = (void*) args.opendir_repl;
new_opendir_ptr = (void*) args->fs_wrapper.opendir_repl; new_closedir_ptr = (void*) args.closedir_repl;
new_closedir_ptr = (void*) args->fs_wrapper.closedir_repl; new_readdir_ptr = (void*) args.readdir_repl;
new_readdir_ptr = (void*) args->fs_wrapper.readdir_repl;
}
} }
int __real_open(const char *pathname, int flags); int __real_open(const char *pathname, int flags);

View File

@ -17,11 +17,9 @@ static void * overlayfunction_ptr __attribute__((section(".data"))) = NULL;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void WUPS_InitOverlay(wups_loader_init_plugin_args_t* args){ void WUPS_InitOverlay(wups_loader_init_overlay_args_t args){
if(args != NULL){
InitOSFunctionPointers(); InitOSFunctionPointers();
overlayfunction_ptr = (void*) args->overlayfunction_ptr; overlayfunction_ptr = (void*) args.overlayfunction_ptr;
}
} }
void WUPS_Overlay_PrintTextOnScreen(wups_overlay_options_type_t screen, int x,int y, const char * msg, ...){ void WUPS_Overlay_PrintTextOnScreen(wups_overlay_options_type_t screen, int x,int y, const char * msg, ...){

View File

@ -101,7 +101,6 @@ typedef enum wups_loader_library_type_t {
WUPS_LOADER_LIBRARY_ZLIB125, WUPS_LOADER_LIBRARY_ZLIB125,
} wups_loader_library_type_t; } wups_loader_library_type_t;
typedef enum wups_loader_entry_type_t { typedef enum wups_loader_entry_type_t {
WUPS_LOADER_ENTRY_FUNCTION, WUPS_LOADER_ENTRY_FUNCTION,
WUPS_LOADER_ENTRY_FUNCTION_MANDATORY, WUPS_LOADER_ENTRY_FUNCTION_MANDATORY,

View File

@ -18,22 +18,24 @@
#ifndef WUPS_HOOKS_DEF_H_ #ifndef WUPS_HOOKS_DEF_H_
#define WUPS_HOOKS_DEF_H_ #define WUPS_HOOKS_DEF_H_
#include "common.h"
#include <dynamic_libs/os_types.h> #include <dynamic_libs/os_types.h>
#include "common.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define WUPS_HOOK_EX(type_def,original_func) \ #define WUPS_HOOK_EX(type_def,original_func) \
extern const wups_loader_hook_t wups_hooks_ ## original_func \ extern const wups_loader_hook_t wups_hooks_ ## original_func WUPS_SECTION("hooks"); \
WUPS_SECTION("hooks"); \
const wups_loader_hook_t wups_hooks_ ## original_func = { \ const wups_loader_hook_t wups_hooks_ ## original_func = { \
.type = type_def, \ .type = type_def, \
.target = (const void*)&(original_func) \ .target = (const void*)&(original_func) \
} }
typedef enum wups_loader_hook_type_t { typedef enum wups_loader_hook_type_t {
WUPS_LOADER_HOOK_INIT_FS, /* Only for internal usage */
WUPS_LOADER_HOOK_INIT_OVERLAY, /* Only for internal usage */
WUPS_LOADER_HOOK_INIT_PLUGIN, /* Called when exiting the plugin loader */ WUPS_LOADER_HOOK_INIT_PLUGIN, /* Called when exiting the plugin loader */
WUPS_LOADER_HOOK_DEINIT_PLUGIN, /* Called when re-entering the plugin loader */ WUPS_LOADER_HOOK_DEINIT_PLUGIN, /* Called when re-entering the plugin loader */
WUPS_LOADER_HOOK_STARTING_APPLICATION, /* Called when an application gets started */ WUPS_LOADER_HOOK_STARTING_APPLICATION, /* Called when an application gets started */
@ -54,8 +56,11 @@ typedef enum wups_loader_app_status_t {
WUPS_APP_STATUS_UNKNOWN, /* Unknown status _should_ never happen.*/ WUPS_APP_STATUS_UNKNOWN, /* Unknown status _should_ never happen.*/
} wups_loader_app_status_t; } wups_loader_app_status_t;
typedef struct wups_loader_init_plugin_args_t { typedef struct wups_loader_init_overlay_args_t {
struct { const void * overlayfunction_ptr;
} wups_loader_init_overlay_args_t;
typedef struct wups_loader_init_fs_args_t {
const void * open_repl; const void * open_repl;
const void * close_repl; const void * close_repl;
const void * write_repl; const void * write_repl;
@ -66,9 +71,8 @@ typedef struct wups_loader_init_plugin_args_t {
const void * opendir_repl; const void * opendir_repl;
const void * closedir_repl; const void * closedir_repl;
const void * readdir_repl; const void * readdir_repl;
} fs_wrapper; } wups_loader_init_fs_args_t;
const void * overlayfunction_ptr;
} wups_loader_init_plugin_args_t;
typedef struct wups_loader_app_started_args_t { typedef struct wups_loader_app_started_args_t {
bool sd_mounted; bool sd_mounted;
@ -76,19 +80,24 @@ typedef struct wups_loader_app_started_args_t {
} wups_loader_app_started_args_t; } wups_loader_app_started_args_t;
#define INITIALIZE_PLUGIN() \ #define WUPS_FS_ACCESS() \
void init_plugin(wups_loader_init_plugin_args_t*);\ void init_fs(wups_loader_init_fs_args_t);\
void myInit_plugin(void);\ WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_FS,init_fs); \
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_PLUGIN,init_plugin); \ void init_fs(wups_loader_init_fs_args_t args){ \
void init_plugin(wups_loader_init_plugin_args_t* args){ \
if(args != NULL){\
WUPS_InitFS(args);\ WUPS_InitFS(args);\
}
#define WUPS_ALLOW_OVERLAY() \
void init_overlay(wups_loader_init_overlay_args_t);\
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_OVERLAY,init_overlay); \
void init_overlay(wups_loader_init_overlay_args_t args){ \
WUPS_InitOverlay(args);\ WUPS_InitOverlay(args);\
\ }
}\
myInit_plugin();\ #define INITIALIZE_PLUGIN() \
} \ void init_plugin(void);\
void myInit_plugin() WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_PLUGIN,init_plugin); \
void init_plugin()
#define DEINITIALIZE_PLUGIN() \ #define DEINITIALIZE_PLUGIN() \
void deinit_plugin(void);\ void deinit_plugin(void);\

View File

@ -37,8 +37,8 @@ typedef void (*overlay_callback)(wups_overlay_options_type_t);
/* /*
Gets called by the framework Gets called by the framework
*/ */
void WUPS_InitFS(wups_loader_init_plugin_args_t* args); void WUPS_InitFS(wups_loader_init_fs_args_t args);
void WUPS_InitOverlay(wups_loader_init_plugin_args_t* args); void WUPS_InitOverlay(wups_loader_init_overlay_args_t args);
/* /*
Can be called by the user. Can be called by the user.