diff --git a/src/main/kotlin/app/revanced/patches/music/utils/litho/patch/LithoFilterPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/litho/patch/LithoFilterPatch.kt index 55753b9bc..f9946c077 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/litho/patch/LithoFilterPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/litho/patch/LithoFilterPatch.kt @@ -4,7 +4,6 @@ import app.revanced.extensions.exception import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions -import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patches.music.utils.annotations.MusicCompatibility @@ -22,36 +21,37 @@ class LithoFilterPatch : BytecodePatch( override fun execute(context: BytecodeContext) { identifierHook("$MUSIC_ADS_PATH/LithoFilterPatch;->filter") - LithoFilterFingerprint.result?.mutableMethod?.apply { - removeInstructions(2, 4) // Remove dummy filter. + LithoFilterFingerprint.result?.let { + it.mutableMethod.apply { + removeInstructions(0, 6) - addFilter = { classDescriptor -> - addInstructions( - 2, - """ - new-instance v1, $classDescriptor - invoke-direct {v1}, $classDescriptor->()V - ${getConstString(2, filterCount++)} - aput-object v1, v0, v2 + addFilter = { classDescriptor -> + addInstructions( + 0, """ + new-instance v0, $classDescriptor + invoke-direct {v0}, $classDescriptor->()V + const/16 v2, ${filterCount++} + aput-object v0, v1, v2 """ - ) + ) + } } } ?: throw LithoFilterFingerprint.exception } override fun close() = LithoFilterFingerprint.result!! - .mutableMethod.replaceInstruction(0, getConstString(0, filterCount)) + .mutableMethod.addInstructions( + 0, """ + const/16 v1, $filterCount + new-array v1, v1, [Lapp/revanced/music/patches/ads/Filter; + """ + ) companion object { internal lateinit var addFilter: (String) -> Unit private set private var filterCount = 0 - - private fun getConstString( - register: Int, - count: Int - ): String = if (count >= 8) "const/16 v$register, $count" else "const/4 v$register, $count" } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoFilterPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoFilterPatch.kt index cf4ff0243..2df982726 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoFilterPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoFilterPatch.kt @@ -5,7 +5,6 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions -import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod @@ -59,15 +58,15 @@ class LithoFilterPatch : BytecodePatch( generalHook("$ADS_PATH/LithoFilterPatch;->filters") LithoFilterFingerprint.result?.mutableMethod?.apply { - removeInstructions(2, 4) // Remove dummy filter. + removeInstructions(0, 6) addFilter = { classDescriptor -> addInstructions( - 2, """ - new-instance v1, $classDescriptor - invoke-direct {v1}, $classDescriptor->()V - ${getConstString(2, filterCount++)} - aput-object v1, v0, v2 + 0, """ + new-instance v0, $classDescriptor + invoke-direct {v0}, $classDescriptor->()V + const/16 v2, ${filterCount++} + aput-object v0, v1, v2 """ ) } @@ -76,17 +75,17 @@ class LithoFilterPatch : BytecodePatch( } override fun close() = LithoFilterFingerprint.result!! - .mutableMethod.replaceInstruction(0, getConstString(0, filterCount)) + .mutableMethod.addInstructions( + 0, """ + const/16 v1, $filterCount + new-array v1, v1, [Lapp/revanced/integrations/patches/ads/Filter; + """ + ) companion object { internal lateinit var addFilter: (String) -> Unit private set private var filterCount = 0 - - private fun getConstString( - register: Int, - count: Int - ): String = if (count >= 8) "const/16 v$register, $count" else "const/4 v$register, $count" } }