2022-07-11 08:56:33 +02:00
|
|
|
package app.revanced.patches.youtube.misc.autorepeat.patch
|
2022-07-09 15:53:33 +02:00
|
|
|
|
|
|
|
import app.revanced.patcher.annotation.Description
|
|
|
|
import app.revanced.patcher.annotation.Name
|
|
|
|
import app.revanced.patcher.annotation.Version
|
|
|
|
import app.revanced.patcher.data.impl.BytecodeData
|
|
|
|
import app.revanced.patcher.extensions.addInstructions
|
|
|
|
import app.revanced.patcher.extensions.removeInstruction
|
|
|
|
import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils.resolve
|
|
|
|
import app.revanced.patcher.patch.PatchResult
|
|
|
|
import app.revanced.patcher.patch.PatchResultError
|
|
|
|
import app.revanced.patcher.patch.PatchResultSuccess
|
2022-08-03 03:53:35 +02:00
|
|
|
import app.revanced.patcher.patch.annotations.DependsOn
|
2022-07-09 15:53:33 +02:00
|
|
|
import app.revanced.patcher.patch.annotations.Patch
|
|
|
|
import app.revanced.patcher.patch.impl.BytecodePatch
|
2022-07-11 08:56:33 +02:00
|
|
|
import app.revanced.patches.youtube.misc.autorepeat.annotations.AutoRepeatCompatibility
|
|
|
|
import app.revanced.patches.youtube.misc.autorepeat.fingerprints.AutoRepeatFingerprint
|
|
|
|
import app.revanced.patches.youtube.misc.autorepeat.fingerprints.AutoRepeatParentFingerprint
|
2022-07-09 15:53:33 +02:00
|
|
|
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
|
|
|
|
2022-07-31 12:15:26 +02:00
|
|
|
@Patch
|
2022-08-03 03:53:35 +02:00
|
|
|
@DependsOn([IntegrationsPatch::class])
|
2022-07-24 11:46:18 +02:00
|
|
|
@Name("always-autorepeat")
|
|
|
|
@Description("Always repeats the playing video again.")
|
2022-07-09 15:53:33 +02:00
|
|
|
@AutoRepeatCompatibility
|
|
|
|
@Version("0.0.1")
|
|
|
|
class AutoRepeatPatch : BytecodePatch(
|
|
|
|
listOf(
|
|
|
|
AutoRepeatParentFingerprint
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
override fun execute(data: BytecodeData): PatchResult {
|
|
|
|
//Get Result from the ParentFingerprint which is the playMethod we need to get.
|
|
|
|
val parentResult = AutoRepeatParentFingerprint.result
|
|
|
|
?: return PatchResultError("ParentFingerprint did not resolve.")
|
|
|
|
|
|
|
|
//this one needs to be called when app/revanced/integrations/patches/AutoRepeatPatch;->shouldAutoRepeat() returns true
|
|
|
|
val playMethod = parentResult.mutableMethod
|
|
|
|
AutoRepeatFingerprint.resolve(data, parentResult.classDef)
|
|
|
|
//String is: Laamp;->E()V
|
|
|
|
val methodToCall = playMethod.definingClass + "->" + playMethod.name + "()V";
|
|
|
|
|
|
|
|
//This is the method we search for
|
|
|
|
val result = AutoRepeatFingerprint.result
|
|
|
|
?: return PatchResultError("FingerPrint did not resolve.")
|
|
|
|
val method = result.mutableMethod
|
|
|
|
|
|
|
|
//Instructions to add to the smali code
|
|
|
|
val instructions = """
|
|
|
|
invoke-static {}, Lapp/revanced/integrations/patches/AutoRepeatPatch;->shouldAutoRepeat()Z
|
|
|
|
move-result v0
|
|
|
|
if-eqz v0, :noautorepeat
|
2022-07-11 08:56:33 +02:00
|
|
|
invoke-virtual {p0}, $methodToCall
|
2022-07-09 15:53:33 +02:00
|
|
|
:noautorepeat
|
|
|
|
return-void
|
|
|
|
"""
|
|
|
|
|
|
|
|
//Get the implementation so we can do a check for null and get instructions size.
|
|
|
|
val implementation = method.implementation
|
|
|
|
?: return PatchResultError("No Method Implementation found!")
|
|
|
|
|
|
|
|
//Since addInstructions needs an index which starts counting at 0 and size starts counting at 1,
|
|
|
|
//we have to remove 1 to get the latest instruction
|
2022-07-16 17:32:03 +02:00
|
|
|
val index = implementation.instructions.size - 1
|
2022-07-09 15:53:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
//remove last instruction which is return-void
|
|
|
|
method.removeInstruction(index)
|
|
|
|
// Add our own instructions there
|
|
|
|
method.addInstructions(index, instructions)
|
|
|
|
|
|
|
|
//Everything worked as expected, return Success
|
|
|
|
return PatchResultSuccess()
|
|
|
|
}
|
|
|
|
}
|