feat(YouTube Music): Add Disable QUIC protocol patch https://github.com/inotia00/ReVanced_Extended/issues/2763

This commit is contained in:
inotia00
2025-02-28 09:18:40 +09:00
parent e4771f558b
commit ef63c8dba7
16 changed files with 99 additions and 70 deletions

View File

@ -2,7 +2,6 @@ package app.revanced.patches.music.misc.codecs
import app.revanced.patcher.patch.resourcePatch
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.music.utils.extension.Constants.MISC_PATH
import app.revanced.patches.music.utils.patch.PatchList.ENABLE_OPUS_CODEC
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.ResourceUtils.updatePatchStatus
@ -18,10 +17,8 @@ val opusCodecPatch = resourcePatch(
compatibleWith(COMPATIBLE_PACKAGE)
dependsOn(
baseOpusCodecsPatch(
"$MISC_PATH/OpusCodecPatch;->enableOpusCodec()Z"
),
settingsPatch
settingsPatch,
baseOpusCodecsPatch(),
)
execute {
@ -30,8 +27,6 @@ val opusCodecPatch = resourcePatch(
"revanced_enable_opus_codec",
"false"
)
updatePatchStatus(ENABLE_OPUS_CODEC)
}
}

View File

@ -0,0 +1,34 @@
package app.revanced.patches.music.misc.quic
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.music.utils.patch.PatchList.DISABLE_QUIC_PROTOCOL
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.ResourceUtils.updatePatchStatus
import app.revanced.patches.music.utils.settings.addSwitchPreference
import app.revanced.patches.music.utils.settings.settingsPatch
import app.revanced.patches.shared.quic.baseQuicProtocolPatch
@Suppress("unused", "SpellCheckingInspection")
val quicProtocolPatch = bytecodePatch(
DISABLE_QUIC_PROTOCOL.title,
DISABLE_QUIC_PROTOCOL.summary,
) {
compatibleWith(COMPATIBLE_PACKAGE)
dependsOn(
settingsPatch,
baseQuicProtocolPatch(),
)
execute {
addSwitchPreference(
CategoryType.MISC,
"revanced_disable_quic_protocol",
"false"
)
updatePatchStatus(DISABLE_QUIC_PROTOCOL)
}
}

View File

@ -61,6 +61,10 @@ internal enum class PatchList(
"Disable music video in album",
"Adds option to redirect music videos from albums for non-premium users."
),
DISABLE_QUIC_PROTOCOL(
"Disable QUIC protocol",
"Adds an option to disable CronetEngine's QUIC protocol."
),
ENABLE_OPUS_CODEC(
"Enable OPUS codec",
"Adds an option to enable the OPUS audio codec if the player response includes it."

View File

@ -4,6 +4,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWith
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.extension.Constants.PATCHES_PATH
import app.revanced.util.fingerprint.matchOrThrow
import app.revanced.util.fingerprint.methodOrThrow
import app.revanced.util.getReference
@ -13,9 +14,10 @@ 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.reference.MethodReference
fun baseOpusCodecsPatch(
descriptor: String,
) = bytecodePatch(
private const val EXTENSION_CLASS_DESCRIPTOR =
"$PATCHES_PATH/OpusCodecPatch;"
fun baseOpusCodecsPatch() = bytecodePatch(
description = "baseOpusCodecsPatch"
) {
execute {
@ -35,7 +37,7 @@ fun baseOpusCodecsPatch(
addInstructionsWithLabels(
targetIndex + 1, """
invoke-static {}, $descriptor
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->enableOpusCodec()Z
move-result v$freeRegister
if-eqz v$freeRegister, :mp4a
invoke-static {}, $opusCodecReference

View File

@ -0,0 +1,30 @@
@file:Suppress("SpellCheckingInspection")
package app.revanced.patches.shared.quic
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.shared.extension.Constants.PATCHES_PATH
import app.revanced.util.fingerprint.methodOrThrow
private const val EXTENSION_CLASS_DESCRIPTOR =
"$PATCHES_PATH/QUICProtocolPatch;"
fun baseQuicProtocolPatch() = bytecodePatch(
description = "baseQuicProtocolPatch"
) {
execute {
arrayOf(
cronetEngineBuilderFingerprint,
experimentalCronetEngineBuilderFingerprint
).forEach {
it.methodOrThrow().addInstructions(
0, """
invoke-static {p1}, $EXTENSION_CLASS_DESCRIPTOR->disableQUICProtocol(Z)Z
move-result p1
"""
)
}
}
}

View File

@ -1,6 +1,6 @@
@file:Suppress("SpellCheckingInspection")
package app.revanced.patches.youtube.misc.quic
package app.revanced.patches.shared.quic
import app.revanced.util.fingerprint.legacyFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

View File

@ -3,7 +3,6 @@ package app.revanced.patches.youtube.misc.codecs
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.shared.opus.baseOpusCodecsPatch
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.extension.Constants.MISC_PATH
import app.revanced.patches.youtube.utils.patch.PatchList.ENABLE_OPUS_CODEC
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
import app.revanced.patches.youtube.utils.settings.settingsPatch
@ -16,16 +15,11 @@ val opusCodecPatch = bytecodePatch(
compatibleWith(COMPATIBLE_PACKAGE)
dependsOn(
baseOpusCodecsPatch(
"$MISC_PATH/OpusCodecPatch;->enableOpusCodec()Z"
),
settingsPatch,
baseOpusCodecsPatch(),
)
execute {
// region add settings
addPreference(
arrayOf(
"PREFERENCE_CATEGORY: MISC_EXPERIMENTAL_FLAGS",
@ -33,8 +27,5 @@ val opusCodecPatch = bytecodePatch(
),
ENABLE_OPUS_CODEC
)
// endregion
}
}

View File

@ -1,47 +1,30 @@
package app.revanced.patches.youtube.misc.quic
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.shared.quic.baseQuicProtocolPatch
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.extension.Constants.MISC_PATH
import app.revanced.patches.youtube.utils.patch.PatchList.DISABLE_QUIC_PROTOCOL
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
import app.revanced.patches.youtube.utils.settings.settingsPatch
import app.revanced.util.fingerprint.methodOrThrow
@Suppress("unused")
@Suppress("unused", "SpellCheckingInspection")
val quicProtocolPatch = bytecodePatch(
DISABLE_QUIC_PROTOCOL.title,
DISABLE_QUIC_PROTOCOL.summary,
) {
compatibleWith(COMPATIBLE_PACKAGE)
dependsOn(settingsPatch)
dependsOn(
settingsPatch,
baseQuicProtocolPatch(),
)
execute {
arrayOf(
cronetEngineBuilderFingerprint,
experimentalCronetEngineBuilderFingerprint
).forEach {
it.methodOrThrow().addInstructions(
0, """
invoke-static {p1}, $MISC_PATH/QUICProtocolPatch;->disableQUICProtocol(Z)Z
move-result p1
"""
)
}
// region add settings
addPreference(
arrayOf(
"SETTINGS: DISABLE_QUIC_PROTOCOL"
),
DISABLE_QUIC_PROTOCOL
)
// endregion
}
}