Writing A Basic Plugin
Before You Begin
The plugin which we will guide you to create in this guide will only teach you how to interact with AnchorChain. This guide isn't about building mods, just loading one via AnchorChain. If you would like to learn how to build a mod, then we recommend looking to the Harmony documentation.
What Anchor Chain Requires
As of writing, there is no nuget package for an Anchor Chain plugin, so you'll have to do things the old-fashioned way. Thankfully, AC plugins are fairly simple. There are two things that define a plugin:
The ACPlugin
attribute is how AnchorChain will find and identify your plugin. It should be applied to any classes that you want to be loaded as a plugin.
Arguments
string guid
AnchorChain's internal name for your plugin. We recommend that you use reverse domain notation for
GUID
. For modders, this usually comes in the form of your github.io url. For example, AnchorChain'sGUID
isio.github.seapower_modders.anchorchain
.string name
The name of your plugin is completely arbitrary. AnchorChain will only use it in logging and error messages, and it will always be paired with the plugin's
guid
.string version
The version of your plugin. Must be in a format acceptable by
System.Version
. AnchorChain recommends that you adhere to the convention of SemVer.string[] before
An array of plugins that you want your plugin to always load before. Do not use this option without reason, as if AnchorChain detects a conflict between two mods both wanting to load first, it will abort loading all mods.
The plugins in
before
should be identified by their GUIDs.string[] after
An array of plugins that you want your plugin to always load after. Do not use this option without reason, as if AnchorChain detects a conflict between two mods both wanting to load second, it will abort loading all mods.
The plugins in
after
should be identified by their GUIDs.
IAnchorChainMod
is a simple interface, only consisting of a single method.
TriggerEntryPoint()
This is what AnchorChain will call to load your plugin. As such, it should contain all setup required for your plugin.
Writing Your Plugin
Create a new project in your preferred code editor.
Import AnchorChain to your project. The dll that you should use is available on our releases page in
dev.zip
.Create your plugin's namespace. We recommend choosing a unique name to avoid collisions with other mods.
Create a class for your plugin. It should be annotated with
ACPlugin
and implementIAnchorChainMod
.Add your
guid
,name
, andversion
string toACPlugin
.Create the
public void TriggerEntryPoint
function.All that's left is to add your mod's code to
TriggerEntryPoint()
. For this example, we'll just make it log a message to console using Unity'sDebug.Log()
.
Your file should be similar to the following:
Now, your code should look something like this:
Finally, we have our completed plugin.
Load Your Plugin
First, make sure that the Anchor Chain and its preloader are installed in your Sea Power directory. If that is not the case, follow the instructions here.
Anchor Chain is made to make loading plugins easier for users. Unfortunately, that does not translate into an easier time for modders. You will need to build your plugin and manually move it into <Sea Power>/Sea Power_Data/StreamingAssets
Once your plugin is in StreamingAssets
, just boot the game as normal. Your plugin will load and log your debug message to <your user directory>/AppData/LocalLow/Triassic Games/Sea Power/Player.log
.
Congratulations, you've made and loaded an Anchor Chain plugin!