Skip to content

Commit 5bc42b1

Browse files
committed
USB ports can now be assigned in config file the same way as in Pro1 Hook.
1 parent a2607be commit 5bc42b1

6 files changed

Lines changed: 79 additions & 1 deletion

File tree

cmake/src/main/hook/pro2/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
1212
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-fPIC")
1313
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
1414

15-
target_link_libraries(${PROJECT_NAME} hook-core patch ptapi-io-piuio-util util dl pthread)
15+
target_link_libraries(${PROJECT_NAME} hook-core patch propatch ptapi-io-piuio-util util dl pthread)

dist/conf/pro2hook.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ patch.piuio.emu_lib=
2525
# [bool (0/1)]: Enable game exit on Test + Service
2626
patch.piuio_exit.test_serv=0
2727

28+
# [str]: Bus and port (format: X-X, e.g. 1-2) of the USB slot to assign to Player 1 when a USB thumb drive is plugged in
29+
patch.usb_profile.p1.bus_port=
30+
31+
# [str]: Bus and port (format: X-X, e.g. 1-2) of the USB slot to assign to Player 2 when a USB thumb drive is plugged in
32+
patch.usb_profile.p2.bus_port=
33+
34+
# [str]: Device nodes of plugged in USB thumb drives to consider for mounting for usb profiles, format: sdX,sdY e.g. sde,sdf
35+
patch.usb_profile.dev_nodes=
36+
2837
# [str]: Path to a library implementing the x11-input-handler api to capture X11 keyboard inputs
2938
patch_x11_event_loop.input_handler_lib=
3039

doc/hook/pro2hook.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ Each folder with the content from the dump.
6464
## USB thumb drive/profile support
6565
See instructions on the [prohook readme](prohook.md#usb-thumb-driveprofile-support).
6666

67+
When using `pro2hook.so`, make sure your `hook.conf` contains the same USB
68+
profile keys used by Pro 1:
69+
70+
```text
71+
patch.usb_profile.p1.bus_port=2-1
72+
patch.usb_profile.p2.bus_port=2-2
73+
patch.usb_profile.dev_nodes=sdb,sdc
74+
```
75+
6776
## Troubleshooting and FAQ
6877
Since the game is based on Pro 1, have a look at the
6978
[troubleshooting section there](19-pro.md#troubleshooting-and-faq). Most of the things listed there

src/main/hook/pro2/main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "hook/patch/usb-init-fix.h"
2020
#include "hook/patch/x11-event-loop.h"
2121

22+
#include "hook/propatch/usb-fix.h"
23+
2224
#include "hook/patch/piubtn.h"
2325
#include "hook/patch/piuio.h"
2426

@@ -160,6 +162,14 @@ static void pro2hook_patch_x11_event_loop_init(struct pro2hook_options *options)
160162
}
161163
}
162164

165+
static void pro2hook_patch_usbprofiles(struct pro2hook_options *options)
166+
{
167+
propatch_usb_fix_init(
168+
options->patch.usb_profile.device_nodes,
169+
options->patch.usb_profile.p1_bus_port,
170+
options->patch.usb_profile.p2_bus_port);
171+
}
172+
163173
static void pro2hook_patch_piuio_init(struct pro2hook_options *options)
164174
{
165175
log_assert(options);
@@ -236,6 +246,7 @@ void pro2hook_trap_before_main(int argc, char **argv)
236246
pro2hook_fs_redirs_init(&options);
237247
pro2hook_patch_sigsegv_init(&options);
238248
pro2hook_patch_x11_event_loop_init(&options);
249+
pro2hook_patch_usbprofiles(&options);
239250
pro2hook_patch_piuio_init(&options);
240251
pro2hook_patch_piubtn_init(&options);
241252
pro2hook_patch_secure_binary();
@@ -245,6 +256,7 @@ void pro2hook_trap_before_main(int argc, char **argv)
245256

246257
void pro2hook_trap_after_main(void)
247258
{
259+
propatch_usb_fix_shutdown();
248260
patch_piubtn_shutdown();
249261
patch_piuio_shutdown();
250262
}

src/main/hook/pro2/options.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
#define PRO2HOOK_OPTIONS_STR_PATCH_PIUIO_EMU_LIB "patch.piuio.emu_lib"
1313
#define PRO2HOOK_OPTIONS_STR_PATCH_PIUIO_EXIT_TEST_SERV \
1414
"patch.piuio_exit.test_serv"
15+
#define PRO2HOOK_OPTIONS_STR_PATCH_USB_PROFILE_P1_BUS_PORT \
16+
"patch.usb_profile.p1.bus_port"
17+
#define PRO2HOOK_OPTIONS_STR_PATCH_USB_PROFILE_P2_BUS_PORT \
18+
"patch.usb_profile.p2.bus_port"
19+
#define PRO2HOOK_OPTIONS_STR_PATCH_USB_PROFILE_DEV_NODES \
20+
"patch.usb_profile.dev_nodes"
1521
#define PRO2HOOK_OPTIONS_STR_PATCH_X11_EVENT_LOOP_INPUT_HANDLER \
1622
"patch_x11_event_loop.input_handler_lib"
1723
#define PRO2HOOK_OPTIONS_STR_PATCH_X11_EVENT_LOOP_INPUT_HANDLER2 \
@@ -94,6 +100,36 @@ const struct util_options_def pro2hook_options_def[] = {
94100
.is_secret_data = false,
95101
.default_value.b = false,
96102
},
103+
{
104+
.name = PRO2HOOK_OPTIONS_STR_PATCH_USB_PROFILE_P1_BUS_PORT,
105+
.description = "Bus and port (format: X-X, e.g. 1-2) of the USB slot "
106+
"to assign to Player 1 when a USB thumb "
107+
"drive is plugged in",
108+
.param = 'a',
109+
.type = UTIL_OPTIONS_TYPE_STR,
110+
.is_secret_data = false,
111+
.default_value.str = NULL,
112+
},
113+
{
114+
.name = PRO2HOOK_OPTIONS_STR_PATCH_USB_PROFILE_P2_BUS_PORT,
115+
.description = "Bus and port (format: X-X, e.g. 1-2) of the USB slot "
116+
"to assign to Player 2 when a USB thumb "
117+
"drive is plugged in",
118+
.param = 'k',
119+
.type = UTIL_OPTIONS_TYPE_STR,
120+
.is_secret_data = false,
121+
.default_value.str = NULL,
122+
},
123+
{
124+
.name = PRO2HOOK_OPTIONS_STR_PATCH_USB_PROFILE_DEV_NODES,
125+
.description = "Device nodes of plugged in USB thumb drives to "
126+
"consider for mounting for usb profiles, format: "
127+
"sdX,sdY e.g. sde,sdf",
128+
.param = 't',
129+
.type = UTIL_OPTIONS_TYPE_STR,
130+
.is_secret_data = false,
131+
.default_value.str = NULL,
132+
},
97133
{
98134
.name = PRO2HOOK_OPTIONS_STR_PATCH_X11_EVENT_LOOP_INPUT_HANDLER,
99135
.description = "Path to a library implementing the x11-input-handler "
@@ -172,6 +208,12 @@ bool pro2hook_options_init(
172208
options_opt, PRO2HOOK_OPTIONS_STR_PATCH_PIUIO_EMU_LIB);
173209
options->patch.piuio.exit_test_serv = util_options_get_bool(
174210
options_opt, PRO2HOOK_OPTIONS_STR_PATCH_PIUIO_EXIT_TEST_SERV);
211+
options->patch.usb_profile.device_nodes = util_options_get_str(
212+
options_opt, PRO2HOOK_OPTIONS_STR_PATCH_USB_PROFILE_DEV_NODES);
213+
options->patch.usb_profile.p1_bus_port = util_options_get_str(
214+
options_opt, PRO2HOOK_OPTIONS_STR_PATCH_USB_PROFILE_P1_BUS_PORT);
215+
options->patch.usb_profile.p2_bus_port = util_options_get_str(
216+
options_opt, PRO2HOOK_OPTIONS_STR_PATCH_USB_PROFILE_P2_BUS_PORT);
175217
options->patch.x11_event_loop.api_lib = util_options_get_str(
176218
options_opt, PRO2HOOK_OPTIONS_STR_PATCH_X11_EVENT_LOOP_INPUT_HANDLER);
177219
options->patch.x11_event_loop.api_lib2 = util_options_get_str(

src/main/hook/pro2/options.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ struct pro2hook_options {
2929
bool exit_test_serv;
3030
} piuio;
3131

32+
struct usb_profile {
33+
const char *device_nodes;
34+
const char *p1_bus_port;
35+
const char *p2_bus_port;
36+
} usb_profile;
37+
3238
struct x11_event_loop {
3339
const char *api_lib;
3440
const char *api_lib2;

0 commit comments

Comments
 (0)