From b1f345945f2013e6975ed105933b0d195b71f164 Mon Sep 17 00:00:00 2001 From: Yahya14 Date: Sun, 23 Jul 2017 10:50:59 -0400 Subject: [PATCH] Added TV button swapping --- meta/meta.xml | 4 +-- src/main.c | 9 ++++--- src/patcher/function_hooks.c | 47 +++++++++++++++++++----------------- src/patcher/function_hooks.h | 1 + 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/meta/meta.xml b/meta/meta.xml index de32a69..eeda905 100644 --- a/meta/meta.xml +++ b/meta/meta.xml @@ -3,12 +3,12 @@ Swap DRC OatmealDome and Yahya14 TBA - 1.0 + 1.1 201707190000000 Switch TV display onto the gamepad This tool installs Swap DRC, TCPGecko, and/or Cafiine into system memory. -Switch the TV and gamepad display (and the DRC sensor bar) by holding the L shoulder button, and then press MINUS. +Switch the TV and gamepad display (and the DRC sensor bar) by holding the L shoulder button, and then press MINUS. Pressing the TV button also works. Special thanks to: Maschell, dimok, NWPlayer123, Brienj, and BKOOL999! diff --git a/src/main.c b/src/main.c index c139327..d6b0942 100644 --- a/src/main.c +++ b/src/main.c @@ -25,6 +25,7 @@ #define PRINT_TEXT2(x, y, ...) { snprintf(msg, 80, __VA_ARGS__); OSScreenPutFontEx(0, x, y, msg); OSScreenPutFontEx(1, x, y, msg); } #define PRINT_TEXT3(x, y, _fmt, ...) { __os_snprintf(msg, 80, _fmt, __VA_ARGS__); OSScreenPutFontEx(1, x, y, msg); } +#define DEBUG 0 #define BUILD 1.1 @@ -103,8 +104,9 @@ int Menu_Main() InitAXFunctionPointers(); InitProcUIFunctionPointers(); - - log_init("192.168.2.18"); + if (DEBUG) { + log_init("192.168.2.18"); + } SetupKernelCallback(); @@ -240,7 +242,8 @@ int Menu_Main() PRINT_TEXT2(0,10, " <---"); - PRINT_TEXT2(0,13, "Hold L then press Minus to swap displays."); + PRINT_TEXT2(0, 13, "Hold L then press Minus to swap displays."); + PRINT_TEXT2(0, 14, "You can also press the TV button."); PRINT_TEXT2(0, 15, "Press B to return to the menu."); diff --git a/src/patcher/function_hooks.c b/src/patcher/function_hooks.c index c33bb8e..75a375e 100644 --- a/src/patcher/function_hooks.c +++ b/src/patcher/function_hooks.c @@ -30,6 +30,7 @@ res my_ ## name(__VA_ARGS__) int swapForce = 0; +unsigned int homeCoolDown = 0; // AX FUNCTIONS DECL(s32, AXSetVoiceDeviceMixOld, void *v, s32 device, u32 id, void *mix) { @@ -72,8 +73,7 @@ DECL(void, AXFreeVoice, void *v) { real_AXFreeVoice(v); } -void swapVoices() -{ +void swapVoices() { swapAll(); for (int i = 0; i < VOICE_INFO_MAX; i++) { if (gVoiceInfos[i].voice == NULL) continue; @@ -85,8 +85,7 @@ void swapVoices() } // GX2 FUNCTIONS -DECL(void, GX2CopyColorBufferToScanBuffer, GX2ColorBuffer *colorBuffer, s32 scan_target) -{ +DECL(void, GX2CopyColorBufferToScanBuffer, GX2ColorBuffer *colorBuffer, s32 scan_target) { // GX2 destinations: // 0x1 = TV // 0x4 = 1st GamePad @@ -96,12 +95,10 @@ DECL(void, GX2CopyColorBufferToScanBuffer, GX2ColorBuffer *colorBuffer, s32 scan // 0x1 = swap // check drc swap and force the drcMode to default when inkstrike is activated - if (drcMode == 0 || swapForce) - { + if (drcMode == 0 || swapForce) { real_GX2CopyColorBufferToScanBuffer(colorBuffer, scan_target); } - else - { + else { switch (scan_target) { case 0x1: @@ -115,40 +112,46 @@ DECL(void, GX2CopyColorBufferToScanBuffer, GX2ColorBuffer *colorBuffer, s32 scan } //VPAD FUNCTIONS -DECL(int, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *error) -{ +DECL(int, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *error) { + int result = real_VPADRead(chan, buffer, buffer_size, error); // switch on L and SELECT - if (buffer->btns_d & VPAD_BUTTON_MINUS && buffer->btns_h & VPAD_BUTTON_L && AppInBackground) - { + if (buffer->btns_d & VPAD_BUTTON_MINUS && buffer->btns_h & VPAD_BUTTON_L && AppInBackground) { drcSwap(); } + // switch on TV button + if (buffer->btns_h & VPAD_BUTTON_TV && homeCoolDown == 0 && AppInBackground) { + homeCoolDown = 0x5A; + drcSwap(); + } + else if (homeCoolDown > 0) { + homeCoolDown--; + } + + // patches splatoon enhanced controls - if (isSplatoon) - { + if (isSplatoon) { gambitPatches(buffer); gambitDRC(); } - return real_VPADRead(chan, buffer, buffer_size, error); + return result; } -DECL(void, VPADGetTPCalibratedPoint, int chan, VPADTPData *screen, VPADTPData *raw) -{ +DECL(void, VPADGetTPCalibratedPoint, int chan, VPADTPData *screen, VPADTPData *raw) { real_VPADGetTPCalibratedPoint(chan, screen, raw); - if (isSplatoon) + if (isSplatoon) { // handles modified touch input for super jumps gambitTouch(screen); + } } -DECL(void, VPADSetSensorBar, s32 chan, bool on) -{ +DECL(void, VPADSetSensorBar, s32 chan, bool on){ real_VPADSetSensorBar(chan, on); } -void drcSwap() -{ +void drcSwap() { // swap drc modes drcMode = !drcMode; diff --git a/src/patcher/function_hooks.h b/src/patcher/function_hooks.h index dba55de..d881f5b 100644 --- a/src/patcher/function_hooks.h +++ b/src/patcher/function_hooks.h @@ -18,6 +18,7 @@ extern void swapVoices(); extern void drcSwap(); int swapForce; +unsigned int homeCoolDown; void PatchMethodHooks(void); void RestoreInstructions(void); unsigned int GetAddressOfFunction(const char * functionName,unsigned int library);