refactor: simplify casting instructions

This commit is contained in:
inotia00
2023-05-10 21:31:51 +09:00
parent 0f5350e691
commit 2b70050200
144 changed files with 888 additions and 1272 deletions

View File

@ -21,18 +21,11 @@ import org.w3c.dom.Element
@YouTubeCompatibility
@Version("0.0.1")
class PlayerButtonBackgroundPatch : ResourcePatch {
private companion object {
const val RESOURCE_FILE_PATH = "res/drawable/player_button_circle_background.xml"
val replacements = arrayOf(
"color"
)
}
override fun execute(context: ResourceContext): PatchResult {
context.xmlEditor[RESOURCE_FILE_PATH].use { editor ->
context.xmlEditor["res/drawable/player_button_circle_background.xml"].use { editor ->
editor.file.doRecursively { node ->
replacements.forEach replacement@{ replacement ->
arrayOf("color").forEach replacement@{ replacement ->
if (node !is Element) return@replacement
node.getAttributeNode("android:$replacement")?.let { attribute ->

View File

@ -14,9 +14,9 @@ import app.revanced.patches.youtube.layout.etc.theme.patch.GeneralThemePatch
import app.revanced.patches.youtube.layout.etc.theme.patch.GeneralThemePatch.Companion.isMonetPatchIncluded
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.resources.ResourceHelper.updatePatchStatusTheme
import app.revanced.util.resources.ResourceUtils
import app.revanced.util.resources.ResourceUtils.copyResources
import app.revanced.util.resources.ResourceUtils.copyXmlNode
import java.nio.file.Files
import java.nio.file.StandardCopyOption
@Patch(false)
@Name("materialyou")
@ -32,35 +32,28 @@ import java.nio.file.StandardCopyOption
class MaterialYouPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
val drawables1 = "drawable-night-v31" to arrayOf(
"new_content_dot_background.xml"
)
val drawables2 = "drawable-v31" to arrayOf(
"new_content_count_background.xml",
"new_content_dot_background.xml"
)
val layout1 = "layout-v31" to arrayOf(
"new_content_count.xml"
)
arrayOf(drawables1, drawables2, layout1).forEach { (path, resourceNames) ->
Files.createDirectory(context["res"].resolve(path).toPath())
resourceNames.forEach { name ->
val monetPath = "$path/$name"
Files.copy(
this.javaClass.classLoader.getResourceAsStream("youtube/materialyou/$monetPath")!!,
context["res"].resolve(monetPath).toPath(),
StandardCopyOption.REPLACE_EXISTING
)
}
arrayOf(
ResourceUtils.ResourceGroup(
"drawable-night-v31",
"new_content_dot_background.xml"
),
ResourceUtils.ResourceGroup(
"drawable-v31",
"new_content_count_background.xml",
"new_content_dot_background.xml"
),
ResourceUtils.ResourceGroup(
"layout-v31",
"new_content_count.xml"
)
).forEach {
context["res/${it.resourceDirectoryName}"].mkdirs()
context.copyResources("youtube/materialyou", it)
}
context.copyXmlNode("youtube/materialyou/host", "values-v31/colors.xml", "resources")
/*
/**
* Add settings
*/
context.updatePatchStatusTheme("materialyou")

View File

@ -29,7 +29,7 @@ class RedundantResourcePatch : ResourcePatch {
WHITELIST_XHDPI,
WHITELIST_XXXHDPI
).forEach { (path, array) ->
val tmpDirectory = path + "-v21"
val tmpDirectory = "$path-v21"
Files.createDirectory(context["res"].resolve(tmpDirectory).toPath())
(WHITELIST_GENERAL + array).forEach { name ->

View File

@ -2,19 +2,13 @@ package app.revanced.patches.youtube.layout.etc.tooltip.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.toolTipId
import app.revanced.util.bytecode.isWideLiteralExists
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object TooltipContentViewFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.tooltipLabelId
} == true
}
customFingerprint = { it.isWideLiteralExists(toolTipId) }
)

View File

@ -39,7 +39,7 @@ class TooltipContentViewPatch : BytecodePatch(
"return-void"
) ?: return TooltipContentViewFingerprint.toErrorResult()
/*
/**
* Add settings
*/
SettingsPatch.updatePatchStatus("hide-tooltip-content")