Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions source/TVOverlayManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "TVOverlayManager.h"
#include "ButtonComboManager.h"
#include "export.h"
#include "globals.h"
#include "logger.h"

#include <coreinit/cache.h>
#include <coreinit/debug.h>
#include <coreinit/time.h>

static ButtonComboModule_ComboHandle sTVButtonHandle;
static OSTime sTVPressed[2]; // when the button was last pressed, or zero if timeout expired
static bool sTVMenuBlocked[2];

static void TVComboCallback(ButtonComboModule_ControllerTypes triggeredBy,
ButtonComboModule_ComboHandle,
void *) {
VPADChan chan;
switch (triggeredBy) {
case BUTTON_COMBO_MODULE_CONTROLLER_VPAD_0:
chan = VPAD_CHAN_0;
break;
case BUTTON_COMBO_MODULE_CONTROLLER_VPAD_1:
chan = VPAD_CHAN_1;
break;
default:
return;
}
// OSReport("TV pressed\n");
sTVPressed[chan] = OSGetSystemTime();
OSMemoryBarrier();
}

void registerTVCombo() {
ButtonComboModule_ComboOptions opt = {};
opt.version = BUTTON_COMBO_MODULE_COMBO_OPTIONS_VERSION;
opt.metaOptions.label = "TV remote overlay combo";
opt.callbackOptions.callback = TVComboCallback;
opt.callbackOptions.context = {};
opt.buttonComboOptions.type = BUTTON_COMBO_MODULE_COMBO_TYPE_PRESS_DOWN_OBSERVER;
opt.buttonComboOptions.basicCombo.combo = BCMPAD_BUTTON_TV;
opt.buttonComboOptions.basicCombo.controllerMask = BUTTON_COMBO_MODULE_CONTROLLER_VPAD;
opt.buttonComboOptions.optionalHoldForXMs = 0;
if (ButtonComboModule_AddButtonCombo(&opt, &sTVButtonHandle, nullptr) != BUTTON_COMBO_MODULE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE("FAILED TO SET UP TV COMBO!");
}
}

void unregisterTVCombo() {
ButtonComboModule_RemoveButtonCombo(sTVButtonHandle);
}

void initTVStatus(VPADChan channel, bool block) {
VPADSetTVMenuInvalid(channel, block);
sTVMenuBlocked[channel] = block;

sTVPressed[channel] = 0;
OSMemoryBarrier();
}

void resetTVStatus(VPADChan channel) {
sTVPressed[channel] = 0;
OSMemoryBarrier();
}

void updateTVStatus(VPADChan channel) {
if (sTVPressed[channel]) {
uint64_t elapsed = OSGetSystemTime() - sTVPressed[channel];
if (elapsed > OSMillisecondsToTicks(100) && sTVMenuBlocked[channel]) {
// OSReport("TV menu unblocked\n");
VPADSetTVMenuInvalid(channel, false);
sTVMenuBlocked[channel] = false;
}
if (elapsed > OSMillisecondsToTicks(1000) && !VPADGetTVMenuStatus(channel)) {
bool block = gButtonComboManager->hasActiveComboWithTVButton();
// OSReport("TV timeout reached, setting TV Menu block to %s\n",
// block ? "blocked" : "unblocked");
VPADSetTVMenuInvalid(channel, block);
sTVMenuBlocked[channel] = block;
sTVPressed[channel] = 0;
}
}
}
13 changes: 13 additions & 0 deletions source/TVOverlayManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <vpad/input.h>

void registerTVCombo();

void unregisterTVCombo();

void initTVStatus(VPADChan channel, bool block);

void resetTVStatus(VPADChan channel);

void updateTVStatus(VPADChan channel);
4 changes: 2 additions & 2 deletions source/export.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "export.h"
#include "ButtonComboManager.h"
#include "globals.h"

#include <buttoncombo/defines.h>
#include <logger.h>

#include <wums/exports.h>
Expand Down Expand Up @@ -227,4 +227,4 @@ WUMS_EXPORT_FUNCTION(ButtonComboModule_GetButtonComboCallback);
WUMS_EXPORT_FUNCTION(ButtonComboModule_GetButtonComboInfoEx);
WUMS_EXPORT_FUNCTION(ButtonComboModule_CheckComboAvailable);
WUMS_EXPORT_FUNCTION(ButtonComboModule_DetectButtonCombo_Blocking);
WUMS_EXPORT_FUNCTION(ButtonComboModule_GetVersion);
WUMS_EXPORT_FUNCTION(ButtonComboModule_GetVersion);
9 changes: 9 additions & 0 deletions source/export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <buttoncombo/defines.h>

extern ButtonComboModule_Error ButtonComboModule_AddButtonCombo(const ButtonComboModule_ComboOptions *options,
ButtonComboModule_ComboHandle *outHandle,
ButtonComboModule_ComboStatus *outStatus);

extern ButtonComboModule_Error ButtonComboModule_RemoveButtonCombo(const ButtonComboModule_ComboHandle handle);
13 changes: 9 additions & 4 deletions source/function_patches.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ButtonComboInfo.h"
#include "ButtonComboManager.h"
#include "TVOverlayManager.h"
#include "globals.h"

#include <function_patcher/fpatching_defines.h>
Expand All @@ -18,6 +19,9 @@ DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buf
if (error) {
*error = real_error;
}

updateTVStatus(chan);

return result;
}

Expand All @@ -37,10 +41,11 @@ struct WUT_PACKED CCRCDCCallbackData {
DECL_FUNCTION(void, __VPADBASEAttachCallback, CCRCDCCallbackData *data, void *context) {
real___VPADBASEAttachCallback(data, context);

if (data && data->attached) {
if (gButtonComboManager) {
const bool block = gButtonComboManager->hasActiveComboWithTVButton();
VPADSetTVMenuInvalid(data->chan, block);
if (data) {
if (data->attached && gButtonComboManager) {
initTVStatus(data->chan, gButtonComboManager->hasActiveComboWithTVButton());
} else {
resetTVStatus(data->chan);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/globals.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "globals.h"
#include "ButtonComboManager.h"

std::unique_ptr<ButtonComboManager> gButtonComboManager = {};
std::unique_ptr<ButtonComboManager> gButtonComboManager = {};
2 changes: 1 addition & 1 deletion source/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

class ButtonComboManager;

extern std::unique_ptr<ButtonComboManager> gButtonComboManager;
extern std::unique_ptr<ButtonComboManager> gButtonComboManager;
5 changes: 5 additions & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "ButtonComboManager.h"
#include "TVOverlayManager.h"
#include "export.h"
#include "function_patches.h"
#include "globals.h"
#include "logger.h"
Expand Down Expand Up @@ -34,10 +36,13 @@ WUMS_INITIALIZE() {

gButtonComboManager = std::make_unique<ButtonComboManager>();

registerTVCombo();

deinitLogging();
}

WUMS_DEINITIALIZE() {
unregisterTVCombo();
gButtonComboManager.reset();
}

Expand Down