CWAPI

版本 v1.1.0·更新於 2025-08-01

A powerful api for developers to easily patch methods, add new features, create custom RPCs. Makes most of the repetitive tasks disappear

模組介紹 作者原文

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

安裝與使用 安裝:BepInEx 外掛

  1. 本站下載的壓縮包就是模組本體,通常是 BepInEx 外掛(解壓後得到 .dll 或外掛資料夾)。
  2. 建議流程:用社群模組管理器(如 r2modman)選中本遊戲後匯入該模組,管理器會自動裝好 BepInEx 前置並處理依賴。
  3. 手動流程:先在遊戲目錄裝好 BepInEx 載入器,再把解壓出的 .dll 或外掛資料夾放進 BepInEx/plugins/。
  4. 啟動遊戲,BepInEx 控制台會列印載入日誌;確認這個模組出現在日誌裡即為安裝成功。

帶「前置依賴」的模組需要一併安裝,否則不會載入。功能開關通常在遊戲內或外掛自帶的設定檔裡調整。

前置依賴

下面這些內容需要先安裝,否則該模組不會生效:

BepInEx-BepInExPackRugbugRedfern-MyceliumNetworking

檔案與校驗

檔案名稱
CWAPI-1.1.0.zip
檔案大小
47.2 KiB