private void FixAsset(AssetTypeValueField field, AssetFileInfoEx inf) { if (inf.curFileType == 0x01) //fix gameobject { AssetTypeValueField Array = field.Get("m_Component").Get("Array"); //remove all null pointers List <AssetTypeValueField> newFields = Array.children.Where(f => f.children[0].children[1].GetValue().AsInt64() != 0 ).ToList(); int newSize = newFields.Count; Array.SetChildrenList(newFields.ToArray()); Array.GetValue().Set(new AssetTypeArray() { size = newSize }); } else if (inf.curFileType == 0x1c) //fix texture2d { AssetTypeValueField path = field.Get("m_StreamData").Get("path"); string pathString = path.GetValue().AsString(); string fixedPath = Path.GetFileName(pathString); path.GetValue().Set(fixedPath); } else if (inf.curFileType == 0x53) //fix audioclip { AssetTypeValueField path = field.Get("m_Resource").Get("m_Source"); string pathString = path.GetValue().AsString(); string fixedPath = Path.GetFileName(pathString); path.GetValue().Set(fixedPath); } }
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; } } }
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); } }
public static NamedAssetPPtr ReadNamedAssetPPtr(AssetNameResolver namer, AssetTypeValueField field) { int fileId = field.Get("m_FileID").GetValue().AsInt(); long pathId = field.Get("m_PathID").GetValue().AsInt64(); return(namer.GetNamedPtr(new AssetPPtr(fileId, pathId))); }
public static AssetsReplacer ConvertMaterial(AssetTypeValueField baseField, ulong pathId, ulong shaderPathId) { AssetTypeValueField m_Shader = baseField.Get("m_Shader"); m_Shader.Get("m_FileID").GetValue().Set(0); m_Shader.Get("m_PathID").GetValue().Set((long)shaderPathId); AssetTypeValueField m_TexEnvs = baseField.Get("m_SavedProperties").Get("m_TexEnvs").Get("Array"); foreach (AssetTypeValueField m_TexEnv in m_TexEnvs.pChildren) { AssetTypeValueField m_Texture = m_TexEnv.Get("second").Get("m_Texture"); m_Texture.Get("m_FileID").GetValue().Set(0); m_Texture.Get("m_PathID").GetValue().Set((long)0); } byte[] materialAsset; using (MemoryStream memStream = new MemoryStream()) using (AssetsFileWriter writer = new AssetsFileWriter(memStream)) { writer.bigEndian = false; baseField.Write(writer); materialAsset = memStream.ToArray(); } return(new AssetsReplacerFromMemory(0, pathId, 0x15, 0xFFFF, materialAsset)); }
private void BtnSave_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) { if (modImageBytes != null) { TextureFormat fmt = (TextureFormat)(ddTextureFmt.SelectedIndex + 1); byte[] encImageBytes = TextureEncoderDecoder.Encode(modImageBytes, tex.m_Width, tex.m_Height, fmt); AssetTypeValueField m_StreamData = baseField.Get("m_StreamData"); m_StreamData.Get("offset").GetValue().Set(0); m_StreamData.Get("size").GetValue().Set(0); m_StreamData.Get("path").GetValue().Set(""); baseField.Get("m_TextureFormat").GetValue().Set((int)fmt); baseField.Get("m_Width").GetValue().Set(tex.m_Width); baseField.Get("m_Height").GetValue().Set(tex.m_Height); AssetTypeValueField image_data = baseField.Get("image data"); image_data.GetValue().type = EnumValueTypes.ByteArray; image_data.templateField.valueType = EnumValueTypes.ByteArray; AssetTypeByteArray byteArray = new AssetTypeByteArray() { size = (uint)encImageBytes.Length, data = encImageBytes }; image_data.GetValue().Set(byteArray); } Close(true); }
public AssetContainer GetAssetContainer(AssetTypeValueField pptrField) { var fileId = pptrField.Get("m_FileID").GetValue().AsInt(); var pathId = pptrField.Get("m_PathID").GetValue().AsInt64(); return(GetAssetContainer(fileId, pathId)); }
///////////////////////////////////////////////////////// /*private static byte[] FixTexture2DFast(AssetsFileInstance inst, AssetFileInfoEx inf) * { * AssetsFileReader r = inst.file.reader; * r.Position = inf.absoluteFilePos; * r.Position += (ulong)r.ReadInt32() + 4; * r.Align(); * r.Position += 0x48; * r.Position += (ulong)r.ReadInt32() + 4; * r.Align(); * r.Position += 0x8; * ulong filePathPos = r.Position; * int assetLengthMinusFP = (int)(filePathPos - inf.absoluteFilePos); * string filePath = r.ReadCountStringInt32(); * string directory = Path.GetDirectoryName(inst.path); * string fixedPath = Path.Combine(directory, filePath); * * Console.WriteLine(filePath + " => " + fixedPath); * * byte[] newData = new byte[assetLengthMinusFP + 4 + fixedPath.Length]; * r.Position = inf.absoluteFilePos; * //imo easier to write it with binary writer than manually copy the bytes * using (MemoryStream ms = new MemoryStream()) * using (AssetsFileWriter w = new AssetsFileWriter(ms)) * { * w.bigEndian = false; * w.Write(r.ReadBytes(assetLengthMinusFP)); * w.WriteCountStringInt32(fixedPath); * return ms.ToArray(); * } * }*/ private static byte[] FixTexture2DSlow(AssetsFileInstance inst, AssetTypeValueField baseField) { AssetTypeValueField m_StreamData = baseField.Get("m_StreamData"); int offset = (int)m_StreamData.Get("offset").GetValue().AsUInt(); int size = (int)m_StreamData.Get("size").GetValue().AsUInt(); if (size != 0) { string dataFolder = Path.GetDirectoryName(inst.path); string path = Path.Combine(dataFolder, m_StreamData.Get("path").GetValue().AsString()); BinaryReader ressr = new BinaryReader(new FileStream(path, FileMode.Open)); ressr.BaseStream.Position = offset; byte[] data = ressr.ReadBytes(size); ressr.Close(); m_StreamData.Get("offset").value.value.asUInt32 = 0; m_StreamData.Get("size").value.value.asUInt32 = 0; m_StreamData.Get("path").value.value.asString = ""; baseField.Get("image data").GetValue().type = EnumValueTypes.ValueType_ByteArray; baseField.Get("image data").GetValue().Set(new AssetTypeByteArray() { data = data, size = (uint)data.Length }); baseField.Get("image data").templateField.valueType = EnumValueTypes.ValueType_ByteArray; } byte[] assetData; using (MemoryStream memStream = new MemoryStream()) using (AssetsFileWriter writer = new AssetsFileWriter(memStream)) { writer.bigEndian = false; baseField.Write(writer); assetData = memStream.ToArray(); } return(assetData); }
public AssetExternal GetExtAsset(AssetsFileInstance relativeTo, AssetTypeValueField atvf, bool onlyGetInfo = false, bool forceFromCldb = false) { int fileId = atvf.Get("m_FileID").GetValue().AsInt(); long pathId = atvf.Get("m_PathID").GetValue().AsInt64(); return(GetExtAsset(relativeTo, fileId, pathId, onlyGetInfo, forceFromCldb)); }
public static void GenerateDiffFile(AssetsManager am, AssetsFileInstance inst, AssetsFileInstance newInst, HKWEMeta meta) { EditorUtility.DisplayProgressBar("HKEdit", "Reading dependencies...", 0.5f); am.UpdateDependencies(); Dictionary <AssetID, AssetID> newToOldIds = new Dictionary <AssetID, AssetID>(); AssetsFileTable newTable = newInst.table; List <AssetFileInfoEx> initialGameObjects = newTable.GetAssetsOfType(0x01); for (int i = 0; i < initialGameObjects.Count; i++) { if (i % 100 == 0) { EditorUtility.DisplayProgressBar("HKEdit", "Finding diff IDs... (step 1/3)", (float)i / initialGameObjects.Count); } AssetFileInfoEx inf = initialGameObjects[i]; AssetTypeValueField baseField = am.GetATI(newInst.file, inf).GetBaseField(); AssetTypeValueField editDifferMono = GetEDMono(am, newInst, baseField); EditDifferData diff = new EditDifferData() { fileId = editDifferMono.Get("fileId").GetValue().AsInt(), pathId = editDifferMono.Get("pathId").GetValue().AsInt64(), origPathId = editDifferMono.Get("origPathId").GetValue().AsInt64(), newAsset = editDifferMono.Get("newAsset").GetValue().AsBool() }; } }
public async Task <bool> SingleExport(Window win, AssetWorkspace workspace, List <AssetContainer> selection) { AssetContainer cont = selection[0]; SaveFileDialog sfd = new SaveFileDialog(); AssetTypeValueField baseField = workspace.GetBaseField(cont); string name = baseField.Get("m_Name").GetValue().AsString(); sfd.Title = "Save text file"; sfd.Filters = new List <FileDialogFilter>() { new FileDialogFilter() { Name = "TXT file", Extensions = new List <string>() { "txt" } } }; sfd.InitialFileName = $"{name}-{Path.GetFileName(cont.FileInstance.path)}-{cont.PathId}.txt"; string file = await sfd.ShowAsync(win); if (file != null && file != string.Empty) { byte[] byteData = baseField.Get("m_Script").GetValue().AsStringBytes(); File.WriteAllBytes(file, byteData); return(true); } return(false); }
public AssetExternal GetExtAsset(AssetsFileInstance relativeTo, AssetTypeValueField atvf, bool onlyGetInfo = false, bool fromTypeTree = false) { uint fileId = (uint)atvf.Get("m_FileID").GetValue().AsInt(); ulong pathId = (ulong)atvf.Get("m_PathID").GetValue().AsInt64(); return(GetExtAsset(relativeTo, fileId, pathId, onlyGetInfo, fromTypeTree)); }
public static AssetPPtr ReadAssetPPtr(AssetTypeValueField field) { int fileId = field.Get("m_FileID").GetValue().AsInt(); long pathId = field.Get("m_PathID").GetValue().AsInt64(); return(new AssetPPtr(fileId, pathId)); }
private static byte[] FixMaterial(AssetsFile file, AssetTypeValueField baseField, byte[] saData) { AssetTypeValueField m_Shader = baseField.Get("m_Shader"); if (m_Shader.Get("m_FileID").GetValue().AsInt() == 1 && //only works for 2017.4.10f1 m_Shader.Get("m_PathID").GetValue().AsInt64() == 10753) { int ggmaIdx = Array.FindIndex(file.dependencies.pDependencies, d => Path.GetFileName(d.assetPath) == "globalgamemanagers.assets"); if (ggmaIdx != -1) { //Sprites-Default m_Shader.Get("m_FileID").GetValue().Set(ggmaIdx + 1); m_Shader.Get("m_PathID").GetValue().Set(4); //only works for this specific version of hk } else { throw new NotImplementedException("no ggm.assets reference"); } } byte[] assetData; using (MemoryStream memStream = new MemoryStream()) using (AssetsFileWriter writer = new AssetsFileWriter(memStream)) { writer.bigEndian = false; baseField.Write(writer); assetData = memStream.ToArray(); } return(assetData); }
public async Task <bool> BatchExport(Window win, AssetWorkspace workspace, List <AssetContainer> selection) { OpenFolderDialog ofd = new OpenFolderDialog(); ofd.Title = "Select export directory"; string dir = await ofd.ShowAsync(win); if (dir != null && dir != string.Empty) { foreach (AssetContainer cont in selection) { AssetTypeValueField baseField = workspace.GetBaseField(cont); string name = baseField.Get("m_Name").GetValue().AsString(); byte[] byteData = baseField.Get("m_Script").GetValue().AsStringBytes(); string file = Path.Combine(dir, $"{name}-{Path.GetFileName(cont.FileInstance.path)}-{cont.PathId}.txt"); File.WriteAllBytes(file, byteData); } return(true); } return(false); }
private Vector3 GetVector3(AssetTypeValueField field) { float x = field.Get("x").GetValue().AsFloat(); float y = field.Get("y").GetValue().AsFloat(); float z = field.Get("z").GetValue().AsFloat(); return(new Vector3(x, y, z)); }
public FsmTransition(AssetTypeValueField valueField) { fsmEvent = new FsmEvent(valueField.Get("fsmEvent")); toState = valueField.Get("toState").GetValue().AsString(); linkStyle = valueField.Get("linkStyle").GetValue().AsInt(); linkConstraint = valueField.Get("linkConstraint").GetValue().AsInt(); colorIndex = (byte)valueField.Get("colorIndex").GetValue().AsInt(); }
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; } } }
public Texture2D LoadUnitySprite(AssetsManager manager, AssetTypeValueField baseField, AssetsFileInstance spriteFileInst) { AssetTypeValueField m_RD = baseField.Get("m_RD"); AssetTypeValueField texture = m_RD.Get("texture"); AssetTypeValueField textureRect = m_RD.Get("textureRect"); int texFileId = texture.Get("m_FileID").GetValue().AsInt(); long texPathId = texture.Get("m_PathID").GetValue().AsInt64(); AssetTypeValueField textureBaseField = manager.GetExtAsset(spriteFileInst, texture).instance.GetBaseField(); int x = (int)Mathf.Floor(textureRect.Get("x").GetValue().AsFloat()); int y = (int)Mathf.Floor(textureRect.Get("y").GetValue().AsFloat()); int width = (int)Mathf.Ceil(textureRect.Get("width").GetValue().AsFloat()); int height = (int)Mathf.Ceil(textureRect.Get("height").GetValue().AsFloat()); Bitmap bitmap = GetBitmap(manager, textureBaseField, texFileId, texPathId, spriteFileInst); List <Point> points = GetUnityPoints(baseField, bitmap.Height); //because the section we are selecting has to be at 0, //we move the sprite from the bottom to the top for (int i = 0; i < points.Count; i++) { points[i] = new Point(points[i].X, points[i].Y - (bitmap.Height - height)); } AssetTypeValueField m_IndexBuffer = m_RD.Get("m_IndexBuffer").Get("Array"); GraphicsPath gp = new GraphicsPath(); for (uint i = 0; i < m_IndexBuffer.GetValue().AsArray().size; i += 6) { int pointA = (int)(m_IndexBuffer[i + 0].GetValue().AsUInt() | (m_IndexBuffer[i + 1].GetValue().AsUInt() << 8)); int pointB = (int)(m_IndexBuffer[i + 2].GetValue().AsUInt() | (m_IndexBuffer[i + 3].GetValue().AsUInt() << 8)); int pointC = (int)(m_IndexBuffer[i + 4].GetValue().AsUInt() | (m_IndexBuffer[i + 5].GetValue().AsUInt() << 8)); Point[] triangle = new Point[] { points[pointA], points[pointB], points[pointC] }; gp.AddPolygon(triangle); } //todo, handle all this in unity (needs algo for clipping in poly) Bitmap croppedBitmap = new Bitmap(width, height); using (Graphics graphics = Graphics.FromImage(croppedBitmap)) { graphics.Clip = new Region(gp); graphics.DrawImage(bitmap, -x, -(bitmap.Height - (y + height))); } //o nose croppedBitmap = ResizeImage(croppedBitmap, (int)(croppedBitmap.Width * 1.5625f), (int)(croppedBitmap.Height * 1.5625f)); //bitmap.Dispose(); //this is terribly inefficent please o please fix Texture2D image = new Texture2D(width, height); using (MemoryStream stream = new MemoryStream()) { croppedBitmap.Save(stream, croppedBitmap.RawFormat); image.LoadImage(stream.ToArray()); } return(image); }
public FsmTemplateControl(AssetNameResolver namer, AssetTypeValueField field) { fsmTemplate = StructUtil.ReadAssetPPtr(field.Get("fsmTemplate")); fsmVarOverrides = new FsmVarOverride[field.Get("fsmVarOverrides").GetChildrenCount()]; for (int i = 0; i < fsmVarOverrides.Length; i++) { fsmVarOverrides[i] = new FsmVarOverride(namer, field.Get("fsmVarOverrides")[i]); } }
private static void FinalizeAsset(AssetsFileInstance file, AssetTypeValueField field, AssetFileInfoEx info) { if (info.curFileType == 0x01) // GameObject { var ComponentArray = field.Get("m_Component").Get("Array"); //remove all null pointers List <AssetTypeValueField> newFields = ComponentArray.pChildren.Where(f => f.pChildren[0].pChildren[1].GetValue().AsInt64() != 0 ).ToList(); var newSize = (uint)newFields.Count; ComponentArray.SetChildrenList(newFields.ToArray(), newSize); ComponentArray.GetValue().Set(new AssetTypeArray() { size = newSize }); } else if (info.curFileType == 0x73) // MonoScript { var m_AssemblyName = field.Get("m_AssemblyName").GetValue(); if (m_AssemblyName.AsString().Equals("Assembly-CSharp.dll")) { m_AssemblyName.Set("HKCode.dll"); } else if (m_AssemblyName.AsString().Equals("Assembly-CSharp-firstpass.dll")) { m_AssemblyName.Set("HKCode-firstpass.dll"); } } else if (info.curFileType == 0x1c) // Texture2D { var path = field.Get("m_StreamData").Get("path"); var pathString = path.GetValue().AsString(); var directory = Path.GetDirectoryName(file.path); if (directory == null) { Debug.LogWarning("Texture2D has null stream data path!"); return; } var fixedPath = Path.Combine(directory, pathString); path.GetValue().Set(fixedPath); } else if (info.curFileType == 0x53) // AudioClip { var path = field.Get("m_Resource").Get("m_Source"); var pathString = path.GetValue().AsString(); var directory = Path.GetDirectoryName(file.path); if (directory == null) { Debug.LogWarning("AudioClip has null resource source path!"); return; } var fixedPath = Path.Combine(directory, pathString); path.GetValue().Set(fixedPath); } }
private Quaternion GetQuaternion(AssetTypeValueField field) { float x = field.Get("x").GetValue().AsFloat(); float y = field.Get("y").GetValue().AsFloat(); float z = field.Get("z").GetValue().AsFloat(); float w = field.Get("w").GetValue().AsFloat(); return(new Quaternion(x, y, z, w)); }
private async Task <bool> ImportTextures(Window win, List <ImportBatchInfo> batchInfos) { StringBuilder errorBuilder = new StringBuilder(); foreach (ImportBatchInfo batchInfo in batchInfos) { AssetContainer cont = batchInfo.cont; string errorAssetName = $"{Path.GetFileName(cont.FileInstance.path)}/{cont.PathId}"; string selectedFilePath = batchInfo.importFile; if (!cont.HasInstance) { continue; } AssetTypeValueField baseField = cont.TypeInstance.GetBaseField(); TextureFormat fmt = (TextureFormat)baseField.Get("m_TextureFormat").GetValue().AsInt(); byte[] encImageBytes = TextureImportExport.ImportPng(selectedFilePath, fmt, out int width, out int height); if (encImageBytes == null) { errorBuilder.AppendLine($"[{errorAssetName}]: Failed to encode texture format {fmt}"); continue; } AssetTypeValueField m_StreamData = baseField.Get("m_StreamData"); m_StreamData.Get("offset").GetValue().Set(0); m_StreamData.Get("size").GetValue().Set(0); m_StreamData.Get("path").GetValue().Set(""); baseField.Get("m_TextureFormat").GetValue().Set((int)fmt); baseField.Get("m_Width").GetValue().Set(width); baseField.Get("m_Height").GetValue().Set(height); AssetTypeValueField image_data = baseField.Get("image data"); image_data.GetValue().type = EnumValueTypes.ByteArray; image_data.templateField.valueType = EnumValueTypes.ByteArray; AssetTypeByteArray byteArray = new AssetTypeByteArray() { size = (uint)encImageBytes.Length, data = encImageBytes }; image_data.GetValue().Set(byteArray); } if (errorBuilder.Length > 0) { string[] firstLines = errorBuilder.ToString().Split('\n').Take(20).ToArray(); string firstLinesStr = string.Join('\n', firstLines); await MessageBoxUtil.ShowDialog(win, "Some errors occurred while exporting", firstLinesStr); } return(true); }
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; } } } } } }
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 AssetsReplacer ConvertTexture(AssetTypeValueField baseField, ulong pathId, string folderPath) { //byte[] data = null; AssetTypeValueField m_StreamData = baseField.Get("m_StreamData"); //int offset = (int)m_StreamData.Get("offset").GetValue().AsUInt(); //int size = (int)m_StreamData.Get("size").GetValue().AsUInt(); // //if (size != 0) //{ // string path = m_StreamData.Get("path").GetValue().AsString(); // using (FileStream stream = new FileStream(Path.Combine(folderPath, path), FileMode.Open)) // using (MemoryStream memStream = new MemoryStream()) // { // long fileSize = stream.Length; // data = new byte[size]; // stream.Position = offset; // // int bytesRead; // var buffer = new byte[2048]; // while (((bytesRead = stream.Read(buffer, 0, Math.Min(2048, (offset + size) - (int)stream.Position))) > 0)) // { // memStream.Write(buffer, 0, bytesRead); // if (stream.Position >= offset + size) // { // break; // } // } // data = memStream.ToArray(); // } //} //this may not be needed, instead change the path to a hardcoded path to the resS //m_StreamData.Get("offset").value.value.asUInt32 = 0; //m_StreamData.Get("size").value.value.asUInt32 = 0; m_StreamData.Get("path").value.value.asString = Path.Combine(folderPath, m_StreamData.Get("path").GetValue().AsString()); //baseField.Get("image data").GetValue().type = EnumValueTypes.ValueType_ByteArray; //baseField.Get("image data").GetValue().Set(new AssetTypeByteArray() { // data = data, // size = (uint)data.Length //}); //baseField.Get("image data").templateField.valueType = EnumValueTypes.ValueType_ByteArray; byte[] textureAsset; using (MemoryStream memStream = new MemoryStream()) using (AssetsFileWriter writer = new AssetsFileWriter(memStream)) { writer.bigEndian = false; baseField.Write(writer); textureAsset = memStream.ToArray(); } return(new AssetsReplacerFromMemory(0, pathId, 0x1C, 0xFFFF, textureAsset)); }
//todo- not guaranteed to get texture in sharedassets private static byte[] FixTexture2D(AssetTypeValueField baseField, byte[] saData) { AssetTypeValueField m_StreamData = baseField.Get("m_StreamData"); int offset = (int)m_StreamData.Get("offset").GetValue().AsUInt(); int size = (int)m_StreamData.Get("size").GetValue().AsUInt(); byte[] data = new byte[0]; if (size != 0) { string path = m_StreamData.Get("path").GetValue().AsString(); using (MemoryStream inStream = new MemoryStream(saData)) using (MemoryStream outStream = new MemoryStream()) { long fileSize = inStream.Length; data = new byte[size]; inStream.Position = offset; int bytesRead; var buffer = new byte[2048]; while ((bytesRead = inStream.Read(buffer, 0, Math.Min(2048, (offset + size) - (int)inStream.Position))) > 0) { outStream.Write(buffer, 0, bytesRead); if (inStream.Position >= offset + size) { break; } } data = outStream.ToArray(); } } m_StreamData.Get("offset").value.value.asUInt32 = 0; m_StreamData.Get("size").value.value.asUInt32 = 0; m_StreamData.Get("path").value.value.asString = ""; baseField.Get("image data").GetValue().type = EnumValueTypes.ValueType_ByteArray; baseField.Get("image data").GetValue().Set(new AssetTypeByteArray() { data = data, size = (uint)data.Length }); baseField.Get("image data").templateField.valueType = EnumValueTypes.ValueType_ByteArray; byte[] assetData; using (MemoryStream memStream = new MemoryStream()) using (AssetsFileWriter writer = new AssetsFileWriter(memStream)) { writer.bigEndian = false; baseField.Write(writer); assetData = memStream.ToArray(); } return(assetData); }
public FsmState(AssetNameResolver namer, AssetTypeValueField field) { name = field.Get("name").GetValue().AsString(); description = field.Get("description").GetValue().AsString(); colorIndex = (byte)field.Get("colorIndex").GetValue().AsUInt(); position = new UnityRect(field.Get("position")); isBreakpoint = field.Get("isBreakpoint").GetValue().AsBool(); isSequence = field.Get("isSequence").GetValue().AsBool(); hideUnused = field.Get("hideUnused").GetValue().AsBool(); transitions = new FsmTransition[field.Get("transitions").GetChildrenCount()]; for (int i = 0; i < transitions.Length; i++) { transitions[i] = new FsmTransition(field.Get("transitions")[i]); } actionData = new ActionData(namer, field.Get("actionData")); }
public List <SceneInfo> LoadSceneList(string folder) { string ggmPath = Path.Combine(folder, "globalgamemanagers"); AssetsFileInstance ggm = am.LoadAssetsFile(ggmPath, false); am.LoadClassDatabaseFromPackage(ggm.file.typeTree.unityVersion); AssetFileInfoEx buildSettingsInfo = ggm.table.GetAssetsOfType(0x8D)[0]; AssetTypeValueField buildSettings = am.GetTypeInstance(ggm, buildSettingsInfo).GetBaseField(); AssetTypeValueField scenes = buildSettings.Get("scenes").Get("Array"); int sceneCount = scenes.GetValue().AsArray().size; List <SceneInfo> sceneInfos = new List <SceneInfo>(); for (int i = 0; i < sceneCount; i++) { sceneInfos.Add(new SceneInfo() { id = i, name = scenes[i].GetValue().AsString(), level = true }); } for (int i = 0; i < sceneCount; i++) { sceneInfos.Add(new SceneInfo() { id = i, name = scenes[i].GetValue().AsString(), level = false }); } return(sceneInfos); }
static void PatchVR(string gameManagersBackupPath, string gameManagersPath, string classDataPath) { Console.WriteLine("Patching globalgamemanagers..."); Console.WriteLine($"Using classData file from path '{classDataPath}'"); AssetsManager am = new AssetsManager(); am.LoadClassPackage(classDataPath); AssetsFileInstance ggm = am.LoadAssetsFile(gameManagersBackupPath, false); AssetsFile ggmFile = ggm.file; AssetsFileTable ggmTable = ggm.table; am.LoadClassDatabaseFromPackage(ggmFile.typeTree.unityVersion); List <AssetsReplacer> replacers = new List <AssetsReplacer>(); AssetFileInfoEx buildSettings = ggmTable.GetAssetInfo(11); AssetTypeValueField buildSettingsBase = am.GetATI(ggmFile, buildSettings).GetBaseField(); AssetTypeValueField enabledVRDevices = buildSettingsBase.Get("enabledVRDevices").Get("Array"); AssetTypeTemplateField stringTemplate = enabledVRDevices.templateField.children[1]; AssetTypeValueField[] vrDevicesList = new AssetTypeValueField[] { StringField("OpenVR", stringTemplate) }; enabledVRDevices.SetChildrenList(vrDevicesList); replacers.Add(new AssetsReplacerFromMemory(0, buildSettings.index, (int)buildSettings.curFileType, 0xffff, buildSettingsBase.WriteToByteArray())); using (AssetsFileWriter writer = new AssetsFileWriter(File.OpenWrite(gameManagersPath))) { ggmFile.Write(writer, 0, replacers, 0); } }