Decompiled source of ValheimBetterWorldModifiers v1.0.0

ValheimBetterWorldModifiers.dll

Decompiled a year ago
using System.Diagnostics;
using System.Linq;
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 UnityEngine;
using UnityEngine.UI;
using ValheimBetterWorldModifiers.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ValheimBetterWorldModifiers")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ValheimBetterWorldModifiers")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0a50151e-663e-42be-9d8a-e3aa10286a4e")]
[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 ValheimBetterWorldModifiers
{
	[BepInPlugin("NoOneOutPizzasTheHut.ValheimBetterWorldModifiers", "BetterWorldModifiers", "1.0.0.0")]
	public class ValheimBetterWorldModifiersBase : BaseUnityPlugin
	{
		private const string modGUID = "NoOneOutPizzasTheHut.ValheimBetterWorldModifiers";

		private const string modName = "BetterWorldModifiers";

		private const string modVersion = "1.0.0.0";

		private readonly Harmony harmony = new Harmony("NoOneOutPizzasTheHut.ValheimBetterWorldModifiers");

		private static ValheimBetterWorldModifiersBase Instance;

		internal static ManualLogSource logger;

		public static ConfigEntry<int> resourceSliderMaxValue { get; private set; }

		private void Awake()
		{
			Initialize();
			applyPatches();
			logger.LogInfo((object)"BetterWorldModifiers has been awaken!");
		}

		public void Initialize()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = new ValheimBetterWorldModifiersBase();
			}
			logger = Logger.CreateLogSource("NoOneOutPizzasTheHut.ValheimBetterWorldModifiers");
			resourceSliderMaxValue = ((BaseUnityPlugin)this).Config.Bind<int>("ValheimBetterWorldModifiers", "resourceSliderMaxValue", 10, "Set the desired max slider value for world modifiers");
			if (resourceSliderMaxValue.Value < 3)
			{
				resourceSliderMaxValue.Value = 3;
			}
		}

		public void applyPatches()
		{
			harmony.PatchAll(typeof(ValheimBetterWorldModifiersBase));
			logger.LogInfo((object)"ValheimBetterWorldModifiersBase has been patched in!");
			harmony.PatchAll(typeof(WorldModifiersPatch));
			logger.LogInfo((object)"ValheimBetterWorldModifiers.KeySliderPatch has been patched in!");
		}
	}
}
namespace ValheimBetterWorldModifiers.Patches
{
	[HarmonyPatch(typeof(ServerOptionsGUI))]
	public static class WorldModifiersPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		private static void ModifyAwake(ServerOptionsGUI __instance)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Expected O, but got Unknown
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			KeyUI[] componentsInChildren = ((Component)__instance.m_modifiersRoot.transform).GetComponentsInChildren<KeyUI>();
			foreach (KeyUI val in componentsInChildren)
			{
				KeySlider val2 = (KeySlider)(object)((val is KeySlider) ? val : null);
				if (val2 == null || !(val2.m_toolTip == "$menu_resources_tooltip"))
				{
					continue;
				}
				int num = 4;
				int num2 = ValheimBetterWorldModifiersBase.resourceSliderMaxValue.Value - (num - 1);
				foreach (int item in Enumerable.Range(num, num2))
				{
					if (item == num + 1)
					{
						val2.m_settings[item].m_modifierValue = (WorldModifierOption)5;
					}
					else if (item == num + num2 - 1)
					{
						SliderSetting val3 = new SliderSetting();
						val3.m_name = "x " + item;
						val3.m_toolTip = "";
						val3.m_keys.Add("resourcerate " + item * 100);
						val3.m_modifierValue = (WorldModifierOption)12;
						val2.m_settings.Add(val3);
						Slider val4 = (Slider)Traverse.Create((object)val2).Field("m_slider").GetValue();
						val4.maxValue += 1f;
						Traverse.Create((object)val2).Field("m_slider").SetValue((object)val4);
					}
					else
					{
						SliderSetting val5 = new SliderSetting();
						val5.m_name = "x " + item;
						val5.m_toolTip = "";
						val5.m_keys.Add("resourcerate " + item * 100);
						val5.m_modifierValue = (WorldModifierOption)5;
						val2.m_settings.Add(val5);
						Slider val6 = (Slider)Traverse.Create((object)val2).Field("m_slider").GetValue();
						val6.maxValue += 1f;
						Traverse.Create((object)val2).Field("m_slider").SetValue((object)val6);
					}
				}
			}
		}
	}
}