Decompiled source of PEAKInjuryUncapper v1.0.1

UncappedDamage.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
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("UncappedDamage")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UncappedDamage")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4eaf577e-ad76-41a6-850c-269239eea9b8")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace UncappedDamage;

[BepInPlugin("com.yourname.uncappeddamage", "Uncapped Damage Bar", "1.0.0")]
public class UncappedDamagePlugin : BaseUnityPlugin
{
	public static ManualLogSource Log;

	private void Awake()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		new Harmony("com.yourname.uncappeddamage").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Uncapped Damage loaded!");
	}
}
[HarmonyPatch(typeof(CharacterAfflictions), "GetStatusCap")]
public class UncapStatusCapPatch
{
	private static void Postfix(STATUSTYPE type, ref float __result)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Invalid comparison between Unknown and I4
		if ((int)type == 0)
		{
			__result = float.MaxValue;
		}
	}
}
[HarmonyPatch(typeof(CharacterMovement), "FallFactor")]
public class UncapFallFactorPatch
{
	public static float UncappedLerp(float a, float b, float value)
	{
		if (Mathf.Approximately(a, b))
		{
			return 0f;
		}
		return Mathf.Max(0f, (value - a) / (b - a));
	}

	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo inverseLerpMethod = AccessTools.Method(typeof(Mathf), "InverseLerp", (Type[])null, (Type[])null);
		MethodInfo ourMethod = AccessTools.Method(typeof(UncapFallFactorPatch), "UncappedLerp", (Type[])null, (Type[])null);
		foreach (CodeInstruction instruction in instructions)
		{
			int num;
			if (instruction.opcode == OpCodes.Call)
			{
				object operand = instruction.operand;
				if (operand is MethodInfo mi)
				{
					num = ((mi == inverseLerpMethod) ? 1 : 0);
					goto IL_00ea;
				}
			}
			num = 0;
			goto IL_00ea;
			IL_00ea:
			if (num != 0)
			{
				yield return new CodeInstruction(OpCodes.Call, (object)ourMethod);
			}
			else
			{
				yield return instruction;
			}
		}
	}
}
[HarmonyPatch(typeof(CharacterMovement), "MaxVelDmg")]
public class UncapMaxVelDmgPatch
{
	private static void Postfix(ref float __result)
	{
		__result = float.MaxValue;
	}
}
[HarmonyPatch(typeof(CharacterAfflictions), "AddStatus")]
public class UncapAddStatusFieldPatch
{
	private static void Prefix(CharacterAfflictions __instance, STATUSTYPE statusType, out float __state)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		__state = __instance.currentStatuses[statusType];
	}

	private static void Postfix(CharacterAfflictions __instance, STATUSTYPE statusType, float amount, bool __result, float __state)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Invalid comparison between Unknown and I4
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		if ((int)statusType <= 0 && __result)
		{
			float num = __instance.currentStatuses[statusType];
			float num2 = num - __state;
			if (amount > num2)
			{
				__instance.currentStatuses[statusType] = __state + amount;
			}
		}
	}
}
public class WrapAroundBarState
{
	public List<RectTransform> rowClones = new List<RectTransform>();

	public float baseHeight;

	public Vector2 pivot;
}
[HarmonyPatch(typeof(BarAffliction), "ChangeAffliction")]
public class WrapAroundBarPatch
{
	private static readonly Dictionary<BarAffliction, WrapAroundBarState> states = new Dictionary<BarAffliction, WrapAroundBarState>();

	private const float ROW_CAPACITY = 3f;

	private const int MAX_VISIBLE_ROWS = 5;

	private const float ROW_GAP = 6f;

	private static bool Prefix(BarAffliction __instance, StaminaBar bar)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Invalid comparison between Unknown and I4
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		if ((int)__instance.afflictionType > 0)
		{
			return true;
		}
		if ((Object)(object)Character.observedCharacter == (Object)null)
		{
			return true;
		}
		float currentStatus = Character.observedCharacter.refs.afflictions.GetCurrentStatus(__instance.afflictionType);
		if (currentStatus <= 1f)
		{
			HideExtraRows(__instance);
			return true;
		}
		HandleWrapAround(__instance, bar, currentStatus);
		return false;
	}

	private static void HandleWrapAround(BarAffliction instance, StaminaBar bar, float currentStatus)
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		Transform parent = ((Component)instance).transform.parent.parent;
		RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
		if (!states.TryGetValue(instance, out var value))
		{
			value = new WrapAroundBarState
			{
				baseHeight = instance.rtf.sizeDelta.y,
				pivot = instance.rtf.pivot
			};
			states[instance] = value;
		}
		float x = bar.fullBar.sizeDelta.x;
		float num = 3f * x;
		int num2 = Mathf.FloorToInt(currentStatus / 3f);
		float num3 = currentStatus - (float)num2 * 3f;
		bool flag = num3 > 0.0001f;
		int num4 = (flag ? (num2 + 1) : num2);
		int needed = num4 - 1;
		float num5 = value.baseHeight + 6f;
		if (num4 > 5)
		{
			num5 = (value.baseHeight + 6f) * 5f / (float)num4;
		}
		float size = ((num4 > 1) ? num : (currentStatus * x));
		instance.size = size;
		((Component)instance).gameObject.SetActive(true);
		Vector3[] array = (Vector3[])(object)new Vector3[4];
		instance.rtf.GetWorldCorners(array);
		Vector3 val2 = ((Transform)val).InverseTransformPoint(array[0]);
		EnsureCloneCount(instance, value, val, needed);
		for (int i = 0; i < value.rowClones.Count; i++)
		{
			int num6 = i + 1;
			bool flag2 = num6 < num4;
			((Component)value.rowClones[i]).gameObject.SetActive(flag2);
			if (flag2)
			{
				bool flag3 = num6 == num4 - 1;
				float num7 = ((flag3 && flag) ? (num3 * x) : num);
				if (num7 < bar.minAfflictionWidth)
				{
					num7 = bar.minAfflictionWidth;
				}
				value.rowClones[i].sizeDelta = new Vector2(num7, value.baseHeight);
				float num8 = val2.x + value.pivot.x * num7;
				float num9 = val2.y + (float)num6 * num5 + value.pivot.y * value.baseHeight;
				((Transform)value.rowClones[i]).localPosition = new Vector3(num8, num9, 0f);
			}
		}
	}

	private static void EnsureCloneCount(BarAffliction instance, WrapAroundBarState state, RectTransform barRt, int needed)
	{
		while (state.rowClones.Count < needed)
		{
			GameObject val = Object.Instantiate<GameObject>(((Component)instance).gameObject, (Transform)(object)barRt);
			((Object)val).name = ((Object)((Component)instance).gameObject).name + "_Row" + (state.rowClones.Count + 1);
			BarAffliction component = val.GetComponent<BarAffliction>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			state.rowClones.Add(val.GetComponent<RectTransform>());
		}
	}

	private static void HideExtraRows(BarAffliction instance)
	{
		if (!states.TryGetValue(instance, out var value))
		{
			return;
		}
		foreach (RectTransform rowClone in value.rowClones)
		{
			if ((Object)(object)rowClone != (Object)null)
			{
				((Component)rowClone).gameObject.SetActive(false);
			}
		}
	}
}