diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/recentlyvisited/RecentlyVisitedShelfPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/recentlyvisited/RecentlyVisitedShelfPatch.kt new file mode 100644 index 000000000..92a3764b5 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/recentlyvisited/RecentlyVisitedShelfPatch.kt @@ -0,0 +1,53 @@ +package app.revanced.patches.reddit.layout.recentlyvisited + +import app.revanced.extensions.exception +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.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.reddit.layout.recentlyvisited.fingerprints.CommunityDrawerPresenterFingerprint +import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus +import app.revanced.patches.reddit.utils.settings.SettingsPatch +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch( + name = "Hide recently visited shelf", + description = "Hides recently visited shelf in sidebar.", + dependencies = [SettingsPatch::class], + compatiblePackages = [CompatiblePackage("com.reddit.frontpage")] +) +@Suppress("unused") +object RecentlyVisitedShelfPatch : BytecodePatch( + setOf(CommunityDrawerPresenterFingerprint) +) { + private const val INTEGRATIONS_METHOD_DESCRIPTOR = + "Lapp/revanced/reddit/patches/RecentlyVisitedShelfPatch;" + + "->hideRecentlyVisitedShelf(Ljava/util/List;)Ljava/util/List;" + + override fun execute(context: BytecodeContext) { + + CommunityDrawerPresenterFingerprint.result?.let { + it.mutableMethod.apply { + arrayOf( + it.scanResult.patternScanResult!!.endIndex, + it.scanResult.patternScanResult!!.startIndex + 3 + ).forEach { insertIndex -> + val insertRegister = + getInstruction(insertIndex).registerA + + addInstructions( + insertIndex, """ + invoke-static {v$insertRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR + move-result-object v$insertRegister + """ + ) + } + } + } ?: throw CommunityDrawerPresenterFingerprint.exception + + updateSettingsStatus("RecentlyVisitedShelf") + + } +} diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/recentlyvisited/fingerprints/CommunityDrawerPresenterFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/recentlyvisited/fingerprints/CommunityDrawerPresenterFingerprint.kt new file mode 100644 index 000000000..a67c9c00b --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/recentlyvisited/fingerprints/CommunityDrawerPresenterFingerprint.kt @@ -0,0 +1,26 @@ +package app.revanced.patches.reddit.layout.recentlyvisited.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +object CommunityDrawerPresenterFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = emptyList(), + opcodes = listOf( + Opcode.XOR_INT_2ADDR, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CHECK_CAST, + Opcode.IGET_OBJECT, + Opcode.IGET_OBJECT, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CHECK_CAST + ), + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/CommunityDrawerPresenter;") + } +) \ No newline at end of file