///void Free(); public void Read(long filePos, AssetsFileReader reader) { reader.Position = filePos; checksumLow = reader.ReadUInt64(); checksumHigh = reader.ReadUInt64(); blockCount = reader.ReadInt32(); blockInf = new AssetBundleBlockInfo06[blockCount]; for (int i = 0; i < blockCount; i++) { blockInf[i] = new AssetBundleBlockInfo06(); blockInf[i].decompressedSize = reader.ReadUInt32(); blockInf[i].compressedSize = reader.ReadUInt32(); blockInf[i].flags = reader.ReadUInt16(); } directoryCount = reader.ReadInt32(); dirInf = new AssetBundleDirectoryInfo06[directoryCount]; for (int i = 0; i < directoryCount; i++) { dirInf[i] = new AssetBundleDirectoryInfo06(); dirInf[i].offset = reader.ReadInt64(); dirInf[i].decompressedSize = reader.ReadInt64(); dirInf[i].flags = reader.ReadUInt32(); dirInf[i].name = reader.ReadNullTerminated(); } }
public static byte[] LoadAssetDataFromBundle(AssetBundleFile bundle, string name) { AssetBundleDirectoryInfo06[] dirInf = bundle.bundleInf6.dirInf; for (int i = 0; i < dirInf.Length; i++) { AssetBundleDirectoryInfo06 info = dirInf[i]; if (info.name == name) { return(LoadAssetDataFromBundle(bundle, i)); } } return(null); }
public static AssetBundleDirectoryInfo06 GetDirInfo(AssetBundleFile bundle, string name) { AssetBundleDirectoryInfo06[] dirInf = bundle.bundleInf6.dirInf; for (int i = 0; i < dirInf.Length; i++) { AssetBundleDirectoryInfo06 info = dirInf[i]; if (info.name == name) { return(info); } } return(null); }
public static AssetBundleFile CreateBlankBundle(string engineVersion, int contentSize) { AssetBundleHeader06 header = new AssetBundleHeader06() { signature = "UnityFS", fileVersion = 6, minPlayerVersion = "5.x.x", fileEngineVersion = engineVersion, totalFileSize = 0x82 + engineVersion.Length + contentSize, compressedSize = 0x5B, decompressedSize = 0x5B, flags = 0x40 }; AssetBundleBlockInfo06 blockInf = new AssetBundleBlockInfo06 { decompressedSize = (uint)contentSize, compressedSize = (uint)contentSize, flags = 0x0040 }; AssetBundleDirectoryInfo06 dirInf = new AssetBundleDirectoryInfo06 { offset = 0, decompressedSize = (uint)contentSize, flags = 4, name = GenerateCabName() }; AssetBundleBlockAndDirectoryList06 info = new AssetBundleBlockAndDirectoryList06() { checksumLow = 0, checksumHigh = 0, blockCount = 1, blockInf = new AssetBundleBlockInfo06[] { blockInf }, directoryCount = 1, dirInf = new AssetBundleDirectoryInfo06[] { dirInf } }; AssetBundleFile bundle = new AssetBundleFile() { bundleHeader6 = header, bundleInf6 = info }; return(bundle); }
public static List <AssetsFile> LoadAllAssetsFromBundle(AssetBundleFile bundle) { List <AssetsFile> files = new List <AssetsFile>(); AssetsFileReader reader = bundle.reader; AssetBundleDirectoryInfo06[] dirInf = bundle.bundleInf6.dirInf; for (int i = 0; i < dirInf.Length; i++) { AssetBundleDirectoryInfo06 info = dirInf[i]; if (bundle.IsAssetsFile(reader, info)) { files.Add(LoadAssetFromBundle(bundle, i)); } } return(files); }
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); }