Skip to content

Plugin Tutorial [LeoConsole v1.5.0]

BoettcherDasOriginal edited this page May 1, 2022 · 1 revision

1. Setup your project

If you use Visual Studio 2022 choose: home -> new Project -> class library (.NET 6)
Than in your project Dependencies -> Add Project Reference -> and add ILeoConsole.dll which can be found in your LeoConsole installation folder.

If your not using Visual Studio, just make sure that u attach ILeoConsole.dll to your project

2. The Plugin class

// https://github.com/BoettcherDasOriginal/LeoConsole-ExamplePlugin/
// ExamplePlugin.cs

using ILeoConsole;
using ILeoConsole.Plugin;
using ILeoConsole.Core;

namespace LeoConsole_ExamplePlugin
{
    public class ExamplePlugin : IPlugin
    {
        public string Name { get { return "ExamplePlugin"; } }

        public string Explanation { get { return "Example Plugin"; } }

        private IData _data;
        public IData data { get { return _data; } set { _data = value; } }

        private List<ICommand> _Commands;
        public List<ICommand> Commands { get { return _Commands; } set { _Commands = value; } }

        public void PluginMain()
        {
            // Add Data

            _data = new ConsoleData();


            // Add Commands

            _Commands = new List<ICommand>();
            _Commands.Add(new randomNumber());
        }
    }
}
  • Name -> the name of your plugin
  • Explanation -> the description of your plugin
  • data -> an interface to the data class from LeoConsole
  • Commands -> a list of all your custom commands
  • PluginMain() -> is called when LeoConsole loads your plugin

3. Your custom command

// https://github.com/BoettcherDasOriginal/LeoConsole-ExamplePlugin/
// randomNumber.cs

using ILeoConsole;
using ILeoConsole.Plugin;
using ILeoConsole.Core;

namespace LeoConsole_ExamplePlugin
{
    public class randomNumber : ICommand
    {
        Random rand = new Random();

        public string Name { get { return "randomNumber"; } }
        public string Description { get { return "generiert einen zuffälligen Code"; } }
        public Action CommandFunktion { get { return () => Command(); } }
        private string[] _InputProperties;
        public string[] InputProperties { get { return _InputProperties; } set { _InputProperties = value; } }
        public void Command()
        {
            try
            {
                int length = Convert.ToInt32(InputProperties[1]);

                int Buchstabe;
                int textOrNumber;

                if (_InputProperties != null)
                {
                    Console.WriteLine("Neuer Code: ");

                    for (int i = 0; i < length; i++)
                    {
                        else
                        {
                            Console.Write(rand.Next(0, 9).ToString());
                        }
                    }

                    Console.WriteLine("");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message + "\n");
            }
        }
    }
}
  • Name -> the name of your command
  • Description -> the description of your command
  • InputProperties -> the given parameter from the user
  • Command() -> the main function of your command

Note: Make sure to add this command class to your command list in the plugin main class

4. Get some Data from the current LeoConsole instance

// https://github.com/BoettcherDasOriginal/LeoConsole-ExamplePlugin/
// randomNumber.cs

using ILeoConsole;
using ILeoConsole.Plugin;
using ILeoConsole.Core;

namespace LeoConsole_ExamplePlugin
{
    public class ConsoleData : IData
    {
        public static User _User;
        public User User { get { return _User; } set { _User = value; } }
        public static string _SavePath;
        public string SavePath { get { return _SavePath; } set { _SavePath = value; } }
        public static string _DownloadPath;
        public string DownloadPath { get { return _DownloadPath; } set { _DownloadPath = value; } }
    }
}
  • User -> the current logged in user
  • SavePath -> the current save path
  • DownloadPath -> the current download path

Note: Make sure to set this to your data class in the plugin main class

6. Debug your Plugin

  1. Go to your LeoConsole installation folder -> data -> plugins
  2. Copy your Plugin dll in to this folder
  3. Start LeoConsole.exe and your plugin should be loaded
  4. Test your Functions and wait for something to go wrong :D

7. Add your Plugin to the package manager

  1. Compile your sources to an .dll file, for example: examplePlugin.dll
  2. Go to https://github.com/BoettcherDasOriginal/LeoConsole/blob/main/PackageList.txt
  3. Add in a new line: pkg -n:yourPluginName -d:yourDirectDownloadLink (Make Sure that the DownloadLink is without https://)
    For Example: pkg -n:examplePlugin -d:github.com/BoettcherDasOriginal/LeoConsole-ExamplePlugin/releases/latest/download/LeoConsole-ExamplePlugin.dll
  4. Make an Pull Request and wait for me to accept it
  5. Install your Plugin with the package manager:
    pkg update
    pkg get yourPluginName
    

Links

The complete source code of the sample plugin can be found here

An awesome plugin template by @alexcoder04 can be found here