mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-13 05:37:40 +02:00
refactor(YouTube/Custom playback speed): move method of show playback speed flyout panel to VideoUtils
This commit is contained in:
@ -1,102 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.flyoutpanel.oldspeedlayout
|
|
||||||
|
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
|
|
||||||
import app.revanced.patcher.extensions.or
|
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
|
||||||
import app.revanced.patcher.patch.PatchException
|
|
||||||
import app.revanced.patcher.patch.annotation.Patch
|
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
|
|
||||||
import app.revanced.patches.shared.litho.LithoFilterPatch
|
|
||||||
import app.revanced.patches.youtube.flyoutpanel.oldspeedlayout.fingerprints.CustomPlaybackSpeedIntegrationsFingerprint
|
|
||||||
import app.revanced.patches.youtube.flyoutpanel.oldspeedlayout.fingerprints.PlaybackRateBottomSheetClassFingerprint
|
|
||||||
import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH
|
|
||||||
import app.revanced.patches.youtube.utils.integrations.Constants.VIDEO_PATH
|
|
||||||
import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch
|
|
||||||
import app.revanced.util.resultOrThrow
|
|
||||||
import com.android.tools.smali.dexlib2.AccessFlags
|
|
||||||
import com.android.tools.smali.dexlib2.immutable.ImmutableField
|
|
||||||
|
|
||||||
@Patch(
|
|
||||||
dependencies = [
|
|
||||||
BottomSheetRecyclerViewPatch::class,
|
|
||||||
LithoFilterPatch::class
|
|
||||||
]
|
|
||||||
)
|
|
||||||
object OldSpeedLayoutPatch : BytecodePatch(
|
|
||||||
setOf(
|
|
||||||
CustomPlaybackSpeedIntegrationsFingerprint,
|
|
||||||
PlaybackRateBottomSheetClassFingerprint
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
private const val FILTER_CLASS_DESCRIPTOR =
|
|
||||||
"$COMPONENTS_PATH/PlaybackSpeedMenuFilter;"
|
|
||||||
|
|
||||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
|
||||||
"$VIDEO_PATH/CustomPlaybackSpeedPatch;"
|
|
||||||
|
|
||||||
private lateinit var playbackRateBottomSheetClass: String
|
|
||||||
private lateinit var playbackRateBottomSheetBuilderMethod: String
|
|
||||||
|
|
||||||
override fun execute(context: BytecodeContext) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Input 'playbackRateBottomSheetClass' in FlyoutPanelPatch.
|
|
||||||
*/
|
|
||||||
PlaybackRateBottomSheetClassFingerprint.resultOrThrow().let {
|
|
||||||
it.mutableMethod.apply {
|
|
||||||
playbackRateBottomSheetClass = definingClass
|
|
||||||
playbackRateBottomSheetBuilderMethod =
|
|
||||||
it.mutableClass.methods.find { method -> method.parameters.isEmpty() && method.returnType == "V" }
|
|
||||||
?.name
|
|
||||||
?: throw PatchException("Could not find PlaybackRateBottomSheetBuilderMethod")
|
|
||||||
|
|
||||||
addInstruction(
|
|
||||||
0,
|
|
||||||
"sput-object p0, $INTEGRATIONS_CLASS_DESCRIPTOR->playbackRateBottomSheetClass:$playbackRateBottomSheetClass"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a static field in the patch
|
|
||||||
* Add a call the Playback Speed Bottom Sheet Fragment method
|
|
||||||
*/
|
|
||||||
CustomPlaybackSpeedIntegrationsFingerprint.resultOrThrow().let {
|
|
||||||
it.mutableMethod.apply {
|
|
||||||
// Create a static field 'playbackRateBottomSheetClass' in FlyoutPanelPatch.
|
|
||||||
it.mutableClass.staticFields.add(
|
|
||||||
ImmutableField(
|
|
||||||
definingClass,
|
|
||||||
"playbackRateBottomSheetClass",
|
|
||||||
playbackRateBottomSheetClass,
|
|
||||||
AccessFlags.PUBLIC or AccessFlags.STATIC,
|
|
||||||
null,
|
|
||||||
annotations,
|
|
||||||
null
|
|
||||||
).toMutable()
|
|
||||||
)
|
|
||||||
|
|
||||||
removeInstruction(1)
|
|
||||||
removeInstruction(0)
|
|
||||||
|
|
||||||
addInstructionsWithLabels(
|
|
||||||
0, """
|
|
||||||
sget-object v0, $INTEGRATIONS_CLASS_DESCRIPTOR->playbackRateBottomSheetClass:$playbackRateBottomSheetClass
|
|
||||||
if-nez v0, :not_null
|
|
||||||
return-void
|
|
||||||
:not_null
|
|
||||||
invoke-virtual {v0}, $playbackRateBottomSheetClass->$playbackRateBottomSheetBuilderMethod()V
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BottomSheetRecyclerViewPatch.injectCall("$INTEGRATIONS_CLASS_DESCRIPTOR->onFlyoutMenuCreate(Landroid/support/v7/widget/RecyclerView;)V")
|
|
||||||
|
|
||||||
LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.flyoutpanel.oldspeedlayout.fingerprints
|
|
||||||
|
|
||||||
import app.revanced.patcher.extensions.or
|
|
||||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
|
||||||
import com.android.tools.smali.dexlib2.AccessFlags
|
|
||||||
|
|
||||||
internal object CustomPlaybackSpeedIntegrationsFingerprint : MethodFingerprint(
|
|
||||||
returnType = "V",
|
|
||||||
accessFlags = AccessFlags.PRIVATE or AccessFlags.STATIC,
|
|
||||||
parameters = emptyList(),
|
|
||||||
customFingerprint = { methodDef, _ ->
|
|
||||||
methodDef.definingClass.endsWith("/CustomPlaybackSpeedPatch;")
|
|
||||||
&& methodDef.name == "showOldPlaybackSpeedMenu"
|
|
||||||
}
|
|
||||||
)
|
|
@ -0,0 +1,73 @@
|
|||||||
|
package app.revanced.patches.youtube.utils.flyoutpanel
|
||||||
|
|
||||||
|
import app.revanced.patcher.patch.annotation.Patch
|
||||||
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
||||||
|
import app.revanced.patcher.extensions.or
|
||||||
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
|
import app.revanced.patcher.patch.PatchException
|
||||||
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
|
||||||
|
import app.revanced.patches.youtube.utils.flyoutpanel.fingerprints.PlaybackRateBottomSheetClassFingerprint
|
||||||
|
import app.revanced.patches.youtube.utils.integrations.Constants.INTEGRATIONS_PATH
|
||||||
|
import app.revanced.util.resultOrThrow
|
||||||
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
|
import com.android.tools.smali.dexlib2.immutable.ImmutableField
|
||||||
|
|
||||||
|
@Patch(description = "Hooks YouTube to open the playback speed flyout panel in the integration.")
|
||||||
|
object PlaybackSpeedFlyoutPanelHookPatch : BytecodePatch(
|
||||||
|
setOf(PlaybackRateBottomSheetClassFingerprint)
|
||||||
|
) {
|
||||||
|
private const val INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR =
|
||||||
|
"$INTEGRATIONS_PATH/utils/VideoUtils;"
|
||||||
|
|
||||||
|
override fun execute(context: BytecodeContext) {
|
||||||
|
|
||||||
|
PlaybackRateBottomSheetClassFingerprint.resultOrThrow().let {
|
||||||
|
it.mutableMethod.apply {
|
||||||
|
val playbackRateBottomSheetClass = definingClass
|
||||||
|
val playbackRateBottomSheetBuilderMethodName =
|
||||||
|
it.mutableClass.methods.find { method -> method.parameters.isEmpty() && method.returnType == "V" }
|
||||||
|
?.name
|
||||||
|
?: throw PatchException("Could not find PlaybackRateBottomSheetBuilderMethod")
|
||||||
|
|
||||||
|
// set playback rate bottom sheet class
|
||||||
|
addInstruction(
|
||||||
|
0,
|
||||||
|
"sput-object p0, $INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR->playbackRateBottomSheetClass:$playbackRateBottomSheetClass"
|
||||||
|
)
|
||||||
|
|
||||||
|
val videoUtilsMutableClass = context.findClass(
|
||||||
|
INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR
|
||||||
|
)!!.mutableClass
|
||||||
|
videoUtilsMutableClass.methods.single { method ->
|
||||||
|
method.name == "showPlaybackSpeedFlyoutPanel"
|
||||||
|
}.apply {
|
||||||
|
// add playback rate bottom sheet class
|
||||||
|
videoUtilsMutableClass.staticFields.add(
|
||||||
|
ImmutableField(
|
||||||
|
definingClass,
|
||||||
|
"playbackRateBottomSheetClass",
|
||||||
|
playbackRateBottomSheetClass,
|
||||||
|
AccessFlags.PUBLIC or AccessFlags.STATIC,
|
||||||
|
null,
|
||||||
|
annotations,
|
||||||
|
null
|
||||||
|
).toMutable()
|
||||||
|
)
|
||||||
|
|
||||||
|
// call playback rate bottom sheet method
|
||||||
|
addInstructionsWithLabels(
|
||||||
|
0, """
|
||||||
|
sget-object v0, $INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR->playbackRateBottomSheetClass:$playbackRateBottomSheetClass
|
||||||
|
if-eqz v0, :ignore
|
||||||
|
invoke-virtual {v0}, $playbackRateBottomSheetClass->$playbackRateBottomSheetBuilderMethodName()V
|
||||||
|
:ignore
|
||||||
|
return-void
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package app.revanced.patches.youtube.flyoutpanel.oldspeedlayout.fingerprints
|
package app.revanced.patches.youtube.utils.flyoutpanel.fingerprints
|
||||||
|
|
||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
import app.revanced.patcher.fingerprint.MethodFingerprint
|
@ -1,8 +1,12 @@
|
|||||||
package app.revanced.patches.youtube.video.customspeed
|
package app.revanced.patches.youtube.video.customspeed
|
||||||
|
|
||||||
import app.revanced.patcher.data.ResourceContext
|
import app.revanced.patcher.data.ResourceContext
|
||||||
import app.revanced.patches.youtube.flyoutpanel.oldspeedlayout.OldSpeedLayoutPatch
|
import app.revanced.patches.shared.litho.LithoFilterPatch
|
||||||
|
import app.revanced.patches.youtube.utils.flyoutpanel.PlaybackSpeedFlyoutPanelHookPatch
|
||||||
import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE
|
import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE
|
||||||
|
import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH
|
||||||
|
import app.revanced.patches.youtube.utils.integrations.Constants.VIDEO_PATH
|
||||||
|
import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch
|
||||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||||
import app.revanced.patches.youtube.video.information.VideoInformationPatch
|
import app.revanced.patches.youtube.video.information.VideoInformationPatch
|
||||||
import app.revanced.util.patch.BaseResourcePatch
|
import app.revanced.util.patch.BaseResourcePatch
|
||||||
@ -13,13 +17,22 @@ object CustomPlaybackSpeedPatch : BaseResourcePatch(
|
|||||||
description = "Adds an option to customize available playback speeds.",
|
description = "Adds an option to customize available playback speeds.",
|
||||||
dependencies = setOf(
|
dependencies = setOf(
|
||||||
CustomPlaybackSpeedBytecodePatch::class,
|
CustomPlaybackSpeedBytecodePatch::class,
|
||||||
OldSpeedLayoutPatch::class,
|
BottomSheetRecyclerViewPatch::class,
|
||||||
|
LithoFilterPatch::class,
|
||||||
|
PlaybackSpeedFlyoutPanelHookPatch::class,
|
||||||
SettingsPatch::class,
|
SettingsPatch::class,
|
||||||
VideoInformationPatch::class
|
VideoInformationPatch::class
|
||||||
),
|
),
|
||||||
compatiblePackages = COMPATIBLE_PACKAGE
|
compatiblePackages = COMPATIBLE_PACKAGE
|
||||||
) {
|
) {
|
||||||
|
private const val FILTER_CLASS_DESCRIPTOR =
|
||||||
|
"$COMPONENTS_PATH/PlaybackSpeedMenuFilter;"
|
||||||
|
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||||
|
"$VIDEO_PATH/CustomPlaybackSpeedPatch;"
|
||||||
|
|
||||||
override fun execute(context: ResourceContext) {
|
override fun execute(context: ResourceContext) {
|
||||||
|
BottomSheetRecyclerViewPatch.injectCall("$INTEGRATIONS_CLASS_DESCRIPTOR->onFlyoutMenuCreate(Landroid/support/v7/widget/RecyclerView;)V")
|
||||||
|
LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add settings
|
* Add settings
|
||||||
|
Reference in New Issue
Block a user