fix(YouTube/Disable force auto captions): patch doesn't work with Shorts https://github.com/inotia00/ReVanced_Extended/issues/2346

This commit is contained in:
inotia00 2024-09-05 15:51:49 +09:00
parent 03dd80a0ac
commit 9d5998b5d2
11 changed files with 81 additions and 122 deletions

View File

@ -1,6 +0,0 @@
package app.revanced.patches.music.general.autocaptions
import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
import app.revanced.patches.shared.captions.BaseAutoCaptionsPatch
object AutoCaptionsBytecodePatch : BaseAutoCaptionsPatch(GENERAL_CLASS_DESCRIPTOR, false)

View File

@ -1,22 +1,38 @@
package app.revanced.patches.music.general.autocaptions package app.revanced.patches.music.general.autocaptions
import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.patch.BaseResourcePatch import app.revanced.patches.shared.fingerprints.SubtitleTrackFingerprint
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@Suppress("unused") @Suppress("unused")
object AutoCaptionsPatch : BaseResourcePatch( object AutoCaptionsPatch : BaseBytecodePatch(
name = "Disable auto captions", name = "Disable auto captions",
description = "Adds an option to disable captions from being automatically enabled.", description = "Adds an option to disable captions from being automatically enabled.",
dependencies = setOf( dependencies = setOf(SettingsPatch::class),
AutoCaptionsBytecodePatch::class, compatiblePackages = COMPATIBLE_PACKAGE,
SettingsPatch::class, fingerprints = setOf(SubtitleTrackFingerprint),
),
compatiblePackages = COMPATIBLE_PACKAGE
) { ) {
override fun execute(context: ResourceContext) { override fun execute(context: BytecodeContext) {
SubtitleTrackFingerprint.resultOrThrow().mutableMethod.apply {
val index = implementation!!.instructions.lastIndex
val register = getInstruction<OneRegisterInstruction>(index).registerA
addInstructions(
index, """
invoke-static {v$register}, $GENERAL_CLASS_DESCRIPTOR->disableAutoCaptions(Z)Z
move-result v$register
"""
)
}
SettingsPatch.addSwitchPreference( SettingsPatch.addSwitchPreference(
CategoryType.GENERAL, CategoryType.GENERAL,

View File

@ -1,65 +0,0 @@
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.util.smali.ExternalLabel
import app.revanced.patches.shared.captions.fingerprints.SubtitleButtonControllerFingerprint
import app.revanced.patches.shared.captions.fingerprints.SubtitleTrackFingerprint
import app.revanced.patches.shared.fingerprints.StartVideoInformerFingerprint
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
abstract class BaseAutoCaptionsPatch(
private val classDescriptor: String,
private val captionsButtonStatus: Boolean
) : BytecodePatch(
setOf(
StartVideoInformerFingerprint,
SubtitleButtonControllerFingerprint,
SubtitleTrackFingerprint
)
) {
override fun execute(context: BytecodeContext) {
SubtitleTrackFingerprint.resultOrThrow().mutableMethod.apply {
if (captionsButtonStatus) {
addInstructionsWithLabels(
0, """
invoke-static {}, $classDescriptor->disableAutoCaptions()Z
move-result v0
if-eqz v0, :disabled
const/4 v0, 0x1
return v0
""", ExternalLabel("disabled", getInstruction(0))
)
} else {
val index = implementation!!.instructions.lastIndex
val register = getInstruction<OneRegisterInstruction>(index).registerA
addInstructions(
index, """
invoke-static {v$register}, $classDescriptor->disableAutoCaptions(Z)Z
move-result v$register
"""
)
}
}
if (!captionsButtonStatus) return
mapOf(
StartVideoInformerFingerprint to 0,
SubtitleButtonControllerFingerprint to 1
).forEach { (fingerprint, enabled) ->
fingerprint.resultOrThrow().mutableMethod.addInstructions(
0, """
const/4 v0, 0x$enabled
invoke-static {v0}, $classDescriptor->setCaptionsButtonStatus(Z)V
"""
)
}
}
}

View File

@ -1,23 +0,0 @@
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
import com.android.tools.smali.dexlib2.Opcode
internal object SubtitleButtonControllerFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Lcom/google/android/libraries/youtube/player/subtitles/model/SubtitleTrack;"),
opcodes = listOf(
Opcode.IGET_OBJECT,
Opcode.IF_NEZ,
Opcode.RETURN_VOID,
Opcode.IGET_BOOLEAN,
Opcode.CONST_4,
Opcode.IF_NEZ,
Opcode.CONST,
Opcode.INVOKE_VIRTUAL,
Opcode.IGET_OBJECT,
)
)

View File

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

View File

@ -1,6 +0,0 @@
package app.revanced.patches.youtube.general.autocaptions
import app.revanced.patches.shared.captions.BaseAutoCaptionsPatch
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
object AutoCaptionsBytecodePatch : BaseAutoCaptionsPatch(GENERAL_CLASS_DESCRIPTOR, true)

View File

@ -1,24 +1,57 @@
package app.revanced.patches.youtube.general.autocaptions package app.revanced.patches.youtube.general.autocaptions
import app.revanced.patcher.data.BytecodeContext 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.util.smali.ExternalLabel
import app.revanced.patches.shared.fingerprints.SubtitleTrackFingerprint
import app.revanced.patches.youtube.general.autocaptions.fingerprints.StoryboardRendererDecoderRecommendedLevelFingerprint
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch import app.revanced.patches.youtube.utils.fingerprints.StartVideoInformerFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
@Suppress("unused") @Suppress("unused")
object AutoCaptionsPatch : BaseBytecodePatch( object AutoCaptionsPatch : BaseBytecodePatch(
name = "Disable auto captions", name = "Disable auto captions",
description = "Adds an option to disable captions from being automatically enabled.", description = "Adds an option to disable captions from being automatically enabled.",
dependencies = setOf( dependencies = setOf(SettingsPatch::class),
AutoCaptionsBytecodePatch::class, compatiblePackages = COMPATIBLE_PACKAGE,
PlayerTypeHookPatch::class, fingerprints = setOf(
SettingsPatch::class SubtitleTrackFingerprint,
), StartVideoInformerFingerprint,
compatiblePackages = COMPATIBLE_PACKAGE StoryboardRendererDecoderRecommendedLevelFingerprint,
)
) { ) {
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
SubtitleTrackFingerprint.resultOrThrow().mutableMethod.apply {
addInstructionsWithLabels(
0, """
invoke-static {}, $GENERAL_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}, $GENERAL_CLASS_DESCRIPTOR->setCaptionsButtonStatus(Z)V
"""
)
}
/** /**
* Add settings * Add settings
*/ */

View File

@ -0,0 +1,12 @@
package app.revanced.patches.youtube.general.autocaptions.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("Lcom/google/android/libraries/youtube/innertube/model/player/PlayerResponseModel;"),
strings = listOf("#-1#")
)

View File

@ -9,7 +9,6 @@ import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.fingerprints.StartVideoInformerFingerprint
import app.revanced.patches.shared.litho.LithoFilterPatch import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.patches.youtube.player.components.fingerprints.CrowdfundingBoxFingerprint import app.revanced.patches.youtube.player.components.fingerprints.CrowdfundingBoxFingerprint
import app.revanced.patches.youtube.player.components.fingerprints.EngagementPanelControllerFingerprint import app.revanced.patches.youtube.player.components.fingerprints.EngagementPanelControllerFingerprint
@ -34,6 +33,7 @@ import app.revanced.patches.youtube.player.components.fingerprints.WatermarkPare
import app.revanced.patches.youtube.player.speedoverlay.SpeedOverlayPatch import app.revanced.patches.youtube.player.speedoverlay.SpeedOverlayPatch
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.controlsoverlay.ControlsOverlayConfigPatch import app.revanced.patches.youtube.utils.controlsoverlay.ControlsOverlayConfigPatch
import app.revanced.patches.youtube.utils.fingerprints.StartVideoInformerFingerprint
import app.revanced.patches.youtube.utils.fingerprints.YouTubeControlsOverlayFingerprint import app.revanced.patches.youtube.utils.fingerprints.YouTubeControlsOverlayFingerprint
import app.revanced.patches.youtube.utils.fix.suggestedvideoendscreen.SuggestedVideoEndScreenPatch import app.revanced.patches.youtube.utils.fix.suggestedvideoendscreen.SuggestedVideoEndScreenPatch
import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH

View File

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

View File

@ -319,9 +319,7 @@ Limitations:
<string name="revanced_change_start_page_entry_watch_later">Watch later</string> <string name="revanced_change_start_page_entry_watch_later">Watch later</string>
<string name="revanced_change_start_page_invalid_toast">Invalid start page, resetting to default.</string> <string name="revanced_change_start_page_invalid_toast">Invalid start page, resetting to default.</string>
<string name="revanced_disable_auto_audio_tracks_title">Disable forced auto audio tracks</string> <string name="revanced_disable_auto_audio_tracks_title">Disable forced auto audio tracks</string>
<string name="revanced_disable_auto_audio_tracks_summary_on">"Forced auto audio tracks are disabled. <string name="revanced_disable_auto_audio_tracks_summary_on">Forced auto audio tracks are disabled.</string>
Limitation: This setting does not apply to Shorts."</string>
<string name="revanced_disable_auto_audio_tracks_summary_off">Forced auto audio tracks are enabled.</string> <string name="revanced_disable_auto_audio_tracks_summary_off">Forced auto audio tracks are enabled.</string>
<string name="revanced_disable_auto_captions_title">Disable forced auto captions</string> <string name="revanced_disable_auto_captions_title">Disable forced auto captions</string>
<string name="revanced_disable_auto_captions_summary_on">Forced auto captions are disabled.</string> <string name="revanced_disable_auto_captions_summary_on">Forced auto captions are disabled.</string>