From c09268f7ecce3b0d34f81fad6cbd82b4be601088 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sun, 25 Dec 2022 22:38:11 +0900 Subject: [PATCH] minor improvements --- .../integrations/patch/IntegrationsPatch.kt | 2 +- .../settings/resource/patch/SettingsPatch.kt | 2 + .../patch/SponsorBlockBytecodePatch.kt | 2 +- .../resource/GeneralThemeResourcePatch.kt | 97 ++++++++++--------- 4 files changed, 54 insertions(+), 49 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/integrations/patch/IntegrationsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/integrations/patch/IntegrationsPatch.kt index 2aa2fe93d..6401bccea 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/integrations/patch/IntegrationsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/integrations/patch/IntegrationsPatch.kt @@ -11,5 +11,5 @@ import app.revanced.shared.patches.integrations.AbstractIntegrationsPatch @YouTubeCompatibility class IntegrationsPatch : AbstractIntegrationsPatch( "Lapp/revanced/integrations/utils/ReVancedUtils;", - listOf(InitFingerprint), + listOf(InitFingerprint, StandalonePlayerFingerprint, ServiceFingerprint), ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/resource/patch/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/resource/patch/SettingsPatch.kt index db00ceb7d..773ed69ea 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/resource/patch/SettingsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/resource/patch/SettingsPatch.kt @@ -14,6 +14,7 @@ import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatc import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourcdIdPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsBytecodePatch import app.revanced.shared.annotation.YouTubeCompatibility +import app.revanced.shared.patches.options.PatchOptions import app.revanced.shared.patches.settings.AbstractSettingsResourcePatch import app.revanced.shared.util.resources.ResourceHelper import app.revanced.shared.util.resources.ResourceUtils @@ -27,6 +28,7 @@ import org.w3c.dom.Element [ FixLocaleConfigErrorPatch::class, IntegrationsPatch::class, + PatchOptions::class, SharedResourcdIdPatch::class, SettingsBytecodePatch::class ] diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt index 13e53c381..09aa8dfce 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt @@ -127,7 +127,7 @@ class SponsorBlockBytecodePatch : BytecodePatch( val instanceRegister = 0 NextGenWatchLayoutFingerprint.result!!.mutableMethod.addInstruction( 3, // after super call - "invoke-static/range {p$instanceRegister}, Lapp/revanced/integrations/sponsorblock/PlayerController;->addSkipSponsorView15(Landroid/view/View;)V" + "invoke-static/range {p$instanceRegister}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->addSkipSponsorView15(Landroid/view/View;)V" ) BytecodeHelper.injectInit(context, "FirstRun", "initializationSB") diff --git a/src/main/kotlin/app/revanced/shared/patches/theme/resource/GeneralThemeResourcePatch.kt b/src/main/kotlin/app/revanced/shared/patches/theme/resource/GeneralThemeResourcePatch.kt index aea2ab768..1e784b028 100644 --- a/src/main/kotlin/app/revanced/shared/patches/theme/resource/GeneralThemeResourcePatch.kt +++ b/src/main/kotlin/app/revanced/shared/patches/theme/resource/GeneralThemeResourcePatch.kt @@ -13,66 +13,69 @@ import org.w3c.dom.Element class GeneralThemeResourcePatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - // copies the resource file to change the splash screen color - context.xmlEditor["res/values/attrs.xml"].use { editor -> - with(editor.file) { - val resourcesNode = getElementsByTagName("resources").item(0) as Element + // edit the resource files to change the splash screen color + val attrsPath = "res/values/attrs.xml" + val stylesPaths: List = listOf( + "res/values/styles.xml", // Android 11 (and below) + "res/values-v31/styles.xml", // Android 12 (and above) + ) - val newElement: Element = createElement("attr") - newElement.setAttribute("format", "reference") - newElement.setAttribute("name", "splashScreenColor") + context.xmlEditor[attrsPath].use { editor -> + val file = editor.file - resourcesNode.appendChild(newElement) - } + (file.getElementsByTagName("resources").item(0) as Element).appendChild( + file.createElement("attr").apply { + setAttribute("format", "reference") + setAttribute("name", "splashScreenColor") + } + ) } + stylesPaths.forEachIndexed { pathIndex, stylesPath -> + context.xmlEditor[stylesPath].use { editor -> + val file = editor.file - context.xmlEditor["res/values/styles.xml"].use { editor -> - with(editor.file) { - val resourcesNode = getElementsByTagName("resources").item(0) as Element + val childNodes = (file.getElementsByTagName("resources").item(0) as Element).childNodes - for (i in 0 until resourcesNode.childNodes.length) { - val node = resourcesNode.childNodes.item(i) as? Element ?: continue + for (i in 0 until childNodes.length) { + val node = childNodes.item(i) as? Element ?: continue + val nodeAttributeName = node.getAttribute("name") - val newElement: Element = createElement("item") - newElement.setAttribute("name", "splashScreenColor") + file.createElement("item").apply { + setAttribute( + "name", + when (pathIndex) { + 0 -> "splashScreenColor" + 1 -> "android:windowSplashScreenBackground" + else -> "null" + } + ) - when (node.getAttribute("name")) { - "Base.Theme.YouTube.Launcher.Dark" -> { - newElement.appendChild(createTextNode("@color/yt_black1")) + appendChild( + file.createTextNode( + when (pathIndex) { + 0 -> when (nodeAttributeName) { + "Base.Theme.YouTube.Launcher.Dark" -> "@color/yt_black1" + "Base.Theme.YouTube.Launcher.Light" -> "@color/yt_white1" + else -> "null" + } + 1 -> when (nodeAttributeName) { + "Base.Theme.YouTube.Launcher" -> "?attr/splashScreenColor" + else -> "null" + } + else -> "null" + } + ) + ) - node.appendChild(newElement) - } - "Base.Theme.YouTube.Launcher.Light" -> { - newElement.appendChild(createTextNode("@color/yt_white1")); - - node.appendChild(newElement) - } + if (this.textContent != "null") + node.appendChild(this) } } } } - context.xmlEditor["res/values-v31/styles.xml"].use { editor -> - with(editor.file) { - val resourcesNode = getElementsByTagName("resources").item(0) as Element - - val newElement: Element = createElement("item") - newElement.setAttribute("name", "android:windowSplashScreenBackground") - - for (i in 0 until resourcesNode.childNodes.length) { - val node = resourcesNode.childNodes.item(i) as? Element ?: continue - - if (node.getAttribute("name") == "Base.Theme.YouTube.Launcher") { - newElement.appendChild(createTextNode("?attr/splashScreenColor")) - - node.appendChild(newElement) - } - } - } - } - - arrayOf("drawable", "drawable-sw600dp").forEach { drawablePath -> - context.xmlEditor["res/$drawablePath/quantum_launchscreen_youtube.xml"].use { editor -> + arrayOf("drawable", "drawable-sw600dp").forEach { quantumLaunchscreenPath -> + context.xmlEditor["res/$quantumLaunchscreenPath/quantum_launchscreen_youtube.xml"].use { editor -> val resourcesNode = editor.file.getElementsByTagName("item").item(0) as Element if (resourcesNode.attributes.getNamedItem("android:drawable") != null)