private void Init(Stream input) { if (input.Length < 0x100) { throw new Exception( "Invalid Savedata!\nData is too short for it to be valid, please select a valid save file"); } long val = input.ReadInt32(true); if (val != (long)PackageHeader.Mc02) { input.Position -= 4; val = input.ReadInt64(true); if (val != (long)PackageHeader.Fb) { throw new Exception("Invalid Package Header!"); } } PackageHeader = (PackageHeader)val; bool isbigendian = PackageHeader == PackageHeader.Mc02; if (PackageHeader == PackageHeader.Mc02) { InitMcPackage(input); } else { InitFbPackage(input); } uint hash = input.ReadUInt32(isbigendian); Header = input.ReadBytes(HeaderLength - 4); var crc = new DA3CRC(); if (crc.Compute(Header) != hash) { throw new Exception( "Header data did not pass intergrity check!\nPlease choose a valid unmodified save to proceed"); } hash = input.ReadUInt32(isbigendian); var data = input.ReadBytes(DataLength - 4); uint xhash = crc.Compute(data); if (hash != xhash) { throw new Exception( "Save data did not pass the intergrity check!\nPlease choose a valid unmodified save to proceed"); } var xio = new DAIIO(data, isbigendian); DataStructure = new SaveDataStructure().Read(xio); xio.Close(); }
internal static int InstanceLength <T>(this DAInterface <T> instance, bool skiplength) where T : class { if (instance == null) { return(0); } int xreturn = 0; var io = new DAIIO(false); instance.Write(io, skiplength); xreturn = (int)io.CurrentBit; io.Close(); return(xreturn); }
public byte[] Rebuild() { var io = new DAIIO(PackageHeader == PackageHeader.Mc02); DataStructure.Write(io); var x = io.ToArray(); io.Close(); io.Dispose(); if (PackageHeader == PackageHeader.Mc02) { return(BuildMcPackage(x)); } return(BuildFbPackage(x)); }