Decompiled source of RedScrapCauldron v1.0.7

RedScrapCauldron.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.UI;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[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("RedScrapCauldron")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2ead27c243be79808092ce19782013fa95aa5f66")]
[assembly: AssemblyProduct("RedScrapCauldron")]
[assembly: AssemblyTitle("RedScrapCauldron")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace RedScrapCauldron
{
	internal static class Log
	{
		internal static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void LogDebug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void LogError(object data)
		{
			_logSource.LogError(data);
		}

		internal static void LogFatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void LogInfo(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void LogMessage(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void LogWarning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInPlugin("com.Pseudo.RedScrapInCauldron", "Red Scrap for Cauldrons", "1.0.7")]
	public class Main : BaseUnityPlugin
	{
		public const string PluginGUID = "com.Pseudo.RedScrapInCauldron";

		public const string PluginName = "Red Scrap for Cauldrons";

		public const string PluginVersion = "1.0.7";

		private static string RedColor = "E7543A";

		private static string GreenColor = "77FF17";

		private static string WhiteColor = "FFFFFF";

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			Hooks();
		}

		public void Hooks()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			CostTypeDef.IsAffordable += new hook_IsAffordable(CostTypeDef_IsAffordable);
			PurchaseInteraction.OnInteractionBegin += new hook_OnInteractionBegin(PurchaseInteraction_OnInteractionBegin);
			PurchaseInteraction.GetContextString += new hook_GetContextString(PurchaseInteraction_GetContextString);
			CostHologramContent.FixedUpdate += new hook_FixedUpdate(CostHologramContent_FixedUpdate);
			PingIndicator.RebuildPing += new hook_RebuildPing(PingIndicator_RebuildPing);
		}

		private bool CostTypeDef_IsAffordable(orig_IsAffordable orig, CostTypeDef thisReference, int cost, Interactor activator)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			if ((int)thisReference.itemTier == 0 && cost == 3 && (CheckIfInteractorHasItem(activator, Items.ScrapGreen) || CheckIfInteractorHasItem(activator, Items.RegeneratingScrap)))
			{
				return true;
			}
			if ((int)thisReference.itemTier == 1 && cost == 5 && CheckIfInteractorHasItem(activator, Items.ScrapRed))
			{
				return true;
			}
			return orig.Invoke(thisReference, cost, activator);
		}

		private void SetPriceTo(PurchaseInteraction purchaseInteraction, CostTypeIndex type, int cost)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			purchaseInteraction.costType = type;
			purchaseInteraction.cost = cost;
		}

		private bool CheckIfInteractorHasItem(Interactor interactor, ItemDef itemDef)
		{
			return CheckIfCharacterMasterHasItem(((Component)interactor).GetComponent<CharacterBody>(), itemDef);
		}

		private bool CheckIfCharacterMasterHasItem(CharacterBody characterBody, ItemDef itemDef)
		{
			return characterBody.inventory.GetItemCount(itemDef) > 0;
		}

		private void PurchaseInteraction_OnInteractionBegin(orig_OnInteractionBegin methodReference, PurchaseInteraction thisReference, Interactor interactor)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Invalid comparison between Unknown and I4
			if ((int)thisReference.costType == 4 && thisReference.cost == 3 && (CheckIfInteractorHasItem(interactor, Items.ScrapGreen) || CheckIfInteractorHasItem(interactor, Items.RegeneratingScrap)))
			{
				SetPriceTo(thisReference, (CostTypeIndex)5, 1);
				methodReference.Invoke(thisReference, interactor);
				SetPriceTo(thisReference, (CostTypeIndex)4, 3);
			}
			else if ((int)thisReference.costType == 5 && thisReference.cost == 5 && CheckIfInteractorHasItem(interactor, Items.ScrapRed))
			{
				SetPriceTo(thisReference, (CostTypeIndex)6, 1);
				methodReference.Invoke(thisReference, interactor);
				SetPriceTo(thisReference, (CostTypeIndex)5, 5);
			}
			else
			{
				methodReference.Invoke(thisReference, interactor);
			}
		}

		private string PurchaseInteraction_GetContextString(orig_GetContextString methodReference, PurchaseInteraction thisReference, Interactor interactor)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Invalid comparison between Unknown and I4
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			if ((thisReference.cost == 3 && (int)thisReference.costType == 4) || (thisReference.cost == 5 && (int)thisReference.costType == 5))
			{
				PurchaseInteraction.sharedStringBuilder.Clear();
				PurchaseInteraction.sharedStringBuilder.Append(Language.GetString(thisReference.contextToken));
				if ((int)thisReference.costType > 0)
				{
					string text = ((thisReference.cost == 5) ? RedColor : GreenColor);
					PurchaseInteraction.sharedStringBuilder.Append(" <nobr>(<color=#" + text + ">1 Scrap(s)</color>)</nobr> / ");
					PurchaseInteraction.sharedStringBuilder.Append(" <nobr>(");
					CostTypeCatalog.GetCostTypeDef(thisReference.costType).BuildCostStringStyled(thisReference.cost, PurchaseInteraction.sharedStringBuilder, false, true);
					PurchaseInteraction.sharedStringBuilder.Append(")</nobr>");
				}
				return PurchaseInteraction.sharedStringBuilder.ToString();
			}
			return methodReference.Invoke(thisReference, interactor);
		}

		private void CostHologramContent_FixedUpdate(orig_FixedUpdate methodReference, CostHologramContent thisReference)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Invalid comparison between Unknown and I4
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Invalid comparison between Unknown and I4
			if ((thisReference.displayValue == 3 && (int)thisReference.costType == 4) || (thisReference.displayValue == 5 && (int)thisReference.costType == 5))
			{
				CostHologramContent.sharedStringBuilder.Clear();
				((Graphic)thisReference.targetTextMesh).color = Color.white;
				string arg = (((int)thisReference.costType == 5) ? RedColor : GreenColor);
				string arg2 = (((int)thisReference.costType == 5) ? GreenColor : WhiteColor);
				((TMP_Text)thisReference.targetTextMesh).SetText($"<nobr><color=#{arg}>1 Scrap(s)</color></nobr><br>OR<br><nobr><color=#{arg2}>{thisReference.displayValue} Item(s)</color></nobr>", true);
			}
			else
			{
				methodReference.Invoke(thisReference);
			}
		}

		private void PingIndicator_RebuildPing(orig_RebuildPing methodReference, PingIndicator thisReference)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Expected O, but got Unknown
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Expected I4, but got Unknown
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0658: Unknown result type (might be due to invalid IL or missing references)
			//IL_065e: Invalid comparison between Unknown and I4
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_067e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0684: Invalid comparison between Unknown and I4
			//IL_069a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a0: Invalid comparison between Unknown and I4
			//IL_0702: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c9: Invalid comparison between Unknown and I4
			((Behaviour)thisReference.pingHighlight).enabled = false;
			((Component)this).transform.rotation = Util.QuaternionSafeLookRotation(thisReference.pingNormal);
			((Component)this).transform.position = (Object.op_Implicit((Object)(object)thisReference.pingTarget) ? thisReference.pingTarget.transform.position : thisReference.pingOrigin);
			((Component)this).transform.localScale = Vector3.one;
			thisReference.positionIndicator.targetTransform = (Object.op_Implicit((Object)(object)thisReference.pingTarget) ? thisReference.pingTarget.transform : null);
			thisReference.positionIndicator.defaultPosition = ((Component)this).transform.position;
			IDisplayNameProvider val = (Object.op_Implicit((Object)(object)thisReference.pingTarget) ? thisReference.pingTarget.GetComponentInParent<IDisplayNameProvider>() : null);
			ModelLocator val2 = null;
			thisReference.pingType = (PingType)0;
			((Behaviour)thisReference.pingObjectScaleCurve).enabled = false;
			((Behaviour)thisReference.pingObjectScaleCurve).enabled = true;
			GameObject[] defaultPingGameObjects = thisReference.defaultPingGameObjects;
			for (int i = 0; i < defaultPingGameObjects.Length; i++)
			{
				defaultPingGameObjects[i].SetActive(false);
			}
			defaultPingGameObjects = thisReference.enemyPingGameObjects;
			for (int j = 0; j < defaultPingGameObjects.Length; j++)
			{
				defaultPingGameObjects[j].SetActive(false);
			}
			defaultPingGameObjects = thisReference.interactablePingGameObjects;
			for (int k = 0; k < defaultPingGameObjects.Length; k++)
			{
				defaultPingGameObjects[k].SetActive(false);
			}
			if (Object.op_Implicit((Object)(object)thisReference.pingTarget))
			{
				Debug.LogFormat("Ping target {0}", new object[1] { thisReference.pingTarget });
				val2 = thisReference.pingTarget.GetComponent<ModelLocator>();
				if (val != null)
				{
					CharacterBody component = thisReference.pingTarget.GetComponent<CharacterBody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						thisReference.pingType = (PingType)1;
						thisReference.targetTransformToFollow = component.coreTransform;
					}
					else
					{
						thisReference.pingType = (PingType)2;
					}
				}
			}
			string ownerName = thisReference.GetOwnerName();
			string text = (Object.op_Implicit((Object)(MonoBehaviour)val) ? Util.GetBestBodyName(((Component)(MonoBehaviour)val).gameObject) : "");
			((Behaviour)thisReference.pingText).enabled = true;
			((TMP_Text)thisReference.pingText).text = ownerName;
			PingType pingType = thisReference.pingType;
			PingType val3 = pingType;
			switch ((int)val3)
			{
			case 0:
			{
				thisReference.pingColor = thisReference.defaultPingColor;
				thisReference.pingDuration = thisReference.defaultPingDuration;
				thisReference.pingHighlight.isOn = false;
				defaultPingGameObjects = thisReference.defaultPingGameObjects;
				for (int num2 = 0; num2 < defaultPingGameObjects.Length; num2++)
				{
					defaultPingGameObjects[num2].SetActive(true);
				}
				Chat.AddMessage(string.Format(Language.GetString("PLAYER_PING_DEFAULT"), ownerName));
				break;
			}
			case 1:
			{
				thisReference.pingColor = thisReference.enemyPingColor;
				thisReference.pingDuration = thisReference.enemyPingDuration;
				defaultPingGameObjects = thisReference.enemyPingGameObjects;
				for (int m = 0; m < defaultPingGameObjects.Length; m++)
				{
					defaultPingGameObjects[m].SetActive(true);
				}
				if (!Object.op_Implicit((Object)(object)val2))
				{
					break;
				}
				Transform modelTransform = val2.modelTransform;
				if (Object.op_Implicit((Object)(object)modelTransform))
				{
					CharacterModel component5 = ((Component)modelTransform).GetComponent<CharacterModel>();
					if (Object.op_Implicit((Object)(object)component5))
					{
						bool flag2 = false;
						RendererInfo[] baseRendererInfos = component5.baseRendererInfos;
						foreach (RendererInfo val6 in baseRendererInfos)
						{
							if (!val6.ignoreOverlays && !flag2)
							{
								thisReference.pingHighlight.highlightColor = (HighlightColor)1;
								thisReference.pingHighlight.targetRenderer = val6.renderer;
								thisReference.pingHighlight.strength = 1f;
								thisReference.pingHighlight.isOn = true;
								((Behaviour)thisReference.pingHighlight).enabled = true;
								break;
							}
						}
					}
				}
				Chat.AddMessage(string.Format(Language.GetString("PLAYER_PING_ENEMY"), ownerName, text));
				break;
			}
			case 2:
			{
				thisReference.pingColor = thisReference.interactablePingColor;
				thisReference.pingDuration = thisReference.interactablePingDuration;
				thisReference.pingTargetPurchaseInteraction = thisReference.pingTarget.GetComponent<PurchaseInteraction>();
				thisReference.halcyonShrine = thisReference.pingTarget.GetComponent<HalcyoniteShrineInteractable>();
				Sprite interactableIcon = PingIndicator.GetInteractableIcon(thisReference.pingTarget);
				SpriteRenderer component2 = thisReference.interactablePingGameObjects[0].GetComponent<SpriteRenderer>();
				ShopTerminalBehavior component3 = thisReference.pingTarget.GetComponent<ShopTerminalBehavior>();
				TeleporterInteraction component4 = thisReference.pingTarget.GetComponent<TeleporterInteraction>();
				if (Object.op_Implicit((Object)(object)component3))
				{
					PickupIndex val4 = component3.CurrentPickupIndex();
					IFormatProvider invariantCulture = CultureInfo.InvariantCulture;
					string format = "{0} ({1})";
					object arg = text;
					object arg2 = ((component3.pickupIndexIsHidden || !Object.op_Implicit((Object)(object)component3.pickupDisplay)) ? "?" : Language.GetString(PickupCatalog.GetPickupDef(val4)?.nameToken ?? PickupCatalog.invalidPickupToken));
					text = string.Format(invariantCulture, format, arg, arg2);
				}
				else if (Object.op_Implicit((Object)(object)component4))
				{
					thisReference.pingDuration = 30f;
					((Behaviour)thisReference.pingText).enabled = false;
					component4.PingTeleporter(ownerName, thisReference);
				}
				else if (!((Object)thisReference.pingTarget.gameObject).name.Contains("Shrine") && (Object.op_Implicit((Object)(object)thisReference.pingTarget.GetComponent<GenericPickupController>()) || Object.op_Implicit((Object)(object)thisReference.pingTarget.GetComponent<PickupPickerController>())))
				{
					thisReference.pingDuration = 60f;
				}
				defaultPingGameObjects = thisReference.interactablePingGameObjects;
				for (int l = 0; l < defaultPingGameObjects.Length; l++)
				{
					defaultPingGameObjects[l].SetActive(true);
				}
				Renderer val5 = ((!Object.op_Implicit((Object)(object)val2)) ? thisReference.pingTarget.GetComponentInChildren<Renderer>() : ((Component)val2.modelTransform).GetComponentInChildren<Renderer>());
				if (Object.op_Implicit((Object)(object)val5))
				{
					thisReference.pingHighlight.highlightColor = (HighlightColor)0;
					thisReference.pingHighlight.targetRenderer = val5;
					thisReference.pingHighlight.strength = 1f;
					thisReference.pingHighlight.isOn = true;
					((Behaviour)thisReference.pingHighlight).enabled = true;
				}
				component2.sprite = interactableIcon;
				((Renderer)component2).enabled = !Object.op_Implicit((Object)(object)component4);
				if (Object.op_Implicit((Object)(object)thisReference.pingTargetPurchaseInteraction) && (int)thisReference.pingTargetPurchaseInteraction.costType > 0)
				{
					PingIndicator.sharedStringBuilder.Clear();
					if (((int)thisReference.pingTargetPurchaseInteraction.costType == 4 && thisReference.pingTargetPurchaseInteraction.cost == 3) || ((int)thisReference.pingTargetPurchaseInteraction.costType == 5 && thisReference.pingTargetPurchaseInteraction.cost == 5))
					{
						bool flag = (int)thisReference.pingTargetPurchaseInteraction.costType == 5;
						PingIndicator.sharedStringBuilder.Append("<nobr><color=#" + (flag ? RedColor : GreenColor) + ">1 Scrap(s)</color></nobr> / ");
					}
					CostTypeDef costTypeDef = CostTypeCatalog.GetCostTypeDef(thisReference.pingTargetPurchaseInteraction.costType);
					int num = thisReference.pingTargetPurchaseInteraction.cost;
					if (((object)(CostTypeIndex)(ref thisReference.pingTargetPurchaseInteraction.costType)).Equals((object)(CostTypeIndex)1) && TeamManager.LongstandingSolitudesInParty() > 0)
					{
						num = (int)((float)num * TeamManager.GetLongstandingSolitudeItemCostScale());
					}
					costTypeDef.BuildCostStringStyled(num, PingIndicator.sharedStringBuilder, false, true);
					Chat.AddMessage(string.Format(Language.GetString("PLAYER_PING_INTERACTABLE_WITH_COST"), ownerName, text, PingIndicator.sharedStringBuilder.ToString()));
				}
				else
				{
					Chat.AddMessage(string.Format(Language.GetString("PLAYER_PING_INTERACTABLE"), ownerName, text));
				}
				break;
			}
			}
			((Graphic)thisReference.pingText).color = thisReference.textBaseColor * thisReference.pingColor;
			thisReference.fixedTimer = thisReference.pingDuration;
		}
	}
}