Exemplo n.º 1
0
        /// <summary>
        /// Reads hues.mul and fills <see cref="List"/>
        /// </summary>
        public static void Initialize(string path)
        {
            int index = 0;

            List = new Hue[3000];

            if (path != null)
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader bin = new BinaryReader(fs);

                    int blockCount = (int)fs.Length / 708;

                    if (blockCount > 375)
                        blockCount = 375;

                    for (int i = 0; i < blockCount; ++i)
                    {
                        bin.ReadInt32();

                        for (int j = 0; j < 8; ++j, ++index)
                            List[index] = new Hue(index, bin);
                    }
                }
            }

            for (; index < List.Length; ++index)
                List[index] = new Hue(index);
        }
Exemplo n.º 2
0
		static Hues()
		{
			string path = Client.GetFilePath( "hues.mul" );
			int index = 0;

			m_List = new Hue[3000];

			if ( path != null )
			{
				using ( FileStream fs = new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read ) )
				{
					BinaryReader bin = new BinaryReader( fs );

					int blockCount = (int)fs.Length / 708;

					if ( blockCount > 375 )
						blockCount = 375;

					for ( int i = 0; i < blockCount; ++i )
					{
						bin.ReadInt32();

						for ( int j = 0; j < 8; ++j, ++index )
							m_List[index] = new Hue( index, bin );
					}
				}
			}

			for ( ; index < 3000; ++index )
				m_List[index] = new Hue( index );
		}
Exemplo n.º 3
0
		/// <summary>
		///     Reads hues.mul and fills <see cref="List" />
		/// </summary>
		public static void Initialize()
		{
			string path = Files.GetFilePath("hues.mul");
			int index = 0;

			List = new Hue[3000];

			if (path != null)
			{
				using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
				{
					int blockCount = (int)fs.Length / 708;

					if (blockCount > 375)
					{
						blockCount = 375;
					}
					m_Header = new int[blockCount];
					int structsize = Marshal.SizeOf(typeof(HueDataMul));
					var buffer = new byte[blockCount * (4 + 8 * structsize)];
					GCHandle gc = GCHandle.Alloc(buffer, GCHandleType.Pinned);
					try
					{
						fs.Read(buffer, 0, buffer.Length);
						long currpos = 0;

						for (int i = 0; i < blockCount; ++i)
						{
							var ptrheader = new IntPtr((long)gc.AddrOfPinnedObject() + currpos);
							currpos += 4;
							m_Header[i] = (int)Marshal.PtrToStructure(ptrheader, typeof(int));

							for (int j = 0; j < 8; ++j, ++index)
							{
								var ptr = new IntPtr((long)gc.AddrOfPinnedObject() + currpos);
								currpos += structsize;
								var cur = (HueDataMul)Marshal.PtrToStructure(ptr, typeof(HueDataMul));
								List[index] = new Hue(index, cur);
							}
						}
					}
					finally
					{
						gc.Free();
					}
				}
			}

			for (; index < List.Length; ++index)
			{
				List[index] = new Hue(index);
			}
		}
Exemplo n.º 4
0
 public HueEdit(int index, Hues m_refmarker)
 {
     InitializeComponent();
     this.Icon = FiddlerControls.Options.GetFiddlerIcon();
     refmarker = m_refmarker;
     hue = Ultima.Hues.GetHue(index);
     Colors = new short[32];
     hue.Colors.CopyTo(Colors, 0);
     textBoxName.Text = hue.Name;
     this.Text = String.Format("HueEdit {0}", index);
     Selected = 0;
     Second_Selected = -1;
     pictureBoxPreview.Image = new Bitmap(pictureBoxPreview.Width, pictureBoxPreview.Height);
 }
Exemplo n.º 5
0
        static Hues()
        {
            //string path = Client.GetFilePath( "hues.mul" );
            //Changed by Nolok
            string path  = "hues.mul";
            int    index = 0;

            m_List = new Hue[3000];

            //if ( path != null )
            //{
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BinaryReader bin = new BinaryReader(fs);

                int blockCount = (int)fs.Length / 708;

                if (blockCount > 375)
                {
                    blockCount = 375;
                }

                for (int i = 0; i < blockCount; ++i)
                {
                    bin.ReadInt32();

                    for (int j = 0; j < 8; ++j, ++index)
                    {
                        m_List[index] = new Hue(index, bin);
                    }
                }
            }
            //}

            for ( ; index < 3000; ++index)
            {
                m_List[index] = new Hue(index);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns Bitmap of index and applies Hue
        /// </summary>
        /// <param name="index"></param>
        /// <param name="hue"></param>
        /// <param name="onlyHueGrayPixels"></param>
        /// <returns></returns>
        public unsafe static Bitmap GetGump(int index, Hue hue, bool onlyHueGrayPixels, out bool patched)
        {
            int    length, extra;
            Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(null);
            }
            if (extra == -1)
            {
                stream.Close();
                return(null);
            }

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

            if (width <= 0 || height <= 0)
            {
                stream.Close();
                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   = pPixel;
                            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;
                                }
                            }
                            stream.Close();
                            return(new Bitmap(width, height, bytesPerStride, PixelFormat.Format16bppArgb1555, (IntPtr)pPixelDataStart));
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        public static unsafe Bitmap GetGump(int index, Hue hue, bool onlyHueGrayPixels)
        {
            int    length;
            int    extra;
            bool   patched;
            Stream stream = Gumps.m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return((Bitmap)null);
            }
            int width  = extra >> 16 & (int)ushort.MaxValue;
            int height = extra & (int)ushort.MaxValue;

            if (width <= 0 || height <= 0)
            {
                return((Bitmap)null);
            }
            int stride = (width << 1) + 3 & -4;
            int num1   = height * stride;
            int num2   = width + 1 & -2;
            int num3   = num2 - width;

            byte[] numArray1 = Gumps.m_PixelBuffer;
            if (numArray1 == null || numArray1.Length < num1)
            {
                Gumps.m_PixelBuffer = numArray1 = new byte[num1 + 2047 & -2048];
            }
            byte[] buffer = Gumps.m_StreamBuffer;
            if (buffer == null || buffer.Length < length)
            {
                Gumps.m_StreamBuffer = buffer = new byte[length + 2047 & -2048];
            }
            byte[] numArray2 = Gumps.m_ColorTable;
            if (numArray2 == null)
            {
                Gumps.m_ColorTable = numArray2 = new byte[128];
            }
            stream.Read(buffer, 0, length);
            fixed(short *numPtr1 = &hue.Colors[0])
            fixed(byte *numPtr2 = &buffer[0])
            fixed(byte *numPtr3 = &numArray1[0])
            fixed(byte *numPtr4 = &numArray2[0])
            {
                ushort *numPtr5 = (ushort *)numPtr1;
                ushort *numPtr6 = numPtr5 + 32;
                ushort *numPtr7 = (ushort *)numPtr4;
                ushort *numPtr8 = numPtr7;

                while (numPtr5 < numPtr6)
                {
                    *numPtr8++ = *numPtr5++;
                }
                ushort *numPtr9  = (ushort *)numPtr3;
                int *   numPtr10 = (int *)numPtr2;
                int *   numPtr11 = numPtr10 + height;
                int *   numPtr12 = numPtr10;
                ushort *numPtr13 = numPtr9;
                ushort *numPtr14 = numPtr13 + width;

                if (onlyHueGrayPixels)
                {
                    while (numPtr10 < numPtr11)
                    {
                        int *   numPtr15 = numPtr12 + *numPtr10++;
                        ushort *numPtr16 = numPtr13;
                        while (numPtr13 < numPtr14)
                        {
                            ushort num4 = *(ushort *)numPtr15;
                            ushort num5 = *(ushort *)(new IntPtr(2) + (IntPtr)numPtr15);
                            numPtr15 += 4;
                            numPtr16 += num5;
                            if ((int)num4 != 0 && ((int)num4 & 31) == ((int)num4 >> 5 & 31) && ((int)num4 & 31) == ((int)num4 >> 10 & 31))
                            {
                                num4 = numPtr7[(int)num4 >> 10];
                            }
                            else if ((int)num4 != 0)
                            {
                                num4 ^= (ushort)short.MinValue;
                            }
                            while (numPtr13 < numPtr16)
                            {
                                *numPtr13++ = num4;
                            }
                        }
                        numPtr13 += num3;
                        numPtr14 += num2;
                    }
                }
                else
                {
                    while (numPtr10 < numPtr11)
                    {
                        int *   numPtr15 = numPtr12 + *numPtr10++;
                        ushort *numPtr16 = numPtr13;
                        while (numPtr13 < numPtr14)
                        {
                            ushort num4 = *(ushort *)numPtr15;
                            ushort num5 = *(ushort *)(new IntPtr(2) + (IntPtr)numPtr15);
                            numPtr15 += 4;
                            numPtr16 += num5;
                            if ((int)num4 != 0)
                            {
                                num4 = numPtr7[(int)num4 >> 10];
                            }
                            while (numPtr13 < numPtr16)
                            {
                                *numPtr13++ = num4;
                            }
                        }
                        numPtr13 += num3;
                        numPtr14 += num2;
                    }
                }
                return(new Bitmap(width, height, stride, PixelFormat.Format16bppArgb1555, (IntPtr)((void *)numPtr9)));
            }
        }
Exemplo n.º 8
0
        public static Frame[] GetAnimation(int body, int action, int direction, int hue, bool preserveHue)
        {
            if (preserveHue)
            {
                Translate(ref body);
            }
            else
            {
                Translate(ref body, ref hue);
            }

            int       fileType = BodyConverter.Convert(ref body);
            FileIndex fileIndex;

            int index;

            switch (fileType)
            {
            default:
            case 1:
            {
                fileIndex = m_FileIndex;

                if (body < 200)
                {
                    index = body * 110;
                }
                else if (body < 400)
                {
                    index = 22000 + ((body - 200) * 65);
                }
                else
                {
                    index = 35000 + ((body - 400) * 175);
                }

                break;
            }

            case 2:
            {
                fileIndex = m_FileIndex2;

                if (body < 200)
                {
                    index = body * 110;
                }
                else
                {
                    index = 22000 + ((body - 200) * 65);
                }

                break;
            }

            case 3:
            {
                fileIndex = m_FileIndex3;

                if (body < 300)
                {
                    index = body * 65;
                }
                else if (body < 400)
                {
                    index = 33000 + ((body - 300) * 110);
                }
                else
                {
                    index = 35000 + ((body - 400) * 175);
                }

                break;
            }
            }

            index += action * 5;

            if (direction <= 4)
            {
                index += direction;
            }
            else
            {
                index += direction - (direction - 4) * 2;
            }

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

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

            bool flip = (direction > 4);

            BinaryReader bin = new BinaryReader(stream);

            ushort[] palette = new ushort[0x100];

            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();
            }

            bool onlyHueGrayPixels = ((hue & 0x8000) == 0);

            hue = (hue & 0x3FFF) - 1;

            Hue hueObject = null;

            if (hue >= 0 && hue < Hues.List.Length)
            {
                hueObject = Hues.List[hue];
            }

            Frame[] frames = new Frame[frameCount];

            for (int i = 0; i < frameCount; ++i)
            {
                bin.BaseStream.Seek(lookups[i], SeekOrigin.Begin);
                frames[i] = new Frame(palette, bin, flip);

                if (hueObject != null)
                {
                    hueObject.ApplyTo(frames[i].Bitmap, onlyHueGrayPixels);
                }
            }

            return(frames);
        }
Exemplo n.º 9
0
		/// <summary>
		///     Returns Bitmap of index and applies Hue
		/// </summary>
		/// <param name="index"></param>
		/// <param name="hue"></param>
		/// <param name="onlyHueGrayPixels"></param>
		/// <returns></returns>
		public static unsafe Bitmap GetGump(int index, Hue hue, bool onlyHueGrayPixels, out bool patched)
		{
			int length, extra;
			Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

			if (stream == null)
			{
				return null;
			}
			if (extra == -1)
			{
				stream.Close();
				return null;
			}

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

			if (width <= 0 || height <= 0)
			{
				stream.Close();
				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)
						{
							var pHueColors = (ushort*)psHueColors;
							ushort* pHueColorsEnd = pHueColors + 32;

							var pColorTable = (ushort*)pbColorTable;

							ushort* pColorTableOpaque = pColorTable;

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

							var pPixelDataStart = (ushort*)pbPixels;

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

							ushort* pPixel = pPixelDataStart;
							ushort* pRleEnd = pPixel;
							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;
								}
							}
							stream.Close();
							return new Bitmap(width, height, bytesPerStride, PixelFormat.Format16bppArgb1555, (IntPtr)pPixelDataStart);
						}
					}
				}
			}
		}
Exemplo n.º 10
0
        public static unsafe Bitmap GetGump(int index, Hue hue, bool onlyHueGrayPixels)
        {
            int    num;
            int    num1;
            bool   flag;
            int *  numPointer;
            ushort num2;
            ushort num3;
            Stream stream = Gumps.m_FileIndex.Seek(index, out num, out num1, out flag);

            if (stream == null)
            {
                return(null);
            }
            int num4 = num1 >> 16 & 65535;
            int num5 = num1 & 65535;

            if (num4 <= 0 || num5 <= 0)
            {
                return(null);
            }
            int num6 = (num4 << 1) + 3 & -4;
            int num7 = num5 * num6;
            int num8 = num4 + 1 & -2;
            int num9 = num8 - num4;

            byte[] mPixelBuffer = Gumps.m_PixelBuffer;
            if (mPixelBuffer == null || (int)mPixelBuffer.Length < num7)
            {
                byte[] numArray = new byte[num7 + 2047 & -2048];
                mPixelBuffer        = numArray;
                Gumps.m_PixelBuffer = numArray;
            }
            byte[] mStreamBuffer = Gumps.m_StreamBuffer;
            if (mStreamBuffer == null || (int)mStreamBuffer.Length < num)
            {
                byte[] numArray1 = new byte[num + 2047 & -2048];
                mStreamBuffer        = numArray1;
                Gumps.m_StreamBuffer = numArray1;
            }
            byte[] mColorTable = Gumps.m_ColorTable;
            if (mColorTable == null)
            {
                byte[] numArray2 = new byte[128];
                mColorTable        = numArray2;
                Gumps.m_ColorTable = numArray2;
            }
            stream.Read(mStreamBuffer, 0, num);
            fixed(short *colors = &hue.Colors[0])
            {
                fixed(byte *numPointer1 = &mStreamBuffer[0])
                {
                    fixed(byte *numPointer2 = &mPixelBuffer[0])
                    {
                        fixed(byte *numPointer3 = &mColorTable[0])
                        {
                            ushort *numPointer4 = (ushort *)colors;
                            ushort *numPointer5 = numPointer4 + 64;
                            ushort *numPointer6 = (ushort *)numPointer3;
                            ushort *numPointer7 = numPointer6;

                            while (numPointer4 < numPointer5)
                            {
                                ushort *numPointer8 = numPointer7;
                                numPointer7 = numPointer8 + 2;
                                ushort *numPointer9 = numPointer4;
                                numPointer4 = numPointer9 + 2;
                                *numPointer8 = *numPointer9;
                            }
                            ushort *numPointer10 = (ushort *)numPointer2;
                            int *   numPointer11 = (int *)numPointer1;
                            int *   numPointer12 = numPointer11 + num5 * 4;
                            int *   numPointer13 = numPointer11;
                            ushort *numPointer14 = numPointer10;
                            ushort *numPointer15 = numPointer14;
                            ushort *numPointer16 = numPointer14 + num4 * 2;

                            if (!onlyHueGrayPixels)
                            {
                                while (numPointer11 < numPointer12)
                                {
                                    int *numPointer17 = numPointer11;
                                    numPointer11 = numPointer17 + 4;
                                    numPointer   = numPointer13 + *numPointer17 * 4;
                                    numPointer15 = numPointer14;
                                    while (numPointer14 < numPointer16)
                                    {
                                        num2         = (ushort)(*numPointer);
                                        num3         = (ushort)(*(2 + numPointer));
                                        numPointer   = numPointer + 4;
                                        numPointer15 = (ushort *)(numPointer15 + (void *)num3 * 2);
                                        if (num2 != 0)
                                        {
                                            num2 = *(numPointer6 + (num2 >> 10) * 2);
                                        }
                                        while (numPointer14 < numPointer15)
                                        {
                                            ushort *numPointer18 = numPointer14;
                                            numPointer14 = numPointer18 + 2;
                                            *numPointer18 = num2;
                                        }
                                    }
                                    numPointer14 = numPointer14 + num9 * 2;
                                    numPointer16 = numPointer16 + num8 * 2;
                                }
                            }
                            else
                            {
                                while (numPointer11 < numPointer12)
                                {
                                    int *numPointer19 = numPointer11;
                                    numPointer11 = numPointer19 + 4;
                                    numPointer   = numPointer13 + *numPointer19 * 4;
                                    numPointer15 = numPointer14;
                                    while (numPointer14 < numPointer16)
                                    {
                                        num2         = (ushort)(*numPointer);
                                        num3         = (ushort)(*(2 + numPointer));
                                        numPointer   = numPointer + 4;
                                        numPointer15 = (ushort *)(numPointer15 + (void *)num3 * 2);
                                        if (num2 != 0 && (num2 & 31) == (num2 >> 5 & 31) && (num2 & 31) == (num2 >> 10 & 31))
                                        {
                                            num2 = *(numPointer6 + (num2 >> 10) * 2);
                                        }
                                        else if (num2 != 0)
                                        {
                                            num2 = (ushort)(num2 ^ 32768);
                                        }
                                        while (numPointer14 < numPointer15)
                                        {
                                            ushort *numPointer20 = numPointer14;
                                            numPointer14 = numPointer20 + 2;
                                            *numPointer20 = num2;
                                        }
                                    }
                                    numPointer14 = numPointer14 + num9 * 2;
                                    numPointer16 = numPointer16 + num8 * 2;
                                }
                            }
                            return(new Bitmap(num4, num5, num6, PixelFormat.Format16bppArgb1555, (IntPtr)numPointer10));
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        private void listBoxStatic_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBoxStatic.SelectedItem == null)
            {
                return;
            }

            int id = FromHex(listBoxStatic.SelectedItem.ToString());

            foreach (Statics.TileInfo s in m_static)
            {
                if (s.StaticID == id)
                {
                    lStaticID.Text  = "0x" + s.StaticID.ToString("X4");
                    lStaticHue.Text = "0x" + s.StaticHue.ToString("X4");
                    lStaticZ.Text   = s.StaticZ.ToString();
                    // Immagine
                    Bitmap staticimage = Ultima.Art.GetStatic(s.StaticID);
                    {
                        if (staticimage != null && s.StaticHue > 0)
                        {
                            int  hue = s.StaticHue;
                            bool onlyHueGrayPixels = (hue & 0x8000) != 0;
                            hue = (hue & 0x3FFF) - 1;
                            Ultima.Hue m_hue = Ultima.Hues.GetHue(hue);
                            m_hue.ApplyTo(staticimage, onlyHueGrayPixels);
                        }
                        ipStaticImg.BackgroundImage = staticimage;
                    }

                    // Static Flag
                    lStaticFlagNone.Text      = (TileData.ItemTable[s.StaticID].Flags == TileFlag.None) ? "Yes" : "No";
                    lStaticFlagNone.ForeColor = (TileData.ItemTable[s.StaticID].Flags == TileFlag.None) ? Color.Green : Color.Red;

                    lStaticFlagTranslucent.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Translucent) != 0) ? "Yes" : "No";
                    lStaticFlagTranslucent.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Translucent) != 0) ? Color.Green : Color.Red;

                    lStaticFlagWall.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Wall) != 0) ? "Yes" : "No";
                    lStaticFlagWall.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Wall) != 0) ? Color.Green : Color.Red;

                    lStaticFlagDamaging.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Damaging) != 0) ? "Yes" : "No";
                    lStaticFlagDamaging.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Damaging) != 0) ? Color.Green : Color.Red;

                    lStaticFlagImpassable.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Impassable) != 0) ? "Yes" : "No";
                    lStaticFlagImpassable.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Impassable) != 0) ? Color.Green : Color.Red;

                    lStaticFlagSurface.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Surface) != 0) ? "Yes" : "No";
                    lStaticFlagSurface.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Surface) != 0) ? Color.Green : Color.Red;

                    lStaticFlagBridge.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Bridge) != 0) ? "Yes" : "No";
                    lStaticFlagBridge.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Bridge) != 0) ? Color.Green : Color.Red;

                    lStaticFlagWindow.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Window) != 0) ? "Yes" : "No";
                    lStaticFlagWindow.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Window) != 0) ? Color.Green : Color.Red;

                    lStaticFlagNoShot.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.NoShoot) != 0) ? "Yes" : "No";
                    lStaticFlagNoShot.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.NoShoot) != 0) ? Color.Green : Color.Red;

                    lStaticFlagFoliage.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Foliage) != 0) ? "Yes" : "No";
                    lStaticFlagFoliage.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Foliage) != 0) ? Color.Green : Color.Red;

                    lStaticFlagHoverOver.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.HoverOver) != 0) ? "Yes" : "No";
                    lStaticFlagHoverOver.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.HoverOver) != 0) ? Color.Green : Color.Red;

                    lStaticFlagRoof.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Roof) != 0) ? "Yes" : "No";
                    lStaticFlagRoof.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Roof) != 0) ? Color.Green : Color.Red;

                    lStaticFlagDoor.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Door) != 0) ? "Yes" : "No";
                    lStaticFlagDoor.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Door) != 0) ? Color.Green : Color.Red;

                    lStaticFlagWet.Text      = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Wet) != 0) ? "Yes" : "No";
                    lStaticFlagWet.ForeColor = ((TileData.ItemTable[s.StaticID].Flags & TileFlag.Wet) != 0) ? Color.Green : Color.Red;

                    break;
                }
            }
        }
Exemplo n.º 12
0
        public static Frame[] GetAnimation(int body, int action, int direction, int hue, bool preserveHue)
        {
            if (preserveHue)
            {
                Animations.Translate(ref body);
            }
            else
            {
                Animations.Translate(ref body, ref hue);
            }
            FileIndex fileIndex;
            int       num1;

            switch (BodyConverter.Convert(ref body))
            {
            case 2:
                fileIndex = Animations.m_FileIndex2;
                num1      = body >= 200 ? 22000 + (body - 200) * 65 : body * 110;
                break;

            case 3:
                fileIndex = Animations.m_FileIndex3;
                num1      = body >= 300 ? (body >= 400 ? 35000 + (body - 400) * 175 : 33000 + (body - 300) * 110) : body * 65;
                break;

            default:
                fileIndex = Animations.m_FileIndex;
                num1      = body >= 200 ? (body >= 400 ? 35000 + (body - 400) * 175 : 22000 + (body - 200) * 65) : body * 110;
                break;
            }
            int    num2   = num1 + action * 5;
            int    index1 = direction > 4 ? num2 + (direction - (direction - 4) * 2) : num2 + direction;
            int    length1;
            int    extra;
            bool   patched;
            Stream input = fileIndex.Seek(index1, out length1, out extra, out patched);

            if (input == null)
            {
                return((Frame[])null);
            }
            bool         flip = direction > 4;
            BinaryReader bin  = new BinaryReader(input);

            ushort[] palette = new ushort[256];
            for (int index2 = 0; index2 < 256; ++index2)
            {
                palette[index2] = (ushort)((uint)bin.ReadUInt16() ^ 32768U);
            }
            int num3    = (int)bin.BaseStream.Position;
            int length2 = bin.ReadInt32();

            int[] numArray = new int[length2];
            for (int index2 = 0; index2 < length2; ++index2)
            {
                numArray[index2] = num3 + bin.ReadInt32();
            }
            bool onlyHueGrayPixels = (hue & 32768) == 0;

            hue = (hue & 16383) - 1;
            Hue hue1 = (Hue)null;

            if (hue >= 0 && hue < Hues.List.Length)
            {
                hue1 = Hues.List[hue];
            }
            Frame[] frameArray = new Frame[length2];
            for (int index2 = 0; index2 < length2; ++index2)
            {
                bin.BaseStream.Seek((long)numArray[index2], SeekOrigin.Begin);
                frameArray[index2] = new Frame(palette, bin, flip);
                if (hue1 != null)
                {
                    hue1.ApplyTo(frameArray[index2].Bitmap, onlyHueGrayPixels);
                }
            }
            return(frameArray);
        }
Exemplo n.º 13
0
 public BaseGump()
     : this(0)
 {
     Hue = new Hue(0);
 }
Exemplo n.º 14
0
        public virtual Bitmap GetImage()
        {
            Bitmap image;

            if (hue == null)
            {
                hue = new Hue(0);
            }

            if( hue.Index == 0 )
                image = Ultima.Gumps.GetGump(index);
            else
                image = Ultima.Gumps.GetGump(index, hue, false);

            Size = image.Size;

            return image;
        }
Exemplo n.º 15
0
 public virtual void Deserialize(XmlReader reader)
 {
     hue =  Hues.GetHue(XmlConvert.ToInt32(reader.GetAttribute("hue")));
     index = XmlConvert.ToInt32(reader.GetAttribute("index"));
     z = XmlConvert.ToInt32(reader.GetAttribute("z"));
     location = new Point(XmlConvert.ToInt32(reader.GetAttribute("x")), XmlConvert.ToInt32(reader.GetAttribute("y")));
     size = new Size(XmlConvert.ToInt32(reader.GetAttribute("width")), XmlConvert.ToInt32(reader.GetAttribute("height")));
 }
Exemplo n.º 16
0
        public static Frame[] GetAnimation(int body, int action, int direction, int hue, bool preserveHue)
        {
            Ultima.FileIndex mFileIndex2;
            int  num;
            int  num1;
            int  num2;
            bool flag;

            if (!preserveHue)
            {
                Animations.Translate(ref body, ref hue);
            }
            else
            {
                Animations.Translate(ref body);
            }
            switch (BodyConverter.Convert(ref body))
            {
            case 2:
            {
                mFileIndex2 = Animations.m_FileIndex2;
                if (body >= 200)
                {
                    num = 22000 + (body - 200) * 65;
                    break;
                }
                else
                {
                    num = body * 110;
                    break;
                }
            }

            case 3:
            {
                mFileIndex2 = Animations.m_FileIndex3;
                if (body < 300)
                {
                    num = body * 65;
                    break;
                }
                else if (body >= 400)
                {
                    num = 35000 + (body - 400) * 175;
                    break;
                }
                else
                {
                    num = 33000 + (body - 300) * 110;
                    break;
                }
            }

            default:
            {
                mFileIndex2 = Animations.m_FileIndex;
                if (body < 200)
                {
                    num = body * 110;
                    break;
                }
                else if (body >= 400)
                {
                    num = 35000 + (body - 400) * 175;
                    break;
                }
                else
                {
                    num = 22000 + (body - 200) * 65;
                    break;
                }
            }
            }
            num = num + action * 5;
            num = (direction > 4 ? num + (direction - (direction - 4) * 2) : num + direction);
            Stream stream = mFileIndex2.Seek(num, out num1, out num2, out flag);

            if (stream == null)
            {
                return(null);
            }
            bool         flag1        = direction > 4;
            BinaryReader binaryReader = new BinaryReader(stream);

            ushort[] numArray = new ushort[256];
            for (int i = 0; i < 256; i++)
            {
                numArray[i] = (ushort)(binaryReader.ReadUInt16() ^ 32768);
            }
            int position = (int)binaryReader.BaseStream.Position;
            int num3     = binaryReader.ReadInt32();

            int[] numArray1 = new int[num3];
            for (int j = 0; j < num3; j++)
            {
                numArray1[j] = position + binaryReader.ReadInt32();
            }
            bool flag2 = (hue & 32768) == 0;

            hue = (hue & 16383) - 1;
            Hue list = null;

            if (hue >= 0 && hue < (int)Hues.List.Length)
            {
                list = Hues.List[hue];
            }
            Frame[] frame = new Frame[num3];
            for (int k = 0; k < num3; k++)
            {
                binaryReader.BaseStream.Seek((long)numArray1[k], SeekOrigin.Begin);
                frame[k] = new Frame(numArray, binaryReader, flag1);
                if (list != null)
                {
                    list.ApplyTo(frame[k].Bitmap, flag2);
                }
            }
            return(frame);
        }
Exemplo n.º 17
0
 public static unsafe Bitmap GetGump(int index, Hue hue, bool onlyHueGrayPixels)
 {
     int length;
       int extra;
       bool patched;
       Stream stream = Gumps.m_FileIndex.Seek(index, out length, out extra, out patched);
       if (stream == null)
     return (Bitmap) null;
       int width = extra >> 16 & (int) ushort.MaxValue;
       int height = extra & (int) ushort.MaxValue;
       if (width <= 0 || height <= 0)
     return (Bitmap) null;
       int stride = (width << 1) + 3 & -4;
       int num1 = height * stride;
       int num2 = width + 1 & -2;
       int num3 = num2 - width;
       byte[] numArray1 = Gumps.m_PixelBuffer;
       if (numArray1 == null || numArray1.Length < num1)
     Gumps.m_PixelBuffer = numArray1 = new byte[num1 + 2047 & -2048];
       byte[] buffer = Gumps.m_StreamBuffer;
       if (buffer == null || buffer.Length < length)
     Gumps.m_StreamBuffer = buffer = new byte[length + 2047 & -2048];
       byte[] numArray2 = Gumps.m_ColorTable;
       if (numArray2 == null)
     Gumps.m_ColorTable = numArray2 = new byte[128];
       stream.Read(buffer, 0, length);
       fixed (short* numPtr1 = &hue.Colors[0])
     fixed (byte* numPtr2 = &buffer[0])
       fixed (byte* numPtr3 = &numArray1[0])
     fixed (byte* numPtr4 = &numArray2[0])
     {
       ushort* numPtr5 = (ushort*) numPtr1;
       ushort* numPtr6 = numPtr5 + 32;
       ushort* numPtr7 = (ushort*) numPtr4;
       ushort* numPtr8 = numPtr7;
       while (numPtr5 < numPtr6)
         *numPtr8++ = *numPtr5++;
       ushort* numPtr9 = (ushort*) numPtr3;
       int* numPtr10 = (int*) numPtr2;
       int* numPtr11 = numPtr10 + height;
       int* numPtr12 = numPtr10;
       ushort* numPtr13 = numPtr9;
       ushort* numPtr14 = numPtr13 + width;
       if (onlyHueGrayPixels)
       {
         while (numPtr10 < numPtr11)
         {
           int* numPtr15 = numPtr12 + *numPtr10++;
           ushort* numPtr16 = numPtr13;
           while (numPtr13 < numPtr14)
           {
             ushort num4 = *(ushort*) numPtr15;
             ushort num5 = *(ushort*) (new IntPtr(2) + (IntPtr) numPtr15);
             numPtr15 += 4;
             numPtr16 += num5;
             if ((int) num4 != 0 && ((int) num4 & 31) == ((int) num4 >> 5 & 31) && ((int) num4 & 31) == ((int) num4 >> 10 & 31))
               num4 = numPtr7[(int) num4 >> 10];
             else if ((int) num4 != 0)
               num4 ^= (ushort) short.MinValue;
             while (numPtr13 < numPtr16)
               *numPtr13++ = num4;
           }
           numPtr13 += num3;
           numPtr14 += num2;
         }
       }
       else
       {
         while (numPtr10 < numPtr11)
         {
           int* numPtr15 = numPtr12 + *numPtr10++;
           ushort* numPtr16 = numPtr13;
           while (numPtr13 < numPtr14)
           {
             ushort num4 = *(ushort*) numPtr15;
             ushort num5 = *(ushort*) (new IntPtr(2) + (IntPtr) numPtr15);
             numPtr15 += 4;
             numPtr16 += num5;
             if ((int) num4 != 0)
               num4 = numPtr7[(int) num4 >> 10];
             while (numPtr13 < numPtr16)
               *numPtr13++ = num4;
           }
           numPtr13 += num3;
           numPtr14 += num2;
         }
       }
       return new Bitmap(width, height, stride, PixelFormat.Format16bppArgb1555, (IntPtr) ((void*) numPtr9));
     }
 }