CWAPI
A powerful api for developers to easily patch methods, add new features, create custom RPCs. Makes most of the repetitive tasks disappear
About this mod Author’s original text
Content Warning API
Some very useful tools for devs when creating mods for Content Warning
Harmony Patcher
If you are using harmony to patch your methods, you may also utilize the CWAPI.HarmonyPatcher for easier patching of your methods. It removes all of the repeating and also has a way to automatically determine the type of the class you are trying to patch as well as the type of the patcher class
Usage example:
using CWAPI; // for the HarmonyPatcher
namespace PluginNamespace; // your plugin namespace
public static class YourGameClassPatch // name your pacther Patch to utilize all of the features the patcher provides
{
// if you are also using the FeatureManager, I strongly advise you to call the Init method from YourFeatureNameFeature.Initialize method
internal static void Init() // the init method you call to apply the patches
{
YourPlugin.Patcher.SaveInfo(); // save the type of the current class and the type you are patching
// this only works if you named your class with a suffix 'Patch'
// if the method doesn't work on release build, try to use any of its overloads
// if the class of the method you are patching is not inside the Assembly-CSharp.dll make sure you specify the correct assembly (without.dll extension)
// if the class of the method you are patching is not inside the global namespace, make sure you specify the namespace of it (can be with or without the dot at the end)
// if something still doesnt work and you cant figure out why, you can also use any of the overloads
YourPlugin.Patcher.Patch(nameof(MethodYouAreTryingToPatch), // self explanatory
prefix: nameof(Prefix)
);
// there are plenty of other ways to use this patcher. I just showed the simplest one. You can check the source code and figure out which overload is the best for you
}
public static bool Prefix() // this is just a normal Harmony prefix patch
{
return true;
}
}
public class YourPlugin: BepInPlugin // this is only an example, not a full class
{
public static HarmonyPatcher Patcher { get; private set; } = default!; // create the public variable and set it to default!
private void Awake()
{
Patcher = new(PLUGIN_GUID, YourPlugin.Logger); // create the harmony patcher instance
}
}
Feature Manager
If you have a lot individual features in your mod, you can also try the CWAPI.FeatureManager! It has a method InitializeFeatures() which must be called when the mod is loading.
Features must inherit the CWAPI.Feature class and be marked with CWAPI.FeatureAttribute for the FeatureManager to find them and register.
Feature manager automatically handles:
- Enabling and disabling individual features
- Has the option to mark a feature as required
Usage exaple:
using BepInEx;
using BepInEx.Configuration;
using CWAPI; // for all of the necessary classes
namespace PluginNamespace; // your plugin namespace
[Feature] // add the FeatureAttribute
internal class YourFeatureNameFeature: Feature // inherit the feature class
{
public override BepInEx.Logging.ManualLogSource LogSource => YourPlugin.Logger; // use your logger
public override bool Required => false; // (optional) if set to true, disallows the user to turn off the feature. The initialize method for it is always called. Default: false (user can disable your feature)
public override string FeatureName => "YourFeatureName"; // name your feature. It can be with spaces or without
public override string FeatureDescription => "Explain what your feature does";
public ConfigEntry SomeSetting { get; private set; } = null!; // example setting
public override void CreateConfig(ConfigSection section)
{
// this function is always called. No matter if this feature is enabled or not
// you can register your feature config here
SomeSetting = section.Bind(
nameof(SomeSetting), // the name of the setting
20f, // the default value of the setting
"""
The description of this setting
"""); // description
}
public override void Initialize()
{
// this function is only called
Install & use Install: BepInEx plugin
- The archive from playbuff is the mod itself — usually a BepInEx plugin (a .dll or a plugin folder once unzipped).
- Recommended: use a community mod manager (such as r2modman) — pick this game, import the mod, and the manager sets up BepInEx and its dependencies for you.
- Manual route: install the BepInEx loader in the game folder, then drop the unzipped .dll or plugin folder into BepInEx/plugins/.
- Launch the game — the BepInEx console logs every plugin it loads; seeing this mod in the log means it is installed.
Mods with listed dependencies need those installed too, or they will not load. Options are usually changed in-game or in the plugin's config file.
Install these first, or the mod will not work: