Skip to content

Commit

Permalink
Add support to change ControllerType
Browse files Browse the repository at this point in the history
  • Loading branch information
nowrep committed Jul 11, 2018
1 parent 2c49b2b commit 784b0ed
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,35 @@ taiHEN plugin that allows to force preferred Remote Play button configuration

### Configuration

By default it sets **keymap 0** - everything on back touchpad. Changing the keymap can be done
by creating `ux0:ps4linkcontrols.txt` file and writing the keymap number (0-7) there.
There are currently 2 options that can be set in configuration file `ux0:ps4linkcontrols.txt`.
First line should be keymap number and second line controller type.

For example, to set keymap = 2 and controller_type = 3, configuration file should contain:

```
2
3
```

#### Keymap

Keymap is a layout how are the additional buttons not present on Vita (L2/R2 and L3/R3) are mapped
on either back or front Vita touch pad.

By default it sets **keymap 0** - everything on back touchpad.
Available keymaps are in `vs0:app/NPXS10013/keymap/`(folder name is the keymap number).

#### Controller Type

Controller Type is how PS4Link app identifies itself when connecting to PS4. By changing this value
it is possible to disable Vita remote play controls customization for some PS4 games. Remote Play client
is available for multiple platforms (which each probably have its own type number), so you may try to experiment
with different values.
Setting this value to `3` (which is Windows Remote Play client) is confirmed to fix Metal Gear Solid V: The Phantom Pain
where it would otherwise remap Vita L/R triggers as L2/R2.

By default it sets **controller type 1** - default Vita value.

### Installation

Add this plugin under `*NPXS10013` section in `ux0:tai/config.txt`:
Expand Down
43 changes: 39 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ static SceUID g_hooks[3];

// vs0:app/NPXS10013/keymap
static int keymap_number = 0;
// RP-ControllerType
static int controller_type = 1;

// TheOfficialFloW/Adrenaline user/utils.c
#define THUMB_SHUFFLE(x) ((((x) & 0xFFFF0000) >> 16) | (((x) & 0xFFFF) << 16))
uint32_t encode_movw(uint8_t rd, uint16_t imm16)
{
uint32_t imm4 = (imm16 >> 12) & 0xF;
uint32_t i = (imm16 >> 11) & 0x1;
uint32_t imm3 = (imm16 >> 8) & 0x7;
uint32_t imm8 = imm16 & 0xFF;
return THUMB_SHUFFLE(0xF2400000 | (rd << 8) | (i << 26) | (imm4 << 16) | (imm3 << 12) | imm8);
}

struct RPJob {
char padding[436];
Expand Down Expand Up @@ -70,10 +83,20 @@ static void load_config()
SceUID fd = sceIoOpen("ux0:ps4linkcontrols.txt", SCE_O_RDONLY, 0);
if (fd >= 0) {
char value = 0;
sceIoRead(fd, &value, sizeof(value));
if (value >= '0' && value <= '7') {
// keymap
int ret = sceIoRead(fd, &value, sizeof(value));
if (ret == 1 && value >= '0' && value <= '7') {
keymap_number = value - '0';
}
// newline
ret = sceIoRead(fd, &value, sizeof(value));
if (ret == 1) {
// controller_type
ret = sceIoRead(fd, &value, sizeof(value));
if (ret == 1 && value >= '0' && value <= '9') {
controller_type = value - '0';
}
}
sceIoClose(fd);
}
}
Expand All @@ -91,26 +114,30 @@ int module_start(SceSize argc, const void *args)
return SCE_KERNEL_START_FAILED;
}

uint32_t offsets[3];
uint32_t offsets[4];

switch (info.module_nid) {
case 0x48A4A1C1: // 3.60
offsets[0] = 0x47a4c;
offsets[1] = 0x4612c;
offsets[2] = 0x457a8;
offsets[3] = 0x48C10;

case 0x4bc536e4: // 3.65
case 0x75CFBD26: // 3.68
offsets[0] = 0x47d2c;
offsets[1] = 0x4640c;
offsets[2] = 0x45a88;
offsets[3] = 0x48EF0;
break;

default:
LOG("ScePS4Link %X NID not recognized", info.module_nid);
return SCE_KERNEL_START_FAILED;
}

load_config();

g_hooks[0] = taiHookFunctionOffset(&ref_hook0,
info.modid,
0, // segidx
Expand All @@ -132,9 +159,17 @@ int module_start(SceSize argc, const void *args)
1, // thumb
rpjob_constructor_patched);

load_config();
// Replace LDR.W R11 [R9, 0xD24] = D9 F8 24 BD
// to MOVW R11, controller_type
uint32_t mov_r11_opcode = encode_movw(11, controller_type);
taiInjectData(info.modid,
0, // segidx
offsets[3], // offset
&mov_r11_opcode,
sizeof(mov_r11_opcode));

LOG("Using keymap %d", keymap_number);
LOG("Using controller type %d", controller_type);

return SCE_KERNEL_START_SUCCESS;
}
Expand Down

0 comments on commit 784b0ed

Please sign in to comment.