mirror of
https://github.com/wiiu-env/ScreenshotWUPS.git
synced 2025-01-09 11:29:22 +01:00
Hook into DRCAttach function instead of registering our own callback
This commit is contained in:
parent
b567ae31b9
commit
541b7e3861
@ -1,75 +0,0 @@
|
||||
#include "DRCAttachCallback.h"
|
||||
#include "retain_vars.hpp"
|
||||
#include "utils/logger.h"
|
||||
#include <coreinit/cache.h>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <wups.h>
|
||||
|
||||
std::mutex gDRCCallbackMutex;
|
||||
CCRCDCCallbackData gCCRCDCCallbackDataCurrent;
|
||||
std::map<CCRCDCCallbackDataCallback, void *> gDRCCallbackData;
|
||||
|
||||
void DRCAttachDetachCallbackWrapper(CCRCDCCallbackData *data, void *context) {
|
||||
std::lock_guard<std::mutex> lock(gDRCCallbackMutex);
|
||||
// Callbacks get called when added, so we need to save the current "data" and then pass it to newly added callbacks
|
||||
memcpy(&gCCRCDCCallbackDataCurrent, data, sizeof(CCRCDCCallbackData));
|
||||
|
||||
// Call all callbacks.
|
||||
for (auto &cur : gDRCCallbackData) {
|
||||
if (cur.first != nullptr) {
|
||||
cur.first(data, cur.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* From what I can tell `CCRCDCRegisterUVCAttachCallback` is never used by any .rpl/.rpx
|
||||
* Let's add multiple for multiple callbacks anyway, better safe than sorry.
|
||||
*/
|
||||
DECL_FUNCTION(void, CCRCDCRegisterUVCAttachCallback, CCRCDCCallbackDataCallback callback, void *context) {
|
||||
std::lock_guard<std::mutex> lock(gDRCCallbackMutex);
|
||||
if (callback == nullptr && context == nullptr) { // Delete (all) callbacks.
|
||||
real_CCRCDCRegisterUVCAttachCallback(callback, context);
|
||||
gDRCCallbackData.clear();
|
||||
return;
|
||||
}
|
||||
if (callback != nullptr) {
|
||||
// Add callback
|
||||
gDRCCallbackData[callback] = context;
|
||||
// Call callback
|
||||
callback(&gCCRCDCCallbackDataCurrent, context);
|
||||
}
|
||||
}
|
||||
|
||||
WUPS_MUST_REPLACE(CCRCDCRegisterUVCAttachCallback, WUPS_LOADER_LIBRARY_NSYSCCR, CCRCDCRegisterUVCAttachCallback);
|
||||
|
||||
void DRCAttachDetachCallback(CCRCDCCallbackData *data, void *context) {
|
||||
gBlockDRCScreenshots = !data->attached;
|
||||
|
||||
if (data->attached) {
|
||||
if (gButtonCombo & VPAD_BUTTON_TV) {
|
||||
DEBUG_FUNCTION_LINE("Block TV Menu");
|
||||
VPADSetTVMenuInvalid(data->chan, true);
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("Unblock TV Menu");
|
||||
VPADSetTVMenuInvalid(data->chan, false);
|
||||
}
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("Block DRC screenshots");
|
||||
}
|
||||
OSMemoryBarrier();
|
||||
}
|
||||
|
||||
extern "C" int CCRCDCRegisterUVCAttachCallback(void (*)(CCRCDCCallbackData *, void *), void *);
|
||||
|
||||
void InitDRCAttachCallbacks() {
|
||||
// Clear existing callbacks
|
||||
gDRCCallbackData.clear();
|
||||
|
||||
// Add wrapper function to support multiple callbacks.
|
||||
real_CCRCDCRegisterUVCAttachCallback(DRCAttachDetachCallbackWrapper, nullptr);
|
||||
|
||||
// Add the real callback we want to use.
|
||||
CCRCDCRegisterUVCAttachCallback(DRCAttachDetachCallback, nullptr);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include <vpad/input.h>
|
||||
#include <wut.h>
|
||||
|
||||
struct WUT_PACKED CCRCDCCallbackData {
|
||||
uint32_t attached;
|
||||
VPADChan chan;
|
||||
WUT_UNKNOWN_BYTES(6);
|
||||
};
|
||||
|
||||
extern CCRCDCCallbackData gCCRCDCCallbackDataCurrent;
|
||||
typedef void (*CCRCDCCallbackDataCallback)(CCRCDCCallbackData *, void *);
|
||||
|
||||
void InitDRCAttachCallbacks();
|
@ -252,9 +252,24 @@ DECL_FUNCTION(void, GX2MarkScanBufferCopied, GX2ScanTarget scan_target) {
|
||||
}
|
||||
|
||||
WUPS_MUST_REPLACE(VPADRead, WUPS_LOADER_LIBRARY_VPAD, VPADRead);
|
||||
struct WUT_PACKED CCRCDCCallbackData {
|
||||
uint32_t attached;
|
||||
VPADChan chan;
|
||||
WUT_UNKNOWN_BYTES(6);
|
||||
};
|
||||
|
||||
DECL_FUNCTION(void, __VPADBASEAttachCallback, CCRCDCCallbackData *data, void *context) {
|
||||
real___VPADBASEAttachCallback(data, context);
|
||||
|
||||
if (data && data->attached) {
|
||||
gBlockDRCScreenshots = !data->attached;
|
||||
}
|
||||
}
|
||||
|
||||
WUPS_MUST_REPLACE(GX2MarkScanBufferCopied, WUPS_LOADER_LIBRARY_GX2, GX2MarkScanBufferCopied);
|
||||
WUPS_MUST_REPLACE(GX2GetCurrentScanBuffer, WUPS_LOADER_LIBRARY_GX2, GX2GetCurrentScanBuffer);
|
||||
WUPS_MUST_REPLACE(GX2CopyColorBufferToScanBuffer, WUPS_LOADER_LIBRARY_GX2, GX2CopyColorBufferToScanBuffer);
|
||||
WUPS_MUST_REPLACE(GX2SetTVBuffer, WUPS_LOADER_LIBRARY_GX2, GX2SetTVBuffer);
|
||||
WUPS_MUST_REPLACE(GX2SetDRCBuffer, WUPS_LOADER_LIBRARY_GX2, GX2SetDRCBuffer);
|
||||
WUPS_MUST_REPLACE(WPADRead, WUPS_LOADER_LIBRARY_PADSCORE, WPADRead);
|
||||
WUPS_MUST_REPLACE_PHYSICAL(__VPADBASEAttachCallback, (0x31000000 + 0x0200146c - 0x00EE0100), (0x0200146c - 0x00EE0100));
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "main.h"
|
||||
#include "DRCAttachCallback.h"
|
||||
#include "config.h"
|
||||
#include "retain_vars.hpp"
|
||||
#include "thread.h"
|
||||
@ -33,9 +32,6 @@ DEINITIALIZE_PLUGIN() {
|
||||
NotificationModule_DeInitLibrary();
|
||||
}
|
||||
|
||||
ON_ACQUIRED_FOREGROUND() {
|
||||
InitDRCAttachCallbacks();
|
||||
}
|
||||
|
||||
// Called whenever an application was started.
|
||||
ON_APPLICATION_START() {
|
||||
@ -45,8 +41,6 @@ ON_APPLICATION_START() {
|
||||
startFSIOThreads();
|
||||
|
||||
ApplyGameSpecificPatches();
|
||||
|
||||
InitDRCAttachCallbacks();
|
||||
}
|
||||
|
||||
ON_APPLICATION_REQUESTS_EXIT() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user