public static void ScanForOffsets() { ProcessModule mod = StyxWoW.Memory.Process.MainModule; var baseAddress = (uint)mod.BaseAddress; if (GlobalPBSettings.Instance.WowVersion != mod.FileVersionInfo.FileVersion || GlobalPBSettings.Instance.KnownSpellsPtr == 0) { PBLog.Log("Scanning for new offsets for WoW {0}", mod.FileVersionInfo.FileVersion); try { IntPtr pointer = FindPattern("00 00 00 00 C1 EA 05 23 04 91 F7 D8 1B C0 F7 D8 5D C3", "????xxxxxxxxxxxxxx"); GlobalPBSettings.Instance.KnownSpellsPtr = StyxWoW.Memory.Read <uint>(true, pointer) - baseAddress; PBLog.Log("Found KnownSpellsPtr offset 0x{0:X}", GlobalPBSettings.Instance.KnownSpellsPtr); GlobalPBSettings.Instance.WowVersion = mod.FileVersionInfo.FileVersion; GlobalPBSettings.Instance.Save(); } catch (InvalidDataException) { PBLog.Warn("There was a problem scanning for offsets"); } } }
private void LoadStrings() { Strings = new Dictionary <string, string>(); string directory = Path.Combine(BotPath, "Localization"); string defaultStringsPath = Path.Combine(directory, "Strings.xml"); LoadStringsFromXml(defaultStringsPath); // file that includes language and country/region string langAndCountryFile = Path.Combine(directory, "Strings." + Thread.CurrentThread.CurrentUICulture.Name + ".xml"); // file that includes language only; string langOnlyFile = Path.Combine( directory, "Strings." + Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName + ".xml"); if (File.Exists(langAndCountryFile)) { PBLog.Log("Loading strings for language {0}", Thread.CurrentThread.CurrentUICulture.Name); LoadStringsFromXml(langAndCountryFile); } else if (File.Exists(langOnlyFile)) { PBLog.Log("Loading strings for language {0}", Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName); LoadStringsFromXml(langOnlyFile); } }
/// <summary> /// Updates the skill level, recipe difficulty and adds new recipes. /// </summary> public void Update() { if (!StyxWoW.IsInGame) { return; } // if HB is not running then we should maybe pulse objectmanger for item counts if (!TreeRoot.IsRunning) { ObjectManager.Update(); } WoWSkill = StyxWoW.Me.GetSkill(SkillLine); Dictionary <uint, Recipe> oldList = KnownRecipes; // cycle through entire recipe list and check update the 'HasRecipe' property foreach (var recipe in Recipes) { recipe.Value.Update(); } IEnumerable <KeyValuePair <uint, Recipe> > newRecipies = KnownRecipes.Except(oldList); foreach (var kv in newRecipies) { PBLog.Log("Leaned a new recipe {0}", kv.Value.Name); using (StyxWoW.Memory.AcquireFrame()) { kv.Value.UpdateHeader(); } } PulseBags(); }
public static void Log( System.Windows.Media.Color headerColor, string header, System.Windows.Media.Color msgColor, string format, params object[] args) { PBLog.Log(headerColor, header, msgColor, format, args); }
public static void LoadPBProfile(string path, XElement element = null) { PbProfile profile = null; if (!string.IsNullOrEmpty(path)) { if (File.Exists(path)) { PBLog.Log("Loading profile {0} from file", Path.GetFileName(path)); profile = PbProfile.LoadFromFile(path); Instance.MySettings.LastProfile = path; } else { PBLog.Warn("Profile: {0} does not exist", path); Instance.MySettings.LastProfile = path; return; } } else if (element != null) { PBLog.Log("Loading profile from Xml element"); profile = PbProfile.LoadFromXml(element); } if (profile == null) { return; } Instance.CurrentProfile = profile; Instance.MySettings.LastProfile = path; Instance.ProfileSettings.Load(); DynamicCodeCompiler.GenorateDynamicCode(); Instance.UpdateMaterials(); if (MainForm.IsValid) { MainForm.Instance.InitActionTree(); MainForm.Instance.RefreshTradeSkillTabs(); } if (MainForm.IsValid) { MainForm.Instance.UpdateControls(); } Instance.MySettings.Save(); }
public void LoadTradeSkills() { var newTradeSkills = new List <TradeSkill>(); try { using (StyxWoW.Memory.AcquireFrame()) { foreach (WoWSkill skill in SupportedTradeSkills) { PBLog.Log("Adding TradeSkill {0}", skill.Name); TradeSkill ts = TradeSkill.GetTradeSkill((SkillLine)skill.Id); if (ts != null) { newTradeSkills.Add(ts); } else { IsTradeSkillsLoaded = false; PBLog.Log("Unable to load tradeskill {0}", (SkillLine)skill.Id); return; } } } } catch (Exception ex) { Logging.Write(Colors.Red, ex.ToString()); } finally { lock (tradeSkillLocker) { TradeSkillList = newTradeSkills; } PBLog.Log("Done Loading Tradeskills."); IsTradeSkillsLoaded = true; if (OnTradeSkillsLoaded != null) { OnTradeSkillsLoaded(this, null); } } }
private void ToolStripSaveClick(object sender, EventArgs e) { saveFileDialog.DefaultExt = "xml"; saveFileDialog.FilterIndex = 1; saveFileDialog.FileName = ProfessionbuddyBot.Instance.CurrentProfile != null && ProfessionbuddyBot.Instance.CurrentProfile.XmlPath != null ? ProfessionbuddyBot.Instance.CurrentProfile.XmlPath : ""; if (saveFileDialog.ShowDialog() == DialogResult.OK) { string extension = Path.GetExtension(saveFileDialog.FileName); bool zip = extension != null && extension.Equals( ".package", StringComparison.InvariantCultureIgnoreCase); // if we are saving to a zip check if CurrentProfile.XmlPath is not blank/null and use it if not. // otherwise use the selected zipname with xml ext. if (ProfessionbuddyBot.Instance.CurrentProfile != null) { string xmlfile = zip ? (ProfessionbuddyBot.Instance.CurrentProfile != null && string.IsNullOrEmpty(ProfessionbuddyBot.Instance.CurrentProfile.XmlPath) ? Path.ChangeExtension(saveFileDialog.FileName, ".xml") : ProfessionbuddyBot.Instance.CurrentProfile.XmlPath) : saveFileDialog.FileName; PBLog.Log("Saving profile to {0}", saveFileDialog.FileName); if (ProfessionbuddyBot.Instance.CurrentProfile != null) { ProfessionbuddyBot.Instance.CurrentProfile.SaveXml(xmlfile); if (zip) { PbProfile.CreatePackage(saveFileDialog.FileName, xmlfile); } } } ProfessionbuddyBot.Instance.MySettings.LastProfile = saveFileDialog.FileName; ProfessionbuddyBot.Instance.MySettings.Save(); UpdateControls(); } }
private static Composite FromXml(XElement xml, Composite comp) { var pbComponentTypes = (from type in Assembly.GetExecutingAssembly().GetTypes() where (typeof(IPBComponent)).IsAssignableFrom(type) && !type.IsAbstract let eleAttr = type.GetCustomAttribute <PBXmlElementAttribute>() where eleAttr != null select new { Type = type, EleAttr = eleAttr }).ToArray(); foreach (XNode node in xml.Nodes()) { if (node.NodeType == XmlNodeType.Comment) { comp.AddChild(new CommentAction(((XComment)node).Value)); continue; } if (node.NodeType != XmlNodeType.Element) { continue; } var element = (XElement)node; var elementName = element.Name.ToString(); var typeInfo = pbComponentTypes.FirstOrDefault( t => (string.IsNullOrEmpty(t.EleAttr.Name) && t.Type.Name == elementName) || t.EleAttr.Matches(elementName)); if (typeInfo == null) { throw new InvalidOperationException(string.Format("Unable to bind XML Element: {0} to a Type", element.Name)); } var pbComp = (IPBComponent)Activator.CreateInstance(typeInfo.Type); pbComp.OnProfileLoad(element); var pbXmlAttrs = (from pi in typeInfo.Type.GetProperties() let attrAttr = pi.GetCustomAttribute <PBXmlAttributeAttribute>() where attrAttr != null select new { PropInfo = pi, AttrAttr = attrAttr }).ToList(); Dictionary <string, string> attributes = element.Attributes().ToDictionary(k => k.Name.ToString(), v => v.Value); // use legacy X,Y,Z location for backwards compatability if (attributes.ContainsKey("X")) { string location = string.Format("{0},{1},{2}", attributes["X"], attributes["Y"], attributes["Z"]); var prop = pbXmlAttrs.Where( p => (string.IsNullOrEmpty(p.AttrAttr.Name) && p.PropInfo.Name == "Location") || p.AttrAttr.Matches("Location")) .Select(p => p.PropInfo) .FirstOrDefault(); if (prop != null) { prop.SetValue(pbComp, location, null); attributes.Remove("X"); attributes.Remove("Y"); attributes.Remove("Z"); } } foreach (var attr in attributes) { var propInfo = pbXmlAttrs.Where( p => (string.IsNullOrEmpty(p.AttrAttr.Name) && p.PropInfo.Name == attr.Key) || p.AttrAttr.Matches(attr.Key)) .Select(p => p.PropInfo).FirstOrDefault(); if (propInfo == null) { PBLog.Log("{0}->{1} appears to be unused", elementName, attr.Key); continue; } // check if there is a type converter attached var typeConverterAttr = (TypeConverterAttribute)propInfo.GetCustomAttributes(typeof(TypeConverterAttribute), true).FirstOrDefault(); if (typeConverterAttr != null) { try { var typeConverter = (TypeConverter)Activator.CreateInstance(Type.GetType(typeConverterAttr.ConverterTypeName)); if (typeConverter.CanConvertFrom(typeof(string))) { propInfo.SetValue(pbComp, typeConverter.ConvertFrom(null, CultureInfo.InvariantCulture, attr.Value), null); } else { PBLog.Warn("The Type Converter {0} can not convert from string.", typeConverterAttr.ConverterTypeName); } } catch (Exception ex) { PBLog.Warn("Type conversion for {0} has failed.\n{1}", typeInfo.Type.Name + attr.Key, ex); } } else { propInfo.SetValue( pbComp, propInfo.PropertyType.IsEnum ? Enum.Parse(propInfo.PropertyType, attr.Value) : Convert.ChangeType(attr.Value, propInfo.PropertyType, CultureInfo.InvariantCulture), null); } } if (pbComp is Composite) { FromXml(element, pbComp as Composite); } comp.AddChild((Component)pbComp); } return(comp); }
public static void Log(Color headerColor, string header, Color msgColor, string format, params object[] args) { PBLog.Log(headerColor, header, msgColor, format, args); }
public static void Log(string format, params object[] args) { PBLog.Log(format, args); }