diff --git a/src/main/kotlin/crimera/patches/twitter/timeline/enableVidAutoAdvance/EnableVidAutoAdvancePatch.kt b/src/main/kotlin/crimera/patches/twitter/timeline/enableVidAutoAdvance/EnableVidAutoAdvancePatch.kt index bf39cf01..45c4fdaa 100644 --- a/src/main/kotlin/crimera/patches/twitter/timeline/enableVidAutoAdvance/EnableVidAutoAdvancePatch.kt +++ b/src/main/kotlin/crimera/patches/twitter/timeline/enableVidAutoAdvance/EnableVidAutoAdvancePatch.kt @@ -9,51 +9,55 @@ 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 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") +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 = true + use = true, ) @Suppress("unused") -class EnableVidAutoAdvancePatch : BytecodePatch( - setOf(EnableVidAutoAdvancePatchFingerprint,SettingsStatusLoadFingerprint) -) { +class EnableVidAutoAdvancePatch : + BytecodePatch( + setOf(EnableVidAutoAdvancePatchFingerprint, SettingsStatusLoadFingerprint), + ) { override fun execute(context: BytecodeContext) { - val result = EnableVidAutoAdvancePatchFingerprint.result - ?: throw PatchException("EnableVidAutoAdvancePatchFingerprint not found") + val result = + EnableVidAutoAdvancePatchFingerprint.result + ?: throw PatchException("EnableVidAutoAdvancePatchFingerprint not found") var strLoc: Int = 0 - result.scanResult.stringsScanResult!!.matches.forEach{ match -> + result.scanResult.stringsScanResult!!.matches.forEach { match -> val str = match.string - if(str.contains("immersive_video_auto_advance_duration_threshold")){ + if (str.contains("immersive_video_auto_advance_duration_threshold")) { strLoc = match.index return@forEach } } - if(strLoc==0){ + if (strLoc == 0) { throw PatchException("hook not found") } val method = result.mutableMethod val instructions = method.getInstructions() - val loc = strLoc+2 - + val loc = instructions.first { it.opcode == Opcode.MOVE_RESULT && it.location.index > strLoc }.location.index val reg = method.getInstruction(loc).registerA - method.addInstruction(loc,""" + method.addInstruction( + loc, + """ invoke-static {}, ${SettingsPatch.PREF_DESCRIPTOR};->enableVidAutoAdvance()I - """.trimIndent()) + """.trimIndent(), + ) SettingsStatusLoadFingerprint.enableSettings("enableVidAutoAdvance") } -} \ No newline at end of file +}