Code:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class DB_head
{
public int name;
public int rCount;
public int fCount;
public int rSize;
public int stringSize;
public int Size { get { return Marshal.SizeOf(this); } }
}
public class DB
{
public byte[] datas, strings;
public DB_head head = new DB_head();
public string name;
public DB(string name)
{
using (FileStream stream = File.Open( name, FileMode.Open, FileAccess.Read, FileShare.Read))
using (BinaryReader r = new BinaryReader(stream))
{
head = BYTE.ToStruct<DB_head>(r.ReadBytes(head.Size));
datas = new byte[head.rCount * head.rSize];
r.Read(datas, 0, head.rCount * head.rSize);
strings = new byte[head.stringSize];
r.Read(strings, 0, head.stringSize);
Debug.Assert(datas.Length + strings.Length != stream.Length);
}
}
public static string read_to_end(BinaryReader r)
{
List<byte> b = new List<byte>();
uint offset = 0;
byte last_b;
while ((last_b= r.ReadByte()) != 0)
{
offset++;
b.Add(last_b);
}
return Encoding.UTF8.GetString(b.ToArray());
}
}
#region Spells DB
DB dbs = new DB(@"G:\WowUNPAC\DBFilesClientRU\Spell.dbc");
byte[] record = new byte[dbs.head.rSize];
wow_spel w_spell;
Spell spell;
List<wow_spel> wow_spels = new List<wow_spel>();
using (MemoryStream ms = new MemoryStream(dbs.datas))
{
using (BinaryReader br = new BinaryReader(ms))
{
for (int i = 0; i < dbs.head.rCount; i++)
{
w_spell = new wow_spel();
wow_spels.Add(BYTE.ToStruct<wow_spel>(br.ReadBytes(w_spell.Size)));
ms.Position = ms.Position + (dbs.head.rSize - w_spell.Size);
}
}
}
using (MemoryStream ms = new MemoryStream(dbs.strings))
{
using (BinaryReader br = new BinaryReader(ms))
{
for (int i = 0; i < wow_spels.Count; i++)
{
spell = new Spell();
spell.id = wow_spels[i].id;
ms.Position = wow_spels[i].name;
spell.name = DB.read_to_end(br);
spells.Add(spell);
}
}
}
spells.Add(new Spell(95861, "Медитация")); //http://ru.wowhead.com/spell=85101
#endregion