private void FollowBtn_Click(object sender, EventArgs e) { valueGrid.Focus(); GridItem item = valueGrid.SelectedGridItem; if (item.Label == "m_FileID" || item.Label == "m_PathID") { int fileId = -1; long pathId = -1; foreach (GridItem gi in item.Parent.EnumerateAllItems()) { if (gi.Label == "m_FileID") { fileId = int.Parse((string)gi.Value); } if (gi.Label == "m_PathID") { pathId = long.Parse((string)gi.Value); } } if (fileId == 0 && pathId == 0) { MessageBox.Show("Cannot open null reference", "Assets View"); return; } else if (fileId == -1 || pathId == -1) { MessageBox.Show("Could not find other id, is this really a pptr?", "Assets View"); return; } AssetExternal ext = helper.GetExtAsset(inst, fileId, pathId, true); GameObjectViewer view = new GameObjectViewer(helper, ext.file, ext.info.index); view.Show(); } }
private void RecursiveChildSearch(TreeNode node, AssetTypeValueField field) { AssetTypeValueField children = helper.GetExtAsset(inst, field.Get("m_Component") .Get("Array") .Get(0) .GetLastChild()).instance .GetBaseField() .Get("m_Children") .Get("Array"); for (int i = 0; i < children.GetValue().AsArray().size; i++) { AssetTypeInstance newInstance = helper.GetExtAsset(inst, children.Get(i)).instance; 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); } }
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 string GetName(AssetPPtr pptr) { if (pptr.pathID == 0) { return(string.Empty); } AssetExternal extObj = am.GetExtAsset(inst, pptr.fileID, pptr.pathID, true); string name = GetAssetNameFastModded(extObj.file.file, am.classFile, extObj.info); return(name); }
public NamedAssetPPtr GetNamedPtr(AssetPPtr pptr) { if (pptr.pathID == 0) { return(new NamedAssetPPtr(pptr.fileID, pptr.pathID, string.Empty, string.Empty)); } AssetExternal extObj = am.GetExtAsset(inst, pptr.fileID, pptr.pathID, true); string name = GetAssetNameFastModded(extObj.file.file, am.classFile, extObj.info); string file = extObj.file.name; return(new NamedAssetPPtr(pptr.fileID, pptr.pathID, name, file)); }
private void SetReferencesRecurse(AssetsFileInstance inst, AssetTypeValueField field) { foreach (AssetTypeValueField child in field.children) { //not a value (ie not an int) if (!child.templateField.hasValue) { //not null if (child == null) { return; } //not array of values either if (child.templateField.isArray && child.templateField.children[1].valueType != EnumValueTypes.ValueType_None) { break; } string typeName = child.templateField.type; //is a pptr if (typeName.StartsWith("PPtr<") && typeName.EndsWith(">") && child.childrenCount == 2) { int fileId = child.Get("m_FileID").GetValue().AsInt(); long pathId = child.Get("m_PathID").GetValue().AsInt64(); //not a null pptr if (pathId == 0) { continue; } AssetID aid = ConvertToAssetID(inst, fileId, pathId); AssetExternal ext = am.GetExtAsset(inst, fileId, pathId); //not already visited and not a gameobject or monobehaviour if (references.ContainsKey(aid) || ext.info.curFileType == 0x01 || ext.info.curFileType == 0x72) { continue; } AddReference(aid, IsAsset(ext.info)); //recurse through dependencies SetReferencesRecurse(ext.file, ext.instance.GetBaseField()); } SetReferencesRecurse(inst, child); } } }
private AssetExternal GetRootGameObject(AssetExternal ext) { AssetExternal transformExt = helper.GetExtAsset(inst, ext.instance.GetBaseField().Get("m_Component").Get("Array")[0].GetLastChild()); while (true) { AssetExternal parentExt = helper.GetExtAsset(inst, transformExt.instance.GetBaseField().Get("m_Father")); if (parentExt.instance == null) { AssetExternal gameObjectExt = helper.GetExtAsset(inst, transformExt.instance.GetBaseField().Get("m_GameObject")); return(gameObjectExt); } transformExt = parentExt; } }
private void GameObjectViewer_Load(object sender, EventArgs e) { //mono won't be able to do this so ignore it if (Type.GetType("Mono.Runtime") == null) { PInvoke.SetWindowTheme(goTree.Handle, "explorer", null); } valueGrid.PropertySort = PropertySort.Categorized; ClassDatabaseFile classFile = helper.classFile; AssetFileInfoEx info = inst.table.GetAssetInfo(selectedId); AssetTypeTemplateField typeTemplate = helper.GetTemplateBaseField(inst.file, info); string typeName = typeTemplate.type; if (typeName == "GameObject") { selectedGameObjectId = selectedId; AssetExternal firstExt = helper.GetExtAsset(inst, 0, selectedId); AssetExternal rootExt = GetRootGameObject(firstExt); PopulateHierarchyTree(null, rootExt); } else { bool hasGameObjectField = typeTemplate.children.Any(f => f.name == "m_GameObject"); if (hasGameObjectField) { AssetTypeValueField firstBaseField = helper.GetTypeInstance(inst.file, info).GetBaseField(); AssetExternal firstExt = helper.GetExtAsset(inst, firstBaseField.Get("m_GameObject")); if (firstExt.info != null) { selectedGameObjectId = firstExt.info.index; AssetExternal rootExt = GetRootGameObject(firstExt); PopulateHierarchyTree(null, rootExt); } else { TreeNode node = goTree.Nodes.Add($"[{typeName} (parentless)]"); node.Tag = helper.GetExtAsset(inst, 0, info.index); } } else { TreeNode node = goTree.Nodes.Add($"[{typeName}]"); node.Tag = helper.GetExtAsset(inst, 0, info.index); } } GetSelectedNodeData(); }
public AssetExternal GetExtAsset(AssetTypeValueField atvf) { AssetExternal ext = new AssetExternal(); if (atvf.Get("m_FileID").GetValue().AsInt() != 0) { Dependency dep = dependencies[atvf.Get("m_FileID").GetValue().AsInt() - 1]; ext.info = dep.aft.getAssetInfo((ulong)atvf.Get("m_PathID").GetValue().AsInt64()); ext.instance = GetATI(dep.file, ext.info); } else { ext.info = initialTable.getAssetInfo((ulong)atvf.Get("m_PathID").GetValue().AsInt64()); ext.instance = GetATI(file, ext.info); } return(ext); }
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); }
private static AssetTypeValueField GetEDMono(AssetsManager am, AssetsFileInstance fileInst, AssetTypeValueField goBaseField) { AssetTypeValueField m_Components = goBaseField.Get("m_Components").Get("Array"); for (int i = 0; i < m_Components.GetValue().AsArray().size; i++) { AssetTypeValueField component = m_Components[i]; AssetExternal ext = am.GetExtAsset(fileInst, component, true); if (ext.info.curFileType == 0x72) { //todo, check if this is the right monob //as there's only one this is fine for now //but I still hate this ext = am.GetExtAsset(fileInst, component, false); AssetTypeValueField monoBaseField = ext.instance.GetBaseField(); return(monoBaseField); } } return(null); }
public async Task <bool> ExecutePlugin(Window win, AssetWorkspace workspace, List <AssetExternal> selection) { AssetExternal tex = selection[0]; AssetTypeValueField texBaseField = tex.instance.GetBaseField(); TextureFile texFile = TextureFile.ReadTextureFile(texBaseField); EditDialog dialog = new EditDialog(texFile.m_Name, texFile, texBaseField); bool saved = await dialog.ShowDialog <bool>(win); if (saved) { byte[] savedAsset = texBaseField.WriteToByteArray(); var replacer = new AssetsReplacerFromMemory( 0, tex.info.index, (int)tex.info.curFileType, AssetHelper.GetScriptIndex(tex.file.file, tex.info), savedAsset); workspace.AddReplacer(tex.file, replacer, new MemoryStream(savedAsset)); return(true); } return(false); }
private Bitmap GetTexture(AssetExternal textureExt) { if (textureExt.instance == null) { return(null); } AssetTypeValueField textureBase = textureExt.instance.GetBaseField(); AssetID id = new AssetID(textureExt.file.name, textureExt.info.index); if (bitmapCache.ContainsKey(id)) { return(bitmapCache[id]); } TextureFile texture = TextureFile.ReadTextureFile(textureBase); byte[] textureBytes = texture.GetTextureData(textureExt.file); if (textureBytes != null && textureBytes.Length > 0) { Bitmap canvas = new Bitmap(texture.m_Width, texture.m_Height, PixelFormat.Format32bppArgb); Rectangle dimension = new Rectangle(0, 0, canvas.Width, canvas.Height); BitmapData picData = canvas.LockBits(dimension, ImageLockMode.ReadWrite, canvas.PixelFormat); picData.Stride = texture.m_Width * 4; IntPtr pixelStartAddress = picData.Scan0; Marshal.Copy(textureBytes, 0, pixelStartAddress, textureBytes.Length); canvas.UnlockBits(picData); //easy way, but wine doesn't have UnsafeAddrOfPinnedArrayElement for some reason //Bitmap canvas = new Bitmap(texture.m_Width, texture.m_Height, texture.m_Width * 4, PixelFormat.Format32bppArgb, // Marshal.UnsafeAddrOfPinnedArrayElement(textureBytes, 0)); canvas.RotateFlip(RotateFlipType.RotateNoneFlipY); bitmapCache[id] = canvas; return(canvas); } return(null); }
public static AssetExternal GetExtAssetNewData(this AssetsManager _this, AssetsFileInstance relativeTo, int fileId, long pathId, Stream data, bool onlyGetInfo = false, bool forceFromCldb = false) { AssetExternal ext = new AssetExternal(); if (fileId == 0 && pathId == 0) { ext.info = null; ext.instance = null; ext.file = null; } else if (fileId != 0) { AssetsFileInstance dep = relativeTo.GetDependency(_this, fileId - 1); ext.info = dep.table.GetAssetInfo(pathId); if (!onlyGetInfo) { ext.instance = _this.GetTypeInstanceNewData(dep.file, ext.info, data, forceFromCldb); } else { ext.instance = null; } ext.file = dep; } else { ext.info = relativeTo.table.GetAssetInfo(pathId); if (!onlyGetInfo) { ext.instance = _this.GetTypeInstanceNewData(relativeTo.file, ext.info, data, forceFromCldb); } else { ext.instance = null; } ext.file = relativeTo; } return(ext); }
private PGProperty LoadGameObjectData(AssetTypeValueField field) { PGProperty root = new PGProperty("root"); AssetTypeValueField components = field.Get("m_Component").Get("Array"); int componentSize = components.GetValue().AsArray().size; for (int i = 0; i < componentSize; i++) { AssetTypeValueField componentPtr = components[i].GetLastChild(); if (ModifierKeys == Keys.Shift) { AssetExternal ext = helper.GetExtAsset(inst, componentPtr); if (ext.instance != null) { LoadComponentData(root, ext.instance.GetBaseField(), ext.info, i, componentSize); } } else { try { AssetExternal ext = helper.GetExtAsset(inst, componentPtr); if (ext.instance != null) { LoadComponentData(root, ext.instance.GetBaseField(), ext.info, i, componentSize); } } catch { if (loadedWithErrors == false) { loadedWithErrors = true; MessageBox.Show("A component failed to load. (tell nes or hold shift to throw)"); } } } } return(root); }
public static AssetExternal GetExtAsset(this AssetsManager am, AssetsFileInstance relativeTo, int fileId, long pathId, bool onlyGetInfo = false) { AssetExternal ext = new AssetExternal(); if (fileId == 0 && pathId == 0) { ext.info = null; ext.instance = null; ext.file = null; } else if (fileId != 0) { AssetsFileInstance dep = relativeTo.dependencies[fileId - 1]; ext.info = dep.table.GetAssetInfo(pathId); if (!onlyGetInfo) { ext.instance = am.GetATI(dep.file, ext.info); } else { ext.instance = null; } ext.file = dep; } else { ext.info = relativeTo.table.GetAssetInfo(pathId); if (!onlyGetInfo) { ext.instance = am.GetATI(relativeTo.file, ext.info); } else { ext.instance = null; } ext.file = relativeTo; } return(ext); }
private void PopulateHierarchyTree(TreeNode node, AssetExternal ext) { AssetTypeValueField baseField = ext.instance.GetBaseField(); long thisId = ext.info.index; TreeNode newNode; if (node == null) { newNode = goTree.Nodes.Add(baseField.Get("m_Name").GetValue().AsString()); } else { newNode = node.Nodes.Add(baseField.Get("m_Name").GetValue().AsString()); } if (!baseField.Get("m_IsActive").GetValue().AsBool()) { newNode.ForeColor = Color.DarkRed; } newNode.Tag = ext; if (thisId == selectedId) { goTree.SelectedNode = newNode; } AssetTypeValueField children = helper.GetExtAsset(inst, baseField.Get("m_Component").Get("Array")[0].GetLastChild()).instance .GetBaseField().Get("m_Children").Get("Array"); for (int i = 0; i < children.childrenCount; i++) { AssetExternal childExternal = helper.GetExtAsset(inst, children[i]); AssetExternal gameObjExt = helper.GetExtAsset(inst, childExternal.instance.GetBaseField().Get("m_GameObject")); PopulateHierarchyTree(newNode, gameObjExt); } }
public AssetExternal GetExtAsset(AssetTypeValueField atvf) { AssetExternal ext = new AssetExternal(); int fileId = atvf.Get("m_FileID").GetValue().AsInt(); long pathId = atvf.Get("m_PathID").GetValue().AsInt64(); if (fileId == 0 && pathId == 0) { ext.info = null; ext.instance = null; } else if (atvf.Get("m_FileID").GetValue().AsInt() != 0) { Dependency dep = dependencies[(int)fileId - 1]; ext.info = dep.aft.GetAssetInfo(pathId); ext.instance = GetATI(dep.file, ext.info); } else { ext.info = initialTable.GetAssetInfo(pathId); ext.instance = GetATI(file, ext.info); } return(ext); }
public static AssetExternal GetExtAssetFixed(this AssetsManager _this, AssetsFileInstance relativeTo, int fileId, long pathId, bool onlyGetInfo = false, bool forceFromCldb = false) { AssetExternal ext = new AssetExternal { info = null, instance = null, file = null }; if (fileId == 0 && pathId == 0) { return(ext); } else if (fileId != 0) { AssetsFileInstance dep = relativeTo.GetDependency(_this, fileId - 1); if (dep == null) { return(ext); } ext.file = dep; ext.info = dep.table.GetAssetInfo(pathId); if (ext.info == null) { return(ext); } if (!onlyGetInfo) { ext.instance = _this.GetTypeInstance(dep.file, ext.info, forceFromCldb); } else { ext.instance = null; } return(ext); } else { ext.file = relativeTo; ext.info = relativeTo.table.GetAssetInfo(pathId); if (ext.info == null) { return(ext); } if (!onlyGetInfo) { ext.instance = _this.GetTypeInstance(relativeTo.file, ext.info, forceFromCldb); } else { ext.instance = null; } return(ext); } }
private List <AssetInfo> GetFSMInfos(AssetsFile file, AssetsFileTable table, bool hasDataField) { List <AssetInfo> assetInfos = new List <AssetInfo>(); uint assetCount = table.assetFileInfoCount; uint fsmTypeId = 0; foreach (AssetFileInfoEx info in table.assetFileInfo) { bool isMono = false; if (fsmTypeId == 0) { ushort monoType; if (file.header.format <= 0x10) { monoType = info.scriptIndex; } else { monoType = file.typeTree.unity5Types[info.curFileTypeOrIndex].scriptIndex; } if (monoType != 0xFFFF) { isMono = true; } } else if (info.curFileType == fsmTypeId) { isMono = true; } if (isMono) { AssetTypeInstance monoAti = am.GetATI(file, info); AssetExternal ext = am.GetExtAsset(curFile, monoAti.GetBaseField().Get("m_Script")); AssetTypeInstance scriptAti = am.GetExtAsset(curFile, monoAti.GetBaseField().Get("m_Script")).instance; AssetTypeInstance goAti = am.GetExtAsset(curFile, monoAti.GetBaseField().Get("m_GameObject")).instance; if (goAti == null) //found a scriptable object, oops { fsmTypeId = 0; continue; } string m_Name = goAti.GetBaseField().Get("m_Name").GetValue().AsString(); string m_ClassName = scriptAti.GetBaseField().Get("m_ClassName").GetValue().AsString(); if (m_ClassName == "PlayMakerFSM") { if (fsmTypeId == 0) { fsmTypeId = info.curFileType; } AssetsFileReader reader = file.reader; long oldPos = reader.BaseStream.Position; reader.BaseStream.Position = info.absoluteFilePos; reader.BaseStream.Position += 28; uint length = reader.ReadUInt32(); reader.ReadBytes((int)length); reader.Align(); reader.BaseStream.Position += 16; if (!hasDataField) { reader.BaseStream.Position -= 4; } uint length2 = reader.ReadUInt32(); string fsmName = Encoding.UTF8.GetString(reader.ReadBytes((int)length2)); reader.BaseStream.Position = oldPos; assetInfos.Add(new AssetInfo() { id = info.index, size = info.curFileSize, name = m_Name + "-" + fsmName }); } } } assetInfos.Sort((x, y) => x.name.CompareTo(y.name)); return(assetInfos); }
private void ReplaceReferencesRecurse(AssetsFileInstance inst, AssetTypeValueField field, AssetFileInfoEx inf) { foreach (AssetTypeValueField child in field.children) { //not a value (ie int) if (!child.templateField.hasValue) { //not null if (child == null) { return; } //not array of values either if (child.templateField.isArray && child.templateField.children[1].valueType != EnumValueTypes.ValueType_None) { break; } string typeName = child.templateField.type; //is a pptr if (typeName.StartsWith("PPtr<") && typeName.EndsWith(">") && child.childrenCount == 2) { int fileId = child.Get("m_FileID").GetValue().AsInt(); long pathId = child.Get("m_PathID").GetValue().AsInt64(); //not a null pptr if (pathId == 0) { continue; } AssetID aid = ConvertToAssetID(inst, fileId, pathId); //not already visited if (references.ContainsKey(aid)) { AssetID id = references[aid]; //normally, I would've just checked if the path names //matched up, but this is faster than looking up names //I check type of this asset and compare with the name //of the assetid to see if it should be itself or if //it should be the dependency file bool isSelfAsset = IsAsset(inf); bool isDepAsset = id.fileName == ASSET_LEVEL_NAME; int newFileId = isDepAsset ^ isSelfAsset ? 1 : 0; child.Get("m_FileID").GetValue().Set(newFileId); child.Get("m_PathID").GetValue().Set(id.pathId); } else { /////////////// todo move to another method AssetsFileInstance depInst = ConvertToInstance(inst, fileId); AssetFileInfoEx depInf = depInst.table.GetAssetInfo(pathId); if (depInf.curFileType == 0x72) { ushort scriptIndex = depInst.file.typeTree.unity5Types[depInf.curFileTypeOrIndex].scriptIndex; if (tk2dSpriteScriptIndex == 0xffff) { AssetTypeValueField monoBase = am.GetATI(depInst.file, depInf).GetBaseField(); AssetExternal scriptBaseExt = am.GetExtAsset(depInst, monoBase.Get("m_Script")); if (scriptBaseExt.instance != null) { AssetTypeValueField scriptBase = scriptBaseExt.instance.GetBaseField(); string scriptName = scriptBase.Get("m_ClassName").GetValue().AsString(); if (scriptName == "tk2dSprite") { tk2dSpriteScriptIndex = scriptIndex; } } } if (tk2dSpriteScriptIndex == depInst.file.typeTree.unity5Types[depInf.curFileTypeOrIndex].scriptIndex) { string managedPath = Path.Combine(Path.GetDirectoryName(depInst.path), "Managed"); AssetTypeValueField spriteBase = am.GetMonoBaseFieldCached(depInst, depInf, managedPath); int spriteId = spriteBase.Get("_spriteId").GetValue().AsInt(); AssetExternal colBaseExt = am.GetExtAsset(depInst, spriteBase.Get("collection")); AssetsFileInstance colInst = colBaseExt.file; AssetTypeValueField colBase = am.GetMonoBaseFieldCached(colInst, colBaseExt.info, managedPath); AssetTypeValueField spriteDefinitions = colBase.Get("spriteDefinitions")[spriteId]; AssetTypeValueField positionsField = spriteDefinitions.Get("positions"); AssetTypeValueField uvsField = spriteDefinitions.Get("uvs"); AssetTypeValueField indicesField = spriteDefinitions.Get("indices"); Vector3[] positions = new Vector3[positionsField.GetChildrenCount()]; Vector2[] uvs = new Vector2[uvsField.GetChildrenCount()]; int[] indices = new int[indicesField.GetChildrenCount()]; for (int i = 0; i < positions.Length; i++) { AssetTypeValueField positionField = positionsField[i]; positions[i] = new Vector3() { x = positionField.Get("x").GetValue().AsFloat(), y = positionField.Get("y").GetValue().AsFloat(), z = positionField.Get("z").GetValue().AsFloat() }; } for (int i = 0; i < uvs.Length; i++) { AssetTypeValueField uvField = uvsField[i]; uvs[i] = new Vector2() { x = uvField.Get("x").GetValue().AsFloat(), y = uvField.Get("y").GetValue().AsFloat() }; } for (int i = 0; i < indices.Length; i++) { AssetTypeValueField indexField = indicesField[i]; indices[i] = indexField.GetValue().AsInt(); } AssetID thisAid = ConvertToAssetID(inst, 0, inf.index); tk2dFromGoLookup[thisAid] = new Tk2dInfo(positions, uvs, indices); } } /////////////// child.Get("m_FileID").GetValue().Set(0); child.Get("m_PathID").GetValue().Set(0); } } ReplaceReferencesRecurse(inst, child, inf); } } }
public async Task <bool> ExecutePlugin(Window win, AssetWorkspace workspace, List <AssetExternal> selection) { AssetExternal tex = selection[0]; AssetTypeValueField texBaseField = GetByteArrayTexture(workspace, tex); TextureFile texFile = TextureFile.ReadTextureFile(texBaseField); SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Save texture"; sfd.Filters = new List <FileDialogFilter>() { new FileDialogFilter() { Name = "PNG file", Extensions = new List <string>() { "png" } } }; string file = await sfd.ShowAsync(win); if (file != null && file != string.Empty) { //bundle resS TextureFile.StreamingInfo streamInfo = texFile.m_StreamData; if (streamInfo.path != null && streamInfo.path != "" && tex.file.parentBundle != null) { //some versions apparently don't use archive:/ string searchPath = streamInfo.path; if (searchPath.StartsWith("archive:/")) { searchPath = searchPath.Substring(9); } searchPath = Path.GetFileName(searchPath); AssetBundleFile bundle = tex.file.parentBundle.file; AssetsFileReader reader = bundle.reader; AssetBundleDirectoryInfo06[] dirInf = bundle.bundleInf6.dirInf; bool foundFile = false; for (int i = 0; i < dirInf.Length; i++) { AssetBundleDirectoryInfo06 info = dirInf[i]; if (info.name == searchPath) { reader.Position = bundle.bundleHeader6.GetFileDataOffset() + info.offset + streamInfo.offset; texFile.pictureData = reader.ReadBytes((int)streamInfo.size); texFile.m_StreamData.offset = 0; texFile.m_StreamData.size = 0; texFile.m_StreamData.path = ""; foundFile = true; break; } } if (!foundFile) { await MessageBoxUtil.ShowDialog(win, "Error", "resS was detected but no file was found in bundle"); return(false); } } byte[] data = GetRawTextureBytes(texFile, tex.file); bool success = await TextureImportExport.ExportPng(data, file, texFile.m_Width, texFile.m_Height, (TextureFormat)texFile.m_TextureFormat); return(success); } return(false); }
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]; } } }
private void FixAssetPre(AssetsFileInstance inst, AssetTypeValueField field, AssetFileInfoEx inf) { if (inf.curFileType == 0xd5) //fix sprite { AssetTypeValueField renderDataKey = field.Get("m_RenderDataKey"); AssetTypeValueField spriteAtlas = field.Get("m_SpriteAtlas"); long spriteAtlasPathId = spriteAtlas.Get("m_PathID").GetValue().AsInt64(); uint rid0 = renderDataKey.Get("first")[0].GetValue().AsUInt(); uint rid1 = renderDataKey.Get("first")[1].GetValue().AsUInt(); uint rid2 = renderDataKey.Get("first")[2].GetValue().AsUInt(); uint rid3 = renderDataKey.Get("first")[3].GetValue().AsUInt(); //editor can't read these for whatever reason if (spriteAtlasPathId != 0) { AssetExternal spriteAtlasExt = am.GetExtAsset(inst, spriteAtlas); AssetTypeValueField spriteAtlasBase = spriteAtlasExt.instance.GetBaseField(); AssetTypeValueField renderDataMap = spriteAtlasBase.Get("m_RenderDataMap").Get("Array"); int renderDataMapCount = renderDataMap.GetValue().AsArray().size; int renderDataIndex = -1; for (int i = 0; i < renderDataMapCount; i++) { AssetTypeValueField renderDataMapKey = renderDataMap[i].Get("first"); uint thisrid0 = renderDataMapKey.Get("first")[0].GetValue().AsUInt(); uint thisrid1 = renderDataMapKey.Get("first")[1].GetValue().AsUInt(); uint thisrid2 = renderDataMapKey.Get("first")[2].GetValue().AsUInt(); uint thisrid3 = renderDataMapKey.Get("first")[3].GetValue().AsUInt(); if (thisrid0 == rid0 && thisrid1 == rid1 && thisrid2 == rid2 && thisrid3 == rid3) { renderDataIndex = i; break; } } if (renderDataIndex != -1) { AssetTypeValueField spriteAtlasRD = renderDataMap[renderDataIndex].Get("second"); AssetTypeValueField spriteRD = field.Get("m_RD"); //texture AssetTypeValueField spriteAtlasTexture = spriteAtlasRD.Get("texture"); AssetTypeValueField spriteTexture = spriteRD.Get("texture"); spriteTexture.Get("m_FileID").GetValue().Set(spriteAtlasTexture.Get("m_FileID").GetValue().AsInt()); spriteTexture.Get("m_PathID").GetValue().Set(spriteAtlasTexture.Get("m_PathID").GetValue().AsInt64()); //alphaTexture AssetTypeValueField spriteAtlasAlphaTexture = spriteAtlasRD.Get("alphaTexture"); AssetTypeValueField spriteAlphaTexture = spriteRD.Get("alphaTexture"); spriteAlphaTexture.Get("m_FileID").GetValue().Set(spriteAtlasAlphaTexture.Get("m_FileID").GetValue().AsInt()); spriteAlphaTexture.Get("m_PathID").GetValue().Set(spriteAtlasAlphaTexture.Get("m_PathID").GetValue().AsInt64()); //textureRect AssetTypeValueField spriteAtlasTextureRect = spriteAtlasRD.Get("textureRect"); AssetTypeValueField spriteTextureRect = spriteRD.Get("textureRect"); spriteTextureRect.Get("x").GetValue().Set(spriteAtlasTextureRect.Get("x").GetValue().AsFloat()); spriteTextureRect.Get("y").GetValue().Set(spriteAtlasTextureRect.Get("y").GetValue().AsFloat()); spriteTextureRect.Get("width").GetValue().Set(spriteAtlasTextureRect.Get("width").GetValue().AsFloat()); spriteTextureRect.Get("height").GetValue().Set(spriteAtlasTextureRect.Get("height").GetValue().AsFloat()); ////textureRectOffset AssetTypeValueField spriteAtlasTextureRectOffset = spriteAtlasRD.Get("textureRectOffset"); AssetTypeValueField spriteTextureRectOffset = spriteRD.Get("textureRectOffset"); spriteTextureRectOffset.Get("x").GetValue().Set(spriteAtlasTextureRectOffset.Get("x").GetValue().AsFloat()); spriteTextureRectOffset.Get("y").GetValue().Set(spriteAtlasTextureRectOffset.Get("y").GetValue().AsFloat()); //atlasRectOffset AssetTypeValueField spriteAtlasAtlasRectOffset = spriteAtlasRD.Get("atlasRectOffset"); AssetTypeValueField spriteAtlasRectOffset = spriteRD.Get("atlasRectOffset"); spriteAtlasRectOffset.Get("x").GetValue().Set(spriteTextureRectOffset.Get("x").GetValue().AsFloat()); spriteAtlasRectOffset.Get("y").GetValue().Set(spriteTextureRectOffset.Get("y").GetValue().AsFloat()); spriteAtlasRectOffset.Get("x").GetValue().Set(spriteAtlasAtlasRectOffset.Get("x").GetValue().AsFloat()); spriteAtlasRectOffset.Get("y").GetValue().Set(spriteAtlasAtlasRectOffset.Get("y").GetValue().AsFloat()); //uvTransform AssetTypeValueField spriteAtlasUvTransform = spriteAtlasRD.Get("uvTransform"); AssetTypeValueField spriteUvTransform = spriteRD.Get("uvTransform"); spriteUvTransform.Get("x").GetValue().Set(spriteAtlasUvTransform.Get("x").GetValue().AsFloat()); spriteUvTransform.Get("y").GetValue().Set(spriteAtlasUvTransform.Get("y").GetValue().AsFloat()); spriteUvTransform.Get("z").GetValue().Set(spriteAtlasUvTransform.Get("z").GetValue().AsFloat()); spriteUvTransform.Get("w").GetValue().Set(spriteAtlasUvTransform.Get("w").GetValue().AsFloat()); //downscaleMultiplier AssetTypeValueField spriteAtlasDownscapeMultiplier = spriteAtlasRD.Get("downscaleMultiplier"); AssetTypeValueField spriteDownscapeMultiplier = spriteRD.Get("downscaleMultiplier"); spriteDownscapeMultiplier.GetValue().Set(spriteAtlasDownscapeMultiplier.GetValue().AsFloat()); //settingsRaw AssetTypeValueField spriteAtlasSettingsRaw = spriteAtlasRD.Get("settingsRaw"); AssetTypeValueField spriteSettingsRaw = spriteRD.Get("settingsRaw"); spriteSettingsRaw.GetValue().Set(spriteAtlasSettingsRaw.GetValue().AsFloat()); spriteAtlas.Get("m_FileID").GetValue().Set(0); spriteAtlas.Get("m_PathID").GetValue().Set((long)0); } //else //{ // Debug.Log("exhausted sprite search"); //} } } }