private void StructureToCMD_Load(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { string path = openFileDialog1.FileName; List <string> pallets = new List <string>(); string cmds = ""; BinaryTagReader file = new BinaryTagReader(new FileStream(path, FileMode.Open)); var doc = file.ReadDocument(); foreach (TagCompound tag in doc.GetList("palette").Value) { string name = tag.GetStringValue("Name"); if (tag.Contains("Properties")) { name += "["; name += tag.GetCompound("Properties").Value.Select(x => x.Name + "=" + x.GetValue().ToString()).Aggregate((x, y) => x + "," + y); name += "]"; } pallets.Add(name); } foreach (TagCompound tag in doc.GetList("blocks").Value) { var pos2 = tag.GetList("pos").Value; var pos = pos2.Select(x => (int)x.GetValue()).ToArray(); cmds += $"/setblock ~{pos[0]} ~{pos[1]} ~{pos[2]} {pallets[tag.GetInt("state").Value]}\n"; } CodeBox.Text = cmds; } }
public void ReadDocument_should_handle_uncompressed_files() { // arrange var expected = CreateComplexData(); Stream stream = File.OpenRead(UncompressedComplexDataFileName); TagReader target = new BinaryTagReader(stream); // act var actual = target.ReadDocument(); // assert NbtAssert.Equal(expected, actual); }
private void Inspector_Load(object sender, EventArgs e) { bool good = false; if (File.Exists(path)) { good = true; } if (!good && openFileDialog1.ShowDialog() == DialogResult.OK) { good = true; path = openFileDialog1.FileName; } if (good) { Dictionary <string, string> mapRevert = new Dictionary <string, string>(); foreach (var key in Compiler.offuscationMap.Keys) { mapRevert[Compiler.offuscationMap[key]] = key; } BinaryTagReader file = new BinaryTagReader(new FileStream(path, FileMode.Open)); foreach (TagCompound i in file.ReadDocument().GetCompound("data").GetList("PlayerScores").Value) { var name = i.GetString("Name").Value; var objective = i.GetString("Objective").Value; var value = i.GetInt("Score").Value; if (mapRevert.ContainsKey(name)) { lst.Add(new Scoreboard(mapRevert[name], objective, GetValue(mapRevert[name], value))); } else if (mapRevert.ContainsKey(objective)) { lst.Add(new Scoreboard(name, mapRevert[objective], GetValue(mapRevert[objective], value))); } else { lst2.Add(new Scoreboard(name, objective, value.ToString())); } } file.Close(); } lst.Sort((x, y) => x.name.CompareTo(y.name)); lst2.Sort((x, y) => x.name.CompareTo(y.name)); Reload(); }
public void ReadDocument_should_handle_uncompressed_files() { // arrange TagReader target; TagCompound expected; TagCompound actual; Stream stream; expected = this.CreateComplexData(); stream = File.OpenRead(this.UncompressedComplexDataFileName); target = new BinaryTagReader(stream); // act actual = target.ReadDocument(); // assert NbtAssert.AreEqual(expected, actual); }