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: custom theme & video quality & some hookinfo #1589

Merged
merged 3 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
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
41 changes: 30 additions & 11 deletions app/src/main/java/me/iacn/biliroaming/BiliBiliPackage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,11 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
null,
null,
null,
true
).asSequence().firstNotNullOfOrNull {
false
).asSequence().mapNotNull {
dexHelper.decodeMethodIndex(it)
}.firstOrNull {
it.declaringClass?.name?.startsWith("okhttp3") == true
}?.declaringClass
okHttp = okHttp {
val responseClass = "okhttp3.Response".from(classloader)
Expand All @@ -483,9 +485,11 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
null,
null,
null,
true
).asSequence().firstNotNullOfOrNull {
false
).asSequence().mapNotNull {
dexHelper.decodeMethodIndex(it)
}.firstOrNull {
it.declaringClass?.name?.startsWith("okhttp3") == true
}?.declaringClass ?: return@okHttp
val requestClass = "okhttp3.Request".from(classloader)
?: dexHelper.findMethodUsingString(
Expand All @@ -498,9 +502,11 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
null,
null,
null,
true
).asSequence().firstNotNullOfOrNull {
false
).asSequence().mapNotNull {
dexHelper.decodeMethodIndex(it)
}.firstOrNull {
it.declaringClass?.name?.startsWith("okhttp3") == true
}?.declaringClass ?: return@okHttp
val urlClass = "okhttp3.HttpUrl".from(classloader)
?: dexHelper.findMethodUsingString(
Expand Down Expand Up @@ -528,9 +534,11 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
null,
null,
null,
true
).asSequence().firstNotNullOfOrNull {
false
).asSequence().mapNotNull {
dexHelper.decodeMethodIndex(it)
}.firstOrNull {
it.declaringClass?.name?.startsWith("okhttp3") == true
} ?: return@okHttp
request = request {
class_ = class_ { name = requestClass.name }
Expand Down Expand Up @@ -1379,10 +1387,21 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
null,
null,
null,
true
).asSequence().firstNotNullOfOrNull {
false
).asSequence().mapNotNull {
dexHelper.decodeMethodIndex(it)
}?.declaringClass ?: return@okIOBuffer
}.firstNotNullOfOrNull {
val method = it as? Method ?: return@firstNotNullOfOrNull null
val firstParameterType = method.parameterTypes.firstOrNull()
val returnType = method.returnType
when {
method.declaringClass?.name?.startsWith("okio") != true -> null
// https://github.com/square/okio/blob/okio-parent-2.0.0-RC1/okio/jvm/src/main/java/okio/Buffer.kt#L1717
firstParameterType == null || firstParameterType == returnType -> it.declaringClass
// https://github.com/square/okio/blob/parent-2.10.0/okio/src/commonMain/kotlin/okio/internal/Buffer.kt#L1509
else -> firstParameterType
}
} ?: return@okIOBuffer
class_ = class_ { name = okioBufferClass.name }
val okioInputStreamMethod = okioBufferClass.declaredMethods.firstOrNull {
it.parameterTypes.isEmpty() && it.returnType == InputStream::class.java
Expand Down
35 changes: 30 additions & 5 deletions app/src/main/java/me/iacn/biliroaming/hook/CustomThemeHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ class CustomThemeHook(classLoader: ClassLoader) : BaseHook(classLoader) {

val allThemes =
instance.builtInThemesClass?.getStaticObjectFieldAs<MutableMap<Long, Any>>(instance.allThemesField())
primaryColor.toTheme()?.let {
allThemes?.put(CUSTOM_THEME_ID1.toLong(), it)
allThemes?.put(CUSTOM_THEME_ID2.toLong(), it)
}

instance.skinList()?.let {
"tv.danmaku.bili.ui.theme.ThemeStoreActivity".hookBeforeMethod(
Expand Down Expand Up @@ -107,6 +103,17 @@ class CustomThemeHook(classLoader: ClassLoader) : BaseHook(classLoader) {
}
}

override fun lateInitHook() {
val primaryColor = customColor

val allThemes =
instance.builtInThemesClass?.getStaticObjectFieldAs<MutableMap<Long, Any>>(instance.allThemesField())
primaryColor.toTheme()?.let {
allThemes?.put(CUSTOM_THEME_ID1.toLong(), it)
allThemes?.put(CUSTOM_THEME_ID2.toLong(), it)
}
}

fun insertColorForWebProcess() {
if (!sPrefs.getBoolean("custom_theme", false)) return

Expand Down Expand Up @@ -205,8 +212,26 @@ class CustomThemeHook(classLoader: ClassLoader) : BaseHook(classLoader) {
private fun @receiver:ColorInt Int.pack() = toLong() and 0xFFFFFFFF shl 32
private fun @receiver:ColorInt Int.toTheme() = instance.themeColorsConstructor?.run {
parameterTypes.let {
val garb = it[0].let { cls ->
try {
cls.new()
} catch (err: NoSuchMethodError) {
// GarbInfo in play v3.20.0
cls.new(
0L, // id
true, // showDarkContent
true, // isPure
"", // homePrimaryBgPath
0L, // primary
0L, // secondary
0L, // background
0L, // textTitle
0L // actionIcon
)
}
}
newInstance(
it[0].new(), // garb
garb, // garb
it[1].enumConstants[0], // currentDayNight ThemeDayNight#Day
pack(), // primary !!important
pack(), // secondary !!important
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class VideoQualityHook(classLoader: ClassLoader) : BaseHook(classLoader) {
if (halfScreenQuality != 0) {
instance.playerPreloadHolderClass?.replaceAllMethods(instance.getPreload()) { null }
instance.playerQualityServices().forEach { (clazz, getDefaultQnThumb) ->
clazz?.replaceMethod(getDefaultQnThumb) { halfScreenQuality }
clazz?.replaceAllMethods(getDefaultQnThumb) { halfScreenQuality }
}
}
if (fullScreenQuality != 0) {
Expand Down
Loading