All methods, fields and properties are static.
void CreateMod(BaseUnityPlugin _plugin, string modName, string modAuthor, string modVersion, bool pathAll = true)
Allows you to create your own mod automatically.
Call ModBase.CreateMod()
to create a mod. It will automatically:
- create ConfigSync
- SetupWatcher on config file
- call Harmony.PatchAll() - can be disabled via
pathAll: false
- Add config server lock
private void Awake()
{
ModBase.CreateMod(_plugin: this, ModName, ModAuthor, ModVersion, pathAll: true);
OnConfigurationChanged += () => { };
}
void RunCommand(Terminal.ConsoleEvent action, Terminal.ConsoleEventArgs args)
When you adding a new command, you can call this method to format it. It automatically uses try catch.
throw new ConsoleCommandException to make error be shown only in in-game console. Any other exception will be shown in the log.
Example:
[HarmonyPatch(typeof(Terminal), nameof(InitTerminal))]
[HarmonyWrapSafe]
internal class TerminalCommands
{
private static void Postfix()
{
new ConsoleCommand("mycoolcommand", "", args => RunCommand(args =>
{
if (!IsAdmin) throw new ConsoleCommandException("You are not an admin on this server.");
//Do something
}, args));
}
}
T GetPlugin<T>() where T : BaseUnityPlugin
Returns the plugin instance of type of BaseUnityPlugin.
Returns the plugin instance of type of T. T should your BaseUnityPlugin type.
GetPlugin<MyMod>().SomeMethodImplodedInMyMod();
void Debug(object msg, bool showInHud = false, bool showInConsole = false)
Logs message to the BepInEx console.
void DebugError(object msg, bool showWriteToDev = true, bool showInConsole = false)
Logs error message to the BepInEx console.
void DebugWarning(object msg, bool showWriteToDev = true, bool showInConsole = false)
Logs warning message to the BepInEx console.
AssetBundle LoadAssetBundle(string filename)
Loads an asset bundle, returns the it and saves it in ModBase.bundle
field.
string CreateModGUID(string ModName, string ModAuthor) => $"com.{ModAuthor}.{ModName}";
Constructs a mod GUID. in format com.ModAuthor.ModName
.
string ModName { get; private set; }
The name of the mod.
string ModAuthor { get; private set; }
The author of the mod.
string ModVersion { get; private set; }
The version of the mod.
string ModGUID { get; private set; }
The GUID of the mod.
Harmony harmony { get; private set; }
The harmony instance for this mod.
bool IsAdmin
Whether the player is an admin on this server.
AssetBundle bundle
The asset bundle of the mod set by LoadAssetBundle
.
Action OnConfigurationChanged
Called when configuration file is changed.