示例#1
0
        public static SpriteUpdateMessage.NetMessage Deserialize(this NetworkReader reader)
        {
            var message = new SpriteUpdateMessage.NetMessage();

            SpriteUpdateMessage.SpriteUpdateEntry UnprocessedData = null;
            while (true)
            {
                UnprocessedData = null;
                bool ProcessSection = true;
                uint NetID          = reader.ReadUInt32();
                if (NetID == 0)
                {
                    break;
                }

                if (NetworkIdentity.spawned.ContainsKey(NetID) == false || NetworkIdentity.spawned[NetID] == null)
                {
                    ProcessSection = false;
                }

                string Name = reader.ReadString();
                if (ProcessSection == false ||
                    NetworkIdentity.spawned.ContainsKey(NetID) == false ||
                    SpriteHandlerManager.PresentSprites.ContainsKey(NetworkIdentity.spawned[NetID]) == false ||
                    SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]].ContainsKey(Name) == false)
                {
                    ProcessSection = false;
                }

                if (ProcessSection == false)
                {
                    UnprocessedData      = new SpriteUpdateMessage.SpriteUpdateEntry();
                    UnprocessedData.name = Name;
                    UnprocessedData.id   = NetID;
                }

                SpriteHandler SP = null;
                if (ProcessSection)
                {
                    SP = SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]][Name];
                }

                while (true)
                {
                    byte Operation = reader.ReadByte();

                    if (Operation == 255)
                    {
                        if (ProcessSection == false)
                        {
                            SpriteUpdateMessage.UnprocessedData.Add(UnprocessedData);
                        }

                        break;
                    }

                    if (Operation == 1)
                    {
                        int SpriteID = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.SetSpriteSO(SpriteCatalogue.Instance.Catalogue[SpriteID], Network: false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PresentSpriteSet);
                            UnprocessedData.arg.Add(SpriteID);
                        }
                    }


                    if (Operation == 2)
                    {
                        int Variant = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.ChangeSpriteVariant(Variant, NetWork: false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.VariantIndex);
                            UnprocessedData.arg.Add(Variant);
                        }
                    }

                    if (Operation == 3)
                    {
                        int Sprite = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.ChangeSprite(Sprite, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.CataloguePage);
                            UnprocessedData.arg.Add(Sprite);
                        }
                    }

                    if (Operation == 4)
                    {
                        int SpriteAnimate = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.AnimateOnce(SpriteAnimate, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.AnimateOnce);
                            UnprocessedData.arg.Add(SpriteAnimate);
                        }
                    }

                    if (Operation == 5)
                    {
                        if (ProcessSection)
                        {
                            SP.PushTexture(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushTexture);
                        }
                    }

                    if (Operation == 6)
                    {
                        if (ProcessSection)
                        {
                            SP.Empty(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Empty);
                        }
                    }


                    if (Operation == 7)
                    {
                        if (ProcessSection)
                        {
                            SP.PushClear(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushClear);
                        }
                    }

                    if (Operation == 8)
                    {
                        if (ProcessSection)
                        {
                            SP.ClearPallet(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.ClearPallet);
                        }
                    }


                    if (Operation == 9)
                    {
                        Color TheColour = reader.ReadColor();
                        if (ProcessSection)
                        {
                            SP.SetColor(TheColour, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.SetColour);
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.r * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.g * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.b * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.a * 255)));
                        }
                    }

                    if (Operation == 10)
                    {
                        int          paletteCount = reader.ReadByte();
                        List <Color> Colours      = new List <Color>();
                        for (int i = 0; i < paletteCount; i++)
                        {
                            Colours.Add(reader.ReadColor());
                        }

                        if (ProcessSection)
                        {
                            SP.SetPaletteOfCurrentSprite(Colours, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Pallet);
                            UnprocessedData.arg.Add(Convert.ToChar(paletteCount));
                            foreach (var color in Colours)
                            {
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.r * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.g * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.b * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.a * 255)));
                            }
                        }
                    }
                }
            }

            return(message);
        }
示例#2
0
        public static void Serialize(this NetworkWriter writer, SpriteUpdateMessage.NetMessage message)
        {
            foreach (var keyValuePair in message.Data)
            {
                var spriteChange = keyValuePair.Value;
                writer.WriteUInt32(keyValuePair.Key.GetMasterNetID().netId);
                writer.WriteString(keyValuePair.Key.name);

                if (spriteChange.PresentSpriteSet != -1)
                {
                    writer.WriteByte((byte)1);
                    writer.WriteInt32(spriteChange.PresentSpriteSet);
                }

                if (spriteChange.VariantIndex != -1)
                {
                    writer.WriteByte((byte)2);
                    writer.WriteInt32(spriteChange.VariantIndex);
                }

                if (spriteChange.CataloguePage != -1)
                {
                    writer.WriteByte((byte)3);
                    writer.WriteInt32(spriteChange.CataloguePage);
                }

                if (spriteChange.AnimateOnce)
                {
                    writer.WriteByte((byte)4);
                    writer.WriteInt32(spriteChange.CataloguePage);
                }

                if (spriteChange.PushTexture)
                {
                    writer.WriteByte((byte)5);
                }

                if (spriteChange.Empty)
                {
                    writer.WriteByte((byte)6);
                }

                if (spriteChange.PushClear)
                {
                    writer.WriteByte((byte)7);
                }

                if (spriteChange.ClearPallet)
                {
                    writer.WriteByte((byte)8);
                }

                if (spriteChange.SetColour != null)
                {
                    writer.WriteByte((byte)9);
                    writer.WriteColor(spriteChange.SetColour.Value);
                }

                if (spriteChange.Pallet != null)
                {
                    writer.WriteByte((byte)10);
                    writer.WriteByte((byte)spriteChange.Pallet.Count);
                    foreach (Color Colour in spriteChange.Pallet)
                    {
                        writer.WriteColor(Colour);
                    }
                }
                writer.WriteByte((byte)255);
            }
            writer.WriteUInt32(0);
        }
        public static SpriteUpdateMessage.NetMessage Deserialize(this NetworkReader reader)
        {
            var message = new SpriteUpdateMessage.NetMessage();

            SpriteUpdateMessage.SpriteUpdateEntry UnprocessedData = null;
            while (true)
            {
                UnprocessedData = null;
                bool ProcessSection = true;
                uint NetID          = reader.ReadUInt32();
                if (NetID == 0)
                {
                    break;
                }

                if (NetworkIdentity.spawned.ContainsKey(NetID) == false || NetworkIdentity.spawned[NetID] == null)
                {
                    ProcessSection = false;
                }

                string Name = reader.ReadString();
                if (ProcessSection == false ||
                    NetworkIdentity.spawned.ContainsKey(NetID) == false ||
                    SpriteHandlerManager.PresentSprites.ContainsKey(NetworkIdentity.spawned[NetID]) == false ||
                    SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]].ContainsKey(Name) == false)
                {
                    ProcessSection = false;
                }

                if (ProcessSection == false)
                {
                    UnprocessedData      = new SpriteUpdateMessage.SpriteUpdateEntry();
                    UnprocessedData.name = Name;
                    UnprocessedData.id   = NetID;
                }

                SpriteHandler SP = null;
                if (ProcessSection)
                {
                    SP = SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]][Name];
                }

                while (true)
                {
                    byte Operation = reader.ReadByte();

                    if (Operation == 255)
                    {
                        if (ProcessSection == false)
                        {
                            SpriteUpdateMessage.UnprocessedData.Add(UnprocessedData);
                        }

                        break;
                    }

                    if (Operation == 1)
                    {
                        int SpriteID = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            try
                            {
                                SP.SetSpriteSO(SpriteCatalogue.Instance.Catalogue[SpriteID], networked: false);
                            }
                            catch (Exception e)
                            {
                                Logger.Log("ddD");
                            }
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PresentSpriteSet);
                            UnprocessedData.arg.Add(SpriteID);
                        }
                    }


                    if (Operation == 2)
                    {
                        int Variant = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.ChangeSpriteVariant(Variant, networked: false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.VariantIndex);
                            UnprocessedData.arg.Add(Variant);
                        }
                    }

                    if (Operation == 3)
                    {
                        int Sprite = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.ChangeSprite(Sprite, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.CataloguePage);
                            UnprocessedData.arg.Add(Sprite);
                        }
                    }

                    if (Operation == 4)
                    {
                        int SpriteAnimate = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.AnimateOnce(SpriteAnimate, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.AnimateOnce);
                            UnprocessedData.arg.Add(SpriteAnimate);
                        }
                    }

                    if (Operation == 5)
                    {
                        if (ProcessSection)
                        {
                            SP.PushTexture(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushTexture);
                        }
                    }

                    if (Operation == 6)
                    {
                        if (ProcessSection)
                        {
                            SP.Empty(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Empty);
                        }
                    }


                    if (Operation == 7)
                    {
                        if (ProcessSection)
                        {
                            SP.PushClear(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushClear);
                        }
                    }

                    if (Operation == 8)
                    {
                        if (ProcessSection)
                        {
                            SP.ClearPalette(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.ClearPallet);
                        }
                    }


                    if (Operation == 9)
                    {
                        Color TheColour = reader.ReadColor();
                        if (ProcessSection)
                        {
                            if (SP)
                            {
                                //TODO: remove this check - registering arrives after the sprite update, all clients will disconnect after a runtime
                                //removing and readding a bodypart through surgery would cause it, since the network identity already exists unlike the creation of a new human
                                SP.SetColor(TheColour, false);
                            }
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.SetColour);
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.r * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.g * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.b * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.a * 255)));
                        }
                    }

                    if (Operation == 10)
                    {
                        int          paletteCount = reader.ReadByte();
                        List <Color> Colours      = new List <Color>();
                        for (int i = 0; i < paletteCount; i++)
                        {
                            Colours.Add(reader.ReadColor());
                        }

                        if (ProcessSection)
                        {
                            SP.SetPaletteOfCurrentSprite(Colours, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Pallet);
                            UnprocessedData.arg.Add(Convert.ToChar(paletteCount));
                            foreach (var color in Colours)
                            {
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.r * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.g * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.b * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.a * 255)));
                            }
                        }
                    }
                }
            }

            return(message);
        }