From 4c7b2276e997a2ae3e2b1afddec1226c1fd73207 Mon Sep 17 00:00:00 2001 From: "U-Speccy\\Scorp" Date: Fri, 16 Dec 2016 11:23:09 +0300 Subject: [PATCH] initial --- CMakeLists.txt | 44 +++++++++++++++++++++++++++++ README.md | 17 ++++++++++++ buttonswap.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ buttonswap.yml | 8 ++++++ 4 files changed, 144 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 buttonswap.c create mode 100644 buttonswap.yml diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..653ba2f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,44 @@ +cmake_minimum_required(VERSION 2.8) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) + if(DEFINED ENV{VITASDK}) + set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file") + else() + message(FATAL_ERROR "Please define VITASDK to point to your SDK path!") + endif() +endif() + +project(ButtonSwap) +include("${VITASDK}/share/vita.cmake" REQUIRED) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-q -Wall -O3 -std=gnu99") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions") + +include_directories( +) + +link_directories( + ${CMAKE_CURRENT_BINARY_DIR} +) + +if (NOT ${RELEASE}) + add_definitions(-DENABLE_LOGGING) +endif() + +add_executable(buttonswap + buttonswap.c +) + +target_link_libraries(buttonswap + taihen_stub + SceLibKernel_stub + SceIofilemgr_stub +) + +set_target_properties(buttonswap + PROPERTIES LINK_FLAGS "-nostdlib" +) + +vita_create_self(buttonswap.suprx buttonswap + CONFIG ${CMAKE_SOURCE_DIR}/buttonswap.yml +) diff --git a/README.md b/README.md new file mode 100644 index 0000000..6a2f81d --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Button Swap +taiHEN plugin for swapping X and O buttons on PSVita + +Installation +-------------------------------------------------------------------------------- + +Put "buttonswap.suprx" in 'tai' folder in the root of your Vita. + +Change config.txt in that directory to load plugin for title of your choice by adding new lines like below: + +```text +# titleid for your game (this one is for Root//Letter for example) +*PCSB01019 +ux0:tai/buttonswap.suprx +``` + +After that just run the game and your buttons should be swapped (this would work only for this game). \ No newline at end of file diff --git a/buttonswap.c b/buttonswap.c new file mode 100644 index 0000000..967307d --- /dev/null +++ b/buttonswap.c @@ -0,0 +1,75 @@ +#include +#include +#include + +static SceUID g_hooks[3]; + +static tai_hook_ref_t ref_hook; + +static int keys_patched(int port, SceCtrlData *ctrl, int count) { + + int ret; + + if (ref_hook == 0) + ret = 1; + else + { + ret = TAI_CONTINUE(int, ref_hook, port, ctrl, count); + + if ((ctrl->buttons & 0x6000) && ((ctrl->buttons & 0x6000) != 0x6000)) + ctrl->buttons = ctrl->buttons ^ 0x6000; + + } + return ret; +} + +static tai_hook_ref_t ref_hook2; + +static int keys_patched2(int port, SceCtrlData *ctrl, int count) { + + int ret; + + if (ref_hook2 == 0) + ret = 1; + else + { + ret = TAI_CONTINUE(int, ref_hook2, port, ctrl, count); + + if ((ctrl->buttons & 0x6000) && ((ctrl->buttons & 0x6000) != 0x6000)) + ctrl->buttons = ctrl->buttons ^ 0x6000; + + } + return ret; +} + + + +void _start() __attribute__ ((weak, alias ("module_start"))); + +int module_start(SceSize argc, const void *args) { + + ref_hook = 0; + ref_hook2 = 0; + + g_hooks[1] = taiHookFunctionImport(&ref_hook, + TAI_MAIN_MODULE, + TAI_ANY_LIBRARY, + 0xA9C3CED6, // sceCtrlPeekBufferPositive + keys_patched); + + g_hooks[2] = taiHookFunctionImport(&ref_hook2, + TAI_MAIN_MODULE, + TAI_ANY_LIBRARY, + 0x15F81E8C, // sceCtrlPeekBufferPositive2 + keys_patched2); + return SCE_KERNEL_START_SUCCESS; +} + +int module_stop(SceSize argc, const void *args) { + + // free hooks that didn't fail + if (g_hooks[1] >= 0) taiHookRelease(g_hooks[1], ref_hook); + if (g_hooks[2] >= 0) taiHookRelease(g_hooks[2], ref_hook2); + + return SCE_KERNEL_STOP_SUCCESS; +} diff --git a/buttonswap.yml b/buttonswap.yml new file mode 100644 index 0000000..07b732c --- /dev/null +++ b/buttonswap.yml @@ -0,0 +1,8 @@ +ButtonSwap: + attributes: 0 + version: + major: 1 + minor: 1 + main: + start: module_start + stop: module_stop