public static void Initialize() { var path = Files.GetFilePath("skillgrp.mul"); List = new List <SkillGroup>(); SkillList = new List <int>(); if (path != null) { using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var bin = new BinaryReader(fs)) { var start = 4; var strlen = 17; var count = bin.ReadInt32(); if (count == -1) { unicode = true; count = bin.ReadInt32(); start *= 2; strlen *= 2; } List.Add(new SkillGroup("Misc")); for (var i = 0; i < count - 1; ++i) { int strbuild; fs.Seek((start + (i * strlen)), SeekOrigin.Begin); var builder2 = new StringBuilder(17); if (unicode) { while ((strbuild = bin.ReadInt16()) != 0) { builder2.Append((char)strbuild); } } else { while ((strbuild = bin.ReadByte()) != 0) { builder2.Append((char)strbuild); } } List.Add(new SkillGroup(builder2.ToString())); } fs.Seek((start + ((count - 1) * strlen)), SeekOrigin.Begin); try { while (bin.BaseStream.Length != bin.BaseStream.Position) { SkillList.Add(bin.ReadInt32()); } } catch // just for safety { } } } } }
/// <summary> /// Reads animdata.mul and fills <see cref="AnimData"/> /// </summary> public static void Initialize() { AnimData = new Dictionary <int, AnimdataEntry>(); string path = Files.GetFilePath("animdata.mul"); if (path == null) { return; } using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var bin = new BinaryReader(fs)) { unsafe { int id = 0; int h = 0; _header = new int[bin.BaseStream.Length / (4 + (8 * (64 + 4)))]; while (h < _header.Length) { _header[h++] = bin.ReadInt32(); // chunk header // Read 8 tiles byte[] buffer = bin.ReadBytes(544); fixed(byte *buf = buffer) { byte *data = buf; for (int i = 0; i < 8; ++i, ++id) { sbyte[] fdata = new sbyte[64]; for (int j = 0; j < 64; ++j) { fdata[j] = (sbyte)*data++; } byte unk = *data++; byte fcount = *data++; byte finter = *data++; byte fstart = *data++; if (fcount > 0) { AnimData[id] = new AnimdataEntry(fdata, unk, fcount, finter, fstart); } } } } var remaining = (int)(bin.BaseStream.Length - bin.BaseStream.Position); if (remaining > 0) { _unknown = bin.ReadBytes(remaining); } } } } }
/// <summary> /// Reads Sounds and def /// </summary> public static void Initialize() { m_Cache = new UOSound[0xFFF]; m_Removed = new bool[0xFFF]; m_FileIndex = new FileIndex("soundidx.mul", "sound.mul", 0xFFF, 8); Regex reg = new Regex(@"(\d{1,4}) \x7B(\d{1,4})\x7D (\d{1,3})", RegexOptions.Compiled); m_Translations = new Dictionary <int, int>(); string line; string path = Files.GetFilePath("Sound.def"); if (path == null) { return; } using (StreamReader reader = new StreamReader(path)) { while ((line = reader.ReadLine()) != null) { if (((line = line.Trim()).Length != 0) && !line.StartsWith("#")) { Match match = reg.Match(line); if (match.Success) { m_Translations.Add(int.Parse(match.Groups[1].Value), int.Parse(match.Groups[2].Value)); } } } } }
/// <summary> /// Initialize <see cref="StringList"/> of Language /// </summary> /// <param name="language"></param> public StringList(string language) { Language = language; LoadEntry(Files.GetFilePath(String.Format("cliloc.{0}", language))); LoadEntry(Files.GetFilePath(String.Format("Cliloc.{0}", language))); }
/// <summary> /// Compares MD5 hash from given mul file with hash in responsible hash-file /// </summary> /// <param name="what"></param> /// <returns></returns> public static bool CompareHashFile(string what, string path) { string FileName = Path.Combine(path, $"UOFiddler{what}.hash"); if (File.Exists(FileName)) { try { using (BinaryReader bin = new BinaryReader(new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read))) { int length = bin.ReadInt32(); byte[] buffer = new byte[length]; bin.Read(buffer, 0, length); string hashold = BitConverter.ToString(buffer).Replace("-", "").ToLower(); return(Files.CompareMD5(Files.GetFilePath($"{what}.mul"), hashold)); } } catch { return(false); } } return(false); }
/// <summary> /// Reads Sounds and def /// </summary> public static void Initialize() { _cache = new UOSound[0xFFF]; _removed = new bool[0xFFF]; _fileIndex = new FileIndex("soundidx.mul", "sound.mul", "soundLegacyMUL.uop", 0xFFF, 8, ".dat", -1, false); var reg = new Regex(@"(\d{1,4}) \x7B(\d{1,4})\x7D (\d{1,3})", RegexOptions.Compiled); _translations = new Dictionary <int, int>(); string path = Files.GetFilePath("Sound.def"); if (path == null) { return; } using (var reader = new StreamReader(path)) { string line; while ((line = reader.ReadLine()) != null) { if ((line = line.Trim()).Length == 0 || line.StartsWith("#")) { continue; } Match match = reg.Match(line); if (match.Success) { _translations.Add(int.Parse(match.Groups[1].Value), int.Parse(match.Groups[2].Value)); } } } }
/// <summary> /// Checks if map1.mul exists and sets <see cref="Ultima.Map"/> /// </summary> public static void CheckForNewMapSize() { if (Files.GetFilePath("map1.mul") != null) { if (Ultima.Map.Trammel.Width == 7168) { Ultima.Map.Trammel = new Ultima.Map(1, 1, 7168, 4096); } else { Ultima.Map.Trammel = new Ultima.Map(1, 1, 6144, 4096); } } else { if (Ultima.Map.Trammel.Width == 7168) { Ultima.Map.Trammel = new Ultima.Map(0, 1, 7168, 4096); } else { Ultima.Map.Trammel = new Ultima.Map(0, 1, 6144, 4096); } } }
/// <summary> /// Compares MD5 hash from given mul file with hash in responsible hash-file /// </summary> /// <param name="what"></param> /// <returns></returns> public static bool CompareHashFile(string what) { string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; string FileName = Path.Combine(path, String.Format("UOFiddler{0}.hash", what)); if (File.Exists(FileName)) { try { using (BinaryReader bin = new BinaryReader(new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read))) { int length = bin.ReadInt32(); byte[] buffer = new byte[length]; bin.Read(buffer, 0, length); string hashold = BitConverter.ToString(buffer).Replace("-", "").ToLower(); return(Files.CompareMD5(Files.GetFilePath(String.Format("{0}.mul", what)), hashold)); } } catch { return(false); } } return(false); }
public static void Initialize() { path = Files.GetFilePath("verdata.mul"); if (path == null) { Patches = new Entry5D[0]; Stream = Stream.Null; } else { using (Stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader bin = new BinaryReader(Stream)) { Patches = new Entry5D[bin.ReadInt32()]; for (int 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(); } } } Stream.Close(); } }
/// <summary> /// ReReads Art.mul /// </summary> public static void Reload() { var idxFileInfo = new FileInfo(Files.GetFilePath("ArtIdx.mul")); var mulFileInfo = new FileInfo(Files.GetFilePath("Art.mul")); int entries = idxFileInfo.Exists ? (int)(idxFileInfo.Length / 12) : 0; IsUOHS = IsUOSA = IsPreAlpha = false; if (entries >= 0x13FDC) { IsUOHS = true; } else if (entries == 0xC000) { IsUOSA = true; } else if (entries == 0x10000) { IsPreAlpha = true; } // Нашлись умники, что раздувают артмулы до размеров альфы, так что // пришлось сделать дополнительную проверку, это не совсем полит коректно // но будем считать что у пре-альфа клиента длина art.mul не более 40 Mib if (IsPreAlpha && mulFileInfo.Length > 0x2800000) { IsPreAlpha = false; } m_FileIndex = new FileIndex("Artidx.mul", "Art.mul", entries, 4); m_Cache = new Bitmap[entries]; m_Removed = new bool[entries]; (m_patched ?? (m_patched = new Hashtable())).Clear(); Modified = false; }
/// <summary> /// Reads animdata.mul and fills <see cref="AnimData"/> /// </summary> public static void Initialize() { AnimData = new Hashtable(); var path = Files.GetFilePath("animdata.mul"); if (path != null) { using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var bin = new BinaryReader(fs)) { unsafe { var id = 0; var h = 0; byte unk; byte fcount; byte finter; byte fstart; sbyte[] fdata; m_Header = new int[bin.BaseStream.Length / (4 + 8 * (64 + 4))]; while (h < m_Header.Length /*bin.BaseStream.Length != bin.BaseStream.Position*/) { m_Header[h++] = bin.ReadInt32(); // chunk header // Read 8 tiles var buffer = bin.ReadBytes(544); fixed(byte *buf = buffer) { var data = buf; for (var i = 0; i < 8; ++i, ++id) { fdata = new sbyte[64]; for (var j = 0; j < 64; ++j) { fdata[j] = (sbyte)*data++; } unk = *data++; fcount = *data++; finter = *data++; fstart = *data++; if (fcount > 0) { AnimData[id] = new Data(fdata, unk, fcount, finter, fstart); } } } } var remaining = (int)(bin.BaseStream.Length - bin.BaseStream.Position); if (remaining > 0) { m_Unknown = bin.ReadBytes(remaining); } } } } } }
/// <summary> /// Returns Bitmap /// </summary> /// <returns></returns> public static unsafe Bitmap GetMultiMap() { string path = Files.GetFilePath("Multimap.rle"); if (path == null) { return(null); } using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var bin = new BinaryReader(fs)) { int x = 0; int width = bin.ReadInt32(); int height = bin.ReadInt32(); var multimap = new Bitmap(width, height, PixelFormat.Format16bppArgb1555); BitmapData bd = multimap.LockBits( new Rectangle(0, 0, multimap.Width, multimap.Height), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555); var line = (ushort *)bd.Scan0; int delta = bd.Stride >> 1; ushort *cur = line; var len = (int)(bin.BaseStream.Length - bin.BaseStream.Position); if (_streamBuffer == null || _streamBuffer.Length < len) { _streamBuffer = new byte[len]; } bin.Read(_streamBuffer, 0, len); int j = 0; while (j != len) { byte pixel = _streamBuffer[j++]; int count = (pixel & 0x7f); // black or white color ushort c = (pixel & 0x80) != 0 ? (ushort)0x8000 : (ushort)0xffff; int i; for (i = 0; i < count; ++i) { cur[x++] = c; if (x < width) { continue; } cur += delta; x = 0; } } multimap.UnlockBits(bd); return(multimap); } }
/// <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 (FileStream 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]; unsafe { int structsize = Marshal.SizeOf(typeof(HueDataMul)); byte[] 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) { IntPtr 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) { IntPtr ptr = new IntPtr((long)gc.AddrOfPinnedObject() + currpos); currpos += structsize; HueDataMul 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); } }
/// <summary> /// Reads animdata.mul and fills <see cref="AnimData"/> /// </summary> public static void Initialize() { AnimData = new Hashtable(); string path = Files.GetFilePath("animdata.mul"); if (path != null) { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader bin = new BinaryReader(fs)) { unsafe { int id = 0; int h = 0; byte unk; byte fcount; byte finter; byte fstart; sbyte[] fdata; int length = 4 + 8 * (64 + 4); m_Header = new int[bin.BaseStream.Length / length]; length *= m_Header.Length; while (bin.BaseStream.Position != length) { m_Header[h++] = bin.ReadInt32(); // chunk header // Read 8 tiles byte[] buffer = bin.ReadBytes(544); fixed(byte *buf = buffer) { byte *data = buf; for (int i = 0; i < 8; ++i, ++id) { fdata = new sbyte[64]; for (int j = 0; j < 64; ++j) { fdata[j] = (sbyte)*data++; } unk = *data++; fcount = *data++; finter = *data++; fstart = *data++; if (fcount > 0) { AnimData[id] = new Data(fdata, unk, fcount, finter, fstart); } } } } m_Trash = bin.ReadBytes((int)(bin.BaseStream.Length - bin.BaseStream.Position)); } } } } }
/// <summary> /// Returns Bitmap /// </summary> /// <returns></returns> public static unsafe Bitmap GetMultiMap() { string path = Files.GetFilePath("Multimap.rle"); if (path != null) { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader bin = new BinaryReader(fs)) { int width, height; byte pixel; int count; int x, i; x = 0; ushort c = 0; width = bin.ReadInt32(); height = bin.ReadInt32(); Bitmap multimap = new Bitmap(width, height, PixelFormat.Format16bppArgb1555); BitmapData bd = multimap.LockBits(new Rectangle(0, 0, multimap.Width, multimap.Height), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555); ushort * line = (ushort *)bd.Scan0; int delta = bd.Stride >> 1; ushort *cur = line; while (bin.BaseStream.Length != bin.BaseStream.Position) { pixel = bin.ReadByte(); count = (pixel & 0x7f); if ((pixel & 0x80) != 0) { c = 0x8000;//Color.Black; } else { c = 0xffff;//Color.White; } for (i = 0; i < count; ++i) { cur[x++] = c; if (x >= width) { cur += delta; x = 0; } } } multimap.UnlockBits(bd); return(multimap); } } } return(null); }
public static void Initialize() { _entries = new Hashtable(); string filePath = Files.GetFilePath("body.def"); if (filePath == null) { return; } using (var def = new StreamReader(filePath)) { string line; while ((line = def.ReadLine()) != null) { if ((line = line.Trim()).Length == 0 || line.StartsWith("#")) { continue; } try { int index1 = line.IndexOf("{", StringComparison.Ordinal); int index2 = line.IndexOf("}", StringComparison.Ordinal); string param1 = line.Substring(0, index1); string param2 = line.Substring(index1 + 1, index2 - index1 - 1); string param3 = line.Substring(index2 + 1); int indexOf = param2.IndexOf(','); if (indexOf > -1) { param2 = param2.Substring(0, indexOf).Trim(); } int iParam1 = Convert.ToInt32(param1.Trim()); int iParam2 = Convert.ToInt32(param2.Trim()); int iParam3 = Convert.ToInt32(param3.Trim()); _entries[iParam1] = new BodyTableEntry(iParam2, iParam1, iParam3); } catch { // TODO: ignored? // ignored } } } }
/// <summary> /// Gets count of definied lights /// </summary> /// <returns></returns> public static int GetCount() { var idxPath = Files.GetFilePath("lightidx.mul"); if (idxPath == null) { return(0); } using (var index = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { return((int)(index.Length / 12)); } }
/// <summary> /// reads facet0*.mul into Bitmap /// </summary> /// <param name="id">facet id</param> /// <returns>Bitmap</returns> public static unsafe Bitmap GetFacetImage(int id) { Bitmap bmp; string path = Files.GetFilePath($"facet0{id}.mul"); if (path != null) { using (BinaryReader reader = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { int width = reader.ReadInt16(); int height = reader.ReadInt16(); bmp = new Bitmap(width, height); BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555); ushort *line = (ushort *)bd.Scan0; int delta = bd.Stride >> 1; for (int y = 0; y < height; y++, line += delta) { int colorsCount = reader.ReadInt32() / 3; ushort *endline = line + delta; ushort *cur = line; ushort *end; for (int c = 0; c < colorsCount; c++) { byte count = reader.ReadByte(); short color = reader.ReadInt16(); end = cur + count; while (cur < end) { if (cur > endline) { break; } *cur++ = (ushort)(color ^ 0x8000); } } } bmp.UnlockBits(bd); } return(bmp); } return(null); }
0x0490 }; // last is BlackTile /// <summary> /// Initialize (opens for reading) Facet mul file from UO client folder /// </summary> /// <param name="fileindex">file index of facetID.mul file</param> public Facet(int fileindex) { if (fileindex < 0 || fileindex > 99) { throw new ArgumentOutOfRangeException(); } m_FileName = Files.GetFilePath(String.Format("facet{0:D2}.mul", fileindex)); if (String.IsNullOrEmpty(FileName)) { throw new Exception(String.Format("File: \"facet{0:D2}.mul\" wasn't found.", fileindex)); } m_FileIndex = fileindex; Initialize(); Reload(); }
/// <summary> /// Loads speech.mul in <see cref="SpeechList.Entries"/> /// </summary> public static void Initialize() { string path = Files.GetFilePath("speech.mul"); if (path == null) { Entries = new List <SpeechEntry>(0); return; } Entries = new List <SpeechEntry>(); using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { byte[] buffer = new byte[fs.Length]; unsafe { int order = 0; fs.Read(buffer, 0, buffer.Length); fixed(byte *data = buffer) { byte *bindat = (byte *)data; byte *bindatend = bindat + buffer.Length; //--bindat; while (bindat != bindatend) { short x1 = *bindat++; short x2 = *bindat++; short id = (short)((x1 << 8) | (x2)); //Swapped Endian short length = (short)((*bindat++ >> 8) | (*bindat++)); if (length > 128) { length = 128; } for (int i = 0; i < length; ++i) { m_Buffer[i] = *bindat++; } string keyword = Encoding.UTF8.GetString(m_Buffer, 0, length); Entries.Add(new SpeechEntry(id, keyword, order)); ++order; } } } } }
/// <summary> /// Reads unifont*.mul /// </summary> public static void Initialize() { for (int i = 0; i < _files.Length; i++) { string filePath = Files.GetFilePath(_files[i]); if (filePath == null) { continue; } Fonts[i] = new UnicodeFont(); using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var bin = new BinaryReader(fs)) { for (int c = 0; c < 0x10000; ++c) { Fonts[i].Chars[c] = new UnicodeChar(); fs.Seek(c * 4, SeekOrigin.Begin); int num2 = bin.ReadInt32(); if ((num2 >= fs.Length) || (num2 <= 0)) { continue; } fs.Seek(num2, SeekOrigin.Begin); sbyte xOffset = bin.ReadSByte(); sbyte yOffset = bin.ReadSByte(); int width = bin.ReadByte(); int height = bin.ReadByte(); Fonts[i].Chars[c].XOffset = xOffset; Fonts[i].Chars[c].YOffset = yOffset; Fonts[i].Chars[c].Width = width; Fonts[i].Chars[c].Height = height; if (!((width == 0) || (height == 0))) { Fonts[i].Chars[c].Bytes = bin.ReadBytes(height * (((width - 1) / 8) + 1)); } } } } } }
/// <summary> /// Create in memmory new Facet from image bitmap /// </summary> /// <param name="fileindex">index of new Facet</param> /// <param name="bitmap">source image to create Facet class from</param> public Facet(int fileindex, Bitmap bitmap) { if (bitmap == null) { throw new ArgumentNullException(); } if (fileindex < 0 || fileindex > 99) { throw new ArgumentOutOfRangeException(); } m_FileIndex = fileindex; m_FileName = Files.GetFilePath(String.Format("facet{0:D2}.mul", fileindex)); m_Width = bitmap.Width; m_Height = bitmap.Height; m_Bitmap = bitmap.Clone(new Rectangle(0, 0, Width, Height), PixelFormat.Format16bppRgb555); }
/// <summary> /// Loads speech.mul in <see cref="SpeechList.Entries"/> /// </summary> public static void Initialize() { var path = Files.GetFilePath("speech.mul"); if (path == null) { Entries = new List <SpeechEntry>(0); return; } Entries = new List <SpeechEntry>(); using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { var buffer = new byte[fs.Length]; unsafe { var order = 0; fs.Read(buffer, 0, buffer.Length); fixed(byte *data = buffer) { var bindat = data; var bindatend = bindat + buffer.Length; while (bindat != bindatend) { var id = (short)((*bindat++ >> 8) | (*bindat++)); //Swapped Endian var length = (short)((*bindat++ >> 8) | (*bindat++)); if (length > 128) { length = 128; } for (var i = 0; i < length; ++i) { m_Buffer[i] = *bindat++; } var keyword = Encoding.UTF8.GetString(m_Buffer, 0, length); Entries.Add(new SpeechEntry(id, keyword, order)); ++order; } } } } }
public static void Initialize() { string path = Files.GetFilePath("radarcol.mul"); if (path != null) { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { m_Colors = new short[fs.Length / 2]; GCHandle gc = GCHandle.Alloc(m_Colors, GCHandleType.Pinned); byte[] buffer = new byte[(int)fs.Length]; fs.Read(buffer, 0, (int)fs.Length); Marshal.Copy(buffer, 0, gc.AddrOfPinnedObject(), (int)fs.Length); gc.Free(); } } else { m_Colors = new short[0x8000]; } }
/// <summary> /// Checks if map1.mul exists and sets <see cref="Ultima.Map"/> /// </summary> public static void CheckForNewMapSize() { if (Files.GetFilePath("map1.mul") != null) { if (Ultima.Map.Britania.Width == 1024) { Ultima.Map.Britania = new Ultima.Map(0, 0, 1024, 1024); } if (Ultima.Map.Sosaria.Width == 12288) { Ultima.Map.Trammel = new Ultima.Map(1, 1, 12288, 8192); } else if (Ultima.Map.Trammel.Width == 7168) { Ultima.Map.Trammel = new Ultima.Map(1, 1, 7168, 4096); } else { Ultima.Map.Trammel = new Ultima.Map(1, 1, 6144, 4096); } } else { if (Ultima.Map.Trammel.Width == 12288) { Ultima.Map.Trammel = new Ultima.Map(0, 1, 12288, 8192); } if (Ultima.Map.Trammel.Width == 7168) { Ultima.Map.Trammel = new Ultima.Map(0, 1, 7168, 4096); } else { Ultima.Map.Trammel = new Ultima.Map(0, 1, 6144, 4096); } } }
/// <summary> /// Fills bodyconv.def Tables /// </summary> public static void Initialize() { string path = Files.GetFilePath("bodyconv.def"); if (path == null) { return; } List <int> list1 = new List <int>(), list2 = new List <int>(), list3 = new List <int>(), list4 = new List <int>(); int max1 = 0, max2 = 0, max3 = 0, max4 = 0; using (var ip = new StreamReader(path)) { string line; while ((line = ip.ReadLine()) != null) { if ((line = line.Trim()).Length == 0 || line.StartsWith("#")) { continue; } try { string[] split = line.Split('\t'); int original = System.Convert.ToInt32(split[0]); int anim2 = System.Convert.ToInt32(split[1]); int anim3; int anim4; int anim5; try { anim3 = System.Convert.ToInt32(split[2]); } catch { anim3 = -1; } try { anim4 = System.Convert.ToInt32(split[3]); } catch { anim4 = -1; } try { anim5 = System.Convert.ToInt32(split[4]); } catch { 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); } } catch { } } } Table1 = new int[max1 + 1]; for (int i = 0; i < Table1.Length; ++i) { Table1[i] = -1; } for (int i = 0; i < list1.Count; i += 2) { Table1[list1[i]] = list1[i + 1]; } Table2 = new int[max2 + 1]; for (int i = 0; i < Table2.Length; ++i) { Table2[i] = -1; } for (int i = 0; i < list2.Count; i += 2) { Table2[list2[i]] = list2[i + 1]; } Table3 = new int[max3 + 1]; for (int i = 0; i < Table3.Length; ++i) { Table3[i] = -1; } for (int i = 0; i < list3.Count; i += 2) { Table3[list3[i]] = list3[i + 1]; } Table4 = new int[max4 + 1]; for (int i = 0; i < Table4.Length; ++i) { Table4[i] = -1; } for (int i = 0; i < list4.Count; i += 2) { Table4[list4[i]] = list4[i + 1]; } }
public TileMatrixPatch(TileMatrix matrix, int index, string path) { BlockWidth = matrix.BlockWidth; BlockHeight = matrix.BlockWidth; LandBlocksCount = StaticBlocksCount = 0; string mapDataPath, mapIndexPath; if (path == null) { mapDataPath = Files.GetFilePath("mapdif{0}.mul", index); mapIndexPath = Files.GetFilePath("mapdifl{0}.mul", index); } else { mapDataPath = Path.Combine(path, string.Format("mapdif{0}.mul", index)); if (!File.Exists(mapDataPath)) { mapDataPath = null; } mapIndexPath = Path.Combine(path, string.Format("mapdifl{0}.mul", index)); if (!File.Exists(mapIndexPath)) { mapIndexPath = null; } } if (mapDataPath != null && mapIndexPath != null) { LandBlocks = new Tile[matrix.BlockWidth][][]; LandBlocksCount = PatchLand(matrix, mapDataPath, mapIndexPath); } string staDataPath, staIndexPath, staLookupPath; if (path == null) { staDataPath = Files.GetFilePath("stadif{0}.mul", index); staIndexPath = Files.GetFilePath("stadifl{0}.mul", index); staLookupPath = Files.GetFilePath("stadifi{0}.mul", index); } else { staDataPath = Path.Combine(path, string.Format("stadif{0}.mul", index)); if (!File.Exists(staDataPath)) { staDataPath = null; } staIndexPath = Path.Combine(path, string.Format("stadifl{0}.mul", index)); if (!File.Exists(staIndexPath)) { staIndexPath = null; } staLookupPath = Path.Combine(path, string.Format("stadifi{0}.mul", index)); if (!File.Exists(staLookupPath)) { staLookupPath = null; } } if (staDataPath != null && staIndexPath != null && staLookupPath != null) { StaticBlocks = new HuedTile[matrix.BlockWidth][][][][]; StaticBlocksCount = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath); } }
public TileMatrix(int fileIndex, int mapID, int width, int height, string path) { Width = width; Height = height; BlockWidth = width >> 3; BlockHeight = height >> 3; if (path == null) { mapPath = Files.GetFilePath("map{0}.mul", fileIndex); if (String.IsNullOrEmpty(mapPath) || !File.Exists(mapPath)) { mapPath = Files.GetFilePath("map{0}LegacyMUL.uop", fileIndex); } if (mapPath != null && mapPath.EndsWith(".uop")) { IsUOPFormat = true; } // For shards that use Fel and Tram before the split if (String.IsNullOrEmpty(mapPath) || (!File.Exists(mapPath) && fileIndex == 1)) { fileIndex = 0; mapPath = Files.GetFilePath("map{0}.mul", fileIndex); } } else { mapPath = Path.Combine(path, String.Format("map{0}.mul", fileIndex)); if (!File.Exists(mapPath)) { mapPath = Path.Combine(path, String.Format("map{0}LegacyMUL.uop", fileIndex)); } if (!File.Exists(mapPath)) { mapPath = null; } else if (mapPath != null && mapPath.EndsWith(".uop")) { IsUOPFormat = true; } } if (mapPath != null && fileIndex == 0) { FileInfo fi = new FileInfo(mapPath); if (fi.Length < 89915392) { // Old map size. Width = 6144; } } if (path == null) { indexPath = Files.GetFilePath("staidx{0}.mul", fileIndex); } else { indexPath = Path.Combine(path, String.Format("staidx{0}.mul", fileIndex)); if (!File.Exists(indexPath)) { indexPath = null; } } if (path == null) { staticsPath = Files.GetFilePath("statics{0}.mul", fileIndex); } else { staticsPath = Path.Combine(path, String.Format("statics{0}.mul", fileIndex)); if (!File.Exists(staticsPath)) { staticsPath = null; } } EmptyStaticBlock = new HuedTile[8][][]; for (int i = 0; i < 8; ++i) { EmptyStaticBlock[i] = new HuedTile[8][]; for (int j = 0; j < 8; ++j) { EmptyStaticBlock[i][j] = new HuedTile[0]; } } InvalidLandBlock = new Tile[196]; m_LandTiles = new Tile[BlockWidth][][]; m_StaticTiles = new HuedTile[BlockWidth][][][][]; Patch = new TileMatrixPatch(this, mapID, path); }
public static void RewriteMap(string path, int map, int width, int height) { string mapPath = Files.GetFilePath("map{0}.mul", map); FileStream m_map; BinaryReader m_mapReader; if (mapPath != null) { m_map = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.Read); m_mapReader = new BinaryReader(m_map); } else { return; } int blockx = width >> 3; int blocky = height >> 3; string mul = Path.Combine(path, String.Format("map{0}.mul", map)); using (var fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write)) { var memmul = new MemoryStream(); using (var binmul = new BinaryWriter(memmul)) { for (int x = 0; x < blockx; ++x) { for (int y = 0; y < blocky; ++y) { try { m_mapReader.BaseStream.Seek(((x * blocky) + y) * 196, SeekOrigin.Begin); int header = m_mapReader.ReadInt32(); binmul.Write(header); for (int i = 0; i < 64; ++i) { short tileid = m_mapReader.ReadInt16(); sbyte z = m_mapReader.ReadSByte(); if ((tileid < 0) || (tileid >= 0x4000)) { tileid = 0; } if (z < -128) { z = -128; } if (z > 127) { z = 127; } binmul.Write(tileid); binmul.Write(z); } } catch //fill rest { binmul.BaseStream.Seek(((x * blocky) + y) * 196, SeekOrigin.Begin); for (; x < blockx; ++x) { for (; y < blocky; ++y) { binmul.Write(0); for (int i = 0; i < 64; ++i) { binmul.Write((short)0); binmul.Write((sbyte)0); } } y = 0; } } } } memmul.WriteTo(fsmul); } } m_mapReader.Close(); }
public static void DefragStatics(string path, Map map, int width, int height, bool remove) { string indexPath = Files.GetFilePath("staidx{0}.mul", map.FileIndex); FileStream m_Index; BinaryReader m_IndexReader; if (indexPath != null) { m_Index = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read); m_IndexReader = new BinaryReader(m_Index); } else { return; } string staticsPath = Files.GetFilePath("statics{0}.mul", map.FileIndex); FileStream m_Statics; BinaryReader m_StaticsReader; if (staticsPath != null) { m_Statics = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read); m_StaticsReader = new BinaryReader(m_Statics); } else { return; } int blockx = width >> 3; int blocky = height >> 3; string idx = Path.Combine(path, String.Format("staidx{0}.mul", map.FileIndex)); string mul = Path.Combine(path, String.Format("statics{0}.mul", map.FileIndex)); using ( FileStream fsidx = new FileStream(idx, FileMode.Create, FileAccess.Write, FileShare.Write), fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write)) { var memidx = new MemoryStream(); var memmul = new MemoryStream(); using (BinaryWriter binidx = new BinaryWriter(memidx), binmul = new BinaryWriter(memmul)) { for (int x = 0; x < blockx; ++x) { for (int y = 0; y < blocky; ++y) { try { m_IndexReader.BaseStream.Seek(((x * blocky) + y) * 12, SeekOrigin.Begin); int lookup = m_IndexReader.ReadInt32(); int length = m_IndexReader.ReadInt32(); int extra = m_IndexReader.ReadInt32(); if (((lookup < 0 || length <= 0) && (!map.Tiles.PendingStatic(x, y))) || (map.Tiles.IsStaticBlockRemoved(x, y))) { binidx.Write(-1); // lookup binidx.Write(-1); // length binidx.Write(-1); // extra } else { if ((lookup >= 0) && (length > 0)) { m_Statics.Seek(lookup, SeekOrigin.Begin); } var fsmullength = (int)binmul.BaseStream.Position; int count = length / 7; if (!remove) //without duplicate remove { bool firstitem = true; for (int i = 0; i < count; ++i) { ushort graphic = m_StaticsReader.ReadUInt16(); byte sx = m_StaticsReader.ReadByte(); byte sy = m_StaticsReader.ReadByte(); sbyte sz = m_StaticsReader.ReadSByte(); short shue = m_StaticsReader.ReadInt16(); if ((graphic >= 0) && (graphic <= Art.GetMaxItemID())) { if (shue < 0) { shue = 0; } if (firstitem) { binidx.Write((int)binmul.BaseStream.Position); //lookup firstitem = false; } binmul.Write(graphic); binmul.Write(sx); binmul.Write(sy); binmul.Write(sz); binmul.Write(shue); } } StaticTile[] tilelist = map.Tiles.GetPendingStatics(x, y); if (tilelist != null) { for (int i = 0; i < tilelist.Length; ++i) { if ((tilelist[i].m_ID >= 0) && (tilelist[i].m_ID <= Art.GetMaxItemID())) { if (tilelist[i].m_Hue < 0) { tilelist[i].m_Hue = 0; } if (firstitem) { binidx.Write((int)binmul.BaseStream.Position); //lookup firstitem = false; } binmul.Write(tilelist[i].m_ID); binmul.Write(tilelist[i].m_X); binmul.Write(tilelist[i].m_Y); binmul.Write(tilelist[i].m_Z); binmul.Write(tilelist[i].m_Hue); } } } } else //with duplicate remove { var tilelist = new StaticTile[count]; int j = 0; for (int i = 0; i < count; ++i) { var tile = new StaticTile(); tile.m_ID = m_StaticsReader.ReadUInt16(); tile.m_X = m_StaticsReader.ReadByte(); tile.m_Y = m_StaticsReader.ReadByte(); tile.m_Z = m_StaticsReader.ReadSByte(); tile.m_Hue = m_StaticsReader.ReadInt16(); if ((tile.m_ID >= 0) && (tile.m_ID <= Art.GetMaxItemID())) { if (tile.m_Hue < 0) { tile.m_Hue = 0; } bool first = true; for (int k = 0; k < j; ++k) { if ((tilelist[k].m_ID == tile.m_ID) && ((tilelist[k].m_X == tile.m_X) && (tilelist[k].m_Y == tile.m_Y)) && (tilelist[k].m_Z == tile.m_Z) && (tilelist[k].m_Hue == tile.m_Hue)) { first = false; break; } } if (first) { tilelist[j] = tile; j++; } } } if (map.Tiles.PendingStatic(x, y)) { StaticTile[] pending = map.Tiles.GetPendingStatics(x, y); StaticTile[] old = tilelist; tilelist = new StaticTile[old.Length + pending.Length]; old.CopyTo(tilelist, 0); for (int i = 0; i < pending.Length; ++i) { if ((pending[i].m_ID >= 0) && (pending[i].m_ID <= Art.GetMaxItemID())) { if (pending[i].m_Hue < 0) { pending[i].m_Hue = 0; } bool first = true; for (int k = 0; k < j; ++k) { if ((tilelist[k].m_ID == pending[i].m_ID) && ((tilelist[k].m_X == pending[i].m_X) && (tilelist[k].m_Y == pending[i].m_Y)) && (tilelist[k].m_Z == pending[i].m_Z) && (tilelist[k].m_Hue == pending[i].m_Hue)) { first = false; break; } } if (first) { tilelist[j++] = pending[i]; } } } } if (j > 0) { binidx.Write((int)binmul.BaseStream.Position); //lookup for (int i = 0; i < j; ++i) { binmul.Write(tilelist[i].m_ID); binmul.Write(tilelist[i].m_X); binmul.Write(tilelist[i].m_Y); binmul.Write(tilelist[i].m_Z); binmul.Write(tilelist[i].m_Hue); } } } fsmullength = (int)binmul.BaseStream.Position - fsmullength; if (fsmullength > 0) { binidx.Write(fsmullength); //length if (extra == -1) { extra = 0; } binidx.Write(extra); //extra } else { binidx.Write(-1); //lookup binidx.Write(-1); //length binidx.Write(-1); //extra } } } catch // fill the rest { binidx.BaseStream.Seek(((x * blocky) + y) * 12, SeekOrigin.Begin); for (; x < blockx; ++x) { for (; y < blocky; ++y) { binidx.Write(-1); //lookup binidx.Write(-1); //length binidx.Write(-1); //extra } y = 0; } } } } memidx.WriteTo(fsidx); memmul.WriteTo(fsmul); } } m_IndexReader.Close(); m_StaticsReader.Close(); }