Your First Plugin

Creating the plugin project

In order to make a plugin, create a new class library in your IDE (this should be easy to figure out using the GUI) The target framework must be compatible with .NET Framwork 3.5 (this is compatible with Unity) (example code can be found below)

Once you compile the project, you'll find it's dll file in a directory like bin/debug/ This is the file you can drop in the Plugins folder of the Application.

Understanding class libraries

LyokoAPI comes in the form of a class library. A class library is essentially a bunch of code that doesn't execute on it's own. Thus, it can't be used by itself. For C#, a library is compiled into a .dll file. Fun fact: Windows uses dll's as well for its own use! In theory, you can use the dll's in other .NET languages like VB.NET Your Plugin must also be a class library

Choosing an IDE

We recommend Jetbrains' Rider. It's free if you have a student email, and once in a while an Early Access Program is available, which is also free.

Adding LAPI to your project

Adding the Nuget package

LAPI V2 and higher comes in a nuget package, found here: https://www.nuget.org/packages/LyokoAPI/ A nuget package insures that you can easily update LAPI and that all it's required components, like YamlDotNet, are also installed automatically

The method of adding a nuget package depends on your IDE. Here are some links to help you: Rider Visual studio

Writing your plugin

There are of course, many ways to write a plugin, but here is a 'template' that you can take inspiration from. See Plugin Introduction for more in-depth info on the rules of writing a good plugin.

Main class

Only ONE class per plugin should extend LyokoAPIPlugin.

ExamplePlugin.cs
public class ExamplePlugin : LyokoAPIPlugin
    {
        public override string Name { get; } = "ExamplePlugin"; //set the name of the plugin

        public override string Author { get; } = "Noob"; //set the author of the plugin
        
        //ATTENTION! this property is set to the AssemblyVersion in AssemblyInfo.cs by default. Please set the version there.
        //public override LVersion Version { get; } = "V1.0.1"; //semantic versioning is preferred. the format is X.X.Y.Y where X and Y are whole numbers and X is mandatory.

        public override List<LVersion> CompatibleLAPIVersions { get; } =
            new List<LVersion>() {"2.0.0", "2.0.1"}; //A list of LAPI versions this plugin should be compatible with.
        private LAPIListener MyListener = new MyListener();
        protected override bool OnEnable()
        {
            MyListener.StartListening(); //Starting to listen to events in the OnEnable() is recommended
            return true; //nothing went wrong, so we return true to show the plugin has been enabled properly
        }

        protected override bool OnDisable()
        {
            MyListener.StopListening(); //Definitely stop listening to events OnDisable(), since code will still be run if you dont.
            return true; //disabled succesfully, returning true.
        }

        /*
        * This method is run when a gamesession starts in the Application (if it has game sessions.)
        *
        */
        public override void OnGameStart(bool storyMode)
        {
            if (storyMode)
            {
                MyListener.StopListening(); //disabling the listener in order to prevent 'cheating' (wether or not you should do this depends on your plugin.
            }
        }

        public override void OnGameEnd(bool failed)
        {
            if (failed) //if the player has lost the game
            {
                LyokoLogger.Log(Name, "Lol you failed you epic loser"); //this will appear in the log as "[ExamplePlugin] Lol you failed you epic loser"
            }

            MyListener.StartListening(); //start listening because we might have stopped in OnGameEnd
        }

        /*
          this method runs when the player leaves the supercomputerinterface/laptop/whatever
        */
        public override void OnInterfaceExit()
        {
            MyListener.StopListening(); //Jeremie cant know about xanafication if he's not at his computer, so it would be cheating to listen to these events
        }

        public override void OnInterfaceEnter()
        {
            MyListener.StartListening(); //Turn it on because we turned it off in OnInterfacExit()
        }
    }

Last updated