Decompiled source of WeatherBonuses v1.0.0

DarthLilo.WeatherBonuses.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using Microsoft.CodeAnalysis;
using WeatherBonuses.Helpers;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DarthLilo.WeatherBonuses")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f7692779c9b5cab5aafe2aed9be33166c48fc6f7")]
[assembly: AssemblyProduct("WeatherBonuses")]
[assembly: AssemblyTitle("DarthLilo.WeatherBonuses")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace WeatherBonuses
{
	[BepInPlugin("DarthLilo.WeatherBonuses", "WeatherBonuses", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class WeatherBonuses : BaseUnityPlugin
	{
		public static WeatherBonuses Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			WeatherBonusesConfigHelper.SetLethalConfig(((BaseUnityPlugin)this).Config);
			Patch();
			Logger.LogInfo((object)"DarthLilo.WeatherBonuses v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("DarthLilo.WeatherBonuses");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DarthLilo.WeatherBonuses";

		public const string PLUGIN_NAME = "WeatherBonuses";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace WeatherBonuses.Patches
{
	[HarmonyPatch(typeof(RoundManager))]
	public class WeatherBonus
	{
		public static Dictionary<string, float> WeatherBonusDict()
		{
			Dictionary<string, float> dictionary = new Dictionary<string, float>();
			string value = WeatherBonusesConfigHelper.WeatherValues.Value;
			List<string> list = value.Split(",").ToList();
			foreach (string item in list)
			{
				if (!(item == ""))
				{
					string[] array = item.Split(":");
					string key = array[0];
					string s = array[1];
					dictionary[key] = float.Parse(s);
				}
			}
			return dictionary;
		}

		public static void AddWeatherEntry(string weather)
		{
			string value = WeatherBonusesConfigHelper.WeatherValues.Value;
			if (value == "")
			{
				WeatherBonusesConfigHelper.WeatherValues.Value = weather + ":1.0";
			}
			else
			{
				WeatherBonusesConfigHelper.WeatherValues.Value = value + "," + weather + ":1.0";
			}
		}

		[HarmonyPatch("SpawnScrapInLevel")]
		[HarmonyPrefix]
		private static void AdjustScrapMultiplier(RoundManager __instance)
		{
			string text = ((object)(LevelWeatherType)(ref __instance.currentLevel.currentWeather)).ToString();
			Dictionary<string, float> dictionary = WeatherBonusDict();
			if (dictionary.ContainsKey(text))
			{
				float num = dictionary[text];
				if (WeatherBonusesConfigHelper.OperationMode.Value == WeatherBonusesConfigHelper.OperationModes.BetterScrap)
				{
					__instance.scrapValueMultiplier *= num;
				}
				else if (WeatherBonusesConfigHelper.OperationMode.Value == WeatherBonusesConfigHelper.OperationModes.MoreScrap)
				{
					__instance.scrapAmountMultiplier *= num;
				}
			}
			else
			{
				AddWeatherEntry(text);
				WeatherBonuses.Logger.LogInfo((object)(text + " does not have a multiplier, creating new multiplier with default of 1!"));
				HUDManager.Instance.DisplayTip("WeatherBonuses", text + " did not have a multiplier, created new multiplier with default of 1!", false, false, "LC_Tip1");
			}
		}

		[HarmonyPatch("SpawnScrapInLevel")]
		[HarmonyPostfix]
		private static void RevertScrapMultiplier(RoundManager __instance)
		{
			string key = ((object)(LevelWeatherType)(ref __instance.currentLevel.currentWeather)).ToString();
			Dictionary<string, float> dictionary = WeatherBonusDict();
			if (dictionary.ContainsKey(key))
			{
				float num = dictionary[key];
				if (WeatherBonusesConfigHelper.OperationMode.Value == WeatherBonusesConfigHelper.OperationModes.BetterScrap)
				{
					__instance.scrapValueMultiplier /= num;
				}
				else if (WeatherBonusesConfigHelper.OperationMode.Value == WeatherBonusesConfigHelper.OperationModes.MoreScrap)
				{
					__instance.scrapAmountMultiplier /= num;
				}
			}
		}
	}
}
namespace WeatherBonuses.Helpers
{
	public static class WeatherBonusesConfigHelper
	{
		public enum OperationModes
		{
			BetterScrap,
			MoreScrap
		}

		public static ConfigEntry<string> WeatherValues;

		public static ConfigEntry<OperationModes> OperationMode;

		public static void SetLethalConfig(ConfigFile config)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			OperationMode = config.Bind<OperationModes>("Weather Bonuses", "OperationMode", OperationModes.BetterScrap, "Better scrap will adjust the value of scrap to be higher depending on the weather, more scrap will increase the amount of scrap that can spawn based on the weather");
			EnumDropDownConfigItem<OperationModes> val = new EnumDropDownConfigItem<OperationModes>(OperationMode, true);
			WeatherValues = config.Bind<string>("Weather Bonuses", "WeatherValues", "Foggy:1.05,Flooded:1.15,Rainy:1.1,Stormy:1.15,Eclipsed:1.25", "Multipliers for weather, increases scrap value for moons with these weather effects");
			TextInputFieldConfigItem val2 = new TextInputFieldConfigItem(WeatherValues, true);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
			LethalConfigManager.SetModDescription("A mod for boosting scrap values on planets with specific weather");
		}
	}
}