-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDRCAttachCallback.cpp
More file actions
76 lines (61 loc) · 2.54 KB
/
DRCAttachCallback.cpp
File metadata and controls
76 lines (61 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "DRCAttachCallback.h"
#include "ButtonComboManager.h"
#include "globals.h"
#include "logger.h"
#include <function_patcher/fpatching_defines.h>
#include <map>
#include <mutex>
#include <cstring>
std::mutex gDRCCallbackMutex;
CCRCDCCallbackData gCCRCDCCallbackDataCurrent;
std::map<CCRCDCCallbackDataCallback, void *> gDRCCallbackData;
void DRCAttachDetachCallbackWrapper(CCRCDCCallbackData *data, void *) {
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 support 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);
}
}
function_replacement_data_t drc_function_replacements[] = {
REPLACE_FUNCTION(CCRCDCRegisterUVCAttachCallback, LIBRARY_NSYSCCR, CCRCDCRegisterUVCAttachCallback),
};
uint32_t drc_function_replacements_size = sizeof(drc_function_replacements) / sizeof(function_replacement_data_t);
void DRCAttachDetachCallback(CCRCDCCallbackData *data, void *) {
if (data->attached) {
if (gButtonComboManager) {
const bool block = gButtonComboManager->hasActiveComboWithTVButton();
VPADSetTVMenuInvalid(data->chan, block);
}
}
}
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);
}