private async void ReturnAssetToAdd() { int fileId = ddFileId.SelectedIndex; //hopefully in order string pathIdText = boxPathId.Text; string typeIdText = boxTypeId.Text; string monoIdText = boxMonoId.Text; bool createBlankAsset = chkCreateZerodAsset.IsChecked ?? false; AssetsFileInstance file = workspace.LoadedFiles[fileId]; AssetTypeTemplateField tempField; byte[] assetBytes; long pathId; int typeId; ushort monoId; if (!long.TryParse(pathIdText, out pathId)) { await MessageBoxUtil.ShowDialog(this, "Bad input", "Path ID was invalid."); return; } if (file.file.typeTree.hasTypeTree) { if (!TryParseTypeTree(file, typeIdText, createBlankAsset, out tempField, out typeId)) { if (!TryParseClassDatabase(typeIdText, createBlankAsset, out tempField, out typeId)) { await MessageBoxUtil.ShowDialog(this, "Bad input", "Class type was invalid."); return; } else { //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 file.file.typeTree.unity5Types.Add(C2T5.Cldb2TypeTree(workspace.am.classFile, typeId)); } } } else { if (!TryParseClassDatabase(typeIdText, createBlankAsset, out tempField, out typeId)) { await MessageBoxUtil.ShowDialog(this, "Bad input", "Class type was invalid."); return; } } if (monoIdText == "-1") { monoId = 0xffff; } else if (!ushort.TryParse(monoIdText, out monoId)) { await MessageBoxUtil.ShowDialog(this, "Bad input", "Mono ID was invalid."); return; } if (createBlankAsset) { AssetTypeValueField baseField = ValueBuilder.DefaultValueFieldFromTemplate(tempField); assetBytes = baseField.WriteToByteArray(); } else { assetBytes = new byte[0]; } workspace.AddReplacer(file, new AssetsReplacerFromMemory(0, pathId, typeId, monoId, assetBytes), new MemoryStream(assetBytes)); Close(true); }
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; }