Exemplo n.º 1
0
        public void PackKnownObject()
        {
            var packer = new MiniMessagePacker();
            var actual = packer.Pack(new MyClass());

            Assert.AreEqual(2, actual.Length);
            Assert.AreEqual(0xa1, actual[0]);
            Assert.AreEqual(0x61, actual[1]);
        }
Exemplo n.º 2
0
 void Awake()
 {
     if (IsNodeJS = open_nodejs(x86))
     {
         ws         = new WebSocket(adress);
         pakage     = new MiniMessagePacker();
         ObjectName = name;
         SetupUnode(ws, adress);
     }
 }
Exemplo n.º 3
0
    public IMNormalTalk(string senderName, string content)
    {
        if (m_MsgPacker == null)
        {
            m_MsgPacker = new MiniMessagePacker();
        }

        m_SendName = senderName;
        m_Content  = content;
    }
Exemplo n.º 4
0
        public void PackArray(object[] array, byte[] expected, string message)
        {
            var packer = new MiniMessagePacker();
            var actual = packer.Pack(array);

            Assert.AreEqual(expected.Length, actual.Length, message + ": length");
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected [i], actual [i], message + ": [" + i + "]");
            }
        }
Exemplo n.º 5
0
        public void PackShortValue(int value, byte[] expected)
        {
            var packer = new MiniMessagePacker();
            var actual = packer.Pack((object)(short)value);

            Assert.AreEqual(expected.Length, actual.Length, "length");
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected [i], actual [i], "byte: " + i);
            }
        }
Exemplo n.º 6
0
        public void PackString(string value, byte[] expected)
        {
            var packer = new MiniMessagePacker();
            var actual = packer.Pack(value);

            Assert.AreEqual(expected.Length, actual.Length, value + ": length");
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected [i], actual [i], value + ": [" + i + "]");
            }
        }
Exemplo n.º 7
0
        public void MapValues(string[] keys, object[] values, byte[] data, string message)
        {
            var packer = new MiniMessagePacker();
            var actual = (Dictionary <string, object>)packer.Unpack(data);

            Assert.AreEqual(keys.Length, actual.Count, message + ": count");
            for (int i = 0; i < keys.Length; i++)
            {
                Assert.AreEqual(values [i], actual [keys[i]], message + "[" + keys[i] + "]");
            }
        }
Exemplo n.º 8
0
        public void ArrayValues(object[] expected, byte[] data, string message)
        {
            var packer = new MiniMessagePacker();
            var actual = packer.Unpack(data) as List <object>;

            Assert.AreNotEqual(actual, null, message + ": type");
            Assert.AreEqual(expected.Length, actual.Count, message + ": count");
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected [i], actual [i], message + "[" + i + "]");
            }
        }
Exemplo n.º 9
0
        protected override void ThreadFunction()
        {
            var    mini = new MiniMessagePacker();
            object message;

            while ((message = mini.Unpack(stream)) != null)
            {
                if (!(message is Dictionary <string, object>))
                {
                    continue;
                }
                Status = MessageSerializer.Serialize((Dictionary <string, object>)message);
            }
        }
Exemplo n.º 10
0
        public void PackMap(string[] keys, object[] values, byte[] expected, string message)
        {
            var packer = new MiniMessagePacker();
            var dict   = new SortedDictionary <string, object> ();

            for (int i = 0; i < keys.Length; i++)
            {
                dict.Add(keys [i], values [i]);
            }
            var actual = packer.Pack(dict);

            Assert.AreEqual(expected.Length, actual.Length, message + ": length");
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected [i], actual [i], message + ": [" + i + "]");
            }
        }
        // Adds in a new animation clip from a CreaturePack Anim Data byte stream
        // This means you are using the separately exported CreaturePack Animation Data files
        public void addSplitAnimClip(Stream byteStream, CreaturePackPlayer playerIn)
        {
            var newReader  = new MiniMessagePacker();
            var unpackData = newReader.Unpack(byteStream);
            var readData   = (object[])unpackData;

            // Add in new clip data
            var splitClip = new CreaturePackSplitAnimClip(readData);
            var clipName  = (string)readData[CreatureConsts.SPLIT_CLIP_NAME_IDX];

            animClipMap[clipName]         = splitClip;
            playerIn.runTimeMap[clipName] = splitClip.startTime;

            UnityEngine.Debug.Log("Adding Pack Split Animation: " + clipName);

            // Process clip point data
            var splitProcessObj = new FinalPointsProcessSplitData(this, readData);

            processPerFinalAllPointsSample(splitProcessObj);
        }
Exemplo n.º 12
0
        public void PackString255()
        {
            var str = new StringBuilder();

            for (int i = 0; i < 255; i++)
            {
                str.Append("a");
            }

            var packer = new MiniMessagePacker();
            var actual = packer.Pack(str.ToString());

            Assert.AreEqual(str.Length + 2, actual.Length);
            Assert.AreEqual(0xd9, actual [0]);
            Assert.AreEqual(0xff, actual [1]);
            for (int i = 0; i < str.Length; i++)
            {
                Assert.AreEqual(0x61, actual [i + 2]);
            }
        }
Exemplo n.º 13
0
        public void PackLongArray()
        {
            var array = new int[65535];

            for (int i = 0; i < array.Length; i++)
            {
                array [i] = 0x00;
            }

            var packer = new MiniMessagePacker();
            var actual = packer.Pack(array);

            Assert.AreEqual(array.Length + 1 + 2, actual.Length);
            Assert.AreEqual(0xdc, actual [0]);
            Assert.AreEqual(0xff, actual [1]);
            Assert.AreEqual(0xff, actual [2]);
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(0x00, actual [i + 1 + 2]);
            }
        }
Exemplo n.º 14
0
        public void runDecoder(Stream byteStream)
        {
            var newReader = new MiniMessagePacker();

            fileData = (object[])newReader.Unpack(byteStream);

            headerList          = (object[])fileData[getBaseOffset()];
            animPairsOffsetList = (object[])fileData[getAnimPairsListOffset()];

            // init basic points and topology structure
            indices = new uint[getNumIndices()];
            points  = new float[getNumPoints()];
            uvs     = new float[getNumUvs()];

            updateIndices(getBaseIndicesOffset());
            updatePoints(getBasePointsOffset());
            updateUVs(getBaseUvsOffset());

            // init Animation Clip Map
            for (int i = 0; i < getAnimationNum(); i++)
            {
                var curOffsetPair = getAnimationOffsets(i);

                var animName = (string)(fileData[curOffsetPair.first]);
                var k        = curOffsetPair.first;
                k++;
                var newClip = new CreaturePackAnimClip(k);

                while (k < curOffsetPair.second)
                {
                    int cur_time = (int)(float)(fileData[k]);
                    newClip.addTimeSample(cur_time, (int)k);

                    k += 4;
                }

                newClip.finalTimeSamples();
                animClipMap[animName] = newClip;
            }
        }
Exemplo n.º 15
0
        public void UnpackExample()
        {
            // it means {"compact":true,"schema":0} in JSON
            var msgpack = new byte[] {
                0x82, 0xa7, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, 0x74, 0xc3,
                0xa6, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x00
            };

            var    packer        = new MiniMessagePacker();
            object unpacked_data = packer.Unpack(msgpack);

            /*
             * unpacked_data = new Dictionary<string, object> {
             *     { "compact", true },
             *     { "schema", 0},
             * };
             */
            var dict = (Dictionary <string, object>)unpacked_data;

            Assert.IsTrue((bool)dict ["compact"]);
            Assert.AreEqual(0, (long)dict ["schema"]);
        }
Exemplo n.º 16
0
        public void PackString65536()
        {
            var str = new StringBuilder();

            for (int i = 0; i < 65536; i++)
            {
                str.Append("a");
            }

            var packer = new MiniMessagePacker();
            var actual = packer.Pack(str.ToString());

            Assert.AreEqual(str.Length + 1 + 4, actual.Length);
            Assert.AreEqual(0xdb, actual [0]);
            Assert.AreEqual(0x00, actual [1]);
            Assert.AreEqual(0x01, actual [2]);
            Assert.AreEqual(0x00, actual [3]);
            Assert.AreEqual(0x00, actual [4]);
            for (int i = 0; i < str.Length; i++)
            {
                Assert.AreEqual(0x61, actual [i + 1 + 4]);
            }
        }
Exemplo n.º 17
0
        public void PackExample()
        {
            var unpacked_data = new SortedDictionary <string, object> {
                { "compact", true },
                { "schema", 0 },
            };

            var packer = new MiniMessagePacker();

            byte[] msgpack = packer.Pack(unpacked_data);

            // it means {"compact":true,"schema":0} in JSON
            var expected = new byte[] {
                0x82, 0xa7, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, 0x74, 0xc3,
                0xa6, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x00
            };

            Assert.AreEqual(expected.Length, msgpack.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected [i], msgpack [i]);
            }
        }
        public void runDecoder(Stream byteStream, bool loadMultiCore)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var newReader = new MiniMessagePacker();

            fileData = (object[])newReader.Unpack(byteStream);

            stopWatch.Stop();
#if (CREATURE_PACK_DEBUG)
            UnityEngine.Debug.Log("---Data Decode time: " + stopWatch.ElapsedMilliseconds);
#endif
            stopWatch.Reset();

            headerList          = (object[])fileData[getBaseOffset()];
            animPairsOffsetList = (object[])fileData[getAnimPairsListOffset()];

            // init basic points and topology structure
            indices = new uint[getNumIndices()];
            points  = new float[getNumPoints()];
            uvs     = new float[getNumUvs()];

            updateIndices(getBaseIndicesOffset());
            updatePoints(getBasePointsOffset());
            updateUVs(getBaseUvsOffset());

            fillDeformRanges();

            stopWatch.Start();

            if (loadMultiCore)
            {
                finalAllPointSamplesThreaded();
            }
            else
            {
                finalAllPointSamples();
            }

            stopWatch.Stop();
#if (CREATURE_PACK_DEBUG)
            UnityEngine.Debug.Log("---Data Packaging time: " + stopWatch.ElapsedMilliseconds);
#endif

            // init Animation Clip Map
            for (int i = 0; i < getAnimationNum(); i++)
            {
                var curOffsetPair = getAnimationOffsets(i);

                var animName = (string)(fileData[curOffsetPair.first]);
                var k        = curOffsetPair.first;
                k++;
                var newClip = new CreaturePackAnimClip(k, fileData);

                while (k < curOffsetPair.second)
                {
                    int cur_time = (int)(float)(fileData[k]);
                    newClip.addTimeSample(cur_time, (int)k);

                    k += 4;
                }

                newClip.finalTimeSamples();
                animClipMap[animName] = newClip;
            }
        }
Exemplo n.º 19
0
        private void HttpRequestData()
        {
            listBox1.Items.Clear();
            progressBar1.Value = 0;
            var path     = Directory.GetCurrentDirectory();
            var gamedata = new DirectoryInfo(path + @"\Android\masterdata\");
            var folder   = new DirectoryInfo(path + @"\Android\");

            progressBar1.Value = progressBar1.Value + 250;
            if (!Directory.Exists(folder.FullName))
            {
                listBox1.Items.Add("正在创建Android目录...");
                listBox1.TopIndex = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
                Directory.CreateDirectory(folder.FullName);
            }

            listBox1.Items.Add("开始下载/更新游戏数据......");
            progressBar1.Value = progressBar1.Value + 250;
            listBox1.TopIndex  = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
            var result = HttpRequest.PhttpReq("https://game.fate-go.jp/gamedata/top", "appVer=2.15.0");
            var res    = JObject.Parse(result);

            if (res["response"][0]["fail"]["action"] != null)
            {
                switch (res["response"][0]["fail"]["action"].ToString())
                {
                case "app_version_up":
                {
                    var tmp = res["response"][0]["fail"]["detail"].ToString();
                    tmp = Regex.Replace(tmp, @".*新ver.:(.*)、現.*", "$1", RegexOptions.Singleline);
                    listBox1.Items.Add("当前游戏版本: " + tmp);
                    listBox1.TopIndex = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
                    result            = HttpRequest.PhttpReq("https://game.fate-go.jp/gamedata/top", "appVer=" + tmp);
                    res = JObject.Parse(result);
                    break;
                }

                case "maint":
                {
                    var tmp = res["response"][0]["fail"]["detail"].ToString();
                    if (MessageBox.Show(
                            "游戏服务器正在维护,请在维护后下载数据. \r\n以下为服务器公告内容:\r\n\r\n『" +
                            tmp.Replace("[00FFFF]", "").Replace("[url=", "")
                            .Replace("][u]公式サイト お知らせ[/u][/url][-]", "") + "』\r\n\r\n点击\"确定\"可打开公告页面.",
                            "维护中", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        var re = new Regex(@"(?<url>http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?)");
                        var mc = re.Matches(tmp);
                        foreach (Match m in mc)
                        {
                            var url = m.Result("${url}");
                            Process.Start(url);
                        }
                    }

                    Application.ExitThread();
                    Close();
                    return;
                }
                }
            }

            if (File.Exists(gamedata.FullName + "webview") || File.Exists(gamedata.FullName + "raw") ||
                File.Exists(gamedata.FullName + "assetbundle") || File.Exists(gamedata.FullName + "webview") ||
                File.Exists(gamedata.FullName + "master"))
            {
                var fileinfo = folder.GetFileSystemInfos(); //返回目录中所有文件和子目录
                foreach (var i in fileinfo)
                {
                    if (i is DirectoryInfo) //判断是否文件夹
                    {
                        var subdir = new DirectoryInfo(i.FullName);
                        subdir.Delete(true); //删除子目录和文件
                        listBox1.Items.Add("删除: " + subdir);
                        listBox1.TopIndex = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
                        continue;
                    }

                    i.Delete();
                    listBox1.Items.Add("删除: " + i);
                    listBox1.TopIndex = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
                }
            }

            if (!Directory.Exists(gamedata.FullName))
            {
                Directory.CreateDirectory(gamedata.FullName);
            }
            File.WriteAllText(gamedata.FullName + "raw", result);
            File.WriteAllText(gamedata.FullName + "assetbundle",
                              res["response"][0]["success"]["assetbundle"].ToString());
            listBox1.Items.Add("Writing file to: " + gamedata.FullName + "assetbundle");
            listBox1.TopIndex  = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
            progressBar1.Value = progressBar1.Value + 40;
            File.WriteAllText(gamedata.FullName + "master", res["response"][0]["success"]["master"].ToString());
            listBox1.Items.Add("Writing file to: " + gamedata.FullName + "master");
            listBox1.TopIndex  = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
            progressBar1.Value = progressBar1.Value + 40;
            File.WriteAllText(gamedata.FullName + "webview",
                              res["response"][0]["success"]["webview"].ToString());
            listBox1.Items.Add("Writing file to: " + gamedata.FullName + "webview");
            listBox1.TopIndex  = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
            progressBar1.Value = progressBar1.Value + 40;
            var data = File.ReadAllText(gamedata.FullName + "master");

            if (!Directory.Exists(gamedata.FullName + "decrypted_masterdata"))
            {
                Directory.CreateDirectory(gamedata.FullName + "decrypted_masterdata");
            }
            var masterData =
                (Dictionary <string, byte[]>)MasterDataUnpacker.MouseGame2Unpacker(
                    Convert.FromBase64String(data));
            var job = new JObject();
            var miniMessagePacker = new MiniMessagePacker();

            foreach (var item in masterData)
            {
                var unpackeditem = (List <object>)miniMessagePacker.Unpack(item.Value);
                var json         = JsonConvert.SerializeObject(unpackeditem, Formatting.Indented);
                File.WriteAllText(gamedata.FullName + "decrypted_masterdata/" + item.Key, json);
                listBox1.Items.Add("Writing file to: " + gamedata.FullName + "decrypted_masterdata/" +
                                   item.Key);
                listBox1.TopIndex  = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
                progressBar1.Value = progressBar1.Value + 40;
            }

            var data2      = File.ReadAllText(gamedata.FullName + "assetbundle");
            var dictionary =
                (Dictionary <string, object>)MasterDataUnpacker.MouseInfoMsgPack(
                    Convert.FromBase64String(data2));
            var str = dictionary.Aggregate <KeyValuePair <string, object>, string>(null,
                                                                                   (current, a) => current + a.Key + ": " + a.Value + "\r\n");

            File.WriteAllText(gamedata.FullName + "assetbundle.txt", str);
            listBox1.Items.Add("folder name: " + dictionary["folderName"]);
            listBox1.TopIndex  = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
            progressBar1.Value = progressBar1.Value + 40;
            var data3       = File.ReadAllText(gamedata.FullName + "webview");
            var dictionary2 =
                (Dictionary <string, object>)MasterDataUnpacker.MouseGame2MsgPack(
                    Convert.FromBase64String(data3));
            var str2 = "baseURL: " + dictionary2["baseURL"] + "\r\n contactURL: " + dictionary2["contactURL"] +
                       "\r\n";

            listBox1.Items.Add(str2);
            listBox1.TopIndex  = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
            progressBar1.Value = progressBar1.Value + 40;
            var filePassInfo = (Dictionary <string, object>)dictionary2["filePass"];

            str = filePassInfo.Aggregate(str, (current, a) => current + a.Key + ": " + a.Value + "\r\n");
            File.WriteAllText(gamedata.FullName + "webview.txt", str2);
            listBox1.Items.Add("Writing file to: " + gamedata.FullName + "webview.txt");
            listBox1.TopIndex = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
            listBox1.Items.Add("下载完成,可以开始解析.");
            listBox1.TopIndex  = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
            progressBar1.Value = progressBar1.Maximum;
            MessageBox.Show("下载完成,可以开始解析.", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Application.ExitThread();
            Close();
        }
 public MsgPackViewer2()
 {
     InitializeComponent();
     packer = new MiniMessagePacker();
 }