From 455886930c41693d2b6066f6ae20f197ad2dffd4 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sat, 28 Sep 2024 22:56:06 +0900 Subject: [PATCH] fix(YouTube/Hide feed components): `Hide related videos` setting hides the player flyout component --- .../feed/components/FeedComponentsPatch.kt | 12 ++++-- .../utils/bottomsheet/BottomSheetHookPatch.kt | 39 +++++++++++++++++++ .../BottomSheetBehaviorFingerprint.kt | 9 +++++ .../utils/resourceid/SharedResourceIdPatch.kt | 2 + 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/utils/bottomsheet/BottomSheetHookPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/utils/bottomsheet/fingerprint/BottomSheetBehaviorFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt index 4e8973778..1ed6fc011 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt @@ -27,6 +27,7 @@ import app.revanced.patches.youtube.feed.components.fingerprints.LinearLayoutMan import app.revanced.patches.youtube.feed.components.fingerprints.RelatedChipCloudFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.SearchResultsChipBarFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.ShowMoreButtonFingerprint +import app.revanced.patches.youtube.utils.bottomsheet.BottomSheetHookPatch import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.fingerprints.EngagementPanelBuilderFingerprint import app.revanced.patches.youtube.utils.fingerprints.ScrollTopParentFingerprint @@ -65,7 +66,8 @@ object FeedComponentsPatch : BaseBytecodePatch( NavigationBarHookPatch::class, PlayerTypeHookPatch::class, SettingsPatch::class, - SharedResourceIdPatch::class + SharedResourceIdPatch::class, + BottomSheetHookPatch::class, ), compatiblePackages = COMPATIBLE_PACKAGE, fingerprints = setOf( @@ -158,7 +160,10 @@ object FeedComponentsPatch : BaseBytecodePatch( fun Method.indexOfEngagementPanelBuilderInstruction(targetMethod: MutableMethod) = indexOfFirstInstruction { opcode == Opcode.INVOKE_DIRECT && - MethodUtil.methodSignaturesMatch(targetMethod, getReference()!!) + MethodUtil.methodSignaturesMatch( + targetMethod, + getReference()!! + ) } EngagementPanelBuilderFingerprint.resultOrThrow().let { @@ -189,7 +194,8 @@ object FeedComponentsPatch : BaseBytecodePatch( // Otherwise, MethodWalker finds the wrong class in YouTube 18.29.38: // https://github.com/ReVanced/revanced-patcher/issues/309 LinearLayoutManagerItemCountsFingerprint.resultOrThrow().let { - val methodWalker = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex) + val methodWalker = + it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex) methodWalker.apply { val index = indexOfFirstInstructionOrThrow(Opcode.MOVE_RESULT) val register = getInstruction(index).registerA diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/bottomsheet/BottomSheetHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/bottomsheet/BottomSheetHookPatch.kt new file mode 100644 index 000000000..3e43d3305 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/bottomsheet/BottomSheetHookPatch.kt @@ -0,0 +1,39 @@ +package app.revanced.patches.youtube.utils.bottomsheet + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.youtube.utils.bottomsheet.fingerprint.BottomSheetBehaviorFingerprint +import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch +import app.revanced.util.findMethodOrThrow +import app.revanced.util.resultOrThrow + +@Patch(dependencies = [SharedResourceIdPatch::class]) +object BottomSheetHookPatch : BytecodePatch( + setOf(BottomSheetBehaviorFingerprint) +) { + private const val INTEGRATIONS_BOTTOM_SHEET_HOOK_CLASS_DESCRIPTOR = + "$UTILS_PATH/BottomSheetHookPatch;" + + override fun execute(context: BytecodeContext) { + + // region patch for set player type + + val bottomSheetClass = + BottomSheetBehaviorFingerprint.resultOrThrow().mutableMethod.definingClass + + arrayOf( + "onAttachedToWindow", + "onDetachedFromWindow" + ).forEach { methodName -> + context.findMethodOrThrow(bottomSheetClass) { + name == methodName + }.addInstruction( + 1, + "invoke-static {}, $INTEGRATIONS_BOTTOM_SHEET_HOOK_CLASS_DESCRIPTOR->$methodName()V" + ) + } + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/bottomsheet/fingerprint/BottomSheetBehaviorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/bottomsheet/fingerprint/BottomSheetBehaviorFingerprint.kt new file mode 100644 index 000000000..73d6aa2cb --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/bottomsheet/fingerprint/BottomSheetBehaviorFingerprint.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.youtube.utils.bottomsheet.fingerprint + +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.DesignBottomSheet +import app.revanced.util.fingerprint.LiteralValueFingerprint + +internal object BottomSheetBehaviorFingerprint : LiteralValueFingerprint( + returnType = "V", + literalSupplier = { DesignBottomSheet } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt index 153c540bf..a8c77ce03 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt @@ -45,6 +45,7 @@ object SharedResourceIdPatch : ResourcePatch() { var ControlsLayoutStub = -1L var DarkBackground = -1L var DarkSplashAnimation = -1L + var DesignBottomSheet = -1L var DonationCompanion = -1L var DrawerContentView = -1L var DrawerResults = -1L @@ -152,6 +153,7 @@ object SharedResourceIdPatch : ResourcePatch() { ControlsLayoutStub = getId(ID, "controls_layout_stub") DarkBackground = getId(ID, "dark_background") DarkSplashAnimation = getId(ID, "dark_splash_animation") + DesignBottomSheet = getId(ID, "design_bottom_sheet") DonationCompanion = getId(LAYOUT, "donation_companion") DrawerContentView = getId(ID, "drawer_content_view") DrawerResults = getId(ID, "drawer_results")