-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuttonswap.c
87 lines (66 loc) · 2.8 KB
/
buttonswap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Button Swap taiHEN plugin
// Copyright (c) 2016 Scorp
#include <psp2/kernel/modulemgr.h>
#include <psp2/ctrl.h>
#include <taihen.h>
static SceUID g_hooks[4];
int invertButtons(int port, tai_hook_ref_t ref_hook, 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_hook1;
static int keys_patched1(int port, SceCtrlData *ctrl, int count) {
return invertButtons(port, ref_hook1, ctrl, count);
}
static tai_hook_ref_t ref_hook2;
static int keys_patched2(int port, SceCtrlData *ctrl, int count) {
return invertButtons(port, ref_hook2, ctrl, count);
}
static tai_hook_ref_t ref_hook3;
static int keys_patched3(int port, SceCtrlData *ctrl, int count) {
return invertButtons(port, ref_hook3, ctrl, count);
}
static tai_hook_ref_t ref_hook4;
static int keys_patched4(int port, SceCtrlData *ctrl, int count) {
return invertButtons(port, ref_hook4, ctrl, count);
}
void _start() __attribute__ ((weak, alias ("module_start")));
int module_start(SceSize argc, const void *args) {
g_hooks[0] = taiHookFunctionImport(&ref_hook1,
TAI_MAIN_MODULE,
TAI_ANY_LIBRARY,
0xA9C3CED6, // sceCtrlPeekBufferPositive
keys_patched1);
g_hooks[1] = taiHookFunctionImport(&ref_hook2,
TAI_MAIN_MODULE,
TAI_ANY_LIBRARY,
0x15F81E8C, // sceCtrlPeekBufferPositive2
keys_patched2);
g_hooks[2] = taiHookFunctionImport(&ref_hook3,
TAI_MAIN_MODULE,
TAI_ANY_LIBRARY,
0x67E7AB83, // sceCtrlReadBufferPositive
keys_patched3);
g_hooks[3] = taiHookFunctionImport(&ref_hook4,
TAI_MAIN_MODULE,
TAI_ANY_LIBRARY,
0xC4226A3E, // sceCtrlReadBufferPositive2
keys_patched4);
return SCE_KERNEL_START_SUCCESS;
}
int module_stop(SceSize argc, const void *args) {
// free hooks that didn't fail
if (g_hooks[0] >= 0) taiHookRelease(g_hooks[0], ref_hook1);
if (g_hooks[1] >= 0) taiHookRelease(g_hooks[1], ref_hook2);
if (g_hooks[2] >= 0) taiHookRelease(g_hooks[2], ref_hook3);
if (g_hooks[3] >= 0) taiHookRelease(g_hooks[3], ref_hook4);
return SCE_KERNEL_STOP_SUCCESS;
}