From 4eafb40d33d35ca56e4ff0ce41648ac0ad2764e6 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sun, 13 Oct 2024 22:40:28 +0900 Subject: [PATCH] feat(YouTube/Hide player flyout menu): add `Hide 1080p Premium menu` setting --- .../flyoutmenu/hide/PlayerFlyoutMenuPatch.kt | 29 ++++++++- .../VideoQualityArrayFingerprint.kt | 60 +++++++++++++++++++ .../youtube/settings/host/values/strings.xml | 3 + .../youtube/settings/xml/revanced_prefs.xml | 1 + 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/player/flyoutmenu/hide/fingerprints/VideoQualityArrayFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/flyoutmenu/hide/PlayerFlyoutMenuPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/flyoutmenu/hide/PlayerFlyoutMenuPatch.kt index 5b48b26061..12cf7f839f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/flyoutmenu/hide/PlayerFlyoutMenuPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/flyoutmenu/hide/PlayerFlyoutMenuPatch.kt @@ -2,11 +2,14 @@ package app.revanced.patches.youtube.player.flyoutmenu.hide import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.shared.litho.LithoFilterPatch import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.AdvancedQualityBottomSheetFingerprint import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.CaptionsBottomSheetFingerprint import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.PiPModeConfigFingerprint +import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.VideoQualityArrayFingerprint import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.fingerprints.QualityMenuViewInflateFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH @@ -18,12 +21,14 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow +import app.revanced.util.indexOfFirstInstructionReversedOrThrow import app.revanced.util.injectLiteralInstructionBooleanCall import app.revanced.util.injectLiteralInstructionViewCall 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.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Suppress("unused") @@ -41,7 +46,8 @@ object PlayerFlyoutMenuPatch : BaseBytecodePatch( AdvancedQualityBottomSheetFingerprint, CaptionsBottomSheetFingerprint, PiPModeConfigFingerprint, - QualityMenuViewInflateFingerprint + QualityMenuViewInflateFingerprint, + VideoQualityArrayFingerprint, ) ) { private const val PANELS_FILTER_CLASS_DESCRIPTOR = @@ -84,6 +90,27 @@ object PlayerFlyoutMenuPatch : BaseBytecodePatch( // endregion + // region patch for hide '1080p Premium' label + + VideoQualityArrayFingerprint.resultOrThrow().mutableMethod.apply { + val qualityLabelIndex = VideoQualityArrayFingerprint.indexOfQualityLabelInstruction(this) + 1 + val qualityLabelRegister = getInstruction(qualityLabelIndex).registerA + val jumpIndex = indexOfFirstInstructionReversedOrThrow(qualityLabelIndex) { + opcode == Opcode.INVOKE_INTERFACE && + getReference()?.name == "hasNext" + } + + addInstructionsWithLabels( + qualityLabelIndex + 1, """ + invoke-static {v$qualityLabelRegister}, $PLAYER_CLASS_DESCRIPTOR->hidePlayerFlyoutMenuEnhancedBitrate(Ljava/lang/String;)Ljava/lang/String; + move-result-object v$qualityLabelRegister + if-eqz v$qualityLabelRegister, :jump + """, ExternalLabel("jump", getInstruction(jumpIndex)) + ) + } + + // endregion + LithoFilterPatch.addFilter(PANELS_FILTER_CLASS_DESCRIPTOR) /** diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/flyoutmenu/hide/fingerprints/VideoQualityArrayFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/player/flyoutmenu/hide/fingerprints/VideoQualityArrayFingerprint.kt new file mode 100644 index 0000000000..0c6f6f2c9a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/player/flyoutmenu/hide/fingerprints/VideoQualityArrayFingerprint.kt @@ -0,0 +1,60 @@ +package app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.VideoQualityArrayFingerprint.ENDS_WITH_PARAMETER_LIST +import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.VideoQualityArrayFingerprint.STARTS_WITH_PARAMETER_LIST +import app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints.VideoQualityArrayFingerprint.indexOfQualityLabelInstruction +import app.revanced.util.getReference +import app.revanced.util.indexOfFirstInstruction +import app.revanced.util.parametersEqual +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.Method +import com.android.tools.smali.dexlib2.iface.reference.MethodReference + +internal object VideoQualityArrayFingerprint : MethodFingerprint( + returnType = "[Lcom/google/android/libraries/youtube/innertube/model/media/VideoQuality;", + accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL, + // 18.29 and earlier parameters are: + // "Ljava/util/List;", + // "Ljava/lang/String;" + // "L" + + // 18.31+ parameters are: + // "Ljava/util/List;", + // "Ljava/util/Collection;", + // "Ljava/lang/String;" + // "L" + customFingerprint = custom@{ methodDef, _ -> + val parameterTypes = methodDef.parameterTypes + val parameterSize = parameterTypes.size + if (parameterSize != 3 && parameterSize != 4) { + return@custom false + } + + val startsWithMethodParameterList = parameterTypes.slice(0..0) + val endsWithMethodParameterList = parameterTypes.slice(parameterSize - 2..< parameterSize) + + parametersEqual(STARTS_WITH_PARAMETER_LIST, startsWithMethodParameterList) && + parametersEqual(ENDS_WITH_PARAMETER_LIST, endsWithMethodParameterList) && + indexOfQualityLabelInstruction(methodDef) >= 0 + } +) { + private val STARTS_WITH_PARAMETER_LIST = listOf( + "Ljava/util/List;" + ) + private val ENDS_WITH_PARAMETER_LIST = listOf( + "Ljava/lang/String;", + "L" + ) + + fun indexOfQualityLabelInstruction(methodDef: Method) = + methodDef.indexOfFirstInstruction { + val reference = getReference() + opcode == Opcode.INVOKE_VIRTUAL && + reference?.returnType == "Ljava/lang/String;" && + reference.parameterTypes.size == 0 && + reference.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/media/FormatStreamModel;" + } +} \ No newline at end of file diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 45c95cfdc8..ee6685abfe 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -818,6 +818,9 @@ Settings → Autoplay → Autoplay next video" Change toggle type Text toggles are used. Switch toggles are used. + Hide 1080p Premium menu + 1080p Premium menu is hidden. + 1080p Premium menu is shown. Hide Audio track menu Audio track menu is hidden. Audio track menu is shown. diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 3c56ea4478..472cfd40df 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -337,6 +337,7 @@ SETTINGS: CHANGE_PLAYER_FLYOUT_MENU_TOGGLE -->