TransformData() public static method

public static TransformData ( byte data ) : byte[]
data byte
return byte[]
Exemplo n.º 1
0
        public void Save(String filePath, bool encrypt = true)
        {
            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);

            // Rebuild save
            bw.Write(SAVE_VERSION);
            bw.Write(header.ToArray());
            bw.Write(gamedata.ToArray());
            bw.Write(footer.ToArray());
            bw.Write(new byte[16]);
            bw.Write(Encryption.GenerateSaveHash(ms.ToArray()));

            // Store save and close streams
            byte[] data = ms.ToArray();
            bw.Close();
            ms.Close();

            // Encrypt if requested
            if (encrypt)
            {
                data = Encryption.TransformData(data);
            }
            File.WriteAllBytes(filePath, data);
        }
Exemplo n.º 2
0
        public SaveFile(String filePath, bool encrypted = true)
        {
            this.filePath = filePath;

            byte[] file = File.ReadAllBytes(filePath);
            byte[] data = encrypted ? Encryption.TransformData(file) : file;

            // Open save to process
            BinaryReader br = new BinaryReader(new MemoryStream(data));

            // Validate that file is a supported save format
            int version = br.ReadInt32();

            if (version != SAVE_VERSION)
            {
                throw new Exception(String.Format("Unsupported save version: {0}", version.ToString("X4")));
            }

            // Process blocks
            this.header   = new DataBlock(br);
            this.gamedata = new GameDataBlock(br);
            this.footer   = new DataBlock(br);

            // We're done with our reader
            br.Close();
        }