Skip to content

Commit

Permalink
feat(YouTube Music/Player components): add settings `Disable miniplay…
Browse files Browse the repository at this point in the history
…er gesture`, `Disable player gesture` inotia00/ReVanced_Extended#2097
  • Loading branch information
inotia00 committed Jul 30, 2024
1 parent 3277681 commit 25287b2
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import app.revanced.patches.music.player.components.fingerprints.OldEngagementPa
import app.revanced.patches.music.player.components.fingerprints.OldPlayerBackgroundFingerprint
import app.revanced.patches.music.player.components.fingerprints.OldPlayerLayoutFingerprint
import app.revanced.patches.music.player.components.fingerprints.PlayerPatchConstructorFingerprint
import app.revanced.patches.music.player.components.fingerprints.PlayerViewPagerConstructorFingerprint
import app.revanced.patches.music.player.components.fingerprints.QuickSeekOverlayFingerprint
import app.revanced.patches.music.player.components.fingerprints.RemixGenericButtonFingerprint
import app.revanced.patches.music.player.components.fingerprints.RepeatTrackFingerprint
Expand All @@ -40,11 +41,14 @@ import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKA
import app.revanced.patches.music.utils.fingerprints.PendingIntentReceiverFingerprint
import app.revanced.patches.music.utils.integrations.Constants.COMPONENTS_PATH
import app.revanced.patches.music.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.patches.music.utils.mainactivity.MainActivityResolvePatch
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.AudioVideoSwitchToggle
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.ColorGrey
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.DarkBackground
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MiniPlayerPlayPauseReplayButton
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MiniPlayerViewPager
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.PlayerViewPager
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.TapBloomView
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.TopEnd
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.TopStart
Expand All @@ -55,11 +59,13 @@ import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.getReference
import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndex
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow
import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.literalInstructionViewHook
import app.revanced.util.patch.BaseBytecodePatch
Expand Down Expand Up @@ -88,6 +94,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
description = "Adds options to hide or change components related to the player.",
dependencies = setOf(
LithoFilterPatch::class,
MainActivityResolvePatch::class,
PlayerComponentsResourcePatch::class,
SettingsPatch::class,
SharedResourceIdPatch::class,
Expand All @@ -111,6 +118,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
OldPlayerLayoutFingerprint,
PendingIntentReceiverFingerprint,
PlayerPatchConstructorFingerprint,
PlayerViewPagerConstructorFingerprint,
QuickSeekOverlayFingerprint,
RemixGenericButtonFingerprint,
RepeatTrackFingerprint,
Expand All @@ -123,6 +131,54 @@ object PlayerComponentsPatch : BaseBytecodePatch(

override fun execute(context: BytecodeContext) {

// region patch for disable gesture in player

val playerViewPagerConstructorMethod =
PlayerViewPagerConstructorFingerprint.resultOrThrow().mutableMethod
val mainActivityOnStartMethod =
MainActivityResolvePatch.getMethod("onStart")

mapOf(
MiniPlayerViewPager to "disableMiniPlayerGesture",
PlayerViewPager to "disablePlayerGesture"
).forEach { (literal, methodName) ->
val viewPagerReference = playerViewPagerConstructorMethod.let {
val constIndex = it.getWideLiteralInstructionIndex(literal)
val targetIndex = it.getTargetIndexOrThrow(constIndex, Opcode.IPUT_OBJECT)

it.getInstruction<ReferenceInstruction>(targetIndex).reference.toString()
}
mainActivityOnStartMethod.apply {
val insertIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.IGET_OBJECT
&& getReference<FieldReference>()?.toString() == viewPagerReference
}
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
val jumpIndex = getTargetIndex(insertIndex, Opcode.INVOKE_VIRTUAL) + 1

addInstructionsWithLabels(
insertIndex, """
invoke-static {}, $PLAYER_CLASS_DESCRIPTOR->$methodName()Z
move-result v$insertRegister
if-nez v$insertRegister, :disable
""", ExternalLabel("disable", getInstruction(jumpIndex))
)
}
}

SettingsPatch.addSwitchPreference(
CategoryType.PLAYER,
"revanced_disable_mini_player_gesture",
"false"
)
SettingsPatch.addSwitchPreference(
CategoryType.PLAYER,
"revanced_disable_player_gesture",
"false"
)

// endregion

// region patch for enable color match player and enable black player background

lateinit var colorMathPlayerInvokeVirtualReference: Reference
Expand Down Expand Up @@ -803,16 +859,18 @@ object PlayerComponentsPatch : BaseBytecodePatch(

// region patch for restore old comments popup panels

OldEngagementPanelFingerprint.literalInstructionBooleanHook(
45427672,
"$PLAYER_CLASS_DESCRIPTOR->restoreOldCommentsPopUpPanels(Z)Z"
)
OldEngagementPanelFingerprint.result?.let {
OldEngagementPanelFingerprint.literalInstructionBooleanHook(
45427672,
"$PLAYER_CLASS_DESCRIPTOR->restoreOldCommentsPopUpPanels(Z)Z"
)

SettingsPatch.addSwitchPreference(
CategoryType.PLAYER,
"revanced_restore_old_comments_popup_panels",
"false"
)
SettingsPatch.addSwitchPreference(
CategoryType.PLAYER,
"revanced_restore_old_comments_popup_panels",
"false"
)
}

// endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package app.revanced.patches.music.player.components.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MiniPlayerViewPager
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.PlayerViewPager
import app.revanced.util.containsWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.AccessFlags

internal object PlayerViewPagerConstructorFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
customFingerprint = { methodDef, _ ->
methodDef.containsWideLiteralInstructionIndex(MiniPlayerViewPager)
&& methodDef.containsWideLiteralInstructionIndex(PlayerViewPager)
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ object SharedResourceIdPatch : ResourcePatch() {
var MiniPlayerDefaultText = -1L
var MiniPlayerMdxPlaying = -1L
var MiniPlayerPlayPauseReplayButton = -1L
var MiniPlayerViewPager = -1L
var MusicNotifierShelf = -1L
var MusicTasteBuilderShelf = -1L
var NamesInactiveAccountThumbnailSize = -1L
var OfflineSettingsMenuItem = -1L
var PlayerOverlayChip = -1L
var PlayerViewPager = -1L
var PrivacyTosFooter = -1L
var QualityAuto = -1L
var RemixGenericButtonSize = -1L
Expand Down Expand Up @@ -77,11 +79,13 @@ object SharedResourceIdPatch : ResourcePatch() {
MiniPlayerDefaultText = getId(STRING, "mini_player_default_text")
MiniPlayerMdxPlaying = getId(STRING, "mini_player_mdx_playing")
MiniPlayerPlayPauseReplayButton = getId(ID, "mini_player_play_pause_replay_button")
MiniPlayerViewPager = getId(ID, "mini_player_view_pager")
MusicNotifierShelf = getId(LAYOUT, "music_notifier_shelf")
MusicTasteBuilderShelf = getId(LAYOUT, "music_tastebuilder_shelf")
NamesInactiveAccountThumbnailSize = getId(DIMEN, "names_inactive_account_thumbnail_size")
OfflineSettingsMenuItem = getId(ID, "offline_settings_menu_item")
PlayerOverlayChip = getId(ID, "player_overlay_chip")
PlayerViewPager = getId(ID, "player_view_pager")
PrivacyTosFooter = getId(ID, "privacy_tos_footer")
QualityAuto = getId(STRING, "quality_auto")
RemixGenericButtonSize = getId(DIMEN, "remix_generic_button_size")
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/music/settings/host/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ This does not bypass the age restriction. It just accepts it automatically."</st
<!-- PreferenceScreen: Player -->
<string name="revanced_preference_screen_player_title">Player</string>

<string name="revanced_disable_mini_player_gesture_title">Disable miniplayer gesture</string>
<string name="revanced_disable_mini_player_gesture_summary">Disable swipe to change tracks in the miniplayer.</string>
<string name="revanced_disable_player_gesture_title">Disable player gesture</string>
<string name="revanced_disable_player_gesture_summary">Disable swipe to change tracks in the player.</string>
<string name="revanced_enable_black_player_background_title">Enable black player background</string>
<string name="revanced_enable_black_player_background_summary">Changes the player background color to black.</string>
<string name="revanced_enable_color_match_player_title">Enable color match player</string>
Expand Down

0 comments on commit 25287b2

Please sign in to comment.