fix(YouTube Music/SponsorBlock): SponsorBlock does not skip segment at the beginning when in background https://github.com/inotia00/ReVanced_Extended/issues/2396

This commit is contained in:
inotia00 2024-09-23 22:05:26 +09:00
parent 3a8e6760a3
commit e25bd1034c
11 changed files with 171 additions and 118 deletions

View File

@ -3,6 +3,7 @@ package app.revanced.patches.music.player.components.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.player.components.fingerprints.MppWatchWhileLayoutFingerprint.indexOfCallableInstruction import app.revanced.patches.music.player.components.fingerprints.MppWatchWhileLayoutFingerprint.indexOfCallableInstruction
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MiniPlayerPlayPauseReplayButton import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MiniPlayerPlayPauseReplayButton
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.containsWideLiteralInstructionValue import app.revanced.util.containsWideLiteralInstructionValue
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstruction
@ -20,8 +21,13 @@ internal object MppWatchWhileLayoutFingerprint : MethodFingerprint(
if (methodDef.name != "onFinishInflate") { if (methodDef.name != "onFinishInflate") {
return@custom false return@custom false
} }
if (!methodDef.containsWideLiteralInstructionValue(MiniPlayerPlayPauseReplayButton)) {
return@custom false
}
if (!SettingsPatch.upward0718) {
return@custom true
}
methodDef.containsWideLiteralInstructionValue(MiniPlayerPlayPauseReplayButton) &&
indexOfCallableInstruction(methodDef) >= 0 indexOfCallableInstruction(methodDef) >= 0
} }
) { ) {

View File

@ -12,7 +12,7 @@ import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.Dislik
import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.LikeFingerprint import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.LikeFingerprint
import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.RemoveLikeFingerprint import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.RemoveLikeFingerprint
import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.TextComponentFingerprint import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.TextComponentFingerprint
import app.revanced.patches.music.video.videoid.VideoIdPatch import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -22,7 +22,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
@Patch( @Patch(
dependencies = [ dependencies = [
SharedResourceIdPatch::class, SharedResourceIdPatch::class,
VideoIdPatch::class VideoInformationPatch::class
] ]
) )
object ReturnYouTubeDislikeBytecodePatch : BytecodePatch( object ReturnYouTubeDislikeBytecodePatch : BytecodePatch(
@ -70,7 +70,7 @@ object ReturnYouTubeDislikeBytecodePatch : BytecodePatch(
} }
} }
VideoIdPatch.hookVideoId("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V") VideoInformationPatch.videoIdHook("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V")
} }

View File

@ -6,14 +6,14 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.music.utils.fingerprints.SeekBarConstructorFingerprint
import app.revanced.patches.music.utils.integrations.Constants.INTEGRATIONS_PATH import app.revanced.patches.music.utils.integrations.Constants.INTEGRATIONS_PATH
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.sponsorblock.fingerprints.MusicPlaybackControlsTimeBarDrawFingerprint import app.revanced.patches.music.utils.sponsorblock.fingerprints.MusicPlaybackControlsTimeBarDrawFingerprint
import app.revanced.patches.music.utils.sponsorblock.fingerprints.MusicPlaybackControlsTimeBarOnMeasureFingerprint import app.revanced.patches.music.utils.sponsorblock.fingerprints.MusicPlaybackControlsTimeBarOnMeasureFingerprint
import app.revanced.patches.music.utils.sponsorblock.fingerprints.RectangleFieldInvalidatorFingerprint
import app.revanced.patches.music.utils.sponsorblock.fingerprints.SeekBarConstructorFingerprint
import app.revanced.patches.music.utils.sponsorblock.fingerprints.SeekbarOnDrawFingerprint import app.revanced.patches.music.utils.sponsorblock.fingerprints.SeekbarOnDrawFingerprint
import app.revanced.patches.music.video.information.VideoInformationPatch import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.patches.music.video.videoid.VideoIdPatch
import app.revanced.util.alsoResolve import app.revanced.util.alsoResolve
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstInstructionOrThrow
@ -29,8 +29,7 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Patch( @Patch(
dependencies = [ dependencies = [
SharedResourceIdPatch::class, SharedResourceIdPatch::class,
VideoInformationPatch::class, VideoInformationPatch::class
VideoIdPatch::class
] ]
) )
object SponsorBlockBytecodePatch : BytecodePatch( object SponsorBlockBytecodePatch : BytecodePatch(
@ -43,7 +42,6 @@ object SponsorBlockBytecodePatch : BytecodePatch(
private const val INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR = private const val INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR =
"$INTEGRATIONS_PATH/sponsorblock/SegmentPlaybackController;" "$INTEGRATIONS_PATH/sponsorblock/SegmentPlaybackController;"
private lateinit var rectangleFieldName: String
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
/** /**
@ -59,6 +57,22 @@ object SponsorBlockBytecodePatch : BytecodePatch(
/** /**
* Responsible for seekbar in fullscreen * Responsible for seekbar in fullscreen
*/ */
var rectangleFieldName =
RectangleFieldInvalidatorFingerprint.alsoResolve(
context, SeekBarConstructorFingerprint
).let {
with (it.mutableMethod) {
val invalidateIndex = RectangleFieldInvalidatorFingerprint.indexOfInvalidateInstruction(this)
val rectangleIndex = indexOfFirstInstructionReversedOrThrow(invalidateIndex + 1) {
getReference<FieldReference>()?.type == "Landroid/graphics/Rect;"
}
val rectangleReference =
getInstruction<ReferenceInstruction>(rectangleIndex).reference
(rectangleReference as FieldReference).name
}
}
SeekbarOnDrawFingerprint.alsoResolve( SeekbarOnDrawFingerprint.alsoResolve(
context, SeekBarConstructorFingerprint context, SeekBarConstructorFingerprint
).let { ).let {
@ -67,7 +81,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
addInstructions( addInstructions(
0, """ 0, """
move-object/from16 v0, p0 move-object/from16 v0, p0
const-string v1, "${VideoInformationPatch.rectangleFieldName}" const-string v1, "$rectangleFieldName"
invoke-static {v0, v1}, $INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarRect(Ljava/lang/Object;Ljava/lang/String;)V invoke-static {v0, v1}, $INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarRect(Ljava/lang/Object;Ljava/lang/String;)V
""" """
) )
@ -100,12 +114,13 @@ object SponsorBlockBytecodePatch : BytecodePatch(
/** /**
* Responsible for seekbar in player * Responsible for seekbar in player
*/ */
rectangleFieldName =
MusicPlaybackControlsTimeBarOnMeasureFingerprint.resultOrThrow().let { MusicPlaybackControlsTimeBarOnMeasureFingerprint.resultOrThrow().let {
it.mutableMethod.apply { with (it.mutableMethod) {
val rectangleIndex = it.scanResult.patternScanResult!!.startIndex val rectangleIndex = it.scanResult.patternScanResult!!.startIndex
val rectangleReference = val rectangleReference =
getInstruction<ReferenceInstruction>(rectangleIndex).reference getInstruction<ReferenceInstruction>(rectangleIndex).reference
rectangleFieldName = (rectangleReference as FieldReference).name (rectangleReference as FieldReference).name
} }
} }
@ -121,7 +136,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
) )
// Draw segment // Draw segment
val drawCircleIndex = indexOfFirstInstructionReversedOrThrow { val drawCircleIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL opcode == Opcode.INVOKE_VIRTUAL
&& getReference<MethodReference>()?.name == "drawCircle" && getReference<MethodReference>()?.name == "drawCircle"
} }
@ -137,6 +152,6 @@ object SponsorBlockBytecodePatch : BytecodePatch(
/** /**
* Set current video id * Set current video id
*/ */
VideoIdPatch.hookVideoId("$INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->setVideoId(Ljava/lang/String;)V") VideoInformationPatch.videoIdHook("$INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->setVideoId(Ljava/lang/String;)V")
} }
} }

View File

@ -1,14 +1,14 @@
package app.revanced.patches.music.video.information.fingerprints package app.revanced.patches.music.utils.sponsorblock.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.video.information.fingerprints.VideoLengthFingerprint.indexOfInvalidateInstruction import app.revanced.patches.music.utils.sponsorblock.fingerprints.RectangleFieldInvalidatorFingerprint.indexOfInvalidateInstruction
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversed import app.revanced.util.indexOfFirstInstructionReversed
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal object VideoLengthFingerprint : MethodFingerprint( internal object RectangleFieldInvalidatorFingerprint : MethodFingerprint(
opcodes = listOf( opcodes = listOf(
Opcode.INVOKE_VIRTUAL, Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_WIDE, Opcode.MOVE_RESULT_WIDE,

View File

@ -1,4 +1,4 @@
package app.revanced.patches.music.utils.fingerprints package app.revanced.patches.music.utils.sponsorblock.fingerprints
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.InlineTimeBarAdBreakMarkerColor import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.InlineTimeBarAdBreakMarkerColor
import app.revanced.util.fingerprint.LiteralValueFingerprint import app.revanced.util.fingerprint.LiteralValueFingerprint

View File

@ -4,6 +4,7 @@ import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patcher.fingerprint.MethodFingerprintResult import app.revanced.patcher.fingerprint.MethodFingerprintResult
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.PatchException
@ -12,31 +13,28 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.patcher.util.smali.toInstructions import app.revanced.patcher.util.smali.toInstructions
import app.revanced.patches.music.utils.fingerprints.SeekBarConstructorFingerprint
import app.revanced.patches.music.utils.integrations.Constants.SHARED_PATH import app.revanced.patches.music.utils.integrations.Constants.SHARED_PATH
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.video.information.fingerprints.PlaybackSpeedFingerprint import app.revanced.patches.music.video.information.fingerprints.PlaybackSpeedFingerprint
import app.revanced.patches.music.video.information.fingerprints.PlaybackSpeedParentFingerprint import app.revanced.patches.music.video.information.fingerprints.PlaybackSpeedParentFingerprint
import app.revanced.patches.music.video.information.fingerprints.PlayerControllerSetTimeReferenceFingerprint import app.revanced.patches.music.video.information.fingerprints.PlayerControllerSetTimeReferenceFingerprint
import app.revanced.patches.music.video.information.fingerprints.VideoEndFingerprint import app.revanced.patches.music.video.information.fingerprints.VideoEndFingerprint
import app.revanced.patches.music.video.information.fingerprints.VideoLengthFingerprint import app.revanced.patches.music.video.information.fingerprints.VideoIdFingerprint
import app.revanced.patches.music.video.information.fingerprints.VideoQualityListFingerprint import app.revanced.patches.music.video.information.fingerprints.VideoQualityListFingerprint
import app.revanced.patches.music.video.information.fingerprints.VideoQualityTextFingerprint 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.patches.shared.fingerprints.MdxPlayerDirectorSetVideoStageFingerprint
import app.revanced.patches.shared.fingerprints.VideoLengthFingerprint
import app.revanced.util.addFieldAndInstructions import app.revanced.util.addFieldAndInstructions
import app.revanced.util.alsoResolve
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction 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.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction 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.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodImplementation import com.android.tools.smali.dexlib2.immutable.ImmutableMethodImplementation
@ -44,10 +42,7 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
import com.android.tools.smali.dexlib2.util.MethodUtil import com.android.tools.smali.dexlib2.util.MethodUtil
@Patch( @Patch(
dependencies = [ dependencies = [SharedResourceIdPatch::class]
SharedResourceIdPatch::class,
VideoIdPatch::class
]
) )
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
object VideoInformationPatch : BytecodePatch( object VideoInformationPatch : BytecodePatch(
@ -55,8 +50,9 @@ object VideoInformationPatch : BytecodePatch(
MdxPlayerDirectorSetVideoStageFingerprint, MdxPlayerDirectorSetVideoStageFingerprint,
PlayerControllerSetTimeReferenceFingerprint, PlayerControllerSetTimeReferenceFingerprint,
PlaybackSpeedParentFingerprint, PlaybackSpeedParentFingerprint,
SeekBarConstructorFingerprint,
VideoEndFingerprint, VideoEndFingerprint,
VideoIdFingerprint,
VideoLengthFingerprint,
VideoQualityListFingerprint, VideoQualityListFingerprint,
VideoQualityTextFingerprint VideoQualityTextFingerprint
) )
@ -64,6 +60,20 @@ object VideoInformationPatch : BytecodePatch(
private const val INTEGRATIONS_CLASS_DESCRIPTOR = private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"$SHARED_PATH/VideoInformation;" "$SHARED_PATH/VideoInformation;"
private const val REGISTER_PLAYER_RESPONSE_MODEL = 4
private const val REGISTER_VIDEO_ID = 0
private const val REGISTER_VIDEO_LENGTH = 1
@Suppress("unused")
private const val REGISTER_VIDEO_LENGTH_DUMMY = 2
private lateinit var PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR: String
private lateinit var videoIdMethodCall: String
private lateinit var videoLengthMethodCall: String
private lateinit var videoInformationMethod: MutableMethod
/** /**
* Used in [VideoEndFingerprint] and [MdxPlayerDirectorSetVideoStageFingerprint]. * Used in [VideoEndFingerprint] and [MdxPlayerDirectorSetVideoStageFingerprint].
* Since both classes are inherited from the same class, * Since both classes are inherited from the same class,
@ -85,7 +95,6 @@ object VideoInformationPatch : BytecodePatch(
private var videoTimeConstructorInsertIndex = 2 private var videoTimeConstructorInsertIndex = 2
// Used by other patches. // Used by other patches.
lateinit var rectangleFieldName: String
internal lateinit var playbackSpeedResult: MethodFingerprintResult internal lateinit var playbackSpeedResult: MethodFingerprintResult
private fun addSeekInterfaceMethods( private fun addSeekInterfaceMethods(
@ -108,7 +117,7 @@ object VideoInformationPatch : BytecodePatch(
4, """ 4, """
# first enum (field a) is SEEK_SOURCE_UNKNOWN # first enum (field a) is SEEK_SOURCE_UNKNOWN
sget-object v0, $seekSourceEnumType->a:$seekSourceEnumType sget-object v0, $seekSourceEnumType->a:$seekSourceEnumType
invoke-virtual {p0, p1, p2, v0}, ${definingClass}->$seekMethodName(J$seekSourceEnumType)Z invoke-virtual {p0, p1, p2, v0}, $definingClass->$seekMethodName(J$seekSourceEnumType)Z
move-result p1 move-result p1
return p1 return p1
""".toInstructions(), """.toInstructions(),
@ -193,6 +202,34 @@ object VideoInformationPatch : BytecodePatch(
} }
} }
/**
* Set current video information
*/
VideoIdFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val playerResponseModelIndex = it.scanResult.patternScanResult!!.startIndex
PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR =
getInstruction(playerResponseModelIndex)
.getReference<MethodReference>()
?.definingClass
?: throw PatchException("Could not find Player Response Model class")
videoIdMethodCall =
VideoIdFingerprint.getPlayerResponseInstruction("Ljava/lang/String;")
videoLengthMethodCall =
VideoLengthFingerprint.getPlayerResponseInstruction("J")
videoInformationMethod = getVideoInformationMethod()
it.mutableClass.methods.add(videoInformationMethod)
addInstruction(
playerResponseModelIndex + 2,
"invoke-direct/range {p0 .. p1}, $definingClass->setVideoInformation($PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR)V"
)
}
}
/** /**
* Set the video time method * Set the video time method
*/ */
@ -209,45 +246,19 @@ object VideoInformationPatch : BytecodePatch(
/** /**
* Set current video length * Set current video length
*/ */
VideoLengthFingerprint.resolve( videoLengthHook("$INTEGRATIONS_CLASS_DESCRIPTOR->setVideoLength(J)V")
context,
SeekBarConstructorFingerprint.resultOrThrow().classDef
)
VideoLengthFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val invalidateIndex = VideoLengthFingerprint.indexOfInvalidateInstruction(this)
val rectangleIndex = indexOfFirstInstructionReversedOrThrow(invalidateIndex + 1) {
getReference<FieldReference>()?.type == "Landroid/graphics/Rect;"
}
rectangleFieldName =
(getInstruction<ReferenceInstruction>(rectangleIndex).reference as FieldReference).name
val videoLengthRegisterIndex = it.scanResult.patternScanResult!!.startIndex + 1
val videoLengthRegister =
getInstruction<OneRegisterInstruction>(videoLengthRegisterIndex).registerA
val dummyRegisterForLong =
videoLengthRegister + 1 // required for long values since they are wide
addInstruction(
videoLengthRegisterIndex + 1,
"invoke-static {v$videoLengthRegister, v$dummyRegisterForLong}, $INTEGRATIONS_CLASS_DESCRIPTOR->setVideoLength(J)V"
)
}
}
/** /**
* Set current video id * Set current video id
*/ */
VideoIdPatch.hookVideoId("$INTEGRATIONS_CLASS_DESCRIPTOR->setVideoId(Ljava/lang/String;)V") videoIdHook("$INTEGRATIONS_CLASS_DESCRIPTOR->setVideoId(Ljava/lang/String;)V")
/** /**
* Hook current playback speed * Hook current playback speed
*/ */
PlaybackSpeedFingerprint.resolve( PlaybackSpeedFingerprint.alsoResolve(
context, context, PlaybackSpeedParentFingerprint
PlaybackSpeedParentFingerprint.resultOrThrow().classDef ).let {
)
PlaybackSpeedFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
playbackSpeedResult = it playbackSpeedResult = it
val endIndex = it.scanResult.patternScanResult!!.endIndex val endIndex = it.scanResult.patternScanResult!!.endIndex
@ -315,6 +326,49 @@ object VideoInformationPatch : BytecodePatch(
} }
} }
private fun MethodFingerprint.getPlayerResponseInstruction(returnType: String): String {
resultOrThrow().mutableMethod.apply {
val targetReference = getInstruction<ReferenceInstruction>(
indexOfFirstInstructionOrThrow {
val reference = getReference<MethodReference>()
(opcode == Opcode.INVOKE_INTERFACE_RANGE || opcode == Opcode.INVOKE_INTERFACE) &&
reference?.definingClass == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR &&
reference.returnType == returnType
}
).reference
return "invoke-interface/range {v$REGISTER_PLAYER_RESPONSE_MODEL .. v$REGISTER_PLAYER_RESPONSE_MODEL}, $targetReference"
}
}
private fun MutableMethod.getVideoInformationMethod(): MutableMethod =
ImmutableMethod(
definingClass,
"setVideoInformation",
listOf(
ImmutableMethodParameter(
PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR,
annotations,
null
)
),
"V",
AccessFlags.PRIVATE or AccessFlags.FINAL,
annotations,
null,
ImmutableMethodImplementation(
REGISTER_PLAYER_RESPONSE_MODEL + 1, """
$videoIdMethodCall
move-result-object v$REGISTER_VIDEO_ID
$videoLengthMethodCall
move-result-wide v$REGISTER_VIDEO_LENGTH
return-void
""".toInstructions(),
null,
null
)
).toMutable()
private fun MutableMethod.insert(insertIndex: Int, register: String, descriptor: String) = private fun MutableMethod.insert(insertIndex: Int, register: String, descriptor: String) =
addInstruction(insertIndex, "invoke-static { $register }, $descriptor") addInstruction(insertIndex, "invoke-static { $register }, $descriptor")
@ -348,6 +402,24 @@ object VideoInformationPatch : BytecodePatch(
"invoke-static { }, $targetMethodClass->$targetMethodName()V" "invoke-static { }, $targetMethodClass->$targetMethodName()V"
) )
internal fun videoIdHook(
descriptor: String
) = videoInformationMethod.apply {
addInstruction(
implementation!!.instructions.lastIndex,
"invoke-static {v$REGISTER_VIDEO_ID}, $descriptor"
)
}
internal fun videoLengthHook(
descriptor: String
) = videoInformationMethod.apply {
addInstruction(
implementation!!.instructions.lastIndex,
"invoke-static {v$REGISTER_VIDEO_LENGTH, v$REGISTER_VIDEO_LENGTH_DUMMY}, $descriptor"
)
}
/** /**
* Hook the video time. * Hook the video time.
* The hook is usually called once per second. * The hook is usually called once per second.

View File

@ -1,4 +1,4 @@
package app.revanced.patches.music.video.videoid.fingerprints package app.revanced.patches.music.video.information.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

View File

@ -12,7 +12,6 @@ import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.music.video.information.VideoInformationPatch import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.patches.music.video.playback.fingerprints.PlaybackSpeedBottomSheetFingerprint import app.revanced.patches.music.video.playback.fingerprints.PlaybackSpeedBottomSheetFingerprint
import app.revanced.patches.music.video.playback.fingerprints.UserQualityChangeFingerprint import app.revanced.patches.music.video.playback.fingerprints.UserQualityChangeFingerprint
import app.revanced.patches.music.video.videoid.VideoIdPatch
import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
@ -29,7 +28,6 @@ object VideoPlaybackPatch : BaseBytecodePatch(
dependencies = setOf( dependencies = setOf(
CustomPlaybackSpeedPatch::class, CustomPlaybackSpeedPatch::class,
SettingsPatch::class, SettingsPatch::class,
VideoIdPatch::class,
VideoInformationPatch::class VideoInformationPatch::class
), ),
compatiblePackages = COMPATIBLE_PACKAGE, compatiblePackages = COMPATIBLE_PACKAGE,
@ -102,7 +100,7 @@ object VideoPlaybackPatch : BaseBytecodePatch(
} }
} }
VideoIdPatch.hookVideoId("$INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V") VideoInformationPatch.videoIdHook("$INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V")
// endregion // endregion

View File

@ -1,38 +0,0 @@
package app.revanced.patches.music.video.videoid
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.music.video.videoid.fingerprints.VideoIdFingerprint
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
object VideoIdPatch : BytecodePatch(
setOf(VideoIdFingerprint)
) {
private var videoIdRegister = 0
private var videoIdInsertIndex = 0
private lateinit var videoIdMethod: MutableMethod
override fun execute(context: BytecodeContext) {
VideoIdFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
videoIdMethod = this
videoIdInsertIndex = it.scanResult.patternScanResult!!.startIndex + 2
videoIdRegister =
getInstruction<OneRegisterInstruction>(videoIdInsertIndex - 1).registerA
}
}
}
fun hookVideoId(
methodDescriptor: String
) = videoIdMethod.addInstruction(
videoIdInsertIndex++,
"invoke-static {v$videoIdRegister}, $methodDescriptor"
)
}

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.video.information.fingerprints package app.revanced.patches.shared.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

View File

@ -31,7 +31,7 @@ import app.revanced.patches.youtube.video.information.fingerprints.SeekRelativeF
import app.revanced.patches.youtube.video.information.fingerprints.VideoIdFingerprint import app.revanced.patches.youtube.video.information.fingerprints.VideoIdFingerprint
import app.revanced.patches.youtube.video.information.fingerprints.VideoIdFingerprintBackgroundPlay import app.revanced.patches.youtube.video.information.fingerprints.VideoIdFingerprintBackgroundPlay
import app.revanced.patches.youtube.video.information.fingerprints.VideoIdFingerprintShorts import app.revanced.patches.youtube.video.information.fingerprints.VideoIdFingerprintShorts
import app.revanced.patches.youtube.video.information.fingerprints.VideoLengthFingerprint import app.revanced.patches.shared.fingerprints.VideoLengthFingerprint
import app.revanced.patches.youtube.video.information.fingerprints.VideoQualityListFingerprint import app.revanced.patches.youtube.video.information.fingerprints.VideoQualityListFingerprint
import app.revanced.patches.youtube.video.information.fingerprints.VideoQualityTextFingerprint import app.revanced.patches.youtube.video.information.fingerprints.VideoQualityTextFingerprint
import app.revanced.patches.youtube.video.information.fingerprints.VideoTitleFingerprint import app.revanced.patches.youtube.video.information.fingerprints.VideoTitleFingerprint
@ -158,7 +158,7 @@ object VideoInformationPatch : BytecodePatch(
4, """ 4, """
# first enum (field a) is SEEK_SOURCE_UNKNOWN # first enum (field a) is SEEK_SOURCE_UNKNOWN
sget-object v0, $seekSourceEnumType->a:$seekSourceEnumType sget-object v0, $seekSourceEnumType->a:$seekSourceEnumType
invoke-virtual {p0, p1, p2, v0}, ${definingClass}->$seekMethodName(J$seekSourceEnumType)Z invoke-virtual {p0, p1, p2, v0}, $definingClass->$seekMethodName(J$seekSourceEnumType)Z
move-result p1 move-result p1
return p1 return p1
""".toInstructions(), """.toInstructions(),
@ -565,7 +565,7 @@ object VideoInformationPatch : BytecodePatch(
} }
).reference ).reference
return "invoke-interface {v${REGISTER_PLAYER_RESPONSE_MODEL}}, $targetReference" return "invoke-interface {v$REGISTER_PLAYER_RESPONSE_MODEL}, $targetReference"
} }
} }
@ -585,7 +585,7 @@ object VideoInformationPatch : BytecodePatch(
annotations, annotations,
null, null,
ImmutableMethodImplementation( ImmutableMethodImplementation(
9, """ REGISTER_PLAYER_RESPONSE_MODEL + 1, """
$channelIdMethodCall $channelIdMethodCall
move-result-object v$REGISTER_CHANNEL_ID move-result-object v$REGISTER_CHANNEL_ID
$channelNameMethodCall $channelNameMethodCall
@ -617,7 +617,7 @@ object VideoInformationPatch : BytecodePatch(
insert( insert(
index, index,
"v${REGISTER_CHANNEL_ID} .. v${REGISTER_VIDEO_IS_LIVE}", "v$REGISTER_CHANNEL_ID .. v$REGISTER_VIDEO_IS_LIVE",
descriptor descriptor
) )
} }
@ -631,7 +631,7 @@ object VideoInformationPatch : BytecodePatch(
insert( insert(
index, index,
"v${REGISTER_CHANNEL_ID} .. v${REGISTER_VIDEO_IS_LIVE}", "v$REGISTER_CHANNEL_ID .. v$REGISTER_VIDEO_IS_LIVE",
descriptor descriptor
) )
} }
@ -645,7 +645,7 @@ object VideoInformationPatch : BytecodePatch(
insert( insert(
index, index,
"v${REGISTER_CHANNEL_ID} .. v${REGISTER_VIDEO_IS_LIVE}", "v$REGISTER_CHANNEL_ID .. v$REGISTER_VIDEO_IS_LIVE",
descriptor descriptor
) )
} }