From bc3c1ae6a5dc052aefaa40ec7f69c22b85168577 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Fri, 21 Apr 2023 13:34:36 +0900 Subject: [PATCH] add support YouTube v18.15.38 --- .../shared/annotation/YouTubeCompatibility.kt | 3 ++- .../patch/SponsorBlockBytecodePatch.kt | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/shared/annotation/YouTubeCompatibility.kt b/src/main/kotlin/app/revanced/patches/shared/annotation/YouTubeCompatibility.kt index 4e45a9bbd..42f527cc4 100644 --- a/src/main/kotlin/app/revanced/patches/shared/annotation/YouTubeCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/shared/annotation/YouTubeCompatibility.kt @@ -14,7 +14,8 @@ import app.revanced.patcher.annotation.Package "18.11.36", "18.12.35", "18.13.38", - "18.14.41" + "18.14.41", + "18.15.38" ) )] ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt index 907dade63..2d310cff4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt @@ -23,6 +23,7 @@ import app.revanced.util.bytecode.BytecodeHelper.injectInit import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus import org.jf.dexlib2.Opcode import org.jf.dexlib2.builder.BuilderInstruction +import org.jf.dexlib2.builder.instruction.BuilderInstruction3rc import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction @@ -122,19 +123,27 @@ class SponsorBlockBytecodePatch : BytecodePatch( /* * Draw segment */ - val drawSegmentInstructionInsertIndex = (insertInstructions.size - 1 - 2) - val (canvasInstance, centerY) = (insertInstructions[drawSegmentInstructionInsertIndex] as FiveRegisterInstruction).let { - it.registerC to it.registerE + for ((index, instruction) in insertInstructions.withIndex()) { + if (instruction.opcode != Opcode.INVOKE_VIRTUAL_RANGE) continue + + val invokeInstruction = instruction as BuilderInstruction3rc + if ((invokeInstruction.reference as MethodReference).name != "restore") continue + + val drawSegmentInstructionInsertIndex = index - 1 + + val (canvasInstance, centerY) = (insertInstructions[drawSegmentInstructionInsertIndex] as FiveRegisterInstruction).let { + it.registerC to it.registerE + } + insertMethod.addInstruction( + drawSegmentInstructionInsertIndex, + "invoke-static {v$canvasInstance, v$centerY}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->drawSponsorTimeBars(Landroid/graphics/Canvas;F)V" + ) + break } - insertMethod.addInstruction( - drawSegmentInstructionInsertIndex, - "invoke-static {v$canvasInstance, v$centerY}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->drawSponsorTimeBars(Landroid/graphics/Canvas;F)V" - ) /* * Voting & Shield button */ - arrayOf("CreateSegmentButtonController", "VotingButtonController").forEach { PlayerControlsPatch.initializeSB("$INTEGRATIONS_BUTTON_CLASS_DESCRIPTOR/ui/$it;") PlayerControlsPatch.injectVisibility("$INTEGRATIONS_BUTTON_CLASS_DESCRIPTOR/ui/$it;")