mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-19 15:57:20 +02:00
fix(YouTube Music/SponsorBlock): SponsorBlock segments at the end of a song cause the player to get stuck https://github.com/inotia00/ReVanced_Extended/issues/2360
This commit is contained in:
parent
250641a600
commit
547fd291ff
@ -8,6 +8,7 @@ import app.revanced.patcher.fingerprint.MethodFingerprintResult
|
||||
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.MutableClass
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||
import app.revanced.patcher.util.smali.toInstructions
|
||||
@ -22,20 +23,26 @@ import app.revanced.patches.music.video.information.fingerprints.VideoLengthFing
|
||||
import app.revanced.patches.music.video.information.fingerprints.VideoQualityListFingerprint
|
||||
import app.revanced.patches.music.video.information.fingerprints.VideoQualityTextFingerprint
|
||||
import app.revanced.patches.music.video.videoid.VideoIdPatch
|
||||
import app.revanced.patches.shared.fingerprints.MdxPlayerDirectorSetVideoStageFingerprint
|
||||
import app.revanced.util.addFieldAndInstructions
|
||||
import app.revanced.util.getReference
|
||||
import app.revanced.util.getTargetIndexWithFieldReferenceTypeReversedOrThrow
|
||||
import app.revanced.util.getTargetIndexWithMethodReferenceNameReversedOrThrow
|
||||
import app.revanced.util.getWalkerMethod
|
||||
import app.revanced.util.indexOfFirstInstructionOrThrow
|
||||
import app.revanced.util.resultOrThrow
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
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
|
||||
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
|
||||
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodImplementation
|
||||
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
|
||||
import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||
|
||||
@Patch(
|
||||
dependencies = [
|
||||
@ -46,6 +53,7 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
object VideoInformationPatch : BytecodePatch(
|
||||
setOf(
|
||||
MdxPlayerDirectorSetVideoStageFingerprint,
|
||||
PlayerControllerSetTimeReferenceFingerprint,
|
||||
PlaybackSpeedParentFingerprint,
|
||||
SeekBarConstructorFingerprint,
|
||||
@ -57,6 +65,23 @@ object VideoInformationPatch : BytecodePatch(
|
||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||
"$SHARED_PATH/VideoInformation;"
|
||||
|
||||
/**
|
||||
* Used in [VideoEndFingerprint] and [MdxPlayerDirectorSetVideoStageFingerprint].
|
||||
* Since both classes are inherited from the same class,
|
||||
* [VideoEndFingerprint] and [MdxPlayerDirectorSetVideoStageFingerprint] always have the same [seekSourceEnumType] and [seekSourceMethodName].
|
||||
*/
|
||||
private var seekSourceEnumType = ""
|
||||
private var seekSourceMethodName = ""
|
||||
|
||||
private lateinit var videoInformationMutableClass: MutableClass
|
||||
private lateinit var context: BytecodeContext
|
||||
|
||||
private lateinit var playerConstructorMethod: MutableMethod
|
||||
private var playerConstructorInsertIndex = -1
|
||||
|
||||
private lateinit var mdxConstructorMethod: MutableMethod
|
||||
private var mdxConstructorInsertIndex = -1
|
||||
|
||||
private lateinit var videoTimeConstructorMethod: MutableMethod
|
||||
private var videoTimeConstructorInsertIndex = 2
|
||||
|
||||
@ -64,15 +89,14 @@ object VideoInformationPatch : BytecodePatch(
|
||||
lateinit var rectangleFieldName: String
|
||||
internal lateinit var playbackSpeedResult: MethodFingerprintResult
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
val videoInformationMutableClass =
|
||||
context.findClass(INTEGRATIONS_CLASS_DESCRIPTOR)!!.mutableClass
|
||||
|
||||
VideoEndFingerprint.resultOrThrow().let {
|
||||
it.mutableMethod.apply {
|
||||
val seekSourceEnumType = parameterTypes[1].toString()
|
||||
|
||||
it.mutableClass.methods.add(
|
||||
private fun addSeekInterfaceMethods(
|
||||
result: MethodFingerprintResult,
|
||||
seekMethodName: String,
|
||||
methodName: String,
|
||||
fieldName: String
|
||||
) {
|
||||
result.mutableMethod.apply {
|
||||
result.mutableClass.methods.add(
|
||||
ImmutableMethod(
|
||||
definingClass,
|
||||
"seekTo",
|
||||
@ -83,8 +107,9 @@ object VideoInformationPatch : BytecodePatch(
|
||||
null,
|
||||
ImmutableMethodImplementation(
|
||||
4, """
|
||||
# first enum (field a) is SEEK_SOURCE_UNKNOWN
|
||||
sget-object v0, $seekSourceEnumType->a:$seekSourceEnumType
|
||||
invoke-virtual {p0, p1, p2, v0}, ${definingClass}->${name}(J$seekSourceEnumType)Z
|
||||
invoke-virtual {p0, p1, p2, v0}, ${definingClass}->$seekMethodName(J$seekSourceEnumType)Z
|
||||
move-result p1
|
||||
return p1
|
||||
""".toInstructions(),
|
||||
@ -107,8 +132,8 @@ object VideoInformationPatch : BytecodePatch(
|
||||
|
||||
videoInformationMutableClass.addFieldAndInstructions(
|
||||
context,
|
||||
"overrideVideoTime",
|
||||
"videoInformationClass",
|
||||
methodName,
|
||||
fieldName,
|
||||
definingClass,
|
||||
smaliInstructions,
|
||||
true
|
||||
@ -116,6 +141,59 @@ object VideoInformationPatch : BytecodePatch(
|
||||
}
|
||||
}
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
this.context = context
|
||||
videoInformationMutableClass =
|
||||
context.findClass(INTEGRATIONS_CLASS_DESCRIPTOR)!!.mutableClass
|
||||
|
||||
VideoEndFingerprint.resultOrThrow().let {
|
||||
it.mutableMethod.apply {
|
||||
playerConstructorMethod =
|
||||
it.mutableClass.methods.first { method -> MethodUtil.isConstructor(method) }
|
||||
|
||||
playerConstructorInsertIndex =
|
||||
playerConstructorMethod.indexOfFirstInstructionOrThrow {
|
||||
opcode == Opcode.INVOKE_DIRECT && getReference<MethodReference>()?.name == "<init>"
|
||||
} + 1
|
||||
|
||||
// hook the player controller for use through integrations
|
||||
onCreateHook(INTEGRATIONS_CLASS_DESCRIPTOR, "initialize")
|
||||
|
||||
seekSourceEnumType = parameterTypes[1].toString()
|
||||
seekSourceMethodName = name
|
||||
|
||||
// Create integrations interface methods.
|
||||
addSeekInterfaceMethods(
|
||||
it,
|
||||
seekSourceMethodName,
|
||||
"overrideVideoTime",
|
||||
"videoInformationClass"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
MdxPlayerDirectorSetVideoStageFingerprint.resultOrThrow().let {
|
||||
it.mutableMethod.apply {
|
||||
mdxConstructorMethod =
|
||||
it.mutableClass.methods.first { method -> MethodUtil.isConstructor(method) }
|
||||
|
||||
mdxConstructorInsertIndex = mdxConstructorMethod.indexOfFirstInstructionOrThrow {
|
||||
opcode == Opcode.INVOKE_DIRECT && getReference<MethodReference>()?.name == "<init>"
|
||||
} + 1
|
||||
|
||||
// hook the MDX director for use through integrations
|
||||
onCreateHookMdx(INTEGRATIONS_CLASS_DESCRIPTOR, "initializeMdx")
|
||||
|
||||
// Create integrations interface methods.
|
||||
addSeekInterfaceMethods(
|
||||
it,
|
||||
seekSourceMethodName,
|
||||
"overrideMDXVideoTime",
|
||||
"videoInformationMDXClass"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the video time method
|
||||
*/
|
||||
@ -246,6 +324,33 @@ object VideoInformationPatch : BytecodePatch(
|
||||
private fun MutableMethod.insertTimeHook(insertIndex: Int, descriptor: String) =
|
||||
insert(insertIndex, "p1, p2", descriptor)
|
||||
|
||||
/**
|
||||
* Hook the player controller. Called when a video is opened or the current video is changed.
|
||||
*
|
||||
* Note: This hook is called very early and is called before the video id, video time, video length,
|
||||
* and many other data fields are set.
|
||||
*
|
||||
* @param targetMethodClass The descriptor for the class to invoke when the player controller is created.
|
||||
* @param targetMethodName The name of the static method to invoke when the player controller is created.
|
||||
*/
|
||||
internal fun onCreateHook(targetMethodClass: String, targetMethodName: String) =
|
||||
playerConstructorMethod.addInstruction(
|
||||
playerConstructorInsertIndex++,
|
||||
"invoke-static { }, $targetMethodClass->$targetMethodName()V"
|
||||
)
|
||||
|
||||
/**
|
||||
* Hook the MDX player director. Called when playing videos while casting to a big screen device.
|
||||
*
|
||||
* @param targetMethodClass The descriptor for the class to invoke when the player controller is created.
|
||||
* @param targetMethodName The name of the static method to invoke when the player controller is created.
|
||||
*/
|
||||
internal fun onCreateHookMdx(targetMethodClass: String, targetMethodName: String) =
|
||||
mdxConstructorMethod.addInstruction(
|
||||
mdxConstructorInsertIndex++,
|
||||
"invoke-static { }, $targetMethodClass->$targetMethodName()V"
|
||||
)
|
||||
|
||||
/**
|
||||
* Hook the video time.
|
||||
* The hook is usually called once per second.
|
||||
|
@ -1,4 +1,4 @@
|
||||
package app.revanced.patches.youtube.video.information.fingerprints
|
||||
package app.revanced.patches.shared.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
|
@ -14,13 +14,13 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
||||
import app.revanced.patcher.util.smali.toInstructions
|
||||
import app.revanced.patches.shared.fingerprints.MdxPlayerDirectorSetVideoStageFingerprint
|
||||
import app.revanced.patches.youtube.utils.fingerprints.VideoEndFingerprint
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.SHARED_PATH
|
||||
import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch
|
||||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
|
||||
import app.revanced.patches.youtube.video.information.fingerprints.ChannelIdFingerprint
|
||||
import app.revanced.patches.youtube.video.information.fingerprints.ChannelNameFingerprint
|
||||
import app.revanced.patches.youtube.video.information.fingerprints.MdxPlayerDirectorSetVideoStageFingerprint
|
||||
import app.revanced.patches.youtube.video.information.fingerprints.OnPlaybackSpeedItemClickFingerprint
|
||||
import app.revanced.patches.youtube.video.information.fingerprints.PlaybackInitializationFingerprint
|
||||
import app.revanced.patches.youtube.video.information.fingerprints.PlaybackSpeedClassFingerprint
|
||||
|
Loading…
x
Reference in New Issue
Block a user