mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
Add new function
This commit is contained in:
@@ -206,8 +206,6 @@ class FieldFinder(
|
||||
|
||||
/**
|
||||
* 得到变量的 [Any] 实例
|
||||
*
|
||||
* - ❗请确认目标变量的类型 - 发生错误会返回默认值
|
||||
* @param instance 变量所在的实例对象 - 如果是静态可不填 - 默认 null
|
||||
* @return [Any] or null
|
||||
*/
|
||||
|
@@ -97,6 +97,20 @@ class HookParam(private val wrapper: HookParamWrapper) {
|
||||
wrapper.result = value
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前 Hook 对象 [method] or [constructor] 的参数对象数组第一位 [T]
|
||||
* @return [T] or null
|
||||
* @throws IllegalStateException 如果数组为空
|
||||
*/
|
||||
inline fun <reified T> firstArgs() = firstArgs as? T?
|
||||
|
||||
/**
|
||||
* 获取当前 Hook 对象 [method] or [constructor] 的参数对象数组最后一位 [T]
|
||||
* @return [T] or null
|
||||
* @throws IllegalStateException 如果数组为空
|
||||
*/
|
||||
inline fun <reified T> lastArgs() = lastArgs as? T?
|
||||
|
||||
/**
|
||||
* 获取当前 Hook 实例的对象 [T]
|
||||
* @return [T]
|
||||
@@ -153,6 +167,68 @@ class HookParam(private val wrapper: HookParamWrapper) {
|
||||
*/
|
||||
inner class ArgsModifyer(private val index: Int) {
|
||||
|
||||
/**
|
||||
* 得到方法参数的实例对象 [T]
|
||||
* @return [T] or null
|
||||
*/
|
||||
fun <T> of() = runCatching { args[index] as? T? }.getOrNull()
|
||||
|
||||
/**
|
||||
* 得到方法参数的实例对象 [Int]
|
||||
*
|
||||
* - ❗请确认目标参数的类型 - 发生错误会返回默认值
|
||||
* @return [Int] 取不到返回 0
|
||||
*/
|
||||
fun ofInt() = of() ?: 0
|
||||
|
||||
/**
|
||||
* 得到方法参数的实例对象 [Long]
|
||||
*
|
||||
* - ❗请确认目标参数的类型 - 发生错误会返回默认值
|
||||
* @return [Long] 取不到返回 0L
|
||||
*/
|
||||
fun ofLong() = of() ?: 0L
|
||||
|
||||
/**
|
||||
* 得到方法参数的实例对象 [Short]
|
||||
*
|
||||
* - ❗请确认目标参数的类型 - 发生错误会返回默认值
|
||||
* @return [Short] 取不到返回 0
|
||||
*/
|
||||
fun ofShort() = of<Short?>() ?: 0
|
||||
|
||||
/**
|
||||
* 得到方法参数的实例对象 [Double]
|
||||
*
|
||||
* - ❗请确认目标参数的类型 - 发生错误会返回默认值
|
||||
* @return [Double] 取不到返回 0.0
|
||||
*/
|
||||
fun ofDouble() = of() ?: 0.0
|
||||
|
||||
/**
|
||||
* 得到方法参数的实例对象 [Float]
|
||||
*
|
||||
* - ❗请确认目标参数的类型 - 发生错误会返回默认值
|
||||
* @return [Float] 取不到返回 0f
|
||||
*/
|
||||
fun ofFloat() = of() ?: 0f
|
||||
|
||||
/**
|
||||
* 得到方法参数的实例对象 [String]
|
||||
*
|
||||
* - ❗请确认目标参数的类型 - 发生错误会返回默认值
|
||||
* @return [String] 取不到返回 ""
|
||||
*/
|
||||
fun ofString() = of() ?: ""
|
||||
|
||||
/**
|
||||
* 得到方法参数的实例对象 [Boolean]
|
||||
*
|
||||
* - ❗请确认目标参数的类型 - 发生错误会返回默认值
|
||||
* @return [Boolean] 取不到返回 false
|
||||
*/
|
||||
fun ofBoolean() = of() ?: false
|
||||
|
||||
/**
|
||||
* 设置方法参数的实例对象
|
||||
* @param any 实例对象
|
||||
|
Reference in New Issue
Block a user