From e374fa306bfc5b5792178e21c8ff9a1ac221c5b9 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Fri, 31 May 2024 23:36:54 +0900 Subject: [PATCH] feat(YouTube Music): remove `Replace Cast button` patch https://github.com/inotia00/ReVanced_Extended/issues/2101 --- .../player/replace/ReplaceCastButtonPatch.kt | 109 ------------------ .../CastButtonContainerFingerprint.kt | 9 -- .../playerresponse/PlayerResponsePatch.kt | 45 -------- .../PlaybackStartDescriptorFingerprint.kt | 31 ----- .../utils/resourceid/SharedResourceIdPatch.kt | 2 - ...PlayerGestureConfigSyntheticFingerprint.kt | 4 +- .../music/cast/layout/open_music_button.xml | 5 - .../music/settings/host/values/strings.xml | 7 -- 8 files changed, 2 insertions(+), 210 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/music/player/replace/ReplaceCastButtonPatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/music/player/replace/fingerprints/CastButtonContainerFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/music/utils/playerresponse/PlayerResponsePatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/music/utils/playerresponse/fingerprints/PlaybackStartDescriptorFingerprint.kt delete mode 100644 src/main/resources/music/cast/layout/open_music_button.xml diff --git a/src/main/kotlin/app/revanced/patches/music/player/replace/ReplaceCastButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/replace/ReplaceCastButtonPatch.kt deleted file mode 100644 index 3b54565c1..000000000 --- a/src/main/kotlin/app/revanced/patches/music/player/replace/ReplaceCastButtonPatch.kt +++ /dev/null @@ -1,109 +0,0 @@ -package app.revanced.patches.music.player.replace - -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstruction -import app.revanced.patcher.extensions.InstructionExtensions.getInstruction -import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction -import app.revanced.patches.music.player.replace.fingerprints.CastButtonContainerFingerprint -import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE -import app.revanced.patches.music.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR -import app.revanced.patches.music.utils.integrations.Constants.UTILS_PATH -import app.revanced.patches.music.utils.mainactivity.MainActivityResolvePatch -import app.revanced.patches.music.utils.mainactivity.MainActivityResolvePatch.mainActivityMutableClass -import app.revanced.patches.music.utils.playerresponse.PlayerResponsePatch -import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch -import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.PlayerCastMediaRouteButton -import app.revanced.patches.music.utils.settings.CategoryType -import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.patches.music.utils.settings.SettingsPatch.contexts -import app.revanced.patches.music.utils.videotype.VideoTypeHookPatch -import app.revanced.util.ResourceGroup -import app.revanced.util.copyResources -import app.revanced.util.getWideLiteralInstructionIndex -import app.revanced.util.patch.BaseBytecodePatch -import app.revanced.util.resultOrThrow -import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction -import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction -import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction -import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c -import com.android.tools.smali.dexlib2.iface.reference.MethodReference - -@Suppress("unused") -object ReplaceCastButtonPatch : BaseBytecodePatch( - name = "Replace Cast button", - description = "Adds an option to replace the Cast button in the player with an Open music button.", - dependencies = setOf( - MainActivityResolvePatch::class, - PlayerResponsePatch::class, - SettingsPatch::class, - SharedResourceIdPatch::class, - VideoTypeHookPatch::class - ), - compatiblePackages = COMPATIBLE_PACKAGE, - use = false -) { - override fun execute(context: BytecodeContext) { - CastButtonContainerFingerprint.resolve(context, mainActivityMutableClass) - - CastButtonContainerFingerprint.resultOrThrow().let { - it.mutableMethod.apply { - val freeIndex = getWideLiteralInstructionIndex(PlayerCastMediaRouteButton) + 1 - val freeRegister = getInstruction(freeIndex).registerA - - val getActivityIndex = freeIndex - 4 - val getActivityRegister = - getInstruction(getActivityIndex).registerB - val getActivityReference = - getInstruction(getActivityIndex).reference - - for (index in freeIndex + 20 downTo freeIndex) { - if (getInstruction(index).opcode != Opcode.INVOKE_VIRTUAL) - continue - - if ((getInstruction(index).reference as MethodReference).name != "addView") - continue - - val viewGroupInstruction = getInstruction(index) - - addInstruction( - index + 1, - "invoke-static {v$freeRegister, v${viewGroupInstruction.registerC}, v${viewGroupInstruction.registerD}}, " + - PLAYER_CLASS_DESCRIPTOR + - "->" + - "replaceCastButton(Landroid/app/Activity;Landroid/view/ViewGroup;Landroid/view/View;)V" - ) - addInstruction( - index + 1, - "iget-object v$freeRegister, v$getActivityRegister, $getActivityReference" - ) - removeInstruction(index) - - break - } - } - } - - PlayerResponsePatch.injectPlaylistCall( - "$UTILS_PATH/CheckMusicVideoPatch;" + - "->" + - "playbackStart(Ljava/lang/String;Ljava/lang/String;IZ)V" - ) - - arrayOf( - ResourceGroup( - "layout", - "open_music_button.xml" - ) - ).forEach { resourceGroup -> - contexts.copyResources("music/cast", resourceGroup) - } - - SettingsPatch.addSwitchPreference( - CategoryType.PLAYER, - "revanced_replace_player_cast_button", - "false" - ) - - } -} diff --git a/src/main/kotlin/app/revanced/patches/music/player/replace/fingerprints/CastButtonContainerFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/player/replace/fingerprints/CastButtonContainerFingerprint.kt deleted file mode 100644 index 8a40da7da..000000000 --- a/src/main/kotlin/app/revanced/patches/music/player/replace/fingerprints/CastButtonContainerFingerprint.kt +++ /dev/null @@ -1,9 +0,0 @@ -package app.revanced.patches.music.player.replace.fingerprints - -import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.PlayerCastMediaRouteButton -import app.revanced.util.fingerprint.LiteralValueFingerprint - -internal object CastButtonContainerFingerprint : LiteralValueFingerprint( - returnType = "V", - literalSupplier = { PlayerCastMediaRouteButton } -) diff --git a/src/main/kotlin/app/revanced/patches/music/utils/playerresponse/PlayerResponsePatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/playerresponse/PlayerResponsePatch.kt deleted file mode 100644 index ad57dea5d..000000000 --- a/src/main/kotlin/app/revanced/patches/music/utils/playerresponse/PlayerResponsePatch.kt +++ /dev/null @@ -1,45 +0,0 @@ -package app.revanced.patches.music.utils.playerresponse - -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructions -import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod -import app.revanced.patches.music.utils.playerresponse.fingerprints.PlaybackStartDescriptorFingerprint -import app.revanced.util.resultOrThrow - -object PlayerResponsePatch : BytecodePatch( - setOf(PlaybackStartDescriptorFingerprint) -) { - private const val VIDEO_ID_PARAMETER = 1 - private const val PLAYLIST_ID_PARAMETER = 4 - private const val PLAYLIST_INDEX_PARAMETER = 5 - private const val VIDEO_IS_OPENING_OR_PLAYING_PARAMETER = 12 - - private lateinit var insertMethod: MutableMethod - - internal fun injectCall( - methodDescriptor: String - ) { - insertMethod.addInstructions( - 0, // move-result-object offset - "invoke-static {p$VIDEO_ID_PARAMETER, p$VIDEO_IS_OPENING_OR_PLAYING_PARAMETER}, $methodDescriptor" - ) - } - - internal fun injectPlaylistCall( - methodDescriptor: String - ) { - insertMethod.addInstructions( - 0, // move-result-object offset - "invoke-static {p$VIDEO_ID_PARAMETER, p$PLAYLIST_ID_PARAMETER, p$PLAYLIST_INDEX_PARAMETER, p$VIDEO_IS_OPENING_OR_PLAYING_PARAMETER}, $methodDescriptor" - ) - } - - override fun execute(context: BytecodeContext) { - - insertMethod = PlaybackStartDescriptorFingerprint.resultOrThrow().mutableMethod - - } - -} - diff --git a/src/main/kotlin/app/revanced/patches/music/utils/playerresponse/fingerprints/PlaybackStartDescriptorFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/utils/playerresponse/fingerprints/PlaybackStartDescriptorFingerprint.kt deleted file mode 100644 index 1a66e47e8..000000000 --- a/src/main/kotlin/app/revanced/patches/music/utils/playerresponse/fingerprints/PlaybackStartDescriptorFingerprint.kt +++ /dev/null @@ -1,31 +0,0 @@ -package app.revanced.patches.music.utils.playerresponse.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.MethodFingerprint -import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode - -internal object PlaybackStartDescriptorFingerprint : MethodFingerprint( - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - returnType = "L", - parameters = listOf( - "Ljava/lang/String;", - "[B", - "Ljava/lang/String;", - "Ljava/lang/String;", - "I", - "I", - "Ljava/util/Set;", - "Ljava/lang/String;", - "Ljava/lang/String;", - "L", - "Z", - "Z" - ), - opcodes = listOf( - Opcode.INVOKE_INTERFACE, - Opcode.MOVE_RESULT_OBJECT, - Opcode.CHECK_CAST, - Opcode.INVOKE_INTERFACE - ) -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt index 149bc0d49..71779e866 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt @@ -38,7 +38,6 @@ object SharedResourceIdPatch : ResourcePatch() { var MusicTasteBuilderShelf = -1L var NamesInactiveAccountThumbnailSize = -1L var OfflineSettingsMenuItem = -1L - var PlayerCastMediaRouteButton = -1L var PlayerOverlayChip = -1L var PrivacyTosFooter = -1L var QualityAuto = -1L @@ -79,7 +78,6 @@ object SharedResourceIdPatch : ResourcePatch() { MusicTasteBuilderShelf = getId(LAYOUT, "music_tastebuilder_shelf") NamesInactiveAccountThumbnailSize = getId(DIMEN, "names_inactive_account_thumbnail_size") OfflineSettingsMenuItem = getId(ID, "offline_settings_menu_item") - PlayerCastMediaRouteButton = getId(LAYOUT, "player_cast_media_route_button") PlayerOverlayChip = getId(ID, "player_overlay_chip") PrivacyTosFooter = getId(ID, "privacy_tos_footer") QualityAuto = getId(STRING, "quality_auto") diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/client/fingerprints/PlayerGestureConfigSyntheticFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/client/fingerprints/PlayerGestureConfigSyntheticFingerprint.kt index 0e50596bf..1671e1a8c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/client/fingerprints/PlayerGestureConfigSyntheticFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/client/fingerprints/PlayerGestureConfigSyntheticFingerprint.kt @@ -42,9 +42,9 @@ internal object PlayerGestureConfigSyntheticFingerprint : MethodFingerprint( Opcode.RETURN_VOID, ), customFingerprint = { methodDef, classDef -> - indexOfDownAndOutAllowedInstruction(methodDef) > 0 && // This method is always called "a" because this kind of class always has a single method. - methodDef.name == "a" && classDef.methods.count() == 2 + methodDef.name == "a" && classDef.methods.count() == 2 && + indexOfDownAndOutAllowedInstruction(methodDef) >= 0 } ) { fun indexOfDownAndOutAllowedInstruction(methodDef: Method) = diff --git a/src/main/resources/music/cast/layout/open_music_button.xml b/src/main/resources/music/cast/layout/open_music_button.xml deleted file mode 100644 index 60d57d44e..000000000 --- a/src/main/resources/music/cast/layout/open_music_button.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index 668e84263..2f8e60541 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -246,13 +246,6 @@ This does not bypass the age restriction. It just accepts it automatically."Restore old player layout "Returns the player layout to the old style. Some features may not work properly in the old player layout." - Replace cast button - "Replaces the cast button in the player with an 'Open music' button, which opens the official audio instead of the music video. (Experimental) - -Info: This feature does not work normally if any songs in the playlist cannot be played." - Already playing from the official music source. - Official music source is unavailable. - Video