Ejemplo n.º 1
0
 private void Update()
 {
     game.world.OnGUI();
     if (_run == -1)
     {//游戏结束
         Debug.LogWarning("==========游戏结束清理资源开始=============");
         _run = 0;
         StopAllCoroutines();//结束所有携程
         method        = null;
         method_update = null;
         method_out    = null;
         appdomain     = null;
         //AssetbundleLoader.Clear();//释放资源
         EndNetWork();
         Debug.LogWarning("==========游戏结束清理资源结束=============");
     }
     else if (_run > 0)
     {
         if (network != null)
         {
             network.Update();
         }
         appdomain.Invoke(method_update, null, null);
     }
 }
Ejemplo n.º 2
0
    public object Invoke()
    {
        if (_params.Length != 0)
        {
            throw new ArgumentOutOfRangeException();
        }

        return(_appDomain.Invoke(_method, null, null));
    }
Ejemplo n.º 3
0
    void ILRuntimeTest()
    {
        Debug.Log(appdomain.Invoke("Hotfix.Test", "GetMsg", null, null));
        object[] param = new object[1];
        param[0] = 666;
        Debug.Log(appdomain.Invoke("Hotfix.Test", "GetMsg1", null, param));
        var testInst = appdomain.Instantiate <IUIInterface>("Hotfix.Test");

        Debug.Log(appdomain.Invoke("Hotfix.Test", "GetMsg2", testInst, null));
        testInst.Show();
        Debug.Log(testInst.GetStr());
        // var testUIInst = appdomain.Instantiate<IUIInterface>("Hotfix.TestUI");
        // testUIInst.Show();
        // Types();
    }
Ejemplo n.º 4
0
    //methods

    private void onLogicDllLoaded(byte[] dllBytes, byte[] pdbBytes, bool isForEditor)
    {
        if (_app == null)
        {
            _app = new ILRuntime.Runtime.Enviorment.AppDomain();
        }

        //发布
        if (pdbBytes == null)
        {
            _app.LoadAssembly(new MemoryStream(dllBytes));
        }
        //调试
        else
        {
            _app.LoadAssembly(new MemoryStream(dllBytes), new MemoryStream(pdbBytes), new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());
        }

        //初始化
        GameC.ILRuntime.initILRuntime(_app);

        string mName = isForEditor ? "mainForEditor" : "main";

        //调用
        _app.Invoke("HGameApp", mName, null, null);

        if (!isForEditor)
        {
            _stepTool.completeStep(LoadGame);
        }
    }
Ejemplo n.º 5
0
    void OnILRuntimeInitialized()
    {
#if UNITY_EDITOR
        // 启动调试服务
        appdomain.DebugService.StartDebugService(56000);
#endif

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

        appdomain.Invoke("Hotfix.Game", "Initialize", null, null);
    }
Ejemplo n.º 6
0
    private void OnILRuntimeInitialized()
    {
        gameManager = appDomain.Instantiate("TestHotFix.GameManager", null);

        appDomain.Invoke("TestHotFix.GameManager", "Init", gameManager, null);

        //appDomain.Invoke("TestHotFix.Class1", "Test1", null, null);
    }
Ejemplo n.º 7
0
 public object Invoke()
 {
     if (appdomain != null)
     {
         return(appdomain.Invoke(method, null, Parameters));
     }
     return(null);
 }
Ejemplo n.º 8
0
 private void GameApp_obj_Invoke(string name, params object[] param)
 {
     if (null != GameApp_obj)
     {
         int paramCount = param == null ? 0 : param.Length;
         var m          = GameApp_type.GetMethod(name, paramCount);
         appdomain.Invoke(m, GameApp_obj, param);
     }
 }
Ejemplo n.º 9
0
 public void Invoke()
 {
     if (appDomain != null)
     {
         if (method == null)
         {
             method = instance.Type.GetMethod(methodName, 0);
         }
         appDomain.Invoke(method, instance, null);
     }
 }
Ejemplo n.º 10
0
    void RunAsIL()
    {
        UnityEngine.Object o  = mResMgr.LoadRes("Logic/Entrance");
        TextAsset          ta = o as TextAsset;

        ILRuntime.Runtime.Enviorment.AppDomain appdomain = new ILRuntime.Runtime.Enviorment.AppDomain();
        using (System.IO.MemoryStream fs = new System.IO.MemoryStream(ta.bytes))
        {
            appdomain.LoadAssembly(fs, null, new Mono.Cecil.Pdb.PdbReaderProvider());
        }
        InitILRuntime(appdomain);
        appdomain.Invoke("Entrance", "Main", null);
    }
Ejemplo n.º 11
0
    /// <summary>
    /// 自定义调用函数  函数签名长度为唯一标准(做了缓存)
    /// </summary>
    /// <param name="methodName"></param>
    /// <param name="prs"></param>
    public object CallMethod(string methodName, params object[] prs)
    {
        if (_mTypeObj == null || _wantType == null || string.IsNullOrEmpty(methodName))
        {
            return(null);
        }
        int paramsCount = 0;

        if (prs == null)
        {
            prs = new object[] { }
        }
        ;
        else
        {
            paramsCount = prs.Length;
        }
        if (!_methodsDic.ContainsKey(methodName))
        {
            _methodsDic[methodName] = new Dictionary <int, IMethod>();
        }
        IMethod method02 = null;

        if (_methodsDic[methodName].ContainsKey(paramsCount))
        {
            method02 = _methodsDic[methodName][paramsCount];
        }
        else
        {
            method02 = _wantType.GetMethod(methodName, paramsCount);
            _methodsDic[methodName][paramsCount] = method02;
        }
        if (method02 != null)
        {
            return(appDomain.Invoke(method02, _mTypeObj, prs));
        }
        return(null);
    }
Ejemplo n.º 12
0
 void OnFinishDownload()
 {
     if (!UnityDebug)
     {
         TextAsset ta = s_Patcher.GetAsset("game") as TextAsset;
         s_Patcher.Clear();
         //if (Application.platform == RuntimePlatform.Android  )
         //{
         //    AppDomain.CurrentDomain.UNL
         //   System.Reflection.Assembly assembly =  AppDomain.CurrentDomain.Load(ta.bytes);
         //    Type type = assembly.GetType("Game");
         //    if (null != ta)
         //    {
         //        System.Reflection.MethodInfo m = type.GetMethod("StartGame");
         //        m.Invoke(null, null);
         //    }
         //}
         //else
         //{
         ILRuntime.Runtime.Enviorment.AppDomain appdomain = new ILRuntime.Runtime.Enviorment.AppDomain();
         using (MemoryStream ms = new MemoryStream(ta.bytes))
         {
             appdomain.LoadAssembly(ms);
         }
         InitILRunTime(appdomain);
         appdomain.Invoke("Game", "StartGame", null);
         //  }
     }
     else
     {
         System.Reflection.Assembly[] assemblys = AppDomain.CurrentDomain.GetAssemblies();
         foreach (var assembly in  assemblys)
         {
             if (assembly.ManifestModule.Name.Contains("Game"))
             {
                 Type type = assembly.GetType("Game");
                 if (null != type)
                 {
                     System.Reflection.MethodInfo m = type.GetMethod("StartGame");
                     m.Invoke(null, null);
                 }
             }
         }
         // Type.GetType("Game").GetMethod("StartGame").Invoke(null,null);
     }
 }
Ejemplo n.º 13
0
        public override void init()
        {
            if (!_g0)
            {
                _m0 = instance.Type.GetMethod("init", 0);
                _g0 = true;
            }

            if (_m0 != null && !_b0)
            {
                _b0 = true;
                appdomain.Invoke(_m0, instance, null);
                _b0 = false;
            }
            else
            {
                base.init();
            }
        }
Ejemplo n.º 14
0
 protected override void Reset()
 {
     if (!mReset_0_Got)
     {
         mReset_0     = instance.Type.GetMethod("Reset", 0);
         mReset_0_Got = true;
     }
     if (mReset_0 != null && !mReset_0_Invoking)
     {
         mReset_0_Invoking = true;
         appdomain.Invoke(mReset_0, this.instance);
         mReset_0_Invoking = false;
     }
     else
     {
         base.Reset();
     }
 }
Ejemplo n.º 15
0
            public IEnumerator GetEnumerator()
            {
                if (!mGetEnumeratorMethodGot)
                {
                    mGetEnumeratorMethod    = __instance.Type.GetMethod("GetEnumerator", 0);
                    mGetEnumeratorMethodGot = true;
                }

                if (mGetEnumeratorMethod != null)
                {
                    var res = mAppdomain.Invoke(mGetEnumeratorMethod, __instance, null);
                    return((IEnumerator)res);
                }
                else
                {
                    return(null);
                }
            }
Ejemplo n.º 16
0
        public override void Dispose()
        {
            if (!_disposeGot)
            {
                _dispose    = instance.Type.GetMethod("Dispose");
                _disposeGot = true;
            }

            if (_dispose != null && !isDisposeInvoking)
            {
                isDisposeInvoking = true;
                appdomain.Invoke(_dispose, instance);
                isDisposeInvoking = false;
            }
            else
            {
                base.Dispose();
            }
        }
Ejemplo n.º 17
0
            protected override void OnAppearing()
            {
                if (!mOnAppearingGot)
                {
                    mOnAppearing    = instance.Type.GetMethod("OnAppearing", 0);
                    mOnAppearingGot = true;
                }

                if (mOnAppearing != null && !mOnAppearingInvoking)
                {
                    mOnAppearingInvoking = true;
                    appdomain.Invoke(mOnAppearing, instance);
                    mOnAppearingInvoking = false;
                }
                else
                {
                    base.OnAppearing();
                }
            }
Ejemplo n.º 18
0
 public override void OnEnter(object param1 = null, object param2 = null, object param3 = null)
 {
     if (mOnEnterMethod == null)
     {
         mOnEnterMethod = mInstance.Type.GetMethod("OnEnter", 3);
     }
     if (mOnEnterMethod != null)
     {
         mParalist[0] = param1;
         mParalist[1] = param2;
         mParalist[2] = param3;
         mAppDomain.Invoke(mOnEnterMethod, mInstance, mParalist);
     }
 }
Ejemplo n.º 19
0
    IEnumerator LoadILRuntime()
    {
        appdomain = new ILRuntime.Runtime.Enviorment.AppDomain();
#if UNITY_ANDROID
        WWW www = new WWW(Application.streamingAssetsPath + "/HotFix.dll");
#else
        WWW www = new WWW("file:///" + Application.streamingAssetsPath + "/HotFix.dll");
#endif
        while (!www.isDone)
        {
            yield return(null);
        }
        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.LogError(www.error);
        }
        byte[] dll = www.bytes;
        www.Dispose();
#if UNITY_ANDROID
        www = new WWW(Application.streamingAssetsPath + "/HotFix.pdb");
#else
        www = new WWW("file:///" + Application.streamingAssetsPath + "/HotFix.pdb");
#endif
        while (!www.isDone)
        {
            yield return(null);
        }
        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.LogError(www.error);
        }
        byte[] pdb = www.bytes;
        using (System.IO.MemoryStream fs = new MemoryStream(dll))
        {
            using (System.IO.MemoryStream p = new MemoryStream(pdb))
            {
                appdomain.LoadAssembly(fs, p, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());
                OnILRuntimeInitialized();
                appdomain.Invoke("HotFix.Bootstrapper", "go", null, null);
            }
        }
    }
Ejemplo n.º 20
0
            public override void OnOpening()
            {
                if (mOnOpeningMethod == null)
                {
                    mOnOpeningMethod = __instance.Type.GetMethod("OnOpening", 0);
                }

                if (mOnOpeningMethod != null && !mIsTestOnOpeningInvoking)
                {
                    mIsTestOnOpeningInvoking = true;
                    mAppdomain.Invoke(mOnOpeningMethod, __instance);
                    mIsTestOnOpeningInvoking = false;
                }
                else
                {
                    base.OnOpening();
                }
            }
Ejemplo n.º 21
0
        public override void OnDestroy()
        {
            if (!_gotMethod)
            {
                _methodOnDestroy = _instance.Type.GetMethod("OnDestroy", 1);
                _gotMethod       = true;
            }

            //对于虚函数而言,必须设定一个标识位来确定是否当前已经在调用中,否则如果脚本类中调用base.TestVirtual()就会造成无限循环,最终导致爆栈
            if (_methodOnDestroy != null && !_isOnDestroyInvoking)
            {
                _isOnDestroyInvoking = true;
                _appdomain.Invoke(_methodOnDestroy, _instance, null);
                _isOnDestroyInvoking = false;
            }
            else
            {
                base.OnDestroy();
            }
        }
Ejemplo n.º 22
0
        public override void writeInfo(StringBuilder sb)
        {
            if (!_g0)
            {
                _m0 = instance.Type.GetMethod("writeInfo", 1);
                _g0 = true;
            }

            if (_m0 != null && !_b0)
            {
                _b0    = true;
                _p1[0] = sb;
                appdomain.Invoke(_m0, instance, _p1);
                _p1[0] = null;
                _b0    = false;
            }
            else
            {
                base.writeInfo(sb);
            }
        }
Ejemplo n.º 23
0
        protected override void toDispatchAttribute(int[] changeList, int num, bool[] changeSet, int[] lastAttributes)
        {
            if (!_g0)
            {
                _m0 = instance.Type.GetMethod("toDispatchAttribute", 4);
                _g0 = true;
            }

            if (_m0 != null)
            {
                _p4[0] = changeList;
                _p4[1] = num;
                _p4[2] = changeSet;
                _p4[3] = lastAttributes;
                appdomain.Invoke(_m0, instance, _p4);
                _p4[0] = null;
                _p4[1] = null;
                _p4[2] = null;
                _p4[3] = null;
            }
        }
Ejemplo n.º 24
0
        protected override void registLogics()
        {
            if (!_g0)
            {
                _m0 = instance.Type.GetMethod("registLogics", 0);
                _g0 = true;
            }

            if (_m0 != null && !_b0)
            {
                _b0 = true;
                appdomain.Invoke(_m0, instance, null);
                _b0 = false;
            }
            else
            {
                base.registLogics();
            }
        }
Ejemplo n.º 25
0
 //你需要重写所有你希望在热更脚本里面重写的方法,并且将控制权转到脚本里去
 public override void ConstructFromXML(XML xml)
 {
     if (!constructFromXMLRecorder.mMethodGot)
     {
         //属性的Getter编译后会以get_XXX存在,如果不确定的话可以打开Reflector等反编译软件看一下函数名称
         constructFromXMLRecorder.mMethod = instance.Type.GetMethod("ConstructFromXML", 1);
         param1[0] = xml;
         constructFromXMLRecorder.mMethodGot = true;
     }
     //对于虚函数而言,必须设定一个标识位来确定是否当前已经在调用中,否则如果脚本类中调用base.Value就会造成无限循环,最终导致爆栈
     if (constructFromXMLRecorder.mMethod != null && !constructFromXMLRecorder.isMethodInvoking)
     {
         constructFromXMLRecorder.isMethodInvoking = true;
         appdomain.Invoke(constructFromXMLRecorder.mMethod, instance, param1);
         constructFromXMLRecorder.isMethodInvoking = false;
     }
     else
     {
         base.ConstructFromXML(xml);
     }
 }
Ejemplo n.º 26
0
        protected override void doOneOverAction(int[] args)
        {
            if (!_g0)
            {
                _m0 = instance.Type.GetMethod("doOneOverAction", 1);
                _g0 = true;
            }

            if (_m0 != null && !_b0)
            {
                _b0    = true;
                _p1[0] = args;
                appdomain.Invoke(_m0, instance, _p1);
                _p1[0] = null;
                _b0    = false;
            }
            else
            {
                base.doOneOverAction(args);
            }
        }
Ejemplo n.º 27
0
            protected override void OnInitialize()
            {
                if (mOnInitialize == null)
                {
                    mOnInitialize = instance.Type.GetMethod("OnInitialize", 0);
                }

                if (mOnInitialize != null)
                {
                    appdomain.Invoke(mOnInitialize, instance, null);
                }
                else
                {
                    base.OnInitialize();
                }
            }
Ejemplo n.º 28
0
        public override bool isCharacter()
        {
            if (!_g0)
            {
                _m0 = instance.Type.GetMethod("isCharacter", 0);
                _g0 = true;
            }

            if (_m0 != null && !_b0)
            {
                _b0 = true;
                bool re = (bool)appdomain.Invoke(_m0, instance, null);
                _b0 = false;
                return(re);
            }
            else
            {
                return(base.isCharacter());
            }
        }
Ejemplo n.º 29
0
        protected override int toCountOne(int type)
        {
            if (!_g0)
            {
                _m0 = instance.Type.GetMethod("toCountOne", 1);
                _g0 = true;
            }

            if (_m0 != null && !_b0)
            {
                _b0    = true;
                _p1[0] = type;
                int re = (int)appdomain.Invoke(_m0, instance, _p1);
                _p1[0] = null;
                _b0    = false;
                return(re);
            }
            else
            {
                return(base.toCountOne(type));
            }
        }
Ejemplo n.º 30
0
        public void Awake()
        {
            //Unity会在ILRuntime准备好这个实例前调用Awake,所以这里暂时先不掉用
            if (instance != null)
            {
                if (!mAwakeMethodGot)
                {
                    mAwakeMethod    = instance.Type.GetMethod("Awake", 0);
                    mAwakeMethodGot = true;
                }

                if (mAwakeMethod != null)
                {
                    appdomain.Invoke(mAwakeMethod, instance, null);
                }
            }
        }