예제 #1
0
        public void Read(BinaryReader reader)
        {
            InSession = reader.ReadBoolean();
            if (!InSession)
            {
                return;
            }

            byte bools;
            int  count;

            if (reader.ReadBoolean())
            {
                ChunkEAudioState audio = new ChunkEAudioState();
                audio.Read(reader);
                Audio = audio.Audio;
            }

            if (reader.ReadBoolean())
            {
                RespawnPoint = new Vector2(reader.ReadSingle(), reader.ReadSingle());
            }

            Inventory           = new PlayerInventory();
            bools               = reader.ReadByte();
            Inventory.Backpack  = UnpackBool(bools, 0);
            Inventory.DreamDash = UnpackBool(bools, 1);
            Inventory.NoRefills = UnpackBool(bools, 2);
            Inventory.Dashes    = reader.ReadByte();

            Flags = new HashSet <string>();
            count = reader.ReadByte();
            for (int i = 0; i < count; i++)
            {
                Flags.Add(reader.ReadNullTerminatedString());
            }

            LevelFlags = new HashSet <string>();
            count      = reader.ReadByte();
            for (int i = 0; i < count; i++)
            {
                LevelFlags.Add(reader.ReadNullTerminatedString());
            }

            Strawberries = new HashSet <EntityID>();
            count        = reader.ReadByte();
            for (int i = 0; i < count; i++)
            {
                Strawberries.Add(new EntityID(reader.ReadNullTerminatedString(), reader.ReadInt32()));
            }

            DoNotLoad = new HashSet <EntityID>();
            count     = reader.ReadByte();
            for (int i = 0; i < count; i++)
            {
                DoNotLoad.Add(new EntityID(reader.ReadNullTerminatedString(), reader.ReadInt32()));
            }

            Keys  = new HashSet <EntityID>();
            count = reader.ReadByte();
            for (int i = 0; i < count; i++)
            {
                Keys.Add(new EntityID(reader.ReadNullTerminatedString(), reader.ReadInt32()));
            }

            Counters = new List <Session.Counter>();
            count    = reader.ReadByte();
            for (int i = 0; i < count; i++)
            {
                Counters.Add(new Session.Counter {
                    Key   = reader.ReadNullTerminatedString(),
                    Value = reader.ReadInt32()
                });
            }

            FurthestSeenLevel = reader.ReadNullTerminatedString()?.Nullify();
            StartCheckpoint   = reader.ReadNullTerminatedString()?.Nullify();
            ColorGrade        = reader.ReadNullTerminatedString()?.Nullify();

            count      = reader.ReadByte();
            SummitGems = new bool[count];
            for (int i = 0; i < count; i++)
            {
                if ((i % 8) == 0)
                {
                    bools = reader.ReadByte();
                }
                SummitGems[i] = UnpackBool(bools, i % 8);
            }

            bools         = reader.ReadByte();
            FirstLevel    = UnpackBool(bools, 0);
            Cassette      = UnpackBool(bools, 1);
            HeartGem      = UnpackBool(bools, 2);
            Dreaming      = UnpackBool(bools, 3);
            GrabbedGolden = UnpackBool(bools, 4);
            HitCheckpoint = UnpackBool(bools, 5);

            LightingAlphaAdd = reader.ReadSingle();
            BloomBaseAdd     = reader.ReadSingle();
            DarkRoomAlpha    = reader.ReadSingle();

            Time = reader.ReadInt64();

            CoreMode = (Session.CoreModes)reader.ReadByte();
        }
예제 #2
0
        public void Write(BinaryWriter writer)
        {
            if (!InSession)
            {
                writer.Write(false);
                return;
            }
            writer.Write(true);

            byte bools;

            if (Audio != null)
            {
                writer.Write(true);
                ChunkEAudioState audio = new ChunkEAudioState(Audio);
                audio.Write(writer);
            }
            else
            {
                writer.Write(false);
            }

            if (RespawnPoint != null)
            {
                writer.Write(true);
                writer.Write(RespawnPoint.Value.X);
                writer.Write(RespawnPoint.Value.Y);
            }
            else
            {
                writer.Write(false);
            }

            writer.Write(PackBools(Inventory.Backpack, Inventory.DreamDash, Inventory.NoRefills));
            writer.Write((byte)Inventory.Dashes);

            writer.Write((byte)Flags.Count);
            foreach (string value in Flags)
            {
                writer.WriteNullTerminatedString(value);
            }

            writer.Write((byte)LevelFlags.Count);
            foreach (string value in LevelFlags)
            {
                writer.WriteNullTerminatedString(value);
            }

            writer.Write((byte)Strawberries.Count);
            foreach (EntityID value in Strawberries)
            {
                writer.WriteNullTerminatedString(value.Level);
                writer.Write(value.ID);
            }

            writer.Write((byte)DoNotLoad.Count);
            foreach (EntityID value in DoNotLoad)
            {
                writer.WriteNullTerminatedString(value.Level);
                writer.Write(value.ID);
            }

            writer.Write((byte)Keys.Count);
            foreach (EntityID value in Keys)
            {
                writer.WriteNullTerminatedString(value.Level);
                writer.Write(value.ID);
            }

            writer.Write((byte)Counters.Count);
            foreach (Session.Counter value in Counters)
            {
                writer.WriteNullTerminatedString(value.Key);
                writer.Write(value.Value);
            }

            writer.WriteNullTerminatedString(FurthestSeenLevel);
            writer.WriteNullTerminatedString(StartCheckpoint);
            writer.WriteNullTerminatedString(ColorGrade);

            writer.Write((byte)SummitGems.Length);
            bools = 0;
            for (int i = 0; i < SummitGems.Length; i++)
            {
                bools = PackBool(bools, i % 8, SummitGems[i]);
                if (((i + 1) % 8) == 0)
                {
                    writer.Write(bools);
                    bools = 0;
                }
            }
            if (SummitGems.Length % 8 != 0)
            {
                writer.Write(bools);
            }

            writer.Write(PackBools(FirstLevel, Cassette, HeartGem, Dreaming, GrabbedGolden, HitCheckpoint));

            writer.Write(LightingAlphaAdd);
            writer.Write(BloomBaseAdd);
            writer.Write(DarkRoomAlpha);

            writer.Write(Time);

            writer.Write((byte)CoreMode);
        }