Jump to content

How to load the default plugin settings


dravrah

Recommended Posts

i have used @Droidz profile Setting backup.cs

using System;
using System.IO;
using robotManager.Helpful;
using wManager;
using wManager.Plugin;
using System.Drawing;
using System.Windows.Forms;

public class Main : IPlugin
{
    private bool _isLaunched;

    public void Initialize()
    {}

    public void Dispose()
    {}

    public void Settings()
    {
        var f = new FormSettingsBackup();
        f.ShowDialog();
    }
}

public class FormSettingsBackup : Form
{
    public FormSettingsBackup()
    {
        InitializeComponent();
        Directory.CreateDirectory(PathFolder);
    }

    string PathFolder { get { return Application.StartupPath + @"\Plugins\Settings Backup\"; } }

    private void ButtonLoadClick(object sender, EventArgs e)
    {
        var file = Others.DialogBoxOpenFile(PathFolder, "General Settings file (*.xml)|*.xml");
        if (!string.IsNullOrWhiteSpace(file))
        {
            if (File.Exists(file) && File.ReadAllText(file).Contains("</wManagerSetting>"))
            {
                var s = XmlSerializer.Deserialize<wManagerSetting>(file);
                if (s != null)
                {
                    wManagerSetting.CurrentSetting = s;
                    wManagerSetting.CurrentSetting.Save();
                    Logging.Write("[SettingsBackup] New setting loaded: " + file);
                }
                else
                {
                    MessageBox.Show("Cannot load selected file.");
                    Logging.WriteError("[SettingsBackup] Cannot load selected file: " + file);
                }
            }
            else
            {
                MessageBox.Show("Selected file is not valid.");
                Logging.WriteError("[SettingsBackup] Selected file is not valid: " + file);
            }
        }
    }

    private void ButtonSaveClick(object sender, EventArgs e)
    {
        var file = Others.DialogBoxSaveFile(PathFolder, "General Settings file (*.xml)|*.xml");
        if (!string.IsNullOrWhiteSpace(file))
        {
            var s = XmlSerializer.Serialize(file, wManagerSetting.CurrentSetting);
            if (s)
            {
                Logging.Write("Setting saved: " + file);
            }
            else
            {
                MessageBox.Show("Cannot save setting.");
                Logging.WriteError("[SettingsBackup] Cannot save setting: " + file);
            }
        }
}

    #region FORM

    private void InitializeComponent()
    {
        SuspendLayout();

        // 
        // buttonLoad
        // 
        var buttonLoad = new Button
        {
            Location = new Point(12, 12),
            Size = new Size(151, 23),
            Text = "Load settings",
            UseVisualStyleBackColor = true
        };
        buttonLoad.Click += ButtonLoadClick;
        // 
        // buttonSave
        // 
        var buttonSave = new Button
        {
            Location = new Point(12, 41),
            Size = new Size(151, 23),
            Text = "Save settings",
            UseVisualStyleBackColor = true
        };
        buttonSave.Click += ButtonSaveClick;
        // 
        // Form
        // 
        AutoScaleDimensions = new SizeF(6F, 13F);
        AutoScaleMode = AutoScaleMode.Font;
        ClientSize = new Size(175, 76);
        Controls.Add(buttonSave);
        Controls.Add(buttonLoad);
        FormBorderStyle = FormBorderStyle.FixedToolWindow;
        Name = "Form1";
        ShowIcon = false;
        Text = "Settings Backup";
        TopMost = true;

        ResumeLayout(false);
    }

    #endregion FORM
}

but this plugin not back up the other settings like HMP. @Matenia

everytime when i create a new character i have to set the HMP once. its really anonying.

so is there a way to edite this profile to make it save the HMP default setting too?

then i just need to click a button then all set.

thanks for advance.

the settings about HMP profile name: CustomPlugin-Master-xxx.Nethergarde.xml

<?xml version="1.0" encoding="utf-8"?>
<PluginSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <TransactionId>123456789</TransactionId>
  <AutoEquipBlacklist>
    <int>7005</int>
    <int>7005</int>
    <int>7005</int>
    <int>7005</int>
  </AutoEquipBlacklist>
  <FirstAid>false</FirstAid>
  <TrainFirstAid>false</TrainFirstAid>
  <Food>false</Food>
  <Drink>false</Drink>
  <BlackListIds />
  <Looting>false</Looting>
  <Skinning>false</Skinning>
  <TrainingLevels />
  <TrainerBlacklist />
  <EscapeElite>true</EscapeElite>
  <EscapePercentMana>0</EscapePercentMana>
  <EscapePercentManaEnemies>0</EscapePercentManaEnemies>
  <SmartPulls>false</SmartPulls>
</PluginSettings>

 

Link to comment
Share on other sites

Hello, try plugin like:

using robotManager.Helpful;
using wManager.Plugin;
using System.Windows.Forms;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;

public class Main : IPlugin
{
    public void Initialize() {}

    public void Dispose() {}

    public void Settings()
    {
        sTemp.CreateHmpSetting();
    }
}

class sTemp : Settings
{
    public static void CreateHmpSetting()
    {
        var filePath = AdviserFilePathAndName("CustomPlugin-Master", ObjectManager.Me.Name + "." + Usefuls.RealmName);

        var fileContent = 
@"<?xml version=""1.0"" encoding=""utf-8""?>
<PluginSettings xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
  <TransactionId>123456789</TransactionId>
  <AutoEquipBlacklist>
    <int>7005</int>
    <int>7005</int>
    <int>7005</int>
    <int>7005</int>
  </AutoEquipBlacklist>
  <FirstAid>false</FirstAid>
  <TrainFirstAid>false</TrainFirstAid>
  <Food>false</Food>
  <Drink>false</Drink>
  <BlackListIds />
  <Looting>false</Looting>
  <Skinning>false</Skinning>
  <TrainingLevels />
  <TrainerBlacklist />
  <EscapeElite>true</EscapeElite>
  <EscapePercentMana>0</EscapePercentMana>
  <EscapePercentManaEnemies>0</EscapePercentManaEnemies>
  <SmartPulls>false</SmartPulls>
</PluginSettings>";

        Others.WriteFile(filePath, fileContent);

        MessageBox.Show("HMP file created");
    }
}

(change xml code for your settings)

Link to comment
Share on other sites

  • 4 years later...

Hello,

I tried adapting the code from earlier. My goal was to change the settings of a specific plugin using a RunCode. Is this even possible in this manner? I hope I haven't missed any forum posts where this issue was already addressed.

 

using robotManager.Helpful;
using wManager.Plugin;
using System.Windows.Forms;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;

public class Main : IPlugin
{
    public void Initialize() {}

    public void Dispose() {}

    public void Settings()
    {
        sTemp.CreateHmpSetting();
    }
}

class sTemp : Settings
{
    public static void CreateHmpSetting()
    {
        var filePath = AdviserFilePathAndName("CustomPlugin-TagAndBag-" ObjectManager.Me.Name + "." + Usefuls.RealmName);

        var fileContent = 
@"<?xml version=""1.0"" encoding=""utf-8""?>
<PluginSettings xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
  <ChannelName>GemeinsamesLeveln</ChannelName>
  <ChannelPassword>GemeinsamesLeveln</ChannelPassword>
  <Followers />
  <GroupRegen>true</GroupRegen>
  <GroupTrain>false</GroupTrain>
</PluginSettings>";

        Others.WriteFile(filePath, fileContent);

        MessageBox.Show("HMP file created");
    }
}


[E] 15:47:32 - Compilator Error (steps cache) :
c:\Projekt\WRobot\Data\temp\vya31g2p.0.cs(102,34) : error CS1513: } erwartet.
c:\Projekt\WRobot\Data\temp\vya31g2p.0.cs(140,15) : error CS1518: Klasse, Delegat, Enumeration, Schnittstelle oder Struktur erwartet.
c:\Projekt\WRobot\Data\temp\vya31g2p.0.cs(360,1) : error CS1022: Typ- oder Namespacedefinition oder Dateiende erwartet.

[E] 15:47:33 - Compilator Error :
c:\Projekt\WRobot\Data\temp\drcen3kt.0.cs(106,34) : error CS1513: } erwartet.
c:\Projekt\WRobot\Data\temp\drcen3kt.0.cs(144,1) : error CS1022: Typ- oder Namespacedefinition oder Dateiende erwartet.

Link to comment
Share on other sites

Can't read that code, please format it properly

The error pretty clearly tells you there's a problem with setting your brackets => }

 

I recommend you get Visual Studio or Visual Studio Code so you have at least basic syntax highlighting enough to help you to write code that will compile.

Link to comment
Share on other sites

Sorry to ask about this topic again.
But I've really tried for a long time to find a solution.
I can't find any errors with the {}.
The error also occurs when I simply copy the original code from Droidz.

This code is very important to me.
It's the last missing piece to complete a group quester.


The goal is to swap the leader role through the plugin using a RunCode.

Would you perhaps have a moment to take a look at it?

If not, I understand. I'll continue searching for the solution in the meantime.

Link to comment
Share on other sites

This is a separate plugin. I don't know where you're trying to paste this code. 

If you're trying to put this INTO an existing plugin, this will never work. The important thing is in the sTemp class, that one has all the required info/functionality for writing a file.
Quite frankly, I don't think you are capable of making a product that quests as a party with next to no coding knowledge.

I'll just tell you one of the obvious things, now that I can read the code:
 

var filePath = AdviserFilePathAndName("CustomPlugin-TagAndBag-" ObjectManager.Me.Name + "." + Usefuls.RealmName);

What's obvious here? Either you do what Droidz did, a plugin name like CustomPlugin-TagAndBag, followed by the second argument (arguments are divided by a comma) OR you concatenate the whole string.

Trying to do XML in a multiline string isn't exactly easy. You need to escape existing quotation marks or they will end the string again. This is why Droidz used double quotation marks.

You can test strings here, for example. Keep in mind, that one uses a more modern version of C#. If you don't compile your own code (I told you, set up Visual Studio), you're limited to .NET Framework 4.0 (if I recall correctly), because WRobot compiles your code at runtime.

image.png.e2567d3972332366350bb2bf54dc4ec9.png

 

using robotManager.Helpful;
using wManager.Plugin;
using System.Windows.Forms;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;

public class Main : IPlugin
{
    public void Initialize() {}

    public void Dispose() {}

    public void Settings()
    {
        sTemp.CreateHmpSetting();
    }
}

class sTemp : Settings
{
    public static void CreateHmpSetting()
    {
        var filePath = AdviserFilePathAndName("CustomPlugin-TagAndBag", ObjectManager.Me.Name + "." + Usefuls.RealmName);

        // read how to do a multiline string here: https://blog.gitnux.com/code/c-sharp-multiline-string/
        var fileContent = 
        @"<?xml version=""1.0"" encoding=""utf-8""?>
        <PluginSettings xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
            <ChannelName>GemeinsamesLeveln</ChannelName>
            <ChannelPassword>GemeinsamesLeveln</ChannelPassword>
            <Followers />
            <GroupRegen>true</GroupRegen>
            <GroupTrain>false</GroupTrain>
        </PluginSettings>";

        Others.WriteFile(filePath, fileContent);

        MessageBox.Show("HMP file created");
    }
}

Again - I have no idea what context you're trying to use this in. If this doesn't work, you'll have to actually do what I said in the first place and learn.

Link to comment
Share on other sites

I already have a completed quester for WOTLK.
Strong classes like Paladin, Warrior, Druid, etc. can handle this on their own.
For the weaker classes, I now want to run the same quester as a group.
In doing so, the two group members switch roles at the predetermined points in the quester using the built-in chat command.

Now, here's my question regarding the code.
There's this plugin: Tag and Bag, where characters can follow the leader.
For this, I want to incorporate a RunCode in my quester that changes the plugin's settings: Leader = true or Leader = false.
 

Link to comment
Share on other sites

If I understand correctly, you're trying to have a group of 2 do a series of quests using the quester product where one member does the quest, and the other follows, and you want to be able to switch those roles at runtime.

I'm not very familiar with the quester, but that seems very difficult to do, if possible at all. You might be better off making your own product at this point.

I created 2 video tutorials for beginners, plugin and product, maybe that will help you.

 

Link to comment
Share on other sites

Not that I know of. Communication between wRobot modules (product/FC/plugins) or between bots is not possible with simple code.

Your initial idea to trigger a setting change using the client's chat is actually the best suited idea for this case I think. If your plugin is open source, then you should try and modify it directly.

Link to comment
Share on other sites

Here's what you should do:

  • add code to to TagNBagger (since it's public) to read a variable in WRobot via Via.GetVar<string>("customName")
  • use your quester to set that var, you can use my example randomized questers to take a look at how to do it
  • when var is set, the internal settings of the plugin are changed FROM WITHIN the plugin, you can then reload the plugin itself if required
  • use Var to communicate between plugins, quester, other parts of WRobot for everything you need

The chat command itself isn't a bad idea either. But within the same instance of WRobot, you don't need to chat and as far as I understand, this is mainly what you're struggling with.

The party mode plugin I released which TagNBagger is based on is also open source, if you need more inspiration.

 

More info: 

 

Edited by Matenia
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...