Esempio n. 1
0
        public static SFXSaveGameFile Read(Stream input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            var save = new SFXSaveGameFile()
            {
                _Version = input.ReadValueU32(Endian.Little)
            };

            if (save._Version != 29 && save._Version.Swap() != 29 &&
                save._Version != 59 && save._Version.Swap() != 59)
            {
                throw new FormatException("unexpected version");
            }
            var endian = save._Version == 29 || save._Version == 59
                             ? Endian.Little
                             : Endian.Big;

            if (endian == Endian.Big)
            {
                save._Version = save._Version.Swap();
            }

            var reader = new Unreal.FileReader(input, save._Version, endian);

            save.Serialize(reader);

            if (save._Version >= 27)
            {
                if (input.Position != input.Length - 4)
                {
                    throw new FormatException("bad checksum position");
                }

                save._Checksum = input.ReadValueU32();
            }

            if (input.Position != input.Length)
            {
                throw new FormatException("did not consume entire file");
            }

            save.Endian = endian;
            return(save);
        }
        public static SFXSaveGameFile Read(Stream input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            var save = new SFXSaveGameFile()
            {
                _Version = input.ReadValueU32(Endian.Little)
            };

            if (save._Version != 29 && save._Version.Swap() != 29 &&
                save._Version != 59 && save._Version.Swap() != 59)
            {
                throw new FormatException("unexpected version");
            }
            var endian = save._Version == 29 || save._Version == 59
                             ? Endian.Little
                             : Endian.Big;
            if (endian == Endian.Big)
            {
                save._Version = save._Version.Swap();
            }

            var reader = new Unreal.FileReader(input, save._Version, endian);
            save.Serialize(reader);

            if (save._Version >= 27)
            {
                if (input.Position != input.Length - 4)
                {
                    throw new FormatException("bad checksum position");
                }

                save._Checksum = input.ReadValueU32();
            }

            if (input.Position != input.Length)
            {
                throw new FormatException("did not consume entire file");
            }

            save.Endian = endian;
            return save;
        }