private double GetRequiredSize() { double totalUncompressedSize; var folders = Directory.EnumerateDirectories(ME3Directory.DLCPath); var extracted = folders.Where(folder => Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories).Any(file => file.EndsWith("mount.dlc", StringComparison.OrdinalIgnoreCase))); var unextracted = folders.Except(extracted); double compressedSize = 0; double uncompressedSize = 0; double largestUncompressedSize = 0; double largestCompressedSize = 0; sfarsToUnpack = new List <DLCUnpack>(); foreach (var folder in unextracted) { if (!Path.GetFileName(folder).StartsWith("DLC")) { continue; } try { FileInfo info = new FileInfo(Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories).First(file => file.EndsWith(".sfar", StringComparison.OrdinalIgnoreCase))); // Skip sfar files which are already unpacked if (info.Length < 64000) { continue; } DLCUnpack sfar = new DLCUnpack(info.FullName); sfarsToUnpack.Add(sfar); compressedSize += info.Length; largestCompressedSize = Math.Max(largestCompressedSize, info.Length); uncompressedSize += sfar.UncompressedSize; largestUncompressedSize = Math.Max(largestUncompressedSize, sfar.UncompressedSize); } catch (Exception) { return(-1); } } totalUncompressedSize = uncompressedSize; if (sfarsToUnpack.Count == 0) { CurrentOverallOperationText = "All installed DLC is currently unpacked."; } // each SFAR is stripped of all its files after unpacking, so the maximum space needed on the drive is // the difference between the uncompressed size and compressed size of all SFARS, plus the compressed and // uncompressed of the largest SFAR. return((uncompressedSize - compressedSize) + largestUncompressedSize + largestCompressedSize); }
private void backgroundWorkerExtractFile_DoWork(object sender, DoWorkEventArgs e) { // Get the BackgroundWorker that raised this event. BackgroundWorker worker = sender as BackgroundWorker; //extracting arguments object[] args = e.Argument as object[]; List <sfarFile> listFiles = (List <sfarFile>)args[0]; TreeNode node = (TreeNode)args[1]; string finalPath; int count = 1; //extract files from the extraction list foreach (sfarFile entry in listFiles) { string fileName = entry.fileName; if (isFile(node)) { finalPath = extractFileDialog.FileName; } else { string fullPath; int indexStr = fileName.IndexOf(node.Text); string chunkPart = fileName.Substring(indexStr); chunkPart = chunkPart.Replace("/", "\\"); fullPath = Path.Combine(extractFolderDialog.FileName, chunkPart); //creating full folder structure if (!Directory.Exists(Path.GetDirectoryName(fullPath))) { Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); } finalPath = fullPath; } worker.ReportProgress(0, count++ + "/" + listFiles.Count + ": Extracting " + Path.GetFileName(fileName)); using (Stream input = File.OpenRead(dlcBase.fileName), output = File.Create(finalPath)) { DLCUnpack.DecompressEntry(entry, input, output, dlcBase.CompressionScheme, worker); } e.Result = true; worker.ReportProgress(100); //toolStripProgressBar.Value = count++; }//end foreach }
private void importLODToolStripMenuItem_Click(object sender, EventArgs e) { ME3Package pcc = null; try { int n = listBox1.SelectedIndex; if (n == -1) { return; } int m = listBox2.SelectedIndex; if (m == -1) { return; } TreeNode t1 = treeView1.SelectedNode; if (t1?.Parent == null || t1.Name == "") { return; } SkeletalMesh skm = new SkeletalMesh(); EntryStruct en; string loc = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\"; if (DisplayStyle == 0) { if (!int.TryParse(t1.Name, out int o)) { return; } en = Entries[o]; if (!en.isDLC) { if (en.isSkeletal) { pcc = MEPackageHandler.OpenME3Package(ME3Directory.cookedPath + en.Filename); skm = new SkeletalMesh(pcc, en.Index); // TODO: pass device } else { return; } } else { string dirDLC = ME3Directory.DLCPath; dirDLC += en.DLCName; dirDLC += "\\CookedPCConsole\\Default.sfar"; DLCUnpack dlc = new DLCUnpack(dirDLC); foreach (DLCUnpack.DLCEntry file in dlc.filesList) { try { string filename = Path.GetFileName(file.filenamePath); if (Path.GetExtension(filename).ToLower().EndsWith(".pcc") && filename == en.Filename) { if (File.Exists(loc + "dlc.pcc")) { File.Delete(loc + "dlc.pcc"); } using (Stream input = File.OpenRead(dirDLC), output = File.Create(loc + "dlc.pcc")) { dlc.ExtractEntry(file, input, output); } if (File.Exists(loc + "dlc.pcc")) { try { if (en.isSkeletal) { pcc = MEPackageHandler.OpenME3Package(loc + "dlc.pcc"); skm = new SkeletalMesh(pcc, en.Index); break; } else { return; } } catch (Exception) { return; } } } } catch (Exception) { return; } } } } else { return; } if (!skm.Loaded || pcc == null) { return; } SkeletalMesh.LODModelStruct lodpcc = skm.LODModels[0]; UDKExplorer.UDK.Classes.SkeletalMesh skmudk = new UDKExplorer.UDK.Classes.SkeletalMesh(udk, Objects[n]); UDKExplorer.UDK.Classes.SkeletalMesh.LODModelStruct lodudk = skmudk.LODModels[m]; lodpcc.Sections = new List <SkeletalMesh.SectionStruct>(); foreach (UDKExplorer.UDK.Classes.SkeletalMesh.SectionStruct secudk in lodudk.Sections) { SkeletalMesh.SectionStruct secpcc = new SkeletalMesh.SectionStruct(); secpcc.BaseIndex = secudk.BaseIndex; secpcc.ChunkIndex = secudk.ChunkIndex; secpcc.MaterialIndex = secudk.MaterialIndex; secpcc.NumTriangles = secudk.NumTriangles; lodpcc.Sections.Add(secpcc); } lodpcc.IndexBuffer = new SkeletalMesh.MultiSizeIndexContainerStruct(); lodpcc.IndexBuffer.IndexCount = lodudk.IndexBuffer.IndexCount; lodpcc.IndexBuffer.IndexSize = lodudk.IndexBuffer.IndexSize; lodpcc.IndexBuffer.Indexes = new List <ushort>(); foreach (ushort Idx in lodudk.IndexBuffer.Indexes) { lodpcc.IndexBuffer.Indexes.Add(Idx); } List <int> BoneMap = new List <int>(); for (int i = 0; i < skmudk.Bones.Count; i++) { string udkb = udk.GetName(skmudk.Bones[i].Name); bool found = false; for (int j = 0; j < skm.Bones.Count; j++) { string pccb = pcc.getNameEntry(skm.Bones[j].Name); if (pccb == udkb) { found = true; BoneMap.Add(j); if (importBonesToolStripMenuItem.Checked) { SkeletalMesh.BoneStruct bpcc = skm.Bones[j]; UDKExplorer.UDK.Classes.SkeletalMesh.BoneStruct budk = skmudk.Bones[i]; bpcc.Orientation = budk.Orientation; bpcc.Position = budk.Position; skm.Bones[j] = bpcc; } } } if (!found) { DebugOutput.PrintLn("ERROR: Cant Match Bone \"" + udkb + "\""); BoneMap.Add(0); } } lodpcc.ActiveBones = new List <ushort>(); foreach (ushort Idx in lodudk.ActiveBones) { lodpcc.ActiveBones.Add((ushort)BoneMap[Idx]); } lodpcc.Chunks = new List <SkeletalMesh.SkelMeshChunkStruct>(); foreach (UDKExplorer.UDK.Classes.SkeletalMesh.SkelMeshChunkStruct chunkudk in lodudk.Chunks) { SkeletalMesh.SkelMeshChunkStruct chunkpcc = new SkeletalMesh.SkelMeshChunkStruct(); chunkpcc.BaseVertexIndex = chunkudk.BaseVertexIndex; chunkpcc.MaxBoneInfluences = chunkudk.MaxBoneInfluences; chunkpcc.NumRigidVertices = chunkudk.NumRigidVertices; chunkpcc.NumSoftVertices = chunkudk.NumSoftVertices; chunkpcc.BoneMap = new List <ushort>(); chunkpcc.RiginSkinVertices = new List <SkeletalMesh.RigidSkinVertexStruct>(); chunkpcc.SoftSkinVertices = new List <SkeletalMesh.SoftSkinVertexStruct>(); foreach (ushort Idx in chunkudk.BoneMap) { chunkpcc.BoneMap.Add((ushort)BoneMap[Idx]); } lodpcc.Chunks.Add(chunkpcc); } lodpcc.Size = lodudk.Size; lodpcc.NumVertices = lodudk.NumVertices; lodpcc.RequiredBones = new List <byte>(); foreach (byte b in lodudk.RequiredBones) { lodpcc.RequiredBones.Add(b); } lodpcc.VertexBufferGPUSkin = new SkeletalMesh.VertexBufferGPUSkinStruct(); lodpcc.VertexBufferGPUSkin.NumTexCoords = lodudk.VertexBufferGPUSkin.NumTexCoords; lodpcc.VertexBufferGPUSkin.Extension = lodudk.VertexBufferGPUSkin.Extension; lodpcc.VertexBufferGPUSkin.Origin = lodudk.VertexBufferGPUSkin.Origin; lodpcc.VertexBufferGPUSkin.VertexSize = lodudk.VertexBufferGPUSkin.VertexSize; lodpcc.VertexBufferGPUSkin.Vertices = new List <SkeletalMesh.GPUSkinVertexStruct>(); foreach (UDKExplorer.UDK.Classes.SkeletalMesh.GPUSkinVertexStruct vudk in lodudk.VertexBufferGPUSkin.Vertices) { SkeletalMesh.GPUSkinVertexStruct vpcc = new SkeletalMesh.GPUSkinVertexStruct(); vpcc.TangentX = vudk.TangentX; vpcc.TangentZ = vudk.TangentZ; vpcc.Position = vudk.Position; vpcc.InfluenceBones = vudk.InfluenceBones; vpcc.InfluenceWeights = vudk.InfluenceWeights; vpcc.U = vudk.U; vpcc.V = vudk.V; lodpcc.VertexBufferGPUSkin.Vertices.Add(vpcc); } for (int i = 0; i < skm.LODModels.Count; i++) { skm.LODModels[i] = lodpcc; } SerializingContainer con = new SerializingContainer(); con.Memory = new MemoryStream(); con.isLoading = false; skm.Serialize(con); int end = skm.GetPropertyEnd(); MemoryStream mem = new MemoryStream(); mem.Write(pcc.Exports[en.Index].Data, 0, end); mem.Write(con.Memory.ToArray(), 0, (int)con.Memory.Length); pcc.Exports[en.Index].Data = mem.ToArray(); pcc.save(); if (!en.isDLC) { MessageBox.Show("Done"); } else { MessageBox.Show("Done. The file is now in following folder, please replace it back to DLC :\n" + loc + "dlc.pcc"); } globalTreeToolStripMenuItem.Visible = optionsToolStripMenuItem.Visible = transferToolStripMenuItem.Visible = splitContainer1.Visible = true; fileToolStripMenuItem.Visible = importLODToolStripMenuItem.Visible = splitContainer3.Visible = false; } finally { pcc?.Dispose(); } }
private void scanToolStripMenuItem_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(ME3Directory.cookedPath)) { MessageBox.Show("This functionality requires ME3 to be installed. Set its path at:\n Options > Set Custom Path > Mass Effect 3"); return; } DebugOutput.StartDebugger("Meshplorer2"); int count = 0; timer1.Enabled = false; Entries = new List <EntryStruct>(); bool ScanDLC = false; if (MessageBox.Show("Scan DLCs too?", "Meshplorer 2", MessageBoxButtons.YesNo) == DialogResult.Yes) { ScanDLC = true; } if (ScanDLC) { #region DLC Stuff string dirDLC = ME3Directory.DLCPath; if (!Directory.Exists(dirDLC)) { DebugOutput.PrintLn("No DLC Folder found!"); } else { string[] subdirs = Directory.GetDirectories(dirDLC); string loc = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\"; Directory.CreateDirectory(loc + "temp"); foreach (string DLCpath in subdirs) { if (!DLCpath.StartsWith("__") && !DLCpath.StartsWith("DLC_UPD")) { string path = DLCpath + "\\CookedPCConsole\\Default.sfar"; DLCUnpack dlcbase; try { dlcbase = new DLCUnpack(path); count = 0; pbar1.Maximum = dlcbase.GetNumberOfFiles; foreach (DLCUnpack.DLCEntry file in dlcbase.filesList) { try { string filename = Path.GetFileName(file.filenamePath); if (Path.GetExtension(filename).ToLower().EndsWith(".pcc")) { using (Stream input = File.OpenRead(path), output = File.Create(loc + "temp\\" + filename)) { dlcbase.ExtractEntry(file, input, output); } FileInfo f = new FileInfo(loc + "temp\\" + filename); DebugOutput.PrintLn("checking DLC: " + Path.GetFileName(DLCpath) + " File: " + filename + " Size: " + f.Length + " bytes", count % 3 == 0); using (ME3Package pcc = MEPackageHandler.OpenME3Package(loc + "temp\\" + filename)) { IReadOnlyList <IExportEntry> Exports = pcc.Exports; for (int i = 0; i < Exports.Count; i++) { if (Exports[i].ClassName == "SkeletalMesh" || Exports[i].ClassName == "StaticMesh") { EntryStruct ent = new EntryStruct(); ent.DLCName = Path.GetFileName(DLCpath); ent.Filename = filename; ent.Index = i; ent.isDLC = true; ent.ObjectPath = Exports[i].GetFullPath; ent.isSkeletal = Exports[i].ClassName == "SkeletalMesh"; Entries.Add(ent); } } } File.Delete(loc + "temp\\" + filename); } if (count % 3 == 0) { pbar1.Value = count; Application.DoEvents(); } count++; } catch (Exception ex) { DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR====="); } } } catch (Exception ex) { DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR====="); } } } Directory.Delete(loc + "temp", true); } #endregion } #region Basegame Stuff string dir = ME3Directory.cookedPath; string[] files = Directory.GetFiles(dir, "*.pcc"); pbar1.Maximum = files.Length - 1; foreach (string file in files) { DebugOutput.PrintLn("Scan file #" + count + " : " + file, count % 10 == 0); try { using (ME3Package pcc = MEPackageHandler.OpenME3Package(file)) { IReadOnlyList <IExportEntry> Exports = pcc.Exports; for (int i = 0; i < Exports.Count; i++) { if (Exports[i].ClassName == "SkeletalMesh" || Exports[i].ClassName == "StaticMesh") { EntryStruct ent = new EntryStruct(); ent.DLCName = ""; ent.Filename = Path.GetFileName(file); ent.Index = i; ent.isDLC = false; ent.ObjectPath = Exports[i].GetFullPath; ent.isSkeletal = Exports[i].ClassName == "SkeletalMesh"; Entries.Add(ent); } } } if (count % 10 == 0) { Application.DoEvents(); pbar1.Value = count; } count++; } catch (Exception ex) { DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR====="); } } #endregion #region Sorting bool run = true; DebugOutput.PrintLn("=====Info=====\n\nSorting names...\n\n=====Info====="); count = 0; while (run) { run = false; for (int i = 0; i < Entries.Count - 1; i++) { if (Entries[i].Filename.CompareTo(Entries[i + 1].Filename) > 0) { EntryStruct tmp = Entries[i]; Entries[i] = Entries[i + 1]; Entries[i + 1] = tmp; run = true; if (count++ % 100 == 0) { Application.DoEvents(); } } } } #endregion TreeRefresh(); timer1.Enabled = true; }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode t = treeView1.SelectedNode; if (DisplayStyle == 0) { if (t.Parent == null || t.Name == "") { return; } preview?.Dispose(); preview = null; try { if (int.TryParse(t.Name, out int i)) { EntryStruct en = Entries[i]; if (!en.isDLC) { using (ME3Package pcc = MEPackageHandler.OpenME3Package(ME3Directory.cookedPath + en.Filename)) { if (en.isSkeletal) { SkeletalMesh skmesh = new SkeletalMesh(pcc, en.Index); // TODO: pass device preview = new ModelPreview(view.Device, skmesh, view.TextureCache); CenterView(); treeView2.Nodes.Clear(); if (previewWithTreeToolStripMenuItem.Checked) { treeView2.Visible = false; Application.DoEvents(); treeView2.Nodes.Add(skmesh.ToTree()); treeView2.Visible = true; } } else { } } } else { string loc = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\"; string dirDLC = ME3Directory.DLCPath; dirDLC += en.DLCName; dirDLC += "\\CookedPCConsole\\Default.sfar"; DLCUnpack dlc = new DLCUnpack(dirDLC); foreach (DLCUnpack.DLCEntry file in dlc.filesList) { try { string filename = Path.GetFileName(file.filenamePath); if (Path.GetExtension(filename).ToLower().EndsWith(".pcc") && filename == en.Filename) { using (Stream input = File.OpenRead(dirDLC), output = File.Create(loc + filename)) { dlc.ExtractEntry(file, input, output); } if (File.Exists(loc + filename)) { try { if (en.isSkeletal) { using (ME3Package pcc = MEPackageHandler.OpenME3Package(loc + filename)) { SkeletalMesh skmesh = new SkeletalMesh(pcc, en.Index); CenterView(); treeView2.Nodes.Clear(); if (previewWithTreeToolStripMenuItem.Checked) { treeView2.Visible = false; Application.DoEvents(); treeView2.Nodes.Add(skmesh.ToTree()); treeView2.Visible = true; } } } } catch (Exception) { } File.Delete(loc + filename); } } } catch (Exception) { } } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }