|
15 | 15 | #include <sys/mman.h> |
16 | 16 | #include <sandbox.h> |
17 | 17 |
|
| 18 | +#include <CoreFoundation/CoreFoundation.h> |
| 19 | +#include <IOKit/hid/IOHIDDevice.h> |
| 20 | + |
18 | 21 | #include "bo3macnative.h" |
19 | 22 | #include "codhavoktypes.h" |
20 | 23 | #include "dobby.h" |
@@ -365,6 +368,41 @@ FILE *popen_new(const char *command, const char *mode) { |
365 | 368 | DYLD_INTERPOSE(system_new, system); |
366 | 369 | DYLD_INTERPOSE(popen_new, popen); |
367 | 370 |
|
| 371 | +// this will get called in SDL2.0.7's FreeDevice, and not anywhere else, so it's safe |
| 372 | +void IOHIDDeviceUnscheduleFromRunLoop_new(IOHIDDeviceRef device, CFRunLoopRef runLoop, CFStringRef runLoopMode) |
| 373 | +{ |
| 374 | + IOHIDDeviceUnscheduleFromRunLoop(device, runLoop, runLoopMode); |
| 375 | + // release the device ref as per https://github.com/libsdl-org/SDL/commit/65fd63369411240dd54cad74916c6a6739e9363b |
| 376 | + //printf("releasing!\n"); |
| 377 | + CFRelease(device); |
| 378 | +} |
| 379 | +DYLD_INTERPOSE(IOHIDDeviceUnscheduleFromRunLoop_new, IOHIDDeviceUnscheduleFromRunLoop); |
| 380 | + |
| 381 | +// this will get called lots in SDL2.0.7's JoystickDeviceWasAddedCallback, so filter for PrimaryUsagePage |
| 382 | +CFTypeRef IOHIDDeviceGetProperty_hook(IOHIDDeviceRef device, CFStringRef key) |
| 383 | +{ |
| 384 | + CFTypeRef orig = IOHIDDeviceGetProperty(device, key); |
| 385 | + // that address is the CFString for PrimaryUsagePage |
| 386 | + if (orig != NULL && key == (void *)(game_base_address + 0x1b8b420)) |
| 387 | + { |
| 388 | + //printf("device = %p\n", device); |
| 389 | + //printf("key = %p\n", key); |
| 390 | + // get the actual usage to see if SDL2.0.7 would be retaining it anyway |
| 391 | + uint32_t usage = 0; |
| 392 | + if (CFNumberGetValue(orig, kCFNumberSInt32Type, &usage)) |
| 393 | + { |
| 394 | + // kHIDUsage_GD_Joystick, kHIDUsage_GD_GamePad, kHIDUsage_GD_MultiAxisController |
| 395 | + if ((usage < 9) && ((0x130U >> (usage & 0x1f) & 1) != 0)) { |
| 396 | + //printf("controller! retaining\n"); |
| 397 | + // retain the device ref as per https://github.com/libsdl-org/SDL/commit/65fd63369411240dd54cad74916c6a6739e9363b |
| 398 | + CFRetain(device); |
| 399 | + } |
| 400 | + } |
| 401 | + } |
| 402 | + return orig; |
| 403 | +} |
| 404 | +DYLD_INTERPOSE(IOHIDDeviceGetProperty_hook, IOHIDDeviceGetProperty); |
| 405 | + |
368 | 406 | int sandbox_init_with_parameters(const char *profile, uint64_t flags, const char *const parameters[], char **errorbuf); |
369 | 407 |
|
370 | 408 | #define EMUPATH_B "C:\\Emu\\AppAssets" |
|
0 commit comments