Decompiled source of NewtPressed v1.0.0

NewtPressed.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.UI;
using RoR2;
using RoR2.UI;
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("NewtPressed")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NewtPressed")]
[assembly: AssemblyTitle("NewtPressed")]
[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 NewtPressed
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

		private static string Format(object data, string file, int line)
		{
			string fileName = Path.GetFileName(file);
			return $"[{fileName}:{line}] {data}";
		}

		internal static void Debug(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogDebug((object)Format(data, file, line));
		}

		internal static void Error(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogError((object)Format(data, file, line));
		}

		internal static void Fatal(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogFatal((object)Format(data, file, line));
		}

		internal static void Info(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogInfo((object)Format(data, file, line));
		}

		internal static void Message(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogMessage((object)Format(data, file, line));
		}

		internal static void Warning(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogWarning((object)Format(data, file, line));
		}
	}
	[BepInPlugin("Leiv.NewtPressed", "NewtPressed", "1.0.0")]
	public class NewtPressed : BaseUnityPlugin
	{
		public const string PluginAuthor = "Leiv";

		public const string PluginName = "NewtPressed";

		public const string PluginGUID = "Leiv.NewtPressed";

		public const string PluginVersion = "1.0.0";

		private GameObject newtPressedPanel = null;

		public static PluginInfo PInfo;

		public void Awake()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			PInfo = ((BaseUnityPlugin)this).Info;
			Asset.Init();
			HUD.Awake += new hook_Awake(Hook_HUD_Awake);
			Chat.AddMessage_ChatMessageBase += new hook_AddMessage_ChatMessageBase(Hook_Chat_AddMessage);
			Stage.Start += new hook_Start(Hook_Stage_Start);
			Log.Init(((BaseUnityPlugin)this).Logger);
		}

		private void OnDestroy()
		{
			//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
			HUD.Awake -= new hook_Awake(Hook_HUD_Awake);
			Chat.AddMessage_ChatMessageBase -= new hook_AddMessage_ChatMessageBase(Hook_Chat_AddMessage);
			Stage.Start -= new hook_Start(Hook_Stage_Start);
		}

		private void Hook_HUD_Awake(orig_Awake orig, HUD self)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_004d: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			newtPressedPanel = new GameObject("NewtAltarNotificationUI");
			newtPressedPanel.transform.SetParent(self.mainContainer.transform, false);
			RectTransform val = newtPressedPanel.AddComponent<RectTransform>();
			val.anchorMin = new Vector2(0.03f, 0.9f);
			val.anchorMax = new Vector2(0.03f, 0.9f);
			val.pivot = new Vector2(0.5f, 0.5f);
			val.sizeDelta = new Vector2(60f, 60f);
			val.anchoredPosition = Vector2.zero;
			Image val2 = newtPressedPanel.AddComponent<Image>();
			if ((Object)(object)Asset.mainBundle != (Object)null)
			{
				Sprite val3 = Asset.mainBundle.LoadAsset<Sprite>("newtUI");
				if ((Object)(object)val3 != (Object)null)
				{
					val2.sprite = val3;
					val2.type = (Type)0;
					((Graphic)val2).color = new Color(1f, 1f, 1f, 0.6f);
					Log.Info("Sprite applied", "C:\\Users\\Leiv\\Desktop\\ExamplePlugin-main\\ExamplePlugin\\NewtPressed.cs", 65);
				}
			}
			else
			{
				Log.Error("Failed to load AssetBundle", "C:\\Users\\Leiv\\Desktop\\ExamplePlugin-main\\ExamplePlugin\\NewtPressed.cs", 70);
			}
			newtPressedPanel.SetActive(false);
			Log.Info("Hid UI element", "C:\\Users\\Leiv\\Desktop\\ExamplePlugin-main\\ExamplePlugin\\NewtPressed.cs", 74);
		}

		private void Hook_Chat_AddMessage(orig_AddMessage_ChatMessageBase orig, ChatMessageBase message)
		{
			orig.Invoke(message);
			string text = null;
			SimpleChatMessage val = (SimpleChatMessage)(object)((message is SimpleChatMessage) ? message : null);
			if (val != null)
			{
				text = val.baseToken;
			}
			else
			{
				SubjectFormatChatMessage val2 = (SubjectFormatChatMessage)(object)((message is SubjectFormatChatMessage) ? message : null);
				if (val2 != null)
				{
					text = ((SubjectChatMessage)val2).baseToken;
				}
			}
			if (text == "PORTAL_SHOP_WILL_OPEN")
			{
				Log.Info("Newt chat message found", "C:\\Users\\Leiv\\Desktop\\ExamplePlugin-main\\ExamplePlugin\\NewtPressed.cs", 87);
				if ((Object)(object)newtPressedPanel != (Object)null)
				{
					newtPressedPanel.SetActive(true);
					Log.Info("UI element shown", "C:\\Users\\Leiv\\Desktop\\ExamplePlugin-main\\ExamplePlugin\\NewtPressed.cs", 91);
				}
			}
		}

		private IEnumerator Hook_Stage_Start(orig_Start orig, Stage stage)
		{
			if ((Object)(object)newtPressedPanel != (Object)null)
			{
				newtPressedPanel.SetActive(false);
				Log.Info("Hid UI element", "C:\\Users\\Leiv\\Desktop\\ExamplePlugin-main\\ExamplePlugin\\NewtPressed.cs", 101);
			}
			return orig.Invoke(stage);
		}
	}
	public static class Asset
	{
		public static AssetBundle mainBundle;

		public const string bundleName = "newtpressed_assets";

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

		public static void Init()
		{
			mainBundle = AssetBundle.LoadFromFile(AssetBundlePath);
		}
	}
}