/// <summary> /// 从DataTable读取 /// </summary> /// <param name="dt">The dt.</param> public static MyDataTable ReadFromDataTable(DataTable dt) { MyDataTable myDt = new MyDataTable(); foreach (DataColumn Column in dt.Columns) { myDt.AddColumn(Column.ColumnName); } long N = dt.Rows.Count; //计算总量 int counter = 0; //计数器 using (var pb = new ConsoleProgressBar.ProgressBar()) { System.Console.WriteLine("从DataTable读取"); for (int i = 0; i < dt.Rows.Count; i++) { MyRow myRow = myDt.NewRow();//新建一行 for (int j = 0; j < dt.Columns.Count; j++) { string ColumnName = myDt.ColumnNames[j]; myRow[ColumnName] = dt.Rows[i][j]; } myDt.AddRow(myRow); counter++; double progress = counter / (double)N; pb.Progress.Report(progress, "正在加载数据");//更新UI } } return(myDt); }
public static async Task <int> DumpCookedEffects(DumpCookedEffectsOptions options) { var dt = DateTime.Now; string idx = RED.CRC32.Crc32Algorithm.Compute(Encoding.ASCII.GetBytes($"{dt.Year}{dt.Month}{dt.Day}{dt.Hour}{dt.Minute}{dt.Second}")).ToString(); var outDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CookedEffectsDump", $"ExtractedFiles_{idx}"); if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } var bm = new BundleManager(); var W3_DIR = System.Environment.GetEnvironmentVariable("W3_DIR", EnvironmentVariableTarget.User); if (!Directory.Exists(W3_DIR)) { return(0); } bm.LoadAll(W3_DIR); //Bundle pa1 = bm.Bundles.First(_ => _.Key.Contains("patch1")).Value; //var actualsize = pa1.Items.Select(_ => _.Value).Select(_ => _.Size).Sum(_ => _); //var actualzsize = pa1.Items.Select(_ => _.Value).Select(_ => _.ZSize).Sum(_ => _); ; //Load MemoryMapped Bundles var memorymappedbundles = new Dictionary <string, MemoryMappedFile>(); foreach (var b in bm.Bundles.Values) { var e = b.ArchiveAbsolutePath.GetHashMD5(); memorymappedbundles.Add(e, MemoryMappedFile.CreateFromFile(b.ArchiveAbsolutePath, FileMode.Open, e, 0, MemoryMappedFileAccess.Read)); } using (StreamWriter writer = File.CreateText(Path.Combine(outDir, $"__effectsdump_{idx}.txt"))) { string head = "RedName\t" + "EffectNames\t" ; writer.WriteLine(head); System.Console.WriteLine(head); var files = bm.FileList .Where(x => x.Name.EndsWith("w2ent")) .GroupBy(p => p.Name) .Select(g => g.First()) .ToList(); using (var pb = new ConsoleProgressBar.ProgressBar()) using (var p1 = pb.Progress.Fork()) { int progress = 0; Parallel.For(0, files.Count, new ParallelOptions { MaxDegreeOfParallelism = 8 }, i => { IWitcherFile f = (IWitcherFile)files[i]; if (f is BundleItem bi) { var buff = new byte[f.Size]; using (var s = new MemoryStream()) { bi.ExtractExistingMMF(s); s.Seek(0, SeekOrigin.Begin); using (var ms = new MemoryStream(s.ToArray())) using (var br = new BinaryReader(ms)) { var crw = new CR2WFile(); crw.Read(br); foreach (var c in crw.Chunks) { if (c.data is CEntityTemplate) { var x = c.data as CEntityTemplate; if (x.CookedEffects != null) { string effectnames = ""; //string animnames = ""; foreach (CEntityTemplateCookedEffect effect in x.CookedEffects) { effectnames += effect.Name == null ? "NULL" : effect.Name.Value + ";"; //animnames += effect.AnimName == null ? "NULL" : effect.AnimName.Value + ";"; } string info = $"{f.Name}\t" + $"{effectnames}\t" //$"{animnames}\t" ; //System.Console.WriteLine(info); lock (writer) { writer.WriteLine(info); } } } } } } } progress += 1; var perc = progress / (double)files.Count; p1.Report(perc, $"Loading bundle entries: {progress}/{files.Count}"); }); } } System.Console.WriteLine($"Finished extracting."); System.Console.ReadLine(); return(1); }
public static async Task <int> DumpXbmInfo(DumpXbmsOptions options) { // create output dir var dt = DateTime.Now; string idx = RED.CRC32.Crc32Algorithm.Compute(Encoding.ASCII.GetBytes($"{dt.Year}{dt.Month}{dt.Day}{dt.Hour}{dt.Minute}{dt.Second}")).ToString(); var outDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "XBMTest", $"ExtractedFiles_{idx}"); if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } // Load bundle manager var bm = new BundleManager(); var W3_DIR = System.Environment.GetEnvironmentVariable("W3_DIR", EnvironmentVariableTarget.User); if (!Directory.Exists(W3_DIR)) { return(0); } bm.LoadAll(W3_DIR); //Load MemoryMapped Bundles var memorymappedbundles = new Dictionary <string, MemoryMappedFile>(); foreach (var b in bm.Bundles.Values) { var e = b.ArchiveAbsolutePath.GetHashMD5(); memorymappedbundles.Add(e, MemoryMappedFile.CreateFromFile(b.ArchiveAbsolutePath, FileMode.Open, e, 0, MemoryMappedFileAccess.Read)); } using (StreamWriter writer = File.CreateText(Path.Combine(outDir, $"__xbmdump_{idx}.txt"))) { string head = "RedName\t" + "Width\t" + "Height\t" + "Format\t" + "Compression\t" + "TextureGroup\t" + "TextureCacheKey\t" + "unk\t" + "unk1\t" + "unk2\t" + "MipsCount\t" ; writer.WriteLine(head); System.Console.WriteLine(head); string ext = "xbm"; var files = bm.FileList.Where(x => x.Name.EndsWith(ext)).ToList(); using (var pb = new ConsoleProgressBar.ProgressBar()) using (var p1 = pb.Progress.Fork()) { int progress = 0; Parallel.For(0, files.Count, new ParallelOptions { MaxDegreeOfParallelism = 8 }, i => { var f = files[i]; if (f is BundleItem bi) { var buff = new byte[f.Size]; using (var s = new MemoryStream()) { bi.ExtractExistingMMF(s); using (var ms = new MemoryStream(s.ToArray())) using (var br = new BinaryReader(ms)) { var crw = new CR2WFile(); crw.Read(br); foreach (var c in crw.Chunks) { if (!(c.data is CBitmapTexture x)) { continue; } string info = $"{f.Name}\t" + $"{x.Width.val}\t" + $"{x.Height.val}\t" + $"{x.Format}\t" + $"{x.Compression}\t" + $"{x.TextureGroup}\t" + $"{x.TextureCacheKey}\t" + $"{x.unk}\t" + $"{x.unk1}\t" + $"{x.unk2}\t" + $"{x.MipsCount}\t" ; //System.Console.WriteLine(info); lock (writer) { writer.WriteLine(info); } } } }
public static async Task <int> DumpCollision(DumpCollisionOptions options) { var dt = DateTime.Now; string idx = RED.CRC32.Crc32Algorithm.Compute(Encoding.ASCII.GetBytes($"{dt.Year}{dt.Month}{dt.Day}{dt.Hour}{dt.Minute}{dt.Second}")).ToString(); var outDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), nameof(DumpCollisionOptions), $"ExtractedFiles_{idx}"); if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } var W3_DIR = System.Environment.GetEnvironmentVariable("W3_DIR", EnvironmentVariableTarget.User); if (!Directory.Exists(W3_DIR)) { return(0); } var bm = new CollisionManager(); bm.LoadAll(W3_DIR); using (StreamWriter writer = File.CreateText(Path.Combine(outDir, $"__collisiondump_{idx}.csv"))) { string head = "idx\t" + "Name\t" + "Bundle\t" + //"Size\t" + //"ZSize\t" + //"Pageoffset\t" + //"Nameoffset\t" + "Unk1\t" + "Unk2\t" + "Unk3\t" + "Unk4\t" + "Unk5\t" + "Comtype\t" + "Tail\t" + "HasMoreInfo"; writer.WriteLine(head); var files = bm.FileList .GroupBy(p => p.Name) .Select(g => g.First()) .ToList(); using (var pb = new ConsoleProgressBar.ProgressBar()) using (var p1 = pb.Progress.Fork()) { int progress = 0; //Parallel.For(0, files.Count, new ParallelOptions { MaxDegreeOfParallelism = 8 }, i => for (int i = 0; i < files.Count; i++) { IWitcherFile f = files[i]; if (f is CollisionCacheItem x) { var bundlename = new DirectoryInfo(x.Bundle.ArchiveAbsolutePath).Parent.Name; if (bundlename == "content") { var par2 = new DirectoryInfo(x.Bundle.ArchiveAbsolutePath).Parent.Parent.Name; bundlename = par2; } if (!(x.Comtype > 4 || x.Comtype == 1)) { string filename = Path.GetFileName(x.Name); string path = Path.Combine(outDir, $"{i}_{bundlename}_{filename}.bin"); using (var temp_ms = new MemoryStream()) using (var output = new FileStream(path, FileMode.Create, FileAccess.Write)) using (var bw = new BinaryWriter(output)) { x.Extract(temp_ms); temp_ms.Seek(0, SeekOrigin.Begin); x.REDheader.Write(bw); temp_ms.CopyTo(output); } } string info = $"{i}\t" + $"{x.Name}\t" + $"{bundlename}\t" + //$"{x.Size}\t" + //$"{x.ZSize}\t" + //$"{x.PageOffset}\t" + //$"{x.NameOffset}\t" + $"{x.Unk1}\t" + $"{x.Unk2}\t" + $"{x.Unk3}\t" + $"{BitConverter.ToString(x.unk4).Replace("-", string.Empty)}\t" + $"{BitConverter.ToString(x.unk5).Replace("-", string.Empty)}\t" + $"{x.Comtype}\t" + $"{BitConverter.ToString(x.Tail).Replace("-", string.Empty)}\t" ; if (x.REDheader != null) { info += string.Join(".", x.REDheader.Items.Select(_ => _.Name)); } //System.Console.WriteLine(info); writer.WriteLine(info); } progress += 1; var perc = progress / (double)files.Count; p1.Report(perc, $"Loading bundle entries: {progress}/{files.Count}"); } } } System.Console.WriteLine($"Finished extracting."); System.Console.ReadLine(); return(1); }
public static async Task <int> DumpDDSInfo(DumpDDSOptions options) { var dt = DateTime.Now; string idx = RED.CRC32.Crc32Algorithm.Compute(Encoding.ASCII.GetBytes($"{dt.Year}{dt.Month}{dt.Day}{dt.Hour}{dt.Minute}{dt.Second}")).ToString(); var outDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "DDSTest", $"ExtractedFiles_{idx}"); if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } // load TextureManager var txc = new TextureManager(); var W3_DIR = System.Environment.GetEnvironmentVariable("W3_DIR", EnvironmentVariableTarget.User); if (!Directory.Exists(W3_DIR)) { return(0); } txc.LoadAll(W3_DIR); System.Console.WriteLine($"Loaded TextureManager"); // load BundleManager var bundlexbmDict = new Dictionary <uint, XBMBundleInfo>(); var bm = new BundleManager(); bm.LoadAll(W3_DIR); System.Console.WriteLine($"Loaded BundleManager"); var memorymappedbundles = new Dictionary <string, MemoryMappedFile>(); foreach (var b in bm.Bundles.Values) { var e = b.ArchiveAbsolutePath.GetHashMD5(); memorymappedbundles.Add(e, MemoryMappedFile.CreateFromFile(b.ArchiveAbsolutePath, FileMode.Open, e, 0, MemoryMappedFileAccess.Read)); } #region XBM DUMP const string ext = "xbm"; using (var pb = new ConsoleProgressBar.ProgressBar()) using (var p1 = pb.Progress.Fork()) { int progress = 0; var files1 = bm.FileList.Where(x => x.Name.EndsWith(ext)).ToList(); Parallel.For(0, files1.Count, new ParallelOptions { MaxDegreeOfParallelism = 8 }, i => { var f = files1[i]; if (f is BundleItem bi) { var buff = new byte[f.Size]; using (var s = new MemoryStream()) { bi.ExtractExistingMMF(s); using (var ms = new MemoryStream(s.ToArray())) using (var br = new BinaryReader(ms)) { var crw = new CR2WFile(); crw.Read(br); foreach (var c in crw.chunks) { if (!(c.data is CBitmapTexture x)) { continue; } lock (bundlexbmDict) { if (!bundlexbmDict.ContainsKey(x.TextureCacheKey.val)) { bundlexbmDict.Add(x.TextureCacheKey.val, new XBMBundleInfo() { //Name = f.Name, //Width = x.Width == null ? "NULL" : x.Width.val.ToString(), //Height = x.Height == null ? "NULL" : x.Height.val.ToString(), Format = x.Format == null ? "NULL" : x.Format.WrappedEnum.ToString(), Compression = x.Compression == null ? "NULL" : x.Compression.WrappedEnum.ToString(), TextureGroup = x.TextureGroup == null ? "NULL" : x.TextureGroup.Value, Unk = x.unk?.ToString() ?? "NULL", Unk1 = x.unk1?.ToString() ?? "NULL", Unk2 = x.unk2?.ToString() ?? "NULL", } ); } } } }