I'm working on converting LOTF to ini and i've just converted accounts which works fine although i'm getting the error in the screenshot and the NPC does not load ingame.
I'm just doing this as a side project for when i'm bored, not planning on using it.
Here this loads over 500 NPCs and it 5017 LOTF... Taken from Hybrids Source and fixed a bit to make into LOTF...
Code:
public static void LoadNPCs()
{
if (Directory.Exists(@"C:\DataBase\\cq_npc\\"))
{
int npcs = 0;
foreach (string file in Directory.GetFiles((@"C:\DataBase\\cq_npc\\")))
{
IniFile2 cq_npc = new IniFile2(file);
uint UID = cq_npc.ReadUInt32("cq_npc", "id", 0);
short X = (short)cq_npc.ReadUInt16("cq_npc", "cellx", 0);
short Y = (short)cq_npc.ReadUInt16("cq_npc", "celly", 0);
short Map = (short)cq_npc.ReadUInt16("cq_npc", "mapid", 0);
ushort Type = cq_npc.ReadUInt16("cq_npc", "lookface", 0);
byte Flags = (byte)(ConquerAngle)cq_npc.ReadUInt16("cq_npc", "type", 0);
byte Sob = (byte)cq_npc.ReadUInt16("cq_npc", "sort", 0);
SingleNPC npc = new SingleNPC(UID, Type, Flags, 2, X, Y, Map, Sob);
npcs++;
NPCs.Add(UID, npc);
}
Console.WriteLine("Loaded " + npcs + " NPCs.");
}
else { Console.WriteLine("CQ_NPC IS MISSING. WARNING: CAN NOT LOAD NPCS!"); }
}
Make sure you define the "NPCs.Add" My NPCs hashtable was in same place where I loaded them... also make sure you define the location of your npcs.. I've uploaded the DataBase/cq_npc file folder..so you can put it in C:/
Forgot to give you IniFile2.. here you go
Code:
public class IniFile2
{
public string FileName;
public IniFile2()
{
}
public IniFile2(string _FileName)
{
this.FileName = _FileName;
}
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int GetPrivateProfileStringA(string Section, string Key, string _Default, StringBuilder Buffer, int BufferSize, string FileName);
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int WritePrivateProfileStringA(string Section, string Key, string Arg, string FileName);
public byte ReadByte(string Section, string Key, byte _Default)
{
byte buf = _Default;
byte.TryParse(this.ReadString(Section, Key, _Default.ToString(), 6), out buf);
return buf;
}
public short ReadInt16(string Section, string Key, short _Default)
{
short buf = _Default;
short.TryParse(this.ReadString(Section, Key, _Default.ToString(), 9), out buf);
return buf;
}
public int ReadInt32(string Section, string Key, int _Default)
{
int buf = _Default;
int.TryParse(this.ReadString(Section, Key, _Default.ToString(), 15), out buf);
return buf;
}
public sbyte ReadSByte(string Section, string Key, byte _Default)
{
sbyte buf = (sbyte)_Default;
sbyte.TryParse(this.ReadString(Section, Key, _Default.ToString(), 6), out buf);
return buf;
}
public string ReadString(string Section, string Key, string _Default)
{
return this.ReadString(Section, Key, _Default, 255);
}
public string ReadString(string Section, string Key, string _Default, int BufSize)
{
StringBuilder Buffer = new StringBuilder(BufSize);
GetPrivateProfileStringA(Section, Key, _Default, Buffer, BufSize, this.FileName);
return Buffer.ToString();
}
public ushort ReadUInt16(string Section, string Key, ushort _Default)
{
ushort buf = _Default;
ushort.TryParse(this.ReadString(Section, Key, _Default.ToString(), 9), out buf);
return buf;
}
public uint ReadUInt32(string Section, string Key, uint _Default)
{
uint buf = _Default;
uint.TryParse(this.ReadString(Section, Key, _Default.ToString(), 15), out buf);
return buf;
}
public void Write(string Section, string Key, object Value)
{
WritePrivateProfileStringA(Section, Key, Value.ToString(), this.FileName);
}
public void Write(string Section, string Key, string Value)
{
WritePrivateProfileStringA(Section, Key, Value, this.FileName);
}
}
and here is conquer angle..
Code:
public enum ConquerAngle : byte
{
SouthWest = 0,
West = 1,
NorthWest = 2,
North = 3,
NorthEast = 4,
East = 5,
SouthEast = 6,
South = 7
}
Just updated my previous post, and yeah I've tested it before and it works great...
Me and my friend a long time ago used the current way LOTF loads npcs ( through mysql ) and inserted over 500NPCs ourself..I've lost it a few times and had to do it again by creating queries.. and then I did lose it again and finally just was like..Why don't I load them from INI? ha so Now I did...
Just updated my previous post, and yeah I've tested it before and it works great...
Me and my friend a long time ago used the current way LOTF loads npcs ( through mysql ) and inserted over 500NPCs ourself..I've lost it a few times and had to do it again by creating queries.. and then I did lose it again and finally just was like..Why don't I load them from INI? ha so Now I did...