Decompiled source of ZUIExampleMod v1.0.0

ZUIExampleMod.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("YourName")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Example mod demonstrating ZUI API usage with buttons and submenus (ZUI optional)")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ZUIExampleMod")]
[assembly: AssemblyTitle("ZUIExampleMod")]
[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 ZUIExampleMod
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.yourname.zuiexample";

		public const string PLUGIN_NAME = "ZUI Example Mod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("com.yourname.zuiexample", "ZUI Example Mod", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public static ManualLogSource LogInstance { get; private set; }

		public override void Load()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			LogInstance = ((BasePlugin)this).Log;
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(23, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("com.yourname.zuiexample");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loading...");
			}
			log.LogInfo(val);
			if (IsZUIAvailable())
			{
				((BasePlugin)this).Log.LogInfo((object)"? ZUI detected! Registering categories and buttons...");
				RegisterWithZUI();
			}
			else
			{
				((BasePlugin)this).Log.LogWarning((object)"? ZUI not found. This is a UI showcase mod - ZUI is required.");
			}
			ManualLogSource log2 = ((BasePlugin)this).Log;
			val = new BepInExInfoLogInterpolatedStringHandler(28, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("com.yourname.zuiexample");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded successfully!");
			}
			log2.LogInfo(val);
		}

		private bool IsZUIAvailable()
		{
			try
			{
				return ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("Zanakinz.ZUI");
			}
			catch
			{
				return false;
			}
		}

		private void RegisterWithZUI()
		{
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Expected O, but got Unknown
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "ZUI");
				if (assembly == null)
				{
					LogInstance.LogError((object)"Could not find ZUI assembly");
					return;
				}
				Type type = assembly.GetType("ZUI.API.ZUI");
				if (type == null)
				{
					LogInstance.LogError((object)"Could not find ZUI.API.ZUI type");
					return;
				}
				MethodInfo method = type.GetMethod("SetPlugin", BindingFlags.Static | BindingFlags.Public);
				MethodInfo method2 = type.GetMethod("AddCategory", BindingFlags.Static | BindingFlags.Public);
				MethodInfo method3 = type.GetMethod("AddButton", BindingFlags.Static | BindingFlags.Public);
				if (method == null || method2 == null || method3 == null)
				{
					LogInstance.LogError((object)"Could not find ZUI API methods");
					ManualLogSource logInstance = LogInstance;
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(39, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("SetPlugin: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(method != null);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", AddCategory: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(method2 != null);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", AddButton: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(method3 != null);
					}
					logInstance.LogError(val);
				}
				else
				{
					method.Invoke(null, new object[1] { "ZUIExample" });
					method2.Invoke(null, new object[1] { "Example" });
					method3.Invoke(null, new object[3] { "Test", ".ignorethis", "" });
					method2.Invoke(null, new object[1] { "Example2" });
					method3.Invoke(null, new object[3] { "Example", ".ignorethis", "" });
					LogInstance.LogInfo((object)"Registered with ZUI successfully!");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logInstance2 = LogInstance;
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(29, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to register with ZUI: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				logInstance2.LogError(val);
				ManualLogSource logInstance3 = LogInstance;
				val = new BepInExErrorLogInterpolatedStringHandler(13, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Stack trace: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.StackTrace);
				}
				logInstance3.LogError(val);
			}
		}
	}
}