コード例 #1
0
        public void Init(Runtime.Enviorment.AppDomain appDomain, ILTypeInstance instance, string methodName)
        {
            this.appDomain = appDomain;

            this.instance = instance;

            this.methodName = methodName;
        }
コード例 #2
0
        public static bool GetJITFlags(this Mono.Cecil.CustomAttribute attribute, Enviorment.AppDomain appdomain, out int flags)
        {
            var at = appdomain.GetType(attribute.AttributeType, null, null);

            flags = ILRuntimeJITFlags.None;
            if (at == appdomain.JITAttributeType)
            {
                if (attribute.HasConstructorArguments)
                {
                    flags = (int)attribute.ConstructorArguments[0].Value;
                }
                else
                {
                    flags = ILRuntimeJITFlags.JITOnDemand;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
    /// <summary>
    /// 加载代码
    /// </summary>
    /// <param name="game"></param>
    void LoadHotFixAssembly(string game)
    {
        appdomain = new ILRuntime.Runtime.Enviorment.AppDomain();
        //appdomain.UnityMainThreadID = Thread.CurrentThread.ManagedThreadId;
        string dll_path = string.Format("{0}/game/{1}/{2}", data_path, game, "HotFix_Project.dll");

        byte[] dll          = File.ReadAllBytes(dll_path);
        string dll_pdb_path = string.Format("{0}/game/{1}/{2}", data_path, game, "HotFix_Project.pdb");

        byte[] pdb = File.ReadAllBytes(dll_pdb_path);
        using (System.IO.MemoryStream fs = new MemoryStream(dll))
        {
            using (System.IO.MemoryStream p = new MemoryStream(pdb))
            {
                appdomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider());
            }
        }
        //此处调用初始化
        InitializeILRuntime();
        //ILRuntime.Runtime.Generated.CLRBindings.Initialize(appdomain);
        Assets.CommGen.Initialize(appdomain);
        OnHotFixLoaded();
    }
コード例 #4
0
    private IEnumerator LoadFromAssetBundle(OnHotFixLoaded callBack)
    {
        ILRuntime.Runtime.Enviorment.AppDomain appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
        string dllPath = string.Format("{0}{1}", Application.streamingAssetsPath, "/hotfix_project.bundle");;

        Debug.Log("LoadDllFromStreamingAssetsPath dllPath: " + dllPath);
        AssetBundleCreateRequest abcr = AssetBundle.LoadFromFileAsync(dllPath);

        yield return(new WaitUntil(() => abcr.isDone && abcr.assetBundle != null));

        AssetBundle        ab  = abcr.assetBundle;
        AssetBundleRequest abr = ab.LoadAssetAsync <TextAsset>("hotfix_project");

        yield return(new WaitUntil(() => abr.isDone && abr.asset != null));

        Debug.Log("LoadDllFromStreamingAssetsPath abr");
        TextAsset txt = abr.asset as TextAsset;

        ab.Unload(false);
        byte[]       dll = txt.bytes;
        MemoryStream fs  = new MemoryStream(dll);

        try
        {
            appDomain.LoadAssembly(fs);
        }
        catch
        {
            Debug.LogError("加载热更DLL失败,请确保已经通过VS打开Assets/Samples/ILRuntime/1.6/Demo/HotFix_Project/HotFix_Project.sln编译过热更DLL");
        }
        InitializeILRuntime(appDomain);
        if (callBack != null)
        {
            callBack(appDomain);
        }
    }
コード例 #5
0
    void AnalyzeDll(byte[] dll, byte[] pdb = null)
    {
        if (_domain == null)
        {
            _domain = new ILRuntime.Runtime.Enviorment.AppDomain();
        }

        using (MemoryStream ds = new MemoryStream(dll))
        {
            if (pdb != null)
            {
                using (MemoryStream ps = new MemoryStream(pdb))
                {
                    _domain.LoadAssembly(ds, ps, new Mono.Cecil.Pdb.PdbReaderProvider());
                }
            }
            else
            {
                _domain.LoadAssembly(ds);
            }
        }

        RegistDelegate();
    }
コード例 #6
0
    static void GenerateCLRBindingByAnalysis()
    {
        // 先删除旧代码
        AssetDatabase.DeleteAsset(ILRDefine.StrMyBindingFolderPath);
        Directory.CreateDirectory(ILRDefine.StrMyBindingFolderPath);

        // 分析热更DLL来生成绑定代码
        ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain();
        string dllFilePath = $"{ILRDefine.StrMyAssemblyFolderPath}/{ILRDefine.StrMyHotfixDLLFileName}.bytes";

        using (FileStream fs = new FileStream(dllFilePath, FileMode.Open, FileAccess.Read))
        {
            domain.LoadAssembly(fs);

            // Crossbind Adapter is needed to generate the correct binding code
            ILRHelper.Init(domain);

            // 生成所有绑定脚本
            ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, ILRDefine.StrMyBindingFolderPath);
        }

        // 刷新目录
        AssetDatabase.Refresh();
    }
コード例 #7
0
    public static void RegisterDelegate(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
    {
        //委托的注册和转换


        RegistAction <System.IAsyncResult>(appdomain);
        RegistAction <Sprite>(appdomain);
        RegistAction <Vector2>(appdomain);
        RegistAction <Vector3>(appdomain);
        RegistAction <object>(appdomain);
        RegistAction <Google.Protobuf.IMessage>(appdomain);
        RegistAction <System.EventArgs>(appdomain);
        RegistAction <GameObject>(appdomain);
        RegistAction <Adapt_IMessage.Adaptor>(appdomain);
        RegistAction <byte[]>(appdomain);
        RegistAction <int, byte[]>(appdomain);
        RegistAction <string, string>(appdomain);
        RegistAction <UnityEngine.Networking.UnityWebRequest>(appdomain);
        RegistAction <GameObject, UnityEngine.EventSystems.PointerEventData>(appdomain);
        RegistUnityDelegate <bool>(appdomain);
        RegistUnityDelegate <int>(appdomain);
        RegistUnityDelegate <float>(appdomain);
        RegistUnityDelegate <string>(appdomain);
        RegistUnityDelegate <Color>(appdomain);
        RegistUnityDelegate <Color32>(appdomain);
        RegistUnityDelegate <Vector2>(appdomain);
        RegistUnityDelegate <Vector3>(appdomain);
        RegistUnityDelegate <UnityEngine.EventSystems.BaseEventData>(appdomain);
        Comparison <byte>(appdomain);
        Predicate <byte>(appdomain);

        //基本转换器
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction>((action) =>
        {
            return(new UnityEngine.Events.UnityAction(() => { ((System.Action)action)(); }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <DG.Tweening.TweenCallback>((action) =>
        {
            return(new DG.Tweening.TweenCallback(() => { ((System.Action)action)(); }));
        });


        //-----------------------如果想直接根据编辑器提示 然后复制代码进来 也是可以的,直接写在下面-----------------------------------//

        appdomain.DelegateManager.RegisterFunctionDelegate <global::Adapt_IMessage.Adaptor, global::Adapt_IMessage.Adaptor, System.Boolean>();

        appdomain.DelegateManager.RegisterDelegateConvertor <System.Comparison <System.Collections.Generic.KeyValuePair <global::Adapt_IMessage.Adaptor, UnityEngine.GameObject> > >((act) =>
        {
            return(new System.Comparison <System.Collections.Generic.KeyValuePair <global::Adapt_IMessage.Adaptor, UnityEngine.GameObject> >((x, y) =>
            {
                return ((Func <System.Collections.Generic.KeyValuePair <global::Adapt_IMessage.Adaptor, UnityEngine.GameObject>, System.Collections.Generic.KeyValuePair <global::Adapt_IMessage.Adaptor, UnityEngine.GameObject>, System.Int32>)act)(x, y);
            }));
        });
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Video.VideoPlayer>();
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Video.VideoPlayer.EventHandler>((act) =>
        {
            return(new UnityEngine.Video.VideoPlayer.EventHandler((source) =>
            {
                ((Action <UnityEngine.Video.VideoPlayer>)act)(source);
            }));
        });
        appdomain.DelegateManager.RegisterFunctionDelegate <System.Collections.Generic.KeyValuePair <global::Adapt_IMessage.Adaptor, UnityEngine.GameObject>, System.Collections.Generic.KeyValuePair <global::Adapt_IMessage.Adaptor, UnityEngine.GameObject>, System.Int32>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.TextAsset>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.AudioClip, System.String>();

        appdomain.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>();
        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);
            }));
        });

        appdomain.DelegateManager.RegisterDelegateConvertor <DG.Tweening.Core.DOSetter <UnityEngine.Vector2> >((act) =>
        {
            return(new DG.Tweening.Core.DOSetter <UnityEngine.Vector2>((pNewValue) =>
            {
                ((Action <UnityEngine.Vector2>)act)(pNewValue);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <DG.Tweening.Core.DOGetter <UnityEngine.Vector2> >((act) =>
        {
            return(new DG.Tweening.Core.DOGetter <UnityEngine.Vector2>(() =>
            {
                return ((Func <UnityEngine.Vector2>)act)();
            }));
        });



        appdomain.DelegateManager.RegisterDelegateConvertor <DG.Tweening.Core.DOSetter <System.Single> >((act) =>
        {
            return(new DG.Tweening.Core.DOSetter <System.Single>((pNewValue) =>
            {
                ((Action <System.Single>)act)(pNewValue);
            }));
        });
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Transform, System.Int32>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.U2D.SpriteAtlas>();
        appdomain.DelegateManager.RegisterMethodDelegate <Texture, Material>();
        appdomain.DelegateManager.RegisterMethodDelegate <Texture2D, Material, string>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Material, UnityEngine.Transform, System.Int32>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject, UnityEngine.Transform>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Object, UnityEngine.Transform>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Sprite, UnityEngine.Transform>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.U2D.SpriteAtlas, UnityEngine.Transform>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.AudioClip, UnityEngine.Transform>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.TextAsset, UnityEngine.Transform>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Transform>();

        RegistAction <string, bool>(appdomain);
        RegistAction <System.Single, System.Boolean>(appdomain);
        appdomain.DelegateManager.RegisterFunctionDelegate <global::Adapt_IMessage.Adaptor, System.Boolean>();

        appdomain.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Int32, System.Int32>();
        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.RegisterMethodDelegate <List <object> >();
        //appdomain.DelegateManager.RegisterMethodDelegate<AChannel, System.Net.Sockets.SocketError>();
        appdomain.DelegateManager.RegisterMethodDelegate <byte[], int, int>();
        //appdomain.DelegateManager.RegisterMethodDelegate<IResponse>();
        //appdomain.DelegateManager.RegisterMethodDelegate<Session, object>();
        //appdomain.DelegateManager.RegisterMethodDelegate<Session, ushort, MemoryStream>();
        //appdomain.DelegateManager.RegisterMethodDelegate<Session>();
        appdomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();

        //Action 带有一个参数 但是没有返回值的 注册
        appdomain.DelegateManager.RegisterMethodDelegate <string>();

        //Func 带有返回值 并且带有参数的
        appdomain.DelegateManager.RegisterFunctionDelegate <int, string, string>();
        appdomain.DelegateManager.RegisterFunctionDelegate <string, string>();

        //delegate 转换
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <string> >
            ((act) =>
        {
            return(new UnityAction <string>((arg0) =>
            {
                ((Action <string>)act)(arg0);
            }));
        });

        appdomain.DelegateManager.RegisterMethodDelegate <string, string, LogType>();
        //打印用的委托转换器
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Application.LogCallback>((action) =>
        {
            return(new UnityEngine.Application.LogCallback((s1, s2, t) => { ((System.Action <string, string, LogType>)action)(s1, s2, t); }));
        });

        appdomain.DelegateManager.RegisterDelegateConvertor <System.AsyncCallback>((act) =>
        {
            return(new System.AsyncCallback((ar) =>
            {
                ((Action <System.IAsyncResult>)act)(ar);
            }));
        });

        appdomain.DelegateManager.RegisterFunctionDelegate <global::Adapt_IMessage.Adaptor, global::Adapt_IMessage.Adaptor, System.Int32>();

        appdomain.DelegateManager.RegisterDelegateConvertor <System.Comparison <global::Adapt_IMessage.Adaptor> >((act) =>
        {
            return(new System.Comparison <global::Adapt_IMessage.Adaptor>((x, y) =>
            {
                return ((Func <global::Adapt_IMessage.Adaptor, global::Adapt_IMessage.Adaptor, System.Int32>)act)(x, y);
            }));
        });

        appdomain.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32>();
        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);
            }));
        });
    }
コード例 #8
0
 static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain domain)
 {
     //这里需要注册所有热更DLL中用到的跨域继承Adapter,否则无法正确抓取引用
     RegisterCrossBindingAdaptorHelper.HelperRegister(domain);
 }
コード例 #9
0
ファイル: CLRRedirections.cs プロジェクト: zfalex/XIL
        /*public unsafe static object DelegateEqulity(ILContext ctx, object instance, object[] param, IType[] genericArguments)
         * {
         *  //op_Equality,op_Inequality
         *  var esp = ctx.ESP;
         *  var mStack = ctx.ManagedStack;
         *  var domain = ctx.AppDomain;
         *
         *  var dele1 = StackObject.ToObject((esp - 1 - 1), domain, mStack);
         *  var dele2 = StackObject.ToObject((esp - 1), domain, mStack);
         *
         *  if (dele1 != null)
         *  {
         *      if (dele2 != null)
         *      {
         *          if (dele1 is IDelegateAdapter)
         *          {
         *              if (dele2 is IDelegateAdapter)
         *                  return ((IDelegateAdapter)dele1).Equals((IDelegateAdapter)dele2);
         *              else
         *                  return ((IDelegateAdapter)dele1).Equals((Delegate)dele2);
         *          }
         *          else
         *          {
         *              if (dele2 is IDelegateAdapter)
         *              {
         *                  return (Delegate)dele1 == ((IDelegateAdapter)dele2).GetConvertor(dele1.GetType());
         *              }
         *              else
         *                  return (Delegate)dele1 == (Delegate)dele2;
         *          }
         *      }
         *      else
         *          return dele1 == null;
         *  }
         *  else
         *      return dele2 == null;
         * }*/

        public unsafe static StackObject *DelegateInequlity(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj)
        {
            //Don't ask me why not esp -2, unity won't return the right result
            var       ret    = esp - 1 - 1;
            AppDomain domain = intp.AppDomain;
            var       param  = esp - 1;
            object    dele2  = StackObject.ToObject(param, domain, mStack);

            intp.Free(param);

            param = esp - 1 - 1;
            object dele1 = StackObject.ToObject(param, domain, mStack);

            intp.Free(param);

            bool res = false;

            if (dele1 != null)
            {
                if (dele2 != null)
                {
                    if (dele1 is IDelegateAdapter)
                    {
                        if (dele2 is IDelegateAdapter)
                        {
                            res = !((IDelegateAdapter)dele1).Equals((IDelegateAdapter)dele2);
                        }
                        else
                        {
                            res = !((IDelegateAdapter)dele1).Equals((Delegate)dele2);
                        }
                    }
                    else
                    {
                        if (dele2 is IDelegateAdapter)
                        {
                            res = (Delegate)dele1 != ((IDelegateAdapter)dele2).GetConvertor(dele1.GetType());
                        }
                        else
                        {
                            res = (Delegate)dele1 != (Delegate)dele2;
                        }
                    }
                }
                else
                {
                    res = dele1 != null;
                }
            }
            else
            {
                res = dele2 != null;
            }
            if (res)
            {
                return(ILIntepreter.PushOne(ret));
            }
            else
            {
                return(ILIntepreter.PushZero(ret));
            }
        }
コード例 #10
0
 public void Clear()
 {
     GameApp_obj  = null;
     appdomain    = null;
     GameApp_type = null;
 }
コード例 #11
0
ファイル: ILRAdaptor.cs プロジェクト: GodTaeja/CodePackage
 static void InitValueTypesBiding(AppDomain appDomain)
 {
     //appDomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
     //appDomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());
     //appDomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());
 }
コード例 #12
0
 static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain domain)
 {
     ILRuntimeExecutor.Register(domain);
 }
コード例 #13
0
 static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain domain)
 {
     //这里需要注册所有热更DLL中用到的跨域继承Adapter,否则无法正确抓取引用
     domain.RegisterCrossBindingAdaptor(new Adapt_IMessage());
     domain.DelegateManager.RegisterFunctionDelegate <Adapt_IMessage.Adaptor>();
 }
コード例 #14
0
 private void RegistCLRRedirection(AppDomain app)
 {
 }
コード例 #15
0
    protected override void initDelegate(AppDomain appdomain)
    {
        base.initDelegate(appdomain);

        appdomain.DelegateManager.RegisterMethodDelegate <GCharacterUseData>();
    }
コード例 #16
0
 /// <summary>
 /// 初始化配置适配器
 /// </summary>
 protected override void initConfigAdapters(AppDomain appdomain)
 {
     base.initConfigAdapters(appdomain);
 }
コード例 #17
0
 /// <summary>
 /// 初始化数据适配器
 /// </summary>
 protected override void initGenerateAdapters(AppDomain appdomain)
 {
     base.initGenerateAdapters(appdomain);
 }
コード例 #18
0
 protected override void initOtherAdapters(AppDomain appdomain)
 {
     base.initOtherAdapters(appdomain);
 }
コード例 #19
0
ファイル: CLRRedirections.cs プロジェクト: zfalex/XIL
        /*public static object GetTypeFromHandle(ILContext ctx, object instance, object[] param, IType[] genericArguments)
         * {
         *  return param[0];
         * }*/

        public unsafe static StackObject *MethodInfoInvoke(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj)
        {
            AppDomain domain = intp.AppDomain;
            //Don't ask me why not esp - 3, unity won't return the right result
            var ret   = ILIntepreter.Minus(esp, 3);
            var param = esp - 1;
            var p     = StackObject.ToObject(param, domain, mStack);

            intp.Free(param);

            param = esp - 1 - 1;
            var obj = StackObject.ToObject(param, domain, mStack);

            intp.Free(param);

            param = ILIntepreter.Minus(esp, 3);
            object instance = CheckCrossBindingAdapter(StackObject.ToObject(param, domain, mStack));

            intp.Free(param);

            if (instance is ILRuntimeMethodInfo)
            {
                if (obj != null)
                {
                    esp = ILIntepreter.PushObject(ret, mStack, obj);
                }
                else
                {
                    esp = ret;
                }
                var ilmethod = ((ILRuntimeMethodInfo)instance).ILMethod;
                if (p != null)
                {
                    object[] arr = (object[])p;
                    for (int i = 0; i < ilmethod.ParameterCount; i++)
                    {
                        esp = ILIntepreter.PushObject(esp, mStack, CheckCrossBindingAdapter(arr[i]));
                    }
                }
                bool unhandled;
                ret = intp.Execute(ilmethod, esp, out unhandled);
                ILRuntimeMethodInfo imi = (ILRuntimeMethodInfo)instance;
                var rt = imi.ILMethod.ReturnType;
                if (rt != domain.VoidType)
                {
                    var res = ret - 1;
                    if (res->ObjectType < ObjectTypes.Object)
                    {
                        return(ILIntepreter.PushObject(res, mStack, rt.TypeForCLR.CheckCLRTypes(StackObject.ToObject(res, domain, mStack)), true));
                    }
                    else
                    {
                        return(ret);
                    }
                }
                else
                {
                    return(ILIntepreter.PushNull(ret));
                }
            }
            else
            {
                return(ILIntepreter.PushObject(ret, mStack, ((MethodInfo)instance).Invoke(obj, (object[])p)));
            }
        }
コード例 #20
0
ファイル: UniRXTestOne.cs プロジェクト: huang8603543/CppLearn
 public UniRXTestOne(string name, ILRuntime.Runtime.Enviorment.AppDomain appDomain, Transform root, Button button, bool showTime) : base(name, appDomain, root, button, showTime)
 {
 }
コード例 #21
0
    void InitILRunTime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
    {
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject>();
        appdomain.DelegateManager.RegisterDelegateConvertor <UIEventListener.VoidDelegate>((act) =>
        {
            return(new UIEventListener.VoidDelegate((go) =>
            {
                ((Action <UnityEngine.GameObject>)act)(go);
            }));
        });

        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject, bool>();
        appdomain.DelegateManager.RegisterDelegateConvertor <UIEventListener.BoolDelegate>((act) =>
        {
            return(new UIEventListener.BoolDelegate((go, state) =>
            {
                ((Action <UnityEngine.GameObject, bool>)act)(go, state);
            }));
        });

        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject, float>();
        appdomain.DelegateManager.RegisterDelegateConvertor <UIEventListener.FloatDelegate>((act) =>
        {
            return(new UIEventListener.FloatDelegate((go, delta) =>
            {
                ((Action <UnityEngine.GameObject, float>)act)(go, delta);
            }));
        });

        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject, Vector2>();
        appdomain.DelegateManager.RegisterDelegateConvertor <UIEventListener.VectorDelegate>((act) =>
        {
            return(new UIEventListener.VectorDelegate((go, delta) =>
            {
                ((Action <UnityEngine.GameObject, Vector2>)act)(go, delta);
            }));
        });

        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject, UnityEngine.GameObject>();
        appdomain.DelegateManager.RegisterDelegateConvertor <UIEventListener.ObjectDelegate>((act) =>
        {
            return(new UIEventListener.ObjectDelegate((go, obj) =>
            {
                ((Action <UnityEngine.GameObject, GameObject>)act)(go, obj);
            }));
        });

        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject, KeyCode>();
        appdomain.DelegateManager.RegisterDelegateConvertor <UIEventListener.KeyCodeDelegate>((act) =>
        {
            return(new UIEventListener.KeyCodeDelegate((go, obj) =>
            {
                ((Action <UnityEngine.GameObject, KeyCode>)act)(go, obj);
            }));
        });


        appdomain.DelegateManager.RegisterDelegateConvertor <EventDelegate.Callback>((act) =>
        {
            return(new EventDelegate.Callback(() =>
            {
                ((Action)act)();
            }));
        });
    }
コード例 #22
0
 private void RegistCLRBinding(AppDomain app)
 {
     ILRuntime.Runtime.Generated.CLRBindings.Initialize(app);
 }
コード例 #23
0
    public static unsafe void InitializeILRuntime(AppDomain appdomain)
    {
        appDomain = appdomain;

#if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE)
        //由于Unity的Profiler接口只允许在主线程使用,为了避免出异常,需要告诉ILRuntime主线程的线程ID才能正确将函数运行耗时报告给Profiler
        appdomain.UnityMainThreadID = Thread.CurrentThread.ManagedThreadId;
        appdomain.DebugService.StartDebugService(56000);
#endif

        #region 这里添加ILRuntime的注册 HERE TO ADD ILRuntime Registerations

        appdomain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter());
        appdomain.RegisterCrossBindingAdaptor(new CoroutineAdapter());
        appdomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor());
        appdomain.RegisterCrossBindingAdaptor(new ExceptionAdapter());
        appdomain.RegisterCrossBindingAdaptor(new IExtensibleAdapter());

        appdomain.DelegateManager.RegisterMethodDelegate <libx.AssetRequest>();
        appdomain.DelegateManager.RegisterFunctionDelegate <System.Threading.Tasks.Task <ILRuntime.Runtime.Intepreter.ILTypeInstance> >();
        appdomain.DelegateManager.RegisterMethodDelegate <Object>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.Object>();
        appdomain.DelegateManager
        .RegisterFunctionDelegate <ILTypeInstance, Boolean>();
        appdomain.DelegateManager.RegisterMethodDelegate <List <Object> >();
        appdomain.DelegateManager
        .RegisterMethodDelegate <IDictionary <String, UnityEngine.Object> >();
        appdomain.DelegateManager.RegisterMethodDelegate <Boolean>();
        appdomain.DelegateManager.RegisterMethodDelegate <Single>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.Object, System.UnhandledExceptionEventArgs>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.Boolean>();
        appdomain.DelegateManager.RegisterMethodDelegate <Boolean, GameObject>();
        appdomain.DelegateManager.RegisterMethodDelegate <Int32, Int32>();
        appdomain.DelegateManager.RegisterMethodDelegate <String>();
        appdomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>();
        appdomain.DelegateManager.RegisterMethodDelegate <GameObject>();
        appdomain.DelegateManager.RegisterMethodDelegate <UIBehaviour, Object>();
        appdomain.DelegateManager.RegisterMethodDelegate <Transform, Object>();
        appdomain.DelegateManager.RegisterMethodDelegate <GameObject>();
        appdomain.DelegateManager.RegisterMethodDelegate <Int32>();
        appdomain.DelegateManager.RegisterMethodDelegate <GameObject, Action>();
        appdomain.DelegateManager.RegisterFunctionDelegate <Object, Boolean>();
        appdomain.DelegateManager.RegisterFunctionDelegate <Boolean>();
        appdomain.DelegateManager.RegisterFunctionDelegate <float>();
        appdomain.DelegateManager.RegisterFunctionDelegate <System.Threading.Tasks.Task>();

        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.String> >((act) =>
        {
            return(new UnityEngine.Events.UnityAction <System.String>((arg0) =>
            {
                ((Action <System.String>)act)(arg0);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.Boolean> >((act) =>
        {
            return(new UnityEngine.Events.UnityAction <System.Boolean>((arg0) =>
            {
                ((Action <System.Boolean>)act)(arg0);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <System.Threading.WaitCallback>((act) =>
        {
            return(new System.Threading.WaitCallback((state) =>
            {
                ((Action <System.Object>)act)(state);
            }));
        });

        appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction>(act =>
        {
            return(new UnityAction(() => { ((Action)act)(); }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <Single> >(act =>
        {
            return(new UnityAction <Single>(arg0 =>
            {
                ((Action <Single>)act)(arg0);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <System.UnhandledExceptionEventHandler>((act) =>
        {
            return(new System.UnhandledExceptionEventHandler((sender, e) =>
            {
                ((Action <System.Object, System.UnhandledExceptionEventArgs>)act)(sender, e);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <Predicate <Object> >(act =>
        {
            return(new Predicate <Object>(obj =>
            {
                return ((Func <Object, Boolean>)act)(obj);
            }));
        });
        appdomain.DelegateManager
        .RegisterDelegateConvertor <Predicate <ILTypeInstance> >(act =>
        {
            return(new Predicate <ILTypeInstance>(obj =>
            {
                return ((Func <ILTypeInstance, Boolean>)act)(obj);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction <Int32> >(act =>
        {
            return(new UnityAction <Int32>(arg0 =>
            {
                ((Action <Int32>)act)(arg0);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <Action <JsonData> >(action =>
        {
            return(new Action <JsonData>(a => { ((Action <JsonData>)action)(a); }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityAction>(act =>
        {
            return(new UnityAction(async() => { ((Action)act)(); }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <ThreadStart>(act =>
        {
            return(new ThreadStart(() => { ((Action)act)(); }));
        });


        //添加MonoBehaviour核心方法
        var arr = typeof(GameObject).GetMethods();
        foreach (var i in arr)
        {
            if (i.Name == "AddComponent" && i.GetGenericArguments().Length == 1)
            {
                appdomain.RegisterCLRMethodRedirection(i, AddComponent);
            }
        }

        foreach (var i in arr)
        {
            if (i.Name == "GetComponent" && i.GetGenericArguments().Length == 1)
            {
                appdomain.RegisterCLRMethodRedirection(i, GetComponent);
            }
        }
        ProtoBuf.PType.RegisterFunctionCreateInstance(PType_CreateInstance);
        ProtoBuf.PType.RegisterFunctionGetRealType(PType_GetRealType);
        JsonMapper.RegisterILRuntimeCLRRedirection(appdomain); //绑定LitJson
        CLRBindings.Initialize(appdomain);                     //CLR绑定

        #endregion
    }
コード例 #24
0
 public ILRStaticMethod(ILRuntime.Runtime.Enviorment.AppDomain appDomain, string typeName, string methodName, int paramsCount)
 {
     _appDomain = appDomain;
     _method    = appDomain.GetType(typeName).GetMethod(methodName, paramsCount);
     _params    = new object[paramsCount];
 }
コード例 #25
0
 static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain domain)
 {
     //这里需要注册所有热更DLL中用到的跨域继承Adapter,否则无法正确抓取引用
     domain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter());
     domain.RegisterCrossBindingAdaptor(new CoroutineAdapter());
 }
コード例 #26
0
 static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain domain)
 {
     //这里需要注册所有热更DLL中用到的跨域继承Adapter,否则无法正确抓取引用
     //domain.RegisterCrossBindingAdaptor(new UIBaseApadater());
 }
コード例 #27
0
ファイル: ILRAdaptor.cs プロジェクト: GodTaeja/CodePackage
    static void InitDelegate(AppDomain appdomain)
    {
        appdomain.DelegateManager.RegisterMethodDelegate <System.String, System.String, UnityEngine.LogType>();

        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Application.LogCallback>((act) =>
        {
            return(new UnityEngine.Application.LogCallback((condition, stackTrace, type) =>
            {
                ((Action <System.String, System.String, UnityEngine.LogType>)act)(condition, stackTrace, type);
            }));
        });
        appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.GameObject>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject>();



        appdomain.DelegateManager.RegisterFunctionDelegate <String>();


        appdomain.DelegateManager.RegisterMethodDelegate <string>();
        appdomain.DelegateManager.RegisterMethodDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance>();

        appdomain.DelegateManager.RegisterMethodDelegate <int>();

        appdomain.DelegateManager.RegisterMethodDelegate <System.Single>();


        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.EventSystems.PointerEventData>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.UInt32>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.String, System.Action>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.Boolean, System.Action>();
        appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.RectTransform, System.Boolean>();

        appdomain.DelegateManager.RegisterDelegateConvertor <System.Predicate <UnityEngine.RectTransform> >((act) =>
        {
            return(new System.Predicate <UnityEngine.RectTransform>((obj) =>
            {
                return ((Func <UnityEngine.RectTransform, System.Boolean>)act)(obj);
            }));
        });



        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject, UnityEngine.Vector2>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.String, System.Int32>();
        appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.Vector2>();

        appdomain.DelegateManager.RegisterFunctionDelegate <System.Single>();

        appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.Vector3>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Vector3>();

        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Color>();
        appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.Color>();


        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction>((act) =>
        {
            return(new UnityEngine.Events.UnityAction(() =>
            {
                ((Action)act)();
            }));
        });


        appdomain.DelegateManager.RegisterDelegateConvertor <System.Threading.ThreadStart>((act) =>
        {
            return(new System.Threading.ThreadStart(() =>
            {
                ((Action)act)();
            }));
        });

        appdomain.DelegateManager.RegisterMethodDelegate <System.String, System.String>();

        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.SceneManagement.Scene, UnityEngine.SceneManagement.LoadSceneMode>();

        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <UnityEngine.SceneManagement.Scene, UnityEngine.SceneManagement.LoadSceneMode> >((act) =>
        {
            return(new UnityEngine.Events.UnityAction <UnityEngine.SceneManagement.Scene, UnityEngine.SceneManagement.LoadSceneMode>((arg0, arg1) =>
            {
                ((Action <UnityEngine.SceneManagement.Scene, UnityEngine.SceneManagement.LoadSceneMode>)act)(arg0, arg1);
            }));
        });

        appdomain.DelegateManager.RegisterDelegateConvertor <System.Predicate <UnityEngine.Transform> >((act) =>
        {
            return(new System.Predicate <UnityEngine.Transform>((obj) =>
            {
                return ((Func <UnityEngine.Transform, System.Boolean>)act)(obj);
            }));
        });


        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 <System.Boolean> >((act) =>
        {
            return(new UnityEngine.Events.UnityAction <System.Boolean>((arg0) =>
            {
                ((Action <System.Boolean>)act)(arg0);
            }));
        });


        appdomain.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Boolean>();
        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);
            }));
        });

        appdomain.DelegateManager.RegisterFunctionDelegate <System.Int32>();

        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <UnityEngine.Vector2> >((act) =>
        {
            return(new UnityEngine.Events.UnityAction <UnityEngine.Vector2>((arg0) =>
            {
                ((Action <UnityEngine.Vector2>)act)(arg0);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.String> >((act) =>
        {
            return(new UnityEngine.Events.UnityAction <System.String>((arg0) =>
            {
                ((Action <System.String>)act)(arg0);
            }));
        });



        appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.Transform>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Transform>();

        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Vector2>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.Boolean>();
        appdomain.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Int32>();
        appdomain.DelegateManager.RegisterFunctionDelegate <System.UInt32, System.Boolean>();
        appdomain.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance>();
        appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.Transform, System.Boolean>();
        appdomain.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.Int32, System.String>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.UInt64>();

        appdomain.DelegateManager.RegisterMethodDelegate <System.Int32, System.Int32>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Vector2, ILRuntime.Runtime.Intepreter.ILTypeInstance>();

        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Vector2, UnityEngine.Vector2>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.EventSystems.PointerEventData>();
        appdomain.DelegateManager.RegisterFunctionDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32>();

        appdomain.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Boolean>();
        appdomain.DelegateManager.RegisterDelegateConvertor <System.Predicate <System.Int32> >((act) =>
        {
            return(new System.Predicate <System.Int32>((obj) =>
            {
                return ((Func <System.Int32, System.Boolean>)act)(obj);
            }));
        });

        appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.SkinnedMeshRenderer, System.Boolean>();
        appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.SkinnedMeshRenderer, UnityEngine.GameObject>();

        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Vector2, System.Int32>();

        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <System.Single> >((act) =>
        {
            return(new UnityEngine.Events.UnityAction <System.Single>((arg0) =>
            {
                ((Action <System.Single>)act)(arg0);
            }));
        });
        appdomain.DelegateManager.RegisterDelegateConvertor <System.Predicate <System.UInt32> >((act) =>
        {
            return(new System.Predicate <System.UInt32>((obj) =>
            {
                return ((Func <System.UInt32, System.Boolean>)act)(obj);
            }));
        });

        appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.UI.Image>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.EventSystems.BaseEventData>();
        appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <UnityEngine.EventSystems.BaseEventData> >((act) =>
        {
            return(new UnityEngine.Events.UnityAction <UnityEngine.EventSystems.BaseEventData>((arg0) =>
            {
                ((Action <UnityEngine.EventSystems.BaseEventData>)act)(arg0);
            }));
        });
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.UI.Image>();
        appdomain.DelegateManager.RegisterMethodDelegate <System.String, System.Single>();
        appdomain.DelegateManager.RegisterFunctionDelegate <System.Collections.Generic.KeyValuePair <System.UInt32, System.Single>, System.Single>();
        appdomain.DelegateManager.RegisterDelegateConvertor <System.Func <System.Collections.Generic.KeyValuePair <System.UInt32, System.Single>, System.Int32> >((act) =>
        {
            return(new System.Func <System.Collections.Generic.KeyValuePair <System.UInt32, System.Single>, System.Int32>((arg1) =>
            {
                return ((Func <System.Collections.Generic.KeyValuePair <System.UInt32, System.Single>, System.Int32>)act)(arg1);
            }));
        });


        appdomain.DelegateManager.RegisterFunctionDelegate <System.Reflection.Assembly, System.Collections.Generic.IEnumerable <System.Type> >();
        appdomain.DelegateManager.RegisterFunctionDelegate <System.Type, System.Boolean>();
        appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.Sprite, LitJson.JsonWriter>();

        appdomain.DelegateManager.RegisterDelegateConvertor <LitJson.ExporterFunc <UnityEngine.Sprite> >((act) =>
        {
            return(new LitJson.ExporterFunc <UnityEngine.Sprite>((obj, writer) =>
            {
                ((Action <UnityEngine.Sprite, LitJson.JsonWriter>)act)(obj, writer);
            }));
        });

        appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.UI.ILayoutElement, System.Single>();
        appdomain.DelegateManager.RegisterDelegateConvertor <System.Converter <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32> >((act) =>
        {
            return(new System.Converter <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32>((input) =>
            {
                return ((Func <ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32>)act)(input);
            }));
        });

        appdomain.DelegateManager.RegisterFunctionDelegate <UnityEngine.Transform, System.Single>();
        appdomain.DelegateManager.RegisterFunctionDelegate <System.Int32, System.Int32, System.Int32>();
        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.RegisterFunctionDelegate <System.Collections.Generic.KeyValuePair <System.Int32, ILRuntime.Runtime.Intepreter.ILTypeInstance>, System.Boolean>();
        appdomain.DelegateManager.RegisterFunctionDelegate <System.String, System.Boolean>();
        appdomain.DelegateManager.RegisterDelegateConvertor <System.Predicate <System.String> >((act) =>
        {
            return(new System.Predicate <System.String>((obj) =>
            {
                return ((Func <System.String, System.Boolean>)act)(obj);
            }));
        });


        appdomain.DelegateManager.RegisterMethodDelegate <System.Int32, ILRuntime.Runtime.Intepreter.ILTypeInstance>();
    }
コード例 #28
0
    void LoadHotFixAssembly()
    {
        Appdomain = new AppDomain();
        _pdb      = null;

        byte[] buffer;

        //开发模式
        #if XASSET_PRO
        if (Assets.development)
        #else
        if (!Assets.runtimeMode)
        #endif
        {
            if (File.Exists(DLLPath))//直接读DLL
            {
                buffer = DLLMgr.FileToByte(DLLPath);

                //模拟加密
                buffer = CryptoHelper.AesEncrypt(buffer, key);
            }
            else
            {
                Log.PrintError("DLL文件不存在");
                return;
            }

            //查看是否有PDB文件
            if (File.Exists(PdbPath) && usePdb && (File.GetLastWriteTime(DLLPath) - File.GetLastWriteTime(PdbPath)).Seconds < 30)
            {
                _pdb = new MemoryStream(DLLMgr.FileToByte(PdbPath));
            }
        }
        else//真机模式解密加载
        {
            var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset));
            if (dllAsset.error != null)
            {
                Log.PrintError(dllAsset.error);
                return;
            }
            var dll = (TextAsset)dllAsset.asset;
            buffer = new byte[dll.bytes.Length];
            Array.Copy(dll.bytes, buffer, dll.bytes.Length);
            dllAsset.Release();//释放掉不需要再用的dll
        }
        try
        {
            // var original = CryptoHelper.AesDecrypt(dll.bytes, Key);以前的用法,过时了

            _fs = new JStream(buffer, key);

            /*
             * 如果一定要先解密,可以这样:
             * var original = CryptoHelper.AesDecrypt(dll.bytes, Key);
             * fs = new JStream(original, Key);
             * fs.Encrypted = false;
             */

            Appdomain.LoadAssembly(_fs, _pdb, new PdbReaderProvider());
        }
        catch (Exception e)
        {
            Log.PrintError("加载热更DLL错误:\n" + e);
            if (!usePdb)
            {
                Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器");
            }
            else
            {
                Log.PrintError("PDB不可用,可能是DLL和PDB版本不一致,可能DLL是Release,如果是Release出包,请取消UsePdb选项,本次已跳过使用PDB");
                usePdb = false;
                LoadHotFixAssembly();
            }
            return;
        }

        Success = true;
        LoadILRuntime.InitializeILRuntime(Appdomain);
    }
コード例 #29
0
ファイル: Init.cs プロジェクト: wayye/JEngine
    void LoadHotFixAssembly()
    {
        appdomain = new AppDomain();

        pdb = null;

        //编译模式
        if (!Assets.runtimeMode)
        {
            if (File.Exists(dllPath))
            {
                fs = new MemoryStream(DLLMgr.FileToByte(dllPath));
            }
            else
            {
                Log.PrintError("DLL文件不存在");
                return;
            }

            //查看是否有PDB文件
            if (File.Exists(pdbPath) && UsePdb && (File.GetLastWriteTime(dllPath) - File.GetLastWriteTime(pdbPath)).Seconds < 30)
            {
                pdb = new MemoryStream(DLLMgr.FileToByte(pdbPath));
            }
        }
        else//解密加载
        {
            var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset));
            if (dllAsset.error != null)
            {
                Log.PrintError(dllAsset.error);
                return;
            }
            var dll = (TextAsset)dllAsset.asset;
            try
            {
                var original = CryptoHelper.AesDecrypt(dll.bytes, Key);
                fs = new MemoryStream(original);
            }
            catch (Exception ex)
            {
                Log.PrintError("加载热更DLL失败,可能是解密密码不正确");
                Log.PrintError("加载热更DLL错误:\n" + ex.Message);
                return;
            }
        }

        try
        {
            appdomain.LoadAssembly(fs, pdb, new PdbReaderProvider());
        }
        catch (Exception e)
        {
            if (!UsePdb)
            {
                Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器");
                Log.PrintError("加载热更DLL错误:\n" + e.Message);
                return;
            }

            Log.PrintError("PDB不可用,可能是DLL和PDB版本不一致,可能DLL是Release,如果是Release出包,请取消UsePdb选项,本次已跳过使用PDB");
            UsePdb = false;
            LoadHotFixAssembly();
        }

        InitILrt.InitializeILRuntime(appdomain);
        OnHotFixLoaded();
    }
コード例 #30
0
ファイル: CLRRedirections.cs プロジェクト: zfalex/XIL
        /*public unsafe static object InitializeArray(ILContext ctx, object instance, object[] param, IType[] genericArguments)
         * {
         *  object array = param[0];
         *  byte[] data = param[1] as byte[];
         *  if (data == null)
         *      return null;
         *  fixed (byte* p = data)
         *  {
         *      if (array is int[])
         *      {
         *          int[] arr = array as int[];
         *          int* ptr = (int*)p;
         *          for (int i = 0; i < arr.Length; i++)
         *          {
         *              arr[i] = ptr[i];
         *          }
         *      }
         *      else if (array is byte[])
         *      {
         *          byte[] arr = array as byte[];
         *          for (int i = 0; i < arr.Length; i++)
         *          {
         *              arr[i] = p[i];
         *          }
         *      }
         *      else if (array is sbyte[])
         *      {
         *          sbyte[] arr = array as sbyte[];
         *          sbyte* ptr = (sbyte*)p;
         *          for (int i = 0; i < arr.Length; i++)
         *          {
         *              arr[i] = ptr[i];
         *          }
         *      }
         *      else if (array is short[])
         *      {
         *          short[] arr = array as short[];
         *          short* ptr = (short*)p;
         *          for (int i = 0; i < arr.Length; i++)
         *          {
         *              arr[i] = ptr[i];
         *          }
         *      }
         *      else if (array is ushort[])
         *      {
         *          ushort[] arr = array as ushort[];
         *          ushort* ptr = (ushort*)p;
         *          for (int i = 0; i < arr.Length; i++)
         *          {
         *              arr[i] = ptr[i];
         *          }
         *      }
         *      else if (array is char[])
         *      {
         *          char[] arr = array as char[];
         *          char* ptr = (char*)p;
         *          for (int i = 0; i < arr.Length; i++)
         *          {
         *              arr[i] = ptr[i];
         *          }
         *      }
         *      else if (array is uint[])
         *      {
         *          uint[] arr = array as uint[];
         *          uint* ptr = (uint*)p;
         *          for (int i = 0; i < arr.Length; i++)
         *          {
         *              arr[i] = ptr[i];
         *          }
         *      }
         *      else if (array is Int64[])
         *      {
         *          long[] arr = array as long[];
         *          long* ptr = (long*)p;
         *          for (int i = 0; i < arr.Length; i++)
         *          {
         *              arr[i] = ptr[i];
         *          }
         *      }
         *      else if (array is UInt64[])
         *      {
         *          ulong[] arr = array as ulong[];
         *          ulong* ptr = (ulong*)p;
         *          for (int i = 0; i < arr.Length; i++)
         *          {
         *              arr[i] = ptr[i];
         *          }
         *      }
         *      else if (array is float[])
         *      {
         *          float[] arr = array as float[];
         *          float* ptr = (float*)p;
         *          for (int i = 0; i < arr.Length; i++)
         *          {
         *              arr[i] = ptr[i];
         *          }
         *      }
         *      else if (array is double[])
         *      {
         *          double[] arr = array as double[];
         *          double* ptr = (double*)p;
         *          for (int i = 0; i < arr.Length; i++)
         *          {
         *              arr[i] = ptr[i];
         *          }
         *      }
         *      else if (array is bool[])
         *      {
         *          bool[] arr = array as bool[];
         *          bool* ptr = (bool*)p;
         *          for (int i = 0; i < arr.Length; i++)
         *          {
         *              arr[i] = ptr[i];
         *          }
         *      }
         *      else
         *      {
         *          throw new NotImplementedException("array=" + array.GetType());
         *      }
         *  }
         *
         *  return null;
         * }*/

        public unsafe static StackObject *DelegateCombine(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj)
        {
            //Don't ask me why not esp -2, unity won't return the right result
            var       ret    = esp - 1 - 1;
            AppDomain domain = intp.AppDomain;
            var       param  = esp - 1;
            object    dele2  = StackObject.ToObject(param, domain, mStack);

            intp.Free(param);

            param = esp - 1 - 1;
            object dele1 = StackObject.ToObject(param, domain, mStack);

            intp.Free(param);

            if (dele1 != null)
            {
                if (dele2 != null)
                {
                    if (dele1 is IDelegateAdapter)
                    {
                        if (dele2 is IDelegateAdapter)
                        {
                            var dele = ((IDelegateAdapter)dele1);
                            //This means it's the original delegate which should be untouch
                            if (!dele.IsClone)
                            {
                                dele = dele.Clone();
                            }
                            if (!((IDelegateAdapter)dele2).IsClone)
                            {
                                dele2 = ((IDelegateAdapter)dele2).Clone();
                            }
                            dele.Combine((IDelegateAdapter)dele2);
                            return(ILIntepreter.PushObject(ret, mStack, dele));
                        }
                        else
                        {
                            if (!((IDelegateAdapter)dele1).IsClone)
                            {
                                dele1 = ((IDelegateAdapter)dele1).Clone();
                            }
                            ((IDelegateAdapter)dele1).Combine((Delegate)dele2);
                            return(ILIntepreter.PushObject(ret, mStack, dele1));
                        }
                    }
                    else
                    {
                        if (dele2 is IDelegateAdapter)
                        {
                            return(ILIntepreter.PushObject(ret, mStack, Delegate.Combine((Delegate)dele1, ((IDelegateAdapter)dele2).GetConvertor(dele1.GetType()))));
                        }
                        else
                        {
                            return(ILIntepreter.PushObject(ret, mStack, Delegate.Combine((Delegate)dele1, (Delegate)dele2)));
                        }
                    }
                }
                else
                {
                    return(ILIntepreter.PushObject(ret, mStack, dele1));
                }
            }
            else
            {
                return(ILIntepreter.PushObject(ret, mStack, dele2));
            }
        }