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
|
2022-10-05 04:03:10 +02:00
|
|
|
import app.revanced.patcher.data.BytecodeContext
|
2023-06-07 03:46:13 +02:00
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
|
2022-09-21 04:11:16 +02:00
|
|
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
2022-10-05 04:03:10 +02:00
|
|
|
import app.revanced.patcher.patch.BytecodePatch
|
2023-08-27 21:40:49 +02:00
|
|
|
import app.revanced.patcher.patch.PatchException
|
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
|
2023-06-07 03:46:13 +02:00
|
|
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
|
|
|
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
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-08-22 01:59:43 +02:00
|
|
|
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
2022-07-09 15:53:33 +02:00
|
|
|
|
2022-07-31 12:15:26 +02:00
|
|
|
@Patch
|
2022-08-03 03:53:35 +02:00
|
|
|
@DependsOn([IntegrationsPatch::class])
|
2023-07-10 20:02:05 +02:00
|
|
|
@Name("Always autorepeat")
|
2022-07-24 11:46:18 +02:00
|
|
|
@Description("Always repeats the playing video again.")
|
2022-07-09 15:53:33 +02:00
|
|
|
@AutoRepeatCompatibility
|
|
|
|
class AutoRepeatPatch : BytecodePatch(
|
|
|
|
listOf(
|
|
|
|
AutoRepeatParentFingerprint
|
|
|
|
)
|
|
|
|
) {
|
2023-08-27 21:40:49 +02:00
|
|
|
override fun execute(context: BytecodeContext) {
|
2022-08-22 01:59:43 +02:00
|
|
|
SettingsPatch.PreferenceScreen.MISC.addPreferences(
|
|
|
|
SwitchPreference(
|
2023-05-15 09:51:43 +02:00
|
|
|
"revanced_auto_repeat",
|
|
|
|
StringResource("revanced_auto_repeat_title", "Enable auto-repeat"),
|
2022-08-22 01:59:43 +02:00
|
|
|
StringResource("revanced_auto_repeat_summary_on", "Auto-repeat is enabled"),
|
|
|
|
StringResource("revanced_auto_repeat_summary_off", "Auto-repeat is disabled")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2022-07-09 15:53:33 +02:00
|
|
|
//Get Result from the ParentFingerprint which is the playMethod we need to get.
|
|
|
|
val parentResult = AutoRepeatParentFingerprint.result
|
2023-08-27 21:40:49 +02:00
|
|
|
?: throw PatchException("ParentFingerprint did not resolve.")
|
2022-07-09 15:53:33 +02:00
|
|
|
|
|
|
|
//this one needs to be called when app/revanced/integrations/patches/AutoRepeatPatch;->shouldAutoRepeat() returns true
|
|
|
|
val playMethod = parentResult.mutableMethod
|
2022-10-05 04:03:10 +02:00
|
|
|
AutoRepeatFingerprint.resolve(context, parentResult.classDef)
|
2022-07-09 15:53:33 +02:00
|
|
|
//String is: Laamp;->E()V
|
2023-07-28 20:11:23 +02:00
|
|
|
val methodToCall = playMethod.definingClass + "->" + playMethod.name + "()V"
|
2022-07-09 15:53:33 +02:00
|
|
|
|
|
|
|
//This is the method we search for
|
|
|
|
val result = AutoRepeatFingerprint.result
|
2023-08-27 21:40:49 +02:00
|
|
|
?: throw PatchException("FingerPrint did not resolve.")
|
2022-07-09 15:53:33 +02:00
|
|
|
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
|
2023-08-27 21:40:49 +02:00
|
|
|
?: throw PatchException("No Method Implementation found!")
|
2022-07-09 15:53:33 +02:00
|
|
|
|
|
|
|
//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
|
2023-06-07 03:46:13 +02:00
|
|
|
method.addInstructionsWithLabels(index, instructions)
|
2022-07-09 15:53:33 +02:00
|
|
|
|
|
|
|
//Everything worked as expected, return Success
|
|
|
|
}
|
|
|
|
}
|