Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        private void FixItemSackData(fNbt.NbtCompound item, int itemSackId)
        {
            if (((fNbt.NbtShort)item["id"]).Value == (short)itemSackId)
            {
                fNbt.NbtCompound tag;

                if (!item.TryGet <fNbt.NbtCompound>("tag", out tag) || tag["type"].GetType() != typeof(fNbt.NbtShort))
                {
                    return;
                }

                fNbt.NbtShort type = (fNbt.NbtShort)tag["type"];

                tag["type"] = new fNbt.NbtString("type", VanillaIDTable.BlockName[type.Value]);

                System.Diagnostics.Debug.WriteLine("Converted type: " + type.Value + "=>" + tag.Get <fNbt.NbtString>("type").Value);
            }
        }
Exemplo n.º 3
0
        private List <fNbt.NbtCompound> GetModListFromNBT(fNbt.NbtCompound rootNbt)
        {
            fNbt.NbtList nbtModList = fNbt.NbtQuery.Get <fNbt.NbtList>(levelNbt.RootTag, "//FML/ModList");           // (fNbt.NbtList)rootNbt["FML"]["ModList"];
            if (null == nbtModList)
            {
                System.Diagnostics.Debug.WriteLine("Not 1.7.x level.dat");
                return(null);
            }

            List <fNbt.NbtCompound> result = new List <fNbt.NbtCompound>();

            foreach (fNbt.NbtCompound modInfo in nbtModList)
            {
                result.Add(modInfo);
            }

            return(result);
        }
Exemplo n.º 4
0
 public CustomTestItem(uint someVariable)
 {
     SomeVariable = someVariable;
     ExtraData    = new fNbt.NbtCompound();
     ExtraData.Add(new fNbt.NbtInt("HashCode", GetHashCode()));
 }
Exemplo n.º 5
0
        private void chunkConvertWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // 出力先ディレクトリチェック
            if (Directory.Exists(outputPath.Text))
            {
                DialogResult result = MessageBox.Show("出力先ディレクトリを上書きします。", "確認", MessageBoxButtons.OKCancel);

                if (result != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }
            }
            else
            {
                Directory.CreateDirectory(outputPath.Text);
            }

            // 総チャンク数をプログレスバーの最大値にセット
            if (chunkConvertProgressBar.InvokeRequired)
            {
                chunkConvertProgressBar.Invoke((Action)(() =>
                {
                    chunkConvertProgressBar.Maximum = int.Parse(chunkCount.Text);

                    inputPath.Enabled = false;
                    inputRef.Enabled = false;

                    outputPath.Enabled = false;
                    outputRef.Enabled = false;

                    startFix.Visible = false;
                    chunkConvertProgressBar.Visible = true;
                }));
            }

            // level.datのPlayerデータを書き換え
            FixPlayerSackData(inputPath.Text + "\\level.dat",
                              InputToOutputPath(inputPath.Text + "\\level.dat"),
                              "//Data/Player/Inventory");


            // Playerフォルダの個別データを書き換え
            Directory.CreateDirectory(outputPath.Text + "\\players");
            foreach (string playerFile in Directory.GetFiles(inputPath.Text + "\\players", "*.dat"))
            {
                FixPlayerSackData(playerFile,
                                  InputToOutputPath(playerFile),
                                  "//Inventory");
            }


            // 処理済みチャンク数
            int fixChunkNum = 0;

            // 袋のID
            int itemSackId = int.Parse(itemSackID.Text);

            foreach (string regionDir in Directory.GetDirectories(inputPath.Text, "region"))
            {
                // 出力先regionフォルダの作成
                Directory.CreateDirectory(InputToOutputPath(regionDir));

                foreach (string mcaFile in Directory.GetFiles(regionDir, "*.mca"))
                {
                    using (RegionFileAccess.RegionFile rf = new RegionFileAccess.RegionFile(mcaFile))
                    {
                        rf.LoadFile();

                        for (int i = 0; i < rf.ChunkData.Count; i++)
                        {
                            if (null != rf.ChunkData[i])
                            {
                                fNbt.NbtCompound nbtRoot = rf.ChunkData[i].GetRootNBT();

#if DEBUG
                                using (StreamWriter sw = new StreamWriter(InputToOutputPath(mcaFile) + "_nbt_" + i + ".txt", false, Encoding.UTF8)) {
                                    sw.Write(nbtRoot.ToString());
                                }
#endif

                                // TileEntities差し替え
                                fNbt.NbtList tileEntities = fNbt.NbtQuery.Get <fNbt.NbtList>(nbtRoot, "//Level/TileEntities");
                                foreach (fNbt.NbtCompound tileEntity in tileEntities)
                                {
                                    fNbt.NbtList items;
                                    if (tileEntity.TryGet <fNbt.NbtList>("Items", out items))
                                    {
                                        foreach (fNbt.NbtCompound item in items)
                                        {
                                            FixItemSackData(item, itemSackId);
                                        }
                                    }
                                }

                                // Entities差し替え
                                fNbt.NbtList entities = fNbt.NbtQuery.Get <fNbt.NbtList>(nbtRoot, "//Level/Entities");
                                foreach (fNbt.NbtCompound entity in entities)
                                {
                                    fNbt.NbtList items;
                                    // チェストトロッコ等のインベントリ
                                    if (entity.TryGet <fNbt.NbtList>("Items", out items))
                                    {
                                        foreach (fNbt.NbtCompound item in items)
                                        {
                                            FixItemSackData(item, itemSackId);
                                        }
                                    }

                                    fNbt.NbtCompound tag;
                                    // ドロップアイテム
                                    if (entity.TryGet <fNbt.NbtCompound>("Item", out tag))
                                    {
                                        FixItemSackData(tag, itemSackId);
                                    }
                                }

                                // チャンクデータ更新
                                rf.ChunkData[i].SetRootNbt(nbtRoot);

                                chunkConvertWorker.ReportProgress(++fixChunkNum);
                            }

                            if (i % 16 == 0)
                            {
                                System.Threading.Thread.Sleep(2);
                            }
                        }

                        rf.SaveFile(InputToOutputPath(mcaFile));
                    }
                }
            }
        }