diff --git a/.gitignore b/.gitignore index 3e35c18..6b42bc5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ build/ *.nacp *.nro +*.DS_Store diff --git a/Overlay/Makefile b/Overlay/Makefile index f881ed9..7184bb0 100644 --- a/Overlay/Makefile +++ b/Overlay/Makefile @@ -38,7 +38,7 @@ include $(DEVKITPRO)/libnx/switch_rules # NACP building is skipped as well. #--------------------------------------------------------------------------------- APP_TITLE := ReverseNX-RT -APP_VERSION := 1.0.1 +APP_VERSION := 1.0.2-OC TARGET := ReverseNX-RT-ovl BUILD := build @@ -53,7 +53,7 @@ NO_ICON := 1 #--------------------------------------------------------------------------------- ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE -CFLAGS := -g -Wall -Os -ffunction-sections \ +CFLAGS := -g -Wall -O2 -ffunction-sections \ $(ARCH) $(DEFINES) CFLAGS += $(INCLUDE) -D__SWITCH__ -DAPP_VERSION="\"$(APP_VERSION)\"" diff --git a/Overlay/libs/Atmosphere-libs b/Overlay/libs/Atmosphere-libs index 2d522dc..c4d0335 160000 --- a/Overlay/libs/Atmosphere-libs +++ b/Overlay/libs/Atmosphere-libs @@ -1 +1 @@ -Subproject commit 2d522dc6a12b2eb5eb3f103a8c5b5126ca301b1a +Subproject commit c4d0335b79da7207b49abf1988f45b0168b692f0 diff --git a/Overlay/libs/libtesla b/Overlay/libs/libtesla index 6628524..640629f 160000 --- a/Overlay/libs/libtesla +++ b/Overlay/libs/libtesla @@ -1 +1 @@ -Subproject commit 66285245361a02e5480c7bb7dac9ef6449ae6181 +Subproject commit 640629f49f9e8997ef0769b21b26f4fc177c736f diff --git a/Overlay/source/main.cpp b/Overlay/source/main.cpp index cec060c..90c020b 100644 --- a/Overlay/source/main.cpp +++ b/Overlay/source/main.cpp @@ -1,9 +1,12 @@ #define TESLA_INIT_IMPL // If you have more than one file using the tesla header, only define this in the main one #include // The Tesla Header +#include #include "dmntcht.h" bool def = true; +bool defChanged = false; bool isDocked = false; +bool isDockedChanged = false; bool PluginRunning = false; bool closed = false; Handle debug; @@ -20,6 +23,10 @@ bool plugin = false; char DockedChar[32]; char SystemChar[32]; char PluginChar[36]; +char SysclkChar[36]; +static Service g_sysclkSrv; +static std::atomic g_refCnt; +bool sysclkComm = false; bool CheckPort () { Handle saltysd; @@ -54,6 +61,57 @@ bool isServiceRunning(const char *serviceName) { } } +#define SYSCLK_IPC_API_VERSION 1 +#define SYSCLK_IPC_SERVICE_NAME "sysclkOC" + +enum SysClkIpcCmd +{ + SysClkIpcCmd_GetApiVersion = 0, + SysClkIpcCmd_SetReverseNXRTMode = 11, +}; + +void sysclkIpcExit(void) +{ + if (--g_refCnt == 0) + { + serviceClose(&g_sysclkSrv); + } +} + +Result sysclkIpcInitialize(void) +{ + Result rc = 0; + + g_refCnt++; + + if (serviceIsActive(&g_sysclkSrv)) + return 0; + + rc = smGetService(&g_sysclkSrv, SYSCLK_IPC_SERVICE_NAME); + + if (R_FAILED(rc)) sysclkIpcExit(); + + return rc; +} + +Result sysclkIpcGetAPIVersion(u32* out_ver) +{ + return serviceDispatchOut(&g_sysclkSrv, SysClkIpcCmd_GetApiVersion, *out_ver); +} + +typedef enum +{ + ReverseNX_SystemDefault = 0, + ReverseNX_Handheld, + ReverseNX_Docked, + ReverseNX_RTResetToDefault, +} ReverseNXMode; + +Result sysclkIpcSetReverseNXRTMode(ReverseNXMode mode) +{ + return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetReverseNXRTMode, mode); +} + class GuiTest : public tsl::Gui { public: GuiTest(u8 arg1, u8 arg2, bool arg3) { } @@ -88,6 +146,7 @@ public: else { renderer->drawString(SystemChar, false, x, y+40, 20, renderer->a(0xFFFF)); renderer->drawString(DockedChar, false, x, y+60, 20, renderer->a(0xFFFF)); + renderer->drawString(SysclkChar, false, x, y+80, 20, renderer->a(0xFFFF)); } } }), 100); @@ -95,9 +154,10 @@ public: if (MAGIC == 0x06BA7E39) { auto *clickableListItem = new tsl::elm::ListItem("Change system control"); clickableListItem->setClickListener([](u64 keys) { - if (keys & KEY_A) { + if (keys & HidNpadButton_A) { if (PluginRunning == true) { def = !def; + defChanged = true; if (dmntcht == true) { dmntchtWriteCheatProcessMemory(def_address, &def, 0x1); dmntchtReadCheatProcessMemory(def_address, &def, 0x1); @@ -120,9 +180,10 @@ public: auto *clickableListItem2 = new tsl::elm::ListItem("Change mode"); clickableListItem2->setClickListener([](u64 keys) { - if (keys & KEY_A) { + if (keys & HidNpadButton_A) { if (PluginRunning == true && def == false) { isDocked =! isDocked; + isDockedChanged = true; if (dmntcht == true) { dmntchtWriteCheatProcessMemory(docked_address, &isDocked, 0x1); dmntchtReadCheatProcessMemory(docked_address, &isDocked, 0x1); @@ -145,7 +206,7 @@ public: else if (SaltySD == true && plugin == true && check == false) { auto *clickableListItem = new tsl::elm::ListItem("(De)activate plugin"); clickableListItem->setClickListener([](u64 keys) { - if (keys & KEY_A) { + if (keys & HidNpadButton_A) { if (bak == false) { rename("sdmc:/SaltySD/plugins/ReverseNX-RT.elf", "sdmc:/SaltySD/plugins/ReverseNX-RT.elf.bak"); bak = true; @@ -179,12 +240,22 @@ public: closed = true; } if (PluginRunning == true) { - if (i > 59) { + if (i > 29) { if (dmntcht == true) dmntchtReadCheatProcessMemory(docked_address, &isDocked, 0x1); else if (R_SUCCEEDED(svcDebugActiveProcess(&debug, PID))) { svcReadDebugProcessMemory(&isDocked, debug, docked_address, 0x1); svcCloseHandle(debug); } + if (sysclkComm && !bak) { + if (!def && isDockedChanged) { + isDockedChanged = false; + sysclkIpcSetReverseNXRTMode(isDocked ? ReverseNX_Docked : ReverseNX_Handheld); + } + if (def && defChanged) { + defChanged = false; + sysclkIpcSetReverseNXRTMode(ReverseNX_RTResetToDefault); + } + } i = 0; } else i++; @@ -198,11 +269,10 @@ public: if (bak == false) sprintf(PluginChar, "ReverseNX-RT plugin is activated."); else sprintf(PluginChar, "ReverseNX-RT plugin is deactivated."); - } // Called once every frame to handle inputs not handled by other UI elements - virtual bool handleInput(u64 keysDown, u64 keysHeld, touchPosition touchInput, JoystickPosition leftJoyStick, JoystickPosition rightJoyStick) override { + virtual bool handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight) override { return false; // Return true here to singal the inputs have been consumed } }; @@ -234,6 +304,13 @@ public: else return; } + // Initialize sysclkIpc + if (isServiceRunning(SYSCLK_IPC_SERVICE_NAME)) { + uint32_t apiVer; + if (R_SUCCEEDED(sysclkIpcInitialize()) && R_SUCCEEDED(sysclkIpcGetAPIVersion(&apiVer)) && apiVer == SYSCLK_IPC_API_VERSION) + sysclkComm = true; + } + if (R_FAILED(pmdmntGetApplicationProcessId(&PID))) remove("sdmc:/SaltySD/ReverseNX-RT.hex"); else { check = true; @@ -278,10 +355,13 @@ public: if (def == true) sprintf(SystemChar, "Controlled by system: Yes"); else sprintf(SystemChar, "Controlled by system: No"); + + sprintf(SysclkChar, "Sys-clk-OC Sync Service: %s", sysclkComm ? "ON" : "OFF"); } // Called at the start to initialize all services necessary for this Overlay virtual void exitServices() override { + sysclkIpcExit(); dmntchtExit(); if (dmntcht == false) svcCloseHandle(debug); fsdevUnmountDevice("sdmc");