Decompiled source of RestoreMapper v1.0.0

RestoreMapper.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RestoreMapper")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Restore the unused mapper item in the shop")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RestoreMapper")]
[assembly: AssemblyTitle("RestoreMapper")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TemplatePluginName
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "RestoreMapper";

		public const string PLUGIN_NAME = "RestoreMapper";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace RestoreMapper
{
	[BepInPlugin("butterystancakes.lethalcompany.restoremapper", "Restore Mapper", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "butterystancakes.lethalcompany.restoremapper";

		private const string PLUGIN_NAME = "Restore Mapper";

		private const string PLUGIN_VERSION = "1.0.0";

		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			new Harmony("butterystancakes.lethalcompany.restoremapper").PatchAll();
			Logger.LogInfo((object)"Restore Mapper v1.0.0 loaded");
		}
	}
	[HarmonyPatch]
	internal class RestoreMapperPatches
	{
		[HarmonyPatch(typeof(Terminal), "Awake")]
		[HarmonyPostfix]
		private static void TerminalPostAwake(Terminal __instance)
		{
			TerminalKeyword? obj = ((IEnumerable<TerminalKeyword>)__instance.terminalNodes?.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword keyword) => ((Object)keyword).name == "Buy"));
			TerminalNode val = ((IEnumerable<CompatibleNoun>)obj?.compatibleNouns).FirstOrDefault((Func<CompatibleNoun, bool>)delegate(CompatibleNoun compatibleNoun)
			{
				TerminalKeyword noun2 = compatibleNoun.noun;
				return ((noun2 != null) ? ((Object)noun2).name : null) == "Mapper";
			}).result;
			CompatibleNoun val2 = ((IEnumerable<CompatibleNoun>)val?.terminalOptions).FirstOrDefault((Func<CompatibleNoun, bool>)delegate(CompatibleNoun compatibleNoun)
			{
				TerminalKeyword noun = compatibleNoun.noun;
				return ((noun != null) ? ((Object)noun).name : null) == "Confirm";
			});
			List<Item> list = StartOfRound.Instance?.allItemsList?.itemsList;
			Item val3 = list?.FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name == "MapDevice"));
			if ((Object)(object)obj == (Object)null || (Object)(object)val == (Object)null || val2 == null || list == null || (Object)(object)val3 == (Object)null)
			{
				Plugin.Logger.LogError((object)"Encountered an error while caching essential references. Loading will be skipped.");
				return;
			}
			__instance.buyableItemsList = CollectionExtensions.AddItem<Item>((IEnumerable<Item>)__instance.buyableItemsList, val3).ToArray();
			val.buyItemIndex = __instance.buyableItemsList.Length - 1;
			val2.result.buyItemIndex = val.buyItemIndex;
			Plugin.Logger.LogDebug((object)"Assigned IDs");
			val3.creditsWorth = 150;
			Plugin.Logger.LogDebug((object)"Assigned price");
			Item val4 = ((IEnumerable<Item>)list).FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name == "ProFlashlight"));
			if ((Object)(object)val4 != (Object)null)
			{
				val3.grabSFX = val4.grabSFX;
				val3.dropSFX = val4.dropSFX;
				val3.pocketSFX = val4.pocketSFX;
				Plugin.Logger.LogDebug((object)"Assigned SFX");
			}
			else
			{
				Plugin.Logger.LogWarning((object)"Couldn't find pro-flashlight item. Sound effects will be missing.");
			}
			try
			{
				AssetBundle val5 = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "restoremapper"));
				val3.itemIcon = val5.LoadAsset<Sprite>("MapperIcon");
				val5.Unload(false);
				Plugin.Logger.LogDebug((object)"Assigned special icon");
			}
			catch
			{
				Plugin.Logger.LogWarning((object)"Encountered some error loading asset bundle. Inventory icon will be incorrect.");
				Item val6 = list?.FirstOrDefault((Func<Item, bool>)delegate(Item item)
				{
					Sprite itemIcon = item.itemIcon;
					return ((itemIcon != null) ? ((Object)itemIcon).name : null) == "caticontest";
				});
				if ((Object)(object)val6 != (Object)null)
				{
					val3.itemIcon = val6.itemIcon;
				}
			}
		}
	}
}