public unsafe Bitmap GetLand(int index) { index &= 0x3FFF; int length, extra; using (var stream = _fileIndex.Seek(index, out length, out extra)) { if (stream == null) { return(null); } var bmp = new Bitmap(44, 44, PixelFormat.Format16bppArgb1555); var bd = bmp.LockBits(new Rectangle(0, 0, 44, 44), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555); var bin = new BinaryReader(stream); var xOffset = 21; var xRun = 2; var line = (ushort *)bd.Scan0; var delta = bd.Stride >> 1; for (var y = 0; y < 22; ++y, --xOffset, xRun += 2, line += delta) { var cur = line + xOffset; var end = cur + xRun; while (cur < end) { *cur++ = (ushort)(bin.ReadUInt16() | 0x8000); } } xOffset = 0; xRun = 44; for (var y = 0; y < 22; ++y, ++xOffset, xRun -= 2, line += delta) { var cur = line + xOffset; var end = cur + xRun; while (cur < end) { *cur++ = (ushort)(bin.ReadUInt16() | 0x8000); } } bmp.UnlockBits(bd); return(bmp); } }
public unsafe Texture GetLand(int index) { index &= 0x3FFF; int length, extra; using (var stream = _fileIndex.Seek(index, out length, out extra)) { using (var bin = new BinaryReader(stream)) { var texture = Texture.New2D(GraphicsDevice, 44, 44, PixelFormat.B5G5R5A1_UNorm); var buffer = new ushort[44 * 44]; var xOffset = 21; var xRun = 2; fixed(ushort *start = buffer) { var ptr = start; var delta = texture.Width; for (var y = 0; y < 22; ++y, --xOffset, xRun += 2, ptr += delta) { var cur = ptr + xOffset; var end = cur + xRun; while (cur < end) { *cur++ = (ushort)(bin.ReadUInt16() | 0x8000); } } xOffset = 0; xRun = 44; for (var y = 0; y < 22; ++y, ++xOffset, xRun -= 2, ptr += delta) { var cur = ptr + xOffset; var end = cur + xRun; while (cur < end) { *cur++ = (ushort)(bin.ReadUInt16() | 0x8000); } } } texture.SetData(buffer); return(texture); } } }
public unsafe ImageSource GetLand(int index) { index &= 0x3FFF; int length, extra; using (var stream = _fileIndex.Seek(index, out length, out extra)) { using (var bin = new BinaryReader(stream)) { var bmp = new WriteableBitmap(44, 44, 96, 96, PixelFormats.Bgr555, null); bmp.Lock(); var xOffset = 21; var xRun = 2; var line = (ushort *)bmp.BackBuffer; var delta = bmp.BackBufferStride >> 1; for (var y = 0; y < 22; ++y, --xOffset, xRun += 2, line += delta) { var cur = line + xOffset; var end = cur + xRun; while (cur < end) { *cur++ = (ushort)(bin.ReadUInt16() | 0x8000); } } xOffset = 0; xRun = 44; for (var y = 0; y < 22; ++y, ++xOffset, xRun -= 2, line += delta) { var cur = line + xOffset; var end = cur + xRun; while (cur < end) { *cur++ = (ushort)(bin.ReadUInt16() | 0x8000); } } bmp.AddDirtyRect(new Int32Rect(0, 0, 44, 44)); bmp.Unlock(); return(bmp); } } }
public static unsafe Texture GetLand(GraphicsDevice graphicsDevice, int index) { index &= 0x3FFF; using (var stream = _fileIndex.Seek(index, out _, out _)) using (var bin = new BinaryReader(stream)) { var texture = new Texture2D(graphicsDevice, 44, 44, false, SurfaceFormat.Bgra5551); var buffer = new ushort[44 * 44]; var xOffset = 21; var xRun = 2; fixed(ushort *start = buffer) { var ptr = start; var delta = texture.Width; for (var y = 0; y < 22; ++y, --xOffset, xRun += 2, ptr += delta) { var cur = ptr + xOffset; var end = cur + xRun; while (cur < end) { *cur++ = (ushort)(bin.ReadUInt16() | 0x8000); } } xOffset = 0; xRun = 44; for (var y = 0; y < 22; ++y, ++xOffset, xRun -= 2, ptr += delta) { var cur = ptr + xOffset; var end = cur + xRun; while (cur < end) { *cur++ = (ushort)(bin.ReadUInt16() | 0x8000); } } } texture.SetData(buffer); return(texture); } }
public unsafe Sound GetSound(int index) { int length, extra; Stream stream = _fileIndex.Seek(index, out length, out extra); if (stream == null) { return(null); } int[] waveHeader = CreateWaveHeader(length); length -= 40; int headerLength = (waveHeader.Length << 2); byte[] stringBuffer = new byte[40]; byte[] buffer = new byte[length + headerLength]; Buffer.BlockCopy(waveHeader, 0, buffer, 0, headerLength); stream.Read(stringBuffer, 0, 40); stream.Read(buffer, headerLength, length); string name = System.Text.Encoding.ASCII.GetString(stringBuffer).Trim(); int end = name.IndexOf("\0"); name = name.Substring(0, end); return(new Sound(name, new MemoryStream(buffer))); }
public unsafe Bitmap GetTexmap(int index) { int length, extra; Stream stream = _fileIndex.Seek(index, out length, out extra); 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); }
public Sound GetSound(int index) { int length, extra; using (var stream = _fileIndex.Seek(index, out length, out extra)) { if (stream == null) { return(null); } var waveHeader = CreateWaveHeader(length); length -= 40; var headerLength = (waveHeader.Length << 2); var stringBuffer = new byte[40]; var buffer = new byte[length + headerLength]; Buffer.BlockCopy(waveHeader, 0, buffer, 0, headerLength); stream.Read(stringBuffer, 0, 40); stream.Read(buffer, headerLength, length); var name = Encoding.ASCII.GetString(stringBuffer).Trim(); var end = name.IndexOf("\0"); name = name.Substring(0, end); return(new Sound(name, new MemoryStream(buffer))); } }
public unsafe Texture GetTexmap(int index) { int extra; int length; using (var stream = _fileIndex.Seek(index, out length, out extra)) { if (stream == null) { return(null); } var size = extra == 0 ? 64 : 128; using (var bin = new BinaryReader(stream)) { var texture = Texture.New2D(GraphicsDevice, size, size, PixelFormat.B5G5R5A1_UNorm); var buffer = new ushort[size * size]; fixed(ushort *start = buffer) { var ptr = start; var delta = texture.Width; for (var y = 0; y < size; ++y, ptr += delta) { var cur = ptr; var end = cur + size; while (cur < end) { *cur++ = (bin.ReadUInt16()); } } } texture.SetData(buffer); return(texture); } } }
private Skill ReadSkill(FileIndexBase fileIndex, int index) { int length, extra; using (var stream = fileIndex.Seek(index, out length, out extra)) { if (stream == null) { return(null); } using (var bin = new BinaryReader(stream)) { var nameLength = length - 2; var useBtn = bin.ReadByte(); var nameBuffer = new byte[nameLength]; bin.Read(nameBuffer, 0, nameLength); var unk = bin.ReadByte(); var sb = new StringBuilder(nameBuffer.Length); for (var i = 0; i < nameBuffer.Length; i++) { sb.Append((char)nameBuffer[i]); } var category = _categories[0]; if (index < _categoryLookup.Length) { category = _categories[_categoryLookup[index]]; } var skill = new Skill(new SkillData(index, sb.ToString(), useBtn > 0, extra, unk, category)); return(skill); } } }
public unsafe ImageSource GetTexmap(int index) { int length, extra; using (var stream = _fileIndex.Seek(index, out length, out extra)) { if (stream == null) { return(null); } var size = extra == 0 ? 64 : 128; using (var bin = new BinaryReader(stream)) { var bmp = new WriteableBitmap(size, size, 96, 96, PixelFormats.Bgr555, null); bmp.Lock(); var line = (ushort *)bmp.BackBuffer; var delta = bmp.BackBufferStride >> 1; for (var y = 0; y < size; ++y, line += delta) { var cur = line; var end = cur + size; while (cur < end) { *cur++ = (ushort)(bin.ReadUInt16() ^ 0x8000); } } bmp.AddDirtyRect(new Int32Rect(0, 0, size, size)); bmp.Unlock(); return(bmp); } } }
public unsafe Frame <ImageSource>[] 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); FileIndexBase fileIndex = _fileIndices[fileType - 1]; int index; switch (fileType) { default: { if (body < 200) { index = body * 110; } else if (body < 400) { index = 22000 + ((body - 200) * 65); } else { index = 35000 + ((body - 400) * 175); } break; } case 2: { if (body < 200) { index = body * 110; } else { index = 22000 + ((body - 200) * 65); } break; } case 3: { if (body < 300) { index = body * 65; } else if (body < 400) { index = 33000 + ((body - 300) * 110); } else { index = 35000 + ((body - 400) * 175); } break; } case 4: { if (body < 200) { index = body * 110; } else if (body < 400) { index = 22000 + ((body - 200) * 65); } else { index = 35000 + ((body - 400) * 175); } break; } case 5: { if (body < 200 && body != 34) // looks strange, though it works. { index = body * 110; } else { index = 35000 + ((body - 400) * 65); } break; } } if ((index + (action * 5)) > int.MaxValue) { throw new ArithmeticException(); } index += action * 5; if (direction <= 4) { index += direction; } else { index += direction - (direction - 4) * 2; } int length, extra; Stream stream = fileIndex.Seek(index, out length, out extra); 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.Table.Length) { hueObject = _hues.Table[hue]; } Frame <ImageSource>[] frames = new Frame <ImageSource> [frameCount]; for (int i = 0; i < frameCount; ++i) { bin.BaseStream.Seek(lookups[i], SeekOrigin.Begin); int xCenter = bin.ReadInt16(); int yCenter = bin.ReadInt16(); int width = bin.ReadUInt16(); int height = bin.ReadUInt16(); WriteableBitmap bmp = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr555, null); bmp.Lock(); ushort *line = (ushort *)bmp.BackBuffer; int delta = bmp.BackBufferStride >> 1; int header; int xBase = xCenter - 0x200; int yBase = (yCenter + height) - 0x200; if (!flip) { line += xBase; line += (yBase * delta); while ((header = bin.ReadInt32()) != 0x7FFF7FFF) { header ^= DoubleXor; ushort *cur = line + ((((header >> 12) & 0x3FF) * delta) + ((header >> 22) & 0x3FF)); ushort *end = cur + (header & 0xFFF); while (cur < end) { *cur++ = palette[bin.ReadByte()]; } } } else { line -= xBase - width + 1; line += (yBase * delta); while ((header = bin.ReadInt32()) != 0x7FFF7FFF) { header ^= DoubleXor; ushort *cur = line + ((((header >> 12) & 0x3FF) * delta) - ((header >> 22) & 0x3FF)); ushort *end = cur - (header & 0xFFF); while (cur > end) { *cur-- = palette[bin.ReadByte()]; } } xCenter = width - xCenter; } bmp.AddDirtyRect(new Int32Rect(0, 0, width, height)); bmp.Unlock(); if (hueObject != null) { ApplyHue(bmp, hueObject, onlyHueGrayPixels); } frames[i] = new Frame <ImageSource>(xCenter, yCenter, bmp); } return(frames); }
public unsafe Bitmap GetGump(int index) { int length, extra; Stream stream = _fileIndex.Seek(index, out length, out extra); if (stream == null) { return(null); } BinaryReader bin = new BinaryReader(stream); int width = (extra >> 16) & 0xFFFF; int height = extra & 0xFFFF; Bitmap bmp = new Bitmap(width, height, PixelFormat.Format16bppArgb1555); BitmapData bd = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555); int[] lookups = new int[height]; int start = (int)bin.BaseStream.Position; for (int i = 0; i < height; ++i) { lookups[i] = start + (bin.ReadInt32() * 4); } ushort *line = (ushort *)bd.Scan0; int delta = bd.Stride >> 1; for (int y = 0; y < height; ++y, line += delta) { bin.BaseStream.Seek(lookups[y], SeekOrigin.Begin); ushort *cur = line; ushort *end = line + bd.Width; while (cur < end) { ushort color = bin.ReadUInt16(); ushort *next = cur + bin.ReadUInt16(); if (color == 0) { cur = next; } else { color ^= 0x8000; while (cur < next) { *cur++ = color; } } } } bmp.UnlockBits(bd); return(bmp); }
public unsafe Texture GetGump(int index) { int length, extra; using (var stream = _fileIndex.Seek(index, out length, out extra)) { if (stream == null) { return(null); } using (var bin = new BinaryReader(stream)) { var width = (extra >> 16) & 0xFFFF; var height = extra & 0xFFFF; var texture = Texture.New2D(GraphicsDevice, width, height, PixelFormat.B5G5R5A1_UNorm); var buffer = new ushort[width * height]; var lookups = new int[height]; var startPosition = (int)bin.BaseStream.Position; for (var i = 0; i < height; ++i) { lookups[i] = startPosition + (bin.ReadInt32() * 4); } fixed(ushort *start = buffer) { var ptr = start; var delta = texture.Width; for (var y = 0; y < height; ++y, ptr += delta) { bin.BaseStream.Seek(lookups[y], SeekOrigin.Begin); var cur = ptr; var end = ptr + delta; while (cur < end) { var color = bin.ReadUInt16(); var next = cur + bin.ReadUInt16(); if (color == 0) { cur = next; } else { color ^= 0x8000; while (cur < next) { *cur++ = color; } } } } } texture.SetData(buffer); return(texture); } } }
public unsafe ImageSource GetGump(int index) { int length, extra; using (var stream = _fileIndex.Seek(index, out length, out extra)) { if (stream == null) { return(null); } using (var bin = new BinaryReader(stream)) { var width = (extra >> 16) & 0xFFFF; var height = extra & 0xFFFF; var bmp = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr555, null); bmp.Lock(); var lookups = new int[height]; var start = (int)bin.BaseStream.Position; for (var i = 0; i < height; ++i) { lookups[i] = start + (bin.ReadInt32() * 4); } var line = (ushort *)bmp.BackBuffer; var delta = (ushort)(bmp.BackBufferStride >> 1); for (var y = 0; y < height; ++y, line += delta) { bin.BaseStream.Seek(lookups[y], SeekOrigin.Begin); var cur = line; var end = line + bmp.PixelWidth; while (cur < end) { var color = bin.ReadUInt16(); var next = cur + bin.ReadUInt16(); if (color == 0) { cur = next; } else { color ^= 0x8000; while (cur < next) { *cur++ = color; } } } } bmp.AddDirtyRect(new Int32Rect(0, 0, width, height)); bmp.Unlock(); return(bmp); } } }