Skip to content

Commit

Permalink
feat(twitch/show-deleted-messages): show-deleted-messages patch (#1030
Browse files Browse the repository at this point in the history
)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
timschneeb and oSumAtrIX committed Nov 13, 2022
1 parent ead676d commit 34c73b7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package app.revanced.patches.twitch.chat.antidelete.annotations

import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package

@Compatibility([Package("tv.twitch.android.app")])
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class ShowDeletedMessagesCompatibility

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app.revanced.patches.twitch.chat.antidelete.fingerprints

import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.extensions.or

import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.twitch.chat.antidelete.annotations.ShowDeletedMessagesCompatibility
import org.jf.dexlib2.AccessFlags

@Name("deleted-msg-span-ctor-fingerprint")
@ShowDeletedMessagesCompatibility
@Version("0.0.1")
object DeletedMessageClickableSpanCtorFingerprint : MethodFingerprint(
"V", AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
customFingerprint = { methodDef ->
methodDef.definingClass.endsWith("DeletedMessageClickableSpan;")
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package app.revanced.patches.twitch.chat.antidelete.fingerprints

import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version

import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.twitch.chat.antidelete.annotations.ShowDeletedMessagesCompatibility

@Name("has-mod-access-fingerprint")
@ShowDeletedMessagesCompatibility
@Version("0.0.1")
object SetHasModAccessFingerprint : MethodFingerprint(
customFingerprint = { methodDef ->
methodDef.definingClass.endsWith("DeletedMessageClickableSpan;") && methodDef.name == "setHasModAccess"
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package app.revanced.patches.twitch.chat.antidelete.patch

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.*
import app.revanced.patcher.patch.*
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.twitch.chat.antidelete.annotations.ShowDeletedMessagesCompatibility
import app.revanced.patches.twitch.chat.antidelete.fingerprints.*
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.builder.instruction.BuilderInstruction10x

@Patch
@Name("show-deleted-messages")
@Description("Shows deleted chat messages behind a clickable spoiler.")
@ShowDeletedMessagesCompatibility
@Version("0.0.1")
class ShowDeletedMessagesPatch : BytecodePatch(
listOf(
SetHasModAccessFingerprint,
DeletedMessageClickableSpanCtorFingerprint,
)
) {
override fun execute(context: BytecodeContext): PatchResult {
// Force set hasModAccess member to true in constructor
with(DeletedMessageClickableSpanCtorFingerprint.result!!.mutableMethod) {
addInstructions(
implementation!!.instructions.lastIndex, /* place in front of return-void */
"""
const/4 v0, 1
iput-boolean v0, p0, $definingClass->hasModAccess:Z
"""
)
}

// Disable setHasModAccess setter
with(SetHasModAccessFingerprint.result!!.mutableMethod.implementation!!) {
addInstruction(0, BuilderInstruction10x(Opcode.RETURN_VOID))
}

return PatchResultSuccess()
}
}

0 comments on commit 34c73b7

Please sign in to comment.