Decompiled source of BodyAuraPlugin v2.1.0

BodyAuraPlugin.dll

Decompiled a year ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
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("BodyAuraPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BodyAuraPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("BodyAuraPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("2.1.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.bodyaura", "Body Aura Plug-In", "2.1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BodyAuraPlugin : BaseUnityPlugin
{
	public static class Utility
	{
		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 + "\nLord Ashes' " + val.Name + " - " + val.Version;
						}
					}
				}
				catch (Exception ex)
				{
					Debug.Log((object)ex);
				}
			};
		}

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

		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)
					{
						if (match.childCount > 0)
						{
							return ((Component)match.GetChild(0)).gameObject;
						}
						return null;
					}
					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
			{
			}
		}

		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 enum BoardState
	{
		boardNotReady,
		boardDelayForMiniBuild,
		boardReady
	}

	public const string Name = "Body Aura Plug-In";

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

	public const string Version = "2.1.0.0";

	public const string Author = "Lord Ashes";

	public string data = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

	public const float baseMagicNumber = 0.570697f;

	private ConfigEntry<KeyboardShortcut> triggerKey { get; set; }

	private ConfigEntry<KeyboardShortcut> triggerReapplyKey { get; set; }

	private ConfigEntry<float> displacement { get; set; }

	private ConfigEntry<bool> displacementMultiplier { get; set; }

	private void Awake()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		Debug.Log((object)"Body Aura Plugin: Active.");
		triggerKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Extract Mesh", new KeyboardShortcut((KeyCode)98, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), (ConfigDescription)null);
		triggerReapplyKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Reapply Body Auras", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)305 }), (ConfigDescription)null);
		displacement = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Aura Displacement", 0.01f, (ConfigDescription)null);
		displacementMultiplier = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Use Aura Displacement Size Multiplier", true, (ConfigDescription)null);
		AssetDataPlugin.Subscribe("org.lordashes.plugins.bodyaura", (Action<DatumChange>)RequestHandler, (Func<DatumChange, bool>)Checker.CheckSourceAsCreature);
		Utility.PostOnMainPage(((object)this).GetType());
	}

	private void Update()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Expected O, but got Unknown
		if (!Utility.isBoardLoaded())
		{
			return;
		}
		KeyboardShortcut value = triggerKey.Value;
		if (((KeyboardShortcut)(ref value)).IsUp())
		{
			CreatureBoardAsset asset = default(CreatureBoardAsset);
			CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref asset);
			if ((Object)(object)asset != (Object)null)
			{
				SystemMessage.AskForTextInput("Aura Texture", "Aura Texture Name", "OK", (Action<string>)delegate(string texName)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					CreatureGuid creatureId3 = asset.CreatureId;
					AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref creatureId3)).ToString(), "org.lordashes.plugins.bodyaura", texName, false);
				}, (Action)null, "Remove", (Action)delegate
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					CreatureGuid creatureId2 = asset.CreatureId;
					AssetDataPlugin.ClearInfo(((object)(CreatureGuid)(ref creatureId2)).ToString(), "org.lordashes.plugins.bodyaura", false);
				}, "");
			}
		}
		value = triggerReapplyKey.Value;
		if (!((KeyboardShortcut)(ref value)).IsUp())
		{
			return;
		}
		Debug.Log((object)"Body Aura Plugin: Reapplying Body Auras");
		foreach (CreatureBoardAsset item in (IEnumerable<CreatureBoardAsset>)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets())
		{
			CreatureGuid creatureId = item.CreatureId;
			string text = AssetDataPlugin.ReadInfo(((object)(CreatureGuid)(ref creatureId)).ToString(), "org.lordashes.plugins.bodyaura");
			if (text != null && text != "")
			{
				DatumChange val = new DatumChange
				{
					action = (ChangeAction)3
				};
				creatureId = item.CreatureId;
				val.source = ((object)(CreatureGuid)(ref creatureId)).ToString();
				val.key = "org.lordashes.plugins.bodyaura";
				val.previous = "";
				val.value = text;
				RequestHandler(val);
			}
		}
	}

	private void RequestHandler(DatumChange change)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Invalid comparison between Unknown and I4
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Invalid comparison between Unknown and I4
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Invalid comparison between Unknown and I4
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		ChangeAction val = (ChangeAction)((change.value.ToString() == "" && (int)change.action != 1) ? 1 : ((int)change.action));
		ChangeAction val2 = val;
		ChangeAction val3 = val2;
		if ((int)val3 == 1)
		{
			if ((Object)(object)GameObject.Find(change.source + ".BodyAura") != (Object)null)
			{
				Object.Destroy((Object)(object)GameObject.Find(change.source + ".BodyAura"));
			}
			return;
		}
		CreatureBoardAsset val4 = null;
		CreaturePresenter.TryGetAsset(new CreatureGuid(change.source), ref val4);
		if ((Object)(object)val4 != (Object)null)
		{
			((MonoBehaviour)this).StartCoroutine("BuildBodyAura", (object)new object[2] { change.value, val4 });
		}
	}

	private IEnumerator BuildBodyAura(object[] inputs)
	{
		yield return (object)new WaitForSeconds(0.1f);
		string texName = (string)inputs[0];
		CreatureBoardAsset asset = (CreatureBoardAsset)inputs[1];
		Debug.Log((object)"Body Aura Plugin: Getting Shader");
		AssetBundle assetBundle = AssetBundle.Load(data + "/siStandardAura", (CacheType)999);
		Shader shader = assetBundle.LoadAsset<Shader>("siStandardAura");
		assetBundle.Unload(false);
		Debug.Log((object)"Body Aura Plugin: Creating Aura Object");
		CreatureGuid creatureId = asset.CreatureId;
		if ((Object)(object)GameObject.Find(((object)(CreatureGuid)(ref creatureId)).ToString() + ".BodyAura") != (Object)null)
		{
			creatureId = asset.CreatureId;
			Object.Destroy((Object)(object)GameObject.Find(((object)(CreatureGuid)(ref creatureId)).ToString() + ".BodyAura"));
		}
		GameObject aura = new GameObject();
		GameObject go = Utility.GetAssetLoader(asset.CreatureId);
		creatureId = asset.CreatureId;
		((Object)aura).name = ((object)(CreatureGuid)(ref creatureId)).ToString() + ".BodyAura";
		aura.transform.localScale = go.transform.localScale * (asset.ScaledBaseRadius / 0.570697f);
		aura.transform.position = go.transform.position;
		aura.transform.eulerAngles = go.transform.eulerAngles;
		aura.transform.SetParent(go.transform);
		Debug.Log((object)"Body Aura Plugin: Creating Aura MeshFilter");
		MeshFilter srcMeshFilter = go.GetComponent<MeshFilter>();
		MeshFilter dstMeshFilter = aura.AddComponent<MeshFilter>();
		Renderer srcRenderer;
		Renderer dstRenderer;
		if ((Object)(object)go.GetComponent<MeshRenderer>() != (Object)null)
		{
			Debug.Log((object)"Body Aura Plugin: Creating Aura MeshRenderer");
			srcRenderer = (Renderer)(object)go.GetComponent<MeshRenderer>();
			dstRenderer = (Renderer)(object)aura.AddComponent<MeshRenderer>();
		}
		else
		{
			Debug.Log((object)"Body Aura Plugin: Creating Aura SkinnedMeshRenderer");
			srcRenderer = (Renderer)(object)go.GetComponent<SkinnedMeshRenderer>();
			dstRenderer = (Renderer)(object)aura.AddComponent<MeshRenderer>();
		}
		if ((Object)(object)srcMeshFilter != (Object)null && (Object)(object)dstMeshFilter != (Object)null && (Object)(object)srcMeshFilter.mesh != (Object)null)
		{
			Debug.Log((object)"Body Aura Plugin: Aplying Mesh");
			dstMeshFilter.mesh = srcMeshFilter.mesh;
		}
		if ((Object)(object)srcRenderer != (Object)null && (Object)(object)dstRenderer != (Object)null)
		{
			float distance = displacement.Value;
			Debug.Log((object)("Body Aura Plugin: Distance = " + distance + ", Scale Multiplier = " + displacementMultiplier.Value + ", Scale = " + go.transform.localScale.y));
			if (displacementMultiplier.Value && go.transform.localScale.y < 1f)
			{
				distance *= 1f / go.transform.localScale.y;
				Debug.Log((object)("Body Aura Plugin: Adjusted Distance = " + distance));
			}
			Debug.Log((object)"Body Aura Plugin: Applying Material");
			dstRenderer.material = srcRenderer.material;
			Debug.Log((object)("Body Aura Plugin: Applying Shader " + ((Object)shader).name));
			dstRenderer.material.shader = shader;
			Debug.Log((object)("Body Aura Plugin: Verifying Shader " + ((Object)dstRenderer.material.shader).name));
			Debug.Log((object)"Body Aura Plugin: Applying Dispalcement");
			dstRenderer.material.SetFloat("_Float0", distance);
			Debug.Log((object)("Body Aura Plugin: Applying Texture " + texName));
			dstRenderer.material.mainTexture = (Texture)(object)Image.LoadTexture("Images/" + texName, (CacheType)999);
		}
	}
}