Change FieldFinder.kt

This commit is contained in:
2022-02-15 10:37:56 +08:00
parent 69b7155ff4
commit a94b8c3142

View File

@@ -65,7 +65,7 @@ class FieldFinder(private val hookInstance: YukiHookCreater.MemberHookCreater, p
/** /**
* [Field] 类型 * [Field] 类型
* *
* - ❗必须设置 * - 可不填写类型 - 默认模糊查找并取第一个匹配的 [Field]
*/ */
var type: Class<*>? = null var type: Class<*>? = null
@@ -82,13 +82,12 @@ class FieldFinder(private val hookInstance: YukiHookCreater.MemberHookCreater, p
loggerE(msg = "Field name cannot be empty in Class [$classSet] [${hookInstance.tag}]") loggerE(msg = "Field name cannot be empty in Class [$classSet] [${hookInstance.tag}]")
Result(isNoSuch = true) Result(isNoSuch = true)
} }
type == null -> {
loggerE(msg = "Field type cannot be null in Class [$classSet] [${hookInstance.tag}]")
Result(isNoSuch = true)
}
else -> try { else -> try {
runBlocking { runBlocking {
fieldInstance = ReflectionUtils.findFieldIfExists(classSet, type?.name, name) fieldInstance =
if (type != null)
ReflectionUtils.findFieldIfExists(classSet, type?.name, name)
else classSet?.getDeclaredField(name)?.apply { isAccessible = true }
}.result { }.result {
hookInstance.onHookLogMsg(msg = "Find Field [${fieldInstance}] takes ${it}ms [${hookInstance.tag}]") hookInstance.onHookLogMsg(msg = "Find Field [${fieldInstance}] takes ${it}ms [${hookInstance.tag}]")
} }