Decompiled source of InterfacePlugin v1.0.0

InterfacePlugin.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
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 System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
using Bounce.Unmanaged;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using WebSocketSharp;
using WebSocketSharp.Server;

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

[BepInPlugin("org.lordashes.plugins.interface", "Interface Plugin", "1.0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class InterfacePlugin : BaseUnityPlugin
{
	public static class Helpers
	{
		private class _CreatureStat
		{
			public float Value { get; set; }

			public float Max { get; set; }

			public CreatureStat toCreatureStat()
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				return new CreatureStat(Value, Max);
			}
		}

		private class ValueObject
		{
			public object Value { get; set; }
		}

		public static object ConvertJsonToType(Type typeName, string jsonValue)
		{
			//IL_008b: 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_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			if (typeName == typeof(Vector3))
			{
				LoggingPlugin.LogTrace("Converting Using Vector3 Custom Path");
				try
				{
					if (jsonValue.StartsWith("{"))
					{
						jsonValue = JsonConvert.DeserializeObject<string>(jsonValue).ToString();
					}
				}
				catch
				{
				}
				string[] array = jsonValue.Split(new char[1] { ',' });
				LoggingPlugin.LogTrace("Converting Content " + array.ToString());
				return (object)new Vector3(Utility.ParseFloat(array[0]), Utility.ParseFloat(array[1]), Utility.ParseFloat(array[2]));
			}
			if (typeName == typeof(Vector2))
			{
				LoggingPlugin.LogTrace("Converting Using Vector2 Custom Path");
				try
				{
					if (jsonValue.StartsWith("{"))
					{
						jsonValue = JsonConvert.DeserializeObject<string>(jsonValue).ToString();
					}
				}
				catch
				{
				}
				string[] array2 = jsonValue.Split(new char[1] { ',' });
				LoggingPlugin.LogTrace("Converting Content " + array2.ToString());
				return (object)new Vector2(Utility.ParseFloat(array2[0]), Utility.ParseFloat(array2[1]));
			}
			if (typeName == typeof(NGuid))
			{
				LoggingPlugin.LogTrace("Converting Using NGuid Custom Path");
				CreatureGuid val = default(CreatureGuid);
				try
				{
					if (jsonValue.StartsWith("{"))
					{
						jsonValue = JsonConvert.DeserializeObject<Guid>(jsonValue).ToString();
					}
				}
				catch
				{
				}
				try
				{
					if (jsonValue.StartsWith("{"))
					{
						jsonValue = JsonConvert.DeserializeObject<string>(jsonValue).ToString();
					}
				}
				catch
				{
				}
				LoggingPlugin.LogTrace("Converting Content " + jsonValue.ToString());
				((CreatureGuid)(ref val))..ctor(jsonValue);
				return val.Value;
			}
			if (typeName == typeof(CreatureStat))
			{
				LoggingPlugin.LogTrace("Converting Using CreatureStat Custom Path");
				_CreatureStat creatureStat = JsonConvert.DeserializeObject<_CreatureStat>(jsonValue);
				LoggingPlugin.LogTrace("Converting Content " + Convert.ToString(jsonValue));
				return JsonConvert.DeserializeObject<_CreatureStat>(jsonValue).toCreatureStat();
			}
			try
			{
				LoggingPlugin.LogTrace("Converting Using Deserialize Path");
				LoggingPlugin.LogTrace("Converting Content " + Convert.ToString(jsonValue));
				return JsonConvert.DeserializeObject(jsonValue, typeName);
			}
			catch
			{
				LoggingPlugin.LogTrace("Converting Using String Path");
				LoggingPlugin.LogTrace("Converting Content " + Convert.ToString(jsonValue));
				return jsonValue;
			}
		}

		public static object ConvertJsonToType(string typeName, string jsonValue)
		{
			return ConvertJsonToType(GetTypeByString(typeName), jsonValue);
		}

		public static Type GetTypeByString(string typeName)
		{
			if (typeName.Contains("+"))
			{
				string[] array = typeName.Split(new char[1] { '+' });
				LoggingPlugin.LogTrace("Converting 3rd party type " + array[1] + " from " + array[0]);
				Assembly assembly = Assembly.Load(array[0]);
				LoggingPlugin.LogTrace("Assembly " + array[0] + " loaded. Obtaining type " + array[1]);
				return assembly.GetType(array[1]);
			}
			LoggingPlugin.LogTrace(JsonConvert.SerializeObject((object)("Converting type " + typeName)));
			return Type.GetType(typeName, throwOnError: true, ignoreCase: true);
		}

		public static void BuildInvokeParameters(Type[] paramTypes, string[] paramJsonIn, ref object[] paramValues)
		{
			paramValues = new object[paramJsonIn.Length];
			for (int i = 0; i < paramTypes.Length; i++)
			{
				string[] array = (paramJsonIn[i] + ":").Split(new char[1] { ':' });
				if (references.ContainsKey(array[0]))
				{
					LoggingPlugin.LogTrace("Building type " + paramTypes[i]?.ToString() + " with stored value " + Convert.ToString(references[paramJsonIn[i]]));
					paramValues[i] = references[paramJsonIn[i]];
				}
				else
				{
					LoggingPlugin.LogTrace("Building type " + paramTypes[i]?.ToString() + " with value " + paramJsonIn[i]);
					paramValues[i] = ConvertJsonToType(paramTypes[i], paramJsonIn[i]);
				}
				if (paramValues[i] != null)
				{
					try
					{
						LoggingPlugin.LogTrace("Conversion Verify: " + paramValues[i].GetType().ToString() + " Value: " + JsonConvert.SerializeObject(paramValues[i]));
					}
					catch
					{
						LoggingPlugin.LogTrace("Conversion Verify: " + paramValues[i].GetType().ToString() + " Value: {Non-Serializable Value}");
					}
				}
				else
				{
					LoggingPlugin.LogTrace("Conversion Verify: " + typeof(string).ToString() + " Value: null");
				}
				switch (array[1].ToUpper())
				{
				case "T":
				case "TEXT":
					paramValues[i] = references[paramJsonIn[i]].ToString();
					break;
				case "J":
				case "JSON":
					paramValues[i] = JsonConvert.SerializeObject(references[paramJsonIn[i]]);
					break;
				case "V":
				case "VALUE":
					paramValues[i] = ((ValueObject)references[paramJsonIn[i]]).Value;
					break;
				case "TV":
				case "TVALUE":
					paramValues[i] = ((ValueObject)references[paramJsonIn[i]]).Value.ToString();
					break;
				}
			}
		}
	}

	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)
					{
						Debug.Log((object)("Interface Plugin: Base Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
						return ((Component)match.GetChild(0)).gameObject;
					}
					Debug.LogWarning((object)"Interface Plugin: 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)
					{
						Debug.Log((object)("Interface Plugin: Asset Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
						return ((Component)match.GetChild(0)).gameObject;
					}
					Debug.LogWarning((object)"Interface Plugin: Could Not Find Asset Loader");
					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 + "\nLordAshes' " + 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 class WebSocketService : WebSocketBehavior
	{
		protected override void OnMessage(MessageEventArgs e)
		{
			string text = ProcessMessage(JsonConvert.DeserializeObject<Request>(e.Data));
			if (text != null)
			{
				((WebSocketBehavior)this).Send(text);
			}
		}
	}

	private class Request
	{
		public string command { get; set; }

		public string source { get; set; }

		public string method { get; set; }

		public string[] paramJson { get; set; }
	}

	public const string Name = "Interface Plugin";

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

	public const string Version = "1.0.0.0";

	public const string Author = "LordAshes";

	private static WebSocketServer wsServer = null;

	private const string EOL = "\r\n";

	private static Dictionary<string, object> references = new Dictionary<string, object>();

	private void Awake()
	{
		//IL_0018: 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_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Diagnostic Level", (DiagnosticLevel)3, (ConfigDescription)null).Value);
		DiagnosticLevel logLevel = LoggingPlugin.GetLogLevel();
		Debug.Log((object)("Interface Plugin: Active. (Diagnostic Mode = " + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + ")"));
		LoggingPlugin.LogInfo(JsonConvert.SerializeObject((object)new CreatureStat(10f, 50f)));
		wsServer = new WebSocketServer(7070);
		wsServer.AddWebSocketService<WebSocketService>("/WebSocketService");
		wsServer.Log.Level = (LogLevel)0;
		wsServer.Start();
	}

	private static string ProcessMessage(Request request)
	{
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_034a: Unknown result type (might be due to invalid IL or missing references)
		//IL_034f: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0371: Unknown result type (might be due to invalid IL or missing references)
		//IL_0376: Unknown result type (might be due to invalid IL or missing references)
		//IL_0600: Unknown result type (might be due to invalid IL or missing references)
		//IL_0637: Unknown result type (might be due to invalid IL or missing references)
		//IL_0672: Unknown result type (might be due to invalid IL or missing references)
		LoggingPlugin.LogDebug("Processing Remote Request: " + JsonConvert.SerializeObject((object)request));
		string text = "";
		switch (request.command.ToUpper())
		{
		case "FIND":
		{
			CreatureGuid creatureId;
			switch (request.method.ToUpper())
			{
			case "INSTANCE":
			{
				Type type = Type.GetType(request.source);
				PropertyInfo property = type.GetProperty("Instance");
				if (property != null)
				{
					references.Add(request.paramJson[0], property.GetValue(null));
					text = property.GetValue(null).ToString() + "\r\n";
					LoggingPlugin.LogDebug("Found Instance Of Type " + request.source + ". Storing As " + request.paramJson[0]);
				}
				else
				{
					text = "No Found\r\n";
					LoggingPlugin.LogDebug("No Instance Of Type " + request.source + " Found.");
				}
				break;
			}
			case "ASSET":
				foreach (CreatureBoardAsset item in (IEnumerable<CreatureBoardAsset>)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets())
				{
					if (item.Name.ToUpper() == request.source.ToUpper())
					{
						references.Add(request.paramJson[0], item);
						creatureId = item.CreatureId;
						text = ((object)(CreatureGuid)(ref creatureId)).ToString() + "\r\n";
						string[] obj = new string[8] { "Found Asset ", item.Name, " (", null, null, null, null, null };
						creatureId = item.CreatureId;
						obj[3] = ((object)(CreatureGuid)(ref creatureId)).ToString();
						obj[4] = ") By Name ";
						obj[5] = request.source;
						obj[6] = ". Storing As ";
						obj[7] = request.paramJson[0];
						LoggingPlugin.LogDebug(string.Concat(obj));
						break;
					}
				}
				if (text == "")
				{
					text = "No Found\r\n";
					LoggingPlugin.LogDebug("No Instance Of Type " + request.source + " Found.");
				}
				break;
			case "CID":
				foreach (CreatureBoardAsset item2 in (IEnumerable<CreatureBoardAsset>)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets())
				{
					creatureId = item2.CreatureId;
					if (((object)(CreatureGuid)(ref creatureId)).ToString().ToUpper() == request.source.ToUpper())
					{
						references.Add(request.paramJson[0], item2);
						text = item2.Name.ToString() + "\r\n";
						LoggingPlugin.LogDebug("Found Asset " + item2.Name + " By CID " + request.source + " (" + item2.Name + "). Storing As " + request.paramJson[0]);
						break;
					}
				}
				if (text == "")
				{
					text = "No Found\r\n";
					LoggingPlugin.LogDebug("No Instance Of Type " + request.source + " Found.");
				}
				break;
			case "GAMEOBJECT":
				references.Add(request.paramJson[0], GameObject.Find(request.source));
				text = references[request.paramJson[0]].ToString() + "\r\n";
				LoggingPlugin.LogDebug("Found Game Object With Name " + request.source + ". Storing As " + request.paramJson[0] + "\r\n");
				break;
			case "TYPE":
				references.Add(request.paramJson[0], Object.FindObjectOfType(Type.GetType(request.source)));
				text = references[request.paramJson[0]].ToString() + "\r\n";
				LoggingPlugin.LogDebug("Found Game Object With Type " + request.source + ". Storing As " + request.paramJson[0]);
				break;
			case "COMPONENT":
				if (references.ContainsKey(request.source))
				{
					references.Add(request.paramJson[0], ((GameObject)references[request.source]).GetComponentsInChildren(Type.GetType(request.method)));
					text = ((Object)(Component)references[request.paramJson[0]]).name + "\r\n";
					LoggingPlugin.LogDebug("Found Asset " + ((Object)(GameObject)references[request.source]).name + " By Storage " + request.source + " Component Type " + request.method + ". Storing As " + request.paramJson[0] + "\r\n");
				}
				break;
			}
			break;
		}
		case "READ":
		case "REF":
		{
			object obj4 = null;
			if (references.ContainsKey(request.source))
			{
				if ((from fi in references[request.source].GetType().GetRuntimeFields()
					where fi.Name == request.method
					select fi).Count() > 0)
				{
					obj4 = (from fi in references[request.source].GetType().GetRuntimeFields()
						where fi.Name == request.method
						select fi).FirstOrDefault().GetValue(references[request.source]);
					LoggingPlugin.LogDebug("Found Field " + request.method + " On Stored Object " + request.source);
				}
				else
				{
					obj4 = (from pi in references[request.source].GetType().GetRuntimeProperties()
						where pi.Name == request.method
						select pi).FirstOrDefault().GetValue(references[request.source]);
					LoggingPlugin.LogDebug("Found Property " + request.method + " On Stored Object " + request.source);
				}
			}
			else if ((from fi in Type.GetType(request.source).GetRuntimeFields()
				where fi.Name == request.method
				select fi).Count() > 0)
			{
				obj4 = (from fi in Type.GetType(request.source).GetRuntimeFields()
					where fi.Name == request.method
					select fi).FirstOrDefault().GetValue(null);
				LoggingPlugin.LogDebug("Found Field " + request.method + " On Static Object " + request.source);
			}
			else
			{
				obj4 = (from pi in Type.GetType(request.source).GetRuntimeProperties()
					where pi.Name == request.method
					select pi).FirstOrDefault().GetValue(null);
				LoggingPlugin.LogDebug("Found Property " + request.method + " On Static Object " + request.source);
			}
			try
			{
				text = JsonConvert.SerializeObject(obj4) + "\r\n";
			}
			catch
			{
				text = JsonConvert.SerializeObject((object)obj4.ToString()) + "\r\n";
			}
			if (request.command.ToUpper() == "REF")
			{
				if (references.ContainsKey(request.paramJson[0]))
				{
					references[request.paramJson[0]] = obj4;
				}
				else
				{
					references.Add(request.paramJson[0], obj4);
				}
				LoggingPlugin.LogDebug("Storing Result " + obj4?.ToString() + " As " + request.paramJson[0]);
			}
			break;
		}
		case "WRITE":
			if (references.ContainsKey(request.source))
			{
				if ((from fi in references[request.source].GetType().GetRuntimeFields()
					where fi.Name == request.method
					select fi).Count() > 0)
				{
					FieldInfo fieldInfo = (from fi in references[request.source].GetType().GetRuntimeFields()
						where fi.Name == request.method
						select fi).ElementAt(0);
					LoggingPlugin.LogDebug("Wrote To Object Stored As " + request.source + " Field " + request.method + " Value " + JsonConvert.SerializeObject((object)request.paramJson[0]));
					fieldInfo.SetValue(references[request.source], Helpers.ConvertJsonToType(fieldInfo.FieldType, request.paramJson[0]));
				}
				else
				{
					PropertyInfo propertyInfo = (from pi in references[request.source].GetType().GetRuntimeProperties()
						where pi.Name == request.method
						select pi).ElementAt(0);
					LoggingPlugin.LogDebug("Wrote To Object Stored As " + request.source + " Property " + request.method + " Value " + JsonConvert.SerializeObject((object)request.paramJson[0]));
					propertyInfo.SetValue(references[request.source], Helpers.ConvertJsonToType(propertyInfo.PropertyType, request.paramJson[0]));
				}
			}
			else if ((from fi in Type.GetType(request.source).GetType().GetRuntimeFields()
				where fi.Name == request.method
				select fi).Count() > 0)
			{
				FieldInfo fieldInfo2 = (from fi in Type.GetType(request.source).GetRuntimeFields()
					where fi.Name == request.method
					select fi).ElementAt(0);
				LoggingPlugin.LogDebug("Wrote To Static Object " + request.source + " Field " + request.method + " Value " + JsonConvert.SerializeObject((object)request.paramJson[0]));
				fieldInfo2.SetValue(null, Helpers.ConvertJsonToType(fieldInfo2.FieldType, request.paramJson[0]));
			}
			else
			{
				PropertyInfo propertyInfo2 = (from pi in Type.GetType(request.source).GetRuntimeProperties()
					where pi.Name == request.method
					select pi).ElementAt(0);
				LoggingPlugin.LogDebug("Wrote To Static Object " + request.source + " Property " + request.method + " Value " + JsonConvert.SerializeObject((object)request.paramJson[0]));
				propertyInfo2.SetValue(null, Helpers.ConvertJsonToType(propertyInfo2.PropertyType, request.paramJson[0]));
			}
			text = ProcessMessage(new Request
			{
				command = "READ",
				source = request.source,
				method = request.method
			});
			break;
		case "INVOKE":
		{
			LoggingPlugin.LogDebug("INVOKE STEP 1");
			Type[] array = new Type[request.paramJson.Length];
			object[] paramValues = new object[request.paramJson.Length];
			object obj2 = null;
			MethodInfo methodInfo = null;
			if (references.ContainsKey(request.source))
			{
				LoggingPlugin.LogDebug("INVOKE STEP 2A METHOD " + request.method + " ON STORED OBJECT " + request.source);
				methodInfo = (from mi in references[request.source].GetType().GetRuntimeMethods()
					where mi.Name == request.method && mi.GetParameters().Length == request.paramJson.Length
					select mi).ElementAt(0);
				LoggingPlugin.LogDebug("INVOKE STEP 2A METHOD NAME " + methodInfo.Name);
				obj2 = references[request.source];
			}
			else
			{
				LoggingPlugin.LogDebug("INVOKE STEP 2B METHOD " + request.method + " ON " + request.source);
				methodInfo = (from mi in Helpers.GetTypeByString(request.source).GetRuntimeMethods()
					where mi.Name == request.method && mi.GetParameters().Length == request.paramJson.Length
					select mi).ElementAt(0);
				LoggingPlugin.LogDebug("INVOKE STEP 2B METHOD NAME " + methodInfo.Name);
				obj2 = null;
			}
			LoggingPlugin.LogDebug("INVOKE STEP 3");
			for (int i = 0; i < methodInfo.GetParameters().Length; i++)
			{
				array[i] = methodInfo.GetParameters().ElementAt(i).ParameterType;
			}
			for (int j = 0; j < array.Length; j++)
			{
				LoggingPlugin.LogTrace("Parameter " + j + " is type " + array[j].ToString());
			}
			LoggingPlugin.LogDebug("INVOKE STEP 4");
			Helpers.BuildInvokeParameters(array, request.paramJson, ref paramValues);
			LoggingPlugin.LogDebug("INVOKE STEP 5");
			try
			{
				LoggingPlugin.LogTrace("Invoke Object " + Convert.ToString(obj2));
				object[] array2 = paramValues;
				foreach (object obj3 in array2)
				{
					if (obj3 != null)
					{
						LoggingPlugin.LogTrace("Invoke Parameter Type " + obj3.GetType().ToString() + ", Value " + Convert.ToString(obj3));
					}
					else
					{
						LoggingPlugin.LogTrace("Invoke Parameter Type " + typeof(string).ToString() + ", Value null");
					}
				}
				object obj4 = methodInfo.Invoke(obj2, paramValues);
				LoggingPlugin.LogDebug("INVOKE STEP 6A");
				text = ((obj4 == null) ? "Success" : JsonConvert.SerializeObject(obj4));
			}
			catch (Exception ex)
			{
				LoggingPlugin.LogDebug("INVOKE STEP 6B");
				text = "Invoke Failure: " + JsonConvert.SerializeObject((object)ex);
			}
			break;
		}
		case "REMOVE":
			if (references.ContainsKey(request.source))
			{
				references.Remove(request.source);
				text = request.source + " removed\r\n";
			}
			break;
		}
		LoggingPlugin.LogTrace("Process Message Returning '" + text.Replace("\r\n", "") + "'");
		return text;
	}
}