Skip to content

Commit

Permalink
feat(reddit): add hide-place-button patch
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Jul 24, 2023
1 parent f65d9a8 commit b3a5631
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app.revanced.patches.reddit.layout.place.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

object HomePagerScreenFingerprint : MethodFingerprint(
returnType = "Landroid/view/View;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Landroid/view/LayoutInflater;", "Landroid/view/ViewGroup;"),
strings = listOf("view.findViewById(Search\u2026nav_search_cta_container)"),
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("/HomePagerScreen;")
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package app.revanced.patches.reddit.layout.place.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.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
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.place.fingerprints.HomePagerScreenFingerprint
import app.revanced.patches.reddit.utils.annotations.RedditCompatibility
import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsBytecodePatch.Companion.updateSettingsStatus
import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.bytecode.getStringIndex
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction

@Patch
@Name("Hide place button")
@Description("Hide r/place button in toolbar.")
@DependsOn([SettingsPatch::class])
@RedditCompatibility
@Version("0.0.1")
class PlaceButtonPatch : BytecodePatch(
listOf(HomePagerScreenFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {

HomePagerScreenFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = getStringIndex("view.findViewById(Search\u2026nav_search_cta_container)")
val targetRegister =
getInstruction<OneRegisterInstruction>(targetIndex - 1).registerA

addInstruction(
targetIndex,
"invoke-static {v$targetRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR"
)
}
} ?: return HomePagerScreenFingerprint.toErrorResult()

updateSettingsStatus("PlaceButton")

return PatchResultSuccess()
}

companion object {
const val INTEGRATIONS_METHOD_DESCRIPTOR =
"Lapp/revanced/reddit/patches/PlaceButtonPatch;" +
"->hidePlaceButton(Landroid/view/View;)V"
}
}

0 comments on commit b3a5631

Please sign in to comment.