-
Notifications
You must be signed in to change notification settings - Fork 0
Assembly Plugins
TBN_MapleWheels edited this page Feb 3, 2023
·
5 revisions
Unlike LuaCsForBarotrauma, the Assembly Loading System allows you to ship compiled assemblies/.dlls with your Steam Workshop addon.
Benefits:
- Allows the use of the
[assembly: IgnoresAccessChecksTo("Barotrauma")]
/[assembly: IgnoresAccessChecksTo("DedicatedServer")]
attribute which allows you to bypass access restrictions (ie. private members) without reflection! All you need is a publicized assembly, which is included in theRefs.zip
from a release. - Enhanced debugging since your IDE can link the assembly error to your code directly, showing you where your errors are.
- Breakpoints and other IDE features work.
- Allows you to ship your own dependencies! Have a Nuget package or library you want to use? Just include it in the same folder as your mod's dll.
-
Hot Reload!(Coming Soon).
-
Complete the Project Setup Guide.
-
The VS Project Skeleton includes a default plugin example skeleton. If you are not using it, create a plugin by having your plugin class implement the
IAssemblyPlugin
interface. The Modloader will automatically find and load your mod class at startup.
Example:
using ModdingToolkit;
namespace MyMod;
public class MyPlugin : IAssemblyPlugin
{
void Initialize()
{
//Called the moment your plugin is instantiated.
}
void OnLoadCompleted()
{
//Called once ALL plugins have had their Initialize() functions called.
//Searching all loaded assemblies
List<MyType> typeList = AssemblyManager.GetSubTypesInLoadedAssemblies<MyType>().ToList(); //Uses yield so call .ToList()
}
PluginInfo GetPluginInfo()
{
//Format: Unique Plugin ID, Version, Special-Case Dependencies (Not Yet Implemented)
return new PluginInfo("AuthorName.MyMod", "0.0.0.0", ImmutableArray<string>.Empty);
}
void Dispose()
{
//Called before your mod is unloaded. YOU MUST cleanup all references and instances stored by code from the main game!
//Any references that persist will halt unloading of your assembly!
}
}
- Your compiled mod's DLL MUST end with
.plugin.dll
! This can be accomplished by setting theAssembly Name
in your IDE. The VS Project Skeleton has this completed already. - In your Barotrauma Mod's ContentPackage folder, you must store your compiled DLL in one of four locations:
-
<ContentPackageRoot>/bin/Client/Standard
will load your mod on the CLIENT only if the ContentPackage is ENABLED. -
<ContentPackageRoot>/bin/Client/Forced
will load your mod on the CLIENT always, even if the ContentPackage is disabled. -
<ContentPackageRoot>/bin/Server/Standard
will load your mod on the SERVER only if the ContentPackage is ENABLED. -
<ContentPackageRoot>/bin/Server/Forced
will load your mod on the SERVER always, even if the ContentPackage is disabled.
- And finally, if using the Steam Workshop, add this mod as a Workshop Dependency.