mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-06 09:34:37 +02:00
fix(YouTube Music/Disable auto captions): captions are always disabled when Disable auto captions
is on
This commit is contained in:
parent
ffd5cb1760
commit
dcd5ffe82e
@ -0,0 +1,37 @@
|
||||
package app.revanced.patches.music.general.autocaptions
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patches.music.utils.integrations.Constants.GENERAL
|
||||
import app.revanced.patches.music.utils.settings.CategoryType
|
||||
import app.revanced.patches.music.utils.settings.SettingsPatch
|
||||
import app.revanced.patches.music.video.videoid.VideoIdPatch
|
||||
import app.revanced.patches.shared.patch.captions.AbstractAutoCaptionsPatch
|
||||
|
||||
@Patch(
|
||||
name = "Disable auto captions",
|
||||
description = "Disables forced auto captions.",
|
||||
dependencies = [
|
||||
SettingsPatch::class,
|
||||
VideoIdPatch::class
|
||||
],
|
||||
compatiblePackages = [CompatiblePackage("com.google.android.apps.youtube.music")],
|
||||
)
|
||||
@Suppress("unused")
|
||||
object AutoCaptionsPatch : AbstractAutoCaptionsPatch(
|
||||
GENERAL
|
||||
) {
|
||||
override fun execute(context: BytecodeContext) {
|
||||
super.execute(context)
|
||||
|
||||
VideoIdPatch.hookBackgroundPlayVideoId("$GENERAL->newVideoStarted(Ljava/lang/String;)V")
|
||||
|
||||
SettingsPatch.addMusicPreference(
|
||||
CategoryType.GENERAL,
|
||||
"revanced_disable_auto_captions",
|
||||
"false"
|
||||
)
|
||||
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package app.revanced.patches.music.general.autocaptions
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patches.music.utils.integrations.Constants.GENERAL
|
||||
import app.revanced.patches.music.utils.settings.CategoryType
|
||||
import app.revanced.patches.music.utils.settings.SettingsPatch
|
||||
import app.revanced.patches.shared.fingerprints.captions.SubtitleTrackFingerprint
|
||||
import app.revanced.util.exception
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
|
||||
@Patch(
|
||||
name = "Disable auto captions",
|
||||
description = "Disables forced auto captions.",
|
||||
dependencies = [SettingsPatch::class],
|
||||
compatiblePackages = [CompatiblePackage("com.google.android.apps.youtube.music")],
|
||||
)
|
||||
@Suppress("unused")
|
||||
object DisableAutoCaptionsPatch : BytecodePatch(
|
||||
setOf(SubtitleTrackFingerprint)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
SubtitleTrackFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
val index = implementation!!.instructions.size - 1
|
||||
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||
|
||||
addInstructions(
|
||||
index, """
|
||||
invoke-static {v$register}, $GENERAL->disableAutoCaptions(Z)Z
|
||||
move-result v$register
|
||||
"""
|
||||
)
|
||||
}
|
||||
} ?: throw SubtitleTrackFingerprint.exception
|
||||
|
||||
SettingsPatch.addMusicPreference(
|
||||
CategoryType.GENERAL,
|
||||
"revanced_disable_auto_captions",
|
||||
"false"
|
||||
)
|
||||
|
||||
}
|
||||
}
|
@ -2,29 +2,34 @@ package app.revanced.patches.music.video.videoid
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||
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.extensions.InstructionExtensions.replaceInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patcher.util.smali.ExternalLabel
|
||||
import app.revanced.patches.music.video.videoid.fingerprints.PlayerResponseModelStoryboardRendererFingerprint
|
||||
import app.revanced.patches.music.video.videoid.fingerprints.VideoIdParentFingerprint
|
||||
import app.revanced.util.exception
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
import java.io.Closeable
|
||||
|
||||
object VideoIdPatch : BytecodePatch(
|
||||
setOf(
|
||||
PlayerResponseModelStoryboardRendererFingerprint,
|
||||
VideoIdParentFingerprint
|
||||
)
|
||||
) {
|
||||
), Closeable {
|
||||
private var videoIdRegister = 0
|
||||
private var videoIdInsertIndex = 0
|
||||
private lateinit var videoIdMethod: MutableMethod
|
||||
|
||||
private var backgroundPlaybackVideoIdRegister = 0
|
||||
private var backgroundPlaybackInsertIndex = 0
|
||||
private var backgroundPlaybackMethodName = ""
|
||||
private lateinit var backgroundPlaybackMethod: MutableMethod
|
||||
@ -57,10 +62,44 @@ object VideoIdPatch : BytecodePatch(
|
||||
?.apply {
|
||||
backgroundPlaybackMethod = this
|
||||
backgroundPlaybackInsertIndex = implementation!!.instructions.size - 1
|
||||
backgroundPlaybackVideoIdRegister = getInstruction<OneRegisterInstruction>(backgroundPlaybackInsertIndex).registerA
|
||||
} ?: throw PlayerResponseModelStoryboardRendererFingerprint.exception
|
||||
}
|
||||
|
||||
override fun close () {
|
||||
backgroundPlaybackMethod.apply {
|
||||
val videoIdIndex = implementation!!.instructions.indexOfLast {
|
||||
it.opcode == Opcode.IGET_OBJECT
|
||||
}
|
||||
val videoIdRegister = getInstruction<TwoRegisterInstruction>(videoIdIndex).registerB
|
||||
val videoIdReference = getInstruction<ReferenceInstruction>(videoIdIndex).reference
|
||||
val videoIdInstructionCall = "iget-object p0, v$videoIdRegister, $videoIdReference"
|
||||
|
||||
if (backgroundPlaybackInsertIndex != videoIdIndex + 1) {
|
||||
replaceInstruction(
|
||||
backgroundPlaybackInsertIndex,
|
||||
"return-object p0"
|
||||
)
|
||||
replaceInstruction(
|
||||
videoIdIndex,
|
||||
videoIdInstructionCall
|
||||
)
|
||||
addInstruction(
|
||||
backgroundPlaybackInsertIndex,
|
||||
videoIdInstructionCall
|
||||
)
|
||||
addInstructionsWithLabels(
|
||||
videoIdIndex + 1, """
|
||||
if-eqz p0, :ignore
|
||||
invoke-virtual {p0}, Ljava/lang/String;->isEmpty()Z
|
||||
move-result p0
|
||||
if-nez p0, :ignore
|
||||
$videoIdInstructionCall
|
||||
""", ExternalLabel("ignore", getInstruction(backgroundPlaybackInsertIndex))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun hookVideoId(
|
||||
methodDescriptor: String
|
||||
) = videoIdMethod.addInstruction(
|
||||
@ -72,7 +111,7 @@ object VideoIdPatch : BytecodePatch(
|
||||
methodDescriptor: String
|
||||
) = backgroundPlaybackMethod.addInstruction(
|
||||
backgroundPlaybackInsertIndex++, // move-result-object offset
|
||||
"invoke-static {v$backgroundPlaybackVideoIdRegister}, $methodDescriptor"
|
||||
"invoke-static {p0}, $methodDescriptor"
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user