private void ScanChat(bool firstScan) { var messageElements = _gameController.Game.IngameState.IngameUi.ChatBox.Children.ToList(); var msgQueue = new Queue <string>(); for (var i = messageElements.Count - 1; i >= 0; i--) { var messageElement = messageElements[i]; if (messageElement.Address == _lastMessageAddress) { break; } if (!messageElement.IsVisibleLocal) { continue; } var text = NativeStringReader.ReadStringLong(messageElement.Address + 0x2E8, messageElement.M); msgQueue.Enqueue(text); //try //{ // File.AppendAllText(LOG_PATH, $"{text}{Environment.NewLine}"); //} //catch //{ // //ignored //} } _lastMessageAddress = messageElements.LastOrDefault()?.Address ?? 0; if (firstScan) { return; } while (msgQueue.Count > 0) { try { MessageReceived(msgQueue.Dequeue()); } catch (Exception e) { DebugWindow.LogError($"Error processing chat message. Error: {e.Message}", 5); } } }
public string ReadNativeString(long addr) => NativeStringReader.ReadString(addr);
private void ParseItemHover(Element tooltip, Element extendedModsElement) { _mods.Clear(); var extendedModsStr = NativeStringReader.ReadString(extendedModsElement.Address + EntityLabelMapOffsets.LabelOffset, tooltip.M, 5000); var extendedModsLines = extendedModsStr.Replace("\r\n", "\n").Split('\n'); var regularModsStr = NativeStringReader.ReadString(_regularModsElement.Address + EntityLabelMapOffsets.LabelOffset, tooltip.M, 5000); var regularModsLines = regularModsStr.Replace("\r\n", "\n").Split('\n'); ModTierInfo currentModTierInfo = null; var modsDict = new Dictionary <string, ModTierInfo>(); foreach (var extendedModsLine in extendedModsLines) { if (extendedModsLine.StartsWith("<italic>")) { continue; } if (extendedModsLine.StartsWith("<smaller>") || extendedModsLine.StartsWith("<crafted>")) { var isPrefix = extendedModsLine.Contains("Prefix"); var isSuffix = extendedModsLine.Contains("Suffix"); if (!isPrefix && !isSuffix) { DebugWindow.LogMsg($"Cannot extract Affix type from mod text: {extendedModsLine}", 4); return; } var affix = isPrefix ? "P" : "S"; var color = isPrefix ? _modsSettings.PrefixColor : _modsSettings.SuffixColor; var isRank = false; const string TIER = "(Tier: "; var tierPos = extendedModsLine.IndexOf(TIER); if (tierPos != -1) { tierPos += TIER.Length; } else { const string RANK = "(Rank: "; tierPos = extendedModsLine.IndexOf(RANK); if (tierPos != -1) { tierPos += RANK.Length; isRank = true; } } if (tierPos != -1 && (int.TryParse(extendedModsLine.Substring(tierPos, 2), out var tier) ||//try parse number 10 and up int.TryParse(extendedModsLine.Substring(tierPos, 1), out tier)) ) { if (isRank) { affix += $" Rank{tier}"; } else { affix += tier; } if (tier == 1) { color = _modsSettings.T1Color.Value; } else if (tier == 2) { color = _modsSettings.T2Color.Value; } else if (tier == 3) { color = _modsSettings.T3Color.Value; } } else if (extendedModsLine.Contains("Essence")) { affix += "(Ess)"; } currentModTierInfo = new ModTierInfo(affix, color); var modTypesMatches = _modTypeRegex.Matches(extendedModsLine); if (modTypesMatches.Count > 0) { foreach (Match modTypeMatch in modTypesMatches) { var modTypeValue = modTypeMatch.Groups[1].Value; var modTypeColor = Color.Gray; switch (modTypeValue) { case "Fire": modTypeColor = Color.Red; break; case "Cold": modTypeColor = new Color(41, 102, 241); break; case "Life": modTypeColor = Color.Magenta; break; case "Lightning": modTypeColor = Color.Yellow; break; case "Physical": modTypeColor = new Color(225, 170, 20); break; case "Critical": modTypeColor = new Color(168, 220, 26); break; case "Mana": modTypeColor = new Color(20, 240, 255); break; case "Attack": modTypeColor = new Color(240, 100, 30); break; case "Speed": modTypeColor = new Color(0, 255, 192); break; case "Caster": modTypeColor = new Color(216, 0, 255); break; case "Elemental": modTypeColor = Color.White; break; case "Gem Level": modTypeColor = new Color(200, 230, 160); break; } currentModTierInfo.ModTypes.Add(new ModType(modTypeValue, modTypeColor)); } } continue; } if (extendedModsLine.StartsWith("<") && !char.IsLetterOrDigit(extendedModsLine[0])) { currentModTierInfo = null; continue; } if (currentModTierInfo != null) { var modLine = Regex.Replace(extendedModsLine, @"\([\d-.]+\)", string.Empty); modLine = Regex.Replace(modLine, @"[\d-.]+", "#"); modLine = Regex.Replace(modLine, @"\s\([\d]+% Increased\)", string.Empty); modLine = modLine.Replace(" (#% Increased)", string.Empty); if (modLine.StartsWith("+")) { modLine = modLine.Substring(1); } if (!modsDict.ContainsKey(modLine)) { modsDict[modLine] = currentModTierInfo; } } } var modTierInfos = new List <ModTierInfo>(); foreach (var regularModsLine in regularModsLines) { var modFixed = regularModsLine; if (modFixed.StartsWith("+")) { modFixed = modFixed.Substring(1); } modFixed = Regex.Replace(modFixed, @"[\d-.]+", "#"); var found = false; foreach (var keyValuePair in modsDict) { if (modFixed.Contains(keyValuePair.Key)) { found = true; modTierInfos.Add(keyValuePair.Value); break; } } if (!found) { DebugWindow.LogMsg($"Cannot extract mod from parsed mods: {modFixed}", 4); var modTierInfo = new ModTierInfo("?", Color.Gray); modTierInfos.Add(modTierInfo); //return; } } if (modTierInfos.Count > 1) { for (var i = 1; i < modTierInfos.Count; i++) { var info = modTierInfos[i]; var prevInfo = modTierInfos[i - 1]; if (info == prevInfo) { info.ModLines++; } } } _mods = modTierInfos; }