@@ -4,98 +4,21 @@ import app.revanced.patcher.data.BytecodeContext
44import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
55import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
66import app.revanced.patcher.patch.BytecodePatch
7- import app.revanced.patcher.patch.PatchException
87import app.revanced.patcher.patch.annotation.Patch
98import app.revanced.patcher.util.smali.ExternalLabel
10- import app.revanced.patches.youtube.player.overlaybuttons.fingerprints.PlayerButtonConstructorFingerprint
119import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
1210import app.revanced.patches.youtube.video.information.VideoInformationPatch
13- import app.revanced.util.addFieldAndInstructions
14- import app.revanced.util.getReference
15- import app.revanced.util.getTargetIndexWithReferenceOrThrow
16- import app.revanced.util.indexOfFirstInstruction
17- import app.revanced.util.indexOfFirstInstructionOrThrow
18- import app.revanced.util.resultOrThrow
19- import com.android.tools.smali.dexlib2.Opcode
20- import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
21- import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
22- import com.android.tools.smali.dexlib2.iface.reference.FieldReference
23- import com.android.tools.smali.dexlib2.iface.reference.MethodReference
2411
2512@Patch(dependencies = [VideoInformationPatch ::class ])
2613object OverlayButtonsBytecodePatch : BytecodePatch(
27- setOf( PlayerButtonConstructorFingerprint )
14+ emptySet( )
2815) {
2916 private const val INTEGRATIONS_ALWAYS_REPEAT_CLASS_DESCRIPTOR =
3017 " $UTILS_PATH /AlwaysRepeatPatch;"
3118
3219 override fun execute (context : BytecodeContext ) {
3320
34- // region patch for always repeat and pause
35-
36- PlayerButtonConstructorFingerprint .resultOrThrow().mutableMethod.apply {
37- val registerResolver = implementation!! .registerCount - parameters.size - 1 + 6 // p6
38-
39- var invokerObjectIndex = indexOfFirstInstruction {
40- opcode == Opcode .IPUT_OBJECT
41- && getReference<FieldReference >()?.definingClass == definingClass
42- && (this as TwoRegisterInstruction ).registerA == registerResolver
43- }
44- if (invokerObjectIndex < 0 ) {
45- val moveObjectIndex = indexOfFirstInstructionOrThrow {
46- (this as ? TwoRegisterInstruction )?.registerB == registerResolver
47- }
48- val moveObjectRegister =
49- getInstruction<TwoRegisterInstruction >(moveObjectIndex).registerA
50- invokerObjectIndex = indexOfFirstInstructionOrThrow(moveObjectIndex) {
51- opcode == Opcode .IPUT_OBJECT
52- && getReference<FieldReference >()?.definingClass == definingClass
53- && (this as TwoRegisterInstruction ).registerA == moveObjectRegister
54- }
55- }
56- val invokerObjectReference =
57- getInstruction<ReferenceInstruction >(invokerObjectIndex).reference
58-
59- val onClickListenerReferenceIndex =
60- getTargetIndexWithReferenceOrThrow(" <init>(Ljava/lang/Object;I[B)V" )
61- val onClickListenerReference =
62- getInstruction<ReferenceInstruction >(onClickListenerReferenceIndex).reference
63- val onClickListenerClass =
64- context.findClass((onClickListenerReference as MethodReference ).definingClass)!! .mutableClass
65-
66- var invokeInterfaceReference = " "
67- onClickListenerClass.methods.find { method -> method.name == " onClick" }
68- ?.apply {
69- val invokeInterfaceIndex =
70- getTargetIndexWithReferenceOrThrow(invokerObjectReference.toString()) + 1
71- if (getInstruction(invokeInterfaceIndex).opcode != Opcode .INVOKE_INTERFACE )
72- throw PatchException (" Opcode does not match" )
73- invokeInterfaceReference =
74- getInstruction<ReferenceInstruction >(invokeInterfaceIndex).reference.toString()
75- } ? : throw PatchException (" Could not find onClick method" )
76-
77- val alwaysRepeatMutableClass =
78- context.findClass(INTEGRATIONS_ALWAYS_REPEAT_CLASS_DESCRIPTOR )!! .mutableClass
79-
80- val smaliInstructions =
81- """
82- if-eqz v0, :ignore
83- iget-object v1, v0, $invokerObjectReference
84- if-eqz v1, :ignore
85- invoke-interface {v1}, $invokeInterfaceReference
86- :ignore
87- return-void
88- """
89-
90- alwaysRepeatMutableClass.addFieldAndInstructions(
91- context,
92- " pauseVideo" ,
93- " pauseButtonClass" ,
94- definingClass,
95- smaliInstructions,
96- true
97- )
98- }
21+ // region patch for always repeat
9922
10023 VideoInformationPatch .videoEndMethod.apply {
10124 addInstructionsWithLabels(
0 commit comments