Decompiled source of Modded Magnet v1.0.2

ModdedMagnet.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ModdedMagnet")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ModdedMagnet")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("db222111-a5e4-4b16-82b8-9366c0ffabd2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ModdedMagnet
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("spapi.etg.modmagnet", "Modded Magnet", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigEntry<float> itemRarityIncrease;

		public static ConfigEntry<float> gunRarityIncrease;

		public static ConfigEntry<bool> isEnabled;

		public static readonly List<WeightedGameObject> objectsIRemovedForItems = new List<WeightedGameObject>();

		public static readonly List<WeightedGameObject> objectsIEditedForItems = new List<WeightedGameObject>();

		public static readonly List<WeightedGameObject> objectsIRemovedForGuns = new List<WeightedGameObject>();

		public static readonly List<WeightedGameObject> objectsIEditedForGuns = new List<WeightedGameObject>();

		public static bool fullyLoaded;

		private static float oldGunWeight = 1f;

		private static float oldItemWeight = 1f;

		public void Awake()
		{
			itemRarityIncrease = ((BaseUnityPlugin)this).Config.Bind<float>("ItemWeight", "ModdedItemRarityMultiplier", 3f, "How much more common modded passive and active items should be.");
			itemRarityIncrease.SettingChanged += delegate
			{
				if (fullyLoaded)
				{
					ReloadItems();
				}
			};
			gunRarityIncrease = ((BaseUnityPlugin)this).Config.Bind<float>("ItemWeight", "ModdedGunRarityMultiplier", 6f, "How much more common modded guns should be.");
			gunRarityIncrease.SettingChanged += delegate
			{
				if (fullyLoaded)
				{
					ReloadGuns();
				}
			};
			isEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Enabled", "ModdedMagnetEnabled", true, "Enable/disable modded item/gun rarity increase.");
			isEnabled.SettingChanged += delegate
			{
				if (fullyLoaded)
				{
					ReloadItems();
					ReloadGuns();
				}
			};
		}

		public void Start()
		{
			ETGModMainBehaviour.WaitForGameManagerStart((Action<GameManager>)GMStart);
		}

		public void GMStart(GameManager manager)
		{
			ETGModConsole.Commands.AddGroup("modded_magnet");
			ConsoleCommandGroup group = ETGModConsole.Commands.GetGroup("modded_magnet");
			group.AddUnit("item_weight", (Action<string[]>)delegate(string[] x)
			{
				float result2;
				if (x.Length < 1)
				{
					ETGModConsole.Log((object)"New weight not given!", false);
				}
				else if (!float.TryParse(x[0], out result2))
				{
					ETGModConsole.Log((object)"Invalid argument! Argument must be a number.", false);
				}
				else
				{
					itemRarityIncrease.Value = result2;
					((BaseUnityPlugin)this).Config.Save();
					ETGModConsole.Log((object)("Modded item weight multiplier successfully set to " + result2), false);
				}
			});
			group.AddUnit("gun_weight", (Action<string[]>)delegate(string[] x)
			{
				float result;
				if (x.Length < 1)
				{
					ETGModConsole.Log((object)"New weight not given!", false);
				}
				else if (!float.TryParse(x[0], out result))
				{
					ETGModConsole.Log((object)"Invalid argument! Argument must be a number.", false);
				}
				else
				{
					gunRarityIncrease.Value = result;
					((BaseUnityPlugin)this).Config.Save();
					ETGModConsole.Log((object)("Modded gun weight multiplier successfully set to " + result), false);
				}
			});
			group.AddUnit("enable", (Action<string[]>)delegate
			{
				isEnabled.Value = true;
				ETGModConsole.Log((object)"Modded item weight increase successfully enabled.", false);
			});
			group.AddUnit("disable", (Action<string[]>)delegate
			{
				isEnabled.Value = false;
				ETGModConsole.Log((object)"Modded item weight increase successfully disabled.", false);
			});
			group.AddUnit("reload", (Action<string[]>)delegate
			{
				if (fullyLoaded)
				{
					ReloadItems();
					ReloadGuns();
					ETGModConsole.Log((object)"Modded item weight increase successfully reloaded.", false);
				}
			});
			group.AddUnit("stats", (Action<string[]>)delegate
			{
				ETGModConsole.Log((object)("Modded item weight multiplier: " + itemRarityIncrease.Value), false);
				ETGModConsole.Log((object)("Modded gun weight multiplier: " + gunRarityIncrease.Value), false);
				ETGModConsole.Log((object)("Modded item weight increase is enabled: " + isEnabled.Value), false);
			});
			ETGModConsole.CommandDescriptions.Add("modded_magnet", "The command group for the Modded Magnet mod.");
			ETGModConsole.CommandDescriptions.Add("modded_magnet item_weight", "Sets the weight multiplier for modded passive and active items.");
			ETGModConsole.CommandDescriptions.Add("modded_magnet gun_weight", "Sets the weight multiplier for modded guns.");
			ETGModConsole.CommandDescriptions.Add("modded_magnet enable", "Enables the weight increase for modded items and guns.");
			ETGModConsole.CommandDescriptions.Add("modded_magnet disable", "Disables the weight increase for modded items and guns.");
			ETGModConsole.CommandDescriptions.Add("modded_magnet reload", "Reloads the modded item and gun weight increase, in case any item or gun was missed.");
			ETGModConsole.CommandDescriptions.Add("modded_magnet stats", "Shows the current weight increase for modded items and guns, as well as if the weight increase is currently enabled.");
			ETGModConsole.Log((object)"Modded Magnet mod successfully loaded.", false);
			ETGModConsole.Log((object)("Modded item weight multiplier: " + itemRarityIncrease.Value), false);
			ETGModConsole.Log((object)("Modded gun weight multiplier: " + gunRarityIncrease.Value), false);
			ETGModConsole.Log((object)("Modded item weight increase is enabled: " + isEnabled.Value), false);
			ETGModConsole.Log((object)"Modded Magnet console command group: modded_magnet", false);
			((MonoBehaviour)this).StartCoroutine(DelayedReloadItems());
		}

		public IEnumerator DelayedReloadItems()
		{
			yield return null;
			ReloadItems();
			ReloadGuns();
			fullyLoaded = true;
		}

		public static void ReloadItems()
		{
			if (objectsIEditedForItems.Count > 0 && oldItemWeight != 0f)
			{
				foreach (WeightedGameObject objectsIEditedForItem in objectsIEditedForItems)
				{
					objectsIEditedForItem.weight /= oldItemWeight;
				}
			}
			objectsIEditedForItems.Clear();
			if (objectsIRemovedForItems.Count > 0)
			{
				GameManager instance = GameManager.Instance;
				if (instance != null)
				{
					instance.RewardManager?.ItemsLootTable?.defaultItemDrops?.elements?.AddRange(objectsIRemovedForItems);
				}
				objectsIRemovedForItems.Clear();
			}
			if (isEnabled.Value)
			{
				GameManager instance2 = GameManager.Instance;
				if (((instance2 == null) ? null : instance2.RewardManager.ItemsLootTable?.defaultItemDrops?.elements) != null)
				{
					foreach (WeightedGameObject element in GameManager.Instance.RewardManager.ItemsLootTable.defaultItemDrops.elements)
					{
						if (element.weight == 0f)
						{
							continue;
						}
						int num = element.pickupId;
						if (num < 0 && (Object)(object)element.gameObject != (Object)null && (Object)(object)element.gameObject.GetComponent<PickupObject>() != (Object)null)
						{
							num = element.gameObject.GetComponent<PickupObject>().PickupObjectId;
						}
						if (num > 823)
						{
							if (itemRarityIncrease.Value == 0f)
							{
								objectsIRemovedForItems.Add(element);
								continue;
							}
							objectsIEditedForItems.Add(element);
							element.weight *= itemRarityIncrease.Value;
						}
					}
				}
			}
			if (objectsIRemovedForItems.Count > 0)
			{
				foreach (WeightedGameObject objectsIRemovedForItem in objectsIRemovedForItems)
				{
					GameManager.Instance.RewardManager.ItemsLootTable.defaultItemDrops.elements.Remove(objectsIRemovedForItem);
				}
			}
			oldItemWeight = itemRarityIncrease.Value;
		}

		public static void ReloadGuns()
		{
			if (objectsIEditedForGuns.Count > 0 && oldGunWeight != 0f)
			{
				foreach (WeightedGameObject objectsIEditedForGun in objectsIEditedForGuns)
				{
					objectsIEditedForGun.weight /= oldGunWeight;
				}
			}
			objectsIEditedForGuns.Clear();
			if (objectsIRemovedForGuns.Count > 0)
			{
				GameManager instance = GameManager.Instance;
				if (instance != null)
				{
					instance.RewardManager?.GunsLootTable?.defaultItemDrops?.elements?.AddRange(objectsIRemovedForGuns);
				}
				objectsIRemovedForGuns.Clear();
			}
			if (isEnabled.Value)
			{
				GameManager instance2 = GameManager.Instance;
				if (((instance2 == null) ? null : instance2.RewardManager.GunsLootTable?.defaultItemDrops?.elements) != null)
				{
					foreach (WeightedGameObject element in GameManager.Instance.RewardManager.GunsLootTable.defaultItemDrops.elements)
					{
						if (element.weight == 0f)
						{
							continue;
						}
						int num = element.pickupId;
						if (num < 0 && (Object)(object)element.gameObject != (Object)null && (Object)(object)element.gameObject.GetComponent<PickupObject>() != (Object)null)
						{
							num = element.gameObject.GetComponent<PickupObject>().PickupObjectId;
						}
						if (num > 823)
						{
							if (gunRarityIncrease.Value == 0f)
							{
								objectsIRemovedForGuns.Add(element);
								continue;
							}
							objectsIEditedForGuns.Add(element);
							element.weight *= gunRarityIncrease.Value;
						}
					}
				}
			}
			if (objectsIRemovedForGuns.Count > 0)
			{
				foreach (WeightedGameObject objectsIRemovedForGun in objectsIRemovedForGuns)
				{
					GameManager.Instance.RewardManager.GunsLootTable.defaultItemDrops.elements.Remove(objectsIRemovedForGun);
				}
			}
			oldGunWeight = gunRarityIncrease.Value;
		}
	}
}