fix(YouTube Music/Disable auto captions): captions cannot be changed when Disable forced auto captions is turned on

This commit is contained in:
inotia00
2024-09-15 20:38:39 +09:00
parent 5e8d280294
commit d708f36052
7 changed files with 72 additions and 66 deletions

View File

@ -0,0 +1,56 @@
package app.revanced.patches.shared.captions
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.captions.fingerprints.StoryboardRendererDecoderRecommendedLevelFingerprint
import app.revanced.patches.shared.captions.fingerprints.SubtitleTrackFingerprint
import app.revanced.patches.shared.fingerprints.StartVideoInformerFingerprint
import app.revanced.patches.shared.integrations.Constants.PATCHES_PATH
import app.revanced.util.resultOrThrow
@Patch(
description = "Disable forced auto captions for YouTube or YouTube Music."
)
object BaseAutoCaptionsPatch : BytecodePatch(
setOf(
StartVideoInformerFingerprint,
StoryboardRendererDecoderRecommendedLevelFingerprint,
SubtitleTrackFingerprint,
)
) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"$PATCHES_PATH/AutoCaptionsPatch;"
override fun execute(context: BytecodeContext) {
SubtitleTrackFingerprint.resultOrThrow().mutableMethod.apply {
addInstructionsWithLabels(
0, """
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->disableAutoCaptions()Z
move-result v0
if-eqz v0, :disabled
const/4 v0, 0x1
return v0
""", ExternalLabel("disabled", getInstruction(0))
)
}
mapOf(
StartVideoInformerFingerprint to 0,
StoryboardRendererDecoderRecommendedLevelFingerprint to 1
).forEach { (fingerprint, enabled) ->
fingerprint.resultOrThrow().mutableMethod.addInstructions(
0, """
const/4 v0, 0x$enabled
invoke-static {v0}, $INTEGRATIONS_CLASS_DESCRIPTOR->setCaptionsButtonStatus(Z)V
"""
)
}
}
}

View File

@ -0,0 +1,12 @@
package app.revanced.patches.shared.captions.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
internal object StoryboardRendererDecoderRecommendedLevelFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
strings = listOf("#-1#")
)

View File

@ -1,4 +1,4 @@
package app.revanced.patches.shared.fingerprints
package app.revanced.patches.shared.captions.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint

View File

@ -0,0 +1,16 @@
package app.revanced.patches.shared.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
internal object StartVideoInformerFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
opcodes = listOf(
Opcode.INVOKE_INTERFACE,
Opcode.RETURN_VOID
),
strings = listOf("pc")
)