diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/general/bytecode/patch/GeneralBytecodeAdsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/general/bytecode/patch/GeneralBytecodeAdsPatch.kt index d3c948124..57ee1f6dd 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/general/bytecode/patch/GeneralBytecodeAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/general/bytecode/patch/GeneralBytecodeAdsPatch.kt @@ -21,6 +21,7 @@ import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.youtube.ad.general.annotation.GeneralAdsCompatibility import app.revanced.patches.youtube.ad.general.bytecode.extensions.MethodExtensions.findMutableMethodOf import app.revanced.patches.youtube.ad.general.bytecode.extensions.MethodExtensions.toDescriptor +import app.revanced.patches.youtube.ad.general.resource.patch.GeneralResourceAdsPatch import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.mapping.patch.ResourceMappingResourcePatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch @@ -38,7 +39,7 @@ import org.jf.dexlib2.iface.reference.MethodReference import org.jf.dexlib2.iface.reference.StringReference @Patch -@DependsOn([ResourceMappingResourcePatch::class, IntegrationsPatch::class, SettingsPatch::class]) +@DependsOn([ResourceMappingResourcePatch::class, IntegrationsPatch::class, SettingsPatch::class, GeneralResourceAdsPatch::class]) @Name("general-ads") @Description("Removes general ads.") @GeneralAdsCompatibility @@ -386,4 +387,4 @@ class GeneralBytecodeAdsPatch : BytecodePatch() { instruction.opcode == Opcode.CONST && (instruction as Instruction31i).narrowLiteral == lithoConstant } ?: false } -} +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/general/resource/patch/GeneralResourceAdsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/general/resource/patch/GeneralResourceAdsPatch.kt new file mode 100644 index 000000000..37b2711eb --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/general/resource/patch/GeneralResourceAdsPatch.kt @@ -0,0 +1,55 @@ +package app.revanced.patches.youtube.ad.general.resource.patch + +import app.revanced.extensions.doRecursively +import app.revanced.extensions.startsWithAny +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.annotations.DependsOn +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patches.youtube.ad.general.annotation.GeneralAdsCompatibility +import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch +import org.w3c.dom.Element + +@DependsOn(dependencies = [FixLocaleConfigErrorPatch::class]) +@Name("general-resource-ads") +@Description("Patch to remove general ads in resources.") +@GeneralAdsCompatibility +@Version("0.0.1") +class GeneralResourceAdsPatch : ResourcePatch { + // list of resource file names which need to be hidden + private val resourceFileNames = arrayOf( + "compact_promoted_", + "promoted_video_", + ) + + // the attributes to change the value of + private val replacements = arrayOf( + "height", + "width", + "marginTop", + ) + + override fun execute(context: ResourceContext): PatchResult { + context.forEach { + if (!it.name.startsWithAny(*resourceFileNames)) return@forEach + + // for each file in the "layouts" directory replace all necessary attributes content + context.xmlEditor[it.absolutePath].use { editor -> + editor.file.doRecursively { node -> + replacements.forEach replacement@{ replacement -> + if (node !is Element) return@replacement + + node.getAttributeNode("android:layout_$replacement")?.let { attribute -> + attribute.textContent = "1.0dip" + } + } + } + } + } + return PatchResultSuccess() + } +}