Update ThemesModule.kt
This commit is contained in:
parent
7152b06265
commit
8616f04995
1 changed files with 49 additions and 29 deletions
|
|
@ -46,7 +46,6 @@ object ThemesModule : Module() {
|
|||
|
||||
private const val THEME_FILE = "current-theme.json"
|
||||
|
||||
|
||||
@Deprecated("This method is deprecated in the parent class")
|
||||
@ExperimentalSerializationApi
|
||||
override fun buildPayload(builder: JsonObjectBuilder) {
|
||||
|
|
@ -86,10 +85,20 @@ object ThemesModule : Module() {
|
|||
}
|
||||
|
||||
fun hookTheme() {
|
||||
try {
|
||||
val themeManager = param.classLoader.loadClass("com.discord.theme.utils.ColorUtilsKt")
|
||||
val darkTheme = param.classLoader.loadClass("com.discord.theme.DarkerTheme")
|
||||
val lightTheme = param.classLoader.loadClass("com.discord.theme.LightTheme")
|
||||
|
||||
hookThemeInternal(themeManager, darkTheme, lightTheme)
|
||||
} catch (e: Throwable) {
|
||||
GoonXposed.xposed.Utils.Log.e("Failed to hook theme: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun hookThemeInternal(
|
||||
themeManager: Class<*>, darkTheme: Class<*>, lightTheme: Class<*>
|
||||
) {
|
||||
val theme = this.theme ?: return
|
||||
|
||||
// Apply rawColors
|
||||
|
|
@ -111,6 +120,7 @@ object ThemesModule : Module() {
|
|||
|
||||
// If there's any rawColors value, hook the color getter
|
||||
if (!theme.data.rawColors.isNullOrEmpty()) {
|
||||
try {
|
||||
val getColorCompat = themeManager.getDeclaredMethod(
|
||||
"getColorCompat",
|
||||
Resources::class.java,
|
||||
|
|
@ -124,11 +134,14 @@ object ThemesModule : Module() {
|
|||
|
||||
val patch = MethodHookBuilder().run {
|
||||
before {
|
||||
try {
|
||||
val arg1 = args[0]
|
||||
val resources = if (arg1 is Context) arg1.resources else (arg1 as Resources)
|
||||
val name = resources.getResourceEntryName(args[1] as Int)
|
||||
|
||||
if (rawColorMap[name] != null) result = rawColorMap[name]
|
||||
} catch (_: Throwable) {
|
||||
}
|
||||
}
|
||||
|
||||
build()
|
||||
|
|
@ -136,17 +149,24 @@ object ThemesModule : Module() {
|
|||
|
||||
getColorCompat.hook(patch)
|
||||
getColorCompatLegacy.hook(patch)
|
||||
} catch (e: Throwable) {
|
||||
GoonXposed.xposed.Utils.Log.e("Failed to hook getColorCompat: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parse HEX colour string to INT. Takes "#RRGGBBAA" or "#RRGGBB"
|
||||
private fun hexStringToColorInt(hexString: String): Int {
|
||||
return if (hexString.length == 9) {
|
||||
return try {
|
||||
if (hexString.length == 9) {
|
||||
// Rearrange RRGGBBAA -> AARRGGBB so parseColor() is happy
|
||||
val alpha = hexString.substring(7, 9)
|
||||
val rrggbb = hexString.substring(1, 7)
|
||||
"#$alpha$rrggbb".toColorInt()
|
||||
} else hexString.toColorInt()
|
||||
} catch (_: Throwable) {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
private fun hookThemeMethod(themeClass: Class<*>, methodName: String, themeValue: Int) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue