Skip to content

Commit

Permalink
Revert "feat: remove trial vip quality"
Browse files Browse the repository at this point in the history
This reverts commit 4eb3502.
  • Loading branch information
Quackgrass committed Jan 4, 2025
1 parent 86e8db4 commit 84250a9
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>

> [!IMPORTANT]
> 基于 [BiliRoamingX](https://github.com/BiliRoamingX/BiliRoamingX)去除番剧解锁、大会员画质试用等功能
> 基于 [BiliRoamingX](https://github.com/BiliRoamingX/BiliRoamingX)去除番剧解锁等功能
>
> 此 Fork 针对 Play 版本测试,仅进行维护性更新。
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package app.revanced.bilibili.patches;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.Keep;

import com.bapis.bilibili.app.playerunite.v1.PlayViewUniteReply;
import com.bapis.bilibili.app.playurl.v1.PlayViewReply;
import com.bapis.bilibili.app.playurl.v1.Stream;

import app.revanced.bilibili.account.Accounts;
import app.revanced.bilibili.settings.Settings;
import app.revanced.bilibili.utils.Utils;

public class TrialQualityPatch {

private static int dp2px(float dp) {
return (int) ((dp * Utils.getContext().getResources().getDisplayMetrics().density) + 0.5f);
}

public static void makeVipFree(PlayViewReply playViewReply) {
playViewReply.clearAb();
playViewReply.getVideoInfo().getStreamListList().stream().filter(Stream::hasDashVideo)
.forEach(e -> {
var streamInfo = e.getStreamInfo();
if (streamInfo.getNeedVip()) {
streamInfo.setNeedVip(false);
streamInfo.setVipFree(true);
}
});
}

public static void makeVipFree(PlayViewUniteReply playViewUniteReply) {
playViewUniteReply.clearQnTrialInfo();
playViewUniteReply.getVodInfo().getStreamListList().stream().filter(com.bapis.bilibili.playershared.Stream::hasDashVideo)
.forEach(e -> {
var streamInfo = e.getStreamInfo();
if (streamInfo.getNeedVip()) {
streamInfo.setNeedVip(false);
streamInfo.setVipFree(true);
}
});
}

@Keep
public static void onBindOnline(boolean selected, TextView strokeBadge, TextView solidBadge) {
if (Settings.TrialVipQuality.get() && !Accounts.isEffectiveVip()
&& Utils.getString("try_listening_tips") // 限免中
.equals(solidBadge.getText().toString())) {
solidBadge.setVisibility(View.GONE);
var strokeText = selected ? Utils.getString("player_try_watching") // 试看中
: Utils.getString("player_try_watch_enable"); // 可试看
strokeBadge.setText(strokeText);
strokeBadge.setVisibility(View.VISIBLE);
if (strokeText.length() > 2) {
strokeBadge.setPadding(dp2px(4f), dp2px(1f), dp2px(4f), dp2px(2f));
} else {
strokeBadge.setPadding(dp2px(8.5f), dp2px(1f), dp2px(8.5f), dp2px(2f));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ object GrpcPlayViewUnite : BaseFakeClientGrpcHook() {
val authIndex = newHeaders.indexOfFirst { it == "authorization" }
if (authIndex != -1)
newHeaders[authIndex + 1] = "identify_v1 ${getFinalAccessKey(false)}"
if ((Utils.isPink() || Utils.isPlay()) && Settings.TrialVipQuality() && !Accounts.isEffectiveVip) {
val keyIndex = newHeaders.indexOfFirst { it == "x-bili-network-bin" }
if (keyIndex == -1)
return Pair.create(url, newHeaders)
val networkBin = newHeaders.getOrNull(keyIndex + 1)
if (!networkBin.isNullOrEmpty()) {
val newNetworkBin = Network.parseFrom(networkBin.base64Decode).apply {
type = NetworkType.WIFI
}.toByteArray().base64
newHeaders[keyIndex + 1] = newNetworkBin
}
}
return Pair.create(url, newHeaders)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,30 @@ object MossPatch {
@Keep
@JvmStatic
fun hookBeforeRequest(url: String, headers: ArrayList<Map.Entry<String, String>>): String {
if (url.endsWith(PLAY_VIEW_UNITE_API)) {
if ((Utils.isPink() || Utils.isPlay()) && Settings.TrialVipQuality() && !Accounts.isEffectiveVip)
pinNetworkType(NetworkType.WIFI, headers)
}
if (url.endsWith(PLAY_VIEW_UNITE_API))
headers["authorization"] = "identify_v1 ${getFinalAccessKey(false)}"
return url
}

@Suppress("SameParameterValue")
private fun pinNetworkType(type: NetworkType, headers: ArrayList<Map.Entry<String, String>>) {
val networkBinKey = "x-bili-network-bin"
val networkBinValue = headers.find { it.key == networkBinKey }?.value
if (!networkBinValue.isNullOrEmpty()) {
val newNetworkBin = Network.parseFrom(networkBinValue.base64Decode).apply {
this.type = type
}.toByteArray().base64
headers[networkBinKey] = newNetworkBin
}
}

@Suppress("SameParameterValue")
private fun fakeClient(client: Client, headers: ArrayList<Map.Entry<String, String>>) {
headers["x-bili-metadata-bin"] = grpcMetadataHeader(client)
headers["x-bili-device-bin"] = grpcDeviceHeader(client)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package app.revanced.bilibili.patches.protobuf.hooks

import android.content.pm.ActivityInfo
import app.revanced.bilibili.account.Accounts
import app.revanced.bilibili.meta.VideoInfo
import app.revanced.bilibili.patches.TrialQualityPatch
import app.revanced.bilibili.patches.VideoQualityPatch
import app.revanced.bilibili.patches.main.ApplicationDelegate
import app.revanced.bilibili.patches.main.VideoInfoHolder
Expand Down Expand Up @@ -53,6 +55,9 @@ object PlayURLPlayViewUGC : MossHook<PlayViewReq, PlayViewReply>() {
}
}
}
if (req.download < 1 && !Accounts.isEffectiveVip
&& Settings.TrialVipQuality()
) TrialQualityPatch.makeVipFree(reply)
if (Utils.isHd() && Settings.NotLockOrientation()) {
val dashVideo = reply.videoInfo.streamListList.firstNotNullOfOrNull {
if (it.hasDashVideo()) it.dashVideo else null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ object Settings {
@JvmField val DefaultPlaybackSpeed = FloatSetting(key = "default_playback_speed")
@JvmField val LongPressPlaybackSpeed = FloatSetting(key = "long_press_playback_speed")
@JvmField val OverridePlaybackSpeed = StringSetting(key = "playback_speed_override", needReboot = true)
@JvmField val TrialVipQuality = BooleanSetting(key = "trial_vip_quality")
@JvmField val DisableSegmentedSection = BooleanSetting(key = "disable_segmented_section")
@JvmField val DisableAutoNextPlay = BooleanSetting(key = "disable_auto_next_play")
@JvmField val DisablePlayerLongPress = BooleanSetting(key = "disable_player_long_press")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package app.revanced.patches.bilibili.misc.other.patch

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.bilibili.misc.other.fingerprints.QualityViewHolderFingerprint
import app.revanced.patches.bilibili.patcher.patch.MultiMethodBytecodePatch
import app.revanced.patches.bilibili.utils.cloneMutable
import app.revanced.patches.bilibili.utils.exception

@Patch(
name = "Trial quality",
description = "试用画质辅助补丁",
compatiblePackages = [
CompatiblePackage(name = "tv.danmaku.bili"),
CompatiblePackage(name = "tv.danmaku.bilibilihd"),
CompatiblePackage(name = "com.bilibili.app.in")
]
)
object TrialQualityPatch : MultiMethodBytecodePatch(
multiFingerprints = setOf(QualityViewHolderFingerprint)
) {
override fun execute(context: BytecodeContext) {
super.execute(context)
val patchMethod = context.findClass("Lapp/revanced/bilibili/patches/TrialQualityPatch;")!!
.mutableClass.methods.first { it.name == "onBindOnline" }
QualityViewHolderFingerprint.result.associate { r ->
r.mutableClass.methods to r.mutableClass.methods.first { m ->
m.parameterTypes.let { it.size == 5 && it[1] == "Z" && it[3] == "Landroid/widget/TextView;" && it[4] == "Landroid/widget/TextView;" }
}
}.ifEmpty {
throw QualityViewHolderFingerprint.exception
}.forEach { (methods, method) ->
val originMethod = method.cloneMutable(name = method.name + "_Origin")
.also { methods.add(it) }
method.also { methods.remove(it) }.cloneMutable(registerCount = 6, clearImplementation = true).apply {
addInstructions(
"""
invoke-direct/range {p0 .. p5}, $originMethod
invoke-static {p2, p4, p5}, $patchMethod
return-void
""".trimIndent()
)
}.also { methods.add(it) }
}
}
}
2 changes: 2 additions & 0 deletions patches/src/main/resources/bilibili/host/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@
<string name="biliroaming_reboot_title">重启</string>
<string name="biliroaming_custom_theme_title">自定义主题色</string>
<string name="biliroaming_custom_theme_summary">添加自定义主题颜色的功能(需从我的右上角调色盘图标进入)</string>
<string name="biliroaming_trial_vip_quality_title">无限试用会员画质</string>
<string name="biliroaming_trial_vip_quality_summary">只解决试用次数问题,能否试用取决于官方接口,仅支持粉版,如不生效,尝试将播放器版本切换为旧版。</string>
<string name="biliroaming_unstable_feature_title">实验性</string>
<string name="biliroaming_filter_story_title">竖屏模式视频过滤</string>
<string name="biliroaming_skin_title">启用自制主题</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
android:key="category_unstable"
android:layout="@layout/bili_app_layout_preference_category_title"
android:title="@string/biliroaming_unstable_feature_title">
<androidx.preference.SwitchPreferenceCompat
android:key="trial_vip_quality"
android:summary="@string/biliroaming_trial_vip_quality_summary"
android:title="@string/biliroaming_trial_vip_quality_title" />
<androidx.preference.SwitchPreferenceCompat
android:key="force_hw_codec"
android:summary="@string/biliroaming_force_hw_codec_summary"
Expand Down

0 comments on commit 84250a9

Please sign in to comment.