public AssetTypeValueField GetBaseField(AssetContainer cont) { AssetsFileInstance fileInst = cont.FileInstance; if (cont.ClassId == 0x72) { TypeTree tt = cont.FileInstance.file.typeTree; //check if typetree data exists already if (!tt.hasTypeTree || AssetHelper.FindTypeTreeTypeByScriptIndex(tt, cont.MonoId) == null) { //deserialize from dll (todo: ask user if dll isn't in normal location) string filePath; if (fileInst.parentBundle != null) filePath = Path.GetDirectoryName(fileInst.parentBundle.path); else filePath = Path.GetDirectoryName(fileInst.path); string managedPath = Path.Combine(filePath, "Managed"); if (Directory.Exists(managedPath)) { AssetTypeValueField monoBaseField = GetConcatMonoBaseField(cont, managedPath); if (monoBaseField != null) return monoBaseField; } //fallback to no mono deserialization for now } } cont = GetAssetContainer(cont.FileInstance, 0, cont.PathId, false); if (cont != null) return cont.TypeInstance.GetBaseField(); else return null; }
public AssetTypeValueField GetBaseField(AssetContainer cont) { var item = cont.Item; var fileInst = cont.FileInstance; if (item.TypeID == 0x72) { var tt = fileInst.file.typeTree; //check if typetree data exists already if (!tt.hasTypeTree || AssetHelper.FindTypeTreeTypeByScriptIndex(tt, item.MonoID) == null) { var filePath = Path.GetDirectoryName(fileInst.parentBundle != null ? fileInst.parentBundle.path : fileInst.path); var managedPath = Path.Combine(filePath ?? Environment.CurrentDirectory, "Managed"); if (!Directory.Exists(managedPath)) { var ofd = new OpenFolderDialog { Title = @"Select a folder for assemblies" }; if (ofd.ShowDialog() != DialogResult.OK) { return(cont.TypeInstance?.GetBaseField()); } managedPath = ofd.Folder; } var monoField = GetMonoBaseField(cont, managedPath); if (monoField != null) { return(monoField); } } } return(cont.TypeInstance?.GetBaseField()); }
public AssetTypeTemplateField GetTemplateField(AssetItem item, bool forceFromCldb = false) { var file = LoadedFiles[item.FileID].file; var hasTypeTree = file.typeTree.hasTypeTree; var baseField = new AssetTypeTemplateField(); var scriptIndex = item.MonoID; var fixedId = AssetHelper.FixAudioID(item.TypeID); if (hasTypeTree && !forceFromCldb) { baseField.From0D(AssetHelper.FindTypeTreeTypeByScriptIndex(file.typeTree, scriptIndex), 0); } else { baseField.FromClassDatabase(Am.classFile, AssetHelper.FindAssetClassByID(Am.classFile, fixedId), 0); } return(baseField); }
//codeflow needs work but should be fine for now public static void GetUABENameFast(AssetsFile file, ClassDatabaseFile cldb, AssetsFileReader reader, long filePosition, uint classId, ushort monoId, out string assetName, out string typeName) { ClassDatabaseType type = AssetHelper.FindAssetClassByID(cldb, classId); if (file.typeTree.hasTypeTree) { Type_0D ttType; if (classId == 0x72) { ttType = AssetHelper.FindTypeTreeTypeByScriptIndex(file.typeTree, monoId); } else { ttType = AssetHelper.FindTypeTreeTypeByID(file.typeTree, classId); } if (ttType != null && ttType.typeFieldsEx.Length != 0) { typeName = ttType.typeFieldsEx[0].GetTypeString(ttType.stringTable); if (ttType.typeFieldsEx.Length > 1 && ttType.typeFieldsEx[1].GetNameString(ttType.stringTable) == "m_Name") { reader.Position = filePosition; assetName = reader.ReadCountStringInt32(); if (assetName == "") { assetName = "Unnamed asset"; } return; } else if (typeName == "GameObject") { reader.Position = filePosition; int size = reader.ReadInt32(); int componentSize = file.header.format > 0x10 ? 0x0c : 0x10; reader.Position += size * componentSize; reader.Position += 0x04; assetName = reader.ReadCountStringInt32(); assetName = $"GameObject {assetName}"; return; } else if (typeName == "MonoBehaviour") { reader.Position = filePosition; reader.Position += 0x1c; assetName = reader.ReadCountStringInt32(); if (assetName == "") { assetName = "Unnamed asset"; } return; } assetName = "Unnamed asset"; return; } } if (type == null) { typeName = $"0x{classId:X8}"; assetName = "Unnamed asset"; return; } typeName = type.name.GetString(cldb); if (type.fields.Count == 0) { assetName = "Unnamed asset"; return; } if (type.fields.Count > 1 && type.fields[1].fieldName.GetString(cldb) == "m_Name") { reader.Position = filePosition; assetName = reader.ReadCountStringInt32(); if (assetName == "") { assetName = "Unnamed asset"; } return; } else if (typeName == "GameObject") { reader.Position = filePosition; int size = reader.ReadInt32(); int componentSize = file.header.format > 0x10 ? 0x0c : 0x10; reader.Position += size * componentSize; reader.Position += 0x04; assetName = reader.ReadCountStringInt32(); assetName = $"GameObject {assetName}"; return; } else if (typeName == "MonoBehaviour") { reader.Position = filePosition; reader.Position += 0x1c; assetName = reader.ReadCountStringInt32(); if (assetName == "") { assetName = "Unnamed asset"; } return; } assetName = "Unnamed asset"; return; }
public static void GetUAAENameFast(AssetsWorkspace workspace, AssetItem item, out string type, out string name) { var file = workspace.LoadedFiles[item.FileID].file; var cldb = workspace.Am.classFile; var classId = item.TypeID; var cldbType = AssetHelper.FindAssetClassByID(cldb, classId); var reader = file.reader; if (file.typeTree.hasTypeTree) { var ttType = classId == 0x72 ? AssetHelper.FindTypeTreeTypeByScriptIndex(file.typeTree, item.MonoID) : AssetHelper.FindTypeTreeTypeByID(file.typeTree, classId); type = ttType.typeFieldsEx[0].GetTypeString(ttType.stringTable); switch (ttType.typeFieldsEx.Length) { case > 1 when ttType.typeFieldsEx[1].GetNameString(ttType.stringTable) == "m_Name": { reader.Position = item.Position; name = reader.ReadCountStringInt32(); if (name != "") { return; } break; } default: switch (type) { case "GameObject": { reader.Position = item.Position; var size = reader.ReadInt32(); var componentSize = file.header.format > 0x10 ? 0x0c : 0x10; reader.Position += size * componentSize; reader.Position += 0x04; name = reader.ReadCountStringInt32(); name = name == "" ? "Unnamed asset" : $"{type} {name}"; return; } case "MonoBehaviour": reader.Position = item.Position; reader.Position += 0x1c; name = reader.ReadCountStringInt32(); name = name == "" ? "Unnamed asset" : $"{type} {name}"; return; } break; } name = "Unnamed asset"; return; } if (cldbType == null) { type = $"0x{classId:X8}"; name = "Unnamed asset"; return; } type = cldbType.name.GetString(cldb); switch (cldbType.fields.Count) { case 0: name = "Unnamed asset"; return; case > 1 when cldbType.fields[1].fieldName.GetString(cldb) == "m_Name": { reader.Position = item.Position; name = reader.ReadCountStringInt32(); if (name != "") { return; } break; } default: switch (type) { case "GameObject": { reader.Position = item.Position; var size = reader.ReadInt32(); var componentSize = file.header.format > 0x10 ? 0x0c : 0x10; reader.Position += size * componentSize; reader.Position += 0x04; name = reader.ReadCountStringInt32(); name = name == "" ? "Unnamed asset" : $"{type} {name}"; return; } case "MonoBehaviour": { reader.Position = item.Position; reader.Position += 0x1c; name = reader.ReadCountStringInt32(); name = name == "" ? "Unnamed asset" : $"{type} {name}"; return; } } break; } name = "Unnamed asset"; }