diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/PlaybackSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/PlaybackSpeedPatch.kt index 3f7c17e7b4..54c4f4d6e0 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/PlaybackSpeedPatch.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/PlaybackSpeedPatch.kt @@ -1,15 +1,21 @@ package app.revanced.patches.tiktok.interaction.speed import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.tiktok.interaction.speed.fingerprints.ChangeSpeedFingerprint +import app.revanced.patches.tiktok.interaction.speed.fingerprints.GetSpeedFingerprint +import app.revanced.patches.tiktok.interaction.speed.fingerprints.OnRenderFirstFrameFingerprint import app.revanced.patches.tiktok.interaction.speed.fingerprints.SpeedControlParentFingerprint import app.revanced.util.exception import app.revanced.util.indexOfFirstInstruction import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction11x import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c import com.android.tools.smali.dexlib2.iface.reference.MethodReference @@ -22,7 +28,14 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference ] ) @Suppress("unused") -object PlaybackSpeedPatch : BytecodePatch(setOf(SpeedControlParentFingerprint)) { +object PlaybackSpeedPatch : BytecodePatch( + setOf( + SpeedControlParentFingerprint, + GetSpeedFingerprint, + OnRenderFirstFrameFingerprint, + ChangeSpeedFingerprint + ) +) { override fun execute(context: BytecodeContext) { SpeedControlParentFingerprint.result?.mutableMethod?.apply { val targetMethodCallIndex = indexOfFirstInstruction { @@ -45,5 +58,34 @@ object PlaybackSpeedPatch : BytecodePatch(setOf(SpeedControlParentFingerprint)) """ ) } ?: throw SpeedControlParentFingerprint.exception + + GetSpeedFingerprint.result?.mutableMethod?.apply { + val injectIndex = indexOfFirstInstruction { + opcode == Opcode.INVOKE_STATIC && ((this as Instruction35c).reference as MethodReference).returnType == "F" + } + 2 + val reg = (getInstruction(injectIndex - 1) as Instruction11x).registerA + addInstruction( + injectIndex, + "invoke-static { v$reg }, Lapp/revanced/tiktok/speed/SpeedPatch;->saveDefaultSpeed(F)V" + ) + } ?: throw GetSpeedFingerprint.exception + + OnRenderFirstFrameFingerprint.result?.mutableMethod?.apply { + ChangeSpeedFingerprint.result?.mutableMethod?.let { changeSpeedMethod -> + addInstructions( + 0, + """ + const/4 v0, 0x1 + invoke-virtual {p0, v0}, Lcom/ss/android/ugc/aweme/feed/panel/BaseListFragmentPanel;->getEnterFrom(Z)Ljava/lang/String; + move-result-object v0 + invoke-virtual {p0}, Lcom/ss/android/ugc/aweme/feed/panel/BaseListFragmentPanel;->getCurrentAweme()Lcom/ss/android/ugc/aweme/feed/model/Aweme; + move-result-object v1 + invoke-static {}, Lapp/revanced/tiktok/speed/SpeedPatch;->getDefaultSpeed()F + move-result-object v2 + invoke-static { v0, v1, v2 }, ${changeSpeedMethod.definingClass}->${changeSpeedMethod.name}(${changeSpeedMethod.parameterTypes[0]}${changeSpeedMethod.parameterTypes[1]}${changeSpeedMethod.parameterTypes[2]})V + """ + ) + } ?: throw ChangeSpeedFingerprint.exception + } ?: throw OnRenderFirstFrameFingerprint.exception } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/ChangeSpeedFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/ChangeSpeedFingerprint.kt new file mode 100644 index 0000000000..dca4a3a471 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/ChangeSpeedFingerprint.kt @@ -0,0 +1,30 @@ +package app.revanced.patches.tiktok.interaction.speed.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +internal object ChangeSpeedFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC, + parameters = listOf( + "Ljava/lang/String;", + "Lcom/ss/android/ugc/aweme/feed/model/Aweme;", + "F" + ), + opcodes = listOf( + Opcode.CONST_STRING, + Opcode.INVOKE_STATIC, + Opcode.SGET, + Opcode.SPUT_OBJECT, + Opcode.SPUT, + Opcode.SPUT, + Opcode.SGET_OBJECT, + Opcode.IF_EQZ, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.SGET_OBJECT + ), + strings = listOf("enterFrom") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/GetSpeedFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/GetSpeedFingerprint.kt new file mode 100644 index 0000000000..58a6239d42 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/GetSpeedFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.tiktok.interaction.speed.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal object GetSpeedFingerprint : MethodFingerprint( + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/BaseListFragmentPanel;") && + methodDef.name == "onFeedSpeedSelectedEvent" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/OnRenderFirstFrameFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/OnRenderFirstFrameFingerprint.kt new file mode 100644 index 0000000000..4b517026a3 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/OnRenderFirstFrameFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.tiktok.interaction.speed.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal object OnRenderFirstFrameFingerprint : MethodFingerprint( + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/BaseListFragmentPanel;") && + methodDef.name == "onRenderFirstFrame" + } +) \ No newline at end of file