feat(YouTube - Swipe controls): Add settings - Disable swipe to enter fullscreen mode, Disable swipe to exit fullscreen mode & Change default values ​​- Disable swipe to change video, Disable watch panel gestures

This commit is contained in:
inotia00
2025-01-03 22:00:04 +09:00
parent 1f95e07e7a
commit 01bd3141b3
6 changed files with 105 additions and 17 deletions

View File

@ -5,8 +5,12 @@ import app.revanced.patches.youtube.utils.resourceid.autoNavScrollCancelPadding
import app.revanced.patches.youtube.utils.resourceid.fullScreenEngagementOverlay
import app.revanced.util.containsLiteralInstruction
import app.revanced.util.fingerprint.legacyFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.or
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal val fullScreenEngagementOverlayFingerprint = legacyFingerprint(
name = "fullScreenEngagementOverlayFingerprint",
@ -73,3 +77,47 @@ internal val watchPanelGesturesChannelBarFingerprint = legacyFingerprint(
method.containsLiteralInstruction(WATCH_PANEL_GESTURES_SECONDARY_FEATURE_FLAG)
}
)
/**
* fuzzyPatternScanThreshold is required to maintain compatibility with YouTube v18.29.38 ~ v18.32.39.
*
* TODO: Remove fuzzyPatternScanThreshold if support for YouTube v18.29.38 to v18.32.39 is dropped.
*/
internal val playerGestureConfigSyntheticFingerprint = legacyFingerprint(
name = "playerGestureConfigSyntheticFingerprint",
fuzzyPatternScanThreshold = 5,
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Ljava/lang/Object;"),
opcodes = listOf(
Opcode.SGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.IF_EQZ,
Opcode.IF_EQZ,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_VIRTUAL, // playerGestureConfig.downAndOutLandscapeAllowed
Opcode.MOVE_RESULT,
Opcode.CHECK_CAST,
Opcode.IPUT_BOOLEAN,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_VIRTUAL, // playerGestureConfig.downAndOutPortraitAllowed
Opcode.MOVE_RESULT,
Opcode.IPUT_BOOLEAN,
Opcode.RETURN_VOID,
),
customFingerprint = { method, classDef ->
// This method is always called "a" because this kind of class always has a single method.
method.name == "a" &&
classDef.methods.count() == 2 &&
method.indexOfFirstInstruction {
val reference = getReference<MethodReference>()
reference?.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;" &&
reference.parameterTypes.isEmpty() &&
reference.returnType == "Z"
} >= 0
},
)

View File

@ -1,6 +1,7 @@
package app.revanced.patches.youtube.swipe.controls
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
@ -29,9 +30,11 @@ import app.revanced.patches.youtube.utils.settings.settingsPatch
import app.revanced.util.ResourceGroup
import app.revanced.util.copyResources
import app.revanced.util.fingerprint.injectLiteralInstructionBooleanCall
import app.revanced.util.fingerprint.matchOrThrow
import app.revanced.util.fingerprint.methodOrThrow
import app.revanced.util.fingerprint.mutableClassOrThrow
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstLiteralInstruction
import app.revanced.util.indexOfFirstLiteralInstructionOrThrow
@ -107,7 +110,7 @@ val swipeControlsPatch = bytecodePatch(
var settingArray = arrayOf(
"PREFERENCE_SCREEN: SWIPE_CONTROLS",
"SETTINGS: DISABLE_WATCH_PANEL_GESTURES"
"SETTINGS: DISABLE_SWIPE_TO_ENTER_FULLSCREEN_MODE_BELOW_THE_PLAYER"
)
// region patch for disable HDR auto brightness
@ -143,12 +146,12 @@ val swipeControlsPatch = bytecodePatch(
// endregion
// region patch for disable watch panel gestures
// region patch for disable swipe to enter fullscreen mode (below the player)
if (!is_19_36_or_greater) {
watchPanelGesturesFingerprint.injectLiteralInstructionBooleanCall(
WATCH_PANEL_GESTURES_PRIMARY_FEATURE_FLAG,
"$EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableWatchPanelGestures()Z"
"$EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableSwipeToEnterFullscreenModeBelowThePlayer()Z"
)
} else {
watchPanelGesturesAlternativeFingerprint.methodOrThrow().apply {
@ -188,7 +191,7 @@ val swipeControlsPatch = bytecodePatch(
addInstructionsWithLabels(
targetIndex, """
invoke-static {}, $EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableWatchPanelGestures()Z
invoke-static {}, $EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableSwipeToEnterFullscreenModeBelowThePlayer()Z
move-result v${fieldInstruction.registerA}
if-eqz v${fieldInstruction.registerA}, :disable
iget-object v${fieldInstruction.registerA}, v${fieldInstruction.registerB}, $fieldReference
@ -201,12 +204,38 @@ val swipeControlsPatch = bytecodePatch(
if (is_19_15_or_greater) {
watchPanelGesturesChannelBarFingerprint.injectLiteralInstructionBooleanCall(
WATCH_PANEL_GESTURES_SECONDARY_FEATURE_FLAG,
"$EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableWatchPanelGestures()Z"
"$EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableSwipeToEnterFullscreenModeBelowThePlayer()Z"
)
}
// endregion
// region patch for disable swipe to enter fullscreen mode (in the player) and disable swipe to exit fullscreen mode
playerGestureConfigSyntheticFingerprint.matchOrThrow().let {
val endIndex = it.patternMatch!!.endIndex
mapOf(
3 to "disableSwipeToEnterFullscreenModeInThePlayer",
9 to "disableSwipeToExitFullscreenMode"
).forEach { (offSet, methodName) ->
it.getWalkerMethod(endIndex - offSet).apply {
val index = implementation!!.instructions.lastIndex
val register = getInstruction<OneRegisterInstruction>(index).registerA
addInstructions(
index,
"""
invoke-static {v$register}, $EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->$methodName(Z)Z
move-result v$register
"""
)
}
}
}
// endregion
// region copy resources
getContext().copyResources(

View File

@ -134,16 +134,17 @@ fun Pair<String, Fingerprint>.injectLiteralInstructionViewCall(
internal fun legacyFingerprint(
name: String,
fuzzyPatternScanThreshold: Int = 0,
accessFlags: Int? = null,
returnType: String? = null,
parameters: List<String>? = null,
opcodes: List<Opcode?>? = null,
strings: List<String>? = null,
literals: List<Long>? = null,
customFingerprint: ((methodDef: Method, classDef: ClassDef) -> Boolean)? = null
customFingerprint: ((methodDef: Method, classDef: ClassDef) -> Boolean)? = null,
) = Pair(
name,
fingerprint {
fingerprint(fuzzyPatternScanThreshold = fuzzyPatternScanThreshold) {
if (accessFlags != null) {
accessFlags(accessFlags)
}