Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
U-Speccy\Scorp authored and U-Speccy\Scorp committed Dec 16, 2016
0 parents commit 4c7b227
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
44 changes: 44 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
75 changes: 75 additions & 0 deletions buttonswap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <psp2/kernel/modulemgr.h>
#include <psp2/ctrl.h>
#include <taihen.h>

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;
}
8 changes: 8 additions & 0 deletions buttonswap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ButtonSwap:
attributes: 0
version:
major: 1
minor: 1
main:
start: module_start
stop: module_stop

0 comments on commit 4c7b227

Please sign in to comment.