Decompiled source of Maxwell ScrapItem v1.0.1

BepInEx\plugins\MaxwellScrap.dll

Decompiled a year ago
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LaserTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LaserTweaks")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4963e0ea-7a99-4390-9cae-a4bdd01b6b43")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace MaxwellScrap
{
	public class Assets
	{
		public static AssetBundle MainAssetBundle;

		public static Item Item;

		internal static Stream GetEmbededResource(string name)
		{
			return Assembly.GetExecutingAssembly().GetManifestResourceStream("MaxwellScrap." + name);
		}

		public static void Init()
		{
			MainAssetBundle = AssetBundle.LoadFromStream(GetEmbededResource("maxwell.bundle"));
			Item = MainAssetBundle.LoadAsset<Item>("Assets/Mods/MaxwellScrapItem/Maxwell.asset");
		}
	}
	[BepInPlugin("Kittenji.MaxwellScrap", "Maxwell Scrap", "1.0.1")]
	public class Loader : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(GameNetworkManager))]
		internal class GameNetworkManagerPatch
		{
			[HarmonyPatch("Start")]
			[HarmonyPostfix]
			private static void StartPatch()
			{
				((Component)GameNetworkManager.Instance).GetComponent<NetworkManager>().AddNetworkPrefab(Assets.Item.spawnPrefab);
				Debug.Log((object)"[MAXWELL] Added network prefab");
			}
		}

		[HarmonyPatch(typeof(StartOfRound))]
		internal class StartOfRoundPatch
		{
			[HarmonyPatch("Awake")]
			[HarmonyPostfix]
			private static void AwakePatch(ref StartOfRound __instance)
			{
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Expected O, but got Unknown
				SelectableLevel[] levels = __instance.levels;
				foreach (SelectableLevel val in levels)
				{
					if (val.spawnableScrap.Any((SpawnableItemWithRarity x) => (Object)(object)x.spawnableItem == (Object)(object)Assets.Item))
					{
						continue;
					}
					int num = 2;
					SpawnableItemWithRarity val2 = val.spawnableScrap.Find((SpawnableItemWithRarity s) => Object.op_Implicit((Object)(object)s.spawnableItem) && Object.op_Implicit((Object)(object)s.spawnableItem.spawnPrefab) && ((Object)s.spawnableItem.spawnPrefab).name == "CashRegisterItem");
					if (val2 != null)
					{
						num = val2.rarity;
					}
					else if (val.spawnableScrap.Count > 0)
					{
						int num2 = int.MaxValue;
						foreach (SpawnableItemWithRarity item2 in val.spawnableScrap)
						{
							if (item2.rarity < num2)
							{
								num2 = item2.rarity;
							}
						}
						num = num2;
					}
					num = Mathf.Min(100, Mathf.Max(1, num));
					SpawnableItemWithRarity item = new SpawnableItemWithRarity
					{
						spawnableItem = Assets.Item,
						rarity = num
					};
					val.spawnableScrap.Add(item);
				}
				if (!__instance.allItemsList.itemsList.Contains(Assets.Item))
				{
					__instance.allItemsList.itemsList.Add(Assets.Item);
				}
			}
		}

		private const string modGUID = "Kittenji.MaxwellScrap";

		private readonly Harmony harmony = new Harmony("Kittenji.MaxwellScrap");

		private const int DefaultSpawnRarity = 2;

		private void Awake()
		{
			Assets.Init();
			harmony.PatchAll();
		}
	}
}