Beispiel #1
0
        public static Byte[] GetBytes(String input, Encoding encoding)
        {
            Assert.IsNotNull(input, nameof(input));
            Assert.IsNotNull(encoding, nameof(encoding));

            var buffer = new Byte[GetSize(input)];

            var offset = 0;

            for (var i = 0; i != input.Length; ++i)
            {
                var @char = input[i];
                if (@char > 0x20)
                {
                    offset += encoding.GetBytes(input, i, 1, buffer, offset);
                }
                else if (@char == (Byte)StringCode.COLOR)
                {
                    buffer[offset + 0] = (Byte)@char;
                    buffer[offset + 1] = (Byte)input[i + 1];

                    i      += 1;
                    offset += 2;
                }
                else if (@char == (Byte)StringCode.ITEM)
                {
                    buffer[offset + 0] = (Byte)@char;
                    BinaryIO.WriteIntoBuffer(buffer, offset + 1, (UInt16)input[i + 1], Endian.LittleEndian);

                    i      += 1;
                    offset += 3;
                }
                else
                {
                    buffer[offset] = (Byte)@char;
                    offset        += 1;
                }
            }

            return(buffer);
        }
        public Byte[] Write(Encoding encoding)
        {
            Assert.IsNotNull(encoding, nameof(encoding));

            using (var stream = new MemoryStream())
            {
                foreach (var record in Records)
                {
                    var idbytes   = ConvertId(record.Id);
                    var filebytes = record.MonsterDefinitionFile.Write(encoding);

                    var sizebytes = new Byte[4];
                    BinaryIO.WriteIntoBuffer(sizebytes, 0, (Int32)filebytes.Length);

                    stream.Write(idbytes, 0, idbytes.Length);
                    stream.Write(sizebytes, 0, sizebytes.Length);
                    stream.Write(filebytes, 0, filebytes.Length);
                }

                stream.Write(new Byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, 0, 8);

                return(stream.ToArray());
            }
        }