示例#1
0
        private byte[] m_10023()
        {
            byte[] array;
            using (var ms = new MemoryStream())
            {
                Serializer.Serialize(ms, new sc_10023
                {
                    result        = 0,//0은 튜토리얼 보내기.
                    user_id       = 67751892,
                    server_ticket = "16144400104a8afc841fb14e8dd3b1448782f03472",
                    server_load   = 0,
                    db_load       = 0,
                });
                array = ms.ToArray();
            }
            var packStream = new PackStream(15 + array.Length);

            packStream.WriteUint16((uint)(9 + array.Length));
            packStream.WriteUint8(0);
            packStream.WriteUint16(10023);
            packStream.WriteUint16(0);
            packStream.WriteUint8(8);
            packStream.WriteUint8(0);
            packStream.WriteUint8(16);
            packStream.WriteUint8(0);
            packStream.WriteBuffer(array);

            return(packStream.ToArray());
        }
示例#2
0
            private static IEnumerable <byte> GetMarker(long fields)
            {
                if (fields <= 15)
                {
                    return new[] { (byte)(0xA0 + fields) }
                }
                ;

                var output = new List <byte>();

                if (fields <= byte.MaxValue)
                {
                    output.Add(0xD8);
                }

                if (fields <= ushort.MaxValue)
                {
                    output.Add(0xD9);
                }

                if (fields <= uint.MaxValue)
                {
                    output.Add(0xDA);
                }

                if (fields > uint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(nameof(fields), "Too many fields defined!");
                }

                output.AddRange(PackStream.GetLength(fields));
                return(output.ToArray());
            }
示例#3
0
            internal static byte[] GetMarker(long itemsInList)
            {
                if (itemsInList <= 15)
                {
                    return new[] { (byte)(0x90 + itemsInList) }
                }
                ;

                var output = new List <byte>();

                if (itemsInList <= 0xFF)
                {
                    output.Add(0xD4);
                }

                else if (itemsInList <= 0xFFFF)
                {
                    output.Add(0xD5);
                }

                else if (itemsInList <= uint.MaxValue)
                {
                    output.Add(0xD6);
                }

                if (itemsInList > uint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(nameof(itemsInList), itemsInList, "Too many items in the list!");
                }

                output.AddRange(PackStream.ConvertSizeToBytes(itemsInList));
                return(output.ToArray());
            }
示例#4
0
            private static byte[] PackDictionary(IDictionary content)
            {
                var bytes = new List <byte>();

                bytes.AddRange(GetMarker(content.Count));

                if (content.Count == 0)
                {
                    return(bytes.ToArray());
                }

                var arguments = content.GetType().GetTypeInfo().GenericTypeArguments;
                var keyType   = arguments[0];
                var valueType = arguments[1];



                foreach (var item in content.Keys)
                {
                    var keyBytes = PackStream.Pack(Convert.ChangeType(item, keyType));
                    bytes.AddRange(keyBytes);

                    try
                    {
                        var x = (valueType == typeof(object)) ? (object)content[item] : Convert.ChangeType(content[item], valueType);
                        bytes.AddRange(PackStream.Pack(x));
                    }
                    catch (Exception ex)
                    {
                        int i = 0;
                    }
                }

                return(bytes.ToArray());
            }
示例#5
0
            private static IEnumerable <byte> Marker(long size)
            {
                if (size <= 15)
                {
                    return new[] { (byte)(0x80 + size) }
                }
                ;

                var output = new List <byte>();

                if (size <= 255)
                {
                    output.Add(0xD0);
                }

                else if (size <= 65535)
                {
                    output.Add(0xD1);
                }

                else if (size <= 4294967295)
                {
                    output.Add(0xD2);
                }

                if (size > uint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(nameof(size), size, "Size given is too big.");
                }

                output.AddRange(PackStream.GetLength(size));
                return(output.ToArray());
            }
        public object Read(IPackStreamReader reader, byte signature, long size)
        {
            switch (signature)
            {
            case Point2DStructType:
            {
                PackStream.EnsureStructSize("Point2D", Point2DStructSize, size);
                var srId = reader.ReadInteger();
                var x    = reader.ReadDouble();
                var y    = reader.ReadDouble();

                return(new CypherPoint(srId, x, y));
            }

            case Point3DStructType:
            {
                PackStream.EnsureStructSize("Point3D", Point3DStructSize, size);
                var srId = reader.ReadInteger();
                var x    = reader.ReadDouble();
                var y    = reader.ReadDouble();
                var z    = reader.ReadDouble();

                return(new CypherPoint(srId, x, y, z));
            }

            default:
                throw new ProtocolException(
                          $"Unsupported struct signature {signature} passed to {nameof(PointHandler)}!");
            }
        }
示例#7
0
            private static IDictionary UnpackDictionary <TKey, TValue>(byte[] content)
            {
                int numberOfPairs;
                var markerLess = RemoveMarker(content, out numberOfPairs);

                var output = new Dictionary <TKey, TValue>();

                if (numberOfPairs == 0)
                {
                    return(output);
                }

                var packed = PackStream.GetPackedEntities(markerLess);

                for (var i = 0; i < packed.Length; i += 2)
                {
                    var  key   = PackStream.Unpack(packed[i]);
                    var  value = PackStream.Unpack(packed[i + 1]);
                    Type genericType;
                    if (List.IsEnumerable(typeof(TValue), out genericType))
                    {
                        var method        = typeof(List).GetTypeInfo().GetDeclaredMethod("Unpack");
                        var genericMethod = method.MakeGenericMethod(genericType);
                        var list          = genericMethod.Invoke(null, new object[] { packed[i + 1].Original }) as IEnumerable;
                        value = (TValue)list;
                    }

                    output.Add(key, value);
                }

                return(output);
            }
示例#8
0
        public object Read(IPackStreamReader reader, byte signature, long size)
        {
            PackStream.EnsureStructSize("LocalTime", StructSize, size);

            var nanosOfDay = reader.ReadLong();

            return(TemporalHelpers.NanoOfDayToTime(nanosOfDay));
        }
            public void PacksSmallStringCorrectly(int size, byte[] expected)
            {
                var s = new string('a', size);

                var packed = PackStream.Pack(s);

                packed.Should().Equal(expected);
            }
示例#10
0
            public void PackD1StringCorrectly(int size, byte[] expected)
            {
                var s = new string('a', size);

                var packed = PackStream.Pack(s);

                packed.Take(3).ToArray().Should().Equal(expected, size.ToString("X"));
            }
示例#11
0
        public object Read(IPackStreamReader reader, byte signature, long size)
        {
            PackStream.EnsureStructSize("Date", StructSize, size);

            var epochDays = reader.ReadLong();

            return(TemporalHelpers.EpochDaysToDate(epochDays));
        }
示例#12
0
        public object Read(IPackStreamReader reader, byte signature, long size)
        {
            PackStream.EnsureStructSize("Date", StructSize, size);

            var epochDays = reader.ReadLong();

            return(new CypherDate(epochDays));
        }
示例#13
0
        public object Read(IPackStreamReader reader, byte signature, long size)
        {
            PackStream.EnsureStructSize("LocalTime", StructSize, size);

            var nanosOfDay = reader.ReadLong();

            return(new CypherTime(nanosOfDay));
        }
        public object Read(IPackStreamReader reader, byte signature, long size)
        {
            PackStream.EnsureStructSize("LocalDateTime", StructSize, size);

            var epochSeconds  = reader.ReadLong();
            var nanosOfSecond = reader.ReadInteger();

            return(new CypherDateTime(epochSeconds, nanosOfSecond));
        }
        public object Deserialize(IPackStreamReader reader, byte signature, long size)
        {
            PackStream.EnsureStructSize("LocalDateTime", StructSize, size);

            var epochSeconds  = reader.ReadLong();
            var nanosOfSecond = reader.ReadInteger();

            return(TemporalHelpers.EpochSecondsAndNanoToDateTime(epochSeconds, nanosOfSecond));
        }
示例#16
0
            public void GetsNumberOfItemsOfStruct()
            {
                var bytes          = new byte[] { 0xB3, 0x4E, 0x88, 0x6E, 0x6F, 0x64, 0x65, 0x2F, 0x31, 0x30, 0x35, 0x91, 0x85, 0x4D, 0x6F, 0x76, 0x69, 0x65, 0xA3, 0x87, 0x74, 0x61, 0x67, 0x6C, 0x69, 0x6E, 0x65, 0xD0, 0x17, 0x45, 0x76, 0x65, 0x72, 0x79, 0x74, 0x68, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x63, 0x6F, 0x6E, 0x6E, 0x65, 0x63, 0x74, 0x65, 0x64, 0x85, 0x74, 0x69, 0x74, 0x6C, 0x65, 0x8B, 0x43, 0x6C, 0x6F, 0x75, 0x64, 0x20, 0x41, 0x74, 0x6C, 0x61, 0x73, 0x88, 0x72, 0x65, 0x6C, 0x65, 0x61, 0x73, 0x65, 0x64, 0xC9, 0x07, 0xDC };
                var packedEntities = PackStream.GetPackedEntities(bytes);

                packedEntities.Length.Should().Be(1);
                packedEntities[0].PackType.Should().Be(PackType.Structure);
                packedEntities[0].NumberOfItems.Should().Be(3);
            }
        public object Read(IPackStreamReader reader, byte signature, long size)
        {
            PackStream.EnsureStructSize("Time", StructSize, size);

            var nanosOfDay    = reader.ReadLong();
            var offsetSeconds = reader.ReadInteger();

            return(new CypherTimeWithOffset(nanosOfDay, offsetSeconds));
        }
        public object Deserialize(IPackStreamReader reader, byte signature, long size)
        {
            PackStream.EnsureStructSize("Time", StructSize, size);

            var nanosOfDay    = reader.ReadLong();
            var offsetSeconds = reader.ReadInteger();

            return(new OffsetTime(TemporalHelpers.NanoOfDayToTime(nanosOfDay), offsetSeconds));
        }
示例#19
0
            public void ShouldUnpackCorrectly_UsingDynamic()
            {
                var fields = new[] { "Name", "Year" };
                var input  = new byte[] { 0x92, 0x8B, 0x43, 0x6C, 0x6F, 0x75, 0x64, 0x20, 0x41, 0x74, 0x6C, 0x61, 0x73, 0xC9, 0x07, 0xDC }; //Cloud Atlas | 2012

                var actual = PackStream.UnpackRecord(input, fields);

                Assert.Equal(actual.Name, "Cloud Atlas");
                Assert.Equal(actual.Year, 2012);
            }
示例#20
0
            public void PackEmptyDictionaryCorrectly()
            {
                var dic    = new Dictionary <string, string>();
                var packed = PackStream.Pack(dic);

                packed.Should().NotBeNull();
                var expected = new byte[] { 0xA0 };

                packed.Should().BeEquivalentTo(expected);
            }
示例#21
0
        public object Read(IPackStreamReader reader, byte signature, long size)
        {
            PackStream.EnsureStructSize("DateTimeWithOffset", StructSize, size);

            var epochSecondsUtc = reader.ReadLong();
            var nanosOfSecond   = reader.ReadInteger();
            var offsetSeconds   = reader.ReadInteger();

            return(new CypherDateTimeWithOffset(epochSecondsUtc, nanosOfSecond, offsetSeconds));
        }
示例#22
0
 public void Pack()
 {
     using (var ms = new MemoryStream(Packed))
     {
         var ps  = new PackStream(ms, PackStream.CompressionMode.Decompress);
         var buf = new byte[1024];
         Equal(Unpacked.Length, ps.Read(buf, 0, buf.Length));
         Equal(Unpacked, buf.Take(Unpacked.Length));
     }
 }
        public object Read(IPackStreamReader reader, byte signature, long size)
        {
            PackStream.EnsureStructSize("DateTimeWithZoneId", StructSize, size);

            var epochSecondsUtc = reader.ReadLong();
            var nanosOfSecond   = reader.ReadInteger();
            var zoneId          = reader.ReadString();

            return(new CypherDateTimeWithZoneId(epochSecondsUtc, nanosOfSecond, zoneId));
        }
        public object Deserialize(IPackStreamReader reader, byte signature, long size)
        {
            PackStream.EnsureStructSize("Duration", StructSize, size);

            var months  = reader.ReadLong();
            var days    = reader.ReadLong();
            var seconds = reader.ReadLong();
            var nanos   = reader.ReadInteger();

            return(new Duration(months, days, seconds, nanos));
        }
示例#25
0
        public void Unpack()
        {
            using (var ms = new MemoryStream())
            {
                var ps = new PackStream(ms, PackStream.CompressionMode.Compress);
                ps.Write(Unpacked, 0, Unpacked.Length);
                ps.Dispose();
                var buf = ms.ToArray();

                _output.WriteLine(string.Join(" ", buf.Select(b => b.ToString("X2"))));
                Equal(Packed, buf);
            }
        }
示例#26
0
文件: BtlSvo.cs 项目: talestra/tov
 private void Handle1()
 {
     if (!Patcher.TempFS.Exists("BTL_PACK_UK.DAT"))
     {
         Patcher.GameAccessPath("btl.svo", () =>
         {
             Patcher.GameGetFile("BTL_PACK_UK.DAT", (PackStream) =>
             {
                 Patcher.TempFS.WriteAllBytes("BTL_PACK_UK.DAT", PackStream.ReadAll());
             });
         });
     }
 }
示例#27
0
            public static IEnumerable <T> Unpack <T>(byte[] content)
            {
                if (!IsUnpackable(content))
                {
                    throw new ArgumentException("Not a list.", nameof(content));
                }

                var numberOfElements = GetNumberOfElements(content);
                var bytesToSkip      = GetSizeOfMarkerInBytes(numberOfElements);

                var unpacked = PackStream.Unpack(content.Skip(bytesToSkip).ToArray());

                return(unpacked.Cast <T>());
            }
示例#28
0
            public static byte[] Pack <T>(IEnumerable <T> content)
            {
                var output        = new List <byte>();
                var contentAsList = content.ToList();

                output.AddRange(GetMarker(contentAsList.Count));

                for (var i = 0; i < contentAsList.Count; i++)
                {
                    output.AddRange(PackStream.Pack(contentAsList[i]));
                }

                return(output.ToArray());
            }
示例#29
0
        private static byte[] _GetHashCode()
        {
            IniFile ini = new IniFile();

            ini.Load(Directory.GetCurrentDirectory() + "\\config\\gatewaysvr.ini");

            List <string> m_version = new List <string>
            {
                ini["Hash"]["azhash"].ToString(),
                ini["Hash"]["cvhash"].ToString(),
                "",
                "",
                ini["Hash"]["l2dhash"].ToString(),
                ini["Hash"]["pichash"].ToString(),
                ini["Hash"]["bgmhash"].ToString()
            };

            byte[] array;
            using (var ms = new MemoryStream())
            {
                Serializer.Serialize(ms, new sc_10801
                {
                    gateway_ip   = ini["GateWay"]["ip"].ToString(),
                    gateway_port = Convert.ToUInt16(ini["GateWay"]["port"].ToInt()),
                    url          = ini["GateWay"]["url"].ToString(),
                    version      = m_version,
                    proxy_ip     = ini["GateWay"]["proxy_ip"].ToString(),
                    proxy_port   = Convert.ToUInt16(ini["GateWay"]["proxy_port"].ToInt()),
                    is_ts        = Convert.ToUInt16(ini["GateWay"]["is_ts"].ToInt())
                });
                array = ms.ToArray();
            }

            PackStream packStream = new PackStream(15 + array.Length);

            packStream.WriteUint16((uint)(9 + array.Length));
            packStream.WriteUint8(0);
            packStream.WriteUint16(10801);
            packStream.WriteUint16(0);
            packStream.WriteBuffer(array);
            packStream.WriteUint8(48);
            packStream.WriteUint16(56);
            packStream.WriteUint8(0);

            return(packStream.ToArray());
        }
示例#30
0
        public AudioPlayer(string url, bool loop = false, float?volum = null)
        {
            if (volum == null)
            {
                volum = SharedSetting.BGMVolum;
            }
            PlayThread = new Thread(() =>
            {
                string path_rele = PackStream.Locate(url);
                var audioFile    = new AudioFileReader(path_rele);
                outputDevice     = new WaveOutEvent();
                outputDevice.Init(audioFile);
                outputDevice.Volume = (float)volum;
                do
                {
                    outputDevice.Play(); // 异步执行
                    while (outputDevice.PlaybackState == PlaybackState.Playing)
                    {
                        Thread.Sleep(100);
                        if (!canplay)
                        {
                            break;
                        }
                    }
                    outputDevice.Stop();
                    audioFile.Seek(0, SeekOrigin.Begin);
                } while (loop && canplay);

                outputDevice.Dispose();
                audioFile.Close();
                audioFile.Dispose();
                try
                {
                    File.Delete(path_rele);
                }
                catch
                {
                }
            })
            {
                IsBackground = true
            };
            PlayThread.Start();
        }