add amoled patch

This commit is contained in:
inotia00
2023-04-16 01:13:04 +09:00
parent a34aabe454
commit 6589cf6379
3 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,19 @@
package app.revanced.patches.music.layout.amoled.bytecode.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 LithoThemeFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PROTECTED or AccessFlags.FINAL,
parameters = listOf("L"),
opcodes = listOf(
Opcode.IF_NEZ,
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.RETURN_VOID
),
customFingerprint = { it.name == "onBoundsChange" }
)

View File

@ -0,0 +1,42 @@
package app.revanced.patches.music.layout.amoled.bytecode.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
import app.revanced.patches.music.layout.amoled.bytecode.fingerprints.LithoThemeFingerprint
import app.revanced.util.integrations.Constants.UTILS_PATH
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
@Name("amoled-bytecode-patch")
@YouTubeMusicCompatibility
@Version("0.0.1")
class AmoledBytecodePatch : BytecodePatch(
listOf(
LithoThemeFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
LithoThemeFingerprint.result?.let {
with (it.mutableMethod) {
val insertIndex = it.scanResult.patternScanResult!!.endIndex - 1
val register = (implementation!!.instructions[insertIndex] as Instruction35c).registerD
addInstructions(
insertIndex, """
invoke-static { v$register }, $UTILS_PATH/LithoThemePatch;->applyLithoTheme(I)I
move-result v$register
"""
)
}
} ?: return LithoThemeFingerprint.toErrorResult()
return PatchResultSuccess()
}
}

View File

@ -0,0 +1,42 @@
package app.revanced.patches.music.layout.amoled.resource.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.music.layout.amoled.bytecode.patch.AmoledBytecodePatch
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
import org.w3c.dom.Element
@Patch
@Name("amoled")
@Description("Applies pure black theme in flyout panels.")
@DependsOn([AmoledBytecodePatch::class])
@YouTubeMusicCompatibility
@Version("0.0.1")
class AmoledPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
context.xmlEditor["res/values/colors.xml"].use { editor ->
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
for (i in 0 until resourcesNode.childNodes.length) {
val node = resourcesNode.childNodes.item(i) as? Element ?: continue
node.textContent = when (node.getAttribute("name")) {
"yt_black0", "yt_black1", "yt_black1_opacity95", "yt_black1_opacity98", "yt_black2", "yt_black3",
"yt_black4", "yt_status_bar_background_dark", "ytm_color_grey_12", "material_grey_850" -> "@android:color/black"
else -> continue
}
}
}
return PatchResultSuccess()
}
}