Beispiel #1
0
    static void CopyDll(BuildTarget target)
    {
        switch (target)
        {
        case BuildTarget.Android:
            AutoBuildGameLogic.ChangeGameLogicDefines(new string[] { "UNITY_ANDROID" });
            AutoBuildGameLogic.BuildGameLogic();
            break;

        case BuildTarget.iOS:
            AutoBuildGameLogic.ChangeGameLogicDefines(new string[] { "UNITY_IPHONE" });
            AutoBuildGameLogic.BuildGameLogic();
            break;

        case BuildTarget.StandaloneWindows:
            AutoBuildGameLogic.ChangeGameLogicDefines(new string[] { "UNITY_STANDALONE_WIN" });
            AutoBuildGameLogic.BuildGameLogic();
            break;
        }

        byte[] bytes = File.ReadAllBytes(Application.dataPath + "/../../output/GameLogic.dll");
        Rc4.rc4_go(ref bytes, bytes, (long)bytes.Length, Rc4.key, Rc4.key.Length, 0);
        File.WriteAllBytes(Application.dataPath + "/Resources/Install/Unpackage/GameLogic.bytes", bytes);
        AssetDatabase.Refresh();
    }
Beispiel #2
0
        bool LoadBytes(byte[] bytes)
        {
            Clear();

            try
            {
                Rc4.rc4_go(ref bytes, bytes, bytes.Length, Rc4.key, Rc4.key.Length, 1);

                string                name   = typeof(MetaT).ToString() + "List";
                Type                  type   = Type.GetType(name);
                object                parser = type.GetProperty("Parser").GetValue(null, null);
                MethodInfo            method = parser.GetType().GetMethod("ParseFrom", new Type[] { typeof(byte[]) });
                object                obj    = method.Invoke(parser, new object[] { bytes });
                RepeatedField <MetaT> datas  = obj.GetType().GetProperty("Datas").GetValue(obj, null) as RepeatedField <MetaT>;

                for (int i = 0; i < datas.Count; ++i)
                {
                    if (!OnGetUnit(datas[i]))
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                Debugger.LogException(ex);
                return(false);
            }

            return(true);
        }
        public bool Handle(MemoryStream stream)
        {
            int totalMsgLen = (int)stream.Length;

            if (totalMsgLen < 2)
            {
                Debugger.LogError("Invalid msg[len=" + Convert.ToString(totalMsgLen) + "]");
                return(false);
            }

            stream.Read(_tempBuf, 0, 2);
            ushort lenth = BitConverter.ToUInt16(_tempBuf, 0);

            if (lenth != totalMsgLen)
            {
                Debugger.LogError("msg lenth different");
                return(false);
            }

            _tempStream.Position = 0;
            _tempStream.SetLength(0);
            _tempStream.Write(stream.GetBuffer(), 2, totalMsgLen - 2);
            _tempStream.Position = 0;

            _tempBuf = _tempStream.GetBuffer();
            Rc4.rc4_go(ref _tempBuf, _tempBuf, totalMsgLen - 2, _rc4Key, _rc4Key.Length, 1);

            _deserializeStream.Position = 0;
            _deserializeStream.SetLength(0);
            _deserializeStream.Write(_tempBuf, 0, totalMsgLen - 2);
            _deserializeStream.Position = 0;
            try
            {
                PacketHeader head = PacketHeader.Parser.ParseFrom(_deserializeStream);

                if (UnityDefine.UnityEditor)
                {
                    Debugger.Log("Rcv msg id1:" + head.Id1 + " id2:" + head.Id2);
                }

                _deserializeStream.Position = 0;
                _msgDispatcher.Dispatch(head, _deserializeStream);
            }
            catch (Exception ex)
            {
                Debugger.LogError("Invalid msg");
                Debugger.LogException(ex);
                return(false);
            }

            return(true);
        }
        public bool Send <MsgT>(MsgT msg) where MsgT : IMessage
        {
            try
            {
                _tempStream.SetLength(0);
                _tempStream.Position = 0;
                msg.WriteTo(_tempStream);
                _tempStream.WriteByte(_msgIndex++);
                _tempStream.Position = 0;
                _tempBuf             = _tempStream.GetBuffer();

                Rc4.rc4_go(ref _tempBuf, _tempBuf, _tempStream.Length, _rc4Key, _rc4Key.Length, 0);

                _serializeStream.SetLength(0);
                _serializeStream.Position = 2;
                _serializeStream.Write(_tempBuf, 0, (int)_tempStream.Length);
                // write total msg len to stream
                SerializeTotalLen((ushort)_serializeStream.Length);

                if (_tcpClient.SendStream(_serializeStream))
                {
                    if (UnityDefine.UnityEditor)
                    {
                        Type         type = msg.GetType();
                        PropertyInfo id1  = type.GetProperty("Id1");
                        object       val1 = id1.GetValue(msg, null);
                        PropertyInfo id2  = type.GetProperty("Id2");
                        object       val2 = id2.GetValue(msg, null);
                        Debugger.Log("Send msg id1:" + (PacketID)val1 + " id2:" + (PacketID2)val2);
                    }

                    return(true);
                }

                return(false);
            }
            catch (System.Exception ex)
            {
                Debugger.LogException(ex);
                return(false);
            }
        }
Beispiel #5
0
        protected override bool LoadBytes(byte[] bytes)
        {
            Clear();

            try
            {
                Rc4.rc4_go(ref bytes, bytes, bytes.Length, Rc4.key, Rc4.key.Length, 1);

                string     name   = typeof(MetaT).ToString();
                Type       type   = Type.GetType(name);
                object     parser = type.GetProperty("Parser").GetValue(null, null);
                MethodInfo method = parser.GetType().GetMethod("ParseFrom", new Type[] { typeof(byte[]) });
                data = (MetaT)method.Invoke(parser, new object[] { bytes });
            }
            catch (Exception ex)
            {
                Debugger.LogException(ex);
                return(false);
            }

            return(true);
        }
Beispiel #6
0
    void WriteFile(string fileName)
    {
        fileName = fileName.Replace("\\", "/");
        string name = fileName.Substring(fileName.LastIndexOf('/') + 1, fileName.LastIndexOf('.') - fileName.LastIndexOf('/') - 1);

        if (!Directory.Exists(_dataPath))
        {
            Directory.CreateDirectory(_dataPath);
        }
        string outFile = _dataPath + name + ".bytes";

        FileStream output = new FileStream(outFile, FileMode.Create);

        SerializeCsvData();

        byte[] bytes = new byte[_serializeStream.Length];
        _serializeStream.Read(bytes, 0, bytes.Length);
        Rc4.rc4_go(ref bytes, bytes, bytes.Length, Rc4.key, Rc4.key.Length, 0);

        output.Write(bytes, 0, bytes.Length);

        output.Flush();
        output.Close();
    }
Beispiel #7
0
    public static void Init()
    {
        System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
        w.Start();

        try
        {
#if (UNITY_EDITOR && !DISABLE_ILRUNTIME) || (!UNITY_EDITOR && !UNITY_STANDALONE_WIN) || FOCE_ENABLE_ILRUNTIME
            app = new ILRuntime.Runtime.Enviorment.AppDomain();
            Debugger.Log("ILRuntime Enable!", true);
#else
            Debugger.Log("ILRuntime Disable!", true);
#endif

            string dllname = "GameLogic";
#if UNITY_EDITOR
            string     dllpath = Application.dataPath + "/../../output/";
            FileStream msDll   = new FileStream(dllpath + dllname + ".dll", FileMode.Open);
            FileStream msPdb   = new FileStream(dllpath + dllname + ".pdb", FileMode.Open);
#if !DISABLE_ILRUNTIME || FOCE_ENABLE_ILRUNTIME
            app.LoadAssembly(msDll, msPdb, new Mono.Cecil.Pdb.PdbReaderProvider());
#else
            byte[] dllbytes = new byte[msDll.Length];
            byte[] pdbbytes = new byte[msPdb.Length];
            msDll.Read(dllbytes, 0, dllbytes.Length);
            msPdb.Read(pdbbytes, 0, pdbbytes.Length);
            assembly = Assembly.Load(dllbytes, pdbbytes);
#endif
            msDll.Close();
            msPdb.Close();
#else
#if ILRUNTIME_DEBUG
            string dllpath = Application.persistentDataPath + "/";
#if UNITY_STANDALONE_WIN
            if (ResourceManager.IsILRuntimeDebug)
            {
                string[] lines = File.ReadAllLines(Application.dataPath + "/DebugPath.txt");
                dllpath = Application.dataPath + lines[1];
            }
#endif
            Debugger.Log("dllpath : " + dllpath, true);
            if (File.Exists(dllpath + dllname + ".dll") && File.Exists(dllpath + dllname + ".dll"))
            {
                FileStream msDll = new FileStream(dllpath + dllname + ".dll", FileMode.Open);
                FileStream msPdb = new FileStream(dllpath + dllname + ".pdb", FileMode.Open);
#if !UNITY_STANDALONE_WIN || FOCE_ENABLE_ILRUNTIME
                app.LoadAssembly(msDll, msPdb, new Mono.Cecil.Pdb.PdbReaderProvider());
#else
                byte[] dllbytes = new byte[msDll.Length];
                byte[] pdbbytes = new byte[msPdb.Length];
                msDll.Read(dllbytes, 0, dllbytes.Length);
                msPdb.Read(pdbbytes, 0, pdbbytes.Length);
                assembly = Assembly.Load(dllbytes, pdbbytes);
#endif
                msDll.Close();
                msPdb.Close();
            }
            else
            {
#if UNITY_STANDALONE_WIN
                if (ResourceManager.IsILRuntimeDebug)
                {
                    Debugger.LogError("Can't find " + dllpath + dllname + ".dll");
                }
                else
                {
#endif
#endif
            byte[] bytes = ResourceLoader.LoadUnpackageResBuffer("Install/Unpackage/GameLogic.bytes");
            Rc4.rc4_go(ref bytes, bytes, (long)bytes.Length, Rc4.key, Rc4.key.Length, 1);
#if !UNITY_STANDALONE_WIN || FOCE_ENABLE_ILRUNTIME
            MemoryStream msDll = new MemoryStream(bytes);
            app.LoadAssembly(msDll, null, new Mono.Cecil.Pdb.PdbReaderProvider());
#else
            assembly = Assembly.Load(bytes);
#endif
#if ILRUNTIME_DEBUG
#if UNITY_STANDALONE_WIN
        }
#endif
        }
#endif
#endif

#if (UNITY_EDITOR && !DISABLE_ILRUNTIME) || (!UNITY_EDITOR && !UNITY_STANDALONE_WIN) || FOCE_ENABLE_ILRUNTIME
            SetupCrossBinding();
            SetupMethodDelegate();
            SetupCLRRedirection();
            CLRBindings.Initialize(app);

#if UNITY_EDITOR
            app.DebugService.StartDebugService(56000);
#endif
#endif
        }
        catch (Exception ex)
        {
            Debugger.LogException(ex);
        }

        w.Stop();
        Debugger.Log("Init ILRuntime finish. Use time : " + w.ElapsedMilliseconds + " ms", true);
    }