Decompiled source of LightProxy CCM v1.0.0

LightProxy_CCM.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Bounce.Singletons;
using HarmonyLib;
using ModdingTales;
using Newtonsoft.Json;
using UnityEngine;

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

[BepInPlugin("org.lordashes.proxy.light.ccm", "Light Proxy", "1.0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class LightProxy : BaseUnityPlugin
{
	public static class Provider
	{
		public class LightMenu
		{
			public string iconName { get; set; } = "Light.png";


			public string menuNode { get; set; } = "";


			public string menuLink { get; set; } = "";

		}

		public class LightSpecs
		{
			public string name { get; set; } = "Light";


			public LightMenu menu { get; set; } = new LightMenu();

		}

		public static IEnumerator GetLightAssets(ReadOnlyDictionary<string, AssetInfo> existingAssets, Func<Dictionary<string, AssetInfo>, IEnumerator> callback)
		{
			Dictionary<string, AssetInfo> assets = new Dictionary<string, AssetInfo>();
			yield return (object)new WaitForEndOfFrame();
			string cacheFolder = Paths.PluginPath + "/.cache/org.lordashes.plugins.commoncustomsmenu";
			string json = File.ReadAllText("LightSpecs.json", (CacheType)999);
			LoggingPlugin.LogInfo(json);
			List<LightSpecs> specs = JsonConvert.DeserializeObject<List<LightSpecs>>(json);
			_self.notification = "Registering... [Provider: Light]";
			if (!existingAssets.ContainsKey("Light.General.None"))
			{
				assets.Add("Light.General.None", new AssetInfo
				{
					provider = "LIGHT",
					pack = "Lights",
					prefab = "Light.General.None",
					filename = "None",
					name = "None",
					kind = "AURA",
					category = "Light",
					header = "Lights Plugin",
					groupName = "General"
				});
				byte[] portrait2 = ImageConversion.EncodeToPNG(Image.LoadTexture("None", (CacheType)999));
				File.WriteAllBytes(cacheFolder + "/Portrait.Light.General.None.png", portrait2, (CacheType)999);
			}
			foreach (LightSpecs spec in specs)
			{
				spec.menu.menuNode = ((spec.menu.menuNode == "") ? "General" : spec.menu.menuNode);
				if (!existingAssets.ContainsKey("Light." + spec.menu.menuNode + "." + spec.name))
				{
					_self.notification = "Registering... [Provider: Light, Group: " + spec.menu.menuNode + ", Item: " + spec.name + "]";
					assets.Add("Light." + spec.menu.menuNode + "." + spec.name, new AssetInfo
					{
						provider = "LIGHT",
						pack = "Lights",
						prefab = "Light." + spec.menu.menuNode + "." + spec.name,
						filename = spec.name,
						name = spec.name,
						kind = "AURA",
						category = "Light",
						header = "Lights Plugin",
						groupName = spec.menu.menuNode
					});
					byte[] portrait = ImageConversion.EncodeToPNG(Image.LoadTexture("/" + spec.menu.iconName, (CacheType)999));
					File.WriteAllBytes(cacheFolder + "/Portrait.Light." + spec.menu.menuNode + "." + spec.name + ".png", portrait, (CacheType)999);
				}
			}
			_self.notification = null;
			((MonoBehaviour)_self).StartCoroutine(callback((from kvp in assets
				orderby kvp.Value.header, kvp.Value.category, kvp.Value.name
				select kvp).ToDictionary((KeyValuePair<string, AssetInfo> kvp) => kvp.Key, (KeyValuePair<string, AssetInfo> kvp) => kvp.Value)));
		}

		public static void LightRequest(AssetInfo assetInfo)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			CommonCustomsMenuPlugin._self.Close();
			CreatureBoardAsset val = null;
			CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref val);
			if ((Object)(object)val != (Object)null)
			{
				LoggingPlugin.LogInfo(JsonConvert.SerializeObject((object)assetInfo));
				string[] obj = new string[9] { "Adding Light '", assetInfo.name, "' (", assetInfo.groupName, ") To Asset ", val.Name, " (", null, null };
				CreatureGuid val2 = val.CreatureId;
				obj[7] = ((object)(CreatureGuid)(ref val2)).ToString();
				obj[8] = ")";
				LoggingPlugin.LogInfo(string.Concat(obj));
				val2 = LocalClient.SelectedCreatureId;
				AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref val2)).ToString(), "org.lordashes.plugins.light", assetInfo.filename, false);
			}
			else
			{
				SystemMessage.DisplayInfoText("Light Requires A Selected Asset", 2.5f, 0f);
			}
		}
	}

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

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

		public static GameObject FindInHierarchy(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: true, ref results, ref done);
			return (results.Count > 0) ? results.ElementAt(0) : null;
		}

		public static GameObject FindInHierarchyViaPartialName(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: true, ref results, ref done, partial: true);
			return (results.Count > 0) ? results.ElementAt(0) : null;
		}

		public static GameObject[] FindAllInHierarchy(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: false, ref results, ref done);
			return results.ToArray();
		}

		public static GameObject[] FindAllInHierarchyViaPartialName(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: false, ref results, ref done, partial: true);
			return results.ToArray();
		}

		public static GameObject FindWithComponentInHierarchy(GameObject start, string seekType)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, null, seekType, single: true, ref results, ref done);
			return (results.Count > 0) ? results.ElementAt(0) : null;
		}

		public static GameObject[] FindAllWithComponentInHierarchy<T>(GameObject start, string seekType)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, null, seekType, single: false, ref results, ref done);
			return results.ToArray();
		}

		public static void Traverse(Transform root, string seekName, string seekType, bool single, ref List<GameObject> results, ref bool done, bool partial = false)
		{
			try
			{
				if ((seekName == null || seekName == ((Object)((Component)root).gameObject).name || (partial && ((Object)((Component)root).gameObject).name.Contains(seekName))) && (seekType == null || (Object)(object)((Component)root).GetComponent(seekType) != (Object)null))
				{
					LoggingPlugin.LogTrace("Matched '" + ((Object)((Component)root).gameObject).name + "'");
					results.Add(((Component)root).gameObject);
					if (single)
					{
						done = true;
						return;
					}
				}
				foreach (Transform item in ExtensionMethods.Children(root))
				{
					if (!done)
					{
						Traverse(item, seekName, seekType, single, ref results, ref done, partial);
					}
				}
			}
			catch
			{
			}
		}

		public static object LookUp(in Dictionary<string, object> dictionary, string key)
		{
			foreach (KeyValuePair<string, object> item in dictionary)
			{
				if (item.Key.ToUpper() == key.ToUpper())
				{
					return item.Value;
				}
			}
			return null;
		}

		public static void PostOnMainPage(BaseUnityPlugin plugin)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			string text = "Lord Ashes" + ("Lord Ashes".ToUpper().EndsWith("S") ? "'" : "'s");
			ModdingUtils.Initialize(plugin, new ManualLogSource("Light Proxy"), text, false);
		}
	}

	public const string Name = "Light Proxy";

	public const string Guid = "org.lordashes.proxy.light.ccm";

	public const string Version = "1.0.0.0";

	public const string Author = "Lord Ashes";

	public static LightProxy _self;

	private string notification = null;

	private Rect registrationMessagePos = Rect.zero;

	private GUIStyle registrationMessageStyle = new GUIStyle();

	private void Awake()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Invalid comparison between Unknown and I4
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: 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_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Expected O, but got Unknown
		_self = this;
		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();
		Debug.Log((object)(assemblyQualifiedName + ": Active. (Diagnostic Mode = " + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + ")"));
		if ((int)LoggingPlugin.GetLogLevel() >= 4)
		{
			((MonoBehaviour)this).StartCoroutine(WarnAboutLogLevel());
		}
		string text = CommonCustomsMenuPlugin.RegisterProviderV2("LIGHT", "Light sources", "1.0.0.0", (Func<ReadOnlyDictionary<string, AssetInfo>, Func<Dictionary<string, AssetInfo>, IEnumerator>, IEnumerator>)Provider.GetLightAssets, (Action<AssetInfo>)delegate(AssetInfo selectedAsset)
		{
			Provider.LightRequest(selectedAsset);
		});
		string[] array = text.Split(new char[1] { ',' });
		registrationMessagePos = new Rect((float)int.Parse(array[0]), (float)int.Parse(array[1]), (float)(Screen.width - int.Parse(array[0])), (float)(Screen.height - int.Parse(array[1])));
		registrationMessageStyle.fontSize = int.Parse(array[2]);
		registrationMessageStyle.fontStyle = (FontStyle)1;
		registrationMessageStyle.active.textColor = Color.white;
		registrationMessageStyle.normal.textColor = Color.white;
		Harmony val = new Harmony("org.lordashes.proxy.light.ccm");
		val.PatchAll();
		Utility.PostOnMainPage((BaseUnityPlugin)(object)this);
	}

	private void OnGUI()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		if (notification != null)
		{
			GUI.Label(registrationMessagePos, notification, registrationMessageStyle);
		}
	}

	private IEnumerator WarnAboutLogLevel()
	{
		while (true)
		{
			try
			{
				DiagnosticLevel logLevel = LoggingPlugin.GetLogLevel();
				SystemMessage.DisplayInfoText("Light Proxy: Using '" + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + "' diagnostics.\r\nUse 'Info' for better performance", 10f, 0f);
				SystemMessage.DisplayInfoText("Light Proxy: Use 'Debug' or 'Trace' for\r\ntroubleshooting only.", 10f, 0f);
				break;
			}
			catch
			{
			}
			yield return (object)new WaitForSeconds(1f);
		}
	}
}