Skip to content

Commit

Permalink
feat: PegasusHook support viewUnite
Browse files Browse the repository at this point in the history
  • Loading branch information
CodePwn2021 committed Nov 16, 2024
1 parent 18116c7 commit 81de6bd
Showing 1 changed file with 80 additions and 3 deletions.
83 changes: 80 additions & 3 deletions app/src/main/java/me/iacn/biliroaming/hook/PegasusHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
// 屏蔽过低的播放数
private fun isLowCountVideo(obj: Any): Boolean {
if (hideLowPlayCountLimit == 0L) return false
if (obj is Long) {
return obj < hideLowPlayCountLimit
}
val text = obj.runCatchingOrNull {
getObjectFieldAs<String?>("coverLeftText1")
}.orEmpty()
Expand All @@ -120,8 +123,13 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
private fun durationVideo(obj: Any): Boolean {
if (hideLongDurationLimit == 0 && hideShortDurationLimit == 0)
return false
val duration = obj.getObjectField("playerArgs")
?.getObjectFieldAs("fakeDuration") ?: 0
val duration =
if (obj is Long) {
obj
} else {
obj.getObjectField("playerArgs")
?.getObjectFieldAs("fakeDuration") ?: 0
}
if (hideLongDurationLimit != 0 && duration > hideLongDurationLimit)
return true
return hideShortDurationLimit != 0 && duration < hideShortDurationLimit
Expand Down Expand Up @@ -196,6 +204,46 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
return false
}

private fun isContainsBlockKwdUnite(card: Any): Boolean {
if (card.callMethodAs("hasBasicInfo")) {
card.callMethodAs<Any>("getBasicInfo").let { basicInfo ->
// 屏蔽标题关键词
if (kwdFilterTitleList.isNotEmpty()) {
val title = basicInfo.callMethodAs<String>("getTitle")
if (kwdFilterTitleRegexMode && title.isNotEmpty()) {
if (kwdFilterTitleRegexes.any { title.contains(it) })
return true
} else if (title.isNotEmpty()) {
if (kwdFilterTitleList.any { title.contains(it) })
return true
}
}

basicInfo.callMethodAs<Any>("getAuthor").let { author ->
// 屏蔽UID
if (kwdFilterUidList.isNotEmpty()) {
val uid = author.callMethodAs<Long>("getMid")
if (uid != 0L && kwdFilterUidList.any { it == uid })
return true
}

// 屏蔽UP主
if (kwdFilterUpnameList.isNotEmpty()) {
val upName = author.callMethodAs<String>("getTitle")
if (kwdFilterUpnameRegexMode && upName.isNotEmpty()) {
if (kwdFilterUpnameRegexes.any { upName.contains(it) })
return true
} else if (upName.isNotEmpty()) {
if (kwdFilterUpnameList.any { upName.contains(it) })
return true
}
}
}
}
}
return false
}

private fun ArrayList<Any>.appendReasons() = forEach { item ->
val title = item.getObjectFieldAs<String?>("title").orEmpty()
val rcmdReason = item.runCatchingOrNull {
Expand Down Expand Up @@ -486,6 +534,7 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {

fun MutableList<Any>.filterUnite() = removeAll {
val allowTypeList = mutableListOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
var shouldFiltered = false
allowTypeList.removeAll { digit ->
(removeRelateOnlyAv && digit != 1) || (removeRelatePromote && digit in listOf(
3, // Resource, like mall
Expand All @@ -494,7 +543,35 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
10 // SPECIAL
))
}
removeRelateNothing || it.callMethodAs("getRelateCardTypeValue") !in allowTypeList
// av filter
if (applyToRelate) {
if (it.callMethodAs("hasAv")) {
it.callMethodAs<Any>("getAv").let { av ->
val duration = av.callMethodAs<Long>("getDuration")
if (durationVideo(duration)) {
shouldFiltered = true
return@let
}
if (av.callMethodAs("hasStat")) {
av.callMethodAs<Any>("getStat").let { stat ->
if (stat.callMethodAs("hasVt")) {
stat.callMethodAs<Any>("getVt").let { vt ->
if (isLowCountVideo(vt.callMethodAs<Long>("getValue"))) {
shouldFiltered = true
return@let
}
}
}
}
}
}
if (isContainsBlockKwdUnite(it)) {
shouldFiltered = true
}
}
// todo: support rcmd
}
removeRelateNothing || it.callMethodAs("getRelateCardTypeValue") !in allowTypeList || shouldFiltered
}
instance.viewMossClass?.hookAfterMethod("view", instance.viewReqClass) { param ->
param.result ?: return@hookAfterMethod
Expand Down

0 comments on commit 81de6bd

Please sign in to comment.