Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quick toggle emulation #20

Merged
merged 13 commits into from
Jun 26, 2024
9 changes: 9 additions & 0 deletions plugin/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ WUPS_USE_WUT_DEVOPTAB();
uint32_t currentRemoveAfterOption = 0;

uint32_t currentQuickSelectCombination = 0;
uint32_t currentQuickRemoveCombination = 0;

bool favoritesPerTitle = false;

Expand Down Expand Up @@ -162,6 +163,12 @@ static void quickSelectComboCallback(ConfigItemButtonCombo* item, uint32_t newVa
WUPS_StoreInt(nullptr, "quickSelectCombo", (int32_t) currentQuickSelectCombination);
}

static void quickRemoveComboCallback(ConfigItemButtonCombo* item, uint32_t newValue)
{
currentQuickRemoveCombination = newValue;
WUPS_StoreInt(nullptr, "quickRemoveCombo", (int32_t) currentQuickRemoveCombination);
}

WUPS_GET_CONFIG()
{
if (WUPS_OpenStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
Expand Down Expand Up @@ -213,6 +220,8 @@ WUPS_GET_CONFIG()

WUPSConfigItemButtonCombo_AddToCategoryHandled(config, cat, "quick_select_combination", "Quick Select Combo", currentQuickSelectCombination, quickSelectComboCallback);

WUPSConfigItemButtonCombo_AddToCategoryHandled(config, cat, "quick_remove_combination", "Quick Remove Combo", currentQuickRemoveCombination, quickRemoveComboCallback);

ConfigItemDumpAmiibo_AddToCategoryHandled(config, cat, "dump_amiibo", "Dump Amiibo", (TAG_EMULATION_PATH + "dumps").c_str());

ConfigItemLog_AddToCategoryHandled(config, cat, "log", "Logs");
Expand Down
34 changes: 34 additions & 0 deletions plugin/source/quick_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ extern "C" uint32_t VPADGetButtonProcMode(VPADChan chan);
extern uint32_t currentQuickSelectCombination;
static uint32_t currentQuickSelectIndex = 0;

extern uint32_t currentQuickRemoveCombination;

static uint32_t sWPADLastButtonHold[4];
static uint32_t sWasHoldForXFrame[4];
static uint32_t sWasHoldForXFrameGamePad;
Expand Down Expand Up @@ -40,6 +42,24 @@ static void cycleQuickSelect()
}
}


static void toggleEmulation()
{
NfpiiEmulationState state = NfpiiGetEmulationState();
std::string notifText;
if (state == NFPII_EMULATION_ON) {
NfpiiSetEmulationState(NFPII_EMULATION_OFF);
std::string notifText = "re_nfpii: Disabled emulation";
jadeiseepy marked this conversation as resolved.
Show resolved Hide resolved
} else {
NfpiiSetEmulationState(NFPII_EMULATION_ON);
std::string notifText = "re_nfpii: Enabled emulation";
jadeiseepy marked this conversation as resolved.
Show resolved Hide resolved
};

if (NotificationModule_InitLibrary() == NOTIFICATION_MODULE_RESULT_SUCCESS) {
NotificationModule_AddInfoNotification(notifText.c_str());
}
}

DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus* buffer, uint32_t buffer_size, VPADReadError* error)
{
VPADReadError real_error;
Expand All @@ -52,18 +72,27 @@ DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus* buffer, uint32_t buf
end = result;
}
bool found = false;
bool foundTe = false;

for (uint32_t i = 0; i < end; i++) {
if (currentQuickSelectCombination != 0 && (((buffer[i].hold & 0x000FFFFF) & currentQuickSelectCombination) == currentQuickSelectCombination)) {
found = true;
break;
} else if (currentQuickRemoveCombination != 0 && (((buffer[i].hold & 0x000FFFFF) & currentQuickRemoveCombination) == currentQuickRemoveCombination)) {
foundTe = true;
break;
}
}
if (found) {
if (sWasHoldForXFrameGamePad == 0) {
cycleQuickSelect();
}
sWasHoldForXFrameGamePad++;
} else if (foundTe) {
if (sWasHoldForXFrameGamePad == 0) {
toggleEmulation();
}
sWasHoldForXFrameGamePad++;
} else {
sWasHoldForXFrameGamePad = 0;
}
Expand Down Expand Up @@ -97,6 +126,11 @@ DECL_FUNCTION(void, WPADRead, WPADChan chan, WPADStatusProController* data)
cycleQuickSelect();
}
sWasHoldForXFrame[chan]++;
} else if ((currentQuickRemoveCombination != 0 && (curButtonHold & currentQuickRemoveCombination) == currentQuickRemoveCombination)) {
if (sWasHoldForXFrame[chan] == 0) {
toggleEmulation();
}
sWasHoldForXFrame[chan]++;
} else {
sWasHoldForXFrame[chan] = 0;
}
Expand Down
Loading