forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAndroidReflection.cs
More file actions
88 lines (88 loc) · 3.57 KB
/
AndroidReflection.cs
File metadata and controls
88 lines (88 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
namespace UnityEngine
{
internal class AndroidReflection
{
private const string RELECTION_HELPER_CLASS_NAME = "com/unity3d/player/ReflectionHelper";
private static IntPtr s_ReflectionHelperClass = AndroidJNI.NewGlobalRef(AndroidJNISafe.FindClass("com/unity3d/player/ReflectionHelper"));
private static IntPtr s_ReflectionHelperGetConstructorID = AndroidReflection.GetStaticMethodID("com/unity3d/player/ReflectionHelper", "getConstructorID", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/reflect/Constructor;");
private static IntPtr s_ReflectionHelperGetMethodID = AndroidReflection.GetStaticMethodID("com/unity3d/player/ReflectionHelper", "getMethodID", "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/reflect/Method;");
private static IntPtr s_ReflectionHelperGetFieldID = AndroidReflection.GetStaticMethodID("com/unity3d/player/ReflectionHelper", "getFieldID", "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/reflect/Field;");
private static IntPtr s_ReflectionHelperNewProxyInstance = AndroidReflection.GetStaticMethodID("com/unity3d/player/ReflectionHelper", "newProxyInstance", "(ILjava/lang/Class;)Ljava/lang/Object;");
private static IntPtr GetStaticMethodID(string clazz, string methodName, string signature)
{
IntPtr intPtr = AndroidJNISafe.FindClass(clazz);
IntPtr staticMethodID;
try
{
staticMethodID = AndroidJNISafe.GetStaticMethodID(intPtr, methodName, signature);
}
finally
{
AndroidJNISafe.DeleteLocalRef(intPtr);
}
return staticMethodID;
}
public static IntPtr GetConstructorMember(IntPtr jclass, string signature)
{
jvalue[] array = new jvalue[2];
IntPtr result;
try
{
array[0].l = jclass;
array[1].l = AndroidJNISafe.NewStringUTF(signature);
result = AndroidJNISafe.CallStaticObjectMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperGetConstructorID, array);
}
finally
{
AndroidJNISafe.DeleteLocalRef(array[1].l);
}
return result;
}
public static IntPtr GetMethodMember(IntPtr jclass, string methodName, string signature, bool isStatic)
{
jvalue[] array = new jvalue[4];
IntPtr result;
try
{
array[0].l = jclass;
array[1].l = AndroidJNISafe.NewStringUTF(methodName);
array[2].l = AndroidJNISafe.NewStringUTF(signature);
array[3].z = isStatic;
result = AndroidJNISafe.CallStaticObjectMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperGetMethodID, array);
}
finally
{
AndroidJNISafe.DeleteLocalRef(array[1].l);
AndroidJNISafe.DeleteLocalRef(array[2].l);
}
return result;
}
public static IntPtr GetFieldMember(IntPtr jclass, string fieldName, string signature, bool isStatic)
{
jvalue[] array = new jvalue[4];
IntPtr result;
try
{
array[0].l = jclass;
array[1].l = AndroidJNISafe.NewStringUTF(fieldName);
array[2].l = AndroidJNISafe.NewStringUTF(signature);
array[3].z = isStatic;
result = AndroidJNISafe.CallStaticObjectMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperGetFieldID, array);
}
finally
{
AndroidJNISafe.DeleteLocalRef(array[1].l);
AndroidJNISafe.DeleteLocalRef(array[2].l);
}
return result;
}
public static IntPtr NewProxyInstance(int delegateHandle, IntPtr interfaze)
{
jvalue[] array = new jvalue[2];
array[0].i = delegateHandle;
array[1].l = interfaze;
return AndroidJNISafe.CallStaticObjectMethod(AndroidReflection.s_ReflectionHelperClass, AndroidReflection.s_ReflectionHelperNewProxyInstance, array);
}
}
}