Files
bd2/plugins/BetterExperience/Plugin.cs
T

72 lines
2.3 KiB
C#

using System;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Bd2BetterExperience.Life;
using Bd2BetterExperience.Window;
using Bd2BetterExperience.Performance;
using Bd2BetterExperience.Social;
using Bd2BetterExperience.Rewards;
using Bd2BetterExperience.Housing;
using Bd2BetterExperience.Navigation;
namespace Bd2BetterExperience;
// Quality-of-life additions to the game's own screens. Each module is
// independent and can be turned off in the plugin's BepInEx config.
[BepInPlugin(PluginId, Name, Version)]
public sealed class Plugin : BaseUnityPlugin
{
public const string PluginId = "bd2.betterexperience";
public const string Name = "BD2 Better Experience";
public const string Version = Bd2Build.Versions.Plugin;
internal static ManualLogSource Log;
internal static ConfigFile Settings;
private static readonly IModule[] Modules = [
new LifeBatchEdit(),
new LifeMinimumBuildings(),
new WindowPreferences(),
new PerformanceOverlay(),
new FriendPresence(),
new PassRewardPresentation(),
new RoomPlacementStability(),
new CommissionNavigation()
];
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0051", Justification = "Unity invokes this lifecycle callback.")]
private void Awake()
{
Log = Logger;
Settings = Config;
foreach (IModule module in Modules)
{
ConfigEntry<bool> enabled = Config.Bind("Modules", module.Id, true, module.Description);
if (!enabled.Value) { Logger.LogInfo(module.Id + " disabled"); continue; }
// Each module patches under its own id so one failing leaves the others in place.
#pragma warning disable CA2000
var harmony = new Harmony(PluginId + "." + module.Id);
#pragma warning restore CA2000
try
{
module.Install(harmony);
Logger.LogInfo(module.Id + " installed");
}
catch (Exception error)
{
harmony.UnpatchSelf();
Logger.LogError(module.Id + " failed to install: " + error);
}
}
}
}
internal interface IModule
{
// The config key under [Modules].
string Id { get; }
string Description { get; }
void Install(Harmony harmony);
}