generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
hdr-max-brightness
patch (#105)
- Loading branch information
Showing
4 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
...app/revanced/patches/youtube/misc/hdrbrightness/annotations/HDRBrightnessCompatibility.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,13 @@ | ||
package app.revanced.patches.youtube.misc.hdrbrightness.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf("17.24.34", "17.24.35", "17.25.34") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class HDRBrightnessCompatibility |
35 changes: 35 additions & 0 deletions
35
.../app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprint.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,35 @@ | ||
package app.revanced.patches.youtube.misc.hdrbrightness.fingerprints | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod | ||
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.misc.hdrbrightness.annotations.HDRBrightnessCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction | ||
|
||
@Name("hdrbrightness-fingerprint") | ||
@MatchingMethod( | ||
"Lghz;", "mZ" | ||
) | ||
@FuzzyPatternScanMethod(3) | ||
@HDRBrightnessCompatibility | ||
@Version("0.0.1") | ||
object HDRBrightnessFingerprint : MethodFingerprint( | ||
"V", AccessFlags.PUBLIC or AccessFlags.FINAL, null, | ||
listOf( | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.CONST_HIGH16, | ||
Opcode.IPUT, | ||
Opcode.INVOKE_VIRTUAL | ||
), | ||
null, | ||
customFingerprint = { methodDef -> | ||
methodDef.implementation!!.instructions.count() == 16 && methodDef.implementation!!.instructions.any {((it as? NarrowLiteralInstruction)?.narrowLiteral == (-1.0f).toRawBits())} | ||
} | ||
) |
51 changes: 51 additions & 0 deletions
51
src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/patch/HDRBrightnessPatch.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,51 @@ | ||
package app.revanced.patches.youtube.misc.hdrbrightness.patch; | ||
|
||
import app.revanced.patcher.annotation.Description; | ||
import app.revanced.patcher.annotation.Name; | ||
import app.revanced.patcher.annotation.Version; | ||
import app.revanced.patcher.data.impl.BytecodeData | ||
import app.revanced.patcher.extensions.addInstructions | ||
import app.revanced.patcher.extensions.removeInstruction | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultError | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.Patch; | ||
import app.revanced.patcher.patch.impl.BytecodePatch; | ||
import app.revanced.patcher.util.smali.toBuilderInstruction | ||
import app.revanced.patches.youtube.misc.hdrbrightness.annotations.HDRBrightnessCompatibility; | ||
import app.revanced.patches.youtube.misc.hdrbrightness.fingerprints.HDRBrightnessFingerprint | ||
import org.jf.dexlib2.Opcode | ||
import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction | ||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction | ||
|
||
@Patch | ||
@Name("hdr-max-brightness") | ||
@Description("Set brightness to max for HDR videos in fullscreen mode.") | ||
@HDRBrightnessCompatibility | ||
@Version("0.0.1") | ||
class HDRBrightnessPatch : BytecodePatch( | ||
listOf( | ||
HDRBrightnessFingerprint | ||
) | ||
) { | ||
override fun execute(data: BytecodeData): PatchResult { | ||
val result = HDRBrightnessFingerprint.result | ||
?: return PatchResultError("HDRBrightnessFingerprint could not resolve the method!") | ||
|
||
|
||
val method = result.mutableMethod | ||
|
||
//Get the index here so we know where to inject our code to override -1.0f | ||
val index = method.implementation!!.instructions.indexOfFirst { ((it as? NarrowLiteralInstruction)?.narrowLiteral == (-1.0f).toRawBits()) } | ||
val register = (method.implementation!!.instructions.get(index) as OneRegisterInstruction).registerA | ||
|
||
method.addInstructions( | ||
index + 1, """ | ||
invoke-static {v$register}, Lapp/revanced/integrations/patches/HDRMaxBrightnessPatch;->getHDRBrightness(F)F | ||
move-result v$register | ||
""" | ||
) | ||
|
||
return PatchResultSuccess() | ||
} | ||
} |