Decompiled source of RenameManor v1.4.0

RenameManor.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RenameManor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RenameManor")]
[assembly: AssemblyTitle("RenameManor")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RenameManor
{
	[BepInPlugin("user.repo.renamemanor", "RenameManor", "1.4.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance;

		internal static ManualLogSource Log;

		internal static Harmony HarmonyInstance;

		internal static long SetterHits;

		internal static readonly HashSet<string> ManorKeys = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "LEVEL.NAME.MANOR" };

		internal static ConfigEntry<string> NewName;

		internal static ConfigEntry<string> ExtraNames;

		internal static ConfigEntry<bool> DebugLog;

		internal static readonly List<string> Names = new List<string>();

		private static readonly object Lock = new object();

		private static Regex _rx;

		private static readonly HashSet<string> Logged = new HashSet<string>();

		private void Awake()
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			NewName = ((BaseUnityPlugin)this).Config.Bind<string>("General", "NewName", "хуйня ебаная", "Новое название уровня.");
			ExtraNames = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ExtraNames", "", "Названия Headman Manor на других языках через точку с запятой (если нужно).");
			DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogUiTexts", false, "Писать в лог короткие тексты интерфейса с путём к объекту (для поиска названия на вашем языке).");
			AddName("Headman Manor");
			string[] array = (ExtraNames.Value ?? "").Split(';');
			for (int i = 0; i < array.Length; i++)
			{
				AddName(array[i]);
			}
			HarmonyInstance = new Harmony("user.repo.renamemanor");
			HarmonyInstance.PatchAll();
			Log.LogInfo((object)"RenameManor loaded");
			((MonoBehaviour)this).StartCoroutine(Delayed());
		}

		private IEnumerator Delayed()
		{
			yield return (object)new WaitForSeconds(5f);
			LevelRenamer.RenameAll(null);
			LogPatchOwners();
			Log.LogInfo((object)("[diag] LogUiTexts=" + DebugLog.Value + ", TMP text setter hits so far=" + SetterHits));
		}

		internal static void LogPatchOwners()
		{
			try
			{
				Patches patchInfo = Harmony.GetPatchInfo((MethodBase)AccessTools.PropertySetter(typeof(TMP_Text), "text"));
				if (patchInfo == null)
				{
					return;
				}
				foreach (Patch prefix in patchInfo.Prefixes)
				{
					Log.LogInfo((object)("[patchinfo] prefix owner=" + prefix.owner + " prio=" + prefix.priority + " " + prefix.PatchMethod.DeclaringType?.ToString() + "." + prefix.PatchMethod.Name));
				}
				foreach (Patch postfix in patchInfo.Postfixes)
				{
					Log.LogInfo((object)("[patchinfo] postfix owner=" + postfix.owner + " prio=" + postfix.priority + " " + postfix.PatchMethod.DeclaringType?.ToString() + "." + postfix.PatchMethod.Name));
				}
				foreach (Patch transpiler in patchInfo.Transpilers)
				{
					Log.LogInfo((object)("[patchinfo] transpiler owner=" + transpiler.owner + " " + transpiler.PatchMethod.DeclaringType?.ToString() + "." + transpiler.PatchMethod.Name));
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)ex);
			}
		}

		internal static void AddName(string n)
		{
			if (string.IsNullOrWhiteSpace(n))
			{
				return;
			}
			n = n.Trim();
			if (n.Length < 4)
			{
				return;
			}
			lock (Lock)
			{
				foreach (string name in Names)
				{
					if (string.Equals(name, n, StringComparison.OrdinalIgnoreCase))
					{
						return;
					}
				}
				Names.Add(n);
				List<string> list = new List<string>(Names);
				list.Sort((string a, string b) => b.Length.CompareTo(a.Length));
				List<string> list2 = new List<string>();
				foreach (string item in list)
				{
					list2.Add(Regex.Escape(item));
				}
				_rx = new Regex(string.Join("|", list2.ToArray()), RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.CultureInvariant);
			}
			if (Log != null)
			{
				Log.LogInfo((object)("Known level name: " + n));
			}
		}

		internal static bool Matches(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return false;
			}
			lock (Lock)
			{
				for (int i = 0; i < Names.Count; i++)
				{
					if (s.IndexOf(Names[i], StringComparison.OrdinalIgnoreCase) >= 0)
					{
						return true;
					}
				}
			}
			return false;
		}

		internal static string Fix(string s)
		{
			Regex rx;
			lock (Lock)
			{
				rx = _rx;
			}
			if (rx == null || string.IsNullOrEmpty(s))
			{
				return s;
			}
			string to = NewName.Value;
			return rx.Replace(s, (Match m) => (!(m.Value == m.Value.ToUpperInvariant()) || !(m.Value != m.Value.ToLowerInvariant())) ? to : to.ToUpperInvariant());
		}

		internal static void DebugText(TMP_Text t, string text)
		{
			if (DebugLog.Value && !((Object)(object)t == (Object)null) && !string.IsNullOrEmpty(text) && text.Length >= 4 && text.Length <= 60 && Logged.Count <= 2500 && Logged.Add(text))
			{
				StringBuilder stringBuilder = new StringBuilder();
				Transform val = t.transform;
				while ((Object)(object)val != (Object)null)
				{
					stringBuilder.Insert(0, "/" + ((Object)val).name);
					val = val.parent;
				}
				Log.LogInfo((object)("[text] \"" + text + "\"  @ " + stringBuilder));
			}
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class TextSetterPatch
	{
		[HarmonyPriority(800)]
		private static void Prefix(TMP_Text __instance, ref string value)
		{
			Plugin.SetterHits++;
			Plugin.DebugText(__instance, value);
			if (Plugin.Matches(value))
			{
				value = Plugin.Fix(value);
			}
		}
	}
	[HarmonyPatch(typeof(TMP_Text), "SetText", new Type[]
	{
		typeof(string),
		typeof(bool)
	})]
	internal static class SetTextPatch
	{
		[HarmonyPriority(800)]
		private static void Prefix(TMP_Text __instance, ref string sourceText)
		{
			Plugin.DebugText(__instance, sourceText);
			if (Plugin.Matches(sourceText))
			{
				sourceText = Plugin.Fix(sourceText);
			}
		}
	}
	[HarmonyPatch(typeof(RunManager), "ChangeLevel")]
	internal static class ChangeLevelPatch
	{
		[HarmonyPriority(800)]
		private static void Prefix(RunManager __instance)
		{
			LevelRenamer.RenameAll(__instance);
		}

		private static void Postfix(RunManager __instance)
		{
			LevelRenamer.RenameAll(__instance);
		}
	}
	internal static class LevelRenamer
	{
		private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly HashSet<int> Dumped = new HashSet<int>();

		internal static void RenameAll(RunManager rm)
		{
			try
			{
				List<object> list = new List<object>();
				if ((Object)(object)rm != (Object)null)
				{
					if (AccessTools.Field(typeof(RunManager), "levels")?.GetValue(rm) is IEnumerable enumerable)
					{
						foreach (object item2 in enumerable)
						{
							list.Add(item2);
						}
					}
					object obj = AccessTools.Field(typeof(RunManager), "levelCurrent")?.GetValue(rm);
					if (obj != null)
					{
						list.Add(obj);
					}
				}
				Type type = AccessTools.Field(typeof(RunManager), "levelCurrent")?.FieldType;
				if (type != null)
				{
					Object[] array = Resources.FindObjectsOfTypeAll(type);
					foreach (Object item in array)
					{
						list.Add(item);
					}
				}
				int num = 0;
				int num2 = 0;
				foreach (object item3 in list)
				{
					if (item3 != null)
					{
						num++;
						bool flag = IsManor(item3);
						if (flag)
						{
							num2++;
							DumpOnce(item3);
							Harvest(item3);
						}
						Apply(item3, flag);
					}
				}
				Plugin.Log.LogInfo((object)("[level] processed " + num + " level objects, manor=" + num2));
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)ex);
			}
		}

		private static bool IsManor(object level)
		{
			Object val = (Object)((level is Object) ? level : null);
			if (val != (Object)null && val.name.IndexOf("Manor", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			FieldInfo[] fields = level.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (!(fieldInfo.FieldType != typeof(string)))
				{
					string text = (string)fieldInfo.GetValue(level);
					if (Plugin.Matches(text) || (text != null && text == Plugin.NewName.Value))
					{
						return true;
					}
				}
			}
			return false;
		}

		private static bool LooksLikeNameField(string fieldName)
		{
			string text = fieldName.ToLowerInvariant();
			if (!text.Contains("name") && !text.Contains("title") && !text.Contains("narrative"))
			{
				return text.Contains("locali");
			}
			return true;
		}

		private static bool LooksLikeDisplayText(string v)
		{
			if (!string.IsNullOrWhiteSpace(v) && v.Length >= 4 && v.Length <= 60 && v.IndexOf('/') < 0 && v.IndexOf('\\') < 0)
			{
				return v != Plugin.NewName.Value;
			}
			return false;
		}

		private static void Harvest(object level)
		{
			Object val = (Object)((level is Object) ? level : null);
			FieldInfo[] fields = level.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				object obj = SafeGet(fieldInfo, level);
				Object val2 = (Object)((obj is Object) ? obj : null);
				if (val2 != (Object)null && fieldInfo.FieldType.Name.IndexOf("Localized", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					Plugin.ManorKeys.Add(val2.name);
					LocHooks.Install(fieldInfo.FieldType);
					LocAsset.Process(val2);
				}
				else
				{
					if (!LooksLikeNameField(fieldInfo.Name))
					{
						continue;
					}
					object value = fieldInfo.GetValue(level);
					if (value != null && value.GetType().Name == "LocalizedString")
					{
						string localized = GetLocalized(value);
						if (LooksLikeDisplayText(localized))
						{
							Plugin.AddName(localized);
						}
					}
					else if (value is string text)
					{
						if (LooksLikeDisplayText(text) && (val == (Object)null || text != val.name))
						{
							Plugin.AddName(text);
						}
					}
					else
					{
						if (!(value is IEnumerable enumerable))
						{
							continue;
						}
						foreach (object item in enumerable)
						{
							if (item is string text2 && LooksLikeDisplayText(text2))
							{
								Plugin.AddName(text2);
							}
						}
					}
				}
			}
		}

		private static object SafeGet(FieldInfo f, object o)
		{
			try
			{
				return f.GetValue(o);
			}
			catch
			{
				return null;
			}
		}

		private static string GetLocalized(object ls)
		{
			try
			{
				MethodInfo method = ls.GetType().GetMethod("GetLocalizedString", BindingFlags.Instance | BindingFlags.Public, null, Type.EmptyTypes, null);
				return (method == null) ? null : (method.Invoke(ls, null) as string);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogInfo((object)("[level] GetLocalizedString failed: " + ex.GetBaseException().Message));
				return null;
			}
		}

		private static string Prop(object o, string name)
		{
			try
			{
				PropertyInfo property = o.GetType().GetProperty(name);
				if (property == null)
				{
					return "n/a";
				}
				object value = property.GetValue(o, null);
				return (value == null) ? "null" : value.ToString();
			}
			catch
			{
				return "?";
			}
		}

		private static void DumpOnce(object level)
		{
			int hashCode = RuntimeHelpers.GetHashCode(level);
			if (!Dumped.Add(hashCode))
			{
				return;
			}
			Object val = (Object)((level is Object) ? level : null);
			string text = ((val != (Object)null) ? val.name : level.GetType().Name);
			Plugin.Log.LogInfo((object)("[level] dump of '" + text + "' (" + level.GetType().FullName + ")"));
			FieldInfo[] fields = level.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				string text2;
				try
				{
					object value = fieldInfo.GetValue(level);
					if (value == null)
					{
						text2 = "null";
					}
					else if (value is string text3)
					{
						text2 = "\"" + text3 + "\"";
					}
					else if (value.GetType().Name == "LocalizedString")
					{
						text2 = "LocalizedString table=" + Prop(value, "TableReference") + " entry=" + Prop(value, "TableEntryReference") + " text=\"" + GetLocalized(value) + "\"";
					}
					else
					{
						text2 = value.ToString();
						if (text2.Length > 80)
						{
							text2 = text2.Substring(0, 80);
						}
					}
				}
				catch (Exception ex)
				{
					text2 = "<error " + ex.GetType().Name + ">";
				}
				Plugin.Log.LogInfo((object)("[level]   " + fieldInfo.Name + " : " + fieldInfo.FieldType.Name + " = " + text2));
			}
		}

		private static void Apply(object level, bool manor)
		{
			string value = Plugin.NewName.Value;
			FieldInfo[] fields = level.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.FieldType != typeof(string))
				{
					continue;
				}
				string text = (string)fieldInfo.GetValue(level);
				if (manor && fieldInfo.Name.Equals("NarrativeName", StringComparison.OrdinalIgnoreCase))
				{
					if (text != value)
					{
						fieldInfo.SetValue(level, value);
					}
				}
				else if (Plugin.Matches(text))
				{
					fieldInfo.SetValue(level, Plugin.Fix(text));
				}
			}
		}
	}
	internal static class LocAsset
	{
		private static readonly HashSet<int> Seen = new HashSet<int>();

		private static bool Rewritable(string s)
		{
			if (string.IsNullOrWhiteSpace(s) || s.Length < 4 || s.Length > 60)
			{
				return false;
			}
			if (s == Plugin.NewName.Value)
			{
				return false;
			}
			if (Regex.IsMatch(s, "^[A-Za-z0-9_.\\-]+$"))
			{
				return false;
			}
			return true;
		}

		private static string Short(object v)
		{
			if (v == null)
			{
				return "null";
			}
			if (v is string text)
			{
				return "\"" + text + "\"";
			}
			if (v is IEnumerable enumerable)
			{
				StringBuilder stringBuilder = new StringBuilder("[");
				int num = 0;
				foreach (object item in enumerable)
				{
					if (num++ >= 10)
					{
						stringBuilder.Append(", ...");
						break;
					}
					string text2 = ((item == null) ? "null" : item.ToString());
					if (text2.Length > 40)
					{
						text2 = text2.Substring(0, 40);
					}
					stringBuilder.Append((num > 1) ? ", " : "").Append(text2);
				}
				return stringBuilder.Append("]").ToString();
			}
			string text3 = v.ToString();
			if (text3.Length <= 80)
			{
				return text3;
			}
			return text3.Substring(0, 80);
		}

		internal static void Process(Object asset)
		{
			try
			{
				bool flag = Seen.Add(asset.GetInstanceID());
				Type type = ((object)asset).GetType();
				if (flag)
				{
					Plugin.Log.LogInfo((object)("[loc] asset '" + asset.name + "' type " + type.FullName));
				}
				Type type2 = type;
				while (type2 != null && type2 != typeof(Object) && type2 != typeof(ScriptableObject) && type2 != typeof(object))
				{
					FieldInfo[] fields = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (FieldInfo fieldInfo in fields)
					{
						object value;
						try
						{
							value = fieldInfo.GetValue(asset);
						}
						catch
						{
							continue;
						}
						if (flag)
						{
							Plugin.Log.LogInfo((object)("[loc]   field " + fieldInfo.Name + " : " + fieldInfo.FieldType.Name + " = " + Short(value)));
						}
						if (value is string text)
						{
							if (Rewritable(text))
							{
								Plugin.AddName(text);
								fieldInfo.SetValue(asset, Plugin.NewName.Value);
							}
						}
						else if (value is IList list)
						{
							for (int j = 0; j < list.Count; j++)
							{
								if (list[j] is string text2 && Rewritable(text2))
								{
									Plugin.AddName(text2);
									list[j] = Plugin.NewName.Value;
								}
							}
						}
						else
						{
							if (!(value is IDictionary dictionary))
							{
								continue;
							}
							List<object> list2 = new List<object>();
							foreach (object key in dictionary.Keys)
							{
								list2.Add(key);
							}
							foreach (object item in list2)
							{
								if (dictionary[item] is string text3 && Rewritable(text3))
								{
									Plugin.AddName(text3);
									dictionary[item] = Plugin.NewName.Value;
								}
							}
						}
					}
					type2 = type2.BaseType;
				}
				if (!flag)
				{
					return;
				}
				PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
				foreach (PropertyInfo propertyInfo in properties)
				{
					if (propertyInfo.CanRead && propertyInfo.GetIndexParameters().Length == 0 && !(propertyInfo.PropertyType != typeof(string)) && !(propertyInfo.Name == "name"))
					{
						try
						{
							Plugin.Log.LogInfo((object)("[loc]   property " + propertyInfo.Name + " = " + Short(propertyInfo.GetValue(asset, null))));
						}
						catch
						{
						}
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)ex);
			}
		}
	}
	internal static class LocHooks
	{
		private static bool _done;

		private const BindingFlags All = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private static IEnumerable<Type> SafeTypes(Assembly asm)
		{
			try
			{
				return asm.GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				List<Type> list = new List<Type>();
				Type[] types = ex.Types;
				foreach (Type type in types)
				{
					if (type != null)
					{
						list.Add(type);
					}
				}
				return list;
			}
		}

		private static string Sig(MethodInfo m)
		{
			StringBuilder stringBuilder = new StringBuilder();
			ParameterInfo[] parameters = m.GetParameters();
			foreach (ParameterInfo parameterInfo in parameters)
			{
				if (stringBuilder.Length > 0)
				{
					stringBuilder.Append(", ");
				}
				stringBuilder.Append(parameterInfo.ParameterType.Name).Append(' ').Append(parameterInfo.Name);
			}
			return stringBuilder.ToString();
		}

		internal static void Install(Type assetType)
		{
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Expected O, but got Unknown
			if (_done || assetType == null)
			{
				return;
			}
			_done = true;
			try
			{
				int num = 0;
				int num2 = 0;
				foreach (Type item in SafeTypes(assetType.Assembly))
				{
					bool flag = item == assetType;
					bool flag2 = item.Name.IndexOf("Locali", StringComparison.OrdinalIgnoreCase) >= 0;
					if ((!flag && !flag2) || item.IsGenericTypeDefinition)
					{
						continue;
					}
					MethodInfo[] methods = item.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (MethodInfo methodInfo in methods)
					{
						if (num++ < 250)
						{
							Plugin.Log.LogInfo((object)("[loc] api " + item.FullName + "." + methodInfo.Name + "(" + Sig(methodInfo) + ") : " + methodInfo.ReturnType.Name + (methodInfo.IsStatic ? " [static]" : "")));
						}
						if (methodInfo.ReturnType != typeof(string) || methodInfo.IsAbstract || methodInfo.IsGenericMethodDefinition || methodInfo.Name == "ToString" || methodInfo.Name == "GetHashCode" || methodInfo.Name == "GetType")
						{
							continue;
						}
						bool flag3 = false;
						ParameterInfo[] parameters = methodInfo.GetParameters();
						foreach (ParameterInfo parameterInfo in parameters)
						{
							Type type = (parameterInfo.ParameterType.IsByRef ? parameterInfo.ParameterType.GetElementType() : parameterInfo.ParameterType);
							if (type == assetType || type == typeof(string))
							{
								flag3 = true;
							}
						}
						if ((flag3 || (flag && !methodInfo.IsStatic)) && num2 < 80)
						{
							try
							{
								MethodInfo method = typeof(LocHooks).GetMethod(methodInfo.IsStatic ? "PostfixStatic" : "PostfixInstance", BindingFlags.Static | BindingFlags.Public);
								Plugin.HarmonyInstance.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(method), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								num2++;
								Plugin.Log.LogInfo((object)("[loc] hooked " + item.FullName + "." + methodInfo.Name + "(" + Sig(methodInfo) + ")"));
							}
							catch (Exception ex)
							{
								Plugin.Log.LogWarning((object)("[loc] hook failed " + item.Name + "." + methodInfo.Name + ": " + ex.Message));
							}
						}
					}
				}
				Plugin.Log.LogInfo((object)("[loc] hooks installed: " + num2));
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogWarning((object)ex2);
			}
		}

		public static void PostfixStatic(ref string __result, object[] __args)
		{
			Apply(ref __result, null, __args);
		}

		public static void PostfixInstance(ref string __result, object __instance, object[] __args)
		{
			Apply(ref __result, __instance, __args);
		}

		private static void Apply(ref string result, object inst, object[] args)
		{
			try
			{
				if (IsManorObj(inst) || AnyManorArg(args))
				{
					string value = Plugin.NewName.Value;
					if (result != value)
					{
						result = value;
					}
				}
			}
			catch
			{
			}
		}

		private static bool IsManorObj(object o)
		{
			Object val = (Object)((o is Object) ? o : null);
			if (val != (Object)null)
			{
				return Plugin.ManorKeys.Contains(val.name);
			}
			return false;
		}

		private static bool AnyManorArg(object[] args)
		{
			if (args == null)
			{
				return false;
			}
			foreach (object obj in args)
			{
				if (obj is string item)
				{
					if (Plugin.ManorKeys.Contains(item))
					{
						return true;
					}
				}
				else if (IsManorObj(obj))
				{
					return true;
				}
			}
			return false;
		}
	}
}