public TextureViewer(AssetsFileInstance inst, AssetTypeValueField baseField) { InitializeComponent(); loaded = false; TextureFile tf = TextureFile.ReadTextureFile(baseField); byte[] texDat = tf.GetTextureData(inst); if (texDat != null && texDat.Length > 0) { string fmtName = ((TextureFormat)tf.m_TextureFormat).ToString().Replace("_", " "); Text = $"Texture Viewer [{fmtName}]"; image = new Bitmap(tf.m_Width, tf.m_Height, tf.m_Width * 4, PixelFormat.Format32bppArgb, Marshal.UnsafeAddrOfPinnedArrayElement(texDat, 0)); image.RotateFlip(RotateFlipType.RotateNoneFlipY); x = -image.Width / 2; y = -image.Height / 2; width = image.Width; height = image.Height; sc = 1f; mouseDown = false; DoubleBuffered = true; ClientSize = new Size(width, height); loaded = true; } }
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 TextureViewer(AssetsFileInstance inst, AssetTypeValueField baseField) { InitializeComponent(); loaded = false; TextureFile tf = TextureFile.ReadTextureFile(baseField); byte[] texDat = tf.GetTextureData(inst); if (texDat != null && texDat.Length > 0) { string fmtName = ((TextureFormat)tf.m_TextureFormat).ToString().Replace("_", " "); Text = $"Texture Viewer [{fmtName}]"; image = new Bitmap(tf.m_Width, tf.m_Height, tf.m_Width * 4, PixelFormat.Format32bppArgb, Marshal.UnsafeAddrOfPinnedArrayElement(texDat, 0)); 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 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; } }