From 4ccd4069fa404a6bc04551b804609ae5977a9075 Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Wed, 2 Mar 2022 02:34:04 +0800 Subject: [PATCH] add `ignoredError` function --- .../yukihookapi/hook/core/finder/ConstructorFinder.kt | 11 +++++++++++ .../yukihookapi/hook/core/finder/FieldFinder.kt | 11 +++++++++++ .../yukihookapi/hook/core/finder/MethodFinder.kt | 11 +++++++++++ .../yukihookapi/hook/core/finder/base/BaseFinder.kt | 5 ++++- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/ConstructorFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/ConstructorFinder.kt index 43cae472..3be56b9e 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/ConstructorFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/ConstructorFinder.kt @@ -262,6 +262,17 @@ class ConstructorFinder( return this } + /** + * 忽略任何错误发出的警告 + * + * - 若 [isNotIgnoredHookingFailure] 为 false 则自动忽略 + * @return [Result] 可继续向下监听 + */ + fun ignoredError(): Result { + isShutErrorPrinting = true + return this + } + /** * [Constructor] 实例处理类 * 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 1a9d4f87..2a49bbfe 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 @@ -152,6 +152,17 @@ class FieldFinder( return this } + /** + * 忽略任何错误发出的警告 + * + * - 若 [isNotIgnoredHookingFailure] 为 false 则自动忽略 + * @return [Result] 可继续向下监听 + */ + fun ignoredError(): Result { + isShutErrorPrinting = true + return this + } + /** * [Field] 实例变量处理类 * @param instance 当前 [Field] 所在类的实例对象 diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/MethodFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/MethodFinder.kt index 80cbdbae..1a87d459 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/MethodFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/MethodFinder.kt @@ -290,6 +290,17 @@ class MethodFinder( return this } + /** + * 忽略任何错误发出的警告 + * + * - 若 [isNotIgnoredHookingFailure] 为 false 则自动忽略 + * @return [Result] 可继续向下监听 + */ + fun ignoredError(): Result { + isShutErrorPrinting = true + return this + } + /** * [Method] 实例处理类 * @param instance 当前 [Method] 所在类的实例对象 diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/base/BaseFinder.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/base/BaseFinder.kt index 0d1acef7..9840215e 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/base/BaseFinder.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/finder/base/BaseFinder.kt @@ -47,6 +47,9 @@ abstract class BaseFinder( open val classSet: Class<*>? = null ) { + /** 是否开启忽略错误警告功能 */ + internal var isShutErrorPrinting = false + /** 是否使用了重查找功能 */ internal var isUsingRemedyPlan = false @@ -76,7 +79,7 @@ abstract class BaseFinder( if (isAlwaysPrint) print() else Thread { SystemClock.sleep(10) - if (isNotIgnoredHookingFailure && !isUsingRemedyPlan) print() + if (isNotIgnoredHookingFailure && !isUsingRemedyPlan && !isShutErrorPrinting) print() }.start() }