Exemplo n.º 1
0
        private void WriteAtomDeltasSection(PacketStream stream)
        {
            stream.WriteByte((byte)SectionID.AtomDeltas);
            stream.WriteUInt16((UInt16)DeltaState.AtomDeltas.Count);

            foreach (KeyValuePair <UInt32, DreamDeltaState.AtomDelta> atomDeltaPair in DeltaState.AtomDeltas)
            {
                UInt32 atomID = atomDeltaPair.Key;
                DreamDeltaState.AtomDelta atomDelta = atomDeltaPair.Value;

                stream.WriteUInt32(atomID);

                if (atomDelta.ScreenLocation.HasValue)
                {
                    stream.WriteByte((byte)AtomDeltaValueID.ScreenLocation);
                    stream.WriteScreenLocation(atomDelta.ScreenLocation.Value);
                }

                if (atomDelta.NewIconAppearanceID.HasValue)
                {
                    stream.WriteByte((byte)AtomDeltaValueID.IconAppearance);
                    stream.WriteUInt32((UInt32)atomDelta.NewIconAppearanceID.Value);
                }

                stream.WriteByte((byte)AtomDeltaValueID.End);
            }
        }
Exemplo n.º 2
0
        private void ReadAtomDeltasSection(PacketStream stream)
        {
            UInt16 atomDeltasCount = stream.ReadUInt16();

            for (int i = 0; i < atomDeltasCount; i++)
            {
                UInt32 atomID = stream.ReadUInt32();
                DreamDeltaState.AtomDelta atomDelta = new DreamDeltaState.AtomDelta();

                AtomDeltaValueID valueID;
                do
                {
                    valueID = (AtomDeltaValueID)stream.ReadByte();

                    if (valueID == AtomDeltaValueID.ScreenLocation)
                    {
                        atomDelta.ScreenLocation = stream.ReadScreenLocation();
                    }
                    else if (valueID == AtomDeltaValueID.IconAppearance)
                    {
                        atomDelta.NewIconAppearanceID = (int)stream.ReadUInt32();
                    }
                    else if (valueID != AtomDeltaValueID.End)
                    {
                        throw new Exception("Invalid atom delta value ID in delta game state packet (" + valueID.ToString() + ")");
                    }
                } while (valueID != AtomDeltaValueID.End);

                DeltaState.AtomDeltas.Add(atomID, atomDelta);
            }
        }
Exemplo n.º 3
0
        public void HandlePacketDeltaGameState(PacketDeltaGameState pDeltaGameState)
        {
            DreamDeltaState deltaState = pDeltaGameState.DeltaState;

            foreach (IconAppearance appearance in deltaState.NewIconAppearances)
            {
                Program.OpenDream.IconAppearances.Add(appearance);
            }

            foreach (KeyValuePair <UInt32, DreamDeltaState.AtomCreation> atomCreationPair in deltaState.AtomCreations)
            {
                UInt32 atomID = atomCreationPair.Key;
                DreamDeltaState.AtomCreation atomCreation = atomCreationPair.Value;

                if (!Program.OpenDream.ATOMs.ContainsKey(atomID))
                {
                    ATOM atom = new ATOM(atomID, atomCreation.Type, atomCreation.IconAppearanceID);

                    atom.Icon.Appearance = Program.OpenDream.IconAppearances[atomCreation.IconAppearanceID];
                    atom.ScreenLocation  = atomCreation.ScreenLocation;

                    if (atomCreation.LocationID != UInt32.MaxValue)
                    {
                        if (Program.OpenDream.ATOMs.ContainsKey(atomCreation.LocationID))
                        {
                            atom.Loc = Program.OpenDream.ATOMs[atomCreation.LocationID];
                        }
                        else
                        {
                            Console.WriteLine("Delta state packet gave a new atom an invalid location, so it was not assigned one (ID " + atomID + ")(Location ID " + atomCreation.LocationID + ")");
                        }
                    }
                    else
                    {
                        atom.Loc = null;
                    }
                }
                else
                {
                    Console.WriteLine("Delta state packet created a new atom that already exists, and was ignored (ID " + atomID + ")");
                }
            }

            foreach (UInt32 atomID in deltaState.AtomDeletions)
            {
                if (Program.OpenDream.ATOMs.ContainsKey(atomID))
                {
                    ATOM atom = Program.OpenDream.ATOMs[atomID];

                    atom.Loc = null;
                    Program.OpenDream.ATOMs.Remove(atomID);
                }
                else
                {
                    Console.WriteLine("Delta state packet gives an atom deletion for an invalid atom, and was ignored (ID " + atomID + ")");
                }
            }

            foreach (KeyValuePair <UInt32, DreamDeltaState.AtomDelta> atomDeltaPair in deltaState.AtomDeltas)
            {
                UInt32 atomID = atomDeltaPair.Key;
                DreamDeltaState.AtomDelta atomDelta = atomDeltaPair.Value;

                if (Program.OpenDream.ATOMs.ContainsKey(atomID))
                {
                    ATOM atom = Program.OpenDream.ATOMs[atomID];

                    if (atomDelta.NewIconAppearanceID.HasValue)
                    {
                        if (Program.OpenDream.IconAppearances.Count > atomDelta.NewIconAppearanceID.Value)
                        {
                            atom.Icon.Appearance = Program.OpenDream.IconAppearances[atomDelta.NewIconAppearanceID.Value];
                        }
                        else
                        {
                            Console.WriteLine("Invalid appearance ID " + atomDelta.NewIconAppearanceID.Value);
                        }
                    }

                    if (atomDelta.ScreenLocation.HasValue)
                    {
                        atom.ScreenLocation = atomDelta.ScreenLocation.Value;
                    }
                }
                else
                {
                    Console.WriteLine("Delta state packet contains delta values for an invalid ATOM, and was ignored (ID " + atomID + ")");
                }
            }

            foreach (DreamDeltaState.AtomLocationDelta atomLocationDelta in deltaState.AtomLocationDeltas)
            {
                if (Program.OpenDream.ATOMs.ContainsKey(atomLocationDelta.AtomID))
                {
                    ATOM atom = Program.OpenDream.ATOMs[atomLocationDelta.AtomID];

                    if (atomLocationDelta.LocationID != UInt32.MaxValue)
                    {
                        if (Program.OpenDream.ATOMs.ContainsKey(atomLocationDelta.LocationID))
                        {
                            atom.Loc = Program.OpenDream.ATOMs[atomLocationDelta.LocationID];
                        }
                        else
                        {
                            Console.WriteLine("Delta state packet gave an atom a new invalid location, so it was not changed (ID " + atomLocationDelta.AtomID + ")(Location ID " + atomLocationDelta.LocationID + ")");
                        }
                    }
                    else
                    {
                        atom.Loc = null;
                    }
                }
                else
                {
                    Console.WriteLine("Delta state packet contains a location delta for an invalid ATOM, and was ignored (ID " + atomLocationDelta.AtomID + ")");
                }
            }

            foreach (KeyValuePair <(int X, int Y), UInt32> turfDelta in deltaState.TurfDeltas)
            {
                int    x          = turfDelta.Key.X;
                int    y          = turfDelta.Key.Y;
                UInt32 turfAtomID = turfDelta.Value;

                if (Program.OpenDream.ATOMs.ContainsKey(turfAtomID))
                {
                    ATOM turf = Program.OpenDream.ATOMs[turfAtomID];

                    turf.X = x;
                    turf.Y = y;
                    Program.OpenDream.Map.Turfs[x, y] = turf;
                }
                else
                {
                    Console.WriteLine("Delta state packet sets a turf to an invalid atom, and was ignored (ID " + turfAtomID + ")(Location " + x + ", " + y + ")");
                }
            }

            if (pDeltaGameState.ClientDelta != null)
            {
                ApplyClientDelta(pDeltaGameState.ClientDelta);
            }
        }
Exemplo n.º 4
0
        public void HandlePacketDeltaGameState(PacketDeltaGameState pDeltaGameState)
        {
            DreamDeltaState deltaState = pDeltaGameState.DeltaState;

            foreach (IconAppearance appearance in deltaState.NewIconAppearances)
            {
                Program.OpenDream.IconAppearances.Add(appearance);
            }

            Dictionary <ATOM, UInt32> atomLocations = new();

            foreach (KeyValuePair <UInt32, DreamDeltaState.AtomCreation> atomCreationPair in deltaState.AtomCreations)
            {
                UInt32 atomID = atomCreationPair.Key;
                DreamDeltaState.AtomCreation atomCreation = atomCreationPair.Value;

                if (!Program.OpenDream.ATOMs.ContainsKey(atomID))
                {
                    ATOM atom = new ATOM(atomID, atomCreation.Type, atomCreation.IconAppearanceID);

                    atom.Icon.Appearance = Program.OpenDream.IconAppearances[atomCreation.IconAppearanceID];
                    atom.ScreenLocation  = atomCreation.ScreenLocation;
                    atomLocations.Add(atom, atomCreation.LocationID);
                }
                else
                {
                    Console.WriteLine("Delta state packet created a new atom that already exists, and was ignored (ID " + atomID + ")");
                }
            }

            foreach (KeyValuePair <ATOM, UInt32> atomLocation in atomLocations)
            {
                UInt32 locationId = atomLocation.Value;

                if (locationId != UInt32.MaxValue)
                {
                    if (Program.OpenDream.ATOMs.ContainsKey(locationId))
                    {
                        atomLocation.Key.Loc = Program.OpenDream.ATOMs[locationId];
                    }
                    else
                    {
                        Console.WriteLine("Full game state packet gave an atom an invalid location, which was ignored (ID " + atomLocation.Key.ID + ")(Location ID " + locationId + ")");
                    }
                }
                else
                {
                    atomLocation.Key.Loc = null;
                }
            }

            foreach (UInt32 atomID in deltaState.AtomDeletions)
            {
                if (Program.OpenDream.ATOMs.ContainsKey(atomID))
                {
                    ATOM atom = Program.OpenDream.ATOMs[atomID];

                    atom.Loc = null;
                    Program.OpenDream.ATOMs.Remove(atomID);
                }
                else
                {
                    Console.WriteLine("Delta state packet gives an atom deletion for an invalid atom, and was ignored (ID " + atomID + ")");
                }
            }

            foreach (KeyValuePair <UInt32, DreamDeltaState.AtomDelta> atomDeltaPair in deltaState.AtomDeltas)
            {
                UInt32 atomID = atomDeltaPair.Key;
                DreamDeltaState.AtomDelta atomDelta = atomDeltaPair.Value;

                if (Program.OpenDream.ATOMs.ContainsKey(atomID))
                {
                    ATOM atom = Program.OpenDream.ATOMs[atomID];

                    if (atomDelta.NewIconAppearanceID.HasValue)
                    {
                        if (Program.OpenDream.IconAppearances.Count > atomDelta.NewIconAppearanceID.Value)
                        {
                            atom.Icon.Appearance = Program.OpenDream.IconAppearances[atomDelta.NewIconAppearanceID.Value];
                        }
                        else
                        {
                            Console.WriteLine("Invalid appearance ID " + atomDelta.NewIconAppearanceID.Value);
                        }
                    }

                    if (atomDelta.ScreenLocation.HasValue)
                    {
                        atom.ScreenLocation = atomDelta.ScreenLocation.Value;
                    }
                }
                else
                {
                    Console.WriteLine("Delta state packet contains delta values for an invalid ATOM, and was ignored (ID " + atomID + ")");
                }
            }

            foreach (DreamDeltaState.AtomLocationDelta atomLocationDelta in deltaState.AtomLocationDeltas)
            {
                if (Program.OpenDream.ATOMs.ContainsKey(atomLocationDelta.AtomID))
                {
                    ATOM atom = Program.OpenDream.ATOMs[atomLocationDelta.AtomID];

                    if (atomLocationDelta.LocationID != UInt32.MaxValue)
                    {
                        if (Program.OpenDream.ATOMs.ContainsKey(atomLocationDelta.LocationID))
                        {
                            atom.Loc = Program.OpenDream.ATOMs[atomLocationDelta.LocationID];
                        }
                        else
                        {
                            Console.WriteLine("Delta state packet gave an atom a new invalid location, so it was not changed (ID " + atomLocationDelta.AtomID + ")(Location ID " + atomLocationDelta.LocationID + ")");
                        }
                    }
                    else
                    {
                        atom.Loc = null;
                    }
                }
                else
                {
                    Console.WriteLine("Delta state packet contains a location delta for an invalid ATOM, and was ignored (ID " + atomLocationDelta.AtomID + ")");
                }
            }

            foreach (KeyValuePair <(int X, int Y, int Z), UInt32> turfDelta in deltaState.TurfDeltas)
            {
                int    x          = turfDelta.Key.X;
                int    y          = turfDelta.Key.Y;
                int    z          = turfDelta.Key.Z;
                UInt32 turfAtomID = turfDelta.Value;

                if (z >= Program.OpenDream.Map.Levels.Count)   //Z-Level doesn't exist, create it
                {
                    while (Program.OpenDream.Map.Levels.Count <= z)
                    {
                        int levelWidth  = Program.OpenDream.Map.Levels[0].Turfs.GetLength(0);
                        int levelHeight = Program.OpenDream.Map.Levels[0].Turfs.GetLength(1);

                        Program.OpenDream.Map.Levels.Add(new Map.Level()
                        {
                            Turfs = new ATOM[levelWidth, levelHeight]
                        });
                    }
                }

                if (Program.OpenDream.ATOMs.ContainsKey(turfAtomID))
                {
                    ATOM turf = Program.OpenDream.ATOMs[turfAtomID];

                    turf.X = x;
                    turf.Y = y;
                    turf.Z = z;
                    Program.OpenDream.Map.Levels[z].Turfs[x, y] = turf;
                }
                else
                {
                    Console.WriteLine("Delta state packet sets a turf to an invalid atom, and was ignored (ID " + turfAtomID + ")(Location " + x + ", " + y + ", " + z + ")");
                }
            }

            if (pDeltaGameState.ClientDelta != null)
            {
                ApplyClientDelta(pDeltaGameState.ClientDelta);
            }
        }