-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add cmake toolchain file - Add example for cmake
- Loading branch information
1 parent
51f627d
commit dc54bc4
Showing
11 changed files
with
249 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.2) | ||
|
||
include("${DEVKITPRO}/wups/share/wups.cmake" REQUIRED) | ||
|
||
project(example_cpp CXX) | ||
|
||
add_executable(example_cpp src/main.cpp) | ||
wups_create_plugin(example_cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Example plugin | ||
|
||
This is just a simple example plugin using `cmake` which can be used as a template. | ||
|
||
## Building | ||
|
||
For building you need: | ||
- [wups](https://github.com/Maschell/WiiUPluginSystem) | ||
- [wut](https://github.com/decaf-emu/wut) | ||
|
||
Install them (in this order) according to their README's. Don't forget the dependencies of the libs itself. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
#include "./utils/logger.h" | ||
#include <coreinit/filesystem.h> | ||
#include <coreinit/thread.h> | ||
#include <coreinit/time.h> | ||
#include <malloc.h> | ||
#include <string.h> | ||
#include <whb/libmanager.h> | ||
#include <whb/log_cafe.h> | ||
#include <whb/log_module.h> | ||
#include <whb/log_udp.h> | ||
#include <wups.h> | ||
#include <wups/config/WUPSConfigItemBoolean.h> | ||
|
||
/** | ||
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"); | ||
|
||
/** | ||
All of this defines can be used in ANY file. | ||
It's possible to split it up into multiple files. | ||
**/ | ||
|
||
WUPS_USE_WUT_DEVOPTAB(); // Use the wut devoptabs | ||
WUPS_USE_STORAGE("example_plugin"); // Unqiue id for the storage api | ||
|
||
bool logFSOpen = true; | ||
|
||
/** | ||
Get's called ONCE when the loader exits, but BEFORE the ON_APPLICATION_START gets called or functions are overridden. | ||
**/ | ||
INITIALIZE_PLUGIN() { | ||
if (!WHBLogModuleInit()) { | ||
WHBLogCafeInit(); | ||
WHBLogUdpInit(); | ||
} | ||
DEBUG_FUNCTION_LINE("INITIALIZE_PLUGIN of example_plugin!"); | ||
|
||
// Open storage to read values | ||
WUPSStorageError storageRes = WUPS_OpenStorage(); | ||
if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { | ||
DEBUG_FUNCTION_LINE("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); | ||
} else { | ||
// Try to get value from storage | ||
if ((storageRes = WUPS_GetBool(nullptr, "logFSOpen", &logFSOpen)) == WUPS_STORAGE_ERROR_NOT_FOUND) { | ||
// Add the value to the storage if it's missing. | ||
if (WUPS_StoreBool(nullptr, "logFSOpen", logFSOpen) != WUPS_STORAGE_ERROR_SUCCESS) { | ||
DEBUG_FUNCTION_LINE("Failed to store bool"); | ||
} | ||
} else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) { | ||
DEBUG_FUNCTION_LINE("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes); | ||
} | ||
|
||
// Close storage | ||
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) { | ||
DEBUG_FUNCTION_LINE("Failed to close storage"); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
Gets called when the plugin loader is re-entered => when the plugin is unloaded. | ||
The overridden functions are restored before this is getting called. | ||
**/ | ||
DEINITIALIZE_PLUGIN() { | ||
DEBUG_FUNCTION_LINE("DEINITIALIZE_PLUGIN of example_plugin!"); | ||
} | ||
|
||
/** | ||
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() { | ||
if (!WHBLogModuleInit()) { | ||
WHBLogCafeInit(); | ||
WHBLogUdpInit(); | ||
} | ||
|
||
DEBUG_FUNCTION_LINE("ON_APPLICATION_START of example_plugin!"); | ||
} | ||
|
||
/** | ||
Gets called when an application request to exit. | ||
**/ | ||
ON_APPLICATION_REQUESTS_EXIT() { | ||
DEBUG_FUNCTION_LINE("ON_APPLICATION_REQUESTS_EXIT of example_plugin!"); | ||
} | ||
|
||
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. | ||
if (WUPS_OpenStorage() != WUPS_STORAGE_ERROR_SUCCESS) { | ||
DEBUG_FUNCTION_LINE("Failed to open storage"); | ||
return 0; | ||
} | ||
|
||
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 | ||
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) { | ||
DEBUG_FUNCTION_LINE("Failed to close storage"); | ||
} | ||
} | ||
|
||
/** | ||
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); | ||
if (logFSOpen) { | ||
DEBUG_FUNCTION_LINE("FSOpenFile called for folder %s! Result %d", path, result); | ||
} | ||
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); |
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
plugins/example_plugin/README.md → plugins/make_example_plugin/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <string.h> | ||
#include <whb/log.h> | ||
|
||
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) | ||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) | ||
|
||
#define OSFATAL_FUNCTION_LINE(FMT, ARGS...) \ | ||
do { \ | ||
OSFatal_printf("[%s]%s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ | ||
} while (0) | ||
|
||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \ | ||
do { \ | ||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ | ||
} while (0); | ||
|
||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \ | ||
do { \ | ||
WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ | ||
} while (0); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
cmake_minimum_required(VERSION 3.2) | ||
|
||
# create a WUPS plugin | ||
function(wups_create_plugin target) | ||
set(WUPS_ROOT "${DEVKITPRO}/wups") | ||
|
||
target_include_directories(${target} PRIVATE "${WUPS_ROOT}/include") | ||
target_link_directories(${target} PRIVATE "${WUPS_ROOT}/lib") | ||
target_link_libraries(${target} wups) | ||
target_link_options(${target} PRIVATE "-T${WUPS_ROOT}/share/wups.ld" "-specs=${WUPS_ROOT}/share/wups.specs") | ||
|
||
get_target_property(WUPS_OUTPUT_NAME ${target} OUTPUT_NAME) | ||
get_target_property(WUPS_BINARY_DIR ${target} BINARY_DIR) | ||
if(NOT WUPS_OUTPUT_NAME) | ||
set(WUPS_OUTPUT_NAME "${target}") | ||
endif() | ||
set(WUPS_OUTPUT "${WUPS_BINARY_DIR}/${WUPS_OUTPUT_NAME}.wps") | ||
|
||
add_custom_command(TARGET ${target} POST_BUILD | ||
COMMAND ${WUT_ELF2RPL_EXE} "$<TARGET_FILE:${target}>" "${WUPS_OUTPUT}" | ||
COMMAND echo PL | dd of=${WUPS_OUTPUT} bs=1 seek=9 count=2 conv=notrunc status=none | ||
BYPRODUCTS "${WUPS_OUTPUT}" | ||
COMMENT "Converting ${target} to .wps format" | ||
VERBATIM | ||
) | ||
endfunction() |