private bool GetResSTexture(TextureFile texFile, AssetContainer cont) { TextureFile.StreamingInfo streamInfo = texFile.m_StreamData; if (streamInfo.path != null && streamInfo.path != "" && cont.FileInstance.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 = cont.FileInstance.parentBundle.file; AssetsFileReader reader = bundle.reader; AssetBundleDirectoryInfo06[] dirInf = bundle.bundleInf6.dirInf; 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 = ""; return(true); } } return(false); } else { return(true); } }
public TextureViewer(AssetsFileInstance inst, AssetTypeValueField baseField) { InitializeComponent(); loaded = false; TextureFile tf = TextureFile.ReadTextureFile(baseField); //bundle resS TextureFile.StreamingInfo streamInfo = tf.m_StreamData; if (streamInfo.path != null && inst.parentBundle != null) { string searchPath = streamInfo.path; if (streamInfo.path.StartsWith("archive:/")) { searchPath = searchPath.Substring(9); } searchPath = Path.GetFileName(searchPath); AssetBundleFile bundle = inst.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 + (long)streamInfo.offset; tf.pictureData = reader.ReadBytes((int)streamInfo.size); tf.m_StreamData.offset = 0; tf.m_StreamData.size = 0; tf.m_StreamData.path = ""; foundFile = true; break; } } if (!foundFile) { MessageBox.Show("resS was detected but no file was found in bundle"); } } byte[] texDat = tf.GetTextureData(inst); if (texDat != null && texDat.Length > 0) { string fmtName = ((TextureFormat)tf.m_TextureFormat).ToString().Replace("_", " "); Text = $"Texture Viewer [{fmtName}]"; loadedFileName = tf.m_Name; image = new Bitmap(tf.m_Width, tf.m_Height, PixelFormat.Format32bppArgb); Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); BitmapData picData = image.LockBits(rect, ImageLockMode.ReadWrite, image.PixelFormat); picData.Stride = tf.m_Width * 4; IntPtr startAddr = picData.Scan0; Marshal.Copy(texDat, 0, startAddr, texDat.Length); image.UnlockBits(picData); image.RotateFlip(RotateFlipType.RotateNoneFlipY); x = 0; y = 0; width = image.Width; height = image.Height; sc = 1f; mouseDown = false; DoubleBuffered = true; Rectangle workingArea = Screen.PrimaryScreen.WorkingArea; int waWidth = workingArea.Width; int waHeight = workingArea.Height; int cliDiffWidth = Size.Width - ClientSize.Width; int cliDiffHeight = Size.Height - ClientSize.Height; ClientSize = new Size(Math.Min(width, waWidth - cliDiffWidth), Math.Min(height, waHeight - cliDiffHeight)); loaded = true; } }
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); }