Ejemplo n.º 1
0
        public override void SyncPlayer(int toWho, int fromWho, bool newPlayer)
        {
            ModPacket   packet    = mod.GetPacket();
            int         cnt       = 0;
            TagCompound research2 = new TagCompound();
            IEnumerator <KeyValuePair <string, object> > enume = research.GetEnumerator();

            enume.Reset();
            while (enume.MoveNext())
            {
                research2[enume.Current.Key] = research.GetAsInt(enume.Current.Key);
                cnt += (enume.Current.Key.ToByteArray().Length / 128) + 1;
                if (cnt >= 500)
                {
                    packet.Write((byte)0);
                    packet.Write((byte)player.whoAmI);
                    TagIO.Write(research2, packet);
                    packet.Send(toWho, fromWho);
                    cnt    = 0;
                    packet = mod.GetPacket();
                    research2.Clear();
                }
            }
            if (cnt > 0)
            {
                packet.Write((byte)0);
                packet.Write((byte)player.whoAmI);
                TagIO.Write(research2, packet);
                packet.Send(toWho, fromWho);
            }
            packet = mod.GetPacket();
            packet.Write((byte)1);
            packet.Write((byte)player.whoAmI);
            packet.Send(toWho, fromWho);
        }
Ejemplo n.º 2
0
        public override void NetReceive(BinaryReader reader, bool lightReceive)
        {
            TagCompound tag = TagIO.Read(reader);

            energy = new EnergyCore(tag.GetAsInt("maxEnergy"));
            energy.addEnergy(tag.GetAsInt("energy"));
        }
Ejemplo n.º 3
0
 public static void SyncQEReceive(BinaryReader reader, int sender)
 {
     if (Main.netMode == NetmodeID.Server)
     {
         PortableStorage.Instance.GetModWorld <PSWorld>().Load(TagIO.Read(reader));
     }
 }
Ejemplo n.º 4
0
        public static void ReceiveCablePlacement(BinaryReader reader, int sender)
        {
            TagCompound tag      = TagIO.Read(reader);
            Point16     position = tag.Get <Point16>("Position");
            string      name     = tag.GetString("Name");

            Cable cable = new Cable();

            cable.SetDefaults(name);
            cable.position = position;
            cable.layer    = PTWorld.Instance.layer;
            cable.grid     = new CableGrid
            {
                energy = new EnergyStorage(cable.MaxIO * 2, cable.MaxIO),
                tiles  = new List <Cable> {
                    cable
                }
            };
            PTWorld.Instance.layer.Add(position, cable);

            cable.Merge();
            cable.Frame();

            foreach (Cable merge in Cable.sides.Select(x => x + position).Where(PTWorld.Instance.layer.ContainsKey).Select(x => PTWorld.Instance.layer[x]).Where(x => x.name == name))
            {
                merge.Frame();
            }

            if (Main.netMode == NetmodeID.Server)
            {
                SendCablePlacement(cable, sender);
            }
        }
Ejemplo n.º 5
0
        public override void NetSend(BinaryWriter writer, bool lightSend)
        {
            var pair   = TileUtils.tileToEntity.First(p => p.Value.GetType() == this.GetType());
            int entity = pair.Key;

            TagIO.WriteTag(TileUtils.tileToStructureName[entity], pair.Value.Save(), writer);
        }
        private static void CtorModWorlData(On.Terraria.GameContent.UI.Elements.UIWorldListItem.orig_ctor orig, UIWorldListItem self, WorldFileData data, int snapPointIndex)
        {
            orig(self, data, snapPointIndex);

            if (!SGAConfigClient.Instance.PlayerWorldData)
            {
                return;
            }

            string      path = data.Path.Replace(".wld", ".twld");
            TagCompound tag;

            try
            {
                byte[] buffer = FileUtilities.ReadAllBytes(path, data.IsCloudSave);
                tag = TagIO.FromStream(new MemoryStream(buffer), true);
            }
            catch
            {
                tag = null;
            }

            TagCompound tag2 = tag?.GetList <TagCompound>("modData").FirstOrDefault(testby => testby.GetString("mod") == "SGAmod" && testby.GetString("name") == "SGAWorld");
            TagCompound tag3 = tag2?.Get <TagCompound>("data");

            SGAmodData.Add(self, tag3);
        }
Ejemplo n.º 7
0
        internal static bool LoadFile(string path, Mod mod, bool fullPath = false)
        {
            TagCompound tag;

            if (!fullPath)
            {
                var stream = mod.GetFileStream(path);
                tag = TagIO.FromStream(stream);
                stream.Close();
            }

            else
            {
                tag = TagIO.FromFile(path);
            }

            if (tag is null)
            {
                StructureHelper.Instance.Logger.Warn("Structure was unable to be found. Are you passing the correct path?");
                return(false);
            }

            StructureDataCache.Add(path, tag);
            return(true);
        }
Ejemplo n.º 8
0
        public override void NetSend(BinaryWriter writer, bool lightSend)
        {
            TagCompound tag = new TagCompound();

            tag.Add("energy", energy.getCurrentEnergyLevel());
            tag.Add("maxEnergy", energy.getMaxEnergyLevel());
            TagIO.Write(tag, writer);
        }
        }                                //ModContent.GetInstance<DimensionKeeperMod>();

        public override TagCompound GetTagCompound()
        {
            var bytes       = Mod.GetFileBytes(FileResourcePath);
            var stream      = new MemoryStream(bytes);
            var tagCompound = TagIO.FromStream(stream);

            return(tagCompound);
        }
Ejemplo n.º 10
0
        private TagCompound AfterIO(TagCompound tag)
        {
            var stream = new MemoryStream();

            TagIO.ToStream(tag, stream);
            stream.Position = 0;
            return(TagIO.FromStream(stream));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Called whenever dimension is loading provided that the world tag compound does not contain saved the dimension with this id.
        /// This used to initialize dimension in the first time.
        /// </summary>
        /// <returns>A new dimension</returns>
        public virtual TDimension InitializeTag()
        {
            var tagCompound = GetTagCompound();

            SavedDimensionsTag.Add(Id, tagCompound);
            var dimension = TagIO.Deserialize <TDimension>(tagCompound);

            return(dimension);
        }
        /// <summary>
        /// Send the TagCompound in binary over the network to the client, make thing easier
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="lightSend"></param>
        public sealed override void NetSend(BinaryWriter writer, bool lightSend)
        {
            MemoryStream stream = new MemoryStream(65536);

            EnergyContainer.WriteTagCompound(tag);
            TagIO.ToStream(tag, stream, true);
            writer.Write((ushort)stream.Length);
            writer.Write(stream.ToArray());
        }
        /// <summary>
        /// The client receive the tag compound from the server and sync it
        /// </summary>
        /// <param name="trueReader"></param>
        /// <param name="lightReceive"></param>
        public sealed override void NetReceive(BinaryReader trueReader, bool lightReceive)
        {
            int          len    = trueReader.ReadUInt16();
            MemoryStream stream = new MemoryStream(trueReader.ReadBytes(len));

            tag = TagIO.FromStream(stream, true);
            ErrorLogger.Log(tag.Count);
            EnergyContainer.ReadTagCompound(tag);
        }
Ejemplo n.º 14
0
        public override void NetReceive(BinaryReader reader)
        {
            int count = reader.ReadInt32();

            using (MemoryStream stream = new MemoryStream(reader.ReadBytes(count)))
            {
                Load(TagIO.FromStream(stream));
            }
        }
Ejemplo n.º 15
0
 public override void Load()
 {
     if (System.IO.File.Exists(ModLoader.ModPath.Replace("Mods", "SavedStructures") + "/TestWandCache"))
     {
         TagCompound tag = TagIO.FromFile(ModLoader.ModPath.Replace("Mods", "SavedStructures") + "/TestWandCache");
         PreviewWidth  = tag.GetInt("Width");
         PreviewHeight = tag.GetInt("Height");
     }
 }
Ejemplo n.º 16
0
        public override void NetReceive(BinaryReader reader, bool lightReceive)
        {
            int count = (int)reader.ReadUInt16();

            this.tag = TagIO.FromStream((Stream) new MemoryStream(reader.ReadBytes(count)), true);
            ErrorLogger.Log((object)this.tag.Count, false);
            storage.ReadTagCompound(this.tag);
            ReadDataToTagCompound();
        }
Ejemplo n.º 17
0
        public override void SyncPlayer(int toWho, int fromWho, bool newPlayer)
        {
            ModPacket packet = mod.GetPacket();

            packet.Write((byte)0);
            packet.Write((byte)player.whoAmI);
            TagIO.Write(parts, packet);
            packet.Send(toWho, fromWho);
        }
Ejemplo n.º 18
0
 public static void SyncQE()
 {
     if (Main.netMode == NetmodeID.MultiplayerClient)
     {
         ModPacket packet = PortableStorage.Instance.GetPacket();
         packet.Write((byte)MessageType.SyncQE);
         TagIO.Write(PortableStorage.Instance.GetModWorld <PSWorld>().Save(), packet);
         packet.Send();
     }
 }
Ejemplo n.º 19
0
 public override void NetSend(BinaryWriter writer)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         TagIO.ToStream(Save(), stream);
         byte[] data = stream.ToArray();
         writer.Write(data.Length);
         writer.Write(data);
     }
 }
Ejemplo n.º 20
0
        public override void NetSend(BinaryWriter writer, bool lightSend)
        {
            MemoryStream memoryStream = new MemoryStream(65536);

            WriteDataToTagCompound();
            storage.WriteTagCompound(this.tag);
            TagIO.ToStream(this.tag, (Stream)memoryStream, true);
            writer.Write((ushort)memoryStream.Length);
            writer.Write(memoryStream.ToArray());
        }
Ejemplo n.º 21
0
        public override GlobalItem Clone()
        {
            MysteryGlobalItem clone = (MysteryGlobalItem)base.Clone();

            if (data != null)
            {
                clone.data = TagIO.Clone(data);
            }
            return(clone);
        }
Ejemplo n.º 22
0
        public override GlobalItem Clone()
        {
            UnloadedGlobalItem clone = (UnloadedGlobalItem)base.Clone();

            if (data != null)
            {
                clone.data = TagIO.Clone(data);
            }
            return(clone);
        }
Ejemplo n.º 23
0
        public override ItemInfo Clone()
        {
            var clone = (MysteryGlobalItemInfo)base.Clone();

            if (data != null)
            {
                clone.data = TagIO.Clone(data);
            }

            return(clone);
        }
Ejemplo n.º 24
0
        public static void ReceiveGridReform(BinaryReader reader, int sender)
        {
            TagCompound tag   = TagIO.Read(reader);
            Cable       cable = PTWorld.Instance.layer[tag.Get <Point16>("Position")];

            cable.grid.ReformGrid();

            if (Main.netMode == NetmodeID.Server)
            {
                SendGridReform(cable, sender);
            }
        }
Ejemplo n.º 25
0
 private void CheckNull()
 {
     if (savable == null)
     {
         try
         {
             savable = TagIO.FromFile(Path.Combine(Main.PlayerPath, sscfile));
         }
         catch { }
         savable = savable ?? new TagCompound();
     }
 }
Ejemplo n.º 26
0
        private bool CheckMentalMode(string path, bool isCloudSave)
        {
            path = Path.ChangeExtension(path, ".twld");
            if (!FileUtilities.Exists(path, isCloudSave))
            {
                return(false);
            }

            var buf = FileUtilities.ReadAllBytes(path, isCloudSave);
            var tag = TagIO.FromStream(new MemoryStream(buf));

            return(LoadModData(tag.GetList <TagCompound>("modData")));
        }
Ejemplo n.º 27
0
        public static void ReceiveGridMerge(BinaryReader reader, int sender)
        {
            TagCompound tag    = TagIO.Read(reader);
            Cable       cable1 = PTWorld.Instance.layer[tag.Get <Point16>("Position1")];
            Cable       cable2 = PTWorld.Instance.layer[tag.Get <Point16>("Position2")];

            cable1.grid.MergeGrids(cable2.grid);

            if (Main.netMode == NetmodeID.Server)
            {
                SendGridMerge(cable1, cable2, sender);
            }
        }
Ejemplo n.º 28
0
        public static string SaveTilesToBase64(Tile[,] tiles)
        {
            int oldX = Main.maxTilesX;
            int oldY = Main.maxTilesY;

            Tile[,] oldTiles = Main.tile;
            string base64result = "";

            try
            {
                Main.maxTilesX = tiles.GetLength(0);
                Main.maxTilesY = tiles.GetLength(1);
                Main.tile      = tiles;
                if (SaveTilesMethodInfo == null)
                {
                    SaveTilesMethodInfo = typeof(Main).Assembly.GetType("Terraria.ModLoader.IO.TileIO").GetMethod("SaveTiles", BindingFlags.Static | BindingFlags.NonPublic);
                }
                if (SaveWorldTilesVanillaMethodInfo == null)
                {
                    SaveWorldTilesVanillaMethodInfo = typeof(Main).Assembly.GetType("Terraria.IO.WorldFile").GetMethod("SaveWorldTiles", BindingFlags.Static | BindingFlags.NonPublic);
                }

                TagCompound ModTileData = (TagCompound)SaveTilesMethodInfo.Invoke(null, null);

                byte[] array = null;
                using (MemoryStream memoryStream = new MemoryStream(7000000))
                {
                    using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
                    {
                        int rval = (int)SaveWorldTilesVanillaMethodInfo.Invoke(null, new object[] { binaryWriter });
                        array = memoryStream.ToArray();
                    }
                }

                TagCompound result = new TagCompound()
                {
                    ["d"] = new Point16(Main.maxTilesX, Main.maxTilesY),
                    ["v"] = array,
                    ["m"] = ModTileData,
                };
                MemoryStream ms = new MemoryStream();
                TagIO.ToStream(result, ms, true);
                base64result = Convert.ToBase64String(ms.ToArray());
            }
            catch { }
            Main.maxTilesX = oldX;
            Main.maxTilesY = oldY;
            Main.tile      = oldTiles;
            return(base64result);
        }
Ejemplo n.º 29
0
        public static void ReceiveCableModification(BinaryReader reader, int sender)
        {
            TagCompound tag   = TagIO.Read(reader);
            Cable       cable = PTWorld.Instance.layer[tag.Get <Point16>("Position")];

            cable.connections = tag.GetList <bool>("Connections").ToList();
            cable.IO          = (IO)tag.GetInt("IO");
            cable.Frame();

            if (Main.netMode == NetmodeID.Server)
            {
                SendCableModification(cable, sender);
            }
        }
Ejemplo n.º 30
0
        public override void Save(TDimension dimension)
        {
            if (!Directory.Exists(ResourceFolderName))
            {
                Directory.CreateDirectory(ResourceFolderName);
            }
            if (File.Exists(FileResourcePath))
            {
                File.Delete(FileResourcePath);
            }

            var tag = (TagCompound)TagIO.Serialize(dimension);

            TagIO.ToFile(tag, FileResourcePath);
        }