Skip to content

Commit

Permalink
fix(YouTube/Overlay buttons): Always repeat button doesn't work whe…
Browse files Browse the repository at this point in the history
…n the video is minimized inotia00/ReVanced_Extended#2293
  • Loading branch information
inotia00 committed Aug 7, 2024
1 parent 1b73a5a commit ecd96f2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,98 +4,21 @@ import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.player.overlaybuttons.fingerprints.PlayerButtonConstructorFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.util.addFieldAndInstructions
import app.revanced.util.getReference
import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

@Patch(dependencies = [VideoInformationPatch::class])
object OverlayButtonsBytecodePatch : BytecodePatch(
setOf(PlayerButtonConstructorFingerprint)
emptySet()
) {
private const val INTEGRATIONS_ALWAYS_REPEAT_CLASS_DESCRIPTOR =
"$UTILS_PATH/AlwaysRepeatPatch;"

override fun execute(context: BytecodeContext) {

// region patch for always repeat and pause

PlayerButtonConstructorFingerprint.resultOrThrow().mutableMethod.apply {
val registerResolver = implementation!!.registerCount - parameters.size - 1 + 6 // p6

var invokerObjectIndex = indexOfFirstInstruction {
opcode == Opcode.IPUT_OBJECT
&& getReference<FieldReference>()?.definingClass == definingClass
&& (this as TwoRegisterInstruction).registerA == registerResolver
}
if (invokerObjectIndex < 0) {
val moveObjectIndex = indexOfFirstInstructionOrThrow {
(this as? TwoRegisterInstruction)?.registerB == registerResolver
}
val moveObjectRegister =
getInstruction<TwoRegisterInstruction>(moveObjectIndex).registerA
invokerObjectIndex = indexOfFirstInstructionOrThrow(moveObjectIndex) {
opcode == Opcode.IPUT_OBJECT
&& getReference<FieldReference>()?.definingClass == definingClass
&& (this as TwoRegisterInstruction).registerA == moveObjectRegister
}
}
val invokerObjectReference =
getInstruction<ReferenceInstruction>(invokerObjectIndex).reference

val onClickListenerReferenceIndex =
getTargetIndexWithReferenceOrThrow("<init>(Ljava/lang/Object;I[B)V")
val onClickListenerReference =
getInstruction<ReferenceInstruction>(onClickListenerReferenceIndex).reference
val onClickListenerClass =
context.findClass((onClickListenerReference as MethodReference).definingClass)!!.mutableClass

var invokeInterfaceReference = ""
onClickListenerClass.methods.find { method -> method.name == "onClick" }
?.apply {
val invokeInterfaceIndex =
getTargetIndexWithReferenceOrThrow(invokerObjectReference.toString()) + 1
if (getInstruction(invokeInterfaceIndex).opcode != Opcode.INVOKE_INTERFACE)
throw PatchException("Opcode does not match")
invokeInterfaceReference =
getInstruction<ReferenceInstruction>(invokeInterfaceIndex).reference.toString()
} ?: throw PatchException("Could not find onClick method")

val alwaysRepeatMutableClass =
context.findClass(INTEGRATIONS_ALWAYS_REPEAT_CLASS_DESCRIPTOR)!!.mutableClass

val smaliInstructions =
"""
if-eqz v0, :ignore
iget-object v1, v0, $invokerObjectReference
if-eqz v1, :ignore
invoke-interface {v1}, $invokeInterfaceReference
:ignore
return-void
"""

alwaysRepeatMutableClass.addFieldAndInstructions(
context,
"pauseVideo",
"pauseButtonClass",
definingClass,
smaliInstructions,
true
)
}
// region patch for always repeat

VideoInformationPatch.videoEndMethod.apply {
addInstructionsWithLabels(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ object SharedResourceIdPatch : ResourcePatch() {
var Scrubbing = -1L
var SeekEasyHorizontalTouchOffsetToStartScrubbing = -1L
var SeekUndoEduOverlayStub = -1L
var SingleLoopEduSnackBarText = -1L
var SlidingDialogAnimation = -1L
var SubtitleMenuSettingsFooterInfo = -1L
var SuggestedAction = -1L
Expand Down Expand Up @@ -208,7 +207,6 @@ object SharedResourceIdPatch : ResourcePatch() {
SeekEasyHorizontalTouchOffsetToStartScrubbing =
getId(DIMEN, "seek_easy_horizontal_touch_offset_to_start_scrubbing")
SeekUndoEduOverlayStub = getId(ID, "seek_undo_edu_overlay_stub")
SingleLoopEduSnackBarText = getId(STRING, "single_loop_edu_snackbar_text")
SlidingDialogAnimation = getId(STYLE, "SlidingDialogAnimation")
SubtitleMenuSettingsFooterInfo = getId(STRING, "subtitle_menu_settings_footer_info")
SuggestedAction = getId(LAYOUT, "suggested_action")
Expand Down

0 comments on commit ecd96f2

Please sign in to comment.