Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import <VideoSubscriberAccount/VideoSubscriberAccount.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreMotion/CoreMotion.h>
#import <GameController/GameController.h>

__attribute__((visibility("hidden")))
@interface PTSwizzleLoader : NSObject
Expand Down Expand Up @@ -62,6 +63,30 @@ - (void) swizzleExchangeMethod:(SEL)origSelector withMethod:(SEL)newSelector
method_exchangeImplementations(originalMethod, swizzledMethod);
}

+ (void) swizzleClassMethod:(SEL)origSelector withMethod:(SEL)newSelector {
Class cls = object_getClass((id)self);
Method originalMethod = class_getClassMethod(cls, origSelector);
Method swizzledMethod = class_getClassMethod(cls, newSelector);

if (class_addMethod(cls,
origSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod))) {
class_replaceMethod(cls,
newSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
class_replaceMethod(cls,
newSelector,
class_replaceMethod(cls,
origSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod)),
method_getTypeEncoding(originalMethod));
}
}

- (BOOL) hook_prefersPointerLocked {
return false;
}
Expand Down Expand Up @@ -160,6 +185,14 @@ - (instancetype)hook_CMMotionManager_init {
return motionManager;
}

+ (GCMouse *)hook_GCMouse_current {
return nil;
}

+ (NSArray *)hook_GCMouse_mice {
return @[];
}

// Hook for UIUserInterfaceIdiom

// - (long long) hook_userInterfaceIdiom {
Expand Down Expand Up @@ -301,6 +334,11 @@ + (void)load {
if ([[PlaySettings shared] limitMotionUpdateFrequency]) {
[objc_getClass("CMMotionManager") swizzleInstanceMethod:@selector(init) withMethod:@selector(hook_CMMotionManager_init)];
}

if (([[PlaySettings shared] disableBuiltinMouse])) {
[objc_getClass("GCMouse") swizzleClassMethod:@selector(current) withMethod:@selector(hook_GCMouse_current)];
[objc_getClass("GCMouse") swizzleClassMethod:@selector(mice) withMethod:@selector(hook_GCMouse_mice)];
}
}

@end
32 changes: 32 additions & 0 deletions PlayTools/Controls/PlayInput.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import UIKit
import GameController

// This class is a coordinator (and module entrance), coordinating other concrete classes

Expand All @@ -19,6 +20,10 @@ class PlayInput {
let displaylink = CADisplayLink(target: self, selector: #selector(drainMainDispatchQueue))
displaylink.add(to: .main, forMode: .common)

if PlaySettings.shared.disableBuiltinMouse {
simulateGCMouseDisconnect()
}

if !PlaySettings.shared.keymapping {
return
}
Expand All @@ -41,4 +46,31 @@ class PlayInput {
}
mode.initialize()
}

private func simulateGCMouseDisconnect() {
NotificationCenter.default.addObserver(
forName: .GCMouseDidConnect,
object: nil,
queue: .main
) { nofitication in
guard let mouse = nofitication.object as? GCMouse else {
return
}
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1)) {
NotificationCenter.default.post(name: .GCMouseDidDisconnect, object: mouse)
mouse.mouseInput?.leftButton.pressedChangedHandler = nil
mouse.mouseInput?.leftButton.valueChangedHandler = nil
mouse.mouseInput?.rightButton?.pressedChangedHandler = nil
mouse.mouseInput?.rightButton?.valueChangedHandler = nil
mouse.mouseInput?.middleButton?.pressedChangedHandler = nil
mouse.mouseInput?.middleButton?.valueChangedHandler = nil
mouse.mouseInput?.auxiliaryButtons?.forEach { button in
button.pressedChangedHandler = nil
button.valueChangedHandler = nil
}
mouse.mouseInput?.scroll.valueChangedHandler = nil
mouse.mouseInput?.mouseMovedHandler = nil
}
}
}
}
3 changes: 3 additions & 0 deletions PlayTools/PlaySettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ let settings = PlaySettings.shared
@objc lazy var checkMicPermissionSync = settingsData.checkMicPermissionSync

@objc lazy var limitMotionUpdateFrequency = settingsData.limitMotionUpdateFrequency

@objc lazy var disableBuiltinMouse = settingsData.disableBuiltinMouse
}

struct AppSettingsData: Codable {
Expand Down Expand Up @@ -114,4 +116,5 @@ struct AppSettingsData: Codable {
var hideTitleBar = false
var checkMicPermissionSync = false
var limitMotionUpdateFrequency = false
var disableBuiltinMouse = false
}