diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt index e30dac5c82..e5ad5ca363 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt @@ -36,6 +36,7 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.video.information.VideoInformationPatch import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT import app.revanced.util.getReference +import app.revanced.util.getWalkerMethod import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstInstructionReversedOrThrow import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow @@ -283,15 +284,39 @@ object ShortsComponentPatch : BaseBytecodePatch( ShortsPausedHeaderFingerprint.resultOrThrow().let { it.mutableMethod.apply { - val insertIndex = it.scanResult.patternScanResult!!.startIndex - val insertRegister = getInstruction(insertIndex).registerA - - addInstructions( - insertIndex, """ - invoke-static {v$insertRegister}, $SHORTS_CLASS_DESCRIPTOR->hideShortsPausedHeader(Z)Z - move-result v$insertRegister - """ - ) + val targetIndex = it.scanResult.patternScanResult!!.endIndex + 1 + val targetInstruction = getInstruction(targetIndex) + val targetReference = + (targetInstruction as? ReferenceInstruction)?.reference as? MethodReference + val useMethodWalker = targetInstruction.opcode == Opcode.INVOKE_VIRTUAL && + targetReference?.returnType == "V" && + targetReference.parameterTypes.firstOrNull() == "Landroid/view/View;" + + if (useMethodWalker) { + // YouTube 18.29.38 ~ YouTube 19.28.42 + getWalkerMethod(context, targetIndex).apply { + addInstructionsWithLabels( + 0, """ + invoke-static {}, $SHORTS_CLASS_DESCRIPTOR->hideShortsPausedHeader()Z + move-result v0 + if-eqz v0, :show + return-void + """, ExternalLabel("show", getInstruction(0)) + ) + } + } else { + // YouTube 19.29.42 ~ + val insertIndex = it.scanResult.patternScanResult!!.startIndex + val insertRegister = + getInstruction(insertIndex).registerA + + addInstructions( + insertIndex, """ + invoke-static {v$insertRegister}, $SHORTS_CLASS_DESCRIPTOR->hideShortsPausedHeader(Z)Z + move-result v$insertRegister + """ + ) + } } }