From 59fb674437207aeabed5b92ba32bda120820fb8f Mon Sep 17 00:00:00 2001 From: OxrxL <108184954+OxrxL@users.noreply.github.com> Date: Thu, 22 Sep 2022 07:43:54 +0200 Subject: [PATCH] fix(sponsorblock): broken fingerprint and invert setting `shorts_playing` (#579) Co-authored-by: oSumAtrIX --- .../ShortsPlayerConstructorFingerprint.kt | 13 +++++++++++-- .../bytecode/patch/SponsorBlockBytecodePatch.kt | 6 +++--- .../resource/patch/SponsorBlockResourcePatch.kt | 11 ++++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) 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 index f8a067362..0b5d91841 100644 --- 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 @@ -7,8 +7,10 @@ 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 app.revanced.patches.youtube.layout.sponsorblock.resource.patch.SponsorBlockResourcePatch import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction @Name("shorts-player-constructor-fingerprint") @MatchingMethod("Lhgp;", "") @@ -33,6 +35,13 @@ object ShortsPlayerConstructorFingerprint : MethodFingerprint( Opcode.IPUT_OBJECT, Opcode.NEW_INSTANCE, Opcode.INVOKE_DIRECT, - Opcode.IPUT_OBJECT - ) + Opcode.IPUT_OBJECT, + Opcode.IPUT_OBJECT, + Opcode.CONST_4 + ), + customFingerprint = { methodDef -> + methodDef.implementation?.instructions?.any { instruction -> + (instruction as? WideLiteralInstruction)?.wideLiteral == SponsorBlockResourcePatch.reelButtonGroupResourceId + } == true + } ) \ 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 b9bd83267..f9c3195e0 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 @@ -40,7 +40,7 @@ import org.jf.dexlib2.util.MethodUtil @Patch @DependsOn( - dependencies = [PlayerControlsBytecodePatch::class, IntegrationsPatch::class, ResourceIdMappingProviderResourcePatch::class, SponsorBlockResourcePatch::class, VideoIdPatch::class] + dependencies = [PlayerControlsBytecodePatch::class, IntegrationsPatch::class, SponsorBlockResourcePatch::class, VideoIdPatch::class] ) @Name("sponsorblock") @Description("Integrate SponsorBlock.") @@ -329,7 +329,7 @@ class SponsorBlockBytecodePatch : BytecodePatch( val startVideoInformerMethod = StartVideoInformerFingerprint.result!!.mutableMethod startVideoInformerMethod.addInstructions( 0, """ - const/4 v0, 0x1 + const/4 v0, 0x0 sput-boolean v0, Lapp/revanced/integrations/settings/SettingsEnum;->shorts_playing:Z """ ) @@ -338,7 +338,7 @@ class SponsorBlockBytecodePatch : BytecodePatch( shortsPlayerConstructorMethod.addInstructions( 0, """ - const/4 v0, 0x0 + const/4 v0, 0x1 sput-boolean v0, Lapp/revanced/integrations/settings/SettingsEnum;->shorts_playing:Z """ ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/resource/patch/SponsorBlockResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/resource/patch/SponsorBlockResourcePatch.kt index cad7b7962..333344160 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/resource/patch/SponsorBlockResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/resource/patch/SponsorBlockResourcePatch.kt @@ -9,6 +9,7 @@ import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.impl.ResourcePatch import app.revanced.patches.youtube.layout.sponsorblock.annotations.SponsorBlockCompatibility import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch +import app.revanced.patches.youtube.misc.mapping.patch.ResourceIdMappingProviderResourcePatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import app.revanced.patches.youtube.misc.settings.framework.components.impl.Preference import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource @@ -19,9 +20,13 @@ import app.revanced.util.resources.ResourceUtils.copyXmlNode @Name("sponsorblock-resource-patch") @SponsorBlockCompatibility -@DependsOn([FixLocaleConfigErrorPatch::class, SettingsPatch::class]) +@DependsOn([FixLocaleConfigErrorPatch::class, SettingsPatch::class, ResourceIdMappingProviderResourcePatch::class]) @Version("0.0.1") class SponsorBlockResourcePatch : ResourcePatch() { + companion object { + internal var reelButtonGroupResourceId: Long = 0 + } + override fun execute(data: ResourceData): PatchResult { val youtubePackage = "com.google.android.youtube" SettingsPatch.addPreference( @@ -102,6 +107,10 @@ class SponsorBlockResourcePatch : ResourcePatch() { } }.close() // close afterwards + reelButtonGroupResourceId = ResourceIdMappingProviderResourcePatch.resourceMappings.single { + it.type == "id" && it.name == "reel_persistent_edu_button_group" + }.id + return PatchResultSuccess() } } \ No newline at end of file