Decompiled source of HunkMomentumPassive v1.0.0

HunkMomentumPassive.dll

Decompiled a week ago
using System;
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 BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using R2API;
using R2API.Utils;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HunkMomentumPassive")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HunkMomentumPassive")]
[assembly: AssemblyTitle("HunkMomentumPassive")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HunkMomentumPassive
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.kotme.hunkmomentumpassive", "Hunk Momentum Passive", "1.0.0")]
	public class HunkMomentumPassivePlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.kotme.hunkmomentumpassive";

		public const string PluginName = "Hunk Momentum Passive";

		public const string PluginVersion = "1.0.0";

		public static BuffDef HunkMomentumBuff;

		public static Sprite BuffIconSprite;

		public static ConfigEntry<float> CfgSecondsPerStack;

		public static ConfigEntry<int> CfgMaxStacks;

		public static ConfigEntry<float> CfgMoveSpeedPerStackPercent;

		public static ConfigEntry<float> CfgSprintSpeedPerStackPercent;

		public static ConfigEntry<bool> CfgInstantResetOnStop;

		public static ConfigEntry<float> CfgDecayInterval;

		public static ConfigEntry<bool> CfgApplyToAllSurvivors;

		private void Awake()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			SetupConfig();
			CreateBuff();
			CharacterBody.onBodyStartGlobal += OnBodyStartGlobal;
			RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(OnGetStatCoefficients);
			TryGenerateThunderstoreIconFile();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Hunk Momentum Passive v1.0.0 loaded successfully!");
		}

		private void OnDestroy()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			CharacterBody.onBodyStartGlobal -= OnBodyStartGlobal;
			RecalculateStatsAPI.GetStatCoefficients -= new StatHookEventHandler(OnGetStatCoefficients);
		}

		private void SetupConfig()
		{
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			CfgSecondsPerStack = ((BaseUnityPlugin)this).Config.Bind<float>("Momentum Passive", "Seconds Per Stack", 0.35f, "Seconds of continuous sprinting required to gain 1 stack of Momentum.");
			CfgMaxStacks = ((BaseUnityPlugin)this).Config.Bind<int>("Momentum Passive", "Max Stacks", 100, "Maximum number of Momentum stacks that can be accumulated.");
			CfgMoveSpeedPerStackPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Momentum Passive", "Move Speed Per Stack (%)", 1f, "Base movement speed bonus per stack in percent (e.g., 1.0 = +1% per stack, +100% at 100 stacks).");
			CfgSprintSpeedPerStackPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Momentum Passive", "Sprint Speed Per Stack (%)", 0.5f, "Additional sprint speed multiplier bonus per stack in percent.");
			CfgInstantResetOnStop = ((BaseUnityPlugin)this).Config.Bind<bool>("Momentum Passive", "Instant Reset On Stop", false, "If true, all stacks are lost immediately when stopping sprint. If false, stacks decay gradually.");
			CfgDecayInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Momentum Passive", "Decay Interval (Seconds)", 0.15f, "How fast stacks decay one by one when not sprinting (if Instant Reset is false).");
			CfgApplyToAllSurvivors = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Apply To All Survivors", false, "If false, the passive only applies to HUNK. If true, it applies to any player-controlled survivor.");
			BuffIconSprite = CreateProceduralIcon(64, new Color(0.9f, 0.15f, 0.15f), new Color(0.15f, 0.15f, 0.18f));
			if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				SetupRiskOfOptions();
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private void SetupRiskOfOptions()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_006f: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			//IL_010f: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Expected O, but got Unknown
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Expected O, but got Unknown
			ModSettingsManager.SetModDescription("Adds a customizable sprinting momentum passive for HUNK.", "com.kotme.hunkmomentumpassive", "Hunk Momentum Passive");
			if ((Object)(object)BuffIconSprite != (Object)null)
			{
				ModSettingsManager.SetModIcon(BuffIconSprite, "com.kotme.hunkmomentumpassive", "Hunk Momentum Passive");
			}
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(CfgSecondsPerStack, new StepSliderConfig
			{
				min = 0.05f,
				max = 3f,
				increment = 0.05f
			}));
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(CfgMaxStacks, new IntSliderConfig
			{
				min = 10,
				max = 500
			}));
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(CfgMoveSpeedPerStackPercent, new StepSliderConfig
			{
				min = 0.1f,
				max = 10f,
				increment = 0.1f
			}));
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(CfgSprintSpeedPerStackPercent, new StepSliderConfig
			{
				min = 0f,
				max = 10f,
				increment = 0.1f
			}));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(CfgInstantResetOnStop));
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(CfgDecayInterval, new StepSliderConfig
			{
				min = 0.05f,
				max = 2f,
				increment = 0.05f
			}));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(CfgApplyToAllSurvivors));
		}

		private void CreateBuff()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			HunkMomentumBuff = ScriptableObject.CreateInstance<BuffDef>();
			((Object)HunkMomentumBuff).name = "bdHunkMomentum";
			HunkMomentumBuff.buffColor = new Color(0.95f, 0.2f, 0.2f);
			HunkMomentumBuff.canStack = true;
			HunkMomentumBuff.isDebuff = false;
			HunkMomentumBuff.iconSprite = BuffIconSprite;
			ContentAddition.AddBuffDef(HunkMomentumBuff);
		}

		public static bool IsEligibleBody(CharacterBody body)
		{
			if ((Object)(object)body == (Object)null)
			{
				return false;
			}
			if (CfgApplyToAllSurvivors.Value)
			{
				return body.isPlayerControlled;
			}
			string obj = ((Object)body).name ?? string.Empty;
			string text = body.baseNameToken ?? string.Empty;
			if (obj.IndexOf("Hunk", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return text.IndexOf("HUNK", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return true;
		}

		private void OnBodyStartGlobal(CharacterBody body)
		{
			if (NetworkServer.active && !((Object)(object)body == (Object)null) && IsEligibleBody(body) && (Object)(object)((Component)body).gameObject.GetComponent<HunkMomentumTracker>() == (Object)null)
			{
				((Component)body).gameObject.AddComponent<HunkMomentumTracker>();
			}
		}

		private void OnGetStatCoefficients(CharacterBody sender, StatHookEventArgs args)
		{
			if (!((Object)(object)sender == (Object)null) && !((Object)(object)HunkMomentumBuff == (Object)null))
			{
				int buffCount = sender.GetBuffCount(HunkMomentumBuff);
				if (buffCount > 0)
				{
					args.moveSpeedMultAdd += (float)buffCount * (CfgMoveSpeedPerStackPercent.Value * 0.01f);
					args.sprintSpeedAdd += (float)buffCount * (CfgSprintSpeedPerStackPercent.Value * 0.01f);
				}
			}
		}

		private static Sprite CreateProceduralIcon(int size, Color mainColor, Color bgColor)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_014d: 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)
			//IL_003e: 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_0054: 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)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor((float)size * 0.5f, (float)size * 0.5f);
			float num = (float)size * 0.44f;
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num2 = Vector2.Distance(new Vector2((float)j, (float)i), val2);
					if (num2 > num)
					{
						val.SetPixel(j, i, Color.clear);
						continue;
					}
					if (num2 > num - (float)size * 0.06f)
					{
						val.SetPixel(j, i, mainColor);
						continue;
					}
					float num3 = (float)j / (float)size;
					float num4 = (float)i / (float)size;
					float num5 = Mathf.Abs(num4 - 0.5f) - (0.55f - num3) * 0.8f;
					float num6 = Mathf.Abs(num4 - 0.5f) - (0.78f - num3) * 0.8f;
					bool flag = (Mathf.Abs(num5) < 0.06f && num3 > 0.25f && num3 < 0.55f) || (Mathf.Abs(num6) < 0.06f && num3 > 0.48f && num3 < 0.78f);
					val.SetPixel(j, i, flag ? mainColor : bgColor);
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, (float)size, (float)size), new Vector2(0.5f, 0.5f));
		}

		private void TryGenerateThunderstoreIconFile()
		{
			//IL_0045: 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)
			try
			{
				string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
				if (!string.IsNullOrEmpty(directoryName))
				{
					string text = Path.Combine(directoryName, "icon.png");
					if (!File.Exists(text))
					{
						byte[] bytes = ImageConversion.EncodeToPNG(CreateProceduralIcon(256, new Color(0.9f, 0.15f, 0.15f), new Color(0.12f, 0.12f, 0.15f)).texture);
						File.WriteAllBytes(text, bytes);
						((BaseUnityPlugin)this).Logger.LogInfo((object)("Сгенерирована иконка 256x256 для Thunderstore: " + text));
					}
				}
			}
			catch
			{
			}
		}
	}
	public class HunkMomentumTracker : MonoBehaviour
	{
		private CharacterBody body;

		private CharacterMotor motor;

		private float gainTimer;

		private float decayTimer;

		private float stopGraceTimer;

		private void Awake()
		{
			body = ((Component)this).GetComponent<CharacterBody>();
			motor = ((Component)this).GetComponent<CharacterMotor>();
		}

		private void FixedUpdate()
		{
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active || (Object)(object)body == (Object)null)
			{
				return;
			}
			bool flag = (Object)(object)motor == (Object)null || ((Vector3)(ref motor.velocity)).sqrMagnitude > 0.5f;
			bool num = body.isSprinting && flag;
			int buffCount = body.GetBuffCount(HunkMomentumPassivePlugin.HunkMomentumBuff);
			int value = HunkMomentumPassivePlugin.CfgMaxStacks.Value;
			if (num)
			{
				stopGraceTimer = 0f;
				decayTimer = 0f;
				gainTimer += Time.fixedDeltaTime;
				float num2 = Mathf.Max(0.05f, HunkMomentumPassivePlugin.CfgSecondsPerStack.Value);
				if (gainTimer >= num2)
				{
					gainTimer -= num2;
					if (buffCount < value)
					{
						body.SetBuffCount(HunkMomentumPassivePlugin.HunkMomentumBuff.buffIndex, buffCount + 1);
					}
				}
				return;
			}
			gainTimer = 0f;
			if (buffCount <= 0)
			{
				return;
			}
			stopGraceTimer += Time.fixedDeltaTime;
			if (stopGraceTimer < 0.25f)
			{
				return;
			}
			if (HunkMomentumPassivePlugin.CfgInstantResetOnStop.Value)
			{
				body.SetBuffCount(HunkMomentumPassivePlugin.HunkMomentumBuff.buffIndex, 0);
				return;
			}
			decayTimer += Time.fixedDeltaTime;
			float num3 = Mathf.Max(0.05f, HunkMomentumPassivePlugin.CfgDecayInterval.Value);
			if (decayTimer >= num3)
			{
				decayTimer -= num3;
				body.SetBuffCount(HunkMomentumPassivePlugin.HunkMomentumBuff.buffIndex, buffCount - 1);
			}
		}
	}
}