public unsafe static Bitmap DrawText(int fontId, string text, short hueId) { ASCIIFont font = ASCIIFont.GetFixed(fontId); Bitmap result = new Bitmap(font.GetWidth(text), font.Height); BitmapData surface = result.LockBits(new Rectangle(0, 0, result.Width, result.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); int dx = 0; for (int i = 0; i < text.Length; ++i) { Bitmap bmp = font.GetBitmap(text[i]); BitmapData chr = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); for (int dy = 0; dy < chr.Height; ++dy) { byte *src = ((byte *)chr.Scan0) + (chr.Stride * dy); byte *dest = (((byte *)surface.Scan0) + (surface.Stride * (dy + (font.Height - chr.Height)))) + (dx << 2); for (int k = 0; k < chr.Width; ++k) { *dest++ = *src++; *dest++ = *src++; *dest++ = *src++; *dest++ = *src++; } } dx += chr.Width; bmp.UnlockBits(chr); } result.UnlockBits(surface); hueId = (short)((hueId & 0x3FFF) - 1); if (hueId >= 0 && hueId < Hues.List.Length) { Hue hueObject = Hues.List[hueId]; if (hueObject != null) { hueObject.ApplyTo(result, ((hueId & 0x8000) == 0)); } } return(result); }
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); }
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; } } }
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); }
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); }