Decompiled source of EffectsFix v1.0.0

plugins/AscendantArmoryIgnaviusFix.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 BepInEx;
using BepInEx.Bootstrap;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.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 AscendantArmoryIgnaviusFix
{
	[BepInPlugin("local.ascendantarmory.ignaviusfix", "Ascendant Armory Ignavius Fix", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Id = "local.ascendantarmory.ignaviusfix";

		private const string PrefabName = "Ignavius_BasicStrike";

		private static Plugin instance;

		private readonly HashSet<int> inspected = new HashSet<int>();

		private Harmony harmony;

		private void Awake()
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			instance = this;
			try
			{
				Type type = ((object)Chainloader.PluginInfos["catharis.AscendedArsenal"].Instance).GetType().Assembly.GetType("ItemManager.PrefabManager");
				if (type != null)
				{
					string[] array = new string[2] { "prefabs", "ZnetOnlyPrefabs" };
					foreach (string text in array)
					{
						if (!(AccessTools.Field(type, text)?.GetValue(null) is IEnumerable enumerable))
						{
							continue;
						}
						foreach (object item in enumerable)
						{
							Inspect((GameObject)((item is GameObject) ? item : null));
						}
					}
				}
				harmony = new Harmony("local.ascendantarmory.ignaviusfix");
				harmony.Patch((MethodBase)AccessTools.Method(typeof(ZNetScene), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "SceneReady", (Type[])null)
				{
					priority = 0
				}, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Ignavius compatibility patch initialization failed: " + ex));
			}
		}

		private static void SceneReady(ZNetScene __instance)
		{
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			foreach (GameObject prefab in __instance.m_prefabs)
			{
				instance.Inspect(prefab);
			}
		}

		private void Inspect(GameObject root)
		{
			if (!Object.op_Implicit((Object)(object)root) || ((Object)root).name != "Ignavius_BasicStrike" || inspected.Contains(((Object)root).GetInstanceID()))
			{
				return;
			}
			inspected.Add(((Object)root).GetInstanceID());
			try
			{
				ZNetView[] components = root.GetComponents<ZNetView>();
				TimedDestruction[] components2 = root.GetComponents<TimedDestruction>();
				ZNetView[] componentsInChildren = root.GetComponentsInChildren<ZNetView>(true);
				List<ZNetView> list = new List<ZNetView>();
				ZNetView[] array = componentsInChildren;
				foreach (ZNetView val in array)
				{
					if ((Object)(object)((Component)val).gameObject != (Object)(object)root)
					{
						list.Add(val);
					}
				}
				if (list.Count == 0)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Ignavius_BasicStrike: no duplicate child ZNetView; fix skipped.");
					return;
				}
				if (components.Length != 1 || components2.Length != 1 || list.Count != 1)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Ignavius_BasicStrike: unrecognized hierarchy; left unchanged.");
					return;
				}
				GameObject gameObject = ((Component)list[0]).gameObject;
				TimedDestruction[] components3 = gameObject.GetComponents<TimedDestruction>();
				if (!FixPolicy.Matches(((Object)root).name, ((Object)gameObject).name, (Object)(object)gameObject.transform.parent == (Object)(object)root.transform, components.Length, components2.Length, list.Count, components3.Length, components2[0].m_timeout, (components3.Length == 1) ? components3[0].m_timeout : 0f, components2[0].m_triggerOnAwake, components3.Length == 1 && components3[0].m_triggerOnAwake))
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Ignavius_BasicStrike: layout differs from known duplicate; left unchanged.");
					return;
				}
				Object.DestroyImmediate((Object)(object)components3[0], true);
				Object.DestroyImmediate((Object)(object)list[0], true);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Ignavius_BasicStrike: removed duplicate child networking and timer; parent retained.");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Ignavius prefab fix failed: " + ex));
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			if ((Object)(object)instance == (Object)(object)this)
			{
				instance = null;
			}
		}
	}
	public static class FixPolicy
	{
		public static bool Matches(string root, string child, bool direct, int rootViews, int rootTimers, int nestedViews, int childTimers, float rootTimeout, float childTimeout, bool rootAuto, bool childAuto)
		{
			return root == "Ignavius_BasicStrike" && child == root && direct && rootViews == 1 && rootTimers == 1 && nestedViews == 1 && childTimers == 1 && rootTimeout == 3f && childTimeout == 3f && rootAuto && childAuto;
		}
	}
}