diff --git a/src/main/kotlin/app/revanced/patches/music/player/components/fingerprints/MppWatchWhileLayoutFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/player/components/fingerprints/MppWatchWhileLayoutFingerprint.kt index d60e19839..5da2c8242 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/components/fingerprints/MppWatchWhileLayoutFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/components/fingerprints/MppWatchWhileLayoutFingerprint.kt @@ -3,6 +3,7 @@ package app.revanced.patches.music.player.components.fingerprints import app.revanced.patcher.fingerprint.MethodFingerprint 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.settings.SettingsPatch import app.revanced.util.containsWideLiteralInstructionValue import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction @@ -20,9 +21,14 @@ internal object MppWatchWhileLayoutFingerprint : MethodFingerprint( if (methodDef.name != "onFinishInflate") { 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 } ) { fun indexOfCallableInstruction(methodDef: Method) = diff --git a/src/main/kotlin/app/revanced/patches/music/utils/returnyoutubedislike/ReturnYouTubeDislikeBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/returnyoutubedislike/ReturnYouTubeDislikeBytecodePatch.kt index 7c7223d9f..d1ce151c9 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/returnyoutubedislike/ReturnYouTubeDislikeBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/returnyoutubedislike/ReturnYouTubeDislikeBytecodePatch.kt @@ -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.RemoveLikeFingerprint 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.resultOrThrow import com.android.tools.smali.dexlib2.Opcode @@ -22,7 +22,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @Patch( dependencies = [ SharedResourceIdPatch::class, - VideoIdPatch::class + VideoInformationPatch::class ] ) 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") } diff --git a/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockBytecodePatch.kt index 8845cc5e0..cd6ea4831 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockBytecodePatch.kt @@ -6,14 +6,14 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch 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.resourceid.SharedResourceIdPatch 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.RectangleFieldInvalidatorFingerprint +import app.revanced.patches.music.utils.sponsorblock.fingerprints.SeekBarConstructorFingerprint import app.revanced.patches.music.utils.sponsorblock.fingerprints.SeekbarOnDrawFingerprint 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.getReference import app.revanced.util.indexOfFirstInstructionOrThrow @@ -29,8 +29,7 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Patch( dependencies = [ SharedResourceIdPatch::class, - VideoInformationPatch::class, - VideoIdPatch::class + VideoInformationPatch::class ] ) object SponsorBlockBytecodePatch : BytecodePatch( @@ -43,7 +42,6 @@ object SponsorBlockBytecodePatch : BytecodePatch( private const val INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR = "$INTEGRATIONS_PATH/sponsorblock/SegmentPlaybackController;" - private lateinit var rectangleFieldName: String override fun execute(context: BytecodeContext) { /** @@ -59,6 +57,22 @@ object SponsorBlockBytecodePatch : BytecodePatch( /** * 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()?.type == "Landroid/graphics/Rect;" + } + val rectangleReference = + getInstruction(rectangleIndex).reference + + (rectangleReference as FieldReference).name + } + } + SeekbarOnDrawFingerprint.alsoResolve( context, SeekBarConstructorFingerprint ).let { @@ -67,7 +81,7 @@ object SponsorBlockBytecodePatch : BytecodePatch( addInstructions( 0, """ 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 """ ) @@ -100,14 +114,15 @@ object SponsorBlockBytecodePatch : BytecodePatch( /** * Responsible for seekbar in player */ - MusicPlaybackControlsTimeBarOnMeasureFingerprint.resultOrThrow().let { - it.mutableMethod.apply { - val rectangleIndex = it.scanResult.patternScanResult!!.startIndex - val rectangleReference = - getInstruction(rectangleIndex).reference - rectangleFieldName = (rectangleReference as FieldReference).name + rectangleFieldName = + MusicPlaybackControlsTimeBarOnMeasureFingerprint.resultOrThrow().let { + with (it.mutableMethod) { + val rectangleIndex = it.scanResult.patternScanResult!!.startIndex + val rectangleReference = + getInstruction(rectangleIndex).reference + (rectangleReference as FieldReference).name + } } - } MusicPlaybackControlsTimeBarDrawFingerprint.resultOrThrow().let { it.mutableMethod.apply { @@ -121,7 +136,7 @@ object SponsorBlockBytecodePatch : BytecodePatch( ) // Draw segment - val drawCircleIndex = indexOfFirstInstructionReversedOrThrow { + val drawCircleIndex = indexOfFirstInstructionOrThrow { opcode == Opcode.INVOKE_VIRTUAL && getReference()?.name == "drawCircle" } @@ -137,6 +152,6 @@ object SponsorBlockBytecodePatch : BytecodePatch( /** * 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") } } diff --git a/src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoLengthFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/fingerprints/RectangleFieldInvalidatorFingerprint.kt similarity index 75% rename from src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoLengthFingerprint.kt rename to src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/fingerprints/RectangleFieldInvalidatorFingerprint.kt index 293b0f1ed..3e779cccc 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoLengthFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/fingerprints/RectangleFieldInvalidatorFingerprint.kt @@ -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.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.indexOfFirstInstructionReversed import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.Method import com.android.tools.smali.dexlib2.iface.reference.MethodReference -internal object VideoLengthFingerprint : MethodFingerprint( +internal object RectangleFieldInvalidatorFingerprint : MethodFingerprint( opcodes = listOf( Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_WIDE, diff --git a/src/main/kotlin/app/revanced/patches/music/utils/fingerprints/SeekBarConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/fingerprints/SeekBarConstructorFingerprint.kt similarity index 82% rename from src/main/kotlin/app/revanced/patches/music/utils/fingerprints/SeekBarConstructorFingerprint.kt rename to src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/fingerprints/SeekBarConstructorFingerprint.kt index cf5d9a27f..9edfd4c98 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/fingerprints/SeekBarConstructorFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/fingerprints/SeekBarConstructorFingerprint.kt @@ -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.util.fingerprint.LiteralValueFingerprint diff --git a/src/main/kotlin/app/revanced/patches/music/video/information/VideoInformationPatch.kt b/src/main/kotlin/app/revanced/patches/music/video/information/VideoInformationPatch.kt index 5b3e02e5f..be7131c77 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/information/VideoInformationPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/information/VideoInformationPatch.kt @@ -4,6 +4,7 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.fingerprint.MethodFingerprintResult import app.revanced.patcher.patch.BytecodePatch 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.Companion.toMutable 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.resourceid.SharedResourceIdPatch 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.PlayerControllerSetTimeReferenceFingerprint 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.VideoQualityTextFingerprint -import app.revanced.patches.music.video.videoid.VideoIdPatch import app.revanced.patches.shared.fingerprints.MdxPlayerDirectorSetVideoStageFingerprint +import app.revanced.patches.shared.fingerprints.VideoLengthFingerprint import app.revanced.util.addFieldAndInstructions +import app.revanced.util.alsoResolve import app.revanced.util.getReference import app.revanced.util.getWalkerMethod import app.revanced.util.indexOfFirstInstructionOrThrow -import app.revanced.util.indexOfFirstInstructionReversedOrThrow 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 @@ -44,10 +42,7 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter import com.android.tools.smali.dexlib2.util.MethodUtil @Patch( - dependencies = [ - SharedResourceIdPatch::class, - VideoIdPatch::class - ] + dependencies = [SharedResourceIdPatch::class] ) @Suppress("MemberVisibilityCanBePrivate") object VideoInformationPatch : BytecodePatch( @@ -55,8 +50,9 @@ object VideoInformationPatch : BytecodePatch( MdxPlayerDirectorSetVideoStageFingerprint, PlayerControllerSetTimeReferenceFingerprint, PlaybackSpeedParentFingerprint, - SeekBarConstructorFingerprint, VideoEndFingerprint, + VideoIdFingerprint, + VideoLengthFingerprint, VideoQualityListFingerprint, VideoQualityTextFingerprint ) @@ -64,6 +60,20 @@ object VideoInformationPatch : BytecodePatch( private const val INTEGRATIONS_CLASS_DESCRIPTOR = "$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]. * Since both classes are inherited from the same class, @@ -85,7 +95,6 @@ object VideoInformationPatch : BytecodePatch( private var videoTimeConstructorInsertIndex = 2 // Used by other patches. - lateinit var rectangleFieldName: String internal lateinit var playbackSpeedResult: MethodFingerprintResult private fun addSeekInterfaceMethods( @@ -108,7 +117,7 @@ object VideoInformationPatch : BytecodePatch( 4, """ # first enum (field a) is SEEK_SOURCE_UNKNOWN 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 return p1 """.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() + ?.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 */ @@ -209,45 +246,19 @@ object VideoInformationPatch : BytecodePatch( /** * Set current video length */ - VideoLengthFingerprint.resolve( - context, - SeekBarConstructorFingerprint.resultOrThrow().classDef - ) - VideoLengthFingerprint.resultOrThrow().let { - it.mutableMethod.apply { - val invalidateIndex = VideoLengthFingerprint.indexOfInvalidateInstruction(this) - val rectangleIndex = indexOfFirstInstructionReversedOrThrow(invalidateIndex + 1) { - getReference()?.type == "Landroid/graphics/Rect;" - } - rectangleFieldName = - (getInstruction(rectangleIndex).reference as FieldReference).name - - val videoLengthRegisterIndex = it.scanResult.patternScanResult!!.startIndex + 1 - val videoLengthRegister = - getInstruction(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" - ) - } - } + videoLengthHook("$INTEGRATIONS_CLASS_DESCRIPTOR->setVideoLength(J)V") /** * 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 */ - PlaybackSpeedFingerprint.resolve( - context, - PlaybackSpeedParentFingerprint.resultOrThrow().classDef - ) - PlaybackSpeedFingerprint.resultOrThrow().let { + PlaybackSpeedFingerprint.alsoResolve( + context, PlaybackSpeedParentFingerprint + ).let { it.mutableMethod.apply { playbackSpeedResult = it 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( + indexOfFirstInstructionOrThrow { + val reference = getReference() + (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) = addInstruction(insertIndex, "invoke-static { $register }, $descriptor") @@ -348,6 +402,24 @@ object VideoInformationPatch : BytecodePatch( "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. * The hook is usually called once per second. diff --git a/src/main/kotlin/app/revanced/patches/music/video/videoid/fingerprints/VideoIdFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoIdFingerprint.kt similarity index 90% rename from src/main/kotlin/app/revanced/patches/music/video/videoid/fingerprints/VideoIdFingerprint.kt rename to src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoIdFingerprint.kt index bc75a0302..5f901dc11 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/videoid/fingerprints/VideoIdFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoIdFingerprint.kt @@ -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.fingerprint.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/music/video/playback/VideoPlaybackPatch.kt b/src/main/kotlin/app/revanced/patches/music/video/playback/VideoPlaybackPatch.kt index 1b064ec81..804897727 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/playback/VideoPlaybackPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/playback/VideoPlaybackPatch.kt @@ -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.playback.fingerprints.PlaybackSpeedBottomSheetFingerprint 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.patch.BaseBytecodePatch import app.revanced.util.resultOrThrow @@ -29,7 +28,6 @@ object VideoPlaybackPatch : BaseBytecodePatch( dependencies = setOf( CustomPlaybackSpeedPatch::class, SettingsPatch::class, - VideoIdPatch::class, VideoInformationPatch::class ), 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 diff --git a/src/main/kotlin/app/revanced/patches/music/video/videoid/VideoIdPatch.kt b/src/main/kotlin/app/revanced/patches/music/video/videoid/VideoIdPatch.kt deleted file mode 100644 index 85c190197..000000000 --- a/src/main/kotlin/app/revanced/patches/music/video/videoid/VideoIdPatch.kt +++ /dev/null @@ -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(videoIdInsertIndex - 1).registerA - } - } - } - - fun hookVideoId( - methodDescriptor: String - ) = videoIdMethod.addInstruction( - videoIdInsertIndex++, - "invoke-static {v$videoIdRegister}, $methodDescriptor" - ) -} - diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/information/fingerprints/VideoLengthFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/VideoLengthFingerprint.kt similarity index 84% rename from src/main/kotlin/app/revanced/patches/youtube/video/information/fingerprints/VideoLengthFingerprint.kt rename to src/main/kotlin/app/revanced/patches/shared/fingerprints/VideoLengthFingerprint.kt index 34b4eb74a..bd916f6a6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/information/fingerprints/VideoLengthFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/shared/fingerprints/VideoLengthFingerprint.kt @@ -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.fingerprint.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt index b647bbb30..7c532cf12 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt @@ -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.VideoIdFingerprintBackgroundPlay 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.VideoQualityTextFingerprint import app.revanced.patches.youtube.video.information.fingerprints.VideoTitleFingerprint @@ -158,7 +158,7 @@ object VideoInformationPatch : BytecodePatch( 4, """ # first enum (field a) is SEEK_SOURCE_UNKNOWN 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 return p1 """.toInstructions(), @@ -565,7 +565,7 @@ object VideoInformationPatch : BytecodePatch( } ).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, null, ImmutableMethodImplementation( - 9, """ + REGISTER_PLAYER_RESPONSE_MODEL + 1, """ $channelIdMethodCall move-result-object v$REGISTER_CHANNEL_ID $channelNameMethodCall @@ -617,7 +617,7 @@ object VideoInformationPatch : BytecodePatch( insert( index, - "v${REGISTER_CHANNEL_ID} .. v${REGISTER_VIDEO_IS_LIVE}", + "v$REGISTER_CHANNEL_ID .. v$REGISTER_VIDEO_IS_LIVE", descriptor ) } @@ -631,7 +631,7 @@ object VideoInformationPatch : BytecodePatch( insert( index, - "v${REGISTER_CHANNEL_ID} .. v${REGISTER_VIDEO_IS_LIVE}", + "v$REGISTER_CHANNEL_ID .. v$REGISTER_VIDEO_IS_LIVE", descriptor ) } @@ -645,7 +645,7 @@ object VideoInformationPatch : BytecodePatch( insert( index, - "v${REGISTER_CHANNEL_ID} .. v${REGISTER_VIDEO_IS_LIVE}", + "v$REGISTER_CHANNEL_ID .. v$REGISTER_VIDEO_IS_LIVE", descriptor ) }