Decompiled source of Weather Gains v1.0.0

robuxtrex.weathergains.dll

Decompiled 4 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("robuxtrex.weathergains")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WeatherGains")]
[assembly: AssemblyTitle("robuxtrex.weathergains")]
[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 WeatherGains
{
	[Serializable]
	public class ModConfiguration : SyncedInstance<ModConfiguration>
	{
		public class MultiplierDictType
		{
			public ConfigEntry<float> ValueMultiplier { get; set; }

			public ConfigEntry<float> AmountMultiplier { get; set; }
		}

		public readonly ConfigEntry<bool> Enabled;

		public readonly ConfigEntry<float> FogValueMultiplier;

		public readonly ConfigEntry<float> FogAmountMultiplier;

		public readonly ConfigEntry<float> RainValueMultiplier;

		public readonly ConfigEntry<float> RainAmountMultiplier;

		public readonly ConfigEntry<float> ClearValueMultiplier;

		public readonly ConfigEntry<float> ClearAmountMultiplier;

		public readonly ConfigEntry<float> StormValueMultiplier;

		public readonly ConfigEntry<float> StormAmountMultiplier;

		public readonly ConfigEntry<float> FloodValueMultiplier;

		public readonly ConfigEntry<float> FloodAmountMultiplier;

		public readonly ConfigEntry<float> EclipsedValueMultiplier;

		public readonly ConfigEntry<float> EclipsedAmountMultiplier;

		public readonly Dictionary<LevelWeatherType, MultiplierDictType> Multipliers;

		public ModConfiguration(ConfigFile cfg)
		{
			InitInstance(this);
			cfg.SaveOnConfigSet = false;
			Enabled = cfg.Bind<bool>("General", "Enabled", true, "Whether the mod is enabled.");
			FogValueMultiplier = cfg.Bind<float>("Multipliers", "FogValueMultiplier", 1.2f, "Scrap value multiplier during foggy weather on a moon. Set to 1 for no change.");
			FogAmountMultiplier = cfg.Bind<float>("Multipliers", "FogAmountMultiplier", 1.1f, "Scrap amount multiplier during foggy weather on a moon. Set to 1 for no change.");
			RainValueMultiplier = cfg.Bind<float>("Multipliers", "RainValueMultiplier", 1.2f, "Scrap value multiplier during rain weather on a moon. Set to 1 for no change.");
			RainAmountMultiplier = cfg.Bind<float>("Multipliers", "RainAmountMultiplier", 1.1f, "Scrap amount multiplier during rain weather on a moon. Set to 1 for no change.");
			ClearValueMultiplier = cfg.Bind<float>("Multipliers", "ClearValueMultiplier", 1f, "Scrap value multiplier during clear/no weather on a moon. Set to 1 for no change.");
			ClearAmountMultiplier = cfg.Bind<float>("Multipliers", "ClearAmountMultiplier", 1f, "Scrap amount multiplier during clear/no weather on a moon. Set to 1 for no change.");
			FloodValueMultiplier = cfg.Bind<float>("Multipliers", "FloodValueMultiplier", 1.5f, "Scrap value multiplier during floods on a moon. Set to 1 for no change.");
			FloodAmountMultiplier = cfg.Bind<float>("Multipliers", "FloodAmountMultiplier", 1.25f, "Scrap amount multiplier during floods on a moon. Set to 1 for no change.");
			StormValueMultiplier = cfg.Bind<float>("Multipliers", "StormValueMultiplier", 1.55f, "Scrap value multiplier during storms on a moon. Set to 1 for no change.");
			StormAmountMultiplier = cfg.Bind<float>("Multipliers", "StormAmountMultiplier", 1.3f, "Scrap amount multiplier during storms on a moon. Set to 1 for no change.");
			EclipsedValueMultiplier = cfg.Bind<float>("Multipliers", "EclipsedValueMultiplier", 2.1f, "Scrap value multiplier during eclipsed weather on a moon. Set to 1 for no change.");
			EclipsedAmountMultiplier = cfg.Bind<float>("Multipliers", "EclipsedAmountMultiplier", 1.4f, "Scrap amount multiplier during eclipsed weather on a moon. Set to 1 for no change.");
			ClearOrphanedEntries(cfg);
			cfg.Save();
			cfg.SaveOnConfigSet = true;
			Multipliers = new Dictionary<LevelWeatherType, MultiplierDictType>
			{
				{
					(LevelWeatherType)3,
					new MultiplierDictType
					{
						ValueMultiplier = FogValueMultiplier,
						AmountMultiplier = FogAmountMultiplier
					}
				},
				{
					(LevelWeatherType)1,
					new MultiplierDictType
					{
						ValueMultiplier = RainValueMultiplier,
						AmountMultiplier = RainAmountMultiplier
					}
				},
				{
					(LevelWeatherType)(-1),
					new MultiplierDictType
					{
						ValueMultiplier = ClearValueMultiplier,
						AmountMultiplier = ClearAmountMultiplier
					}
				},
				{
					(LevelWeatherType)2,
					new MultiplierDictType
					{
						ValueMultiplier = StormValueMultiplier,
						AmountMultiplier = StormAmountMultiplier
					}
				},
				{
					(LevelWeatherType)4,
					new MultiplierDictType
					{
						ValueMultiplier = FloodValueMultiplier,
						AmountMultiplier = FloodAmountMultiplier
					}
				},
				{
					(LevelWeatherType)5,
					new MultiplierDictType
					{
						ValueMultiplier = EclipsedValueMultiplier,
						AmountMultiplier = EclipsedAmountMultiplier
					}
				}
			};
		}

		private static void ClearOrphanedEntries(ConfigFile cfg)
		{
			((Dictionary<ConfigDefinition, string>)AccessTools.Property(typeof(ConfigFile), "OrphanedEntries").GetValue(cfg)).Clear();
		}
	}
	[Serializable]
	public class SyncedInstance<T>
	{
		[NonSerialized]
		protected static int IntSize = 4;

		internal static CustomMessagingManager MessageManager => NetworkManager.Singleton.CustomMessagingManager;

		internal static bool IsClient => NetworkManager.Singleton.IsClient;

		internal static bool IsHost => NetworkManager.Singleton.IsHost;

		public static T Default { get; private set; }

		public static T Instance { get; private set; }

		public static bool Synced { get; internal set; }

		protected void InitInstance(T instance)
		{
			Default = instance;
			Instance = instance;
			IntSize = 4;
		}

		internal static void SyncInstance(byte[] data)
		{
			Instance = DeserializeFromBytes(data);
			Synced = true;
		}

		internal static void RevertSync()
		{
			Instance = Default;
			Synced = false;
		}

		public static byte[] SerializeToBytes(T val)
		{
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			using MemoryStream memoryStream = new MemoryStream();
			try
			{
				binaryFormatter.Serialize(memoryStream, val);
				return memoryStream.ToArray();
			}
			catch (Exception arg)
			{
				WeatherGains.Logger.LogError((object)$"Error serializing instance: {arg}");
				return null;
			}
		}

		public static T DeserializeFromBytes(byte[] data)
		{
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			using MemoryStream serializationStream = new MemoryStream(data);
			try
			{
				return (T)binaryFormatter.Deserialize(serializationStream);
			}
			catch (Exception arg)
			{
				WeatherGains.Logger.LogError((object)$"Error deserializing instance: {arg}");
				return default(T);
			}
		}
	}
	[BepInPlugin("robuxtrex.weathergains", "WeatherGains", "1.0.0")]
	public class WeatherGains : BaseUnityPlugin
	{
		internal static ModConfiguration BoundConfig { get; private set; }

		public static WeatherGains 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;
			Logger.LogInfo((object)"robuxtrex.weathergains v1.0.0 is loading...");
			BoundConfig = new ModConfiguration(((BaseUnityPlugin)this).Config);
			if (!BoundConfig.Enabled.Value)
			{
				Logger.LogWarning((object)"robuxtrex.weathergains v1.0.0 is disabled! If this is in error, please refer to the mod's configuration files.");
				return;
			}
			Patch();
			Logger.LogInfo((object)"robuxtrex.weathergains v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("robuxtrex.weathergains");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "robuxtrex.weathergains";

		public const string PLUGIN_NAME = "WeatherGains";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace WeatherGains.Patches
{
	[HarmonyPatch(typeof(RoundManager))]
	public class RoundManagerPatch
	{
		[HarmonyPatch("SpawnScrapInLevel")]
		[HarmonyPrefix]
		private static void SpawnScrapInLevelPatch()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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)
			RoundManager.Instance.scrapValueMultiplier = WeatherGains.BoundConfig.Multipliers[TimeOfDay.Instance.currentLevelWeather].ValueMultiplier.Value;
			RoundManager.Instance.scrapAmountMultiplier = WeatherGains.BoundConfig.Multipliers[TimeOfDay.Instance.currentLevelWeather].AmountMultiplier.Value;
			WeatherGains.Logger.LogInfo((object)($"Successfully attempted to modify the scrap generation values for weather type {TimeOfDay.Instance.currentLevelWeather} on moon (level) {TimeOfDay.Instance.currentLevel}!\n\n" + $"Value Multiplier: {RoundManager.Instance.scrapValueMultiplier}\n" + $"Amount Multiplier: {RoundManager.Instance.scrapAmountMultiplier}"));
		}
	}
}