From 05e0848b99aaf3aa744820c31b9542382b207f87 Mon Sep 17 00:00:00 2001 From: "Hydrogen.P" <77036672+CodePwn2021@users.noreply.github.com> Date: Tue, 19 Nov 2024 08:16:47 +0800 Subject: [PATCH] refactor: optimize code (#1569) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix blockVideoComment fix bangumiPlayUrlHook for hk, tw, thai, cn 重构 精简代码 修复 屏蔽视频评论区 修复 港澳台泰大陆区的番剧观看 --- .../me/iacn/biliroaming/BiliBiliPackage.kt | 5 + .../biliroaming/hook/BangumiPlayUrlHook.kt | 128 +++----- .../biliroaming/hook/BangumiSeasonHook.kt | 48 +-- .../me/iacn/biliroaming/hook/PegasusHook.kt | 88 +----- .../me/iacn/biliroaming/hook/ProtoBufHook.kt | 287 +++--------------- 5 files changed, 111 insertions(+), 445 deletions(-) diff --git a/app/src/main/java/me/iacn/biliroaming/BiliBiliPackage.kt b/app/src/main/java/me/iacn/biliroaming/BiliBiliPackage.kt index f4f376e8a6..9cff5e778d 100644 --- a/app/src/main/java/me/iacn/biliroaming/BiliBiliPackage.kt +++ b/app/src/main/java/me/iacn/biliroaming/BiliBiliPackage.kt @@ -164,6 +164,11 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex val searchVideoCardClass by Weak { "com.bapis.bilibili.polymer.app.search.v1.SearchVideoCard" from mClassLoader } val playSpeedManager by Weak { mHookInfo.playSpeedManager from mClassLoader } + // for v8.17.0+ + val useNewMossFunc = instance.viewMossClass?.declaredMethods?.any { + it.name == "executeRelatesFeed" + } ?: false + val ids: Map by lazy { mHookInfo.mapIds.idsMap } diff --git a/app/src/main/java/me/iacn/biliroaming/hook/BangumiPlayUrlHook.kt b/app/src/main/java/me/iacn/biliroaming/hook/BangumiPlayUrlHook.kt index 04d4e42b15..bfdaf35112 100644 --- a/app/src/main/java/me/iacn/biliroaming/hook/BangumiPlayUrlHook.kt +++ b/app/src/main/java/me/iacn/biliroaming/hook/BangumiPlayUrlHook.kt @@ -197,80 +197,7 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) { "com.bapis.bilibili.pgc.gateway.player.v2.PlayURLMoss".findClassOrNull(mClassLoader)?.run { var isDownload = false hookBeforeMethod( - "playView", - "com.bapis.bilibili.pgc.gateway.player.v2.PlayViewReq" - ) { param -> - val request = param.args[0] - // if getDownload == 1 -> flv download - // if getDownload == 2 -> dash download - // if qn == 0, we are querying available quality - // else we are downloading - // if fnval == 0 -> flv download - // thus fix download will set qn = 0 and set fnval to max - isDownload = sPrefs.getBoolean("allow_download", false) - && request.callMethodAs("getDownload") >= 1 - if (isDownload) { - if (!sPrefs.getBoolean("fix_download", false) - || request.callMethodAs("getFnval") <= 1 - ) { - request.callMethod("setFnval", MAX_FNVAL) - request.callMethod("setFourk", true) - } - request.callMethod("setDownload", 0) - } else if (halfScreenQuality == 1 || fullScreenQuality != 0) { - request.callMethod("setFnval", MAX_FNVAL) - request.callMethod("setFourk", true) - if (halfScreenQuality == 1 && qnApplied.compareAndSet(false, true)) { - defaultQn?.let { request.callMethod("setQn", it) } - } - } - } - hookAfterMethod( - "playView", - "com.bapis.bilibili.pgc.gateway.player.v2.PlayViewReq" - ) { param -> - // th: - // com.bilibili.lib.moss.api.BusinessException: 抱歉您所使用的平台不可观看! - // com.bilibili.lib.moss.api.BusinessException: 啥都木有 - // connection err <- should skip because of cache: - // throwable: com.bilibili.lib.moss.api.NetworkException - if (instance.networkExceptionClass?.isInstance(param.throwable) == true) - return@hookAfterMethod - val request = param.args[0] - val response = - param.result ?: "com.bapis.bilibili.pgc.gateway.player.v2.PlayViewReply" - .on(mClassLoader).new() - if (needProxy(response)) { - try { - val serializedRequest = request.callMethodAs("toByteArray") - val req = PlayViewReq.parseFrom(serializedRequest) - val seasonId = req.seasonId.toString().takeIf { it != "0" } - ?: lastSeasonInfo["season_id"] ?: "0" - val (thaiSeason, thaiEp) = getSeasonLazy(seasonId, req.epId) - val content = getPlayUrl(reconstructQuery(req, response, thaiEp)) - content?.let { - Log.toast("已从代理服务器获取播放地址\n如加载缓慢或黑屏,可去漫游设置中测速并设置 UPOS") - param.result = reconstructResponse( - req, response, it, isDownload, thaiSeason, thaiEp - ) - } - ?: throw CustomServerException(mapOf("未知错误" to "请检查哔哩漫游设置中解析服务器设置。")) - } catch (e: CustomServerException) { - param.result = showPlayerError( - response, - "请求解析服务器发生错误(点此查看更多)\n${e.message}" - ) - Log.toast("请求解析服务器发生错误: ${e.message}", alsoLog = true) - } - } else if (isDownload) { - param.result = fixDownloadProto(response) - } else if (blockBangumiPageAds) { - param.result = purifyViewInfo(response) - } - } - // v8.17.0+ - hookBeforeMethod( - "executePlayView", + if (instance.useNewMossFunc) "executePlayView" else "playView", "com.bapis.bilibili.pgc.gateway.player.v2.PlayViewReq" ) { param -> val request = param.args[0] @@ -299,7 +226,7 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) { } } hookAfterMethod( - "executePlayView", + if (instance.useNewMossFunc) "executePlayView" else "playView", "com.bapis.bilibili.pgc.gateway.player.v2.PlayViewReq" ) { param -> // th: @@ -344,7 +271,10 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) { } instance.playerMossClass?.run { var isDownload = false - hookBeforeMethod("playViewUnite", instance.playViewUniteReqClass) { param -> + hookBeforeMethod( + if (instance.useNewMossFunc) "executePlayViewUnite" else "playViewUnite", + instance.playViewUniteReqClass + ) { param -> val request = param.args[0] val vod = request.callMethod("getVod") ?: return@hookBeforeMethod isDownload = sPrefs.getBoolean("allow_download", false) @@ -371,7 +301,10 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) { } } } - hookAfterMethod("playViewUnite", instance.playViewUniteReqClass) { param -> + hookAfterMethod( + if (instance.useNewMossFunc) "executePlayViewUnite" else "playViewUnite", + instance.playViewUniteReqClass + ) { param -> if (instance.networkExceptionClass?.isInstance(param.throwable) == true) return@hookAfterMethod val request = param.args[0] @@ -380,9 +313,24 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) { .on(mClassLoader).new() val supplementAny = response.callMethod("getSupplement") val typeUrl = supplementAny?.callMethodAs("getTypeUrl") + // Only handle pgc video - if (param.result != null && typeUrl != PGC_ANY_MODEL_TYPE_URL) + /////////////////// + // newPlayUnite: + // request.vod.cid, response.play_arc.cid need skip + val requestVod = request.callMethod("getVod") + val reqCid = requestVod?.callMethodAs("getCid") + + val responsePlayArc = response.callMethod("getPlayArc") + val respCid = responsePlayArc?.callMethodAs("getCid") + + val isThai = reqCid != 0.toLong() && reqCid != respCid + if ( + param.result != null && typeUrl != PGC_ANY_MODEL_TYPE_URL && !isThai + ) { return@hookAfterMethod + } + val extraContent = request.callMethodAs>("getExtraContentMap") val seasonId = extraContent.getOrDefault("season_id", "0") val reqEpId = extraContent.getOrDefault("ep_id", "0").toLong() @@ -391,7 +339,7 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) { val supplement = supplementAny?.callMethod("getValue") ?.callMethodAs("toByteArray") ?.let { PlayViewReply.parseFrom(it) } ?: playViewReply {} - if (needProxyUnite(response, supplement)) { + if (needProxyUnite(response, supplement) || isThai) { try { val serializedRequest = request.callMethodAs("toByteArray") val req = PlayViewUniteReq.parseFrom(serializedRequest) @@ -455,9 +403,24 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) { .on(mClassLoader).new() val supplementAny = response.callMethod("getSupplement") val typeUrl = supplementAny?.callMethodAs("getTypeUrl") + // Only handle pgc video - if (originalResp != null && typeUrl != PGC_ANY_MODEL_TYPE_URL) + /////////////////// + // newPlayUnite: + // request.vod.cid, response.play_arc.cid + val requestVod = request.callMethod("getVod") + val reqCid = requestVod?.callMethodAs("getCid") + + val responsePlayArc = response.callMethod("getPlayArc") + val respCid = responsePlayArc?.callMethodAs("getCid") + + val isThai = reqCid != 0.toLong() && reqCid != respCid + if ( + param.result != null && typeUrl != PGC_ANY_MODEL_TYPE_URL && !isThai + ) { return@mossResponseHandlerReplaceProxy null + } + val extraContent = request.callMethodAs>("getExtraContentMap") val seasonId = extraContent.getOrDefault("season_id", "0") @@ -467,7 +430,7 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) { val supplement = supplementAny?.callMethod("getValue") ?.callMethodAs("toByteArray") ?.let { PlayViewReply.parseFrom(it) } ?: playViewReply {} - val newResponse = if (needProxyUnite(response, supplement)) { + val newResponse = if (needProxyUnite(response, supplement) || isThai) { try { val serializedRequest = request.callMethodAs("toByteArray") val req = PlayViewUniteReq.parseFrom(serializedRequest) @@ -496,7 +459,8 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) { } } instance.playURLMossClass?.hookBeforeMethod( - "playView", instance.playViewReqClass + if (instance.useNewMossFunc) "executePlayView" else "playView", + instance.playViewReqClass ) { param -> val request = param.args[0] val isDownload = request.callMethodAs("getDownload") >= 1 diff --git a/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt b/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt index 6e6e3bd705..9cefedae98 100644 --- a/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt +++ b/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt @@ -321,17 +321,10 @@ class BangumiSeasonHook(classLoader: ClassLoader) : BaseHook(classLoader) { } } - instance.viewMossClass?.hookAfterMethod("view", instance.viewReqClass) { param -> - param.result?.let { return@hookAfterMethod } - val serializedRequest = param.args[0].callMethodAs("toByteArray") - val req = ViewReq.parseFrom(serializedRequest) - val reply = fixViewProto(req) - val serializedReply = reply?.toByteArray() ?: return@hookAfterMethod - param.result = - (param.method as Method).returnType.callStaticMethod("parseFrom", serializedReply) - } - // v8.17.0+ - instance.viewMossClass?.hookAfterMethod("execView", instance.viewReqClass) { param -> + instance.viewMossClass?.hookAfterMethod( + if (instance.useNewMossFunc) "executeView" else "view", + instance.viewReqClass + ) { param -> param.result?.let { return@hookAfterMethod } val serializedRequest = param.args[0].callMethodAs("toByteArray") val req = ViewReq.parseFrom(serializedRequest) @@ -342,7 +335,8 @@ class BangumiSeasonHook(classLoader: ClassLoader) : BaseHook(classLoader) { } instance.viewUniteMossClass?.hookAfterMethod( - "view", "com.bapis.bilibili.app.viewunite.v1.ViewReq" + if (instance.useNewMossFunc) "executeView" else "view", + "com.bapis.bilibili.app.viewunite.v1.ViewReq" ) { param -> if (instance.networkExceptionClass?.isInstance(param.throwable) == true) return@hookAfterMethod val response = param.result @@ -370,36 +364,6 @@ class BangumiSeasonHook(classLoader: ClassLoader) : BaseHook(classLoader) { fixViewProto(response, supplement) } - // v8.17.0+ - instance.viewUniteMossClass?.hookAfterMethod( - "executeView", "com.bapis.bilibili.app.viewunite.v1.ViewReq" - ) { param -> - if (instance.networkExceptionClass?.isInstance(param.throwable) == true) return@hookAfterMethod - val response = param.result - if (response == null) { - val req = param.args[0].callMethodAs("toByteArray").let { - ViewUniteReq.parseFrom(it) - } - val av = (if (req.hasAid()) req.aid.takeIf { it != 0L } else if (req.hasBvid()) bv2av(req.bvid) else null)?.toString() - fixViewProto(req, av)?.toByteArray()?.let { - param.result = - "com.bapis.bilibili.app.viewunite.v1.ViewReply".from(mClassLoader) - ?.callStaticMethod("parseFrom", it) - } ?: Log.toast("解锁失败!", force = true) - return@hookAfterMethod - } - val supplementAny = response.callMethod("getSupplement") - val typeUrl = supplementAny?.callMethodAs("getTypeUrl") - // Only handle pgc video - if (param.result != null && typeUrl != PGC_ANY_MODEL_TYPE_URL) { - return@hookAfterMethod - } - val supplement = - supplementAny?.callMethod("getValue")?.callMethodAs("toByteArray") - ?.let { ViewPgcAny.parseFrom(it) } ?: viewPgcAny {} - - fixViewProto(response, supplement) - } val urlHook: Hooker = fun(param) { val redirectUrl = param.thisObject.getObjectFieldAs("redirectUrl") diff --git a/app/src/main/java/me/iacn/biliroaming/hook/PegasusHook.kt b/app/src/main/java/me/iacn/biliroaming/hook/PegasusHook.kt index 1d3222ee44..21b7985f35 100644 --- a/app/src/main/java/me/iacn/biliroaming/hook/PegasusHook.kt +++ b/app/src/main/java/me/iacn/biliroaming/hook/PegasusHook.kt @@ -576,26 +576,11 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) { } removeRelateNothing || it.callMethodAs("getRelateCardTypeValue") !in allowTypeList || shouldFiltered } - instance.viewMossClass?.hookAfterMethod("view", instance.viewReqClass) { param -> - param.result ?: return@hookAfterMethod - if (removeRelatePromote && removeRelateOnlyAv && removeRelateNothing) { - param.result.callMethod("clearRelates") - param.result.callMethod("clearPagination") - return@hookAfterMethod - } - param.result.callMethod("ensureRelatesIsMutable") - param.result.callMethodAs>("getRelatesList").filter() - } + instance.viewMossClass?.hookAfterMethod( - "relatesFeed", - "com.bapis.bilibili.app.view.v1.RelatesFeedReq" + if (instance.useNewMossFunc) "executeView" else "view", + instance.viewReqClass ) { param -> - param.result ?: return@hookAfterMethod - param.result.callMethod("ensureListIsMutable") - param.result.callMethodAs>("getListList").filter() - } - // v8.17.0+ - instance.viewMossClass?.hookAfterMethod("executeView", instance.viewReqClass) { param -> param.result ?: return@hookAfterMethod if (removeRelatePromote && removeRelateOnlyAv && removeRelateNothing) { param.result.callMethod("clearRelates") @@ -606,7 +591,7 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) { param.result.callMethodAs>("getRelatesList").filter() } instance.viewMossClass?.hookAfterMethod( - "executeRelatesFeed", + if (instance.useNewMossFunc) "executeRelatesFeed" else "relatesFeed", "com.bapis.bilibili.app.view.v1.RelatesFeedReq" ) { param -> param.result ?: return@hookAfterMethod @@ -614,39 +599,11 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) { param.result.callMethodAs>("getListList").filter() } - - instance.viewUniteMossClass?.run { - hookAfterMethod("view", instance.viewUniteReqClass) { param -> - param.result ?: return@hookAfterMethod - param.result.callMethod("getTab")?.run { - callMethod("ensureTabModuleIsMutable") - callMethodAs>("getTabModuleList").map { originalTabModules -> - if (!originalTabModules.callMethodAs("hasIntroduction")) return@map - originalTabModules.callMethodAs("getIntroduction").run { - callMethod("ensureModulesIsMutable") - callMethodAs>("getModulesList").map { module -> - if (!module.callMethodAs("hasRelates")) return@map - module.callMethodAs("getRelates").run { - callMethod("ensureCardsIsMutable") - callMethodAs>("getCardsList").filterUnite() - } - } - } - } - } - } hookAfterMethod( - "relatesFeed", - "com.bapis.bilibili.app.viewunite.v1.RelatesFeedReq" + if (instance.useNewMossFunc) "executeView" else "view", + instance.viewUniteReqClass ) { param -> - param.result?.run { - callMethod("ensureRelatesIsMutable") - callMethodAs>("getRelatesList").filterUnite() - } - } - // v8.17.0+ - hookAfterMethod("executeView", instance.viewUniteReqClass) { param -> param.result ?: return@hookAfterMethod param.result.callMethod("getTab")?.run { callMethod("ensureTabModuleIsMutable") @@ -666,7 +623,7 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) { } } hookAfterMethod( - "executeRelatesFeed", + if (instance.useNewMossFunc) "executeRelatesFeed" else "relatesFeed", "com.bapis.bilibili.app.viewunite.v1.RelatesFeedReq" ) { param -> param.result?.run { @@ -743,34 +700,7 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) { } instance.popularClass?.hookBeforeMethod( - "index", - "com.bapis.bilibili.app.show.popular.v1.PopularResultReq" - ) { param -> - param.args ?: return@hookBeforeMethod - - val idx = param.args[0].getLongFieldOrNull("idx_") - if (idx == null || idx == 0L) { - popularDataCount = 0 - popularDataVersion = "" - return@hookBeforeMethod - } - - param.args[0].setObjectField("lastParam_", popularDataVersion) - param.args[0].setLongField("idx_", popularDataCount) - } - instance.popularClass?.hookAfterMethod( - "index", - "com.bapis.bilibili.app.show.popular.v1.PopularResultReq" - ) { param -> - param.result ?: return@hookAfterMethod - - param.result.callMethod("ensureItemsIsMutable") - param.result.callMethodAs>("getItemsList").filterPopular() - } - - // v8.17.0+ - instance.popularClass?.hookBeforeMethod( - "executeIndex", + if (instance.useNewMossFunc) "executeIndex" else "index", "com.bapis.bilibili.app.show.popular.v1.PopularResultReq" ) { param -> param.args ?: return@hookBeforeMethod @@ -786,7 +716,7 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) { param.args[0].setLongField("idx_", popularDataCount) } instance.popularClass?.hookAfterMethod( - "executeIndex", + if (instance.useNewMossFunc) "executeIndex" else "index", "com.bapis.bilibili.app.show.popular.v1.PopularResultReq" ) { param -> param.result ?: return@hookAfterMethod diff --git a/app/src/main/java/me/iacn/biliroaming/hook/ProtoBufHook.kt b/app/src/main/java/me/iacn/biliroaming/hook/ProtoBufHook.kt index c934a56136..08fe55683f 100644 --- a/app/src/main/java/me/iacn/biliroaming/hook/ProtoBufHook.kt +++ b/app/src/main/java/me/iacn/biliroaming/hook/ProtoBufHook.kt @@ -85,41 +85,10 @@ class ProtoBufHook(classLoader: ClassLoader) : BaseHook(classLoader) { } } - instance.viewMossClass?.hookAfterMethod("view", instance.viewReqClass) { param -> - param.result ?: return@hookAfterMethod - val aid = param.result.callMethod("getArc") - ?.callMethodAs("getAid") ?: -1L - val like = param.result.callMethod("getReqUser") - ?.callMethodAs("getLike") ?: -1 - AutoLikeHook.detail = aid to like - BangumiPlayUrlHook.qnApplied.set(false) - if (unlockPlayLimit) - param.result.callMethod("getConfig") - ?.callMethod("setShowListenButton", true) - if (blockCommentGuide) { - param.result.runCatchingOrNull { - callMethod("getLikeCustom") - ?.callMethod("clearLikeComment") - callMethod("getReplyPreface") - ?.callMethod("clearBadgeType") - } - } - if (hidden && removeHonor) { - param.result.callMethod("clearHonor") - } - if (hidden && removeUgcSeason) { - param.result.callMethod("clearUgcSeason") - } - if (hidden && blockLiveOrder) { - param.result.callMethod("clearLiveOrderInfo") - } - if (hidden && removeUpVipLabel) { - param.result.callMethod("getOwnerExt")?.callMethod("getVip") - ?.callMethod("clearLabel") - } - } - // v8.17.0+ - instance.viewMossClass?.hookAfterMethod("executeView", instance.viewReqClass) { param -> + instance.viewMossClass?.hookAfterMethod( + if (instance.useNewMossFunc) "executeView" else "view", + instance.viewReqClass + ) { param -> param.result ?: return@hookAfterMethod val aid = param.result.callMethod("getArc") ?.callMethodAs("getAid") ?: -1L @@ -155,35 +124,13 @@ class ProtoBufHook(classLoader: ClassLoader) : BaseHook(classLoader) { if (hidden && removeCmdDms) { instance.viewMossClass?.hookAfterMethod( - "viewProgress", - "com.bapis.bilibili.app.view.v1.ViewProgressReq" - ) { param -> - param.result?.callMethod("setVideoGuide", videoGuideClass?.new()) - } - instance.viewUniteMossClass?.hookAfterMethod( - "viewProgress", - "com.bapis.bilibili.app.viewunite.v1.ViewProgressReq" - ) { param -> - param.result?.run { - callMethod("clearDm") - callMethod("getVideoGuide")?.callMethod("clearContractCard") - } - } - instance.viewMossClass?.replaceMethod( - "tFInfo", "com.bapis.bilibili.app.view.v1.TFInfoReq" - ) { null } - instance.dmMossClass?.hookAfterMethod( - "dmView", instance.dmViewReqClass, - ) { it.result?.removeCmdDms() } - // v8.17.0+ - instance.viewMossClass?.hookAfterMethod( - "executeViewProgress", + if (instance.useNewMossFunc) "executeViewProgress" else "viewProgress", "com.bapis.bilibili.app.view.v1.ViewProgressReq" ) { param -> param.result?.callMethod("setVideoGuide", videoGuideClass?.new()) } instance.viewUniteMossClass?.hookAfterMethod( - "executeViewProgress", + if (instance.useNewMossFunc) "executeViewProgress" else "viewProgress", "com.bapis.bilibili.app.viewunite.v1.ViewProgressReq" ) { param -> param.result?.run { @@ -192,24 +139,18 @@ class ProtoBufHook(classLoader: ClassLoader) : BaseHook(classLoader) { } } instance.viewMossClass?.replaceMethod( - "executeTFInfo", "com.bapis.bilibili.app.view.v1.TFInfoReq" + if (instance.useNewMossFunc) "executeTFInfo" else "tFInfo", + "com.bapis.bilibili.app.view.v1.TFInfoReq" ) { null } instance.dmMossClass?.hookAfterMethod( - "executeDmView", instance.dmViewReqClass, + if (instance.useNewMossFunc) "executeDmView" else "dmView", + instance.dmViewReqClass, ) { it.result?.removeCmdDms() } } if (hidden && purifySearch) { "com.bapis.bilibili.app.interfaces.v1.SearchMoss".hookAfterMethod( mClassLoader, - "defaultWords", - "com.bapis.bilibili.app.interfaces.v1.DefaultWordsReq" - ) { param -> - param.result = null - } - // v8.17.0+ - "com.bapis.bilibili.app.interfaces.v1.SearchMoss".hookAfterMethod( - mClassLoader, - "executeDefaultWords", + if (instance.useNewMossFunc) "executeDefaultWords" else "defaultWords", "com.bapis.bilibili.app.interfaces.v1.DefaultWordsReq" ) { param -> param.result = null @@ -236,15 +177,7 @@ class ProtoBufHook(classLoader: ClassLoader) : BaseHook(classLoader) { if (hidden && blockModules) { "com.bapis.bilibili.app.resource.v1.ModuleMoss".hookAfterMethod( mClassLoader, - "list", - "com.bapis.bilibili.app.resource.v1.ListReq" - ) { - it.result?.callMethod("clearPools") - } - // v8.17.0+ - "com.bapis.bilibili.app.resource.v1.ModuleMoss".hookAfterMethod( - mClassLoader, - "executeList", + if (instance.useNewMossFunc) "executeList" else "list", "com.bapis.bilibili.app.resource.v1.ListReq" ) { it.result?.callMethod("clearPools") @@ -274,9 +207,8 @@ class ProtoBufHook(classLoader: ClassLoader) : BaseHook(classLoader) { if (blockCommentGuide || (hidden && blockVideoComment)) { "com.bapis.bilibili.main.community.reply.v1.ReplyMoss".hookBeforeMethod( mClassLoader, - "mainList", + if (instance.useNewMossFunc) "executeMainList" else "mainList", "com.bapis.bilibili.main.community.reply.v1.MainListReq", - instance.mossResponseHandlerClass ) { param -> val type = param.args[0].callMethodAs("getType") if (hidden && blockVideoComment && type == 1L) { @@ -302,134 +234,33 @@ class ProtoBufHook(classLoader: ClassLoader) : BaseHook(classLoader) { emptyPage?.callMethod("addTexts", it) } } - param.args[1].callMethod("onNext", reply) - param.result = null + param.result = reply return@hookBeforeMethod } if (!blockCommentGuide) return@hookBeforeMethod - param.args[1] = param.args[1].mossResponseHandlerProxy { reply -> - reply?.runCatchingOrNull { - callMethod("getSubjectControl")?.run { - callMethod("clearEmptyBackgroundTextPlain") - callMethod("clearEmptyBackgroundTextHighlight") - callMethod("clearEmptyBackgroundUri") - callMethod("getEmptyPage")?.let { page -> - page.callMethod("clearLeftButton") - page.callMethod("clearRightButton") - page.callMethodAs>("getTextsList").takeIf { it.size > 1 } - ?.let { - page.callMethod("clearTexts") - page.callMethod("addTexts", it.first().apply { - callMethod("setRaw", "还没有评论哦") - }) - } - } - } - } - } - } - "com.bapis.bilibili.main.community.reply.v2.ReplyMoss".from(mClassLoader) - ?.hookBeforeMethod( - "subjectDescription", - "com.bapis.bilibili.main.community.reply.v2.SubjectDescriptionReq", - instance.mossResponseHandlerClass - ) { param -> - val defaultText = textV2Class?.new()?.apply { - val tipStr = if (hidden && blockVideoComment) { - "评论区已由漫游屏蔽" - } else { - "还没有评论哦" - } - callMethod("setRaw", tipStr) - textStyleV2Class?.new()?.apply { - callMethod("setFontSize", 14) - callMethod("setTextDayColor", "#FF61666D") - callMethod("setTextNightColor", "#FFA2A7AE") - }?.let { - callMethod("setStyle", it) - } - } ?: return@hookBeforeMethod - param.args[1] = param.args[1].mossResponseHandlerProxy { reply -> - reply?.runCatchingOrNull { - callMethod("getEmptyPage")?.run { - callMethod("clearLeftButton") - callMethod("clearRightButton") - callMethod("ensureTextsIsMutable") - callMethodAs>("getTextsList").run { - clear() - add(defaultText) + param.result.runCatchingOrNull { + callMethod("getSubjectControl")?.run { + callMethod("clearEmptyBackgroundTextPlain") + callMethod("clearEmptyBackgroundTextHighlight") + callMethod("clearEmptyBackgroundUri") + callMethod("getEmptyPage")?.let { page -> + page.callMethod("clearLeftButton") + page.callMethod("clearRightButton") + page.callMethodAs>("getTextsList").takeIf { it.size > 1 } + ?.let { + page.callMethod("clearTexts") + page.callMethod("addTexts", it.first().apply { + callMethod("setRaw", "还没有评论哦") + }) } - if (!(hidden && blockVideoComment)) return@run - callMethod( - "setImageUrl", - "https://i0.hdslb.com/bfs/app-res/android/img_holder_forbid_style1.webp" - ) - } - } - } - } - // v8.17.0+ - "com.bapis.bilibili.main.community.reply.v1.ReplyMoss".hookBeforeMethod( - mClassLoader, - "executeMainList", - "com.bapis.bilibili.main.community.reply.v1.MainListReq", - instance.mossResponseHandlerClass - ) { param -> - val type = param.args[0].callMethodAs("getType") - if (hidden && blockVideoComment && type == 1L) { - val reply = mainListReplyClass?.new()?.apply { - val subjectControl = callMethod("getSubjectControl") - val emptyPage = emptyPageV1Class?.new()?.also { - subjectControl?.callMethod("setEmptyPage", it) - } - emptyPage?.callMethod( - "setImageUrl", - "https://i0.hdslb.com/bfs/app-res/android/img_holder_forbid_style1.webp" - ) - textV1Class?.new()?.apply { - callMethod("setRaw", "评论区已由漫游屏蔽") - textStyleV1Class?.new()?.apply { - callMethod("setFontSize", 14) - callMethod("setTextDayColor", "#FF61666D") - callMethod("setTextNightColor", "#FFA2A7AE") - }?.let { - callMethod("setStyle", it) - } - }?.let { - emptyPage?.callMethod("addTexts", it) - } - } - param.args[1].callMethod("onNext", reply) - param.result = null - return@hookBeforeMethod - } - if (!blockCommentGuide) return@hookBeforeMethod - param.args[1] = param.args[1].mossResponseHandlerProxy { reply -> - reply?.runCatchingOrNull { - callMethod("getSubjectControl")?.run { - callMethod("clearEmptyBackgroundTextPlain") - callMethod("clearEmptyBackgroundTextHighlight") - callMethod("clearEmptyBackgroundUri") - callMethod("getEmptyPage")?.let { page -> - page.callMethod("clearLeftButton") - page.callMethod("clearRightButton") - page.callMethodAs>("getTextsList").takeIf { it.size > 1 } - ?.let { - page.callMethod("clearTexts") - page.callMethod("addTexts", it.first().apply { - callMethod("setRaw", "还没有评论哦") - }) - } - } } } } } "com.bapis.bilibili.main.community.reply.v2.ReplyMoss".from(mClassLoader) ?.hookBeforeMethod( - "executeSubjectDescription", - "com.bapis.bilibili.main.community.reply.v2.SubjectDescriptionReq", - instance.mossResponseHandlerClass + if (instance.useNewMossFunc) "executeSubjectDescription" else "subjectDescription", + "com.bapis.bilibili.main.community.reply.v2.SubjectDescriptionReq" ) { param -> val defaultText = textV2Class?.new()?.apply { val tipStr = if (hidden && blockVideoComment) { @@ -446,22 +277,20 @@ class ProtoBufHook(classLoader: ClassLoader) : BaseHook(classLoader) { callMethod("setStyle", it) } } ?: return@hookBeforeMethod - param.args[1] = param.args[1].mossResponseHandlerProxy { reply -> - reply?.runCatchingOrNull { - callMethod("getEmptyPage")?.run { - callMethod("clearLeftButton") - callMethod("clearRightButton") - callMethod("ensureTextsIsMutable") - callMethodAs>("getTextsList").run { - clear() - add(defaultText) - } - if (!(hidden && blockVideoComment)) return@run - callMethod( - "setImageUrl", - "https://i0.hdslb.com/bfs/app-res/android/img_holder_forbid_style1.webp" - ) + param.result.runCatchingOrNull { + callMethod("getEmptyPage")?.run { + callMethod("clearLeftButton") + callMethod("clearRightButton") + callMethod("ensureTextsIsMutable") + callMethodAs>("getTextsList").run { + clear() + add(defaultText) } + if (!(hidden && blockVideoComment)) return@run + callMethod( + "setImageUrl", + "https://i0.hdslb.com/bfs/app-res/android/img_holder_forbid_style1.webp" + ) } } } @@ -553,34 +382,8 @@ class ProtoBufHook(classLoader: ClassLoader) : BaseHook(classLoader) { } instance.viewUniteMossClass?.hookAfterMethod( - "view", instance.viewUniteReqClass - ) { param -> - if (instance.networkExceptionClass?.isInstance(param.throwable) == true) return@hookAfterMethod - param.result ?: return@hookAfterMethod - - if (blockViewPageAds) { - param.result.callMethod("clearCm") - } - - param.result.callMethod("getTab")?.run { - callMethod("ensureTabModuleIsMutable") - val tabModuleList = callMethodAs>("getTabModuleList") - tabModuleList.removeAll { - blockVideoComment && it.callMethodAs("hasReply") - } - if (!(blockViewPageAds || removeHonor)) return@run - tabModuleList.map { - if (!it.callMethodAs("hasIntroduction")) return@map - it.callMethodAs("getIntroduction").run { - callMethod("ensureModulesIsMutable") - callMethodAs>("getModulesList").filter() - } - } - } - } - // v8.17.0+ - instance.viewUniteMossClass?.hookAfterMethod( - "executeView", instance.viewUniteReqClass + if (instance.useNewMossFunc) "executeView" else "view", + instance.viewUniteReqClass ) { param -> if (instance.networkExceptionClass?.isInstance(param.throwable) == true) return@hookAfterMethod param.result ?: return@hookAfterMethod