Decompiled source of GravityPlugin v1.1.0

GravityPlugin.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
using HarmonyLib;
using RadialUI;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("GravityPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GravityPlugin")]
[assembly: AssemblyCopyright("GravityPlugin ©  2024")]
[assembly: AssemblyTrademark("GravityPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.gravity", "Gravity Plug-In", "1.1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class GravityPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(CreatureBoardAsset), "DropCommon")]
	public static class PatchesCreatureBoardAssetPickup
	{
		public static bool Prefix(ref CreatureBoardAsset __instance, Vector3 dropDestination, float height)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if (!suspendedAssets.Contains(__instance.CreatureId))
			{
				Debug.Log((object)("Gravity Plugin: Dropping Asset " + Utility.GetCreatureName(__instance.Name)));
				return true;
			}
			Debug.Log((object)("Gravity Plugin: Suspending Asset " + Utility.GetCreatureName(__instance.Name)));
			return false;
		}
	}

	public static class Utility
	{
		public static bool isBoardLoaded()
		{
			return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
		}

		public static Guid GuidFromString(string input)
		{
			using MD5 mD = MD5.Create();
			byte[] b = mD.ComputeHash(Encoding.Default.GetBytes(input));
			return new Guid(b);
		}

		public static GameObject GetBaseLoader(CreatureGuid cid)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				CreatureBoardAsset val = null;
				CreaturePresenter.TryGetAsset(cid, ref val);
				if ((Object)(object)val != (Object)null)
				{
					Transform match = null;
					Traverse(((Component)val).transform, "BaseLoader", 0, 10, ref match);
					if ((Object)(object)match != (Object)null)
					{
						return ((Component)match.GetChild(0)).gameObject;
					}
					LoggingPlugin.LogWarning("Could Not Find Base Loader");
					return null;
				}
				return null;
			}
			catch
			{
				return null;
			}
		}

		public static GameObject GetAssetLoader(CreatureGuid cid)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				CreatureBoardAsset val = null;
				CreaturePresenter.TryGetAsset(cid, ref val);
				if ((Object)(object)val != (Object)null)
				{
					Transform match = null;
					Traverse(((Component)val).transform, "AssetLoader", 0, 10, ref match);
					if ((Object)(object)match != (Object)null)
					{
						return ((Component)match.GetChild(0)).gameObject;
					}
					Debug.LogWarning((object)"Could Not Find Asset Loader");
					return null;
				}
				return null;
			}
			catch
			{
				return null;
			}
		}

		public static Transform GetChildTransform(CreatureGuid cid, string childName, int depth = 10)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				CreatureBoardAsset val = null;
				CreaturePresenter.TryGetAsset(cid, ref val);
				if ((Object)(object)val != (Object)null)
				{
					Transform match = null;
					Traverse(((Component)val).transform, childName, 0, depth, ref match);
					if ((Object)(object)match != (Object)null)
					{
						return match;
					}
					Debug.LogWarning((object)("Could Not Find " + childName));
					return null;
				}
				return null;
			}
			catch
			{
				return null;
			}
		}

		public static void Traverse(Transform root, string seek, int depth, int depthMax, ref Transform match)
		{
			try
			{
				if ((Object)(object)match != (Object)null)
				{
					return;
				}
				if (((Object)root).name == seek)
				{
					match = root;
					return;
				}
				foreach (Transform item in ExtensionMethods.Children(root))
				{
					if (depth < depthMax)
					{
						Traverse(item, seek, depth + 1, depthMax, ref match);
					}
				}
			}
			catch
			{
			}
		}

		public static float ParseFloat(string value)
		{
			return float.Parse(value, CultureInfo.InvariantCulture);
		}

		public static string GetCreatureName(string nameBlock)
		{
			if (nameBlock == null)
			{
				return "(Unknown)";
			}
			if (!nameBlock.Contains("<size=0>"))
			{
				return nameBlock;
			}
			return nameBlock.Substring(0, nameBlock.IndexOf("<size=0>")).Trim();
		}

		public static void PostOnMainPage(MemberInfo plugin)
		{
			SceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode)
			{
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Expected O, but got Unknown
				try
				{
					if (((Scene)(ref scene)).name == "UI")
					{
						TextMeshProUGUI uITextByName = GetUITextByName("BETA");
						if (Object.op_Implicit((Object)(object)uITextByName))
						{
							((TMP_Text)uITextByName).text = "INJECTED BUILD - unstable mods";
						}
					}
					else
					{
						TextMeshProUGUI uITextByName2 = GetUITextByName("TextMeshPro Text");
						if (Object.op_Implicit((Object)(object)uITextByName2))
						{
							BepInPlugin val = (BepInPlugin)Attribute.GetCustomAttribute(plugin, typeof(BepInPlugin));
							if (((TMP_Text)uITextByName2).text.EndsWith("</size>"))
							{
								((TMP_Text)uITextByName2).text = ((TMP_Text)uITextByName2).text + "\n\nMods Currently Installed:\n";
							}
							TextMeshProUGUI val2 = uITextByName2;
							((TMP_Text)val2).text = ((TMP_Text)val2).text + "\nPlugin Masters' " + val.Name + " - " + val.Version;
						}
					}
				}
				catch (Exception ex)
				{
					Debug.Log((object)ex);
				}
			};
		}

		private static TextMeshProUGUI GetUITextByName(string name)
		{
			TextMeshProUGUI[] array = Object.FindObjectsOfType<TextMeshProUGUI>();
			for (int i = 0; i < array.Length; i++)
			{
				if (((Object)array[i]).name == name)
				{
					return array[i];
				}
			}
			return null;
		}
	}

	public const string Name = "Gravity Plug-In";

	public const string Guid = "org.lordashes.plugins.gravity";

	public const string Version = "1.1.0.0";

	public static List<CreatureGuid> suspendedAssets = new List<CreatureGuid>();

	private void Awake()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected O, but got Unknown
		LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Diagnostic Level", (DiagnosticLevel)3, (ConfigDescription)null).Value);
		string? assemblyQualifiedName = ((object)this).GetType().AssemblyQualifiedName;
		DiagnosticLevel logLevel = LoggingPlugin.GetLogLevel();
		LoggingPlugin.LogInfo(assemblyQualifiedName + ": Active. (Diagnostic Mode = " + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + ")");
		AssetDataPlugin.Subscribe("org.lordashes.plugins.gravity", (Action<DatumChange>)RequestHandler, (Func<DatumChange, bool>)Checker.CheckSourceAsCreature);
		Harmony val = new Harmony("org.lordashes.plugins.gravity");
		val.PatchAll();
		RadialSubmenu.EnsureMainMenuItem("org.lordashes.plugins.gravity.Gravity", (MenuType)1, "Gravity", Image.LoadSprite("org.lordashes.plugins.gravity.Gravity", (CacheType)999));
		RadialSubmenu.CreateSubMenuItem("org.lordashes.plugins.gravity.Gravity", "Remove", Image.LoadSprite("org.lordashes.plugins.gravity.Gravity.Remove", (CacheType)999), (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid c, string k, MapMenuItem m)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//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)
			GravityCallback(c, new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()), "Remove");
		}, true, (Func<bool>)(() => true));
		RadialSubmenu.CreateSubMenuItem("org.lordashes.plugins.gravity.Gravity", "Apply", Image.LoadSprite("org.lordashes.plugins.gravity.Gravity.Remove", (CacheType)999), (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid c, string k, MapMenuItem m)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//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)
			GravityCallback(c, new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()), "Apply");
		}, true, (Func<bool>)(() => true));
		Utility.PostOnMainPage(((object)this).GetType());
	}

	private void GravityCallback(CreatureGuid rcid, CreatureGuid cid, string option)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		CreatureBoardAsset val = null;
		CreaturePresenter.TryGetAsset(cid, ref val);
		if (option == "Remove")
		{
			LoggingPlugin.LogInfo("Requesting Removal Of Gravity From " + Utility.GetCreatureName(val.Name) + " (" + ((object)(CreatureGuid)(ref cid)).ToString() + ")");
			AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref cid)).ToString(), "org.lordashes.plugins.gravity", (object)DateTime.UtcNow, false);
		}
		else if (option == "Apply")
		{
			LoggingPlugin.LogInfo("Requesting Application Of Gravity To " + Utility.GetCreatureName(val.Name) + " (" + ((object)(CreatureGuid)(ref cid)).ToString() + ")");
			AssetDataPlugin.ClearInfo(((object)(CreatureGuid)(ref cid)).ToString(), "org.lordashes.plugins.gravity", false);
		}
		else
		{
			LoggingPlugin.LogInfo("Unfamiliar With Gravity Request " + option);
		}
	}

	private void RequestHandler(DatumChange datum)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Invalid comparison between Unknown and I4
		//IL_00e6: 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)
		string[] obj = new string[6] { "Request Received ", datum.source, " ", null, null, null };
		ChangeAction action = datum.action;
		obj[3] = ((object)(ChangeAction)(ref action)).ToString();
		obj[4] = " ";
		obj[5] = datum.value?.ToString();
		LoggingPlugin.LogDebug(string.Concat(obj));
		CreatureBoardAsset val = null;
		CreaturePresenter.TryGetAsset(new CreatureGuid(datum.source), ref val);
		if ((Object)(object)val != (Object)null)
		{
			if ((int)datum.action == 1)
			{
				LoggingPlugin.LogTrace("Applying Gravity To " + Utility.GetCreatureName(val.Name));
				suspendedAssets.Remove(val.CreatureId);
				val.DropAtCurrentLocation();
			}
			else
			{
				LoggingPlugin.LogTrace("Removing Gravity From " + Utility.GetCreatureName(val.Name));
				suspendedAssets.Add(val.CreatureId);
			}
		}
		else
		{
			LoggingPlugin.LogTrace("Could Not Find Asset " + datum.source);
		}
	}
}