diff --git a/src/main/kotlin/app/revanced/patches/music/layout/oldstyleminiplayer/fingerprints/NextButtonVisibilityFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/layout/oldstyleminiplayer/fingerprints/NextButtonVisibilityFingerprint.kt new file mode 100644 index 000000000..6010eafcb --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/oldstyleminiplayer/fingerprints/NextButtonVisibilityFingerprint.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.music.layout.oldstyleminiplayer.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode +object NextButtonVisibilityFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf(), + opcodes = listOf( + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.CONST_16, + Opcode.IF_EQZ + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/layout/oldstyleminiplayer/fingerprints/SwipeToCloseFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/layout/oldstyleminiplayer/fingerprints/SwipeToCloseFingerprint.kt new file mode 100644 index 000000000..fdad35825 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/oldstyleminiplayer/fingerprints/SwipeToCloseFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.music.layout.oldstyleminiplayer.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.util.bytecode.isWide32LiteralExists + +object SwipeToCloseFingerprint : MethodFingerprint( + returnType = "Z", + parameters = listOf(), + customFingerprint = { it, _ -> it.isWide32LiteralExists(45398432) } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/layout/oldstyleminiplayer/patch/OldStyleMiniPlayerPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/oldstyleminiplayer/patch/OldStyleMiniPlayerPatch.kt new file mode 100644 index 000000000..6ccce974c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/oldstyleminiplayer/patch/OldStyleMiniPlayerPatch.kt @@ -0,0 +1,73 @@ +package app.revanced.patches.music.layout.oldstyleminiplayer.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.music.layout.oldstyleminiplayer.fingerprints.NextButtonVisibilityFingerprint +import app.revanced.patches.music.layout.oldstyleminiplayer.fingerprints.SwipeToCloseFingerprint +import app.revanced.patches.music.utils.settings.resource.patch.MusicSettingsPatch +import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility +import app.revanced.patches.shared.fingerprints.ColorMatchPlayerParentFingerprint +import app.revanced.util.enum.CategoryType +import app.revanced.util.integrations.Constants.MUSIC_LAYOUT +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch +@Name("enable-old-style-miniplayer") +@Description("Return the miniplayers to old style. (for YT Music v5.55.53+)") +@DependsOn([MusicSettingsPatch::class]) +@YouTubeMusicCompatibility +@Version("0.0.1") +class OldStyleMiniPlayerPatch : BytecodePatch( + listOf( + ColorMatchPlayerParentFingerprint, + SwipeToCloseFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + + ColorMatchPlayerParentFingerprint.result?.let { parentResult -> + NextButtonVisibilityFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { + it.mutableMethod.apply { + val targetIndex = it.scanResult.patternScanResult!!.startIndex + 1 + val targetRegister = getInstruction(targetIndex).registerA + + addInstructions( + targetIndex + 1, """ + invoke-static {v$targetRegister}, $MUSIC_LAYOUT->enableOldStyleMiniPlayer(Z)Z + move-result v$targetRegister + """ + ) + } + } ?: return NextButtonVisibilityFingerprint.toErrorResult() + } ?: return ColorMatchPlayerParentFingerprint.toErrorResult() + + SwipeToCloseFingerprint.result?.let { + it.mutableMethod.apply { + val insertIndex = implementation!!.instructions.size - 1 + val targetRegister = getInstruction(insertIndex).registerA + + addInstructions( + insertIndex, """ + invoke-static {v$targetRegister}, $MUSIC_LAYOUT->enableOldStyleMiniPlayer(Z)Z + move-result v$targetRegister + """ + ) + } + } ?: return SwipeToCloseFingerprint.toErrorResult() + + MusicSettingsPatch.addMusicPreference(CategoryType.LAYOUT, "revanced_enable_old_style_mini_player", "false") + + return PatchResultSuccess() + } +} \ No newline at end of file