Exemplo n.º 1
0
        public static void Write(SFXSaveGameFile save, Stream output)
        {
            if (save == null)
            {
                throw new ArgumentNullException("save");
            }

            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            using (var memory = new MemoryStream())
            {
                memory.WriteValueU32(save.Version, save._Endian);

                var writer = new Unreal.FileWriter(memory, save._Version, save._Endian);
                save.Serialize(writer);

                if (save._Version >= 27)
                {
                    memory.Position = 0;
                    uint checksum = 0;

                    var buffer = new byte[1024];
                    while (memory.Position < memory.Length)
                    {
                        int read = memory.Read(buffer, 0, 1024);
                        checksum = Crc32.Compute(buffer, 0, read, checksum);
                    }

                    save._Checksum = checksum;
                    memory.WriteValueU32(checksum, save._Endian);
                }

                memory.Position = 0;
                output.WriteFromStream(memory, memory.Length);
            }
        }
        public static void Write(SFXSaveGameFile save, Stream output)
        {
            if (save == null)
            {
                throw new ArgumentNullException("save");
            }

            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            using (var memory = new MemoryStream())
            {
                memory.WriteValueU32(save.Version, save._Endian);

                var writer = new Unreal.FileWriter(memory, save._Version, save._Endian);
                save.Serialize(writer);

                if (save._Version >= 27)
                {
                    memory.Position = 0;
                    uint checksum = 0;

                    var buffer = new byte[1024];
                    while (memory.Position < memory.Length)
                    {
                        int read = memory.Read(buffer, 0, 1024);
                        checksum = Crc32.Compute(buffer, 0, read, checksum);
                    }

                    save._Checksum = checksum;
                    memory.WriteValueU32(checksum, save._Endian);
                }

                memory.Position = 0;
                output.WriteFromStream(memory, memory.Length);
            }
        }