generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube): Add patch
Disable HDR video
(#4347)
- Loading branch information
1 parent
6f2e474
commit 0528f7c
Showing
7 changed files
with
120 additions
and
8 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/DisableHdrPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package app.revanced.extension.youtube.patches; | ||
|
||
import app.revanced.extension.youtube.settings.Settings; | ||
|
||
@SuppressWarnings("unused") | ||
public class DisableHdrPatch { | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static boolean disableHDRVideo() { | ||
return !Settings.DISABLE_HDR_VIDEO.get(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
patches/src/main/kotlin/app/revanced/patches/youtube/video/hdr/DisableHdrPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package app.revanced.patches.youtube.video.hdr | ||
|
||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels | ||
import app.revanced.patcher.patch.bytecodePatch | ||
import app.revanced.patches.all.misc.resources.addResources | ||
import app.revanced.patches.all.misc.resources.addResourcesPatch | ||
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference | ||
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch | ||
import app.revanced.patches.youtube.misc.settings.PreferenceScreen | ||
import app.revanced.patches.youtube.misc.settings.settingsPatch | ||
import app.revanced.util.getReference | ||
import app.revanced.util.indexOfFirstInstructionOrThrow | ||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference | ||
|
||
private const val EXTENSION_CLASS_DESCRIPTOR = | ||
"Lapp/revanced/extension/youtube/patches/DisableHdrPatch;" | ||
|
||
@Suppress("unused") | ||
val disableHdrPatch = bytecodePatch( | ||
name = "Disable HDR video", | ||
description = "Adds an option to disable video HDR.", | ||
) { | ||
dependsOn( | ||
sharedExtensionPatch, | ||
settingsPatch, | ||
addResourcesPatch, | ||
) | ||
|
||
compatibleWith( | ||
"com.google.android.youtube"( | ||
"18.38.44", | ||
"18.49.37", | ||
"19.16.39", | ||
"19.25.37", | ||
"19.34.42", | ||
"19.43.41", | ||
"19.45.38", | ||
"19.46.42", | ||
"19.47.53", | ||
), | ||
) | ||
|
||
execute { | ||
addResources("youtube", "video.hdr.disableHdrPatch") | ||
|
||
PreferenceScreen.VIDEO.addPreferences( | ||
SwitchPreference("revanced_disable_hdr_video") | ||
) | ||
|
||
hdrCapabilityFingerprint.let { | ||
it.originalMethod.apply { | ||
val stringIndex = it.stringMatches!!.first().index | ||
val navigateIndex = indexOfFirstInstructionOrThrow(stringIndex) { | ||
val reference = getReference<MethodReference>() | ||
reference?.parameterTypes == listOf("I", "Landroid/view/Display;") && | ||
reference.returnType == "Z" | ||
} | ||
|
||
// Modify the HDR lookup method (Method is in the same class as the fingerprint). | ||
navigate(this).to(navigateIndex).stop().addInstructionsWithLabels( | ||
0, | ||
""" | ||
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->disableHDRVideo()Z | ||
move-result v0 | ||
if-nez v0, :useHdr | ||
return v0 | ||
:useHdr | ||
nop | ||
""" | ||
) | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
patches/src/main/kotlin/app/revanced/patches/youtube/video/hdr/Fingerprints.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package app.revanced.patches.youtube.video.hdr | ||
|
||
import app.revanced.patcher.fingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
|
||
internal val hdrCapabilityFingerprint = fingerprint { | ||
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) | ||
strings( | ||
"av1_profile_main_10_hdr_10_plus_supported", | ||
"video/av01" | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters