Decompiled source of ScrapOutside v1.0.0

ScrapOutside.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Unity.Netcode;
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("ScrapOutside")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ScrapOutside")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("19a4624c-a7b7-4c89-8682-b6fff6feb900")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HideNotifications;

[BepInPlugin("com.toshizuno.scrapoutside", "Scrap Outside", "1.0.0")]
public class ScrapOutsidePlugin : BaseUnityPlugin
{
	public static class Configuration
	{
		public static class Scrap
		{
			public static string Blacklist;

			public static int Chance;

			public static bool Clustered;

			public static int Maximum;

			public static int Minimum;

			public static int Value;
		}
	}

	public static class RoundManager
	{
		public static List<int> allScrapValue;

		public static List<NetworkObjectReference> spawnedScrap;

		public static void SpawnScrapInLevel(RoundManager __instance)
		{
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return;
			}
			spawnedScrap = new List<NetworkObjectReference>();
			allScrapValue = new List<int>();
			if (Configuration.Scrap.Chance <= 0)
			{
				return;
			}
			if (Configuration.Scrap.Chance > 100)
			{
				Configuration.Scrap.Chance = 100;
			}
			if (Configuration.Scrap.Maximum < 1)
			{
				return;
			}
			if (Configuration.Scrap.Minimum > Configuration.Scrap.Maximum)
			{
				Configuration.Scrap.Minimum = Configuration.Scrap.Maximum;
			}
			if (Configuration.Scrap.Value <= 0 || __instance.AnomalyRandom.Next(0, 100) + 1 > Configuration.Scrap.Chance)
			{
				return;
			}
			List<Vector3> list = new List<Vector3>();
			int num = __instance.AnomalyRandom.Next(Configuration.Scrap.Minimum, Configuration.Scrap.Maximum + 1);
			List<GameObject> list2 = new List<GameObject>(__instance.outsideAINodes);
			if (Configuration.Scrap.Clustered)
			{
				Vector3 Anchor = __instance.outsideAINodes[__instance.AnomalyRandom.Next(0, __instance.outsideAINodes.Length - 1)].transform.position;
				list2.Sort((GameObject a, GameObject b) => Vector3.Distance(a.transform.position, Anchor).CompareTo(Vector3.Distance(b.transform.position, Anchor)));
				list.Add(Anchor);
				while (list.Count < num && list2.Count > 0)
				{
					if (list2[0].transform.position == Anchor)
					{
						list2.RemoveAt(0);
						continue;
					}
					list.Add(list2[0].transform.position);
					list2.RemoveAt(0);
				}
			}
			else
			{
				while (list.Count < num && list2.Count > 0)
				{
					int index = __instance.AnomalyRandom.Next(0, list2.Count);
					list.Add(list2[index].transform.position);
					list2.RemoveAt(index);
				}
			}
			List<Item> list3 = new List<Item>();
			List<int> list4 = new List<int>();
			List<SpawnableItemWithRarity> list5 = new List<SpawnableItemWithRarity>();
			for (int i = 0; i < __instance.currentLevel.spawnableScrap.Count; i++)
			{
				bool flag = false;
				string[] array = Configuration.Scrap.Blacklist.Trim().Split(new char[1] { ';' });
				foreach (string text in array)
				{
					if (text.ToLower() == __instance.currentLevel.spawnableScrap[i].spawnableItem.itemName.ToLower())
					{
						flag = true;
					}
					if (__instance.currentLevel.spawnableScrap[i].spawnableItem.minValue > Configuration.Scrap.Value)
					{
						flag = true;
					}
				}
				if (!flag)
				{
					list5.Add(__instance.currentLevel.spawnableScrap[i]);
					list4.Add(__instance.currentLevel.spawnableScrap[i].rarity);
				}
			}
			if (list4.Count == 0)
			{
				return;
			}
			int[] array2 = list4.ToArray();
			for (int k = 0; k < num; k++)
			{
				list3.Add(list5[__instance.GetRandomWeightedIndex(array2, (Random)null)].spawnableItem);
			}
			int num2 = 0;
			int num3 = -1;
			List<Vector3> list6 = new List<Vector3>();
			foreach (Item item in list3)
			{
				if (num2 == list3.Count)
				{
					break;
				}
				num3++;
				if (num3 == list.Count)
				{
					break;
				}
				if (!list6.Contains(list[num3]))
				{
					Vector3 val = list[num3];
					GameObject val2 = Object.Instantiate<GameObject>(list3[num2].spawnPrefab, val, Quaternion.identity, __instance.spawnedScrapContainer);
					GrabbableObject component = val2.GetComponent<GrabbableObject>();
					((Component)component).transform.rotation = Quaternion.Euler(component.itemProperties.restingRotation);
					component.fallTime = 0f;
					((BaseUnityPlugin)instance).Logger.LogFatal((object)$"minValue: {list3[num2].minValue} maxValue: {Configuration.Scrap.Value + 1}");
					allScrapValue.Add((int)((float)__instance.AnomalyRandom.Next(list3[num2].minValue, Configuration.Scrap.Value + 1) * __instance.scrapValueMultiplier));
					component.scrapValue = allScrapValue[allScrapValue.Count - 1];
					NetworkObject component2 = val2.GetComponent<NetworkObject>();
					component2.Spawn(false);
					spawnedScrap.Add(NetworkObjectReference.op_Implicit(component2));
					num2++;
				}
			}
		}

		public static void SyncScrapValuesClientRpc(RoundManager __instance, ref NetworkObjectReference[] spawnedScrap, ref int[] allScrapValue)
		{
			if (((NetworkBehaviour)__instance).IsServer && RoundManager.spawnedScrap.Count != 0)
			{
				List<int> list = new List<int>(allScrapValue);
				list.AddRange(RoundManager.allScrapValue);
				List<NetworkObjectReference> list2 = new List<NetworkObjectReference>(spawnedScrap);
				list2.AddRange(RoundManager.spawnedScrap);
				allScrapValue = list.ToArray();
				spawnedScrap = list2.ToArray();
			}
		}
	}

	private static ScrapOutsidePlugin instance;

	private readonly Harmony patcher = new Harmony("com.toshizuno.scrapoutside");

	private void Awake()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Expected O, but got Unknown
		instance = instance ?? this;
		patcher.Patch((MethodBase)typeof(RoundManager).GetMethod("SpawnScrapInLevel"), (HarmonyMethod)null, new HarmonyMethod(typeof(RoundManager).GetMethod("SpawnScrapInLevel")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		patcher.Patch((MethodBase)typeof(RoundManager).GetMethod("SyncScrapValuesClientRpc"), new HarmonyMethod(typeof(RoundManager).GetMethod("SyncScrapValuesClientRpc")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		ConfigEntry<string> val = ((BaseUnityPlugin)this).Config.Bind<string>("Scrap", "Blacklist", "", "Semicolon-separated list of blacklisted items.");
		ConfigEntry<int> val2 = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "Chance", 100, "The % chance for items to spawn outside.");
		ConfigEntry<bool> val3 = ((BaseUnityPlugin)this).Config.Bind<bool>("Scrap", "Clustered", false, "Whether or not to spawn items in a cluster.");
		ConfigEntry<int> val4 = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "Maximum", 3, "The maximum amount of items to spawn outside.");
		ConfigEntry<int> val5 = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "Minimum", 1, "The minimum amount of items to spawn outside.");
		ConfigEntry<int> val6 = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "Value", 32, "The maximum value that outside items can be worth.");
		Configuration.Scrap.Blacklist = val.Value;
		Configuration.Scrap.Chance = val2.Value;
		Configuration.Scrap.Clustered = val3.Value;
		Configuration.Scrap.Maximum = val4.Value;
		Configuration.Scrap.Minimum = val5.Value;
		Configuration.Scrap.Value = val6.Value;
	}
}