示例#1
0
        public SsqInfoChunk Decode(SsqChunk ssqChunk)
        {
            var text     = new string[12];
            var chunkMem = new ReadOnlyMemoryStream(ssqChunk.Data);
            var reader   = new BinaryReader(chunkMem, Encodings.CP1252);
            var builder  = new StringBuilder();

            for (var i = 0; i < text.Length; i++)
            {
                while (true)
                {
                    var c = reader.ReadChar();
                    if (c == 0)
                    {
                        break;
                    }
                    builder.Append(c);
                }

                text[i] = builder.ToString();
                builder.Clear();
            }

            return(new SsqInfoChunk
            {
                Text = text,
                Difficulties = reader.ReadBytes(10)
            });
        }
        public void Write(Stream stream, SsqChunk ssqChunk)
        {
            var writer = new BinaryWriter(stream);

            if (ssqChunk == null)
            {
                writer.Write(0);
                return;
            }

            var chunkData   = ssqChunk.Data ?? new byte[0];
            var writeLength = ((chunkData.Length + 3) >> 2) << 2;
            var writeData   = new byte[writeLength];

            Array.Copy(chunkData, writeData, chunkData.Length);

            var parameter0 = ssqChunk.Parameter0;
            var parameter1 = ssqChunk.Parameter1;

            writer.Write(writeLength + 8);
            writer.Write(parameter0);
            writer.Write(parameter1);
            writer.Write(writeData);
        }