Decompiled source of Minos Adaptation v1.0.0

plugins/Minos_Adaptation/mahoraga_minos.dll

Decompiled a month 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 Configgy;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("mahoraga_minos")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("mahoraga_minos")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 mahoraga_minos
{
	public class Adaptation : MonoBehaviour
	{
		public float AdaptationAmount = 0f;

		private Machine machine;

		public Animator wheel;

		public bool adapt;

		public bool showadapt;

		public int max;

		public int percentage;

		public float lost;

		private float prevHealth;

		public float newHealth;

		public void Start()
		{
			machine = ((Component)this).GetComponent<Machine>();
			prevHealth = machine.health;
		}

		public void FixedUpdate()
		{
			newHealth = machine.health;
			if (prevHealth > newHealth)
			{
				wheel.Play("Spin");
				if (adapt)
				{
					float num = prevHealth - newHealth;
					float num2 = ((AdaptationAmount > 0f) ? (num * (AdaptationAmount / 100f)) : 0f);
					float num3 = num - num2;
					machine.health = prevHealth - num3;
					Debug.Log((object)$"ADAPTION RESULTS\n  ORIGINAL DAMAGE {num}\n  DAMAGE TAKEN OFF {num2}\n  ADAPTED DAMAGE {num3}\n  HEALTH WITHOUT ADAPTION {prevHealth}\n  NEW HEALTH {machine.health}");
					AdaptationAmount += percentage;
					AdaptationAmount = Mathf.Clamp(AdaptationAmount, 0.01f, (float)max);
				}
			}
			else if (prevHealth == newHealth)
			{
				AdaptationAmount -= lost;
				AdaptationAmount = Mathf.Clamp(AdaptationAmount, 0.01f, (float)max);
			}
			if (showadapt)
			{
				BossHealthBar component = ((Component)this).GetComponent<BossHealthBar>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.secondaryBar = true;
					if (AdaptationAmount != 0f)
					{
						component.secondaryBarValue = AdaptationAmount / (float)max;
					}
					else
					{
						component.secondaryBarValue = 0f;
					}
				}
			}
			prevHealth = newHealth;
		}
	}
	[BepInPlugin("lazy.mehraga", "mahoraga minos", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(EnemyIdentifier), "Start")]
		private class InstantiatePatch
		{
			private static void Postfix(EnemyIdentifier __instance)
			{
				thing(((Component)__instance).gameObject);
			}
		}

		private ConfigBuilder config;

		[Configgable("", "Enable Adaptation", 0, "Disables the function of the wheel, but still keeps the visuals")]
		private static ConfigToggle enableAdaptation = new ConfigToggle(true);

		[Configgable("", "Show Adaptation on Boss Bar (NOT RECCOMENDED)", 0, "Displays the adaptation amount on the boss bar. Can impact performance")]
		private static ConfigToggle showAdaptation = new ConfigToggle(false);

		[Configgable("", "Max Adaptation Amount", 0, "Max amount of damage reduction")]
		private static ConfigSlider<int> maxAdaptation = (ConfigSlider<int>)new IntegerSlider(70, 0, 100);

		[Configgable("", "Adaptation Per Hit", 0, "Adaptation added after getting hit")]
		private static ConfigSlider<int> adapatationAmountPerHit = (ConfigSlider<int>)new IntegerSlider(5, 0, 100);

		[Configgable("", "Adaptation Lost Per Frame", 0, "Every FIXED frame. Gotta specify this so that other modders don't come after me")]
		private static ConfigSlider<float> adapatationLost = (ConfigSlider<float>)new FloatSlider(0.01f, 0f, 3f);

		private void Awake()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			config = new ConfigBuilder("lazy.mehraga", "Mahoraga");
			config.Build();
			Debug.Log((object)"Plugin mahoraga_minos is loaded!");
			Harmony val = new Harmony("com.lazy.mahoraga");
			val.PatchAll();
		}

		private static void thing(GameObject prefab)
		{
			MinosPrime component = prefab.GetComponent<MinosPrime>();
			if ((Object)(object)component != (Object)null)
			{
				Transform val = prefab.transform.Find("Model/Armature.001/Root/Spine01/Spine02/Spine03/Neck/Head/Head_end");
				if ((Object)(object)val != (Object)null)
				{
					Adaptation adaptation = prefab.AddComponent<Adaptation>();
					Animator wheel = AttachItemToBone(val);
					adaptation.adapt = ((ConfigValueElement<bool>)(object)enableAdaptation).Value;
					adaptation.showadapt = ((ConfigValueElement<bool>)(object)showAdaptation).Value;
					adaptation.max = ((ConfigValueElement<int>)(object)maxAdaptation).Value;
					adaptation.lost = ((ConfigValueElement<float>)(object)adapatationLost).Value;
					adaptation.percentage = ((ConfigValueElement<int>)(object)adapatationAmountPerHit).Value;
					adaptation.wheel = wheel;
				}
			}
		}

		private static Animator AttachItemToBone(Transform bone)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mahorag.bundle"));
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			GameObject val2 = val.LoadAsset<GameObject>("Wheel");
			GameObject val3 = Object.Instantiate<GameObject>(val2, bone);
			val3.transform.localPosition = new Vector3(-0.07028385f, 0.1970696f, 0.0004116188f);
			val3.transform.localRotation = Quaternion.Euler(16.885f, -121.503f, -10.094f);
			val.Unload(false);
			return val3.GetComponent<Animator>();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "mahoraga_minos";

		public const string PLUGIN_NAME = "My first plugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}