Esempio n. 1
0
        public static void WriteHallOfFameDataToSave(HallOfFameStructure hofs, System.IO.Stream file, int offset = 0x1C000, int pages = 2)
        {
            using (System.IO.Stream buffer = new System.IO.MemoryStream(0xF80 * pages)) {
                // Serialize
                buffer.Position = 0;
                hofs.Serialize(buffer);
                buffer.WriteAlign(0xF80 * pages, 0x00);

                // Calculate checksums
                buffer.Position = 0;
                ushort[] checksums = new ushort[pages];
                for (int i = 0; i < pages; ++i)
                {
                    checksums[i] = Checksum.CalculateSaveChecksum(buffer, 0xF80);
                }

                // Write back into save
                buffer.Position = 0;
                for (int i = 0; i < pages; ++i)
                {
                    int secpos = offset + i * 0x1000;
                    file.WriteAlign(secpos + 0x1000, 0x00);

                    file.Position = secpos;
                    Util.CopyStream(buffer, file, 0xF80);
                    file.Position = secpos + 0xFF4;
                    file.WriteUInt16(checksums[i]);
                    file.Position = secpos + 0xFF8;
                    file.WriteUInt32(0x08012025);

                    file.Position = secpos + 0x1000;
                }
            }
        }