feat(YouTube): Add Disable suggested video end screen patch

This commit is contained in:
oSumAtrIX 2023-10-25 01:47:04 +02:00
parent 2a5514a6b3
commit 09f168406c
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,48 @@
package app.revanced.patches.youtube.layout.hide.suggestedvideoendscreen
import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
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.layout.hide.suggestedvideoendscreen.fingerprints.CreateEndScreenViewFingerprint
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@Patch(
name = "Disable suggested video end screen",
description = "Disables the suggested video end screen at the end of a video.",
dependencies = [IntegrationsPatch::class, DisableSuggestedVideoEndScreenResourcePatch::class],
compatiblePackages = [
CompatiblePackage(
"com.google.android.youtube", [
"18.37.36",
"18.38.44"
]
)
]
)
@Suppress("unused")
object DisableSuggestedVideoEndScreenPatch : BytecodePatch(
setOf(CreateEndScreenViewFingerprint)
) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"Lapp/revanced/integrations/patches/DisableSuggestedVideoEndScreenPatch;"
override fun execute(context: BytecodeContext) {
CreateEndScreenViewFingerprint.result?.let {
it.mutableMethod.apply {
val addOnClickEventListenerIndex = it.scanResult.patternScanResult!!.endIndex - 1
val viewRegister = getInstruction<FiveRegisterInstruction>(addOnClickEventListenerIndex).registerC
addInstruction(
addOnClickEventListenerIndex + 1,
"invoke-static {v$viewRegister}, " +
"$INTEGRATIONS_CLASS_DESCRIPTOR->closeEndScreen(Landroid/widget/ImageView;)V"
)
}
} ?: throw CreateEndScreenViewFingerprint.exception
}
}

View File

@ -0,0 +1,43 @@
package app.revanced.patches.youtube.layout.hide.suggestedvideoendscreen
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.shared.mapping.misc.ResourceMappingPatch
import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
import app.revanced.patches.youtube.misc.settings.SettingsPatch
@Patch(
dependencies = [
SettingsPatch::class,
ResourceMappingPatch::class
],
)
object DisableSuggestedVideoEndScreenResourcePatch : ResourcePatch() {
internal var sizeAdjustableLiteAutoNavOverlay: Long = -1
override fun execute(context: ResourceContext) {
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SwitchPreference(
"revanced_disable_suggested_video_end_screen",
StringResource(
"revanced_disable_suggested_video_end_screen_title",
"Disable suggested video end screen"
),
StringResource(
"revanced_disable_suggested_video_end_screen_summary_on",
"Suggested videos will be disabled"
),
StringResource(
"revanced_disable_suggested_video_end_screen_summary_off",
"Suggested videos will be shown"
),
)
)
sizeAdjustableLiteAutoNavOverlay = ResourceMappingPatch.resourceMappings.single {
it.type == "layout" && it.name == "size_adjustable_lite_autonav_overlay"
}.id
}
}

View File

@ -0,0 +1,19 @@
package app.revanced.patches.youtube.layout.hide.suggestedvideoendscreen.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patches.youtube.layout.hide.suggestedvideoendscreen.DisableSuggestedVideoEndScreenResourcePatch
import app.revanced.util.patch.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object CreateEndScreenViewFingerprint : LiteralValueFingerprint(
returnType= "Landroid/view/View;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Landroid/content/Context;"),
opcodes = listOf(
Opcode.INVOKE_DIRECT,
Opcode.INVOKE_VIRTUAL,
Opcode.CONST
),
literalSupplier = { DisableSuggestedVideoEndScreenResourcePatch.sizeAdjustableLiteAutoNavOverlay }
)