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:
disable-autoplay-button
patch (#79)
- Loading branch information
Showing
4 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...revanced/patches/youtube/layout/autoplaybutton/annotations/AutoplayButtonCompatibility.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.autoplaybutton.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf("17.25.34") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class AutoplayButtonCompatibility |
38 changes: 38 additions & 0 deletions
38
...revanced/patches/youtube/layout/autoplaybutton/fingerprints/AutonavInformerFingerprint.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,38 @@ | ||
package app.revanced.patches.youtube.layout.autoplaybutton.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.annotation.FuzzyPatternScanMethod | ||
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.autoplaybutton.annotations.AutoplayButtonCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("autonav-informer-fingerprint") | ||
@MatchingMethod( | ||
"com/google/android/libraries/youtube/player/features/prefetch/WillAutonavInformer;", "k" | ||
) | ||
@FuzzyPatternScanMethod(2) | ||
@AutoplayButtonCompatibility | ||
@Version("0.0.1") | ||
object AutonavInformerFingerprint : MethodFingerprint( | ||
"Z", | ||
AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
null, | ||
listOf( | ||
Opcode.IGET_BOOLEAN, | ||
Opcode.IF_EQZ, | ||
Opcode.IGET_BOOLEAN, | ||
Opcode.RETURN, | ||
Opcode.IGET_OBJECT, | ||
Opcode.INVOKE_INTERFACE, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.CHECK_CAST, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT, | ||
), | ||
null, | ||
{ it.definingClass.endsWith("WillAutonavInformer;") } | ||
) |
32 changes: 32 additions & 0 deletions
32
...vanced/patches/youtube/layout/autoplaybutton/fingerprints/LayoutConstructorFingerprint.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.autoplaybutton.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.annotation.FuzzyPatternScanMethod | ||
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.autoplaybutton.annotations.AutoplayButtonCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("layout-constructor-fingerprint") | ||
@MatchingMethod( | ||
"Lcom/google/android/apps/youtube/app/player/overlay/YouTubeControlsOverlay;", "F" | ||
) | ||
@FuzzyPatternScanMethod(2) | ||
@AutoplayButtonCompatibility | ||
@Version("0.0.1") | ||
object LayoutConstructorFingerprint : MethodFingerprint( | ||
"V", | ||
AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
null, | ||
listOf( | ||
Opcode.CONST, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.CHECK_CAST, | ||
Opcode.INVOKE_VIRTUAL, | ||
), | ||
listOf("1.0x") | ||
) |
61 changes: 61 additions & 0 deletions
61
...in/app/revanced/patches/youtube/layout/autoplaybutton/patch/AutoplayButtonRemoverPatch.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,61 @@ | ||
package app.revanced.patches.youtube.layout.autoplaybutton.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.removeInstructions | ||
import app.revanced.patcher.extensions.replaceInstructions | ||
import app.revanced.patcher.patch.PatchResult | ||
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.autoplaybutton.annotations.AutoplayButtonCompatibility | ||
import app.revanced.patches.youtube.layout.autoplaybutton.fingerprints.AutonavInformerFingerprint | ||
import app.revanced.patches.youtube.layout.autoplaybutton.fingerprints.LayoutConstructorFingerprint | ||
import app.revanced.patches.youtube.misc.mapping.patch.ResourceIdMappingProviderResourcePatch | ||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction | ||
|
||
@Patch | ||
@Dependencies(dependencies = [ResourceIdMappingProviderResourcePatch::class]) | ||
@Name("disable-autoplay-button") | ||
@Description("Disable the autoplay button.") | ||
@AutoplayButtonCompatibility | ||
@Version("0.0.1") | ||
class AutoplayButtonRemoverPatch : BytecodePatch( | ||
listOf( | ||
LayoutConstructorFingerprint, AutonavInformerFingerprint | ||
) | ||
) { | ||
override fun execute(data: BytecodeData): PatchResult { | ||
val layoutGenMethod = LayoutConstructorFingerprint.result!!.mutableMethod | ||
|
||
val autonavToggle = | ||
ResourceIdMappingProviderResourcePatch.resourceMappings.first { it.type == "id" && it.name == "autonav_toggle" } | ||
val autonavPreviewStub = | ||
ResourceIdMappingProviderResourcePatch.resourceMappings.first { it.type == "id" && it.name == "autonav_preview_stub" } | ||
|
||
val autonavToggleConstIndex = | ||
layoutGenMethod.implementation!!.instructions.indexOfFirst { (it as? WideLiteralInstruction)?.wideLiteral == autonavToggle.id } | ||
val autonavPreviewStubConstIndex = | ||
layoutGenMethod.implementation!!.instructions.indexOfFirst { (it as? WideLiteralInstruction)?.wideLiteral == autonavPreviewStub.id } | ||
|
||
//remove adding autoplay button to the layout | ||
layoutGenMethod.removeInstructions(autonavToggleConstIndex, 5) | ||
layoutGenMethod.removeInstructions(autonavPreviewStubConstIndex, 5) | ||
|
||
val autonavInformerMethod = AutonavInformerFingerprint.result!!.mutableMethod | ||
|
||
//force disable autoplay since it's hard to do without the button | ||
autonavInformerMethod.replaceInstructions( | ||
0, | ||
""" | ||
const/4 v0, 0x0 | ||
return v0 | ||
""" | ||
) | ||
|
||
return PatchResultSuccess() | ||
} | ||
} |