mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-03 16:14:28 +02:00
feat(YouTube Music): remove Replace Cast button
patch https://github.com/inotia00/ReVanced_Extended/issues/2101
This commit is contained in:
parent
a71ce6b88c
commit
e374fa306b
@ -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<OneRegisterInstruction>(freeIndex).registerA
|
|
||||||
|
|
||||||
val getActivityIndex = freeIndex - 4
|
|
||||||
val getActivityRegister =
|
|
||||||
getInstruction<TwoRegisterInstruction>(getActivityIndex).registerB
|
|
||||||
val getActivityReference =
|
|
||||||
getInstruction<ReferenceInstruction>(getActivityIndex).reference
|
|
||||||
|
|
||||||
for (index in freeIndex + 20 downTo freeIndex) {
|
|
||||||
if (getInstruction(index).opcode != Opcode.INVOKE_VIRTUAL)
|
|
||||||
continue
|
|
||||||
|
|
||||||
if ((getInstruction<ReferenceInstruction>(index).reference as MethodReference).name != "addView")
|
|
||||||
continue
|
|
||||||
|
|
||||||
val viewGroupInstruction = getInstruction<Instruction35c>(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"
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -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 }
|
|
||||||
)
|
|
@ -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
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
)
|
|
||||||
)
|
|
@ -38,7 +38,6 @@ object SharedResourceIdPatch : ResourcePatch() {
|
|||||||
var MusicTasteBuilderShelf = -1L
|
var MusicTasteBuilderShelf = -1L
|
||||||
var NamesInactiveAccountThumbnailSize = -1L
|
var NamesInactiveAccountThumbnailSize = -1L
|
||||||
var OfflineSettingsMenuItem = -1L
|
var OfflineSettingsMenuItem = -1L
|
||||||
var PlayerCastMediaRouteButton = -1L
|
|
||||||
var PlayerOverlayChip = -1L
|
var PlayerOverlayChip = -1L
|
||||||
var PrivacyTosFooter = -1L
|
var PrivacyTosFooter = -1L
|
||||||
var QualityAuto = -1L
|
var QualityAuto = -1L
|
||||||
@ -79,7 +78,6 @@ object SharedResourceIdPatch : ResourcePatch() {
|
|||||||
MusicTasteBuilderShelf = getId(LAYOUT, "music_tastebuilder_shelf")
|
MusicTasteBuilderShelf = getId(LAYOUT, "music_tastebuilder_shelf")
|
||||||
NamesInactiveAccountThumbnailSize = getId(DIMEN, "names_inactive_account_thumbnail_size")
|
NamesInactiveAccountThumbnailSize = getId(DIMEN, "names_inactive_account_thumbnail_size")
|
||||||
OfflineSettingsMenuItem = getId(ID, "offline_settings_menu_item")
|
OfflineSettingsMenuItem = getId(ID, "offline_settings_menu_item")
|
||||||
PlayerCastMediaRouteButton = getId(LAYOUT, "player_cast_media_route_button")
|
|
||||||
PlayerOverlayChip = getId(ID, "player_overlay_chip")
|
PlayerOverlayChip = getId(ID, "player_overlay_chip")
|
||||||
PrivacyTosFooter = getId(ID, "privacy_tos_footer")
|
PrivacyTosFooter = getId(ID, "privacy_tos_footer")
|
||||||
QualityAuto = getId(STRING, "quality_auto")
|
QualityAuto = getId(STRING, "quality_auto")
|
||||||
|
@ -42,9 +42,9 @@ internal object PlayerGestureConfigSyntheticFingerprint : MethodFingerprint(
|
|||||||
Opcode.RETURN_VOID,
|
Opcode.RETURN_VOID,
|
||||||
),
|
),
|
||||||
customFingerprint = { methodDef, classDef ->
|
customFingerprint = { methodDef, classDef ->
|
||||||
indexOfDownAndOutAllowedInstruction(methodDef) > 0 &&
|
|
||||||
// This method is always called "a" because this kind of class always has a single method.
|
// 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) =
|
fun indexOfDownAndOutAllowedInstruction(methodDef: Method) =
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<com.google.android.libraries.youtube.common.ui.TouchImageView android:id="@+id/open_music_button" android:padding="@dimen/remix_overlay_player_control_button_padding" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/yt_fill_youtube_music_white_24" android:tint="@color/ytm_icon_color_active" android:contentDescription="@string/logo_button_accessibility" style="@style/MusicPlayerButton" />
|
|
||||||
</LinearLayout>
|
|
@ -246,13 +246,6 @@ This does not bypass the age restriction. It just accepts it automatically."</st
|
|||||||
<string name="revanced_restore_old_player_layout_title">Restore old player layout</string>
|
<string name="revanced_restore_old_player_layout_title">Restore old player layout</string>
|
||||||
<string name="revanced_restore_old_player_layout_summary">"Returns the player layout to the old style.
|
<string name="revanced_restore_old_player_layout_summary">"Returns the player layout to the old style.
|
||||||
Some features may not work properly in the old player layout."</string>
|
Some features may not work properly in the old player layout."</string>
|
||||||
<string name="revanced_replace_player_cast_button_title">Replace cast button</string>
|
|
||||||
<string name="revanced_replace_player_cast_button_summary">"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."</string>
|
|
||||||
<string name="revanced_replace_player_cast_button_playlist_dismiss">Already playing from the official music source.</string>
|
|
||||||
<string name="revanced_replace_player_cast_button_playlist_error">Official music source is unavailable.</string>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- PreferenceScreen: Video -->
|
<!-- PreferenceScreen: Video -->
|
||||||
<string name="revanced_preference_screen_video_title">Video</string>
|
<string name="revanced_preference_screen_video_title">Video</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user