Decompiled source of HostEnemyLimbDestroyFix v1.0.1

Hikaria.HostEnemyLimbDestroyFix.dll

Decompiled 9 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Agents;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using CharacterDestruction;
using Gear;
using HarmonyLib;
using Hikaria.HostEnemyLimbDestroyFix;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using SNetwork;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Hikaria.HostEnemyLimbDestroyFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b858167e66c62769704523e9c4cb87b0dfc13e56")]
[assembly: AssemblyProduct("Hikaria.HostEnemyLimbDestroyFix")]
[assembly: AssemblyTitle("Hikaria.HostEnemyLimbDestroyFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
internal static class Logs
{
	public static void LogDebug(object data)
	{
		((BasePlugin)EntryPoint.Instance).Log.LogDebug(data);
	}

	public static void LogError(object data)
	{
		((BasePlugin)EntryPoint.Instance).Log.LogError(data);
	}

	public static void LogFatal(object data)
	{
		((BasePlugin)EntryPoint.Instance).Log.LogFatal(data);
	}

	public static void LogInfo(object data)
	{
		((BasePlugin)EntryPoint.Instance).Log.LogInfo(data);
	}

	public static void LogMessage(object data)
	{
		((BasePlugin)EntryPoint.Instance).Log.LogMessage(data);
	}

	public static void LogWarning(object data)
	{
		((BasePlugin)EntryPoint.Instance).Log.LogWarning(data);
	}
}
namespace Hikaria.HostEnemyLimbDestroyFix
{
	[BepInPlugin("Hikaria.HostEnemyLimbDestroyFix", "HostEnemyLimbDestroyFix", "1.0.1")]
	public class EntryPoint : BasePlugin
	{
		private static Harmony m_Harmony;

		public static EntryPoint Instance { get; private set; }

		public override void Load()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			Instance = this;
			m_Harmony = new Harmony("Hikaria.HostEnemyLimbDestroyFix");
			m_Harmony.PatchAll();
			Logs.LogMessage("OK");
		}
	}
	public static class PluginInfo
	{
		public const string GUID = "Hikaria.HostEnemyLimbDestroyFix";

		public const string NAME = "HostEnemyLimbDestroyFix";

		public const string VERSION = "1.0.1";
	}
}
namespace Hikaria.HostEnemyLimbDestroyFix.Patches
{
	[HarmonyPatch]
	public static class Patches
	{
		private static bool AllowDestroyLimb = true;

		private static Queue<Tuple<Dam_EnemyDamageBase, int, sDestructionEventData>> DestroyLimbDataQueue = new Queue<Tuple<Dam_EnemyDamageBase, int, sDestructionEventData>>();

		[HarmonyPatch(typeof(Shotgun), "Fire")]
		[HarmonyPrefix]
		private static void Shotgun__Fire__Prefix(Shotgun __instance)
		{
			AllowDestroyLimb = !SNet.IsMaster || (!((Agent)((Item)__instance).Owner).IsLocallyOwned && !((Item)__instance).Owner.Owner.IsBot);
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireShotgunSemi")]
		[HarmonyPrefix]
		private static void SentryGunInstance_Firing_Bullets__UpdateFireShotgunSemi__Prefix(bool isMaster)
		{
			AllowDestroyLimb = !(SNet.IsMaster && isMaster);
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireShotgunSemi")]
		[HarmonyPostfix]
		private static void SentryGunInstance_Firing_Bullets__UpdateFireShotgunSemi__Postfix()
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if (AllowDestroyLimb)
			{
				return;
			}
			AllowDestroyLimb = true;
			Tuple<Dam_EnemyDamageBase, int, sDestructionEventData> result;
			while (DestroyLimbDataQueue.TryDequeue(out result))
			{
				Dam_EnemyDamageBase item = result.Item1;
				bool? obj;
				if (item == null)
				{
					obj = null;
				}
				else
				{
					Dam_EnemyDamageLimb obj2 = ((Il2CppArrayBase<Dam_EnemyDamageLimb>)(object)item.DamageLimbs)[result.Item2];
					obj = ((obj2 != null) ? new bool?(obj2.IsDestroyed) : null);
				}
				bool? flag = obj;
				if (flag.HasValue && !flag.GetValueOrDefault() && !((Object)(object)item.Owner == (Object)null))
				{
					item.SendDestroyLimb(result.Item2, result.Item3);
				}
			}
		}

		[HarmonyPatch(typeof(Shotgun), "Fire")]
		[HarmonyPostfix]
		private static void Shotgun__Fire__Postfix()
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if (AllowDestroyLimb)
			{
				return;
			}
			AllowDestroyLimb = true;
			Tuple<Dam_EnemyDamageBase, int, sDestructionEventData> result;
			while (DestroyLimbDataQueue.TryDequeue(out result))
			{
				Dam_EnemyDamageBase item = result.Item1;
				bool? obj;
				if (item == null)
				{
					obj = null;
				}
				else
				{
					Dam_EnemyDamageLimb obj2 = ((Il2CppArrayBase<Dam_EnemyDamageLimb>)(object)item.DamageLimbs)[result.Item2];
					obj = ((obj2 != null) ? new bool?(obj2.IsDestroyed) : null);
				}
				bool? flag = obj;
				if (flag.HasValue && !flag.GetValueOrDefault() && !((Object)(object)item.Owner == (Object)null))
				{
					item.SendDestroyLimb(result.Item2, result.Item3);
				}
			}
		}

		[HarmonyPatch(typeof(Dam_EnemyDamageBase), "SendDestroyLimb")]
		[HarmonyPrefix]
		private static bool Dam_EnemyDamageBase__SendDestroyLimb__Prefix(Dam_EnemyDamageBase __instance, int limbID, sDestructionEventData destructionEventData)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (!AllowDestroyLimb)
			{
				DestroyLimbDataQueue.Enqueue(new Tuple<Dam_EnemyDamageBase, int, sDestructionEventData>(__instance, limbID, destructionEventData));
				return false;
			}
			return true;
		}
	}
}