public static void LoadNextProfile(string name = null, string path = null) { if (name != null) { int nextProfileIndex = profiles.IndexOf(profilePath + "\\" + name); if (nextProfileIndex == -1) { ProfileSwitcher.Log("Profile not found - check your Profile XML!"); } else { if (wasLastProfile()) { } else { LoadProfile(profiles[nextProfileIndex]); } } } else if (path != null) { if (tempProfileWasLoaded) { tempProfileWasLoaded = false; if (wasLastProfile(preDeathProfile)) { } else { LoadProfile(path); } } else { LoadProfile(path); } } else { if (tempProfileWasLoaded) { tempProfileWasLoaded = false; LoadProfile(getNextProfilePath(preDeathProfile)); } else { if (wasLastProfile()) { } else { LoadProfile(getNextProfilePath()); } } } ProfileSwitcher.deathRetries = 0; }
public static void readXml(XmlTextReader xml) { bool error = false; profileHandler.profileWaypoints.Clear(); while (xml.Read()) { switch (xml.NodeType) { case XmlNodeType.Element: Vector3 waypoint = new Vector3(); if (xml.Name == "MoveTo" || xml.Name == "UseWaypoint" || xml.Name == "UseObject") { try { xml.MoveToAttribute("x"); waypoint.X = float.Parse(xml.Value, System.Globalization.CultureInfo.CreateSpecificCulture("en-us")); } catch (Exception e) { ProfileSwitcher.Log(String.Format("x coordinate can't be parsed from xml; Element: {0} Line: {1} Position: {2}", xml.Name, xml.LineNumber, xml.LinePosition)); error = true; } try { xml.MoveToAttribute("y"); waypoint.Y = float.Parse(xml.Value, System.Globalization.CultureInfo.CreateSpecificCulture("en-us")); } catch (Exception e) { ProfileSwitcher.Log(String.Format("y coordinate can't be parsed from xml; Element: {0} Line: {1} Position: {2}", xml.Name, xml.LineNumber, xml.LinePosition)); error = true; } try { xml.MoveToAttribute("z"); waypoint.Z = float.Parse(xml.Value, System.Globalization.CultureInfo.CreateSpecificCulture("en-us")); } catch (Exception e) { ProfileSwitcher.Log(String.Format("z coordinate can't be parsed from xml; Element: {0} Line: {1} Position: {2}", xml.Name, xml.LineNumber, xml.LinePosition)); error = true; } } if (!error) { profileHandler.profileWaypoints.Add(waypoint); } else { error = false; ProfileSwitcher.Log("Ignoring Waypoint"); } break; } } }
public static void LoadProfile(string path) { DateTime currentDateTime = DateTime.Now; String dateStr = currentDateTime.ToString("dd.MM HH:mm:ss"); ProfileSwitcher.Logger("" + dateStr + " loading profile: " + path); ProfileSwitcher.startRunTimer(); ProfileSwitcher.deathRetries = 0; ProfileSwitcher.Log("Loading profile: " + path); ProfileManager.Load(path); }
public static bool LoadTempProfile() { float min = 150; xmlHandler.readXml(new XmlTextReader(preDeathProfile)); revivePosition = ZetaDia.Actors.Me.Position; Vector3 closestWP = new Vector3(); foreach (Vector3 wp in profileWaypoints) { if (Vector3.Distance(wp, ZetaDia.Actors.Me.Position) < min) { min = Vector3.Distance(wp, revivePosition); closestWP = wp; } } if ((int)min != 150) { ProfileSwitcher.Log("Closest profile waypoint: " + closestWP.ToString()); ProfileSwitcher.Log("Distance: " + min); ProfileSwitcher.Log("Generating temporary profile..."); string tmpProfile = xmlHandler.generateTempProfile(closestWP, preDeathProfile, getNextProfilePath(preDeathProfile)); ProfileSwitcher.Log("Loading temporary profile: " + tmpProfile); if (tmpProfile != null) { ProfileManager.Load(tmpProfile); } else { ProfileSwitcher.Log("Something went wrong while profile generation - reloading actual profile instead!"); ReloadProfile(); } tempProfileWasLoaded = true; return(true); } else { return(false); } }
public static bool wasLastProfile(string profile = null) { if (getNextProfilePath(profile) == getFirstProfilePath()) { ProfileSwitcher.Log("All profiles completed, logging out!."); if (!ZetaDia.Me.IsInTown) { ZetaDia.Service.Games.LeaveGame(); BotMain.PauseFor(System.TimeSpan.FromSeconds(15)); } else { ZetaDia.Service.Games.LeaveGame(); BotMain.PauseFor(System.TimeSpan.FromSeconds(2)); } return(true); } else { return(false); } }
public static string generateTempProfile(Vector3 nearestWaypoint, string currentProfile, string nextProfile) { bool indexWritten = false; bool foundWP = false; bool error = false; string[] whileAttrNames = new string[5]; string[] whileAttrValues = new string[5]; int j = 0; int ifindex = 0; int whileIndex = 0; DateTime currentDateTime = DateTime.Now; String dateStr = currentDateTime.ToString("yyyy-MM-dd HH_mm_ss"); string tmpProfilePath = Path.GetTempPath() + dateStr + ".xml"; XmlTextReader origProfile = new XmlTextReader(currentProfile); XmlTextWriter tempProfile = new XmlTextWriter(tmpProfilePath, null); tempProfile.Formatting = Formatting.Indented; tempProfile.WriteStartDocument(); while (origProfile.Read()) { switch (origProfile.NodeType) { case XmlNodeType.Element: tempProfile.Flush(); if (origProfile.Name == "Order") { tempProfile.WriteStartElement(origProfile.Name); indexWritten = true; break; } if (foundWP) { if (origProfile.Name == "nextProfile" || origProfile.Name == "Continue") { tempProfile.WriteStartElement("nextProfile"); tempProfile.WriteAttributeString("path", nextProfile); tempProfile.WriteEndElement(); break; } tempProfile.WriteStartElement(origProfile.Name); while (origProfile.MoveToNextAttribute()) { tempProfile.WriteAttributeString(origProfile.Name, origProfile.Value); } origProfile.MoveToElement(); if (origProfile.Name != "If" && origProfile.Name != "While" && origProfile.Name != "KillMonsters" && origProfile.Name != "PickupLoot" && origProfile.Name != "TargetBlacklists") { tempProfile.WriteEndElement(); } break; } if (!indexWritten) { tempProfile.WriteStartElement(origProfile.Name); if (origProfile.HasAttributes) { while (origProfile.MoveToNextAttribute()) { tempProfile.WriteAttributeString(origProfile.Name, origProfile.Value); } } origProfile.MoveToElement(); if (origProfile.Name == "GameParams" || origProfile.Name == "TargetBlacklist") { tempProfile.WriteEndElement(); } break; } if (indexWritten && origProfile.Name == "If" && !foundWP) { ifindex++; break; } if (indexWritten && origProfile.Name == "While" && !foundWP) { Array.Clear(whileAttrNames, 0, whileAttrNames.Length); Array.Clear(whileAttrValues, 0, whileAttrValues.Length); if (origProfile.HasAttributes) { for (int i = 0; i < origProfile.AttributeCount; i++) { origProfile.MoveToNextAttribute(); whileAttrNames[i] = origProfile.Name; whileAttrValues[i] = origProfile.Value; } } whileIndex = 1; break; } if (indexWritten && (origProfile.Name == "MoveTo" || origProfile.Name == "UseWaypoint" || origProfile.Name == "UseObject") && !foundWP) { ProfileSwitcher.Log("Searching WP..." + ++j); Vector3 waypoint = new Vector3(); error = false; try { origProfile.MoveToElement(); origProfile.MoveToAttribute("x"); waypoint.X = float.Parse(origProfile.Value, System.Globalization.CultureInfo.CreateSpecificCulture("en-us")); origProfile.MoveToElement(); origProfile.MoveToAttribute("y"); waypoint.Y = float.Parse(origProfile.Value, System.Globalization.CultureInfo.CreateSpecificCulture("en-us")); origProfile.MoveToElement(); origProfile.MoveToAttribute("z"); waypoint.Z = float.Parse(origProfile.Value, System.Globalization.CultureInfo.CreateSpecificCulture("en-us")); } catch (Exception e) { error = true; } origProfile.MoveToElement(); if (!error && (waypoint == nearestWaypoint)) { ProfileSwitcher.Log("Found WP:" + waypoint.ToString()); if (whileIndex == 1) { tempProfile.WriteStartElement("While"); for (int i = 0; i < whileAttrNames.Length; i++) { if (whileAttrNames[i] != null) { tempProfile.WriteAttributeString(whileAttrNames[i], whileAttrValues[i]); } } whileIndex = 0; } tempProfile.WriteStartElement(origProfile.Name); while (origProfile.MoveToNextAttribute()) { tempProfile.WriteAttributeString(origProfile.Name, origProfile.Value); } foundWP = true; tempProfile.WriteEndElement(); } else { //ProfileSwitcher.Log("Wrong waypoint: " + waypoint.ToString()); } break; } break; case XmlNodeType.Text: if (!indexWritten || foundWP) { tempProfile.WriteString(origProfile.Value); } break; case XmlNodeType.EndElement: if (indexWritten && !foundWP && (ifindex > 0)) { ifindex--; break; } if (indexWritten && !foundWP && (whileIndex == 1)) { whileIndex = 0; Array.Clear(whileAttrNames, 0, whileAttrNames.Length); Array.Clear(whileAttrValues, 0, whileAttrValues.Length); break; } if (!indexWritten || foundWP) { if (ifindex > 0) { ifindex--; break; } tempProfile.WriteFullEndElement(); } break; } } tempProfile.WriteEndDocument(); tempProfile.Flush(); tempProfile.Close(); if (foundWP) { return(tmpProfilePath); } else { return(null); } }
public static void updateProfiles() { int startIndex = 0; ProfileSwitcher.Log("Updating profiles..."); profilePath = ProfileSwitcher.profilesPath; profiles = Directory.GetFiles(profilePath, "*.xml"); if (ProfileSwitcher.profileRandomization == true) { string randomFilePath = profilePath + "\\random.txt"; Random randGenerator = new Random(DateTime.Now.Ticks.GetHashCode()); profilePriorities = new float[profiles.Length]; if (File.Exists(randomFilePath)) { using (StreamReader reader = new StreamReader(randomFilePath)) { string line; int i = 0; while (((line = reader.ReadLine()) != null) && (i < profiles.Length)) { int priority = Int32.Parse(line); if ((priority < 1) || (priority > 99) && (priority != 0)) { ProfileSwitcher.Log("Warning: Randomization priorities lower than 1 or higher than 99 can cause problems!!!"); } profilePriorities[i] = (float)priority; i++; } } } else { for (int i = 0; i < profiles.Length; i++) { ProfileSwitcher.Log(randomFilePath + " not found, Randomizing all profiles!"); profilePriorities[i] = (float)1; } } for (int i = 0; i < profilePriorities.Length; i++) { float multiplier = (float)randGenerator.Next(10000, 10100) / (float)10000.0; profilePriorities[i] = (float)profilePriorities[i] * multiplier; } randomProfiles = new string[profiles.Length]; Array.Copy(profiles, randomProfiles, profiles.Length); Array.Sort(profilePriorities, randomProfiles); startIndex = 0; for (int i = 0; i < profilePriorities.Length; i++) { if (profilePriorities[i] > 0.0) { startIndex = i; break; } } if (ZetaDia.IsInGame && Zeta.CommonBot.BotMain.IsRunning) { int counter = 0; ProfileSwitcher.Log("Randomized profiles for next run:"); ProfileSwitcher.Logger("Randomization order for this run:"); for (int i = 0; i < profilePriorities.Length; i++) { if (i >= startIndex) { ProfileSwitcher.Log((++counter) + ": " + randomProfiles[i]); ProfileSwitcher.Logger((counter) + ": " + randomProfiles[i]); } } ProfileSwitcher.Logger("\n"); } Array.Clear(profiles, 0, profiles.Length); Array.Copy(randomProfiles, startIndex, profiles, 0, randomProfiles.Length - startIndex); } }
public static void ReloadProfile() { ProfileSwitcher.startRunTimer(); ProfileSwitcher.Log("Loading profile: " + GlobalSettings.Instance.LastProfile); ProfileManager.Load(GlobalSettings.Instance.LastProfile); }