mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-11 12:04:39 +02:00
feat(YouTube/Swipe controls) add Enable swipe to change video
setting (YouTube 19.19.39+)
This commit is contained in:
parent
33cd741081
commit
30f5cb50e4
@ -2,13 +2,13 @@ package app.revanced.patches.youtube.swipe.controls
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
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.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||
import app.revanced.patcher.util.smali.ExternalLabel
|
||||
import app.revanced.patches.youtube.swipe.controls.fingerprints.FullScreenEngagementOverlayFingerprint
|
||||
import app.revanced.patches.youtube.swipe.controls.fingerprints.HDRBrightnessFingerprint
|
||||
import app.revanced.patches.youtube.swipe.controls.fingerprints.SwipeToSwitchVideoFingerprint
|
||||
import app.revanced.patches.youtube.swipe.controls.fingerprints.WatchPanelGesturesFingerprint
|
||||
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.INTEGRATIONS_PATH
|
||||
@ -23,14 +23,13 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts
|
||||
import app.revanced.util.ResourceGroup
|
||||
import app.revanced.util.copyResources
|
||||
import app.revanced.util.getTargetIndex
|
||||
import app.revanced.util.getWideLiteralInstructionIndex
|
||||
import app.revanced.util.literalInstructionBooleanHook
|
||||
import app.revanced.util.patch.BaseBytecodePatch
|
||||
import app.revanced.util.resultOrThrow
|
||||
import app.revanced.util.transformMethods
|
||||
import app.revanced.util.traverseClassHierarchy
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
|
||||
|
||||
@ -49,6 +48,7 @@ object SwipeControlsPatch : BaseBytecodePatch(
|
||||
fingerprints = setOf(
|
||||
FullScreenEngagementOverlayFingerprint,
|
||||
HDRBrightnessFingerprint,
|
||||
SwipeToSwitchVideoFingerprint,
|
||||
WatchPanelGesturesFingerprint
|
||||
)
|
||||
) {
|
||||
@ -101,74 +101,63 @@ object SwipeControlsPatch : BaseBytecodePatch(
|
||||
|
||||
// endregion
|
||||
|
||||
var settingArray = arrayOf(
|
||||
"PREFERENCE_SCREEN: SWIPE_CONTROLS"
|
||||
)
|
||||
|
||||
// region patch for disable HDR auto brightness
|
||||
|
||||
HDRBrightnessFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
addInstructionsWithLabels(
|
||||
0, """
|
||||
invoke-static {}, $INTEGRATIONS_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableHDRAutoBrightness()Z
|
||||
move-result v0
|
||||
if-eqz v0, :default
|
||||
return-void
|
||||
""", ExternalLabel("default", getInstruction(0))
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add settings
|
||||
*/
|
||||
SettingsPatch.addPreference(
|
||||
arrayOf(
|
||||
"PREFERENCE_CATEGORY: SWIPE_CONTROLS_EXPERIMENTAL_FLAGS",
|
||||
"SETTINGS: DISABLE_HDR_BRIGHTNESS"
|
||||
)
|
||||
// Since it does not support all versions,
|
||||
// add settings only if the patch is successful.
|
||||
HDRBrightnessFingerprint.result?.mutableMethod?.apply {
|
||||
addInstructionsWithLabels(
|
||||
0, """
|
||||
invoke-static {}, $INTEGRATIONS_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableHDRAutoBrightness()Z
|
||||
move-result v0
|
||||
if-eqz v0, :default
|
||||
return-void
|
||||
""", ExternalLabel("default", getInstruction(0))
|
||||
)
|
||||
} // no exceptions are raised for compatibility with all versions.
|
||||
|
||||
settingArray += "PREFERENCE_CATEGORY: SWIPE_CONTROLS_EXPERIMENTAL_FLAGS"
|
||||
settingArray += "SETTINGS: DISABLE_HDR_BRIGHTNESS"
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region patch for enable swipe to switch video
|
||||
|
||||
// Since it does not support all versions,
|
||||
// add settings only if the patch is successful.
|
||||
SwipeToSwitchVideoFingerprint.result?.let {
|
||||
SwipeToSwitchVideoFingerprint.literalInstructionBooleanHook(
|
||||
45631116,
|
||||
"$INTEGRATIONS_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->enableSwipeToSwitchVideo()Z"
|
||||
)
|
||||
|
||||
settingArray += "PREFERENCE_CATEGORY: SWIPE_CONTROLS_EXPERIMENTAL_FLAGS"
|
||||
settingArray += "SETTINGS: ENABLE_SWIPE_TO_SWITCH_VIDEO"
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region patch for enable watch panel gestures
|
||||
|
||||
// Even if it fails to resolve the fingerprint, the [Swipe controls] patch should succeed.
|
||||
// So instead of throwing an exception, it just prints WARNING.
|
||||
// Since it does not support all versions,
|
||||
// add settings only if the patch is successful.
|
||||
WatchPanelGesturesFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
val literalIndex = getWideLiteralInstructionIndex(45372793)
|
||||
val targetIndex = getTargetIndex(literalIndex, Opcode.MOVE_RESULT)
|
||||
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
|
||||
|
||||
addInstructions(
|
||||
targetIndex + 1, """
|
||||
invoke-static {}, $INTEGRATIONS_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->enableWatchPanelGestures()Z
|
||||
move-result v$targetRegister
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add settings
|
||||
*/
|
||||
SettingsPatch.addPreference(
|
||||
arrayOf(
|
||||
"PREFERENCE_CATEGORY: SWIPE_CONTROLS_EXPERIMENTAL_FLAGS",
|
||||
"SETTINGS: ENABLE_WATCH_PANEL_GESTURES"
|
||||
)
|
||||
WatchPanelGesturesFingerprint.literalInstructionBooleanHook(
|
||||
45372793,
|
||||
"$INTEGRATIONS_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->enableWatchPanelGestures()Z"
|
||||
)
|
||||
} ?: println("WARNING: Failed to resolve WatchPanelGesturesFingerprint")
|
||||
|
||||
settingArray += "PREFERENCE_CATEGORY: SWIPE_CONTROLS_EXPERIMENTAL_FLAGS"
|
||||
settingArray += "SETTINGS: ENABLE_WATCH_PANEL_GESTURES"
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
/**
|
||||
* Add settings
|
||||
*/
|
||||
SettingsPatch.addPreference(
|
||||
arrayOf(
|
||||
"PREFERENCE_SCREEN: SWIPE_CONTROLS"
|
||||
)
|
||||
)
|
||||
|
||||
SettingsPatch.updatePatchStatus(this)
|
||||
// region copy resources
|
||||
|
||||
contexts.copyResources(
|
||||
"youtube/swipecontrols",
|
||||
@ -180,5 +169,14 @@ object SwipeControlsPatch : BaseBytecodePatch(
|
||||
"ic_sc_volume_normal.xml"
|
||||
)
|
||||
)
|
||||
|
||||
// endregion
|
||||
|
||||
/**
|
||||
* Add settings
|
||||
*/
|
||||
SettingsPatch.addPreference(settingArray)
|
||||
|
||||
SettingsPatch.updatePatchStatus(this)
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package app.revanced.patches.youtube.swipe.controls.fingerprints
|
||||
|
||||
import app.revanced.util.fingerprint.LiteralValueFingerprint
|
||||
|
||||
/**
|
||||
* This fingerprint is compatible with YouTube v19.19.39+
|
||||
*/
|
||||
internal object SwipeToSwitchVideoFingerprint : LiteralValueFingerprint(
|
||||
returnType = "V",
|
||||
literalSupplier = { 45631116 }
|
||||
)
|
@ -2,6 +2,9 @@ package app.revanced.patches.youtube.swipe.controls.fingerprints
|
||||
|
||||
import app.revanced.util.fingerprint.LiteralValueFingerprint
|
||||
|
||||
/**
|
||||
* This fingerprint is compatible with YouTube v18.29.38+
|
||||
*/
|
||||
internal object WatchPanelGesturesFingerprint : LiteralValueFingerprint(
|
||||
returnType = "V",
|
||||
literalSupplier = { 45372793 }
|
||||
|
@ -1111,6 +1111,9 @@ Limitation: Official headers in search results will be hidden."</string>
|
||||
<string name="revanced_enable_watch_panel_gestures_title">Enable watch panel gestures</string>
|
||||
<string name="revanced_enable_watch_panel_gestures_summary_on">Entering fullscreen when swiping down below the video player is enabled.</string>
|
||||
<string name="revanced_enable_watch_panel_gestures_summary_off">Entering fullscreen when swiping down below the video player is disabled.</string>
|
||||
<string name="revanced_enable_swipe_to_switch_video_title">Enable swipe to change video</string>
|
||||
<string name="revanced_enable_swipe_to_switch_video_summary_on">Swiping up / down will play the next / previous video.</string>
|
||||
<string name="revanced_enable_swipe_to_switch_video_summary_off">Swiping up / down will not play the next / previous video.</string>
|
||||
<string name="revanced_swipe_lowest_value_auto_brightness_overlay_text">Auto</string>
|
||||
|
||||
|
||||
|
@ -504,6 +504,9 @@
|
||||
<!-- SETTINGS: DISABLE_HDR_BRIGHTNESS
|
||||
<SwitchPreference android:title="@string/revanced_disable_hdr_auto_brightness_title" android:key="revanced_disable_hdr_auto_brightness" android:summaryOn="@string/revanced_disable_hdr_auto_brightness_summary_on" android:summaryOff="@string/revanced_disable_hdr_auto_brightness_summary_off" />SETTINGS: DISABLE_HDR_BRIGHTNESS -->
|
||||
|
||||
<!-- SETTINGS: ENABLE_SWIPE_TO_SWITCH_VIDEO
|
||||
<SwitchPreference android:title="@string/revanced_enable_swipe_to_switch_video_title" android:key="revanced_enable_swipe_to_switch_video" android:summaryOn="@string/revanced_enable_swipe_to_switch_video_summary_on" android:summaryOff="@string/revanced_enable_swipe_to_switch_video_summary_off" />SETTINGS: ENABLE_SWIPE_TO_SWITCH_VIDEO -->
|
||||
|
||||
<!-- SETTINGS: ENABLE_WATCH_PANEL_GESTURES
|
||||
<SwitchPreference android:title="@string/revanced_enable_watch_panel_gestures_title" android:key="revanced_enable_watch_panel_gestures" android:summaryOn="@string/revanced_enable_watch_panel_gestures_summary_on" android:summaryOff="@string/revanced_enable_watch_panel_gestures_summary_off" />SETTINGS: ENABLE_WATCH_PANEL_GESTURES -->
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user