Exemplo n.º 1
0
        private void OpenTexture(Stream data, string fname, TextureFormat format)
        {
            TextureViewer viewer = new TextureViewer();

            long oldPosition = data.Position;

            try
            {
                viewer.OpenTexture(data, fname, format);
                viewer.Show();
            }
            catch (TextureNeedsPaletteException)
            {
                ArchiveInfo info = openedArchives.Peek();

                // Seems like we need a palette for this texture. Let's try to find one.
                string textureName      = Path.GetFileNameWithoutExtension(fname) + Texture.GetModule(format).PaletteFileExtension;
                int    paletteFileIndex = -1;

                for (int i = 0; i < info.Archive.Entries.Count; i++)
                {
                    if (info.Archive.Entries[i].Name.ToLower() == textureName.ToLower())
                    {
                        paletteFileIndex = i;
                        break;
                    }
                }

                // Let's see if we found the palette file. And if so, open it up.
                // Due to the nature of how this works, we need to copy the palette data to another stream first
                if (paletteFileIndex != -1)
                {
                    Stream entryData     = info.Archive.OpenEntry(paletteFileIndex);
                    int    paletteLength = (int)entryData.Length;

                    // Get the palette data (we may need to copy over the data to another stream)
                    Stream paletteData = new MemoryStream();
                    PTStream.CopyTo(entryData, paletteData);
                    paletteData.Position = 0;

                    // Now open the texture
                    data.Position = oldPosition;
                    viewer.OpenTexture(data, fname, paletteData, format);
                    viewer.Show();
                }
            }
        }
Exemplo n.º 2
0
        private void OpenTexture(Stream data, string fname, TextureFormat format)
        {
            TextureViewer viewer = new TextureViewer();

            long oldPosition = data.Position;

            try
            {
                viewer.OpenTexture(data, fname, format);
                viewer.Show();
            }
            catch (TextureNeedsPaletteException)
            {
                ArchiveInfo info = openedArchives.Peek();

                // Seems like we need a palette for this texture. Let's try to find one.
                string textureName = Path.GetFileNameWithoutExtension(fname) + Texture.GetModule(format).PaletteFileExtension;
                int paletteFileIndex = -1;

                for (int i = 0; i < info.Archive.Entries.Count; i++)
                {
                    if (info.Archive.Entries[i].Name.ToLower() == textureName.ToLower())
                    {
                        paletteFileIndex = i;
                        break;
                    }
                }

                // Let's see if we found the palette file. And if so, open it up.
                // Due to the nature of how this works, we need to copy the palette data to another stream first
                if (paletteFileIndex != -1)
                {
                    Stream entryData = info.Archive.OpenEntry(paletteFileIndex);
                    int paletteLength = (int)entryData.Length;

                    // Get the palette data (we may need to copy over the data to another stream)
                    Stream paletteData = new MemoryStream();
                    PTStream.CopyTo(entryData, paletteData);
                    paletteData.Position = 0;

                    // Now open the texture
                    data.Position = oldPosition;
                    viewer.OpenTexture(data, fname, paletteData, format);
                    viewer.Show();
                }
            }
        }