Decompiled source of NewtDialogueRestoration v1.0.0

NewtDialogueRestoration.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates.NewtMonster;
using Microsoft.CodeAnalysis;
using On.EntityStates.NewtMonster;
using On.RoR2;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("NewtDialogueRestoration")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+44e61db89f9fe4898e92ea2b8fb7910a87febb30")]
[assembly: AssemblyProduct("NewtDialogueRestoration")]
[assembly: AssemblyTitle("NewtDialogueRestoration")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace NewtDialogueRestoration
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

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

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

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

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

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

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInPlugin("SSM24.NewtDialogueRestoration", "NewtDialogueRestoration", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class NewtDialogueRestoration : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_CommentOnLunarPurchase <>9__8_0;

			internal void <Awake>b__8_0(orig_CommentOnLunarPurchase _, BazaarController _)
			{
			}
		}

		public const string PluginGUID = "SSM24.NewtDialogueRestoration";

		public const string PluginAuthor = "SSM24";

		public const string PluginName = "NewtDialogueRestoration";

		public const string PluginVersion = "1.0.0";

		public static ConfigEntry<float> PurchaseDialogueChance;

		public static ConfigEntry<float> AnnoyDialogueChance;

		public static ConfigEntry<float> UpgradeDialogueOnRerollChance;

		public static ConfigEntry<float> UpgradeDialogueOnCauldronChance;

		private static int lastRolledIndex;

		public void Awake()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Expected O, but got Unknown
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			Log.Init(((BaseUnityPlugin)this).Logger);
			PurchaseDialogueChance = ((BaseUnityPlugin)this).Config.Bind<float>("Chances", "Purchase Dialogue", 50f, "Chance for dialogue on purchasing a lunar item");
			AnnoyDialogueChance = ((BaseUnityPlugin)this).Config.Bind<float>("Chances", "Annoy Dialogue", 100f, "Chance for dialogue on getting kicked out of the shop");
			UpgradeDialogueOnRerollChance = ((BaseUnityPlugin)this).Config.Bind<float>("Chances", "Upgrade Dialogue On Reroll", 0f, "Chance for \"upgrade\" dialogue on rerolling lunar items");
			UpgradeDialogueOnCauldronChance = ((BaseUnityPlugin)this).Config.Bind<float>("Chances", "Upgrade Dialogue On Cauldron", 0f, "Chance for \"upgrade\" dialogue on using a cauldron");
			ModSettingsManager.AddOption((BaseOption)new SliderOption(PurchaseDialogueChance));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(AnnoyDialogueChance));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(UpgradeDialogueOnRerollChance));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(UpgradeDialogueOnCauldronChance));
			try
			{
				using Stream stream = File.OpenRead(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "icon.png"));
				Texture2D val = new Texture2D(0, 0);
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, (int)stream.Length);
				if (ImageConversion.LoadImage(val, array))
				{
					ModSettingsManager.SetModIcon(Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0f, 0f)));
				}
			}
			catch (FileNotFoundException)
			{
			}
			KickFromShop.OnEnter += new hook_OnEnter(On_KickFromShop_OnEnter);
			PurchaseInteraction.OnInteractionBegin += new hook_OnInteractionBegin(On_PurchaseInteraction_OnInteractionBegin);
			object obj = <>c.<>9__8_0;
			if (obj == null)
			{
				hook_CommentOnLunarPurchase val2 = delegate
				{
				};
				<>c.<>9__8_0 = val2;
				obj = (object)val2;
			}
			BazaarController.CommentOnLunarPurchase += (hook_CommentOnLunarPurchase)obj;
		}

		private void On_KickFromShop_OnEnter(orig_OnEnter orig, KickFromShop self)
		{
			orig.Invoke(self);
			SendNewtMessage("NEWT_ANNOY", 6, AnnoyDialogueChance.Value);
		}

		private void On_PurchaseInteraction_OnInteractionBegin(orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator)
		{
			orig.Invoke(self, activator);
			if (Object.op_Implicit((Object)(object)BazaarController.instance))
			{
				string name = ((Object)((Component)self).gameObject).name;
				if (name.StartsWith("LunarShopTerminal"))
				{
					SendNewtMessage("NEWT_LUNAR_PURCHASE", 8, PurchaseDialogueChance.Value);
				}
				else if (name.StartsWith("LunarRecycler"))
				{
					SendNewtMessage("NEWT_UPGRADE", 3, UpgradeDialogueOnRerollChance.Value);
				}
				else if (name.StartsWith("LunarCauldron"))
				{
					SendNewtMessage("NEWT_UPGRADE", 3, UpgradeDialogueOnCauldronChance.Value);
				}
			}
		}

		private static void SendNewtMessage(string token, int tokenCount, float percentChance)
		{
			//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_007b: Expected O, but got Unknown
			if (!NetworkServer.active)
			{
				return;
			}
			CharacterBody val = FindNewtBody();
			if (Object.op_Implicit((Object)(object)val) && Util.CheckRoll(percentChance, 0f, (CharacterMaster)null))
			{
				int num;
				do
				{
					num = Random.Range(1, tokenCount);
				}
				while (num == lastRolledIndex);
				lastRolledIndex = num;
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = string.Format(CultureInfo.InvariantCulture, "<color=#b0e5ff><size=120%>{0}: {1}</color></size>", Util.GetBestBodyName(((Component)val).gameObject), Language.GetString(token + "_" + num))
				});
				Util.PlaySound("Play_UI_chatMessage", ((Component)RoR2Application.instance).gameObject);
			}
		}

		private static CharacterBody FindNewtBody()
		{
			foreach (TeamComponent teamMember in TeamComponent.GetTeamMembers((TeamIndex)0))
			{
				if (((Object)teamMember).name.StartsWith("ShopkeeperBody"))
				{
					return teamMember.body;
				}
			}
			return null;
		}
	}
}