Seek() 공개 메소드

public Seek ( int index, int &length, int &extra, bool &patched ) : Stream
index int
length int
extra int
patched bool
리턴 System.IO.Stream
예제 #1
0
        public static byte[] GetRawGump(int index, out int width, out int height)
        {
            width  = -1;
            height = -1;
            int    length, extra;
            bool   patched;
            Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(null);
            }
            if (extra == -1)
            {
                return(null);
            }
            width  = (extra >> 16) & 0xFFFF;
            height = extra & 0xFFFF;
            if (width <= 0 || height <= 0)
            {
                return(null);
            }
            byte[] buffer = new byte[length];
            stream.Read(buffer, 0, length);
            stream.Close();
            return(buffer);
        }
예제 #2
0
파일: Art.cs 프로젝트: uotools/UltimaSDK
        public static Bitmap GetLand(int index, bool cache)
        {
            index &= 0x3FFF;

            if (m_Cache[index] != null)
            {
                return(m_Cache[index]);
            }

            int    length, extra;
            bool   patched;
            Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(null);
            }

            if (cache)
            {
                return(m_Cache[index] = LoadLand(stream));
            }
            else
            {
                return(LoadLand(stream));
            }
        }
예제 #3
0
        /// <summary>
        ///     Tests if given index is valid
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static bool TestLight(int index)
        {
            if (m_Removed[index])
            {
                return(false);
            }
            if (m_Cache[index] != null)
            {
                return(true);
            }

            int  length, extra;
            bool patched;

            var stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(false);
            }
            stream.Close();
            var width  = (extra & 0xFFFF);
            var height = ((extra >> 16) & 0xFFFF);

            if ((width > 0) && (height > 0))
            {
                return(true);
            }

            return(false);
        }
예제 #4
0
        /// <summary>
        /// Tests if given index is valid
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static bool TestLight(int index)
        {
            if (_removed[index])
            {
                return(false);
            }

            if (_cache[index] != null)
            {
                return(true);
            }

            Stream stream = _fileIndex.Seek(index, out int _, out int extra, out bool _);

            if (stream == null)
            {
                return(false);
            }

            stream.Close();

            int width  = (extra & 0xFFFF);
            int height = ((extra >> 16) & 0xFFFF);

            return((width > 0) && (height > 0));
        }
예제 #5
0
        /// <summary>
        /// Tests if Static is defined (width and height check)
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static bool IsValidStatic(int index)
        {
            index  = GetLegalItemID(index);
            index += 0x4000;

            if (_removed[index])
            {
                return(false);
            }

            if (_cache[index] != null)
            {
                return(true);
            }

            Stream stream = _fileIndex.Seek(index, out int _, out int _, out bool _);

            if (stream == null)
            {
                return(false);
            }

            stream.Seek(4, SeekOrigin.Current);
            stream.Read(_validBuffer, 0, 4);

            ref var width  = ref _validBuffer[0];
예제 #6
0
파일: Multis.cs 프로젝트: credzba/Razor
        public static MultiComponentList Load(int index)
        {
            try
            {
                int    length, extra;
                bool   patched;
                Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

                if (stream == null)
                {
                    return(MultiComponentList.Empty);
                }

                if (PostHSFormat || Art.IsUOAHS())
                {
                    return(new MultiComponentList(new BinaryReader(stream), length / 16));
                }
                else
                {
                    return(new MultiComponentList(new BinaryReader(stream), length / 12));
                }
            }
            catch
            {
                return(MultiComponentList.Empty);
            }
        }
예제 #7
0
파일: Art.cs 프로젝트: nydehi/divinity
		public static Bitmap GetLand( int index )
		{
			index &= 0x3FFF;

			if ( m_Cache[index] != null )
				return m_Cache[index];

			int length, extra;
			bool patched;
			Stream stream = m_FileIndex.Seek( index, out length, out extra, out patched );

			if ( stream == null )
				return null;

			return m_Cache[index] = LoadLand( stream );
		}
예제 #8
0
        /// <summary>
        ///     Tests if Static is definied (width and hight check)
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static unsafe bool IsValidStatic(int index)
        {
            index  = GetLegalItemID(index);
            index += 0x4000;

            try
            {
                if (m_Removed[index])
                {
                    return(false);
                }
                if (m_Cache[index] != null)
                {
                    return(true);
                }
            }
            catch
            {
                throw new ArgumentException(String.Format("Index: {0}", index));
            }

            int    length, extra;
            bool   patched;
            Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(false);
            }

            if (Validbuffer == null)
            {
                Validbuffer = new byte[4];
            }
            stream.Seek(4, SeekOrigin.Current);
            stream.Read(Validbuffer, 0, 4);
            fixed(byte *b = Validbuffer)
            {
                var dat = (short *)b;

                if (*dat++ <= 0 || *dat <= 0)
                {
                    return(false);
                }
                return(true);
            }
        }
예제 #9
0
        /// <summary>
        /// Tests if Static is definied (width and hight check)
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static unsafe bool IsValidStatic(int index)
        {
            index  = GetLegalItemID(index);
            index += 0x4000;

            if (m_Removed[index])
            {
                return(false);
            }

            if (m_Cache[index] != null)
            {
                return(true);
            }

            var stream = m_FileIndex.Seek(index, out var length, out var extra, out var patched);

            if (stream == null)
            {
                return(false);
            }

            if (Validbuffer == null)
            {
                Validbuffer = new byte[4];
            }

            stream.Seek(4, SeekOrigin.Current);
            stream.Read(Validbuffer, 0, 4);
            fixed(byte *b = Validbuffer)
            {
                var dat = (short *)b;

                if (*dat++ <= 0 || *dat <= 0)
                {
                    return(false);
                }

                return(true);
            }
        }
예제 #10
0
파일: Art.cs 프로젝트: m309/fiddler-plus
        /// <summary>
        /// Tests if Static is definied (width and hight check)
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static unsafe bool IsValidStatic(int index)
        {
            index = 0x4000 + System.Math.Min(index & 0xFFFF, StaticLength - 1);

            if (m_Removed[index])
            {
                return(false);
            }
            if (m_Cache[index] != null)
            {
                return(true);
            }

            int    length, extra;
            bool   patched;
            Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(false);
            }

            if (Validbuffer == null)
            {
                Validbuffer = new byte[4];
            }
            stream.Seek(4, SeekOrigin.Current);
            stream.Read(Validbuffer, 0, 4);
            fixed(byte *b = Validbuffer)
            {
                short *dat = (short *)b;

                if (*dat++ <= 0 || *dat <= 0)
                {
                    return(false);
                }
                return(true);
            }
        }
예제 #11
0
파일: Art.cs 프로젝트: UOAccess/UOFiddler
        /// <summary>
        /// Tests if Static is defined (width and height check)
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static unsafe bool IsValidStatic(int index)
        {
            index  = GetLegalItemID(index);
            index += 0x4000;

            if (_removed[index])
            {
                return(false);
            }

            if (_cache[index] != null)
            {
                return(true);
            }

            Stream stream = _fileIndex.Seek(index, out int _, out int _, out bool _);

            if (stream == null)
            {
                return(false);
            }

            if (_validBuffer == null)
            {
                _validBuffer = new byte[4];
            }

            stream.Seek(4, SeekOrigin.Current);
            stream.Read(_validBuffer, 0, 4);
            fixed(byte *b = _validBuffer)
            {
                var dat = (short *)b;

                return(*dat++ > 0 && *dat > 0);
            }
        }
예제 #12
0
파일: Skills.cs 프로젝트: uotools/UltimaSDK
        public static Skill GetSkill(int index)
        {
            if (m_List[index] != null)
            {
                return(m_List[index]);
            }

            int    length, extra;
            bool   patched;
            Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(m_List[index] = new Skill(SkillData.DefaultData));
            }

            return(m_List[index] = LoadSkill(index, stream));
        }
예제 #13
0
파일: Multis.cs 프로젝트: m309/fiddler-plus
        public static MultiComponentList Load(int index)
        {
            try
            {
                int    length, extra;
                bool   patched;
                Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

                if (stream == null)
                {
                    return(MultiComponentList.Empty);
                }

                return(new MultiComponentList(new BinaryReader(stream), length / (Art.IsUOHS ? 16 : 12)));
            }
            catch
            {
                return(MultiComponentList.Empty);
            }
        }
예제 #14
0
        public AnimIdx(int index, FileIndex fileIndex, int filetype)
        {
            Palette = new ushort[0x100];
            int    length, extra;
            bool   patched;
            Stream stream = fileIndex.Seek(index, out length, out extra, out patched);

            if ((stream == null) || (length < 1))
            {
                return;
            }

            idxextra = extra;
            using (BinaryReader bin = new BinaryReader(stream))
            {
                for (int i = 0; i < 0x100; ++i)
                {
                    Palette[i] = (ushort)(bin.ReadUInt16() ^ 0x8000);
                }

                int start      = (int)bin.BaseStream.Position;
                int frameCount = bin.ReadInt32();

                int[] lookups = new int[frameCount];

                for (int i = 0; i < frameCount; ++i)
                {
                    lookups[i] = start + bin.ReadInt32();
                }

                Frames = new List <FrameEdit>();

                for (int i = 0; i < frameCount; ++i)
                {
                    stream.Seek(lookups[i], SeekOrigin.Begin);
                    Frames.Add(new FrameEdit(bin));
                }
            }

            stream.Close();
        }
예제 #15
0
        /// <summary>
        /// Returns <see cref="SkillInfo"/> of index
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static SkillInfo GetSkill(int index)
        {
            Stream stream = _fileIndex.Seek(index, out int length, out int extra, out bool _);

            if (stream == null)
            {
                return(null);
            }

            if (length == 0)
            {
                return(null);
            }

            using (var bin = new BinaryReader(stream))
            {
                bool   action = bin.ReadBoolean();
                string name   = ReadNameString(bin, length - 1);
                return(new SkillInfo(index, name, action, extra));
            }
        }
예제 #16
0
파일: Skills.cs 프로젝트: AsYlum-/Razor-1
        /// <summary>
        /// Returns <see cref="SkillInfo"/> of index
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private static SkillInfo GetSkill(int index)
        {
            Stream stream = _fileIndex.Seek(index, out int length, out int extra, out bool patched);

            if (stream != null)
            {
                if (length == 0)
                {
                    return(null);
                }

                using (BinaryReader bin = new BinaryReader(stream))
                {
                    bool   action      = bin.ReadBoolean();
                    string name        = ReadNameString(bin, length - 1);
                    string displayName = Language.GetSkillCliloc(index);
                    return(new SkillInfo(index, name, displayName, action, extra));
                }
            }

            return(null);
        }
예제 #17
0
        /// <summary>
        ///     Returns <see cref="SkillInfo" /> of index
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static SkillInfo GetSkill(int index)
        {
            int  length, extra;
            bool patched;

            var stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(null);
            }
            if (length == 0)
            {
                return(null);
            }

            using (var bin = new BinaryReader(stream))
            {
                var action = bin.ReadBoolean();
                var name   = ReadNameString(bin, length - 1);
                return(new SkillInfo(index, name, action, extra));
            }
        }
예제 #18
0
        public unsafe static Bitmap GetTexture(int index)
        {
            int  length, extra;
            bool patched;

            Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(null);
            }

            int size = extra == 0 ? 64 : 128;

            Bitmap       bmp = new Bitmap(size, size, PixelFormat.Format16bppArgb1555);
            BitmapData   bd  = bmp.LockBits(new Rectangle(0, 0, size, size), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);
            BinaryReader bin = new BinaryReader(stream);

            ushort *line  = (ushort *)bd.Scan0;
            int     delta = bd.Stride >> 1;

            for (int y = 0; y < size; ++y, line += delta)
            {
                ushort *cur = line;
                ushort *end = cur + size;

                while (cur < end)
                {
                    *cur++ = (ushort)(bin.ReadUInt16() ^ 0x8000);
                }
            }

            bmp.UnlockBits(bd);

            return(bmp);
        }
예제 #19
0
        /// <summary>
        /// Returns <see cref="UOSound"/> of ID with bool translated in .def
        /// </summary>
        /// <param name="soundId"></param>
        /// <param name="translated"></param>
        /// <returns></returns>
        public static UOSound GetSound(int soundId, out bool translated)
        {
            translated = false;
            if (soundId < 0)
            {
                return(null);
            }

            if (_removed[soundId])
            {
                return(null);
            }

            if (_cache[soundId] != null)
            {
                return(_cache[soundId]);
            }

            Stream stream = _fileIndex.Seek(soundId, out int length, out int _, out bool _);

            if (_fileIndex.Index[soundId].Lookup < 0 || length <= 0)
            {
                if (!_translations.TryGetValue(soundId, out soundId))
                {
                    return(null);
                }

                translated = true;
                stream     = _fileIndex.Seek(soundId, out length, out int _, out bool _);
            }

            if (stream == null)
            {
                return(null);
            }

            length -= 32;
            int[] waveHeader = WaveHeader(length);

            var stringBuffer = new byte[32];
            var buffer       = new byte[length];

            stream.Read(stringBuffer, 0, 32);
            stream.Read(buffer, 0, length);
            stream.Close();

            var resultBuffer = new byte[buffer.Length + (waveHeader.Length << 2)];

            Buffer.BlockCopy(waveHeader, 0, resultBuffer, 0, waveHeader.Length << 2);
            Buffer.BlockCopy(buffer, 0, resultBuffer, waveHeader.Length << 2, buffer.Length);

            string str = Encoding.ASCII.GetString(stringBuffer);

            // seems that the null terminator's not being properly recognized :/
            if (str.IndexOf('\0') > 0)
            {
                str = str.Substring(0, str.IndexOf('\0'));
            }

            var sound = new UOSound(str, soundId, resultBuffer);

            if (!Files.CacheData)
            {
                return(sound);
            }

            if (!translated) // no .def definition
            {
                _cache[soundId] = sound;
            }

            return(sound);
        }
예제 #20
0
파일: Sound.cs 프로젝트: roxya/Razor
        /// <summary>
        /// Returns <see cref="UOSound"/> of ID with bool translated in .def
        /// </summary>
        /// <param name="soundID"></param>
        /// <param name="translated"></param>
        /// <returns></returns>
        public static UOSound GetSound(int soundID, out bool translated)
        {
            translated = false;
            if (soundID < 0)
            {
                return(null);
            }
            if (m_Cache[soundID] != null)
            {
                return(m_Cache[soundID]);
            }

            int    length, extra;
            bool   patched;
            Stream stream = m_FileIndex.Seek(soundID, out length, out extra, out patched);

            if ((m_FileIndex.Index[soundID].lookup < 0) || (length <= 0))
            {
                if (!m_Translations.TryGetValue(soundID, out soundID))
                {
                    return(null);
                }

                translated = true;
                stream     = m_FileIndex.Seek(soundID, out length, out extra, out patched);
            }

            if (stream == null)
            {
                return(null);
            }

            length -= 32;
            int[] waveHeader = WaveHeader(length);

            byte[] stringBuffer = new byte[32];
            byte[] buffer       = new byte[length];

            stream.Read(stringBuffer, 0, 32);
            stream.Read(buffer, 0, length);
            stream.Close();

            byte[] resultBuffer = new byte[buffer.Length + (waveHeader.Length << 2)];

            Buffer.BlockCopy(waveHeader, 0, resultBuffer, 0, (waveHeader.Length << 2));
            Buffer.BlockCopy(buffer, 0, resultBuffer, (waveHeader.Length << 2), buffer.Length);

            string
                str = Encoding.ASCII
                      .GetString(stringBuffer); // seems that the null terminator's not being properly recognized :/

            if (str.IndexOf('\0') > 0)
            {
                str = str.Substring(0, str.IndexOf('\0'));
            }
            UOSound sound = new UOSound(str, soundID, resultBuffer);

            if (Files.CacheData)
            {
                if (!translated) // no .def definition
                {
                    m_Cache[soundID] = sound;
                }
            }

            return(sound);
        }
예제 #21
0
        public unsafe static Bitmap GetGump(int index, Hue hue, bool onlyHueGrayPixels)
        {
            int    length, extra;
            bool   patched;
            Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(null);
            }

            int width  = (extra >> 16) & 0xFFFF;
            int height = extra & 0xFFFF;

            if (width <= 0 || height <= 0)
            {
                return(null);
            }

            int bytesPerLine   = width << 1;
            int bytesPerStride = (bytesPerLine + 3) & ~3;
            int bytesForImage  = height * bytesPerStride;

            int pixelsPerStride      = (width + 1) & ~1;
            int pixelsPerStrideDelta = pixelsPerStride - width;

            byte[] pixelBuffer = m_PixelBuffer;

            if (pixelBuffer == null || pixelBuffer.Length < bytesForImage)
            {
                m_PixelBuffer = pixelBuffer = new byte[(bytesForImage + 2047) & ~2047];
            }

            byte[] streamBuffer = m_StreamBuffer;

            if (streamBuffer == null || streamBuffer.Length < length)
            {
                m_StreamBuffer = streamBuffer = new byte[(length + 2047) & ~2047];
            }

            byte[] colorTable = m_ColorTable;

            if (colorTable == null)
            {
                m_ColorTable = colorTable = new byte[128];
            }

            stream.Read(streamBuffer, 0, length);

            fixed(short *psHueColors = hue.Colors)
            {
                fixed(byte *pbStream = streamBuffer)
                {
                    fixed(byte *pbPixels = pixelBuffer)
                    {
                        fixed(byte *pbColorTable = colorTable)
                        {
                            ushort *pHueColors    = (ushort *)psHueColors;
                            ushort *pHueColorsEnd = pHueColors + 32;

                            ushort *pColorTable = (ushort *)pbColorTable;

                            ushort *pColorTableOpaque = pColorTable;

                            while (pHueColors < pHueColorsEnd)
                            {
                                *pColorTableOpaque++ = *pHueColors++;
                            }

                            ushort *pPixelDataStart = (ushort *)pbPixels;

                            int *pLookup        = (int *)pbStream;
                            int *pLookupEnd     = pLookup + height;
                            int *pPixelRleStart = pLookup;
                            int *pPixelRle;

                            ushort *pPixel = pPixelDataStart;
                            ushort *pRleEnd;
                            ushort *pPixelEnd = pPixel + width;

                            ushort color, count;

                            if (onlyHueGrayPixels)
                            {
                                while (pLookup < pLookupEnd)
                                {
                                    pPixelRle = pPixelRleStart + *pLookup++;
                                    pRleEnd   = pPixel;

                                    while (pPixel < pPixelEnd)
                                    {
                                        color = *(ushort *)pPixelRle;
                                        count = *(1 + (ushort *)pPixelRle);
                                        ++pPixelRle;

                                        pRleEnd += count;

                                        if (color != 0 && (color & 0x1F) == ((color >> 5) & 0x1F) && (color & 0x1F) == ((color >> 10) & 0x1F))
                                        {
                                            color = pColorTable[color >> 10];
                                        }
                                        else if (color != 0)
                                        {
                                            color ^= 0x8000;
                                        }

                                        while (pPixel < pRleEnd)
                                        {
                                            *pPixel++ = color;
                                        }
                                    }

                                    pPixel    += pixelsPerStrideDelta;
                                    pPixelEnd += pixelsPerStride;
                                }
                            }
                            else
                            {
                                while (pLookup < pLookupEnd)
                                {
                                    pPixelRle = pPixelRleStart + *pLookup++;
                                    pRleEnd   = pPixel;

                                    while (pPixel < pPixelEnd)
                                    {
                                        color = *(ushort *)pPixelRle;
                                        count = *(1 + (ushort *)pPixelRle);
                                        ++pPixelRle;

                                        pRleEnd += count;

                                        if (color != 0)
                                        {
                                            color = pColorTable[color >> 10];
                                        }

                                        while (pPixel < pRleEnd)
                                        {
                                            *pPixel++ = color;
                                        }
                                    }

                                    pPixel    += pixelsPerStrideDelta;
                                    pPixelEnd += pixelsPerStride;
                                }
                            }

                            return(new Bitmap(width, height, bytesPerStride, PixelFormat.Format16bppArgb1555, (IntPtr)pPixelDataStart));
                        }
                    }
                }
            }
        }
예제 #22
0
        /// <summary>
        /// Returns Bitmap of Texture with verdata bool
        /// </summary>
        /// <param name="index"></param>
        /// <param name="patched"></param>
        /// <returns></returns>
        public unsafe static Bitmap GetTexture(int index, out bool patched)
        {
            if (m_patched.Contains(index))
            {
                patched = (bool)m_patched[index];
            }
            else
            {
                patched = false;
            }
            if (m_Removed[index])
            {
                return(null);
            }
            if (m_Cache[index] != null)
            {
                return(m_Cache[index]);
            }

            int    length, extra;
            Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(null);
            }
            if (length == 0)
            {
                return(null);
            }
            if (patched)
            {
                m_patched[index] = true;
            }

            int size = extra == 0 ? 64 : 128;

            Bitmap     bmp = new Bitmap(size, size, PixelFormat.Format16bppArgb1555);
            BitmapData bd  = bmp.LockBits(new Rectangle(0, 0, size, size), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);

            ushort *line  = (ushort *)bd.Scan0;
            int     delta = bd.Stride >> 1;

            int max = size * size * 2;

            if (m_StreamBuffer == null || m_StreamBuffer.Length < max)
            {
                m_StreamBuffer = new byte[max];
            }
            stream.Read(m_StreamBuffer, 0, max);

            fixed(byte *data = m_StreamBuffer)
            {
                ushort *bindat = (ushort *)data;

                for (int y = 0; y < size; ++y, line += delta)
                {
                    ushort *cur = line;
                    ushort *end = cur + size;

                    while (cur < end)
                    {
                        *cur++ = (ushort)(*bindat++ ^ 0x8000);
                    }
                }
            }

            bmp.UnlockBits(bd);

            stream.Close();
            if (!Files.CacheData)
            {
                return(m_Cache[index] = bmp);
            }
            else
            {
                return(bmp);
            }
        }
예제 #23
0
        public AnimIdx(int index, FileIndex fileIndex, int filetype)
        {
            Palette = new ushort[0x100];
            int length, extra;
            bool patched;
            Stream stream = fileIndex.Seek(index, out length, out extra, out patched);
            if ((stream == null) || (length < 1))
                return;

            idxextra = extra;
            using (BinaryReader bin = new BinaryReader(stream))
            {
                for (int i = 0; i < 0x100; ++i)
                    Palette[i] = (ushort)(bin.ReadUInt16() ^ 0x8000);

                int start = (int)bin.BaseStream.Position;
                int frameCount = bin.ReadInt32();

                int[] lookups = new int[frameCount];

                for (int i = 0; i < frameCount; ++i)
                    lookups[i] = start + bin.ReadInt32();

                Frames = new List<FrameEdit>();

                for (int i = 0; i < frameCount; ++i)
                {
                    stream.Seek(lookups[i], SeekOrigin.Begin);
                    Frames.Add(new FrameEdit(bin));
                }
            }
            stream.Close();
        }
예제 #24
0
        /// <summary>
        /// Returns Bitmap of Texture with verdata bool
        /// </summary>
        /// <param name="index"></param>
        /// <param name="patched"></param>
        /// <returns></returns>
        public static unsafe Bitmap GetTexture(int index, out bool patched)
        {
            patched = _patched.ContainsKey(index) && _patched[index];

            if (_removed[index])
            {
                return(null);
            }

            if (_cache[index] != null)
            {
                return(_cache[index]);
            }

            Stream stream = _fileIndex.Seek(index, out int length, out int extra, out patched);

            if (stream == null)
            {
                return(null);
            }

            if (length == 0)
            {
                return(null);
            }

            if (patched)
            {
                _patched[index] = true;
            }

            int size = extra == 0 ? 64 : 128;

            var        bmp = new Bitmap(size, size, PixelFormat.Format16bppArgb1555);
            BitmapData bd  = bmp.LockBits(new Rectangle(0, 0, size, size), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);

            var line  = (ushort *)bd.Scan0;
            int delta = bd.Stride >> 1;

            int max = size * size * 2;

            byte[] streamBuffer = new byte[max];

            stream.Read(streamBuffer, 0, max);

            fixed(byte *data = streamBuffer)
            {
                var binData = (ushort *)data;

                for (int y = 0; y < size; ++y, line += delta)
                {
                    ushort *cur = line;
                    ushort *end = cur + size;

                    while (cur < end)
                    {
                        *cur++ = (ushort)(*binData++ ^ 0x8000);
                    }
                }
            }

            bmp.UnlockBits(bd);

            stream.Close();

            if (!Files.CacheData)
            {
                return(_cache[index] = bmp);
            }

            return(bmp);
        }