private void Menu_Load(object sender, EventArgs e) { Am = new AssetsManager(); if (File.Exists("classdata.tpk")) { try { Am.LoadClassPackage("classdata.tpk"); if (Am.classPackage.valid) { return; } MsgBoxUtils.ShowErrorDialog("Invalid classdata.tpk file."); } catch (Exception ex) { MsgBoxUtils.ShowErrorDialog("Can't load classdata.tpk:\n" + ex); } } else { MsgBoxUtils.ShowErrorDialog("Missing classdata.tpk by exe.\n" + "Please make sure it exists."); } Close(); Environment.Exit(1); }
private void btnLoad_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog { Title = @"Open texture", Filter = @"PNG file (*.png)|*.png|TGA file (*.tga)|*.tga|All types (*.*)|*.*" }; if (ofd.ShowDialog() != DialogResult.OK) { return; } try { using var image = Image.Load <Rgba32>(ofd.FileName); tex.m_Width = image.Width; tex.m_Height = image.Height; image.Mutate(i => i.Flip(FlipMode.Vertical)); imgBytes = image.TryGetSinglePixelSpan(out var pixelSpan) ? MemoryMarshal.AsBytes(pixelSpan).ToArray() : null; if (imgBytes == null) { MsgBoxUtils.ShowErrorDialog(this, "Failed to parse current texture."); } } catch (Exception ex) { MsgBoxUtils.ShowErrorDialog(this, "Something went wrong when importing the texture:\n" + ex); } }
private bool FailIfNothingSelected() { switch (GetSelectedCount()) { case 0: MsgBoxUtils.ShowErrorDialog("No item selected."); return(true); default: return(false); } }
private void btnOK_Click(object sender, EventArgs e) { FileID = cboxFileID.SelectedIndex; if (long.TryParse(boxPathID.Text, out var pathId)) { PathID = pathId; } else { MsgBoxUtils.ShowErrorDialog("Path ID is invalid!"); } }
private void btnOK_Click(object sender, EventArgs e) { if (BundleInst == null) { return; } AssetBundleCompressionType compType; if (rbtnLZ4.Checked) { compType = AssetBundleCompressionType.LZ4; } else if (rbtnLZMA.Checked) { compType = AssetBundleCompressionType.LZMA; } else { MsgBoxUtils.ShowErrorDialog("You didn't choose any compression method!\n" + "Please go back and select it.\n"); DialogResult = DialogResult.None; return; } try { var bw = new BackgroundWorker(); bw.DoWork += delegate { var sfd = new SaveFileDialog { FileName = BundleInst.name + ".packed", Filter = @"All types (*.*)|*.*" }; if (sfd.ShowDialog() != DialogResult.OK) { return; } CompressBundle(BundleInst, sfd.FileName, compType); }; bw.RunWorkerCompleted += delegate { MsgBoxUtils.ShowInfoDialog("The bundle file has been successfully packed!", MessageBoxButtons.OK); Compressed = true; }; bw.RunWorkerAsync(); } catch (Exception ex) { MsgBoxUtils.ShowErrorDialog("Something went wrong when packing the bundle:\n" + ex); } }
private void btnInfo_Click(object sender, EventArgs e) { if (BundleInst == null || cboxBundleContents.SelectedItem == null) { return; } var index = cboxBundleContents.SelectedIndex; var dirInf = BundleHelper.GetDirInfo(BundleInst.file, index); var bunAssetName = dirInf.name; //When we make a modification to an assets file in the bundle, //we replace the assets file in the manager. This way, all we //have to do is not reload from the bundle if our assets file //has been modified MemoryStream assetStream; if (!ModifiedFiles.ContainsKey(bunAssetName)) { var assetData = BundleHelper.LoadAssetDataFromBundle(BundleInst.file, index); assetStream = new MemoryStream(assetData); } else { //unused if the file already exists assetStream = null; } //warning: does not update if you import an assets file onto //a file that wasn't originally an assets file var isAssetsFile = BundleInst.file.IsAssetsFile(BundleInst.file.reader, dirInf); if (isAssetsFile) { var assetMemPath = Path.Combine(BundleInst.path, bunAssetName); var fileInst = Am.LoadAssetsFile(assetStream, assetMemPath, true); if (!LoadOrAskCldb(fileInst)) { return; } var info = new AssetsViewer(Am, fileInst, true); info.Closing += AssetsViewerClosing; info.Show(); } else { MsgBoxUtils.ShowErrorDialog("This doesn't seem to be a valid assets file."); } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (Modified) { AskSaveChanges(); } var ofd = new OpenFileDialog { Title = @"Open assets or bundle file", Filter = @"All types (*.*)|*.*|Unity content (*.unity3d;*.assets)|*.unity3d;*.assets|Bundle file (*.unity3d)|*.unity3d|Assets file (*.assets)|*.assets" }; if (ofd.ShowDialog() != DialogResult.OK) { return; } var selectedFile = ofd.FileName; var fileType = AssetsBundleDetector.DetectFileType(selectedFile); CloseAllFiles(); switch (fileType) { case DetectedFileType.AssetsFile: { var fileInst = Am.LoadAssetsFile(selectedFile, true); if (!LoadOrAskCldb(fileInst)) { return; } new AssetsViewer(Am, fileInst).ShowDialog(); break; } case DetectedFileType.BundleFile: LoadBundle(selectedFile); break; default: MsgBoxUtils.ShowErrorDialog("Unable to read the file!\n" + "Invalid file or unknown (unsupported) version."); break; } }
private List <AssetTypeValueField> GetSelectedFields() { try { var fields = new List <AssetTypeValueField>(); foreach (var cont in GetSelectedAssets()) { fields.Add(Workspace.GetBaseField(cont)); } return(fields); } catch { MsgBoxUtils.ShowErrorDialog("Unable to process the asset data!\n" + "This might be due to an incompatible type database."); return(null); } }
public void WriteFiles(List <AssetsReplacer> replacers, bool overwrite = false) { var lastFileId = replacers.Max(r => r.GetFileID()); for (var fileId = 0; fileId <= lastFileId; fileId++) { var id = fileId; var sortedAssetsList = replacers.Where(r => r.GetFileID() == id).ToList(); // sort the list of replacers by fileID var fileInst = Workspace.LoadedFiles[fileId]; if (overwrite) { var path = fileInst.path; var tempPath = Path.Combine(Path.GetTempPath(), fileInst.name); using var fs = File.OpenWrite(tempPath); using var writer = new AssetsFileWriter(fs); fileInst.file.Write(writer, 0, sortedAssetsList, 0); Am.UnloadAssetsFile(path); fs.Close(); File.Replace(tempPath, path, path + ".backup"); Workspace.LoadedFiles[fileId] = Am.LoadAssetsFile(path, false); } else { var sfd = new SaveFileDialog { Title = @"Save as...", Filter = @"All types (*.*)|*.*|Assets file (*.assets)|*.assets", FileName = fileInst.name }; if (sfd.ShowDialog() != DialogResult.OK) { continue; } if (fileInst.path == sfd.FileName) { MsgBoxUtils.ShowErrorDialog("If you want to overwrite files go to \"File->Save\" instead of \"File->Save as...\"!"); return; } using var fs = File.OpenWrite(sfd.FileName); using var writer = new AssetsFileWriter(fs); fileInst.file.Write(writer, 0, sortedAssetsList, 0); } } }
private void btnOK_Click(object sender, EventArgs e) { if (rbtnTXT.Checked) { dumpType = DumpType.TXT; } else if (rbtnXML.Checked) { dumpType = DumpType.XML; } else if (rbtnJSON.Checked) { dumpType = DumpType.TXT; // todo } else { MsgBoxUtils.ShowErrorDialog("You didn't choose any dump type!\n" + "Please go back and select it.\n"); DialogResult = DialogResult.None; } }
private void btnViewData_Click(object sender, EventArgs e) { if (FailIfNothingSelected()) { return; } var baseFields = GetSelectedFields(); if (baseFields == null) { return; } var cldb = Workspace.Am.classFile; foreach (var baseField in baseFields) { var cldbType = AssetHelper.FindAssetClassByName(cldb, baseField.GetFieldType()); if (cldbType != null) { if (HasAnyField(cldbType)) { continue; } MsgBoxUtils.ShowErrorDialog("This asset has no data to view."); } else { MsgBoxUtils.ShowErrorDialog("Unknown asset format."); } baseFields.Remove(baseField); } if (baseFields.Count == 0) { return; } foreach (var baseField in baseFields) { new AssetData(Workspace, baseField).Show(); } }
private void btnOK_Click(object sender, EventArgs e) { if (BundleInst == null) { return; } AssetBundleDecompressionType decompType; if (rbtnFile.Checked) { decompType = AssetBundleDecompressionType.File; } else if (rbtnMemory.Checked) { decompType = AssetBundleDecompressionType.Memory; } else { MsgBoxUtils.ShowErrorDialog("You didn't choose any decompression type!\n" + "Please go back and select it.\n"); DialogResult = DialogResult.None; return; } try { Bw = new BackgroundWorker(); if (BundleInst.file.IsBundleDataCompressed()) { switch ((int)decompType) { // Decompress to File case 0: { var sfd = new SaveFileDialog { FileName = BundleInst.name + ".unpacked", Filter = @"All types (*.*)|*.*" }; if (sfd.ShowDialog() != DialogResult.OK) { return; } Bw.DoWork += delegate { DecompressToFile(sfd.FileName); }; break; } // Decompress to Memory case 1: Bw.DoWork += delegate { DecompressToMemory(); }; break; } } else { Bw.DoWork += delegate { DecompressToMemory(); }; } Bw.RunWorkerCompleted += delegate { MsgBoxUtils.ShowInfoDialog("The bundle file has been successfully unpacked!", MessageBoxButtons.OK); //Decompressed = true; }; Bw.RunWorkerAsync(); } catch (Exception ex) { MsgBoxUtils.ShowErrorDialog("Something went wrong when unpacking the bundle:\n" + ex); } }
private void btnOK_Click(object sender, EventArgs e) { var cldb = Workspace.Am.classFile; var fileInst = Workspace.LoadedFiles[cboxFileID.SelectedIndex]; AssetTypeTemplateField templateField; var fileId = cboxFileID.SelectedIndex; if (!long.TryParse(boxPathID.Text, out var pathId)) { MsgBoxUtils.ShowErrorDialog("Path ID is invalid!"); return; } var type = boxTypeNameOrID.Text; int typeId; var createBlankAsset = chboxCreateBlankAssets.Checked; if (fileInst.file.typeTree.hasTypeTree) { if (!TryParseTypeTree(fileInst, ref type, createBlankAsset, out templateField, out typeId)) { if (!TryParseClassDatabase(ref type, createBlankAsset, out templateField, out typeId)) { MsgBoxUtils.ShowErrorDialog("Class type is invalid!"); return; } //has typetree but had to lookup to cldb //we need to add a new typetree entry because this is //probably not a type that existed in this bundle fileInst.file.typeTree.unity5Types.Add(C2T5.Cldb2TypeTree(cldb, typeId)); } } else { if (!TryParseClassDatabase(ref type, createBlankAsset, out templateField, out typeId)) { MsgBoxUtils.ShowErrorDialog("Class type is invalid!"); return; } } var monoSelected = cboxTypePreset.SelectedIndex == 1; ushort monoId; if (typeId != 0x72 || !monoSelected) { monoId = ushort.MaxValue; } else { if (!ushort.TryParse(boxMonoID.Text, out monoId)) { MsgBoxUtils.ShowErrorDialog("Mono ID is invalid!"); return; } } if (!int.TryParse(boxCount.Text, out var count)) { MsgBoxUtils.ShowErrorDialog("The count of assets being created is invalid!"); return; } byte[] assetBytes; if (createBlankAsset) { var baseField = ValueBuilder.DefaultValueFieldFromTemplate(templateField); assetBytes = baseField.WriteToByteArray(); } else { assetBytes = Array.Empty <byte>(); } for (var i = 0; i < count; i++) { var item = new AssetItem { Type = type, TypeID = (uint)typeId, FileID = fileId, PathID = pathId + i, Size = assetBytes.Length, Modified = "*", MonoID = monoId }; Items.Add(item); Workspace.AddReplacer(AssetModifier.CreateAssetReplacer(item, assetBytes), new MemoryStream(assetBytes)); } DialogResult = DialogResult.OK; }