public bool SelectionValidForPlugin(AssetsManager am, UABEAPluginAction action, List <AssetContainer> selection, out string name) { name = "Batch import .png"; if (action != UABEAPluginAction.Import) { return(false); } if (selection.Count <= 1) { return(false); } int classId = AssetHelper.FindAssetClassByName(am.classFile, "Texture2D").classId; foreach (AssetContainer cont in selection) { if (cont.ClassId != classId) { return(false); } } return(true); }
public bool SelectionValidForPlugin(AssetsManager am, UABEAPluginAction action, List <AssetExternal> selection, out string name) { name = "Export .png"; if (action != UABEAPluginAction.Export) { return(false); } //temporary if (selection.Count != 1) { return(false); } int classId = AssetHelper.FindAssetClassByName(am.classFile, "Texture2D").classId; foreach (AssetExternal ext in selection) { if (ext.info.curFileType != classId) { return(false); } } return(true); }
private bool TryParseClassDatabase(ref string type, bool createBlankAsset, out AssetTypeTemplateField templateField, out int typeId) { templateField = null; var cldb = Workspace.Am.classFile; ClassDatabaseType cldbType; bool needsTypeId; if (int.TryParse(type, out typeId)) { cldbType = AssetHelper.FindAssetClassByID(cldb, (uint)typeId); needsTypeId = false; } else { cldbType = AssetHelper.FindAssetClassByName(cldb, type); needsTypeId = true; } if (cldbType == null) { return(false); } if (needsTypeId) { typeId = cldbType.classId; } if (createBlankAsset) { templateField = new AssetTypeTemplateField(); if (cldbType.fields.Count == 0) { typeId = 0x01; cldbType = AssetHelper.FindAssetClassByID(cldb, 0x01); } type = cldbType.name.GetString(cldb); templateField.FromClassDatabase(cldb, cldbType, 0); } return(true); }
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 bool TryParseClassDatabase(string typeIdText, bool createBlankAsset, out AssetTypeTemplateField tempField, out int typeId) { tempField = null; ClassDatabaseFile cldb = workspace.am.classFile; ClassDatabaseType cldbType; bool needsTypeId; if (int.TryParse(typeIdText, out typeId)) { cldbType = AssetHelper.FindAssetClassByID(cldb, (uint)typeId); needsTypeId = false; } else { cldbType = AssetHelper.FindAssetClassByName(cldb, typeIdText); needsTypeId = true; } if (cldbType == null) { return(false); } if (needsTypeId) { typeId = cldbType.classId; } if (createBlankAsset) { tempField = new AssetTypeTemplateField(); tempField.FromClassDatabase(cldb, cldbType, 0); } return(true); }
public static AssetsReplacer DiffComponent(AssetFileInfoEx info, AssetTypeValueField baseField, ClassDatabaseFile cldb, ComponentChangeOrAdd compChange, ulong pathId) { //todo: shouldn't need to overwrite, using info.curFileType would probably work fine int classId = AssetHelper.FindAssetClassByName(cldb, compChange.componentType).classId; foreach (FieldChange fieldChange in compChange.changes) { AssetTypeValueField field = baseField; foreach (string curPath in fieldChange.fieldName.Split('/')) { field = field.Get(curPath); } object value = DecodeValueByName(fieldChange.data, fieldChange.fieldType); if (value != null) { //UnityEngine.Debug.Log("HKWE SV " + value.ToString()); field.GetValue().Set(value); } else { //UnityEngine.Debug.Log("HKWE NV"); } } byte[] moveAsset; using (MemoryStream memStream = new MemoryStream()) using (AssetsFileWriter writer = new AssetsFileWriter(memStream)) { writer.bigEndian = false; baseField.Write(writer); moveAsset = memStream.ToArray(); } return(new AssetsReplacerFromMemory(0, pathId, classId, 0xFFFF, moveAsset)); }
private void assetList_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (assetList.SelectedCells.Count > 0) { var selRow = assetList.SelectedRows[0]; string typeName = (string)selRow.Cells[2].Value; if (typeName == "Folder") { string dirName = (string)selRow.Cells[1].Value; ChangeDirectory(dirName); } else { ClassDatabaseFile classFile = helper.classFile; AssetsFileInstance correctAti = currentFile; ClassDatabaseType classType = AssetHelper.FindAssetClassByName(classFile, typeName); if (currentFile.name == "globalgamemanagers") { int rsrcIndex = helper.files.FindIndex(f => f.name == "resources.assets"); if (rsrcIndex != -1) { correctAti = helper.files[rsrcIndex]; } else { string rsrcPath = Path.Combine(Path.GetDirectoryName(currentFile.path), "resources.assets"); correctAti = helper.LoadAssetsFile(rsrcPath, false); UpdateDependencies(); } if (typeName == "") { return; } } AssetFileInfoEx info = correctAti.table.getAssetInfo((ulong)selRow.Cells[3].Value); bool hasGameobjectField = classType.fields.Any(f => f.fieldName.GetString(classFile) == "m_GameObject"); bool parentPointerNull = false; if (typeName != "GameObject" && hasGameobjectField) { //get gameobject parent AssetTypeValueField componentBaseField = helper.GetATI(correctAti.file, info).GetBaseField(); AssetFileInfoEx newInfo = helper.GetExtAsset(correctAti, componentBaseField["m_GameObject"], true).info; if (newInfo != null && newInfo.index != 0) { info = newInfo; } else { parentPointerNull = true; } } if ((typeName == "GameObject" || hasGameobjectField) && !parentPointerNull) { AssetTypeValueField baseField = helper.GetATI(correctAti.file, info).GetBaseField(); AssetTypeValueField transformPtr = baseField["m_Component"]["Array"][0]["component"]; AssetTypeValueField transform = helper.GetExtAsset(correctAti, transformPtr).instance.GetBaseField(); baseField = GetRootTransform(helper, currentFile, transform); AssetTypeValueField gameObjectPtr = baseField["m_GameObject"]; AssetTypeValueField gameObject = helper.GetExtAsset(correctAti, gameObjectPtr).instance.GetBaseField(); GameObjectViewer view = new GameObjectViewer(helper, correctAti, gameObject, info.index, (ulong)selRow.Cells[3].Value); view.Show(); } else { AssetTypeValueField baseField = helper.GetATI(correctAti.file, info).GetBaseField(); GameObjectViewer view = new GameObjectViewer(helper, correctAti, baseField, info); view.Show(); } } } }