Decompiled source of CombatMomentum v1.0.0

CombatMomentum.dll

Decompiled a day ago
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using CombatMomentum.Managers;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CombatMomentum")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ReviOS 11 24.06")]
[assembly: AssemblyProduct("CombatMomentum")]
[assembly: AssemblyCopyright("Copyright © ReviOS 11 24.06 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("85c2ec00-9c79-4aa3-9200-b6989641281f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CombatMomentum
{
	[BepInPlugin("com.senez.combatmomentum", "Combat Momentum", "1.0.0")]
	public class CombatMomentum : BaseUnityPlugin
	{
		public const string ModGUID = "com.senez.combatmomentum";

		public const string ModName = "Combat Momentum";

		public const string ModVersion = "1.0.0";

		public static CombatMomentum Instance;

		public static string AssetPath = Path.Combine(Paths.PluginPath, "CombatMomentum", "Assets");

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			string[] manifestResourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
			foreach (string text in manifestResourceNames)
			{
				Log.LogInfo((object)("RESOURCE: " + text));
			}
			_harmony = new Harmony("com.senez.combatmomentum");
			_harmony.PatchAll();
			Log.LogInfo((object)"========================================");
			Log.LogInfo((object)"Combat Momentum v1.0.0 loaded!");
			Log.LogInfo((object)"Combat Momentum initialized successfully.");
			Log.LogInfo((object)"========================================");
		}

		private void Update()
		{
			MomentumManager.Update(Time.deltaTime);
		}
	}
	public static class EmbeddedAssets
	{
		public static Sprite LoadSprite(string name)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string text = null;
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			foreach (string text2 in manifestResourceNames)
			{
				if (text2.EndsWith(name))
				{
					text = text2;
					break;
				}
			}
			if (text == null)
			{
				CombatMomentum.Log.LogError((object)("Resource not found: " + name));
				return null;
			}
			using Stream stream = executingAssembly.GetManifestResourceStream(text);
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}
	}
}
namespace CombatMomentum.Patches
{
	[HarmonyPatch(typeof(Hud), "Update")]
	public static class HudPatch
	{
		private static GameObject _panel;

		private static Text _title;

		private static Text _damage;

		private static Text _speedText;

		private static Text _timeText;

		private static Image _timerFill;

		private static List<Image> _runes = new List<Image>();

		private static List<Outline> _runeOutlines = new List<Outline>();

		private static int _lastRuneCount = 0;

		private static float _runeFlash = 0f;

		private static int _lastStacks = 0;

		private static float _pulseTimer = 0f;

		private static float _runePulse = 0f;

		private static float _maxPulse = 0f;

		private static Sprite _whiteSprite;

		private static Color _gold = new Color(1f, 0.75f, 0.25f, 1f);

		private static Color _orange = new Color(1f, 0.45f, 0.1f, 1f);

		private static Color _red = new Color(1f, 0.15f, 0.05f, 1f);

		private static void Postfix(Hud __instance)
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			if ((Object)(object)_panel == (Object)null)
			{
				CreateUI(__instance);
				CreateTopLine();
			}
			int current = MomentumManager.Current;
			if (current <= 0)
			{
				_panel.SetActive(false);
				_lastStacks = 0;
				return;
			}
			_panel.SetActive(true);
			_runePulse += Time.deltaTime;
			_maxPulse += Time.deltaTime;
			UpdateRunes(current);
			_damage.text = "+" + current * 10 + "% DAMAGE";
			_speedText.text = "+" + current * 8 + "% SPEED";
			if (current == 5)
			{
				((Graphic)_title).color = Color.Lerp(Color.yellow, Color.red, Mathf.PingPong(Time.time, 1f));
			}
			else
			{
				((Graphic)_title).color = Color.white;
			}
			float timeRemaining = MomentumManager.TimeRemaining;
			_timeText.text = timeRemaining.ToString("0.0") + "s";
			float num = timeRemaining / MomentumManager.MaxTime;
			float x = ((Transform)((Graphic)_timerFill).rectTransform).localScale.x;
			float num2 = Mathf.Lerp(x, num, Time.deltaTime * 8f);
			((Transform)((Graphic)_timerFill).rectTransform).localScale = new Vector3(num2, 1f, 1f);
			if (current > _lastStacks)
			{
				_pulseTimer = 0.25f;
			}
			_lastStacks = current;
			if (_pulseTimer > 0f)
			{
				_pulseTimer -= Time.deltaTime;
				float num3 = 1f + _pulseTimer;
				_panel.transform.localScale = Vector3.one * num3;
			}
			else
			{
				_panel.transform.localScale = Vector3.one;
			}
		}

		private static void UpdateRunes(int stacks)
		{
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			if (stacks > _lastRuneCount)
			{
				_runeFlash = 0.35f;
			}
			_lastRuneCount = stacks;
			if (_runeFlash > 0f)
			{
				_runeFlash -= Time.deltaTime;
			}
			float num = 1f + Mathf.Sin(_runePulse * 4f) * 0.05f;
			for (int i = 0; i < _runes.Count; i++)
			{
				if (i < stacks)
				{
					Color val = _gold;
					if (stacks >= 3)
					{
						val = _orange;
					}
					if (stacks == 5)
					{
						val = Color.Lerp(_orange, _red, Mathf.PingPong(_maxPulse, 1f));
					}
					((Graphic)_runes[i]).color = val;
					((Shadow)_runeOutlines[i]).effectColor = new Color(val.r, val.g, val.b, 0.8f);
					((Component)_runes[i]).transform.localScale = Vector3.one * num;
					if (_runeFlash > 0f)
					{
						float num2 = 1f + _runeFlash * 2f;
						((Component)_runes[i]).transform.localScale = Vector3.one * num2;
					}
				}
				else
				{
					((Graphic)_runes[i]).color = new Color(0.12f, 0.12f, 0.12f, 1f);
					((Component)_runes[i]).transform.localScale = Vector3.one;
				}
			}
		}

		private static void CreateTopLine()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("TopLine");
			val.transform.SetParent(_panel.transform, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.sizeDelta = new Vector2(240f, 2f);
			val2.anchoredPosition = new Vector2(0f, 55f);
			Image val3 = val.AddComponent<Image>();
			((Graphic)val3).color = new Color(1f, 0.65f, 0.2f, 0.8f);
		}

		private static void CreateRunes()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			_runes.Clear();
			for (int i = 0; i < 5; i++)
			{
				GameObject val = new GameObject("Rune_" + i);
				val.transform.SetParent(_panel.transform, false);
				RectTransform val2 = val.AddComponent<RectTransform>();
				val2.sizeDelta = new Vector2(16f, 16f);
				val2.anchoredPosition = new Vector2((float)(-48 + i * 24), 5f);
				((Transform)val2).localRotation = Quaternion.Euler(0f, 0f, 45f);
				Image val3 = val.AddComponent<Image>();
				val3.sprite = GetWhiteSprite();
				((Graphic)val3).color = new Color(0.12f, 0.12f, 0.12f, 1f);
				Outline val4 = val.AddComponent<Outline>();
				_runeOutlines.Add(val4);
				((Shadow)val4).effectColor = new Color(0f, 0f, 0f, 0.7f);
				((Shadow)val4).effectDistance = new Vector2(1f, -1f);
				_runes.Add(val3);
			}
		}

		private static Sprite GetWhiteSprite()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			if ((Object)(object)_whiteSprite != (Object)null)
			{
				return _whiteSprite;
			}
			Texture2D val = new Texture2D(1, 1);
			val.SetPixel(0, 0, Color.white);
			val.Apply();
			_whiteSprite = Sprite.Create(val, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f));
			return _whiteSprite;
		}

		private static void CreateUI(Hud hud)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: 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_01f2: Expected O, but got Unknown
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Expected O, but got Unknown
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			_panel = new GameObject("CombatMomentumHUD");
			_panel.transform.SetParent(((Component)hud).transform, false);
			RectTransform val = _panel.AddComponent<RectTransform>();
			val.anchorMin = new Vector2(0f, 0f);
			val.anchorMax = new Vector2(0f, 0f);
			val.pivot = new Vector2(0f, 0f);
			val.anchoredPosition = new Vector2(260f, 70f);
			val.sizeDelta = new Vector2(240f, 120f);
			GameObject val2 = new GameObject("Background");
			val2.transform.SetParent(_panel.transform, false);
			RectTransform val3 = val2.AddComponent<RectTransform>();
			val3.anchorMin = Vector2.zero;
			val3.anchorMax = Vector2.one;
			val3.offsetMin = Vector2.zero;
			val3.offsetMax = Vector2.zero;
			Image val4 = val2.AddComponent<Image>();
			((Graphic)val4).color = new Color(0.015f, 0.012f, 0.008f, 0.85f);
			Outline val5 = val2.AddComponent<Outline>();
			((Shadow)val5).effectColor = new Color(1f, 0.65f, 0.2f, 0.6f);
			((Shadow)val5).effectDistance = new Vector2(2f, 2f);
			_title = CreateText("⚔ MOMENTUM", 18, new Vector2(0f, 35f));
			CreateRunes();
			_damage = CreateText("+0% DAMAGE", 16, new Vector2(0f, -20f));
			_speedText = CreateText("+0% SPEED", 14, new Vector2(0f, -38f));
			_timeText = CreateText("10s", 14, new Vector2(85f, -25f));
			GameObject val6 = new GameObject("TimerBar");
			val6.transform.SetParent(_panel.transform, false);
			RectTransform val7 = val6.AddComponent<RectTransform>();
			val7.sizeDelta = new Vector2(170f, 6f);
			val7.anchoredPosition = new Vector2(0f, -55f);
			Image val8 = val6.AddComponent<Image>();
			((Graphic)val8).color = new Color(0.15f, 0.15f, 0.15f, 1f);
			GameObject val9 = new GameObject("Fill");
			val9.transform.SetParent(val6.transform, false);
			RectTransform val10 = val9.AddComponent<RectTransform>();
			val10.anchorMin = Vector2.zero;
			val10.anchorMax = Vector2.one;
			val10.offsetMin = Vector2.zero;
			val10.offsetMax = Vector2.zero;
			_timerFill = val9.AddComponent<Image>();
			_timerFill.sprite = GetWhiteSprite();
			((Graphic)_timerFill).color = new Color(1f, 0.7f, 0.2f, 1f);
		}

		private static Text CreateText(string value, int size, Vector2 position)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Text");
			val.transform.SetParent(_panel.transform, false);
			Text val2 = val.AddComponent<Text>();
			val2.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			val2.fontSize = size;
			val2.text = value;
			val2.alignment = (TextAnchor)4;
			((Graphic)val2).color = Color.white;
			Shadow val3 = val.AddComponent<Shadow>();
			val3.effectColor = Color.black;
			val3.effectDistance = new Vector2(1f, -1f);
			RectTransform component = ((Component)val2).GetComponent<RectTransform>();
			component.sizeDelta = new Vector2(220f, 25f);
			component.anchoredPosition = position;
			return val2;
		}
	}
	[HarmonyPatch(typeof(HitData))]
	public static class MomentumAttackPatch
	{
		[HarmonyPatch("GetTotalDamage")]
		[HarmonyPostfix]
		private static void Postfix(HitData __instance, ref float __result)
		{
			Character attacker = __instance.GetAttacker();
			if ((Object)(object)attacker != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			int current = MomentumManager.Current;
			if (current > 0)
			{
				float num = 1f + (float)current * 0.1f;
				__result *= num;
				if (current >= 5 && Random.value <= 0.2f)
				{
					__result *= 2f;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid))]
	public static class MomentumAttackAnimationPatch
	{
		[HarmonyPatch("UpdateAttack")]
		[HarmonyPostfix]
		private static void Postfix(Humanoid __instance)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			ZSyncAnimation componentInChildren = ((Component)__instance).GetComponentInChildren<ZSyncAnimation>();
			if (!((Object)(object)componentInChildren == (Object)null))
			{
				int current = MomentumManager.Current;
				if (current <= 0)
				{
					componentInChildren.SetSpeed(1f);
				}
				else if (((Character)__instance).InAttack())
				{
					float speed = 1f + (float)current * 0.08f;
					componentInChildren.SetSpeed(speed);
				}
				else
				{
					componentInChildren.SetSpeed(1f);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "BlockAttack")]
	public static class PerfectParryPatch
	{
		private static FieldInfo blockTimerField = AccessTools.Field(typeof(Humanoid), "m_blockTimer");

		private static void Postfix(Humanoid __instance, HitData hit, Character attacker, bool __result)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (__result && !((Object)(object)attacker == (Object)null) && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !(blockTimerField == null))
			{
				float num = (float)blockTimerField.GetValue(__instance);
				if (num != -1f && num < 0.25f)
				{
					MomentumManager.AddStack();
					attacker.Stagger(-hit.m_dir);
				}
			}
		}
	}
}
namespace CombatMomentum.Managers
{
	public static class MomentumManager
	{
		private static float _timer;

		private const int MaxStacks = 5;

		private const float StackDuration = 10f;

		private static int _stacks;

		public static int Stacks => _stacks;

		public static float MaxTime => 10f;

		public static float TimeRemaining => _timer;

		public static int Current => _stacks;

		public static void AddStack()
		{
			if (_stacks < 5)
			{
				_stacks++;
			}
			_timer = 10f;
		}

		public static void RemoveStack()
		{
			if (_stacks > 0)
			{
				_stacks--;
			}
		}

		public static void Reset()
		{
			_stacks = 0;
			_timer = 0f;
		}

		public static void Update(float deltaTime)
		{
			if (_stacks > 0)
			{
				_timer -= deltaTime;
				if (_timer <= 0f)
				{
					RemoveStack();
					_timer = 10f;
				}
			}
		}
	}
}