From 1157026b8b828c58d03e93ac74ba8ee598342e4c Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 8 Mar 2018 20:15:37 +0100 Subject: [PATCH] [Plugin] Increased the stability of the screenshot tool --- plugins/screenshot/src/function_patcher.cpp | 14 +++++++------- plugins/screenshot/src/main.cpp | 6 +++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/plugins/screenshot/src/function_patcher.cpp b/plugins/screenshot/src/function_patcher.cpp index 7da6c8d..4f6475f 100644 --- a/plugins/screenshot/src/function_patcher.cpp +++ b/plugins/screenshot/src/function_patcher.cpp @@ -11,15 +11,15 @@ #include "screenshot_utils.h" #include "retain_vars.hpp" -static bool takeScreenshotTV = false; -static bool takeScreenshotDRC = false; -static u8 screenshotCooldown = 0; -static u32 counter = 0; +static bool takeScreenshotTV __attribute__((section(".data"))) = false; +static bool takeScreenshotDRC __attribute__((section(".data"))) = false; +static u8 screenshotCooldown __attribute__((section(".data"))) = 0; +static u32 counter __attribute__((section(".data"))) = 0; DECL_FUNCTION(int, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *error) { int result = real_VPADRead(chan, buffer, buffer_size, error); - u32 btns = gButtonCombo; - if(result > 0 && (buffer[0].btns_h == btns) && screenshotCooldown == 0 && OSIsHomeButtonMenuEnabled()) { + + if(result > 0 && (buffer[0].btns_h == gButtonCombo) && screenshotCooldown == 0 && OSIsHomeButtonMenuEnabled()) { counter++; takeScreenshotTV = true; takeScreenshotDRC = true; @@ -34,7 +34,7 @@ DECL_FUNCTION(int, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *e } DECL_FUNCTION(void, GX2CopyColorBufferToScanBuffer, const GX2ColorBuffer *colorBuffer, s32 scan_target) { - if(takeScreenshotTV || takeScreenshotDRC) { + if((takeScreenshotTV || takeScreenshotDRC) && gAppStatus == WUPS_APP_STATUS_FOREGROUND) { OSCalendarTime output; OSTicksToCalendarTime(OSGetTime(), &output); char buffer[255] = {0}; diff --git a/plugins/screenshot/src/main.cpp b/plugins/screenshot/src/main.cpp index 004d307..f3eda13 100644 --- a/plugins/screenshot/src/main.cpp +++ b/plugins/screenshot/src/main.cpp @@ -36,8 +36,10 @@ INITIALIZE_PLUGIN() { InitOSFunctionPointers(); InitVPadFunctionPointers(); u32 res = SplashScreen(10,2); - gButtonCombo = res; + gButtonCombo = res; + ICInvalidateRange((void*)(&gButtonCombo), 4); + DCFlushRange((void*)(&gButtonCombo), 4); } // Called whenever an application was started. @@ -46,6 +48,8 @@ ON_APPLICATION_START(my_args) { InitSocketFunctionPointers(); InitFSFunctionPointers(); + gAppStatus = WUPS_APP_STATUS_FOREGROUND; + log_init(); }