diff --git a/build.gradle.kts b/build.gradle.kts index b7264438..130ac9ad 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,7 +25,7 @@ repositories { dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.21") - implementation("app.revanced:revanced-patcher:1.0.0-dev.16") + implementation("app.revanced:revanced-patcher:1.0.0-dev.17") implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.21") } diff --git a/src/main/kotlin/app/revanced/patches/music/audio/codecs/patch/CodecsUnlockPatch.kt b/src/main/kotlin/app/revanced/patches/music/audio/codecs/patch/CodecsUnlockPatch.kt index a30729d1..69fef3f9 100644 --- a/src/main/kotlin/app/revanced/patches/music/audio/codecs/patch/CodecsUnlockPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/audio/codecs/patch/CodecsUnlockPatch.kt @@ -32,7 +32,8 @@ class CodecsUnlockPatch : BytecodePatch( val instructionIndex = result.scanResult.startIndex result = signatures.last().result!! - val codecMethod = data.toMethodWalker(result.immutableMethod).walk(result.scanResult.startIndex).getMethod() + val codecMethod = + data.toMethodWalker(result.immutableMethod).nextMethod(result.scanResult.startIndex).getMethod() implementation.replaceInstruction( instructionIndex, diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/home/patch/PromotionsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/home/patch/PromotionsPatch.kt index c8d397c5..78856f6d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/home/patch/PromotionsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/home/patch/PromotionsPatch.kt @@ -6,8 +6,8 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.implementation.BytecodeData import app.revanced.patcher.data.implementation.toMethodWalker +import app.revanced.patcher.extensions.PatchExtensions.patchName import app.revanced.patcher.extensions.or -import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.implementation.BytecodePatch import app.revanced.patcher.patch.implementation.misc.PatchResult import app.revanced.patcher.patch.implementation.misc.PatchResultError @@ -23,7 +23,7 @@ import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.instruction.formats.Instruction11x -@Patch +//@Patch(dependencies = [IntegrationsPatch::class]) @Name("home-promo-ads") @Description("Patch to remove promoted ads in YouTube.") @PromotionsCompatibility @@ -47,14 +47,14 @@ class PromotionsPatch : BytecodePatch( val toBePatchedInvokeOffset = requiredMethod.immutableMethod.implementation!!.instructions.indexOfFirst { it.opcode == Opcode.INVOKE_DIRECT } val toBePatchedMethod = - data.toMethodWalker(requiredMethod.immutableMethod).walk(toBePatchedInvokeOffset, true) + data.toMethodWalker(requiredMethod.immutableMethod).nextMethod(toBePatchedInvokeOffset, true) .getMethod() as MutableMethod val implementation = toBePatchedMethod.implementation!! val invokeVirtualOffset = implementation.instructions.indexOfFirst { it.opcode == Opcode.INVOKE_VIRTUAL } val moveResultInstruction = implementation.instructions[invokeVirtualOffset + 1] - if (moveResultInstruction.opcode != Opcode.MOVE_RESULT_OBJECT) return PatchResultError("The toBePatchedInvokeOffset offset was wrong in ${(this::class.annotations.find { it is Name } as Name).name}") + if (moveResultInstruction.opcode != Opcode.MOVE_RESULT_OBJECT) return PatchResultError("The toBePatchedInvokeOffset offset was wrong in ${this.javaClass.patchName}") val register = (moveResultInstruction as Instruction11x).registerA implementation.injectHideCall(invokeVirtualOffset + 2, register) diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/video/patch/VideoAdsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/video/patch/VideoAdsPatch.kt index ef1f5272..a6ab73cb 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/video/patch/VideoAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/video/patch/VideoAdsPatch.kt @@ -17,9 +17,10 @@ import app.revanced.patcher.signature.implementation.method.annotation.MatchingM import app.revanced.patcher.util.smali.toInstructions import app.revanced.patches.youtube.ad.video.annotations.VideoAdsCompatibility import app.revanced.patches.youtube.ad.video.signatures.ShowVideoAdsConstructorSignature +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import org.jf.dexlib2.AccessFlags -@Patch +@Patch(dependencies = [IntegrationsPatch::class]) @Name("video-ads") @Description("Patch to remove ads in the YouTube video player.") @VideoAdsCompatibility @@ -37,7 +38,6 @@ class VideoAdsPatch : BytecodePatch( "V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf("Z"), null ) {}) ?: return PatchResultError("Required parent method could not be found.") - // Override the parameter by calling shouldShowAds and setting the parameter to the result result.method.implementation!!.addInstructions( 0, """ diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/patch/EnableSeekbarTappingPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/patch/EnableSeekbarTappingPatch.kt index 37d1f4ef..7048842c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/patch/EnableSeekbarTappingPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/patch/EnableSeekbarTappingPatch.kt @@ -14,6 +14,7 @@ import app.revanced.patcher.util.smali.toInstructions import app.revanced.patches.youtube.interaction.seekbar.annotation.SeekbarTappingCompatibility import app.revanced.patches.youtube.interaction.seekbar.signatures.SeekbarTappingParentSignature import app.revanced.patches.youtube.interaction.seekbar.signatures.SeekbarTappingSignature +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import org.jf.dexlib2.Opcode import org.jf.dexlib2.builder.instruction.BuilderInstruction21t import org.jf.dexlib2.iface.Method @@ -21,7 +22,7 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction11n import org.jf.dexlib2.iface.instruction.formats.Instruction35c -@Patch +@Patch(dependencies = [IntegrationsPatch::class]) @Name("seekbar-tapping") @Description("Enable tapping on the seekbar of the YouTube player.") @SeekbarTappingCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/amoled/patch/AmoledPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/amoled/patch/AmoledPatch.kt index 99538a54..a6f4fc7c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/amoled/patch/AmoledPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/amoled/patch/AmoledPatch.kt @@ -9,10 +9,15 @@ import app.revanced.patcher.patch.implementation.ResourcePatch import app.revanced.patcher.patch.implementation.misc.PatchResult import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess import app.revanced.patches.youtube.layout.amoled.annotations.AmoledCompatibility +import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch import org.w3c.dom.Element import java.io.File -@Patch +@Patch( + dependencies = [ + FixLocaleConfigErrorPatch::class + ] +) @Name("amoled") @Description("Enables pure black theme.") @AmoledCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/createbutton/patch/CreateButtonRemoverPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/createbutton/patch/CreateButtonRemoverPatch.kt index 42b75c40..d4b343cc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/createbutton/patch/CreateButtonRemoverPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/createbutton/patch/CreateButtonRemoverPatch.kt @@ -12,10 +12,11 @@ import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess import app.revanced.patcher.util.smali.toInstruction import app.revanced.patches.youtube.layout.createbutton.annotations.CreateButtonCompatibility import app.revanced.patches.youtube.layout.createbutton.signatures.CreateButtonSignature +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.instruction.formats.Instruction35c -@Patch +@Patch(dependencies = [IntegrationsPatch::class]) @Name("disable-create-button") @Description("Disable the create button.") @CreateButtonCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/minimizedplayback/patch/MinimizedPlaybackPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/minimizedplayback/patch/MinimizedPlaybackPatch.kt index 8cd9c79b..bb28b6c8 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/minimizedplayback/patch/MinimizedPlaybackPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/minimizedplayback/patch/MinimizedPlaybackPatch.kt @@ -19,7 +19,6 @@ import app.revanced.patches.youtube.layout.minimizedplayback.signatures.Minimize @Description("Enable minimized and background playback.") @MinimizedPlaybackCompatibility @Version("0.0.1") - class MinimizedPlaybackPatch : BytecodePatch( listOf( MinimizedPlaybackManagerSignature diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/patch/OldQualityLayoutPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/patch/OldQualityLayoutPatch.kt index 88b397cc..2ba18245 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/patch/OldQualityLayoutPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/patch/OldQualityLayoutPatch.kt @@ -17,11 +17,12 @@ import app.revanced.patcher.signature.implementation.method.annotation.MatchingM import app.revanced.patcher.util.smali.toInstructions import app.revanced.patches.youtube.layout.oldqualitylayout.annotations.OldQualityLayoutCompatibility import app.revanced.patches.youtube.layout.oldqualitylayout.signatures.OldQualityParentSignature +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode import org.jf.dexlib2.builder.instruction.BuilderInstruction21t -@Patch +@Patch(dependencies = [IntegrationsPatch::class]) @Name("old-quality-layout") @Description("Enable the original quality flyout menu.") @OldQualityLayoutCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/button/patch/ShortsButtonRemoverPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/button/patch/ShortsButtonRemoverPatch.kt index 60a24861..0c0b05f2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/button/patch/ShortsButtonRemoverPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/button/patch/ShortsButtonRemoverPatch.kt @@ -12,9 +12,10 @@ import app.revanced.patcher.util.smali.toInstruction import app.revanced.patches.youtube.layout.shorts.button.annotations.ShortsButtonCompatibility import app.revanced.patches.youtube.layout.shorts.button.signatures.PivotBarButtonTabenumSignature import app.revanced.patches.youtube.layout.shorts.button.signatures.PivotBarButtonsViewSignature +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import org.jf.dexlib2.iface.instruction.formats.Instruction11x -@Patch +@Patch(dependencies = [IntegrationsPatch::class]) @Name("shorts-button") @Description("Hide the shorts button.") @ShortsButtonCompatibility 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 25bfe66e..d21ef17c 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 @@ -6,9 +6,9 @@ import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.implementation.BytecodeData import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.or -import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.implementation.BytecodePatch import app.revanced.patcher.patch.implementation.misc.PatchResult +import app.revanced.patcher.patch.implementation.misc.PatchResultError import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import app.revanced.patcher.util.smali.toInstructions @@ -18,7 +18,6 @@ import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.immutable.ImmutableMethod import org.jf.dexlib2.immutable.ImmutableMethodImplementation -@Patch @Name("integrations") @Description("Applies mandatory patches to implement the ReVanced integrations into the application.") @IntegrationsCompatibility @@ -29,6 +28,9 @@ class IntegrationsPatch : BytecodePatch( ) ) { override fun execute(data: BytecodeData): PatchResult { + if (data.findClass("Lapp/revanced/integrations/Globals") == null) + return PatchResultError("Integrations have not been merged yet. This patch can not succeed without the integrations.") + val result = signatures.first().result!! val implementation = result.method.implementation!! diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/manifest/patch/FixLocaleConfigErrorPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/manifest/patch/FixLocaleConfigErrorPatch.kt index 6248acc5..7a7a357f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/manifest/patch/FixLocaleConfigErrorPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/manifest/patch/FixLocaleConfigErrorPatch.kt @@ -4,14 +4,12 @@ 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.annotations.Patch import app.revanced.patcher.patch.implementation.ResourcePatch import app.revanced.patcher.patch.implementation.misc.PatchResult import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess import app.revanced.patches.youtube.misc.manifest.annotations.FixLocaleConfigErrorCompatibility import org.w3c.dom.Element -@Patch @Name("locale-config-fix") @Description("Fix an error when building the resources by patching the manifest file.") @FixLocaleConfigErrorCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/mapping/patch/ResourceIdMappingProviderResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/mapping/patch/ResourceIdMappingProviderResourcePatch.kt new file mode 100644 index 00000000..bb11d591 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/mapping/patch/ResourceIdMappingProviderResourcePatch.kt @@ -0,0 +1,36 @@ +package app.revanced.patches.youtube.misc.mapping.patch + +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 app.revanced.patches.youtube.ad.general.resource.util.Extensions.doRecursively +import org.w3c.dom.Element + +@Name("resource-id-mapping-provider-resource-patch-dependency") +@Description("This patch works as a acts as a provider for resources mapped to their ids.") +@Version("0.0.1") +class ResourceIdMappingProviderResourcePatch : ResourcePatch() { + companion object { + internal lateinit var resourceMappings: Map + 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() + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt index c958d9f1..4b23fe84 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt @@ -135,11 +135,13 @@ class MicroGBytecodePatch : BytecodePatch( const/4 v0, 0x0 return-object v0 """ + 'V' -> "return-void" 'I' -> """ const/4 v0, 0x0 return v0 """ + else -> throw Exception("This case should never happen.") } result.method.implementation!!.addInstructions(