Decompiled source of SingleItemDayOnly v1.0.0

baer1.SingleItemWeek.dll

Decompiled 19 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalModUtils;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("baer1.SingleItemWeek")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+773c31656698b1b5adcaf16e2d889ea7391f3a96")]
[assembly: AssemblyProduct("LethalSingleItemDayOnly")]
[assembly: AssemblyTitle("baer1.SingleItemWeek")]
[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 LethalSingleItemDayOnly
{
	[BepInPlugin("baer1.SingleItemWeek", "LethalSingleItemDayOnly", "1.0.0")]
	public class LethalSingleItemDayOnly : BaseUnityPlugin
	{
		private ConfigEntry<bool> enableMod = null;

		private ConfigEntry<string> forceItem = null;

		public static LethalSingleItemDayOnly Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		public bool EnableMod => enableMod.Value;

		public string ForceItem => forceItem.Value;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			enableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableMod", true, "Enables or disables the mod");
			forceItem = ((BaseUnityPlugin)this).Config.Bind<string>("Overrides", "ForceItem", string.Empty, "Overrides the spawned item");
			Patch();
			Logger.LogInfo((object)"baer1.SingleItemWeek v1.0.0 has loaded!");
			static void Patch()
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Expected O, but got Unknown
				if (Harmony == null)
				{
					Harmony = new Harmony("baer1.SingleItemWeek");
				}
				Logger.LogDebug((object)"Patching...");
				Harmony.PatchAll();
				Logger.LogDebug((object)"Finished patching!");
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
	internal static class RoundManager_SpawnScrapInLevel
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			Label label = default(Label);
			Label label2 = default(Label);
			return CodeMatcherExtensions.MatchForward(CodeMatcherExtensions.MatchForward(CodeMatcherExtensions.MatchForward(new CodeMatcher(instructions, generator), (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_M1, (object)null, (string)null)
			}), (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_M1, (object)null, (string)null)
			}).Advance(2).CreateLabel(ref label)
				.Start(), (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_M1, (object)null, (string)null)
			}).Advance(1).CreateLabel(ref label2)
				.Insert((CodeInstruction[])(object)new CodeInstruction[7]
				{
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(RoundManager_SpawnScrapInLevel), "UseCustomGeneration", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Brfalse, (object)label2),
					new CodeInstruction(OpCodes.Pop, (object)null),
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(RoundManager_SpawnScrapInLevel), "SelectSIDScrapItem", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Stloc_2, (object)null),
					new CodeInstruction(OpCodes.Br, (object)label)
				})
				.InstructionEnumeration();
		}

		private static bool UseCustomGeneration()
		{
			return LethalSingleItemDayOnly.Instance.EnableMod;
		}

		private static int SelectSIDScrapItem(RoundManager __instance)
		{
			LethalSingleItemDayOnly.Logger.LogInfo((object)("Spawnable items on " + __instance.currentLevel.PlanetName + ":\n" + string.Join('\n', __instance.currentLevel.spawnableScrap.Select((SpawnableItemWithRarity i) => ">> " + (CanItemBeSID(i) ? "✔" : "-") + " " + i.spawnableItem.itemName))));
			string forceItem = LethalSingleItemDayOnly.Instance.ForceItem.Trim();
			if (!string.IsNullOrWhiteSpace(forceItem))
			{
				List<KeyValuePair<int, SpawnableItemWithRarity>> list = (from kvp in __instance.currentLevel.spawnableScrap.Select((SpawnableItemWithRarity v, int k) => new KeyValuePair<int, SpawnableItemWithRarity>(k, v))
					where kvp.Value.spawnableItem.itemName.Trim().Equals(forceItem, StringComparison.InvariantCultureIgnoreCase)
					select kvp).ToList();
				if (list.Count <= 0)
				{
					Warn("Item \"" + forceItem + "\" can not be spawned.\nPlease verify your spelling with the log output and make sure the item can appear on the current moon.");
					return -1;
				}
				KeyValuePair<int, SpawnableItemWithRarity> keyValuePair = list[__instance.AnomalyRandom.Next(0, list.Count)];
				bool flag = CanItemBeSID(keyValuePair.Value);
				HUDManager.Instance.AddTextMessageServerRpc("<color=#" + (flag ? "00" : "ff") + "ff00>[SID-ONLY v1.0.0] Successfully forced " + keyValuePair.Value.spawnableItem.itemName + " single-item day" + (flag ? string.Empty : ". This item is not valid for SID and this day will not appear in vanilla") + "</color>");
				return keyValuePair.Key;
			}
			List<KeyValuePair<int, SpawnableItemWithRarity>> list2 = (from kvp in __instance.currentLevel.spawnableScrap.Select((SpawnableItemWithRarity v, int k) => new KeyValuePair<int, SpawnableItemWithRarity>(k, v))
				where CanItemBeSID(kvp.Value)
				select kvp).ToList();
			if (list2.Count <= 0)
			{
				Warn("No valid item found for single-item day");
				return -1;
			}
			KeyValuePair<int, SpawnableItemWithRarity> keyValuePair2 = list2[__instance.AnomalyRandom.Next(0, list2.Count)];
			HUDManager.Instance.AddTextMessageServerRpc("<color=#00ff00>[SID-ONLY v1.0.0] Successfully forced " + keyValuePair2.Value.spawnableItem.itemName + " single-item day</color>");
			return keyValuePair2.Key;
			static bool CanItemBeSID(SpawnableItemWithRarity i)
			{
				return i.rarity >= 5 && !i.spawnableItem.twoHanded;
			}
			static void Warn(string message)
			{
				LethalSingleItemDayOnly.Logger.LogWarning((object)message);
				HUDManager.Instance.AddTextMessageServerRpc("<color=#ffff00>[SID-ONLY] " + message + "</color>");
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "baer1.SingleItemWeek";

		public const string PLUGIN_NAME = "LethalSingleItemDayOnly";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}