generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
autorepeat-by-default
patch (#106)
- Loading branch information
Showing
5 changed files
with
157 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...lin/app/revanced/patches/youtube/layout/autorepeat/annotations/AutoRepeatCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package app.revanced.patches.youtube.layout.autorepeat.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf("17.24.35", "17.25.34") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class AutoRepeatCompatibility |
32 changes: 32 additions & 0 deletions
32
...tlin/app/revanced/patches/youtube/layout/autorepeat/fingerprints/AutoRepeatFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package app.revanced.patches.youtube.layout.autorepeat.fingerprints | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod | ||
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod | ||
import app.revanced.patches.youtube.layout.autorepeat.annotations.AutoRepeatCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
|
||
@Name("auto-repeat-fingerprint") | ||
@MatchingMethod( | ||
"Laamp;", "ae" | ||
) | ||
@FuzzyPatternScanMethod(2) | ||
@AutoRepeatCompatibility | ||
@Version("0.0.1") | ||
//Finds method: | ||
/* | ||
public final void ae() { | ||
aq(aabj.ENDED); | ||
} | ||
*/ | ||
object AutoRepeatFingerprint : MethodFingerprint( | ||
"V", | ||
AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
null, | ||
null, | ||
null, | ||
customFingerprint = { methodDef -> methodDef.implementation!!.instructions.count() == 3 } | ||
) |
35 changes: 35 additions & 0 deletions
35
...pp/revanced/patches/youtube/layout/autorepeat/fingerprints/AutoRepeatParentFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package app.revanced.patches.youtube.layout.autorepeat.fingerprints | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod | ||
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod | ||
import app.revanced.patches.youtube.layout.autorepeat.annotations.AutoRepeatCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
|
||
@Name("auto-repeat-parent-fingerprint") | ||
@MatchingMethod( | ||
"Laamp;", "E" | ||
) | ||
@FuzzyPatternScanMethod(2) | ||
@AutoRepeatCompatibility | ||
@Version("0.0.1") | ||
//This Fingerprints finds the play() method needed to be called when AutoRepeatPatch.shouldAutoRepeat() == true | ||
/* | ||
public final void E() { | ||
Stuff happens | ||
String str = "play() called when the player wasn't loaded."; | ||
String str2 = "play() blocked because Background Playability failed"; | ||
Stuff happens again | ||
} | ||
*/ | ||
object AutoRepeatParentFingerprint : MethodFingerprint( | ||
"V", | ||
AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
null, | ||
null, | ||
listOf("play() called when the player wasn't loaded.", "play() blocked because Background Playability failed"), | ||
null | ||
) |
76 changes: 76 additions & 0 deletions
76
src/main/kotlin/app/revanced/patches/youtube/layout/autorepeat/patch/AutoRepeatPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package app.revanced.patches.youtube.layout.autorepeat.patch | ||
|
||
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 | ||
import app.revanced.patcher.patch.annotations.Dependencies | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patcher.patch.impl.BytecodePatch | ||
import app.revanced.patches.youtube.layout.autorepeat.annotations.AutoRepeatCompatibility | ||
import app.revanced.patches.youtube.layout.autorepeat.fingerprints.AutoRepeatFingerprint | ||
import app.revanced.patches.youtube.layout.autorepeat.fingerprints.AutoRepeatParentFingerprint | ||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch | ||
|
||
@Patch(include = false) | ||
@Dependencies(dependencies = [IntegrationsPatch::class]) | ||
@Name("autorepeat-by-default") | ||
@Description("Enables auto repeating of videos by default.") | ||
@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 | ||
const/4 v0, 0x0 | ||
invoke-virtual {}, $methodToCall | ||
: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 | ||
val index = implementation.instructions.size-1 | ||
|
||
|
||
//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() | ||
} | ||
} |