public static bool TryGetSoundData(int soundID, out byte[] data, out string name) { // Sounds.mul is exclusively locked by the legacy client, so we need to make sure this file is available // before attempting to play any sounds. if (!m_filesPrepared) { setupFiles(); } data = null; name = null; if (!m_filesPrepared || soundID < 0) { return(false); } else { int length, extra; bool is_patched; BinaryFileReader reader = m_Index.Seek(soundID, out length, out extra, out is_patched); int streamStart = (int)reader.Position; int offset = (int)reader.Position; if ((offset < 0) || (length <= 0)) { if (!m_Translations.TryGetValue(soundID, out soundID)) { return(false); } reader = m_Index.Seek(soundID, out length, out extra, out is_patched); streamStart = (int)reader.Position; offset = (int)reader.Position; } if ((offset < 0) || (length <= 0)) { return(false); } byte[] stringBuffer = new byte[40]; data = new byte[length - 40]; reader.Seek((long)(offset), SeekOrigin.Begin); stringBuffer = reader.ReadBytes(40); data = reader.ReadBytes(length - 40); name = Encoding.ASCII.GetString(stringBuffer).Trim(); int end = name.IndexOf("\0"); name = name.Substring(0, end); Metrics.ReportDataRead((int)reader.Position - streamStart); return(true); } }
unsafe Texture2D ReadLandTexture(int index) { int length, extra; bool is_patched; BinaryFileReader reader = m_FileIndex.Seek(index, out length, out extra, out is_patched); if (reader == null) { return(null); } ushort[] pixels = new ushort[44 * 44]; ushort[] data = reader.ReadUShorts(23 * 44); // land tile textures store only opaque pixels Metrics.ReportDataRead(data.Length); int i = 0; fixed(ushort *pData = pixels) { ushort *dataRef = pData; // fill the top half of the tile int count = 2; int offset = 21; for (int y = 0; y < 22; y++, count += 2, offset--, dataRef += 44) { ushort *start = dataRef + offset; ushort *end = start + count; while (start < end) { ushort color = data[i++]; * start++ = (ushort)(color | 0x8000); } } // file the bottom half of the tile count = 44; offset = 0; for (int y = 0; y < 22; y++, count -= 2, offset++, dataRef += 44) { ushort *start = dataRef + offset; ushort *end = start + count; while (start < end) { ushort color = data[i++]; * start++ = (ushort)(color | 0x8000); } } } Texture2D texture = new Texture2D(m_Graphics, 44, 44, false, SurfaceFormat.Bgra5551); texture.SetData(pixels); return(texture); }
unsafe Texture2DInfo ReadLandTexture(int index) { var r = _fileIndex.Seek(index, out int length, out int extra, out bool patched); if (r == null) { return(null); } var pixels = new byte[44 * 44 * 4]; var fileData = r.ReadUShorts(23 * 44); // land tile textures store only opaque pixels Metrics.ReportDataRead(fileData.Length); var i = 0; fixed(byte *pData = pixels) { uint *dataRef = (uint *)pData; // fill the top half of the tile int count = 2; int offset = 21; for (int y = 0; y < 22; y++, count += 2, offset--, dataRef += 44) { uint *start = dataRef + offset; uint *end = start + count; while (start < end) { uint color = ConvertUtils.FromBGR555(fileData[i++]); * start++ = color; } } // file the bottom half of the tile count = 44; offset = 0; for (int y = 0; y < 22; y++, count -= 2, offset++, dataRef += 44) { uint *start = dataRef + offset; uint *end = start + count; while (start < end) { uint color = ConvertUtils.FromBGR555(fileData[i++]); * start++ = color; } } } var texture = new Texture2DInfo(44, 44, TextureFormat.BGRA32, false, pixels); //texture.Rotate2D(45); return(texture); }
public static bool TryGetSoundData(int soundId, out byte[] data, out string name) { // Sounds.mul is exclusively locked by the legacy client, so we need to make sure this file is available // before attempting to play any sounds. if (!_filesPrepared) { SetupFiles(); } data = null; name = null; if (!_filesPrepared || soundId < 0) { return(false); } else { var r = _index.Seek(soundId, out int length, out int extra, out bool patched); var streamStart = (int)r.Position; var offset = (int)r.Position; if (offset < 0 || length <= 0) { if (!_translations.TryGetValue(soundId, out soundId)) { return(false); } r = _index.Seek(soundId, out length, out extra, out patched); streamStart = (int)r.Position; offset = (int)r.Position; } if (offset < 0 || length <= 0) { return(false); } var stringBuffer = new byte[40]; data = new byte[length - 40]; r.Seek(offset, SeekOrigin.Begin); stringBuffer = r.ReadBytes(40); data = r.ReadBytes(length - 40); name = Encoding.ASCII.GetString(stringBuffer).Trim(); var end = name.IndexOf("\0"); name = name.Substring(0, end); Metrics.ReportDataRead((int)r.Position - streamStart); return(true); } }
public static MultiComponentList Load(int index) { try { var r = _fileIndex.Seek(index, out int length, out int extra, out bool patched); if (r == null) { return(MultiComponentList.Empty); } return(new MultiComponentList(r, length / 12)); } catch { return(MultiComponentList.Empty); } }
public static Skill GetSkill(int index) { if (_list[index] != null) { return(_list[index]); } var r = _fileIndex.Seek(index, out int length, out int extra, out bool patched); if (r == null) { return(_list[index] = new Skill(SkillVars.NullV)); } return(_list[index] = LoadSkill(index, r)); }
private unsafe Texture2D readTexmapTexture(int index) { int length, extra; bool is_patched; BinaryFileReader reader = m_Index.Seek(index, out length, out extra, out is_patched); if (reader == null) { return(null); } if (reader.Stream.Length == 0) { Tracer.Warn("Requested texmap texture #{0} does not exist. Replacing with 'unused' graphic.", index); return(GetTexmapTexture(DEFAULT_TEXTURE)); } int metrics_dataread_start = (int)reader.Position; int textureSize = (extra == 0) ? 64 : 128; ushort[] pixelData = new ushort[textureSize * textureSize]; ushort[] fileData = reader.ReadUShorts(textureSize * textureSize); fixed(ushort *pData = pixelData) { ushort *pDataRef = pData; int count = 0; int max = textureSize * textureSize; while (count < max) { ushort color = (ushort)(fileData[count] | 0x8000); * pDataRef++ = color; count++; } } Texture2D texture = new Texture2D(m_Graphics, textureSize, textureSize, false, SurfaceFormat.Bgra5551); texture.SetData <ushort>(pixelData); Metrics.ReportDataRead((int)reader.Position - metrics_dataread_start); return(texture); }
public static Skill GetSkill(int index) { if (m_List[index] != null) { return(m_List[index]); } int length, extra; bool patched; BinaryFileReader reader = m_FileIndex.Seek(index, out length, out extra, out patched); if (reader == null) { return(m_List[index] = new Skill(SkillVars.NullV)); } return(m_List[index] = LoadSkill(index, reader)); }
public static MultiComponentList Load(int index) { try { int length, extra; bool patched; BinaryFileReader reader = m_FileIndex.Seek(index, out length, out extra, out patched); if (reader == null) { return(MultiComponentList.Empty); } return(new MultiComponentList(reader, length / 12)); } catch { return(MultiComponentList.Empty); } }
private unsafe Texture2DInfo ReadTexmapTexture(int index) { var r = _index.Seek(index, out int length, out int extra, out bool isPatched); if (r == null) { return(null); } if (r.Stream.Length == 0) { Utils.Warning($"Requested texmap texture #{index} does not exist. Replacing with 'unused' graphic."); return(GetTexmapTexture(DEFAULT_TEXTURE)); } var metrics_dataread_start = (int)r.Position; var textureSize = extra == 0 ? 64 : 128; var fileSize = textureSize * textureSize; var pixels = new byte[fileSize * 4]; var fileData = r.ReadUShorts(fileSize); fixed(byte *pData = pixels) { uint *pDataRef = (uint *)pData; int count = 0; int max = fileSize; while (count < max) { uint color = ConvertUtils.FromBGR555(fileData[count]); * pDataRef++ = color; count++; } } var texture = new Texture2DInfo(textureSize, textureSize, TextureFormat.BGRA32, false, pixels); Metrics.ReportDataRead((int)r.Position - metrics_dataread_start); return(texture); }
public unsafe Texture2D GetGumpXNA(int index, bool replaceMask080808 = false) { if (index < 0) { return(null); } if (m_TextureCache[index] == null) { int length, extra; bool patched; BinaryFileReader reader = m_FileIndex.Seek(index, out length, out extra, out patched); if (reader == null) { return(null); } int width = (extra >> 16) & 0xFFFF; int height = extra & 0xFFFF; int metrics_dataread_start = (int)reader.Position; int[] lookups = reader.ReadInts(height); ushort[] fileData = reader.ReadUShorts(length - (height * 2)); ushort[] pixels = new ushort[width * height]; fixed(ushort *line = &pixels[0]) { fixed(ushort *data = &fileData[0]) { for (int y = 0; y < height; ++y) { ushort *dataRef = data + (lookups[y] - height) * 2; ushort *cur = line + (y * width); ushort *end = cur + width; while (cur < end) { ushort color = *dataRef++; ushort *next = cur + *dataRef++; if (color == 0) { cur = next; } else { color |= 0x8000; while (cur < next) { *cur++ = color; } } } } } } Metrics.ReportDataRead(length); if (replaceMask080808) { for (int i = 0; i < pixels.Length; i++) { if (pixels[i] == 0x8421) { pixels[i] = 0xFC1F; } } } Texture2D texture = new Texture2D(m_graphicsDevice, width, height, false, SurfaceFormat.Bgra5551); texture.SetData(pixels); m_TextureCache[index] = texture; } return(m_TextureCache[index]); }
public unsafe Texture2DInfo GetGumpTexture(int textureID, bool replaceMask080808 = false) { if (textureID < 0) { return(null); } if (_textureCache[textureID] == null) { var reader = _fileIndex.Seek(textureID, out int length, out int extra, out bool patched); if (reader == null) { return(null); } var width = (extra >> 16) & 0xFFFF; var height = extra & 0xFFFF; if (width == 0 || height == 0) { return(null); } var shortsToRead = length - (height * 2); if (reader.Stream.Length - reader.Position < (shortsToRead * 2)) { Utils.Error($"Could not read gump {textureID:X4}: not enough data. Gump texture file truncated?"); return(null); } var lookups = reader.ReadInts(height); var metrics_dataread_start = (int)reader.Position; var fileData = reader.ReadUShorts(shortsToRead); var pixels = new byte[width * height * 4]; fixed(byte *line = &pixels[0]) fixed(ushort *data = &fileData[0]) for (int y = 0; y < height; ++y) { ushort *dataRef = data + (lookups[y] - height) * 2; uint * cur = (uint *)line + (y * width); uint * end = cur + width; while (cur < end) { uint color = ConvertUtils.FromBGR555(*dataRef++, false); uint *next = cur + *dataRef++; if (color == 0) { cur = next; } else { color |= 0xFF000000; while (cur < next) { *cur++ = color; } } } } Metrics.ReportDataRead(length); //if (replaceMask080808) // for (var i = 0; i < pixels.Length; i++) // if (pixels[i] == 0x8421) // pixels[i] = 0xFC1F; var texture = new Texture2DInfo(width, height, TextureFormat.BGRA32, false, pixels); //: SurfaceFormat.Bgra5551 _textureCache[textureID] = texture; _picking.Set(textureID, width, height, pixels); } return(_textureCache[textureID]); }
public unsafe Texture2D GetGumpTexture(int textureID, bool replaceMask080808 = false) { if (textureID < 0) { return(null); } if (m_TextureCache[textureID] == null) { int length, extra; bool patched; BinaryFileReader reader = m_FileIndex.Seek(textureID, out length, out extra, out patched); if (reader == null) { return(null); } int width = (extra >> 16) & 0xFFFF; int height = extra & 0xFFFF; if (width == 0 || height == 0) { return(null); } int shortsToRead = length - (height * 2); if (reader.Stream.Length - reader.Position < (shortsToRead * 2)) { Tracer.Error($"Could not read gump {textureID:X4}: not enough data. Gump texture file truncated?"); return(null); } int[] lookups = reader.ReadInts(height); int metrics_dataread_start = (int)reader.Position; ushort[] fileData = reader.ReadUShorts(shortsToRead); ushort[] pixels = new ushort[width * height]; fixed(ushort *line = &pixels[0]) { fixed(ushort *data = &fileData[0]) { for (int y = 0; y < height; ++y) { ushort *dataRef = data + (lookups[y] - height) * 2; ushort *cur = line + (y * width); ushort *end = cur + width; while (cur < end) { ushort color = *dataRef++; ushort *next = cur + *dataRef++; if (color == 0) { cur = next; } else { color |= 0x8000; while (cur < next) { *cur++ = color; } } } } } } Metrics.ReportDataRead(length); if (replaceMask080808) { for (int i = 0; i < pixels.Length; i++) { if (pixels[i] == 0x8421) { pixels[i] = 0xFC1F; } } } Texture2D texture = new Texture2D(m_graphicsDevice, width, height, false, SurfaceFormat.Bgra5551); texture.SetData(pixels); m_TextureCache[textureID] = texture; m_Picking.Set(textureID, width, height, pixels); } return(m_TextureCache[textureID]); }