├── OpenEmuSystem ├── OpenEmuSystem.private.modulemap ├── OpenEmuSystemPrivate │ ├── module.modulemap │ └── OpenEmuSystemPrivate.h ├── OpenEmuSystem-Prefix.pch ├── OEPS3HIDDeviceHandler.h ├── OEXBox360HIDDeviceHander.h ├── OEBindingDescription.h ├── OEXBox360HIDDeviceHander.m ├── OEBindingDescription.m ├── OEPS3HIDDeviceHandler.m ├── OEPS4HIDDeviceHandler.h ├── OEDeviceManager_Internal.h ├── OEHIDDeviceParser.h ├── OEFile.h ├── OECloneCD.h ├── OETouchbarHIDDeviceHandler.h ├── OETouchbarHIDDeviceHandler.m ├── OESwitchProControllerHIDDeviceHandler.h ├── OEDreamcastGDI.h ├── OEM3UFile.h ├── OEDiscDescriptor_Internal.h ├── OEBindingDescription_Internal.h ├── NSResponder+OEHIDAdditions.h ├── OEDeviceDescription.h ├── OEEvent.h ├── OECloneCD.m ├── OEBindingMap.h ├── OECUESheet.h ├── OEMultiHIDDeviceHandler.h ├── DataProtocol+HexString.swift ├── OpenEmuSystem.h ├── OEBindingsController.h ├── OEControlDescription.h ├── OEEvent.m ├── OEControllerDescription_Internal.h ├── OEDiscDescriptor.h ├── OEWiimoteHIDDeviceHandler.h ├── OEControllerDescription.h ├── NSResponder+OEHIDAdditions.m ├── OEPlayerBindings.h ├── OEKeyBindingGroupDescription.h ├── OEDeviceManager.h ├── OEKeyBindingDescription.h ├── OEMultiHIDDeviceHandler.m ├── OEHIDDeviceHandler.h ├── OEFile.m ├── OEDeviceDescription.m ├── OESystemResponder.h ├── OEDreamcastGDI.m ├── OEBindingsController_Internal.h ├── OEHIDEvent.h ├── OEBindingMap.m ├── OESystemBindings.h ├── OEM3UFile.m ├── OEPS4HIDDeviceHandler.m ├── OEDeviceHandler.h ├── OEHIDEvent_Internal.h └── OELocalizationHelper.swift ├── OpenEmuBaseTests ├── OpenEmuBaseTests-Bridging-Header.h └── OEDiffQueueTests.m ├── .gitignore ├── OpenEmuBase ├── OEPropertyList.h ├── OEAbstractAdditions.h ├── OEDiffQueue.h ├── NSDictionary+OpenEmuSDK.h ├── NSUserDefaults+OpenEmuSDK.h ├── OELogging.h ├── NSDictionary+OpenEmuSDK.m ├── OETimingUtils.h ├── OESystemResponderClient.h ├── NSUserDefaults+OpenEmuSDK.m ├── OELogging.m ├── OpenEmuBase.h ├── OEGeometry.m ├── OEGeometry.swift ├── OERingBuffer.h ├── OEAbstractAdditions.m ├── OEAudioBuffer.h └── OEGameCoreController.h ├── OpenEmuSystemTests └── NSDataCategoryTests.m └── OpenEmu-SDK.xcodeproj └── xcshareddata └── xcschemes ├── OpenEmuBase.xcscheme └── OpenEmuSystem.xcscheme /OpenEmuSystem/OpenEmuSystem.private.modulemap: -------------------------------------------------------------------------------- 1 | module OpenEmuSystem.OpenEmuSystemPrivate { 2 | export * 3 | } 4 | -------------------------------------------------------------------------------- /OpenEmuSystem/OpenEmuSystemPrivate/module.modulemap: -------------------------------------------------------------------------------- 1 | module OpenEmuSystemPrivate { 2 | header "OpenEmuSystemPrivate.h" 3 | export * 4 | } 5 | -------------------------------------------------------------------------------- /OpenEmuBaseTests/OpenEmuBaseTests-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | 5 | -------------------------------------------------------------------------------- /OpenEmuSystem/OpenEmuSystem-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'OpenEmuSystem' target in the 'OpenEmuSystem' project 3 | // 4 | 5 | #define TODO(x) 6 | #define FIXME(x) 7 | #define NOTE(x) 8 | 9 | #define BOOL_STR(value) ((value) ? "YES" : "NO") 10 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEPS3HIDDeviceHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // OEPS3HIDDeviceHandler.h 3 | // OpenEmu 4 | // 5 | // Created by Joshua Weinberg on 12/30/12. 6 | // 7 | // 8 | 9 | #import "OEHIDDeviceHandler.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface OEPS3HIDDeviceHandler : OEHIDDeviceHandler 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEXBox360HIDDeviceHander.h: -------------------------------------------------------------------------------- 1 | // 2 | // OEXBox360HIDDeviceHander.h 3 | // OpenEmu 4 | // 5 | // Created by Joshua Weinberg on 12/30/12. 6 | // 7 | // 8 | 9 | #import "OEHIDDeviceHandler.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface OEXBox360HIDDeviceHander : OEHIDDeviceHandler 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | DerivedData/ 3 | *.DS_Store 4 | OEBuildVersion.h 5 | */build/* 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | *.xcworkspace 15 | !OpenEmu.xcworkspace 16 | !default.xcworkspace 17 | xcuserdata 18 | profile 19 | *.moved-aside 20 | icon? 21 | .gitconfig 22 | -------------------------------------------------------------------------------- /OpenEmuSystem/OpenEmuSystemPrivate/OpenEmuSystemPrivate.h: -------------------------------------------------------------------------------- 1 | 2 | #import "../OEBindingDescription_Internal.h" 3 | #import "../OEBindingsController_Internal.h" 4 | #import "../OEControllerDescription_Internal.h" 5 | #import "../OEDeviceManager_Internal.h" 6 | #import "../OEDiscDescriptor_Internal.h" 7 | #import "../OEHIDEvent_Internal.h" 8 | #import "../OEHIDDeviceHandler.h" 9 | #import "../OEHIDDeviceParser.h" 10 | #import "../OEHIDUsageToVK.h" 11 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEBindingDescription.h: -------------------------------------------------------------------------------- 1 | // 2 | // OEBindingDescription.h 3 | // OpenEmu-SDK 4 | // 5 | // Created by Remy Demarest on 24/11/2015. 6 | // 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @class OESystemController; 14 | 15 | @interface OEBindingDescription : NSObject 16 | 17 | - (instancetype)init NS_UNAVAILABLE; 18 | 19 | @property (weak, nullable, readonly, nonatomic) OESystemController *systemController; 20 | 21 | @end 22 | 23 | NS_ASSUME_NONNULL_END 24 | -------------------------------------------------------------------------------- /OpenEmuBase/OEPropertyList.h: -------------------------------------------------------------------------------- 1 | // 2 | // OEPropertyList.h 3 | // OpenEmu-SDK 4 | // 5 | // Created by Remy Demarest on 22/12/2015. 6 | // 7 | // 8 | 9 | @protocol OEPropertyList 10 | @end 11 | 12 | @interface NSArray (OEPropertyList) 13 | @end 14 | 15 | @interface NSData (OEPropertyList) 16 | @end 17 | 18 | @interface NSDate (OEPropertyList) 19 | @end 20 | 21 | @interface NSDictionary (OEPropertyList) 22 | @end 23 | 24 | @interface NSNumber (OEPropertyList) 25 | @end 26 | 27 | @interface NSString (OEPropertyList) 28 | @end 29 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEXBox360HIDDeviceHander.m: -------------------------------------------------------------------------------- 1 | // 2 | // OEXBox360HIDDeviceHander.m 3 | // OpenEmu 4 | // 5 | // Created by Joshua Weinberg on 12/30/12. 6 | // 7 | // 8 | 9 | #import "OEXBox360HIDDeviceHander.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface OEDeviceHandler () 14 | @property(readwrite) NSUInteger deviceNumber; 15 | @end 16 | 17 | @implementation OEXBox360HIDDeviceHander 18 | 19 | + (BOOL)canHandleDevice:(IOHIDDeviceRef)device 20 | { 21 | NSString *deviceName = (__bridge id)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); 22 | return [deviceName isEqualToString:@"Controller"]; 23 | } 24 | 25 | - (void)setDeviceNumber:(NSUInteger)deviceNumber 26 | { 27 | // see: http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo#toc3 28 | [super setDeviceNumber:deviceNumber]; 29 | 30 | NSUInteger pattern = deviceNumber + 0x6; 31 | 32 | IOHIDDeviceSetReport([self device], 33 | kIOHIDReportTypeOutput, 34 | 0x0, 35 | (uint8_t[]){ 0x1, 0x3, pattern }, 36 | 3); 37 | } 38 | 39 | @end 40 | 41 | NS_ASSUME_NONNULL_END 42 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEBindingDescription.m: -------------------------------------------------------------------------------- 1 | // 2 | // OEBindingDescription.m 3 | // OpenEmu-SDK 4 | // 5 | // Created by Remy Demarest on 24/11/2015. 6 | // 7 | // 8 | 9 | #import "OEBindingDescription.h" 10 | 11 | #import "OESystemController.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | static NSString *const OEBindingDescriptionSystemControllerKey = @"OEBindingDescriptionSystemController"; 16 | 17 | @implementation OEBindingDescription 18 | 19 | - (instancetype)init 20 | { 21 | return nil; 22 | } 23 | 24 | - (instancetype)initWithSystemController:(OESystemController *)systemController; 25 | { 26 | if (!(self = [super init])) 27 | return nil; 28 | 29 | _systemController = systemController; 30 | 31 | return self; 32 | } 33 | 34 | - (id)copyWithZone:(nullable NSZone *)zone 35 | { 36 | return self; 37 | } 38 | 39 | + (BOOL)supportsSecureCoding 40 | { 41 | return YES; 42 | } 43 | 44 | - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder 45 | { 46 | if (!(self = [super init])) 47 | return nil; 48 | 49 | _systemController = [OESystemController systemControllerWithIdentifier:[aDecoder decodeObjectOfClass:[NSString class] forKey:OEBindingDescriptionSystemControllerKey]]; 50 | 51 | return self; 52 | } 53 | 54 | - (void)encodeWithCoder:(NSCoder *)aCoder 55 | { 56 | [aCoder encodeObject:_systemController.systemIdentifier forKey:OEBindingDescriptionSystemControllerKey]; 57 | } 58 | 59 | @end 60 | 61 | NS_ASSUME_NONNULL_END 62 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEPS3HIDDeviceHandler.m: -------------------------------------------------------------------------------- 1 | // 2 | // OEPS3HIDDeviceHandler.m 3 | // OpenEmu 4 | // 5 | // Created by Joshua Weinberg on 12/30/12. 6 | // 7 | // 8 | 9 | #import "OEPS3HIDDeviceHandler.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface OEDeviceHandler () 14 | @property(readwrite) NSUInteger deviceNumber; 15 | @end 16 | 17 | @implementation OEPS3HIDDeviceHandler { 18 | uint8_t _reportBuffer[128]; 19 | } 20 | 21 | + (BOOL)canHandleDevice:(IOHIDDeviceRef)device 22 | { 23 | NSString *deviceName = (__bridge id)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); 24 | return [deviceName hasPrefix:@"PLAYSTATION(R)3 Controller"]; 25 | } 26 | 27 | - (BOOL)connect 28 | { 29 | return YES; 30 | } 31 | 32 | - (void)disconnect 33 | { 34 | [super disconnect]; 35 | [self setDeviceNumber:0]; 36 | } 37 | 38 | - (void)setDeviceNumber:(NSUInteger)deviceNumber 39 | { 40 | [super setDeviceNumber:deviceNumber]; 41 | 42 | uint8_t dNum = (deviceNumber & 0x0F) << 1; 43 | const uint8_t control_packet[] = { 44 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, dNum, 0xFF, 0x27, 0x10, 46 | 0x10, 0x32, 0xFF, 0x27, 0x10, 0x00, 0x32, 47 | 0xFF, 0x27, 0x10, 0x00, 0x32, 0xFF, 0x27, 48 | 0x10, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 51 | }; 52 | 53 | IOHIDDeviceSetReport([self device], 54 | kIOHIDReportTypeOutput, 55 | 0x09, 56 | control_packet, 57 | sizeof(control_packet)); 58 | } 59 | 60 | @end 61 | 62 | NS_ASSUME_NONNULL_END 63 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEPS4HIDDeviceHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OEHIDDeviceHandler.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | @interface OEPS4HIDDeviceHandler : OEHIDDeviceHandler 32 | 33 | @end 34 | 35 | NS_ASSUME_NONNULL_END 36 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEDeviceManager_Internal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import "OEDeviceManager.h" 26 | 27 | @interface OEDeviceManager () 28 | 29 | - (void)OE_removeDeviceHandler:(__kindof OEDeviceHandler *)handler; 30 | 31 | @end 32 | 33 | -------------------------------------------------------------------------------- /OpenEmuBase/OEAbstractAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | 29 | @interface NSObject (OEAbstractAdditions) 30 | 31 | - (void)doesNotImplementSelector:(SEL)aSel; 32 | - (void)doesNotImplementOptionalSelector:(SEL)aSel; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEHIDDeviceParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #import "OEHIDDeviceHandler.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @interface OEHIDDeviceParser : NSObject 33 | 34 | @end 35 | 36 | NS_ASSUME_NONNULL_END 37 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEFile.h: -------------------------------------------------------------------------------- 1 | // 2 | // OEFile.h 3 | // OpenEmu-SDK 4 | // 5 | // Created by Remy Demarest on 28/08/2016. 6 | // 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface OEFile : NSObject 14 | 15 | + (void)registerClass:(Class)cls forFileExtension:(NSString *)fileExtension; 16 | + (nullable __kindof OEFile *)fileWithURL:(NSURL *)fileURL error:(NSError **)error; 17 | 18 | - (instancetype)init NS_UNAVAILABLE; 19 | - (nullable instancetype)initWithFileURL:(NSURL *)fileURL error:(NSError **)error; 20 | 21 | /// URL of the file with which the receiver was created. 22 | @property (nonatomic, copy, readonly) NSURL *fileURL; 23 | @property (nonatomic, copy, readonly) NSString *fileExtension; 24 | @property (nonatomic, readonly) NSUInteger fileSize; 25 | 26 | @property (nonatomic, copy, readonly) NSArray *allFileURLs; 27 | 28 | /// URL of the main data track file. 29 | @property (nonatomic, copy, readonly) NSURL *dataTrackFileURL; 30 | 31 | /// Return empty data if the range is invalid. 32 | - (NSData *)readDataInRange:(NSRange)dataRange; 33 | 34 | /// Return empty string if the range is invalid or 35 | /// if the data could not be read as an ASCII string. 36 | - (NSString *)readASCIIStringInRange:(NSRange)dataRange; 37 | 38 | - (nullable instancetype)fileByMovingFileToURL:(NSURL *)destinationURL error:(NSError **)error; 39 | - (nullable instancetype)fileByCopyingFileToURL:(NSURL *)destinationURL error:(NSError **)error; 40 | 41 | /// Move all the referenced files to the destinationURL directory. 42 | - (BOOL)moveToURL:(NSURL *)destinationURL error:(NSError **)error; 43 | 44 | /// Copy all the referenced files to the destinationURL directory. 45 | - (BOOL)copyToURL:(NSURL *)destinationURL error:(NSError **)error; 46 | 47 | @end 48 | 49 | NS_ASSUME_NONNULL_END 50 | -------------------------------------------------------------------------------- /OpenEmuSystem/OECloneCD.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #import 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | Class to handle .ccd files and manage img/sub files. 34 | */ 35 | @interface OECloneCD : OEDiscDescriptor 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /OpenEmuBase/OEDiffQueue.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015, OpenEmu Team 3 | 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the OpenEmu Team nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | @interface OEDiffQueue : NSObject 31 | 32 | - (instancetype)init; 33 | - (instancetype)initWithCapacity:(NSUInteger)capacity; 34 | 35 | - (void)push:(NSData *)aData; 36 | - (NSData *)pop; 37 | 38 | @property(readonly) NSUInteger count; 39 | @property(readonly) BOOL isEmpty; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /OpenEmuBase/NSDictionary+OpenEmuSDK.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import 26 | 27 | NS_ASSUME_NONNULL_BEGIN 28 | 29 | 30 | @interface NSDictionary (OpenEmuSDK) 31 | 32 | - (NSDictionary *)OE_dictionaryByAddingEntriesFromDictionary:(NSDictionary *)merge; 33 | 34 | @end 35 | 36 | 37 | NS_ASSUME_NONNULL_END 38 | -------------------------------------------------------------------------------- /OpenEmuBase/NSUserDefaults+OpenEmuSDK.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import 26 | 27 | @interface NSUserDefaults (OpenEmuSDK) 28 | 29 | @property (class, nonatomic, readonly, nonnull) NSUserDefaults *oe_application; 30 | 31 | + (nonnull instancetype)oe_applicationUserDefaults NS_SWIFT_UNAVAILABLE("Use oe_application instead"); 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /OpenEmuBase/OELogging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import 26 | 27 | extern os_log_t OE_LOG_AUDIO_READ, OE_LOG_AUDIO_WRITE; 28 | extern os_log_t OE_LOG_CORE_RUN; 29 | /*! used to track performance of rewind serialization and deserialization 30 | */ 31 | extern os_log_t OE_LOG_CORE_REWIND; 32 | 33 | /// Used for logging messages 34 | extern os_log_t OE_LOG_DEFAULT; 35 | 36 | -------------------------------------------------------------------------------- /OpenEmuBase/NSDictionary+OpenEmuSDK.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import "NSDictionary+OpenEmuSDK.h" 26 | 27 | 28 | @implementation NSDictionary (OpenEmuSDK) 29 | 30 | 31 | - (NSDictionary *)OE_dictionaryByAddingEntriesFromDictionary:(NSDictionary *)merge 32 | { 33 | NSMutableDictionary *res = [self mutableCopy]; 34 | [res addEntriesFromDictionary:merge]; 35 | return [res copy]; 36 | } 37 | 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /OpenEmuSystem/OETouchbarHIDDeviceHandler.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import "OEHIDDeviceHandler.h" 26 | 27 | enum { 28 | OETouchbarHIDDevicePID = 0x8600, 29 | OETouchbarHIDDeviceVID = 0x5ac 30 | }; 31 | 32 | /** A dummy device handler which exists solely because the Touchbar does not 33 | * have a product name or a location ID. */ 34 | 35 | @interface OETouchbarHIDDeviceHandler : OEHIDDeviceHandler 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /OpenEmuBase/OETimingUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | 29 | __BEGIN_DECLS 30 | NSTimeInterval OEMonotonicTime(void); 31 | void OEWaitUntil(NSTimeInterval time); 32 | 33 | void OEPerfMonitorSignpost(NSString *name, NSTimeInterval maximumTime); 34 | void OEPerfMonitorObserve(NSString *name, NSTimeInterval maximumTime, void (^block)(void)); 35 | BOOL OESetThreadRealtime(NSTimeInterval period, NSTimeInterval computation, NSTimeInterval constraint); 36 | __END_DECLS 37 | -------------------------------------------------------------------------------- /OpenEmuSystem/OETouchbarHIDDeviceHandler.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import "OETouchbarHIDDeviceHandler.h" 26 | 27 | 28 | @implementation OETouchbarHIDDeviceHandler 29 | 30 | 31 | - (NSString *)product 32 | { 33 | return @"(OE) Apple Touchbar Generic Desktop Keyboard Device"; 34 | } 35 | 36 | 37 | - (NSNumber *)locationID 38 | { 39 | /* return a random number */ 40 | return @4059184895; 41 | } 42 | 43 | - (BOOL)isFunctionKeyPressed 44 | { 45 | return YES; 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /OpenEmuSystem/OESwitchProControllerHIDDeviceHandler.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import "OEHIDDeviceParser.h" 26 | #import "OEHIDDeviceHandler.h" 27 | 28 | NS_ASSUME_NONNULL_BEGIN 29 | 30 | 31 | @interface OESwitchProControllerHIDDeviceHandler : OEHIDDeviceHandler 32 | 33 | @property (nonatomic, readonly) BOOL isUSB; 34 | @property (nonatomic, readonly) NSData *internalSerialNumber; 35 | 36 | @end 37 | 38 | 39 | @interface OESwitchProControllerHIDDeviceParser : OEHIDDeviceParser 40 | 41 | @end 42 | 43 | 44 | NS_ASSUME_NONNULL_END 45 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEDreamcastGDI.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #import 29 | 30 | extern NSString *const OEDreamcastGDIErrorDomain; 31 | 32 | typedef NS_ERROR_ENUM(OEDreamcastGDIErrorDomain, OEDreamcastGDIErrors) { 33 | OEDreamcastGDINoFileNameFoundError = -1, 34 | OEDreamcastGDIInvalidFileCountError = -2, 35 | }; 36 | 37 | /** 38 | Class to handle .gdi (Dreamcast Gigabyte Disc Image) files and manage track file references inside. 39 | */ 40 | @interface OEDreamcastGDI : OEDiscDescriptor 41 | @end 42 | -------------------------------------------------------------------------------- /OpenEmuSystemTests/NSDataCategoryTests.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import 26 | #import 27 | 28 | @interface NSDataCategoryTests : XCTestCase 29 | 30 | @end 31 | 32 | @implementation NSDataCategoryTests 33 | 34 | - (void)testHexStringRepresentation { 35 | char const * const bytes = "ABC.abc"; 36 | __auto_type data = [NSData dataWithBytes:bytes length:strlen(bytes)]; 37 | 38 | NSString * str = data.oe_hexStringRepresentation; 39 | XCTAssertEqualObjects(str, @"4142432E616263"); 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /OpenEmuBase/OESystemResponderClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | 29 | @protocol OESystemResponderClient 30 | 31 | - (void)performBlock:(void(^)(void))block; 32 | 33 | - (void)setFrameCallback:(void(^)(NSTimeInterval frameInterval))block; 34 | 35 | - (void)fastForward:(BOOL)flag; 36 | - (void)fastForwardAtSpeed:(CGFloat)fastForwardSpeed; 37 | - (void)rewind:(BOOL)flag; 38 | - (void)rewindAtSpeed:(CGFloat)rewindSpeed; 39 | - (void)slowMotionAtSpeed:(CGFloat)slowMotionSpeed; 40 | - (void)stepFrameForward; 41 | - (void)stepFrameBackward; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEM3UFile.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #import 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @class OECUESheet; 33 | 34 | extern NSString *const OEM3UFileErrorDomain; 35 | 36 | NS_ENUM(NSInteger) { 37 | OEM3UFileEmptyFileError = -1, 38 | }; 39 | 40 | @interface OEM3UFile : OEDiscDescriptor 41 | 42 | @property (nonatomic, copy, readonly) NSArray *referencedDiscDescriptors; // or DiscDescriptorFiles? 43 | 44 | @property(readonly) NSString *fileContentWithRelativeFilePaths; 45 | 46 | @end 47 | 48 | NS_ASSUME_NONNULL_END 49 | -------------------------------------------------------------------------------- /OpenEmuBase/NSUserDefaults+OpenEmuSDK.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import "NSUserDefaults+OpenEmuSDK.h" 26 | 27 | 28 | @implementation NSUserDefaults (OpenEmuSDK) 29 | 30 | + (instancetype)oe_applicationUserDefaults 31 | { 32 | NSBundle *thisBundle = [NSBundle mainBundle]; 33 | if ([[thisBundle bundleIdentifier] isEqual:@"org.openemu.OpenEmu"]) 34 | return [[self class] standardUserDefaults]; 35 | return [[[self class] alloc] initWithSuiteName:@"org.openemu.OpenEmu"]; 36 | } 37 | 38 | + (NSUserDefaults *)oe_application 39 | { 40 | return [self oe_applicationUserDefaults]; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEDiscDescriptor_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OEDiscDescriptor.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | @interface OEDiscDescriptor () 32 | 33 | - (BOOL)_setUpFileReferencesWithError:(NSError **)error; 34 | - (nullable NSString *)_fileContentWithError:(NSError **)error; 35 | 36 | @property (nonatomic, copy, readwrite) NSArray *referencedFileURLs; 37 | @property (nonatomic, copy, readwrite) NSArray *allReferencedFileURLs; 38 | @property (nonatomic, copy, readwrite) NSArray *referencedBinaryFileURLs; 39 | @property (nonatomic, copy, readwrite) NSURL *dataTrackFileURL; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEBindingDescription_Internal.h: -------------------------------------------------------------------------------- 1 | // 2 | // OEBindingDescription_Internal.h 3 | // OpenEmu-SDK 4 | // 5 | // Created by Remy Demarest on 27/11/2015. 6 | // 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface OEBindingDescription () 14 | - (instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER; 15 | - (instancetype)initWithSystemController:(nullable OESystemController *)systemController NS_DESIGNATED_INITIALIZER; 16 | @end 17 | 18 | @interface OEKeyBindingGroupDescription () 19 | - (instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER; 20 | - (instancetype)initWithSystemController:(nullable OESystemController *)systemController NS_UNAVAILABLE; 21 | - (instancetype)initWithSystemController:(nullable OESystemController *)systemController groupType:(OEKeyGroupType)aType keys:(NSArray *)groupedKeys NS_DESIGNATED_INITIALIZER; 22 | @end 23 | 24 | @interface OEKeyBindingDescription () 25 | 26 | - (instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER; 27 | - (instancetype)initWithSystemController:(nullable OESystemController *)systemController NS_UNAVAILABLE; 28 | - (instancetype)initWithSystemController:(nullable OESystemController *)systemController name:(nullable NSString *)keyName index:(NSUInteger)keyIndex isSystemWide:(BOOL)systemWide NS_DESIGNATED_INITIALIZER; 29 | 30 | @property(readwrite, getter=isAnalogic, setter=OE_setAnalogic:) BOOL analogic; 31 | @property(weak, readwrite, nullable, nonatomic, setter=OE_setHatSwitchGroup:) OEKeyBindingGroupDescription *hatSwitchGroup; 32 | @property(weak, readwrite, nullable, nonatomic, setter=OE_setAxisGroup:) OEKeyBindingGroupDescription *axisGroup; 33 | 34 | @end 35 | 36 | @interface OEGlobalKeyBindingDescription () 37 | - (instancetype)initWithSystemController:(nullable OESystemController *)systemController name:(nullable NSString *)keyName index:(NSUInteger)keyIndex isSystemWide:(BOOL)systemWide NS_UNAVAILABLE; 38 | - (instancetype)initWithButtonIdentifier:(OEGlobalButtonIdentifier)identifier NS_DESIGNATED_INITIALIZER; 39 | - (instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER; 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /OpenEmuSystem/NSResponder+OEHIDAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | 29 | @class OEHIDEvent; 30 | 31 | @interface NSResponder (OEHIDAdditions) 32 | 33 | // Parses anEvent and sends the appropriate event handler messages 34 | - (void)handleHIDEvent:(OEHIDEvent *)anEvent; 35 | 36 | - (void)axisMoved:(OEHIDEvent *)anEvent; 37 | 38 | - (void)triggerPull:(OEHIDEvent *)anEvent; 39 | - (void)triggerRelease:(OEHIDEvent *)anEvent; 40 | 41 | - (void)buttonDown:(OEHIDEvent *)anEvent; 42 | - (void)buttonUp:(OEHIDEvent *)anEvent; 43 | 44 | - (void)hatSwitchChanged:(OEHIDEvent *)anEvent; 45 | 46 | - (void)HIDKeyDown:(OEHIDEvent *)anEvent; 47 | - (void)HIDKeyUp:(OEHIDEvent *)anEvent; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /OpenEmuBase/OELogging.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import "OELogging.h" 26 | 27 | os_log_t OE_LOG_AUDIO_READ, OE_LOG_AUDIO_WRITE; 28 | os_log_t OE_LOG_CORE_RUN, OE_LOG_CORE_REWIND; 29 | os_log_t OE_LOG_DEFAULT; 30 | 31 | __attribute__((constructor)) 32 | static void InitializeLogging(void) { 33 | OE_LOG_AUDIO_READ = os_log_create("org.openemu.OpenEmuBase.audio", "read"); 34 | OE_LOG_AUDIO_WRITE = os_log_create("org.openemu.OpenEmuBase.audio", "write"); 35 | OE_LOG_CORE_RUN = os_log_create("org.openemu.OpenEmuBase.core", "run"); 36 | OE_LOG_CORE_REWIND = os_log_create("org.openemu.OpenEmuBase.core", "rewind"); 37 | OE_LOG_DEFAULT = os_log_create("org.openemu.OpenEmuBase", "default"); 38 | } 39 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEDeviceDescription.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | 29 | @class OEDeviceHandler, OEControllerDescription; 30 | 31 | @interface OEDeviceDescription : NSObject 32 | 33 | @property(readonly) OEControllerDescription *controllerDescription; 34 | 35 | @property(readonly) NSString *name; 36 | @property(readonly) NSString *product; 37 | @property(readonly) NSUInteger vendorID; 38 | @property(readonly) NSUInteger productID; 39 | @property(readonly) uint32_t cookie; 40 | @property(readonly) BOOL requiresNameMatch; 41 | 42 | @property(readonly) NSString *identifier; 43 | @property(readonly) NSString *controllerIdentifier; 44 | @property(readonly) NSString *genericDeviceIdentifier; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /OpenEmuBase/OpenEmuBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #if TARGET_OS_OSX 29 | #import 30 | #endif 31 | 32 | #if !__has_feature(objc_arc) 33 | #error OEGameCores will probably not function without ARC 34 | #endif 35 | 36 | #import 37 | #import 38 | #import 39 | #import 40 | #import 41 | #import 42 | #import 43 | #import 44 | #import 45 | #import 46 | #import 47 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEEvent.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #if TARGET_OS_OSX 29 | #import 30 | #elif TARGET_OS_IOS 31 | #import 32 | #else 33 | #error "Unsupported OS" 34 | #endif 35 | 36 | #import 37 | 38 | NS_ASSUME_NONNULL_BEGIN 39 | 40 | @interface OEEvent : NSObject 41 | 42 | - (instancetype)initWithMouseEvent:(NSEvent *)event withLocationInGameView:(OEIntPoint)location NS_SWIFT_NAME(init(mouseEvent:locationInGameView:)); 43 | - (instancetype)init NS_UNAVAILABLE; 44 | 45 | @property (nonatomic, readonly) OEIntPoint locationInGameView; 46 | #if TARGET_OS_OSX 47 | @property (nonatomic, readonly) NSEventType type; 48 | #endif 49 | 50 | @end 51 | 52 | NS_ASSUME_NONNULL_END 53 | -------------------------------------------------------------------------------- /OpenEmuSystem/OECloneCD.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OECloneCD.h" 28 | 29 | #import "OEDiscDescriptor_Internal.h" 30 | 31 | @implementation OECloneCD 32 | 33 | - (BOOL)_setUpFileReferencesWithError:(NSError **)error 34 | { 35 | if (![self _fileContentWithError:error]) 36 | return NO; 37 | 38 | NSURL *URLWithoutFileExtension = self.fileURL.URLByDeletingPathExtension; 39 | NSURL *IMGFileURL = [URLWithoutFileExtension URLByAppendingPathExtension:@"img"]; 40 | NSURL *SUBFileURL = [URLWithoutFileExtension URLByAppendingPathExtension:@"sub"]; 41 | 42 | self.dataTrackFileURL = IMGFileURL; 43 | self.referencedBinaryFileURLs = self.allReferencedFileURLs = self.referencedFileURLs = @[ IMGFileURL, SUBFileURL ]; 44 | 45 | return YES; 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /OpenEmuBase/OEGeometry.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import 26 | #import "OEGeometry.h" 27 | 28 | OEIntSize OECorrectScreenSizeForAspectSize(OEIntSize screenSize, OEIntSize aspectSize) 29 | { 30 | // calculate aspect ratio 31 | CGFloat wr = (CGFloat) aspectSize.width / screenSize.width; 32 | CGFloat hr = (CGFloat) aspectSize.height / screenSize.height; 33 | CGFloat ratio = MAX(hr, wr); 34 | CGSize scaled = CGSizeMake((wr / ratio), (hr / ratio)); 35 | 36 | CGFloat halfw = scaled.width; 37 | CGFloat halfh = scaled.height; 38 | 39 | OEIntSize corrected = screenSize.width <= aspectSize.width ? 40 | OEIntSizeMake(round(screenSize.width / halfh), round(screenSize.height / halfw)) : 41 | OEIntSizeMake(round(screenSize.width * halfw), round(screenSize.height * halfh)); 42 | 43 | return corrected; 44 | } 45 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEBindingMap.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | 29 | @class OEHIDEvent; 30 | @class OESystemKey; 31 | @class OESystemController; 32 | 33 | @interface OEBindingMap : NSObject 34 | 35 | - (OESystemKey *)systemKeyForEvent:(OEHIDEvent *)anEvent; 36 | - (void)setSystemKey:(OESystemKey *)aKey forEvent:(OEHIDEvent *)anEvent; 37 | - (void)removeSystemKeyForEvent:(OEHIDEvent *)anEvent; 38 | 39 | @end 40 | 41 | @interface OESystemKey : NSObject 42 | + (instancetype)systemKeyWithKey:(NSUInteger)aKeyNumber player:(NSUInteger)playerNumber isAnalogic:(BOOL)isAnalogic; 43 | - (instancetype)initWithKey:(NSUInteger)aKeyNumber player:(NSUInteger)playerNumber isAnalogic:(BOOL)isAnalogic; 44 | @property(nonatomic) NSUInteger key; 45 | @property(nonatomic) NSUInteger player; 46 | @property(nonatomic, getter=isAnalogic) BOOL analogic; 47 | @property(readonly) BOOL isGlobalButtonKey; 48 | @end 49 | -------------------------------------------------------------------------------- /OpenEmuSystem/OECUESheet.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #import 29 | 30 | // Options to handle 'broken' cue files: 31 | #define OECUESheetImproveReadingByUsingBinExtension 0 // If a referenced file does not have an extension we automatically append .bin and see if that works better 32 | #define OECUESheetImproveReadingByUsingSheetBin 0 // if there's only one referenced file which is not available we check if there's a bin file with the same name as the cue and use that instead 33 | 34 | extern NSString *const OECUESheetErrorDomain; 35 | 36 | typedef NS_ERROR_ENUM(OECUESheetErrorDomain, OECUESheetErrors) { 37 | OECUESheetNoFileNameFoundError = -1, 38 | OECUESheetInvalidFileFormatError = -2, 39 | OECUESheetInvalidQuotationMarkError = -3, 40 | }; 41 | 42 | /** 43 | Class to handle .cue files and manage track files references in cue sheets. 44 | Only does some very basic parsing. 45 | */ 46 | @interface OECUESheet : OEDiscDescriptor 47 | @end 48 | -------------------------------------------------------------------------------- /OpenEmuBase/OEGeometry.swift: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | import Foundation 26 | 27 | extension OEIntSize: Equatable { 28 | @inlinable public static func == (lhs: OEIntSize, rhs: OEIntSize) -> Bool { 29 | OEIntSizeEqualToSize(lhs, rhs) 30 | } 31 | } 32 | 33 | extension OEIntRect: Equatable { 34 | @inlinable public static func == (lhs: OEIntRect, rhs: OEIntRect) -> Bool { 35 | OEIntRectEqualToRect(lhs, rhs) 36 | } 37 | } 38 | 39 | extension OEIntPoint: Equatable { 40 | @inlinable public static func == (lhs: OEIntPoint, rhs: OEIntPoint) -> Bool { 41 | OEIntPointEqualToPoint(lhs, rhs) 42 | } 43 | } 44 | 45 | extension CGSize { 46 | @inlinable public func scaled(by factor: CGFloat) -> Self { 47 | CGSize(width: self.width * factor, height: self.height * factor) 48 | } 49 | } 50 | 51 | extension CGPoint { 52 | @inlinable public static func + (lhs: CGPoint, rhs: CGPoint) -> CGPoint { 53 | CGPoint(x: lhs.x + rhs.x, y: lhs.y + rhs.y) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEMultiHIDDeviceHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OEHIDDeviceHandler.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | @class OEHIDSubdeviceHandler; 32 | 33 | @interface OEMultiHIDDeviceHandler : OEHIDDeviceHandler 34 | 35 | - (instancetype)initWithIOHIDDevice:(IOHIDDeviceRef)aDevice deviceDescription:(OEDeviceDescription *)deviceDescription subdeviceDescriptions:(NSDictionary *)descriptions; 36 | 37 | @property(readonly) NSArray *subdeviceHandlers; 38 | @property(readonly) NSDictionary *subdeviceDescriptions; 39 | 40 | @end 41 | 42 | @interface OEHIDSubdeviceHandler : OEDeviceHandler 43 | 44 | - (instancetype)initWithParentDeviceHandler:(OEMultiHIDDeviceHandler *)parentHandler deviceDescription:(OEDeviceDescription *)deviceDescription subdeviceIdentifier:(id)identifier; 45 | 46 | @property(readonly) OEMultiHIDDeviceHandler *parentDeviceHandler; 47 | @property(readonly) id subdeviceIdentifier; 48 | 49 | @end 50 | 51 | NS_ASSUME_NONNULL_END 52 | -------------------------------------------------------------------------------- /OpenEmuSystem/DataProtocol+HexString.swift: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | import Foundation 26 | 27 | private let charA = UInt8(ascii: "A") 28 | private let char0 = UInt8(ascii: "0") 29 | 30 | private func itoh(_ value: UInt8) -> UInt8 { 31 | assert(value <= 0xF) 32 | return (value > 9) ? (charA + value - 10) : (char0 + value) 33 | } 34 | 35 | public extension DataProtocol { 36 | /// Returns a hexadecimal encoding of the receiver. Letters are uppercase. 37 | var hexString: String { 38 | let hexLen = self.count * 2 39 | var bytes: [UInt8] = [] 40 | bytes.reserveCapacity(hexLen) 41 | 42 | for i in self { 43 | bytes.append(itoh((i >> 4) & 0xF)) 44 | bytes.append(itoh(i & 0xF)) 45 | } 46 | 47 | return String(bytes: bytes, encoding: .utf8)! 48 | } 49 | } 50 | 51 | public extension NSData { 52 | /// Returns a hexadecimal encoding of the receiver. Letters are uppercase. 53 | @objc(oe_hexStringRepresentation) 54 | var hexString: String { 55 | return (self as Data).hexString 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /OpenEmuBase/OERingBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #import 29 | #import 30 | 31 | typedef NS_ENUM(NSUInteger, OERingBufferDiscardPolicy) { 32 | OERingBufferDiscardPolicyNewest, 33 | OERingBufferDiscardPolicyOldest 34 | }; 35 | 36 | @interface OERingBuffer : NSObject 37 | 38 | - (instancetype)initWithLength:(NSUInteger)length; 39 | 40 | @property NSUInteger length; 41 | @property(readonly) NSUInteger availableBytes; 42 | @property(readonly) NSUInteger freeBytes; 43 | @property(readonly) NSUInteger bytesWritten; 44 | @property(readonly) NSUInteger usedBytes __attribute__((deprecated("use -freeBytes"))); 45 | @property OERingBufferDiscardPolicy discardPolicy; 46 | 47 | /** If set to yes, any reads when there is less than double the amount of bytes 48 | * requested already in the buffer will be refused. */ 49 | @property BOOL anticipatesUnderflow; 50 | 51 | - (NSUInteger)read:(void *)buffer maxLength:(NSUInteger)len; 52 | - (NSUInteger)write:(const void *)buffer maxLength:(NSUInteger)length; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /OpenEmuSystem/OpenEmuSystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013, OpenEmu Team 3 | 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the OpenEmu Team nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | #import 30 | #import 31 | #import 32 | #import 33 | 34 | #import 35 | #import 36 | #import 37 | #import 38 | #import 39 | #import 40 | #import 41 | #import 42 | #import 43 | #import 44 | #import 45 | #import 46 | #import 47 | #import 48 | #import 49 | #import 50 | #import 51 | #import 52 | #import 53 | #import 54 | #import 55 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEBindingsController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the OpenEmu Team nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | extern NSNotificationName const OEBindingsRepairedNotification; 33 | 34 | @class OESystemController, OESystemBindings; 35 | 36 | /// Manages all bindings for all systems available 37 | @interface OEBindingsController : NSObject 38 | 39 | + (NSURL *)fileURLForConfigurationWithName:(NSString *)aName; 40 | 41 | // Class method because all bindings controllers need to know about it 42 | + (void)registerSystemController:(OESystemController *)aController; 43 | 44 | @property (class, nonatomic, readonly) OEBindingsController *defaultBindingsController; 45 | 46 | + (OEBindingsController *)bindingsControllerWithConfigurationName:(nullable NSString *)aName; 47 | - (instancetype)initWithConfigurationName:(nullable NSString *)aName; 48 | 49 | @property(readonly) NSString *configurationName; 50 | 51 | @property(readonly) NSURL *fileURL; 52 | 53 | @property(readonly, copy) NSArray *systemBindings; 54 | 55 | - (OESystemBindings *)systemBindingsForSystemIdentifier:(NSString *)systemIdentifier; 56 | - (OESystemBindings *)systemBindingsForSystemController:(OESystemController *)systemController; 57 | 58 | - (BOOL)synchronize; 59 | 60 | @end 61 | 62 | NS_ASSUME_NONNULL_END 63 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEControlDescription.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #import 29 | 30 | @class OEControllerDescription; 31 | @class OEControlValueDescription; 32 | 33 | @interface OEControlDescription : NSObject 34 | 35 | @property(readonly) OEControllerDescription *controllerDescription; 36 | 37 | @property(readonly) OEHIDEventType type; 38 | @property(readonly) NSUInteger controlIdentifier; 39 | @property(readonly) NSString *name; 40 | @property(readonly) NSString *identifier; 41 | @property(readonly) NSArray *controlValues; 42 | @property(readonly) BOOL isGenericControl; 43 | 44 | @property(readonly) OEHIDEvent *genericEvent; 45 | 46 | - (void)setUpControlValuesUsingRepresentations:(NSDictionary *)representations; 47 | 48 | @end 49 | 50 | @interface OEControlValueDescription : NSObject 51 | 52 | @property(readonly, weak) OEControlDescription *controlDescription; 53 | 54 | @property(readonly) NSString *name; 55 | @property(readonly) NSString *identifier; 56 | @property(readonly) NSNumber *valueIdentifier; 57 | @property(readonly) id representation; 58 | @property(readonly) OEHIDEvent *event; 59 | 60 | - (OEControlValueDescription *)associatedControlValueDescriptionForEvent:(OEHIDEvent *)anEvent; 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /OpenEmuBase/OEAbstractAdditions.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OEAbstractAdditions.h" 28 | 29 | 30 | @implementation NSObject (OEAbstractAdditions) 31 | 32 | + (void)doesNotImplementSelector:(SEL)aSel 33 | { 34 | @throw [NSException exceptionWithName:NSInvalidArgumentException 35 | reason:[NSString stringWithFormat:@"*** +%s cannot be sent to the abstract class %@: Create a concrete subclass!", sel_getName(aSel), [self class]] 36 | userInfo:nil]; 37 | } 38 | 39 | - (void)doesNotImplementSelector:(SEL)aSel 40 | { 41 | @throw [NSException exceptionWithName:NSInvalidArgumentException 42 | reason:[NSString stringWithFormat:@"*** -%s cannot be sent to an abstract object of class %@: Create a concrete instance!", sel_getName(aSel), [self class]] 43 | userInfo:nil]; 44 | } 45 | 46 | + (void)doesNotImplementOptionalSelector:(SEL)aSel 47 | { 48 | NSLog(@"*** +%s is an optional method and it is not implemented in %@!", sel_getName(aSel), NSStringFromClass([self class])); 49 | } 50 | 51 | - (void)doesNotImplementOptionalSelector:(SEL)aSel 52 | { 53 | NSLog(@"*** -%s is an optional method and it is not implemented in %@!", sel_getName(aSel), NSStringFromClass([self class])); 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEEvent.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OEEvent.h" 28 | 29 | static NSString *const OEEventLocationXKey = @"OEEventLocationX"; 30 | static NSString *const OEEventLocationYKey = @"OEEventLocationY"; 31 | static NSString *const OEEventTypeKey = @"OEEventType"; 32 | 33 | @implementation OEEvent 34 | 35 | - (instancetype)init 36 | { 37 | return nil; 38 | } 39 | 40 | - (instancetype)initWithMouseEvent:(NSEvent *)anEvent withLocationInGameView:(OEIntPoint)aLocation; 41 | { 42 | if((self = [super init])) 43 | { 44 | _type = anEvent.type; 45 | _locationInGameView = aLocation; 46 | } 47 | 48 | return self; 49 | } 50 | 51 | + (BOOL)supportsSecureCoding 52 | { 53 | return YES; 54 | } 55 | 56 | - (instancetype)initWithCoder:(NSCoder *)aDecoder 57 | { 58 | if (!(self = [super init])) 59 | return nil; 60 | 61 | _locationInGameView.x = [aDecoder decodeIntForKey:OEEventLocationXKey]; 62 | _locationInGameView.y = [aDecoder decodeIntForKey:OEEventLocationYKey]; 63 | _type = [aDecoder decodeIntegerForKey:OEEventTypeKey]; 64 | 65 | return self; 66 | } 67 | 68 | - (void)encodeWithCoder:(NSCoder *)aCoder 69 | { 70 | [aCoder encodeInt:_locationInGameView.x forKey:OEEventLocationXKey]; 71 | [aCoder encodeInt:_locationInGameView.y forKey:OEEventLocationYKey]; 72 | [aCoder encodeInteger:_type forKey:OEEventTypeKey]; 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /OpenEmuBase/OEAudioBuffer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import 26 | 27 | /** 28 | Reads the specified amount of bytes into the destination buffer. 29 | 30 | @param buffer Pointer to where to store the data after reading. 31 | @param bytesRequested Amount of bytes to be read. 32 | 33 | @returns The number of bytes read. 34 | */ 35 | typedef NSUInteger (^OEAudioBufferReadBlock)(void * buffer, NSUInteger bytesRequested); 36 | 37 | @protocol OEAudioBuffer 38 | 39 | /** 40 | * Reads the specified amount of bytes from the buffer. 41 | * @param buffer Pointer to where to store the data after reading. 42 | * @param len Amount of bytes to be read. 43 | * @returns The amount of bytes effectively read. 44 | */ 45 | - (NSUInteger)read:(void *)buffer maxLength:(NSUInteger)len; 46 | 47 | /** 48 | * Writes the specified amount of bytes to the buffer. 49 | * @param buffer Pointer to the data to be written. 50 | * @param length Amount of bytes to be written. 51 | * @returns The amount of bytes effectively written. 52 | */ 53 | - (NSUInteger)write:(const void *)buffer maxLength:(NSUInteger)length; 54 | 55 | /** 56 | * The maximum amount of bytes that can be read at once. 57 | */ 58 | @property(readonly) NSUInteger length; 59 | 60 | @optional 61 | 62 | /** 63 | Returns a block which can be used to read data from the buffer. 64 | */ 65 | - (OEAudioBufferReadBlock)readBlock; 66 | 67 | @end 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEControllerDescription_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OEControllerDescription.h" 28 | #import "OEControlDescription.h" 29 | #import "OEDeviceDescription.h" 30 | #import "OEHIDEvent_Internal.h" 31 | 32 | @interface OEControllerDescription () 33 | + (OEControllerDescription *)OE_controllerDescriptionForVendorID:(NSUInteger)vendorID productID:(NSUInteger)productID product:(NSString *)product; 34 | 35 | + (NSDictionary *> *)OE_representationForControllerDescription:(OEControllerDescription *)controllerDescription; 36 | 37 | - (OEDeviceDescription *)OE_addDeviceDescriptionWithVendorID:(NSUInteger)vendorID productID:(NSUInteger)productID product:(NSString *)product cookie:(uint32_t)cookie; 38 | - (void)OE_controlDescription:(OEControlDescription *)control didAddControlValue:(OEControlValueDescription *)valueDesc; 39 | @end 40 | 41 | @interface OEDeviceDescription () 42 | - (instancetype)OE_initWithRepresentation:(NSDictionary *)representation controllerDescription:(OEControllerDescription *)controllerDescription __attribute__((objc_method_family(init))); 43 | - (instancetype)OE_deviceDescriptionWithControllerDescription:(OEControllerDescription *)controllerDescription; 44 | @end 45 | 46 | @interface OEControlDescription () 47 | - (instancetype)OE_initWithIdentifier:(NSString *)identifier name:(NSString *)name genericEvent:(OEHIDEvent *)genericEvent controllerDescription:(OEControllerDescription *)controllerDescription __attribute__((objc_method_family(init))); 48 | @end 49 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEDiscDescriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #import 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | extern NSString *const OEDiscDescriptorErrorDomain; 33 | 34 | typedef NS_ERROR_ENUM(OEDiscDescriptorErrorDomain, OEDiscDescriptorErrors) { 35 | OEDiscDescriptorUnreadableFileError = -1, 36 | OEDiscDescriptorMissingFilesError = -2, 37 | OEDiscDescriptorNotPlainTextFileError = -3, 38 | OEDiscDescriptorNoPermissionReadFileError = -4, 39 | }; 40 | 41 | @interface OEDiscDescriptor : OEFile 42 | 43 | /// URLs of the files directly referenced by the receiver. 44 | @property (nonatomic, copy, readonly) NSArray *referencedFileURLs; 45 | 46 | /// URLs of the files referenced by the receiver including subfiles where applicable. 47 | @property (nonatomic, copy, readonly) NSArray *allReferencedFileURLs; 48 | 49 | /// URLs of the all the binary files referenced by the receiver. 50 | @property (nonatomic, copy, readonly) NSArray *referencedBinaryFileURLs; 51 | 52 | /// URL of the main data track file. 53 | @property (nonatomic, copy, readonly) NSURL *dataTrackFileURL; 54 | 55 | /// Move all the referenced files to the destinationURL directory. 56 | - (BOOL)moveReferencedFilesToDirectoryAtURL:(NSURL *)destinationURL error:(NSError **)error; 57 | 58 | /// Copy all the referenced files to the destinationURL directory. 59 | - (BOOL)copyReferencedFilesToDirectoryAtURL:(NSURL *)destinationURL error:(NSError **)error; 60 | 61 | @end 62 | 63 | NS_ASSUME_NONNULL_END 64 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEWiimoteHIDDeviceHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #import "OEHIDDeviceHandler.h" 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | typedef enum : unsigned char { 33 | OEWiimoteDeviceHandlerLED1 = 0x10, 34 | OEWiimoteDeviceHandlerLED2 = 0x20, 35 | OEWiimoteDeviceHandlerLED3 = 0x40, 36 | OEWiimoteDeviceHandlerLED4 = 0x80, 37 | OEWiimoteDeviceHandlerLEDAll = 0xF0, 38 | } OEWiimoteDeviceHandlerLED; 39 | 40 | typedef enum { 41 | OEWiimoteExpansionTypeUnknown, 42 | OEWiimoteExpansionTypeNunchuck, 43 | OEWiimoteExpansionTypeClassicController, 44 | OEWiimoteExpansionTypeWiiUProController, 45 | OEWiimoteExpansionTypeFightingStick, 46 | 47 | OEWiimoteExpansionTypeNotConnected, 48 | } OEWiimoteExpansionType; 49 | 50 | typedef enum { 51 | OEWiimoteIRModeBasic = 0x01, 52 | OEWiimoteIRModeExtended = 0x03, 53 | OEWiimoteIRModeFull = 0x05, 54 | } OEWiimoteIRMode; 55 | 56 | extern NSNotificationName const OEWiimoteDeviceHandlerDidDisconnectNotification; 57 | 58 | @interface OEWiimoteHIDDeviceHandler : OEHIDDeviceHandler 59 | 60 | @property(nonatomic) OEWiimoteDeviceHandlerLED illuminatedLEDs; 61 | @property(readonly) BOOL lowBatteryWarning; 62 | 63 | @property(nonatomic, getter=isRumbleActivated) BOOL rumbleActivated; 64 | @property(nonatomic, getter=isExpansionPortEnabled) BOOL expansionPortEnabled; 65 | @property(nonatomic, getter=isExpansionPortAttached, readonly) BOOL expansionPortAttached; 66 | 67 | + (BOOL)canHandleDeviceWithName:(NSString *)name; 68 | 69 | @end 70 | 71 | NS_ASSUME_NONNULL_END 72 | -------------------------------------------------------------------------------- /OpenEmu-SDK.xcodeproj/xcshareddata/xcschemes/OpenEmuBase.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 54 | 60 | 61 | 67 | 68 | 69 | 70 | 72 | 73 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /OpenEmu-SDK.xcodeproj/xcshareddata/xcschemes/OpenEmuSystem.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 54 | 60 | 61 | 67 | 68 | 69 | 70 | 72 | 73 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEControllerDescription.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #import 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @class OEControlDescription; 33 | @class OEControlValueDescription; 34 | @class OEDeviceDescription; 35 | @class OEHIDEvent; 36 | 37 | @interface OEControllerDescription : NSObject 38 | 39 | // Return YES if the controller is not known to the application database. 40 | @property(readonly) BOOL isGeneric; 41 | 42 | @property(readonly) NSString *identifier; 43 | @property(readonly) NSString *name; 44 | 45 | @property(readonly) NSArray *deviceDescriptions; 46 | - (OEDeviceDescription *)deviceDescriptionForVendorID:(NSUInteger)vendorID productID:(NSUInteger)productID cookie:(uint32_t)cookie; 47 | 48 | @property(readonly) NSUInteger numberOfControls; 49 | @property(readonly) NSArray *controls; 50 | @property (nonatomic, readonly) BOOL wantsCalibration; 51 | 52 | - (OEControlValueDescription *)controlValueDescriptionForEvent:(OEHIDEvent *)event; 53 | - (nullable OEControlValueDescription *)controlValueDescriptionForRepresentation:(id)representation; 54 | 55 | - (OEControlDescription *)addControlWithIdentifier:(nullable NSString *)identifier name:(nullable NSString *)name event:(OEHIDEvent *)event; 56 | - (OEControlDescription *)addControlWithIdentifier:(NSString *)identifier name:(NSString *)name event:(OEHIDEvent *)event valueRepresentations:(NSDictionary *)valueRepresentations; 57 | 58 | @end 59 | 60 | OEHIDEventType OEHIDEventTypeFromNSString(NSString *string); 61 | NSUInteger OEUsageFromUsageStringWithType(NSString *usageString, OEHIDEventType type); 62 | 63 | NS_ASSUME_NONNULL_END 64 | -------------------------------------------------------------------------------- /OpenEmuSystem/NSResponder+OEHIDAdditions.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "NSResponder+OEHIDAdditions.h" 28 | #import "OEHIDEvent.h" 29 | 30 | @implementation NSResponder (OEHIDAdditions) 31 | 32 | - (void)handleHIDEvent:(OEHIDEvent *)anEvent 33 | { 34 | switch([anEvent type]) 35 | { 36 | case OEHIDEventTypeAxis : 37 | [self axisMoved:anEvent]; 38 | break; 39 | case OEHIDEventTypeTrigger : 40 | if([anEvent hasOffState]) 41 | [self triggerRelease:anEvent]; 42 | else 43 | [self triggerPull:anEvent]; 44 | break; 45 | case OEHIDEventTypeButton : 46 | if([anEvent hasOffState]) 47 | [self buttonUp:anEvent]; 48 | else 49 | [self buttonDown:anEvent]; 50 | break; 51 | case OEHIDEventTypeHatSwitch : 52 | [self hatSwitchChanged:anEvent]; 53 | break; 54 | case OEHIDEventTypeKeyboard : 55 | if([anEvent hasOffState]) 56 | [self HIDKeyUp:anEvent]; 57 | else 58 | [self HIDKeyDown:anEvent]; 59 | break; 60 | default: 61 | break; 62 | } 63 | } 64 | 65 | #define FORWARD_MESSAGE(name, type) \ 66 | - (void)name:(type)arg \ 67 | { \ 68 | if(self.nextResponder != nil) \ 69 | [self.nextResponder name:arg]; \ 70 | } 71 | 72 | FORWARD_MESSAGE(axisMoved, OEHIDEvent *) 73 | FORWARD_MESSAGE(triggerPull, OEHIDEvent *) 74 | FORWARD_MESSAGE(triggerRelease, OEHIDEvent *) 75 | FORWARD_MESSAGE(buttonDown, OEHIDEvent *) 76 | FORWARD_MESSAGE(buttonUp, OEHIDEvent *) 77 | FORWARD_MESSAGE(hatSwitchChanged, OEHIDEvent *) 78 | FORWARD_MESSAGE(HIDKeyDown, OEHIDEvent *) 79 | FORWARD_MESSAGE(HIDKeyUp, OEHIDEvent *) 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEPlayerBindings.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the OpenEmu Team nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | #import 31 | #import 32 | 33 | NS_ASSUME_NONNULL_BEGIN 34 | 35 | @class OEBindingDescription, OEControlValueDescription, OEKeyBindingDescription, OESystemBindings, OEDeviceHandler, OEHIDEvent; 36 | 37 | /// Manages the bindings for a specific player in a system, useful for preferences 38 | /// Instances of this class are allocated by OESystemBindings 39 | @interface OEPlayerBindings : NSObject 40 | 41 | @property(readonly, weak) OESystemBindings *systemBindingsController; 42 | 43 | @property(readonly) NSUInteger playerNumber; 44 | 45 | // Keys: NSString - All key-name for each existing bindings excluding key groups 46 | // Values: NSString - String representation of the associated event 47 | // There are no key-groups in this case, all keys have their own strings 48 | @property(readonly, copy) NSDictionary *bindingDescriptions; 49 | 50 | // Keys: OEKeyBindingsDescription or OEOrientedKeyGroupBindingDescription - All keys for saved bindings 51 | // Values: OEHIDEvent or OEControlValueDescription - Associated event 52 | @property(readonly, copy) NSDictionary<__kindof OEBindingDescription *, id> *bindingEvents; 53 | 54 | /// @param key one of the control keys 55 | /// @result the event value for the specific type 56 | - (nullable id)valueForKey:(NSString *)key; 57 | 58 | /// @result the key or key group that got assigned 59 | - (nullable id)assignEvent:(OEHIDEvent *)anEvent toKeyWithName:(NSString *)aKeyName; 60 | - (void)removeEventForKeyWithName:(NSString *)aKeyName; 61 | 62 | @end 63 | 64 | @interface OEDevicePlayerBindings : OEPlayerBindings 65 | @property(readonly, nonatomic, nullable) OEDeviceHandler *deviceHandler; 66 | @property(readonly, copy) NSDictionary<__kindof OEBindingDescription *, OEControlValueDescription *> *bindingEvents; 67 | @end 68 | 69 | @interface OEKeyboardPlayerBindings : OEPlayerBindings 70 | @property(readonly, copy) NSDictionary *bindingEvents; 71 | @end 72 | 73 | NS_ASSUME_NONNULL_END 74 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEKeyBindingGroupDescription.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the OpenEmu Team nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | #import 31 | 32 | NS_ASSUME_NONNULL_BEGIN 33 | 34 | @class OEKeyBindingDescription, OEOrientedKeyGroupBindingDescription; 35 | 36 | typedef NS_ENUM(NSInteger, OEKeyGroupType) { 37 | OEKeyGroupTypeUnknown, 38 | OEKeyGroupTypeAxis, 39 | OEKeyGroupTypeHatSwitch, 40 | }; 41 | 42 | extern NSString *NSStringFromOEKeyGroupType(OEKeyGroupType type); 43 | 44 | // OEKeyGroupBindingsDescription allows OEKeyBindingsDescription objects to know about their peers, this class is only used by OESystemBindings 45 | @interface OEKeyBindingGroupDescription : OEBindingDescription 46 | 47 | @property(readonly) OEKeyGroupType type; 48 | @property(readonly, copy) NSString *groupIdentifier; 49 | @property(readonly, copy) NSArray *keys; 50 | @property(readonly, copy) NSArray *keyNames; 51 | @property(readonly, getter=isAnalogic) BOOL analogic; 52 | 53 | - (OEKeyBindingDescription *)oppositeKeyOfKey:(OEKeyBindingDescription *)aKey; 54 | 55 | - (OEOrientedKeyGroupBindingDescription *)orientedKeyGroupWithBaseKey:(OEKeyBindingDescription *)aKey; 56 | 57 | - (NSUInteger)indexOfKey:(OEKeyBindingDescription *)aKey; 58 | 59 | - (void)enumerateKeysFromKey:(OEKeyBindingDescription *)baseKey usingBlock:(void(^)(OEKeyBindingDescription *key, BOOL *stop))block; 60 | - (void)enumerateOrientedKeyGroupsFromKey:(OEKeyBindingDescription *)baseKey usingBlock:(void (^)(OEOrientedKeyGroupBindingDescription *key, BOOL *stop))block; 61 | 62 | @end 63 | 64 | // OEOrientedKeyGroupBindingDescription is used to know to which key of the group a certain value was set when saving the bindings to the disk, it's also used by responders the same way 65 | @interface OEOrientedKeyGroupBindingDescription : OEKeyBindingGroupDescription 66 | 67 | @property(readonly, weak) OEKeyBindingGroupDescription *parentKeyGroup; 68 | @property(readonly, weak) OEKeyBindingDescription *baseKey; 69 | 70 | @property(readonly) OEKeyBindingDescription *oppositeKey; 71 | 72 | @property(readonly) NSUInteger indexOfBaseKey; 73 | - (void)enumerateKeysFromBaseKeyUsingBlock:(void(^)(OEKeyBindingDescription *key, BOOL *stop))block; 74 | - (void)enumerateOrientedKeyGroupsFromBaseKeyUsingBlock:(void(^)(OEOrientedKeyGroupBindingDescription *key, BOOL *stop))block; 75 | 76 | @end 77 | 78 | NS_ASSUME_NONNULL_END 79 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEDeviceManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | 29 | #import 30 | #import 31 | 32 | NS_ASSUME_NONNULL_BEGIN 33 | 34 | typedef NS_ENUM(NSUInteger, OEDeviceAccessType) 35 | { 36 | /*! User has granted permission to monitor keyboard device */ 37 | OEDeviceAccessTypeGranted, 38 | 39 | /*! User has denied permission to monitor keyboard device */ 40 | OEDeviceAccessTypeDenied, 41 | 42 | /*! User has not been asked permission to monitor keyboard device */ 43 | OEDeviceAccessTypeUnknown, 44 | }; 45 | 46 | @class OEHIDEvent; 47 | @class OEDeviceHandler; 48 | 49 | extern NSNotificationName const OEDeviceManagerDidAddDeviceHandlerNotification; 50 | extern NSNotificationName const OEDeviceManagerDidRemoveDeviceHandlerNotification; 51 | 52 | extern NSNotificationName const OEDeviceManagerDidAddGlobalEventMonitorHandlerNotification; 53 | extern NSNotificationName const OEDeviceManagerDidRemoveGlobalEventMonitorHandlerNotification; 54 | 55 | extern NSString *const OEDeviceManagerDeviceHandlerUserInfoKey; 56 | 57 | @interface OEDeviceManager : NSObject 58 | 59 | @property(class, readonly) OEDeviceManager *sharedDeviceManager; 60 | 61 | @property(readonly) NSArray *deviceHandlers; 62 | @property(readonly) NSArray *controllerDeviceHandlers; 63 | @property(readonly) NSArray *keyboardDeviceHandlers; 64 | @property(readonly) OEDeviceAccessType accessType API_AVAILABLE(macosx(10.15)) API_UNAVAILABLE(ios, tvos, watchos); 65 | 66 | - (void)startWiimoteSearch; 67 | - (void)stopWiimoteSearch; 68 | @property(readonly) BOOL isBluetoothEnabled; 69 | 70 | - (BOOL)requestAccess API_AVAILABLE(macosx(10.15)) API_UNAVAILABLE(ios, tvos, watchos); 71 | 72 | // If the device has not yet been retrieved, this method will return an OEDeviceHandlerPlaceholder that must be resolved manually. 73 | - (OEDeviceHandler *)deviceHandlerForUniqueIdentifier:(NSString *)uniqueIdentifier; 74 | 75 | - (void)deviceHandler:(nullable OEDeviceHandler *)handler didReceiveEvent:(OEHIDEvent *)event; 76 | 77 | @property (readonly, nonatomic) BOOL hasEventMonitor; 78 | 79 | - (id)addGlobalEventMonitorHandler:(BOOL(^)(OEDeviceHandler *handler, OEHIDEvent *event))handler; 80 | - (id)addEventMonitorForDeviceHandler:(OEDeviceHandler *)device handler:(void(^)(OEDeviceHandler *handler, OEHIDEvent *event))handler; 81 | - (id)addUnhandledEventMonitorHandler:(void(^)(OEDeviceHandler *handler, OEHIDEvent *event))handler; 82 | - (void)removeMonitor:(id)monitor; 83 | 84 | @end 85 | 86 | NS_ASSUME_NONNULL_END 87 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEKeyBindingDescription.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the OpenEmu Team nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | #import 31 | 32 | NS_ASSUME_NONNULL_BEGIN 33 | 34 | @class OEKeyBindingGroupDescription; 35 | 36 | typedef NS_ENUM(NSUInteger, OEGlobalButtonIdentifier) { 37 | OEGlobalButtonIdentifierUnknown, 38 | 39 | OEGlobalButtonIdentifierSaveState, 40 | OEGlobalButtonIdentifierLoadState, 41 | OEGlobalButtonIdentifierQuickSave, 42 | OEGlobalButtonIdentifierQuickLoad, 43 | OEGlobalButtonIdentifierFullScreen, 44 | OEGlobalButtonIdentifierMute, 45 | OEGlobalButtonIdentifierVolumeDown, 46 | OEGlobalButtonIdentifierVolumeUp, 47 | 48 | OEGlobalButtonIdentifierStop, 49 | OEGlobalButtonIdentifierReset, 50 | OEGlobalButtonIdentifierPause, 51 | OEGlobalButtonIdentifierRewind, 52 | OEGlobalButtonIdentifierFastForward, 53 | OEGlobalButtonIdentifierSlowMotion, 54 | OEGlobalButtonIdentifierStepFrameBackward, 55 | OEGlobalButtonIdentifierStepFrameForward, 56 | OEGlobalButtonIdentifierNextDisplayMode, 57 | OEGlobalButtonIdentifierLastDisplayMode, 58 | OEGlobalButtonIdentifierScreenshot, 59 | 60 | OEGlobalButtonIdentifierRapidFireToggle, 61 | OEGlobalButtonIdentifierRapidFireClear, 62 | OEGlobalButtonIdentifierRapidFireReset, 63 | 64 | OEGlobalButtonIdentifierCount, 65 | 66 | OEGlobalButtonIdentifierFlag = 1 << 24, 67 | }; 68 | 69 | NSString *NSStringFromOEGlobalButtonIdentifier(OEGlobalButtonIdentifier identifier); 70 | 71 | @interface OEKeyBindingDescription : OEBindingDescription 72 | 73 | @property(readonly, copy) NSString *name; 74 | @property(readonly) NSUInteger index; 75 | @property(readonly, getter=isAnalogic) BOOL analogic; 76 | @property(weak, nullable, nonatomic, readonly) OEKeyBindingGroupDescription *hatSwitchGroup; 77 | @property(weak, nullable, nonatomic, readonly) OEKeyBindingGroupDescription *axisGroup; 78 | 79 | // Returns YES if the key does not depend on the player number 80 | @property(readonly, getter=isSystemWide) BOOL systemWide; 81 | 82 | // Returns nil if the key does not have an opposite key 83 | @property(readonly, nullable, weak) OEKeyBindingDescription *oppositeKey; 84 | // Returns nil if the key is not part of a hat switch 85 | @property(readonly, nullable, copy) NSArray *hatSwitchKeys; 86 | 87 | - (void)enumerateHatSwitchKeysUsingBlock:(void(^)(OEKeyBindingDescription *key, BOOL *stop))block; 88 | 89 | @end 90 | 91 | @interface OEGlobalKeyBindingDescription : OEKeyBindingDescription 92 | @property (readonly) OEGlobalButtonIdentifier buttonIdentifier; 93 | @end 94 | 95 | NS_ASSUME_NONNULL_END 96 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEMultiHIDDeviceHandler.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OEMultiHIDDeviceHandler.h" 28 | #import "OEDeviceDescription.h" 29 | #import "OEControllerDescription.h" 30 | #import "OEHIDEvent_Internal.h" 31 | 32 | NS_ASSUME_NONNULL_BEGIN 33 | 34 | @implementation OEMultiHIDDeviceHandler { 35 | NSDictionary *_subdeviceHandlers; 36 | } 37 | 38 | - (instancetype)initWithIOHIDDevice:(IOHIDDeviceRef)aDevice deviceDescription:(OEDeviceDescription *)deviceDescription subdeviceDescriptions:(NSDictionary *)descriptions; 39 | { 40 | if((self = [super initWithIOHIDDevice:aDevice deviceDescription:deviceDescription])) { 41 | _subdeviceDescriptions = descriptions; 42 | 43 | NSMutableDictionary *subhandlers = [[NSMutableDictionary alloc] initWithCapacity:[_subdeviceDescriptions count]]; 44 | 45 | [_subdeviceDescriptions enumerateKeysAndObjectsUsingBlock:^(NSNumber *key, OEDeviceDescription *desc, BOOL *stop) { 46 | OEHIDSubdeviceHandler *subhandler = [[OEHIDSubdeviceHandler alloc] initWithParentDeviceHandler:self deviceDescription:desc subdeviceIdentifier:key]; 47 | subhandlers[key] = subhandler; 48 | }]; 49 | 50 | _subdeviceHandlers = [subhandlers copy]; 51 | } 52 | return self; 53 | } 54 | 55 | - (NSArray *)subdeviceHandlers 56 | { 57 | return [_subdeviceHandlers allValues]; 58 | } 59 | 60 | - (OEHIDEvent *)eventWithHIDValue:(IOHIDValueRef)aValue 61 | { 62 | IOHIDElementRef element = IOHIDValueGetElement(aValue); 63 | id deviceIdentifier = (__bridge id)IOHIDElementGetProperty(element, CFSTR(kOEHIDElementDeviceIdentifierKey)); 64 | OEHIDSubdeviceHandler *handler = _subdeviceHandlers[deviceIdentifier]; 65 | 66 | NSAssert(handler != nil, @"Element %@ received by %@ has an invalid identifier %@ not corresponding to a subdevice handler.", element, self, deviceIdentifier); 67 | 68 | return [OEHIDEvent eventWithDeviceHandler:handler value:aValue]; 69 | } 70 | 71 | @end 72 | 73 | @implementation OEHIDSubdeviceHandler 74 | 75 | - (instancetype)initWithParentDeviceHandler:(OEMultiHIDDeviceHandler *)parentHandler deviceDescription:(OEDeviceDescription *)deviceDescription subdeviceIdentifier:(id)identifier; 76 | { 77 | if((self = [super initWithDeviceDescription:deviceDescription])) { 78 | _parentDeviceHandler = parentHandler; 79 | _subdeviceIdentifier = identifier; 80 | } 81 | 82 | return self; 83 | } 84 | 85 | - (NSString *)uniqueIdentifier 86 | { 87 | return [NSString stringWithFormat:@"%@ %u", [[self parentDeviceHandler] locationID], [[self deviceDescription] cookie]]; 88 | } 89 | 90 | @end 91 | 92 | NS_ASSUME_NONNULL_END 93 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEHIDDeviceHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #import 29 | #import 30 | #import 31 | #import 32 | 33 | NS_ASSUME_NONNULL_BEGIN 34 | 35 | @protocol OEHIDDeviceParser; 36 | 37 | @interface OEHIDDeviceHandler : OEDeviceHandler 38 | 39 | + (id)deviceParser; 40 | 41 | + (BOOL)canHandleDevice:(IOHIDDeviceRef)device; 42 | 43 | - (instancetype)initWithDeviceDescription:(nullable OEDeviceDescription *)deviceDescription NS_UNAVAILABLE; 44 | - (instancetype)initWithIOHIDDevice:(IOHIDDeviceRef)aDevice deviceDescription:(nullable OEDeviceDescription *)deviceDescription NS_DESIGNATED_INITIALIZER; 45 | 46 | @property(readonly) IOHIDDeviceRef device; 47 | @property(readonly) BOOL isUSBDevice; 48 | @property(readonly) NSNumber *interfaceNumber; 49 | 50 | - (void)dispatchEvent:(OEHIDEvent *)event; 51 | 52 | - (OEHIDEvent *)eventWithHIDValue:(IOHIDValueRef)aValue; 53 | - (void)dispatchEventWithHIDValue:(IOHIDValueRef)aValue; 54 | - (void)dispatchFunctionKeyEventWithHIDValue:(IOHIDValueRef)aValue; 55 | - (io_service_t)serviceRef; 56 | 57 | - (void)forceFeedbackWithStrongIntensity:(CGFloat)strongIntensity weakIntensity:(CGFloat)weakIntensity; 58 | @property(readonly) BOOL supportsForceFeedback; 59 | - (void)enableForceFeedback; 60 | - (void)disableForceFeedback; 61 | 62 | /** The CFRunLoop where the HID report callbacks are called. 63 | * @discussion The default RunLoop is the main RunLoop. 64 | * @note If a custom device handler needs events to be dispatched to a 65 | * different runloop, it shall override: (1) this property (2) the 66 | * -setUpCallbacks method (3) the -dispatchEvent: method or, 67 | * alternatively, the -dispatchEventWithHIDValue: and the 68 | * -dispatchFunctionKeyEventWithHIDValue: methods (for keyboards). 69 | * @warning This reference to eventRunLoop *must absolutely be kept alive as 70 | * long as the device exists*. Otherwise, the HID Manager will eventually 71 | * crash, *even if the device is unscheduled from the runloop*. 72 | * Practically, this means that you must retain the eventRunLoop, and 73 | * release it in the -dealloc method. */ 74 | @property(readonly) CFRunLoopRef eventRunLoop; 75 | 76 | /** Registers the callbacks used for receiving HID reports from the device. 77 | * @note If you override eventRunLoop, override this method to create 78 | * the thread which will receive the events to ensure that the 79 | * newly created CFRunLoop doesn't terminate immediately due to a 80 | * lack of registered event sources. */ 81 | - (void)setUpCallbacks; 82 | 83 | @end 84 | 85 | @protocol OEHIDDeviceParser 86 | - (OEHIDDeviceHandler *)deviceHandlerForIOHIDDevice:(IOHIDDeviceRef)aDevice; 87 | @end 88 | 89 | NS_ASSUME_NONNULL_END 90 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEFile.m: -------------------------------------------------------------------------------- 1 | // 2 | // OEFile.m 3 | // OpenEmu-SDK 4 | // 5 | // Created by Remy Demarest on 28/08/2016. 6 | // 7 | // 8 | 9 | #import "OEFile.h" 10 | 11 | @implementation OEFile { 12 | NSFileHandle *_fileHandle; 13 | NSUInteger _fileSize; 14 | } 15 | 16 | static NSMutableDictionary *extensionToSubclassDictionary; 17 | 18 | + (void)initialize 19 | { 20 | if (self != [OEFile class]) 21 | return; 22 | 23 | extensionToSubclassDictionary = [NSMutableDictionary dictionary]; 24 | 25 | [self registerClass:NSClassFromString(@"OECUESheet") forFileExtension:@"cue"]; 26 | [self registerClass:NSClassFromString(@"OECloneCD") forFileExtension:@"ccd"]; 27 | [self registerClass:NSClassFromString(@"OEDreamcastGDI") forFileExtension:@"gdi"]; 28 | [self registerClass:NSClassFromString(@"OEM3UFile") forFileExtension:@"m3u"]; 29 | } 30 | 31 | + (__kindof OEFile *)fileWithURL:(NSURL *)fileURL error:(NSError **)error 32 | { 33 | Class discDescriptorClass = extensionToSubclassDictionary[fileURL.pathExtension.lowercaseString]; 34 | if (discDescriptorClass != Nil) 35 | return [[discDescriptorClass alloc] initWithFileURL:fileURL error:error]; 36 | 37 | return [[OEFile alloc] initWithFileURL:fileURL error:error]; 38 | } 39 | 40 | + (void)registerClass:(Class)cls forFileExtension:(NSString *)fileExtension 41 | { 42 | NSAssert([cls isSubclassOfClass:[OEFile class]], @"Subclass of OEFile required."); 43 | extensionToSubclassDictionary[fileExtension] = cls; 44 | } 45 | 46 | - (nullable instancetype)initWithFileURL:(NSURL *)fileURL error:(NSError **)error 47 | { 48 | if (!(self = [super init])) 49 | return nil; 50 | 51 | _fileURL = [fileURL copy]; 52 | _fileExtension = _fileURL.pathExtension.lowercaseString; 53 | 54 | return self; 55 | } 56 | 57 | - (void)dealloc 58 | { 59 | [_fileHandle closeFile]; 60 | } 61 | 62 | - (NSArray *)allFileURLs 63 | { 64 | return @[ _fileURL ]; 65 | } 66 | 67 | - (NSUInteger)fileSize 68 | { 69 | if (_fileSize == 0) { 70 | NSNumber *fileSize; 71 | [_fileURL getResourceValue:&fileSize forKey:NSURLFileSizeKey error:nil]; 72 | _fileSize = fileSize.unsignedIntegerValue; 73 | } 74 | 75 | return _fileSize; 76 | } 77 | 78 | - (NSURL *)dataTrackFileURL 79 | { 80 | return _fileURL; 81 | } 82 | 83 | - (NSData *)readDataInRange:(NSRange)dataRange 84 | { 85 | if (_fileHandle == nil) 86 | _fileHandle = [NSFileHandle fileHandleForReadingFromURL:self.dataTrackFileURL error:nil]; 87 | 88 | if (_fileHandle == nil) 89 | return [NSData data]; 90 | 91 | if (@available(macOS 10.15, *)) 92 | { 93 | if (![_fileHandle seekToOffset:dataRange.location error:nil]) 94 | return [NSData data]; 95 | 96 | return [_fileHandle readDataUpToLength:dataRange.length error:nil]; 97 | } 98 | 99 | @try { 100 | [_fileHandle seekToFileOffset:dataRange.location]; 101 | } 102 | @catch (...) { 103 | return [NSData data]; 104 | } 105 | 106 | return [_fileHandle readDataOfLength:dataRange.length]; 107 | } 108 | 109 | - (NSString *)readASCIIStringInRange:(NSRange)dataRange 110 | { 111 | return [[NSString alloc] initWithData:[self readDataInRange:dataRange] encoding:NSASCIIStringEncoding] ?: @""; 112 | } 113 | 114 | - (nullable instancetype)fileByMovingFileToURL:(NSURL *)destinationURL error:(NSError **)error 115 | { 116 | if (![self moveToURL:destinationURL error:error]) 117 | return nil; 118 | 119 | return [[self.class alloc] initWithFileURL:destinationURL error:error]; 120 | } 121 | 122 | - (nullable instancetype)fileByCopyingFileToURL:(NSURL *)destinationURL error:(NSError **)error 123 | { 124 | if (![self copyToURL:destinationURL error:error]) 125 | return nil; 126 | 127 | return [[self.class alloc] initWithFileURL:destinationURL error:error]; 128 | } 129 | 130 | - (BOOL)moveToURL:(NSURL *)destinationURL error:(NSError **)error 131 | { 132 | return [[NSFileManager defaultManager] moveItemAtURL:_fileURL toURL:destinationURL error:error]; 133 | } 134 | 135 | - (BOOL)copyToURL:(NSURL *)destinationURL error:(NSError **)error 136 | { 137 | return [[NSFileManager defaultManager] copyItemAtURL:_fileURL toURL:destinationURL error:error]; 138 | } 139 | 140 | @end 141 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEDeviceDescription.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OEDeviceDescription.h" 28 | #import "OEControllerDescription_Internal.h" 29 | 30 | @implementation OEDeviceDescription 31 | 32 | - (instancetype)OE_initWithRepresentation:(NSDictionary *)representation controllerDescription:(OEControllerDescription *)controllerDescription 33 | { 34 | if((self = [super init])) 35 | { 36 | _name = [representation[@"OEControllerDeviceName"] copy]; 37 | _product = [representation[@"OEControllerProductName"] copy] ?: _name; 38 | _vendorID = [representation[@"OEControllerVendorID"] integerValue]; 39 | _productID = [representation[@"OEControllerProductID"] integerValue]; 40 | _cookie = [representation[@"OEControllerCookie"] unsignedShortValue]; 41 | _requiresNameMatch = [representation[@"OEControllerRequiresNameMatch"] boolValue]; 42 | _genericDeviceIdentifier = [NSString stringWithFormat:@"OEGenericDeviceIdentifier_%ld_%ld", _vendorID, _productID]; 43 | _controllerDescription = controllerDescription; 44 | } 45 | 46 | return self; 47 | } 48 | 49 | - (instancetype)OE_deviceDescriptionWithControllerDescription:(OEControllerDescription *)controllerDescription 50 | { 51 | OEDeviceDescription *ret = [[[self class] alloc] init]; 52 | ret->_name = [_name copy]; 53 | ret->_product = [_product copy]; 54 | ret->_vendorID = _vendorID; 55 | ret->_productID = _productID; 56 | ret->_cookie = _cookie; 57 | ret->_genericDeviceIdentifier = _genericDeviceIdentifier; 58 | ret->_requiresNameMatch = _requiresNameMatch; 59 | ret->_controllerDescription = controllerDescription; 60 | 61 | return ret; 62 | } 63 | 64 | - (id)copyWithZone:(nullable NSZone *)zone 65 | { 66 | return self; 67 | } 68 | 69 | - (NSUInteger)hash; 70 | { 71 | NSUInteger hash = _vendorID << 32 | _productID; 72 | 73 | if (_requiresNameMatch) { 74 | hash ^= _product.hash; 75 | } 76 | 77 | return hash; 78 | } 79 | 80 | - (BOOL)isEqual:(OEDeviceDescription *)object; 81 | { 82 | if(self == object) return YES; 83 | 84 | if(![object isKindOfClass:[OEDeviceDescription class]]) 85 | return NO; 86 | 87 | if (_vendorID != object->_vendorID) 88 | return NO; 89 | 90 | if (_productID != object->_productID) 91 | return NO; 92 | 93 | if (_requiresNameMatch != object->_requiresNameMatch) 94 | return NO; 95 | 96 | if (!_requiresNameMatch) 97 | return YES; 98 | 99 | return [_product isEqualToString:object->_product]; 100 | } 101 | 102 | - (NSString *)description 103 | { 104 | return [NSString stringWithFormat:@"<%@ %@ %ld %ld>", _name, [[self controllerDescription] name], _vendorID, _productID]; 105 | } 106 | 107 | - (NSString *)identifier 108 | { 109 | return [self genericDeviceIdentifier]; 110 | } 111 | 112 | - (NSString *)controllerIdentifier 113 | { 114 | return [[self controllerDescription] identifier]; 115 | } 116 | 117 | @end 118 | -------------------------------------------------------------------------------- /OpenEmuSystem/OESystemResponder.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | 29 | #if TARGET_OS_OSX 30 | #import 31 | #elif TARGET_OS_IOS 32 | #import 33 | #else 34 | #error "Unsupported platform" 35 | #endif 36 | #import 37 | #import 38 | #import 39 | #import 40 | 41 | NS_ASSUME_NONNULL_BEGIN 42 | 43 | @class OEEvent; 44 | @class OESystemController; 45 | @protocol OESystemResponderClient; 46 | @protocol OEGlobalEventsHandler; 47 | 48 | #if TARGET_OS_OSX 49 | @interface OESystemResponder : NSResponder 50 | #elif TARGET_OS_IOS 51 | @interface OESystemResponder : UIResponder 52 | #endif 53 | 54 | - (instancetype)init NS_UNAVAILABLE; 55 | - (instancetype)initWithController:(OESystemController *)controller NS_DESIGNATED_INITIALIZER; 56 | 57 | @property(strong, readonly) OESystemController *controller; 58 | @property(weak, nonatomic) id client; 59 | @property(weak, nonatomic) id globalEventsHandler; 60 | 61 | - (void)handleMouseEvent:(OEEvent *)event; 62 | 63 | @property(nonatomic, strong) OEBindingMap *keyMap; 64 | 65 | - (OESystemKey *)emulatorKeyForKey:(OEKeyBindingDescription *)aKey player:(NSUInteger)thePlayer; 66 | 67 | - (void)pressEmulatorKey:(OESystemKey *)aKey; 68 | - (void)releaseEmulatorKey:(OESystemKey *)aKey; 69 | - (void)mouseDownAtPoint:(OEIntPoint)aPoint; 70 | - (void)mouseUpAtPoint; 71 | - (void)rightMouseDownAtPoint:(OEIntPoint)aPoint; 72 | - (void)rightMouseUpAtPoint; 73 | - (void)mouseMovedAtPoint:(OEIntPoint)aPoint; 74 | - (void)changeAnalogEmulatorKey:(OESystemKey *)aKey value:(CGFloat)value; 75 | 76 | - (void)systemBindingsDidSetEvent:(OEHIDEvent *)event forBinding:(__kindof OEBindingDescription *)bindingDescription playerNumber:(NSUInteger)playerNumber; 77 | - (void)systemBindingsDidUnsetEvent:(OEHIDEvent *)event forBinding:(__kindof OEBindingDescription *)bindingDescription playerNumber:(NSUInteger)playerNumber; 78 | 79 | @end 80 | 81 | // Methods that subclasses must override 82 | @interface OESystemResponder (OEGameSystemResponderSubclass) 83 | + (Protocol *)gameSystemResponderClientProtocol; 84 | @end 85 | 86 | @protocol OEGlobalEventsHandler 87 | - (void)saveState:(id)sender; 88 | - (void)loadState:(id)sender; 89 | - (void)quickSave:(id)sender; 90 | - (void)quickLoad:(id)sender; 91 | - (void)toggleFullScreen:(id)sender; 92 | - (void)toggleAudioMute:(id)sender; 93 | - (void)volumeDown:(id)sender; 94 | - (void)volumeUp:(id)sender; 95 | - (void)stopEmulation:(id)sender; 96 | - (void)resetEmulation:(id)sender; 97 | - (void)toggleEmulationPaused:(id)sender; 98 | - (void)takeScreenshot:(id)sender; 99 | - (void)fastForwardGameplay:(BOOL)enable; 100 | - (void)rewindGameplay:(BOOL)enable; 101 | - (void)stepGameplayFrameForward:(id)sender; 102 | - (void)stepGameplayFrameBackward:(id)sender; 103 | - (void)nextDisplayMode:(id)sender; 104 | - (void)lastDisplayMode:(id)sender; 105 | @end 106 | 107 | NS_ASSUME_NONNULL_END 108 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEDreamcastGDI.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OEDreamcastGDI.h" 28 | 29 | #import "OEDiscDescriptor_Internal.h" 30 | 31 | NSString *const OEDreamcastGDIErrorDomain = @"org.openemu.OEDreamcastGDI.ErrorDomain"; 32 | 33 | @implementation OEDreamcastGDI 34 | 35 | - (BOOL)_setUpFileReferencesWithError:(NSError **)error 36 | { 37 | NSString *fileContent = [self _fileContentWithError:error]; 38 | if (fileContent == nil) 39 | return NO; 40 | 41 | // Handle both standard and Redump style GDI formats 42 | // Many ways to do this... 43 | // (?:(?:2352|2048|2336) "?)(.*\w)(?:"? \d) 44 | // ^(?:[ ]?\d+[ ]+\d+[ ]+\d+[ ]\d+[ ]"?)(.*\w)(?:"?[ ]\d)$ 45 | // (?:\h*(?:\d+\h+){4})(("(.*)")|(.+))(?: \d) 46 | NSRegularExpression *fileNamePattern = [NSRegularExpression regularExpressionWithPattern:@"(?:\\h*(?:\\d+\\h+){4}\"?)(.*\\w)(?:\"? \\d)" options:0 error:nil]; 47 | 48 | NSRange fullRange = NSMakeRange(0, fileContent.length); 49 | NSArray *matches = [fileNamePattern matchesInString:fileContent options:0 range:fullRange]; 50 | NSString *trackCount = [fileContent componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet].firstObject; 51 | NSString *matchCount = [NSString stringWithFormat:@"%@", @(matches.count)]; 52 | 53 | if (matches.count == 0) { 54 | if (error == nil) 55 | return NO; 56 | 57 | *error = [NSError errorWithDomain:OEDreamcastGDIErrorDomain code:OEDreamcastGDINoFileNameFoundError userInfo:@{ 58 | NSLocalizedDescriptionKey: NSLocalizedString(@"GDI does not contain any tracks", @"Missing track file references in GDI error description"), 59 | NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:NSLocalizedString(@"The GDI %@ should contain file names referencing tracks but none could be found.", @"Missing track file references in GDI file error failure reason"), self.fileURL.lastPathComponent], 60 | }]; 61 | 62 | return NO; 63 | } 64 | 65 | if (![trackCount isEqualToString:matchCount]) { 66 | if (error == nil) 67 | return NO; 68 | 69 | *error = [NSError errorWithDomain:OEDreamcastGDIErrorDomain code:OEDreamcastGDIInvalidFileCountError userInfo:@{ 70 | NSLocalizedDescriptionKey: NSLocalizedString(@"Track count mismatch", @"Track count mismatch in GDI error description"), 71 | NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:NSLocalizedString(@"The track count (%@) and the track file references found (%@) in the GDI %@ do not match.", @"Track count mismatch in GDI file error failure reason"), trackCount, matchCount, self.fileURL.lastPathComponent], 72 | }]; 73 | 74 | return NO; 75 | } 76 | 77 | NSURL *folderURL = self.fileURL.URLByDeletingLastPathComponent; 78 | NSMutableArray *fileURLs = [NSMutableArray array]; 79 | 80 | for (NSTextCheckingResult *match in matches) { 81 | NSString *fileNameMatch = [fileContent substringWithRange:[match rangeAtIndex:1]]; 82 | 83 | [fileURLs addObject:[folderURL URLByAppendingPathComponent:fileNameMatch]]; 84 | } 85 | 86 | self.dataTrackFileURL = fileURLs.firstObject; 87 | self.referencedBinaryFileURLs = self.allReferencedFileURLs = self.referencedFileURLs = fileURLs; 88 | 89 | return YES; 90 | } 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEBindingsController_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the OpenEmu Team nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import "OEBindingsController.h" 29 | #import "OEKeyBindingGroupDescription.h" 30 | #import "OEKeyBindingDescription.h" 31 | #import "OESystemBindings.h" 32 | #import "OEPlayerBindings.h" 33 | #import 34 | 35 | NS_ASSUME_NONNULL_BEGIN 36 | 37 | @class OEControlValueDescription; 38 | 39 | @interface OEBindingsController () 40 | - (void)OE_setRequiresSynchronization; 41 | @end 42 | 43 | @interface OESystemBindings () 44 | 45 | - (instancetype)OE_initWithBindingsController:(nullable OEBindingsController *)parentController systemController:(OESystemController *)aController dictionaryRepresentation:(NSDictionary *)aDictionary __attribute__((objc_method_family(init))); 46 | 47 | - (NSDictionary> *)OE_dictionaryRepresentation; 48 | 49 | - (BOOL)OE_didAddDeviceHandler:(OEDeviceHandler *)aHandler; 50 | - (void)OE_didRemoveDeviceHandler:(OEDeviceHandler *)aHandler; 51 | 52 | - (id)OE_playerBindings:(OEPlayerBindings *)sender didAssignEvent:(OEHIDEvent *)value toKeyWithName:(NSString *)aKey; 53 | - (void)OE_playerBindings:(OEPlayerBindings *)sender didRemoveEventForKeyWithName:(NSString *)aKey; 54 | 55 | @end 56 | 57 | @interface OEPlayerBindings () 58 | 59 | - (instancetype)OE_initWithSystemBindings:(OESystemBindings *)aController playerNumber:(NSUInteger)playerNumber __attribute__((objc_method_family(init))); 60 | 61 | @property(readwrite, setter=OE_setPlayerNumber:) NSUInteger playerNumber; 62 | 63 | // Keys: NSString - All key-name for each existing bindings excluding key groups 64 | // Values: NSString - String representation of the associated event 65 | @property(readwrite, copy, setter=OE_setBindingDescriptions:) NSDictionary *bindingDescriptions; 66 | 67 | - (id)OE_bindingDescriptionForKey:(NSString *)aKey; 68 | - (void)OE_setBindingDescription:(nullable NSString *)value forKey:(NSString *)aKey; 69 | 70 | // Keys: OEKeyBindingsDescription or OEOrientedKeyGroupBindingDescription - All keys for saved bindings 71 | // Values: OEHIDEvent or OEControlValueDescription - Associated event 72 | @property(readwrite, copy, setter=OE_setBindingEvents:) NSDictionary<__kindof OEBindingDescription *, id> *bindingEvents; 73 | 74 | - (id)OE_bindingEventForKey:(id)aKey; 75 | - (void)OE_setBindingEvent:(nullable id)value forKey:(id)aKey; 76 | 77 | @end 78 | 79 | @interface OEDevicePlayerBindings () 80 | 81 | - (instancetype)OE_initWithSystemBindings:(OESystemBindings *)aController playerNumber:(NSUInteger)playerNumber deviceHandler:(nullable OEDeviceHandler *)handler __attribute__((objc_method_family(init))); 82 | 83 | @property(readwrite, nullable, nonatomic, setter=OE_setDeviceHandler:) OEDeviceHandler *deviceHandler; 84 | 85 | @end 86 | 87 | @interface OEDevicePlayerBindings (TypeOverrides) 88 | - (OEControlValueDescription *)OE_bindingEventForKey:(__kindof OEBindingDescription *)aKey; 89 | - (void)OE_setBindingEvent:(nullable OEControlValueDescription *)value forKey:(__kindof OEBindingDescription *)aKey; 90 | @end 91 | 92 | @interface OEKeyboardPlayerBindings (TypeOverrides) 93 | - (OEHIDEvent *)OE_bindingEventForKey:(OEKeyBindingDescription *)aKey; 94 | - (void)OE_setBindingEvent:(nullable OEHIDEvent *)value forKey:(OEKeyBindingDescription *)aKey; 95 | @end 96 | 97 | NS_ASSUME_NONNULL_END 98 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEHIDEvent.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009, OpenEmu Team 3 | 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the OpenEmu Team nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | #define OEGlobalEventsKey @"OEGlobalEventsKey" 31 | 32 | typedef NS_ENUM(NSUInteger, OEHIDEventType) { 33 | OEHIDEventTypeAxis = 1, 34 | // Only for analogic triggers 35 | OEHIDEventTypeTrigger = 5, 36 | OEHIDEventTypeButton = 2, 37 | OEHIDEventTypeHatSwitch = 3, 38 | OEHIDEventTypeKeyboard = 4, 39 | }; 40 | 41 | typedef NS_ENUM(NSUInteger, OEHIDEventAxis) { 42 | OEHIDEventAxisNone = 0x00, 43 | OEHIDEventAxisX = 0x30, 44 | OEHIDEventAxisY = 0x31, 45 | OEHIDEventAxisZ = 0x32, 46 | OEHIDEventAxisRx = 0x33, 47 | OEHIDEventAxisRy = 0x34, 48 | OEHIDEventAxisRz = 0x35, 49 | OEHIDEventAxisAccelerator = 0xC4, 50 | OEHIDEventAxisBrake = 0xC5, 51 | }; 52 | 53 | typedef NS_CLOSED_ENUM(NSInteger, OEHIDEventAxisDirection) { 54 | OEHIDEventAxisDirectionNegative = -1, 55 | OEHIDEventAxisDirectionNull = 0, 56 | OEHIDEventAxisDirectionPositive = 1 57 | }; 58 | 59 | typedef NS_ENUM(NSUInteger, OEHIDEventHatSwitchType) { 60 | OEHIDEventHatSwitchTypeUnknown, 61 | OEHIDEventHatSwitchType4Ways, 62 | OEHIDEventHatSwitchType8Ways 63 | }; 64 | 65 | typedef NS_OPTIONS(NSUInteger, OEHIDEventHatDirection) { 66 | OEHIDEventHatDirectionNull = 0, 67 | OEHIDEventHatDirectionNorth = 1 << 0, 68 | OEHIDEventHatDirectionEast = 1 << 1, 69 | OEHIDEventHatDirectionSouth = 1 << 2, 70 | OEHIDEventHatDirectionWest = 1 << 3, 71 | 72 | OEHIDEventHatDirectionNorthEast = OEHIDEventHatDirectionNorth | OEHIDEventHatDirectionEast, 73 | OEHIDEventHatDirectionSouthEast = OEHIDEventHatDirectionSouth | OEHIDEventHatDirectionEast, 74 | OEHIDEventHatDirectionNorthWest = OEHIDEventHatDirectionNorth | OEHIDEventHatDirectionWest, 75 | OEHIDEventHatDirectionSouthWest = OEHIDEventHatDirectionSouth | OEHIDEventHatDirectionWest 76 | }; 77 | 78 | typedef NS_CLOSED_ENUM(NSInteger, OEHIDEventState) { 79 | OEHIDEventStateOff, 80 | OEHIDEventStateOn 81 | }; 82 | 83 | enum { 84 | OEHIDUsage_KeyboardFunctionKey = 0xE8, 85 | }; 86 | 87 | @interface OEHIDEvent : NSObject 88 | 89 | @property(readonly) NSString *displayDescription; 90 | 91 | @property(readonly) OEHIDEventType type; 92 | @property(readonly) BOOL hasOffState; 93 | 94 | // Axis event or Trigger event 95 | @property(readonly) OEHIDEventAxis axis; // Axis and Trigger 96 | @property(readonly) OEHIDEventAxisDirection direction; // Axis and Trigger (only Null and Positive for Trigger) 97 | @property(readonly) OEHIDEventAxisDirection oppositeDirection; // Axis only 98 | @property(readonly) CGFloat value; // Axis and Trigger 99 | @property(readonly) CGFloat absoluteValue; // Axis and Trigger 100 | 101 | // Button event 102 | @property(readonly) NSUInteger buttonNumber; 103 | 104 | // Key event 105 | @property(readonly) NSUInteger keycode; 106 | @property(readonly) BOOL isEscapeKeyEvent; 107 | 108 | // Button or Key event state 109 | @property(readonly) OEHIDEventState state; 110 | 111 | // HatSwitch event 112 | @property(readonly) OEHIDEventHatSwitchType hatSwitchType; 113 | @property(readonly) OEHIDEventHatDirection hatDirection; 114 | 115 | - (BOOL)isEqualToEvent:(OEHIDEvent *)anObject; 116 | - (BOOL)isUsageEqualToEvent:(OEHIDEvent *)anObject; // Checks all properties but state 117 | 118 | @property(readonly) NSUInteger controlIdentifier; 119 | @property(readonly) NSUInteger controlValueIdentifier; 120 | 121 | @end 122 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEBindingMap.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OEBindingMap.h" 28 | #import "OEKeyBindingDescription.h" 29 | #import "OESystemController.h" 30 | #import "OEHIDEvent_Internal.h" 31 | 32 | @interface OEBindingMap () 33 | { 34 | NSMutableDictionary *_keyMap; 35 | dispatch_queue_t _queue; 36 | } 37 | 38 | @end 39 | 40 | static Boolean _OEBindingMapKeyEqualCallBack(OEHIDEvent *value1, OEHIDEvent *value2) 41 | { 42 | return [value1 isBindingEqualToEvent:value2]; 43 | } 44 | 45 | static CFHashCode _OEBindingMapKeyHashCallBack(OEHIDEvent *value) 46 | { 47 | return [value bindingHash]; 48 | } 49 | 50 | @implementation OEBindingMap 51 | 52 | - (instancetype)init 53 | { 54 | if((self = [super init])) 55 | { 56 | CFDictionaryKeyCallBacks keyCallbacks = { 57 | .retain = kCFTypeDictionaryKeyCallBacks.retain, 58 | .release = kCFTypeDictionaryKeyCallBacks.release, 59 | .copyDescription = kCFTypeDictionaryKeyCallBacks.copyDescription, 60 | .equal = (CFDictionaryEqualCallBack)_OEBindingMapKeyEqualCallBack, 61 | .hash = (CFDictionaryHashCallBack) _OEBindingMapKeyHashCallBack 62 | }; 63 | 64 | _keyMap = (__bridge_transfer NSMutableDictionary *)CFDictionaryCreateMutable(NULL, 0, &keyCallbacks, &kCFTypeDictionaryValueCallBacks); 65 | _queue = dispatch_queue_create("org.openemu.OEBindingMap.queue", DISPATCH_QUEUE_CONCURRENT); 66 | } 67 | 68 | return self; 69 | } 70 | 71 | - (OESystemKey *)systemKeyForEvent:(OEHIDEvent *)anEvent; 72 | { 73 | __block OESystemKey *ret = nil; 74 | dispatch_sync(_queue, ^{ 75 | ret = [self->_keyMap objectForKey:anEvent]; 76 | }); 77 | 78 | return ret; 79 | } 80 | 81 | - (void)setSystemKey:(OESystemKey *)aKey forEvent:(OEHIDEvent *)anEvent; 82 | { 83 | dispatch_barrier_async(_queue, ^{ 84 | [self->_keyMap setObject:aKey forKey:anEvent]; 85 | }); 86 | } 87 | 88 | - (void)removeSystemKeyForEvent:(OEHIDEvent *)anEvent 89 | { 90 | dispatch_barrier_async(_queue, ^{ 91 | [self->_keyMap removeObjectForKey:anEvent]; 92 | }); 93 | } 94 | 95 | - (NSString *)description 96 | { 97 | __block NSString *keyMapDescription = [_keyMap description]; 98 | dispatch_sync(_queue, ^{ 99 | keyMapDescription = [self->_keyMap description]; 100 | }); 101 | 102 | return [NSString stringWithFormat:@"<%@ %p events: %@>", [self class], self, keyMapDescription]; 103 | } 104 | 105 | @end 106 | 107 | @implementation OESystemKey 108 | 109 | + (instancetype)systemKeyWithKey:(NSUInteger)key player:(NSUInteger)player isAnalogic:(BOOL)isAnalogic 110 | { 111 | return [[self alloc] initWithKey:key player:player isAnalogic:isAnalogic]; 112 | } 113 | 114 | - (instancetype)initWithKey:(NSUInteger)key player:(NSUInteger)player isAnalogic:(BOOL)isAnalogic 115 | { 116 | if((self = [super init])) 117 | { 118 | _key = key; 119 | _player = player; 120 | _analogic = isAnalogic; 121 | } 122 | 123 | return self; 124 | } 125 | 126 | - (BOOL)isGlobalButtonKey 127 | { 128 | return !!(_key & OEGlobalButtonIdentifierFlag); 129 | } 130 | 131 | - (NSUInteger)hash 132 | { 133 | return _key << 32 | _player; 134 | } 135 | 136 | - (BOOL)isEqual:(OESystemKey *)object 137 | { 138 | if(self == object) return YES; 139 | 140 | if([object isKindOfClass:[OESystemKey class]]) 141 | return _key == object->_key && _player == object->_player; 142 | 143 | return NO; 144 | } 145 | 146 | - (NSString *)description 147 | { 148 | return [NSString stringWithFormat:@"<%@ %p key: %lu player: %lu>", [self class], self, _key, _player]; 149 | } 150 | 151 | @end 152 | -------------------------------------------------------------------------------- /OpenEmuSystem/OESystemBindings.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, OpenEmu Team 3 | 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the OpenEmu Team nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @protocol OESystemBindingsObserver; 33 | @class OEBindingDescription; 34 | @class OEBindingsController; 35 | @class OEDeviceHandler; 36 | @class OEDevicePlayerBindings; 37 | @class OEHIDEvent; 38 | @class OEKeyboardPlayerBindings; 39 | @class OEPlayerBindings; 40 | @class OESystemController; 41 | @class OEGlobalKeyBindingDescription; 42 | 43 | extern NSString *const OEGlobalButtonSaveState; 44 | extern NSString *const OEGlobalButtonLoadState; 45 | extern NSString *const OEGlobalButtonQuickSave; 46 | extern NSString *const OEGlobalButtonQuickLoad; 47 | extern NSString *const OEGlobalButtonFullScreen; 48 | extern NSString *const OEGlobalButtonMute; 49 | extern NSString *const OEGlobalButtonVolumeDown; 50 | extern NSString *const OEGlobalButtonVolumeUp; 51 | extern NSString *const OEGlobalButtonStop; 52 | extern NSString *const OEGlobalButtonReset; 53 | extern NSString *const OEGlobalButtonPause; 54 | extern NSString *const OEGlobalButtonRewind; 55 | extern NSString *const OEGlobalButtonFastForward; 56 | extern NSString *const OEGlobalButtonSlowMotion; 57 | extern NSString *const OEGlobalButtonStepFrameBackward; 58 | extern NSString *const OEGlobalButtonStepFrameForward; 59 | extern NSString *const OEGlobalButtonNextDisplayMode; 60 | extern NSString *const OEGlobalButtonLastDisplayMode; 61 | extern NSString *const OEGlobalButtonScreenshot; 62 | extern NSString *const OEGlobalButtonRapidFireToggle; 63 | extern NSString *const OEGlobalButtonRapidFireClear; 64 | extern NSString *const OEGlobalButtonRapidFireReset; 65 | 66 | /// Manages the bindings for a specific system, useful for system responders 67 | /// Instances of this class are allocated by OEGameBindingsController 68 | @interface OESystemBindings : NSObject 69 | 70 | @property(readonly, weak) OEBindingsController *bindingsController; 71 | @property(readonly, weak) OESystemController *systemController; 72 | 73 | @property(readonly) NSUInteger numberOfPlayers; 74 | 75 | - (nullable OEDevicePlayerBindings *)devicePlayerBindingsForPlayer:(NSUInteger)playerNumber; 76 | - (nullable OEKeyboardPlayerBindings *)keyboardPlayerBindingsForPlayer:(NSUInteger)playerNumber; 77 | 78 | - (NSUInteger)playerForDeviceHandler:(OEDeviceHandler *)deviceHandler; 79 | - (nullable OEDeviceHandler *)deviceHandlerForPlayer:(NSUInteger)playerNumber; 80 | - (OEDevicePlayerBindings *)devicePlayerBindingsForDeviceHandler:(OEDeviceHandler *)deviceHandler; 81 | - (void)setDeviceHandler:(OEDeviceHandler *)deviceHandler forPlayer:(NSUInteger)playerNumber; 82 | 83 | // Returns player number based on the device number of the event 84 | // Returns 0 for any keyboard events 85 | - (NSUInteger)playerNumberForEvent:(OEHIDEvent *)anEvent; 86 | 87 | - (void)addBindingsObserver:(id)observer; 88 | - (void)removeBindingsObserver:(id)observer; 89 | 90 | @end 91 | 92 | @protocol OESystemBindingsObserver 93 | 94 | /// @param event OEHIDEvent object representing the event to watch 95 | /// @param bindingDescription OEKeyBindingsDescription or OEOrientedKeyGroupBindingDescription object representing the key to trigger for the event 96 | /// @param playerNumber NSUInteger from 0 to numberOfPlayers included, 0 indicates system bindings 97 | - (void)systemBindings:(OESystemBindings *)sender didSetEvent:(OEHIDEvent *)event forBinding:(__kindof OEBindingDescription *)bindingDescription playerNumber:(NSUInteger)playerNumber; 98 | - (void)systemBindings:(OESystemBindings *)sender didUnsetEvent:(OEHIDEvent *)event forBinding:(__kindof OEBindingDescription *)bindingDescription playerNumber:(NSUInteger)playerNumber; 99 | 100 | @end 101 | 102 | NS_ASSUME_NONNULL_END 103 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEM3UFile.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OEM3UFile.h" 28 | 29 | #import "OEDiscDescriptor_Internal.h" 30 | 31 | NSString *const OEM3UFileErrorDomain = @"org.openemu.OEM3UFile.ErrorDomain"; 32 | 33 | @implementation OEM3UFile 34 | 35 | - (BOOL)_setUpFileReferencesWithError:(NSError **)error 36 | { 37 | NSString *fileContent = [self _fileContentWithError:error]; 38 | if (!fileContent) 39 | return NO; 40 | 41 | fileContent = [fileContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 42 | 43 | NSURL *directoryURL = self.fileURL.URLByDeletingLastPathComponent; 44 | 45 | NSMutableArray *referencedFileURLs = [NSMutableArray array]; 46 | NSMutableArray *allReferencedFileURLs = [NSMutableArray array]; 47 | NSMutableArray *referencedBinaryFileURLs = [NSMutableArray array]; 48 | NSMutableArray *referencedDiscDescriptors = [NSMutableArray array]; 49 | 50 | __block NSError *localError; 51 | __block BOOL failedToValidateContainedFiles = NO; 52 | [fileContent enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) { 53 | NSURL *url = [NSURL fileURLWithPath:line isDirectory:NO relativeToURL:directoryURL].absoluteURL; 54 | 55 | __kindof OEFile *referencedFile = [OEFile fileWithURL:url error:&localError]; 56 | if (![referencedFile isKindOfClass:[OEDiscDescriptor class]]) { 57 | // Don't import the m3u if it contains invalid referenced files (unreachable or non-OEDiscDescriptor). 58 | failedToValidateContainedFiles = YES; 59 | return; 60 | } 61 | 62 | OEDiscDescriptor *referencedDiscDescriptor = referencedFile; 63 | 64 | [referencedFileURLs addObject:url]; 65 | [allReferencedFileURLs addObject:url]; 66 | [allReferencedFileURLs addObjectsFromArray:referencedDiscDescriptor.allReferencedFileURLs]; 67 | [referencedBinaryFileURLs addObjectsFromArray:referencedDiscDescriptor.referencedBinaryFileURLs]; 68 | [referencedDiscDescriptors addObject:referencedDiscDescriptor]; 69 | }]; 70 | 71 | if (failedToValidateContainedFiles) { 72 | if (error != nil) 73 | *error = localError; 74 | 75 | return NO; 76 | } 77 | 78 | self.dataTrackFileURL = referencedBinaryFileURLs.firstObject; 79 | self.referencedFileURLs = referencedFileURLs; 80 | self.allReferencedFileURLs = allReferencedFileURLs; 81 | self.referencedBinaryFileURLs = referencedBinaryFileURLs; 82 | 83 | return YES; 84 | } 85 | 86 | - (BOOL)moveToURL:(NSURL *)destinationURL error:(NSError **)error; 87 | { 88 | // Rewrite the file in case there are relative paths in the original file. 89 | if (![self.fileContentWithRelativeFilePaths writeToURL:destinationURL atomically:YES encoding:NSUTF8StringEncoding error:error]) 90 | return NO; 91 | 92 | if (![[NSFileManager defaultManager] removeItemAtURL:self.fileURL error:error]) 93 | return NO; 94 | 95 | return [self moveReferencedFilesToDirectoryAtURL:destinationURL.URLByDeletingLastPathComponent error:error]; 96 | } 97 | 98 | - (BOOL)copyToURL:(NSURL *)destinationURL error:(NSError *__autoreleasing *)error 99 | { 100 | // Rewrite the file in case there are relative paths in the original file. 101 | if (![self.fileContentWithRelativeFilePaths writeToURL:destinationURL atomically:YES encoding:NSUTF8StringEncoding error:error]) 102 | return NO; 103 | 104 | return [self copyReferencedFilesToDirectoryAtURL:destinationURL.URLByDeletingLastPathComponent error:error]; 105 | } 106 | 107 | - (NSString *)fileContentWithRelativeFilePaths 108 | { 109 | return [[self.referencedFileURLs valueForKey:@"lastPathComponent"] componentsJoinedByString:@"\n"]; 110 | } 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEPS4HIDDeviceHandler.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import "OEPS4HIDDeviceHandler.h" 28 | 29 | NS_ASSUME_NONNULL_BEGIN 30 | 31 | @interface OEDeviceHandler () 32 | @property(readwrite) NSUInteger deviceNumber; 33 | @end 34 | 35 | @implementation OEPS4HIDDeviceHandler { 36 | } 37 | 38 | + (BOOL)canHandleDevice:(IOHIDDeviceRef)device 39 | { 40 | NSString *deviceName = (__bridge id)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); 41 | return [deviceName hasPrefix:@"Wireless Controller"]; 42 | } 43 | 44 | - (BOOL)connect 45 | { 46 | // Unfortunately, HID stops responding after sending an output report. 47 | // https://stackoverflow.com/questions/30793753/iokit-not-receiving-hid-interrupt-reports-from-dualshock-4-controller-connected 48 | // https://stackoverflow.com/questions/43852993/macos-hid-usb-control-transfer-hid-api-libusb-macos 49 | #if 0 50 | CFTypeRef transportType = IOHIDDeviceGetProperty([self device], CFSTR(kIOHIDTransportKey)); 51 | BOOL isBluetooth = CFStringCompare(transportType, CFSTR(kIOHIDTransportBluetoothValue), 0) == kCFCompareEqualTo; 52 | 53 | if (isBluetooth) 54 | { 55 | // Turn off lightbar 56 | // https://github.com/torvalds/linux/blob/a3818841bd5e9b4a7e0e732c19cf3a632fcb525e/drivers/hid/hid-sony.c#L2179 57 | // http://www.psdevwiki.com/ps4/DS4-BT#0x11_2 58 | uint8_t data[79]; 59 | memset(data, 0, sizeof(data)); 60 | data[0] = 0xA2; // Bluetooth header, transaction type DATA (0x0a), report type OUTPUT (0x02). 61 | data[1] = 0x11; // protocol code/ID or encoded packet size? 62 | data[2] = 0xC0 | 4; // Poll interval 4ms 63 | data[4] = 0x07; // Enable LEDs, flash, rumble 64 | data[7] = 0x00; // Rumble (right / weak) 65 | data[8] = 0x00; // Rumble (left / strong) 66 | data[9] = 0x00; // LED Red 67 | data[10] = 0x00; // LED Green 68 | data[11] = 0x00; // LED Blue 69 | data[12] = 0x00; // Duration LED flash bright 70 | data[13] = 0x00; // Duration LED flash dark 71 | 72 | // Calculate little-endian CRC32, then add the 4 bytes to end of data 73 | uint32_t crc = rc_crc32(0, data, sizeof(data) - 4); 74 | data[75] = crc & 0xff; 75 | data[76] = (crc >> 8) & 0xff; 76 | data[77] = (crc >> 16) & 0xff; 77 | data[78] = crc >> 24; 78 | 79 | IOHIDDeviceSetReport([self device], 80 | kIOHIDReportTypeOutput, 81 | data[0], // Matters? 82 | data + 1, 83 | sizeof(data) - 1); 84 | } 85 | #endif 86 | return YES; 87 | } 88 | 89 | - (void)disconnect 90 | { 91 | [super disconnect]; 92 | } 93 | 94 | // https://rosettacode.org/wiki/CRC-32#C 95 | // Alternative: use zlib 96 | uint32_t rc_crc32(uint32_t crc, unsigned char const *buf, size_t len) 97 | { 98 | static uint32_t table[256]; 99 | static int have_table = 0; 100 | uint32_t rem; 101 | uint8_t octet; 102 | int i, j; 103 | unsigned char const *p, *q; 104 | 105 | /* This check is not thread safe; there is no mutex. */ 106 | if (have_table == 0) { 107 | /* Calculate CRC table. */ 108 | for (i = 0; i < 256; i++) { 109 | rem = i; /* remainder from polynomial division */ 110 | for (j = 0; j < 8; j++) { 111 | if (rem & 1) { 112 | rem >>= 1; 113 | rem ^= 0xedb88320; 114 | } else 115 | rem >>= 1; 116 | } 117 | table[i] = rem; 118 | } 119 | have_table = 1; 120 | } 121 | 122 | crc = ~crc; 123 | q = buf + len; 124 | for (p = buf; p < q; p++) { 125 | octet = *p; /* Cast to unsigned octet. */ 126 | crc = (crc >> 8) ^ table[(crc & 0xff) ^ octet]; 127 | } 128 | return ~crc; 129 | } 130 | 131 | @end 132 | 133 | NS_ASSUME_NONNULL_END 134 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEDeviceHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | 29 | #import 30 | 31 | NS_ASSUME_NONNULL_BEGIN 32 | 33 | #define kOEHIDElementIsTriggerKey "OEHIDElementIsTrigger" 34 | #define kOEHIDElementHatSwitchTypeKey "OEHIDElementHatSwitchType" 35 | #define kOEHIDElementDeviceIdentifierKey "OEHIDElementDeviceIdentifier" 36 | 37 | @class IOBluetoothDevice; 38 | @class OEControllerDescription; 39 | @class OEDeviceDescription; 40 | @class OEControlDescription; 41 | 42 | extern NSNotificationName const OEDeviceHandlerDidReceiveLowBatteryWarningNotification; 43 | extern NSNotificationName const OEDeviceHandlerPlaceholderOriginalDeviceDidBecomeAvailableNotification; 44 | 45 | typedef struct { 46 | NSInteger min; 47 | NSInteger center; 48 | NSInteger max; 49 | } OEAxisCalibration; 50 | 51 | static inline OEAxisCalibration OEAxisCalibrationMake(NSInteger min, NSInteger max) 52 | { 53 | return (OEAxisCalibration){min, (min+max+1)/2, max}; 54 | } 55 | 56 | static inline OEAxisCalibration OEAxisCalibrationMake2(NSInteger min, NSInteger center, NSInteger max) 57 | { 58 | return (OEAxisCalibration){min, center, max}; 59 | } 60 | 61 | CGFloat OEScaledValueWithCalibration(OEAxisCalibration cal, NSInteger rawValue); 62 | 63 | #define OE_CLAMP(minimum, value, maximum) ((MAX(minimum, MIN(value, maximum)))) 64 | 65 | @interface OEDeviceHandler : NSObject 66 | 67 | - (instancetype)init NS_UNAVAILABLE; 68 | - (instancetype)initWithDeviceDescription:(nullable OEDeviceDescription *)deviceDescription NS_DESIGNATED_INITIALIZER; 69 | - (instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER; 70 | 71 | - (void)setUpControllerDescription:(OEControllerDescription *)description usingRepresentation:(NSDictionary *)controlRepresentations; 72 | 73 | // Uniquely identifies a controller. 74 | // WARNING: This is used by OEHIDEvents, do NOT toy with it. 75 | @property(readonly) NSUInteger deviceIdentifier; 76 | 77 | @property(readonly) NSUInteger deviceNumber; 78 | 79 | @property(nullable, readonly) OEControllerDescription *controllerDescription; 80 | @property(nullable, readonly) OEDeviceDescription *deviceDescription; 81 | 82 | @property(readonly) NSString *uniqueIdentifier; 83 | @property(readonly) NSString *serialNumber; 84 | @property(readonly) NSString *manufacturer; 85 | @property(readonly) NSString *product; 86 | @property(readonly) NSUInteger vendorID; 87 | @property(readonly) NSUInteger productID; 88 | @property(readonly) NSNumber *locationID; 89 | 90 | - (BOOL)connect; 91 | - (void)disconnect; 92 | 93 | @property(readonly) BOOL isKeyboardDevice; 94 | @property(readonly) BOOL isFunctionKeyPressed; 95 | 96 | @property(readonly) BOOL isPlaceholder; 97 | 98 | @property(nonatomic) CGFloat defaultDeadZone; 99 | 100 | - (CGFloat)deadZoneForControlCookie:(NSUInteger)controlCookie; 101 | - (CGFloat)deadZoneForControlDescription:(OEControlDescription *)controlDesc; 102 | - (void)setDeadZone:(CGFloat)deadZone forControlDescription:(OEControlDescription *)controlDesc; 103 | 104 | @property (nonatomic, readonly, getter=isAutoCalibrated) BOOL autoCalibrated; 105 | - (BOOL)calibration:(OEAxisCalibration *)outCalib forControlCookie:(NSUInteger)controlCookie; 106 | - (void)setCalibration:(OEAxisCalibration)calibration forControlCookie:(NSUInteger)controlCookie; 107 | 108 | - (CGFloat)scaledValue:(NSInteger)rawValue forAxis:(OEHIDEventAxis)axis controlCookie:(NSUInteger)cookie defaultCalibration:(OEAxisCalibration)fallback; 109 | - (CGFloat)applyDeadZoneToScaledValue:(CGFloat)value forAxis:(OEHIDEventAxis)axis controlCookie:(NSUInteger)cookie; 110 | - (CGFloat)calibratedValue:(NSInteger)rawValue forAxis:(OEHIDEventAxis)axis controlCookie:(NSUInteger)cookie defaultCalibration:(OEAxisCalibration)fallback; 111 | 112 | @end 113 | 114 | @interface OEDeviceHandlerPlaceholder : OEDeviceHandler 115 | - (instancetype)initWithUniqueIdentifier:(NSString *)uniqueIdentifier; 116 | - (void)notifyOriginalDeviceDidBecomeAvailable; 117 | @end 118 | 119 | NS_ASSUME_NONNULL_END 120 | -------------------------------------------------------------------------------- /OpenEmuBase/OEGameCoreController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009, OpenEmu Team 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the OpenEmu Team nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #import 28 | #if TARGET_OS_OSX 29 | #import 30 | #endif 31 | #import 32 | 33 | 34 | extern NSString *const OEAdvancedPreferenceKey; 35 | 36 | extern NSString *const OEGameCoreClassKey; 37 | extern NSString *const OEGameCorePlayerCountKey; 38 | extern NSString *const OEGameCoreSystemIdentifiersKey; 39 | /// Boolean key. When set to YES and the current macOS version at least 40 | /// the one specified by the OEGameCoreDeprecatedMinMacOSVersionKey key, 41 | /// a warning message is shown when opening a game with this core. 42 | extern NSString *const OEGameCoreDeprecatedKey; 43 | /// String key. The minimum macOS version required for the deprecation warning 44 | /// to take effect. 45 | extern NSString *const OEGameCoreDeprecatedMinMacOSVersionKey; 46 | /// Dictionary key specifying a suggested replacement core for each system. 47 | /// When the core is automatically removed, these cores will set as the new 48 | /// defaults for each system where the default was the removed core. 49 | extern NSString *const OEGameCoreSuggestedReplacement; 50 | /// The date after which the core will be automatically removed. 51 | /// If the macOS version is lesser than the one specified by 52 | /// OEGameCoreDeprecatedMinMacOSVersionKey, it has no effect. 53 | extern NSString *const OEGameCoreSupportDeadlineKey; 54 | extern NSString *const OEGameCoreOptionsKey; 55 | 56 | // sub-keys of OEGameCoreOptionsKey 57 | extern NSString *const OEGameCoreSupportsCheatCodeKey; 58 | extern NSString *const OEGameCoreRequiresFilesKey; 59 | extern NSString *const OEGameCoreRequiredFilesKey; 60 | extern NSString *const OEGameCoreHasGlitchesKey; 61 | extern NSString *const OEGameCoreSupportsMultipleDiscsKey; 62 | extern NSString *const OEGameCoreSaveStatesNotSupportedKey; 63 | extern NSString *const OEGameCoreSupportsRewindingKey; 64 | extern NSString *const OEGameCoreRewindIntervalKey; 65 | extern NSString *const OEGameCoreRewindBufferSecondsKey; 66 | extern NSString *const OEGameCoreSupportsFileInsertionKey; 67 | extern NSString *const OEGameCoreSupportsDisplayModeChangeKey; 68 | 69 | @class OEGameCore, OESystemResponder; 70 | 71 | #if TARGET_OS_OSX 72 | @interface OEGameCoreController : NSResponder 73 | #else 74 | @interface OEGameCoreController : NSObject 75 | #endif 76 | 77 | - (instancetype)initWithBundle:(NSBundle *)aBundle; 78 | 79 | @property(readonly) NSBundle *bundle; 80 | @property(readonly) Class gameCoreClass; 81 | 82 | @property(readonly) NSString *pluginName; 83 | @property(readonly) NSArray *systemIdentifiers; 84 | @property(readonly) NSDictionary *> *coreOptions; 85 | 86 | @property(readonly) NSURL *supportDirectory; 87 | @property(readonly) NSURL *biosDirectory; 88 | @property(readonly) NSUInteger playerCount; 89 | 90 | - (bycopy OEGameCore *)newGameCore; 91 | - (NSArray *> *)requiredFilesForSystemIdentifier:(NSString *)systemIdentifier; 92 | - (BOOL)requiresFilesForSystemIdentifier:(NSString *)systemIdentifier; 93 | - (BOOL)supportsCheatCodeForSystemIdentifier:(NSString *)systemIdentifier; 94 | - (BOOL)hasGlitchesForSystemIdentifier:(NSString *)systemIdentifier; 95 | - (BOOL)saveStatesNotSupportedForSystemIdentifier:(NSString *)systemIdentifier; 96 | - (BOOL)supportsMultipleDiscsForSystemIdentifier:(NSString *)systemIdentifier; 97 | - (BOOL)supportsRewindingForSystemIdentifier:(NSString *)systemIdentifier; 98 | - (BOOL)supportsFileInsertionForSystemIdentifier:(NSString *)systemIdentifier; 99 | - (BOOL)supportsDisplayModeChangeForSystemIdentifier:(NSString *)systemIdentifier; 100 | - (NSUInteger)rewindIntervalForSystemIdentifier:(NSString *)systemIdentifier; 101 | - (NSUInteger)rewindBufferSecondsForSystemIdentifier:(NSString *)systemIdentifier; 102 | 103 | @end 104 | 105 | 106 | @interface OEGameCoreController (Deprecated) 107 | 108 | @property(readonly) NSString *supportDirectoryPath __attribute__((deprecated("Use -supportDirectory"))); 109 | @property(readonly) NSString *biosDirectoryPath __attribute__((deprecated("Use -biosDirectory"))); 110 | 111 | @end 112 | -------------------------------------------------------------------------------- /OpenEmuSystem/OEHIDEvent_Internal.h: -------------------------------------------------------------------------------- 1 | // 2 | // OEHIDEvent_Internal.h 3 | // OpenEmu-SDK 4 | // 5 | // Created by Remy Demarest on 22/12/2015. 6 | // 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | @class OEDeviceHandler, OEHIDDeviceHandler, OEWiimoteHIDDeviceHandler; 14 | 15 | extern OEHIDEventHatDirection OEHIDEventHatDirectionFromNSString(NSString *string); 16 | extern NSString *NSStringFromOEHIDHatDirection(OEHIDEventHatDirection dir); 17 | extern NSString *NSLocalizedStringFromOEHIDHatDirection(OEHIDEventHatDirection dir); 18 | extern NSString *OEHIDEventAxisDisplayDescription(OEHIDEventAxis axis, OEHIDEventAxisDirection direction); 19 | 20 | extern NSString *NSStringFromOEHIDEventType(OEHIDEventType type); 21 | extern OEHIDEventAxis OEHIDEventAxisFromNSString(NSString *string); 22 | extern NSString *NSStringFromOEHIDEventAxis(OEHIDEventAxis axis); 23 | extern NSString *NSStringFromIOHIDElement(IOHIDElementRef elem); 24 | extern OEHIDEventType OEHIDEventTypeFromIOHIDElement(IOHIDElementRef elem); 25 | extern BOOL OEIOHIDElementIsTrigger(IOHIDElementRef elem); 26 | 27 | extern const NSEventModifierFlags OENSEventModifierFlagFunctionKey; 28 | 29 | enum { 30 | OEUndefinedCookie = 0ULL, 31 | }; 32 | 33 | @interface OEHIDEvent () 34 | 35 | + (instancetype)eventWithDictionaryRepresentation:(NSDictionary> *)dictionaryRepresentation; 36 | - (NSDictionary> *)dictionaryRepresentation; 37 | 38 | @property(readonly) __kindof OEDeviceHandler *deviceHandler; 39 | @property(readonly) BOOL hasDeviceHandlerPlaceholder; 40 | - (void)resolveDeviceHandlerPlaceholder; 41 | 42 | @property(readonly) NSTimeInterval timestamp; 43 | @property(readonly) NSUInteger cookie; 44 | @property(readonly) NSUInteger usage; 45 | 46 | @property(readonly) NSEvent *keyboardEvent; 47 | @property(readonly) NSEventModifierFlags modifierFlags; 48 | @property(readonly, copy) NSString *characters; 49 | @property(readonly, copy) NSString *charactersIgnoringModifiers; 50 | 51 | + (NSUInteger)keyCodeForVirtualKey:(CGCharCode)charCode; 52 | + (instancetype)eventWithDeviceHandler:(OEDeviceHandler *)aDeviceHandler value:(IOHIDValueRef)aValue; 53 | + (instancetype)axisEventWithDeviceHandler:(OEDeviceHandler *)aDeviceHandler timestamp:(NSTimeInterval)timestamp axis:(OEHIDEventAxis)axis direction:(OEHIDEventAxisDirection)direction cookie:(NSUInteger)cookie; 54 | + (instancetype)axisEventWithDeviceHandler:(OEDeviceHandler *)aDeviceHandler timestamp:(NSTimeInterval)timestamp axis:(OEHIDEventAxis)axis value:(CGFloat)value cookie:(NSUInteger)cookie; 55 | + (instancetype)axisEventWithDeviceHandler:(OEDeviceHandler *)aDeviceHandler timestamp:(NSTimeInterval)timestamp axis:(OEHIDEventAxis)axis minimum:(NSInteger)minimum value:(NSInteger)value maximum:(NSInteger)maximum cookie:(NSUInteger)cookie; 56 | + (instancetype)triggerEventWithDeviceHandler:(OEDeviceHandler *)aDeviceHandler timestamp:(NSTimeInterval)timestamp axis:(OEHIDEventAxis)axis direction:(OEHIDEventAxisDirection)direction cookie:(NSUInteger)cookie; 57 | + (instancetype)triggerEventWithDeviceHandler:(OEDeviceHandler *)aDeviceHandler timestamp:(NSTimeInterval)timestamp axis:(OEHIDEventAxis)axis value:(NSInteger)value maximum:(NSInteger)maximum cookie:(NSUInteger)cookie; 58 | + (instancetype)triggerEventWithDeviceHandler:(OEDeviceHandler *)aDeviceHandler timestamp:(NSTimeInterval)timestamp axis:(OEHIDEventAxis)axis value:(CGFloat)value cookie:(NSUInteger)cookie; 59 | + (instancetype)buttonEventWithDeviceHandler:(OEDeviceHandler *)aDeviceHandler timestamp:(NSTimeInterval)timestamp buttonNumber:(NSUInteger)number state:(OEHIDEventState)state cookie:(NSUInteger)cookie; 60 | + (instancetype)hatSwitchEventWithDeviceHandler:(OEDeviceHandler *)aDeviceHandler timestamp:(NSTimeInterval)timestamp type:(OEHIDEventHatSwitchType)hatSwitchType direction:(OEHIDEventHatDirection)aDirection cookie:(NSUInteger)cookie; 61 | + (instancetype)keyEventWithTimestamp:(NSTimeInterval)timestamp keyCode:(NSUInteger)keyCode state:(OEHIDEventState)state cookie:(NSUInteger)cookie; 62 | 63 | - (BOOL)isAxisDirectionOppositeToEvent:(OEHIDEvent *)anObject; 64 | 65 | + (NSUInteger)controlIdentifierForType:(OEHIDEventType)type cookie:(NSUInteger)cookie usage:(NSUInteger)usage; 66 | 67 | // The value parameter can be an OEHIDEventAxisDirection for Axis and Trigger, 68 | // or OEHIDEventHatDirection for HatSwitch, 1 is assumed for Button and Keyboard types. 69 | + (NSUInteger)controlValueIdentifierForType:(OEHIDEventType)type cookie:(NSUInteger)cookie usage:(NSUInteger)usage value:(NSInteger)value; 70 | 71 | @end 72 | 73 | @interface OEHIDEvent (OEHIDEventCopy) 74 | 75 | - (instancetype)nullEvent; 76 | 77 | // Axis event copy 78 | - (instancetype)axisEventWithOppositeDirection; 79 | - (instancetype)axisEventWithDirection:(OEHIDEventAxisDirection)aDirection; 80 | 81 | // Hatswitch event copy 82 | - (instancetype)hatSwitchEventWithDirection:(OEHIDEventHatDirection)aDirection; 83 | 84 | - (instancetype)eventWithDeviceHandler:(OEDeviceHandler *)aDeviceHandler; 85 | 86 | @end 87 | 88 | @interface OEHIDEvent (OEHIDEventBinding) 89 | 90 | @property(readonly) NSUInteger bindingHash; 91 | - (BOOL)isBindingEqualToEvent:(OEHIDEvent *)anEvent; 92 | 93 | @end 94 | 95 | @interface NSEvent (OEEventConversion) 96 | + (NSEvent *)eventWithKeyCode:(unsigned short)keyCode; 97 | + (NSEvent *)eventWithKeyCode:(unsigned short)keyCode keyIsDown:(BOOL)keyDown; 98 | + (NSString *)charactersForKeyCode:(unsigned short)keyCode; 99 | + (NSString *)printableCharactersForKeyCode:(unsigned short)keyCode; 100 | + (NSUInteger)modifierFlagsForKeyCode:(unsigned short)keyCode; 101 | + (NSString *)displayDescriptionForKeyCode:(unsigned short)keyCode; 102 | @property(readonly) NSString *displayDescription; 103 | @end 104 | 105 | @interface NSNumber (OEEventConversion) 106 | @property(readonly) NSString *displayDescription; 107 | @end 108 | -------------------------------------------------------------------------------- /OpenEmuSystem/OELocalizationHelper.swift: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | import Foundation 26 | 27 | @objc 28 | @objcMembers 29 | public class OELocalizationHelper: NSObject { 30 | 31 | @objc public enum OERegion: Int { 32 | @objc(OERegionNA) 33 | case na = 0 34 | @objc(OERegionJPN) 35 | case jpn = 1 36 | @objc(OERegionEU) 37 | case eu = 2 38 | @objc(OERegionOther) 39 | case other = 3 40 | 41 | public var name: String { 42 | switch self { 43 | case .eu: 44 | return NSLocalizedString("Europe", comment: "") 45 | case .na: 46 | return NSLocalizedString("North America", comment: "") 47 | case .jpn: 48 | return NSLocalizedString("Japan", comment: "") 49 | case .other: 50 | return NSLocalizedString("Other Region", comment: "") 51 | } 52 | } 53 | } 54 | 55 | public static let OERegionKey = "region" 56 | 57 | @objc(sharedHelper) 58 | public static let shared = OELocalizationHelper() 59 | 60 | public private(set) var region: OERegion = .other 61 | 62 | private override init() { 63 | super.init() 64 | updateRegion() 65 | 66 | UserDefaults.standard.addObserver(self, forKeyPath: Self.OERegionKey, options: [], context: nil) 67 | } 68 | 69 | deinit { 70 | UserDefaults.standard.removeObserver(self, forKeyPath: Self.OERegionKey) 71 | } 72 | 73 | override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { 74 | updateRegion() 75 | } 76 | 77 | private func updateRegion() { 78 | if let value = UserDefaults.standard.value(forKey: Self.OERegionKey) as? Int { 79 | region = OELocalizationHelper.OERegion(rawValue: value) ?? .other 80 | } 81 | else if let regionCode = Locale.current.regionCode { 82 | 83 | if OERegionCodes.europe.contains(regionCode) { 84 | region = .eu 85 | } 86 | else if OERegionCodes.northAmerica.contains(regionCode) { 87 | region = .na 88 | } 89 | else if ["JP", "HK", "TW"].contains(regionCode) { 90 | region = .jpn 91 | } 92 | else { 93 | region = .other 94 | } 95 | } 96 | else { 97 | region = .other 98 | } 99 | } 100 | 101 | // MARK: - Region Codes 102 | 103 | private enum OERegionCodes { 104 | static let africa = ["AO","BF","BI","BJ","BW","CD","CF","CG","CI","CM","CV","DJ","DZ","EG","EH","ER","ET","GA","GH","GM","GN","GQ","GW","KE","KM","LR","LS","LY","MA","MG","ML","MR","MU","MW","MZ","NA","NE","NG","RE","RW","SC","SD","SH","SL","SN","SO","SS","ST","SZ","TD","TG","TN","TZ","UG","YT","ZA","ZM","ZW"] 105 | static let antarctica = ["AQ","BV","GS","HM","TF"] 106 | static let asia = ["AE","AF","AM","AZ","BD","BH","BN","BT","CC","CN","CX","CY","GE","HK","ID","IL","IN","IO","IQ","IR","JO","JP","KG","KH","KP","KR","KW","KZ","LA","LB","LK","MM","MN","MO","MV","MY","NP","OM","PH","PK","PS","QA","SA","SG","SY","TH","TJ","TL","TM","TR","TW","UZ","VN","YE"] 107 | static let europe = ["AD","AL","AT","AX","BA","BE","BG","BY","CH","CZ","DE","DK","EE","ES","FI","FO","FR","GB","GG","GI","GR","HR","HU","IE","IM","IS","IT","JE","LI","LT","LU","LV","MC","MD","ME","MK","MT","NL","NO","PL","PT","RO","RS","RU","SE","SI","SJ","SK","SM","UA","VA"] 108 | static let northAmerica = ["AG","AI","AW","BB","BL","BM","BQ","BS","BZ","CA","CR","CU","CW","DM","DO","GD","GL","GP","GT","HN","HT","JM","KN","KY","LC","MF","MQ","MS","MX","NI","PA","PM","PR","SV","SX","TC","TT","US","VC","VG","VI"] 109 | static let southAmerica = ["AR","BO","BR","CL","CO","EC","FK","GF","GY","PE","PY","SR","UY","VE"] 110 | static let oceania = ["AS","AU","CK","FJ","FM","GU","KI","MH","MP","NC","NF","NR","NU","NZ","PF","PG","PN","PW","SB","TK","TO","TV","UM","VU","WF","WS"] 111 | } 112 | } 113 | 114 | @objc public extension OELocalizationHelper { 115 | 116 | var regionName: String { 117 | return region.name 118 | } 119 | 120 | var isRegionEU: Bool { 121 | region == .eu 122 | } 123 | 124 | var isRegionNA: Bool { 125 | region == .na 126 | } 127 | 128 | var isRegionJPN: Bool { 129 | region == .jpn 130 | } 131 | 132 | @available(*, deprecated, renamed: "isRegionJPN") 133 | var isRegionJAP: Bool { 134 | isRegionJPN 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /OpenEmuBaseTests/OEDiffQueueTests.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, OpenEmu Team 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are met: 5 | // * Redistributions of source code must retain the above copyright 6 | // notice, this list of conditions and the following disclaimer. 7 | // * Redistributions in binary form must reproduce the above copyright 8 | // notice, this list of conditions and the following disclaimer in the 9 | // documentation and/or other materials provided with the distribution. 10 | // * Neither the name of the OpenEmu Team nor the 11 | // names of its contributors may be used to endorse or promote products 12 | // derived from this software without specific prior written permission. 13 | // 14 | // THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | // DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY 18 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | #import 26 | #import "OEDiffQueue.h" 27 | 28 | 29 | @interface OpenEmuBaseTests : XCTestCase 30 | 31 | @end 32 | 33 | 34 | @implementation OpenEmuBaseTests 35 | 36 | 37 | - (NSData *)randomDataOfSize:(NSInteger)size 38 | { 39 | /* using rand because the seed is deterministic */ 40 | char *buf = malloc(size); 41 | for (NSInteger i=0; i *)dataset 70 | { 71 | OEDiffQueue *dq = [[OEDiffQueue alloc] init]; 72 | 73 | XCTAssertTrue([dq count] == 0, @"item count is wrong"); 74 | for (NSInteger i=0; i= 0; i--) { 79 | NSData *popped = [dq pop]; 80 | XCTAssertTrue([dq count] == i, @"item count is wrong"); 81 | XCTAssertTrue([popped isEqual:dataset[i]], @"popped different data than pushed"); 82 | } 83 | XCTAssertNil([dq pop], @"emptied new diff queue not popping nil"); 84 | } 85 | 86 | 87 | - (void)testNewIsEmpty 88 | { 89 | [self runComparisonTest:@[]]; 90 | } 91 | 92 | 93 | - (void)testFirstInsertion 94 | { 95 | [self runComparisonTest:@[[self randomDataOfSize:100]]]; 96 | } 97 | 98 | 99 | - (void)testDeltaInsertion 100 | { 101 | NSMutableArray *dataset = [NSMutableArray arrayWithObject:[self randomDataOfSize:100]]; 102 | [dataset addObject:[self dataByMutatingData:dataset[0] withFrequency:0.1 sizeDifference:0]]; 103 | [dataset addObject:[self dataByMutatingData:dataset[1] withFrequency:0.1 sizeDifference:10]]; 104 | [dataset addObject:[self dataByMutatingData:dataset[2] withFrequency:0.1 sizeDifference:-7]]; 105 | [self runComparisonTest:dataset]; 106 | } 107 | 108 | 109 | - (void)testNoDeltaInsertion 110 | { 111 | [self runComparisonTest:@[ 112 | [self randomDataOfSize:100], 113 | [self randomDataOfSize:100], 114 | [self randomDataOfSize:110], 115 | [self randomDataOfSize:90] 116 | ]]; 117 | } 118 | 119 | 120 | - (void)testBigDeltas 121 | { 122 | NSMutableArray *dataset = [NSMutableArray arrayWithObject:[self randomDataOfSize:10000]]; 123 | for (int i=1; i<100; i++) { 124 | [dataset addObject: 125 | [self dataByMutatingData:dataset[i-1] 126 | withFrequency:arc4random_uniform(50) / 100.0 127 | sizeDifference:((int)arc4random_uniform(3000))-1500]]; 128 | } 129 | [self runComparisonTest:dataset]; 130 | } 131 | 132 | 133 | - (void)testCapacity 134 | { 135 | OEDiffQueue *dq = [[OEDiffQueue alloc] initWithCapacity:10]; 136 | NSMutableArray *dataset = [NSMutableArray arrayWithObject:[self randomDataOfSize:100]]; 137 | [dq push:dataset[0]]; 138 | for (int i=1; i<15; i++) { 139 | [dataset addObject:[self dataByMutatingData:dataset[i-1] withFrequency:0.1 sizeDifference:0]]; 140 | [dq push:dataset[i]]; 141 | XCTAssertEqual([dq count], MIN(i+1, 10), @"count exceeded capacity"); 142 | } 143 | 144 | int j=15-1; 145 | for (int i=0; i<10; i++) { 146 | XCTAssertTrue([[dq pop] isEqual:dataset[j]], @"popped different data than pushed"); 147 | j--; 148 | } 149 | XCTAssertNil([dq pop], @"popped data when it should have been discarded"); 150 | } 151 | 152 | 153 | - (void)testEmptyData 154 | { 155 | [self runComparisonTest:@[[NSData data]]]; 156 | [self runComparisonTest:@[[NSData data], [NSData data]]]; 157 | } 158 | 159 | 160 | - (void)testSmallDiff 161 | { 162 | [self runComparisonTest:@[ 163 | [NSData data], 164 | [self randomDataOfSize:1], 165 | [self randomDataOfSize:2], 166 | [self randomDataOfSize:3], 167 | [self randomDataOfSize:4], 168 | [self randomDataOfSize:6], 169 | [self randomDataOfSize:8] 170 | ]]; 171 | } 172 | 173 | 174 | @end 175 | --------------------------------------------------------------------------------