Пример #1
0
        // Reads all records in SaveTree
        // Reader must be positioned at start of first RecordElement
        void ReadRecords(BinaryReader reader)
        {
            RecordDictionary.Clear();
            RootRecord = new SaveTreeBaseRecord();
            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                // Read record length and skip empty records as they have no data
                int length = reader.ReadInt32();
                if (length <= 0)
                {
                    continue;
                }

                // Handle potential stream overflow (e.g. corrupt save, something went wrong)
                if (reader.BaseStream.Position + length >= reader.BaseStream.Length)
                {
                    break;
                }

                // Peek record type from RecordRoot so we can instantiate record class based on type
                RecordTypes type = PeekRecordType(reader);

                // Add record based on type
                SaveTreeBaseRecord record;
                switch (type)
                {
                case RecordTypes.Item:
                    record = new ItemRecord(reader, length);
                    break;

                case RecordTypes.Character:
                    record = new CharacterRecord(reader, length);
                    break;

                case RecordTypes.Spell:
                    record = new SpellRecord(reader, length);
                    break;

                case RecordTypes.Container:
                    record = new ContainerRecord(reader, length);
                    break;

                //case RecordTypes.Door:
                //    record = new SaveTreeBaseRecord(reader, length);    // Read then skip these records for now
                //    continue;
                //case RecordTypes.DungeonData:
                //    record = new SaveTreeBaseRecord(reader, length);    // Read then skip these records for now
                //    continue;
                default:
                    record = new SaveTreeBaseRecord(reader, length);
                    break;
                }
                AddRecord(record);
            }

            LinkChildren();
        }
        // Reads all records in SaveTree
        // Reader must be positioned at start of first RecordElement
        void ReadRecords(BinaryReader reader)
        {
            RecordDictionary.Clear();
            RootRecord = new SaveTreeBaseRecord();
            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                // Read record length and skip empty records as they have no data
                int length = reader.ReadInt32();
                if (length <= 0)
                    continue;

                // Handle potential stream overflow (e.g. corrupt save, something went wrong)
                if (reader.BaseStream.Position + length >= reader.BaseStream.Length)
                    break;

                // Peek record type from RecordRoot so we can instantiate record class based on type
                RecordTypes type = PeekRecordType(reader);

                // Add record based on type
                SaveTreeBaseRecord record;
                switch (type)
                {
                    case RecordTypes.Item:
                        record = new ItemRecord(reader, length);
                        break;
                    case RecordTypes.Spell:
                        record = new SpellRecord(reader, length);
                        break;
                    case RecordTypes.Character:
                        record = new CharacterRecord(reader, length);
                        break;
                    case RecordTypes.Container:
                        record = new ContainerRecord(reader, length);
                        break;
                    //case RecordTypes.UnknownTownLink:
                    //    record = new SaveTreeBaseRecord(reader, length);    // Read then skip these records for now
                    //    continue;
                    //case RecordTypes.DungeonData:
                    //    record = new SaveTreeBaseRecord(reader, length);    // Read then skip these records for now
                    //    continue;
                    default:
                        record = new SaveTreeBaseRecord(reader, length);
                        break;
                }
                AddRecord(record);
            }

            LinkChildren();
        }