@@ -12,6 +12,7 @@ import app.revanced.extension.youtube.sponsorblock.ui.SponsorBlockPreferenceGrou
1212import app.revanced.extension.youtube.sponsorblock.ui.SponsorBlockStatsPreferenceCategory
1313import app.revanced.extension.youtube.sponsorblock.ui.SponsorBlockViewController
1414import io.github.chsbuffer.revancedxposed.addModuleAssets
15+ import io.github.chsbuffer.revancedxposed.scopedHook
1516import io.github.chsbuffer.revancedxposed.setObjectField
1617import io.github.chsbuffer.revancedxposed.shared.misc.settings.preference.NonInteractivePreference
1718import io.github.chsbuffer.revancedxposed.shared.misc.settings.preference.PreferenceCategory
@@ -30,7 +31,7 @@ fun YoutubeHook.SponsorBlock() {
3031 dependsOn(
3132 ::VideoInformationHook ,
3233 ::VideoIdPatch ,
33- ::PlayerTypeHook
34+ ::PlayerTypeHook ,
3435 )
3536
3637 PreferenceScreen .SPONSORBLOCK .addPreferences(
@@ -97,34 +98,36 @@ fun YoutubeHook.SponsorBlock() {
9798
9899 // Seekbar drawing
99100 val seekbarOnDrawMethod = getDexMethod(" seekbarOnDrawFingerprint" )
100- val seekbarDrawLock = ThreadLocal <Boolean ?>()
101-
101+ var rectSetOnce = false
102102 seekbarOnDrawMethod.hookMethod {
103- val SponsorBarRectField = getDexField(" SponsorBarRect" ).toField()
103+ val sponsorBarRectField = getDexField(" SponsorBarRect" ).toField()
104104 before { param ->
105105 // Get left and right of seekbar rectangle.
106- SegmentPlaybackController .setSponsorBarRect(SponsorBarRectField .get(param.thisObject) as Rect )
107- seekbarDrawLock.set(true )
108- }
109-
110- after { param ->
111- seekbarDrawLock.set(false )
106+ rectSetOnce = false
107+ SegmentPlaybackController .setSponsorBarRect(sponsorBarRectField.get(param.thisObject) as Rect )
112108 }
113109 }
114-
115- // Find the drawCircle call and draw the segment before it.
116- DexMethod (" Landroid/graphics/RecordingCanvas;->drawCircle(FFFLandroid/graphics/Paint;)V" ).hookMethod {
117- before { param ->
118- if (seekbarDrawLock.get() != true ) return @before
119- val radius = (param.args[2 ] as Float ).toInt()
110+ seekbarOnDrawMethod.hookMethod(
111+ scopedHook(
120112 // Set the thickness of the segment.
121- SegmentPlaybackController .setSponsorBarThickness(radius)
122-
123- SegmentPlaybackController .drawSponsorTimeBars(
124- param.thisObject as Canvas , param.args[1 ] as Float
125- )
126- }
127- }
113+ DexMethod (" Landroid/graphics/Rect;->set(IIII)V" ).toMethod() to {
114+ before { param ->
115+ // Only the first call to Rect.set from onDraw sets the segment thickness.
116+ if (rectSetOnce) return @before
117+ SegmentPlaybackController .setSponsorBarThickness((param.thisObject as Rect ).height())
118+ rectSetOnce = true
119+ }
120+ },
121+ // Find the drawCircle call and draw the segment before it.
122+ DexMethod (" Landroid/graphics/RecordingCanvas;->drawCircle(FFFLandroid/graphics/Paint;)V" ).toMethod() to {
123+ before { param ->
124+ SegmentPlaybackController .drawSponsorTimeBars(
125+ param.thisObject as Canvas , param.args[1 ] as Float
126+ )
127+ }
128+ },
129+ )
130+ )
128131
129132 // Initialize the SponsorBlock view.
130133 val inset_overlay_view_layout = Utils .getResourceIdentifier(" inset_overlay_view_layout" , " id" )
0 commit comments