From d3f22b76d77d8f14a38cc5ef47541649670beb78 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Fri, 25 Feb 2022 01:06:19 -0700 Subject: [PATCH] Enable multi-disc support. Add some fixmes. --- Classes/PCSX2GameCore.mm | 65 ++++++++++++++++++++++++++++++--- PCSX2.xcodeproj/project.pbxproj | 4 ++ Resources/Info.plist | 10 ++--- 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/Classes/PCSX2GameCore.mm b/Classes/PCSX2GameCore.mm index 4a6d058..390fbfa 100644 --- a/Classes/PCSX2GameCore.mm +++ b/Classes/PCSX2GameCore.mm @@ -75,6 +75,11 @@ PCSX2GameCore *_current; std::unique_ptr hostDisplay; VMBootParameters params; + + //Multi-disc booting. + NSUInteger _maxDiscs; + NSMutableArray *_allCueSheetFiles; + NSString *basePath; } - (instancetype)init @@ -82,16 +87,58 @@ PCSX2GameCore *_current; if (self = [super init]) { _current = self; VMManager::InitializeMemory(); + _maxDiscs = 0; } return self; } +static NSString *binCueFix(NSString *path) +{ + if ([[path pathExtension] caseInsensitiveCompare:@"cue"] == NSOrderedSame) { + // Assume the bin file is the same as the cue. + return [[path stringByDeletingPathExtension] stringByAppendingPathExtension:@"bin"]; + } + return path; +} + - (BOOL)loadFileAtPath:(NSString *)path error:(NSError **)error { // PCSX2 can't handle cue files... but can read bin files if ([[path pathExtension] caseInsensitiveCompare:@"cue"] == NSOrderedSame) { - // Assume the bin file is the same as the cue. + // Assume the bin file is the same name as the cue. gamePath = [[path stringByDeletingPathExtension] stringByAppendingPathExtension:@"bin"]; + } else if([path.pathExtension.lowercaseString isEqualToString:@"m3u"]) { + basePath = path.stringByDeletingLastPathComponent; + NSString *m3uString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; + NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@".*\\.cue|.*\\.ccd|.*\\.iso" options:NSRegularExpressionCaseInsensitive error:nil]; + NSUInteger numberOfMatches = [regex numberOfMatchesInString:m3uString options:0 range:NSMakeRange(0, m3uString.length)]; + + NSLog(@"[PCSX2] Loaded m3u containing %lu cue sheets or ccd", numberOfMatches); + + _maxDiscs = numberOfMatches; + + // Keep track of cue sheets for use with SBI files + [regex enumerateMatchesInString:m3uString options:0 range:NSMakeRange(0, m3uString.length) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) { + NSRange range = result.range; + NSString *match = [m3uString substringWithRange:range]; + + if([match containsString:@".cue"] || [match containsString:@".iso"]) { + [_allCueSheetFiles addObject:[m3uString substringWithRange:range]]; + } + }]; + + if (_allCueSheetFiles.count <= 0) { + if (error) { + *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadROMError userInfo:@{NSFilePathErrorKey: path}]; + } + + return false; + } else { + NSString *ToPassBack = [[basePath stringByAppendingPathComponent:_allCueSheetFiles.firstObject] stringByStandardizingPath]; + ToPassBack = binCueFix(ToPassBack); + + gamePath = ToPassBack; + } } else { gamePath = [path copy]; } @@ -100,6 +147,7 @@ PCSX2GameCore *_current; - (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block { + // FIXME: fix save states. bool success = true; //VMManager::LoadState(fileName.fileSystemRepresentation); //block(success, success ? nil : [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadStateError userInfo:@{NSFilePathErrorKey: fileName}]); block(success, nil); @@ -107,6 +155,7 @@ PCSX2GameCore *_current; - (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block { + // FIXME: fix save states. Console.Error("SaveState Requested"); bool success = true ; //VMManager::SaveState(fileName.fileSystemRepresentation); //block(success, success ? nil : [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotSaveStateError userInfo:@{NSFilePathErrorKey: fileName}]); @@ -291,7 +340,7 @@ PCSX2GameCore *_current; - (OEGameCoreRendering)gameCoreRendering { - //TODO: return OEGameCoreRenderingMetal1Video; + //FIXME: return OEGameCoreRenderingMetal1Video; return OEGameCoreRenderingOpenGL3Video; } @@ -346,11 +395,17 @@ PCSX2GameCore *_current; - (NSUInteger)discCount { - return 1; + return _maxDiscs ? _maxDiscs : 1; } - (void)setDisc:(NSUInteger)discNumber { + NSString *ToPassBack = [basePath stringByAppendingPathComponent:_allCueSheetFiles[discNumber - 1]]; + ToPassBack = [binCueFix(ToPassBack) stringByStandardizingPath]; + + gamePath = ToPassBack; + + VMManager::ChangeDisc(gamePath.fileSystemRepresentation); } @end @@ -431,8 +486,8 @@ void Host::WriteToSoundBuffer(s16 Left, s16 Right) { GET_CURRENT_OR_RETURN(); - [[_current audioBufferAtIndex:0] write:(&Left) maxLength:sizeof(s16)]; - [[_current audioBufferAtIndex:0] write:(&Right) maxLength:sizeof(s16)]; + [[current audioBufferAtIndex:0] write:(&Left) maxLength:sizeof(s16)]; + [[current audioBufferAtIndex:0] write:(&Right) maxLength:sizeof(s16)]; } void Host::AddOSDMessage(std::string message, float duration) diff --git a/PCSX2.xcodeproj/project.pbxproj b/PCSX2.xcodeproj/project.pbxproj index 349faa8..f1f28fe 100644 --- a/PCSX2.xcodeproj/project.pbxproj +++ b/PCSX2.xcodeproj/project.pbxproj @@ -8880,6 +8880,7 @@ CLANG_WARN_DOCUMENTATION_COMMENTS = NO; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1.7.0; EXPORTED_SYMBOLS_FILE = Classes/PCSX2Exports.exp; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = pcsx2/pcsx2/PrecompiledHeader.h; @@ -8896,6 +8897,7 @@ ); INFOPLIST_FILE = Resources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; + MARKETING_VERSION = 1.7.0; PRODUCT_BUNDLE_IDENTIFIER = "org.openemu.${PRODUCT_NAME:identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -8947,6 +8949,7 @@ CLANG_WARN_DOCUMENTATION_COMMENTS = NO; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1.7.0; DEAD_CODE_STRIPPING = YES; EXPORTED_SYMBOLS_FILE = Classes/PCSX2Exports.exp; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -8965,6 +8968,7 @@ INFOPLIST_FILE = Resources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; LLVM_LTO = YES_THIN; + MARKETING_VERSION = 1.7.0; PRODUCT_BUNDLE_IDENTIFIER = "org.openemu.${PRODUCT_NAME:identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/Resources/Info.plist b/Resources/Info.plist index 973b4e8..94ce3d7 100644 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString - 1.0 + $(MARKETING_VERSION) CFBundleVersion - 1 + $(CURRENT_PROJECT_VERSION) NSPrincipalClass OEGameCoreController OEGameCoreClass @@ -28,14 +28,14 @@ openemu.system.ps2 - OEGameCoreSaveStatesNotSupported - OEGameCoreHasGlitches + OEGameCoreSaveStatesNotSupported + OEGameCoreSupportsCheatCode OEGameCoreSupportsMultipleDiscs - + OERequiredFiles