|
| 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 | +} |
0 commit comments