Skip to content

Commit

Permalink
refactor: merge duplex TimRemoveToastTips into one
Browse files Browse the repository at this point in the history
  • Loading branch information
cinit committed Aug 3, 2024
1 parent 8b35e1e commit 2f947ab
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 77 deletions.
60 changes: 41 additions & 19 deletions app/src/main/java/cc/microblock/hook/TimRemoveToastTips.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,64 @@

package cc.microblock.hook

import cc.hicore.QApp.QAppUtils
import cc.ioctl.util.HookUtils
import cc.ioctl.util.Reflex
import cc.ioctl.util.hookBeforeIfEnabled
import io.github.qauxv.base.annotation.FunctionHookEntry
import io.github.qauxv.base.annotation.UiItemAgentEntry
import io.github.qauxv.dsl.FunctionEntryRouter
import io.github.qauxv.hook.CommonSwitchFunctionHook
import io.github.qauxv.util.Initiator
import xyz.nextalone.util.get
import xyz.nextalone.util.set
import io.github.qauxv.util.TIMVersion
import io.github.qauxv.util.requireMinTimVersion
import io.github.qauxv.util.requireTimVersionExactly
import java.lang.reflect.Method

@FunctionHookEntry
@UiItemAgentEntry
object TimRemoveToastTips : CommonSwitchFunctionHook() {
override val name = "移除群聊“修改/设置消息设置”提示"
override val description = "仅供 TIM 3.5.1 使用";

override val description = "仅供 TIM 3.0.0(1082) / 3.5.1 使用";
override val uiItemLocation = FunctionEntryRouter.Locations.Auxiliary.GROUP_CATEGORY

override val isAvailable: Boolean
get() = requireTimVersionExactly(
TIMVersion.TIM_3_0_0, TIMVersion.TIM_3_0_0_1, TIMVersion.TIM_3_5_1
)

override fun initOnce(): Boolean {
HookUtils.hookBeforeIfEnabled(
this, Reflex.findMethod(
// 功能基于 Issue #781 和 #667 移植实现
val runMethods = ArrayList<Method>();

if (requireMinTimVersion(TIMVersion.TIM_3_5_1)) {
// TIM 3.5.1
runMethods += Reflex.findMethod(
Initiator.loadClass("com.tencent.mobileqq.activity.aio.rebuild.TroopChatPie\$8\$1"),
"run")
) {
it.result = null;
}
// 漏了一个“你可以在这里xxxxx”,实在吐了,这玩意不定时的
HookUtils.hookBeforeIfEnabled(
this, Reflex.findMethod(
"run"
)

// 漏了一个“你可以在这里xxxxx”,实在吐了,这玩意不定时的
runMethods += Reflex.findMethod(
Initiator.loadClass("com.tencent.mobileqq.activity.aio.rebuild.TroopChatPie\$38"),
"run")
) {
it.result = null;
"run"
)
} else if (requireMinTimVersion(TIMVersion.TIM_3_0_0_1)) {
// TIM 3.0.0(1082)
// Resource ID: 0x7f0e0189
// Lcom/tencent/mobileqq/activity/aio/rebuild/TroopChatPie$39$1;->run()V
// 原文本:修改消息设置,实时...
runMethods += Reflex.findMethod(
Initiator.loadClass("com.tencent.mobileqq.activity.aio.rebuild.TroopChatPie\$39\$1"),
"run"
)
}

runMethods.forEach {
hookBeforeIfEnabled(it) { param ->
param.result = null
}
}
return true;

return runMethods.isNotEmpty()
}

}
58 changes: 0 additions & 58 deletions app/src/main/java/io/github/moonleeeaf/hook/FuckGroupToastTips.kt

This file was deleted.

7 changes: 7 additions & 0 deletions app/src/main/java/io/github/qauxv/util/HostInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ fun requireMinTimVersion(versionCode: Long): Boolean {
return requireMinVersion(versionCode, HostSpecies.TIM)
}

fun requireTimVersionExactly(vararg versionCodeList: Long): Boolean {
if (hostInfo.hostSpecies != HostSpecies.TIM) {
return false
}
return hostInfo.versionCode in versionCodeList
}

fun requireMinVersion(versionCode: Long, hostSpecies: HostSpecies): Boolean {
return hostInfo.hostSpecies == hostSpecies && hostInfo.versionCode >= versionCode
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/io/github/qauxv/util/TIMVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ public class TIMVersion {
public static final long TIM_3_4_9 = 1268;
public static final long TIM_3_5_0 = 1278;
public static final long TIM_3_5_0_2 = 1288;
public static final long TIM_3_5_1 = 1298;
public static final long TIM_3_5_6 = 1338;
}

0 comments on commit 2f947ab

Please sign in to comment.