Merge pull request #2 from PaiGramTeam/fix

This commit is contained in:
HolographicHat 2024-08-08 19:12:03 +08:00 committed by GitHub
commit add41e1e1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,14 +1,13 @@
package hat.holo.token package hat.holo.token
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.AlertDialog
import android.app.Application import android.app.Application
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.res.XResources import android.content.res.XResources
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView import android.widget.ImageView
import android.widget.LinearLayout
import androidx.annotation.Keep import androidx.annotation.Keep
import dalvik.system.BaseDexClassLoader import dalvik.system.BaseDexClassLoader
import de.robv.android.xposed.IXposedHookLoadPackage import de.robv.android.xposed.IXposedHookLoadPackage
@ -53,21 +52,28 @@ class ModuleMain : IXposedHookLoadPackage, IXposedHookZygoteInit {
appendToClassPath(app.applicationContext) appendToClassPath(app.applicationContext)
} }
}) })
val c1 = loadClass("com.mihoyo.hyperion.main.user.MainUserInfoPage") val u = loadClass("com.mihoyo.hyperion.user_profile.UserProfileFragment")
XposedBridge.hookAllConstructors(c1, object : XC_MethodHook() { val rng = loadClass("rn.g") // FragmentUserProfileBinding.java
findAndHookMethod(u, "onViewCreated", android.view.View::class.java, android.os.Bundle::class.java, object : XC_MethodHook() {
override fun afterHookedMethod(p: MethodHookParam) { override fun afterHookedMethod(p: MethodHookParam) {
if (p.args.size != 3 || p.args.getOrNull(0) !is Context) return val getBinding = u.getDeclaredMethod("getBinding")
val root1 = p.thisObject as FrameLayout getBinding.isAccessible = true
val root2 = root1.getChildAt(0) as FrameLayout val bindingInstance = getBinding.invoke(p.thisObject)
val root3 = root2.getChildAt(0) as ViewGroup val getLinearLayout = rng.getDeclaredField("b")
val ctx = root1.context getLinearLayout.isAccessible = true
val scanId = ctx.resources.getIdentifier("scanIv", "id", targetPackageName) val linearLayout = getLinearLayout.get(bindingInstance) as LinearLayout
val scanBtn = root3.findViewById<ImageView>(scanId) val ctx = linearLayout.context
val getScanButton = rng.getDeclaredField("w")
getScanButton.isAccessible = true
val scanButton = getScanButton.get(bindingInstance) as ImageView
val tokenBtn = ImageView(ctx) val tokenBtn = ImageView(ctx)
tokenBtn.id = XResources.getFakeResId("getTokenIv") tokenBtn.id = XResources.getFakeResId("getTokenIv")
tokenBtn.setImageDrawable(Res.iconToken) tokenBtn.setImageDrawable(Res.iconToken)
val size = Dimension.convertDpToPixel(32f, ctx).roundToInt() val size = Dimension.convertDpToPixel(32f, ctx).roundToInt()
tokenBtn.layoutParams = ViewGroup.LayoutParams(size, size) tokenBtn.layoutParams = ViewGroup.LayoutParams(size, size)
tokenBtn.setPadding(10, 6, 0, 6)
tokenBtn.scaleType = ImageView.ScaleType.FIT_XY
tokenBtn.setOnClickListener { tokenBtn.setOnClickListener {
if (AccountManager.isLogin) { if (AccountManager.isLogin) {
if (isPatch) { if (isPatch) {
@ -85,23 +91,12 @@ class ModuleMain : IXposedHookLoadPackage, IXposedHookZygoteInit {
AppUtils.showToast("未登录") AppUtils.showToast("未登录")
} }
} }
root3.addView(tokenBtn)
for (i in 0 until root3.childCount) { linearLayout.addView(tokenBtn, linearLayout.indexOfChild(scanButton) + 1)
val view = root3.getChildAt(i) for (i in 0 until linearLayout.childCount) {
val view = linearLayout.getChildAt(i)
if (view.id == -1) view.id = XResources.getFakeResId("b5AaLhI6WDlkTMIrRA$i") if (view.id == -1) view.id = XResources.getFakeResId("b5AaLhI6WDlkTMIrRA$i")
} }
val set = createConstraintSet(ctx)
if (set == null) {
AlertDialog.Builder(ctx).run {
setTitle("Error")
setMessage("Create ConstraintSetWrapper fail.")
}.create().show()
return
}
set.clone(root3)
set.connect(tokenBtn.id, 2, scanBtn.id, 1, Dimension.convertDpToPixel(9f, ctx).roundToInt())
set.connect(tokenBtn.id, 3, scanBtn.id, 3)
set.applyTo(root3)
} }
}) })
} }