Decompiled source of ZUIExampleMod v1.1.0

ZUIExampleMod.dll

Decompiled 2 weeks 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, submenus, and custom windows.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+089edb29d88f29cffd47c1ce016456dd8e4dab61")]
[assembly: AssemblyProduct("ZUIExampleMod")]
[assembly: AssemblyTitle("ZUIExampleMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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.1.0";
	}
	[BepInPlugin("com.yourname.zuiexample", "ZUI Example Mod", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private static Type _zui;

		public static ManualLogSource LogInstance { get; private set; }

		public override void Load()
		{
			LogInstance = ((BasePlugin)this).Log;
			((BasePlugin)this).Log.LogInfo((object)"Loading Example Mod...");
			if (InitZUI())
			{
				CreateSimpleUI();
				CreateCustomUI();
			}
		}

		private bool InitZUI()
		{
			if (!((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("Zanakinz.ZUI"))
			{
				return false;
			}
			_zui = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "ZUI")?.GetType("ZUI.API.ZUI");
			return _zui != null;
		}

		private void Call(string name, params object[] args)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			if (_zui == null)
			{
				return;
			}
			MethodInfo methodInfo = _zui.GetMethods(BindingFlags.Static | BindingFlags.Public).FirstOrDefault((MethodInfo m) => m.Name == name && m.GetParameters().Length == args.Length);
			if (methodInfo != null)
			{
				methodInfo.Invoke(null, args);
				return;
			}
			ManualLogSource logInstance = LogInstance;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(46, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not find ZUI method '");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(name);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' with ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(args.Length);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" parameters.");
			}
			logInstance.LogError(val);
		}

		private void CreateSimpleUI()
		{
			Call("SetPlugin", "ZUI Example");
			Call("SetTargetWindow", "Main");
			Call("AddCategory", "Simple Stuff");
			Call("AddButton", "Hello World", ".say Hello");
			Call("AddButton", "Kill Self", ".kill");
		}

		private void CreateCustomUI()
		{
			Call("SetPlugin", "YourPluginName");
			Call("SetTargetWindow", "YourWindowName");
			Call("SetUI", 500, 350);
			Call("HideTitleBar");
			Call("SetTitle", "<color=#B30000>ZUIExampleMod</color>");
			Call("AddText", "<color=#61c200>You can create your own custom UI</color>", 15f, 210f);
			Call("AddText", "<color=#61c200>with relative ease using this!</color>", 15f, 230f);
			Call("AddButton", "Test", ".ignorethis", 320f, 220f);
			Call("AddCategory", "<color=#ffd700>README:</color>", 15f, 190f);
			Call("AddCategory", "<color=#ffd700>COMMANDS:</color>", 315f, 190f);
			Call("AddImage", "CHANGENAME.png", 20f, 40f, 460f, 150f);
			Call("AddButton", "Long", ".ignorethis", 20f, 280f, 460f, 20f);
		}
	}
}