From 47fbcba3f845b5c3ef35c4dded8d6f9ffafc5d9e Mon Sep 17 00:00:00 2001 From: OxrxL <108184954+OxrxL@users.noreply.github.com> Date: Wed, 21 Sep 2022 03:03:47 +0200 Subject: [PATCH] feat: disable sponsorblock on shorts (#439) --- .../ShortsPlayerConstructorFingerprint.kt | 38 +++++++++++++++++++ .../patch/SponsorBlockBytecodePatch.kt | 21 +++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/fingerprints/ShortsPlayerConstructorFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/fingerprints/ShortsPlayerConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/fingerprints/ShortsPlayerConstructorFingerprint.kt new file mode 100644 index 000000000..f8a067362 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/fingerprints/ShortsPlayerConstructorFingerprint.kt @@ -0,0 +1,38 @@ +package app.revanced.patches.youtube.layout.sponsorblock.bytecode.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod +import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.layout.sponsorblock.annotations.SponsorBlockCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("shorts-player-constructor-fingerprint") +@MatchingMethod("Lhgp;", "") +@FuzzyPatternScanMethod(3) +@SponsorBlockCompatibility +@Version("0.0.1") +object ShortsPlayerConstructorFingerprint : MethodFingerprint( + "V", AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + opcodes = listOf( + Opcode.MOVE_OBJECT_FROM16, + Opcode.MOVE_OBJECT_FROM16, + Opcode.MOVE_OBJECT_FROM16, + Opcode.INVOKE_DIRECT_RANGE, + Opcode.NEW_INSTANCE, + Opcode.INVOKE_DIRECT, + Opcode.IPUT_OBJECT, + Opcode.NEW_INSTANCE, + Opcode.INVOKE_DIRECT, + Opcode.IPUT_OBJECT, + Opcode.NEW_INSTANCE, + Opcode.INVOKE_DIRECT, + Opcode.IPUT_OBJECT, + Opcode.NEW_INSTANCE, + Opcode.INVOKE_DIRECT, + Opcode.IPUT_OBJECT + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt index c2ff0764c..671877f4b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt @@ -25,6 +25,7 @@ import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.mapping.patch.ResourceIdMappingProviderResourcePatch import app.revanced.patches.youtube.misc.playercontrols.bytecode.patch.PlayerControlsBytecodePatch import app.revanced.patches.youtube.misc.videoid.patch.VideoIdPatch +import app.revanced.patches.youtube.layout.autocaptions.fingerprints.StartVideoInformerFingerprint import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode import org.jf.dexlib2.builder.MutableMethodImplementation @@ -53,7 +54,8 @@ class SponsorBlockBytecodePatch : BytecodePatch( NextGenWatchLayoutFingerprint, AppendTimeFingerprint, PlayerInitFingerprint, - PlayerOverlaysLayoutInitFingerprint + PlayerOverlaysLayoutInitFingerprint, + ShortsPlayerConstructorFingerprint ) ) { override fun execute(data: BytecodeData): PatchResult {/* @@ -324,6 +326,23 @@ class SponsorBlockBytecodePatch : BytecodePatch( } } + val startVideoInformerMethod = StartVideoInformerFingerprint.result!!.mutableMethod + startVideoInformerMethod.addInstructions( + 0, """ + const/4 v0, 0x1 + sput-boolean v0, Lapp/revanced/integrations/settings/SettingsEnum;->shorts_playing:Z + """ + ) + + val shortsPlayerConstructorMethod = ShortsPlayerConstructorFingerprint.result!!.mutableMethod + + shortsPlayerConstructorMethod.addInstructions( + 0, """ + const/4 v0, 0x0 + sput-boolean v0, Lapp/revanced/integrations/settings/SettingsEnum;->shorts_playing:Z + """ + ) + // TODO: isSBChannelWhitelisting implementation return PatchResultSuccess()