From 3ae638218cf9fa75422fa69f09c071deaba2997f Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sun, 12 Mar 2023 02:37:16 +0900 Subject: [PATCH] add `disable-auto-captions` patch --- .../patch/DisableAutoCaptionsPatch.kt | 50 +++++++++++++++++++ .../music/settings/host/values/strings.xml | 2 + 2 files changed, 52 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/music/layout/autocaptions/patch/DisableAutoCaptionsPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/music/layout/autocaptions/patch/DisableAutoCaptionsPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/autocaptions/patch/DisableAutoCaptionsPatch.kt new file mode 100644 index 000000000..2de9ff6b6 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/autocaptions/patch/DisableAutoCaptionsPatch.kt @@ -0,0 +1,50 @@ +package app.revanced.patches.music.layout.autocaptions.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.music.misc.settings.patch.MusicSettingsPatch +import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility +import app.revanced.patches.shared.fingerprints.SubtitleTrackFingerprint +import app.revanced.util.integrations.Constants.MUSIC_SETTINGS_PATH +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch +@Name("disable-auto-captions") +@Description("Disable forced captions from automatically enabling in video player.") +@DependsOn([MusicSettingsPatch::class]) +@YouTubeMusicCompatibility +@Version("0.0.1") +class DisableAutoCaptionsPatch : BytecodePatch( + listOf( + SubtitleTrackFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + + SubtitleTrackFingerprint.result?.mutableMethod?.let { + with (it.implementation!!.instructions) { + val index = size - 1 + val register = (elementAt(index) as OneRegisterInstruction).registerA + it.addInstructions( + index, """ + invoke-static {v$register}, $MUSIC_SETTINGS_PATH->disableAutoCaptions(Z)Z + move-result v$register + """ + ) + } + } ?: return SubtitleTrackFingerprint.toErrorResult() + + MusicSettingsPatch.addMusicPreference("design", "revanced_disable_auto_captions", "false") + + return PatchResultSuccess() + } +} \ No newline at end of file diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index 6032bcd7d..b767a3b3c 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -4,6 +4,8 @@ Design Listening Navigation + Disable forced captions from automatically enabling in video player. + Disable auto captions Sets the navigation bar color to black. Enable black navbar Matches the fullscreen player color with the minimized one.