diff --git a/src/main/kotlin/app/revanced/patches/music/general/autocaptions/AutoCaptionsPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/autocaptions/AutoCaptionsPatch.kt new file mode 100644 index 000000000..7e1616194 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/general/autocaptions/AutoCaptionsPatch.kt @@ -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" + ) + + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/general/autocaptions/DisableAutoCaptionsPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/autocaptions/DisableAutoCaptionsPatch.kt deleted file mode 100644 index fa0c6a7c9..000000000 --- a/src/main/kotlin/app/revanced/patches/music/general/autocaptions/DisableAutoCaptionsPatch.kt +++ /dev/null @@ -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(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" - ) - - } -} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/video/videoid/VideoIdPatch.kt b/src/main/kotlin/app/revanced/patches/music/video/videoid/VideoIdPatch.kt index fc1e377b0..ba8a34127 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/videoid/VideoIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/videoid/VideoIdPatch.kt @@ -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(backgroundPlaybackInsertIndex).registerA } ?: throw PlayerResponseModelStoryboardRendererFingerprint.exception } + override fun close () { + backgroundPlaybackMethod.apply { + val videoIdIndex = implementation!!.instructions.indexOfLast { + it.opcode == Opcode.IGET_OBJECT + } + val videoIdRegister = getInstruction(videoIdIndex).registerB + val videoIdReference = getInstruction(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" ) }