Skip to content

Commit

Permalink
fix: disable try vip quality for v7.50.0+ (yujincheng08#1609)
Browse files Browse the repository at this point in the history
  • Loading branch information
TinyHai authored Jan 9, 2025
1 parent 5e46c07 commit 1f2f8bf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 26 deletions.
55 changes: 38 additions & 17 deletions app/src/main/java/me/iacn/biliroaming/BiliBiliPackage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ 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 }
val continuationClass by Weak { mHookInfo.continuation.class_ from mClassLoader }
val vipQualityTrialService by Weak { mHookInfo.vipQualityTrialService.class_ from mClassLoader }

// for v8.17.0+
val useNewMossFunc = instance.viewMossClass?.declaredMethods?.any {
Expand Down Expand Up @@ -284,7 +285,7 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex

fun cancelShowToast() = mHookInfo.toastHelper.cancel.orNull

fun canTryWatchVipQuality() = mHookInfo.canTryWatchVipQuality.orNull
fun canTrialMethod() = mHookInfo.vipQualityTrialService.canTrial.orNull

fun setInvalidTips() = commentInvalidFragmentClass?.declaredMethods?.find { m ->
m.parameterTypes.let { it.size == 2 && it[0] == commentInvalidFragmentClass && it[1].name == "kotlin.Pair" }
Expand Down Expand Up @@ -1645,22 +1646,6 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
dexHelper.decodeMethodIndex(it)
}?.declaringClass?.name ?: return@class_
}
canTryWatchVipQuality = method {
name = dexHelper.findMethodUsingString(
"user is vip, cannot trywatch",
false,
dexHelper.encodeClassIndex(Boolean::class.java),
-1,
null,
-1,
null,
null,
null,
true
).firstOrNull()?.let {
dexHelper.decodeMethodIndex(it)
}?.name ?: return@method
}
dexHelper.findMethodUsingString(
"player.player.story-button.0.player",
false,
Expand Down Expand Up @@ -2104,6 +2089,42 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
val continuation = continuationImpl.interfaces.firstOrNull() ?: return@continuation
class_ = class_ { name = continuation.name }
}
vipQualityTrialService = vipQualityTrialService {
val serviceClass = dexHelper.findMethodUsingString(
"go to buy vip: ",
false,
-1,
-1,
null,
-1,
null,
null,
null,
false
).asSequence().mapNotNull {
dexHelper.decodeMethodIndex(it)?.declaringClass
}.firstOrNull {
it.name.startsWith("com.bilibili")
} ?: return@vipQualityTrialService
val canTrialMethod = serviceClass.declaredMethods.asSequence().filter {
it.returnType == Boolean::class.javaPrimitiveType && it.parameterCount == 0
}.firstNotNullOfOrNull { candidate ->
val getTrialInfoMethods = dexHelper.findMethodInvoking(
dexHelper.encodeMethodIndex(candidate),
-1,
0,
null,
dexHelper.encodeClassIndex(serviceClass),
null,
null,
null,
true
)
if (getTrialInfoMethods.isNotEmpty()) candidate else null
} ?: return@vipQualityTrialService
class_ = class_ { name = serviceClass.name }
canTrial = method { name = canTrialMethod.name }
}

dexHelper.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ package me.iacn.biliroaming.hook
import me.iacn.biliroaming.BiliBiliPackage.Companion.instance
import me.iacn.biliroaming.utils.Log
import me.iacn.biliroaming.utils.hookBeforeMethod
import me.iacn.biliroaming.utils.replaceMethod
import me.iacn.biliroaming.utils.sPrefs

class TryWatchVipQualityHook(classLoader: ClassLoader) : BaseHook(classLoader) {
override fun startHook() {
if (!sPrefs.getBoolean("disable_try_watch_vip_quality", false)) return

Log.d("startHook: TryWatchVipQualityHook")
instance.canTryWatchVipQuality()?.let { m ->
instance.playerQualityServiceClass?.hookBeforeMethod(
m
) {
it.result = false
}
}
instance.vipQualityTrialService?.replaceMethod(instance.canTrialMethod()) { false }
}
}
7 changes: 6 additions & 1 deletion app/src/main/proto/me/iacn/biliroaming/configs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ message Continuation {
optional Class class = 1;
}

message VipQualityTrialService {
optional Class class = 1;
optional Method canTrial = 2;
}

message HookInfo {
int64 last_update_time = 1;
optional MapIds map_ids = 2;
Expand Down Expand Up @@ -311,7 +316,6 @@ message HookInfo {
optional KanBan kan_ban = 67;
optional ToastHelper toast_helper = 68;
optional Class brotli_input_stream = 69;
optional Method can_try_watch_vip_quality = 70;
repeated PlayerFullStoryWidget player_full_story_widget = 71;
optional BiliCall bili_call = 72;
optional Class comment_long_click_new = 73;
Expand All @@ -335,4 +339,5 @@ message HookInfo {
optional AutoSupremumQuality autoSupremumQuality = 94;
optional QualityStrategyProvider qualityStrategyProvider = 95;
optional Continuation continuation = 96;
optional VipQualityTrialService vipQualityTrialService = 97;
}

0 comments on commit 1f2f8bf

Please sign in to comment.