2023-05-13 01:32:41 +02:00
|
|
|
package app.revanced.patches.youtube.video.hdrbrightness.patch
|
2022-07-03 20:50:20 +02:00
|
|
|
|
2022-07-08 21:17:50 +02:00
|
|
|
import app.revanced.patcher.annotation.Description
|
|
|
|
import app.revanced.patcher.annotation.Name
|
|
|
|
import app.revanced.patcher.annotation.Version
|
2022-10-05 04:03:10 +02:00
|
|
|
import app.revanced.patcher.data.BytecodeContext
|
2022-07-03 20:50:20 +02:00
|
|
|
import app.revanced.patcher.extensions.addInstructions
|
2022-10-05 04:03:10 +02:00
|
|
|
import app.revanced.patcher.patch.BytecodePatch
|
2022-07-03 20:50:20 +02:00
|
|
|
import app.revanced.patcher.patch.PatchResult
|
|
|
|
import app.revanced.patcher.patch.PatchResultSuccess
|
2022-08-03 03:53:35 +02:00
|
|
|
import app.revanced.patcher.patch.annotations.DependsOn
|
2022-07-08 21:17:50 +02:00
|
|
|
import app.revanced.patcher.patch.annotations.Patch
|
2023-05-13 01:32:41 +02:00
|
|
|
import app.revanced.patches.youtube.video.hdrbrightness.annotations.HDRBrightnessCompatibility
|
|
|
|
import app.revanced.patches.youtube.video.hdrbrightness.fingerprints.HDRBrightnessFingerprint
|
2022-07-11 18:59:26 +02:00
|
|
|
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
2022-08-22 01:59:43 +02:00
|
|
|
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
2022-11-28 20:13:34 +01:00
|
|
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
|
|
|
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
2022-07-11 18:59:26 +02:00
|
|
|
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
|
|
|
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
|
|
|
|
import org.jf.dexlib2.iface.reference.FieldReference
|
2022-07-03 20:50:20 +02:00
|
|
|
|
2022-07-31 12:15:26 +02:00
|
|
|
@Patch
|
2022-07-11 18:59:26 +02:00
|
|
|
@Name("hdr-auto-brightness")
|
|
|
|
@Description("Makes the brightness of HDR videos follow the system default.")
|
2022-07-03 20:50:20 +02:00
|
|
|
@HDRBrightnessCompatibility
|
2022-07-11 18:59:26 +02:00
|
|
|
@Version("0.0.2")
|
2022-08-22 01:59:43 +02:00
|
|
|
@DependsOn([IntegrationsPatch::class, SettingsPatch::class])
|
2022-07-03 20:50:20 +02:00
|
|
|
class HDRBrightnessPatch : BytecodePatch(
|
2022-09-18 08:06:35 +02:00
|
|
|
listOf(HDRBrightnessFingerprint)
|
2022-07-03 20:50:20 +02:00
|
|
|
) {
|
2022-10-05 04:03:10 +02:00
|
|
|
override fun execute(context: BytecodeContext): PatchResult {
|
2023-05-13 01:32:41 +02:00
|
|
|
SettingsPatch.PreferenceScreen.VIDEO.addPreferences(
|
2022-08-22 01:59:43 +02:00
|
|
|
SwitchPreference(
|
2023-05-15 09:51:43 +02:00
|
|
|
"revanced_hdr_auto_brightness",
|
|
|
|
StringResource("revanced_hdr_auto_brightness_title", "Enable auto HDR brightness"),
|
|
|
|
StringResource("revanced_hdr_auto_brightness_summary_on", "Auto HDR brightness is enabled"),
|
|
|
|
StringResource("revanced_hdr_auto_brightness_summary_off", "Auto HDR brightness is disabled")
|
2022-08-22 01:59:43 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2022-09-18 08:06:35 +02:00
|
|
|
val method = HDRBrightnessFingerprint.result!!.mutableMethod
|
2022-07-03 20:50:20 +02:00
|
|
|
|
2022-09-18 08:06:35 +02:00
|
|
|
method.implementation!!.instructions.filter { instruction ->
|
|
|
|
val fieldReference = (instruction as? ReferenceInstruction)?.reference as? FieldReference
|
|
|
|
fieldReference?.let { it.name == "screenBrightness" } == true
|
2022-07-11 18:59:26 +02:00
|
|
|
}.forEach { instruction ->
|
2022-09-18 08:06:35 +02:00
|
|
|
val brightnessRegisterIndex = method.implementation!!.instructions.indexOf(instruction)
|
2022-07-11 18:59:26 +02:00
|
|
|
val register = (instruction as TwoRegisterInstruction).registerA
|
2022-07-03 20:50:20 +02:00
|
|
|
|
2022-09-18 08:06:35 +02:00
|
|
|
val insertIndex = brightnessRegisterIndex + 1
|
2022-07-11 18:59:26 +02:00
|
|
|
method.addInstructions(
|
2022-09-18 08:06:35 +02:00
|
|
|
insertIndex,
|
|
|
|
"""
|
|
|
|
invoke-static {v$register}, Lapp/revanced/integrations/patches/HDRAutoBrightnessPatch;->getHDRBrightness(F)F
|
|
|
|
move-result v$register
|
|
|
|
"""
|
2022-07-11 18:59:26 +02:00
|
|
|
)
|
|
|
|
}
|
2022-09-18 08:06:35 +02:00
|
|
|
|
2022-07-03 20:50:20 +02:00
|
|
|
return PatchResultSuccess()
|
|
|
|
}
|
|
|
|
}
|