From a94b8c314221710965edbc233dcb9766d5147a16 Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Tue, 15 Feb 2022 10:37:56 +0800 Subject: [PATCH] Change FieldFinder.kt --- .../yukihookapi/hook/core/finder/FieldFinder.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt index f3a9fcea..eb325d54 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/FieldFinder.kt @@ -65,7 +65,7 @@ class FieldFinder(private val hookInstance: YukiHookCreater.MemberHookCreater, p /** * [Field] 类型 * - * - ❗必须设置 + * - 可不填写类型 - 默认模糊查找并取第一个匹配的 [Field] */ 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}]") Result(isNoSuch = true) } - type == null -> { - loggerE(msg = "Field type cannot be null in Class [$classSet] [${hookInstance.tag}]") - Result(isNoSuch = true) - } else -> try { 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 { hookInstance.onHookLogMsg(msg = "Find Field [${fieldInstance}] takes ${it}ms [${hookInstance.tag}]") }