Skip to content

Commit

Permalink
fix(YouTube Music/SponsorBlock): SponsorBlock does not skip segment a…
Browse files Browse the repository at this point in the history
…t the beginning when in background inotia00/ReVanced_Extended#2396
  • Loading branch information
inotia00 committed Sep 23, 2024
1 parent 3a8e676 commit e25bd10
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,7 +22,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
@Patch(
dependencies = [
SharedResourceIdPatch::class,
VideoIdPatch::class
VideoInformationPatch::class
]
)
object ReturnYouTubeDislikeBytecodePatch : BytecodePatch(
Expand Down Expand Up @@ -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")

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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) {

/**
Expand All @@ -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<FieldReference>()?.type == "Landroid/graphics/Rect;"
}
val rectangleReference =
getInstruction<ReferenceInstruction>(rectangleIndex).reference

(rectangleReference as FieldReference).name
}
}

SeekbarOnDrawFingerprint.alsoResolve(
context, SeekBarConstructorFingerprint
).let {
Expand All @@ -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
"""
)
Expand Down Expand Up @@ -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<ReferenceInstruction>(rectangleIndex).reference
rectangleFieldName = (rectangleReference as FieldReference).name
rectangleFieldName =
MusicPlaybackControlsTimeBarOnMeasureFingerprint.resultOrThrow().let {
with (it.mutableMethod) {
val rectangleIndex = it.scanResult.patternScanResult!!.startIndex
val rectangleReference =
getInstruction<ReferenceInstruction>(rectangleIndex).reference
(rectangleReference as FieldReference).name
}
}
}

MusicPlaybackControlsTimeBarDrawFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
Expand All @@ -121,7 +136,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
)

// Draw segment
val drawCircleIndex = indexOfFirstInstructionReversedOrThrow {
val drawCircleIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL
&& getReference<MethodReference>()?.name == "drawCircle"
}
Expand All @@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit e25bd10

Please sign in to comment.