Decompiled source of NewtsBargain v1.1.1

NewtsBargain.dll

Decompiled 18 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.NewtMonster;
using HarmonyLib;
using R2API.Networking;
using R2API.Networking.Interfaces;
using RoR2;
using RoR2.Achievements;
using RoR2.ContentManagement;
using RoR2.UI.LogBook;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace NewtsBargain;

[BepInPlugin("binma.newtsbargain", "Newt's Bargain", "1.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	internal static Plugin Instance;

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> PearlTrade;

	internal static ConfigEntry<bool> OnlyFromNewt;

	internal static ConfigEntry<bool> SilentNewt;

	internal static ConfigEntry<bool> LunarPods;

	internal static ConfigEntry<bool> Everywhere;

	internal static ConfigEntry<bool> NewtSpeaks;

	internal static ConfigEntry<bool> UnkillableNewt;

	internal static ConfigEntry<bool> VoidReflect;

	internal static ConfigEntry<bool> TransmitterTranslates;

	internal static ConfigEntry<int> PearlCost;

	internal static ConfigEntry<int> IrradiantCost;

	internal static ConfigEntry<int> TradesPerVisit;

	internal const string ElegyName = "LunarPortalOnUse";

	internal static int Cost => Math.Max(1, PearlCost.Value);

	internal static int IrradiantCostValue => Math.Max(1, IrradiantCost.Value);

	private void Awake()
	{
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		PearlTrade = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Pearl trade", true, "Give Newt Pearls or an Irradiant Pearl in the Bazaar to receive Elegy of Extinction.");
		PearlCost = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Pearls per trade", 2, "How many regular Pearls Newt takes for one Elegy of Extinction.");
		IrradiantCost = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Irradiant Pearls per trade", 1, "How many Irradiant Pearls Newt takes for one Elegy of Extinction (the alternative to regular Pearls).");
		TradesPerVisit = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Elegy trades per visit", 1, "How many times each player can trade Newt for Elegy of Extinction per Bazaar visit.");
		OnlyFromNewt = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Elegy only from Newt", true, "Elegy of Extinction never drops on its own (e.g. when Recovered and Reformed enables it). Newt's trade is the only way to get it. Once unlocked, a Recycler can still turn lunar equipment into it.");
		LunarPods = ((BaseUnityPlugin)this).Config.Bind<bool>("Unlocked", "Elegy in Lunar Pods", true, "Once Elegy of Extinction is unlocked, it can also come out of Lunar Pods on stages (never the Bazaar's).");
		Everywhere = ((BaseUnityPlugin)this).Config.Bind<bool>("Unlocked", "Elegy drops everywhere", false, "Once Elegy of Extinction is unlocked, let it drop anywhere lunar equipment normally can, Bazaar included.");
		NewtSpeaks = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Newt speaks", true, "Newt says short lines in his own tongue at moments in the Bazaar: greeting you, trades, purchases, portals, being shot, kicking you out, and more. Some travelers can understand him.");
		UnkillableNewt = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Unkillable Newt", true, "Newt can be hurt and still kicks you out when he gets low, but he can't die.");
		VoidReflect = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Newt returns the void", true, "Newt can't be erased by Lost Seer's Lenses. If you try, the void takes you instead.");
		TransmitterTranslates = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "H34V-EN Transmitter translates Newt", true, "With DegenerateItems installed, the H34V-EN Transmitter also lets everyone understand Newt.");
		SilentNewt = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Silent Newt", true, "Silences chat lines other mods give Newt, since he doesn't talk in the base game. His own lines from this mod are controlled by Newt speaks.");
		NetworkingAPI.RegisterMessageType<NewtFxMessage>();
		Unlock.Init();
		Harmony val = new Harmony("binma.newtsbargain");
		Type[] types = typeof(Plugin).Assembly.GetTypes();
		foreach (Type type in types)
		{
			if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Length != 0)
			{
				try
				{
					val.CreateClassProcessor(type).Patch();
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Patch " + type.Name + " failed: " + ex));
				}
			}
		}
		Trade.Setup(val);
		NewtEvents.Init(val);
		ConstructorCompat.Init(val);
	}

	internal static void Delay(float seconds, Action action)
	{
		if (Object.op_Implicit((Object)(object)Instance))
		{
			((MonoBehaviour)Instance).StartCoroutine(DelayRoutine(seconds, action));
		}
	}

	private static IEnumerator DelayRoutine(float seconds, Action action)
	{
		yield return (object)new WaitForSeconds(seconds);
		try
		{
			action();
		}
		catch (Exception ex)
		{
			Log.LogError((object)ex);
		}
	}
}
internal static class Trade
{
	private static Type erTrader;

	private static FieldInfo erTake;

	private static FieldInfo erGive;

	private static FieldInfo erAvailable;

	private static MethodInfo erSetAvailable;

	private static readonly Dictionary<uint, int> tradesThisVisit = new Dictionary<uint, int>();

	internal static void Setup(Harmony harmony)
	{
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Expected O, but got Unknown
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Expected O, but got Unknown
		erTrader = AccessTools.TypeByName("EnemiesReturns.Behaviors.Judgement.Newt.NewtTrader");
		if (erTrader != null)
		{
			erTake = AccessTools.Field(erTrader, "itemToTake");
			erGive = AccessTools.Field(erTrader, "itemToGive");
			erAvailable = AccessTools.Field(erTrader, "available");
			erSetAvailable = AccessTools.PropertySetter(erTrader, "Networkavailable");
			try
			{
				harmony.Patch((MethodBase)AccessTools.Method(erTrader, "GetInteractability", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Trade), "ErInteractability", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(erTrader, "OnInteractionBegin", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Trade), "ErInteract", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(erTrader, "GetContextString", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Trade), "ErContext", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Enemies Returns Newt hook failed: " + ex));
			}
		}
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(AddOwnTraderIfNeeded));
	}

	private static void AddOwnTraderIfNeeded()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			GameObject val = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Shopkeeper/ShopkeeperBody.prefab").WaitForCompletion();
			if (!Object.op_Implicit((Object)(object)val) || (erTrader != null && Object.op_Implicit((Object)(object)val.GetComponent(erTrader))) || Object.op_Implicit((Object)(object)val.GetComponent<PearlTrader>()))
			{
				return;
			}
			val.AddComponent<PearlTrader>();
			if (!Object.op_Implicit((Object)(object)val.GetComponent<Highlight>()))
			{
				Highlight val2 = val.AddComponent<Highlight>();
				Transform val3 = val.transform.Find("ModelBase/mdlNewtShopkeeper/NewtMesh");
				if (Object.op_Implicit((Object)(object)val3))
				{
					val2.targetRenderer = ((Component)val3).GetComponent<Renderer>();
				}
			}
			if (!Object.op_Implicit((Object)(object)val.GetComponent<EntityLocator>()))
			{
				val.AddComponent<EntityLocator>().entity = val;
			}
			Plugin.Log.LogInfo((object)"Added the pearl trade to Newt.");
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Newt setup failed: " + ex));
		}
	}

	internal static Inventory Inv(Interactor activator)
	{
		if (!Object.op_Implicit((Object)(object)activator))
		{
			return null;
		}
		CharacterBody component = ((Component)activator).GetComponent<CharacterBody>();
		return (!Object.op_Implicit((Object)(object)component)) ? null : component.inventory;
	}

	internal static bool HasPearls(Inventory inv)
	{
		return Object.op_Implicit((Object)(object)inv) && inv.GetItemCountPermanent(Items.Pearl) >= Plugin.Cost;
	}

	internal static bool HasIrradiant(Inventory inv)
	{
		return Object.op_Implicit((Object)(object)inv) && inv.GetItemCountPermanent(Items.ShinyPearl) >= Plugin.IrradiantCostValue;
	}

	internal static void ResetVisit()
	{
		tradesThisVisit.Clear();
	}

	private static uint Key(Inventory inv)
	{
		//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)
		NetworkIdentity val = ((!Object.op_Implicit((Object)(object)inv)) ? null : ((Component)inv).GetComponent<NetworkIdentity>());
		int result;
		if (Object.op_Implicit((Object)(object)val))
		{
			NetworkInstanceId netId = val.netId;
			result = (int)((NetworkInstanceId)(ref netId)).Value;
		}
		else
		{
			result = 0;
		}
		return (uint)result;
	}

	internal static bool TradeLeft(Inventory inv)
	{
		tradesThisVisit.TryGetValue(Key(inv), out var value);
		return value < Math.Max(1, Plugin.TradesPerVisit.Value);
	}

	internal static void CountTrade(Inventory inv)
	{
		uint key = Key(inv);
		tradesThisVisit.TryGetValue(key, out var value);
		tradesThisVisit[key] = value + 1;
	}

	internal static bool HasPearl(Inventory inv)
	{
		return Plugin.PearlTrade.Value && (HasPearls(inv) || HasIrradiant(inv)) && TradeLeft(inv);
	}

	internal static string ContextFor(Inventory inv)
	{
		if (HasPearls(inv))
		{
			return "Offer " + Plugin.Cost + ((Plugin.Cost != 1) ? " Pearls" : " Pearl");
		}
		int irradiantCostValue = Plugin.IrradiantCostValue;
		return (irradiantCostValue != 1) ? ("Offer " + irradiantCostValue + " Irradiant Pearls") : "Offer Irradiant Pearl";
	}

	private static bool ErRock(object trader, Inventory inv)
	{
		if (!Object.op_Implicit((Object)(object)inv) || erTake == null)
		{
			return false;
		}
		bool flag = erAvailable != null && (bool)erAvailable.GetValue(trader);
		object? value = erTake.GetValue(trader);
		ItemDef val = (ItemDef)((value is ItemDef) ? value : null);
		return flag && Object.op_Implicit((Object)(object)val) && inv.GetItemCountPermanent(val) > 0;
	}

	private static bool ErInteractability(object __instance, Interactor __0, ref Interactability __result)
	{
		try
		{
			Inventory inv = Inv(__0);
			__result = (Interactability)((ErRock(__instance, inv) || HasPearl(inv)) ? 2 : 0);
			return false;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
			return true;
		}
	}

	private static bool ErContext(object __instance, Interactor __0, ref string __result)
	{
		try
		{
			Inventory inv = Inv(__0);
			if (ErRock(__instance, inv))
			{
				return true;
			}
			if (HasPearl(inv))
			{
				__result = ContextFor(inv);
				return false;
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
		return true;
	}

	private static bool ErInteract(object __instance, Interactor __0)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!NetworkServer.active)
			{
				return false;
			}
			Component val = (Component)((__instance is Component) ? __instance : null);
			Inventory val2 = Inv(__0);
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2))
			{
				return false;
			}
			if (ErRock(__instance, val2))
			{
				ItemDef val3 = (ItemDef)erTake.GetValue(__instance);
				object? value = erGive.GetValue(__instance);
				ItemDef val4 = (ItemDef)((value is ItemDef) ? value : null);
				val2.RemoveItemPermanent(val3, val2.GetItemCountPermanent(val3));
				if (erSetAvailable != null)
				{
					erSetAvailable.Invoke(__instance, new object[1] { false });
				}
				if (Object.op_Implicit((Object)(object)val4))
				{
					Give(val.gameObject, PickupCatalog.FindPickupIndex(val4.itemIndex));
				}
				NewtVoice.Say(NewtVoice.RockLines);
			}
			else if (HasPearl(val2))
			{
				PearlTrade(val.gameObject, val2);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
		return false;
	}

	internal static void PearlTrade(GameObject newt, Inventory inv)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Invalid comparison between Unknown and I4
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		CountTrade(inv);
		if (HasPearls(inv))
		{
			inv.RemoveItemPermanent(Items.Pearl, Plugin.Cost);
		}
		else
		{
			inv.RemoveItemPermanent(Items.ShinyPearl, Plugin.IrradiantCostValue);
		}
		EquipmentIndex val = EquipmentCatalog.FindEquipmentIndex("LunarPortalOnUse");
		if ((int)val == -1)
		{
			Plugin.Log.LogWarning((object)"Elegy of Extinction not found.");
			return;
		}
		Give(newt, PickupCatalog.FindPickupIndex(val));
		NewtVoice.Say(NewtVoice.PearlLines);
		NewtFxMessage.Send(((Component)inv).gameObject, 2);
	}

	internal static void Give(GameObject newt, PickupIndex pickup)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		NetworkIdentity component = newt.GetComponent<NetworkIdentity>();
		NewtFxMessage.Send(newt, 0);
		Plugin.Delay(1.2f, delegate
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)newt) && NetworkServer.active)
			{
				Vector3 val = Vector3.up * 20f + newt.transform.forward * 8f;
				PickupDropletController.CreatePickupDroplet(new UniquePickup(pickup), newt.transform.position, val, false);
			}
		});
	}

	internal static void PlayFx(GameObject newt)
	{
		CharacterBody component = newt.GetComponent<CharacterBody>();
		Transform val = ((!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.modelLocator)) ? null : component.modelLocator.modelTransform);
		Animator val2 = ((!Object.op_Implicit((Object)(object)val)) ? null : ((Component)val).GetComponent<Animator>());
		if (Object.op_Implicit((Object)(object)val2))
		{
			int layerIndex = val2.GetLayerIndex("Body");
			if (layerIndex >= 0)
			{
				val2.SetFloat("Stomp.playbackRate", 1f);
				val2.Play("Stomp", layerIndex, 0f);
			}
		}
		string spawnSoundString = SpawnState.spawnSoundString;
		if (!string.IsNullOrEmpty(spawnSoundString))
		{
			Util.PlaySound(spawnSoundString, newt);
		}
	}
}
public class PearlTrader : MonoBehaviour, IInteractable
{
	public string GetContextString(Interactor activator)
	{
		return Trade.ContextFor(Trade.Inv(activator));
	}

	public Interactability GetInteractability(Interactor activator)
	{
		return (Interactability)(Trade.HasPearl(Trade.Inv(activator)) ? 2 : 0);
	}

	public void OnInteractionBegin(Interactor activator)
	{
		if (NetworkServer.active)
		{
			Inventory inv = Trade.Inv(activator);
			if (Trade.HasPearl(inv))
			{
				Trade.PearlTrade(((Component)this).gameObject, inv);
			}
		}
	}

	public bool ShouldIgnoreSpherecastForInteractibility(Interactor activator)
	{
		return false;
	}

	public bool ShouldShowOnScanner()
	{
		return false;
	}

	public bool ShouldProximityHighlight()
	{
		return true;
	}

	public int GetInteractablePriority(Interactor activator)
	{
		return 0;
	}

	public bool ShouldSpawnLesserInteractionRewards(Interactor activator)
	{
		return false;
	}
}
public class NewtFxMessage : INetMessage, ISerializableObject
{
	internal const string VoiceSound = "Play_newtShopkeep_VO";

	private NetworkInstanceId id;

	private byte mode;

	public NewtFxMessage()
	{
	}

	public NewtFxMessage(NetworkInstanceId id, byte mode = 0)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		this.id = id;
		this.mode = mode;
	}

	public void Serialize(NetworkWriter writer)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		writer.Write(id);
		writer.Write(mode);
	}

	public void Deserialize(NetworkReader reader)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		id = reader.ReadNetworkId();
		mode = reader.ReadByte();
	}

	public void OnReceived()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			GameObject val = Util.FindNetworkObject(id);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			if (mode == 2)
			{
				if (NewtsBargainAchievement.Traded != null)
				{
					NewtsBargainAchievement.Traded(val);
				}
			}
			else if (mode == 1)
			{
				Util.PlaySound("Play_newtShopkeep_VO", val);
			}
			else
			{
				Trade.PlayFx(val);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}

	internal static void Send(GameObject newt, byte mode)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		NetworkIdentity val = ((!Object.op_Implicit((Object)(object)newt)) ? null : newt.GetComponent<NetworkIdentity>());
		if (Object.op_Implicit((Object)(object)val))
		{
			NetMessageExtensions.Send((INetMessage)(object)new NewtFxMessage(val.netId, mode), (NetworkDestination)1);
		}
	}
}
internal static class SilentNewt
{
	internal static bool Blocked(ChatMessageBase msg)
	{
		if (NewtVoice.Speaking || !Plugin.SilentNewt.Value || msg == null)
		{
			return false;
		}
		string value = Traverse.Create((object)msg).Field("baseToken").GetValue<string>();
		if (string.IsNullOrEmpty(value))
		{
			return false;
		}
		return value.StartsWith("ENEMIES_RETURNS_JUDGEMENT_NEWT", StringComparison.Ordinal) || value.IndexOf("SHOPKEEPER", StringComparison.OrdinalIgnoreCase) >= 0 || value.IndexOf("NEWT_", StringComparison.OrdinalIgnoreCase) >= 0;
	}
}
internal static class ChefCompat
{
	internal static bool ChefHere()
	{
		try
		{
			NetworkIdentity[] array = Object.FindObjectsOfType<NetworkIdentity>();
			foreach (NetworkIdentity val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && ((Object)((Component)val).gameObject).name.StartsWith("MealPrep", StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
		return false;
	}
}
[HarmonyPatch]
internal static class ChatPatch
{
	private static IEnumerable<MethodBase> TargetMethods()
	{
		MethodInfo[] methods = typeof(Chat).GetMethods(BindingFlags.Static | BindingFlags.Public);
		foreach (MethodInfo m in methods)
		{
			if (m.Name == "SendBroadcastChat" && m.GetParameters().Length >= 1 && typeof(ChatMessageBase).IsAssignableFrom(m.GetParameters()[0].ParameterType))
			{
				yield return m;
			}
		}
	}

	private static bool Prefix(ChatMessageBase __0)
	{
		try
		{
			if (VoidReflectDeathPatch.active && __0 != null)
			{
				Traverse val = Traverse.Create((object)__0).Field("baseToken");
				string value = val.GetValue<string>();
				if (value != null && value.StartsWith("PLAYER_DEATH_QUOTE", StringComparison.Ordinal))
				{
					val.SetValue((object)"NEWTSBARGAIN_DEATH_QUOTE");
				}
			}
			return !SilentNewt.Blocked(__0);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
			return true;
		}
	}
}
internal static class Unlock
{
	private class Provider : IContentPackProvider
	{
		private readonly ContentPack pack = new ContentPack();

		public string identifier => "binma.newtsbargain";

		public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
		{
			pack.unlockableDefs.Add((UnlockableDef[])(object)new UnlockableDef[1] { Def });
			args.ReportProgress(1f);
			yield break;
		}

		public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
		{
			ContentPack.Copy(pack, args.output);
			args.ReportProgress(1f);
			yield break;
		}

		public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
		{
			args.ReportProgress(1f);
			yield break;
		}
	}

	internal const string AchievementId = "BinmaNewtsBargain";

	internal const string UnlockName = "Items.Binma.ElegyOfExtinction";

	internal const string NameToken = "ACHIEVEMENT_BINMANEWTSBARGAIN_NAME";

	internal const string DescToken = "ACHIEVEMENT_BINMANEWTSBARGAIN_DESCRIPTION";

	internal static UnlockableDef Def;

	internal static readonly Dictionary<string, string> Tokens = new Dictionary<string, string>
	{
		{ "ACHIEVEMENT_BINMANEWTSBARGAIN_NAME", "Newt's Bargain" },
		{ "ACHIEVEMENT_BINMANEWTSBARGAIN_DESCRIPTION", "Trade a Pearl or an Irradiant Pearl to the Keeper of the Bazaar." },
		{ "NEWTSBARGAIN_DEATH_QUOTE", "{0} was lost to the void at the hands of the Shopkeeper." }
	};

	internal static void Init()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		Def = ScriptableObject.CreateInstance<UnlockableDef>();
		Def.cachedName = "Items.Binma.ElegyOfExtinction";
		Def.nameToken = "EQUIPMENT_LUNARPORTALONUSE_NAME";
		ContentManager.collectContentPackProviders += (CollectContentPackProvidersDelegate)delegate(AddContentPackProviderDelegate add)
		{
			add.Invoke((IContentPackProvider)(object)new Provider());
		};
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(Attach));
	}

	private static void Attach()
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Invalid comparison between Unknown and I4
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Def.getHowToUnlockString = () => Language.GetStringFormatted("UNLOCK_VIA_ACHIEVEMENT_FORMAT", new object[2]
			{
				Language.GetString("ACHIEVEMENT_BINMANEWTSBARGAIN_NAME"),
				Language.GetString("ACHIEVEMENT_BINMANEWTSBARGAIN_DESCRIPTION")
			});
			Def.getUnlockedString = () => Language.GetStringFormatted("UNLOCKED_FORMAT", new object[2]
			{
				Language.GetString("ACHIEVEMENT_BINMANEWTSBARGAIN_NAME"),
				Language.GetString("ACHIEVEMENT_BINMANEWTSBARGAIN_DESCRIPTION")
			});
			EquipmentIndex val = EquipmentCatalog.FindEquipmentIndex("LunarPortalOnUse");
			if ((int)val == -1)
			{
				return;
			}
			EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(val);
			equipmentDef.unlockableDef = Def;
			PickupDef pickupDef = PickupCatalog.GetPickupDef(PickupCatalog.FindPickupIndex(val));
			if (pickupDef != null)
			{
				pickupDef.unlockableDef = Def;
			}
			if (Object.op_Implicit((Object)(object)equipmentDef.pickupIconSprite))
			{
				Def.achievementIcon = equipmentDef.pickupIconSprite;
				AchievementDef achievementDef = AchievementManager.GetAchievementDef("BinmaNewtsBargain");
				if (achievementDef != null)
				{
					achievementDef.SetAchievedIcon(equipmentDef.pickupIconSprite);
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}
}
[RegisterAchievement("BinmaNewtsBargain", "Items.Binma.ElegyOfExtinction", null, 5u, null)]
public class NewtsBargainAchievement : BaseAchievement
{
	internal static Action<GameObject> Traded;

	public override void OnInstall()
	{
		((BaseAchievement)this).OnInstall();
		Traded = (Action<GameObject>)Delegate.Combine(Traded, new Action<GameObject>(Check));
	}

	public override void OnUninstall()
	{
		Traded = (Action<GameObject>)Delegate.Remove(Traded, new Action<GameObject>(Check));
		((BaseAchievement)this).OnUninstall();
	}

	private void Check(GameObject master)
	{
		try
		{
			if (Object.op_Implicit((Object)(object)master) && ((BaseAchievement)this).localUser != null && (Object)(object)((BaseAchievement)this).localUser.cachedMasterObject == (Object)(object)master)
			{
				((BaseAchievement)this).Grant();
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}
}
[HarmonyPatch(typeof(Language), "GetLocalizedStringByToken")]
internal static class LanguagePatch
{
	private static void Postfix(string __0, ref string __result)
	{
		if (__0 != null && (__result == null || __result == __0) && Unlock.Tokens.TryGetValue(__0, out var value))
		{
			__result = value;
		}
	}
}
internal static class ElegyLists
{
	internal static void Strip(Run run)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)run) || !Plugin.OnlyFromNewt.Value)
		{
			return;
		}
		EquipmentIndex val = EquipmentCatalog.FindEquipmentIndex("LunarPortalOnUse");
		if ((int)val == -1 || (Plugin.Everywhere.Value && run.IsEquipmentAvailable(val)))
		{
			return;
		}
		PickupIndex pickup = PickupCatalog.FindPickupIndex(val);
		FieldInfo[] fields = typeof(Run).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		foreach (FieldInfo fieldInfo in fields)
		{
			if (!(fieldInfo.FieldType != typeof(List<PickupIndex>)) && fieldInfo.GetValue(run) is List<PickupIndex> list)
			{
				list.RemoveAll((PickupIndex p) => p == pickup);
			}
		}
	}
}
[HarmonyPatch(typeof(PickupDropTable), "RegenerateAll")]
internal static class DropTableRegenPatch
{
	private static void Prefix(Run __0)
	{
		try
		{
			ElegyLists.Strip(__0);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}
}
[HarmonyPatch(typeof(Run), "BuildDropTable")]
internal static class DropTablePatch
{
	private static readonly MethodInfo regenAll = AccessTools.Method(typeof(PickupDropTable), "RegenerateAll", (Type[])null, (Type[])null);

	private static void Postfix(Run __instance)
	{
		try
		{
			ElegyLists.Strip(__instance);
			if (regenAll != null && Plugin.OnlyFromNewt.Value)
			{
				regenAll.Invoke(null, new object[1] { __instance });
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}
}
[HarmonyPatch(typeof(LogBookController), "GetPickupTooltipContent")]
internal static class TooltipGuard
{
	private static void Prefix(ref Entry __0)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (__0 == null || !(__0.extraData is PickupIndex))
			{
				return;
			}
			PickupDef pickupDef = PickupCatalog.GetPickupDef((PickupIndex)__0.extraData);
			UnlockableDef u = pickupDef?.unlockableDef;
			if (!Object.op_Implicit((Object)(object)u))
			{
				return;
			}
			if (u.getHowToUnlockString == null)
			{
				Plugin.Log.LogWarning((object)("Unlockable '" + u.cachedName + "' on " + pickupDef.internalName + " had no unlock text; filled it in so the logbook doesn't break."));
				u.getHowToUnlockString = () => Language.GetString("UNIDENTIFIED");
			}
			if (u.getUnlockedString == null)
			{
				u.getUnlockedString = () => Language.GetString(u.nameToken ?? "");
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}
}
[HarmonyPatch(typeof(ChestBehavior), "Roll")]
internal static class LunarPodPatch
{
	private static readonly MethodInfo setPickup = AccessTools.PropertySetter(typeof(ChestBehavior), "currentPickup");

	private static void Postfix(ChestBehavior __instance)
	{
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Invalid comparison between Unknown and I4
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!NetworkServer.active || !Plugin.LunarPods.Value || !Plugin.OnlyFromNewt.Value || Plugin.Everywhere.Value || !Object.op_Implicit((Object)(object)__instance) || ((Object)((Component)__instance).gameObject).name.IndexOf("LunarChest", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return;
			}
			SceneDef sceneDefForCurrentScene = SceneCatalog.GetSceneDefForCurrentScene();
			if (!Object.op_Implicit((Object)(object)sceneDefForCurrentScene) || sceneDefForCurrentScene.cachedName == "bazaar")
			{
				return;
			}
			Run instance = Run.instance;
			EquipmentIndex val = EquipmentCatalog.FindEquipmentIndex("LunarPortalOnUse");
			if (Object.op_Implicit((Object)(object)instance) && (int)val != -1 && instance.IsEquipmentAvailable(val))
			{
				int num = ((instance.availableLunarCombinedDropList != null) ? instance.availableLunarCombinedDropList.Count : 0);
				if (!(instance.treasureRng.nextNormalizedFloat >= 1f / (float)(num + 1)) && setPickup != null)
				{
					setPickup.Invoke(__instance, new object[1] { (object)new UniquePickup(PickupCatalog.FindPickupIndex(val)) });
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}
}
internal struct Line
{
	public readonly string Tongue;

	public readonly string English;

	public Line(string tongue, string english)
	{
		Tongue = tongue;
		English = english;
	}
}
internal static class NewtVoice
{
	internal static bool Speaking;

	internal static readonly Line[] Greet = new Line[5]
	{
		new Line("Vëshaal. Far? No. Back.", "Traveler. You think you came far. You came back."),
		new Line("Säethïr. Rivers return. Sëiä.", "Again. Rivers return to where they began. So it is."),
		new Line("Vëshaal. Ënnuvaal waits here.", "Traveler. Time waits here."),
		new Line("Säethïr. Early, late. Same.", "Again. Early or late, it is the same here."),
		new Line("Vëshaal. Answers sought. Coins spent. Sëiä.", "Traveler. Many seek answers. Most spend coins. So it is.")
	};

	internal static readonly Line[] PearlLines = new Line[3]
	{
		new Line("Thëssarïn. Fair. Väelith ūm.", "Pearls. Fair. The door is yours."),
		new Line("Thëssarïn for passage. Sëiä.", "Pearls for passage. So it is."),
		new Line("Thëssarïn kaë. Dhäl is yours. Walk wisely.", "Pearls given. The path is yours. Walk it wisely.")
	};

	internal static readonly Line[] RockLines = new Line[3]
	{
		new Line("Khärroth kaë. Lïessaë ūm. Sëiä.", "Stone given. Bloom taken. So it is."),
		new Line("Heavy khärroth. Light lïessaë. Both burdens.", "Heavy stone. Light bloom. Both are burdens."),
		new Line("He will know it. Sëiä.", "He will know it. So it is.")
	};

	internal static readonly Line[] Artificer = new Line[4]
	{
		new Line("Lïraëth. Ënnuvaal lets go.", "Freed. Time lets go."),
		new Line("Frozen. Waiting. Ënnuvaal sees no difference.", "Frozen, or waiting. Time sees no difference."),
		new Line("Ïlun forgets. She won't.", "The cold forgets. She won't."),
		new Line("Still burning. Go, lïraëth.", "Still burning. Go, freed one.")
	};

	internal static readonly Line[] CauldronWhite = new Line[3]
	{
		new Line("Three mïnthar. One grävaal. Sëiä.", "Three small things. One greater thing. So it is."),
		new Line("Melt, säethïr. Become more.", "Melt it again. Become something more."),
		new Line("Little things, kaë. Better thing, ūm.", "Little things given. A better thing taken.")
	};

	internal static readonly Line[] CauldronGreen = new Line[3]
	{
		new Line("Five kaë. One ūm. Ënnuvaal approves.", "Five given. One taken. Time approves."),
		new Line("Much sacrificed. Grävaal earned. Sëiä.", "Much sacrificed. Something great earned. So it is."),
		new Line("Five fade. One burns brighter. Sëiä.", "Five fade away. One burns brighter. So it is.")
	};

	internal static readonly Line[] ConstructorUse = new Line[2]
	{
		new Line("Scrap kaë. Form ūm. Sëiä.", "Scrap given. A form taken. So it is."),
		new Line("Säethïr, it shapes. Sëiä.", "Again, it takes shape. So it is.")
	};

	internal static readonly Line[] ConstructorLunar = new Line[1]
	{
		new Line("Lunar grävaal. It knows you.", "A great lunar thing. It knows you.")
	};

	internal static readonly Line[] ConstructorTemp = new Line[1]
	{
		new Line("Brief. Ënnuvaal will take it back.", "Brief. Time will take it back.")
	};

	internal static readonly Line[] ConstructorHex = new Line[1]
	{
		new Line("Hexed. Kaë with care. Sëiä.", "Hexed. Given with care. So it is.")
	};

	internal static readonly Line[] ConstructorVoid = new Line[1]
	{
		new Line("Nūllaveth answers. Rarely.", "The void answers. Rarely.")
	};

	internal static readonly Line[] ConstructorNone = new Line[1]
	{
		new Line("Nothing kaë. Nothing ūm. Sëiä.", "Nothing given. Nothing taken. So it is.")
	};

	internal static readonly Line[] LensWarning = new Line[3]
	{
		new Line("Nūllaveth in your eyes. Not here, vëshaal.", "The void in your eyes. Not here, traveler."),
		new Line("Careful. Nūllaveth looks back. Sëiä.", "Careful. The void looks back. So it is."),
		new Line("Those eyes. Lower them, vëshaal.", "Those eyes. Lower them, traveler.")
	};

	internal static readonly Line[] TricornLaugh = new Line[3]
	{
		new Line("Hm hm hm. A trophy? Of me? Sëiä.", "Heh heh heh. A trophy? Of me? So it is."),
		new Line("Ha. Ënnuvaal has seen braver hunters.", "Ha. Time has seen braver hunters."),
		new Line("Hm hm. Nice hat, vëshaal. Kaë nothing.", "Heh heh. Nice hat, traveler. It gets you nothing.")
	};

	internal static readonly Line[] Bud = new Line[4]
	{
		new Line("Lunar mïnthar. Fair coin. Sëiä.", "A lunar trade. Fair coin. So it is."),
		new Line("Lïessaë of the moon. Handle carefully.", "Fortune of the moon. Handle carefully."),
		new Line("Coin kaë. Curse ūm. Sëiä.", "Coin given. Curse taken. So it is."),
		new Line("Every gift costs. Ënnuvaal knows.", "Every gift costs. Time knows.")
	};

	internal static readonly Line[] Chef = new Line[3]
	{
		new Line("The cook returns. Eat, vëshaal. Ënnuvaal can wait.", "The cook is back. Eat, traveler. Time can wait."),
		new Line("Smoke and spice. Mïnthar of another kind. Sëiä.", "Smoke and spice. A trade of another kind. So it is."),
		new Line("His food is good. Do not tell him. Sëiä.", "His food is good. Don't tell him. So it is.")
	};

	internal static readonly Line[] MeridianParadox = new Line[3]
	{
		new Line("Two sons. One throne. Ënnuvaal ties itself in knots again. Sëiä.", "Two sons. One throne. Time ties itself in knots again. So it is."),
		new Line("You go to meet yourself, vëshaal. Ënnuvaal laughs.", "You go to meet yourself, traveler. Time laughs."),
		new Line("A son, fighting his own shadow. Ënnuvaal has seen stranger. Barely.", "A son, fighting his own shadow. Time has seen stranger. Barely.")
	};

	internal static readonly Line[] Tickle = new Line[3]
	{
		new Line("Hm hm. That tickles, vëshaal.", "Heh heh. That tickles, traveler."),
		new Line("Tickles. Ënnuvaal has struck harder.", "It tickles. Time has struck harder."),
		new Line("Ha. A feather. Again? Sëiä.", "Ha. A feather. Again? So it is.")
	};

	internal static readonly Line[] VoidLost = new Line[3]
	{
		new Line("Nūllaveth ūm. Sëiä.", "The void takes. So it is."),
		new Line("Lost. Nūllaveth keeps what it takes. Out.", "Lost. The void keeps what it takes. Out."),
		new Line("Ënnuvaal forgets them already. Go.", "Time has already forgotten them. Go.")
	};

	internal static readonly Line[] Commencement = new Line[3]
	{
		new Line("The brother waits above. Väelith opens.", "The brother waits above. The door opens."),
		new Line("Hatred on a throne. Go, vëshaal. Sëiä.", "Hatred sits on a throne. Go, traveler. So it is."),
		new Line("Ënnuvaal bends toward the moon. He is waiting.", "Time bends toward the moon. He is waiting.")
	};

	internal static readonly Line[] Farewell = new Line[3]
	{
		new Line("Go well, vëshaal. Sëiä.", "Go well, traveler. So it is."),
		new Line("Ënnuvaal walks with you. Until again.", "Time walks with you. Until we meet again."),
		new Line("Leave, then. Väelith remembers you.", "Leave, then. The door remembers you.")
	};

	internal static readonly Line[] Kick = new Line[5]
	{
		new Line("Hëh. Ënnuvaal laughs. Out.", "Heh. Even time laughs. Out you go."),
		new Line("Vëshaal... out. Ënnuvaal will wait for you.", "Traveler... out. Time will wait for you."),
		new Line("Strike again. Ënnuvaal forgets it already.", "Strike again. Time has already forgotten it."),
		new Line("Mmh. A moment's storm. Ënnuvaal passes it. Sëiä.", "Mmh. A storm for a moment. Time lets it pass. So it is."),
		new Line("Mmh? Vëshaal... thäl? Ënnuvaal blinked. Nothing.", "Mmh? Traveler... did something touch me? Time blinked. Nothing.")
	};

	internal static readonly Line[] Hallowed = new Line[3]
	{
		new Line("Hallowed ground. Tread soft. Sëiä.", "Hallowed ground. Tread softly. So it is."),
		new Line("Ōrunvaal tests. Few pass.", "The trials test you. Few pass."),
		new Line("Vëshaal. Prove it.", "Traveler. Prove yourself.")
	};

	internal static readonly Line[] Gilded = new Line[3]
	{
		new Line("Ǽurëlith sleeps there. It wakes.", "Gold sleeps there. It wakes when you arrive."),
		new Line("Ǽurëlith. Guarded. Sëiä.", "Gold. Guarded. So it is."),
		new Line("Ǽurëlith walls. Old fury. Sëiä.", "Walls of gold. An old fury. So it is.")
	};

	internal static readonly Line[] VoidFields = new Line[3]
	{
		new Line("Nūllaveth. Nothing. Everything.", "The void. Nothing. Everything."),
		new Line("Cells open. Few close them. Sëiä.", "The cells open. Few close them. So it is."),
		new Line("Lose yourself. Find more. Sëiä.", "Lose yourself there. Find more. So it is.")
	};

	internal static readonly Line[] VoidLocus = new Line[4]
	{
		new Line("Nūllaveth deeper. It hungers. Sëiä.", "Deeper into the void. It hungers. So it is."),
		new Line("Sïgreth call. Answer carefully.", "The signals call. Answer them carefully."),
		new Line("Beyond, its kördhal. Vëshaal, beware.", "Beyond lies its heart. Traveler, beware."),
		new Line("What is ūm there... stays. Sëiä.", "What is taken there stays there. So it is.")
	};

	internal static readonly Line[] Altar = new Line[3]
	{
		new Line("Ärkhavol. Stone father watches. Sëiä.", "The altar. The stone father watches. So it is."),
		new Line("Sand remembers his shadow. Sëiä.", "The sand remembers his shadow. So it is."),
		new Line("Väelith green. First step.", "A green door. The first step.")
	};

	internal static readonly Line[] Colony = new Line[3]
	{
		new Line("Higher. Ënnuvaal thins. Sëiä.", "Higher. Time grows thin. So it is."),
		new Line("Vïrenthal. Roots above stone.", "The colony. Roots grow above the stone."),
		new Line("Väelith green, säethïr. Closer.", "A green door, again. Closer now.")
	};

	internal static readonly Line[] Dieback = new Line[3]
	{
		new Line("Ǽurëlith leaves. Falling. Sëiä.", "Golden leaves. Falling. So it is."),
		new Line("Vïrenthal withers. Säethïr, yet higher.", "The colony withers. Again, yet higher."),
		new Line("Even ǽurëlith fades. He does not.", "Even gold fades. He does not.")
	};

	internal static readonly Line[] Meridian = new Line[3]
	{
		new Line("The son waits. Unloved. Sëiä.", "The son waits. Unloved. So it is."),
		new Line("Father's shadow. Son's fury. Väelith ends here.", "The father's shadow. The son's fury. The path ends here."),
		new Line("Two brothers. Hatred. Passion. One son. Sëiä.", "Two brothers. One's hatred, the other's passion. One son. So it is.")
	};

	private static readonly Dictionary<Line[], int> lastPicked = new Dictionary<Line[], int>();

	private static ItemDef Transmitter()
	{
		//IL_0016: 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_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Invalid comparison between Unknown and I4
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.TransmitterTranslates.Value)
		{
			return null;
		}
		ItemIndex val = ItemCatalog.FindItemIndex("DEGENERATEITEMS_HEAVENTRANSMITTER_NAME");
		return ((int)val == -1) ? null : ItemCatalog.GetItemDef(val);
	}

	private static bool AnyoneCanTranslate(out string color)
	{
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		ItemDef val = Transmitter();
		bool flag = false;
		bool flag2 = false;
		bool flag3 = false;
		bool flag4 = false;
		bool flag5 = false;
		bool flag6 = false;
		bool flag7 = false;
		foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
		{
			if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.master))
			{
				Inventory inventory = instance.master.inventory;
				if (Object.op_Implicit((Object)(object)inventory) && inventory.GetItemCountPermanent(Items.CritGlassesVoid) > 0)
				{
					flag = true;
				}
				if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)inventory) && inventory.GetItemCountPermanent(val) > 0)
				{
					flag2 = true;
				}
				CharacterBody body = instance.master.GetBody();
				string text = ((!Object.op_Implicit((Object)(object)body)) ? "" : (BodyCatalog.GetBodyName(body.bodyIndex) ?? ""));
				if (text.IndexOf("Heretic", StringComparison.OrdinalIgnoreCase) >= 0 || HasAllHeresies(inventory))
				{
					flag3 = true;
				}
				if (text == "MageBody")
				{
					flag4 = true;
				}
				if (text == "CrocoBody")
				{
					flag5 = true;
				}
				if (text.IndexOf("Chirr", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					flag6 = true;
				}
				if (text == "FalseSonBody")
				{
					flag7 = true;
				}
			}
		}
		int num = (flag3 ? 1 : 0) + (flag4 ? 1 : 0) + (flag5 ? 1 : 0) + (flag6 ? 1 : 0) + (flag7 ? 1 : 0);
		int num2 = (flag ? 1 : 0) + (flag2 ? 1 : 0);
		int num3 = num + num2;
		if (num >= 2)
		{
			color = "#D2F0F7";
		}
		else if (num == 1)
		{
			if (flag3)
			{
				color = "#7F9CFF";
			}
			else if (flag4)
			{
				color = "#A6E3FF";
			}
			else if (flag5)
			{
				color = "#E3EE6A";
			}
			else if (flag6)
			{
				color = "#F5A3D0";
			}
			else
			{
				color = "#FF8F8F";
			}
		}
		else if (num2 >= 2)
		{
			color = "#D2F0F7";
		}
		else if (flag2)
		{
			color = "#8CFFC1";
		}
		else
		{
			color = "#C9A6FF";
		}
		return num3 > 0;
	}

	private static bool HasAllHeresies(Inventory inv)
	{
		return Object.op_Implicit((Object)(object)inv) && inv.GetItemCountPermanent(Items.LunarPrimaryReplacement) > 0 && inv.GetItemCountPermanent(Items.LunarSecondaryReplacement) > 0 && inv.GetItemCountPermanent(Items.LunarUtilityReplacement) > 0 && inv.GetItemCountPermanent(Items.LunarSpecialReplacement) > 0;
	}

	private static int Pick(Line[] lines)
	{
		int num = Random.Range(0, lines.Length);
		if (lines.Length > 1 && lastPicked.TryGetValue(lines, out var value) && num == value)
		{
			num = (num + Random.Range(1, lines.Length)) % lines.Length;
		}
		lastPicked[lines] = num;
		return num;
	}

	internal static void Say(Line[] lines, float delay = 1.2f)
	{
		try
		{
			if (!Plugin.NewtSpeaks.Value || lines == null || lines.Length == 0 || !NetworkServer.active || !NewtEvents.IsBazaar())
			{
				return;
			}
			Line line = lines[Pick(lines)];
			if (delay <= 0f)
			{
				Send(line);
				return;
			}
			Plugin.Delay(delay, delegate
			{
				if (NetworkServer.active && NewtEvents.IsBazaar())
				{
					Send(line);
				}
			});
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}

	private static void Send(Line line)
	{
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Expected O, but got Unknown
		string color;
		string text = ((!AnyoneCanTranslate(out color)) ? ("<color=#C9DAFF><i><cspace=0.08em>" + Waver(line.Tongue) + "</cspace></i></color>") : ("<color=" + color + "><i>[" + line.English + "]</i></color>"));
		string baseToken = "<size=120%><color=#AFC8FF>Newt:</color> " + text + "</size>";
		Speaking = true;
		try
		{
			SimpleChatMessage val = new SimpleChatMessage();
			val.baseToken = baseToken;
			Chat.SendBroadcastChat((ChatMessageBase)(object)val);
			foreach (CharacterBody readOnlyInstances in CharacterBody.readOnlyInstancesList)
			{
				if (Object.op_Implicit((Object)(object)readOnlyInstances) && ((Object)readOnlyInstances).name.StartsWith("ShopkeeperBody", StringComparison.Ordinal))
				{
					NewtFxMessage.Send(((Component)readOnlyInstances).gameObject, 1);
					break;
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
		finally
		{
			Speaking = false;
		}
	}

	private static string Waver(string line)
	{
		StringBuilder stringBuilder = new StringBuilder();
		int num = 0;
		foreach (char c in line)
		{
			if (char.IsLetter(c))
			{
				float num2 = ((num % 3 == 0) ? 0.06f : ((num % 3 != 1) ? 0f : (-0.04f)));
				num++;
				if (num2 != 0f)
				{
					stringBuilder.Append("<voffset=").Append(num2.ToString(CultureInfo.InvariantCulture)).Append("em>")
						.Append(c)
						.Append("</voffset>");
					continue;
				}
			}
			stringBuilder.Append(c);
		}
		return stringBuilder.ToString();
	}
}
internal static class NewtEvents
{
	[CompilerGenerated]
	private static Dictionary<string, int> <>f__switch$map0;

	internal static void Init(Harmony harmony)
	{
		Stage.onServerStageBegin += delegate
		{
			KickPatch.kickedThisStage = false;
			Trade.ResetVisit();
		};
		try
		{
			Type type = AccessTools.TypeByName("EntityStates.LockedMage.UnlockingMage");
			EventInfo eventInfo = ((!(type != null)) ? null : type.GetEvent("onOpened", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
			if (eventInfo != null)
			{
				eventInfo.AddEventHandler(null, (Action<Interactor>)delegate
				{
					if (NetworkServer.active)
					{
						NewtVoice.Say(NewtVoice.Artificer, 2f);
					}
				});
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Artificer hook failed: " + ex));
		}
		SceneExitController.onBeginExit += OnBeginExit;
	}

	internal static bool IsBazaar()
	{
		SceneDef sceneDefForCurrentScene = SceneCatalog.GetSceneDefForCurrentScene();
		return Object.op_Implicit((Object)(object)sceneDefForCurrentScene) && sceneDefForCurrentScene.cachedName == "bazaar";
	}

	private static bool FalseSonInLobby()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
		{
			CharacterBody val = ((!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance.master)) ? null : instance.master.GetBody());
			if (Object.op_Implicit((Object)(object)val) && BodyCatalog.GetBodyName(val.bodyIndex) == "FalseSonBody")
			{
				return true;
			}
		}
		return false;
	}

	private static void OnBeginExit(SceneExitController exit)
	{
		try
		{
			if (!NetworkServer.active || !Object.op_Implicit((Object)(object)exit) || !IsBazaar() || KickPatch.kickedThisStage)
			{
				return;
			}
			Transform val = ((Component)exit).transform;
			while (Object.op_Implicit((Object)(object)val))
			{
				if (((Object)val).name.IndexOf("Kick", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return;
				}
				val = val.parent;
			}
			string text = ((Object)((Component)exit).gameObject).name.ToLowerInvariant();
			string text2 = ((!Object.op_Implicit((Object)(object)exit.destinationScene)) ? "" : exit.destinationScene.cachedName);
			if (exit.useRunNextStageScene && Object.op_Implicit((Object)(object)Run.instance) && Object.op_Implicit((Object)(object)Run.instance.nextStageScene))
			{
				text2 = Run.instance.nextStageScene.cachedName;
			}
			string text3 = ((!text.Contains("goldshores") && !(text2 == "goldshores")) ? ((!text.Contains("arena") && !(text2 == "arena")) ? ((!text.Contains("voidstage") && !(text2 == "voidstage") && !text.Contains("deepvoid")) ? ((!text.Contains("trial") && !text.Contains("hallow") && !text.Contains("gong")) ? text2 : "hallowed") : "voidstage") : "arena") : "goldshores");
			Line[] array = null;
			if (text3 != null)
			{
				if (<>f__switch$map0 == null)
				{
					Dictionary<string, int> dictionary = new Dictionary<string, int>(10);
					dictionary.Add("hallowed", 0);
					dictionary.Add("goldshores", 1);
					dictionary.Add("arena", 2);
					dictionary.Add("voidstage", 3);
					dictionary.Add("lemuriantemple", 4);
					dictionary.Add("habitat", 5);
					dictionary.Add("habitatfall", 6);
					dictionary.Add("meridian", 7);
					dictionary.Add("moon", 8);
					dictionary.Add("moon2", 8);
					<>f__switch$map0 = dictionary;
				}
				if (<>f__switch$map0.TryGetValue(text3, out var value))
				{
					switch (value)
					{
					case 0:
						break;
					case 1:
						goto IL_02a7;
					case 2:
						goto IL_02b3;
					case 3:
						goto IL_02bf;
					case 4:
						goto IL_02cb;
					case 5:
						goto IL_02d7;
					case 6:
						goto IL_02e3;
					case 7:
						goto IL_02ef;
					case 8:
						goto IL_030f;
					default:
						goto IL_031b;
					}
					array = NewtVoice.Hallowed;
					goto IL_0327;
				}
			}
			goto IL_031b;
			IL_02cb:
			array = NewtVoice.Altar;
			goto IL_0327;
			IL_02d7:
			array = NewtVoice.Colony;
			goto IL_0327;
			IL_02ef:
			array = ((!FalseSonInLobby()) ? NewtVoice.Meridian : NewtVoice.MeridianParadox);
			goto IL_0327;
			IL_02a7:
			array = NewtVoice.Gilded;
			goto IL_0327;
			IL_02e3:
			array = NewtVoice.Dieback;
			goto IL_0327;
			IL_031b:
			array = NewtVoice.Farewell;
			goto IL_0327;
			IL_0327:
			if (array != null)
			{
				NewtVoice.Say(array, 0f);
			}
			return;
			IL_030f:
			array = NewtVoice.Commencement;
			goto IL_0327;
			IL_02b3:
			array = NewtVoice.VoidFields;
			goto IL_0327;
			IL_02bf:
			array = NewtVoice.VoidLocus;
			goto IL_0327;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}
}
[HarmonyPatch(typeof(SpawnState), "OnEnter")]
internal static class GreetPatch
{
	private static void Postfix()
	{
		if (NetworkServer.active)
		{
			NewtVoice.Say((!ChefCompat.ChefHere()) ? NewtVoice.Greet : NewtVoice.Chef, 1.5f);
		}
	}
}
[HarmonyPatch(typeof(KickFromShop), "OnEnter")]
internal static class KickPatch
{
	internal static bool quietOnce;

	internal static bool kickedThisStage;

	private static void Postfix()
	{
		if (NetworkServer.active)
		{
			kickedThisStage = true;
			if (quietOnce)
			{
				quietOnce = false;
			}
			else
			{
				NewtVoice.Say(NewtVoice.Kick, 0.5f);
			}
		}
	}
}
internal static class Unkillable
{
	private static BodyIndex newtIndex = (BodyIndex)(-1);

	internal static bool IsNewt(HealthComponent hc)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Invalid comparison between Unknown and I4
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.UnkillableNewt.Value || !Object.op_Implicit((Object)(object)hc) || !Object.op_Implicit((Object)(object)hc.body))
		{
			return false;
		}
		if ((int)newtIndex == -1)
		{
			newtIndex = BodyCatalog.FindBodyIndex("ShopkeeperBody");
		}
		return hc.body.bodyIndex == newtIndex;
	}
}
[HarmonyPatch(typeof(HealthComponent), "set_Networkhealth")]
internal static class NewtHealthFloorPatch
{
	private static void Prefix(HealthComponent __instance, ref float value)
	{
		if (value < 1f && NetworkServer.active && Unkillable.IsNewt(__instance))
		{
			value = 1f;
		}
	}
}
[HarmonyPatch]
internal static class NewtSuicidePatch
{
	private static IEnumerable<MethodBase> TargetMethods()
	{
		MethodInfo[] methods = typeof(HealthComponent).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		foreach (MethodInfo m in methods)
		{
			if ((m.Name == "Suicide" || m.Name == "TrueKill" || m.Name == "Die") && m.DeclaringType == typeof(HealthComponent))
			{
				yield return m;
			}
		}
	}

	private static bool Prefix(HealthComponent __instance)
	{
		return !Unkillable.IsNewt(__instance);
	}
}
[HarmonyPatch(typeof(PurchaseInteraction), "OnInteractionBegin")]
internal static class CauldronPatch
{
	private static float nextAllowed;

	private static float nextBud;

	private static void Prefix(PurchaseInteraction __instance, Interactor __0)
	{
		try
		{
			if (!NetworkServer.active || !Object.op_Implicit((Object)(object)__instance) || !Object.op_Implicit((Object)(object)__0))
			{
				return;
			}
			string name = ((Object)((Component)__instance).gameObject).name;
			if (ConstructorCompat.manager != null && Object.op_Implicit((Object)(object)((Component)__instance).GetComponent(ConstructorCompat.manager)) && __instance.CanBeAffordedByInteractor(__0))
			{
				ConstructorCompat.OnUse();
			}
			else if (name.IndexOf("LunarShopTerminal", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				if (__instance.available && __instance.CanBeAffordedByInteractor(__0) && !(Time.time < nextBud))
				{
					nextBud = Time.time + 8f;
					NewtVoice.Say(NewtVoice.Bud, 0.8f);
				}
			}
			else if (name.IndexOf("LunarCauldron", StringComparison.OrdinalIgnoreCase) >= 0 && __instance.CanBeAffordedByInteractor(__0) && !(Time.time < nextAllowed))
			{
				Line[] array = null;
				if (name.IndexOf("WhiteToGreen", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					array = NewtVoice.CauldronWhite;
				}
				else if (name.IndexOf("GreenToRed", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					array = NewtVoice.CauldronGreen;
				}
				if (array != null)
				{
					nextAllowed = Time.time + 8f;
					NewtVoice.Say(array, 0.8f);
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}
}
internal static class ConstructorCompat
{
	internal static Type manager;

	private static bool inAccident;

	private static bool granted;

	private static float lastAccident = -100f;

	private static float nextAllowed;

	internal static void Init(Harmony harmony)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		//IL_0064: Expected O, but got Unknown
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Expected O, but got Unknown
		manager = AccessTools.TypeByName("LunarConstructor.ConstructorManager");
		if (manager == null)
		{
			return;
		}
		try
		{
			harmony.Patch((MethodBase)AccessTools.Method(manager, "DoAccident", (Type[])null, (Type[])null), new HarmonyMethod(typeof(ConstructorCompat), "AccidentPrefix", (Type[])null), new HarmonyMethod(typeof(ConstructorCompat), "AccidentPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo = AccessTools.Method(manager, "AttemptGrantPickupDirectly", (Type[])null, (Type[])null);
			HarmonyMethod val = new HarmonyMethod(typeof(ConstructorCompat), "GrantPostfix", (Type[])null);
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Plugin.Log.LogInfo((object)"Lunar Constructor found: Newt will comment on it.");
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Lunar Constructor hook failed: " + ex));
		}
	}

	private static void AccidentPrefix()
	{
		inAccident = true;
		granted = false;
		lastAccident = Time.time;
	}

	private static void AccidentPostfix()
	{
		if (inAccident && !granted)
		{
			NewtVoice.Say(NewtVoice.ConstructorNone, 1f);
		}
		inAccident = false;
	}

	private static void GrantPostfix(UniquePickup __0)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (inAccident && !granted)
			{
				granted = true;
				PickupDef pickupDef = PickupCatalog.GetPickupDef(__0.pickupIndex);
				Run instance = Run.instance;
				Line[] lines = ((__0.decayValue > 0f) ? NewtVoice.ConstructorTemp : ((pickupDef != null && pickupDef.isLunar) ? NewtVoice.ConstructorLunar : ((!Object.op_Implicit((Object)(object)instance) || instance.availableHexTierDropList == null || !instance.availableHexTierDropList.Contains(__0.pickupIndex)) ? NewtVoice.ConstructorVoid : NewtVoice.ConstructorHex)));
				NewtVoice.Say(lines, 1f);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}

	internal static void OnUse()
	{
		if (Time.time < nextAllowed)
		{
			return;
		}
		nextAllowed = Time.time + 8f;
		float used = Time.time;
		Plugin.Delay(1.2f, delegate
		{
			if (lastAccident < used - 0.1f)
			{
				NewtVoice.Say(NewtVoice.ConstructorUse, 0f);
			}
		});
	}
}
[HarmonyPatch(typeof(EquipmentSlot), "FireBossHunter")]
internal static class TricornPatch
{
	private static bool Prefix(EquipmentSlot __instance, ref bool __result)
	{
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Expected O, but got Unknown
		try
		{
			if (!NetworkServer.active || !Object.op_Implicit((Object)(object)__instance) || !NewtEvents.IsBazaar())
			{
				return true;
			}
			GameObject val = TricornAim.AimedNewt(__instance);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return true;
			}
			NewtVoice.Say(NewtVoice.TricornLaugh, 0.3f);
			Spend(__instance);
			HealthComponent val2 = ((!Object.op_Implicit((Object)(object)__instance.characterBody)) ? null : __instance.characterBody.healthComponent);
			if (Object.op_Implicit((Object)(object)val2) && val2.alive)
			{
				val2.Networkshield = 0f;
				val2.Networkhealth = 1f;
			}
			EntityStateMachine val3 = EntityStateMachine.FindByCustomName(val, "Body");
			if (Object.op_Implicit((Object)(object)val3) && !(val3.state is KickFromShop))
			{
				KickPatch.quietOnce = true;
				val3.SetNextState((EntityState)new KickFromShop());
			}
			__result = true;
			return false;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
			return true;
		}
	}

	private static void Spend(EquipmentSlot slot)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		CharacterBody characterBody = slot.characterBody;
		if (!Object.op_Implicit((Object)(object)characterBody) || !Object.op_Implicit((Object)(object)characterBody.inventory))
		{
			return;
		}
		EquipmentIndex equipmentIndex = Equipment.BossHunterConsumed.equipmentIndex;
		try
		{
			CharacterMasterNotificationQueue.SendTransformNotification(characterBody.master, characterBody.inventory.currentEquipmentIndex, equipmentIndex, (TransformationType)0);
		}
		catch
		{
		}
		Type nestedType = typeof(EquipmentSlot).GetNestedType("FireEquipmentResult", BindingFlags.Public | BindingFlags.NonPublic);
		MethodInfo methodInfo = AccessTools.Method(typeof(EquipmentSlot), "SetFireEquipmentResult", (Type[])null, (Type[])null);
		if (nestedType != null && methodInfo != null)
		{
			object obj2 = Activator.CreateInstance(nestedType);
			FieldInfo fieldInfo = AccessTools.Field(nestedType, "equipmentIndexToTransformInto");
			if (fieldInfo != null)
			{
				fieldInfo.SetValue(obj2, new EquipmentIndex?(equipmentIndex));
			}
			methodInfo.Invoke(slot, new object[1] { obj2 });
		}
		else
		{
			characterBody.inventory.SetEquipmentIndex(equipmentIndex);
		}
		MethodInfo methodInfo2 = AccessTools.Method(typeof(EquipmentSlot), "InvalidateCurrentTarget", (Type[])null, (Type[])null);
		if (methodInfo2 != null)
		{
			methodInfo2.Invoke(slot, null);
		}
	}
}
[HarmonyPatch(typeof(EquipmentSlot), "UpdateTargets")]
internal static class TricornAim
{
	private static readonly FieldInfo currentTarget = AccessTools.Field(typeof(EquipmentSlot), "currentTarget");

	private static readonly FieldInfo indicator = AccessTools.Field(typeof(EquipmentSlot), "targetIndicator");

	private static GameObject prefab;

	private static bool prefabTried;

	private static readonly Dictionary<CharacterBody, Transform> fingers = new Dictionary<CharacterBody, Transform>();

	private static bool Prefix(EquipmentSlot __instance, EquipmentIndex __0)
	{
		//IL_000b: 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)
		try
		{
			if (!Object.op_Implicit((Object)(object)__instance) || __0 != Equipment.BossHunter.equipmentIndex || !NewtEvents.IsBazaar())
			{
				return true;
			}
			CharacterBody val = InCone(__instance);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return true;
			}
			HurtBox val2 = WeakPoint(val) ?? val.mainHurtBox;
			if (!Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val.hurtBoxGroup) && val.hurtBoxGroup.hurtBoxes != null && val.hurtBoxGroup.hurtBoxes.Length > 0)
			{
				val2 = val.hurtBoxGroup.hurtBoxes[0];
			}
			if (Object.op_Implicit((Object)(object)val2))
			{
				currentTarget.SetValue(__instance, Activator.CreateInstance(currentTarget.FieldType, val2));
			}
			Indicator val3 = (Indicator)((!(indicator != null)) ? null : /*isinst with value type is only supported in some contexts*/);
			GameObject val4 = IndicatorPrefab();
			if (val3 != null && Object.op_Implicit((Object)(object)val4))
			{
				Transform val5 = Finger(val);
				if ((Object)(object)val3.visualizerPrefab != (Object)(object)val4)
				{
					val3.visualizerPrefab = val4;
				}
				if ((Object)(object)val3.targetTransform != (Object)(object)val5)
				{
					val3.targetTransform = val5;
				}
				if (!val3.active)
				{
					val3.active = true;
				}
			}
			return false;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
			return true;
		}
	}

	private static GameObject IndicatorPrefab()
	{
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)prefab) || prefabTried)
		{
			return prefab;
		}
		prefabTried = true;
		try
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				Type type = assembly.GetType("LegacyResourcesAPI") ?? assembly.GetType("RoR2.LegacyResourcesAPI");
				if (type == null)
				{
					continue;
				}
				MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.Name == "Load" && methodInfo.IsGenericMethodDefinition && methodInfo.GetParameters().Length == 1)
					{
						object? obj = methodInfo.MakeGenericMethod(typeof(GameObject)).Invoke(null, new object[1] { "Prefabs/BossHunterIndicator" });
						prefab = (GameObject)((obj is GameObject) ? obj : null);
						break;
					}
				}
				if (Object.op_Implicit((Object)(object)prefab))
				{
					break;
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Tricorn reticle (legacy): " + ex.Message));
		}
		if (!Object.op_Implicit((Object)(object)prefab))
		{
			try
			{
				prefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC1/BossHunter/BossHunterIndicator.prefab").WaitForCompletion();
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogWarning((object)("Tricorn reticle (addressables): " + ex2.Message));
			}
		}
		return prefab;
	}

	internal static HurtBox WeakPoint(CharacterBody newt)
	{
		HurtBoxGroup val = newt.hurtBoxGroup;
		if (!Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)newt.modelLocator) && Object.op_Implicit((Object)(object)newt.modelLocator.modelTransform))
		{
			val = ((Component)newt.modelLocator.modelTransform).GetComponent<HurtBoxGroup>();
		}
		if (Object.op_Implicit((Object)(object)val) && val.hurtBoxes != null)
		{
			HurtBox[] hurtBoxes = val.hurtBoxes;
			foreach (HurtBox val2 in hurtBoxes)
			{
				if (Object.op_Implicit((Object)(object)val2) && val2.isSniperTarget)
				{
					return val2;
				}
			}
		}
		return null;
	}

	private static Transform Finger(CharacterBody newt)
	{
		if (fingers.TryGetValue(newt, out var value) && Object.op_Implicit((Object)(object)value))
		{
			return value;
		}
		HurtBox val = WeakPoint(newt);
		value = ((!Object.op_Implicit((Object)(object)val)) ? null : ((Component)val).transform);
		Transform val2 = ((!Object.op_Implicit((Object)(object)newt.modelLocator)) ? null : newt.modelLocator.modelTransform);
		if (Object.op_Implicit((Object)(object)val2) && !Object.op_Implicit((Object)(object)value))
		{
			string[] array = new string[4] { "finger2.3.r_end", "finger1.3.r_end", "finger2.3.r", "hand.r" };
			foreach (string text in array)
			{
				Transform[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Transform>(true);
				foreach (Transform val3 in componentsInChildren)
				{
					if (((Object)val3).name == text)
					{
						value = val3;
						break;
					}
				}
				if (Object.op_Implicit((Object)(object)value))
				{
					break;
				}
			}
		}
		if (!Object.op_Implicit((Object)(object)value))
		{
			value = ((!Object.op_Implicit((Object)(object)newt.mainHurtBox)) ? ((Component)newt).transform : ((Component)newt.mainHurtBox).transform);
		}
		fingers[newt] = value;
		return value;
	}

	private static HurtBox CurrentHurtBox(EquipmentSlot slot)
	{
		try
		{
			return Traverse.Create((object)slot).Field("currentTarget").Field("hurtBox")
				.GetValue<HurtBox>();
		}
		catch
		{
			return null;
		}
	}

	private static CharacterBody InCone(EquipmentSlot slot)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//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_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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)
		CharacterBody characterBody = slot.characterBody;
		if (!Object.op_Implicit((Object)(object)characterBody) || !Object.op_Implicit((Object)(object)characterBody.inputBank))
		{
			return null;
		}
		Ray aimRay = characterBody.inputBank.GetAimRay();
		foreach (CharacterBody readOnlyInstances in CharacterBody.readOnlyInstancesList)
		{
			if (Object.op_Implicit((Object)(object)readOnlyInstances) && IsNewt(readOnlyInstances))
			{
				Vector3 val = readOnlyInstances.corePosition - ((Ray)(ref aimRay)).origin;
				Vector3 val2 = Finger(readOnlyInstances).position - ((Ray)(ref aimRay)).origin;
				float num = Mathf.Min(Vector3.Angle(((Ray)(ref aimRay)).direction, val), Vector3.Angle(((Ray)(ref aimRay)).direction, val2));
				if (((Vector3)(ref val)).magnitude < 250f && num < 15f)
				{
					return readOnlyInstances;
				}
			}
		}
		return null;
	}

	internal static GameObject AimedNewt(EquipmentSlot slot)
	{
		HurtBox val = CurrentHurtBox(slot);
		if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.healthComponent) && Object.op_Implicit((Object)(object)val.healthComponent.body) && IsNewt(val.healthComponent.body))
		{
			return ((Component)val.healthComponent).gameObject;
		}
		CharacterBody val2 = InCone(slot);
		return (!Object.op_Implicit((Object)(object)val2)) ? null : ((Component)val2).gameObject;
	}

	private static bool IsNewt(CharacterBody b)
	{
		return ((Object)b).name.StartsWith("ShopkeeperBody", StringComparison.Ordinal);
	}
}
[HarmonyPatch(typeof(HealthComponent), "TakeDamageProcess")]
internal static class VoidReflectPatch
{
	internal const string DeathToken = "NEWTSBARGAIN_DEATH_QUOTE";

	internal static HealthComponent shielding;

	internal static readonly HashSet<GameObject> reflected = new HashSet<GameObject>();

	private static readonly Dictionary<GameObject, float> warned = new Dictionary<GameObject, float>();

	private static readonly Dictionary<GameObject, float> tickled = new Dictionary<GameObject, float>();

	private static bool Prefix(HealthComponent __instance, DamageInfo __0)
	{
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Expected O, but got Unknown
		try
		{
			if (!NetworkServer.active || __0 == null || !Object.op_Implicit((Object)(object)__instance) || !Object.op_Implicit((Object)(object)__instance.body))
			{
				return true;
			}
			if (!((Object)__instance.body).name.StartsWith("ShopkeeperBody", StringComparison.Ordinal))
			{
				return true;
			}
			CharacterBody val = ((!Object.op_Implicit((Object)(object)__0.attacker)) ? null : __0.attacker.GetComponent<CharacterBody>());
			bool flag = Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.inventory) && val.inventory.GetItemCountEffective(Items.CritGlassesVoid) > 0;
			if (Object.op_Implicit((Object)(object)val) && (!flag || !Plugin.VoidReflect.Value))
			{
				Tickled(((Component)val).gameObject);
			}
			if (!Plugin.VoidReflect.Value)
			{
				return true;
			}
			shielding = __instance;
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.inventory) || !Object.op_Implicit((Object)(object)val.healthComponent) || !val.healthComponent.alive)
			{
				return true;
			}
			int itemCountEffective = val.inventory.GetItemCountEffective(Items.CritGlassesVoid);
			if (itemCountEffective <= 0)
			{
				return true;
			}
			if (!Util.CheckRoll((float)itemCountEffective * 0.5f * __0.procCoefficient, val.master))
			{
				if (!warned.TryGetValue(((Component)val).gameObject, out var value) || Time.time >= value)
				{
					warned[((Component)val).gameObject] = Time.time + 12f;
					NewtVoice.Say(NewtVoice.LensWarning, 0f);
				}
				return true;
			}
			reflected.Add(((Component)val).gameObject);
			if (Object.op_Implicit((Object)(object)val.master))
			{
				reflected.Add(((Component)val.master).gameObject);
			}
			GameObject gameObject = ((Component)__instance).gameObject;
			val.healthComponent.Suicide(gameObject, gameObject, new DamageTypeCombo(DamageTypeCombo.op_Implicit((DamageType)65536), (DamageTypeExtended)0, (DamageSource)0));
			KickPatch.quietOnce = true;
			NewtVoice.Say(NewtVoice.VoidLost, 0.8f);
			EntityStateMachine val2 = EntityStateMachine.FindByCustomName(gameObject, "Body");
			if (Object.op_Implicit((Object)(object)val2) && !(val2.state is KickFromShop))
			{
				val2.SetNextState((EntityState)new KickFromShop());
			}
			return false;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
			return true;
		}
	}

	private static void Tickled(GameObject attacker)
	{
		if (!KickPatch.kickedThisStage && (!tickled.TryGetValue(attacker, out var value) || !(Time.time < value)))
		{
			tickled[attacker] = Time.time + 12f;
			NewtVoice.Say(NewtVoice.Tickle, 0.2f);
		}
	}

	private static void Postfix()
	{
		shielding = null;
	}

	private static Exception Finalizer(Exception __exception)
	{
		shielding = null;
		return __exception;
	}
}
[HarmonyPatch(typeof(CharacterBody), "get_isBoss")]
internal static class BossShieldPatch
{
	private static void Postfix(CharacterBody __instance, ref bool __result)
	{
		if ((Object)(object)VoidReflectPatch.shielding != (Object)null && !__result && (Object)(object)VoidReflectPatch.shielding.body == (Object)(object)__instance)
		{
			__result = true;
		}
	}
}
[HarmonyPatch(typeof(GlobalEventManager), "OnPlayerCharacterDeath")]
internal static class VoidReflectDeathPatch
{
	internal static bool active;

	private static void Prefix(DamageReport __0)
	{
		active = __0 != null && Object.op_Implicit((Object)(object)__0.victimBody) && (VoidReflectPatch.reflected.Contains(((Component)__0.victimBody).gameObject) || (Object.op_Implicit((Object)(object)__0.victimMaster) && VoidReflectPatch.reflected.Contains(((Component)__0.victimMaster).gameObject)));
	}

	private static void Postfix(DamageReport __0, NetworkUser __1)
	{
		try
		{
			if (active)
			{
				if (Object.op_Implicit((Object)(object)__1) && Object.op_Implicit((Object)(object)__1.masterController))
				{
					__1.masterController.finalMessageTokenServer = "NEWTSBARGAIN_DEATH_QUOTE";
				}
				if (Object.op_Implicit((Object)(object)__0.victimBody))
				{
					VoidReflectPatch.reflected.Remove(((Component)__0.victimBody).gameObject);
				}
				if (Object.op_Implicit((Object)(object)__0.victimMaster))
				{
					VoidReflectPatch.reflected.Remove(((Component)__0.victimMaster).gameObject);
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
		finally
		{
			active = false;
		}
	}
}