public EffectDataResource() { // From http://wpdev.sourceforge.net/docs/guide/node167.html: // There are 2048 blocks, 8 entries per block, 68 bytes per entry. // Thanks to Krrios for figuring out the blocksizes. // Each block has an 4 byte header which is currently unknown. The // entries correspond with the Static ID. You can lookup an entry // for a given static with this formula: // Offset = (id>>3)*548+(id&15)*68+4; // Here is the record format for each entry: // byte[64] Frames // byte Unknown // byte Number of Frames Used // byte Frame Interval // byte Start Interval _animData = new EffectData[Count][]; using (var s = UltimaFileManager.GetFile("animdata.mul")) { var r = new BinaryReader(s); for (var i = 0; i < Count; i++) { var data = new EffectData[8]; var header = r.ReadInt32(); // unknown value. for (var j = 0; j < 8; j++) { data[j] = new EffectData(r); } _animData[i] = data; } } }
void LoadCliloc(string path) { path = UltimaFileManager.GetFilePath(path); if (path == null) { return; } byte[] buffer; using (var r = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { buffer = r.ReadBytes((int)r.BaseStream.Length); Metrics.ReportDataRead((int)r.BaseStream.Position); } var pos = 6; var count = buffer.Length; while (pos < count) { var number = BitConverter.ToInt32(buffer, pos); var length = BitConverter.ToInt16(buffer, pos + 5); var text = Encoding.UTF8.GetString(buffer, pos + 7, length); pos += length + 7; _table[number] = text; // auto replace with updates. } }
/// <summary> /// Creates a reference to an index file. (Ex: anim.idx) /// </summary> /// <param name="idxFile">Name of .idx file in UO base directory.</param> /// <param name="mulFile">Name of .mul file that this index file provides an index for.</param> /// <param name="length">Number of indexes in this index file.</param> /// <param name="patch_file">Index to patch data in Versioning.</param> public MulFileIndex(string idxFile, string mulFile, int length, int patch_file) : base(mulFile) { IndexPath = UltimaFileManager.GetFilePath(idxFile); Length = length; patchFile = patch_file; Open(); }
void LoadFonts() { // load Ascii fonts using (var r = new BinaryReader(new FileStream(UltimaFileManager.GetFilePath("fonts.mul"), FileMode.Open, FileAccess.Read))) for (var i = 0; i < AsciiFontCount; i++) { _asciiFonts[i] = new FontAscii(); _asciiFonts[i].Initialize(r); _asciiFonts[i].HasBuiltInOutline = true; } // load Unicode fonts var maxHeight = 0; // because all unifonts are designed to be used together, they must all share a single maxheight value. for (var i = 0; i < UniFontCount; i++) { var path = UltimaFileManager.GetFilePath($"unifont{(i == 0 ? string.Empty : i.ToString())}.mul"); if (path != null) { _unicodeFonts[i] = new FontUnicode(); _unicodeFonts[i].Initialize(new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read))); if (_unicodeFonts[i].Height > maxHeight) { maxHeight = _unicodeFonts[i].Height; } } } for (var i = 0; i < UniFontCount; i++) { if (_unicodeFonts[i] == null) { continue; } _unicodeFonts[i].Height = maxHeight; } }
static void SetupFiles() { try { _index = ClientVersion.InstallationIsUopFormat ? UltimaFileManager.CreateFileIndex("soundLegacyMUL.uop", 0xFFF, false, ".dat") : UltimaFileManager.CreateFileIndex("soundidx.mul", "sound.mul", 0x1000, -1); // new BinaryReader(new FileStream(FileManager.GetFilePath("soundidx.mul"), FileMode.Open)); _filesPrepared = true; } catch { _filesPrepared = false; return; } var reg = new Regex(@"(\d{1,3}) \x7B(\d{1,3})\x7D (\d{1,3})", RegexOptions.Compiled); _translations = new Dictionary <int, int>(); string line; using (var r = new StreamReader(UltimaFileManager.GetFilePath("Sound.def"))) while ((line = r.ReadLine()) != null) { if (((line = line.Trim()).Length != 0) && !line.StartsWith("#")) { var match = reg.Match(line); if (match.Success) { _translations.Add(int.Parse(match.Groups[1].Value), int.Parse(match.Groups[2].Value)); } } } }
public ArtMulResource(object graphics) { _fileIndex = ClientVersion.InstallationIsUopFormat ? UltimaFileManager.CreateFileIndex("artLegacyMUL.uop", 0x10000, false, ".tga") : UltimaFileManager.CreateFileIndex("artidx.mul", "art.mul", 0x10000, -1); // !!! must find patch file reference for artdata. _staticPicking = new PixelPicking(); _landTileTextureCache = new Texture2DInfo[0x10000]; _staticTileTextureCache = new Texture2DInfo[0x10000]; }
static uint[] getTextureData() { var r = new BinaryReader(UltimaFileManager.GetFile("hues.mul")); var currentHue = 0; var currentIndex = 0; var data = new uint[_hueTextureWidth * _hueTextureHeight * 2]; Metrics.ReportDataRead((int)r.BaseStream.Length); currentIndex += 32; while (r.BaseStream.Position < r.BaseStream.Length) { r.ReadInt32(); //Header for (var entry = 0; entry < 8; entry++) { for (var i = 0; i < 32; i++) { const float multiplier = 0xff / 0x1f; var color = r.ReadUInt16(); if (i == 31) { _hues[currentHue] = (ushort)color; } data[currentIndex++] = 0xFF000000 + ( ((uint)(((color >> 10) & 0x1F) * multiplier)) | ((uint)(((color >> 5) & 0x1F) * multiplier) << 8) | ((uint)((color & 0x1F) * multiplier) << 16) ); } r.ReadInt16(); //table start r.ReadInt16(); //table end r.ReadBytes(20); //name currentHue++; } } r.Close(); var webSafeHuesBegin = _hueTextureHeight * 2 - 216; for (var b = 0; b < 6; b++) { for (var g = 0; g < 6; g++) { for (var r_ = 0; r_ < 6; r_++) { data[(webSafeHuesBegin + r_ + g * 6 + b * 36) * 32 + 31] = (uint)( 0xff000000 + b * 0x00330000 + g * 0x00003300 + r_ * 0x00000033); } } } return(data); }
bool LoadStaticsStream(uint index, out FileStream dataStream, out BinaryReader indexReader) { dataStream = null; indexReader = null; var pathData = UltimaFileManager.GetFilePath($"statics{index}.mul"); var pathIndex = UltimaFileManager.GetFilePath($"staidx{index}.mul"); if (File.Exists(pathData) && File.Exists(pathIndex)) { dataStream = new FileStream(pathData, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); indexReader = new BinaryReader(new FileStream(pathIndex, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); return(true); } return(false); }
static unsafe SkillCategory[] LoadCategories() { var list = new SkillCategory[0]; var grpPath = UltimaFileManager.GetFilePath("skillgrp.mul"); if (grpPath == null) { return(new SkillCategory[0]); } else { var toAdd = new List <SkillCategory>(); using (var stream = new FileStream(grpPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { var r = new BinaryReader(stream); var start = new byte[4]; //File Start Offset r.Read(start, 0, 4); var index = 0; long x = stream.Length, y = 0; while (y < x) //Position < Length { var name = ParseName(stream); var fileIndex = stream.Position - name.Length; if (name.Length > 0) { toAdd.Add(new SkillCategory(new SkillCategoryData(fileIndex, index, name))); y = stream.Position; ++index; } } } if (toAdd.Count > 0) { list = new SkillCategory[toAdd.Count]; for (var i = 0; i < toAdd.Count; i++) { list[i] = toAdd[i]; } toAdd.Clear(); } } return(list); }
unsafe int LoadLandPatches(TileMatrixData tileMatrix, string landPath, string indexPath) { _landPatchPtrs = new Dictionary <uint, LandPatchData>(); if (ClientVersion.InstallationIsUopFormat) { return(0); } _landPatchStream = UltimaFileManager.GetFile(landPath); if (_landPatchStream == null) { return(0); } using (var fsIndex = UltimaFileManager.GetFile(indexPath)) { var indexReader = new BinaryReader(fsIndex); var count = (int)(indexReader.BaseStream.Length / 4); var ptr = 0U; for (var i = 0U; i < count; ++i) { var blockId = indexReader.ReadUInt32(); var x = blockId / tileMatrix.ChunkHeight; var y = blockId % tileMatrix.ChunkHeight; var key = MakeChunkKey(x, y); ptr += 4; if (_landPatchPtrs.ContainsKey(key)) { var current = _landPatchPtrs[key]; while (current.Next != null) { current = current.Next; } current.Next = new LandPatchData(i, ptr); } else { _landPatchPtrs.Add(key, new LandPatchData(i, ptr)); } ptr += 192; } indexReader.Close(); return(count); } }
unsafe int LoadStaticPatches(TileMatrixData tileMatrix, string dataPath, string indexPath, string lookupPath) { _staticPatchPtrs = new Dictionary <uint, StaticPatchData>(); _staticPatchStream = UltimaFileManager.GetFile(dataPath); if (_staticPatchStream == null) { return(0); } using (var fsIndex = UltimaFileManager.GetFile(indexPath)) using (var fsLookup = UltimaFileManager.GetFile(lookupPath)) { var indexReader = new BinaryReader(fsIndex); var lookupReader = new BinaryReader(fsLookup); var count = (int)(indexReader.BaseStream.Length / 4); for (var i = 0U; i < count; ++i) { var blockID = indexReader.ReadUInt32(); var blockX = blockID / tileMatrix.ChunkHeight; var blockY = blockID % tileMatrix.ChunkHeight; var key = MakeChunkKey(blockX, blockY); var offset = lookupReader.ReadUInt32(); var length = lookupReader.ReadInt32(); lookupReader.ReadInt32(); if (_staticPatchPtrs.ContainsKey(key)) { var current = _staticPatchPtrs[key]; while (current.Next != null) { current = current.Next; } current.Next = new StaticPatchData(i, offset, length); } else { _staticPatchPtrs.Add(key, new StaticPatchData(i, offset, length)); } } indexReader.Close(); lookupReader.Close(); return(count); } }
bool LoadMapStream(uint index, out FileStream mapDataStream, out UOPIndex uopIndex) { mapDataStream = null; uopIndex = null; var path = UltimaFileManager.GetFilePath($"map{index}.mul"); if (File.Exists(path)) { mapDataStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); return(true); } path = UltimaFileManager.GetFilePath($"map{index}LegacyMUL.uop"); if (File.Exists(path)) { mapDataStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); uopIndex = new UOPIndex(_mapDataStream); return(true); } return(false); }
static List <Dictionary <int, SpeechEntry> > LoadSpeechFile() { var tables = new List <Dictionary <int, SpeechEntry> >(); var lastIndex = -1; Dictionary <int, SpeechEntry> table = null; var path = UltimaFileManager.GetFilePath("speech.mul"); using (var r = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { while (r.PeekChar() >= 0) { var index = (r.ReadByte() << 8) | r.ReadByte(); var length = (r.ReadByte() << 8) | r.ReadByte(); var text = Encoding.UTF8.GetString(r.ReadBytes(length)).Trim(); if (text.Length == 0) { continue; } if (table == null || lastIndex > index) { if (index == 0 && text == "*withdraw*") { tables.Insert(0, table = new Dictionary <int, SpeechEntry>()); } else { tables.Add(table = new Dictionary <int, SpeechEntry>()); } } lastIndex = index; table.TryGetValue(index, out SpeechEntry entry); if (entry == null) { table[index] = entry = new SpeechEntry(index); } entry.Strings.Add(text); entry.Regex.Add(new Regex(text.Replace("*", @".*"), RegexOptions.IgnoreCase)); } return(tables); } }
static BodyDef() { _entries = new Dictionary <int, BodyTableEntry>(); var filePath = UltimaFileManager.GetFilePath("body.def"); if (filePath == null) { return; } var def = new StreamReader(filePath); string line; var totalDataRead = 0; while ((line = def.ReadLine()) != null) { totalDataRead += line.Length; if ((line = line.Trim()).Length == 0 || line.StartsWith("#")) { continue; } try { var index1 = line.IndexOf("{"); var index2 = line.IndexOf("}"); var origBody = line.Substring(0, index1); var newBody = line.Substring(index1 + 1, index2 - index1 - 1); var newHue = line.Substring(index2 + 1); var indexOf = newBody.IndexOf(','); if (indexOf > -1) { newBody = newBody.Substring(0, indexOf).Trim(); } var iParam1 = Convert.ToInt32(origBody); var iParam2 = Convert.ToInt32(newBody); var iParam3 = Convert.ToInt32(newHue); _entries[iParam1] = new BodyTableEntry(iParam1, iParam2, iParam3); } catch { } } Metrics.ReportDataRead(totalDataRead); }
static MobtypeData() { var path = UltimaFileManager.GetFilePath("mobtypes.txt"); { var r = new StreamReader(path); while (!r.EndOfStream) { var line = r.ReadLine(); Metrics.ReportDataRead(line.Length); if ((line != string.Empty) && (line.Substring(0, 1) != "#")) { var data = line.Split('\t'); var bodyId = int.Parse(data[0]); if (_entries.ContainsKey(bodyId)) { _entries.Remove(bodyId); } _entries.Add(bodyId, new MobtypeEntry(data[1], data[2])); } } } }
static VerData() { var path = UltimaFileManager.GetFilePath("verdata.mul"); if (!File.Exists(path)) { Patches = new FileIndexEntry5D[0]; Stream = Stream.Null; } else { Stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); var bin = new BinaryReader(Stream); Patches = new FileIndexEntry5D[bin.ReadInt32()]; for (var i = 0; i < Patches.Length; ++i) { Patches[i].file = bin.ReadInt32(); Patches[i].index = bin.ReadInt32(); Patches[i].lookup = bin.ReadInt32(); Patches[i].length = bin.ReadInt32(); Patches[i].extra = bin.ReadInt32(); } } }
static RadarColorData() { using (var index = new FileStream(UltimaFileManager.GetFilePath("Radarcol.mul"), FileMode.Open, FileAccess.Read, FileShare.Read)) { var r = new BinaryReader(index); // Prior to 7.0.7.1, all clients have 0x10000 colors. Newer clients have fewer colors. var colorCount = (int)index.Length / 2; for (var i = 0; i < colorCount; i++) { var c = (uint)r.ReadUInt16(); Colors[i] = 0xFF000000 | ( ((((c >> 10) & 0x1F) * multiplier)) | ((((c >> 5) & 0x1F) * multiplier) << 8) | (((c & 0x1F) * multiplier) << 16) ); } // fill the remainder of the color table with non-transparent magenta. for (var i = colorCount; i < Colors.Length; i++) { Colors[i] = 0xFFFF00FF; } Metrics.ReportDataRead((int)r.BaseStream.Position); } }
static BodyConverter() { var path = UltimaFileManager.GetFilePath("bodyconv.def"); if (path == null) { return; } ArrayList list1 = new ArrayList(), list2 = new ArrayList(), list3 = new ArrayList(), list4 = new ArrayList(); int max1 = 0, max2 = 0, max3 = 0, max4 = 0; using (var ip = new StreamReader(path)) { string line; var totalDataRead = 0; while ((line = ip.ReadLine()) != null) { totalDataRead += line.Length; if ((line = line.Trim()).Length == 0 || line.StartsWith("#") || line.StartsWith("\"#")) { continue; } // string[] split = line.Split('\t'); var split = Regex.Split(line, @"\t|\s+", RegexOptions.IgnoreCase); var original = System.Convert.ToInt32(split[0]); var anim2 = System.Convert.ToInt32(split[1]); if (split.Length < 3 || !int.TryParse(split[2], out int anim3)) { anim3 = -1; } if (split.Length < 4 || !int.TryParse(split[3], out int anim4)) { anim4 = -1; } if (split.Length < 5 || !int.TryParse(split[4], out int anim5)) { anim5 = -1; } if (anim2 != -1) { if (anim2 == 68) { anim2 = 122; } if (original > max1) { max1 = original; } list1.Add(original); list1.Add(anim2); } if (anim3 != -1) { if (original > max2) { max2 = original; } list2.Add(original); list2.Add(anim3); } if (anim4 != -1) { if (original > max3) { max3 = original; } list3.Add(original); list3.Add(anim4); } if (anim5 != -1) { if (original > max4) { max4 = original; } list4.Add(original); list4.Add(anim5); } } Metrics.ReportDataRead(totalDataRead); } _table1 = new int[max1 + 1]; _table2 = new int[max2 + 1]; _table3 = new int[max3 + 1]; _table4 = new int[max4 + 1]; for (var i = 0; i < _table1.Length; ++i) { _table1[i] = -1; } for (var i = 0; i < list1.Count; i += 2) { _table1[(int)list1[i]] = (int)list1[i + 1]; } for (var i = 0; i < _table2.Length; ++i) { _table2[i] = -1; } for (var i = 0; i < list2.Count; i += 2) { _table2[(int)list2[i]] = (int)list2[i + 1]; } for (var i = 0; i < _table3.Length; ++i) { _table3[i] = -1; } for (var i = 0; i < list3.Count; i += 2) { _table3[(int)list3[i]] = (int)list3[i + 1]; } for (var i = 0; i < _table4.Length; ++i) { _table4[i] = -1; } for (var i = 0; i < list4.Count; i += 2) { _table4[(int)list4[i]] = (int)list4[i + 1]; } }
// Issue 5 - End static TileData() { using (var s = UltimaFileManager.GetFile("tiledata.mul")) { var r = new BinaryReader(s); LandData landData; ItemData itemData; if (s.Length == 3188736) // 7.0.9.0 { LandData = new LandData[0x4000]; for (var i = 0; i < 0x4000; ++i) { landData = new LandData(); if (i == 1 || (i > 0 && (i & 0x1F) == 0)) { r.ReadInt32(); } var flags = (TileFlag)r.ReadInt64(); var textureID = r.ReadInt16(); landData.Name = Encoding.ASCII.GetString(r.ReadBytes(20)); landData.Name = landData.Name.Trim('\0'); //r.BaseStream.Seek(20, SeekOrigin.Current); landData.Flags = flags; landData.TextureID = textureID; LandData[i] = landData; } ItemData = new ItemData[0x10000]; for (var i = 0; i < 0x10000; ++i) { itemData = new ItemData { ItemId = i }; if ((i & 0x1F) == 0) { r.ReadInt32(); } itemData.Flags = (TileFlag)r.ReadInt64(); itemData.Weight = r.ReadByte(); itemData.Quality = r.ReadByte(); itemData.Unknown1 = r.ReadByte(); itemData.Unknown2 = r.ReadByte(); itemData.Unknown3 = r.ReadByte(); itemData.Quantity = r.ReadByte(); itemData.AnimId = r.ReadInt16(); r.BaseStream.Seek(2, SeekOrigin.Current); // hue? itemData.Unknown4 = r.ReadByte(); itemData.Value = r.ReadByte(); itemData.Height = r.ReadByte(); itemData.Name = Encoding.ASCII.GetString(r.ReadBytes(20)); itemData.Name = itemData.Name.Trim('\0'); // r.BaseStream.Seek(20, SeekOrigin.Current); if (i > 1005 && i < 7640) { itemData.IsStairs = !(Array.BinarySearch(_stairsID, i) < 0); } // Issue 5 - End ItemData[i] = itemData; } } else { LandData = new LandData[0x4000]; for (var i = 0; i < 0x4000; ++i) { landData = new LandData(); if ((i & 0x1F) == 0) { r.ReadInt32(); } var flags = (TileFlag)r.ReadInt32(); var textureID = r.ReadInt16(); landData.Name = Encoding.ASCII.GetString(r.ReadBytes(20)); landData.Name = landData.Name.Trim('\0'); //r.BaseStream.Seek(20, SeekOrigin.Current); landData.Flags = flags; landData.TextureID = textureID; LandData[i] = landData; } if (s.Length == 1644544) // 7.0.0.0 { ItemData = new ItemData[0x8000]; for (var i = 0; i < 0x8000; ++i) { itemData = new ItemData { ItemId = i }; if ((i & 0x1F) == 0) { r.ReadInt32(); } itemData.Flags = (TileFlag)r.ReadInt32(); itemData.Weight = r.ReadByte(); itemData.Quality = r.ReadByte(); itemData.Unknown1 = r.ReadByte(); itemData.Unknown2 = r.ReadByte(); itemData.Unknown3 = r.ReadByte(); itemData.Quantity = r.ReadByte(); itemData.AnimId = r.ReadInt16(); r.BaseStream.Seek(2, SeekOrigin.Current); // hue? itemData.Unknown4 = r.ReadByte(); itemData.Value = r.ReadByte(); itemData.Height = r.ReadByte(); itemData.Name = Encoding.ASCII.GetString(r.ReadBytes(20)); itemData.Name = itemData.Name.Trim('\0'); // r.BaseStream.Seek(20, SeekOrigin.Current); if (i > 1005 && i < 7640) { itemData.IsStairs = !(Array.BinarySearch(_stairsID, i) < 0); } // Issue 5 - End ItemData[i] = itemData; } } else { ItemData = new ItemData[0x4000]; for (var i = 0; i < 0x4000; ++i) { itemData = new ItemData { ItemId = i }; if ((i & 0x1F) == 0) { r.ReadInt32(); } itemData.Flags = (TileFlag)r.ReadInt32(); itemData.Weight = r.ReadByte(); itemData.Quality = r.ReadByte(); itemData.Unknown1 = r.ReadByte(); itemData.Unknown2 = r.ReadByte(); itemData.Unknown3 = r.ReadByte(); itemData.Quantity = r.ReadByte(); itemData.AnimId = r.ReadInt16(); r.BaseStream.Seek(2, SeekOrigin.Current); // hue? itemData.Unknown4 = r.ReadByte(); itemData.Value = r.ReadByte(); itemData.Height = r.ReadByte(); itemData.Name = Encoding.ASCII.GetString(r.ReadBytes(20)); itemData.Name = itemData.Name.Trim('\0'); // r.BaseStream.Seek(20, SeekOrigin.Current); if (i > 1005 && i < 7640) { itemData.IsStairs = !(Array.BinarySearch(_stairsID, i) < 0); } // Issue 5 - End ItemData[i] = itemData; } } } Metrics.ReportDataRead((int)r.BaseStream.Position); } }