Decompiled source of DanielSteginkUtils v4.1.1

DanielSteginkUtils.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using DanielSteginkUtils.Loggers;
using HarmonyLib;
using HutongGames.PlayMaker;
using HutongGames.PlayMaker.Actions;
using Microsoft.CodeAnalysis;
using UnityEngine;
using WavLib;

[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("DanielSteginkUtils")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("This is a library of custom helpers and logic for Hollow Knight: Silksong mods.")]
[assembly: AssemblyFileVersion("4.1.1.0")]
[assembly: AssemblyInformationalVersion("4.1.1+915a4aece66c829458cac1ec73d494f3f2b7a37f")]
[assembly: AssemblyProduct("DanielSteginkUtils")]
[assembly: AssemblyTitle("DanielSteginkUtils")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/danielstegink/Silksong.DanielSteginkUtils")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("4.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace DanielSteginkUtils
{
	[BepInPlugin("io.github.danielstegink.danielsteginkutils", "DanielSteginkUtils", "4.1.1")]
	public class DanielSteginkUtils : BaseUnityPlugin
	{
		public const string Id = "io.github.danielstegink.danielsteginkutils";

		internal static DanielSteginkUtils Instance { get; private set; }

		public static string Name => "DanielSteginkUtils";

		public static string Version => "4.1.1";

		private void Awake()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			new Harmony("io.github.danielstegink.danielsteginkutils").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + Name + " (io.github.danielstegink.danielsteginkutils) has loaded!"));
		}

		internal void Log(string message)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)message);
		}
	}
}
namespace DanielSteginkUtils.Utilities
{
	public static class Calculations
	{
		public static float GetSilkPerSoul()
		{
			float num = 99f;
			return 9f / num;
		}
	}
	public static class ClassIntegrations
	{
		public static O GetField<I, O>(I? input, string fieldName, BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
		{
			return (O)typeof(I).GetField(fieldName, flags).GetValue(input);
		}

		public static void SetField<I>(I? input, string fieldName, object value, BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
		{
			typeof(I).GetField(fieldName, flags).SetValue(input, value);
		}

		public static O GetProperty<I, O>(I? input, string fieldName, BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
		{
			return (O)typeof(I).GetProperty(fieldName, flags).GetValue(input);
		}

		public static void SetProperty<I>(I? input, string fieldName, object value, BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
		{
			typeof(I).GetProperty(fieldName, flags).SetValue(input, value);
		}

		public static O CallFunction<I, O>(I? input, string fieldName, object[] parameters, BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
		{
			return (O)typeof(I).GetMethod(fieldName, flags).Invoke(input, parameters);
		}
	}
	public static class Components
	{
		public static void RemoveComponent<T>(this GameObject gameObject) where T : Component
		{
			T component = gameObject.GetComponent<T>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
		}
	}
	public static class NotchCosts
	{
		public static float NailDamagePerNotch()
		{
			return 0.5f / (float)UnbreakableCharmCost(3);
		}

		public static float SpellDamagePerNotch()
		{
			return 1f / 6f;
		}

		public static float SingleSpellDamagePerNotch()
		{
			return 3f * SpellDamagePerNotch();
		}

		public static float SpellDiscountPerNotch()
		{
			return 0f;
		}

		public static float PassiveHealTime()
		{
			return 10f * 4f;
		}

		public static float PassiveSilkTime()
		{
			return 0.5f * 5f / Calculations.GetSilkPerSoul();
		}

		public static int UnbreakableCharmCost(int baseCost)
		{
			return baseCost + 2;
		}
	}
}
namespace DanielSteginkUtils.Loggers
{
	[HarmonyPatch(typeof(HealthManager), "TakeDamage")]
	public static class EnemyDamageLogger
	{
		private static bool isActive;

		[HarmonyPrefix]
		internal static void Prefix(HealthManager __instance, HitInstance hitInstance)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			if (isActive && (Object)(object)hitInstance.Source != (Object)null)
			{
				Logging.Log("EnemyDamageLogger", $"Enemy {((Object)((Component)__instance).gameObject).name} taking {hitInstance.DamageDealt} damage (Type {hitInstance.AttackType}) from {((Object)hitInstance.Source).name}", performLogging: true);
			}
		}

		public static void Toggle(bool isActive)
		{
			EnemyDamageLogger.isActive = isActive;
		}
	}
	internal static class Logging
	{
		internal static void Log(string prefix, string message, bool performLogging = false)
		{
			if (performLogging)
			{
				DanielSteginkUtils.Instance.Log(prefix + " - " + message);
			}
		}
	}
}
namespace DanielSteginkUtils.Helpers
{
	public static class DamageEnemy
	{
		public static void DealDamage(HealthManager enemy, int amount, AttackTypes attackType, string attackName)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(attackName);
			DealDamage(enemy, amount, attackType, val);
			Object.Destroy((Object)(object)val);
		}

		public static void DealDamage(HealthManager enemy, int amount, AttackTypes attackType, GameObject attacker)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			HitInstance val = default(HitInstance);
			val.DamageDealt = amount;
			val.AttackType = attackType;
			val.IgnoreInvulnerable = true;
			val.Source = attacker;
			val.Multiplier = 1f;
			HitInstance val2 = val;
			enemy.Hit(val2);
		}
	}
	public static class GetEnemy
	{
		public static List<GameObject> GetEnemies(float maxDistance)
		{
			GameObject[] array = (from x in Object.FindObjectsByType<GameObject>((FindObjectsSortMode)0)
				where x.activeSelf
				select x).ToArray();
			if (array.Length == 0)
			{
				return new List<GameObject>();
			}
			GameObject[] array2 = array.Where((GameObject x) => IsEnemy(x)).ToArray();
			if (array2.Length == 0)
			{
				return new List<GameObject>();
			}
			Transform playerPosition = ((Component)HeroController.instance).gameObject.transform;
			return array2.Where((GameObject x) => GetDistance(x.transform, playerPosition) <= maxDistance).ToList();
		}

		public static bool IsEnemy(GameObject gameObject)
		{
			bool result = false;
			if ((gameObject.layer == 11 || gameObject.tag == "Boss") && (Object)(object)gameObject.GetComponent<HealthManager>() != (Object)null)
			{
				result = true;
			}
			return result;
		}

		public static float GetDistance(Transform enemy, Transform player)
		{
			float num = Math.Abs(Extensions.GetPositionX(enemy) - Extensions.GetPositionX(player));
			float num2 = Math.Abs(Extensions.GetPositionY(enemy) - Extensions.GetPositionY(player));
			return (float)Math.Sqrt(num * num + num2 * num2);
		}
	}
	public static class GetTools
	{
		public static List<string> GetEquippedTools()
		{
			List<string> list = new List<string>();
			foreach (ToolItem item in ToolItemManager.GetUnlockedTools().ToList())
			{
				if (((ToolBase)item).IsEquipped)
				{
					list.Add(item.name);
				}
			}
			return list;
		}
	}
	[HarmonyPatch(typeof(Fsm), "Awake")]
	public static class Needolin
	{
		public static Fsm? NeedolinFsm { get; private set; }

		public static AudioClip? DefaultClip { get; private set; }

		public static AudioClip? NewDefaultClip { get; private set; }

		public static AudioClip? CurrentClip { get; private set; }

		[HarmonyPostfix]
		private static void GetNeedolinFsm(Fsm __instance)
		{
			if (__instance.name.Equals("FSM") && __instance.GameObjectName.Equals("Hero_Hornet(Clone)") && GetNeedolinState(__instance) != null)
			{
				NeedolinFsm = __instance;
				CacheDefaultAudioClip(NeedolinFsm);
			}
		}

		public static FsmState? GetNeedolinState(Fsm needolinFsm)
		{
			FsmState val = needolinFsm.GetState("Start Needolin Proper");
			if (val == null)
			{
				val = null;
			}
			return val;
		}

		private static void CacheDefaultAudioClip(Fsm needolinFsm, bool performLogging = false)
		{
			//IL_0023: 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)
			//IL_003c: Expected O, but got Unknown
			FsmState needolinState = GetNeedolinState(needolinFsm);
			if (needolinState == null)
			{
				Logging.Log("CacheDefaultAudioClip", "Error getting FSM state", performLogging);
				return;
			}
			DefaultClip = (AudioClip)((StartNeedolinAudioLoop)needolinState.Actions[6]).DefaultClip.Value;
			Logging.Log("CacheDefaultAudioClip", "Default clip set: " + ((Object)DefaultClip).name, performLogging);
		}

		public static void SetNewDefaultClip(AudioClip audioClip)
		{
			NewDefaultClip = audioClip;
		}

		public static void SetNewAudioClip(Fsm needolinFsm, AudioClip audioClip, bool performLogging = false)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0048: Expected O, but got Unknown
			FsmState needolinState = GetNeedolinState(needolinFsm);
			if (needolinState == null)
			{
				Logging.Log("SetNewAudioClip", "Error getting FSM state", performLogging);
				return;
			}
			StartNeedolinAudioLoop val = (StartNeedolinAudioLoop)needolinState.Actions[6];
			val.DefaultClip.value = (Object)(object)audioClip;
			CurrentClip = (AudioClip)val.DefaultClip.value;
			Logging.Log("SetNewAudioClip", "New clip set: " + ((Object)CurrentClip).name, performLogging);
		}

		public static void ResetAudioClip(Fsm needolinFsm, bool useNewDefault, bool performLogging = false)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_004d: Expected O, but got Unknown
			FsmState needolinState = GetNeedolinState(needolinFsm);
			if (needolinState == null)
			{
				Logging.Log("ResetAudioClip", "Error getting FSM state", performLogging);
				return;
			}
			StartNeedolinAudioLoop val = (StartNeedolinAudioLoop)needolinState.Actions[6];
			val.DefaultClip.value = (Object)(object)GetDefaultClip(useNewDefault);
			CurrentClip = (AudioClip)val.DefaultClip.value;
			Logging.Log("ResetAudioClip", "Clip reset: " + ((Object)CurrentClip).name, performLogging);
		}

		public static AudioClip? GetDefaultClip(bool useNewDefault)
		{
			if (useNewDefault && (Object)(object)NewDefaultClip != (Object)null)
			{
				return NewDefaultClip;
			}
			return DefaultClip;
		}
	}
}
namespace DanielSteginkUtils.ExternalFiles
{
	public static class GetAssetBundle
	{
		public static AssetBundle? GetBundle(string path, bool performLogging = false)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			string streamingAssetsPath = Application.streamingAssetsPath;
			RuntimePlatform platform = Application.platform;
			string text = (((int)platform == 1) ? "StandaloneOSX" : (((int)platform == 2) ? "StandaloneWindows64" : (((int)platform != 13) ? "" : "StandaloneLinux64")));
			string path2 = text;
			AssetBundle obj = AssetBundle.LoadFromFile(Path.Combine(Path.Combine(streamingAssetsPath, "aa", path2), path));
			if ((Object)(object)obj == (Object)null)
			{
				Logging.Log("GetBundle", "Error loading bundle " + path, performLogging);
			}
			return obj;
		}
	}
	public static class GetAudioClip
	{
		[Obsolete("This method is deprecated. Pass in the Assembly instead.")]
		public static AudioClip? GetAudioClipFromAssembly(string assemblyName, string fileName, bool performLogging = false)
		{
			string prefix = "GetAudioClipFromAssembly";
			Logging.Log(prefix, "Getting " + fileName + " from assembly", performLogging);
			Assembly assembly = Assembly.Load(assemblyName);
			if (assembly == null)
			{
				Logging.Log(prefix, "Assembly '" + assemblyName + "' not found", performLogging);
				return null;
			}
			return GetAudioClipFromAssembly(assembly, fileName, performLogging);
		}

		public static AudioClip? GetAudioClipFromAssembly(Assembly assembly, string fileName, bool performLogging = false)
		{
			using Stream stream = assembly.GetManifestResourceStream(fileName ?? "");
			if (stream == null)
			{
				Logging.Log("GetAudioClipFromAssembly", "Embedded resource '" + fileName + "' not found", performLogging);
				return null;
			}
			return GetAudioClipFromStream(stream, fileName, performLogging);
		}

		public static AudioClip? GetAudioClipFromStream(Stream stream, string clipName, bool performLogging = false)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			string prefix = "GetAudioClipFromStream";
			WavData val = new WavData();
			if (!val.Parse(stream, (Action<string>)null))
			{
				Logging.Log(prefix, "Unable to parse '" + clipName + "' into WAV data", performLogging);
				return null;
			}
			float[] samples = val.GetSamples();
			int num = samples.Length / val.FormatChunk.NumChannels;
			int numChannels = val.FormatChunk.NumChannels;
			int sampleRate = (int)val.FormatChunk.SampleRate;
			AudioClip obj = AudioClip.Create(clipName, num, numChannels, sampleRate, false);
			obj.SetData(samples, 0);
			Object.DontDestroyOnLoad((Object)(object)obj);
			Logging.Log(prefix, "'" + clipName + "' converted to AudioClip", performLogging);
			return obj;
		}
	}
	public static class GetSprite
	{
		[Obsolete("This method is deprecated. Pass in the Assembly instead.")]
		public static Sprite? GetLocalSprite(string filePath, string assemblyName, bool performLogging = false)
		{
			string prefix = "GetSprite";
			Logging.Log(prefix, "Getting sprite " + filePath + " in assembly '" + assemblyName + "'", performLogging);
			Assembly assembly = Assembly.Load(assemblyName);
			if (assembly == null)
			{
				Logging.Log(prefix, "Assembly '" + assemblyName + "' not found");
				return null;
			}
			return GetLocalSprite(filePath, assembly, performLogging);
		}

		public static Sprite? GetLocalSprite(string filePath, Assembly assembly, bool performLogging = false)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			string[] manifestResourceNames = assembly.GetManifestResourceNames();
			Logging.Log("GetSprite", "All resources found: " + string.Join(", ", manifestResourceNames), performLogging);
			using Stream stream = assembly.GetManifestResourceStream(filePath);
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, array, true);
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}
	}
}