Yea that version doesn't work anymore :/ It's not just an array
Here is a new version which copies the data into memory once, still slow when you call it, but faster than before!
Code:
#region Previously completed quests
private static Dictionary<UInt32, UInt32> QuestIDToIndex = new Dictionary<uint, uint>();
private static Thread Thread_UpdateQuestIDCache = new Thread(UpdateQuestIDCache);
private static void UpdateQuestIDCache()
{
while (true)
{
try
{
int StartTime = Environment.TickCount;
// only try to update if it's 0!
if (QuestIDToIndex.Count == 0)
{
var Info = MyWoW.Helpers.ClientDB.Functions.ClientDB_GetInfo(MyWoW.Memory.WowBaseAddress + (uint)MyWoW.Resources.Offsets.DBCs.QuestV2);
Dictionary<UInt32, UInt32> Result = new Dictionary<UInt32, UInt32>();
for (uint i = 0; i < Info.NumRows; i++)
{
uint quest_id = MyWoW.Memory.ReadUInt(Info.FirstRows + 8 * i);
if (quest_id > 0)
{
uint Row = MyWoW.Helpers.ClientDB.Functions.ClientDB__GetRow(MyWoW.Memory.WowBaseAddress + (uint)MyWoW.Resources.Offsets.DBCs.QuestV2, (uint)quest_id);
if (Row > 0)
{
uint quest_index = MyWoW.Memory.ReadUInt(Row + 0x4);
Result.Add(quest_id, quest_index);
}
}
}
if (Result.Count > 0)
{
Console.WriteLine("[DEBUG] Loaded quest index cache in {0} seconds ({1} items)", (Environment.TickCount - StartTime) / 1000, Result.Count);
}
QuestIDToIndex = Result;
}
// done - only need to load it once!
else {
break;
}
}
catch { }
System.Threading.Thread.Sleep(500);
}
}
internal static void UpdateQuestIndexCache()
{
if (Thread_UpdateQuestIDCache.IsAlive)
{
Thread_UpdateQuestIDCache.Abort();
}
Thread_UpdateQuestIDCache = new Thread(UpdateQuestIDCache);
Thread_UpdateQuestIDCache.Priority = ThreadPriority.BelowNormal;
Thread_UpdateQuestIDCache.Start();
}
public static List<UInt32> GetQuestsCompleted
{
get
{
#region Wait for quest cache to populate...
if (QuestIDToIndex.Count == 0)
{
while (Thread_UpdateQuestIDCache.IsAlive && QuestIDToIndex.Count == 0)
{
Thread.Sleep(10);
}
if (QuestIDToIndex.Count == 0)
{
throw new Exception("Unable to load quest id/index cache!");
}
}
#endregion
List<UInt32> CompletedQuests = new List<UInt32>();
foreach (KeyValuePair<UInt32, UInt32> entry in QuestIDToIndex)
{
uint quest_id = entry.Key;
uint quest_index = entry.Value;
if ( quest_id > 0 && quest_index > 0 ){
uint Array = MyWoW.Memory.WowBaseAddress + (uint)MyWoW.Resources.Offsets.Questing.QuestsCompleted;
uint ArrayIndex = ((quest_index - 1) >> 3);
Byte UnkFlag1 = MyWoW.Memory.ReadByte(Array + ArrayIndex);
Byte UnkFlag2 = (Byte)(1 << (((int)quest_index - 1) & 7));
if ((UnkFlag1 & UnkFlag2) > 0)
{
CompletedQuests.Add(quest_id);
}
}
}
return CompletedQuests;
}
}
#endregion