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 b32022b5..79bb00f3 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 @@ -14,11 +14,15 @@ import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess 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 app.revanced.patches.youtube.misc.mapping.patch.ResourceIdMappingProviderResourcePatch import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.formats.Instruction35c +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import org.jf.dexlib2.iface.reference.MethodReference @Patch -@Dependencies(dependencies = [IntegrationsPatch::class]) +@Dependencies(dependencies = [IntegrationsPatch::class, ResourceIdMappingProviderResourcePatch::class]) @Name("disable-create-button") @Description("Disable the create button.") @CreateButtonCompatibility @@ -33,16 +37,27 @@ class CreateButtonRemoverPatch : BytecodePatch( // Get the required register which holds the view object we need to pass to the method hideCreateButton val implementation = result.method.implementation!! - val instruction = implementation.instructions[result.scanResult.endIndex + 1] - if (instruction.opcode != Opcode.INVOKE_STATIC) return PatchResultError("Could not find the correct register") - val register = (instruction as Instruction35c).registerC + + val imageOnlyLayout = ResourceIdMappingProviderResourcePatch.resourceMappings["image_only_tab"] + ?: return PatchResultError("Required resource could not be found in the map") + + val imageOnlyLayoutConstIndex = + implementation.instructions.indexOfFirst { (it as? WideLiteralInstruction)?.wideLiteral == imageOnlyLayout } + + val (instructionIndex, instruction) = implementation.instructions.drop(imageOnlyLayoutConstIndex).withIndex() + .first { (((it.value as? ReferenceInstruction)?.reference) as? MethodReference)?.definingClass?.contains("PivotBar") ?: false } + + if (instruction.opcode != Opcode.INVOKE_VIRTUAL) return PatchResultError("Could not find the correct instruction") + + val moveResultIndex = imageOnlyLayoutConstIndex + instructionIndex + 1 + val moveResultInstruction = implementation.instructions[moveResultIndex] as OneRegisterInstruction // Hide the button view via proxy by passing it to the hideCreateButton method result.method.addInstruction( - result.scanResult.endIndex + 1, - "invoke-static { v$register }, Lfi/razerman/youtube/XAdRemover;->hideCreateButton(Landroid/view/View;)V" + moveResultIndex + 1, + "invoke-static { v${moveResultInstruction.registerA} }, Lfi/razerman/youtube/XAdRemover;->hideCreateButton(Landroid/view/View;)V" ) return PatchResultSuccess() } -} \ No newline at end of file +}