Skip to content

Manic EMU is an all-in-one retro game emulator for iOS. It packs powerful features while keeping a clean, sleek UI and delivering buttery-smooth gameplay.

Swift

Add BitBop integration

Daiuno8e069e160801
diff --git a/ManicEmu/ManicEmu.xcodeproj/project.pbxproj b/ManicEmu/ManicEmu.xcodeproj/project.pbxproj
index 48116094..e55b70ef 100644
--- a/ManicEmu/ManicEmu.xcodeproj/project.pbxproj
+++ b/ManicEmu/ManicEmu.xcodeproj/project.pbxproj
@@ -2225,6 +2225,10 @@
E524FBC9308F2B41009885DA /* WiiU.swift in Sources */ = {isa = PBXBuildFile; fileRef = E524FBC7308F2B38009885DA /* WiiU.swift */; };
E524FBCA308F2B41009885DA /* WiiU.swift in Sources */ = {isa = PBXBuildFile; fileRef = E524FBC7308F2B38009885DA /* WiiU.swift */; };
E524FBCB308F2B41009885DA /* WiiU.swift in Sources */ = {isa = PBXBuildFile; fileRef = E524FBC7308F2B38009885DA /* WiiU.swift */; };
+ E524FC023090E598009885DA /* BitBopKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = E524FC013090E591009885DA /* BitBopKit.swift */; };
+ E524FC033090E598009885DA /* BitBopKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = E524FC013090E591009885DA /* BitBopKit.swift */; };
+ E524FC043090E598009885DA /* BitBopKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = E524FC013090E591009885DA /* BitBopKit.swift */; };
+ E524FC053090E598009885DA /* BitBopKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = E524FC013090E591009885DA /* BitBopKit.swift */; };
E5385955E04D43598CAC5694 /* vice.x64sc.libretro.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6A6021052A14459DA6F729AB /* vice.x64sc.libretro.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
E5A00BB23080B2CC00E99223 /* ProHUDExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5A00BB13080B2C200E99223 /* ProHUDExtensions.swift */; };
E5A00BB33080B2CC00E99223 /* ProHUDExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5A00BB13080B2C200E99223 /* ProHUDExtensions.swift */; };
@@ -7499,6 +7503,7 @@
E524FABA308866D4009885DA /* DuoHingeKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DuoHingeKit.swift; sourceTree = "<group>"; };
E524FB053088C9BB009885DA /* ShortcutButtonContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutButtonContainerView.swift; sourceTree = "<group>"; };
E524FBC7308F2B38009885DA /* WiiU.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WiiU.swift; sourceTree = "<group>"; };
+ E524FC013090E591009885DA /* BitBopKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitBopKit.swift; sourceTree = "<group>"; };
E5A00BB13080B2C200E99223 /* ProHUDExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProHUDExtensions.swift; sourceTree = "<group>"; };
E5D10A010000000000000001 /* DuoLayoutKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DuoLayoutKit.swift; sourceTree = "<group>"; };
F0C500000000000000000101 /* FocusTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FocusTypes.swift; sourceTree = "<group>"; };
@@ -14060,6 +14065,7 @@
57BA59B42E3F13C900110849 /* EmulationCore.swift */,
E5D10A010000000000000001 /* DuoLayoutKit.swift */,
E524FABA308866D4009885DA /* DuoHingeKit.swift */,
+ E524FC013090E591009885DA /* BitBopKit.swift */,
);
path = Others;
sourceTree = "<group>";
@@ -14782,6 +14788,7 @@
00000000000051A10000009B /* ASListToolView.swift in Sources */,
00000000000051A10000009C /* PhotoSaver.swift in Sources */,
00000000000051A10000009D /* PurchaseManager.swift in Sources */,
+ E524FC053090E598009885DA /* BitBopKit.swift in Sources */,
00000000000051A10000009E /* ProHUDExtensions.swift in Sources */,
00000000000051A10000009F /* FlexItemView.swift in Sources */,
00000000000051A1000000A0 /* BlankSlateCollectionView.swift in Sources */,
@@ -15227,6 +15234,7 @@
57909406303C7D9100A53656 /* ASListToolView.swift in Sources */,
57909407303C7D9100A53656 /* PhotoSaver.swift in Sources */,
57909408303C7D9100A53656 /* PurchaseManager.swift in Sources */,
+ E524FC033090E598009885DA /* BitBopKit.swift in Sources */,
E5A00BB43080B2CC00E99223 /* ProHUDExtensions.swift in Sources */,
57909409303C7D9100A53656 /* FlexItemView.swift in Sources */,
5790940A303C7D9100A53656 /* BlankSlateCollectionView.swift in Sources */,
@@ -15709,6 +15717,7 @@
57BF60962FE2ABF70073D318 /* ASListToolView.swift in Sources */,
57CDCDEA2FD5CBD3005BA4C8 /* PhotoSaver.swift in Sources */,
57CDCDEC2FD5CBD3005BA4C8 /* PurchaseManager.swift in Sources */,
+ E524FC023090E598009885DA /* BitBopKit.swift in Sources */,
E5A00BB23080B2CC00E99223 /* ProHUDExtensions.swift in Sources */,
577160AF30078D680088345B /* FlexItemView.swift in Sources */,
57CDCDED2FD5CBD3005BA4C8 /* BlankSlateCollectionView.swift in Sources */,
@@ -16355,6 +16364,7 @@
57E0C1A72D56580F00962555 /* UITextFieldExtensions.swift in Sources */,
5720E7CA2E54470000EC0DA5 /* ArrayExtensions.swift in Sources */,
57CC338E2DBC78AE00DF7418 /* FlexSkinSettingViewController.swift in Sources */,
+ E524FC043090E598009885DA /* BitBopKit.swift in Sources */,
5706AFC62DF7DABD0066122E /* BIOSCollectionViewCell.swift in Sources */,
579454232FE683F700D32DD6 /* ASTextView.swift in Sources */,
57E9632E2D6B0B8A0022914C /* SparkleSeperatorView.swift in Sources */,
diff --git a/ManicEmu/ManicEmu.xcodeproj/xcshareddata/xcschemes/ManicEmuDebug.xcscheme b/ManicEmu/ManicEmu.xcodeproj/xcshareddata/xcschemes/ManicEmuDebug.xcscheme
index d844db88..d127904b 100644
--- a/ManicEmu/ManicEmu.xcodeproj/xcshareddata/xcschemes/ManicEmuDebug.xcscheme
+++ b/ManicEmu/ManicEmu.xcodeproj/xcshareddata/xcschemes/ManicEmuDebug.xcscheme
@@ -31,7 +31,7 @@
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
- buildConfiguration = "SideloadRelease"
+ buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/Contents.json b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/Contents.json
new file mode 100644
index 00000000..73c00596
--- /dev/null
+++ b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/Contents.json
@@ -0,0 +1,6 @@
+{
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/Contents.json b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/Contents.json
new file mode 100644
index 00000000..76ea028a
--- /dev/null
+++ b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/Contents.json
@@ -0,0 +1,54 @@
+{
+ "images" : [
+ {
+ "idiom" : "universal",
+ "scale" : "1x"
+ },
+ {
+ "appearances" : [
+ {
+ "appearance" : "luminosity",
+ "value" : "dark"
+ }
+ ],
+ "idiom" : "universal",
+ "scale" : "1x"
+ },
+ {
+ "filename" : "[email protected]",
+ "idiom" : "universal",
+ "scale" : "2x"
+ },
+ {
+ "appearances" : [
+ {
+ "appearance" : "luminosity",
+ "value" : "dark"
+ }
+ ],
+ "filename" : "[email protected]",
+ "idiom" : "universal",
+ "scale" : "2x"
+ },
+ {
+ "filename" : "[email protected]",
+ "idiom" : "universal",
+ "scale" : "3x"
+ },
+ {
+ "appearances" : [
+ {
+ "appearance" : "luminosity",
+ "value" : "dark"
+ }
+ ],
+ "filename" : "[email protected]",
+ "idiom" : "universal",
+ "scale" : "3x"
+ }
+ ],
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/[email protected] b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/[email protected]
new file mode 100644
index 00000000..eab323a4
Binary files /dev/null and b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/[email protected] differ
diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/[email protected] b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/[email protected]
new file mode 100644
index 00000000..6448e7c3
Binary files /dev/null and b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/[email protected] differ
diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/[email protected] b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/[email protected]
new file mode 100644
index 00000000..ab8da6b5
Binary files /dev/null and b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/[email protected] differ
diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/[email protected] b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/[email protected]
new file mode 100644
index 00000000..1c87180e
Binary files /dev/null and b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_bg.imageset/[email protected] differ
diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_logo.imageset/Contents.json b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_logo.imageset/Contents.json
new file mode 100644
index 00000000..a0226651
--- /dev/null
+++ b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_logo.imageset/Contents.json
@@ -0,0 +1,22 @@
+{
+ "images" : [
+ {
+ "idiom" : "universal",
+ "scale" : "1x"
+ },
+ {
+ "filename" : "[email protected]",
+ "idiom" : "universal",
+ "scale" : "2x"
+ },
+ {
+ "filename" : "[email protected]",
+ "idiom" : "universal",
+ "scale" : "3x"
+ }
+ ],
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_logo.imageset/[email protected] b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_logo.imageset/[email protected]
new file mode 100644
index 00000000..9590f907
Binary files /dev/null and b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_logo.imageset/[email protected] differ
diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_logo.imageset/[email protected] b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_logo.imageset/[email protected]
new file mode 100644
index 00000000..0ac7fd26
Binary files /dev/null and b/ManicEmu/ManicEmu/Resources/Assets.xcassets/BitBop/bitbop_logo.imageset/[email protected] differ
diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/Symbols/bitbop_icon.symbols.symbolset/Contents.json b/ManicEmu/ManicEmu/Resources/Assets.xcassets/Symbols/bitbop_icon.symbols.symbolset/Contents.json
new file mode 100644
index 00000000..2c11ce99
--- /dev/null
+++ b/ManicEmu/ManicEmu/Resources/Assets.xcassets/Symbols/bitbop_icon.symbols.symbolset/Contents.json
@@ -0,0 +1,12 @@
+{
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ },
+ "symbols" : [
+ {
+ "filename" : "bitbop_icon.symbols.svg",
+ "idiom" : "universal"
+ }
+ ]
+}
diff --git a/ManicEmu/ManicEmu/Resources/Assets.xcassets/Symbols/bitbop_icon.symbols.symbolset/bitbop_icon.symbols.svg b/ManicEmu/ManicEmu/Resources/Assets.xcassets/Symbols/bitbop_icon.symbols.symbolset/bitbop_icon.symbols.svg
new file mode 100644
index 00000000..885c93a8
--- /dev/null
+++ b/ManicEmu/ManicEmu/Resources/Assets.xcassets/Symbols/bitbop_icon.symbols.symbolset/bitbop_icon.symbols.svg
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg width="800" height="600" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <g id="Notes" font-family="'LucidaGrande', 'Lucida Grande', sans-serif" font-weight="500" font-size="13px">
+ <rect x="0" y="0" width="800" height="600" fill="white"/>
+ <g font-weight="500" font-size="13px">
+ <text x="18px" y="176px">Small</text>
+ <text x="18px" y="376px">Medium</text>
+ <text x="18px" y="576px">Large</text>
+ </g>
+ <g font-weight="300" font-size="9px">
+ <text x="250px" y="30px">Ultralight</text>
+ <text x="450px" y="30px">Regular</text>
+ <text x="650px" y="30px">Black</text>
+ <text id="template-version" fill="#505050" x="785.0" y="575.0" text-anchor="end">Template v.3.0</text>
+ <a href="https://wangchujiang.com/#/app">
+ <text fill="#505050" x="785.0" y="590.0" text-anchor="end">https://wangchujiang.com/#/app</text>
+ </a>
+ </g>
+ </g>
+
+ <g id="Guides" stroke="rgb(39,170,225)" stroke-width="0.5px">
+ <path id="Capline-S" d="M18,76 l800,0" />
+ <path id="H-reference"
+ d="M85,145.755 L87.685,145.755 L113.369,79.287 L114.052002,79.287
+ L114.052002,76 L112.148,76 L85,145.755 Z
+ M95.693,121.536 L130.996,121.536 L130.263,119.313 L96.474,119.313 L95.693,121.536 Z
+ M139.14999,145.755 L141.787,145.755 L114.638,76 L113.466,76 L113.466,79.287 L139.14999,145.755 Z" stroke="none" />
+ <path id="Baseline-S" d="M18,146 l800,0" />
+ <path id="left-margin-Ultralight-S" d="M221,56 l0,110" />
+ <path id="right-margin-Ultralight-S" d="M309,56 l0,110" /> <path id="left-margin-Regular-S" d="M421,56 l0,110" />
+ <path id="right-margin-Regular-S" d="M509,56 l0,110" /> <path id="left-margin-Black-S" d="M621,56 l0,110" />
+ <path id="right-margin-Black-S" d="M709,56 l0,110" />
+ <path id="Capline-M" d="M18,276 l800,0" />
+ <path id="Baseline-M" d="M18,346 l800,0" />
+
+ <path id="Capline-L" d="M18,476 l800,0" />
+ <path id="Baseline-L" d="M18,546 l800,0" />
+
+ </g>
+
+ <g id="Symbols">
+ <g id="Ultralight-S">
+<path d="M239.211 76 C247.349 76 253.947 82.598 253.947 90.737 L253.947 120.211 C253.947 126.315 258.896 131.263 265 131.263 C271.104 131.263 276.053 126.315 276.053 120.211 C276.053 114.106 271.104 109.158 265 109.158 C263.708 109.158 262.468 109.38 261.316 109.788 L261.316 94.683 C262.519 94.511 263.749 94.421 265 94.421 C279.243 94.421 290.789 105.967 290.789 120.211 C290.789 134.454 279.243 146 265 146 C250.757 146 239.211 134.454 239.211 120.211 L239.211 76 Z" fill="currentColor"/>
+ </g>
+ <g id="Regular-S">
+<path d="M439.211 76 C447.349 76 453.947 82.598 453.947 90.737 L453.947 120.211 C453.947 126.315 458.896 131.263 465 131.263 C471.104 131.263 476.053 126.315 476.053 120.211 C476.053 114.106 471.104 109.158 465 109.158 C463.708 109.158 462.468 109.38 461.316 109.788 L461.316 94.683 C462.519 94.511 463.749 94.421 465 94.421 C479.243 94.421 490.789 105.967 490.789 120.211 C490.789 134.454 479.243 146 465 146 C450.757 146 439.211 134.454 439.211 120.211 L439.211 76 Z" fill="currentColor"/>
+ </g>
+ <g id="Black-S">
+<path d="M639.211 76 C647.349 76 653.947 82.598 653.947 90.737 L653.947 120.211 C653.947 126.315 658.896 131.263 665 131.263 C671.104 131.263 676.053 126.315 676.053 120.211 C676.053 114.106 671.104 109.158 665 109.158 C663.708 109.158 662.468 109.38 661.316 109.788 L661.316 94.683 C662.519 94.511 663.749 94.421 665 94.421 C679.243 94.421 690.789 105.967 690.789 120.211 C690.789 134.454 679.243 146 665 146 C650.757 146 639.211 134.454 639.211 120.211 L639.211 76 Z" fill="currentColor"/>
+ </g>
+ </g>
+</svg>
\ No newline at end of file
diff --git a/ManicEmu/ManicEmu/Resources/Info.plist b/ManicEmu/ManicEmu/Resources/Info.plist
index 8cbee213..6a24e4ac 100644
--- a/ManicEmu/ManicEmu/Resources/Info.plist
+++ b/ManicEmu/ManicEmu/Resources/Info.plist
@@ -631,6 +631,7 @@
<string>gba4ios</string>
<string>consolesapp</string>
<string>melocafe</string>
+ <string>bitbop</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
diff --git a/ManicEmu/ManicEmu/Resources/en.lproj/Localizable.strings b/ManicEmu/ManicEmu/Resources/en.lproj/Localizable.strings
index dd5b5ebc..8a1b3bd8 100644
--- a/ManicEmu/ManicEmu/Resources/en.lproj/Localizable.strings
+++ b/ManicEmu/ManicEmu/Resources/en.lproj/Localizable.strings
@@ -1206,3 +1206,18 @@ Press the controller button to complete mapping...";
"game3DSEncryptedTips" = "Import the correct aes_keys.txt to read encrypted ROMs. Only the Citra core can run them.";
"FetchGamesFromMeloCafe" = "Import Games from MeloCafe";
+
+"ListenWithBitBop" = "Listen with BitBop";
+"BitBopSendFailed" = "Couldn't send this to BitBop. Wait a moment and try again.";
+"BitBopTracksUnavailable" = "BitBop doesn't have tracks for this ROM.";
+"BitBopListenTitle" = "Keep the Soundtrack";
+"BitBopAlbumReady" = "「%@」 is already in BitBop";
+"BitBopAlbumTrackPreview" = "Start with %@.";
+"BitBopAlbumQuiet" = "「%@」 is already in BitBop, but the soundtrack isn't available to play.";
+"BitBopTrackCount" = "%d tracks";
+"BitBopParseRom" = "Some melodies don't have to end with the level. Send them to BitBop, and they become an album you can play anytime.";
+"BitBopScanRom" = "This cartridge may still hold music that was never heard on its own. BitBop will find it and turn it into an album.";
+"MoreFromManic" = "More from Manic";
+"BitBopPromoTitle" = "BitBop: Your Games, Your Music";
+"BitBopPromoDetail" = "Import your favorite classics and listen to the music that brings them to life.";
+"BitBopTryNow" = "Try Now";
diff --git a/ManicEmu/ManicEmu/Resources/zh-Hans.lproj/Localizable.strings b/ManicEmu/ManicEmu/Resources/zh-Hans.lproj/Localizable.strings
index 4c54a329..49837172 100644
--- a/ManicEmu/ManicEmu/Resources/zh-Hans.lproj/Localizable.strings
+++ b/ManicEmu/ManicEmu/Resources/zh-Hans.lproj/Localizable.strings
@@ -1201,3 +1201,18 @@
"game3DSEncryptedTips" = "请导入正确的 aes_keys.txt 以读取加密 ROM。仅 Citra 核心可以运行此类 ROM。";
"FetchGamesFromMeloCafe" = "从 MeloCafe 导入游戏";
+
+"ListenWithBitBop" = "用 BitBop 聆听";
+"BitBopSendFailed" = "这次没能交给 BitBop。稍等片刻,再试一次。";
+"BitBopTracksUnavailable" = "BitBop 没有这款 ROM 的曲目。";
+"BitBopListenTitle" = "把配乐单独留下";
+"BitBopAlbumReady" = "「%@」已经在 BitBop 里";
+"BitBopAlbumTrackPreview" = "可以先从 %@ 听起。";
+"BitBopAlbumQuiet" = "「%@」已经在 BitBop 里,只是现在听不到配乐。";
+"BitBopTrackCount" = "%d 首曲目";
+"BitBopParseRom" = "游戏里有些旋律,本来就不必跟着关卡一起结束。交给 BitBop,它们会成为一张随时能听的专辑。";
+"BitBopScanRom" = "这张卡带里,也许还留着没被单独听过的配乐。BitBop 会把它找出来,做成一张专辑。";
+"MoreFromManic" = "更多来自 Manic";
+"BitBopPromoTitle" = "BitBop:你的游戏,你的音乐";
+"BitBopPromoDetail" = "导入你喜爱的经典游戏,聆听赋予它们生命的配乐。";
+"BitBopTryNow" = "立即体验";
diff --git a/ManicEmu/ManicEmu/Sources/Base/Constants.swift b/ManicEmu/ManicEmu/Sources/Base/Constants.swift
index 270a1aff..16bc64a8 100644
--- a/ManicEmu/ManicEmu/Sources/Base/Constants.swift
+++ b/ManicEmu/ManicEmu/Sources/Base/Constants.swift
@@ -1357,6 +1357,7 @@ extension _R {
static let SymbianFlexSkinUrl = URL(fileURLWithPath: R.Path.Resource.appendingPathComponent("Symbian_Flex.manicskin"))
static let SymbianEdgeSkinUrl = URL(fileURLWithPath: R.Path.Resource.appendingPathComponent("Symbian_Edge.manicskin"))
static let SymbianEdgeFlexSkinUrl = URL(fileURLWithPath: R.Path.Resource.appendingPathComponent("Symbian_Edge_Flex.manicskin"))
+ static let BitBopStoreUrl = URL(string: "https://apps.apple.com/app/id6828015363")!
}
diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASSheet.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASSheet.swift
index 5bf6bfad..b708f5f2 100644
--- a/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASSheet.swift
+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Models/ASSheet.swift
@@ -31,7 +31,9 @@ struct ASSheet {
detail: String,
detailAlignment: NSTextAlignment = .center,
buttonTitle: String? = nil,
- destructiveButtonTitle: String? = nil)
+ buttonTitleColor: UIColor = R.Color.LabelSecondary,
+ destructiveButtonTitle: String? = nil,
+ destructiveButtonTitleColor: UIColor = R.Color.Main)
case updation(title: String, detail: String)
case step(title: String? = nil,
detail: String? = nil,
diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASSheetView.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASSheetView.swift
index 9fb4a9cf..aee723d6 100644
--- a/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASSheetView.swift
+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Views/ASSheetView.swift
@@ -116,12 +116,16 @@ class ASSheetView: BaseView {
let detail,
let detailAlignment,
let buttonTitle,
- let destructiveButtonTitle):
+ let buttonTitleColor,
+ let destructiveButtonTitle,
+ let destructiveButtonTitleColor):
updateText(title: title,
detail: detail,
detailAlignment: detailAlignment,
buttonTitle: buttonTitle,
+ buttonTitleColor: buttonTitleColor,
destructiveButtonTitle: destructiveButtonTitle,
+ destructiveButtonTitleColor: destructiveButtonTitleColor,
refreshData: refreshData)
@@ -538,7 +542,9 @@ class ASSheetView: BaseView {
detail: String,
detailAlignment: NSTextAlignment = .center,
buttonTitle: String? = nil,
+ buttonTitleColor: UIColor = R.Color.LabelSecondary,
destructiveButtonTitle: String? = nil,
+ destructiveButtonTitleColor: UIColor = R.Color.Main,
refreshData: ASSheetRefreshData) {
let contentView = refreshData.contentView
@@ -552,7 +558,9 @@ class ASSheetView: BaseView {
detail: detail,
detailAlignment: detailAlignment,
buttonTitle: buttonTitle,
+ buttonTitleColor: buttonTitleColor,
destructiveButtonTitle: destructiveButtonTitle,
+ destructiveButtonTitleColor: destructiveButtonTitleColor,
enableGrabber: refreshData.sheetData.enableGrabber)
contentView.addSubview(textSheetView)
textSheetView.snp.makeConstraints { make in
@@ -561,12 +569,20 @@ class ASSheetView: BaseView {
let updation: ASSheetViewUpdation = { [weak contentView, weak sheetView] updateData in
guard let contentView, let sheetView else { return }
- if case let .text(title, detail, detailAlignment, buttonTitle, destructiveButtonTitle) = updateData {
+ if case let .text(title,
+ detail,
+ detailAlignment,
+ buttonTitle,
+ buttonTitleColor,
+ destructiveButtonTitle,
+ destructiveButtonTitleColor) = updateData {
updateText(title: title,
detail: detail,
detailAlignment: detailAlignment,
buttonTitle: buttonTitle,
+ buttonTitleColor: buttonTitleColor,
destructiveButtonTitle: destructiveButtonTitle,
+ destructiveButtonTitleColor: destructiveButtonTitleColor,
refreshData: (contentView, sheetView, action, sheetData))
}
}
@@ -806,7 +822,9 @@ extension ASSheetView {
detail: String,
detailAlignment: NSTextAlignment = .center,
buttonTitle: String? = nil,
+ buttonTitleColor: UIColor = R.Color.LabelSecondary,
destructiveButtonTitle: String? = nil,
+ destructiveButtonTitleColor: UIColor = R.Color.Main,
enableGrabber: Bool) {
super.init(frame: .zero)
@@ -857,7 +875,7 @@ extension ASSheetView {
verticalLine.backgroundColor = R.Color.Border
let button = ASButtonView(.quickButton(title: buttonTitle,
- titleColor: R.Color.LabelSecondary,
+ titleColor: buttonTitleColor,
titleFont: R.Font.Headline(),
titleAlignment: .center,
background: .clear,
@@ -870,7 +888,7 @@ extension ASSheetView {
var destructiveButton: ASButtonView? = nil
if let destructiveButtonTitle {
let view = ASButtonView(.quickButton(title: destructiveButtonTitle,
- titleColor: R.Color.Main,
+ titleColor: destructiveButtonTitleColor,
titleFont: R.Font.Headline(emphasis: true),
titleAlignment: .center,
background: .clear,
diff --git a/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoCoverView.swift b/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoCoverView.swift
index fda4dc61..77e47eac 100644
--- a/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoCoverView.swift
+++ b/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoCoverView.swift
@@ -39,8 +39,26 @@ class GameInfoCoverView: BaseView {
}()
private var game: Game
+ private var bitbopOffer: BitBopKit.CoverOffer = .hidden
private var CoverImageSize: CGSize = .init(UIDevice.isPhone ? 236.0 : 200.0)
+ private lazy var bitbopButton: ASButtonView = {
+ let view = ASButtonView(.iconOnlyWithSmallSize(icon: .symbolImage(R.image.bitbop_iconSymbols(),
+ colors: [R.Color.LabelPrimary.forceStyle(.dark)]),
+ background: R.Color.Red))
+ view.cornerStyle = .circle
+ view.isHidden = true
+ view.accessibilityLabel = R.string.localizable.listenWithBitBop()
+ view.didTapButton = { [weak self] in
+ guard let self, self.bitbopOffer.showsButton else { return }
+ UIDevice.generateHaptic()
+ // Re-check at tap time so a library alert is not shown after BitBop has been removed.
+ let offer: BitBopKit.CoverOffer = BitBopKit.isBitBopInstalled ? self.bitbopOffer : .send(scansCartridge: false)
+ BitBopKit.presentCoverOffer(offer, for: self.game, in: self.hostingWindowScene)
+ }
+ return view
+ }()
+
init(game: Game) {
self.game = game
@@ -85,6 +103,15 @@ class GameInfoCoverView: BaseView {
maskTopView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
+
+ if game.gameType.supportBitBop {
+ addSubview(bitbopButton)
+ bitbopButton.snp.makeConstraints { make in
+ make.top.equalTo(coverContainerView).offset(R.Size.ContentSpaceExtraSmall)
+ make.trailing.equalTo(coverContainerView).offset(-R.Size.ContentSpaceExtraSmall)
+ }
+ refreshBitBopButton()
+ }
}
required init?(coder: NSCoder) {
@@ -100,6 +127,29 @@ class GameInfoCoverView: BaseView {
coverImageView.updateRating(esrp: GameMetadata.getGameMetadata(game: game)?.ESRPRating)
}
+ /// The options list is transparent over the cover and sits above this view, so it steals taps on the lower half of the button.
+ func bitbopButton(at point: CGPoint, with event: UIEvent?) -> UIView? {
+ guard game.gameType.supportBitBop, !bitbopButton.isHidden, bitbopButton.alpha > 0.01 else { return nil }
+ let local = bitbopButton.convert(point, from: self)
+ guard bitbopButton.point(inside: local, with: event) else { return nil }
+ return bitbopButton.hitTest(local, with: event)
+ }
+
+ /// Sits on the cover art so it stays clear of the navigation close button.
+ private func refreshBitBopButton() {
+ let gameType = game.gameType
+ let romURL = game.romUrl
+ let bitbopInstalled = BitBopKit.isBitBopInstalled
+ DispatchQueue.global(qos: .userInitiated).async { [weak self] in
+ let offer = BitBopKit.prepareCoverOffer(gameType: gameType, romURL: romURL, bitbopInstalled: bitbopInstalled)
+ DispatchQueue.main.async {
+ guard let self else { return }
+ self.bitbopOffer = offer
+ self.bitbopButton.isHidden = !offer.showsButton
+ }
+ }
+ }
+
private func updateCoverContainerViewConstraints() {
coverContainerView.snp.remakeConstraints { make in
make.size.equalTo(proHUDLayoutStyle() == .landscape ? CoverImageSize.applying(.init(scaleX: 0.8, y: 0.8)) : CoverImageSize)
diff --git a/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoView.swift b/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoView.swift
index e524f7df..32cef092 100644
--- a/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoView.swift
+++ b/ManicEmu/ManicEmu/Sources/Business/GameInfo/VIews/GameInfoView.swift
@@ -228,6 +228,14 @@ class GameInfoView: BaseView {
}
}
+ override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
+ let coverPoint = gameCoverView.convert(point, from: self)
+ if let button = gameCoverView.bitbopButton(at: coverPoint, with: event) {
+ return button
+ }
+ return super.hitTest(point, with: event)
+ }
+
override func layoutSubviews() {
super.layoutSubviews()
guard width > 0 else { return }
diff --git a/ManicEmu/ManicEmu/Sources/Business/Games/Models/GameOption.swift b/ManicEmu/ManicEmu/Sources/Business/Games/Models/GameOption.swift
index ef43eb9e..91ee909d 100644
--- a/ManicEmu/ManicEmu/Sources/Business/Games/Models/GameOption.swift
+++ b/ManicEmu/ManicEmu/Sources/Business/Games/Models/GameOption.swift
@@ -85,7 +85,8 @@ enum GameOption: Int, CaseIterable {
slowMotion,
ndsLidToggle,
editLink,
- skinButtonBinding
+ skinButtonBinding,
+ bitbop
//When adding a new option, make sure to add it at the end; otherwise, it might affect the existing Prefference configurations
@@ -235,6 +236,8 @@ enum GameOption: Int, CaseIterable {
.symbol(.squareTophalfFilled)
case .skinButtonBinding:
.symbolImage(R.image.keyboard_iconSymbols())
+ case .bitbop:
+ .symbolImage(R.image.bitbop_iconSymbols(), colors: [R.Color.Red])
}
}
@@ -392,6 +395,8 @@ enum GameOption: Int, CaseIterable {
R.string.localizable.ndsLidToggle()
case .skinButtonBinding:
R.string.localizable.skinButtonBinding()
+ case .bitbop:
+ R.string.localizable.listenWithBitBop()
}
}
@@ -469,6 +474,9 @@ enum GameOption: Int, CaseIterable {
]
static let defaultGroupAndSort: [[Self]] = [
+ [
+ .bitbop
+ ],
[
.rename,
.cover,
@@ -1011,7 +1019,8 @@ enum GameOption: Int, CaseIterable {
.coverScraping,
.ndsLidToggle,
.pspJitType,
- .skinButtonBinding:
+ .skinButtonBinding,
+ .bitbop:
break
}
return .chevron(nil)
@@ -1069,7 +1078,8 @@ enum GameOption: Int, CaseIterable {
.snesVRAM,
.symbianDevice,
.coverScraping,
- .dolphinCpuCore
+ .dolphinCpuCore,
+ .bitbop
]
}
}
@@ -1330,6 +1340,10 @@ enum GameOption: Int, CaseIterable {
allOptions.remove(.skinButtonBinding)
}
+ if !game.gameType.supportBitBop {
+ allOptions.remove(.bitbop)
+ }
+
allOptions.subtract(disableOptionsForScene(scene))
return Array(allOptions)
diff --git a/ManicEmu/ManicEmu/Sources/Business/Games/Models/GameOptionPerform.swift b/ManicEmu/ManicEmu/Sources/Business/Games/Models/GameOptionPerform.swift
index 37ab9213..609f5e51 100644
--- a/ManicEmu/ManicEmu/Sources/Business/Games/Models/GameOptionPerform.swift
+++ b/ManicEmu/ManicEmu/Sources/Business/Games/Models/GameOptionPerform.swift
@@ -1122,6 +1122,9 @@ extension GameOption {
case .skinButtonBinding:
SkinButtonBindingView.show(games: games)
+
+ case .bitbop:
+ BitBopKit.sendToBitBop(games: games, in: scene)
}
}
diff --git a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsListView.swift b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsListView.swift
index 7b835263..b5de77bb 100644
--- a/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsListView.swift
+++ b/ManicEmu/ManicEmu/Sources/Business/Settings/Views/SettingsListView.swift
@@ -13,7 +13,7 @@ import MessageUI
class SettingsListView: BaseView {
enum SectionIndex: Int, CaseIterable {
- case top, general, advance, support, others, bottom
+ case top, general, advance, support, others, moreFromManic, bottom
var title: String {
switch self {
case .top, .bottom:
@@ -26,6 +26,8 @@ class SettingsListView: BaseView {
R.string.localizable.supportSettingTitle()
case .others:
R.string.localizable.othersSettingTitle()
+ case .moreFromManic:
+ R.string.localizable.moreFromManic()
}
}
}
@@ -59,7 +61,7 @@ class SettingsListView: BaseView {
}
for section in SectionIndex.allCases {
- if section == .top || section == .bottom {
+ if section == .top || section == .bottom || section == .moreFromManic {
datas[section] = []
} else if section == .general {
@@ -197,6 +199,13 @@ class SettingsListView: BaseView {
let section = ASListPage.Section(cells: settingItems.map({ $0.cellData }), header: header)
sections.append(section)
+ case .moreFromManic:
+ let promo = SettingsBitBopPromoView()
+ sections.append(ASListPage.Section(cells: [.custom(promo)],
+ header: .defaultHeader(title: sectionIndex.title),
+ decoration: .init(enable: false),
+ itemLayout: .fixedHeight(100)))
+
case .bottom:
var cellHeight = 479.0
#if SIDE_LOAD
@@ -474,7 +483,7 @@ class SettingsListView: BaseView {
}
}
- case .bottom:
+ case .moreFromManic, .bottom:
break
}
}
@@ -512,3 +521,82 @@ extension SettingsListView: MFMailComposeViewControllerDelegate {
}
}
+
+/// Settings promo for BitBop. Layout follows the Settings-BitBop card: 100pt, 20pt corners, logo on the right.
+private final class SettingsBitBopPromoView: BaseView {
+ override init(frame: CGRect) {
+ super.init(frame: frame)
+ layer.cornerRadius = R.Size.CornerRadiusLarge
+ clipsToBounds = true
+
+ let backgroundView = UIImageView(image: R.image.bitbop_bg())
+ backgroundView.contentMode = .scaleAspectFill
+ addSubview(backgroundView)
+ backgroundView.snp.makeConstraints { make in
+ make.edges.equalToSuperview()
+ }
+
+ let logoView = UIImageView(image: R.image.bitbop_logo())
+ logoView.contentMode = .scaleAspectFill
+ logoView.layer.cornerRadius = R.Size.CornerRadiusMedium
+ logoView.clipsToBounds = true
+ addSubview(logoView)
+ logoView.snp.makeConstraints { make in
+ make.trailing.equalToSuperview().inset(12)
+ make.centerY.equalToSuperview()
+ make.size.equalTo(60)
+ }
+
+ let titleLabel = UILabel()
+ titleLabel.text = R.string.localizable.bitBopPromoTitle()
+ titleLabel.font = R.Font.Body(emphasis: true)
+ titleLabel.textColor = R.Color.LabelPrimary.forceStyle(.dark)
+ titleLabel.numberOfLines = 1
+ addSubview(titleLabel)
+ titleLabel.snp.makeConstraints { make in
+ make.leading.equalToSuperview().offset(12)
+ make.trailing.equalTo(logoView.snp.leading).offset(-12)
+ make.top.equalToSuperview().offset(11)
+ }
+
+ let detailLabel = UILabel()
+ detailLabel.text = R.string.localizable.bitBopPromoDetail()
+ detailLabel.font = R.Font.Caption()
+ detailLabel.textColor = R.Color.LabelSecondary.forceStyle(.dark)
+ detailLabel.numberOfLines = 2
+ addSubview(detailLabel)
+ detailLabel.snp.makeConstraints { make in
+ make.leading.trailing.equalTo(titleLabel)
+ make.top.equalToSuperview().offset(31)
+ }
+
+ let tryNowLabel = UILabel()
+ tryNowLabel.text = R.string.localizable.bitBopTryNow()
+ tryNowLabel.font = R.Font.Caption()
+ tryNowLabel.textColor = R.Color.Red
+ let tryNowView = UIView()
+ tryNowView.isUserInteractionEnabled = false
+ tryNowView.backgroundColor = UIColor.white.withAlphaComponent(0.16)
+ tryNowView.layer.cornerRadius = 12
+ tryNowView.addSubview(tryNowLabel)
+ tryNowLabel.snp.makeConstraints { make in
+ make.leading.trailing.equalToSuperview().inset(10)
+ make.centerY.equalToSuperview()
+ }
+ addSubview(tryNowView)
+ tryNowView.snp.makeConstraints { make in
+ make.leading.equalTo(titleLabel)
+ make.top.equalToSuperview().offset(65)
+ make.height.equalTo(24)
+ }
+
+ addTapGesture { _ in
+ UIDevice.generateHaptic()
+ BitBopKit.openBitBop()
+ }
+ }
+
+ @MainActor required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+}
diff --git a/ManicEmu/ManicEmu/Sources/Tools/Extensions/GameTypeExtensions.swift b/ManicEmu/ManicEmu/Sources/Tools/Extensions/GameTypeExtensions.swift
index 4c06aac7..d00c5f3d 100644
--- a/ManicEmu/ManicEmu/Sources/Tools/Extensions/GameTypeExtensions.swift
+++ b/ManicEmu/ManicEmu/Sources/Tools/Extensions/GameTypeExtensions.swift
@@ -913,6 +913,21 @@ extension GameType {
}
return []
}
+
+ var supportBitBop: Bool {
+ if self == .ds ||
+ self == .md ||
+ self == .n64 ||
+ self == .nes ||
+ self == .snes ||
+ self == .gb ||
+ self == .gbc ||
+ self == .gba ||
+ self == .vb {
+ return true
+ }
+ return false
+ }
}
///让GameType支持realm的存储
diff --git a/ManicEmu/ManicEmu/Sources/Tools/Extensions/UIViewExtensions.swift b/ManicEmu/ManicEmu/Sources/Tools/Extensions/UIViewExtensions.swift
index 7c8bdffa..e7c0a9a6 100644
--- a/ManicEmu/ManicEmu/Sources/Tools/Extensions/UIViewExtensions.swift
+++ b/ManicEmu/ManicEmu/Sources/Tools/Extensions/UIViewExtensions.swift
@@ -277,7 +277,9 @@ extension UIView {
detail: String,
detailAlignment: NSTextAlignment = .center,
cancelTitle: String = R.string.localizable.cancelTitle(),
+ cancelTitleColor: UIColor = R.Color.LabelSecondary,
confirmTitle: String? = nil,
+ confirmTitleColor: UIColor = R.Color.Main,
confirmAutoHide: Bool = true,
enableForceHide: Bool = true,
cancelAction: (()->Void)? = nil,
@@ -291,7 +293,9 @@ extension UIView {
detail: detail,
detailAlignment: detailAlignment,
buttonTitle: cancelTitle,
- destructiveButtonTitle: confirmTitle),
+ buttonTitleColor: cancelTitleColor,
+ destructiveButtonTitle: confirmTitle,
+ destructiveButtonTitleColor: confirmTitleColor),
enableGrabber: enableForceHide,
enableTapBackgroundDismiss: enableForceHide)
let enableMultiInstance = identifier == nil
diff --git a/ManicEmu/ManicEmu/Sources/Tools/Others/BitBopKit.swift b/ManicEmu/ManicEmu/Sources/Tools/Others/BitBopKit.swift
new file mode 100644
index 00000000..6194bca6
--- /dev/null
+++ b/ManicEmu/ManicEmu/Sources/Tools/Others/BitBopKit.swift
@@ -0,0 +1,544 @@
+//
+// BitBopKit.swift
+// ManicEmu
+//
+// Created by Daiuno on 2026/10/27.
+// Copyright © 2026 Manic EMU. All rights reserved.
+//
+
+import CryptoKit
+
+struct BitBopKit {
+ /// Entitlement id shared with BitBop. Distinct from `R.DefaultKey.AppGroupName`, which only keys UserDefaults.
+ private static let appGroupIdentifier = "group.aoshuang.manicemu"
+ private static let importDirectoryName = "Import"
+ private static let launchURL = URL(string: "bitbop://import")!
+ /// Opens BitBop without starting an import. `bitbop://library` is ignored by BitBop's handoff route.
+ private static let openURL = URL(string: "bitbop://library")!
+ private static let stateLock = NSLock()
+ private static var supportCache: CachedSupport?
+ private static var libraryCache: CachedLibrary?
+ private static var digestCache: [String: CachedDigest] = [:]
+ private static let stagingQueue = DispatchQueue(label: "com.aoshuang.manicemu.bitbop", qos: .userInitiated)
+ /// Touched only on the main thread, so a second tap cannot replace Import while the first copy is in flight.
+ private static var isSending = false
+
+ private enum StageError: Error {
+ case missingContainer
+ case noRom
+ }
+
+ private enum HandoffChoice {
+ case unsupported
+ case send([(source: URL, fileName: String)])
+ }
+
+ /// App Store builds copy into the shared Import folder, then open BitBop. Sideload builds have no App Group, so the user picks BitBop in the share sheet. Opens the App Store when BitBop cannot be launched.
+ static func sendToBitBop(games: [Game], in scene: UIWindowScene?) {
+ let supported = games.filter { $0.gameType.supportBitBop }
+ guard !supported.isEmpty else { return }
+
+ guard UIApplication.shared.canOpenURL(launchURL) else {
+ UIApplication.shared.open(R.URLs.BitBopStoreUrl)
+ return
+ }
+
+ // Capture paths and names on the caller thread. Realm objects must not be read from the staging queue.
+ let roms = supported.compactMap { game -> (source: URL, fileName: String, gameType: GameType)? in
+ let url = game.romUrl
+ guard url.isFileURL, FileManager.default.fileExists(atPath: url.path) else { return nil }
+ let fileName = game.fileName
+ guard !fileName.isEmpty else { return nil }
+ return (url, fileName, game.gameType)
+ }
+ guard !roms.isEmpty else {
+ UIView.makeToast(message: R.string.localizable.bitBopSendFailed())
+ return
+ }
+ guard !isSending else { return }
+ isSending = true
+ UIView.makeLoading()
+
+ stagingQueue.async {
+ switch handoffChoice(for: roms) {
+ case .unsupported:
+ DispatchQueue.main.async {
+ isSending = false
+ UIView.hideLoading {
+ UIView.makeToast(message: R.string.localizable.bitBopTracksUnavailable())
+ }
+ }
+ case .send(let ready):
+#if SIDE_LOAD
+ let readyPaths = Set(ready.map(\.source.path))
+ DispatchQueue.main.async {
+ isSending = false
+ UIView.hideLoading {
+ let shareable = supported.filter { readyPaths.contains($0.romUrl.path) }
+ ShareManager.shareFiles(games: shareable, shareFileType: .rom, in: scene)
+ }
+ }
+#else
+ let result = Result { try stageRoms(ready) }
+ DispatchQueue.main.async {
+ isSending = false
+ UIView.hideLoading {
+ switch result {
+ case .success:
+ UIApplication.shared.open(launchURL, options: [:]) { success in
+ guard !success else { return }
+ DispatchQueue.main.async {
+ UIApplication.shared.open(R.URLs.BitBopStoreUrl)
+ }
+ }
+ case .failure(let error):
+ Log.error("BitBop import staging failed: \(error)")
+ UIView.makeToast(message: R.string.localizable.bitBopSendFailed())
+ }
+ }
+ }
+#endif
+ }
+ }
+ }
+
+ /// GB, GBC, and GBA can still be scanned without a catalog hit. Other platforms need `support.bbix`; a missing file falls back to sending.
+ private static func handoffChoice(for roms: [(source: URL, fileName: String, gameType: GameType)]) -> HandoffChoice {
+#if SIDE_LOAD
+ // Sideload builds cannot read the App Group indexes. Treat them as missing and share every captured ROM.
+ return .send(roms.map { ($0.source, $0.fileName) })
+#else
+ let needsCatalog = roms.contains { !canScanWithoutCatalog($0.gameType) }
+ let catalog = needsCatalog ? supportTable() : nil
+ if needsCatalog && catalog == nil {
+ return .send(roms.map { ($0.source, $0.fileName) })
+ }
+ var ready: [(source: URL, fileName: String)] = []
+ for rom in roms {
+ if canScanWithoutCatalog(rom.gameType) {
+ ready.append((rom.source, rom.fileName))
+ continue
+ }
+ guard let catalog, let digest = fileDigest(at: rom.source), catalog.contains(digest) else { continue }
+ ready.append((rom.source, rom.fileName))
+ }
+ return ready.isEmpty ? .unsupported : .send(ready)
+#endif
+ }
+
+ private static func canScanWithoutCatalog(_ gameType: GameType) -> Bool {
+ gameType == .gb || gameType == .gbc || gameType == .gba
+ }
+
+ /// Replaces Import so BitBop receives only this selection.
+ /// Destination name is `game.fileName`. A numeric suffix is added only when that name is already used in this batch.
+ private static func stageRoms(_ roms: [(source: URL, fileName: String)]) throws {
+ guard let container = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier) else {
+ throw StageError.missingContainer
+ }
+ let importDirectory = container.appendingPathComponent(importDirectoryName, isDirectory: true)
+ if FileManager.default.fileExists(atPath: importDirectory.path) {
+ try FileManager.safeRemoveItem(at: importDirectory)
+ }
+ try FileManager.default.createDirectory(at: importDirectory, withIntermediateDirectories: true)
+
+ var usedNames = Set<String>()
+ var copied = 0
+ for rom in roms {
+ let name = uniqueFileName(rom.fileName, usedNames: &usedNames)
+ let destination = importDirectory.appendingPathComponent(name)
+ try FileManager.safeCopyItem(at: rom.source, to: destination, shouldReplace: true)
+ copied += 1
+ }
+ guard copied > 0 else { throw StageError.noRom }
+ }
+
+ private static func uniqueFileName(_ preferred: String, usedNames: inout Set<String>) -> String {
+ if !usedNames.contains(preferred) {
+ usedNames.insert(preferred)
+ return preferred
+ }
+ let fileURL = URL(fileURLWithPath: preferred)
+ let base = fileURL.deletingPathExtension().lastPathComponent
+ let ext = fileURL.pathExtension
+ var index = 2
+ var name = preferred
+ repeat {
+ name = ext.isEmpty ? "\(base)-\(index)" : "\(base)-\(index).\(ext)"
+ index += 1
+ } while usedNames.contains(name)
+ usedNames.insert(name)
+ return name
+ }
+
+ /// What the game-info cover button should do. `supportBitBop` stays a platform check; this reads the shared indexes for one ROM.
+ enum CoverOffer {
+ case hidden
+ /// `scansCartridge` is a GB, GBC, or GBA revision that is absent from a readable support table.
+ case send(scansCartridge: Bool)
+ case open(LibraryAlbum)
+
+ var showsButton: Bool {
+ if case .hidden = self { return false }
+ return true
+ }
+ }
+
+ struct LibraryAlbum {
+ var title: String
+ var artist: String
+ var system: String
+ var hasSoundtrack: Bool
+ var trackTitles: [String]
+ }
+
+ /// `canOpenURL` must run on the main thread. Both launch URLs share the `bitbop` scheme.
+ static var isBitBopInstalled: Bool {
+ UIApplication.shared.canOpenURL(openURL)
+ }
+
+ /// Platform gate first. Sideload builds and a missing BitBop install skip both index files.
+ static func prepareCoverOffer(gameType: GameType, romURL: URL, bitbopInstalled: Bool) -> CoverOffer {
+ guard gameType.supportBitBop else { return .hidden }
+#if SIDE_LOAD
+ _ = bitbopInstalled
+ return .send(scansCartridge: false)
+#else
+ guard bitbopInstalled else { return .send(scansCartridge: false) }
+ let digest = fileDigest(at: romURL)
+ if let digest, let album = libraryIndex()?.albums[digest] { return .open(album) }
+ if let support = supportTable(), let digest {
+ let hit = support.contains(digest)
+ let canScanWithoutAHit = gameType == .gb || gameType == .gbc || gameType == .gba
+ if !hit && !canScanWithoutAHit { return .hidden }
+ return .send(scansCartridge: !hit && canScanWithoutAHit)
+ }
+ return .send(scansCartridge: false)
+#endif
+ }
+
+ static func presentCoverOffer(_ offer: CoverOffer, for game: Game, in scene: UIWindowScene?) {
+ switch offer {
+ case .hidden:
+ return
+ case .send(let scansCartridge):
+ UIView.makeAlert(title: R.string.localizable.bitBopListenTitle(),
+ detail: scansCartridge ? R.string.localizable.bitBopScanRom() : R.string.localizable.bitBopParseRom(),
+ detailAlignment: .left,
+ cancelTitle: R.string.localizable.listenWithBitBop(),
+ cancelTitleColor: R.Color.Red,
+ cancelAction: { sendToBitBop(games: [game], in: scene) })
+ case .open(let album):
+ UIView.makeAlert(title: R.string.localizable.bitBopListenTitle(),
+ detail: albumDetail(album, fallbackTitle: game.displayName),
+ detailAlignment: .left,
+ cancelTitle: R.string.localizable.listenWithBitBop(),
+ cancelTitleColor: R.Color.Red,
+ cancelAction: { openBitBop() })
+ }
+ }
+
+ /// Brings BitBop forward. Does not copy a ROM and does not open `bitbop://import`.
+ static func openBitBop() {
+ guard UIApplication.shared.canOpenURL(openURL) else {
+ UIApplication.shared.open(R.URLs.BitBopStoreUrl)
+ return
+ }
+ UIApplication.shared.open(openURL, options: [:]) { success in
+ guard !success else { return }
+ DispatchQueue.main.async {
+ UIApplication.shared.open(R.URLs.BitBopStoreUrl)
+ }
+ }
+ }
+
+ private static func albumDetail(_ album: LibraryAlbum, fallbackTitle: String) -> String {
+ let title = album.title.isEmpty ? fallbackTitle : album.title
+ guard album.hasSoundtrack else {
+ return R.string.localizable.bitBopAlbumQuiet(title)
+ }
+ var lines: [String] = []
+ if !album.artist.isEmpty { lines.append(album.artist) }
+ if !album.system.isEmpty { lines.append(album.system) }
+ if !album.trackTitles.isEmpty {
+ lines.append(R.string.localizable.bitBopTrackCount(album.trackTitles.count))
+ }
+ var detail = R.string.localizable.bitBopAlbumReady(title)
+ if !lines.isEmpty {
+ detail += "\n\n" + lines.joined(separator: "\n")
+ }
+ // Match the list punctuation to the language of the preview sentence.
+ let separator = (Bundle.main.preferredLocalizations.first ?? "").hasPrefix("zh") ? "、" : ", "
+ let preview = album.trackTitles.prefix(3).filter { !$0.isEmpty }.joined(separator: separator)
+ if !preview.isEmpty {
+ detail += "\n\n" + R.string.localizable.bitBopAlbumTrackPreview(preview)
+ }
+ return detail
+ }
+
+ private static func fileURL(_ name: String) -> URL? {
+ FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier)?
+ .appendingPathComponent("BitBop", isDirectory: true)
+ .appendingPathComponent(name)
+ }
+
+ private static func supportTable() -> SupportTable? {
+ guard let url = fileURL("support.bbix"), let stamp = fileStamp(of: url) else { return nil }
+ if let cached = locked({ supportCache }),
+ cached.stamp == stamp,
+ cached.generation == headerGeneration(of: url),
+ cached.appVersion == headerAppVersion(of: url) {
+ return cached.table
+ }
+ guard let data = try? Data(contentsOf: url), let table = SupportTable(data: data) else {
+ return locked { supportCache?.table }
+ }
+ locked {
+ supportCache = CachedSupport(stamp: stamp, generation: table.generation, appVersion: table.appVersion, table: table)
+ }
+ return table
+ }
+
+ private static func libraryIndex() -> LibraryIndex? {
+ guard let url = fileURL("library.bbix"), let stamp = fileStamp(of: url) else { return nil }
+ if let cached = locked({ libraryCache }),
+ cached.stamp == stamp,
+ cached.generation == headerGeneration(of: url) {
+ return cached.index
+ }
+ guard let data = try? Data(contentsOf: url), let index = LibraryIndex(data: data) else {
+ return locked { libraryCache?.index }
+ }
+ locked {
+ libraryCache = CachedLibrary(stamp: stamp, generation: index.generation, index: index)
+ }
+ return index
+ }
+
+ /// Whole-file MD5, cached by path, size, and modification time. This is the expensive part, not parsing the index.
+ private static func fileDigest(at url: URL) -> Data? {
+ guard url.isFileURL else { return nil }
+ guard let attributes = try? FileManager.default.attributesOfItem(atPath: url.path),
+ let modified = attributes[.modificationDate] as? Date else { return nil }
+ let size: UInt64
+ if let number = attributes[.size] as? NSNumber {
+ size = number.uint64Value
+ } else if let value = attributes[.size] as? UInt64 {
+ size = value
+ } else {
+ return nil
+ }
+ if let cached = locked({ digestCache[url.path] }), cached.size == size, cached.modified == modified {
+ return cached.digest
+ }
+ guard let handle = try? FileHandle(forReadingFrom: url) else { return nil }
+ defer { try? handle.close() }
+ var hasher = Insecure.MD5()
+ while true {
+ let chunk = handle.readData(ofLength: 1024 * 1024)
+ if chunk.isEmpty { break }
+ hasher.update(data: chunk)
+ }
+ let digest = Data(hasher.finalize())
+ locked { digestCache[url.path] = CachedDigest(size: size, modified: modified, digest: digest) }
+ return digest
+ }
+
+ private static func fileStamp(of url: URL) -> FileStamp? {
+ guard let values = try? url.resourceValues(forKeys: [.fileSizeKey, .contentModificationDateKey, .isRegularFileKey]),
+ values.isRegularFile == true,
+ let size = values.fileSize,
+ let modified = values.contentModificationDate else { return nil }
+ return FileStamp(size: size, modified: modified.timeIntervalSince1970)
+ }
+
+ private static func headerGeneration(of url: URL) -> UInt32? {
+ guard let handle = try? FileHandle(forReadingFrom: url) else { return nil }
+ defer { try? handle.close() }
+ guard let header = try? handle.read(upToCount: 16), header.count >= 16 else { return nil }
+ return Cursor(data: header).uint32(at: 12)
+ }
+
+ private static func headerAppVersion(of url: URL) -> String? {
+ guard let handle = try? FileHandle(forReadingFrom: url) else { return nil }
+ defer { try? handle.close() }
+ guard let header = try? handle.read(upToCount: 64), header.count >= 64 else { return nil }
+ return Cursor(data: header).appVersion(at: 16, length: 48)
+ }
+
+ private static func locked<T>(_ body: () -> T) -> T {
+ stateLock.lock()
+ defer { stateLock.unlock() }
+ return body()
+ }
+}
+
+private struct FileStamp: Equatable {
+ var size: Int
+ var modified: TimeInterval
+}
+
+private struct CachedDigest {
+ var size: UInt64
+ var modified: Date
+ var digest: Data
+}
+
+private struct CachedSupport {
+ var stamp: FileStamp
+ var generation: UInt32
+ var appVersion: String
+ var table: SupportTable
+}
+
+private struct CachedLibrary {
+ var stamp: FileStamp
+ var generation: UInt32
+ var index: LibraryIndex
+}
+
+private struct SupportTable {
+ var generation: UInt32
+ var appVersion: String
+ var hashes: Data
+
+ init?(data: Data) {
+ let cursor = Cursor(data: data)
+ guard data.count >= 64,
+ cursor.ascii(at: 0, equals: "BBIX"),
+ cursor.uint16(at: 4) == UInt16(2),
+ cursor.uint16(at: 6) == UInt16(64),
+ let countValue = cursor.uint32(at: 8),
+ let generation = cursor.uint32(at: 12) else { return nil }
+ let count = Int(countValue)
+ guard count >= 1, data.count == 64 + count * 16 else { return nil }
+ self.generation = generation
+ appVersion = cursor.appVersion(at: 16, length: 48)
+ hashes = data.subdata(in: 64..<data.count)
+ guard Self.isStrictlySorted(hashes, count: count) else { return nil }
+ }
+
+ func contains(_ digest: Data) -> Bool {
+ guard digest.count == 16 else { return false }
+ let count = hashes.count / 16
+ return digest.withUnsafeBytes { digestBytes in
+ hashes.withUnsafeBytes { hashBytes in
+ guard let digestBase = digestBytes.bindMemory(to: UInt8.self).baseAddress,
+ let hashBase = hashBytes.bindMemory(to: UInt8.self).baseAddress else { return false }
+ var lo = 0
+ var hi = count
+ while lo < hi {
+ let mid = (lo + hi) / 2
+ let compared = memcmp(hashBase + mid * 16, digestBase, 16)
+ if compared == 0 { return true }
+ if compared < 0 { lo = mid + 1 } else { hi = mid }
+ }
+ return false
+ }
+ }
+ }
+
+ private static func isStrictlySorted(_ hashes: Data, count: Int) -> Bool {
+ guard count > 1 else { return count == 1 }
+ return hashes.withUnsafeBytes { raw in
+ guard let base = raw.bindMemory(to: UInt8.self).baseAddress else { return false }
+ for index in 1..<count {
+ if memcmp(base + (index - 1) * 16, base + index * 16, 16) >= 0 { return false }
+ }
+ return true
+ }
+ }
+}
+
+private struct LibraryIndex {
+ var generation: UInt32
+ var albums: [Data: BitBopKit.LibraryAlbum]
+
+ init?(data: Data) {
+ var cursor = Cursor(data: data)
+ guard data.count >= 32,
+ cursor.ascii(at: 0, equals: "BBLB"),
+ cursor.uint16(at: 4) == UInt16(1),
+ cursor.uint16(at: 6) == UInt16(32),
+ let countValue = cursor.uint32(at: 8),
+ let generation = cursor.uint32(at: 12),
+ let payloadValue = cursor.uint32(at: 16) else { return nil }
+ let count = Int(countValue)
+ self.generation = generation
+ let payloadBytes = Int(payloadValue)
+ guard data.count == 32 + payloadBytes else { return nil }
+ cursor.index = 32
+ var albums: [Data: BitBopKit.LibraryAlbum] = [:]
+ for _ in 0..<count {
+ guard let record = cursor.album() else { return nil }
+ albums[record.md5] = record.album
+ }
+ guard cursor.index == data.count else { return nil }
+ self.albums = albums
+ }
+}
+
+private struct Cursor {
+ let data: Data
+ var index = 0
+
+ func ascii(at offset: Int, equals text: String) -> Bool {
+ guard let bytes = bytes(at: offset, count: text.utf8.count) else { return false }
+ return bytes == Data(text.utf8)
+ }
+
+ func uint16(at offset: Int) -> UInt16? {
+ guard offset >= 0, offset + 2 <= data.count else { return nil }
+ return UInt16(data[offset]) | (UInt16(data[offset + 1]) << 8)
+ }
+
+ func uint32(at offset: Int) -> UInt32? {
+ guard offset >= 0, offset + 4 <= data.count else { return nil }
+ return UInt32(data[offset])
+ | (UInt32(data[offset + 1]) << 8)
+ | (UInt32(data[offset + 2]) << 16)
+ | (UInt32(data[offset + 3]) << 24)
+ }
+
+ func appVersion(at offset: Int, length: Int) -> String {
+ guard let bytes = bytes(at: offset, count: length) else { return "" }
+ let end = bytes.firstIndex(of: 0) ?? bytes.endIndex
+ return String(data: bytes.prefix(upTo: end), encoding: .utf8) ?? ""
+ }
+
+ mutating func album() -> (md5: Data, album: BitBopKit.LibraryAlbum)? {
+ guard let md5 = take(16),
+ let flags = take(1)?.first,
+ take(1) != nil,
+ let trackCountBytes = take(2),
+ let title = takeString(),
+ let artist = takeString(),
+ let system = takeString() else { return nil }
+ let trackCount = Int(UInt16(trackCountBytes[0]) | (UInt16(trackCountBytes[1]) << 8))
+ var titles: [String] = []
+ titles.reserveCapacity(trackCount)
+ for _ in 0..<trackCount {
+ guard take(2) != nil, take(4) != nil, take(1) != nil, let trackTitle = takeString() else { return nil }
+ titles.append(trackTitle)
+ }
+ return (md5, .init(title: title, artist: artist, system: system, hasSoundtrack: flags & 1 == 1, trackTitles: titles))
+ }
+
+ private mutating func takeString() -> String? {
+ guard let lengthBytes = take(2) else { return nil }
+ let length = Int(UInt16(lengthBytes[0]) | (UInt16(lengthBytes[1]) << 8))
+ guard let bytes = take(length) else { return nil }
+ return String(data: bytes, encoding: .utf8) ?? ""
+ }
+
+ private mutating func take(_ count: Int) -> Data? {
+ guard let bytes = bytes(at: index, count: count) else { return nil }
+ index += count
+ return bytes
+ }
+
+ private func bytes(at offset: Int, count: Int) -> Data? {
+ guard offset >= 0, count >= 0, offset + count <= data.count else { return nil }
+ return data.subdata(in: offset..<(offset + count))
+ }
+}