Skip to content

Commit

Permalink
feat: add AntiNickBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
lliioollcn committed Nov 30, 2023
1 parent 262e375 commit 873279e
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/src/main/java/cc/ioctl/util/MsgRecordUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,21 @@ object MsgRecordUtil {
}
}

val NICK_BLOCKS = object : HashBiMap<String, String>() {
init {
put("VIP图标", "AIOVipIconProcessor")
put("额外VIP图标", "AIOVipIconExProcessor")
put("游戏图标", "AIOGameIconProcessor")
put("昵称", "MainNickNameBlock")
put("机器人图标", "NickNameRobotBlock")
put("群等级图标", "AIOTroopMemberLevelBlock")
put("群数字等级图标", "AIOTroopMemberGradeLevelBlock")
put("群荣耀图标", "AIOTroopHonorNickBlock")
put("群匿名图标", "AIOTroopAnonymousNickBlock")
put("群QQ圈图标", "QCircleTroopIconProcessor")
}
}

val MSG_WITH_DESC = object : HashBiMap<String, Int>() {
init {
MSG.forEach {
Expand Down Expand Up @@ -341,4 +356,14 @@ object MsgRecordUtil {
map[cache]!!
} else cache
}

fun parseNickBlocks(activeItems: List<String>): List<String> {
val items: MutableList<String> = ArrayList()
for (item in activeItems) {
if (NICK_BLOCKS.containsKey(item)) {
items.add(NICK_BLOCKS[item]!!)
}
}
return items
}
}
91 changes: 91 additions & 0 deletions app/src/main/java/cn/lliiooll/hook/AntiNickBlock.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* QAuxiliary - An Xposed module for QQ/TIM
* Copyright (C) 2019-2023 QAuxiliary developers
* https://github.com/cinit/QAuxiliary
*
* This software is non-free but opensource software: you can redistribute it
* and/or modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation; either
* version 3 of the License, or any later version and our eula as published
* by QAuxiliary contributors.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* and eula along with this software. If not, see
* <https://www.gnu.org/licenses/>
* <https://github.com/cinit/QAuxiliary/blob/master/LICENSE.md>.
*/

package cn.lliiooll.hook

import cc.ioctl.util.HookUtils
import cc.ioctl.util.MsgRecordUtil
import com.github.kyuubiran.ezxhelper.utils.findMethod
import com.github.kyuubiran.ezxhelper.utils.loadClass
import com.github.kyuubiran.ezxhelper.utils.paramCount
import io.github.qauxv.base.annotation.FunctionHookEntry
import io.github.qauxv.base.annotation.UiItemAgentEntry
import io.github.qauxv.dsl.FunctionEntryRouter.Locations.Simplify
import io.github.qauxv.util.QQVersion
import io.github.qauxv.util.requireMinQQVersion
import me.ketal.util.hookMethod
import xyz.nextalone.base.MultiItemDelayableHook
import java.text.Collator
import java.util.Locale

@FunctionHookEntry
@UiItemAgentEntry
object AntiNickBlock : MultiItemDelayableHook("ll_anti_nickblock") {
override var allItems = setOf<String>()
override val defaultItems = setOf<String>()
override var items: MutableList<String> = MsgRecordUtil.NICK_BLOCKS.keys.sortedWith(chineseSorter).toMutableList()
override val preferenceTitle: String = "屏蔽群昵称图标"
override val dialogDesc = "屏蔽群昵称图标"
override val enableCustom = false
override val uiItemLocation = Simplify.UI_CHAT_MSG


override fun initOnce(): Boolean {
val providerList = arrayOf(
"com.tencent.mobileqq.vas.vipicon.g",
"com.tencent.qqnt.aio.nick.f",
"com.tencent.mobileqq.aio.msglist.holder.component.nick.block.f",
"com.tencent.mobileqq.activity.qcircle.c",
)
val callBack = HookUtils.afterIfEnabled(this) { param ->
if (param.result != null) {
val modified = (param.result as List<*>).toMutableList()
val sources = (param.result as List<*>).toMutableList()
modified.clear()
val items: List<String> = MsgRecordUtil.parseNickBlocks(activeItems)
for (i in 0 until sources.size) {
if (!items.contains(sources[i]?.javaClass?.simpleName)) {
modified.add(sources[i])
}
}
param.result = modified.toList()
}
}

providerList.forEach { provider ->
loadClass(provider).findMethod {
//protected List<AbsNickBlock> a(@NotNull Context context, @NotNull LinearLayout rootView)
paramCount == 2
}.hookMethod(callBack)
}
return true
}

override var isEnabled: Boolean
get() = true
set(value) {}

override val isAvailable = requireMinQQVersion(QQVersion.QQ_8_9_80)

}

val chineseSorter = Comparator<String>(Collator.getInstance(Locale.CHINA)::compare)

0 comments on commit 873279e

Please sign in to comment.