From 8b5036e6a6c5bc09d96c9b04dfa488c03ccef999 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sun, 17 Sep 2023 23:50:50 +0900 Subject: [PATCH] fix(youtube/hide-suggestions-shelf): suggestions shelf is not hidden or playlist shelf is hidden under certain circumstances --- .../SuggestionContentsBuilderFingerprint.kt | 26 +++++++++++++++++ .../patch/SuggestionsShelfPatch.kt | 28 ++++++++++++++----- 2 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/general/suggestions/fingerprints/SuggestionContentsBuilderFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/suggestions/fingerprints/SuggestionContentsBuilderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/suggestions/fingerprints/SuggestionContentsBuilderFingerprint.kt new file mode 100644 index 000000000..af6a75e60 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/suggestions/fingerprints/SuggestionContentsBuilderFingerprint.kt @@ -0,0 +1,26 @@ +package app.revanced.patches.youtube.general.suggestions.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +object SuggestionContentsBuilderFingerprint : MethodFingerprint( + returnType = "L", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L", "L"), + opcodes = listOf( + Opcode.INVOKE_VIRTUAL_RANGE, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_STATIC, + Opcode.RETURN_OBJECT, + Opcode.IGET_OBJECT, + Opcode.IGET, + Opcode.IGET_OBJECT, + Opcode.IGET_OBJECT, + Opcode.IGET_OBJECT, + Opcode.CHECK_CAST + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/suggestions/patch/SuggestionsShelfPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/suggestions/patch/SuggestionsShelfPatch.kt index 98364a80c..05d3837b5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/suggestions/patch/SuggestionsShelfPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/suggestions/patch/SuggestionsShelfPatch.kt @@ -5,13 +5,17 @@ import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.shared.patch.litho.ComponentParserPatch.Companion.emptyComponentLabel import app.revanced.patches.youtube.general.suggestions.fingerprints.BreakingNewsFingerprint +import app.revanced.patches.youtube.general.suggestions.fingerprints.SuggestionContentsBuilderFingerprint import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility -import app.revanced.patches.youtube.utils.navbarindex.patch.NavBarIndexHookPatch +import app.revanced.patches.youtube.utils.litho.patch.LithoFilterPatch import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch import app.revanced.util.integrations.Constants.GENERAL import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -21,16 +25,22 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Description("Hides the suggestions shelf.") @DependsOn( [ - NavBarIndexHookPatch::class, + LithoFilterPatch::class, SettingsPatch::class ] ) @YouTubeCompatibility class SuggestionsShelfPatch : BytecodePatch( - listOf(BreakingNewsFingerprint) + listOf( + BreakingNewsFingerprint, + SuggestionContentsBuilderFingerprint + ) ) { override fun execute(context: BytecodeContext) { + /** + * Legacy code for old layout + */ BreakingNewsFingerprint.result?.let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex @@ -43,19 +53,23 @@ class SuggestionsShelfPatch : BytecodePatch( } } ?: throw BreakingNewsFingerprint.exception - /* + /** + * For new layout + * + * Target method only removes the horizontal video shelf's content in the feed. + * Since the header of the horizontal video shelf is not removed, it must be removed through the low level filter + */ SuggestionContentsBuilderFingerprint.result?.let { it.mutableMethod.apply { addInstructionsWithLabels( 2, """ invoke-static/range {p2 .. p2}, $GENERAL->hideSuggestionsShelf(Ljava/lang/Object;)Z move-result v0 - if-eqz v0, :not_an_ad - """ + emptyComponentLabel, ExternalLabel("not_an_ad", getInstruction(2)) + if-eqz v0, :show + """ + emptyComponentLabel, ExternalLabel("show", getInstruction(2)) ) } } ?: throw SuggestionContentsBuilderFingerprint.exception - */ /**