少年修仙传客户端基础资源
dabaoji
2023-11-13 0a23e1b83f8fda8ab9f9e32fe71c26c431faf63a
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
using System;
using System.Collections.Generic;
using System.IO;
using ILCrossBinding;
using ILRuntime.CLR.Method;
using ILRuntime.Mono.Cecil.Pdb;
using ILRuntime.Runtime.Intepreter;
using Snxxz.UI;
using UnityEngine;
 
public class ILLauncherProxy : SingletonMonobehaviour<ILLauncherProxy>
{
    FileStream dllFS, pdbFS;
 
    private ILRuntime.Runtime.Enviorment.AppDomain _appdomain;
 
    public ILRuntime.Runtime.Enviorment.AppDomain appdomain {
        get {
            return _appdomain;
        }
    }
 
    public bool started;
 
    ILTypeInstance launcherInstance;
 
    IMethod update, onDestroy;
 
    public void Init()
    {
        started = false;
        LoadILRuntime();
        //由于Unity的Profiler接口只允许在主线程使用,为了避免出异常,需要告诉ILRuntime主线程的线程ID才能正确将函数运行耗时报告给Profiler
#if UNITY_EDITOR
        _appdomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId;
#endif
        //对LitJson进行注册
        LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(_appdomain);
        RegisterCrossBindingAdaptor(appdomain);
        RegisterValueTypeBinder();
        RegisterDelegate();
#if UNITY_EDITOR
        // CLRBindings 是动态生成出来的,editor下可能不存在,所以使用反射方式调用
        var type = Type.GetType("ILRuntime.Runtime.Generated.CLRBindings");
        if (type != null)
        {
            var m = type.GetMethod("Initialize");
            m.Invoke(null, new object[] { appdomain });
        }
#else
        ILRuntime.Runtime.Generated.CLRBindings.Initialize(_appdomain);
#endif
    }
 
    void LoadILRuntime()
    {
        _appdomain = new ILRuntime.Runtime.Enviorment.AppDomain();
        var dllPath = string.Empty;
        var pdbPath = string.Empty;
        if (AssetSource.logicFromEditor)
        {
            dllPath = ResourcesPath.ResourcesOutAssetPath + "logic/Logic.dll.bytes";
            pdbPath = ResourcesPath.ResourcesOutAssetPath + "logic/Logic.pdb";
        }
        else
        {
            dllPath = AssetVersionUtility.GetAssetFilePath("logic/Logic.dll.bytes");
            pdbPath = AssetVersionUtility.GetAssetFilePath("logic/Logic.pdb");
        }
        if (!File.Exists(dllPath))
        {
            DebugEx.LogErrorFormat("找不到热更代码:{0}", dllPath);
            return;
        }
 
        dllFS = new FileStream(dllPath, FileMode.Open);
        if (VersionConfig.Get().debugVersion && File.Exists(pdbPath))
            pdbFS = new FileStream(pdbPath, FileMode.Open);
        _appdomain.LoadAssembly(dllFS, pdbFS, new PdbReaderProvider());
    }
 
    //注册跨域继承适配器
    public static void RegisterCrossBindingAdaptor(ILRuntime.Runtime.Enviorment.AppDomain domain)
    {
        domain.RegisterCrossBindingAdaptor(new CoroutineAdapter());
        domain.RegisterCrossBindingAdaptor(new DtcBasicAdapter());
        domain.RegisterCrossBindingAdaptor(new GameNetPackBasicAdapter());
        domain.RegisterCrossBindingAdaptor(new OperationBaseAdapter());
        domain.RegisterCrossBindingAdaptor(new IConfigPostProcessAdapter());
    }
 
    //注册值类型绑定
    private void RegisterValueTypeBinder()
    {
        appdomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
        appdomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());
        appdomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());
    }
 
    //注册委托
    private void RegisterDelegate()
    {
        appdomain.DelegateManager.RegisterDelegateConvertor<UGUIEventListenerContainDrag.VoidDelegate>((action) =>
        {
            return new UGUIEventListenerContainDrag.VoidDelegate((go) => ((Action<GameObject>)action)(go));
        });
        appdomain.DelegateManager.RegisterMethodDelegate<UnityEngine.GameObject, UnityEngine.EventSystems.PointerEventData>();
        appdomain.DelegateManager.RegisterDelegateConvertor<global::UGUIEventListenerContainDrag.VoidDelegateDrag>((act) =>
        {
            return new global::UGUIEventListenerContainDrag.VoidDelegateDrag((go, eventData) =>
            {
                ((System.Action<UnityEngine.GameObject, UnityEngine.EventSystems.PointerEventData>)act)(go, eventData);
            });
        });
 
        //无返回值
        appdomain.DelegateManager.RegisterMethodDelegate<int>();
        appdomain.DelegateManager.RegisterMethodDelegate<long>();
        appdomain.DelegateManager.RegisterMethodDelegate<string>();
        appdomain.DelegateManager.RegisterMethodDelegate<float>();
        appdomain.DelegateManager.RegisterMethodDelegate<double>();
        appdomain.DelegateManager.RegisterMethodDelegate<bool>();
        appdomain.DelegateManager.RegisterMethodDelegate<byte[]>();
        appdomain.DelegateManager.RegisterMethodDelegate<bool, bool>();
        appdomain.DelegateManager.RegisterMethodDelegate<bool, string>();
        appdomain.DelegateManager.RegisterMethodDelegate<int, string>();
        appdomain.DelegateManager.RegisterMethodDelegate<int, float>();
        appdomain.DelegateManager.RegisterMethodDelegate<string, int>();
        appdomain.DelegateManager.RegisterMethodDelegate<int, bool, string>();
        appdomain.DelegateManager.RegisterMethodDelegate<int, int>();
        appdomain.DelegateManager.RegisterMethodDelegate<int, bool>();
        appdomain.DelegateManager.RegisterMethodDelegate<bool, int>();
        appdomain.DelegateManager.RegisterMethodDelegate<ulong>();
        appdomain.DelegateManager.RegisterMethodDelegate<uint>();
        appdomain.DelegateManager.RegisterMethodDelegate<Snxxz.UI.Operation>();
        appdomain.DelegateManager.RegisterMethodDelegate<Snxxz.UI.Operation, int>();
        appdomain.DelegateManager.RegisterMethodDelegate<float, Vector2>();
        appdomain.DelegateManager.RegisterMethodDelegate<int, Transform>();
        appdomain.DelegateManager.RegisterMethodDelegate<Vector2>();
        appdomain.DelegateManager.RegisterMethodDelegate<Vector3>();
        appdomain.DelegateManager.RegisterMethodDelegate<Transform>();
        appdomain.DelegateManager.RegisterMethodDelegate<GameObject>();
        appdomain.DelegateManager.RegisterMethodDelegate<Component>();
        appdomain.DelegateManager.RegisterMethodDelegate<E_AttackMode>();
        appdomain.DelegateManager.RegisterMethodDelegate<PlayerDataType>();
        appdomain.DelegateManager.RegisterMethodDelegate<PlayerDataType, int>();
        appdomain.DelegateManager.RegisterMethodDelegate<List<Vector3>>();
        appdomain.DelegateManager.RegisterMethodDelegate<ChatData>();
        appdomain.DelegateManager.RegisterMethodDelegate<VoiceHttpRequest.VoiceDecodec>();
        appdomain.DelegateManager.RegisterMethodDelegate<Snxxz.UI.ComposeMatCell, NeedMatType>();
        appdomain.DelegateManager.RegisterMethodDelegate<ItemCompoundConfig, int>();
        appdomain.DelegateManager.RegisterMethodDelegate<Snxxz.UI.ComposeMatCell, int, SelectItemType>();
        appdomain.DelegateManager.RegisterMethodDelegate<GroupType, bool>();
        appdomain.DelegateManager.RegisterMethodDelegate<PackType, int>();
        appdomain.DelegateManager.RegisterMethodDelegate<PackType, string>();
        appdomain.DelegateManager.RegisterMethodDelegate<PackType, int, int>();
        appdomain.DelegateManager.RegisterMethodDelegate<SystemSwitch, bool>();
        appdomain.DelegateManager.RegisterMethodDelegate<ChatBoolType, bool>();
        appdomain.DelegateManager.RegisterMethodDelegate<E_NpcType, int, uint>();
        appdomain.DelegateManager.RegisterMethodDelegate<TeamInviteType>();
        appdomain.DelegateManager.RegisterMethodDelegate<Snxxz.UI.PlayerDetails.DetailType>();
        appdomain.DelegateManager.RegisterMethodDelegate<FunctionUnlockType>();
        appdomain.DelegateManager.RegisterMethodDelegate<TreasureCategory>();
        appdomain.DelegateManager.RegisterMethodDelegate<Window>();
        appdomain.DelegateManager.RegisterMethodDelegate<TimeMgr.SyntonyType>();
        appdomain.DelegateManager.RegisterMethodDelegate<DateTime>();
        appdomain.DelegateManager.RegisterMethodDelegate<System.Object>();
        appdomain.DelegateManager.RegisterMethodDelegate<global::ScrollerDataType, global::CellView>();
        appdomain.DelegateManager.RegisterMethodDelegate<int, LitJson.JsonData>();
        appdomain.DelegateManager.RegisterMethodDelegate<System.UInt32, System.UInt32, global::GActorPlayerBase.PlayerInfo, global::E_ActorGroup>();
        appdomain.DelegateManager.RegisterMethodDelegate<global::GameNetPackBasic>();
        appdomain.DelegateManager.RegisterMethodDelegate<System.Byte>();
        appdomain.DelegateManager.RegisterMethodDelegate<System.UInt32, UnityEngine.GameObject>();
        appdomain.DelegateManager.RegisterMethodDelegate<ILCrossBinding.GameNetPackBasicAdapter.Adapter>();
        appdomain.DelegateManager.RegisterMethodDelegate<global::GA_ILClientPlayer>();
        appdomain.DelegateManager.RegisterMethodDelegate<System.UInt32, System.UInt64, System.UInt64>();
        appdomain.DelegateManager.RegisterMethodDelegate<global::DungeonCoolDownType>();
        appdomain.DelegateManager.RegisterMethodDelegate<global::HA9A2_tagPYBillboardData>();
        appdomain.DelegateManager.RegisterMethodDelegate<System.UInt32, System.UInt32>();
        appdomain.DelegateManager.RegisterMethodDelegate<System.UInt32, System.Int32>();
        appdomain.DelegateManager.RegisterMethodDelegate<int, int, int>();
        appdomain.DelegateManager.RegisterMethodDelegate<PackType>();
        appdomain.DelegateManager.RegisterMethodDelegate<UnityEngine.Color>();
        appdomain.DelegateManager.RegisterMethodDelegate<global::HA705_tagSCQueryPlayerCacheResult>();
        appdomain.DelegateManager.RegisterMethodDelegate<int, int, int, int>();
        appdomain.DelegateManager.RegisterMethodDelegate<long, long>();
        appdomain.DelegateManager.RegisterMethodDelegate<long, long, long>();
        appdomain.DelegateManager.RegisterMethodDelegate<System.Int32, System.Single, System.Single>();
 
        //有返回值
        appdomain.DelegateManager.RegisterFunctionDelegate<UnityEngine.Color>();
        appdomain.DelegateManager.RegisterFunctionDelegate<int>();
        appdomain.DelegateManager.RegisterFunctionDelegate<bool>();
        appdomain.DelegateManager.RegisterFunctionDelegate<long>();
        appdomain.DelegateManager.RegisterFunctionDelegate<string>();
        appdomain.DelegateManager.RegisterFunctionDelegate<float>();
        appdomain.DelegateManager.RegisterFunctionDelegate<double>();
        appdomain.DelegateManager.RegisterFunctionDelegate<int, bool>();
        appdomain.DelegateManager.RegisterFunctionDelegate<System.Int32, System.Int32, System.Int32>();
        appdomain.DelegateManager.RegisterFunctionDelegate<ILRuntime.Runtime.Intepreter.ILTypeInstance, ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32>();
        appdomain.DelegateManager.RegisterFunctionDelegate<ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>();
        appdomain.DelegateManager.RegisterFunctionDelegate<global::Int3, global::Int3, System.Int32>();
        appdomain.DelegateManager.RegisterFunctionDelegate<global::StoreModel.StoreData, global::StoreModel.StoreData, System.Int32>();
 
 
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction<System.Int32, System.Single, System.Single>>((act) =>
        {
            return new UnityEngine.Events.UnityAction<System.Int32, System.Single, System.Single>((arg0, arg1, arg2) =>
            {
                ((Action<System.Int32, System.Single, System.Single>)act)(arg0, arg1, arg2);
            });
        });
 
 
        appdomain.DelegateManager.RegisterDelegateConvertor<System.Comparison<global::StoreModel.StoreData>>((act) =>
        {
            return new System.Comparison<global::StoreModel.StoreData>((x, y) =>
            {
                return ((Func<global::StoreModel.StoreData, global::StoreModel.StoreData, System.Int32>)act)(x, y);
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<System.Comparison<global::Int3>>((act) =>
        {
            return new System.Comparison<global::Int3>((x, y) =>
            {
                return ((Func<global::Int3, global::Int3, System.Int32>)act)(x, y);
            });
        });
 
 
        appdomain.DelegateManager.RegisterDelegateConvertor<System.Predicate<ILRuntime.Runtime.Intepreter.ILTypeInstance>>((act) =>
        {
            return new System.Predicate<ILRuntime.Runtime.Intepreter.ILTypeInstance>((obj) =>
            {
                return ((Func<ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>)act)(obj);
            });
        });
 
 
        //DG.Tweening
        appdomain.DelegateManager.RegisterDelegateConvertor<DG.Tweening.TweenCallback<System.Int32>>((act) =>
        {
            return new DG.Tweening.TweenCallback<System.Int32>((value) =>
            {
                ((System.Action<System.Int32>)act)(value);
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<DG.Tweening.Core.DOSetter<UnityEngine.Color>>((act) =>
        {
            return new DG.Tweening.Core.DOSetter<UnityEngine.Color>((pNewValue) =>
            {
                ((System.Action<UnityEngine.Color>)act)(pNewValue);
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<DG.Tweening.Core.DOGetter<UnityEngine.Color>>((act) =>
        {
            return new DG.Tweening.Core.DOGetter<UnityEngine.Color>(() =>
            {
                return ((Func<UnityEngine.Color>)act)();
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<DG.Tweening.TweenCallback>((act) =>
        {
            return new DG.Tweening.TweenCallback(() =>
            {
                ((System.Action)act)();
            });
        });
 
        //自定义委托转换
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction>((action) =>
        {
            return new UnityEngine.Events.UnityAction(() =>
            {
                ((System.Action)action)();
            });
        });
        appdomain.DelegateManager.RegisterDelegateConvertor<System.Threading.WaitCallback>((act) =>
        {
            return new System.Threading.WaitCallback((state) =>
             {
                 ((Action<System.Object>)act)(state);
             });
        });
        appdomain.DelegateManager.RegisterDelegateConvertor<System.Comparison<System.Int32>>((act) =>
        {
            return new System.Comparison<System.Int32>((x, y) =>
            {
                return ((Func<System.Int32, System.Int32, System.Int32>)act)(x, y);
            });
        });
        appdomain.DelegateManager.RegisterDelegateConvertor<global::ScrollerController.OnRefreshCellDelegate>((act) =>
        {
            return new global::ScrollerController.OnRefreshCellDelegate((type, cell) =>
            {
                ((Action<global::ScrollerDataType, global::CellView>)act)(type, cell);
            });
        });
        appdomain.DelegateManager.RegisterDelegateConvertor<System.Comparison<ILRuntime.Runtime.Intepreter.ILTypeInstance>>((act) =>
        {
            return new System.Comparison<ILRuntime.Runtime.Intepreter.ILTypeInstance>((x, y) =>
            {
                return ((Func<ILRuntime.Runtime.Intepreter.ILTypeInstance, ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32>)act)(x, y);
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction<bool>>((act) =>
        {
            return new UnityEngine.Events.UnityAction<bool>((arg0) =>
            {
                ((System.Action<bool>)act)(arg0);
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction<float>>((act) =>
        {
            return new UnityEngine.Events.UnityAction<float>((arg0) =>
            {
                ((System.Action<float>)act)(arg0);
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction<string>>((act) =>
        {
            return new UnityEngine.Events.UnityAction<string>((arg0) =>
            {
                ((System.Action<string>)act)(arg0);
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction<System.UInt32, System.UInt32, global::GActorPlayerBase.PlayerInfo, global::E_ActorGroup>>((act) =>
        {
            return new UnityEngine.Events.UnityAction<System.UInt32, System.UInt32, global::GActorPlayerBase.PlayerInfo, global::E_ActorGroup>((arg0, arg1, arg2, arg3) =>
            {
                ((System.Action<System.UInt32, System.UInt32, global::GActorPlayerBase.PlayerInfo, global::E_ActorGroup>)act)(arg0, arg1, arg2, arg3);
            });
        });
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction<global::GameNetPackBasic>>((act) =>
        {
            return new UnityEngine.Events.UnityAction<global::GameNetPackBasic>((arg0) =>
            {
                ((System.Action<global::GameNetPackBasic>)act)(arg0);
            });
        });
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction<System.Byte>>((act) =>
        {
            return new UnityEngine.Events.UnityAction<System.Byte>((arg0) =>
            {
                ((System.Action<System.Byte>)act)(arg0);
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction<System.UInt32, UnityEngine.GameObject>>((act) =>
        {
            return new UnityEngine.Events.UnityAction<System.UInt32, UnityEngine.GameObject>((arg0, arg1) =>
            {
                ((System.Action<System.UInt32, UnityEngine.GameObject>)act)(arg0, arg1);
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction<System.UInt64>>((act) =>
        {
            return new UnityEngine.Events.UnityAction<System.UInt64>((arg0) =>
            {
                ((System.Action<System.UInt64>)act)(arg0);
            });
        });
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction<System.Int32>>((act) =>
        {
            return new UnityEngine.Events.UnityAction<System.Int32>((arg0) =>
            {
                ((System.Action<System.Int32>)act)(arg0);
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction<global::GA_ILClientPlayer>>((act) =>
        {
            return new UnityEngine.Events.UnityAction<global::GA_ILClientPlayer>((arg0) =>
            {
                ((System.Action<global::GA_ILClientPlayer>)act)(arg0);
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction<System.UInt32, System.UInt64, System.UInt64>>((act) =>
        {
            return new UnityEngine.Events.UnityAction<System.UInt32, System.UInt64, System.UInt64>((arg0, arg1, arg2) =>
            {
                ((System.Action<System.UInt32, System.UInt64, System.UInt64>)act)(arg0, arg1, arg2);
            });
        });
        appdomain.DelegateManager.RegisterDelegateConvertor<global::BuffModel.OnObjAddBuff>((act) =>
        {
            return new global::BuffModel.OnObjAddBuff(() =>
            {
                ((System.Action)act)();
            });
        });
 
        appdomain.DelegateManager.RegisterDelegateConvertor<global::BuffModel.OnObjDelBuff>((act) =>
        {
            return new global::BuffModel.OnObjDelBuff(() =>
            {
                ((System.Action)act)();
            });
        });
 
 
 
 
    }
 
    public void LaunchStart()
    {
#if UNITY_EDITOR
        _appdomain.DebugService.StartDebugService(56000);
#endif
        launcherInstance = appdomain.Instantiate("LogicLauncher");
        var type = launcherInstance.Type;
        update = type.GetMethod("Update");
        onDestroy = type.GetMethod("OnDestroy", 0);
 
        _appdomain.Invoke("LogicLauncher", "LaunchStart", launcherInstance, null);
    }
 
    private void Update()
    {
        if (update != null)
            appdomain.Invoke(update, launcherInstance);
    }
 
    protected override void OnDestroy()
    {
        base.OnDestroy();
 
        if (onDestroy != null)
            appdomain.Invoke(onDestroy, launcherInstance);
 
#if UNITY_EDITOR
        var type = Type.GetType("ILRuntime.Runtime.Generated.CLRBindings");
        if (type != null)
        {
            var m = type.GetMethod("Shutdown");
            m.Invoke(null, new object[] { appdomain });
        }
#else
        ILRuntime.Runtime.Generated.CLRBindings.Shutdown(appdomain);
#endif
        dllFS?.Close();
        pdbFS?.Close();
    }
}