WiiUPluginLoaderBackend/source/patcher/hooks_patcher_static.cpp

48 lines
1.7 KiB
C++
Raw Normal View History

#include "hooks_patcher_static.h"
#include <malloc.h>
#include <wups.h>
#include <vpad/input.h>
#include <coreinit/messagequeue.h>
#include <coreinit/core.h>
2020-12-26 14:17:50 +01:00
#include "../utils/logger.h"
#include "../globals.h"
#include "../hooks.h"
DECL_FUNCTION(void, GX2WaitForVsync, void) {
CallHook(gPluginInformation, WUPS_LOADER_HOOK_VSYNC);
real_GX2WaitForVsync();
}
2019-11-16 15:12:30 +01:00
static uint32_t lastData0 = 0;
DECL_FUNCTION(uint32_t, OSReceiveMessage, OSMessageQueue *queue, OSMessage *message, uint32_t flags) {
2020-05-03 12:30:15 +02:00
int32_t res = real_OSReceiveMessage(queue, message, flags);
if (queue == OSGetSystemMessageQueue()) {
2020-12-26 14:17:50 +01:00
if (message != nullptr && res) {
2020-05-03 12:30:15 +02:00
if (lastData0 != message->args[0]) {
if (message->args[0] == 0xFACEF000) {
CallHook(gPluginInformation, WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND);
2020-05-03 12:30:15 +02:00
} else if (message->args[0] == 0xD1E0D1E0) {
// Implemented via WUMS Hook
2019-11-16 15:12:30 +01:00
}
}
lastData0 = message->args[0];
2019-11-16 15:12:30 +01:00
}
}
return res;
}
DECL_FUNCTION(void, OSReleaseForeground) {
2020-05-03 12:30:15 +02:00
if (OSGetCoreId() == 1) {
CallHook(gPluginInformation, WUPS_LOADER_HOOK_RELEASE_FOREGROUND);
2019-11-16 15:12:30 +01:00
}
real_OSReleaseForeground();
}
function_replacement_data_t method_hooks_hooks_static[] __attribute__((section(".data"))) = {
2020-08-09 18:14:58 +02:00
REPLACE_FUNCTION(GX2WaitForVsync, LIBRARY_GX2, GX2WaitForVsync),
REPLACE_FUNCTION(OSReceiveMessage, LIBRARY_COREINIT, OSReceiveMessage),
REPLACE_FUNCTION(OSReleaseForeground, LIBRARY_COREINIT, OSReleaseForeground)
};
uint32_t method_hooks_size_hooks_static __attribute__((section(".data"))) = sizeof(method_hooks_hooks_static) / sizeof(function_replacement_data_t);