public AssetTypeInstance GetATI(AssetsFile file, AssetFileInfoEx info, bool fromTypeTree = false) { //do we still need pooling? //(it accumulates memory over time and we don't // really need to read the same ati twice) ushort scriptIndex = file.typeTree.pTypes_Unity5[info.curFileTypeOrIndex].scriptIndex; //unity is wack uint fixedId = info.curFileType; if (fixedId == 0xf1) //AudioMixerController { fixedId = 0xf0; //AudioMixer } else if (fixedId == 0xf3) //AudioMixerGroupController { fixedId = 0x111; //AudioMixerGroup } else if (fixedId == 0xf5) //AudioMixerSnapshotController { fixedId = 0x110; //AudioMixerSnapshot } AssetTypeTemplateField pBaseField = null; if (useTemplateFieldCache) { if (templateFieldCache.ContainsKey(fixedId)) { pBaseField = templateFieldCache[fixedId]; } else { pBaseField = new AssetTypeTemplateField(); if (fromTypeTree) { pBaseField.From0D(file.typeTree.pTypes_Unity5.First(t => (t.classId == fixedId || t.classId == info.curFileType) && t.scriptIndex == scriptIndex), 0); } else { pBaseField.FromClassDatabase(classFile, AssetHelper.FindAssetClassByID(classFile, fixedId), 0); } templateFieldCache[fixedId] = pBaseField; } } else { pBaseField = new AssetTypeTemplateField(); if (fromTypeTree) { pBaseField.From0D(file.typeTree.pTypes_Unity5.First(t => (t.classId == fixedId || t.classId == info.curFileType) && t.scriptIndex == scriptIndex), 0); } else { pBaseField.FromClassDatabase(classFile, AssetHelper.FindAssetClassByID(classFile, fixedId), 0); } } return(new AssetTypeInstance(pBaseField, file.reader, false, info.absoluteFilePos)); }
public AssetTypeInstance GetATI(Stream file, AssetFileInfoEx info) { int index = 0; bool foundInList = false; ClassDatabaseType type = AssetHelper.FindAssetClassByID(initialClassFile, info.curFileType); for (int i = 0; i < attfs.Count; i++) { if (attfs[i].type == type.name.GetString(initialClassFile)) { index = i; foundInList = true; } } AssetTypeInstance ati; if (foundInList) { ati = new AssetTypeInstance(new[] { attfs[index] }, new AssetsFileReader(file), info.absoluteFilePos); } else { AssetTypeTemplateField baseField = new AssetTypeTemplateField(); baseField.FromClassDatabase(initialClassFile, AssetHelper.FindAssetClassByID(initialClassFile, info.curFileType), 0); attfs.Add(baseField); ati = new AssetTypeInstance(new[] { attfs.Last() }, new AssetsFileReader(file), info.absoluteFilePos); } return(ati); }
public static AssetTypeInstance GetATI(AssetFile file, AssetFileInfoEx info) { ushort scriptIndex = file.fileInstance.file.typeTree.unity5Types[info.curFileTypeOrIndex].scriptIndex; uint fixedId = info.curFileType; if (fixedId == 0xf1) //AudioMixerController { fixedId = 0xf0; //AudioMixer } else if (fixedId == 0xf3) //AudioMixerGroupController { fixedId = 0x111; //AudioMixerGroup } else if (fixedId == 0xf5) //AudioMixerSnapshotController { fixedId = 0x110; //AudioMixerSnapshot } bool hasTypeTree = file.fileInstance.file.typeTree.hasTypeTree; var baseField = new AssetTypeTemplateField(); if (hasTypeTree) { baseField.From0D( file.fileInstance.file.typeTree.unity5Types.First(t => (t.classId == fixedId || t.classId == info.curFileType) && t.scriptIndex == scriptIndex), 0); } else { baseField.FromClassDatabase(file.classDBFile, AssetHelper.FindAssetClassByID(file.classDBFile, fixedId), 0); } return(new AssetTypeInstance(baseField, file.fileInstance.file.reader, info.absoluteFilePos)); }
//time to update the api I guess private AssetTypeValueField CreatePPtrField(int fileId, long pathId) { AssetTypeTemplateField pptrTemp = new AssetTypeTemplateField(); pptrTemp.FromClassDatabase(am.classFile, AssetHelper.FindAssetClassByID(am.classFile, 0x01), 5); //[5] PPtr<Component> component AssetTypeValueField fileVal = new AssetTypeValueField() { templateField = pptrTemp.children[0], childrenCount = 0, children = null, value = new AssetTypeValue(EnumValueTypes.ValueType_Int32, fileId) }; AssetTypeValueField pathVal = new AssetTypeValueField() { templateField = pptrTemp.children[1], childrenCount = 0, children = null, value = new AssetTypeValue(EnumValueTypes.ValueType_Int64, pathId) }; AssetTypeValueField pptrVal = new AssetTypeValueField() { templateField = pptrTemp, childrenCount = 2, children = new AssetTypeValueField[] { fileVal, pathVal }, value = new AssetTypeValue(EnumValueTypes.ValueType_None, null) }; return(pptrVal); }
public AssetTypeTemplateField GetTemplateBaseField(AssetsFile file, AssetFileInfoEx info, bool forceFromCldb = false) { ushort scriptIndex = AssetHelper.GetScriptIndex(file, info); uint fixedId = AssetHelper.FixAudioID(info.curFileType); bool hasTypeTree = file.typeTree.hasTypeTree; AssetTypeTemplateField baseField; if (useTemplateFieldCache && templateFieldCache.ContainsKey(fixedId)) { baseField = templateFieldCache[fixedId]; } else { baseField = new AssetTypeTemplateField(); if (hasTypeTree && !forceFromCldb) { baseField.From0D(AssetHelper.FindTypeTreeTypeByID(file.typeTree, fixedId, scriptIndex), 0); } else { baseField.FromClassDatabase(classFile, AssetHelper.FindAssetClassByID(classFile, fixedId), 0); } if (useTemplateFieldCache) { templateFieldCache[fixedId] = baseField; } } return(baseField); }
public static AssetTypeValueField GetMonoBaseField(AssetsManager am, AssetsFileInstance inst, AssetFileInfoEx info, string managedPath) { AssetsFile file = inst.file; AssetTypeTemplateField baseField = new AssetTypeTemplateField(); baseField.FromClassDatabase(am.classFile, AssetHelper.FindAssetClassByID(am.classFile, info.curFileType), 0); AssetTypeInstance mainAti = new AssetTypeInstance(baseField, file.reader, false, info.absoluteFilePos); if (file.typeTree.pTypes_Unity5[info.curFileTypeOrIndex].scriptIndex != 0xFFFF) { AssetTypeInstance scriptAti = am.GetExtAsset(inst, mainAti.GetBaseField().Get("m_Script")).instance; string scriptName = scriptAti.GetBaseField().Get("m_Name").GetValue().AsString(); string assemblyName = scriptAti.GetBaseField().Get("m_AssemblyName").GetValue().AsString(); string assemblyPath = Path.Combine(managedPath, assemblyName); if (File.Exists(assemblyPath)) { MonoClass mc = new MonoClass(); mc.Read(scriptName, assemblyPath, inst.file.header.format); AssetTypeTemplateField[] monoTemplateFields = mc.children; AssetTypeTemplateField[] templateField = baseField.children.Concat(monoTemplateFields).ToArray(); baseField.children = templateField; baseField.childrenCount = (uint)baseField.children.Length; mainAti = new AssetTypeInstance(baseField, file.reader, false, info.absoluteFilePos); } } return(mainAti.GetBaseField()); }
public AssetTypeInstance GetATI(AssetsFile file, AssetFileInfoEx info, bool forceFromCldb = false) { ushort scriptIndex = file.typeTree.unity5Types[info.curFileTypeOrIndex].scriptIndex; //unity is wack uint fixedId = info.curFileType; if (fixedId == 0xf1) //AudioMixerController { fixedId = 0xf0; //AudioMixer } else if (fixedId == 0xf3) //AudioMixerGroupController { fixedId = 0x111; //AudioMixerGroup } else if (fixedId == 0xf5) //AudioMixerSnapshotController { fixedId = 0x110; //AudioMixerSnapshot } bool hasTypeTree = file.typeTree.hasTypeTree; AssetTypeTemplateField baseField = null; if (useTemplateFieldCache) { if (templateFieldCache.ContainsKey(fixedId)) { baseField = templateFieldCache[fixedId]; } else { baseField = new AssetTypeTemplateField(); if (hasTypeTree && !forceFromCldb) { baseField.From0D(file.typeTree.unity5Types.First(t => (t.classId == fixedId || t.classId == info.curFileType) && t.scriptIndex == scriptIndex), 0); } else { baseField.FromClassDatabase(classFile, AssetHelper.FindAssetClassByID(classFile, fixedId), 0); } templateFieldCache[fixedId] = baseField; } } else { baseField = new AssetTypeTemplateField(); if (hasTypeTree && !forceFromCldb) { baseField.From0D(file.typeTree.unity5Types.First(t => (t.classId == fixedId || t.classId == info.curFileType) && t.scriptIndex == scriptIndex), 0); } else { baseField.FromClassDatabase(classFile, AssetHelper.FindAssetClassByID(classFile, fixedId), 0); } } return(new AssetTypeInstance(baseField, file.reader, info.absoluteFilePos)); }
public AssetTypeTemplateField GetTemplateField(AssetsFile file, uint type, ushort scriptIndex) { uint fixedId = AssetHelper.FixAudioID(type); bool hasTypeTree = file.typeTree.hasTypeTree; AssetTypeTemplateField baseField = new AssetTypeTemplateField(); if (hasTypeTree) { Type_0D type0d = Extensions.FindTypeTreeTypeByID(file.typeTree, fixedId, scriptIndex); if (type0d != null && type0d.typeFieldsExCount > 0) baseField.From0D(type0d, 0); else //fallback to cldb baseField.FromClassDatabase(am.classFile, AssetHelper.FindAssetClassByID(am.classFile, fixedId), 0); } else { baseField.FromClassDatabase(am.classFile, AssetHelper.FindAssetClassByID(am.classFile, fixedId), 0); } return baseField; }
public static AssetTypeValueField GetMonoBaseField(AssetsManager am, AssetsFileInstance inst, AssetFileInfoEx info, string managedPath, bool cached = true) { AssetsFile file = inst.file; AssetTypeTemplateField baseField = new AssetTypeTemplateField(); baseField.FromClassDatabase(am.classFile, AssetHelper.FindAssetClassByID(am.classFile, info.curFileType), 0); AssetTypeInstance mainAti = new AssetTypeInstance(baseField, file.reader, info.absoluteFilePos); ushort scriptIndex = AssetHelper.GetScriptIndex(file, info); if (scriptIndex != 0xFFFF) { AssetTypeInstance scriptAti = am.GetExtAsset(inst, mainAti.GetBaseField().Get("m_Script")).instance; string scriptName = scriptAti.GetBaseField().Get("m_ClassName").GetValue().AsString(); string scriptNamespace = scriptAti.GetBaseField().Get("m_Namespace").GetValue().AsString(); string assemblyName = scriptAti.GetBaseField().Get("m_AssemblyName").GetValue().AsString(); string assemblyPath = Path.Combine(managedPath, assemblyName); if (scriptNamespace != string.Empty) { scriptName = scriptNamespace + "." + scriptName; } if (File.Exists(assemblyPath)) { AssemblyDefinition asmDef; if (cached) { if (!loadedAssemblies.ContainsKey(assemblyName)) { loadedAssemblies.Add(assemblyName, GetAssemblyWithDependencies(assemblyPath)); } asmDef = loadedAssemblies[assemblyName]; } else { asmDef = GetAssemblyWithDependencies(assemblyPath); } MonoDeserializer mc = new MonoDeserializer(); mc.Read(scriptName, asmDef, inst.file.header.format); List <AssetTypeTemplateField> monoTemplateFields = mc.children; AssetTypeTemplateField[] templateField = baseField.children.Concat(monoTemplateFields).ToArray(); baseField.children = templateField; baseField.childrenCount = baseField.children.Length; mainAti = new AssetTypeInstance(baseField, file.reader, info.absoluteFilePos); } } return(mainAti.GetBaseField()); }
public AssetTypeValueField GetMonoBaseField(AssetContainer cont, string managedPath) { var file = cont.FileInstance.file; var item = cont.Item; var baseTemp = new AssetTypeTemplateField(); baseTemp.FromClassDatabase(Am.classFile, AssetHelper.FindAssetClassByID(Am.classFile, item.TypeID), 0); var mainAti = new AssetTypeInstance(baseTemp, cont.FileReader, item.Position); var scriptIndex = item.MonoID; if (scriptIndex != 0xFFFF) { var monoScriptCont = GetAssetContainer(mainAti.GetBaseField().Get("m_Script")); if (monoScriptCont == null) { return(null); } var scriptBaseField = monoScriptCont.TypeInstance.GetBaseField(); var scriptName = scriptBaseField.Get("m_Name").GetValue().AsString(); var scriptNamespace = scriptBaseField.Get("m_Namespace").GetValue().AsString(); var assemblyName = scriptBaseField.Get("m_AssemblyName").GetValue().AsString(); var assemblyPath = Path.Combine(managedPath, assemblyName); if (scriptNamespace != string.Empty) { scriptName = scriptNamespace + "." + scriptName; } if (File.Exists(assemblyPath)) { if (!LoadedAssemblies.ContainsKey(assemblyName)) { LoadedAssemblies.Add(assemblyName, MonoDeserializer.GetAssemblyWithDependencies(assemblyPath)); } var asmDef = LoadedAssemblies[assemblyName]; var mc = new MonoDeserializer(); mc.Read(scriptName, asmDef, file.header.format); var monoTemplateFields = mc.children; var templateField = baseTemp.children.Concat(monoTemplateFields).ToArray(); baseTemp.children = templateField; baseTemp.childrenCount = baseTemp.children.Length; mainAti = new AssetTypeInstance(baseTemp, cont.FileReader, item.Position); } } return(mainAti.GetBaseField()); }
public static AssetTypeValueField GetMonoBaseFieldCached(this AssetsManager am, AssetsFileInstance inst, AssetFileInfoEx info, string managedPath, List <string> fileNames, Dictionary <AssetID, long> aidToPid) { AssetsFile file = inst.file; ushort scriptIndex = file.typeTree.unity5Types[info.curFileTypeOrIndex].scriptIndex; if (scriptIndex != 0xFFFF && inst.templateFieldCache.ContainsKey(scriptIndex)) { AssetTypeTemplateField baseTemplateField = inst.templateFieldCache[scriptIndex]; AssetTypeInstance baseAti = new AssetTypeInstance(baseTemplateField, file.reader, info.absoluteFilePos); return(baseAti.GetBaseField()); } else { AssetTypeTemplateField baseField = new AssetTypeTemplateField(); baseField.FromClassDatabase(am.classFile, AssetHelper.FindAssetClassByID(am.classFile, info.curFileType), 0); AssetTypeInstance mainAti = new AssetTypeInstance(baseField, file.reader, info.absoluteFilePos); if (file.typeTree.unity5Types[info.curFileTypeOrIndex].scriptIndex != 0xFFFF) { AssetTypeValueField m_Script = mainAti.GetBaseField().Get("m_Script"); int m_ScriptFileId = m_Script.Get("m_FileID").GetValue().AsInt(); long m_ScriptPathId = m_Script.Get("m_PathID").GetValue().AsInt64(); AssetID id = new AssetID(fileNames[-m_ScriptFileId], m_ScriptPathId); long m_ScriptRealPathId = aidToPid[id]; AssetTypeInstance scriptAti = am.GetExtAsset(inst, 0, m_ScriptRealPathId).instance; string scriptName = scriptAti.GetBaseField().Get("m_Name").GetValue().AsString(); string assemblyName = scriptAti.GetBaseField().Get("m_AssemblyName").GetValue().AsString(); string assemblyPath = Path.Combine(managedPath, assemblyName); Console.WriteLine("checking " + scriptName + " in " + assemblyName + " from id " + info.index); if (File.Exists(assemblyPath)) { MonoDeserializer mc = new MonoDeserializer(); mc.Read(scriptName, assemblyPath, inst.file.header.format); List <AssetTypeTemplateField> monoTemplateFields = mc.children; AssetTypeTemplateField[] templateField = baseField.children.Concat(monoTemplateFields).ToArray(); baseField.children = templateField; baseField.childrenCount = baseField.children.Length; mainAti = new AssetTypeInstance(baseField, file.reader, info.absoluteFilePos); } } AssetTypeValueField baseValueField = mainAti.GetBaseField(); inst.templateFieldCache[scriptIndex] = baseValueField.templateField; return(baseValueField); } }
public AssetTypeInstance GetATI(AssetsFile file, AssetFileInfoEx info, bool forceFromCldb = false) { ushort scriptIndex = AssetHelper.GetScriptIndex(file, info); uint fixedId = AssetHelper.FixAudioID(info.curFileType); bool hasTypeTree = file.typeTree.hasTypeTree; AssetTypeTemplateField baseField; if (useTemplateFieldCache && templateFieldCache.ContainsKey(fixedId)) { baseField = templateFieldCache[fixedId]; } else { baseField = new AssetTypeTemplateField(); if (hasTypeTree && !forceFromCldb) { if (file.header.format < 0x10) { if (scriptIndex == 0xFFFF) { baseField.From0D(AssetHelper.FindTypeTreeTypeByID(file.typeTree, fixedId), 0); } else { baseField.From0D(AssetHelper.FindTypeTreeTypeByScriptIndex(file.typeTree, scriptIndex), 0); } } else { baseField.From0D(AssetHelper.FindTypeTreeTypeByID(file.typeTree, fixedId), 0); } } else { baseField.FromClassDatabase(classFile, AssetHelper.FindAssetClassByID(classFile, fixedId), 0); } if (useTemplateFieldCache) { templateFieldCache[fixedId] = baseField; } } return(new AssetTypeInstance(baseField, file.reader, info.absoluteFilePos)); }
public AssetTypeValueField GetConcatMonoBaseField(AssetContainer cont, string managedPath) { AssetsFile file = cont.FileInstance.file; AssetTypeTemplateField baseTemp = new AssetTypeTemplateField(); baseTemp.FromClassDatabase(am.classFile, AssetHelper.FindAssetClassByID(am.classFile, cont.ClassId), 0); AssetTypeInstance mainAti = new AssetTypeInstance(baseTemp, cont.FileReader, cont.FilePosition); ushort scriptIndex = cont.MonoId; if (scriptIndex != 0xFFFF) { AssetContainer monoScriptCont = GetAssetContainer(cont.FileInstance, mainAti.GetBaseField().Get("m_Script"), false); if (monoScriptCont == null) return null; AssetTypeValueField scriptBaseField = monoScriptCont.TypeInstance.GetBaseField(); string scriptName = scriptBaseField.Get("m_Name").GetValue().AsString(); string scriptNamespace = scriptBaseField.Get("m_Namespace").GetValue().AsString(); string assemblyName = scriptBaseField.Get("m_AssemblyName").GetValue().AsString(); string assemblyPath = Path.Combine(managedPath, assemblyName); if (scriptNamespace != string.Empty) scriptName = scriptNamespace + "." + scriptName; if (File.Exists(assemblyPath)) { AssemblyDefinition asmDef; if (!LoadedAssemblies.ContainsKey(assemblyName)) { LoadedAssemblies.Add(assemblyName, MonoDeserializer.GetAssemblyWithDependencies(assemblyPath)); } asmDef = LoadedAssemblies[assemblyName]; MonoDeserializer mc = new MonoDeserializer(); mc.Read(scriptName, asmDef, file.header.format); List<AssetTypeTemplateField> monoTemplateFields = mc.children; AssetTypeTemplateField[] templateField = baseTemp.children.Concat(monoTemplateFields).ToArray(); baseTemp.children = templateField; baseTemp.childrenCount = baseTemp.children.Length; mainAti = new AssetTypeInstance(baseTemp, cont.FileReader, cont.FilePosition); } } return mainAti.GetBaseField(); }
public AssetTypeValueField GetByteArrayTexture(AssetWorkspace workspace, AssetExternal tex) { ClassDatabaseType textureType = AssetHelper.FindAssetClassByID(workspace.am.classFile, tex.info.curFileType); AssetTypeTemplateField textureTemp = new AssetTypeTemplateField(); textureTemp.FromClassDatabase(workspace.am.classFile, textureType, 0); AssetTypeTemplateField image_data = textureTemp.children.FirstOrDefault(f => f.name == "image data"); if (image_data == null) { return(null); } image_data.valueType = EnumValueTypes.ByteArray; AssetTypeInstance textureTypeInstance = new AssetTypeInstance(new[] { textureTemp }, tex.file.file.reader, tex.info.absoluteFilePos); AssetTypeValueField textureBase = textureTypeInstance.GetBaseField(); return(textureBase); }
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); }
public AssetTypeInstance GetATI(AssetsFile file, AssetFileInfoEx info) { //do we still need pooling? //(it accumulates memory over time and we don't // really need to read the same ati twice) //unity is wack uint fixedId = info.curFileType; if (fixedId == 0xf1) //AudioMixerController { fixedId = 0xf0; //AudioMixer } else if (fixedId == 0xf3) //AudioMixerGroupController { fixedId = 0x111; //AudioMixerGroup } else if (fixedId == 0xf5) //AudioMixerSnapshotController { fixedId = 0x110; //AudioMixerSnapshot } AssetTypeTemplateField pBaseField = null; if (useTemplateFieldCache) { if (templateFieldCache.ContainsKey(fixedId)) { pBaseField = templateFieldCache[fixedId]; } else { pBaseField = new AssetTypeTemplateField(); pBaseField.FromClassDatabase(classFile, AssetHelper.FindAssetClassByID(classFile, fixedId), 0); templateFieldCache[fixedId] = pBaseField; } } else { pBaseField = new AssetTypeTemplateField(); pBaseField.FromClassDatabase(classFile, AssetHelper.FindAssetClassByID(classFile, fixedId), 0); } return(new AssetTypeInstance(pBaseField, file.reader, false, info.absoluteFilePos)); }
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); }
public static AssetTypeValueField GetMonoBaseField(AssetsManager am, AssetsFile af, AssetFileInfoEx afi, string folderPath) { ClassDatabaseType cldt = AssetHelper.FindAssetClassByID(am.classFile, afi.curFileType); AssetTypeTemplateField pBaseField = new AssetTypeTemplateField(); pBaseField.FromClassDatabase(am.classFile, cldt, 0); AssetTypeInstance mainAti = new AssetTypeInstance(1, new[] { pBaseField }, af.reader, false, afi.absoluteFilePos); AssetTypeTemplateField[] desMonos; desMonos = TryDeserializeMono(mainAti, am, folderPath); if (desMonos != null) { AssetTypeTemplateField[] templateField = pBaseField.children.Concat(desMonos).ToArray(); pBaseField.children = templateField; pBaseField.childrenCount = (uint)pBaseField.children.Length; mainAti = new AssetTypeInstance(1, new[] { pBaseField }, af.reader, false, afi.absoluteFilePos); } return(mainAti.GetBaseField()); }
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); }
private void PopulateTree() { ClassDatabaseType cldt = AssetHelper.FindAssetClassByID(am.initialClassFile, assetDetails.type); AssetTypeTemplateField baseFieldTemp = new AssetTypeTemplateField(); baseFieldTemp.FromClassDatabase(am.initialClassFile, cldt, 0); mainAti = new AssetTypeInstance(new[] { baseFieldTemp }, af.reader, assetDetails.position); if (assetDetails.type == 0x72) { AssetTypeTemplateField[] desMonos = TryDeserializeMono(mainAti); if (desMonos != null) { AssetTypeTemplateField[] templateField = baseFieldTemp.children.Concat(desMonos).ToArray(); baseFieldTemp.children = templateField; baseFieldTemp.childrenCount = baseFieldTemp.children.Length; mainAti = new AssetTypeInstance(new[] { baseFieldTemp }, af.reader, assetDetails.position); } } AssetTypeValueField baseField = mainAti.GetBaseField(); rawViewTree.Nodes.Add(baseField.GetFieldType() + " " + baseField.GetName()); RecursiveTreeLoad(mainAti.GetBaseField(), rawViewTree.Nodes[0], 0); }
private void GetTk2dSprites(AssetsFileInstance inst) { collections = new List <TkSpriteCollection>(); animations = new List <TkSpriteAnimation>(); animationClips = new List <TkSpriteAnimationClip>(); List <TkSpriteFrame> sprFrames = new List <TkSpriteFrame>(); string managedPath = Path.Combine(Path.GetDirectoryName(inst.path), "Managed"); Dictionary <AssetID, TkSpriteCollection> collectionLookup = new Dictionary <AssetID, TkSpriteCollection>(); int tk2dSCid = -1; int tk2dSAid = -1; foreach (AssetFileInfoEx mbInf in inst.table.GetAssetsOfType(0x72)) { string scriptName = null; ushort scriptIndex = AssetHelper.GetScriptIndex(inst.file, mbInf); if (tk2dSCid != -1 && scriptIndex == tk2dSCid) { scriptName = "tk2dSpriteCollectionData"; } else if (tk2dSAid != -1 && scriptIndex == tk2dSAid) { scriptName = "tk2dSpriteAnimation"; } if (tk2dSCid == -1 || tk2dSAid == -1) //still looking for script ids { AssetTypeValueField mbBase = am.GetATI(inst.file, mbInf).GetBaseField(); AssetTypeValueField scBase = am.GetExtAsset(inst, mbBase.Get("m_Script")).instance.GetBaseField(); scriptName = scBase.Get("m_Name").GetValue().AsString(); if (scriptName == "tk2dSpriteCollectionData") { tk2dSCid = scriptIndex; } else if (scriptName == "tk2dSpriteAnimation") { tk2dSAid = scriptIndex; } else { continue; //nope, nobody cares } } if (scriptName == null) { continue; } AssetTypeValueField mbSerialBase = am.GetMonoBaseFieldCached(inst, mbInf, managedPath); if (scriptName == "tk2dSpriteCollectionData") { AssetTypeValueField textures = mbSerialBase.Get("textures"); List <AssetExternal> textureExts = new List <AssetExternal>(); List <int> textureWidths = new List <int>(); List <int> textureHeights = new List <int>(); for (int i = 0; i < textures.childrenCount; i++) { AssetExternal textureExt = am.GetExtAsset(inst, mbSerialBase.Get("textures")[i], true); if (textureExt.info.curFileSize > 100000) { //bad news, unity probably stored the entire image into an array which is gonna //take up too much memory when we decode it, so we'll change the data to a byte array ClassDatabaseType textureType = AssetHelper.FindAssetClassByID(am.classFile, textureExt.info.curFileType); AssetTypeTemplateField textureTemp = new AssetTypeTemplateField(); textureTemp.FromClassDatabase(am.classFile, textureType, 0); AssetTypeTemplateField image_data = textureTemp.children[textureTemp.childrenCount - 1]; image_data.valueType = EnumValueTypes.ByteArray; //convert array to bytearray, much better AssetTypeInstance textureTypeInstance = new AssetTypeInstance(new[] { textureTemp }, inst.file.reader, textureExt.info.absoluteFilePos); AssetTypeValueField textureBase = textureTypeInstance.GetBaseField(); textureExt.instance = textureTypeInstance; textureExts.Add(textureExt); textureWidths.Add(textureBase.Get("m_Width").GetValue().AsInt()); textureHeights.Add(textureBase.Get("m_Height").GetValue().AsInt()); } else { textureExt = am.GetExtAsset(inst, mbSerialBase.Get("textures")[i]); AssetTypeValueField textureBase = textureExt.instance.GetBaseField(); textureExts.Add(textureExt); textureWidths.Add(textureBase.Get("m_Width").GetValue().AsInt()); textureHeights.Add(textureBase.Get("m_Height").GetValue().AsInt()); } } TkSpriteCollection collection = new TkSpriteCollection() { name = mbSerialBase.Get("spriteCollectionName").GetValue().AsString(), version = mbSerialBase.Get("version").GetValue().AsInt(), baseTexture = null, //do later textures = new Dictionary <int, Bitmap>(), //same textureExts = textureExts, sprites = new List <TkSpriteDefinition>() }; collectionLookup[new AssetID(inst.name, mbInf.index)] = collection; AssetTypeValueField spriteDefinitions = mbSerialBase.Get("spriteDefinitions"); foreach (AssetTypeValueField def in spriteDefinitions.children) { bool flipped = def.Get("flipped").GetValue().AsInt() == 1; int materialId = def.Get("materialId").GetValue().AsInt(); int textureWidth = textureWidths[materialId]; int textureHeight = textureHeights[materialId]; double uxn = double.MaxValue; double uxp = 0; double uyn = double.MaxValue; double uyp = 0; double pxn = double.MaxValue; double pyn = double.MaxValue; AssetTypeValueField positions = def.Get("positions"); AssetTypeValueField uvs = def.Get("uvs"); for (int i = 0; i < 4; i++) { AssetTypeValueField pos = positions[i]; AssetTypeValueField uv = uvs[i]; double posX = pos.Get("x").GetValue().AsFloat(); double posY = pos.Get("y").GetValue().AsFloat(); double uvX = Math.Round(uv.Get("x").GetValue().AsFloat() * textureWidth); double uvY = textureHeight - Math.Round(uv.Get("y").GetValue().AsFloat() * textureHeight); if (posX < pxn) { pxn = posX; } if (posY < pyn) { pyn = posY; } if (uvX < uxn) { uxn = uvX; } if (uvX > uxp) { uxp = uvX; } if (uvY < uyn) { uyn = uvY; } if (uvY > uyp) { uyp = uvY; } } int spriteX = (int)uxn; int spriteY = (int)uyn; int spriteWidth = (int)(uxp - uxn); int spriteHeight = (int)(uyp - uyn); AssetTypeValueField boundsData = def.Get("boundsData"); AssetTypeValueField untrimmedBoundsData = def.Get("untrimmedBoundsData"); AssetTypeValueField texelSize = def.Get("texelSize"); float texelX = texelSize.Get("x").GetValue().AsFloat(); float texelY = texelSize.Get("y").GetValue().AsFloat(); float realX = ((float)pxn) / texelX; float realY = -((flipped ? spriteWidth : spriteHeight) + ((float)pyn) / texelY); TkSpriteDefinition sprite = new TkSpriteDefinition() { parent = collection, name = def.Get("name").GetValue().AsString(), x = spriteX, y = spriteY, width = spriteWidth, height = spriteHeight, xOff = realX, yOff = realY, materialId = materialId, fullWidth = untrimmedBoundsData[1].Get("x").GetValue().AsFloat() / texelX, fullHeight = untrimmedBoundsData[1].Get("y").GetValue().AsFloat() / texelY, flipped = flipped }; collection.sprites.Add(sprite); } collections.Add(collection); } else if (scriptName == "tk2dSpriteAnimation") { AssetFileInfoEx gameObjectInfo = inst.table.GetAssetInfo(mbSerialBase.Get("m_GameObject").Get("m_PathID").GetValue().AsInt64()); TkSpriteAnimation animation = new TkSpriteAnimation() { parents = new List <TkSpriteCollection>(), //do later parentIds = new List <AssetID>(), gameObjectName = AssetHelper.GetAssetNameFast(inst.file, am.classFile, gameObjectInfo), clips = new List <TkSpriteAnimationClip>() }; AssetTypeValueField clips = mbSerialBase.Get("clips"); foreach (AssetTypeValueField clip in clips.children) { TkSpriteAnimationClip aniClip = new TkSpriteAnimationClip() { parent = animation, name = clip.Get("name").GetValue().AsString(), fps = clip.Get("fps").GetValue().AsFloat(), loopStart = clip.Get("loopStart").GetValue().AsInt(), wrapMode = (WrapMode)clip.Get("wrapMode").GetValue().AsInt(), frames = new List <TkSpriteFrame>() }; animation.clips.Add(aniClip); animationClips.Add(aniClip); AssetTypeValueField frames = clip.Get("frames"); foreach (AssetTypeValueField frame in frames.children) { AssetExternal collectionExt = am.GetExtAsset(inst, frame.Get("spriteCollection")); AssetID collectionId = new AssetID(collectionExt.file.name, collectionExt.info.index); if (!animation.parentIds.Contains(collectionId)) { animation.parentIds.Add(collectionId); } TkSpriteFrame sprFrame = new TkSpriteFrame() { collection = null, //do later collectionId = collectionId, spriteId = frame.Get("spriteId").GetValue().AsInt() }; sprFrames.Add(sprFrame); aniClip.frames.Add(sprFrame); } } animations.Add(animation); } } foreach (TkSpriteAnimation animation in animations) { foreach (AssetID parentId in animation.parentIds) { if (collectionLookup.ContainsKey(parentId)) { animation.parents.Add(collectionLookup[parentId]); } } } foreach (TkSpriteFrame frame in sprFrames) { if (collectionLookup.ContainsKey(frame.collectionId)) { frame.collection = collectionLookup[frame.collectionId]; } } }