From c6faf2120f11a683037f5e894a1d79d9e79ab29f Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Mon, 25 Mar 2024 05:42:04 +0900 Subject: [PATCH] feat(YouTube/Description components): add `Always expand panel` and `Disable description interaction` settings --- .../oldqualitylayout/OldQualityLayoutPatch.kt | 16 +------ .../oldspeedlayout/OldSpeedLayoutPatch.kt | 18 ++----- .../DescriptionComponentsPatch.kt | 48 +++++++++++++++++-- .../TextViewComponentFingerprint.kt | 14 ++++++ .../BottomSheetRecyclerViewPatch.kt | 31 ++++++++++-- ...ttomSheetRecyclerViewBuilderFingerprint.kt | 2 +- .../RecyclerViewTreeObserverFingerprint.kt | 2 +- .../youtube/utils/settings/SettingsPatch.kt | 27 ++++++----- .../youtube/settings/host/values/strings.xml | 8 ++++ .../youtube/settings/xml/revanced_prefs.xml | 12 +++-- 10 files changed, 123 insertions(+), 55 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/general/descriptions/fingerprints/TextViewComponentFingerprint.kt rename src/main/kotlin/app/revanced/patches/youtube/{flyoutpanel => utils}/recyclerview/BottomSheetRecyclerViewPatch.kt (54%) rename src/main/kotlin/app/revanced/patches/youtube/{flyoutpanel => utils}/recyclerview/fingerprints/BottomSheetRecyclerViewBuilderFingerprint.kt (70%) rename src/main/kotlin/app/revanced/patches/youtube/utils/{ => recyclerview}/fingerprints/RecyclerViewTreeObserverFingerprint.kt (89%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldqualitylayout/OldQualityLayoutPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldqualitylayout/OldQualityLayoutPatch.kt index f57e5a5cd..86f1faf3d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldqualitylayout/OldQualityLayoutPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldqualitylayout/OldQualityLayoutPatch.kt @@ -9,13 +9,12 @@ import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.smali.ExternalLabel -import app.revanced.patches.youtube.flyoutpanel.recyclerview.BottomSheetRecyclerViewPatch import app.revanced.patches.youtube.utils.fingerprints.QualityMenuViewInflateFingerprint -import app.revanced.patches.youtube.utils.fingerprints.RecyclerViewTreeObserverFingerprint import app.revanced.patches.youtube.utils.fingerprints.VideoQualitySetterFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.FLYOUT_PANEL import app.revanced.patches.youtube.utils.litho.LithoFilterPatch +import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.util.exception @@ -69,7 +68,6 @@ import com.android.tools.smali.dexlib2.iface.reference.FieldReference @Suppress("unused") object OldQualityLayoutPatch : BytecodePatch( setOf( - RecyclerViewTreeObserverFingerprint, QualityMenuViewInflateFingerprint, VideoQualitySetterFingerprint ) @@ -117,17 +115,7 @@ object OldQualityLayoutPatch : BytecodePatch( /** * New method */ - RecyclerViewTreeObserverFingerprint.result?.let { - it.mutableMethod.apply { - val insertIndex = it.scanResult.patternScanResult!!.startIndex - val recyclerViewRegister = 2 - - addInstruction( - insertIndex, - "invoke-static/range { p$recyclerViewRegister .. p$recyclerViewRegister }, $FLYOUT_PANEL->onFlyoutMenuCreate(Landroid/support/v7/widget/RecyclerView;)V" - ) - } - } ?: throw RecyclerViewTreeObserverFingerprint.exception + BottomSheetRecyclerViewPatch.injectCall("$FLYOUT_PANEL->onFlyoutMenuCreate(Landroid/support/v7/widget/RecyclerView;)V") LithoFilterPatch.addFilter("$COMPONENTS_PATH/VideoQualityMenuFilter;") diff --git a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldspeedlayout/OldSpeedLayoutPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldspeedlayout/OldSpeedLayoutPatch.kt index da8695ff7..d7012a771 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldspeedlayout/OldSpeedLayoutPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldspeedlayout/OldSpeedLayoutPatch.kt @@ -11,11 +11,10 @@ import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable import app.revanced.patches.youtube.flyoutpanel.oldspeedlayout.fingerprints.CustomPlaybackSpeedIntegrationsFingerprint import app.revanced.patches.youtube.flyoutpanel.oldspeedlayout.fingerprints.PlaybackRateBottomSheetClassFingerprint -import app.revanced.patches.youtube.flyoutpanel.recyclerview.BottomSheetRecyclerViewPatch -import app.revanced.patches.youtube.utils.fingerprints.RecyclerViewTreeObserverFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.VIDEO_PATH import app.revanced.patches.youtube.utils.litho.LithoFilterPatch +import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch import app.revanced.util.exception import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.immutable.ImmutableField @@ -30,8 +29,7 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableField object OldSpeedLayoutPatch : BytecodePatch( setOf( CustomPlaybackSpeedIntegrationsFingerprint, - PlaybackRateBottomSheetClassFingerprint, - RecyclerViewTreeObserverFingerprint + PlaybackRateBottomSheetClassFingerprint ) ) { override fun execute(context: BytecodeContext) { @@ -91,17 +89,7 @@ object OldSpeedLayoutPatch : BytecodePatch( /** * New method */ - RecyclerViewTreeObserverFingerprint.result?.let { - it.mutableMethod.apply { - val insertIndex = it.scanResult.patternScanResult!!.startIndex - val recyclerViewRegister = 2 - - addInstruction( - insertIndex, - "invoke-static/range { p$recyclerViewRegister .. p$recyclerViewRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->onFlyoutMenuCreate(Landroid/support/v7/widget/RecyclerView;)V" - ) - } - } ?: throw RecyclerViewTreeObserverFingerprint.exception + BottomSheetRecyclerViewPatch.injectCall("$INTEGRATIONS_CLASS_DESCRIPTOR->onFlyoutMenuCreate(Landroid/support/v7/widget/RecyclerView;)V") LithoFilterPatch.addFilter("$COMPONENTS_PATH/PlaybackSpeedMenuFilter;") diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/descriptions/DescriptionComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/descriptions/DescriptionComponentsPatch.kt index fd22c8d21..19738cfd0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/descriptions/DescriptionComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/descriptions/DescriptionComponentsPatch.kt @@ -1,17 +1,26 @@ package app.revanced.patches.youtube.general.descriptions import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.youtube.general.descriptions.fingerprints.TextViewComponentFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH +import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL import app.revanced.patches.youtube.utils.litho.LithoFilterPatch +import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.util.exception +import app.revanced.util.getTargetIndexWithMethodReferenceName +import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @Patch( - name = "Hide description components", - description = "Adds an option to hide description components.", + name = "Description components", + description = "Adds an option to hide or disable description components.", dependencies = [ + BottomSheetRecyclerViewPatch::class, LithoFilterPatch::class, SettingsPatch::class ], @@ -46,8 +55,37 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch ] ) @Suppress("unused") -object DescriptionComponentsPatch : BytecodePatch(emptySet()) { +object DescriptionComponentsPatch : BytecodePatch( + setOf(TextViewComponentFingerprint) +) { override fun execute(context: BytecodeContext) { + + if (SettingsPatch.upward1902) { + TextViewComponentFingerprint.result?.let { + it.mutableMethod.apply { + val insertIndex = getTargetIndexWithMethodReferenceName("setTextIsSelectable") + val insertInstruction = getInstruction(insertIndex) + + replaceInstruction( + insertIndex, + "invoke-static {v${insertInstruction.registerC}, v${insertInstruction.registerD}}, " + + "$GENERAL->disableDescriptionInteraction(Landroid/widget/TextView;Z)V" + ) + } + } ?: throw TextViewComponentFingerprint.exception + + BottomSheetRecyclerViewPatch.injectCall("$GENERAL->onDescriptionPanelCreate(Landroid/support/v7/widget/RecyclerView;)V") + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "SETTINGS: DESCRIPTION_PANEL_INTERACTION" + ) + ) + } + LithoFilterPatch.addFilter("$COMPONENTS_PATH/DescriptionsFilter;") /** @@ -56,11 +94,11 @@ object DescriptionComponentsPatch : BytecodePatch(emptySet()) { SettingsPatch.addPreference( arrayOf( "PREFERENCE: GENERAL_SETTINGS", - "SETTINGS: HIDE_DESCRIPTION_COMPONENTS" + "SETTINGS: DESCRIPTION_COMPONENTS" ) ) - SettingsPatch.updatePatchStatus("Hide description components") + SettingsPatch.updatePatchStatus("Description components") } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/descriptions/fingerprints/TextViewComponentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/descriptions/fingerprints/TextViewComponentFingerprint.kt new file mode 100644 index 000000000..683389178 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/descriptions/fingerprints/TextViewComponentFingerprint.kt @@ -0,0 +1,14 @@ +package app.revanced.patches.youtube.general.descriptions.fingerprints + +import app.revanced.util.fingerprint.MethodReferenceNameFingerprint +import com.android.tools.smali.dexlib2.Opcode + +/** + * This fingerprint is compatible with YouTube v18.35.xx~ + * Nonetheless, the patch works in YouTube v19.02.xx~ + */ +object TextViewComponentFingerprint : MethodReferenceNameFingerprint( + returnType = "V", + opcodes = listOf(Opcode.CMPL_FLOAT), + reference = { "setBreakStrategy" } +) diff --git a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/recyclerview/BottomSheetRecyclerViewPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/BottomSheetRecyclerViewPatch.kt similarity index 54% rename from src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/recyclerview/BottomSheetRecyclerViewPatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/BottomSheetRecyclerViewPatch.kt index edbec9702..3dc49e9fb 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/recyclerview/BottomSheetRecyclerViewPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/BottomSheetRecyclerViewPatch.kt @@ -1,17 +1,24 @@ -package app.revanced.patches.youtube.flyoutpanel.recyclerview +package app.revanced.patches.youtube.utils.recyclerview import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.fingerprint.MethodFingerprintResult import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patches.youtube.flyoutpanel.recyclerview.fingerprints.BottomSheetRecyclerViewBuilderFingerprint +import app.revanced.patches.youtube.utils.recyclerview.fingerprints.BottomSheetRecyclerViewBuilderFingerprint +import app.revanced.patches.youtube.utils.recyclerview.fingerprints.RecyclerViewTreeObserverFingerprint import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction object BottomSheetRecyclerViewPatch : BytecodePatch( - setOf(BottomSheetRecyclerViewBuilderFingerprint) + setOf( + BottomSheetRecyclerViewBuilderFingerprint, + RecyclerViewTreeObserverFingerprint + ) ) { + private lateinit var recyclerViewTreeObserverResult: MethodFingerprintResult + override fun execute(context: BytecodeContext) { /** @@ -32,5 +39,23 @@ object BottomSheetRecyclerViewPatch : BytecodePatch( } } ?: throw BottomSheetRecyclerViewBuilderFingerprint.exception + recyclerViewTreeObserverResult = RecyclerViewTreeObserverFingerprint.result + ?: throw RecyclerViewTreeObserverFingerprint.exception + + } + + fun injectCall(descriptor: String) { + recyclerViewTreeObserverResult.let { + it.mutableMethod.apply { + val insertIndex = it.scanResult.patternScanResult!!.startIndex + val recyclerViewRegister = 2 + + addInstruction( + insertIndex, + "invoke-static/range { p$recyclerViewRegister .. p$recyclerViewRegister }, $descriptor" + ) + } + } + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/recyclerview/fingerprints/BottomSheetRecyclerViewBuilderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/fingerprints/BottomSheetRecyclerViewBuilderFingerprint.kt similarity index 70% rename from src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/recyclerview/fingerprints/BottomSheetRecyclerViewBuilderFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/fingerprints/BottomSheetRecyclerViewBuilderFingerprint.kt index 5fffd3b5a..9624e022e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/recyclerview/fingerprints/BottomSheetRecyclerViewBuilderFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/fingerprints/BottomSheetRecyclerViewBuilderFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.flyoutpanel.recyclerview.fingerprints +package app.revanced.patches.youtube.utils.recyclerview.fingerprints import app.revanced.util.fingerprint.LiteralValueFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/RecyclerViewTreeObserverFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/fingerprints/RecyclerViewTreeObserverFingerprint.kt similarity index 89% rename from src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/RecyclerViewTreeObserverFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/fingerprints/RecyclerViewTreeObserverFingerprint.kt index 8cef88787..b03f0a105 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/RecyclerViewTreeObserverFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/fingerprints/RecyclerViewTreeObserverFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.utils.fingerprints +package app.revanced.patches.youtube.utils.recyclerview.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt index acaab4dbc..3e42afa33 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt @@ -64,6 +64,17 @@ import java.util.jar.Manifest object SettingsPatch : AbstractSettingsResourcePatch( "youtube/settings" ), Closeable { + + private val THREAD_COUNT = Runtime.getRuntime().availableProcessors() + private val threadPoolExecutor = Executors.newFixedThreadPool(THREAD_COUNT) + + internal lateinit var contexts: ResourceContext + internal var upward1831: Boolean = false + internal var upward1834: Boolean = false + internal var upward1839: Boolean = false + internal var upward1849: Boolean = false + internal var upward1902: Boolean = false + override fun execute(context: ResourceContext) { super.execute(context) contexts = context @@ -92,9 +103,10 @@ object SettingsPatch : AbstractSettingsResourcePatch( val playServicesVersion = node.textContent.toInt() upward1831 = 233200000 <= playServicesVersion - upward1834 = 233502000 <= playServicesVersion - upward1839 = 234002000 <= playServicesVersion - upward1849 = 235002000 <= playServicesVersion + upward1834 = 233500000 <= playServicesVersion + upward1839 = 234000000 <= playServicesVersion + upward1849 = 235000000 <= playServicesVersion + upward1902 = 240204000 < playServicesVersion break } @@ -155,15 +167,6 @@ object SettingsPatch : AbstractSettingsResourcePatch( } - private val THREAD_COUNT = Runtime.getRuntime().availableProcessors() - private val threadPoolExecutor = Executors.newFixedThreadPool(THREAD_COUNT) - - internal lateinit var contexts: ResourceContext - internal var upward1831: Boolean = false - internal var upward1834: Boolean = false - internal var upward1839: Boolean = false - internal var upward1849: Boolean = false - internal fun addPreference(settingArray: Array) { contexts.addPreference(settingArray) } diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 9c7c2d5e3..45d63d846 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -50,6 +50,9 @@ Tap here to learn more about DeArrow." Append playback speed. Append video quality. Append information type + Description panel is expanded manually. + Description panel is always expanded. + Always expand panel Bottom player Button container Ambient mode is disabled in battery saver mode. @@ -110,6 +113,11 @@ Note: This feature hasn't been tested." Forced auto captions are enabled. Forced auto captions are disabled. Disable forced auto captions + "Disables the following interactions when the description panel is expanded: + +• Tap to scroll. +• Tap and hold to select text." + Disable description interaction Default playback speed is enabled in live stream. Default playback speed is disabled in live stream. Disable playback speed in live stream diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 9501c857c..8c2da9f80 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -300,8 +300,12 @@ SETTINGS: HIDE_CHANNEL_PROFILE_COMPONENTS --> - + + + SETTINGS: DESCRIPTION_COMPONENTS --> @@ -427,6 +431,7 @@ + @@ -438,7 +443,6 @@ -