Decompiled source of Risk of Multiprinting v1.0.0

risk_of_multiprinting.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Duplicator;
using EntityStates.Scrapper;
using Grumpy;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using R2API.Networking;
using R2API.Networking.Interfaces;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;
using risk_of_multiprinting.patches.duplicating;
using risk_of_multiprinting.patches.scraplimit;

[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("risk_of_multiprinting")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Risk of Multiprinting")]
[assembly: AssemblyTitle("risk_of_multiprinting")]
[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 risk_of_multiprinting
{
	[BepInPlugin("risk_of_multiprinting", "Risk of Multiprinting", "1.0.0")]
	[BepInProcess("Risk of Rain 2.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private Harmony harmonyPatcher;

		public static PluginInfo PInfo { get; private set; }

		private void Awake()
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			PInfo = ((BaseUnityPlugin)this).Info;
			amountSelectorAsset.Init();
			Logger.LogInfo((object)"Plugin risk_of_multiprinting is loaded!");
			Stage.onStageStartGlobal += delegate
			{
				Logger.LogInfo((object)"Patching scrapper duration values");
				WaitToBeginScrapping.duration = 0.1f;
				Scrapping.duration = 0.05f;
				ScrappingToIdle.duration = 0.1f;
			};
			Logger.LogInfo((object)"Patching DLLs:");
			harmonyPatcher = new Harmony("risk_of_multiprinting");
			Logger.LogInfo((object)"Patching Duplicating");
			NetworkingAPI.RegisterMessageType<SendCustomAmountRPC>();
			harmonyPatcher.CreateClassProcessor(typeof(DuplicatingPatch)).Patch();
			Logger.LogInfo((object)"Patching Scrap Limit");
			harmonyPatcher.CreateClassProcessor(typeof(ScrapLimitPatch)).Patch();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "risk_of_multiprinting";

		public const string PLUGIN_NAME = "Risk of Multiprinting";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace risk_of_multiprinting.patches.scraplimit
{
	[HarmonyPatch]
	public class ScrapLimitPatch
	{
		[HarmonyPatch(typeof(ScrapperController), "Start")]
		[HarmonyPostfix]
		private static void AlterScrapLimit(ScrapperController __instance)
		{
			__instance.maxItemsToScrapAtATime = 50;
		}
	}
}
namespace risk_of_multiprinting.patches.duplicating
{
	public static class amountSelectorAsset
	{
		public static AssetBundle mainBundle;

		public const string bundleName = "multiprintingamountselectorpanel";

		public const string assetBundleFolder = "assets";

		public static string AssetBundlePath => Path.Combine(Path.GetDirectoryName(Plugin.PInfo.Location), "multiprintingamountselectorpanel");

		public static void Init()
		{
			mainBundle = AssetBundle.LoadFromFile(AssetBundlePath);
		}
	}
	[HarmonyPatch]
	public class DuplicatingPatch
	{
		[HarmonyPatch(typeof(Duplicating), "DropDroplet")]
		[HarmonyPrefix]
		private static bool PatchedDropDroplet(Duplicating __instance)
		{
			if (__instance.hasDroppedDroplet)
			{
				return false;
			}
			__instance.hasDroppedDroplet = true;
			PurchaseInteraction component = ((EntityState)__instance).GetComponent<PurchaseInteraction>();
			for (int i = 0; i < component.cost; i++)
			{
				((EntityState)__instance).GetComponent<ShopTerminalBehavior>().DropPickup();
			}
			component.cost = 1;
			if (!Object.op_Implicit((Object)(object)__instance.muzzleTransform))
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)__instance.bakeEffectInstance))
			{
				if ((Object)(object)__instance._emh_bakeEffectInstance != (Object)null && __instance._emh_bakeEffectInstance.OwningPool != null)
				{
					((GenericPool<EffectManagerHelper>)(object)__instance._emh_bakeEffectInstance.OwningPool).ReturnObject(__instance._emh_bakeEffectInstance);
				}
				else
				{
					EntityState.Destroy((Object)(object)__instance.bakeEffectInstance);
				}
				__instance._emh_bakeEffectInstance = null;
				__instance.bakeEffectInstance = null;
			}
			if (!Object.op_Implicit((Object)(object)Duplicating.releaseEffectPrefab))
			{
				return false;
			}
			EffectManager.SimpleMuzzleFlash(Duplicating.releaseEffectPrefab, ((EntityState)__instance).gameObject, Duplicating.muzzleString, false);
			return false;
		}

		[HarmonyPatch(typeof(Interactor), "AttemptInteraction")]
		[HarmonyPrefix]
		private static bool ChooseCustomAmount(GameObject interactableObject, Interactor __instance)
		{
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Expected O, but got Unknown
			if (!((Object)interactableObject).name.Contains("Duplicator"))
			{
				return true;
			}
			PurchaseInteraction component = interactableObject.GetComponent<PurchaseInteraction>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return true;
			}
			Debug.Log((object)"Risk of Multiprinting: Opening duplicator prompt");
			LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
			HUD val = HUD.instancesList.Find((HUD instance) => instance.localUserViewer == firstLocalUser);
			if (!Object.op_Implicit((Object)(object)val))
			{
				Debug.Log((object)"Risk of Mutliprinting: No HUD found!");
				return false;
			}
			MPEventSystem eventSystem = MPEventSystem.instancesList.Find((MPEventSystem instance) => instance.localUser == firstLocalUser);
			if (!Object.op_Implicit((Object)(object)eventSystem))
			{
				return false;
			}
			int chosenValue = 0;
			GameObject val2 = amountSelectorAsset.mainBundle.LoadAsset<GameObject>("multiprintingAmountSelectorPanel");
			GameObject panel = Object.Instantiate<GameObject>(val2, val.mainContainer.transform);
			MPEventSystem obj = eventSystem;
			obj.cursorOpenerCount += 1;
			Transform val3 = panel.transform.Find("Text");
			TextMeshProUGUI textComponent = ((Component)val3).gameObject.GetComponent<TextMeshProUGUI>();
			Slider componentInChildren = panel.GetComponentInChildren<Slider>();
			((UnityEvent<float>)(object)componentInChildren.onValueChanged).AddListener((UnityAction<float>)delegate(float value)
			{
				chosenValue = (int)value;
				((TMP_Text)textComponent).text = chosenValue.ToString();
			});
			Transform val4 = panel.transform.Find("Button");
			Button component2 = ((Component)val4).gameObject.GetComponent<Button>();
			((UnityEvent)component2.onClick).AddListener((UnityAction)delegate
			{
				MPEventSystem obj2 = eventSystem;
				obj2.cursorOpenerCount -= 1;
				Object.Destroy((Object)(object)panel);
				if (chosenValue != 0)
				{
					if (NetworkServer.active)
					{
						Debug.Log((object)"Risk of Multiprinting: Directly calling function with modified values");
						InteractorAdditions interactorAdditions = new InteractorAdditions();
						interactorAdditions.PerformModifiedDuplicationInteraction(__instance, interactableObject, chosenValue);
					}
					else
					{
						Debug.Log((object)"Risk of Multiprinting: Sending RPC message to host with modified values");
						NetMessageExtensions.Send((INetMessage)(object)new SendCustomAmountRPC(((Component)__instance).gameObject, interactableObject, chosenValue), (NetworkDestination)2);
					}
				}
			});
			return false;
		}
	}
	public class SendCustomAmountRPC : INetMessage, ISerializableObject
	{
		private GameObject interactorParentObject;

		private GameObject duplicator;

		private int customAmount;

		public SendCustomAmountRPC()
		{
		}

		public SendCustomAmountRPC(GameObject interactorParentObject, GameObject duplicator, int customAmount)
		{
			this.interactorParentObject = interactorParentObject;
			this.duplicator = duplicator;
			this.customAmount = customAmount;
		}

		public void Deserialize(NetworkReader reader)
		{
			interactorParentObject = reader.ReadGameObject();
			duplicator = reader.ReadGameObject();
			customAmount = reader.ReadInt32();
		}

		public void OnReceived()
		{
			if (NetworkServer.active)
			{
				Interactor component = interactorParentObject.GetComponent<Interactor>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					Debug.Log((object)"Risk of Multiprinting: Restoring interactor from parent object failed!");
					return;
				}
				if (!Object.op_Implicit((Object)(object)duplicator))
				{
					Debug.Log((object)"Risk of Multiprinting: transmitting duplicator object failed!");
					return;
				}
				Debug.Log((object)"Risk of Multiprinting: Received RPC message for modified duplication interaction");
				InteractorAdditions interactorAdditions = new InteractorAdditions();
				interactorAdditions.PerformModifiedDuplicationInteraction(component, duplicator, customAmount);
			}
		}

		public void Serialize(NetworkWriter writer)
		{
			writer.Write(interactorParentObject);
			writer.Write(duplicator);
			writer.Write(customAmount);
		}
	}
	public class InteractorAdditions
	{
		[Server]
		public void PerformModifiedDuplicationInteraction(Interactor interactor, GameObject duplicator, int customAmount)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Void RoR2.InteractorAdditions::PerformModifiedDuplicationInteraction(UnityEngine.GameObject)' called on client");
				return;
			}
			PurchaseInteraction component = duplicator.GetComponent<PurchaseInteraction>();
			Interactability interactability = component.GetInteractability(interactor);
			if ((int)interactability == 2)
			{
				component.cost = customAmount;
				if (!component.CanBeAffordedByInteractor(interactor))
				{
					component.cost = 1;
					return;
				}
				component.OnInteractionBegin(interactor);
				GlobalEventManager.instance.OnInteractionBegin(interactor, (IInteractable)(object)component, duplicator);
			}
		}
	}
}