public FileEntry SetupFileEntry(ASST asset, string name, string fullName, bool IsCompressed) { FileEntry fileEntry = new FileEntry(); fileEntry.FullName = fullName; fileEntry.Name = name; fileEntry.Text = name; fileEntry.unk1 = asset.unk; fileEntry.unk2 = asset.unk2; fileEntry.IsCompressed = IsCompressed; // fileEntry.data = asset.FileData; //Now check magic //Todo clean this part up byte[] data = asset.FileData; if (IsCompressed) { try { data = STLibraryCompression.ZSTD.Decompress(asset.FileData); } catch { Console.WriteLine("Unkwon compression for file " + fileEntry.Name); } } string ext = Path.GetExtension(name); string SarcEx = SARCExt.SARC.GuessFileExtension(data); if (name.EndsWith("bfres") || name.EndsWith("fmdb") || name.EndsWith("fskb") || name.EndsWith("ftsb") || name.EndsWith("fvmb") || name.EndsWith("fvbb") || name.EndsWith("fspb") || name.EndsWith("fsnb")) { fileEntry.ImageKey = "bfres"; fileEntry.SelectedImageKey = "bfres"; } if (SarcEx == ".bntx") { fileEntry.ImageKey = "bntx"; fileEntry.SelectedImageKey = "bntx"; } if (SarcEx == ".byaml") { fileEntry.ImageKey = "byaml"; fileEntry.SelectedImageKey = "byaml"; } if (SarcEx == ".aamp") { fileEntry.ImageKey = "aamp"; fileEntry.SelectedImageKey = "aamp"; } if (ext == ".lua") { } data = new byte[0]; return(fileEntry); }
public byte[] Save() { beaFile.FileList.Clear(); beaFile.FileDictionary.Clear(); foreach (TreeNode node in Collect(Nodes)) { if (node is TreeNodeFile && node != this) { IFileFormat fileFormat = (IFileFormat)node; if (fileFormat != null && fileFormat.CanSave) { byte[] uncomrompressedData = new byte[0]; //Save any active files in the editor if supported if (fileFormat.CanSave) { uncomrompressedData = fileFormat.Save(); } //Create a new asset entry ASST asset = new ASST(); asset.unk = 2; asset.unk2 = 2; asset.UncompressedSize = uncomrompressedData.LongLength; if (fileFormat.IFileInfo.FileIsCompressed) { asset.FileData = STLibraryCompression.ZSTD.Compress(uncomrompressedData); } else { asset.FileData = uncomrompressedData; } asset.FileName = fileFormat.FilePath; beaFile.FileList.Add(fileFormat.FilePath, asset); beaFile.FileDictionary.Add(fileFormat.FilePath); } } else if (node is FileEntry) { ASST asset = new ASST(); asset.unk = ((FileEntry)node).unk1; asset.unk2 = ((FileEntry)node).unk2; asset.FileName = ((FileEntry)node).FullName; asset.FileData = ((FileEntry)node).data; byte[] uncomp = GetASSTData((FileEntry)node); asset.UncompressedSize = uncomp.Length; beaFile.FileList.Add(asset.FileName, asset); beaFile.FileDictionary.Add(asset.FileName); } } MemoryStream mem = new MemoryStream(); beaFile.Save(mem); return(mem.ToArray()); }
public FileEntry SetupFileEntry(ASST asset) { FileEntry fileEntry = new FileEntry(); fileEntry.FileName = asset.FileName; fileEntry.unk1 = asset.unk; fileEntry.unk2 = asset.unk2; fileEntry.IsCompressed = asset.IsCompressed; fileEntry.CompressedData = asset.FileData; return(fileEntry); }
public void Save(System.IO.Stream stream) { beaFile.FileList.Clear(); beaFile.FileDictionary.Clear(); foreach (FileEntry node in Files) { node.SaveFileFormat(); ASST asset = new ASST(); asset.unk = node.unk1; asset.unk2 = node.unk2; asset.FileName = node.FileName; asset.FileData = node.CompressedData; asset.UncompressedSize = node.FileData.Length; beaFile.FileList.Add(asset.FileName, asset); beaFile.FileDictionary.Add(asset.FileName); } beaFile.Save(stream); }
public static void SetASST(byte[] data, string path) { if (beaFile.FileList.ContainsKey(path)) { ASST asst = beaFile.FileList[path]; Console.WriteLine(path + " A match!"); asst.UncompressedSize = data.Length; if (asst.IsCompressed) { using (var compressor = new Compressor()) { asst.FileData = compressor.Wrap(data); } } else { asst.FileData = data; } } }
void Repack(string FolderName) { progressBar = new ProgressBar(); progressBar.Task = "Reading Directory..."; progressBar.Value = 0; progressBar.StartPosition = FormStartPosition.CenterScreen; progressBar.Show(); progressBar.Refresh(); List <string> flist = new List <string>(); List <byte[]> fdata = new List <byte[]>(); readFiles(FolderName, flist, fdata); progressBar.Task = "Repacking Files..."; progressBar.Refresh(); int i = 0; foreach (string f in flist) { int value = (i * 100) / flist.Count; progressBar.Value = value; if (beaFile.FileList.ContainsKey(f)) { ASST asst = beaFile.FileList[f]; if (f == asst.FileName) { Console.WriteLine(f + " A match!"); asst.UncompressedSize = fdata[i].Length; if (asst.UncompressedSize == fdata[i].Length) { progressBar.Task = "Packing " + Path.GetFileName(f); progressBar.Refresh(); asst.FileData = fdata[i]; } else { progressBar.Task = "Compressing " + Path.GetFileName(f); progressBar.Refresh(); using (var compressor = new Compressor()) { asst.FileData = compressor.Wrap(fdata[i]); } } } } if (value == 99) { value = 100; progressBar.Value = value; progressBar.Refresh(); } i++; } fdata.Clear(); flist.Clear(); GC.Collect(); ReloadTree(); }