private int GetFMLItemID(string filename, string modid, string itemname, FMLItemType itemType) { if (!File.Exists(filename)) { throw new FileNotFoundException("level.datが見つかりません。"); } if (string.Empty == modid || string.Empty == itemname) { return(-1); } string fmlKeyName = ((itemType == FMLItemType.Block) ? "\u0001" : "\u0002") + modid + ":" + itemname; fNbt.NbtFile nbt = new fNbt.NbtFile(filename); fNbt.NbtList idList = fNbt.NbtQuery.Get <fNbt.NbtList>(nbt.RootTag, "//FML/ItemData"); foreach (fNbt.NbtCompound itemData in idList) { if (itemData.Get <fNbt.NbtString>("K").Value == fmlKeyName) { return(itemData.Get <fNbt.NbtInt>("V").Value); } } return(-1); }
private bool CheckModID(string filename, string modid) { if (!File.Exists(filename)) { throw new FileNotFoundException("level.datが見つかりません。"); } if (string.Empty == modid) { return(false); } fNbt.NbtFile nbt = new fNbt.NbtFile(filename); fNbt.NbtList modList = fNbt.NbtQuery.Get <fNbt.NbtList>(nbt.RootTag, "//FML/ModList"); foreach (fNbt.NbtCompound mod in modList) { if (mod.Get <fNbt.NbtString>("ModId").Value == modid) { return(true); } } return(false); }
private void FixPlayerSackData(string nbtFile, string nbtOutputFile, string nbtPath) { fNbt.NbtFile nbt = new fNbt.NbtFile(nbtFile); fNbt.NbtList playerInv = fNbt.NbtQuery.Get <fNbt.NbtList>(nbt.RootTag, nbtPath); foreach (fNbt.NbtCompound item in playerInv) { FixItemSackData(item, int.Parse(itemSackID.Text)); } nbt.SaveToFile(nbtOutputFile, fNbt.NbtCompression.GZip); }
private void NbtLoad() { if (!File.Exists(inputPath.Text)) { return; } saveLevelDatButton.Enabled = false; updateLevelDatButton.Enabled = false; loadingNbtFilePath = inputPath.Text; levelNbt = new fNbt.NbtFile(); levelNbt.LoadFromFile(loadingNbtFilePath); }
public void SetRootNbt(fNbt.NbtCompound rootNbtCompound) { // NBTデータを更新した場合にはキャッシュ無効化 doUseCache = false; cacheCompressData = null; fNbt.NbtFile nbt = new fNbt.NbtFile(); nbt.RootTag = rootNbtCompound; using (MemoryStream nbtStream = new MemoryStream()) { nbt.SaveToStream(nbtStream, fNbt.NbtCompression.None); nbtStream.Close(); chunkNBTBinary = nbtStream.ToArray(); } }
protected override string GetWorldName(string folder) { string leveldat = Path.Combine(folder, "level.dat"); if (File.Exists(leveldat)) { try { var nbtfile = new fNbt.NbtFile(leveldat); return(nbtfile.RootTag["Data"]?["LevelName"]?.StringValue); } catch { return(null); } } return(null); }
public static void CreateReportFIle() { fNbt.NbtFile reportFile = new fNbt.NbtFile(new fNbt.NbtCompound("report")); string ticketniLog = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\Logs\\Ticketnik.log"; string errorLog = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\Logs\\Error.log"; string userConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath; reportFile.RootTag.Add(new fNbt.NbtByteArray("Ticketnik.log", File.ReadAllBytes(ticketniLog))); //MessageBox.Show(reportFile.RootTag.Count.ToString()); reportFile.RootTag.Add(new fNbt.NbtByteArray("Error.log", File.ReadAllBytes(errorLog))); reportFile.RootTag.Add(new fNbt.NbtString("user.config cesta", userConfig)); reportFile.RootTag.Add(new fNbt.NbtString("Cesta k tic", Properties.Settings.Default.filePath)); reportFile.RootTag.Add(new fNbt.NbtByteArray("Soubor", File.ReadAllBytes(Properties.Settings.Default.filePath))); reportFile.RootTag.Add(new fNbt.NbtByteArray("user.config", File.ReadAllBytes(userConfig))); reportFile.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Ticketnik_crash.report", fNbt.NbtCompression.GZip); }
public WorldControl(string worldfolder, Edition edition) { InitializeComponent(); WorldFolder = worldfolder; string icon; string name = ""; if (edition == Edition.Java) { icon = Path.Combine(worldfolder, "icon.png"); string leveldat = Path.Combine(worldfolder, "level.dat"); if (File.Exists(leveldat)) { try { var nbtfile = new fNbt.NbtFile(leveldat); name = nbtfile.RootTag["Data"]?["LevelName"]?.StringValue; } catch { } } } else { icon = Path.Combine(worldfolder, "world_icon.jpeg"); string namepath = Path.Combine(worldfolder, "levelname.txt"); if (File.Exists(namepath)) { name = File.ReadAllText(namepath); } } if (File.Exists(icon)) { try { WorldIcon.Image = Image.FromFile(icon); } catch { WorldIcon.Image = Properties.Resources.image_map_icon; } } WorldName.Text = name; FolderName.Text = Path.GetFileName(worldfolder); }
static void Main(string[] args) { TcpListener serverSocket = new TcpListener(8888); TcpClient clientSocket = default; serverSocket.Start(); byte[] bytesFrom = new byte[65536]; string FromClient; while (true) { clientSocket = serverSocket.AcceptTcpClient(); NetworkStream NetStream = clientSocket.GetStream(); NetStream.Read(bytesFrom, 0, clientSocket.ReceiveBufferSize); MemoryStream stream = new MemoryStream(); stream.Write(bytesFrom, 0, bytesFrom.Length); var rr = new fNbt.NbtFile(); rr.LoadFromBuffer(bytesFrom, 0, 65536, fNbt.NbtCompression.GZip); var root = rr.RootTag; switch ((ReqType)(root["Type"] as NbtInt).IntValue) { case ReqType.REGISTER: var uuid = Guid.NewGuid(); UserList.Add(uuid, new PUser { UserName = root["Data"]["UserName"].StringValue, NickName = root["Data"]["UserName"].StringValue, UUID = uuid, PassKey = root["Data"]["PassKey"].StringValue }); NetStream.Write(uuid.ToByteArray(), 0, uuid.ToByteArray().Length); break; } } }
public fNbt.NbtCompound GetRootNBT() { fNbt.NbtFile nbt = new fNbt.NbtFile(); nbt.LoadFromStream(new MemoryStream(chunkNBTBinary), fNbt.NbtCompression.None); return(nbt.RootTag); }
static void Main(string[] args) { Log.Reset(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException); if (File.Exists("DllUpdater.exe")) { File.Delete("DllUpdater.exe"); } FileVersionInfo fi = FileVersionInfo.GetVersionInfo("fNbt.dll"); if (Properties.Settings.Default.Lang == "" && fi.ProductVersion != Properties.Settings.Default.fNbtString) { //kvůli updatu z předchozích verzí File.WriteAllBytes("DllUpdater.exe", Properties.Resources.DllUpdater); Log.Write("Removing old fNbt.dll", Log.Verbosity.Info); Process.Start("DllUpdater.exe", "firstRun"); Application.Exit(); } if (Application.ProductVersion.Contains("dev")) { try { Log.Write("Copying CZ.xml", Log.Verbosity.Info); File.Copy("..\\..\\CZ.xml", "CZ.xml", true); } catch (Exception e) { Log.Write("CZ.xml copy failed\r\n" + e.Message, Log.Verbosity.Error); }; } if (!File.Exists("CZ.xml")) { try { Log.Write("Downloading CZ.xml", Log.Verbosity.Info); WebClient wc = new WebClient(); wc.DownloadFile("https://raw.githubusercontent.com/Caesar008/SaveEdit/master/SaveEdit/bin/Release/CZ.xml", "CZ.xml"); wc.Dispose(); } catch { } } if (!File.Exists("itemy.xml")) { try { WebClient wc = new WebClient(); wc.DownloadFile("https://raw.githubusercontent.com/Caesar008/SaveEdit/master/SaveEdit/bin/Release/itemy.xml", "itemy.xml"); wc.Dispose(); } catch { } } if (!File.Exists("items.png")) { try { WebClient wc = new WebClient(); wc.DownloadFile("https://raw.githubusercontent.com/Caesar008/SaveEdit/master/SaveEdit/bin/Release/items.png", "items.png"); wc.Dispose(); } catch { } } if (!File.Exists("terrain.png")) { try { WebClient wc = new WebClient(); wc.DownloadFile("https://raw.githubusercontent.com/Caesar008/SaveEdit/master/SaveEdit/bin/Release/terrain.png", "terrain.png"); wc.Dispose(); } catch { } } if (!File.Exists("ArmorSlotPics.png")) { try { WebClient wc = new WebClient(); wc.DownloadFile("https://raw.githubusercontent.com/Caesar008/SaveEdit/master/SaveEdit/bin/Release/ArmorSlotPics.png", "ArmorSlotPics.png"); wc.Dispose(); } catch { } } if (!Rozsirujici.Program.JednaInstance.BeziGlobalne(TimeSpan.FromSeconds(5), "Caesaruv SaveEdit")) { try { Log.Write("Starting Application Window", Log.Verbosity.Info); Application.Run(new Form1()); } catch (Exception e) { if (Application.ProductVersion.EndsWith("dev")) { Log.Write("Developer version crashed.", Log.Verbosity.Critical); MessageBox.Show(e.Message + "\r\n\r\n" + e.StackTrace); } else { Log.Write("SaveEdit crashed. Creating report file on Desktop", Log.Verbosity.Critical); fNbt.NbtFile reportFile = new fNbt.NbtFile(new fNbt.NbtCompound("report")); reportFile.RootTag.Add(new fNbt.NbtString("StackTrace", e.Message + "\r\n\r\n" + e.StackTrace)); string logFile = ""; if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SaveEdit\SaveEditLog.log")) { logFile = File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SaveEdit\SaveEditLog.log"); } reportFile.RootTag.Add(new fNbt.NbtString("LogFile", logFile)); if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SaveEdit\LastFile")) { reportFile.RootTag.Add(new fNbt.NbtByteArray("SaveFile", File.ReadAllBytes(File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SaveEdit\LastFile")))); } reportFile.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\SaveEdit_crash.report", fNbt.NbtCompression.GZip); MessageBox.Show(new Rozsirujici.Jazyk.Jazyk("CZ.xml").ReturnPreklad("Messages/ErrorCrash"), "SaveEdit", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { Log.Write("SaveEdit is already running", Log.Verbosity.Warning); MessageBox.Show(new Rozsirujici.Jazyk.Jazyk("CZ.xml").ReturnPreklad("Messages/AlreadyRunning")); } }