Skip to content

Commit

Permalink
fix: custom theme & video quality & some hookinfo (yujincheng08#1589)
Browse files Browse the repository at this point in the history
- 修复自定义主题
- 修复视频半屏/全屏清晰度
- 修复okio/okhttp的hookinfo
  • Loading branch information
TinyHai authored Dec 28, 2024
1 parent 1e00861 commit 1287ece
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
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

0 comments on commit 1287ece

Please sign in to comment.