2022-06-01 01:35:23 +02:00
|
|
|
package app.revanced.patches.youtube.misc.mapping.patch
|
|
|
|
|
2022-06-01 01:50:01 +02:00
|
|
|
import app.revanced.extensions.doRecursively
|
2022-06-01 01:35:23 +02:00
|
|
|
import app.revanced.patcher.annotation.Description
|
|
|
|
import app.revanced.patcher.annotation.Name
|
|
|
|
import app.revanced.patcher.annotation.Version
|
|
|
|
import app.revanced.patcher.data.implementation.ResourceData
|
|
|
|
import app.revanced.patcher.patch.implementation.ResourcePatch
|
|
|
|
import app.revanced.patcher.patch.implementation.misc.PatchResult
|
|
|
|
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
|
|
|
|
import org.w3c.dom.Element
|
|
|
|
|
|
|
|
@Name("resource-id-mapping-provider-resource-patch-dependency")
|
2022-06-03 17:38:56 +02:00
|
|
|
@Description("This patch acts as a provider/ dependency for resource mappings.")
|
2022-06-01 01:35:23 +02:00
|
|
|
@Version("0.0.1")
|
|
|
|
class ResourceIdMappingProviderResourcePatch : ResourcePatch() {
|
|
|
|
companion object {
|
|
|
|
internal lateinit var resourceMappings: Map<String, Long>
|
|
|
|
private set
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun execute(data: ResourceData): PatchResult {
|
|
|
|
data.getXmlEditor("res/values/public.xml").use { editor ->
|
|
|
|
resourceMappings = buildMap {
|
|
|
|
editor.file.documentElement.doRecursively { node ->
|
|
|
|
if (node !is Element) return@doRecursively
|
|
|
|
val nameAttribute = node.getAttribute("name")
|
|
|
|
if (node.nodeName != "public" || nameAttribute.startsWith("APKTOOL")) return@doRecursively
|
|
|
|
this[nameAttribute] = node.getAttribute("id").substring(2).toLong(16)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PatchResultSuccess()
|
|
|
|
}
|
|
|
|
}
|