diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/fingerprints/BottomNavScreenFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/fingerprints/BottomNavScreenFingerprint.kt new file mode 100644 index 000000000..7beefb11f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/fingerprints/BottomNavScreenFingerprint.kt @@ -0,0 +1,19 @@ +package app.revanced.patches.reddit.layout.navigation.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object BottomNavScreenFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L", "L", "Z", "L", "L"), + opcodes = listOf( + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT + ), + customFingerprint = { _, classDef -> classDef.type.startsWith("Lcom/reddit/launch/bottomnav/BottomNavScreen\$") } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/NavigationButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/NavigationButtonsPatch.kt new file mode 100644 index 000000000..e29878e79 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/NavigationButtonsPatch.kt @@ -0,0 +1,64 @@ +package app.revanced.patches.reddit.layout.navigation.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultError +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.reddit.layout.navigation.fingerprints.BottomNavScreenFingerprint +import app.revanced.patches.reddit.utils.annotations.RedditCompatibility +import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch +import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch.Companion.updateSettingsStatus +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.ReferenceInstruction + +@Patch +@Name("hide-navigation-buttons") +@Description("Hide navigation buttons.") +@DependsOn([SettingsPatch::class]) +@RedditCompatibility +@Version("0.0.1") +class NavigationButtonsPatch : BytecodePatch( + listOf(BottomNavScreenFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + + BottomNavScreenFingerprint.result?.let { + it.mutableMethod.apply { + val startIndex = it.scanResult.patternScanResult!!.startIndex + val reference = getInstruction(startIndex).reference.toString() + + if (!reference.endsWith("Ljava/util/List;")) + return PatchResultError("Invalid reference: $reference") + + val insertIndex = startIndex + 2 + val insertRegister = getInstruction(startIndex + 1).registerA + + addInstructions( + insertIndex, """ + invoke-static {v$insertRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR + move-result-object v$insertRegister + """ + ) + } + } ?: return BottomNavScreenFingerprint.toErrorResult() + + updateSettingsStatus("NavigationButtons") + + return PatchResultSuccess() + } + + private companion object { + private const val INTEGRATIONS_METHOD_DESCRIPTOR = + "Lapp/revanced/reddit/patches/NavigationButtonsPatch;" + + "->hideNavigationButtons(Ljava/util/List;)Ljava/util/List;" + } +} diff --git a/src/main/resources/reddit/settings/host/values/strings.xml b/src/main/resources/reddit/settings/host/values/strings.xml index 33e31d64a..09b77dae0 100644 --- a/src/main/resources/reddit/settings/host/values/strings.xml +++ b/src/main/resources/reddit/settings/host/values/strings.xml @@ -3,6 +3,12 @@ Disables the popup that shows up when taking a screenshot Disable screenshot popup ReVanced Extended + Hide chat button in navigation + Hide chat button + Hide create button in navigation + Hide create button + Hide discover button in navigation + Hide discover button Skips over redirection URLs to external links Open links directly Open links outside of the app directly in your browser