Beispiel #1
0
        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");
                }
            }
        }
 public void UpdateMaterials()
 {
     if (!_init)
     {
         return;
     }
     try
     {
         lock (materialLocker)
         {
             _materialList.Clear();
             List <CastSpellAction> castSpellList = CastSpellAction.GetCastSpellActionList(Branch);
             if (castSpellList != null)
             {
                 foreach (CastSpellAction ca in castSpellList)
                 {
                     if (ca.IsRecipe && ca.RepeatType != CastSpellAction.RepeatCalculationType.Craftable)
                     {
                         foreach (Ingredient ingred in ca.Recipe.Ingredients)
                         {
                             _materialList[ingred.ID] = _materialList.ContainsKey(ingred.ID)
                                                                         ? _materialList[ingred.ID] +
                                                        (ca.CalculatedRepeat > 0 ? (int)ingred.Required * (ca.CalculatedRepeat - ca.Casted) : 0)
                                                                         : (ca.CalculatedRepeat > 0 ? (int)ingred.Required * (ca.CalculatedRepeat - ca.Casted) : 0);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         PBLog.Warn(ex.ToString());
     }
 }
 private void OnBagUpdate(object obj, LuaEventArgs args)
 {
     if (_onBagUpdateTimer.IsFinished)
     {
         try
         {
             lock (tradeSkillLocker)
             {
                 foreach (TradeSkill ts in TradeSkillList)
                 {
                     ts.PulseBags();
                 }
                 UpdateMaterials();
                 if (MainForm.IsValid)
                 {
                     MainForm.Instance.RefreshTradeSkillTabs();
                     MainForm.Instance.RefreshActionTree(typeof(CastSpellAction));
                 }
             }
         }
         catch (Exception ex)
         {
             PBLog.Warn(ex.ToString());
         }
         _onBagUpdateTimer.Reset();
     }
 }
Beispiel #4
0
 private void LoadGlobalSettings()
 {
     if (File.Exists(GlobalSettingsPath))
     {
         using (XmlReader reader = XmlReader.Create(GlobalSettingsPath))
         {
             try
             {
                 var serializer = new DataContractSerializer(typeof(Dictionary <string, object>));
                 var temp       = (Dictionary <string, object>)serializer.ReadObject(reader);
                 if (temp != null)
                 {
                     foreach (var kv in temp)
                     {
                         SettingsDictionary[kv.Key] = new PbProfileSettingEntry {
                             Value = kv.Value
                         };
                     }
                 }
             }
             catch (Exception ex)
             {
                 PBLog.Warn(ex.ToString());
             }
         }
     }
 }
Beispiel #5
0
 private void ToolStripBotComboSelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         ProfessionbuddyBot.ChangeSecondaryBot((string)toolStripBotCombo.SelectedItem);
     }
     catch (Exception ex)
     {
         PBLog.Warn(ex.ToString());
     }
 }
        public static void ChangeSecondaryBot(string botName)
        {
            BotBase bot = Util.GetBotByName(botName);

            if (bot != null)
            {
                ChangeSecondaryBot(bot);
            }
            else
            {
                PBLog.Warn("Bot with name: {0} was not found", botName);
            }
        }
Beispiel #7
0
        public MainForm()
        {
            try
            {
                Instance = this;
                InitializeComponent();
                // assign the localized strings
                toolStripOpen.Text            = ProfessionbuddyBot.Instance.Strings["UI_FileOpen"];
                toolStripSave.Text            = ProfessionbuddyBot.Instance.Strings["UI_FileSave"];
                toolStripHelp.Text            = ProfessionbuddyBot.Instance.Strings["UI_Help"];
                toolStripCopy.Text            = ProfessionbuddyBot.Instance.Strings["UI_Copy"];
                toolStripCut.Text             = ProfessionbuddyBot.Instance.Strings["UI_Cut"];
                toolStripPaste.Text           = ProfessionbuddyBot.Instance.Strings["UI_Paste"];
                toolStripDelete.Text          = ProfessionbuddyBot.Instance.Strings["UI_Delete"];
                toolStripBotConfigButton.Text = ProfessionbuddyBot.Instance.Strings["UI_Settings"];
                ProfileTab.Text              = ProfessionbuddyBot.Instance.Strings["UI_Profiles"];
                ActionsColumn.HeaderText     = ActionsTab.Text = ProfessionbuddyBot.Instance.Strings["UI_Actions"];
                TradeSkillTab.Text           = ProfessionbuddyBot.Instance.Strings["UI_Tradeskill"];
                TabPageProfile.Text          = ProfessionbuddyBot.Instance.Strings["UI_Profile"];
                IngredientsColumn.HeaderText = ProfessionbuddyBot.Instance.Strings["UI_Ingredients"];
                NeedColumn.HeaderText        = ProfessionbuddyBot.Instance.Strings["UI_Need"];
                BagsColumn.HeaderText        = ProfessionbuddyBot.Instance.Strings["UI_Bags"];
                BankColumn.HeaderText        = ProfessionbuddyBot.Instance.Strings["UI_Bank"];
                toolStripAddBtn.Text         = ProfessionbuddyBot.Instance.Strings["UI_Add"];
                toolStripReloadBtn.Text      = ProfessionbuddyBot.Instance.Strings["UI_Reload"];
                LoadProfileButton.Text       = ProfessionbuddyBot.Instance.Strings["UI_LoadProfile"];

                saveFileDialog.InitialDirectory = ProfessionbuddyBot.ProfilePath;
                _profileWatcher = new FileSystemWatcher(ProfessionbuddyBot.ProfilePath)
                {
                    NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName
                };
                _profileWatcher.Changed            += ProfileWatcherChanged;
                _profileWatcher.Created            += ProfileWatcherChanged;
                _profileWatcher.Deleted            += ProfileWatcherChanged;
                _profileWatcher.Renamed            += ProfileWatcherChanged;
                _profileWatcher.EnableRaisingEvents = true;

                // used by the dev to display the 'Secret button', a button that dumps some debug info of the Task list.
                if (Environment.UserName == "high")
                {
                    toolStripSecretButton.Visible = true;
                }
            }
            catch (Exception ex)
            {
                PBLog.Warn(ex.ToString());
            }
        }
        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();
        }
Beispiel #9
0
        /// <summary>Profile behavior.</summary>
        //public PrioritySelector Branch { get; protected set; }
        public static PbProfile LoadFromFile(string path)
        {
            try
            {
                if (File.Exists(path))
                {
                    string extension = Path.GetExtension(path);
                    if (extension != null && extension.Equals(".package", StringComparison.InvariantCultureIgnoreCase))
                    {
                        using (Package zipFile = Package.Open(path, FileMode.Open, FileAccess.Read))
                        {
                            PackageRelationship packageRelation = zipFile.GetRelationships().FirstOrDefault();
                            if (packageRelation == null)
                            {
                                PBLog.Warn("{0} contains no usable profiles", path);
                                return(null);
                            }
                            PackagePart pbProfilePart = zipFile.GetPart(packageRelation.TargetUri);
                            path = ExtractPart(pbProfilePart, DynamicCodeCompiler.TempFolder);
                            PackageRelationshipCollection pbProfileRelations = pbProfilePart.GetRelationships();
                            foreach (PackageRelationship rel in pbProfileRelations)
                            {
                                PackagePart hbProfilePart = zipFile.GetPart(rel.TargetUri);
                                ExtractPart(hbProfilePart, DynamicCodeCompiler.TempFolder);
                            }
                        }
                    }
                    var element     = XElement.Load(path);
                    var versionAttr = element.Attribute("version");
                    var version     = versionAttr != null?int.Parse(versionAttr.Value) : 0;

                    var branch = (PBBranch)FromXml(element, new PBBranch());
                    return(new PbProfile(branch, version, path));
                }
                PBLog.Warn("Profile: {0} does not exist", path);
                return(null);
            }
            catch (Exception ex)
            {
                PBLog.Warn(ex.ToString());
                return(null);
            }
        }
Beispiel #10
0
        public static void CreatePackage(string path, string profilePath)
        {
            try
            {
                Uri partUriProfile = PackUriHelper.CreatePartUri(new Uri(Path.GetFileName(profilePath), UriKind.Relative));
                var hbProfiles     = new List <LoadProfileAction>();

                GetHbprofiles(profilePath, ProfessionbuddyBot.Instance.Branch, hbProfiles);
                var hbProfileUrls = hbProfiles.ToDictionary(
                    l =>
                {
                    var pbProfileDirectory = Path.GetDirectoryName(profilePath);
                    return(Path.Combine(pbProfileDirectory, l.Path));
                },
                    l => PackUriHelper.CreatePartUri(new Uri(l.Path, UriKind.Relative)));

                using (Package package = Package.Open(path, FileMode.Create))
                {
                    // Add the PB profile
                    PackagePart packagePartDocument = package.CreatePart(partUriProfile, MediaTypeNames.Text.Xml, CompressionOption.Normal);
                    using (var fileStream = new FileStream(profilePath, FileMode.Open, FileAccess.Read))
                    {
                        CopyStream(fileStream, packagePartDocument.GetStream());
                    }
                    package.CreateRelationship(packagePartDocument.Uri, TargetMode.Internal, PackageRelationshipType);

                    foreach (var kv in hbProfileUrls)
                    {
                        PackagePart packagePartHbProfile = package.CreatePart(kv.Value, MediaTypeNames.Text.Xml, CompressionOption.Normal);

                        using (var fileStream = new FileStream(kv.Key, FileMode.Open, FileAccess.Read))
                        {
                            CopyStream(fileStream, packagePartHbProfile.GetStream());
                        }
                        packagePartDocument.CreateRelationship(kv.Value, TargetMode.Internal, ResourceRelationshipType);
                    }
                }
            }
            catch (Exception ex)
            {
                PBLog.Warn(ex.ToString());
            }
        }
 private void OnSkillUpdate(object obj, LuaEventArgs args)
 {
     if (_onSkillUpdateTimer.IsFinished)
     {
         try
         {
             lock (tradeSkillLocker)
             {
                 UpdateMaterials();
                 // check if there was any tradeskills added or removed.
                 WoWSkill[] skills  = SupportedTradeSkills;
                 bool       changed = skills.Count(s => TradeSkillList.Count(l => l.SkillLine == (SkillLine)s.Id) == 1) !=
                                      TradeSkillList.Count ||
                                      skills.Length != TradeSkillList.Count;
                 if (changed)
                 {
                     PBLog.Debug("A profession was added or removed. Reloading Tradeskills (OnSkillUpdateTimerCB)");
                     OnTradeSkillsLoaded += Professionbuddy_OnTradeSkillsLoaded;
                     LoadTradeSkills();
                 }
                 else
                 {
                     PBLog.Debug("Updated tradeskills from OnSkillUpdateTimerCB");
                     foreach (TradeSkill ts in TradeSkillList)
                     {
                         ts.PulseSkill();
                     }
                     if (MainForm.IsValid)
                     {
                         MainForm.Instance.RefreshTradeSkillTabs();
                         MainForm.Instance.RefreshActionTree(typeof(CastSpellAction));
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             PBLog.Warn(ex.ToString());
         }
         _onSkillUpdateTimer.Reset();
     }
 }
Beispiel #12
0
        public static PbProfile LoadFromXml(XElement element)
        {
            if (element == null)
            {
                PBLog.Warn("FromXml: element is null");
                return(null);
            }
            try
            {
                var branch      = (PBBranch)FromXml(element, new PBBranch());
                var versionAttr = element.Attribute("version");
                var version     = versionAttr != null?int.Parse(versionAttr.Value) : 0;

                return(new PbProfile(branch, version));
            }
            catch (Exception ex)
            {
                PBLog.Warn(ex.ToString());
                return(null);
            }
        }
 private void OnSpellsChanged(object obj, LuaEventArgs args)
 {
     if (_onSpellsChangedTimer.IsFinished)
     {
         try
         {
             foreach (TradeSkill ts in TradeSkillList)
             {
                 ts.PulseSkill();
             }
             if (MainForm.IsValid)
             {
                 MainForm.Instance.InitTradeSkillTab();
                 MainForm.Instance.RefreshActionTree(typeof(CastSpellAction));
             }
         }
         catch (Exception ex)
         {
             PBLog.Warn(ex.ToString());
         }
         _onSpellsChangedTimer.Reset();
     }
 }
Beispiel #14
0
        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 override void Initialize()
        {
            try
            {
                if (!_init)
                {
                    PBLog.Debug("Initializing ...");
                    Util.ScanForOffsets();
                    if (!Directory.Exists(BotPath))
                    {
                        Directory.CreateDirectory(BotPath);
                    }
                    DynamicCodeCompiler.WipeTempFolder();
                    // force Tripper.Tools.dll to load........
                    new Vector3(0, 0, 0);

                    MySettings =
                        new ProfessionBuddySettings(
                            Path.Combine(
                                Utilities.AssemblyDirectory,
                                string.Format(@"Settings\{0}\{0}[{1}-{2}].xml", Name, Me.Name, Lua.GetReturnVal <string>("return GetRealmName()", 0))));

                    IsTradeSkillsLoaded = false;
                    LoadTradeSkills();
                    DataStore = new DataStore();
                    DataStore.ImportDataStore();
                    LoadTradeskillTools();
                    // load localized strings
                    LoadStrings();

                    // load the previous
                    BotBase bot =
                        BotManager.Instance.Bots.Values.FirstOrDefault(
                            b => b.Name.IndexOf(MySettings.LastBotBase, StringComparison.InvariantCultureIgnoreCase) >= 0);

                    if (bot == null)
                    {
                        // look for combat bot, otherwise select first bot if combat bot is not found
                        bot = BotManager.Instance.Bots.Values.FirstOrDefault(b => b.GetType().ToString() == "CombatBot")
                              ?? BotManager.Instance.Bots.Values.FirstOrDefault();
                        MySettings.LastBotBase = bot.Name;
                        MySettings.Save();
                    }
                    SecondaryBot = bot;

                    bot.DoInitialize();

                    try
                    {
                        if (!string.IsNullOrEmpty(_profileToLoad))
                        {
                            LoadPBProfile(_profileToLoad);
                        }
                        else if (!string.IsNullOrEmpty(MySettings.LastProfile))
                        {
                            LoadPBProfile(MySettings.LastProfile);
                        }
                    }
                    catch (Exception ex)
                    {
                        PBLog.Warn(ex.ToString());
                    }

                    _init = true;
                }
            }
            catch (Exception ex)
            {
                Logging.Write(Colors.Red, ex.ToString());
            }
        }
Beispiel #16
0
        private static XElement ToXml(XElement xml, Composite comp)
        {
            foreach (var pbComp in comp.Children.OfType <IPBComponent>())
            {
                var comment = pbComp as CommentAction;
                if (comment != null)
                {
                    xml.Add(new XComment(comment.Text));
                }
                else
                {
                    var elementAttr =
                        (PBXmlElementAttribute)pbComp.GetType()
                        .GetCustomAttributes(typeof(PBXmlElementAttribute), true)
                        .FirstOrDefault();

                    if (elementAttr == null)
                    {
                        PBLog.Warn("{0} does not have a PBXmlElementAttribute attached", pbComp.GetType().Name);
                        continue;
                    }

                    var eleName    = !string.IsNullOrEmpty(elementAttr.Name) ? elementAttr.Name : pbComp.GetType().Name;
                    var newElement = new XElement(eleName);

                    pbComp.OnProfileSave(newElement);
                    List <PropertyInfo> propInfoList =
                        pbComp.GetType()
                        .GetProperties()
                        .Where(p => p.GetCustomAttributes(typeof(PBXmlAttributeAttribute), true).Any())
                        .ToList();

                    foreach (PropertyInfo propInfo in propInfoList)
                    {
                        var xmlAttr =
                            propInfo.GetCustomAttributes(typeof(PBXmlAttributeAttribute), true)
                            .OfType <PBXmlAttributeAttribute>().FirstOrDefault();

                        if (xmlAttr == null)
                        {
                            continue;
                        }

                        string attrName = !string.IsNullOrEmpty(xmlAttr.Name)
                                                        ? xmlAttr.Name
                                                        : propInfo.Name;

                        if (newElement.Attribute(attrName) != null)
                        {
                            continue;
                        }
                        string value             = "";
                        var    typeConverterAttr =
                            (TypeConverterAttribute)propInfo.GetCustomAttributes(typeof(TypeConverterAttribute), true).FirstOrDefault();
                        if (typeConverterAttr != null)
                        {
                            try
                            {
                                var typeConverter = (TypeConverter)Activator.CreateInstance(Type.GetType(typeConverterAttr.ConverterTypeName));
                                if (typeConverter.CanConvertTo(typeof(string)))
                                {
                                    value =
                                        (string)
                                        typeConverter.ConvertTo(null, CultureInfo.InvariantCulture, propInfo.GetValue(pbComp, null), typeof(string));
                                }
                                else
                                {
                                    PBLog.Warn("The TypeConvert {0} can not convert to string.", typeConverterAttr.ConverterTypeName);
                                }
                            }
                            catch (Exception ex)
                            {
                                PBLog.Warn("Type conversion for {0}->{1} has failed.\n{2}", comp.GetType().Name, propInfo.Name, ex);
                            }
                        }
                        else
                        {
                            value = Convert.ToString(propInfo.GetValue(pbComp, null), CultureInfo.InvariantCulture);
                        }
                        newElement.Add(new XAttribute(attrName, value));
                    }
                    var composite = pbComp as Composite;
                    if (composite != null)
                    {
                        ToXml(newElement, composite);
                    }

                    xml.Add(newElement);
                }
            }
            return(xml);
        }
 public static void Warn(string format, params object[] args)
 {
     PBLog.Warn(format, args);
 }