public static void SetHuntTime(Hunt h, int clearMinutes) { var expInformation = GlobalDataManager.GetTotalExperience(TimestampManager.getLatestTimes(clearMinutes)); h.totalExp = expInformation.Item1; h.totalTime = expInformation.Item2 * 60; }
public static List <Tuple <string, string> > GetRecentCommands(int type, int max_entries = 15) { List <string> times = TimestampManager.getLatestTimes(5); times.Reverse(); Dictionary <string, List <Tuple <string, string> > > dict = type == 0 ? GlobalDataManager.totalCommands : GlobalDataManager.totalURLs; List <Tuple <string, string> > results = new List <Tuple <string, string> >(); lock (dict) { foreach (string t in times) { if (dict.ContainsKey(t)) { foreach (Tuple <string, string> tpl in dict[t]) { if (tpl.Item2.Contains("recent", StringComparison.OrdinalIgnoreCase) || tpl.Item2.Contains("last", StringComparison.OrdinalIgnoreCase)) { continue; } results.Add(tpl); if (results.Count >= max_entries) { return(results); } } } } } return(results); }
public static bool HasAnyValidTimestampsFlash(byte[] array, int bytesRead, List <int> stamps) { // scan the memory for "timestamp values" // i.e. values that are like "xx:xx" where x = a number // we consider timestamps the "starting point" of a string, and the null terminator the "ending point" for (int i = 0; i < bytesRead - 6; i++) { if (array[i + 2] == ':' && (array[i + 5] == ' ' || array[i + 5] == ':') && array[i] >= '0' && array[i] <= '2' && array[i + 1] >= '0' && array[i + 1] <= '9' && array[i + 3] >= '0' && array[i + 3] <= '5' && array[i + 4] >= '0' && array[i + 4] <= '9') { int start = i; i += 6; while (array[i] != '\0') { ++i; } int h1 = (array[start] - '0') * 10; int h2 = array[start + 1] - '0'; int m1 = (array[start + 3] - '0') * 10; int m2 = array[start + 4] - '0'; if (stamps.Contains(TimestampManager.getStamp(h1 + h2, m1 + m2)) && !array.Contains(start, i - start, "</font>")) { return(true); } } } return(false); }
public static void clearOldLog(Hunt h, int clearMinutes = 10) { var time = DateTime.Now; int hour = time.Hour; int minute = time.Minute; while (clearMinutes > 60) { hour--; clearMinutes -= 60; } if (minute >= clearMinutes) { minute -= clearMinutes; } else { hour--; minute = 60 + (minute - clearMinutes); } int stamp = TimestampManager.getDayStamp(); while (hour < 0) { hour += 24; stamp--; } h.Reset(clearMinutes); HuntManager.SetHuntTime(h, clearMinutes); LootDatabaseManager.DeleteMessagesBefore(h, stamp, hour, minute); SQLiteDataReader reader = LootDatabaseManager.GetHuntMessages(h); Dictionary <string, List <string> > logMessages = new Dictionary <string, List <string> >(); while (reader.Read()) { string line = reader["message"].ToString(); if (line.Length < 15) { continue; } string t = line.Substring(0, 5); if (!(t[0].isDigit() && t[1].isDigit() && t[3].isDigit() && t[4].isDigit() && t[2] == ':')) { continue; //not a valid timestamp } if (!logMessages.ContainsKey(t)) { logMessages.Add(t, new List <string>()); } logMessages[t].Add(line); } Parser.ParseLootMessages(h, logMessages, null, false, false, true); LootDatabaseManager.UpdateLoot(); }
public static void AddLoot(Hunt h, Item item, int itemCount) { h.AddItem(item, itemCount); int stamp = TimestampManager.getDayStamp(); Tuple <int, int> time = TimestampManager.getCurrentTime(); LootDatabaseManager.InsertMessage(h, stamp, time.Item1, time.Item2, String.Format("{0}:{1} Loot of a non-existent creature: {2} {3}", time.Item1, time.Item2, itemCount, item.GetName())); LootDatabaseManager.UpdateLoot(); }
public void refreshExperienceChart() { this.mChart.Visible = true; this.mChart.Series[0].Points.Clear(); this.mChart.ChartAreas[0].AxisX.CustomLabels.Clear(); Dictionary <string, int> experienceCopy = new Dictionary <string, int>(); foreach (KeyValuePair <string, int> kvp in GlobalDataManager.GetExperience()) { experienceCopy.Add(kvp.Key, kvp.Value); } List <string> stamps = TimestampManager.getLatestTimes(60); stamps.Reverse(); int index = 60; foreach (string stamp in stamps) { if (experienceCopy.ContainsKey(stamp)) { break; } index--; } index = Math.Max(index, 5); int interval = Math.Max(1, index / 12); this.mChart.ChartAreas[0].AxisX.Interval = interval; this.mChart.ChartAreas[0].AxisX.Minimum = 1; this.mChart.ChartAreas[0].AxisX.Maximum = index; stamps = TimestampManager.getLatestTimes(index); stamps.Reverse(); int i = 0; long average = 0; foreach (string stamp in stamps) { if (i % interval == 0) { this.mChart.ChartAreas[0].AxisX.CustomLabels.Add(i, i + interval, stamp); } int exp = experienceCopy.ContainsKey(stamp) ? experienceCopy[stamp] : 0; this.mChart.Series[0].Points.AddXY(++i, exp * 60); average += exp; } stripLine.IntervalOffset = 60 * (average / i); mChart.ChartAreas[0].AxisY.StripLines.Clear(); mChart.ChartAreas[0].AxisY.StripLines.Add(stripLine); refreshTimer(); }
public void ClearItems(int clearMinutes) { string currentTime = TimestampManager.getCurrentTime(); lock (hashSets) { for (int i = 0; i < hashSets.Count; i++) { if (TimestampManager.Distance(currentTime, hashSets[i].Item1) > clearMinutes) { hashSets.RemoveAt(i); i--; } } } }
public static int GetExperiencePerHour() { if (SettingsManager.getSettingString("ExperiencePerHourCalculation") == "TibiaStyle") { return(GetTotalExperience(TimestampManager.getLatestTimes(15)).Item1 * 4); } else { List <string> times = TimestampManager.getLatestTimes(coefficients.Length); double totalExperience = 0; for (int i = 0; i < coefficients.Length; i++) { if (totalExperienceResults.ContainsKey(times[i])) { totalExperience += totalExperienceResults[times[i]] * coefficients[i]; } } return((int)(totalExperience * 4)); } }
public static void InsertSkin(Creature cr, int count = 1) { var time = DateTime.Now; int hour = time.Hour; int minute = time.Minute; int stamp = TimestampManager.getDayStamp(); string timestamp = String.Format("{0}:{1}", (hour < 10 ? "0" + hour.ToString() : hour.ToString()), (minute < 10 ? "0" + minute.ToString() : minute.ToString())); Item item = StorageManager.getItem(cr.skin.dropitemid); if (item == null) { return; } string message = String.Format("{0} Loot of a {1}: {2} {3}", timestamp, cr.displayname.ToLower(), count, item.displayname.ToLower()); Hunt h = HuntManager.activeHunt; LootDatabaseManager.InsertMessage(h, stamp, hour, minute, message); HuntManager.AddSkin(h, message, cr, item, count, timestamp); LootDatabaseManager.UpdateLoot(); }
private static void SearchChunk(IEnumerable <string> chunk, ReadMemoryResults res, bool readChatMessages = true, bool readLogMessages = true) { List <int> stamps = TimestampManager.getLatestStamps(3, ignoreStamp); foreach (string it in chunk) { string logMessage = it; string t = logMessage.Substring(0, 5); int hour = int.Parse(logMessage.Substring(0, 2)); int minute = int.Parse(logMessage.Substring(3, 2)); if (!stamps.Contains(TimestampManager.getStamp(hour, minute))) { continue; // the log message is not recent, so we skip parsing it } if (flashClient) { // there is some inconsistency with log messages, certain log messages use "12:00: Message.", others use "12:00 Message" // if there is a : after the timestamp we remove it if (logMessage[5] == ':') { logMessage = logMessage.Remove(5, 1); } } string message = logMessage.Substring(6); // message without timestamp if (readLogMessages) { if (logMessage.Length > 14 && logMessage.Substring(5, 9) == " You see ") { // the message contains "you see", so it's a look message if (!res.lookMessages.ContainsKey(t)) { res.lookMessages.Add(t, new List <string>()); } res.lookMessages[t].Add(logMessage); continue; } else if (message.Contains(':')) { if (logMessage.Length > 14 && logMessage.Substring(5, 9) == " Loot of ") // loot drop message { if (!res.itemDrops.ContainsKey(t)) { res.itemDrops.Add(t, new List <string>()); } res.itemDrops[t].Add(logMessage); continue; } } else if (logMessage.Length > 17 && logMessage.Substring(5, 12) == " You gained ") { // the message is an experience string, "You gained x experience." try { int experience = int.Parse(logMessage.Substring(17).Split(' ')[0]); if (!res.exp.ContainsKey(t)) { res.exp.Add(t, experience); } else { res.exp[t] = res.exp[t] + experience; } } catch { } continue; } else if (logMessage.Length == 19 && logMessage.Substring(5, 14) == " You are dead.") { if (!res.deaths.ContainsKey(t)) { res.deaths.Add(t, true); } } else if (logMessage.Length > 18) { string[] split = message.Split(' '); int index = split.IndexOf("hitpoints"); if (index > 0) { int ind; // damage log message (X loses Y hitpoints due to an attack by Z.) int damage = 0; if (!int.TryParse(split[index - 1], out damage)) { continue; } string player; if (logMessage.Substring(logMessage.Length - 12) == "your attack.") { // X lost Y hitpoints because of your attack. // attacker is the player himself player = "You"; } else if (split.Contains("by")) { // X lost Y hitpoints because of an attack by Z. // Z is the attacker => after the word "by" player = ""; ind = split.IndexOf("by") + 1; for (int i = ind; i < split.Length; i++) { player = (player == "" ? player : player + " ") + split[i]; } } else { continue; } string splitTerm; if (split.Contains("loses")) { splitTerm = "loses"; } else if (split.Contains("lose")) { splitTerm = "lose"; } else { continue; } ind = split.IndexOf(splitTerm); string target = ""; for (int i = 0; i < ind; i++) { target = (target == "" ? target : target + " ") + split[i]; } if (!res.damageDealt.ContainsKey(player)) { res.damageDealt.Add(player, new Dictionary <string, DamageEntry>()); } DamageEntry damageEntry; if (!res.damageDealt[player].ContainsKey(t)) { damageEntry = new DamageEntry(); damageEntry.damage = damage; damageEntry.targetDamage.Add(target, damage); res.damageDealt[player].Add(t, damageEntry); } else { damageEntry = res.damageDealt[player][t]; damageEntry.damage += damage; if (damageEntry.targetDamage.ContainsKey(target)) { damageEntry.targetDamage[target] += damage; } else { damageEntry.targetDamage.Add(target, damage); } } continue; } else { index = split.IndexOf("hitpoints."); if (index > 0) { // heal log message (X healed Y for Z hitpoints.) int healing = 0; if (!int.TryParse(split[index - 1], out healing)) { continue; } int forIndex = split.IndexOf("for"); if (forIndex <= 0) { continue; } string splitTerm; if (split.Contains("heal")) { splitTerm = "heal"; } else if (split.Contains("healed")) { splitTerm = "healed"; } else { continue; } int healIndex = split.IndexOf(splitTerm); if (healIndex >= forIndex) { continue; } string source = ""; for (int i = 0; i < healIndex; i++) { if (split[i] == "was" || split[i] == "were") { break; } if (split[i] == "by") { continue; } source = (source == "" ? source : source + " ") + split[i]; } string target = ""; for (int i = healIndex + 1; i < forIndex; i++) { if (split[i] == "was" || split[i] == "were") { break; } if (split[i] == "by") { continue; } target = (target == "" ? target : target + " ") + split[i]; } if (target == "yourself" || target == "itself" || target == "himself" || target == "herself") { target = source; } if (target.Length == 0 || source.Length == 0) { continue; } if (split.Contains("by")) { // X healed Y for Z. => X is the source and Y is the target (default) // X was healed by Y for Z. => X is the target and Y is the source, so swap source and target string temp = source; source = target; target = temp; } if (!res.healingDone.ContainsKey(source)) { res.healingDone.Add(source, new Dictionary <string, DamageEntry>()); } DamageEntry healingEntry; if (!res.healingDone[source].ContainsKey(t)) { healingEntry = new DamageEntry(); healingEntry.damage = healing; healingEntry.targetDamage.Add(target, healing); res.healingDone[source].Add(t, healingEntry); } else { healingEntry = res.healingDone[source][t]; healingEntry.damage += healing; if (healingEntry.targetDamage.ContainsKey(target)) { healingEntry.targetDamage[target] += healing; } else { healingEntry.targetDamage.Add(target, healing); } } } else if (logMessage.Substring(5, 14) == " You advanced " && logMessage.Contains("level", StringComparison.OrdinalIgnoreCase)) { // advancement log message (You advanced from level x to level x + 1.) if (logMessage[logMessage.Length - 1] == '.') { if (GlobalDataManager.AddLevelAdvance(logMessage)) { res.newAdvances.Add(logMessage); } continue; } } else if (logMessage.Substring(5, 7) == " Using " && logMessage.Substring(logMessage.Length - 3, 3) == "...") { // using log message (Using one of X items...) var values = Parser.ParseUsingMessage(logMessage); if (!res.usingMessages.ContainsKey(values.Item1)) { res.usingMessages.Add(values.Item1, new Dictionary <string, HashSet <int> >()); } if (!res.usingMessages[values.Item1].ContainsKey(t)) { res.usingMessages[values.Item1].Add(t, new HashSet <int>()); } res.usingMessages[values.Item1][t].Add(values.Item2); continue; } else { foreach (Event ev in StorageManager.eventIdMap.Values) { foreach (string evMessage in ev.eventMessages) { if (logMessage.Length == evMessage.Length + 6 && logMessage.Contains(evMessage.Trim(), StringComparison.OrdinalIgnoreCase)) { res.eventMessages.Add(new Tuple <Event, string>(ev, logMessage)); } } } } } } } if (readChatMessages) { if (message.Contains(':')) { if (logMessage.Length > 14 && logMessage.Substring(5, 9) == " Loot of ") // loot drop message { continue; } else // if the message contains the ':' symbol but is not a loot drop message, it is a chat message, i.e. a command or url // we only split at most once, because the chat message can contain the ':' symbol as well and we don't want to discard that { string[] split = message.Split(new char[] { ':' }, 2); string command = split[1]; // now get the player name, we have to discard the level that is between brackets // players can also have spaces in their name, so we take that into account string[] playersplit = split[0].Split(' '); string player = ""; foreach (string str in playersplit) { if (str.Contains('[')) { break; } player = (player == "" ? player : player + " ") + str; } if (player == "http" || player == "https") { continue; // I don't remember why we do this, possible http link in a log message? not sure } if (command.Contains('@')) { // @ symbol symbolizes a command, so if there is an @ symbol, we treat the string as a command if (!res.commands.ContainsKey(t)) { res.commands.Add(t, new List <Tuple <string, string> >()); } res.commands[t].Add(new Tuple <string, string>(player, command)); } else if (command.Contains("www") || command.Contains("http") || command.Contains(".com") || command.Contains(".net") || command.Contains(".tv") || command.Contains(".br")) { // check if the command is an url, we aren't really smart about this, just check for a couple of common url-like things if (!res.urls.ContainsKey(t)) { res.urls.Add(t, new List <Tuple <string, string> >()); } res.urls[t].Add(new Tuple <string, string>(player, command)); } } } } } }
/// <summary> /// Scan the memory for any chunks that are missing from the whitelist table /// </summary> public static void ScanMissingChunks() { if (UseInternalScan) { return; // If we are scanning the internal tabs structure, we do not need to scan missing chunks } SYSTEM_INFO sys_info; GetSystemInfo(out sys_info); IntPtr proc_min_address = sys_info.minimumApplicationAddress; IntPtr proc_max_address = sys_info.maximumApplicationAddress; long proc_min_address_l = (long)proc_min_address; long proc_max_address_l = (long)proc_max_address; long sys_min_address_l = (long)proc_min_address; Process[] processes = ProcessManager.GetTibiaProcesses(); if (processes == null || processes.Length == 0) { return; } flashClient = ProcessManager.IsFlashClient(); var newWhitelistedAddresses = whiteListedAddresses.ToDictionary(x => x.Key, x => new HashSet <long>(x.Value)); foreach (Process process in processes) { HashSet <long> whitelist; if (!newWhitelistedAddresses.TryGetValue(process.Id, out whitelist)) { whitelist = new HashSet <long>(); newWhitelistedAddresses[process.Id] = whitelist; } proc_min_address_l = sys_min_address_l; IntPtr processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_WM_READ, false, process.Id); MEMORY_BASIC_INFORMATION mem_basic_info; List <int> stamps = TimestampManager.getLatestStamps(3, ignoreStamp); int bytesRead = 0; // number of bytes read with ReadProcessMemory try { while (proc_min_address_l < proc_max_address_l) { proc_min_address = new IntPtr(proc_min_address_l); // 28 = sizeof(MEMORY_BASIC_INFORMATION) VirtualQueryEx(processHandle, proc_min_address, out mem_basic_info, 28); long addr = (long)proc_min_address; // check if this memory chunk is accessible if (mem_basic_info.Protect == PAGE_READWRITE && mem_basic_info.State == MEM_COMMIT) { if (!whitelist.Contains(addr)) { if (missingChunksBuffer == null || missingChunksBuffer.Length < mem_basic_info.RegionSize) { missingChunksBuffer = new byte[mem_basic_info.RegionSize]; } // read everything in the buffer above ReadProcessMemory((int)processHandle, mem_basic_info.BaseAddress, missingChunksBuffer, mem_basic_info.RegionSize, ref bytesRead); // scan the memory for strings that start with timestamps and end with the null terminator ('\0') IEnumerable <string> timestampLines; if (!flashClient) { timestampLines = Parser.FindTimestamps(missingChunksBuffer, bytesRead); // if there are any timestamps found, add the address to the list of whitelisted addresses if (timestampLines.Any(x => stamps.Contains(TimestampManager.getStamp(int.Parse(x.Substring(0, 2)), int.Parse(x.Substring(3, 2)))))) { whitelist.Add(addr); } } else { if (Parser.HasAnyValidTimestampsFlash(missingChunksBuffer, bytesRead, stamps)) { whitelist.Add(addr); } } } } // move to the next memory chunk proc_min_address_l += mem_basic_info.RegionSize; } } catch (Exception ex) { Console.WriteLine(ex.Message); return; } } Interlocked.Exchange(ref whiteListedAddresses, newWhitelistedAddresses); }
public static void Initialize() { ignoreStamp = TimestampManager.createStamp(); }
public static ParseMemoryResults ParseLogResults(ReadMemoryResults res) { if (res == null) { return(null); } ParseMemoryResults o = new ParseMemoryResults(); // first we add the new parsed damage logs to the totalDamageResults o.newDamage = GlobalDataManager.UpdateDamageInformation(res.damageDealt); // now that we have updated the damage results, fill in the DPS meter, we use damage from the last 15 minutes for this List <string> times = TimestampManager.getLatestTimes(15); GlobalDataManager.GenerateDamageResults(o.damagePerSecond, times); // similar to damage, we keep a totalExperienceResults list // first update it with the new information int newExperience = GlobalDataManager.UpdateExperience(res.exp); // now compute the experience per hour // we use the same formula Tibia itself does so we get the same value // this formula is basically, take the experience in the last 15 minutes and multiply it by 4 o.expPerHour = GlobalDataManager.GetExperiencePerHour(); // Parse event messages foreach (Tuple <Event, string> newEvent in GlobalDataManager.UpdateEventInformation(res.eventMessages)) { o.newEventMessages.Add(newEvent); } // Update the look information foreach (string newLook in GlobalDataManager.UpdateLookInformation(res.lookMessages)) { o.newLooks.Add(newLook); } // Update death information o.death = GlobalDataManager.UpdateDeaths(res.deaths); // now parse any new commands given by users foreach (string newCommand in GlobalDataManager.UpdateCommands(res.commands)) { o.newCommands.Add(newCommand); } // check new urls GlobalDataManager.UpdateURLs(res.urls); HuntManager.AddUsedItems(HuntManager.activeHunt, res.usingMessages); Parser.ParseLootMessages(HuntManager.activeHunt, res.itemDrops, o.newItems, true, true); HuntManager.activeHunt.totalExp += newExperience; readWatch.Stop(); if (newExperience == 0) { if (ticksSinceExperience < 120) { ticksSinceExperience += readWatch.Elapsed.TotalSeconds; } } else { ticksSinceExperience = 0; } if (ticksSinceExperience < 120) { HuntManager.activeHunt.totalTime += readWatch.Elapsed.TotalSeconds; } readWatch.Restart(); HuntManager.SaveHunts(); return(o); }
public static void ParseLootMessages(Hunt h, Dictionary <string, List <string> > newDrops, List <Tuple <Creature, List <Tuple <Item, int> >, string> > newItems, bool commit = true, bool switchHunt = false, bool addEverything = false) { SQLiteTransaction transaction = null; if (commit) { transaction = LootDatabaseManager.BeginTransaction(); } int stamp = TimestampManager.getDayStamp(); Dictionary <string, List <string> > itemDrops = addEverything ? new Dictionary <string, List <string> >() : globalMessages; // now the big one: parse the log messages and check the dropped items foreach (KeyValuePair <string, List <string> > kvp in newDrops) { string t = kvp.Key; List <string> itemList = kvp.Value; if (!itemDrops.ContainsKey(t)) { itemDrops.Add(t, new List <string>()); } if (itemList.Count > itemDrops[t].Count) { int hour = int.Parse(t.Substring(0, 2)); int minute = int.Parse(t.Substring(3, 2)); foreach (string message in itemList) { if (!itemDrops[t].Contains(message)) { // new log message, scan it for new items Tuple <Creature, List <Tuple <Item, int> > > resultList = ParseLootMessage(message); if (resultList == null) { continue; } Creature cr = resultList.Item1; if (switchHunt && commit) { h = HuntManager.CheckTrackedHunts(h, resultList, t, message, stamp, hour, minute, transaction); } HuntManager.AddKillToHunt(h, resultList, t, message, stamp, hour, minute, transaction); if (newItems != null && MainForm.fileWriter != null && SettingsManager.getSettingBool("AutomaticallyWriteLootToFile")) { MainForm.fileWriter.WriteLine(message); MainForm.fileWriter.Flush(); } if (newItems != null) { newItems.Add(new Tuple <Creature, List <Tuple <Item, int> >, string>(resultList.Item1, resultList.Item2, message)); } } else { itemDrops[t].Remove(message); } } itemDrops[t] = itemList; } } if (transaction != null) { transaction.Commit(); } }
private static bool SearchChunk(IEnumerable <string> chunk, ReadMemoryResults res) { List <int> stamps = TimestampManager.getLatestStamps(3, ignoreStamp); bool chunksExist = false; foreach (string it in chunk) { chunksExist = true; string logMessage = it; string t = logMessage.Substring(0, 5); int hour = int.Parse(logMessage.Substring(0, 2)); int minute = int.Parse(logMessage.Substring(3, 2)); if (!stamps.Contains(TimestampManager.getStamp(hour, minute))) { continue; // the log message is not recent, so we skip parsing it } if (flashClient) { // there is some inconsistency with log messages, certain log messages use "12:00: Message.", others use "12:00 Message" // if there is a : after the timestamp we remove it if (logMessage[5] == ':') { logMessage = logMessage.Remove(5, 1); } } string message = logMessage.Substring(6); // message without timestamp if (logMessage.Length > 14 && logMessage.Substring(5, 9) == " You see ") { // the message contains "you see", so it's a look message if (!res.lookMessages.ContainsKey(t)) { res.lookMessages.Add(t, new List <string>()); } res.lookMessages[t].Add(logMessage); } else if (message.Contains(':')) { if (logMessage.Length > 14 && logMessage.Substring(5, 9) == " Loot of ") // loot drop message { if (!res.itemDrops.ContainsKey(t)) { res.itemDrops.Add(t, new List <string>()); } res.itemDrops[t].Add(logMessage); } else // if the message contains the ':' symbol but is not a loot drop message, it is a chat message, i.e. a command or url // we only split at most once, because the chat message can contain the ':' symbol as well and we don't want to discard that { string[] split = message.Split(new char[] { ':' }, 2); string command = split[1]; // now get the player name, we have to discard the level that is between brackets // players can also have spaces in their name, so we take that into account string[] playersplit = split[0].Split(' '); string player = ""; foreach (string str in playersplit) { if (str.Contains('[')) { break; } player = (player == "" ? player : player + " ") + str; } if (player == "http" || player == "https") { continue; // I don't remember why we do this, possible http link in a log message? not sure } if (command.Contains('@')) { // @ symbol symbolizes a command, so if there is an @ symbol, we treat the string as a command if (!res.commands.ContainsKey(t)) { res.commands.Add(t, new List <Tuple <string, string> >()); } res.commands[t].Add(new Tuple <string, string>(player, command)); } else if (command.Contains("www") || command.Contains("http") || command.Contains(".com") || command.Contains(".net") || command.Contains(".tv") || command.Contains(".br")) { // check if the command is an url, we aren't really smart about this, just check for a couple of common url-like things if (!res.urls.ContainsKey(t)) { res.urls.Add(t, new List <Tuple <string, string> >()); } res.urls[t].Add(new Tuple <string, string>(player, command)); } } } else if (logMessage.Length > 17 && logMessage.Substring(5, 12) == " You gained ") { // the message is an experience string, "You gained x experience." try { int experience = int.Parse(logMessage.Substring(17).Split(' ')[0]); if (!res.exp.ContainsKey(t)) { res.exp.Add(t, experience); } else { res.exp[t] = res.exp[t] + experience; } } catch { continue; } } else if (logMessage.Length == 19 && logMessage.Substring(5, 14) == " You are dead.") { if (!res.deaths.ContainsKey(t)) { res.deaths.Add(t, true); } } else if (logMessage.Length > 18) { string[] split = message.Split(' '); if (split.Contains("hitpoints") && split.ToList().IndexOf("hitpoints") > 0) { // damage log message (X loses Y hitpoints due to an attack by Z.) int damage = 0; if (!int.TryParse(split[split.ToList().IndexOf("hitpoints") - 1], out damage)) { continue; } string player; if (logMessage.Substring(logMessage.Length - 12) == "your attack.") { // X lost Y hitpoints because of your attack. // attacker is the player himself player = "You"; } else { // X lost Y hitpoints because of an attack by Z. // Z is the attacker => after the word "by" if (!split.Contains("by")) { continue; } player = ""; int ind = split.ToList().IndexOf("by") + 1; for (int i = ind; i < split.Length; i++) { player = (player == "" ? player : player + " ") + split[i]; } } if (!res.damageDealt.ContainsKey(player)) { res.damageDealt.Add(player, new Dictionary <string, int>()); } if (!res.damageDealt[player].ContainsKey(t)) { res.damageDealt[player].Add(t, damage); } else { res.damageDealt[player][t] = res.damageDealt[player][t] + damage; } } else if (logMessage.Substring(5, 14) == " You advanced " && logMessage.Contains("level", StringComparison.OrdinalIgnoreCase)) { // advancement log message (You advanced from level x to level x + 1.) if (logMessage[logMessage.Length - 1] == '.') { if (GlobalDataManager.AddLevelAdvance(logMessage)) { res.newAdvances.Add(logMessage); } } } else { foreach (Event ev in StorageManager.eventIdMap.Values) { foreach (string evMessage in ev.eventMessages) { if (logMessage.Length == evMessage.Length + 6 && logMessage.Contains(evMessage.Trim(), StringComparison.OrdinalIgnoreCase)) { res.eventMessages.Add(new Tuple <Event, string>(ev, logMessage)); } } } } } } return(chunksExist); }
public static bool ExecuteCommand(string command, ParseMemoryResults parseMemoryResults = null) { try { if (parseMemoryResults == null) { parseMemoryResults = ScanningManager.lastResults; } string comp = command.Trim().ToLower(); Console.WriteLine(command); if (comp.StartsWith("creature" + Constants.CommandSymbol)) //creature@ { string[] split = command.Split(Constants.CommandSymbol); string parameter = split[1].Trim().ToLower(); Creature cr = StorageManager.getCreature(parameter); if (cr != null) { NotificationManager.ShowCreatureDrops(cr, command); } else { List <TibiaObject> creatures = StorageManager.searchCreature(parameter); if (creatures.Count == 1) { NotificationManager.ShowCreatureDrops(creatures[0].AsCreature(), command); } else if (creatures.Count > 1) { NotificationManager.ShowCreatureList(creatures, "Creature List", command); } } } else if (comp.StartsWith("look" + Constants.CommandSymbol)) //look@ { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); if (parameter == "on") { SettingsManager.setSetting("LookMode", "True"); } else if (parameter == "off") { SettingsManager.setSetting("LookMode", "False"); } else { List <string> times = TimestampManager.getLatestTimes(5); List <TibiaObject> items = new List <TibiaObject>(); foreach (string message in GlobalDataManager.GetLookInformation(times)) { string itemName = Parser.parseLookItem(message).ToLower(); Item item = StorageManager.getItem(itemName); if (item != null) { items.Add(item); } else { Creature cr = StorageManager.getCreature(itemName); if (cr != null) { items.Add(cr); } } } if (items.Count == 1) { if (items[0] is Item) { NotificationManager.ShowItemNotification("item" + Constants.CommandSymbol + items[0].GetName().ToLower()); } else if (items[0] is Creature) { NotificationManager.ShowCreatureDrops(items[0].AsCreature(), command); } } else if (items.Count > 1) { NotificationManager.ShowCreatureList(items, "Looked At Items", command); } } } else if (comp.StartsWith("stats" + Constants.CommandSymbol)) //stats@ { string name = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); Creature cr = StorageManager.getCreature(name); if (cr != null) { NotificationManager.ShowCreatureStats(cr, command); } } else if (comp.StartsWith("close" + Constants.CommandSymbol)) //close@ // close all notifications { NotificationManager.ClearNotifications(); PopupManager.ClearSimpleNotifications(); } else if (comp.StartsWith("delete" + Constants.CommandSymbol)) //delete@ { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); int killCount; if (int.TryParse(parameter, out killCount)) { HuntManager.deleteCreatureWithThreshold(killCount); } else { Creature cr = StorageManager.getCreature(parameter); if (cr != null) { HuntManager.deleteCreatureFromLog(cr); } } } else if (comp.StartsWith("skin" + Constants.CommandSymbol)) //skin@ { string[] split = command.Split(Constants.CommandSymbol); string parameter = split[1].Trim().ToLower(); int count = 1; Creature cr = StorageManager.getCreature(parameter); if (cr != null) { if (split.Length > 2) { int.TryParse(split[2], out count); } HuntManager.InsertSkin(cr, count); } else { int.TryParse(parameter, out count); // find creature with highest killcount with a skin and skin that cr = HuntManager.GetHighestKillCreature(HuntManager.activeHunt); if (cr != null) { HuntManager.InsertSkin(cr, count); } } } else if (comp.StartsWith("city" + Constants.CommandSymbol)) //city@ { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); if (StorageManager.cityNameMap.ContainsKey(parameter)) { City city = StorageManager.cityNameMap[parameter]; NotificationManager.ShowCityDisplayForm(city, command); } } else if (comp.StartsWith("damage" + Constants.CommandSymbol)) //damage@ { if (parseMemoryResults != null) { string[] splits = command.Split(Constants.CommandSymbol); string screenshot_path = ""; string parameter = splits[1].Trim().ToLower(); if (parameter == "screenshot" && splits.Length > 2) { parameter = ""; screenshot_path = splits[2]; } NotificationManager.ShowDamageMeter(parseMemoryResults.damagePerSecond, command, parameter, screenshot_path); } } else if (comp.StartsWith("experience" + Constants.CommandSymbol)) //experience@ { if (parseMemoryResults != null) { NotificationManager.ShowExperienceChartNotification(command); } } else if (comp.StartsWith("remindme" + Constants.CommandSymbol)) //remindme@ { string[] splits = command.Split(Constants.CommandSymbol); string time = splits[1].ToLower().Replace(" ", "").Replace("\t", "").Replace("\n", "") + 's'; //remove all whitespace int timeInSeconds = 0; int startIndex = 0, endIndex = 0; for (int i = 0; i < time.Length; i++) { if (time[i].isDigit()) { endIndex = i + 1; } else if (endIndex > startIndex) { int value = int.Parse(time.Substring(startIndex, endIndex - startIndex)); if (time[i] == 'm') { value *= 60; } else if (time[i] == 'h') { value *= 3600; } timeInSeconds += value; startIndex = i + 1; endIndex = startIndex; } else { startIndex = i + 1; } } if (timeInSeconds > 0) { Image iconImage = null; if (splits.Length > 4) { string icon = splits[4]; TibiaObject[] objects = new TibiaObject[] { StorageManager.getItem(icon), StorageManager.getCreature(icon), StorageManager.getNPC(icon), StorageManager.getMount(icon), StorageManager.getSpell(icon), StorageManager.getOutfit(icon) }; foreach (var obj in objects) { if (obj != null) { iconImage = obj.GetImage(); if (iconImage != null) { break; } } } } string title = splits.Length > 2 ? splits[2] : "Reminder!"; string message = splits.Length > 3 ? splits[3] : String.Format("Reminder from {0} seconds ago!", timeInSeconds); const int notificationWarningTime = 5; if (timeInSeconds <= notificationWarningTime) { PopupManager.ShowSimpleNotification(new SimpleTimerNotification(iconImage, title, message, timeInSeconds)); } else { System.Timers.Timer timer = new System.Timers.Timer(1000 * (timeInSeconds - notificationWarningTime)); timer.Elapsed += (sender, e) => { timer.Enabled = false; timer.Dispose(); MainForm.mainForm.Invoke((MethodInvoker) delegate { PopupManager.ShowSimpleNotification(new SimpleTimerNotification(iconImage, title, message, notificationWarningTime)); }); }; timer.Enabled = true; } } } else if (comp.StartsWith("exp" + Constants.CommandSymbol)) //exp@ { string title = "Experience"; string text = "Currently gaining " + (parseMemoryResults == null ? "unknown" : ((int)parseMemoryResults.expPerHour).ToString()) + " experience an hour."; Image image = StyleManager.GetImage("tibia.png"); if (!SettingsManager.getSettingBool("UseRichNotificationType")) { PopupManager.ShowSimpleNotification(title, text, image); } else { PopupManager.ShowSimpleNotification(new SimpleTextNotification(null, title, text)); } } else if (comp.StartsWith("waste" + Constants.CommandSymbol)) //waste@ { NotificationManager.ShowWasteForm(HuntManager.activeHunt, command); } else if (comp.StartsWith("summary" + Constants.CommandSymbol)) //summary@ { NotificationManager.ShowSummaryForm(command); } else if (comp.StartsWith("loot" + Constants.CommandSymbol)) //loot@ { string[] splits = command.Split(Constants.CommandSymbol); string screenshot_path = ""; string parameter = splits[1].Trim().ToLower(); if (parameter == "screenshot" && splits.Length > 2) { parameter = ""; screenshot_path = splits[2]; } Hunt currentHunt = HuntManager.activeHunt; if (splits.Length >= 2 && splits[1] != "") { Hunt h = HuntManager.GetHunt(splits[1]); if (h != null) { currentHunt = h; } } // display loot notification NotificationManager.ShowLootDrops(currentHunt, command, screenshot_path); } else if (comp.StartsWith("clipboard" + Constants.CommandSymbol)) //clipboard@ // Copy loot message to the clipboard // clipboard@damage copies the damage information to the clipboard // clipboard@<creature> copies the loot of a specific creature to the clipboard // clipboard@ copies all loot to the clipboard { string creatureName = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); Creature lootCreature = null; if (creatureName == "damage" && parseMemoryResults != null) { var damageInformation = DamageChart.GenerateDamageInformation(parseMemoryResults.damagePerSecond, ""); string damageString = "Damage Dealt: "; foreach (var damage in damageInformation) { damageString += String.Format("{0}: {1:N1}%; ", damage.name, damage.percentage); } Clipboard.SetText(damageString.Substring(0, damageString.Length - 2)); return(true); } else if (creatureName != "") { lootCreature = StorageManager.getCreature(creatureName); } var tpl = LootDropForm.GenerateLootInformation(HuntManager.activeHunt, "", lootCreature); var creatureKills = tpl.Item1; var itemDrops = tpl.Item2; string lootString = ""; if (creatureKills.Count == 1) { foreach (KeyValuePair <Creature, int> kvp in creatureKills) { lootString = "Total Loot of " + kvp.Value.ToString() + " " + kvp.Key.GetName() + (kvp.Value > 1 ? "s" : "") + ": "; } } else { int totalKills = 0; foreach (KeyValuePair <Creature, int> kvp in creatureKills) { totalKills += kvp.Value; } lootString = "Total Loot of " + totalKills + " Kills: "; } foreach (Tuple <Item, int> kvp in itemDrops) { lootString += kvp.Item2 + " " + kvp.Item1.displayname + (kvp.Item2 > 1 ? "s" : "") + ", "; } lootString = lootString.Substring(0, lootString.Length - 2) + "."; Clipboard.SetText(lootString); } else if (comp.StartsWith("reset" + Constants.CommandSymbol)) //reset@ { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); int time = 0; if (parameter == "old") { HuntManager.clearOldLog(HuntManager.activeHunt); } else if (int.TryParse(parameter, out time) && time > 0) { HuntManager.clearOldLog(HuntManager.activeHunt, time); } else { // reset@<hunt> resets the specified hunt if (parameter.Length > 0 && HuntManager.resetHunt(parameter)) { return(true); } else { //reset@ deletes all loot from the currently active hunt HuntManager.resetHunt(HuntManager.activeHunt); } } MainForm.mainForm.refreshHunts(); ReadMemoryManager.ignoreStamp = TimestampManager.createStamp(); } else if (comp.StartsWith("refresh" + Constants.CommandSymbol)) //refresh@ // refresh: refresh duration on current form, or if no current form, repeat last command without removing it from stack /*if (tooltipForm != null && !tooltipForm.IsDisposed) { * try { * (tooltipForm as NotificationForm).ResetTimer(); * } catch { * } * } else if (command_stack.Count > 0) {*/ { ExecuteCommand(NotificationManager.LastCommand().command); //} return(true); } else if (comp.StartsWith("switch" + Constants.CommandSymbol)) //switch@ // switch: switch to hunt { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); HuntManager.SwitchHunt(parameter); HuntManager.SaveHunts(); } else if (comp.StartsWith("item" + Constants.CommandSymbol)) //item@ //show the item with all the NPCs that sell it { NotificationManager.ShowItemNotification(command); } else if (comp.StartsWith("task" + Constants.CommandSymbol)) //task@ { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); if (StorageManager.taskList.Keys.Contains(parameter)) { NotificationManager.ShowCreatureList(StorageManager.taskList[parameter].ToList <TibiaObject>(), StorageManager.taskList[parameter][0].groupname, command); } else { int id = -1; int.TryParse(parameter, out id); List <TibiaObject> tasks = new List <TibiaObject>(); foreach (KeyValuePair <string, List <Task> > kvp in StorageManager.taskList) { foreach (Task t in kvp.Value) { if (id >= 0 && t.id == id) { NotificationManager.ShowTaskNotification(t, command); return(true); } else { if (t.GetName().Contains(parameter, StringComparison.OrdinalIgnoreCase)) { tasks.Add(t); } } } } if (tasks.Count == 1) { NotificationManager.ShowTaskNotification(tasks[0] as Task, command); } else { NotificationManager.ShowCreatureList(tasks, String.Format("Tasks Containing \"{0}\"", parameter), command); } } } else if (comp.StartsWith("category" + Constants.CommandSymbol)) //category@ // list all items with the specified category { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); List <TibiaObject> items = StorageManager.getItemsByCategory(parameter); if (items.Count == 1) { NotificationManager.ShowItemNotification("item" + Constants.CommandSymbol + items[0].GetName().ToLower()); } else if (items.Count > 1) { NotificationManager.ShowCreatureList(items, "Category: " + parameter, command, true); } } else if (comp.StartsWith("hunt" + Constants.CommandSymbol)) //hunt@ { string[] splits = command.Split(Constants.CommandSymbol); string parameter = splits[1].Trim().ToLower(); int page = 0; if (splits.Length > 2 && int.TryParse(splits[2], out page)) { } if (Constants.cities.Contains(parameter)) { List <HuntingPlace> huntingPlaces = StorageManager.getHuntsInCity(parameter); NotificationManager.ShowCreatureList(huntingPlaces.ToList <TibiaObject>(), "Hunts in " + parameter, command); return(true); } HuntingPlace h = StorageManager.getHunt(parameter); if (h != null) { NotificationManager.ShowHuntingPlace(h, command); return(true); } Creature cr = StorageManager.getCreature(parameter); if (cr != null) { List <HuntingPlace> huntingPlaces = StorageManager.getHuntsForCreature(cr.id); NotificationManager.ShowCreatureList(huntingPlaces.ToList <TibiaObject>(), "Hunts containing creature " + parameter.ToTitle(), command); return(true); } int minlevel = -1, maxlevel = -1; int level; if (int.TryParse(parameter, out level)) { minlevel = (int)(level * 0.8); maxlevel = (int)(level * 1.2); } else if (parameter.Contains('-')) { string[] split = parameter.Split('-'); int.TryParse(split[0].Trim(), out minlevel); int.TryParse(split[1].Trim(), out maxlevel); } if (minlevel >= 0 && maxlevel >= 0) { List <HuntingPlace> huntingPlaces = StorageManager.getHuntsForLevels(minlevel, maxlevel); huntingPlaces = huntingPlaces.OrderBy(o => o.level).ToList(); NotificationManager.ShowCreatureList(huntingPlaces.ToList <TibiaObject>(), "Hunts between levels " + minlevel.ToString() + "-" + maxlevel.ToString(), command); return(true); } else { string title; List <HuntingPlace> huntList = StorageManager.searchHunt(parameter); title = "Hunts Containing \"" + parameter + "\""; if (huntList.Count == 1) { NotificationManager.ShowHuntingPlace(huntList[0], command); } else if (huntList.Count > 1) { NotificationManager.ShowCreatureList(huntList.ToList <TibiaObject>(), title, command); } } } else if (comp.StartsWith("npc" + Constants.CommandSymbol)) //npc@ { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); NPC npc = StorageManager.getNPC(parameter); if (npc != null) { NotificationManager.ShowNPCForm(npc, command); } else if (Constants.cities.Contains(parameter)) { NotificationManager.ShowCreatureList(StorageManager.getNPCWithCity(parameter), "NPC List", command); } else { NotificationManager.ShowCreatureList(StorageManager.searchNPC(parameter), "NPC List", command); } } else if (comp.StartsWith("savelog" + Constants.CommandSymbol)) { HuntManager.SaveLog(HuntManager.activeHunt, command.Split(Constants.CommandSymbol)[1].Trim().Replace("'", "\\'")); } else if (comp.StartsWith("loadlog" + Constants.CommandSymbol)) { HuntManager.LoadLog(HuntManager.activeHunt, command.Split(Constants.CommandSymbol)[1].Trim().Replace("'", "\\'")); } else if (comp.StartsWith("setdiscardgoldratio" + Constants.CommandSymbol)) { double val; if (double.TryParse(command.Split(Constants.CommandSymbol)[1].Trim(), out val)) { StorageManager.setGoldRatio(val); } } else if (comp.StartsWith("wiki" + Constants.CommandSymbol)) { string parameter = command.Split(Constants.CommandSymbol)[1].Trim(); string response = ""; using (WebClient client = new WebClient()) { response = client.DownloadString(String.Format("http://tibia.wikia.com/api/v1/Search/List?query={0}&limit=1&minArticleQuality=10&batch=1&namespaces=0", parameter)); } Regex regex = new Regex("\"url\":\"([^\"]+)\""); Match m = regex.Match(response); var gr = m.Groups[1]; MainForm.OpenUrl(gr.Value.Replace("\\/", "/")); } else if (comp.StartsWith("char" + Constants.CommandSymbol)) { string parameter = command.Split(Constants.CommandSymbol)[1].Trim(); MainForm.OpenUrl("https://secure.tibia.com/community/?subtopic=characters&name=" + parameter); } else if (comp.StartsWith("setconvertgoldratio" + Constants.CommandSymbol)) { string parameter = command.Split(Constants.CommandSymbol)[1].Trim(); string[] split = parameter.Split('-'); if (split.Length < 2) { return(true); } int stackable = 0; if (split[0] == "1") { stackable = 1; } double val; if (double.TryParse(split[1], out val)) { StorageManager.setConvertRatio(val, stackable == 1); } } else if (comp.StartsWith("recent" + Constants.CommandSymbol) || comp.StartsWith("url" + Constants.CommandSymbol) || comp.StartsWith("last" + Constants.CommandSymbol)) { bool url = comp.StartsWith("url" + Constants.CommandSymbol); int type = url ? 1 : 0; string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); if (comp.StartsWith("last" + Constants.CommandSymbol)) { parameter = "1"; } List <Command> command_list = GlobalDataManager.GetRecentCommands(type).Select(o => new Command() { player = o.Item1, command = o.Item2 }).ToList(); command_list.Reverse(); int number; //recent@<number> opens the last <number> command, so recent@1 opens the last command if (int.TryParse(parameter, out number)) { if (number > 0 && number <= command_list.Count) { ListNotification.OpenCommand(command_list[number - 1].command, type);; return(true); } } else { //recent@<player> opens the last bool found = false; foreach (Command comm in command_list) { if (comm.player.ToLower() == parameter) { ListNotification.OpenCommand(command_list[number].command, type); found = true; break; } } if (found) { return(true); } } NotificationManager.ShowListNotification(command_list, type, command); } else if (comp.StartsWith("spell" + Constants.CommandSymbol)) // spell@ { string[] splits = command.Split(Constants.CommandSymbol); string parameter = splits[1].Trim().ToLower(); int initialVocation = -1; if (splits.Length > 2 && int.TryParse(splits[2], out initialVocation)) { } Spell spell = StorageManager.getSpell(parameter); if (spell != null) { NotificationManager.ShowSpellNotification(spell, initialVocation, command); } else { List <TibiaObject> spellList = new List <TibiaObject>(); string title; if (Constants.vocations.Contains(parameter)) { spellList = StorageManager.getSpellsForVocation(parameter); title = parameter.ToTitle() + " Spells"; } else { spellList = StorageManager.searchSpell(parameter); if (spellList.Count == 0) { spellList = StorageManager.searchSpellWords(parameter); } title = "Spells Containing \"" + parameter + "\""; } if (spellList.Count == 1) { NotificationManager.ShowSpellNotification(spellList[0].AsSpell(), initialVocation, command); } else if (spellList.Count > 1) { NotificationManager.ShowCreatureList(spellList, title, command); } } } else if (comp.StartsWith("outfit" + Constants.CommandSymbol)) // outfit@ { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); Outfit outfit = StorageManager.getOutfit(parameter); if (outfit != null) { NotificationManager.ShowOutfitNotification(outfit, command); } else { string title; List <TibiaObject> outfitList = StorageManager.searchOutfit(parameter); title = "Outfits Containing \"" + parameter + "\""; if (outfitList.Count == 1) { NotificationManager.ShowOutfitNotification(outfitList[0].AsOutfit(), command); } else if (outfitList.Count > 1) { NotificationManager.ShowCreatureList(outfitList, title, command); } } } else if (comp.StartsWith("quest" + Constants.CommandSymbol)) // quest@ { string[] splits = command.Split(Constants.CommandSymbol); string parameter = splits[1].Trim().ToLower(); int page = 0; if (splits.Length > 2 && int.TryParse(splits[2], out page)) { } List <Quest> questList = new List <Quest>(); if (StorageManager.questNameMap.ContainsKey(parameter)) { NotificationManager.ShowQuestNotification(StorageManager.questNameMap[parameter], command); } else { string title; if (Constants.cities.Contains(parameter)) { title = "Quests In " + parameter; foreach (Quest q in StorageManager.questIdMap.Values) { if (q.city.ToLower() == parameter) { questList.Add(q); } } } else { title = "Quests Containing \"" + parameter + "\""; string[] splitStrings = parameter.Split(' '); foreach (Quest quest in StorageManager.questIdMap.Values) { bool found = true; foreach (string str in splitStrings) { if (!quest.name.Contains(str, StringComparison.OrdinalIgnoreCase)) { found = false; break; } } if (found) { questList.Add(quest); } } } if (questList.Count == 1) { NotificationManager.ShowQuestNotification(questList[0], command); } else if (questList.Count > 1) { NotificationManager.ShowCreatureList(questList.ToList <TibiaObject>(), title, command); //ShowQuestList(questList, title, command, page); } } } else if (comp.StartsWith("guide" + Constants.CommandSymbol)) // guide@ { string[] splits = command.Split(Constants.CommandSymbol); string parameter = splits[1].Trim().ToLower(); int page = 0; string mission = ""; if (splits.Length > 2 && int.TryParse(splits[2], out page)) { } if (splits.Length > 3) { mission = splits[3]; } List <Quest> questList = new List <Quest>(); if (StorageManager.questNameMap.ContainsKey(parameter)) { NotificationManager.ShowQuestGuideNotification(StorageManager.questNameMap[parameter], command, page, mission); } else { string title; foreach (Quest quest in StorageManager.questIdMap.Values) { if (quest.name.Contains(parameter, StringComparison.OrdinalIgnoreCase)) { questList.Add(quest); } } title = "Quests Containing \"" + parameter + "\""; if (questList.Count == 1) { NotificationManager.ShowQuestGuideNotification(questList[0], command, page, mission); } else if (questList.Count > 1) { NotificationManager.ShowCreatureList(questList.ToList <TibiaObject>(), title, command); } } } else if (comp.StartsWith("direction" + Constants.CommandSymbol)) // direction@ { string[] splits = command.Split(Constants.CommandSymbol); string parameter = splits[1].Trim().ToLower(); int page = 0; if (splits.Length > 2 && int.TryParse(splits[2], out page)) { } List <HuntingPlace> huntList = new List <HuntingPlace>(); HuntingPlace h = StorageManager.getHunt(parameter); if (h != null) { NotificationManager.ShowHuntGuideNotification(h, command, page); } else { string title; huntList = StorageManager.searchHunt(parameter); title = "Hunts Containing \"" + parameter + "\""; if (huntList.Count == 1) { NotificationManager.ShowHuntGuideNotification(huntList[0], command, page); } else if (huntList.Count > 1) { NotificationManager.ShowCreatureList(huntList.ToList <TibiaObject>(), title, command); } } } else if (comp.StartsWith("mount" + Constants.CommandSymbol)) // mount@ { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); Mount m = StorageManager.getMount(parameter); if (m != null) { NotificationManager.ShowMountNotification(m, command); } else { string title; List <TibiaObject> mountList = StorageManager.searchMount(parameter); title = "Mounts Containing \"" + parameter + "\""; if (mountList.Count == 1) { NotificationManager.ShowMountNotification(mountList[0].AsMount(), command); } else if (mountList.Count > 1) { NotificationManager.ShowCreatureList(mountList, title, command); } } } else if (comp.StartsWith("pickup" + Constants.CommandSymbol)) { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); Item item = StorageManager.getItem(parameter); if (item != null) { StorageManager.setItemDiscard(item, false); } } else if (comp.StartsWith("nopickup" + Constants.CommandSymbol)) { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); Item item = StorageManager.getItem(parameter); if (item != null) { StorageManager.setItemDiscard(item, true); } } else if (comp.StartsWith("convert" + Constants.CommandSymbol)) { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); Item item = StorageManager.getItem(parameter); if (item != null) { StorageManager.setItemConvert(item, true); } } else if (comp.StartsWith("noconvert" + Constants.CommandSymbol)) { string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); Item item = StorageManager.getItem(parameter); if (item != null) { StorageManager.setItemConvert(item, false); } } else if (comp.StartsWith("setval" + Constants.CommandSymbol)) { string parameter = command.Split(Constants.CommandSymbol)[1].Trim(); if (!parameter.Contains('=')) { return(true); } string[] split = parameter.Split('='); string item = split[0].Trim().ToLower().Replace("'", "\\'"); long value = 0; if (long.TryParse(split[1].Trim(), out value)) { Item it = StorageManager.getItem(split[0]); if (it != null) { StorageManager.setItemValue(it, value); } } } else if (comp.StartsWith("screenshot" + Constants.CommandSymbol)) { ScreenshotManager.saveScreenshot("Screenshot", ScreenshotManager.takeScreenshot()); } else { bool found = false; foreach (string city in Constants.cities) { if (comp.StartsWith(city + Constants.CommandSymbol)) { string itemName = command.Split(Constants.CommandSymbol)[1].Trim().ToLower(); Item item = StorageManager.getItem(itemName); if (item != null) { NPC npc = StorageManager.getNPCSellingItemInCity(item.id, city); if (npc != null) { NotificationManager.ShowNPCForm(npc, command); } } else { Spell spell = StorageManager.getSpell(itemName); if (spell != null) { NPC npc = StorageManager.getNPCTeachingSpellInCity(spell.id, city); if (npc != null) { NotificationManager.ShowNPCForm(npc, command); } } } found = true; } } // else try custom commands foreach (SystemCommand c in MainForm.mainForm.GetCustomCommands()) { if (c.tibialyzer_command.Trim().Length > 0 && comp.StartsWith(c.tibialyzer_command + Constants.CommandSymbol)) { string[] parameters = command.Split(Constants.CommandSymbol); string systemCallParameters = c.parameters; int i = 0; while (true) { if (systemCallParameters.Contains("{" + i.ToString() + "}")) { systemCallParameters = systemCallParameters.Replace("{" + i.ToString() + "}", parameters.Length > i + 1 ? parameters[i + 1].Trim() : ""); } else { break; } i++; } ProcessStartInfo procStartInfo = new ProcessStartInfo(c.command, systemCallParameters); procStartInfo.UseShellExecute = true; // Do not show the cmd window to the user. procStartInfo.CreateNoWindow = true; procStartInfo.WindowStyle = ProcessWindowStyle.Hidden; Process.Start(procStartInfo); return(true); } } if (found) { return(true); } //if we get here we didn't find any command return(false); } return(true); } catch (Exception e) { MainForm.mainForm.DisplayWarning(String.Format("Tibialyzer Exception While Processing Command \"{0}\".\nMessage: {1} ", command, e.Message)); Console.WriteLine(e.Message); return(true); } }