/// <summary> /// Returns true if initialized /// </summary> public static bool InitItemCache() { if (mainInstance.IsIngame() == false) { return(false); } if (ItemCache != null) { // Already initialized return(true); } var itemCount = MemoryRead(g_hD2Common + 0x9FB94, g_ahD2Handle); ItemCache = new List <CacheItem>(itemCount); var pItemsTxt = (IntPtr)MemoryRead(g_hD2Common + 0x9FB98, g_ahD2Handle); for (int iClass = 0; iClass < itemCount; iClass++) { IntPtr pBaseAddr = pItemsTxt + 0x1A8 * iClass; IntPtr iNameID = (IntPtr)MemoryRead(pBaseAddr + 0xF4, g_ahD2Handle, "word"); IntPtr iName = (IntPtr)mainInstance.RemoteThread(mainInstance.g_pD2InjectGetString, iNameID); var rawBytes = MemoryRead(iName, g_ahD2Handle, new byte[200]); var rawString = Encoding.Unicode.GetString(rawBytes); var sName = rawString.Substring(0, rawString.IndexOf('\0')); sName = sName.Replace("\n", "|"); sName = Regex.Replace(sName, "ÿc.", ""); // == Get tier == // = tier "0" is Amulet/Ring var sTier = "0"; if (MemoryRead(pBaseAddr + 0x84, g_ahD2Handle) > 0) { // Weapon / Armor var match = Regex.Match(sName, "[1-4]|[(]Sacred[)]"); if (match.Success) { sTier = match.Value.Equals("(Sacred)") ? "sacred" : match.Value; } } var cacheItem = new CacheItem() { FullText = sName, Tier = ItemFlags.GetFlagId(sTier), Name = Regex.Replace(sName, ".+\\|", "") }; ItemCache.Add(cacheItem); } MainWindow.mainInstance.InitItemAutocomplete(ItemCache); return(true); }
public void Do() { InitItemCache(); UpdateMatchList(); int[] aiOffsets = new int[] { 0, 0x2C, 0x1C, 0x0 }; var pPaths = MemoryPointerRead(g_hD2Client + 0x11BBFC, g_ahD2Handle, aiOffsets); aiOffsets[3] = 0x24; var iPaths = MemoryPointerRead(g_hD2Client + 0x11BBFC, g_ahD2Handle, aiOffsets); if (pPaths == IntPtr.Zero || iPaths == IntPtr.Zero) { return; } //logger.Debug("========= start ========="); for (int i = 0; i < (uint)iPaths; i++) { var pPath = (IntPtr)MemoryRead(pPaths + 4 * i, g_ahD2Handle); var pUnit = (IntPtr)MemoryRead(pPath + 0x74, g_ahD2Handle); while ((uint)pUnit > 0) { var unitAny = ReadProcessMemoryStruct <UnitAny>(g_ahD2Handle, pUnit); pUnit = (IntPtr)unitAny.pUnitNext; //logger.Debug("unitAny.iUnitType: " + unitAny.iUnitType); if (unitAny.IsItem) { var tItemData = ReadProcessMemoryStruct <ItemData>(g_ahD2Handle, (IntPtr)unitAny.pUnitData); // Using the ear level field to check if we've seen this item on the ground before // Resets when the item is picked up or we move too far away if (!mainInstance.g_bnotifierChanged && tItemData.iEarLevel != 0) { continue; } int iNewEarLevel = 1; var isNewItem = (0x2000 & tItemData.iFlags) != 0; var isSocketed = (0x800 & tItemData.iFlags) != 0; var isEthereal = (0x400000 & tItemData.iFlags) != 0; var itemText = unitAny.Name; bool notify = false; int iFlagsSound = 0; int iFlagsColour = 0; for (int j = 0; j < notifyMatchList.Count; j++) { if (Regex.IsMatch(unitAny.FullText, notifyMatchList[j].Match)) { int iFlagsTier = notifyMatchList[j].Tier; int iFlagsQuality = notifyMatchList[j].Quality; int iFlagsMisc = notifyMatchList[j].Misc; iFlagsColour = notifyMatchList[j].Colour; iFlagsSound = notifyMatchList[j].Sound; if (iFlagsTier != 0 && 0 == (iFlagsTier & unitAny.TierFlag)) { continue; } if (iFlagsQuality != 0 && 0 == (iFlagsQuality & (1 << (int)tItemData.iQuality - 1))) { continue; } if (isSocketed == false && 0 != (iFlagsMisc & ItemFlags.GetFlagId("socket"))) { continue; } if (isEthereal) { itemText += " (Eth)"; } else if (0 != (iFlagsMisc & ItemFlags.GetFlagId("eth"))) { continue; } if (iFlagsColour == ItemFlags.GetFlagId("hide")) { iNewEarLevel = 2; } else if (iFlagsColour != ItemFlags.GetFlagId("show")) { notify = true; } break; } } // Write the the status of item (1 => already seen no pickup | 2 => already seen pickup MemoryWrite((IntPtr)unitAny.pUnitData + 0x48, g_ahD2Handle, new byte[] { (byte)iNewEarLevel }); if (notify) { PrintColor iColor; if (iFlagsColour != 0) { iColor = (PrintColor)iFlagsColour - 1; } else if ((ItemQuality)tItemData.iQuality == ItemQuality.Normal && unitAny.TierFlag == ItemFlags.GetFlagId("0")) { iColor = PrintColor.Orange; } else { iColor = qualityColor[tItemData.iQuality]; } if (Settings.Default.notifySuperior && (ItemQuality)tItemData.iQuality == ItemQuality.Superior) { itemText = "Superior " + itemText; } mainInstance.PrintString("- " + itemText, iColor); if (iFlagsSound != -1) { MainWindow.mainInstance.Sounds.List[iFlagsSound].Play(); } } } } } mainInstance.g_bnotifierChanged = false; }