Decompiled source of PowersConfigurator v1.0.0

PowersConfigurator.dll

Decompiled 5 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using ServerSync;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PowersConfigurator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PowersConfigurator")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a0b75ab7-b527-489e-ba01-050120bb7a51")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PowersConfigurator;

internal static class PowerFinder
{
	public static BossPowerConfigEntry<float> GetFlagsForBoss(BossIds bossId)
	{
		BossPowerConfigEntry<float> bossPowerConfigEntry = new BossPowerConfigEntry<float>
		{
			Duration = 300f,
			Cooldown = 900f
		};
		if (PowersConfiguratorMod.ModConfig[bossId] != null)
		{
			bossPowerConfigEntry.Cooldown = PowersConfiguratorMod.ModConfig[bossId].Cooldown.Value;
			bossPowerConfigEntry.Duration = PowersConfiguratorMod.ModConfig[bossId].Duration.Value;
		}
		else
		{
			PowersConfiguratorMod.BepinLogger.LogError((object)$"No data for \"{bossId}\"");
			bossPowerConfigEntry.Cooldown = PowersConfiguratorMod.DefaultCooldown.Value;
			bossPowerConfigEntry.Duration = PowersConfiguratorMod.DefaultDuration.Value;
		}
		return bossPowerConfigEntry;
	}

	public static BossIds StatusNameToBossId(string statusName)
	{
		switch (statusName)
		{
		case "GP_Eikthyr":
			return BossIds.Eikthyr;
		case "GP_TheElder":
			return BossIds.Elder;
		case "GP_Bonemass":
			return BossIds.Bonemass;
		case "GP_Moder":
			return BossIds.Moder;
		case "GP_Yagluth":
			return BossIds.Yagluth;
		case "GP_Queen":
			return BossIds.Queen;
		case "GP_Ashlands":
		case "GP_Fader":
			return BossIds.Fader;
		default:
			Debug.Log((object)("Unknown Guardian Power: \"" + (statusName ?? "none") + "\""));
			return BossIds.Global;
		}
	}
}
[HarmonyPatch(typeof(Player), "ActivateGuardianPower")]
internal static class ActivatePower_Patch
{
	private static void Prefix(Player __instance, StatusEffect ___m_guardianSE)
	{
		Debug.Log((object)"Prefix ActivateGuardianPower");
		if (!((Object)(object)___m_guardianSE == (Object)null))
		{
			BossIds num = PowerFinder.StatusNameToBossId(((Object)___m_guardianSE).name);
			BossPowerConfigEntry<float> flagsForBoss = PowerFinder.GetFlagsForBoss(num);
			Debug.Log((object)num);
			Debug.Log((object)flagsForBoss.Cooldown);
			Debug.Log((object)"/Prefix");
			___m_guardianSE.m_cooldown = flagsForBoss.Cooldown;
			___m_guardianSE.m_ttl = flagsForBoss.Duration;
		}
	}
}
[HarmonyPatch(typeof(Player), "SetGuardianPower")]
internal static class SetPower_Patch
{
	private static void Postfix(Player __instance, StatusEffect ___m_guardianSE)
	{
		Debug.Log((object)"Postfix SetGuardianPower");
		if (!((Object)(object)___m_guardianSE == (Object)null))
		{
			BossIds num = PowerFinder.StatusNameToBossId(((Object)___m_guardianSE).name);
			BossPowerConfigEntry<float> flagsForBoss = PowerFinder.GetFlagsForBoss(num);
			Debug.Log((object)num);
			Debug.Log((object)flagsForBoss.Cooldown);
			Debug.Log((object)"/Postfix");
			___m_guardianSE.m_cooldown = flagsForBoss.Cooldown;
			___m_guardianSE.m_ttl = flagsForBoss.Duration;
		}
	}
}
[BepInPlugin("fibrechips.PowersConfigurator", "Powers Configurator", "1.0.0")]
public class PowersConfiguratorMod : BaseUnityPlugin
{
	internal const string ModName = "Powers Configurator";

	internal const string ModVersion = "1.0.0";

	internal const string Author = "FibreChips";

	private readonly Harmony harmony = new Harmony("FibreChips.Powers Configurator");

	private const string ModGUID = "FibreChips.Powers Configurator";

	private static readonly string ConfigFileName = "FibreChips.Powers Configurator.cfg";

	private static readonly string ConfigFileFullPath;

	public static readonly ManualLogSource BepinLogger;

	private static readonly ConfigSync ConfigSync;

	private static ConfigEntry<bool> _serverConfigLocked;

	public static ConfigEntry<float> DefaultCooldown;

	public static ConfigEntry<float> DefaultDuration;

	public static ConfigEntry<float> DefaultMultiplier;

	public static Dictionary<BossIds, BossPowerConfigEntry<ConfigEntry<float>>> ModConfig { get; set; }

	private void Awake()
	{
		_serverConfigLocked = ConfigOpt("99 - ServerSync", "Lock Configuration", value: true, "If on, the configuration is locked and can be changed by server admins only.");
		ConfigSync.AddLockingConfigEntry<bool>(_serverConfigLocked);
		int num = 0;
		foreach (BossIds value in Enum.GetValues(typeof(BossIds)))
		{
			string name = Enum.GetName(typeof(BossIds), value);
			ModConfig.Add(value, new BossPowerConfigEntry<ConfigEntry<float>>
			{
				Cooldown = ConfigOpt($"{num} - {name}", name + " Cooldown", 900f, name + " Cooldown (seconds)"),
				Duration = ConfigOpt($"{num} - {name}", name + " Duration", 300f, name + " Duration (seconds)")
			});
			num++;
		}
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		harmony.PatchAll(executingAssembly);
		SetupWatcher();
	}

	private void OnDestroy()
	{
		((BaseUnityPlugin)this).Config.Save();
		harmony.UnpatchSelf();
	}

	private void SetupWatcher()
	{
		FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
		fileSystemWatcher.Changed += ReadConfigValues;
		fileSystemWatcher.Created += ReadConfigValues;
		fileSystemWatcher.Renamed += ReadConfigValues;
		fileSystemWatcher.IncludeSubdirectories = true;
		fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
		fileSystemWatcher.EnableRaisingEvents = true;
	}

	private void ReadConfigValues(object sender, FileSystemEventArgs e)
	{
		if (!File.Exists(ConfigFileFullPath))
		{
			return;
		}
		try
		{
			((BaseUnityPlugin)this).Config.Reload();
		}
		catch
		{
			BepinLogger.LogError((object)("Error reading " + ConfigFileName));
		}
	}

	private ConfigEntry<T> ConfigOpt<T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags);
		ConfigEntry<T> val2 = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val);
		((OwnConfigEntryBase)ConfigSync.AddConfigEntry<T>(val2)).SynchronizedConfig = synchronizedSetting;
		return val2;
	}

	private ConfigEntry<T> ConfigOpt<T>(string group, string name, T value, string description, bool synchronizedSetting = true)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		return ConfigOpt(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
	}

	static PowersConfiguratorMod()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		string configPath = Paths.ConfigPath;
		char directorySeparatorChar = Path.DirectorySeparatorChar;
		ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
		BepinLogger = Logger.CreateLogSource("Powers Configurator");
		ConfigSync = new ConfigSync("FibreChips.Powers Configurator")
		{
			DisplayName = "Powers Configurator",
			CurrentVersion = "1.0.0",
			MinimumRequiredVersion = "1.0.0",
			ModRequired = false
		};
		_serverConfigLocked = null;
		ModConfig = new Dictionary<BossIds, BossPowerConfigEntry<ConfigEntry<float>>>();
	}
}
public enum BossIds
{
	Global,
	Eikthyr,
	Elder,
	Bonemass,
	Moder,
	Yagluth,
	Queen,
	Fader
}
public class BossPowerConfigEntry<T>
{
	public T Duration { get; set; }

	public T Cooldown { get; set; }
}