Decompiled source of PrintToInventory v1.3.0

PrintToInventory.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using EntityStates;
using EntityStates.Duplicator;
using EntityStates.MealPrep;
using EntityStates.Scrapper;
using IL.EntityStates.MealPrep;
using IL.EntityStates.Scrapper;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.EntityStates.Duplicator;
using On.RoR2;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[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("PrintToInventory")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+01d2f2afe37ea8542ba94441fe97bd75a0840986")]
[assembly: AssemblyProduct("PrintToInventory")]
[assembly: AssemblyTitle("PrintToInventory")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace PrintToInventory
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.Moffein.PrintToInventory", "PrintToInventory", "1.3.0")]
	public class PrintToInventory : BaseUnityPlugin
	{
		public static bool affectScrappers = true;

		public static bool affectPrinters = true;

		public static bool affectCauldrons = true;

		public static bool affectCleanse = true;

		public static bool affectWanderingChef = true;

		public static bool multiplayerOnly = true;

		private static bool hooksAdded = false;

		public void Awake()
		{
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Expected O, but got Unknown
			if (Chainloader.PluginInfos.ContainsKey("com.funkfrog_sipondo.sharesuite"))
			{
				Debug.LogError((object)"PrintToInventory: ShareSuite detected! PrintToInventory will be disabled due to incompatibilities.");
				return;
			}
			multiplayerOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Multiplayer Only", true, "Only active this mod in multiplayer.").Value;
			affectCauldrons = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Cauldron", true, "Affect this interactable.").Value;
			affectPrinters = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Printer", true, "Affect this interactable.").Value;
			affectScrappers = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Scrapper", true, "Affect this interactable.").Value;
			affectCleanse = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Cleansing Pool", true, "Affect this interactable.").Value;
			affectWanderingChef = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Affect Wandering Chef", true, "Affect this interactable.").Value;
			Run.Start += new hook_Start(Run_Start);
			Run.OnDestroy += new hook_OnDestroy(Run_OnDestroy);
		}

		private void Run_OnDestroy(orig_OnDestroy orig, Run self)
		{
			orig.Invoke(self);
			RemoveHooks();
		}

		private void Run_Start(orig_Start orig, Run self)
		{
			orig.Invoke(self);
			if (!multiplayerOnly || !RoR2Application.isInSinglePlayer)
			{
				AddHooks();
			}
		}

		public void AddHooks()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			if (!hooksAdded)
			{
				hooksAdded = true;
				if (affectPrinters)
				{
					Duplicating.OnEnter += new hook_OnEnter(Duplicating_OnEnter);
				}
				if (affectCauldrons || affectCleanse)
				{
					PurchaseInteraction.OnInteractionBegin += new hook_OnInteractionBegin(ImmediatelyGiveItem);
					ShopTerminalBehavior.DropPickup += new hook_DropPickup(PreventDrop);
				}
				if (affectScrappers)
				{
					ScrappingToIdle.OnEnter += new Manipulator(ScrappingToIdle_DirectToInventory);
				}
				if (affectWanderingChef)
				{
					MealPrepController.BeginCookingServer += new hook_BeginCookingServer(MealPrepController_BeginCookingServer);
					CookingToIdle.DropItem += new Manipulator(DisableMealPrepDrop);
				}
			}
		}

		public void RemoveHooks()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			if (hooksAdded)
			{
				hooksAdded = false;
				if (affectPrinters)
				{
					Duplicating.OnEnter -= new hook_OnEnter(Duplicating_OnEnter);
				}
				if (affectCauldrons || affectCleanse)
				{
					PurchaseInteraction.OnInteractionBegin -= new hook_OnInteractionBegin(ImmediatelyGiveItem);
					ShopTerminalBehavior.DropPickup -= new hook_DropPickup(PreventDrop);
				}
				if (affectScrappers)
				{
					ScrappingToIdle.OnEnter -= new Manipulator(ScrappingToIdle_DirectToInventory);
				}
				if (affectWanderingChef)
				{
					MealPrepController.BeginCookingServer -= new hook_BeginCookingServer(MealPrepController_BeginCookingServer);
					CookingToIdle.DropItem -= new Manipulator(DisableMealPrepDrop);
				}
			}
		}

		private void MealPrepController_BeginCookingServer(orig_BeginCookingServer orig, MealPrepController self, Interactor activator, PickupIndex[] itemsToTake, PickupIndex reward, int count)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Invalid comparison between Unknown and I4
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self, activator, itemsToTake, reward, count);
			if (!NetworkServer.active || !Object.op_Implicit((Object)(object)activator))
			{
				return;
			}
			CharacterBody component = ((Component)activator).GetComponent<CharacterBody>();
			if (Object.op_Implicit((Object)(object)component.inventory))
			{
				PickupDef pickupDef = PickupCatalog.GetPickupDef(reward);
				if (pickupDef != null && (int)pickupDef.itemIndex != -1)
				{
					component.inventory.GiveItemPermanent(pickupDef.itemIndex, count);
				}
			}
		}

		private void DisableMealPrepDrop(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCall(x, typeof(NetworkServer), "get_active")
			}))
			{
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Func<bool, CookingToIdle, bool>>((Func<bool, CookingToIdle, bool>)delegate(bool active, CookingToIdle self)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					//IL_0017: Invalid comparison between Unknown and I4
					PickupDef pickupDef = PickupCatalog.GetPickupDef(((MealPrepBaseState)self).pickupToDrop);
					if (pickupDef != null && (int)pickupDef.itemIndex != -1)
					{
						if (NetworkServer.active)
						{
							self.itemsDropped++;
						}
						return false;
					}
					return active;
				});
			}
			else
			{
				Debug.LogError((object)"PrintToInventory: CookingToIdle_DropItem DisableMealPrepDrop IL hook failed.");
			}
		}

		private void ScrappingToIdle_DirectToInventory(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<ScrapperController>(x, "IsRewardPickupQueueEmpty")
			}))
			{
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Func<bool, ScrappingToIdle, bool>>((Func<bool, ScrappingToIdle, bool>)delegate(bool queueEmpty, ScrappingToIdle self)
				{
					//IL_0088: Unknown result type (might be due to invalid IL or missing references)
					//IL_008d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0090: Unknown result type (might be due to invalid IL or missing references)
					//IL_0092: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
					//IL_00aa: Invalid comparison between Unknown and I4
					//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
					//IL_0104: Unknown result type (might be due to invalid IL or missing references)
					//IL_0112: Unknown result type (might be due to invalid IL or missing references)
					if (!queueEmpty && Object.op_Implicit((Object)(object)((ScrapperBaseState)self).scrapperController) && Object.op_Implicit((Object)(object)((ScrapperBaseState)self).scrapperController.interactor) && ((ScrapperBaseState)self).scrapperController.pickupPrintQueue != null)
					{
						CharacterBody component = ((Component)((ScrapperBaseState)self).scrapperController.interactor).GetComponent<CharacterBody>();
						if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.inventory))
						{
							List<UniquePickup> list = new List<UniquePickup>();
							foreach (UniquePickup item in ((ScrapperBaseState)self).scrapperController.pickupPrintQueue)
							{
								PickupDef pickupDef = PickupCatalog.GetPickupDef(item.pickupIndex);
								if (pickupDef != null && (int)pickupDef.itemIndex != -1)
								{
									component.inventory.GiveItemPermanent(pickupDef.itemIndex, 1);
									list.Add(item);
								}
							}
							foreach (UniquePickup item2 in list)
							{
								((ScrapperBaseState)self).scrapperController.pickupPrintQueue.Remove(item2);
							}
							return ((ScrapperBaseState)self).scrapperController.IsRewardPickupQueueEmpty();
						}
					}
					return queueEmpty;
				});
			}
			else
			{
				Debug.LogError((object)"PrintToInventory: Scrapper IL hook failed.");
			}
		}

		private void Duplicating_OnEnter(orig_OnEnter orig, Duplicating self)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Invalid comparison between Unknown and I4
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (!NetworkServer.active)
			{
				return;
			}
			PurchaseInteraction component = ((EntityState)self).GetComponent<PurchaseInteraction>();
			ShopTerminalBehavior component2 = ((EntityState)self).GetComponent<ShopTerminalBehavior>();
			if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component2))
			{
				return;
			}
			CharacterBody component3 = ((Component)component.lastActivator).GetComponent<CharacterBody>();
			if (Object.op_Implicit((Object)(object)component3) && Object.op_Implicit((Object)(object)component3.inventory))
			{
				PickupDef pickupDef = PickupCatalog.GetPickupDef(component2.pickup.pickupIndex);
				if (pickupDef != null && (int)pickupDef.itemIndex != -1)
				{
					component3.inventory.GiveItem(pickupDef.itemIndex, 1);
					component2.SetHasBeenPurchased(true);
					self.hasDroppedDroplet = true;
					self.hasStartedCooking = true;
				}
			}
		}

		private void ImmediatelyGiveItem(orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator)
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Invalid comparison between Unknown and I4
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Invalid comparison between Unknown and I4
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Invalid comparison between Unknown and I4
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Invalid comparison between Unknown and I4
			orig.Invoke(self, activator);
			PurchaseInteraction component = ((Component)self).GetComponent<PurchaseInteraction>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return;
			}
			bool flag = affectCauldrons && component.displayNameToken == "BAZAAR_CAULDRON_NAME";
			bool flag2 = affectCleanse && component.displayNameToken == "SHRINE_CLEANSE_NAME";
			if (!(flag || flag2))
			{
				return;
			}
			CharacterBody component2 = ((Component)activator).GetComponent<CharacterBody>();
			ShopTerminalBehavior component3 = ((Component)self).GetComponent<ShopTerminalBehavior>();
			if (!Object.op_Implicit((Object)(object)component2) || !Object.op_Implicit((Object)(object)component2.inventory) || !Object.op_Implicit((Object)(object)component3))
			{
				return;
			}
			PickupDef pickupDef = PickupCatalog.GetPickupDef(component3.pickup.pickupIndex);
			if (pickupDef != null && (int)pickupDef.itemIndex != -1)
			{
				int num = 1;
				if (flag && component.cost == 1 && (int)component.costType == 6 && ((int)component3.itemTier == 0 || (int)component3.itemTier == 6 || (int)component3.itemTier == 3))
				{
					num = 3;
				}
				component2.inventory.GiveItem(pickupDef.itemIndex, num);
				component3.SetHasBeenPurchased(true);
				component.lastActivator = null;
			}
		}

		private void PreventDrop(orig_DropPickup orig, ShopTerminalBehavior self)
		{
			if (NetworkServer.active)
			{
				PurchaseInteraction component = ((Component)self).GetComponent<PurchaseInteraction>();
				if (Object.op_Implicit((Object)(object)component))
				{
					bool flag = affectCauldrons && component.displayNameToken == "BAZAAR_CAULDRON_NAME";
					bool flag2 = affectCleanse && component.displayNameToken == "SHRINE_CLEANSE_NAME";
					if ((flag || flag2) && (Object)(object)component.lastActivator == (Object)null)
					{
						return;
					}
				}
			}
			orig.Invoke(self);
		}
	}
}
namespace R2API.Utils
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class ManualNetworkRegistrationAttribute : Attribute
	{
	}
}