Skip to content

Commit fcacd0f

Browse files
d4rkk3yoSumAtrIX
andauthored
feat(Tiktok): Add Remember clear mode patch (#2509)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent 4f0c756 commit fcacd0f

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

api/revanced-patches.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,12 @@ public final class app/revanced/patches/tiktok/feedfilter/FeedFilterPatch : app/
818818
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
819819
}
820820

821+
public final class app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch : app/revanced/patcher/patch/BytecodePatch {
822+
public static final field INSTANCE Lapp/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch;
823+
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
824+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
825+
}
826+
821827
public final class app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch : app/revanced/patcher/patch/BytecodePatch {
822828
public static final field INSTANCE Lapp/revanced/patches/tiktok/interaction/downloads/DownloadsPatch;
823829
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package app.revanced.patches.tiktok.interaction.clearmode
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
5+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
6+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
7+
import app.revanced.patcher.patch.BytecodePatch
8+
import app.revanced.patcher.patch.annotation.CompatiblePackage
9+
import app.revanced.patcher.patch.annotation.Patch
10+
import app.revanced.patcher.util.smali.ExternalLabel
11+
import app.revanced.patches.tiktok.interaction.clearmode.fingerprints.OnClearModeEventFingerprint
12+
import app.revanced.patches.tiktok.interaction.clearmode.fingerprints.OnRenderFirstFrameFingerprint
13+
import app.revanced.util.exception
14+
import app.revanced.util.indexOfFirstInstruction
15+
import com.android.tools.smali.dexlib2.Opcode
16+
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction22c
17+
18+
@Patch(
19+
name = "Remember clear mode",
20+
description = "Remembers the clear mode configurations in between videos.",
21+
compatiblePackages = [
22+
CompatiblePackage("com.ss.android.ugc.trill", ["32.5.3"]),
23+
CompatiblePackage("com.zhiliaoapp.musically", ["32.5.3"])
24+
]
25+
)
26+
@Suppress("unused")
27+
object RememberClearModePatch : BytecodePatch(
28+
setOf(
29+
OnClearModeEventFingerprint,
30+
OnRenderFirstFrameFingerprint
31+
)
32+
) {
33+
override fun execute(context: BytecodeContext) {
34+
OnClearModeEventFingerprint.result?.mutableMethod?.let {
35+
// region Hook the "Clear mode" configuration save event to remember the state of clear mode.
36+
37+
val isEnabledIndex = it.indexOfFirstInstruction { opcode == Opcode.IGET_BOOLEAN } + 1
38+
val isEnabledRegister = it.getInstruction<Instruction22c>(isEnabledIndex - 1).registerA
39+
40+
it.addInstructions(
41+
isEnabledIndex,
42+
"invoke-static { v$isEnabledRegister }, " +
43+
"Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->rememberClearModeState(Z)V"
44+
)
45+
46+
// endregion
47+
48+
// region Override the "Clear mode" configuration load event to load the state of clear mode.
49+
50+
val clearModeEventClass = it.parameters[0].type
51+
OnRenderFirstFrameFingerprint.result?.mutableMethod?.apply {
52+
addInstructionsWithLabels(
53+
0,
54+
"""
55+
# Create a new clearModeEvent and post it to the EventBus (https://github.com/greenrobot/EventBus)
56+
57+
# The state of clear mode.
58+
invoke-static { }, Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->getClearModeState()Z
59+
move-result v3
60+
if-eqz v3, :clear_mode_disabled
61+
62+
# Clear mode type such as 0 = LONG_PRESS, 1 = SCREEN_RECORD etc.
63+
const/4 v1, 0x0
64+
65+
# Name of the clear mode type which is equivalent to the clear mode type.
66+
const-string v2, "long_press"
67+
68+
new-instance v0, $clearModeEventClass
69+
invoke-direct { v0, v1, v2, v3 }, $clearModeEventClass-><init>(ILjava/lang/String;Z)V
70+
invoke-virtual { v0 }, $clearModeEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent;
71+
""",
72+
ExternalLabel("clear_mode_disabled", getInstruction(0))
73+
)
74+
} ?: throw OnRenderFirstFrameFingerprint.exception
75+
76+
// endregion
77+
} ?: throw OnClearModeEventFingerprint.exception
78+
}
79+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package app.revanced.patches.tiktok.interaction.clearmode.fingerprints
2+
3+
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
5+
internal object OnClearModeEventFingerprint : MethodFingerprint(
6+
customFingerprint = { methodDef, _ ->
7+
methodDef.definingClass.endsWith("/ClearModePanelComponent;") && methodDef.name == "onClearModeEvent"
8+
}
9+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package app.revanced.patches.tiktok.interaction.clearmode.fingerprints
2+
3+
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
5+
internal object OnRenderFirstFrameFingerprint : MethodFingerprint(
6+
customFingerprint = { methodDef, _ ->
7+
methodDef.definingClass.endsWith("/BaseListFragmentPanel;") && methodDef.name == "onRenderFirstFrame"
8+
}
9+
)

0 commit comments

Comments
 (0)