feat(youtube): sponsorblock improvements (#1557)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:

committed by
oSumAtrIX

parent
04a2accfe9
commit
b5d712a332
@ -1,10 +0,0 @@
|
||||
package app.revanced.patches.youtube.layout.sponsorblock.bytecode.fingerprints
|
||||
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.util.MethodUtil
|
||||
|
||||
object NextGenWatchLayoutFingerprint : MethodFingerprint(
|
||||
"V", // constructors return void, in favour of speed of matching, this fingerprint has been added
|
||||
customFingerprint = { methodDef -> MethodUtil.isConstructor(methodDef) && methodDef.parameterTypes.size == 3 && methodDef.definingClass.endsWith("NextGenWatchLayout;") }
|
||||
)
|
@ -1,5 +1,6 @@
|
||||
package app.revanced.patches.youtube.layout.sponsorblock.bytecode.patch
|
||||
|
||||
import app.revanced.extensions.toErrorResult
|
||||
import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
@ -22,10 +23,13 @@ import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
|
||||
import app.revanced.patches.youtube.layout.sponsorblock.annotations.SponsorBlockCompatibility
|
||||
import app.revanced.patches.youtube.layout.sponsorblock.bytecode.fingerprints.*
|
||||
import app.revanced.patches.youtube.layout.sponsorblock.resource.patch.SponsorBlockResourcePatch
|
||||
import app.revanced.patches.youtube.misc.autorepeat.fingerprints.AutoRepeatFingerprint
|
||||
import app.revanced.patches.youtube.misc.autorepeat.fingerprints.AutoRepeatParentFingerprint
|
||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||
import app.revanced.patches.youtube.misc.playercontrols.bytecode.patch.PlayerControlsBytecodePatch
|
||||
import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch
|
||||
import app.revanced.patches.youtube.misc.video.information.patch.VideoInformationPatch
|
||||
import app.revanced.patches.youtube.misc.video.speed.remember.patch.RememberPlaybackSpeedPatch
|
||||
import app.revanced.patches.youtube.misc.video.videoid.patch.VideoIdPatch
|
||||
import org.jf.dexlib2.Opcode
|
||||
import org.jf.dexlib2.iface.instruction.*
|
||||
@ -38,11 +42,12 @@ import org.jf.dexlib2.iface.reference.StringReference
|
||||
@DependsOn(
|
||||
dependencies = [
|
||||
VideoInformationPatch::class, // updates video information and adds method to seek in video
|
||||
VideoIdPatch::class,
|
||||
PlayerControlsBytecodePatch::class,
|
||||
PlayerTypeHookPatch::class,
|
||||
RememberPlaybackSpeedPatch::class,
|
||||
IntegrationsPatch::class,
|
||||
SponsorBlockResourcePatch::class,
|
||||
VideoIdPatch::class
|
||||
]
|
||||
)
|
||||
@Name("sponsorblock")
|
||||
@ -52,15 +57,21 @@ import org.jf.dexlib2.iface.reference.StringReference
|
||||
class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
listOf(
|
||||
SeekbarFingerprint,
|
||||
NextGenWatchLayoutFingerprint,
|
||||
AppendTimeFingerprint,
|
||||
PlayerOverlaysLayoutInitFingerprint,
|
||||
AutoRepeatParentFingerprint,
|
||||
)
|
||||
) {
|
||||
|
||||
private companion object {
|
||||
const val INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR =
|
||||
"Lapp/revanced/integrations/sponsorblock/PlayerController;"
|
||||
const val INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR =
|
||||
"Lapp/revanced/integrations/sponsorblock/SegmentPlaybackController;"
|
||||
const val INTEGRATIONS_CREATE_SEGMENT_BUTTON_CONTROLLER_CLASS_DESCRIPTOR =
|
||||
"Lapp/revanced/integrations/sponsorblock/ui/CreateSegmentButtonController;"
|
||||
const val INTEGRATIONS_VOTING_BUTTON_CONTROLLER_CLASS_DESCRIPTOR =
|
||||
"Lapp/revanced/integrations/sponsorblock/ui/VotingButtonController;"
|
||||
const val INTEGRATIONS_SPONSORBLOCK_VIEW_CONTROLLER_CLASS_DESCRIPTOR =
|
||||
"Lapp/revanced/integrations/sponsorblock/ui/SponsorBlockViewController;"
|
||||
}
|
||||
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
@ -69,19 +80,15 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
*/
|
||||
with(VideoInformationPatch) {
|
||||
videoTimeHook(
|
||||
INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR,
|
||||
INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR,
|
||||
"setVideoTime"
|
||||
)
|
||||
highPrecisionTimeHook(
|
||||
INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR,
|
||||
"setHighPrecisionVideoTime"
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
Set current video id
|
||||
*/
|
||||
VideoIdPatch.injectCallBackgroundPlay("$INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setCurrentVideoId(Ljava/lang/String;)V")
|
||||
VideoIdPatch.injectCallBackgroundPlay("$INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->setCurrentVideoId(Ljava/lang/String;)V")
|
||||
|
||||
/*
|
||||
Seekbar drawing
|
||||
@ -99,7 +106,7 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
if (instruction.opcode != Opcode.MOVE_OBJECT_FROM16) continue
|
||||
seekbarMethod.addInstruction(
|
||||
index + 1,
|
||||
"invoke-static/range {p0 .. p0}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarRect(Ljava/lang/Object;)V"
|
||||
"invoke-static/range {p0 .. p0}, $INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarRect(Ljava/lang/Object;)V"
|
||||
)
|
||||
break
|
||||
}
|
||||
@ -115,7 +122,7 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
// set the thickness of the segment
|
||||
seekbarMethod.addInstruction(
|
||||
insertIndex,
|
||||
"invoke-static {v${invokeInstruction.registerC}}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarThickness(I)V"
|
||||
"invoke-static {v${invokeInstruction.registerC}}, $INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarThickness(I)V"
|
||||
)
|
||||
break
|
||||
}
|
||||
@ -136,11 +143,11 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
// the reason for that is that we get the index, add instructions and then the offset would be wrong
|
||||
seekbarMethod.addInstruction(
|
||||
indexLeft + 1,
|
||||
"invoke-static {v$rectangleLeftRegister}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarAbsoluteLeft(Landroid/graphics/Rect;)V"
|
||||
"invoke-static {v$rectangleLeftRegister}, $INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarAbsoluteLeft(Landroid/graphics/Rect;)V"
|
||||
)
|
||||
seekbarMethod.addInstruction(
|
||||
indexRight + 1,
|
||||
"invoke-static {v$rectangleRightRegister}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarAbsoluteRight(Landroid/graphics/Rect;)V"
|
||||
"invoke-static {v$rectangleRightRegister}, $INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarAbsoluteRight(Landroid/graphics/Rect;)V"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -152,7 +159,7 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
}
|
||||
seekbarMethod.addInstruction(
|
||||
drawSegmentInstructionInsertIndex,
|
||||
"invoke-static {v$canvasInstance, v$centerY}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->drawSponsorTimeBars(Landroid/graphics/Canvas;F)V"
|
||||
"invoke-static {v$canvasInstance, v$centerY}, $INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->drawSponsorTimeBars(Landroid/graphics/Canvas;F)V"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -181,8 +188,8 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
method.addInstructions(
|
||||
moveResultInstructionIndex + 1, // insert right after moving the view to the register and use that register
|
||||
"""
|
||||
invoke-static {v$inflatedViewRegister}, Lapp/revanced/integrations/sponsorblock/ShieldButton;->initialize(Ljava/lang/Object;)V
|
||||
invoke-static {v$inflatedViewRegister}, Lapp/revanced/integrations/sponsorblock/VotingButton;->initialize(Ljava/lang/Object;)V
|
||||
invoke-static {v$inflatedViewRegister}, $INTEGRATIONS_CREATE_SEGMENT_BUTTON_CONTROLLER_CLASS_DESCRIPTOR->initialize(Ljava/lang/Object;)V
|
||||
invoke-static {v$inflatedViewRegister}, $INTEGRATIONS_VOTING_BUTTON_CONTROLLER_CLASS_DESCRIPTOR->initialize(Ljava/lang/Object;)V
|
||||
"""
|
||||
)
|
||||
}
|
||||
@ -193,8 +200,8 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
// change visibility of the buttons
|
||||
invertVisibilityMethod.addInstructions(
|
||||
0, """
|
||||
invoke-static {p1}, Lapp/revanced/integrations/sponsorblock/ShieldButton;->changeVisibilityNegatedImmediate(Z)V
|
||||
invoke-static {p1}, Lapp/revanced/integrations/sponsorblock/VotingButton;->changeVisibilityNegatedImmediate(Z)V
|
||||
invoke-static {p1}, $INTEGRATIONS_CREATE_SEGMENT_BUTTON_CONTROLLER_CLASS_DESCRIPTOR->changeVisibilityNegatedImmediate(Z)V
|
||||
invoke-static {p1}, $INTEGRATIONS_VOTING_BUTTON_CONTROLLER_CLASS_DESCRIPTOR->changeVisibilityNegatedImmediate(Z)V
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@ -203,15 +210,8 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
}
|
||||
|
||||
// change visibility of the buttons
|
||||
PlayerControlsBytecodePatch.injectVisibilityCheckCall("Lapp/revanced/integrations/sponsorblock/ShieldButton;->changeVisibility(Z)V")
|
||||
PlayerControlsBytecodePatch.injectVisibilityCheckCall("Lapp/revanced/integrations/sponsorblock/VotingButton;->changeVisibility(Z)V")
|
||||
|
||||
// set SegmentHelperLayout.context to the player layout instance
|
||||
val instanceRegister = 0
|
||||
NextGenWatchLayoutFingerprint.result!!.mutableMethod.addInstruction(
|
||||
3, // after super call
|
||||
"invoke-static/range {p$instanceRegister}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->addSkipSponsorView15(Landroid/view/View;)V"
|
||||
)
|
||||
PlayerControlsBytecodePatch.injectVisibilityCheckCall("$INTEGRATIONS_CREATE_SEGMENT_BUTTON_CONTROLLER_CLASS_DESCRIPTOR->changeVisibility(Z)V")
|
||||
PlayerControlsBytecodePatch.injectVisibilityCheckCall("$INTEGRATIONS_VOTING_BUTTON_CONTROLLER_CLASS_DESCRIPTOR->changeVisibility(Z)V")
|
||||
|
||||
// append the new time to the player layout
|
||||
val appendTimeFingerprintResult = AppendTimeFingerprint.result!!
|
||||
@ -221,18 +221,18 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
|
||||
appendTimeFingerprintResult.mutableMethod.addInstructions(
|
||||
appendTimePatternScanStartIndex + 2, """
|
||||
invoke-static {v$targetRegister}, Lapp/revanced/integrations/sponsorblock/SponsorBlockUtils;->appendTimeWithoutSegments(Ljava/lang/String;)Ljava/lang/String;
|
||||
invoke-static {v$targetRegister}, $INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->appendTimeWithoutSegments(Ljava/lang/String;)Ljava/lang/String;
|
||||
move-result-object v$targetRegister
|
||||
"""
|
||||
)
|
||||
|
||||
// initialize the player controller
|
||||
VideoInformationPatch.onCreateHook(INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR, "initialize")
|
||||
VideoInformationPatch.onCreateHook(INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR, "initialize")
|
||||
|
||||
// initialize the sponsorblock view
|
||||
PlayerOverlaysLayoutInitFingerprint.result!!.mutableMethod.addInstruction(
|
||||
6, // after inflating the view
|
||||
"invoke-static {p0}, Lapp/revanced/integrations/sponsorblock/player/ui/SponsorBlockView;->initialize(Ljava/lang/Object;)V"
|
||||
"invoke-static {p0}, $INTEGRATIONS_SPONSORBLOCK_VIEW_CONTROLLER_CLASS_DESCRIPTOR->initialize(Ljava/lang/Object;)V"
|
||||
)
|
||||
|
||||
// get rectangle field name
|
||||
@ -244,7 +244,7 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
|
||||
// replace the "replaceMeWith*" strings
|
||||
context
|
||||
.proxy(context.classes.first { it.type.endsWith("PlayerController;") })
|
||||
.proxy(context.classes.first { it.type.endsWith("SegmentPlaybackController;") })
|
||||
.mutableClass
|
||||
.methods
|
||||
.find { it.name == "setSponsorBarRect" }
|
||||
@ -268,6 +268,16 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
}
|
||||
} ?: return PatchResultError("Could not find the method which contains the replaceMeWith* strings")
|
||||
|
||||
|
||||
// detect end of the video has been reached
|
||||
AutoRepeatParentFingerprint.result ?: return AutoRepeatParentFingerprint.toErrorResult()
|
||||
AutoRepeatFingerprint.also {
|
||||
it.resolve(context, AutoRepeatParentFingerprint.result!!.classDef)
|
||||
}.result?.mutableMethod?.addInstruction(
|
||||
0,
|
||||
"invoke-static {}, $INTEGRATIONS_SPONSORBLOCK_VIEW_CONTROLLER_CLASS_DESCRIPTOR->endOfVideoReached()V"
|
||||
) ?: return AutoRepeatFingerprint.toErrorResult()
|
||||
|
||||
// TODO: isSBChannelWhitelisting implementation
|
||||
|
||||
return PatchResultSuccess()
|
||||
|
@ -122,7 +122,7 @@ class VideoInformationPatch : BytecodePatch(
|
||||
/*
|
||||
Hook the methods which set the time
|
||||
*/
|
||||
highPrecisionTimeHook(INTEGRATIONS_CLASS_DESCRIPTOR, "setVideoTime")
|
||||
highPrecisionTimeHook(INTEGRATIONS_CLASS_DESCRIPTOR, "setVideoTimeHighPrecision")
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
@ -155,6 +155,7 @@ class VideoInformationPatch : BytecodePatch(
|
||||
|
||||
/**
|
||||
* Hook the video time.
|
||||
* The hook is usually called once per second.
|
||||
*
|
||||
* @param targetMethodClass The descriptor for the static method to invoke when the player controller is created.
|
||||
* @param targetMethodName The name of the static method to invoke when the player controller is created.
|
||||
@ -167,6 +168,8 @@ class VideoInformationPatch : BytecodePatch(
|
||||
|
||||
/**
|
||||
* Hook the high precision video time.
|
||||
* The hooks is called extremely often (10 to 15 times a seconds), so use with caution.
|
||||
* Note: the hook is usually called _off_ the main thread
|
||||
*
|
||||
* @param targetMethodClass The descriptor for the static method to invoke when the player controller is created.
|
||||
* @param targetMethodName The name of the static method to invoke when the player controller is created.
|
||||
|
Reference in New Issue
Block a user