From 71df0f558355928751d52dee2a43debc41737000 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Sat, 20 Aug 2022 05:15:51 +0800 Subject: [PATCH] Fix method return type check failed bug in YukiMemberHookCreater --- .../hook/core/YukiMemberHookCreater.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreater.kt b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreater.kt index b14af341..bc61b6a2 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreater.kt +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/core/YukiMemberHookCreater.kt @@ -621,9 +621,24 @@ class YukiMemberHookCreater(@PublishedApi internal val packageParam: PackagePara * @throws IllegalStateException 如果返回值不正确 */ private fun checkingReturnType(origin: Class<*>?, target: Class<*>?) { + /** + * 获取当前 [Class] 的 Java 基本类型 + * @return [String] + */ + fun Class<*>.objectName() = + name.replace(Unit.toString(), newValue = "void") + .replace(oldValue = "java.lang.Void", newValue = "void") + .replace(oldValue = "java.lang.Boolean", newValue = "boolean") + .replace(oldValue = "java.lang.Integer", newValue = "int") + .replace(oldValue = "java.lang.Float", newValue = "float") + .replace(oldValue = "java.lang.Double", newValue = "double") + .replace(oldValue = "java.lang.Long", newValue = "long") + .replace(oldValue = "java.lang.Short", newValue = "short") + .replace(oldValue = "java.lang.Character", newValue = "char") + .replace(oldValue = "java.lang.Byte", newValue = "byte") if (origin == null || target == null) return - val originName = origin.name.replace(Unit.toString(), newValue = "void") - val targetName = target.name.replace(Unit.toString(), newValue = "void") + val originName = origin.objectName() + val targetName = target.objectName() if (originName != targetName) error("Hooked method return type match failed, required [$originName] but got [$targetName]") }