Added instanceOrNull functions in HookParam

This commit is contained in:
2023-01-31 21:30:27 +08:00
parent cf2473b92c
commit 5bd1b3b79e
3 changed files with 98 additions and 4 deletions

View File

@@ -87,16 +87,24 @@ class HookParam internal constructor(
*/
val args get() = param?.args ?: error("Current hooked Member args is null")
//val instanceOrNull?
/**
* 获取当前 Hook 实例的对象
*
* - ❗如果你当前 Hook 的对象是一个静态 - 那么它将不存在实例的对象
*
* - 如果你不确定当前实例的对象是否为 null - 你可以使用 [instanceOrNull]
* @return [Any]
* @throws IllegalStateException 如果对象为空
*/
val instance get() = param?.instance ?: error("HookParam instance got null! Is this a static member?")
/**
* 获取当前 Hook 实例的对象
*
* - ❗如果你当前 Hook 的对象是一个静态 - 那么它将不存在实例的对象
* @return [Any]
* @throws IllegalStateException 如果对象为空
* @return [Any] or null
*/
val instance get() = param?.instance ?: error("HookParam instance got null! Is this a static member?")
val instanceOrNull get() = param?.instance
/**
* 获取当前 Hook 实例的类对象
@@ -186,6 +194,12 @@ class HookParam internal constructor(
*/
inline fun <reified T> instance() = instance as? T? ?: error("HookParam instance cannot cast to ${classOf<T>().name}")
/**
* 获取当前 Hook 实例的对象 [T]
* @return [T] or null
*/
inline fun <reified T> instanceOrNull() = instanceOrNull as? T?
/**
* 获取当前 Hook 对象的 [method] or [constructor] 的参数数组下标实例化类
* @return [ArgsIndexCondition]