forked from inotia00/revanced-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reddit): add
hide-place-button
patch
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...otlin/app/revanced/patches/reddit/layout/place/fingerprints/HomePagerScreenFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;") | ||
} | ||
) |
56 changes: 56 additions & 0 deletions
56
src/main/kotlin/app/revanced/patches/reddit/layout/place/patch/PlaceButtonPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |