forked from Tencent/xLua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExampleConfig.cs
307 lines (294 loc) · 14.1 KB
/
ExampleConfig.cs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
* Tencent is pleased to support the open source community by making xLua available.
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
using System.Collections.Generic;
using System;
using XLua;
using System.Reflection;
using System.Linq;
//配置的详细介绍请看Doc下《XLua的配置.doc》
public static class ExampleConfig
{
/***************如果你全lua编程,可以参考这份自动化配置***************/
//--------------begin 纯lua编程配置参考----------------------------
//static List<string> exclude = new List<string> {
// "HideInInspector", "ExecuteInEditMode",
// "AddComponentMenu", "ContextMenu",
// "RequireComponent", "DisallowMultipleComponent",
// "SerializeField", "AssemblyIsEditorAssembly",
// "Attribute", "Types",
// "UnitySurrogateSelector", "TrackedReference",
// "TypeInferenceRules", "FFTWindow",
// "RPC", "Network", "MasterServer",
// "BitStream", "HostData",
// "ConnectionTesterStatus", "GUI", "EventType",
// "EventModifiers", "FontStyle", "TextAlignment",
// "TextEditor", "TextEditorDblClickSnapping",
// "TextGenerator", "TextClipping", "Gizmos",
// "ADBannerView", "ADInterstitialAd",
// "Android", "Tizen", "jvalue",
// "iPhone", "iOS", "Windows", "CalendarIdentifier",
// "CalendarUnit", "CalendarUnit",
// "ClusterInput", "FullScreenMovieControlMode",
// "FullScreenMovieScalingMode", "Handheld",
// "LocalNotification", "NotificationServices",
// "RemoteNotificationType", "RemoteNotification",
// "SamsungTV", "TextureCompressionQuality",
// "TouchScreenKeyboardType", "TouchScreenKeyboard",
// "MovieTexture", "UnityEngineInternal",
// "Terrain", "Tree", "SplatPrototype",
// "DetailPrototype", "DetailRenderMode",
// "MeshSubsetCombineUtility", "AOT", "Social", "Enumerator",
// "SendMouseEvents", "Cursor", "Flash", "ActionScript",
// "OnRequestRebuild", "Ping",
// "ShaderVariantCollection", "SimpleJson.Reflection",
// "CoroutineTween", "GraphicRebuildTracker",
// "Advertisements", "UnityEditor", "WSA",
// "EventProvider", "Apple",
// "ClusterInput", "Motion",
// "UnityEngine.UI.ReflectionMethodsCache", "NativeLeakDetection",
// "NativeLeakDetectionMode", "WWWAudioExtensions", "UnityEngine.Experimental",
//};
//static bool isExcluded(Type type)
//{
// var fullName = type.FullName;
// for (int i = 0; i < exclude.Count; i++)
// {
// if (fullName.Contains(exclude[i]))
// {
// return true;
// }
// }
// return false;
//}
//[LuaCallCSharp]
//public static IEnumerable<Type> LuaCallCSharp
//{
// get
// {
// List<string> namespaces = new List<string>() // 在这里添加名字空间
// {
// "UnityEngine",
// "UnityEngine.UI"
// };
// var unityTypes = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
// where !(assembly.ManifestModule is System.Reflection.Emit.ModuleBuilder)
// from type in assembly.GetExportedTypes()
// where type.Namespace != null && namespaces.Contains(type.Namespace) && !isExcluded(type)
// && type.BaseType != typeof(MulticastDelegate) && !type.IsInterface && !type.IsEnum
// select type);
// string[] customAssemblys = new string[] {
// "Assembly-CSharp",
// };
// var customTypes = (from assembly in customAssemblys.Select(s => Assembly.Load(s))
// from type in assembly.GetExportedTypes()
// where type.Namespace == null || !type.Namespace.StartsWith("XLua")
// && type.BaseType != typeof(MulticastDelegate) && !type.IsInterface && !type.IsEnum
// select type);
// return unityTypes.Concat(customTypes);
// }
//}
////自动把LuaCallCSharp涉及到的delegate加到CSharpCallLua列表,后续可以直接用lua函数做callback
//[CSharpCallLua]
//public static List<Type> CSharpCallLua
//{
// get
// {
// var lua_call_csharp = LuaCallCSharp;
// var delegate_types = new List<Type>();
// var flag = BindingFlags.Public | BindingFlags.Instance
// | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly;
// foreach (var field in (from type in lua_call_csharp select type).SelectMany(type => type.GetFields(flag)))
// {
// if (typeof(Delegate).IsAssignableFrom(field.FieldType))
// {
// delegate_types.Add(field.FieldType);
// }
// }
// foreach (var method in (from type in lua_call_csharp select type).SelectMany(type => type.GetMethods(flag)))
// {
// if (typeof(Delegate).IsAssignableFrom(method.ReturnType))
// {
// delegate_types.Add(method.ReturnType);
// }
// foreach (var param in method.GetParameters())
// {
// var paramType = param.ParameterType.IsByRef ? param.ParameterType.GetElementType() : param.ParameterType;
// if (typeof(Delegate).IsAssignableFrom(paramType))
// {
// delegate_types.Add(paramType);
// }
// }
// }
// return delegate_types.Where(t => t.BaseType == typeof(MulticastDelegate) && !hasGenericParameter(t) && !delegateHasEditorRef(t)).Distinct().ToList();
// }
//}
//--------------end 纯lua编程配置参考----------------------------
/***************热补丁可以参考这份自动化配置***************/
//[Hotfix]
//static IEnumerable<Type> HotfixInject
//{
// get
// {
// return (from type in Assembly.Load("Assembly-CSharp").GetTypes()
// where type.Namespace == null || !type.Namespace.StartsWith("XLua")
// select type);
// }
//}
//--------------begin 热补丁自动化配置-------------------------
//static bool hasGenericParameter(Type type)
//{
// if (type.IsGenericTypeDefinition) return true;
// if (type.IsGenericParameter) return true;
// if (type.IsByRef || type.IsArray)
// {
// return hasGenericParameter(type.GetElementType());
// }
// if (type.IsGenericType)
// {
// foreach (var typeArg in type.GetGenericArguments())
// {
// if (hasGenericParameter(typeArg))
// {
// return true;
// }
// }
// }
// return false;
//}
//static bool typeHasEditorRef(Type type)
//{
// if (type.Namespace != null && (type.Namespace == "UnityEditor" || type.Namespace.StartsWith("UnityEditor.")))
// {
// return true;
// }
// if (type.IsNested)
// {
// return typeHasEditorRef(type.DeclaringType);
// }
// if (type.IsByRef || type.IsArray)
// {
// return typeHasEditorRef(type.GetElementType());
// }
// if (type.IsGenericType)
// {
// foreach (var typeArg in type.GetGenericArguments())
// {
// if (typeHasEditorRef(typeArg))
// {
// return true;
// }
// }
// }
// return false;
//}
//static bool delegateHasEditorRef(Type delegateType)
//{
// if (typeHasEditorRef(delegateType)) return true;
// var method = delegateType.GetMethod("Invoke");
// if (method == null)
// {
// return false;
// }
// if (typeHasEditorRef(method.ReturnType)) return true;
// return method.GetParameters().Any(pinfo => typeHasEditorRef(pinfo.ParameterType));
//}
// 配置某Assembly下所有涉及到的delegate到CSharpCallLua下,Hotfix下拿不准那些delegate需要适配到lua function可以这么配置
//[CSharpCallLua]
//static IEnumerable<Type> AllDelegate
//{
// get
// {
// BindingFlags flag = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
// List<Type> allTypes = new List<Type>();
// var allAssemblys = new Assembly[]
// {
// Assembly.Load("Assembly-CSharp")
// };
// foreach (var t in (from assembly in allAssemblys from type in assembly.GetTypes() select type))
// {
// var p = t;
// while (p != null)
// {
// allTypes.Add(p);
// p = p.BaseType;
// }
// }
// allTypes = allTypes.Distinct().ToList();
// var allMethods = from type in allTypes
// from method in type.GetMethods(flag)
// select method;
// var returnTypes = from method in allMethods
// select method.ReturnType;
// var paramTypes = allMethods.SelectMany(m => m.GetParameters()).Select(pinfo => pinfo.ParameterType.IsByRef ? pinfo.ParameterType.GetElementType() : pinfo.ParameterType);
// var fieldTypes = from type in allTypes
// from field in type.GetFields(flag)
// select field.FieldType;
// return (returnTypes.Concat(paramTypes).Concat(fieldTypes)).Where(t => t.BaseType == typeof(MulticastDelegate) && !hasGenericParameter(t) && !delegateHasEditorRef(t)).Distinct();
// }
//}
//--------------end 热补丁自动化配置-------------------------
//黑名单
[BlackList]
public static List<List<string>> BlackList = new List<List<string>>() {
new List<string>(){"System.Xml.XmlNodeList", "ItemOf"},
new List<string>(){"UnityEngine.WWW", "movie"},
#if UNITY_WEBGL
new List<string>(){"UnityEngine.WWW", "threadPriority"},
#endif
new List<string>(){"UnityEngine.Texture2D", "alphaIsTransparency"},
new List<string>(){"UnityEngine.Security", "GetChainOfTrustValue"},
new List<string>(){"UnityEngine.CanvasRenderer", "onRequestRebuild"},
new List<string>(){"UnityEngine.Light", "areaSize"},
new List<string>(){"UnityEngine.Light", "lightmapBakeType"},
new List<string>(){"UnityEngine.WWW", "MovieTexture"},
new List<string>(){"UnityEngine.WWW", "GetMovieTexture"},
new List<string>(){"UnityEngine.AnimatorOverrideController", "PerformOverrideClipListCleanup"},
#if !UNITY_WEBPLAYER
new List<string>(){"UnityEngine.Application", "ExternalEval"},
#endif
new List<string>(){"UnityEngine.GameObject", "networkView"}, //4.6.2 not support
new List<string>(){"UnityEngine.Component", "networkView"}, //4.6.2 not support
new List<string>(){"System.IO.FileInfo", "GetAccessControl", "System.Security.AccessControl.AccessControlSections"},
new List<string>(){"System.IO.FileInfo", "SetAccessControl", "System.Security.AccessControl.FileSecurity"},
new List<string>(){"System.IO.DirectoryInfo", "GetAccessControl", "System.Security.AccessControl.AccessControlSections"},
new List<string>(){"System.IO.DirectoryInfo", "SetAccessControl", "System.Security.AccessControl.DirectorySecurity"},
new List<string>(){"System.IO.DirectoryInfo", "CreateSubdirectory", "System.String", "System.Security.AccessControl.DirectorySecurity"},
new List<string>(){"System.IO.DirectoryInfo", "Create", "System.Security.AccessControl.DirectorySecurity"},
new List<string>(){"UnityEngine.MonoBehaviour", "runInEditMode"},
};
#if UNITY_2018_1_OR_NEWER
[BlackList]
public static Func<MemberInfo, bool> MethodFilter = (memberInfo) =>
{
if (memberInfo.DeclaringType.IsGenericType && memberInfo.DeclaringType.GetGenericTypeDefinition() == typeof(Dictionary<,>))
{
if (memberInfo.MemberType == MemberTypes.Constructor)
{
ConstructorInfo constructorInfo = memberInfo as ConstructorInfo;
var parameterInfos = constructorInfo.GetParameters();
if (parameterInfos.Length > 0)
{
if (typeof(System.Collections.IEnumerable).IsAssignableFrom(parameterInfos[0].ParameterType))
{
return true;
}
}
}
else if (memberInfo.MemberType == MemberTypes.Method)
{
var methodInfo = memberInfo as MethodInfo;
if (methodInfo.Name == "TryAdd" || methodInfo.Name == "Remove" && methodInfo.GetParameters().Length == 2)
{
return true;
}
}
}
return false;
};
#endif
}