diff --git a/src/main/kotlin/crimera/patches/twitter/ads/timelineEntryHook/HideVideosForYou.kt b/src/main/kotlin/crimera/patches/twitter/ads/timelineEntryHook/HideVideosForYou.kt new file mode 100644 index 00000000..f8f9d8bb --- /dev/null +++ b/src/main/kotlin/crimera/patches/twitter/ads/timelineEntryHook/HideVideosForYou.kt @@ -0,0 +1,23 @@ +package crimera.patches.twitter.ads.timelineEntryHook + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import crimera.patches.twitter.misc.settings.SettingsPatch +import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFingerprint + +@Patch( + name = "Remove videos for you", + description = "Removes \"videos for you\" from explore", + dependencies = [SettingsPatch::class,TimelineModuleItemHookPatch::class], + compatiblePackages = [CompatiblePackage("com.twitter.android")], + use = true +) +object HideVideosForYou :BytecodePatch( + setOf(SettingsStatusLoadFingerprint) +){ + override fun execute(context: BytecodeContext) { + SettingsStatusLoadFingerprint.enableSettings("hideVideosForYou") + } +} \ No newline at end of file diff --git a/src/main/kotlin/crimera/patches/twitter/ads/timelineEntryHook/TimelineModuleItemHookPatch.kt b/src/main/kotlin/crimera/patches/twitter/ads/timelineEntryHook/TimelineModuleItemHookPatch.kt new file mode 100644 index 00000000..6b547917 --- /dev/null +++ b/src/main/kotlin/crimera/patches/twitter/ads/timelineEntryHook/TimelineModuleItemHookPatch.kt @@ -0,0 +1,45 @@ +package crimera.patches.twitter.ads.timelineEntryHook + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstructions +import app.revanced.patcher.fingerprint.MethodFingerprint +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchException +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import com.android.tools.smali.dexlib2.Opcode +import crimera.patches.twitter.misc.settings.SettingsPatch + +object TimelineModuleItemHookFingerprint:MethodFingerprint( + returnType = "Ljava/lang/Object", + customFingerprint = {it,_-> + it.definingClass == "Lcom/twitter/model/json/timeline/urt/JsonTimelineModuleItem\$\$JsonObjectMapper;" && it.name == "parse" + } +) + +@Patch( + compatiblePackages = [CompatiblePackage("com.twitter.android")], +) +object TimelineModuleItemHookPatch:BytecodePatch( + setOf(TimelineModuleItemHookFingerprint) +){ + override fun execute(context: BytecodeContext) { + val TIMELINE_ENTRY_DESCRIPTOR = "${SettingsPatch.PATCHES_DESCRIPTOR}/TimelineEntry" + + val result = TimelineModuleItemHookFingerprint.result + ?:throw PatchException("TimelineModuleItemHookFingerprint not found") + + val methods = result.mutableMethod + val instructions = methods.getInstructions() + + val returnObj = instructions.last { it.opcode == Opcode.RETURN_OBJECT }.location.index + + methods.addInstructions(returnObj,""" + invoke-static {p1}, $TIMELINE_ENTRY_DESCRIPTOR;->checkEntry(Lcom/twitter/model/json/timeline/urt/JsonTimelineModuleItem;)Lcom/twitter/model/json/timeline/urt/JsonTimelineModuleItem; + move-result-object p1 + """.trimIndent()) + + //end + } +} \ No newline at end of file diff --git a/src/main/resources/twitter/settings/values/strings.xml b/src/main/resources/twitter/settings/values/strings.xml index bdbe6f4f..18d63946 100644 --- a/src/main/resources/twitter/settings/values/strings.xml +++ b/src/main/resources/twitter/settings/values/strings.xml @@ -34,6 +34,7 @@ Google ads Main event (Explore) Superhero event (Explore) + videos for you "Who to follow" section "Creators to subscribe" section "Community to join" section