Decompiled source of Reverse Grief v1.0.2

BepInEx/plugins/LCModReverseGrief.dll

Decompiled 6 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LCModReverseGrief.Patches;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LCModReverseGrief")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCModReverseGrief")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("42a79041-ca5e-48eb-94a9-d4cbda3dd44f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCModReverseGrief
{
	[BepInPlugin("7ph.dev.lcmodreversegrief", "LC Mod - Reverse Grief", "1.0.2")]
	public class ModeBase : BaseUnityPlugin
	{
		private const string modGUID = "7ph.dev.lcmodreversegrief";

		private const string modName = "LC Mod - Reverse Grief";

		private const string modVersion = "1.0.2";

		private readonly Harmony harmony = new Harmony("7ph.dev.lcmodreversegrief");

		public static ModeBase Instance;

		internal ManualLogSource mls;

		public ManualLogSource Mls => mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("7ph.dev.lcmodreversegrief");
			mls.LogInfo((object)"LC Mod - Reverse Grief initialized");
			harmony.PatchAll(typeof(ModeBase));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
		}
	}
}
namespace LCModReverseGrief.Patches
{
	internal class PlayerControllerBPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayerFromOtherClientClientRpc")]
		public static bool PlayerDamaged(ref int damageAmount, ref Vector3 hitDirection, ref int playerWhoHit, ref int newHealthAmount, PlayerControllerB __instance)
		{
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)__instance).IsOwner)
			{
				return true;
			}
			CentipedeAI[] array = Object.FindObjectsByType<CentipedeAI>((FindObjectsSortMode)0);
			for (int i = 0; i < array.Length; i++)
			{
				if ((Object)(object)array[i].clingingToPlayer == (Object)(object)__instance)
				{
					ModeBase.Instance.mls.LogInfo((object)$"REVERSE_GRIEF: Accepting the hit from player{playerWhoHit}");
					return true;
				}
			}
			ModeBase.Instance.mls.LogInfo((object)$"REVERSE_GRIEF: Detected grief from another player{playerWhoHit}");
			PlayerControllerB val = FindPlayerById(playerWhoHit);
			if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)__instance)
			{
				ModeBase.Instance.mls.LogInfo((object)$"REVERSE_GRIEF: Identified griefing player{playerWhoHit}. Hitting back other player instantly.");
				val.DamagePlayerFromOtherClientServerRpc(damageAmount, -hitDirection, playerWhoHit);
			}
			else
			{
				ModeBase.Instance.mls.LogInfo((object)"REVERSE_GRIEF: Unable to identify griefing player. Skipping revenge.");
			}
			damageAmount = 0;
			newHealthAmount = __instance.health;
			return true;
		}

		private static PlayerControllerB FindPlayerById(int playerId)
		{
			PlayerControllerB[] array = Object.FindObjectsOfType<PlayerControllerB>();
			PlayerControllerB[] array2 = array;
			foreach (PlayerControllerB val in array2)
			{
				if ((int)val.playerClientId == playerId)
				{
					return val;
				}
			}
			return null;
		}
	}
}