First you will need a data structure to hold the information your going to load, this could be a class if you really wanted although i dont recommend it. Im using a struct:
Code:
public struct ItemDetail
{
public string Name, Description;
public uint ID, Price;
public ushort Class, Prof, Level, Str_Req, Dex_Req, Vit_Req,
Spi_Req, Damage_Max, Damage_Min, Defense_Add, Dex_Add, Dodge_Add,
HP_Add, MP_Add, Magic_Attack, MDefense_Add, Dura, MaxDura, Frequency;
public byte Range, TradeType;
}
Secondly you need the method to load the itemtype.dat, and heres my version:
Code:
private static Dictionary<uint, ItemDetail> _Itemdata = new Dictionary<uint, ItemDetail>();
public static void LoadItemData()
{
Console.WriteLine("[Database] Loading Item Data");
int start = System.Environment.TickCount;
FileStream File = new FileStream(Constants.ItemTypePath, FileMode.Open);
BinaryReader Reader = new BinaryReader(File);
uint Amount = Reader.ReadUInt32();
ItemDetail _IDetail;
for (int i = 0; i < Amount; i++)
Reader.ReadUInt32();
for (int i = 0; i < Amount; i++)
{
_IDetail = new ItemDetail();
_IDetail.ID = Reader.ReadUInt32();
for (int x = 0; x < 16; x++)
{
_IDetail.Name += (char)Reader.ReadByte();
}
_IDetail.Name = _IDetail.Name.Trim('\0');
_IDetail.Class = Reader.ReadByte();
_IDetail.Prof = Reader.ReadByte();
_IDetail.Level = Reader.ReadUInt16();
_IDetail.Vit_Req = Reader.ReadUInt16();
_IDetail.Str_Req = Reader.ReadUInt16();
_IDetail.Dex_Req = Reader.ReadUInt16();
_IDetail.Spi_Req = Reader.ReadUInt16();
_IDetail.TradeType = (byte)Reader.ReadUInt32();
_IDetail.Price = Reader.ReadUInt32();
File.Seek(4, SeekOrigin.Current);
_IDetail.Damage_Max = Reader.ReadUInt16();
_IDetail.Damage_Min = Reader.ReadUInt16();
_IDetail.Defense_Add = Reader.ReadUInt16();
_IDetail.Dex_Add = Reader.ReadUInt16();
_IDetail.Dodge_Add = Reader.ReadUInt16();
_IDetail.HP_Add = Reader.ReadUInt16();
_IDetail.MP_Add = Reader.ReadUInt16(); ;
_IDetail.Dura = Reader.ReadUInt16();
_IDetail.MaxDura = Reader.ReadUInt16();
_IDetail.Magic_Attack = Reader.ReadUInt16();
_IDetail.MDefense_Add = Reader.ReadUInt16();
File.Seek(6, SeekOrigin.Current);
_IDetail.Range = (byte)Reader.ReadUInt16();
_IDetail.Frequency = Reader.ReadUInt16();
for (int x = 0; x < 16; x++)
{
_IDetail.Description += (char)Reader.ReadByte();
}
_IDetail.Description = _IDetail.Description.Trim('\0');
if (!_Itemdata.ContainsKey(_IDetail.ID))
_Itemdata.Add(_IDetail.ID, _IDetail);
File.Seek(112, SeekOrigin.Current);
}
Console.WriteLine("[Database] Loaded {0} ItemDetails in {1}ms", _Itemdata.Count, Environment.TickCount - start);
File.Dispose();
File.Close();
Reader.Close();
}
The dictionary is where the data is stored and can be accessed like this:
Code:
_Itemdata[ItemID];
Code:
_Itemdata[ItemID].Class;
ItemDetail _IDetail = _Itemdata[ItemID];
_IDetail.Class;
Code:
for (int i = 0; i < Amount; i++)
Reader.ReadUInt32();
Anyways i think thats everything, any questions feel free to ask.
Thanks are appreciated.






