/// <summary> /// Loads Art data from files. /// </summary> /// <param name="idxFile">Path to index file.</param> /// <param name="mulFile">Path to data file.</param> /// <param name="access">Access mode to data file.</param> /// <returns>New object encapsulating loaded data.</returns> public static Art Load(string idxFile, string mulFile, MulFileAccessMode access) { Stream dataStream = null; try { switch (access) { case MulFileAccessMode.RequestWrite: dataStream = File.Open(mulFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read); break; case MulFileAccessMode.TryWrite: try { dataStream = File.Open(mulFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read); } catch { goto case MulFileAccessMode.ReadOnly; } break; case MulFileAccessMode.ReadOnly: dataStream = File.Open(mulFile, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read); break; } IndexFile indexFile = IndexFile.Load(idxFile); Art art = new Art(Path.GetFullPath(mulFile), indexFile, dataStream); Trace.WriteLine(String.Format("Art: File \"{0}\" succesfully loaded.", mulFile), "MulLib"); return(art); } catch (Exception e) { if (dataStream != null) { dataStream.Close(); } throw new Exception("Error loading Art.", e); } }
/// <summary> /// Loads skills from files. /// </summary> /// <param name="idxFile">Index file.</param> /// <param name="mulFile">Data file.</param> /// <returns>New Skills object with loaded data.</returns> public static Skills Load(string idxFile, string mulFile) { IndexFile indexFile = null; Stream stream = null; BinaryReader reader = null; try { indexFile = IndexFile.Load(idxFile); stream = File.OpenRead(mulFile); reader = new BinaryReader(stream); Skills skills = new Skills(); IndexData indexData; SkillData skillData = new SkillData(); for (int i = 0; i < indexFile.Count; i++) { indexData = indexFile[i]; if (indexData.IsValid) { stream.Seek(indexData.Lookup, SeekOrigin.Begin); skillData.Action = reader.ReadByte() != 0; skillData.Extra = indexData.Extra; byte[] nameBytes = reader.ReadBytes((int)indexData.Lenght - 1); skillData.Name = Encoding.ASCII.GetString(nameBytes).TrimEnd(' ', '\0'); skills.list.Add(skillData); } else { Trace.WriteLine("Skills: Found " + i.ToString() + " skills.", "MulLib"); break; } } Trace.WriteLine(String.Format("Skills: File \"{0}\" succesfully loaded.", mulFile), "MulLib"); return(skills); } catch (Exception e) { throw new Exception("Error loading Skills.", e); } finally { if (indexFile != null) { indexFile.Dispose(); } if (reader != null) { reader.Close(); } if (stream != null) { stream.Close(); } } }
public static Multi Load(string idxFile, string mulFile, MulFileAccessMode mode) { IndexFile indexFile = null; Stream stream = null; BinaryReader reader = null; try { indexFile = IndexFile.Load(idxFile); stream = File.OpenRead(mulFile); reader = new BinaryReader(stream); Multi multi = new Multi(); IndexData indexData; for (int i = 0; i < indexFile.Count; i++) { indexData = indexFile[i]; if (indexData.IsValid) { stream.Seek(indexData.Lookup, SeekOrigin.Begin); MultiData multiData = new MultiData(); multiData.Id = (ushort)i; multiData.Tiles = new MultiTile[indexData.Lenght / 12]; for (int j = 0; j < indexData.Lenght / 12; j++) { MultiTile tile = new MultiTile { ItemID = reader.ReadUInt16(), X = reader.ReadInt16(), Y = reader.ReadInt16(), Z = reader.ReadInt16(), Flags = reader.ReadInt32() }; multiData.Tiles[j] = tile; } multi.data.Add(multiData.Id, multiData); } } Trace.WriteLine(String.Format("Multi: File \"{0}\" succesfully loaded.", mulFile), "MulLib"); return(multi); } catch (Exception e) { throw new Exception("Error loading Multi.", e); } finally { if (indexFile != null) { indexFile.Dispose(); } if (reader != null) { reader.Close(); } if (stream != null) { stream.Close(); } } }