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); }
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); }
} //ModContent.GetInstance<DimensionKeeperMod>(); public override TagCompound GetTagCompound() { var bytes = Mod.GetFileBytes(FileResourcePath); var stream = new MemoryStream(bytes); var tagCompound = TagIO.FromStream(stream); return(tagCompound); }
private TagCompound AfterIO(TagCompound tag) { var stream = new MemoryStream(); TagIO.ToStream(tag, stream); stream.Position = 0; return(TagIO.FromStream(stream)); }
/// <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); }
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(); }
public override void NetReceive(BinaryReader reader) { int count = reader.ReadInt32(); using (MemoryStream stream = new MemoryStream(reader.ReadBytes(count))) { Load(TagIO.FromStream(stream)); } }
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"))); }
private void AddWorldData(On.Terraria.GameContent.UI.Elements.UIWorldListItem.orig_ctor orig, UIWorldListItem self, WorldFileData data, int snapPointIndex) { orig(self, data, snapPointIndex); string path = data.Path.Replace(".wld", ".twld"); TagCompound tag; try { byte[] buf = FileUtilities.ReadAllBytes(path, data.IsCloudSave); tag = TagIO.FromStream(new MemoryStream(buf), true); } catch { tag = null; } TagCompound tag2 = tag?.GetList <TagCompound>("modData").FirstOrDefault(k => k.GetString("mod") == "StarlightRiver" && k.GetString("name") == "StarlightWorld"); TagCompound tag3 = tag2?.Get <TagCompound>("data"); worldDataCache.Add(self, tag3); }
private static void UIWorldListItemOnctor(On.Terraria.GameContent.UI.Elements.UIWorldListItem.orig_ctor orig, Terraria.GameContent.UI.Elements.UIWorldListItem self, WorldFileData data, int snappointindex) { orig(self, data, snappointindex); try { string path = Path.ChangeExtension(data.Path, ".twld"); if (File.Exists(path)) { var buf = FileUtilities.ReadAllBytes(path, data.IsCloudSave); var tag = TagIO.FromStream(new MemoryStream(buf)); var list = tag.GetList <TagCompound>("modData").FirstOrDefault((TagCompound m) => m.Get <string>("mod") == "TUA" && m.Get <string>("name") == "TUAWorld"); if (list != null) { TUAWorldData.Add(data.UniqueId, tag.GetList <TagCompound>("modData").FirstOrDefault((TagCompound m) => m.Get <string>("mod") == "TUA" && m.Get <string>("name") == "TUAWorld")); } } } catch (Exception e) { ErrorLogger.Log(e.Message); } }
public static Tile[,] LoadTilesFromBase64(string data) { int oldX = Main.maxTilesX; int oldY = Main.maxTilesY; Tile[,] oldTiles = Main.tile; Tile[,] loadedTiles = new Tile[0, 0]; try { TagCompound tagCompound = TagIO.FromStream(new MemoryStream(Convert.FromBase64String(data))); if (LoadTilesMethodInfo == null) { LoadTilesMethodInfo = typeof(Main).Assembly.GetType("Terraria.ModLoader.IO.TileIO").GetMethod("LoadTiles", BindingFlags.Static | BindingFlags.NonPublic); } if (LoadWorldTilesVanillaMethodInfo == null) { LoadWorldTilesVanillaMethodInfo = typeof(Main).Assembly.GetType("Terraria.IO.WorldFile").GetMethod("LoadWorldTiles", BindingFlags.Static | BindingFlags.NonPublic); } bool[] importance = new bool[TileID.Count]; for (int i = 0; i < TileID.Count; i++) { importance[i] = Main.tileFrameImportant[i]; } Point16 dimensions = tagCompound.Get <Point16>("d"); Main.maxTilesX = dimensions.X; Main.maxTilesY = dimensions.Y; loadedTiles = new Tile[Main.maxTilesX, Main.maxTilesY]; for (int i = 0; i < Main.maxTilesX; i++) { for (int j = 0; j < Main.maxTilesY; j++) { loadedTiles[i, j] = new Tile(); } } Main.tile = loadedTiles; using (MemoryStream memoryStream = new MemoryStream(tagCompound.GetByteArray("v"))) { using (BinaryReader binaryReader = new BinaryReader(memoryStream)) { LoadWorldTilesVanillaMethodInfo.Invoke(null, new object[] { binaryReader, importance }); } } if (tagCompound.ContainsKey("m")) { LoadTilesMethodInfo.Invoke(null, new object[] { tagCompound["m"] }); } // Expand because TileFrame ignores edges of map. Main.maxTilesX = dimensions.X + 12; Main.maxTilesY = dimensions.Y + 12; Tile[,] loadedTilesExpanded = new Tile[Main.maxTilesX, Main.maxTilesY]; for (int i = 0; i < Main.maxTilesX; i++) { for (int j = 0; j < Main.maxTilesY; j++) { if (i < 6 || i >= Main.maxTilesX - 6 || j < 6 || j >= Main.maxTilesY - 6) { loadedTilesExpanded[i, j] = new Tile(); } else { loadedTilesExpanded[i, j] = Main.tile[i - 6, j - 6]; } } } Main.tile = loadedTilesExpanded; for (int i = 0; i < Main.maxTilesX; i++) { for (int j = 0; j < Main.maxTilesY; j++) { //WorldGen.TileFrame(i, j, true, false); //if (i > 5 && j > 5 && i < Main.maxTilesX - 5 && j < Main.maxTilesY - 5 // 0 needs to be 6 , MaxX == 5, 4 index, // need tp add 6? 4(10) < 5(11) - 5 if (Main.tile[i, j].active()) { WorldGen.TileFrame(i, j, true, false); } if (Main.tile[i, j].wall > 0) { Framing.WallFrame(i, j, true); } } } } catch { } Main.maxTilesX = oldX; Main.maxTilesY = oldY; Main.tile = oldTiles; return(loadedTiles); }
private void ProfessionalText(On.Terraria.GameContent.UI.Elements.UIWorldListItem.orig_DrawSelf orig, Terraria.GameContent.UI.Elements.UIWorldListItem self, SpriteBatch spriteBatch) { orig(self, spriteBatch); FieldInfo dataInfo = self.GetType().GetField("_data", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo worldIconInfo = self.GetType().GetField("_worldIcon", BindingFlags.NonPublic | BindingFlags.Instance); WorldFileData fileData = (WorldFileData)dataInfo.GetValue(self); UIImage worldIcon = (UIImage)worldIconInfo.GetValue(self); string filePath = fileData.Path.Replace(".wld", ".twld"); //remember .wld exists ahh TagCompound tagCompound1; try { byte[] bytes = FileUtilities.ReadAllBytes(filePath, fileData.IsCloudSave); tagCompound1 = TagIO.FromStream(new MemoryStream(bytes), true); } catch { tagCompound1 = null; } TagCompound tagCompound2 = tagCompound1?.GetList <TagCompound>("modData").FirstOrDefault(i => i.GetString("mod") == "SpectraMod" && i.GetString("name") == "SpectraWorld"); //allow null TagCompound tagCompound3 = tagCompound2?.Get <TagCompound>("data"); CalculatedStyle innerDimensions = self.GetInnerDimensions(); CalculatedStyle dimensions = worldIcon.GetDimensions(); float num7 = dimensions.X + dimensions.Width; Color color = fileData.IsValid ? Color.White : Color.Red; Utils.DrawBorderString(spriteBatch, fileData.Name, new Vector2(num7 + 6f, dimensions.Y - 2f), color); spriteBatch.Draw(TextureManager.Load("Images/UI/Divider"), new Vector2(num7, innerDimensions.Y + 21f), null, Color.White, 0f, Vector2.Zero, new Vector2((self.GetDimensions().X + self.GetDimensions().Width - num7) / 8f, 1f), SpriteEffects.None, 0f); Vector2 vector = new Vector2(num7 + 6f, innerDimensions.Y + 29f); float num6 = 100f; DrawPanel(spriteBatch, vector, num6); bool?IsProfessionalMode = tagCompound3?.GetBool("IsProfessionalMode"); if (IsProfessionalMode == null) { IsProfessionalMode = false; } string text; if ((bool)IsProfessionalMode) { text = "Professional"; } else if (fileData.IsExpertMode && (bool)!IsProfessionalMode) { text = Language.GetTextValue("UI.Expert"); } else { text = Language.GetTextValue("UI.Normal"); } float x11 = Main.fontMouseText.MeasureString(text).X; float x10 = num6 * 0.5f - x11 * 0.5f; if ((bool)IsProfessionalMode) { text = "Professional"; } else if (fileData.IsExpertMode && (bool)!IsProfessionalMode) { text = Language.GetTextValue("UI.Expert"); } else { text = Language.GetTextValue("UI.Normal"); } Color difficultyColor; if ((bool)IsProfessionalMode) { difficultyColor = new Color(255, 0, 0); } else if (fileData.IsExpertMode && (bool)!IsProfessionalMode) { difficultyColor = new Color(217, 143, 244); } else { difficultyColor = Color.White; } Utils.DrawBorderString(spriteBatch, text, vector + new Vector2(x10, 3f), difficultyColor); vector.X += num6 + 5f; float num5 = 150f; if (!GameCulture.English.IsActive) { num5 += 40f; } DrawPanel(spriteBatch, vector, num5); string textValue3 = Language.GetTextValue("UI.WorldSizeFormat", fileData.WorldSizeName); float x9 = Main.fontMouseText.MeasureString(textValue3).X; float x8 = num5 * 0.5f - x9 * 0.5f; Utils.DrawBorderString(spriteBatch, textValue3, vector + new Vector2(x8, 3f), Color.White); vector.X += num5 + 5f; float num4 = innerDimensions.X + innerDimensions.Width - vector.X; DrawPanel(spriteBatch, vector, num4); string arg = (!GameCulture.English.IsActive) ? fileData.CreationTime.ToShortDateString() : fileData.CreationTime.ToString("d MMMM yyyy"); string textValue2 = Language.GetTextValue("UI.WorldCreatedFormat", arg); float x7 = Main.fontMouseText.MeasureString(textValue2).X; float x6 = num4 * 0.5f - x7 * 0.5f; Utils.DrawBorderString(spriteBatch, textValue2, vector + new Vector2(x6, 3f), Color.White); vector.X += num4 + 5f; }