#region References
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
#endregion
namespace Ultima
{
public sealed class Multis
{
private static MultiComponentList[] m_Components = new MultiComponentList[0x2000];
private static FileIndex m_FileIndex = new FileIndex("Multi.idx", "Multi.mul", 0x2000, 14);
public enum ImportType
{
TXT,
UOA,
UOAB,
WSC,
MULTICACHE,
UOADESIGN
}
public static bool PostHSFormat { get; set; }
///
/// ReReads multi.mul
///
public static void Reload()
{
m_FileIndex = new FileIndex("Multi.idx", "Multi.mul", 0x2000, 14);
m_Components = new MultiComponentList[0x2000];
}
///
/// Gets of multi
///
///
///
public static MultiComponentList GetComponents(int index)
{
MultiComponentList mcl;
index &= 0x1FFF;
if (index >= 0 && index < m_Components.Length)
{
mcl = m_Components[index];
if (mcl == null)
{
m_Components[index] = mcl = Load(index);
}
}
else
{
mcl = MultiComponentList.Empty;
}
return mcl;
}
public static MultiComponentList Load(int index)
{
try
{
int length, extra;
bool patched;
Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);
if (stream == null)
{
return MultiComponentList.Empty;
}
if (PostHSFormat || Art.IsUOAHS())
{
return new MultiComponentList(new BinaryReader(stream), length / 16);
}
else
{
return new MultiComponentList(new BinaryReader(stream), length / 12);
}
}
catch
{
return MultiComponentList.Empty;
}
}
public static void Remove(int index)
{
m_Components[index] = MultiComponentList.Empty;
}
public static void Add(int index, MultiComponentList comp)
{
m_Components[index] = comp;
}
public static MultiComponentList ImportFromFile(int index, string FileName, ImportType type)
{
try
{
return m_Components[index] = new MultiComponentList(FileName, type);
}
catch
{
return m_Components[index] = MultiComponentList.Empty;
}
}
public static MultiComponentList LoadFromFile(string FileName, ImportType type)
{
try
{
return new MultiComponentList(FileName, type);
}
catch
{
return MultiComponentList.Empty;
}
}
public static List LoadFromCache(string FileName)
{
var multilist = new List();
using (var ip = new StreamReader(FileName))
{
string line;
while ((line = ip.ReadLine()) != null)
{
string[] split = Regex.Split(line, @"\s+");
if (split.Length == 7)
{
int count = Convert.ToInt32(split[2]);
multilist.Add(new MultiComponentList(ip, count));
}
}
}
return multilist;
}
public static string ReadUOAString(BinaryReader bin)
{
byte flag = bin.ReadByte();
if (flag == 0)
{
return null;
}
else
{
return bin.ReadString();
}
}
public static List