Decompiled source of CustomBossBars v0.1.0

CustomBossbars.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using CustomBossbars.Helpers;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.AddressableAssets.ResourceLocators;
using UnityEngine.ResourceManagement.ResourceLocations;
using UnityEngine.SceneManagement;

[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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class ExtensionMarkerAttribute : Attribute
	{
		private readonly string <Name>k__BackingField;

		public string Name => <Name>k__BackingField;

		public ExtensionMarkerAttribute(string name)
		{
			<Name>k__BackingField = name;
		}
	}
}
namespace CustomBossbars
{
	[BepInPlugin("duviz.CustomBossbars", "CustomBossbars", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin instance;

		public static ConfigFile config;

		public static List<(ConfigEntry<Color>, ConfigEntry<Color>)> bossbars = new List<(ConfigEntry<Color>, ConfigEntry<Color>)>();

		public static List<(ConfigEntry<string>, ConfigEntry<string>)> namesOverrides = new List<(ConfigEntry<string>, ConfigEntry<string>)>();

		public static ConfigEntry<Color> secondaryBossbarColor;

		public void Awake()
		{
			//IL_0025: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			config = ((BaseUnityPlugin)this).Config;
			new Harmony("duviz.CustomBossbars").PatchAll();
			secondaryBossbarColor = config.Bind<Color>("Colors", "Stamina bar color", Color.red, (ConfigDescription)null);
			for (int i = 0; i < 16; i++)
			{
				bossbars.Add((config.Bind<Color>("Colors", $"Bossbar color n{i + 1}", Color.red, (ConfigDescription)null), config.Bind<Color>("Colors", $"Bossbar damage color n{i + 1}", Color.white, (ConfigDescription)null)));
			}
			for (int j = 0; j < 32; j++)
			{
				namesOverrides.Add((config.Bind<string>("Names", $"Boss original name n{j + 1}", "", (ConfigDescription)null), config.Bind<string>("Names", $"Boss replacement name n{j + 1}", "", (ConfigDescription)null)));
			}
		}

		public void Start()
		{
			SceneManager.sceneLoaded += delegate
			{
				config.Reload();
			};
		}

		public static T Ass<T>(string path)
		{
			return AssHelper.Ass<T>(path);
		}

		public static void LogInfo(object msg)
		{
			((BaseUnityPlugin)instance).Logger.LogInfo(msg);
		}

		public static void LogWarning(object msg)
		{
			((BaseUnityPlugin)instance).Logger.LogWarning(msg);
		}

		public static void LogError(object msg)
		{
			((BaseUnityPlugin)instance).Logger.LogError(msg);
		}
	}
	[HarmonyPatch]
	public class Patch
	{
		[HarmonyPatch(typeof(BossHealthBarTemplate), "Initialize")]
		public static void Prefix(BossHealthBarTemplate __instance, BossHealthBar bossBar, ref SliderLayer[] colorLayers)
		{
			//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_0039: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			Plugin.config.Reload();
			Plugin.LogInfo(colorLayers.Length);
			for (int i = 0; i < colorLayers.Length; i++)
			{
				colorLayers[i] = new SliderLayer
				{
					color = Plugin.bossbars[i].Item1.Value,
					afterImageColor = Plugin.bossbars[i].Item2.Value
				};
			}
			string bossName = bossBar.bossName;
			foreach (var (val, val2) in Plugin.namesOverrides)
			{
				if (val.Value.ToLower() == bossName.ToLower())
				{
					bossBar.bossName = val2.Value;
				}
			}
		}

		[HarmonyPatch(typeof(BossHealthBar), "SetSecondaryBarColor")]
		[HarmonyPrefix]
		public static bool Prefix2(BossHealthBar __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Plugin.config.Reload();
			__instance.secondaryBarColor = Plugin.secondaryBossbarColor.Value;
			return false;
		}

		[HarmonyPatch(typeof(BossHealthBar), "Awake")]
		[HarmonyPrefix]
		public static void Prefix3(BossHealthBar __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Plugin.config.Reload();
			__instance.secondaryBarColor = Plugin.secondaryBossbarColor.Value;
		}

		[HarmonyPatch(typeof(BossHealthBar), "Start")]
		[HarmonyPrefix]
		public static void Prefix4(BossHealthBar __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Plugin.config.Reload();
			__instance.secondaryBarColor = Plugin.secondaryBossbarColor.Value;
		}
	}
	public class PluginInfo
	{
		public const string GUID = "duviz.CustomBossbars";

		public const string Name = "CustomBossbars";

		public const string Version = "0.1.0";
	}
}
namespace CustomBossbars.Helpers
{
	public static class AssHelper
	{
		[SpecialName]
		public sealed class <G>$34505F560D9EACF86A87F3ED1F85E448
		{
			[SpecialName]
			public static class <M>$69FE22D2D9367C6033D7C9FA04F1ABE9
			{
			}

			[ExtensionMarker("<M>$69FE22D2D9367C6033D7C9FA04F1ABE9")]
			public int Occurrences(char lookUp)
			{
				throw new NotSupportedException();
			}

			[ExtensionMarker("<M>$69FE22D2D9367C6033D7C9FA04F1ABE9")]
			public IEnumerable<int> Occurences(char lookUp)
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <Occurences>d__9 : IEnumerable<int>, IEnumerable, IEnumerator<int>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private int <>2__current;

			private int <>l__initialThreadId;

			private string str;

			public string <>3__str;

			private char lookUp;

			public char <>3__lookUp;

			private int <i>5__1;

			int IEnumerator<int>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Occurences>d__9(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				int num = <>1__state;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -1;
					goto IL_0062;
				}
				<>1__state = -1;
				<i>5__1 = 0;
				goto IL_0072;
				IL_0062:
				<i>5__1++;
				goto IL_0072;
				IL_0072:
				if (<i>5__1 < str.Length)
				{
					if (str[<i>5__1] == lookUp)
					{
						<>2__current = <i>5__1;
						<>1__state = 1;
						return true;
					}
					goto IL_0062;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<int> IEnumerable<int>.GetEnumerator()
			{
				<Occurences>d__9 <Occurences>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<Occurences>d__ = this;
				}
				else
				{
					<Occurences>d__ = new <Occurences>d__9(0);
				}
				<Occurences>d__.str = <>3__str;
				<Occurences>d__.lookUp = <>3__lookUp;
				return <Occurences>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<int>)this).GetEnumerator();
			}
		}

		private static List<string> cache_PrefabKeys = null;

		public static Dictionary<string, object> CachedAddressableAssets = new Dictionary<string, object>();

		public static IResourceLocator MainAddressablesLocator => Addressables.ResourceLocators.FirstOrDefault((Func<IResourceLocator, bool>)((IResourceLocator loc) => loc.LocatorId == "AddressablesMainContentCatalog"));

		public static IEnumerable<object> GetAddressableKeys()
		{
			IResourceLocator mainAddressablesLocator = MainAddressablesLocator;
			return ((mainAddressablesLocator != null) ? mainAddressablesLocator.Keys : null) ?? Array.Empty<object>();
		}

		public static List<string> GetPrefabAddressableKeys(Func<string, bool> Search = null)
		{
			if (cache_PrefabKeys != null)
			{
				return cache_PrefabKeys.Where(Search).ToList();
			}
			List<string> list = new List<string>();
			IList<IResourceLocation> list2 = default(IList<IResourceLocation>);
			foreach (object addressableKey in GetAddressableKeys())
			{
				if (MainAddressablesLocator.Locate(addressableKey, typeof(GameObject), ref list2) && !list.Contains(list2[0].PrimaryKey))
				{
					list.Add(list2[0].PrimaryKey);
				}
			}
			list.Sort();
			cache_PrefabKeys = list;
			return list.Where(Search).ToList();
		}

		public static T Ass<T>(string key)
		{
			//IL_0030: 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)
			if (CachedAddressableAssets.TryGetValue(key + typeof(T).Name, out var value))
			{
				return (T)value;
			}
			T val = Addressables.LoadAssetAsync<T>((object)key).WaitForCompletion();
			if (val != null)
			{
				CachedAddressableAssets.Add(key + typeof(T).Name, val);
			}
			else
			{
				Plugin.LogError("Failed to load asset: " + key);
			}
			return val;
		}

		public static int Occurrences(this string str, char lookUp)
		{
			int num = 0;
			foreach (char c in str)
			{
				if (c == lookUp)
				{
					num++;
				}
			}
			return num;
		}

		[IteratorStateMachine(typeof(<Occurences>d__9))]
		public static IEnumerable<int> Occurences(this string str, char lookUp)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Occurences>d__9(-2)
			{
				<>3__str = str,
				<>3__lookUp = lookUp
			};
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}