Decompiled source of Weather Gains v1.1.0

robuxtrex.weathergains.dll

Decompiled 2 months 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;
using WeatherGains.Types;

[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+88c0c692f99ff9ac779eaf040c708d75ae9e0072")]
[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 ConfigEntry<bool> ValueMultiEnabled;

		public ConfigEntry<bool> AmountMultiEnabled;

		public ConfigEntry<bool> LungValueMultiEnabled;

		public ConfigEntry<float> FogValueMultiplier;

		public ConfigEntry<float> FogAmountMultiplier;

		public ConfigEntry<float> RainValueMultiplier;

		public ConfigEntry<float> RainAmountMultiplier;

		public ConfigEntry<float> ClearValueMultiplier;

		public ConfigEntry<float> ClearAmountMultiplier;

		public ConfigEntry<float> StormValueMultiplier;

		public ConfigEntry<float> StormAmountMultiplier;

		public ConfigEntry<float> FloodValueMultiplier;

		public ConfigEntry<float> FloodAmountMultiplier;

		public ConfigEntry<float> EclipsedValueMultiplier;

		public ConfigEntry<float> EclipsedAmountMultiplier;

		public readonly Dictionary<LevelWeatherType, MultiValueGroup> Multipliers;

		public ConfigFile ApplyConfig(ConfigFile cfg)
		{
			ValueMultiEnabled = cfg.Bind<bool>("General", "Value Multiplier Enabled", true, "Whether the scrap value multiplier is enabled.");
			AmountMultiEnabled = cfg.Bind<bool>("General", "Amount Multiplier Enabled", true, "Whether the scrap amount multiplier is enabled.");
			LungValueMultiEnabled = cfg.Bind<bool>("General", "Apparatus Multiplier Enabled", true, "Whether the Apparatus value multiplier 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.");
			return cfg;
		}

		public ModConfiguration(ConfigFile cfg)
		{
			InitInstance(this);
			cfg.SaveOnConfigSet = false;
			cfg = ApplyConfig(cfg);
			Multipliers = new Dictionary<LevelWeatherType, MultiValueGroup>
			{
				{
					(LevelWeatherType)3,
					new MultiValueGroup
					{
						ValueMultiplier = FogValueMultiplier,
						AmountMultiplier = FogAmountMultiplier
					}
				},
				{
					(LevelWeatherType)1,
					new MultiValueGroup
					{
						ValueMultiplier = RainValueMultiplier,
						AmountMultiplier = RainAmountMultiplier
					}
				},
				{
					(LevelWeatherType)(-1),
					new MultiValueGroup
					{
						ValueMultiplier = ClearValueMultiplier,
						AmountMultiplier = ClearAmountMultiplier
					}
				},
				{
					(LevelWeatherType)2,
					new MultiValueGroup
					{
						ValueMultiplier = StormValueMultiplier,
						AmountMultiplier = StormAmountMultiplier
					}
				},
				{
					(LevelWeatherType)4,
					new MultiValueGroup
					{
						ValueMultiplier = FloodValueMultiplier,
						AmountMultiplier = FloodAmountMultiplier
					}
				},
				{
					(LevelWeatherType)5,
					new MultiValueGroup
					{
						ValueMultiplier = EclipsedValueMultiplier,
						AmountMultiplier = EclipsedAmountMultiplier
					}
				}
			};
			ClearOrphanedEntries(cfg);
			cfg.Save();
			cfg.SaveOnConfigSet = true;
		}

		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);
			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.Types
{
	public class MultiValueGroup
	{
		public ConfigEntry<float> ValueMultiplier { get; set; }

		public ConfigEntry<float> AmountMultiplier { get; set; }
	}
}
namespace WeatherGains.Patches
{
	[HarmonyPatch(typeof(LungProp))]
	public class LungPropPatch
	{
		[HarmonyPatch("DisconnectFromMachinery")]
		[HarmonyPrefix]
		private static void DisconnectFromMachineryPatch(LungProp __instance)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (WeatherGains.BoundConfig.LungValueMultiEnabled.Value)
			{
				((GrabbableObject)__instance).SetScrapValue((int)((float)((GrabbableObject)__instance).scrapValue * WeatherGains.BoundConfig.Multipliers[TimeOfDay.Instance.currentLevelWeather].ValueMultiplier.Value));
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	public class RoundManagerPatch
	{
		[HarmonyPatch("SpawnScrapInLevel")]
		[HarmonyPrefix]
		private static void SpawnScrapInLevelPrefix()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (WeatherGains.BoundConfig.ValueMultiEnabled.Value)
			{
				RoundManager instance = RoundManager.Instance;
				instance.scrapValueMultiplier *= WeatherGains.BoundConfig.Multipliers[TimeOfDay.Instance.currentLevelWeather].ValueMultiplier.Value;
			}
			if (WeatherGains.BoundConfig.AmountMultiEnabled.Value)
			{
				RoundManager instance2 = RoundManager.Instance;
				instance2.scrapAmountMultiplier *= WeatherGains.BoundConfig.Multipliers[TimeOfDay.Instance.currentLevelWeather].AmountMultiplier.Value;
			}
			WeatherGains.Logger.LogInfo((object)($"Successfully modified the scrap generation values for weather type {TimeOfDay.Instance.currentLevelWeather} on moon (level) {TimeOfDay.Instance.currentLevel}!\n\n" + $"Modded Value Multiplier: {RoundManager.Instance.scrapValueMultiplier}\n" + $"Modded Amount Multiplier: {RoundManager.Instance.scrapAmountMultiplier}"));
		}

		[HarmonyPatch("SpawnScrapInLevel")]
		[HarmonyPostfix]
		private static void SpawnScrapInLevelPostfix()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (WeatherGains.BoundConfig.ValueMultiEnabled.Value)
			{
				RoundManager.Instance.scrapValueMultiplier = 1f;
			}
			if (WeatherGains.BoundConfig.AmountMultiEnabled.Value)
			{
				RoundManager.Instance.scrapAmountMultiplier = 1f;
			}
			WeatherGains.Logger.LogInfo((object)($"Successfully reverted the scrap generation values for weather type {TimeOfDay.Instance.currentLevelWeather} on moon (level) {TimeOfDay.Instance.currentLevel}!\n\n" + $"Reverted Value Multiplier: {RoundManager.Instance.scrapValueMultiplier}\n" + $"Reverted Amount Multiplier: {RoundManager.Instance.scrapAmountMultiplier}\n\n" + "This is intended functionality... the mod isn't breaking!"));
		}
	}
}