From 650d0d9fffe12f52964a5a644d0ea48212c698de Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Mon, 2 Oct 2023 22:30:32 +0900 Subject: [PATCH] fix(music/enable-playback-speed): excluding enable playback speed patch still shows playback speed icon in the flyout menu --- .../hide/patch/FlyoutPanelPatch.kt | 4 +- .../playbackspeed/patch/PlaybackSpeedPatch.kt | 44 ++------------- .../FlyoutPanelLikeButtonFingerprint.kt | 2 +- .../patch/FlyoutButtonContainerPatch.kt | 53 +++++++++++++++++++ 4 files changed, 60 insertions(+), 43 deletions(-) rename src/main/kotlin/app/revanced/patches/music/{flyoutpanel/playbackspeed => utils/flyoutbutton}/fingerprints/FlyoutPanelLikeButtonFingerprint.kt (89%) create mode 100644 src/main/kotlin/app/revanced/patches/music/utils/flyoutbutton/patch/FlyoutButtonContainerPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/hide/patch/FlyoutPanelPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/hide/patch/FlyoutPanelPatch.kt index 47afb6ad7..09f62a945 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/hide/patch/FlyoutPanelPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/hide/patch/FlyoutPanelPatch.kt @@ -13,7 +13,7 @@ import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.music.flyoutpanel.utils.EnumUtils.getEnumIndex import app.revanced.patches.music.utils.annotations.MusicCompatibility import app.revanced.patches.music.utils.fingerprints.MenuItemFingerprint -import app.revanced.patches.music.utils.flyoutbutton.patch.FlyoutButtonContainerResourcePatch +import app.revanced.patches.music.utils.flyoutbutton.patch.FlyoutButtonContainerPatch import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch import app.revanced.util.enum.CategoryType import app.revanced.util.integrations.Constants.MUSIC_FLYOUT @@ -27,7 +27,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @Description("Hides flyout panel components.") @DependsOn( [ - FlyoutButtonContainerResourcePatch::class, + FlyoutButtonContainerPatch::class, SettingsPatch::class ] ) diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/playbackspeed/patch/PlaybackSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/playbackspeed/patch/PlaybackSpeedPatch.kt index 2e6a7f8c3..a179c37e2 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/playbackspeed/patch/PlaybackSpeedPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/playbackspeed/patch/PlaybackSpeedPatch.kt @@ -1,67 +1,31 @@ package app.revanced.patches.music.flyoutpanel.playbackspeed.patch -import app.revanced.extensions.exception import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstruction -import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.music.flyoutpanel.playbackspeed.fingerprints.FlyoutPanelLikeButtonFingerprint import app.revanced.patches.music.utils.annotations.MusicCompatibility -import app.revanced.patches.music.utils.flyoutbutton.patch.FlyoutButtonContainerResourcePatch +import app.revanced.patches.music.utils.flyoutbutton.patch.FlyoutButtonContainerPatch import app.revanced.patches.music.utils.overridespeed.patch.OverrideSpeedHookPatch -import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch -import app.revanced.util.bytecode.getWideLiteralIndex import app.revanced.util.enum.CategoryType -import app.revanced.util.integrations.Constants.MUSIC_FLYOUT -import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch @Name("Enable playback speed") @Description("Add playback speed button to the flyout panel.") @DependsOn( [ - FlyoutButtonContainerResourcePatch::class, + FlyoutButtonContainerPatch::class, OverrideSpeedHookPatch::class, - SettingsPatch::class, - SharedResourceIdPatch::class + SettingsPatch::class ] ) @MusicCompatibility -class PlaybackSpeedPatch : BytecodePatch( - listOf(FlyoutPanelLikeButtonFingerprint) -) { +class PlaybackSpeedPatch : BytecodePatch() { override fun execute(context: BytecodeContext) { - FlyoutPanelLikeButtonFingerprint.result?.let { - it.mutableMethod.apply { - val targetIndex = getWideLiteralIndex(SharedResourceIdPatch.MusicMenuLikeButtons) - - var insertIndex = -1 - - for (index in targetIndex until targetIndex + 5) { - if (getInstruction(index).opcode != Opcode.MOVE_RESULT_OBJECT) continue - - val register = getInstruction(index).registerA - insertIndex = index - - addInstruction( - index + 1, - "invoke-static {v$register}, $MUSIC_FLYOUT->setFlyoutButtonContainer(Landroid/view/View;)V" - ) - break - } - if (insertIndex == -1) - throw PatchException("Couldn't find target Index") - } - } ?: throw FlyoutPanelLikeButtonFingerprint.exception - SettingsPatch.addMusicPreference( CategoryType.FLYOUT, "revanced_enable_flyout_panel_playback_speed", diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/playbackspeed/fingerprints/FlyoutPanelLikeButtonFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/utils/flyoutbutton/fingerprints/FlyoutPanelLikeButtonFingerprint.kt similarity index 89% rename from src/main/kotlin/app/revanced/patches/music/flyoutpanel/playbackspeed/fingerprints/FlyoutPanelLikeButtonFingerprint.kt rename to src/main/kotlin/app/revanced/patches/music/utils/flyoutbutton/fingerprints/FlyoutPanelLikeButtonFingerprint.kt index 2e81b8b85..252be54bf 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/playbackspeed/fingerprints/FlyoutPanelLikeButtonFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/flyoutbutton/fingerprints/FlyoutPanelLikeButtonFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.music.flyoutpanel.playbackspeed.fingerprints +package app.revanced.patches.music.utils.flyoutbutton.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/music/utils/flyoutbutton/patch/FlyoutButtonContainerPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/flyoutbutton/patch/FlyoutButtonContainerPatch.kt new file mode 100644 index 000000000..5fb2c5738 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/utils/flyoutbutton/patch/FlyoutButtonContainerPatch.kt @@ -0,0 +1,53 @@ +package app.revanced.patches.music.utils.flyoutbutton.patch + +import app.revanced.extensions.exception +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchException +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patches.music.utils.flyoutbutton.fingerprints.FlyoutPanelLikeButtonFingerprint +import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch.Companion.MusicMenuLikeButtons +import app.revanced.util.bytecode.getWideLiteralIndex +import app.revanced.util.integrations.Constants.MUSIC_FLYOUT +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction + +@DependsOn( + [ + FlyoutButtonContainerResourcePatch::class, + SharedResourceIdPatch::class + ] +) +class FlyoutButtonContainerPatch : BytecodePatch( + listOf(FlyoutPanelLikeButtonFingerprint) +) { + override fun execute(context: BytecodeContext) { + + FlyoutPanelLikeButtonFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = getWideLiteralIndex(MusicMenuLikeButtons) + + var insertIndex = -1 + + for (index in targetIndex until targetIndex + 5) { + if (getInstruction(index).opcode != Opcode.MOVE_RESULT_OBJECT) continue + + val register = getInstruction(index).registerA + insertIndex = index + + addInstruction( + index + 1, + "invoke-static {v$register}, $MUSIC_FLYOUT->setFlyoutButtonContainer(Landroid/view/View;)V" + ) + break + } + if (insertIndex == -1) + throw PatchException("Couldn't find target Index") + } + } ?: throw FlyoutPanelLikeButtonFingerprint.exception + + } +} \ No newline at end of file