2018-06-28 22:27:25 +02:00
|
|
|
#include <wups.h>
|
2019-11-18 11:50:03 +01:00
|
|
|
#include <whb/libmanager.h>
|
2018-06-28 22:27:25 +02:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <utils/logger.h>
|
2019-11-18 11:50:03 +01:00
|
|
|
#include <coreinit/time.h>
|
|
|
|
#include <coreinit/thread.h>
|
2018-06-28 22:27:25 +02:00
|
|
|
#include <coreinit/filesystem.h>
|
2021-11-06 23:31:22 +01:00
|
|
|
#include <whb/log_cafe.h>
|
|
|
|
#include <whb/log_module.h>
|
2020-12-16 15:10:17 +01:00
|
|
|
#include <whb/log_udp.h>
|
2021-09-24 19:57:15 +02:00
|
|
|
#include <wups/config/WUPSConfigItemBoolean.h>
|
2018-06-28 22:27:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Mandatory plugin information.
|
|
|
|
If not set correctly, the loader will refuse to use the plugin.
|
|
|
|
**/
|
|
|
|
WUPS_PLUGIN_NAME("Example plugin");
|
|
|
|
WUPS_PLUGIN_DESCRIPTION("This is just an example plugin and will log the FSOpenFile function.");
|
|
|
|
WUPS_PLUGIN_VERSION("v1.0");
|
|
|
|
WUPS_PLUGIN_AUTHOR("Maschell");
|
|
|
|
WUPS_PLUGIN_LICENSE("BSD");
|
|
|
|
|
|
|
|
/**
|
2019-11-18 11:50:03 +01:00
|
|
|
All of this defines can be used in ANY file.
|
|
|
|
It's possible to split it up into multiple files.
|
|
|
|
|
2018-06-28 22:27:25 +02:00
|
|
|
**/
|
2019-11-18 11:50:03 +01:00
|
|
|
|
2021-10-01 17:24:45 +02:00
|
|
|
WUPS_USE_WUT_DEVOPTAB(); // Use the wut devoptabs
|
|
|
|
WUPS_USE_STORAGE("example_plugin"); // Use the storage API
|
2021-09-24 19:57:15 +02:00
|
|
|
|
|
|
|
bool logFSOpen = true;
|
2019-11-18 11:50:03 +01:00
|
|
|
|
2018-06-28 22:27:25 +02:00
|
|
|
/**
|
|
|
|
Get's called ONCE when the loader exits, but BEFORE the ON_APPLICATION_START gets called or functions are overridden.
|
|
|
|
**/
|
|
|
|
INITIALIZE_PLUGIN(){
|
2021-11-06 23:31:22 +01:00
|
|
|
if (!WHBLogModuleInit()) {
|
|
|
|
WHBLogCafeInit();
|
|
|
|
WHBLogUdpInit();
|
|
|
|
}
|
2020-12-16 15:10:17 +01:00
|
|
|
DEBUG_FUNCTION_LINE("INITIALIZE_PLUGIN of example_plugin!");
|
2021-09-24 19:57:15 +02:00
|
|
|
|
|
|
|
// Open storage to read values
|
|
|
|
WUPS_OpenStorage();
|
|
|
|
|
|
|
|
// Try to get value from storage
|
|
|
|
if(WUPS_GetBool(nullptr, "logFSOpen", &logFSOpen) != WUPS_STORAGE_ERROR_SUCCESS){
|
|
|
|
// Add the value to the storage if it's missing.
|
|
|
|
WUPS_StoreBool(nullptr, "logFSOpen", logFSOpen);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close storage
|
|
|
|
WUPS_CloseStorage();
|
2018-06-28 22:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets called when the plugin loader is re-entered => when the plugin is unloaded.
|
|
|
|
The overridden functions are restored before this is getting called.
|
|
|
|
**/
|
2020-12-16 15:10:17 +01:00
|
|
|
DEINITIALIZE_PLUGIN(){
|
|
|
|
DEBUG_FUNCTION_LINE("DEINITIALIZE_PLUGIN of example_plugin!");
|
2018-06-28 22:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets called when an application starts.
|
|
|
|
This is called BEFORE the functions are overridden.
|
|
|
|
Make sure to initialize all functions you're using in the overridden functions!
|
|
|
|
**/
|
|
|
|
ON_APPLICATION_START(){
|
2021-11-06 23:31:22 +01:00
|
|
|
if (!WHBLogModuleInit()) {
|
|
|
|
WHBLogCafeInit();
|
|
|
|
WHBLogUdpInit();
|
|
|
|
}
|
2018-06-28 22:27:25 +02:00
|
|
|
|
2020-12-16 15:10:17 +01:00
|
|
|
DEBUG_FUNCTION_LINE("ON_APPLICATION_START of example_plugin!");
|
2018-06-28 22:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-06 12:32:44 +02:00
|
|
|
Gets called when an application request to exit.
|
2018-06-28 22:27:25 +02:00
|
|
|
**/
|
2021-04-06 12:32:44 +02:00
|
|
|
ON_APPLICATION_REQUESTS_EXIT(){
|
|
|
|
DEBUG_FUNCTION_LINE("ON_APPLICATION_REQUESTS_EXIT of example_plugin!");
|
2018-06-28 22:27:25 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 19:57:15 +02:00
|
|
|
void logFSOpenChanged(ConfigItemBoolean *item, bool newValue) {
|
|
|
|
DEBUG_FUNCTION_LINE("New value in logFSOpenChanged: %d", newValue);
|
|
|
|
logFSOpen = newValue;
|
|
|
|
// If the value has changed, we store it in the storage.
|
|
|
|
WUPS_StoreInt(nullptr, "logFSOpen", logFSOpen);
|
|
|
|
}
|
|
|
|
|
|
|
|
WUPS_GET_CONFIG() {
|
|
|
|
// We open the storage so we can persist the configuration the user did.
|
|
|
|
WUPS_OpenStorage();
|
|
|
|
|
|
|
|
WUPSConfigHandle config;
|
|
|
|
WUPSConfig_CreateHandled(&config, "Example Plugin");
|
|
|
|
|
|
|
|
WUPSConfigCategoryHandle cat;
|
|
|
|
WUPSConfig_AddCategoryByNameHandled(config, "Logging", &cat);
|
|
|
|
|
|
|
|
WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, "logFSOpen", "Log FSOpen calls", logFSOpen, &logFSOpenChanged);
|
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
WUPS_CONFIG_CLOSED() {
|
|
|
|
// Save all changes
|
|
|
|
WUPS_CloseStorage();
|
|
|
|
}
|
|
|
|
|
2018-06-28 22:27:25 +02:00
|
|
|
/**
|
|
|
|
This defines a function replacement.
|
|
|
|
It allows to replace the system function with an own function.
|
|
|
|
So whenever a game / application calles an overridden function, your function gets called instead.
|
|
|
|
|
|
|
|
Currently it's only possible to override functions that are loaded from .rpl files of OSv10 (00050010-1000400A).
|
|
|
|
|
|
|
|
Signature of this macro:
|
|
|
|
DECL_FUNCTION( RETURN_TYPE, ARBITRARY_NAME_OF_FUNCTION , ARGS_SEPERATED_BY_COMMA){
|
|
|
|
//Your code goes here.
|
|
|
|
}
|
|
|
|
|
|
|
|
Within this macro, two more function get declare you can use.
|
|
|
|
my_ARBITRARY_NAME_OF_FUNCTION and real_FSOpenFile
|
|
|
|
|
|
|
|
RETURN_TYPE my_ARBITRARY_NAME_OF_FUNCTION(ARGS_SEPERATED_BY_COMMA):
|
|
|
|
is just name of the function that gets declared in this macro.
|
|
|
|
It has the same effect as calling the overridden function directly.
|
|
|
|
|
|
|
|
RETURN_TYPE real_ARBITRARY_NAME_OF_FUNCTION(ARGS_SEPERATED_BY_COMMA):
|
|
|
|
is the name of the function, that leads to function that was overridden.
|
|
|
|
Use this to call the original function that will be overridden.
|
|
|
|
CAUTION: Other plugins may already have manipulated the the return value or arguments.
|
|
|
|
|
|
|
|
|
|
|
|
Use this macro for each function you want to override
|
|
|
|
|
|
|
|
**/
|
|
|
|
DECL_FUNCTION(int, FSOpenFile, FSClient *pClient, FSCmdBlock *pCmd, const char *path, const char *mode, int *handle, int error) {
|
|
|
|
int result = real_FSOpenFile(pClient, pCmd, path, mode, handle, error);
|
2021-09-24 19:57:15 +02:00
|
|
|
if (logFSOpen) {
|
|
|
|
DEBUG_FUNCTION_LINE("FSOpenFile called for folder %s! Result %d",path,result);
|
|
|
|
}
|
2018-06-28 22:27:25 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
This tells the loader which functions from which library (.rpl) should be replaced with which function from this file.
|
|
|
|
The list of possible libraries can be found in the wiki. (In general it's WUPS_LOADER_LIBRARY_ + the name of the RPL in caps lock)
|
|
|
|
|
|
|
|
WUPS_MUST_REPLACE(FUNCTION_NAME_IN_THIS_FILE, NAME_OF_LIB_WHICH_CONTAINS_THIS_FUNCTION, NAME_OF_FUNCTION_TO_OVERRIDE)
|
|
|
|
|
|
|
|
Define this for each function you want to override.
|
|
|
|
**/
|
|
|
|
WUPS_MUST_REPLACE(FSOpenFile, WUPS_LOADER_LIBRARY_COREINIT, FSOpenFile);
|