Decompiled source of AlwaysSingleItemDay v1.0.1

AlwaysSingleItemDay.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
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("AlwaysSingleItemDay")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AlwaysSingleItemDay")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("50608724-716f-4acd-bb43-680dfb16f88f")]
[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 AlwaysSingleItemDay;

[BepInPlugin("azumi.alwayssingleitemday", "AlwaysSingleItemDay", "1.0.1")]
public class AlwaysSingleItemDayPlugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	internal static ConfigEntry<float> SidChance;

	internal static ConfigEntry<bool> EnablePredictionChat;

	internal static bool SidActive;

	internal static Item SidItem;

	private void Awake()
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		SidChance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SidChance", 100f, "Probability of SID activation (0-100).");
		EnablePredictionChat = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnablePredictionChat", true, "Send SID prediction message to chat.");
		Harmony val = new Harmony("azumi.alwayssingleitemday");
		val.PatchAll();
		Log.LogInfo((object)"AlwaysSingleItemDay loaded.");
	}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
	private static bool chatSent;

	[HarmonyPatch("FinishGeneratingNewLevelClientRpc")]
	[HarmonyPostfix]
	private static void Reset()
	{
		AlwaysSingleItemDayPlugin.SidActive = false;
		AlwaysSingleItemDayPlugin.SidItem = null;
		chatSent = false;
	}

	[HarmonyPatch("SpawnScrapInLevel")]
	[HarmonyPrefix]
	private static bool SpawnScrapInLevel(RoundManager __instance)
	{
		try
		{
			if (!((NetworkBehaviour)StartOfRound.Instance).IsHost)
			{
				return true;
			}
			if ((Object)(object)__instance.currentLevel == (Object)null)
			{
				return true;
			}
			if (__instance.currentLevel.PlanetName != null && __instance.currentLevel.PlanetName.ToLower().Contains("gordion"))
			{
				return true;
			}
			float num = Mathf.Clamp(AlwaysSingleItemDayPlugin.SidChance.Value, 0f, 100f);
			float num2 = (float)__instance.AnomalyRandom.NextDouble() * 100f;
			if (num2 > num)
			{
				return true;
			}
			List<SpawnableItemWithRarity> spawnableScrap = __instance.currentLevel.spawnableScrap;
			if (spawnableScrap == null || spawnableScrap.Count == 0)
			{
				return true;
			}
			List<int> list = new List<int>();
			for (int i = 0; i < spawnableScrap.Count; i++)
			{
				list.Add(Mathf.Max(1, spawnableScrap[i].rarity));
			}
			int randomWeightedIndex = __instance.GetRandomWeightedIndex(list.ToArray(), (Random)null);
			if (randomWeightedIndex < 0 || randomWeightedIndex >= spawnableScrap.Count)
			{
				return true;
			}
			Item spawnableItem = spawnableScrap[randomWeightedIndex].spawnableItem;
			if ((Object)(object)spawnableItem == (Object)null)
			{
				return true;
			}
			AlwaysSingleItemDayPlugin.SidActive = true;
			AlwaysSingleItemDayPlugin.SidItem = spawnableItem;
			SendPredictionChat(spawnableItem);
			AlwaysSingleItemDayPlugin.Log.LogInfo((object)("SID ACTIVATED: " + spawnableItem.itemName));
			SpawnAllAsSingleItem(__instance, spawnableItem);
			return false;
		}
		catch (Exception ex)
		{
			AlwaysSingleItemDayPlugin.Log.LogError((object)ex);
			return true;
		}
	}

	private static void SendPredictionChat(Item item)
	{
		try
		{
			if (AlwaysSingleItemDayPlugin.EnablePredictionChat.Value && !chatSent && !((Object)(object)item == (Object)null))
			{
				string text = "[SID]Prediction : \"" + item.itemName + "\"";
				HUDManager.Instance.AddTextToChatOnServer(text, -1);
				chatSent = true;
				AlwaysSingleItemDayPlugin.Log.LogInfo((object)("Prediction sent: " + item.itemName));
			}
		}
		catch (Exception arg)
		{
			AlwaysSingleItemDayPlugin.Log.LogError((object)$"Prediction error: {arg}");
		}
	}

	private static void SpawnAllAsSingleItem(RoundManager rm, Item item)
	{
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: 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)
		int num = (int)((float)rm.AnomalyRandom.Next(rm.currentLevel.minScrap, rm.currentLevel.maxScrap) * rm.scrapAmountMultiplier);
		if (rm.currentDungeonType == 4)
		{
			num += 6;
		}
		if (StartOfRound.Instance.isChallengeFile)
		{
			int num2 = rm.AnomalyRandom.Next(10, 30);
			num += num2;
		}
		RandomScrapSpawn[] source = Object.FindObjectsOfType<RandomScrapSpawn>();
		List<NetworkObjectReference> list = new List<NetworkObjectReference>();
		List<int> list2 = new List<int>();
		List<RandomScrapSpawn> usedSpawns = new List<RandomScrapSpawn>();
		int num3 = 0;
		for (int i = 0; i < num; i++)
		{
			List<RandomScrapSpawn> list3 = ((item.spawnPositionTypes != null && item.spawnPositionTypes.Count != 0) ? source.Where((RandomScrapSpawn x) => item.spawnPositionTypes.Contains(x.spawnableItems) && !x.spawnUsed).ToList() : source.ToList());
			if (list3.Count <= 0)
			{
				continue;
			}
			if (usedSpawns.Count > 0)
			{
				list3.RemoveAll((RandomScrapSpawn x) => usedSpawns.Contains(x));
				if (list3.Count <= 0)
				{
					usedSpawns.Clear();
					i--;
					continue;
				}
			}
			RandomScrapSpawn val = list3[rm.AnomalyRandom.Next(0, list3.Count)];
			usedSpawns.Add(val);
			Vector3 val2;
			if (val.spawnedItemsCopyPosition)
			{
				val.spawnUsed = true;
				val2 = ((!Object.op_Implicit((Object)(object)val.spawnWithParent)) ? ((Component)val).transform.position : ((Component)val.spawnWithParent).transform.position);
			}
			else
			{
				val2 = rm.GetRandomNavMeshPositionInBoxPredictable(((Component)val).transform.position, val.itemSpawnRange, rm.navHit, rm.AnomalyRandom, -8193, 1f) + Vector3.up * item.verticalOffset;
			}
			GameObject val3 = Object.Instantiate<GameObject>(item.spawnPrefab, val2, Quaternion.identity, (Transform)null);
			GrabbableObject component = val3.GetComponent<GrabbableObject>();
			((Component)component).transform.rotation = Quaternion.Euler(component.itemProperties.restingRotation);
			component.fallTime = 0f;
			int num4 = (component.scrapValue = Mathf.Clamp((int)((float)rm.AnomalyRandom.Next(item.minValue, item.maxValue) * rm.scrapValueMultiplier), 50, 170));
			list2.Add(num4);
			num3 += num4;
			NetworkObject component2 = val3.GetComponent<NetworkObject>();
			component2.Spawn(false);
			list.Add(NetworkObjectReference.op_Implicit(component2));
		}
		float num5 = (item.twoHanded ? 1500f : 600f);
		if (num3 > 4500)
		{
			num3 = 0;
			for (int j = 0; j < list2.Count; j++)
			{
				list2[j] = (int)((float)list2[j] * 0.7f);
				num3 += list2[j];
			}
		}
		else if ((float)num3 < num5)
		{
			num3 = 0;
			for (int k = 0; k < list2.Count; k++)
			{
				list2[k] = (int)((float)list2[k] * 1.4f);
				num3 += list2[k];
			}
		}
		rm.totalScrapValueInLevel = num3;
		rm.scrapCollectedInLevel = 0;
		rm.valueOfFoundScrapItems = 0;
		rm.SyncScrapValuesClientRpc(list.ToArray(), list2.ToArray());
		AlwaysSingleItemDayPlugin.Log.LogInfo((object)$"Spawned {list.Count}x {item.itemName} | Total value: {num3}");
	}
}