Decompiled source of GiveHostClientDamage v0.0.6

ClientDamage.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using API;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using CharacterDestruction;
using ClientDamage;
using GameData;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using UnityEngine;
using UnityEngine.Analytics;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ClientDamage")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2c435be81d3d3a572082f15ef08a2800495af897")]
[assembly: AssemblyProduct("ClientDamage")]
[assembly: AssemblyTitle("ClientDamage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
[BepInPlugin("randomuserhi.ClientDamage", "ClientDamage", "0.0.1")]
public class Plugin : BasePlugin
{
	private static Harmony? harmony;

	public override void Load()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		APILogger.Log("Plugin is loaded!");
		harmony = new Harmony("randomuserhi.ClientDamage");
		harmony.PatchAll();
		APILogger.Log("Debug is " + (ConfigManager.Debug ? "Enabled" : "Disabled"));
	}
}
namespace ClientDamage
{
	public static class Module
	{
		public const string GUID = "randomuserhi.ClientDamage";

		public const string Name = "ClientDamage";

		public const string Version = "0.0.1";
	}
	internal static class ConfigManager
	{
		private static ConfigEntry<bool> debug;

		private static ConfigEntry<float> delay;

		private static ConfigEntry<bool> delayBulletDamage;

		private static ConfigEntry<bool> includeShotgunSentry;

		public static bool Debug
		{
			get
			{
				return debug.Value;
			}
			set
			{
				debug.Value = value;
			}
		}

		public static float Delay
		{
			get
			{
				return delay.Value;
			}
			set
			{
				delay.Value = value;
			}
		}

		public static bool DelayBulletDamage
		{
			get
			{
				return delayBulletDamage.Value;
			}
			set
			{
				delayBulletDamage.Value = value;
			}
		}

		public static bool IncludeShotgunSentry
		{
			get
			{
				return includeShotgunSentry.Value;
			}
			set
			{
				includeShotgunSentry.Value = value;
			}
		}

		static ConfigManager()
		{
			//IL_0010: 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)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "ClientDamage.cfg"), true);
			debug = val.Bind<bool>("Debug", "enable", false, "Enables debug messages when true.");
			delay = val.Bind<float>("Settings", "delay", 0.05f, "Delay in seconds until a limb breaks. Clamped to a value between 0 and 0.2 to prevent abuse.");
			delayBulletDamage = val.Bind<bool>("Settings", "delayBulletDamage", false, "Delay your bullet damage to mimic delay on client - Useful for mimicing delayed enemy reactions for burst weapons to make hitting full burst more consistent.\nWARNING: This literally adds ping to your shots which may make your play experience much worse. Use at your own risk.");
			includeShotgunSentry = val.Bind<bool>("Settings", "includeShotgunSentry", false, "Set to true if you want shotgun sentry to be able to abuse the limb destruction delay.");
		}
	}
}
namespace ClientDamage.Patches
{
	[HarmonyPatch]
	internal static class BulletDamage
	{
		private static bool callOriginal;

		private static IEnumerator DelayBulletDamage(Dam_EnemyDamageLimb limb, float dam, Agent sourceAgent, Vector3 position, Vector3 direction, Vector3 normal, bool allowDirectionalBonus, float staggerMulti, float precisionMulti, uint gearCategoryId)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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)
			yield return (object)new WaitForSeconds(Mathf.Clamp(ConfigManager.Delay, 0f, 0.2f));
			if ((Object)(object)limb != (Object)null)
			{
				callOriginal = true;
				limb.BulletDamage(dam, sourceAgent, position, direction, normal, allowDirectionalBonus, staggerMulti, precisionMulti, gearCategoryId);
				callOriginal = false;
			}
		}

		[HarmonyPatch(typeof(Dam_EnemyDamageLimb), "BulletDamage")]
		[HarmonyPrefix]
		private static bool Prefix_ReceiveBulletDamage(Dam_EnemyDamageLimb __instance, float dam, Agent sourceAgent, Vector3 position, Vector3 direction, Vector3 normal, bool allowDirectionalBonus, float staggerMulti, float precisionMulti, uint gearCategoryId)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (!SNet.IsMaster || Sentry.anySentryShot || ConfigManager.Delay == 0f || !ConfigManager.DelayBulletDamage)
			{
				return true;
			}
			if (sourceAgent.GlobalID != ((Agent)PlayerManager.GetLocalPlayerAgent()).GlobalID)
			{
				return true;
			}
			if (!callOriginal)
			{
				APILogger.Debug("Delay bullet shot.");
				((MonoBehaviour)__instance).StartCoroutine(CollectionExtensions.WrapToIl2Cpp(DelayBulletDamage(__instance, dam, sourceAgent, position, direction, normal, allowDirectionalBonus, staggerMulti, precisionMulti, gearCategoryId)));
			}
			return callOriginal;
		}
	}
	[HarmonyPatch]
	internal static class LimbDestruction
	{
		private static bool callOriginal;

		private static IEnumerator DelayLimbDestruction(Dam_EnemyDamageLimb limb, sDestructionEventData data)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForSeconds(Mathf.Clamp(ConfigManager.Delay, 0f, 0.2f));
			if ((Object)(object)limb != (Object)null && !limb.IsDestroyed)
			{
				callOriginal = true;
				limb.DestroyLimb(data);
				callOriginal = false;
			}
		}

		[HarmonyPatch(typeof(Dam_EnemyDamageLimb), "DestroyLimb")]
		[HarmonyPrefix]
		private static bool Prefix_ReceiveDestroyLimb(Dam_EnemyDamageLimb __instance, sDestructionEventData destructionEventData)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (!SNet.IsMaster || Sentry.sentryShot || (Sentry.shotgunSentryShot && !ConfigManager.IncludeShotgunSentry) || ConfigManager.Delay == 0f)
			{
				return true;
			}
			if (!callOriginal)
			{
				APILogger.Debug("Delay limb break.");
				((MonoBehaviour)__instance).StartCoroutine(CollectionExtensions.WrapToIl2Cpp(DelayLimbDestruction(__instance, destructionEventData)));
			}
			return callOriginal;
		}
	}
	[HarmonyPatch]
	internal static class CustomLimbDestruction
	{
		private static bool callOriginal;

		private static IEnumerator DelayLimbDestruction(Dam_EnemyDamageLimb_Custom limb, sDestructionEventData data)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForSeconds(Mathf.Clamp(ConfigManager.Delay, 0f, 0.2f));
			if ((Object)(object)limb != (Object)null && !((Dam_EnemyDamageLimb)limb).IsDestroyed)
			{
				callOriginal = true;
				((Dam_EnemyDamageLimb)limb).DestroyLimb(data);
				callOriginal = false;
			}
		}

		[HarmonyPatch(typeof(Dam_EnemyDamageLimb_Custom), "DestroyLimb")]
		[HarmonyPrefix]
		private static bool Prefix_ReceiveDestroyLimb(Dam_EnemyDamageLimb_Custom __instance, sDestructionEventData destructionEventData)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (!SNet.IsMaster || Sentry.sentryShot || (Sentry.shotgunSentryShot && !ConfigManager.IncludeShotgunSentry) || ConfigManager.Delay == 0f)
			{
				return true;
			}
			if (!callOriginal)
			{
				APILogger.Debug("Delay limb custom break.");
				((MonoBehaviour)__instance).StartCoroutine(CollectionExtensions.WrapToIl2Cpp(DelayLimbDestruction(__instance, destructionEventData)));
			}
			return callOriginal;
		}
	}
	[HarmonyPatch]
	internal class Sentry
	{
		public static bool sentryShot;

		public static bool shotgunSentryShot;

		public static bool anySentryShot
		{
			get
			{
				if (!sentryShot)
				{
					return shotgunSentryShot;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "FireBullet")]
		[HarmonyPrefix]
		private static void Prefix_SentryGunFiringBullet(bool doDamage, bool targetIsTagged)
		{
			if (doDamage)
			{
				sentryShot = true;
			}
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "FireBullet")]
		[HarmonyPostfix]
		private static void Postfix_SentryGunFiringBullet()
		{
			sentryShot = false;
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireShotgunSemi")]
		[HarmonyPrefix]
		private static void Prefix_ShotgunSentryFiring(SentryGunInstance_Firing_Bullets __instance, bool isMaster, bool targetIsTagged)
		{
			if (isMaster && Clock.Time > __instance.m_fireBulletTimer)
			{
				shotgunSentryShot = true;
			}
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireShotgunSemi")]
		[HarmonyPostfix]
		private static void Postfix_ShotgunSentryFiring()
		{
			shotgunSentryShot = false;
		}
	}
}
namespace API
{
	[HarmonyPatch(typeof(GameDataInit))]
	internal class GameDataInit_Patches
	{
		[HarmonyPatch("Initialize")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		public static void Initialize_Postfix()
		{
			Analytics.enabled = false;
		}
	}
	internal static class APILogger
	{
		private static readonly ManualLogSource logger;

		static APILogger()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			logger = new ManualLogSource("Rand-API");
			Logger.Sources.Add((ILogSource)(object)logger);
		}

		private static string Format(string module, object msg)
		{
			return $"[{module}]: {msg}";
		}

		public static void Info(string module, object data)
		{
			logger.LogMessage((object)Format(module, data));
		}

		public static void Verbose(string module, object data)
		{
		}

		public static void Log(object data)
		{
			logger.LogDebug((object)Format("ClientDamage", data));
		}

		public static void Debug(object data)
		{
			if (ConfigManager.Debug)
			{
				Log(data);
			}
		}

		public static void Warn(object data)
		{
			logger.LogWarning((object)Format("ClientDamage", data));
		}

		public static void Error(object data)
		{
			logger.LogError((object)Format("ClientDamage", data));
		}
	}
}