Decompiled source of RaidControl v1.0.1

BepInEx/plugins/RaidControl/RaidControl.dll

Decompiled 2 weeks ago
using System;
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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using CandideServer;
using CandideServer.Server;
using CandideServer.ServerManagers;
using CandideServer.ServerServices;
using HarmonyLib;
using ModSettingsMenu.Api;
using RaidControl.Configuration;
using RomesteadLocalizationAPI.Api;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Raid Control")]
[assembly: AssemblyDescription("Raid Control for Romestead by Ice Box Studio")]
[assembly: AssemblyCompany("Ice Box Studio")]
[assembly: AssemblyProduct("Raid Control")]
[assembly: AssemblyCopyright("Copyright © 2026 Ice Box Studio All rights reserved.")]
[assembly: ComVisible(false)]
[assembly: Guid("f363bb10-e4c3-4a54-962d-9157b37c9dd6")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
namespace RaidControl
{
	internal static class I18n
	{
		public static readonly RomesteadLocalizer L = RomesteadLocalization.For("IceBoxStudio.Romestead.RaidControl");
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "IceBoxStudio.Romestead.RaidControl";

		public const string PLUGIN_NAME = "Raid Control";

		public const string PLUGIN_VERSION = "1.0.1";

		public const string PLUGIN_AUTHOR = "Ice Box Studio";

		public const string PLUGIN_AUTHOR_URL = "https://steamcommunity.com/id/ibox666/";

		public const int NEXUS_MODS_ID = 54;

		public const string THUNDERSTORE_TEAM = "Ice_Box_Studio_Romestead";

		public const string THUNDERSTORE_MOD_NAME = "RaidControl";

		public const string UPDATE_MANIFEST_URL = "https://cdn.jsdelivr.net/gh/ibox233/MyMod_Version@main/RaidControl.json";
	}
	[BepInPlugin("IceBoxStudio.Romestead.RaidControl", "Raid Control", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class RaidControl : BasePlugin
	{
		private Harmony _harmony;

		public static RaidControl Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		public override void Load()
		{
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			Instance = this;
			Logger = ((BasePlugin)this).Log;
			bool flag = default(bool);
			try
			{
				Logger.LogInfo((object)"=============================================");
				ManualLogSource logger = Logger;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(16, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Raid Control");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" initializing...");
				}
				logger.LogInfo(val);
				ManualLogSource logger2 = Logger;
				val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Author: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Ice Box Studio");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("(");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("https://steamcommunity.com/id/ibox666/");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
				}
				logger2.LogInfo(val);
				if (TryGetBridgeRaidTogglePath(out var path))
				{
					ManualLogSource logger3 = Logger;
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(95, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Detected RomesteadBridge RaidToggle at '");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(path);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'. ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("Raid Control");
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" will stay inactive to avoid duplicate raid control.");
					}
					logger3.LogWarning(val2);
					Logger.LogInfo((object)"=============================================");
					return;
				}
				I18n.L.RegisterJson(Path.Combine(Paths.PluginPath, "RaidControl", "Localization.json"));
				ConfigManager.Init(((BasePlugin)this).Config);
				ModSettingsMenuRegistration.Register(((BasePlugin)this).Config);
				_harmony = new Harmony("IceBoxStudio.Romestead.RaidControl");
				_harmony.PatchAll(Assembly.GetExecutingAssembly());
				ManualLogSource logger4 = Logger;
				val = new BepInExInfoLogInterpolatedStringHandler(13, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Raid Control");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" initialized.");
				}
				logger4.LogInfo(val);
				Logger.LogInfo((object)"=============================================");
			}
			catch (Exception ex)
			{
				ManualLogSource logger5 = Logger;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(24, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>("Raid Control");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" initialization error: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("\n");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.StackTrace);
				}
				logger5.LogError(val3);
			}
		}

		private static bool TryGetBridgeRaidTogglePath(out string path)
		{
			string[] array = new string[2]
			{
				Path.Combine(Paths.PluginPath, "RomesteadBridge", "Mods", "RaidToggle", "RaidToggle.dll"),
				Path.Combine(Paths.GameRootPath, "Mods", "RaidToggle", "RaidToggle.dll")
			};
			foreach (string text in array)
			{
				if (File.Exists(text))
				{
					path = text;
					return true;
				}
			}
			path = null;
			return false;
		}
	}
}
namespace RaidControl.Patches
{
	[HarmonyPatch(typeof(RaidsServerManager), "OnNewDay")]
	internal static class RaidsServerManagerPatch
	{
		private const float BaseDailyRaidChance = 0.0574f;

		private static bool IsServerRunning
		{
			get
			{
				BaseServer instance = BaseServer.Instance;
				if (!instance.Running && !instance.Updating)
				{
					return ServerGlobals.StandAlone;
				}
				return true;
			}
		}

		private static bool ShouldApply
		{
			get
			{
				if (!ConfigManager.Active)
				{
					return false;
				}
				return IsServerRunning;
			}
		}

		private static bool Prefix(bool __runOriginal)
		{
			if (!__runOriginal)
			{
				return false;
			}
			if (!ShouldApply)
			{
				return true;
			}
			float naturalRaidChanceModifier = ConfigManager.NaturalRaidChanceModifier;
			if (naturalRaidChanceModifier == 1f)
			{
				return true;
			}
			if (naturalRaidChanceModifier <= 0f || ServerGameState.Towns.Count == 0 || PlayerServerService.JoinedPlayers.Count == 0)
			{
				return false;
			}
			float num = 0.0574f * naturalRaidChanceModifier;
			if (ServerGlobals.Random.NextSingle() < num)
			{
				RaidsServerManager.CreateRandomRaid();
			}
			return false;
		}
	}
}
namespace RaidControl.Configuration
{
	internal static class ConfigManager
	{
		private sealed class SectionTag
		{
			private readonly string _displayNameKey;

			public string Section { get; }

			public string DisplayName => Text(_displayNameKey);

			public int? Order { get; }

			public SectionTag(string section, string displayNameKey, int? order)
			{
				Section = section;
				_displayNameKey = displayNameKey;
				Order = order;
			}
		}

		private sealed class EntryTag
		{
			private readonly string _displayNameKey;

			private readonly string _descriptionKey;

			public string DisplayName => Text(_displayNameKey);

			public string Description => Text(_descriptionKey);

			public int? Order { get; }

			public double? SliderStep { get; }

			public EntryTag(string displayNameKey, string descriptionKey, int? order, double? sliderStep)
			{
				_displayNameKey = displayNameKey;
				_descriptionKey = descriptionKey;
				Order = order;
				SliderStep = sliderStep;
			}
		}

		public const string GeneralSection = "General";

		public const string RaidsSection = "Raids";

		private const float MaxRaidModifier = 20f;

		public static ConfigEntry<bool> Enabled { get; private set; }

		public static ConfigEntry<float> RaidModifier { get; private set; }

		public static bool Active => Enabled?.Value ?? false;

		public static float NaturalRaidChanceModifier
		{
			get
			{
				if (RaidModifier != null)
				{
					return RaidModifier.Value;
				}
				return 1f;
			}
		}

		public static void Init(ConfigFile config)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			Enabled = config.Bind<bool>("General", "Enabled", true, Description("config.enabled.description", "entry.enabled", 1, "General", "section.general", 10));
			RaidModifier = config.Bind<float>("Raids", "RaidModifier", 1f, new ConfigDescription(Text("config.raid_modifier.description"), (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), new object[2]
			{
				new SectionTag("Raids", "section.raids", 20),
				new EntryTag("entry.raid_modifier", "config.raid_modifier.description", 1, 0.1)
			}));
		}

		private static ConfigDescription Description(string descriptionKey, string displayNameKey, int entryOrder, string section, string sectionDisplayNameKey, int sectionOrder, AcceptableValueBase acceptableValues = null, double? sliderStep = null)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			return new ConfigDescription(Text(descriptionKey), acceptableValues, new object[2]
			{
				new SectionTag(section, sectionDisplayNameKey, sectionOrder),
				new EntryTag(displayNameKey, descriptionKey, entryOrder, sliderStep)
			});
		}

		private static string Text(string key)
		{
			return I18n.L.Text(key, Array.Empty<object>());
		}
	}
	internal static class ModSettingsMenuRegistration
	{
		private static ConfigFile _config;

		private static string _locale;

		private static bool _subscribed;

		public static void Register(ConfigFile config)
		{
			_config = config;
			if (!_subscribed)
			{
				ModSettingsRegistry.RefreshRequested += Refresh;
				_subscribed = true;
			}
			RegisterCurrent(config);
		}

		private static void Refresh()
		{
			if (_config != null)
			{
				string currentLocale = I18n.L.CurrentLocale;
				ModSettingsRegistration val = default(ModSettingsRegistration);
				if (!(_locale == currentLocale) || !ModSettingsRegistry.TryGet("IceBoxStudio.Romestead.RaidControl", ref val))
				{
					RegisterCurrent(_config);
				}
			}
		}

		private static void RegisterCurrent(ConfigFile config)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			ModSettingsRegistry.Register("IceBoxStudio.Romestead.RaidControl", Text("mod.name"), config, new ModSettingsModOptions
			{
				Icon = "cog",
				Version = "1.0.1",
				Author = "Ice Box Studio",
				Description = Text("mod.description"),
				NexusModsId = 54,
				ThunderstoreTeam = "Ice_Box_Studio_Romestead",
				ThunderstoreModName = "RaidControl",
				UpdateManifestUrl = "https://cdn.jsdelivr.net/gh/ibox233/MyMod_Version@main/RaidControl.json",
				Order = -75
			});
			_locale = I18n.L.CurrentLocale;
		}

		private static string Text(string key)
		{
			return I18n.L.Text(key, Array.Empty<object>());
		}
	}
}