#Creating RocketMod Plugins
9 messages · Page 1 of 1 (latest)
Install Visual Studio
In order to program while having a full suite of tools to ensure safe code, you can install Visual Studio 2022 Community
.
Note: Use the Visual Studio Installer to 'Modify' your installation if you have VS 2022 already installed.
During the installation process, select the '.NET desktop development' (
). Check the sidebar to ensure you are installing the .NET Framework. Afterwards, press the 'Install' or 'Modify' button.
Creating a New Project (Part 1)
Open Visual Studio 2022
following its installation. Keep in mind that you may have to restart your device in order for the installation to fully complete. Under 'Getting started', select 'Create a new project.'
In the new project menu, select 'Class Library (.NET Framework).' Please be aware that you must use the .NET Framework or .NET Standard 2.1 for creating Unturned plugins (.NS2.1 is not yet widely used for plugin development).
Creating a New Project (Part 2)
In the project configuration menu, set the 'Project name' to whatever you want your plugin to be called. Reminder that you should stick to English characters and avoid using spaces.
Modify the Framework option and set it to '.NET Framework 4.8.'
Installing Necessary Dependencies Through NuGet
For .NET (including .NET Core), the Microsoft-supported mechanism for sharing code is NuGet, which defines how packages for .NET are created, hosted, and consumed, and provides the tools for each of those roles.
-Microsoft
Open the 'Package Manager Console'
in Visual Studio
and execute the following commands to install the necessary dependencies for RocketMod.
NuGet\Install-Package RocketModFix.Rocket.API -Version 4.16.0 - Rocket.API library.
NuGet\Install-Package RocketModFix.Rocket.Core -Version 4.16.0 - Rocket.Core library.
NuGet\Install-Package RocketModFix.Rocket.Unturned -Version 4.16.0 - Rocket.Unturned library.
NuGet\Install-Package RocketModFix.Unturned.Redist -Version 3.23.12.3 - Libraries included with Unturned (SDG's libraries).
NuGet\Install-Package RocketModFix.UnityEngine.Redist -Version 2021.3.29.1 - Libraries included with Unity 2021.3.29.f1
Starting Off Your Main 'RocketPlugin' (
) Class
In the starting script, which should be named 'Class1.cs' by default, change the class name to something more appropriate. Since this is the main plugin class, I'll name it 'Main'. I'd recommend doing the same, as it clearly indicates the class tasked with initializing the rest of the plugin.
Moving on, have the 'Main' class inherit the 'RocketPlugin' class. In inheritance is part of the concept of abstraction. This makes your 'Main' class object also a 'RocketPlugin' class object.
If you are getting an error or Visual Studio
underlines the 'RocketPlugin' text, then press Alt+Tab while having the text selected to receive options on how to resolve the error. In this case, you need to add using Rocket.Core.Plugins; the beginning of your script.
Overriding the Load() and Unload() Methods
In Visual Studio
, you can override specific methods provided in the class that you inherited. In this case, you can override the 'Load' and 'Unload' methods.
In between the brackets holding the body of the class together, type override Load and then press Tab, this should automatically generate the Load method within your class. You can do the same for the Unload method by typing override Unload and then press Tab.
In the newly generated methods, you can use RocketMod's 'Logger' class to log messages into the server console. Simply use Logger.Log("whatever text you'd like");
Building the Plugin Library (Part 1)
In Visual Studio
, select 'Build' -> 'Build Solution' or Ctrl+Shift+B. This will compile the code to IL (Intermediate Language) within a .dll file.
Building the Plugin Library (Part 2)
Right click your C# (
) project in the 'Solution Explorer' (usually on the right side) and press 'Open Folder In File Explorer'
. Then, navigate to 'bin/Debug' where your plugin's .dll file should be located.
Take that file and install the plugin onto your server as you normally would. You have created your first plugin!
