fix(youtube/hide-suggestions-shelf): suggestions shelf is not hidden or playlist shelf is hidden under certain circumstances

This commit is contained in:
inotia00 2023-09-17 23:50:50 +09:00
parent 0a041e5198
commit 8b5036e6a6
2 changed files with 47 additions and 7 deletions

View File

@ -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
)
)

View File

@ -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
*/
/**