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()); }
private void RecursiveChildSearch(TreeNode node, AssetTypeValueField field) { AssetTypeValueField children = helper.GetExtAsset(inst, field.Get("m_Component") .Get("Array") .Get(0) .Get("component")).instance .GetBaseField() .Get("m_Children") .Get("Array"); for (int i = 0; i < children.GetValue().AsArray().size; i++) { AssetTypeInstance newInstance = helper.GetExtAsset(inst, children.Get((uint)i)).instance; AssetsManager.AssetExternal gameObjExt = helper.GetExtAsset(inst, newInstance.GetBaseField().Get("m_GameObject")); AssetTypeInstance newAti = gameObjExt.instance; AssetTypeValueField newBaseField = newAti.GetBaseField(); TreeNode newNode = node.Nodes.Add(newBaseField.Get("m_Name").GetValue().AsString()); if (!newBaseField.Get("m_IsActive").GetValue().AsBool()) { newNode.ForeColor = Color.DarkRed; } newNode.Tag = newBaseField; if (gameObjExt.info.index == selectedIndex) { goTree.SelectedNode = newNode; } RecursiveChildSearch(newNode, newBaseField); } }
//AssetTypeInstance public static void Write(this AssetTypeInstance instance, AssetsFileWriter writer) { for (int i = 0; i < instance.baseFieldCount; i++) { instance.baseFields[i].Write(writer); } }
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); }
private void LoadGGM(AssetsFileInstance mainFile) { //swap this with resources so we can actually see ggm assets foreach (AssetFileInfoEx info in mainFile.table.pAssetFileInfo) { ClassDatabaseType type = AssetHelper.FindAssetClassByID(helper.classFile, info.curFileType); if (type.name.GetString(helper.classFile) == "ResourceManager") { AssetTypeInstance inst = helper.GetATI(mainFile.file, info); AssetTypeValueField baseField = inst.GetBaseField(); AssetTypeValueField m_Container = baseField.Get("m_Container").Get("Array"); //Dictionary<string, AssetDetails> paths = new Dictionary<string, AssetDetails>(); List <AssetDetails> assets = new List <AssetDetails>(); for (uint i = 0; i < m_Container.GetValue().AsArray().size; i++) { AssetTypeValueField item = m_Container[i]; string path = item.Get("first").GetValue().AsString(); AssetTypeValueField pointerField = item.Get("second"); uint fileID = (uint)pointerField.Get("m_FileID").GetValue().AsInt(); ulong pathID = (ulong)pointerField.Get("m_PathID").GetValue().AsInt64(); //paths[path] = new AssetDetails(new AssetPPtr(fileID, pathID)); assets.Add(new AssetDetails(new AssetPPtr(fileID, pathID), AssetIcon.Unknown, path)); } rootDir = new FSDirectory(); //rootDir.Create(paths); rootDir.Create(assets); ChangeDirectory(""); helper.UpdateDependencies(); CheckResourcesInfo(); return; } } }
public AssetTypeValueField GetMonoBaseFieldCached(AssetsFileInstance inst, AssetFileInfoEx info, string managedPath) { //AssetsFile file = inst.file; //ushort scriptIndex = AssetHelper.GetScriptIndex(file, info); //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 //{ // AssetTypeValueField baseValueField = MonoDeserializer.GetMonoBaseField(this, inst, info, managedPath); // inst.templateFieldCache[scriptIndex] = baseValueField.templateField; // return baseValueField; //} AssetsFile file = inst.file; ushort scriptIndex = AssetHelper.GetScriptIndex(file, info); if (scriptIndex == 0xFFFF) { return(null); } string scriptName; if (!inst.monoIdToName.ContainsKey(scriptIndex)) { AssetTypeInstance scriptAti = GetExtAsset(inst, GetATI(inst.file, info).GetBaseField().Get("m_Script")).instance; scriptName = scriptAti.GetBaseField().Get("m_Name").GetValue().AsString(); string scriptNamespace = scriptAti.GetBaseField().Get("m_Namespace").GetValue().AsString(); string assemblyName = scriptAti.GetBaseField().Get("m_AssemblyName").GetValue().AsString(); if (scriptNamespace != string.Empty) { scriptNamespace = "-"; } scriptName = $"{assemblyName}.{scriptNamespace}.{scriptName}"; inst.monoIdToName[scriptIndex] = scriptName; } else { scriptName = inst.monoIdToName[scriptIndex]; } if (monoTemplateFieldCache.ContainsKey(scriptName)) { AssetTypeTemplateField baseTemplateField = monoTemplateFieldCache[scriptName]; AssetTypeInstance baseAti = new AssetTypeInstance(baseTemplateField, file.reader, info.absoluteFilePos); return(baseAti.GetBaseField()); } else { AssetTypeValueField baseValueField = MonoDeserializer.GetMonoBaseField(this, inst, info, managedPath); monoTemplateFieldCache[scriptName] = baseValueField.templateField; return(baseValueField); } }
private void LoadResources(AssetsFileInstance ggm) { foreach (AssetFileInfoEx info in ggm.table.assetFileInfo) { ClassDatabaseType type = AssetHelper.FindAssetClassByID(helper.classFile, info.curFileType); if (type.name.GetString(helper.classFile) == "ResourceManager") { AssetTypeInstance inst = helper.GetTypeInstance(ggm.file, info); AssetTypeValueField baseField = inst.GetBaseField(); AssetTypeValueField m_Container = baseField.Get("m_Container").Get("Array"); List <AssetDetails> assets = new List <AssetDetails>(); for (int i = 0; i < m_Container.GetValue().AsArray().size; i++) { AssetTypeValueField item = m_Container[i]; string path = item.Get("first").GetValue().AsString(); AssetTypeValueField pointerField = item.Get("second"); //paths[path] = new AssetDetails(new AssetPPtr(fileID, pathID)); AssetExternal assetExt = helper.GetExtAsset(ggm, pointerField, true); AssetFileInfoEx assetInfo = assetExt.info; if (assetInfo == null) { continue; } ClassDatabaseType assetType = AssetHelper.FindAssetClassByID(helper.classFile, assetInfo.curFileType); if (assetType == null) { continue; } string assetTypeName = assetType.name.GetString(helper.classFile); string assetName = AssetHelper.GetAssetNameFast(assetExt.file.file, helper.classFile, assetInfo); if (path.Contains("/")) { if (path.Substring(path.LastIndexOf('/') + 1) == assetName.ToLower()) { path = path.Substring(0, path.LastIndexOf('/') + 1) + assetName; } } else { if (path == assetName.ToLower()) { path = path.Substring(0, path.LastIndexOf('/') + 1) + assetName; } } assets.Add(new AssetDetails(new AssetPPtr(0, assetInfo.index), GetIconForName(assetTypeName), path, assetTypeName, (int)assetInfo.curFileSize)); } rootDir = new FSDirectory(); //rootDir.Create(paths); rootDir.Create(assets); ChangeDirectory(""); helper.UpdateDependencies(); CheckResourcesInfo(); return; } } }
//Existing assets public AssetContainer MakeAssetContainer(AssetItem item, bool forceFromCldb = false) { var fileInst = LoadedFiles[item.FileID]; var reader = fileInst.file.reader; var templateField = GetTemplateField(item, forceFromCldb); var typeInst = new AssetTypeInstance(templateField, reader, item.Position); return(new AssetContainer(item, fileInst, typeInst)); }
private string GetClassName(AssetsManager manager, AssetsFileInstance inst, AssetTypeValueField baseField) { AssetTypeInstance scriptAti = manager.GetExtAsset(inst, baseField.Get("m_Script")).instance; if (scriptAti == null) { return("Unknown class name"); } return(scriptAti.GetBaseField().Get("m_Name").GetValue().AsString()); }
//Newly created assets public AssetContainer MakeAssetContainer(AssetItem item, Stream ms, bool forceFromCldb = false) { var fileInst = LoadedFiles[item.FileID]; using var reader = new AssetsFileReader(ms); var templateField = GetTemplateField(item, forceFromCldb); var typeInst = new AssetTypeInstance(templateField, reader, 0); return(new AssetContainer(reader, item, fileInst, typeInst)); }
private void button1_Click(object sender, EventArgs e) { if (startedScanning) { return; } listBox1.Items.Clear(); startedScanning = true; loadingBar.Maximum = details.Count; if (textBox1.Text == "") { return; } long searchNum = long.Parse(textBox1.Text); BackgroundWorker bw = new BackgroundWorker(); bw.WorkerReportsProgress = true; bw.DoWork += delegate(object s, DoWorkEventArgs ev) { for (int i = 0; i < details.Count; i++) { AssetDetails ad = details[i]; if (ad.fileID != 0 && !checkBox1.Checked) { continue; } if (ad.typeName == "GameObject") { AssetTypeInstance gameObjectAti = manager.GetATI(manager.GetStream(ad.fileID), manager.GetInfo(ad.fileID, ad.pathID)); AssetTypeValueField components = gameObjectAti.GetBaseField().Get("m_Component").Get("Array"); for (uint j = 0; j < components.GetValue().AsArray().size; j++) { int fileId = components.Get(j).Get("component").Get("m_FileID").GetValue().AsInt(); long pathId = components.Get(j).Get("component").Get("m_PathID").GetValue().AsInt64(); if (pathId == searchNum) { bw.ReportProgress(i, gameObjectAti.GetBaseField().Get("m_Name").GetValue().AsString() + "(" + ad.fileID + "/" + ad.pathID + ")"); } } bw.ReportProgress(i); } } startedScanning = false; }; bw.ProgressChanged += delegate(object s, ProgressChangedEventArgs ev) { loadingBar.Value = ev.ProgressPercentage; if (ev.UserState != null) { listBox1.Items.Add(ev.UserState); } }; bw.RunWorkerAsync(); }
public static byte[] WriteToByteArray(this AssetTypeInstance instance) { byte[] data; using (MemoryStream ms = new MemoryStream()) using (AssetsFileWriter w = new AssetsFileWriter(ms)) { instance.Write(w); data = ms.ToArray(); } return(data); }
public void ReadMesh(AssetTypeInstance ati) { AssetTypeValueField baseField = ati.GetBaseField(); name = baseField.Get("m_Name").GetValue().AsString(); AssetTypeValueField channelArray = baseField.Get("m_VertexData") .Get("m_Channels") .Get("Array"); ChannelInfo[] channelInfos = new ChannelInfo[channelArray.GetValue().AsArray().size]; for (uint i = 0; i < channelInfos.Length; i++) { AssetTypeValueField channelInfo = channelArray.Get(i); channelInfos[i].stream = (byte)channelInfo.Get("stream").GetValue().AsInt(); channelInfos[i].offset = (byte)channelInfo.Get("offset").GetValue().AsInt(); channelInfos[i].format = (byte)channelInfo.Get("format").GetValue().AsInt(); channelInfos[i].dimension = (byte)channelInfo.Get("dimension").GetValue().AsInt(); } AssetTypeValueField subMeshArray = baseField.Get("m_SubMeshes") .Get("Array"); SubMeshInfo[] subMeshInfos = new SubMeshInfo[subMeshArray.GetValue().AsArray().size]; for (uint i = 0; i < subMeshInfos.Length; i++) { AssetTypeValueField subMeshInfo = subMeshArray.Get(i); subMeshInfos[i].firstByte = (uint)subMeshInfo.Get("firstByte").GetValue().AsInt(); subMeshInfos[i].indexCount = (uint)subMeshInfo.Get("indexCount").GetValue().AsInt(); subMeshInfos[i].topology = subMeshInfo.Get("topology").GetValue().AsInt(); subMeshInfos[i].firstVertex = (uint)subMeshInfo.Get("firstVertex").GetValue().AsInt(); subMeshInfos[i].vertexCount = (uint)subMeshInfo.Get("vertexCount").GetValue().AsInt(); } SubMesh[] subMeshes = new SubMesh[subMeshInfos.Length]; int r = 0; byte[] vertData = baseField.Get("m_VertexData").Get("m_DataSize").GetValue().AsByteArray().data; //asbytearray wont work in at.net yet rip :( for (uint i = 0; i < subMeshInfos.Length; i++) { for (uint j = 0; j < subMeshInfos[i].vertexCount; j++) { for (uint k = 0; k < channelInfos.Length; k++) { for (uint l = 0; l < channelInfos[k].dimension; l++) { switch (k) { case 0: ReadValue(vertData, r, channelInfos[k].format); break; } } } } } }
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 AssetTypeInstance GetByteArrayTexture(AssetsWorkspace workspace, AssetContainer tex) { var textureTemp = workspace.GetTemplateField(tex.Item); var image_data = textureTemp.children.FirstOrDefault(f => f.name == "image data"); if (image_data == null) { return(null); } image_data.valueType = EnumValueTypes.ByteArray; var texTypeInst = new AssetTypeInstance(new[] { textureTemp }, tex.FileReader, tex.Item.Position); return(texTypeInst); }
public static AssetTypeInstance GetByteArrayTexture(AssetWorkspace workspace, AssetContainer tex) { AssetTypeTemplateField textureTemp = workspace.GetTemplateField(tex.FileInstance.file, tex.ClassId, tex.MonoId); 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.FileReader, tex.FilePosition); return(textureTypeInstance); }
public AssetTypeValueField this[string name] { get { foreach (AssetTypeValueField atvf in children) { if (atvf.templateField.name == name) { return(atvf); } } return(AssetTypeInstance.GetDummyAssetTypeField()); } set { } }
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 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 AssetTypeValueField GetMonoBaseFieldCached(AssetsFileInstance inst, AssetFileInfoEx info, string managedPath) { AssetsFile file = inst.file; ushort scriptIndex = AssetHelper.GetScriptIndex(file, info); 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 { AssetTypeValueField baseValueField = MonoDeserializer.GetMonoBaseField(this, inst, info, managedPath); inst.templateFieldCache[scriptIndex] = baseValueField.templateField; return(baseValueField); } }
private AssetTypeTemplateField[] TryDeserializeMono(AssetTypeInstance ati, AssetsManager am, string rootDir) { AssetTypeInstance scriptAti = am.GetExtAsset(curFile, ati.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(rootDir, "Managed", assemblyName); if (File.Exists(assemblyPath)) { MonoClass mc = new MonoClass(); mc.Read(scriptName, assemblyPath); return(mc.children); } else { return(null); } }
public AssetTypeValueField GetMonoBaseFieldCached(AssetsFileInstance inst, AssetFileInfoEx info, string managedPath) { AssetsFile file = inst.file; ushort scriptIndex = file.typeTree.pTypes_Unity5[info.curFileTypeOrIndex].scriptIndex; if (scriptIndex != 0xFFFF && inst.templateFieldCache.ContainsKey(scriptIndex)) { AssetTypeTemplateField baseTemplateField = inst.templateFieldCache[scriptIndex]; AssetTypeInstance baseAti = new AssetTypeInstance(baseTemplateField, file.reader, false, info.absoluteFilePos); return(baseAti.GetBaseField()); } else { AssetTypeValueField baseValueField = MonoClass.GetMonoBaseField(this, inst, info, managedPath); inst.templateFieldCache[scriptIndex] = baseValueField.templateField; return(baseValueField); } }
private AssetTypeTemplateField[] TryDeserializeMono(AssetTypeInstance ati) { AssetTypeInstance scriptAti = am.GetExtAsset(ati.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(rootDir, "Managed", assemblyName); if (File.Exists(assemblyPath)) { MonoDeserializer mc = new MonoDeserializer(); mc.Read(scriptName, assemblyPath, af.header.format); return(mc.children.ToArray()); } else { return(null); } }
internal static void ChangeDisableUnityAudio(string path, bool newValue, QModGame game) { if (game != QModGame.Subnautica && game != QModGame.BelowZero) { throw new ArgumentException("Neither Subnautica nor Below Zero detected!"); } AssetsManager am = new AssetsManager(); AssetsFileInstance afi = am.LoadAssetsFile(path, false); if (game == QModGame.Subnautica) { am.LoadClassDatabase("cldb.dat"); } else { am.LoadClassDatabase("cldb2018.dat"); } AssetFileInfoEx audioInfo = afi.table.getAssetInfo(4); AssetTypeInstance audioAti = am.GetATI(afi.file, audioInfo); AssetTypeValueField audioBaseField = audioAti.GetBaseField(); audioBaseField.Get("m_DisableAudio").GetValue().Set(newValue); byte[] audioAsset; using (MemoryStream memStream = new MemoryStream()) using (AssetsFileWriter writer = new AssetsFileWriter(memStream)) { writer.bigEndian = false; audioBaseField.Write(writer); audioAsset = memStream.ToArray(); } List <AssetsReplacer> rep = new List <AssetsReplacer>() { new AssetsReplacerFromMemory(0, 4, 0x0B, 0xFFFF, audioAsset) }; using (MemoryStream memStream = new MemoryStream()) using (AssetsFileWriter writer = new AssetsFileWriter(memStream)) { afi.file.Write(writer, 0, rep.ToArray(), 0); afi.stream.Close(); File.WriteAllBytes(path, memStream.ToArray()); } }
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()); }
public AssetContainer GetAssetContainer(AssetsFileInstance fileInst, int fileId, long pathId, bool onlyInfo = true) { if (fileId != 0) { fileInst = fileInst.GetDependency(am, fileId - 1); } if (fileInst != null) { AssetID assetId = new AssetID(fileInst.path, pathId); if (LoadedAssets.TryGetValue(assetId, out AssetContainer? cont)) { if (!onlyInfo && !cont.HasInstance) { AssetTypeTemplateField tempField = GetTemplateField(cont.FileInstance.file, cont.ClassId, cont.MonoId); AssetTypeInstance typeInst = new AssetTypeInstance(tempField, cont.FileReader, cont.FilePosition); cont = new AssetContainer(cont, typeInst); } return cont; } } return null; }
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 static void ReadGameInfo(AssetsManager assetsManager) { string gameDataPath = MelonUtils.GetGameDataDirectory(); AssetsFileInstance instance = null; try { string bundlePath = Path.Combine(gameDataPath, "globalgamemanagers"); if (!File.Exists(bundlePath)) { bundlePath = Path.Combine(gameDataPath, "mainData"); } if (!File.Exists(bundlePath)) { bundlePath = Path.Combine(gameDataPath, "data.unity3d"); if (!File.Exists(bundlePath)) { return; } BundleFileInstance bundleFile = assetsManager.LoadBundleFile(bundlePath); instance = assetsManager.LoadAssetsFileFromBundle(bundleFile, "globalgamemanagers"); } else { instance = assetsManager.LoadAssetsFile(bundlePath, true); } if (instance == null) { return; } assetsManager.LoadIncludedClassPackage(); if (!instance.file.typeTree.hasTypeTree) { assetsManager.LoadClassDatabaseFromPackage(instance.file.typeTree.unityVersion); } EngineVersion = UnityVersion.Parse(instance.file.typeTree.unityVersion); List <AssetFileInfoEx> assetFiles = instance.table.GetAssetsOfType(129); if (assetFiles.Count > 0) { AssetFileInfoEx playerSettings = assetFiles.First(); AssetTypeInstance assetTypeInstance = null; try { assetTypeInstance = assetsManager.GetTypeInstance(instance, playerSettings); } catch (Exception ex) { if (MelonDebug.IsEnabled()) { MelonLogger.Error(ex); MelonLogger.Warning("Attempting to use Large Class Package..."); } assetsManager.LoadIncludedLargeClassPackage(); assetsManager.LoadClassDatabaseFromPackage(instance.file.typeTree.unityVersion); assetTypeInstance = assetsManager.GetTypeInstance(instance, playerSettings); } if (assetTypeInstance != null) { AssetTypeValueField playerSettings_baseField = assetTypeInstance.GetBaseField(); AssetTypeValueField bundleVersion = playerSettings_baseField.Get("bundleVersion"); if (bundleVersion != null) { GameVersion = bundleVersion.GetValue().AsString(); } AssetTypeValueField companyName = playerSettings_baseField.Get("companyName"); if (companyName != null) { GameDeveloper = companyName.GetValue().AsString(); } AssetTypeValueField productName = playerSettings_baseField.Get("productName"); if (productName != null) { GameName = productName.GetValue().AsString(); } } } } catch (Exception ex) { if (MelonDebug.IsEnabled()) { MelonLogger.Error(ex); } MelonLogger.Error("Failed to Initialize Assets Manager!"); } if (instance != null) { instance.file.Close(); } }