|
| 1 | +package app.revanced.patches.instagram.hide.navigation |
| 2 | + |
| 3 | +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels |
| 4 | +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction |
| 5 | +import app.revanced.patcher.patch.booleanOption |
| 6 | +import app.revanced.patcher.patch.bytecodePatch |
| 7 | +import app.revanced.patcher.util.smali.ExternalLabel |
| 8 | +import app.revanced.util.findFreeRegister |
| 9 | +import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction |
| 10 | +import java.util.logging.Logger |
| 11 | + |
| 12 | +@Suppress("unused") |
| 13 | +val hideNavigationButtonsPatch = bytecodePatch( |
| 14 | + name = "Hide navigation buttons", |
| 15 | + description = "Hides navigation bar buttons, such as the Reels and Create button.", |
| 16 | + use = false |
| 17 | +) { |
| 18 | + compatibleWith("com.instagram.android") |
| 19 | + |
| 20 | + val hideReels by booleanOption( |
| 21 | + key = "hideReels", |
| 22 | + default = true, |
| 23 | + title = "Hide Reels" |
| 24 | + ) |
| 25 | + |
| 26 | + val hideCreate by booleanOption( |
| 27 | + key = "hideCreate", |
| 28 | + default = true, |
| 29 | + title = "Hide Create" |
| 30 | + ) |
| 31 | + |
| 32 | + execute { |
| 33 | + if (!hideReels!! && !hideCreate!!) { |
| 34 | + return@execute Logger.getLogger(this::class.java.name).warning( |
| 35 | + "No hide navigation buttons options are enabled. No changes made." |
| 36 | + ) |
| 37 | + } |
| 38 | + |
| 39 | + tabCreateButtonsLoopStartFingerprint.method.apply { |
| 40 | + // Check the current loop index, and skip over adding the |
| 41 | + // navigation button view if the index matches a given button. |
| 42 | + |
| 43 | + val startIndex = tabCreateButtonsLoopStartFingerprint.patternMatch!!.startIndex |
| 44 | + val endIndex = tabCreateButtonsLoopEndFingerprint.patternMatch!!.endIndex |
| 45 | + val insertIndex = startIndex + 1 |
| 46 | + val loopIndexRegister = getInstruction<TwoRegisterInstruction>(startIndex).registerA |
| 47 | + val freeRegister = findFreeRegister(insertIndex, loopIndexRegister) |
| 48 | + val instruction = getInstruction(endIndex - 1) |
| 49 | + |
| 50 | + var instructions = buildString { |
| 51 | + if (hideCreate!!) { |
| 52 | + appendLine( |
| 53 | + """ |
| 54 | + const v$freeRegister, 0x2 |
| 55 | + if-eq v$freeRegister, v$loopIndexRegister, :skipAddView |
| 56 | + """ |
| 57 | + ) |
| 58 | + } |
| 59 | + |
| 60 | + if (hideReels!!) { |
| 61 | + appendLine( |
| 62 | + """ |
| 63 | + const v$freeRegister, 0x3 |
| 64 | + if-eq v$freeRegister, v$loopIndexRegister, :skipAddView |
| 65 | + """ |
| 66 | + ) |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + addInstructionsWithLabels( |
| 71 | + insertIndex, |
| 72 | + instructions, |
| 73 | + ExternalLabel("skipAddView", instruction) |
| 74 | + ) |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + |
0 commit comments