diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/hdr/fingerprints/HdrCapabilitiesFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/video/hdr/fingerprints/HdrCapabilitiesFingerprint.kt new file mode 100644 index 000000000..98df5e3ff --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/video/hdr/fingerprints/HdrCapabilitiesFingerprint.kt @@ -0,0 +1,20 @@ +package app.revanced.patches.youtube.video.hdr.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object HdrCapabilitiesFingerprint : MethodFingerprint( + returnType = "V", + access = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L", "L"), + opcodes = listOf( + Opcode.INVOKE_VIRTUAL_RANGE, + Opcode.MOVE_RESULT, + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_VIRTUAL, + ), + strings = listOf("av1_profile_main_10_hdr_10_plus_supported") +) diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/hdr/patch/DisableHdrVideoPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/hdr/patch/DisableHdrVideoPatch.kt new file mode 100644 index 000000000..e64ba34a2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/video/hdr/patch/DisableHdrVideoPatch.kt @@ -0,0 +1,68 @@ +package app.revanced.patches.youtube.video.hdr.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.data.toMethodWalker +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction +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.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.shared.annotation.YouTubeCompatibility +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.patches.youtube.video.hdr.fingerprints.HdrCapabilitiesFingerprint +import app.revanced.util.integrations.Constants.VIDEO_PATH + +@Patch +@Name("disable-hdr-video") +@Description("Disable HDR video.") +@DependsOn([SettingsPatch::class]) +@YouTubeCompatibility +@Version("0.0.1") +class DisableHdrVideoPatch : BytecodePatch( + listOf( + HdrCapabilitiesFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + + HdrCapabilitiesFingerprint.result?.let { + with (context + .toMethodWalker(it.method) + .nextMethod(it.scanResult.patternScanResult!!.endIndex, true) + .getMethod() as MutableMethod + ) { + addInstructions( + 0, + """ + invoke-static {}, $VIDEO_PATH/HDRVideoPatch;->disableHDRVideo()Z + move-result v0 + if-nez v0, :default + return v0 + """, listOf(ExternalLabel("default", instruction(0))) + ) + } + } ?: return HdrCapabilitiesFingerprint.toErrorResult() + + /* + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: VIDEO_SETTINGS", + "SETTINGS: DISABLE_HDR_VIDEO" + ) + ) + + SettingsPatch.updatePatchStatus("disable-hdr-video") + + return PatchResultSuccess() + } +} diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 70ca3dc59..852bc16ec 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -54,6 +54,9 @@ Zoom haptic feedback is enabled Zoom haptic feedback is disabled Disable zoom haptic feedback + HDR video is enabled + HDR video is disabled + Disable HDR video Landscape mode when entering fullscreen is enabled Landscape mode when entering fullscreen is disabled Disable landscape mode diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 7e3a04b8c..a1f29ee8d 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -405,6 +405,9 @@ + + @@ -535,6 +538,7 @@ +