Decompiled source of BloodRush v1.0.0

BloodRush.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FishNet.Object;
using HarmonyLib;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ClassLibrary1")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ClassLibrary1")]
[assembly: AssemblyTitle("ClassLibrary1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace KillHealMod;

[BepInPlugin("dxncheeks.BloodRush", "Blood Rush", "1.0.0")]
public class KillHealMod : BaseUnityPlugin
{
	private const string modGUID = "dxncheeks.BloodRush";

	private const string modName = "Blood Rush";

	private const string modVersion = "1.0.0";

	internal static ManualLogSource Log;

	internal static ConfigEntry<float> SpeedBoostMultiplier;

	internal static ConfigEntry<float> SpeedBoostDuration;

	internal static Dictionary<FirstPersonController, float> BoostExpiry = new Dictionary<FirstPersonController, float>();

	private readonly Harmony harmony = new Harmony("dxncheeks.BloodRush");

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		SpeedBoostMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "SpeedBoostMultiplier", 16f, "Target movement speed during the boost (walkSpeed=7, sprintSpeed=12 by default — set this above sprint speed for a noticeable boost)");
		SpeedBoostDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "SpeedBoostDuration", 3f, "How long the speed boost lasts, in seconds");
		harmony.PatchAll(typeof(KillHealPatch));
		harmony.PatchAll(typeof(SpeedBoostPatch));
		harmony.PatchAll(typeof(SpawnClearBoostPatch));
		Log.LogInfo((object)"KillHealMod loaded");
	}

	private void Update()
	{
		try
		{
			Keyboard current = Keyboard.current;
			if (current == null || !((ButtonControl)current.f9Key).wasPressedThisFrame)
			{
				return;
			}
			Log.LogInfo((object)"F9 key detected");
			PlayerHealth val = ((IEnumerable<PlayerHealth>)Object.FindObjectsOfType<PlayerHealth>(true)).FirstOrDefault((Func<PlayerHealth, bool>)((PlayerHealth p) => ((NetworkBehaviour)p).IsOwner));
			if ((Object)(object)val == (Object)null)
			{
				Log.LogInfo((object)"F9: no local PlayerHealth found");
				return;
			}
			float num = val.fullHealth - val.sync___get_value_health();
			Log.LogInfo((object)$"F9 test: health {val.sync___get_value_health()}/{val.fullHealth}, deficit {num}");
			if (num > 0f)
			{
				val.RemoveHealth(0f - num);
			}
			if ((Object)(object)val.controller != (Object)null)
			{
				BoostExpiry[val.controller] = Time.time + SpeedBoostDuration.Value;
			}
			Log.LogInfo((object)"F9 test applied");
		}
		catch (Exception arg)
		{
			Log.LogError((object)$"F9 test error: {arg}");
		}
	}
}
[HarmonyPatch(typeof(GameManager), "RpcLogic___PlayerDied_3316948804")]
internal static class KillHealPatch
{
	private static void Postfix(int playerId)
	{
		try
		{
			KillHealMod.Log.LogInfo((object)$"PlayerDied fired for playerId {playerId}");
			PlayerHealth val = ((IEnumerable<PlayerHealth>)Object.FindObjectsOfType<PlayerHealth>(true)).FirstOrDefault((Func<PlayerHealth, bool>)delegate(PlayerHealth p)
			{
				PlayerValues val3 = p.sync___get_value_playerValues();
				if ((Object)(object)val3 == (Object)null)
				{
					return false;
				}
				ClientInstance val4 = val3.sync___get_value_playerClient();
				return (Object)(object)val4 != (Object)null && val4.PlayerId == playerId;
			});
			if ((Object)(object)val == (Object)null)
			{
				KillHealMod.Log.LogInfo((object)"No PlayerHealth found matching victim playerId");
				return;
			}
			Transform val2 = val.sync___get_value_killer();
			if ((Object)(object)val2 == (Object)null)
			{
				KillHealMod.Log.LogInfo((object)"Killer transform is null (void/suicide death)");
				return;
			}
			PlayerHealth component = ((Component)val2).GetComponent<PlayerHealth>();
			if ((Object)(object)component == (Object)null)
			{
				KillHealMod.Log.LogInfo((object)"No PlayerHealth found on killer transform");
				return;
			}
			if ((Object)(object)component == (Object)(object)val)
			{
				KillHealMod.Log.LogInfo((object)"Killer == victim, skipping");
				return;
			}
			float num = component.sync___get_value_health();
			float num2 = component.fullHealth - num;
			KillHealMod.Log.LogInfo((object)$"Killer health {num}/{component.fullHealth}, deficit {num2}");
			if (num2 > 0f)
			{
				component.RemoveHealth(0f - num2);
				KillHealMod.Log.LogInfo((object)"Healed killer to full");
			}
			if ((Object)(object)component.controller != (Object)null)
			{
				KillHealMod.BoostExpiry[component.controller] = Time.time + KillHealMod.SpeedBoostDuration.Value;
				KillHealMod.Log.LogInfo((object)"Applied speed boost");
			}
			else
			{
				KillHealMod.Log.LogInfo((object)"killerHealth.controller is null, no speed boost applied");
			}
		}
		catch (Exception arg)
		{
			KillHealMod.Log.LogError((object)$"KillHeal patch error: {arg}");
		}
	}
}
[HarmonyPatch(typeof(FirstPersonController), "HandleMovementInput")]
internal static class SpeedBoostPatch
{
	private static readonly FieldInfo dirForwardField = AccessTools.Field(typeof(FirstPersonController), "dirForward");

	private static readonly FieldInfo dirRightField = AccessTools.Field(typeof(FirstPersonController), "dirRight");

	private static void Postfix(FirstPersonController __instance)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (KillHealMod.BoostExpiry.TryGetValue(__instance, out var value))
			{
				if (Time.time < value)
				{
					Vector2 val = (__instance.currentInput = ((Vector2)(ref __instance.currentInput)).normalized * KillHealMod.SpeedBoostMultiplier.Value);
					Vector3 val2 = (Vector3)dirForwardField.GetValue(__instance);
					Vector3 val3 = (Vector3)dirRightField.GetValue(__instance);
					float y = __instance.moveDirection.y;
					__instance.moveDirection = val2 * val.x + val3 * val.y;
					__instance.moveDirection.y = y;
				}
				else
				{
					KillHealMod.BoostExpiry.Remove(__instance);
				}
			}
		}
		catch (Exception arg)
		{
			KillHealMod.Log.LogError((object)$"SpeedBoostPatch error: {arg}");
		}
	}
}
[HarmonyPatch(typeof(FirstPersonController), "OnBeforeSpawn")]
internal static class SpawnClearBoostPatch
{
	private static void Postfix(FirstPersonController __instance)
	{
		KillHealMod.BoostExpiry.Remove(__instance);
	}
}