Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use viewUnite for replaceStoryVideo #1566

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions app/src/main/java/me/iacn/biliroaming/hook/StartActivityHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@ import me.iacn.biliroaming.utils.hookBeforeAllMethods
import me.iacn.biliroaming.utils.hookBeforeMethod
import me.iacn.biliroaming.utils.packageName
import me.iacn.biliroaming.utils.sPrefs
import me.iacn.biliroaming.utils.toJSONObject
import kotlin.math.floor

class StartActivityHook(classLoader: ClassLoader) : BaseHook(classLoader) {

private fun fixIntentUri(original: Uri): Uri {
val fixedUri = Uri.parse(original.toString().replace("bilibili://story/", "bilibili://united_video/")).buildUpon()
.clearQuery()
.appendQueryParameter("from_spmid", original.getQueryParameter("from_spmid"))
.appendQueryParameter("aid", original.path?.split("/")?.last() ?: "")
.appendQueryParameter("bvid", "")
.build()
return fixedUri
}

override fun startHook() {
"tv.danmaku.bili.ui.intent.IntentHandlerActivity".hookBeforeMethod(mClassLoader, "onCreate", Bundle::class.java) { param ->
val a = param.thisObject as Activity
Expand All @@ -27,11 +40,35 @@ class StartActivityHook(classLoader: ClassLoader) : BaseHook(classLoader) {
false
) && uri.startsWith("bilibili://story/")
) {
intent.component = ComponentName(
intent.component?.packageName ?: packageName,
"com.bilibili.video.videodetail.VideoDetailsActivity"
)
intent.data = Uri.parse(uri.replace("bilibili://story/", "bilibili://video/"))
intent.data?.let {
try {
val cid = intent.data?.getQueryParameter("player_preload").toJSONObject().getLong("cid")
intent.data = fixIntentUri(Uri.parse(intent.dataString))
// fix extra
val pre = Uri.parse(intent.dataString).buildUpon().clearQuery().build().toString()
val aid = pre.split("/").last().toLong()
intent.removeExtra("player_preload")
intent.putExtra("player_preload", floor(Math.random()*1000000000).toInt().toString())
intent.putExtra("blrouter.targeturl", pre)
intent.putExtra("blrouter.pagename", "bilibili://united_video/")
intent.putExtra("jumpFrom", 7)
intent.putExtra("", aid)
intent.putExtra("aid", aid)
intent.putExtra("cid", cid)
intent.putExtra("bvid", "")
intent.putExtra("from", 7)
intent.putExtra("blrouter.targeturl", pre)
intent.putExtra("blrouter.matchrule", "bilibili://united_video/")
// fix component
intent.component = ComponentName(
intent.component?.packageName ?: packageName,
"com.bilibili.ship.theseus.detail.UnitedBizDetailsActivity"
)
} catch (e: Exception) {
Log.e("replaceStoryVideo fix intent failed!!!")
Log.e(e)
}
}
}
if (sPrefs.getBoolean("force_browser", false)) {
if (intent.component?.className?.endsWith("MWebActivity") == true &&
Expand Down
Loading