From 102433849861c77103c593082fec77bd7362234a Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 25 Feb 2018 15:18:52 +0100 Subject: [PATCH] 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. --- loader/src/main.cpp | 2 + loader/src/patcher/function_patcher.h | 3 -- loader/src/utils.cpp | 32 +++++++------ plugins/example_plugin/src/main.cpp | 10 +++- plugins/hid_to_vpad/src/main.cpp | 7 ++- plugins/memory_info/src/main.c | 1 - plugins/overlay/src/main.cpp | 9 ++-- plugins/sdcafiine/src/main.cpp | 4 +- plugins/swipswapme/src/main.cpp | 1 + src/fs_function_wrapper.c | 24 +++++----- src/overlay.c | 8 ++-- wups_include/function_patching.h | 1 - wups_include/hooks.h | 67 +++++++++++++++------------ wups_include/utils.h | 4 +- 14 files changed, 94 insertions(+), 79 deletions(-) diff --git a/loader/src/main.cpp b/loader/src/main.cpp index e8b4c32..6f39840 100644 --- a/loader/src/main.cpp +++ b/loader/src/main.cpp @@ -121,6 +121,8 @@ extern "C" int Menu_Main(int argc, char **argv) { } if(result == APPLICATION_CLOSE_APPLY) { + CallHook(WUPS_LOADER_HOOK_INIT_FS); + CallHook(WUPS_LOADER_HOOK_INIT_OVERLAY); CallHook(WUPS_LOADER_HOOK_INIT_PLUGIN); DEBUG_FUNCTION_LINE("Loading the system menu.\n"); DeInit(); diff --git a/loader/src/patcher/function_patcher.h b/loader/src/patcher/function_patcher.h index e54881e..64e02a1 100644 --- a/loader/src/patcher/function_patcher.h +++ b/loader/src/patcher/function_patcher.h @@ -31,9 +31,6 @@ struct rpl_handling { const char rplname[15]; u32 handle; }; - -#define FUNCTION_PATCHER_METHOD_STORE_SIZE 7 - #define STATIC_FUNCTION 0 #define DYNAMIC_FUNCTION 1 diff --git a/loader/src/utils.cpp b/loader/src/utils.cpp index 47a2925..67b598a 100644 --- a/loader/src/utils.cpp +++ b/loader/src/utils.cpp @@ -64,21 +64,27 @@ void CallHookEx(wups_loader_hook_type_t hook_type, s32 plugin_index_needed) { // Adding arguments! if(func_ptr != NULL) { - if(hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN) { - wups_loader_init_plugin_args_t args; - args.fs_wrapper.open_repl = (const void*)&open; - args.fs_wrapper.close_repl = (const void*)&close; - args.fs_wrapper.write_repl = (const void*)&write; - args.fs_wrapper.read_repl = (const void*)&read; - args.fs_wrapper.lseek_repl = (const void*)&lseek; - args.fs_wrapper.stat_repl = (const void*)&stat; - args.fs_wrapper.fstat_repl = (const void*)&fstat; - args.fs_wrapper.opendir_repl = (const void*)&opendir; - args.fs_wrapper.closedir_repl = (const void*)&closedir; - args.fs_wrapper.readdir_repl = (const void*)&readdir; + if(hook_type == WUPS_LOADER_HOOK_INIT_FS) { + wups_loader_init_fs_args_t args; + args.open_repl = (const void*)&open; + args.close_repl = (const void*)&close; + args.write_repl = (const void*)&write; + args.read_repl = (const void*)&read; + args.lseek_repl = (const void*)&lseek; + args.stat_repl = (const void*)&stat; + args.fstat_repl = (const void*)&fstat; + args.opendir_repl = (const void*)&opendir; + args.closedir_repl = (const void*)&closedir; + 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; - ((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) { ((void (*)(void))((unsigned int*)func_ptr) )(); } else if(hook_type == WUPS_LOADER_HOOK_STARTING_APPLICATION) { diff --git a/plugins/example_plugin/src/main.cpp b/plugins/example_plugin/src/main.cpp index b300e49..7b2e530 100644 --- a/plugins/example_plugin/src/main.cpp +++ b/plugins/example_plugin/src/main.cpp @@ -16,6 +16,15 @@ WUPS_PLUGIN_VERSION("v1.0"); WUPS_PLUGIN_AUTHOR("Maschell"); 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. 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. **/ INITIALIZE_PLUGIN(){ - // Initializes overlay and fs features in the background. InitOSFunctionPointers(); InitSocketFunctionPointers(); diff --git a/plugins/hid_to_vpad/src/main.cpp b/plugins/hid_to_vpad/src/main.cpp index af90fda..ebb3e66 100644 --- a/plugins/hid_to_vpad/src/main.cpp +++ b/plugins/hid_to_vpad/src/main.cpp @@ -15,14 +15,13 @@ WUPS_PLUGIN_VERSION("v1.0"); WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_LICENSE("GPL"); +// We want access to the SDCard! +WUPS_FS_ACCESS() + #define SD_PATH "sd:" #define WIIU_PATH "/wiiu" #define DEFAULT_HID_TO_VPAD_PATH SD_PATH WIIU_PATH "/apps/hidtovpad" -INITIALIZE_PLUGIN(){ - // Needed for SD access -} - DEINITIALIZE_PLUGIN(){ //CursorDrawer::destroyInstance(); ControllerPatcher::DeInit(); diff --git a/plugins/memory_info/src/main.c b/plugins/memory_info/src/main.c index 26a375a..64c5b6d 100644 --- a/plugins/memory_info/src/main.c +++ b/plugins/memory_info/src/main.c @@ -11,7 +11,6 @@ WUPS_PLUGIN_VERSION("v1.0"); WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_LICENSE("GPL"); - ON_APPLICATION_START(args) { InitOSFunctionPointers(); InitSocketFunctionPointers(); diff --git a/plugins/overlay/src/main.cpp b/plugins/overlay/src/main.cpp index 85c6e3d..e5bb55c 100644 --- a/plugins/overlay/src/main.cpp +++ b/plugins/overlay/src/main.cpp @@ -37,9 +37,10 @@ WUPS_PLUGIN_VERSION("v0.1"); WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_LICENSE("GPL"); -INITIALIZE_PLUGIN(){ - // To init the overlay and FS -} +/* + To be able to create overlays +*/ +WUPS_ALLOW_OVERLAY() /* Entry point */ ON_APPLICATION_START(args){ @@ -52,5 +53,5 @@ ON_APPLICATION_START(args){ log_init(); - DEBUG_FUNCTION_LINE("OVERLAY TEST INIT DONE.\n"); + DEBUG_FUNCTION_LINE("OVERLAYTEST INIT DONE.\n"); } \ No newline at end of file diff --git a/plugins/sdcafiine/src/main.cpp b/plugins/sdcafiine/src/main.cpp index 5c790ba..6983e57 100644 --- a/plugins/sdcafiine/src/main.cpp +++ b/plugins/sdcafiine/src/main.cpp @@ -20,9 +20,7 @@ WUPS_PLUGIN_VERSION("v1.0"); WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_LICENSE("GPL"); -INITIALIZE_PLUGIN(){ - // Initializes overlay and fs features in the background. -} +WUPS_FS_ACCESS() ON_APPLICATION_START(args) { InitOSFunctionPointers(); diff --git a/plugins/swipswapme/src/main.cpp b/plugins/swipswapme/src/main.cpp index ed42640..7a89544 100644 --- a/plugins/swipswapme/src/main.cpp +++ b/plugins/swipswapme/src/main.cpp @@ -43,6 +43,7 @@ WUPS_PLUGIN_VERSION("v1.0"); WUPS_PLUGIN_AUTHOR("Maschell"); WUPS_PLUGIN_LICENSE("GPL"); +WUPS_FS_ACCESS() u32 SplashScreen(s32 time,s32 combotime); diff --git a/src/fs_function_wrapper.c b/src/fs_function_wrapper.c index b98ec1b..a906119 100644 --- a/src/fs_function_wrapper.c +++ b/src/fs_function_wrapper.c @@ -21,19 +21,17 @@ static void * new_readdir_ptr __attribute__((section(".data"))) = NULL; #ifdef __cplusplus extern "C" { #endif - void WUPS_InitFS(wups_loader_init_plugin_args_t* args){ - if(args != NULL){ - new_open_ptr = (void*) args->fs_wrapper.open_repl; - new_close_ptr = (void*) args->fs_wrapper.close_repl; - new_write_ptr = (void*) args->fs_wrapper.write_repl; - new_read_ptr = (void*) args->fs_wrapper.read_repl; - new_lseek_ptr = (void*) args->fs_wrapper.lseek_repl; - new_stat_ptr = (void*) args->fs_wrapper.stat_repl; - new_fstat_ptr = (void*) args->fs_wrapper.fstat_repl; - new_opendir_ptr = (void*) args->fs_wrapper.opendir_repl; - new_closedir_ptr = (void*) args->fs_wrapper.closedir_repl; - new_readdir_ptr = (void*) args->fs_wrapper.readdir_repl; - } + void WUPS_InitFS(wups_loader_init_fs_args_t args){ + new_open_ptr = (void*) args.open_repl; + new_close_ptr = (void*) args.close_repl; + new_write_ptr = (void*) args.write_repl; + new_read_ptr = (void*) args.read_repl; + new_lseek_ptr = (void*) args.lseek_repl; + new_stat_ptr = (void*) args.stat_repl; + new_fstat_ptr = (void*) args.fstat_repl; + new_opendir_ptr = (void*) args.opendir_repl; + new_closedir_ptr = (void*) args.closedir_repl; + new_readdir_ptr = (void*) args.readdir_repl; } int __real_open(const char *pathname, int flags); diff --git a/src/overlay.c b/src/overlay.c index 97efb9b..f54aafc 100644 --- a/src/overlay.c +++ b/src/overlay.c @@ -17,11 +17,9 @@ static void * overlayfunction_ptr __attribute__((section(".data"))) = NULL; #ifdef __cplusplus extern "C" { #endif - void WUPS_InitOverlay(wups_loader_init_plugin_args_t* args){ - if(args != NULL){ - InitOSFunctionPointers(); - overlayfunction_ptr = (void*) args->overlayfunction_ptr; - } + void WUPS_InitOverlay(wups_loader_init_overlay_args_t args){ + InitOSFunctionPointers(); + overlayfunction_ptr = (void*) args.overlayfunction_ptr; } void WUPS_Overlay_PrintTextOnScreen(wups_overlay_options_type_t screen, int x,int y, const char * msg, ...){ diff --git a/wups_include/function_patching.h b/wups_include/function_patching.h index d63031b..910a368 100644 --- a/wups_include/function_patching.h +++ b/wups_include/function_patching.h @@ -101,7 +101,6 @@ typedef enum wups_loader_library_type_t { WUPS_LOADER_LIBRARY_ZLIB125, } wups_loader_library_type_t; - typedef enum wups_loader_entry_type_t { WUPS_LOADER_ENTRY_FUNCTION, WUPS_LOADER_ENTRY_FUNCTION_MANDATORY, diff --git a/wups_include/hooks.h b/wups_include/hooks.h index f05934c..575353c 100644 --- a/wups_include/hooks.h +++ b/wups_include/hooks.h @@ -18,24 +18,26 @@ #ifndef WUPS_HOOKS_DEF_H_ #define WUPS_HOOKS_DEF_H_ -#include "common.h" #include +#include "common.h" #ifdef __cplusplus extern "C" { #endif #define WUPS_HOOK_EX(type_def,original_func) \ - extern const wups_loader_hook_t wups_hooks_ ## original_func \ - WUPS_SECTION("hooks"); \ + extern const wups_loader_hook_t wups_hooks_ ## original_func WUPS_SECTION("hooks"); \ const wups_loader_hook_t wups_hooks_ ## original_func = { \ .type = type_def, \ .target = (const void*)&(original_func) \ } 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_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_ENDING_APPLICATION, /* Called when an application ends */ WUPS_LOADER_HOOK_VSYNC, /* Called when an application calls GX2WaitForVsync (most times each frame) */ @@ -54,21 +56,23 @@ typedef enum wups_loader_app_status_t { WUPS_APP_STATUS_UNKNOWN, /* Unknown status _should_ never happen.*/ } wups_loader_app_status_t; -typedef struct wups_loader_init_plugin_args_t { - struct { - const void * open_repl; - const void * close_repl; - const void * write_repl; - const void * read_repl; - const void * lseek_repl; - const void * stat_repl; - const void * fstat_repl; - const void * opendir_repl; - const void * closedir_repl; - const void * readdir_repl; - } fs_wrapper; +typedef struct wups_loader_init_overlay_args_t { const void * overlayfunction_ptr; -} wups_loader_init_plugin_args_t; +} wups_loader_init_overlay_args_t; + +typedef struct wups_loader_init_fs_args_t { + const void * open_repl; + const void * close_repl; + const void * write_repl; + const void * read_repl; + const void * lseek_repl; + const void * stat_repl; + const void * fstat_repl; + const void * opendir_repl; + const void * closedir_repl; + const void * readdir_repl; +} wups_loader_init_fs_args_t; + typedef struct wups_loader_app_started_args_t { bool sd_mounted; @@ -76,19 +80,24 @@ typedef struct wups_loader_app_started_args_t { } wups_loader_app_started_args_t; +#define WUPS_FS_ACCESS() \ + void init_fs(wups_loader_init_fs_args_t);\ + WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_FS,init_fs); \ + void init_fs(wups_loader_init_fs_args_t 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);\ + } + #define INITIALIZE_PLUGIN() \ - void init_plugin(wups_loader_init_plugin_args_t*);\ - void myInit_plugin(void);\ + void init_plugin(void);\ WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_PLUGIN,init_plugin); \ - void init_plugin(wups_loader_init_plugin_args_t* args){ \ - if(args != NULL){\ - WUPS_InitFS(args);\ - WUPS_InitOverlay(args);\ - \ - }\ - myInit_plugin();\ - } \ - void myInit_plugin() + void init_plugin() #define DEINITIALIZE_PLUGIN() \ void deinit_plugin(void);\ diff --git a/wups_include/utils.h b/wups_include/utils.h index 4178870..64e93c9 100644 --- a/wups_include/utils.h +++ b/wups_include/utils.h @@ -37,8 +37,8 @@ typedef void (*overlay_callback)(wups_overlay_options_type_t); /* Gets called by the framework */ -void WUPS_InitFS(wups_loader_init_plugin_args_t* args); -void WUPS_InitOverlay(wups_loader_init_plugin_args_t* args); +void WUPS_InitFS(wups_loader_init_fs_args_t args); +void WUPS_InitOverlay(wups_loader_init_overlay_args_t args); /* Can be called by the user.