Decompiled source of LightProxy CCM v1.0.1

LightProxy_CCM.dll

Decompiled 2 months 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("1.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.proxy.light.ccm", "Light Proxy", "1.0.1.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();

		}

		[CompilerGenerated]
		private sealed class <GetLightAssets>d__0 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public ReadOnlyDictionary<string, AssetInfo> existingAssets;

			public Func<Dictionary<string, AssetInfo>, string, IEnumerator> callback;

			private Dictionary<string, AssetInfo> <assets>5__1;

			private string <cacheFolder>5__2;

			private string <json>5__3;

			private List<LightSpecs> <specs>5__4;

			private byte[] <portrait>5__5;

			private List<LightSpecs>.Enumerator <>s__6;

			private LightSpecs <spec>5__7;

			private byte[] <portrait>5__8;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <GetLightAssets>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<assets>5__1 = null;
				<cacheFolder>5__2 = null;
				<json>5__3 = null;
				<specs>5__4 = null;
				<portrait>5__5 = null;
				<>s__6 = default(List<LightSpecs>.Enumerator);
				<spec>5__7 = null;
				<portrait>5__8 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d3: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Unknown result type (might be due to invalid IL or missing references)
				//IL_010f: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0127: Unknown result type (might be due to invalid IL or missing references)
				//IL_0138: Expected O, but got Unknown
				//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0307: Unknown result type (might be due to invalid IL or missing references)
				//IL_0319: Unknown result type (might be due to invalid IL or missing references)
				//IL_0325: Unknown result type (might be due to invalid IL or missing references)
				//IL_0331: Unknown result type (might be due to invalid IL or missing references)
				//IL_033d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0359: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<assets>5__1 = new Dictionary<string, AssetInfo>();
					<>2__current = (object)new WaitForEndOfFrame();
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<cacheFolder>5__2 = Paths.PluginPath + "/.cache/org.lordashes.plugins.commoncustomsmenu";
					<json>5__3 = File.ReadAllText("LightSpecs.json", (CacheType)999);
					LoggingPlugin.LogInfo(<json>5__3);
					<specs>5__4 = JsonConvert.DeserializeObject<List<LightSpecs>>(<json>5__3);
					_self.notification = "Registering... [Provider: Light]";
					if (!existingAssets.ContainsKey("Light.General.None"))
					{
						<assets>5__1.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"
						});
						<portrait>5__5 = ImageConversion.EncodeToPNG(Image.LoadTexture("None", (CacheType)999));
						File.WriteAllBytes(<cacheFolder>5__2 + "/Portrait.Light.General.None.png", <portrait>5__5, (CacheType)999);
						<portrait>5__5 = null;
					}
					<>s__6 = <specs>5__4.GetEnumerator();
					try
					{
						while (<>s__6.MoveNext())
						{
							<spec>5__7 = <>s__6.Current;
							<spec>5__7.menu.menuNode = ((<spec>5__7.menu.menuNode == "") ? "General" : <spec>5__7.menu.menuNode);
							if (!existingAssets.ContainsKey("Light." + <spec>5__7.menu.menuNode + "." + <spec>5__7.name))
							{
								_self.notification = "Registering... [Provider: Light, Group: " + <spec>5__7.menu.menuNode + ", Item: " + <spec>5__7.name + "]";
								<assets>5__1.Add("Light." + <spec>5__7.menu.menuNode + "." + <spec>5__7.name, new AssetInfo
								{
									provider = "LIGHT",
									pack = "Lights",
									prefab = "Light." + <spec>5__7.menu.menuNode + "." + <spec>5__7.name,
									filename = <spec>5__7.name,
									name = <spec>5__7.name,
									kind = "AURA",
									category = "Light",
									header = "Lights Plugin",
									groupName = <spec>5__7.menu.menuNode
								});
								<portrait>5__8 = ImageConversion.EncodeToPNG(Image.LoadTexture("/" + <spec>5__7.menu.iconName, (CacheType)999));
								File.WriteAllBytes(<cacheFolder>5__2 + "/Portrait.Light." + <spec>5__7.menu.menuNode + "." + <spec>5__7.name + ".png", <portrait>5__8, (CacheType)999);
								<portrait>5__8 = null;
							}
							<spec>5__7 = null;
						}
					}
					finally
					{
						((IDisposable)<>s__6).Dispose();
					}
					<>s__6 = default(List<LightSpecs>.Enumerator);
					_self.notification = null;
					((MonoBehaviour)_self).StartCoroutine(callback((from kvp in <assets>5__1
						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), "Light"));
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[IteratorStateMachine(typeof(<GetLightAssets>d__0))]
		public static IEnumerator GetLightAssets(ReadOnlyDictionary<string, AssetInfo> existingAssets, Func<Dictionary<string, AssetInfo>, string, IEnumerator> callback)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GetLightAssets>d__0(0)
			{
				existingAssets = existingAssets,
				callback = callback
			};
		}

		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);
		}
	}

	[CompilerGenerated]
	private sealed class <WarnAboutLogLevel>d__12 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public LightProxy <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <WarnAboutLogLevel>d__12(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0029: 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)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			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);
			}
			catch
			{
				goto IL_0072;
			}
			return false;
			IL_0072:
			<>2__current = (object)new WaitForSeconds(1f);
			<>1__state = 1;
			return true;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	public const string Name = "Light Proxy";

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

	public const string Version = "1.0.1.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.1.0", (Func<ReadOnlyDictionary<string, AssetInfo>, Func<Dictionary<string, AssetInfo>, string, 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);
		}
	}

	[IteratorStateMachine(typeof(<WarnAboutLogLevel>d__12))]
	private IEnumerator WarnAboutLogLevel()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <WarnAboutLogLevel>d__12(0)
		{
			<>4__this = this
		};
	}
}