Skip to content

Commit

Permalink
chore: Fix merge typo, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios committed Oct 27, 2024
1 parent a0317f6 commit a46094b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import app.revanced.patches.youtube.misc.playservice.is_19_17_or_greater
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.findInstructionIndicesReversed
import app.revanced.util.getReference
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/SlideToSeekPatch;"
internal const val EXTENSION_METHOD_DESCRIPTOR =
"Lapp/revanced/extension/youtube/patches/SlideToSeekPatch;->isSlideToSeekDisabled(Z)Z"

@Suppress("unused")
val enableSlideToSeekPatch = bytecodePatch(
Expand Down Expand Up @@ -59,51 +61,35 @@ val enableSlideToSeekPatch = bytecodePatch(
var modifiedMethods = false

// Restore the behaviour to slide to seek.
val checkIndex =
slideToSeekMatch.patternMatch!!.startIndex
val checkReference =
slideToSeekMatch.mutableMethod.getInstruction(checkIndex).getReference<MethodReference>()!!
val checkIndex = slideToSeekMatch.patternMatch!!.startIndex
val checkReference = slideToSeekMatch.mutableMethod.getInstruction(checkIndex)
.getReference<MethodReference>()!!

// A/B check method was only called on this class.
slideToSeekMatch.mutableClass.methods.forEach { method ->
method.implementation!!.instructions.forEachIndexed { index, instruction ->
if (instruction.opcode == Opcode.INVOKE_VIRTUAL &&
instruction.getReference<MethodReference>() == checkReference
) {
method.apply {
val targetRegister = getInstruction<OneRegisterInstruction>(index + 1).registerA

addInstructions(
index + 2,
"""
invoke-static { v$targetRegister }, $EXTENSION_CLASS_DESCRIPTOR
move-result v$targetRegister
""",
)
}

modifiedMethods = true
method.findInstructionIndicesReversed {
opcode == Opcode.INVOKE_VIRTUAL && getReference<MethodReference>() == checkReference
}.forEach { index ->
method.apply {
val register = getInstruction<OneRegisterInstruction>(index + 1).registerA

addInstructions(
index + 2,
"""
invoke-static { v$register }, $EXTENSION_METHOD_DESCRIPTOR
move-result v$register
"""
)
}

modifiedMethods = true
}
}

if (!modifiedMethods) throw PatchException("Could not find methods to modify")

// Disable the double speed seek gesture.
if (!is_19_17_or_greater) {
disableFastForwardLegacyMatch.mutableMethod.apply {
val insertIndex = disableFastForwardLegacyMatch.patternMatch!!.endIndex + 1
val targetRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA

addInstructions(
insertIndex,
"""
invoke-static { v$targetRegister }, $EXTENSION_CLASS_DESCRIPTOR
move-result v$targetRegister
""",
)
}
} else {
if (is_19_17_or_greater) {
arrayOf(
disableFastForwardGestureMatch,
disableFastForwardNoticeMatch,
Expand All @@ -115,12 +101,27 @@ val enableSlideToSeekPatch = bytecodePatch(
addInstructions(
targetIndex + 1,
"""
invoke-static { v$targetRegister }, $EXTENSION_CLASS_DESCRIPTOR
invoke-static { v$targetRegister }, $EXTENSION_METHOD_DESCRIPTOR
move-result v$targetRegister
""",
)
}
}
} else {
disableFastForwardLegacyMatch.let {
it.mutableMethod.apply {
val insertIndex = it.patternMatch!!.endIndex + 1
val targetRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA

addInstructions(
insertIndex,
"""
invoke-static { v$targetRegister }, $EXTENSION_METHOD_DESCRIPTOR
move-result v$targetRegister
"""
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ internal val disableFastForwardNoticeFingerprint = fingerprint {
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
)
strings("Failed to easy seek haptics vibrate")
strings("search_landing_cache_key", "batterymanager")
custom { method, _ ->
method.name == "run"
}
}

internal val onTouchEventHandlerFingerprint = fingerprint(fuzzyPatternScanThreshold = 3) {
Expand Down Expand Up @@ -107,7 +110,7 @@ internal val seekbarTappingFingerprint = fingerprint {

internal val slideToSeekFingerprint = fingerprint {
accessFlags(AccessFlags.PRIVATE, AccessFlags.FINAL)
returns("Z")
returns("V")
parameters("Landroid/view/View;", "F")
opcodes(
Opcode.INVOKE_VIRTUAL,
Expand Down

0 comments on commit a46094b

Please sign in to comment.