Skip to content

Commit

Permalink
feat(Twitter): Added Control video auto scroll patch
Browse files Browse the repository at this point in the history
  • Loading branch information
swakwork committed Jul 30, 2024
1 parent b601133 commit 7a21924
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package crimera.patches.twitter.timeline.enableVidAutoAdvance

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
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.iface.instruction.OneRegisterInstruction
import crimera.patches.twitter.misc.settings.SettingsPatch
import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFingerprint

object EnableVidAutoAdvancePatchFingerprint: MethodFingerprint(
strings = listOf("immersive_video_auto_advance_duration_threshold")
)


@Patch(
name = "Control video auto scroll",
description = "Control video auto scroll in immersive view",
compatiblePackages = [CompatiblePackage("com.twitter.android")],
dependencies = [SettingsPatch::class],
use = false
)
@Suppress("unused")
class EnableVidAutoAdvancePatch : BytecodePatch(
setOf(EnableVidAutoAdvancePatchFingerprint,SettingsStatusLoadFingerprint)
) {
override fun execute(context: BytecodeContext) {
val result = EnableVidAutoAdvancePatchFingerprint.result
?: throw PatchException("EnableVidAutoAdvancePatchFingerprint not found")

var strLoc: Int = 0
result.scanResult.stringsScanResult!!.matches.forEach{ match ->
val str = match.string
if(str.contains("immersive_video_auto_advance_duration_threshold")){
strLoc = match.index
return@forEach
}
}
if(strLoc==0){
throw PatchException("hook not found")
}

val method = result.mutableMethod
val instructions = method.getInstructions()
val loc = strLoc+2

val reg = method.getInstruction<OneRegisterInstruction>(loc).registerA
method.addInstruction(loc,"""
invoke-static {}, ${SettingsPatch.PREF_DESCRIPTOR};->enableVidAutoAdvance()I
""".trimIndent())

SettingsStatusLoadFingerprint.enableSettings("enableVidAutoAdvance")
}
}
2 changes: 2 additions & 0 deletions src/main/resources/twitter/settings/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
<string name="piko_pref_show_poll_result_desc">View poll results without voting</string>
<string name="piko_pref_hide_immersive_player">immersive player</string>
<string name="piko_pref_hide_immersive_player_desc">Removes swipe up for more videos in video player</string>
<string name="piko_pref_enable_vid_auto_advance">Enable video auto scroll</string>
<string name="piko_pref_enable_vid_auto_advance_desc">Enables video auto scroll in immersive view</string>
<string name="piko_pref_hide_hidden_replies">hidden replies</string>

<string name="piko_title_customisation">Customization</string>
Expand Down

0 comments on commit 7a21924

Please sign in to comment.