Decompiled source of EnemyBossbars v1.0.4

Colossus.dll

Decompiled 3 weeks 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.Text.Json;
using System.Text.Json.Serialization;
using AIGraph;
using Agents;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enemies;
using GTFO.API;
using GTFO.API.Utilities;
using GameData;
using Globals;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using MTFO.API;
using MTFO.Managers;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
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(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Colossus")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Colossus")]
[assembly: AssemblyTitle("Colossus")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
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;
		}
	}
}
namespace Colossus
{
	public static class BossbarJson
	{
		private static readonly JsonSerializerOptions _setting;

		static BossbarJson()
		{
			_setting = new JsonSerializerOptions
			{
				ReadCommentHandling = JsonCommentHandling.Skip,
				IncludeFields = true,
				PropertyNameCaseInsensitive = true,
				WriteIndented = true,
				IgnoreReadOnlyProperties = true
			};
			_setting.Converters.Add(new Vector3Converter());
		}

		public static T? Deserialize<T>(string json)
		{
			return JsonSerializer.Deserialize<T>(json, _setting);
		}

		public static T? Deserialize<T>(ref Utf8JsonReader reader)
		{
			return JsonSerializer.Deserialize<T>(ref reader, _setting);
		}

		public static object? Deserialize(Type type, string json)
		{
			return JsonSerializer.Deserialize(json, type, _setting);
		}

		public static string Serialize<T>(T value)
		{
			return JsonSerializer.Serialize(value, _setting);
		}

		public static void Serialize<T>(Utf8JsonWriter writer, T value)
		{
			JsonSerializer.Serialize(writer, value, _setting);
		}
	}
	internal class BossbarMain : MonoBehaviour
	{
		public List<BossData> bossDatas = new List<BossData>();

		public readonly List<EnemyAgent> bossAgents = new List<EnemyAgent>();

		private List<BossData>? source = null;

		public static readonly List<PUI_InteractionPrompt> bossBars = new List<PUI_InteractionPrompt>();

		public void LevelStarted()
		{
			foreach (PUI_InteractionPrompt bossBar in bossBars)
			{
				ToggleBossbar(bossBar, value: false);
			}
			if (source == null)
			{
				source = ReadData();
			}
			if (!SNet.IsMaster)
			{
				return;
			}
			for (int i = 0; i < source.Count; i++)
			{
				if (source[i].SpawnOnLevelGen)
				{
					Debug.LogWarning(Object.op_Implicit("Got Boss that wants to spawn on level gen: " + source[i].BossName + ". Spawning.."));
					SpawnBoss();
				}
			}
		}

		private void ToggleBossbar(PUI_InteractionPrompt bar, bool value)
		{
			((Component)bar.m_timer).gameObject.SetActive(value);
			((Component)bar).gameObject.SetActive(value);
		}

		public void LevelCleanup()
		{
		}

		public void SpawnBoss()
		{
			//IL_0119: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			uint levelLayoutData = RundownManager.ActiveExpedition.LevelLayoutData;
			for (int i = 0; i < source.Count; i++)
			{
				if (source[i].LevelLayoutID == levelLayoutData && source[i].InternalEnabled)
				{
					if (Builder.CurrentFloor.m_dimensions[source[i].DimensionIndex] == null)
					{
						Debug.LogWarning(Object.op_Implicit("Spawn Dimension is invalid!"));
						break;
					}
					EnemyAllocator.Current.SpawnEnemy(source[i].BossId, Builder.CurrentFloor.m_dimensions[source[i].DimensionIndex].Layers[source[i].SpawnLayer].m_zones[source[i].SpawnZone].m_areas[source[i].SpawnArea].m_courseNode, source[i].SpawnMode, source[i].SpawnCoords, Quaternion.EulerAngles(source[i].SpawnRot), (EnemyGroup)null, -1);
				}
				else
				{
					Debug.LogWarning(Object.op_Implicit("Enemy " + source[i].BossName + " is not supposed to spawn on this level or is disabled! Skipping.."));
				}
			}
		}

		private void TryGetBossEnemy()
		{
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Invalid comparison between Unknown and I4
			for (int num = bossAgents.Count - 1; num >= 0; num--)
			{
				if ((Object)(object)bossAgents[num] == (Object)null || !((Agent)bossAgents[num]).Alive)
				{
					bossAgents.RemoveAt(num);
					bossDatas.RemoveAt(num);
				}
			}
			if (bossAgents.Count == 3)
			{
				return;
			}
			foreach (PUI_InteractionPrompt bossBar in bossBars)
			{
				ToggleBossbar(bossBar, value: false);
			}
			List<EnemyAgent> reachableEnemiesInNodes = AIG_CourseGraph.GetReachableEnemiesInNodes(((Agent)PlayerManager.GetLocalPlayerAgent()).CourseNode, 100);
			if (reachableEnemiesInNodes == null)
			{
				return;
			}
			uint levelLayoutData = RundownManager.ActiveExpedition.LevelLayoutData;
			Enumerator<EnemyAgent> enumerator2 = reachableEnemiesInNodes.GetEnumerator();
			while (enumerator2.MoveNext())
			{
				EnemyAgent enemy = enumerator2.Current;
				if (bossAgents.Any((EnemyAgent agent) => ((Il2CppObjectBase)agent).Pointer == ((Il2CppObjectBase)enemy).Pointer))
				{
					continue;
				}
				if (bossAgents.Count >= 3)
				{
					break;
				}
				if (!((Agent)enemy).Alive || (int)enemy.Locomotion.CurrentStateEnum == 14)
				{
					continue;
				}
				for (int i = 0; i < source.Count; i++)
				{
					if (((GameDataBlockBase<EnemyDataBlock>)(object)enemy.EnemyData).persistentID == source[i].BossId && (source[i].IgnoreLevelLayoutCheck || source[i].LevelLayoutID == levelLayoutData))
					{
						bossDatas.Add(source[i]);
						bossAgents.Add(enemy);
					}
				}
			}
		}

		public void Update()
		{
			//IL_00b1: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			if (RundownManager.ExpeditionIsStarted)
			{
				if (source == null)
				{
					source = ReadData();
				}
				TryGetBossEnemy();
				for (int i = 0; i < bossAgents.Count; i++)
				{
					AssignValuesToBar(bossBars[i], bossAgents[i], bossDatas[i]);
				}
				switch (bossAgents.Count)
				{
				case 1:
					((RectTransformComp)bossBars[0]).SetPosition(new Vector2(0f, 225f));
					((Component)bossBars[0]).transform.localScale = new Vector3(1f, 1f, 1f);
					break;
				case 2:
					((RectTransformComp)bossBars[0]).SetPosition(new Vector2(-300f, 250f));
					((RectTransformComp)bossBars[1]).SetPosition(new Vector2(300f, 250f));
					((Component)bossBars[0]).transform.localScale = new Vector3(0.75f, 0.75f, 1f);
					((Component)bossBars[1]).transform.localScale = new Vector3(0.75f, 0.75f, 1f);
					break;
				case 3:
					((RectTransformComp)bossBars[0]).SetPosition(new Vector2(-500f, 250f));
					((RectTransformComp)bossBars[1]).SetPosition(new Vector2(500f, 250f));
					((RectTransformComp)bossBars[2]).SetPosition(new Vector2(0f, 225f));
					((Component)bossBars[0]).transform.localScale = new Vector3(0.67f, 0.67f, 1f);
					((Component)bossBars[1]).transform.localScale = new Vector3(0.67f, 0.67f, 1f);
					((Component)bossBars[2]).transform.localScale = new Vector3(0.67f, 0.67f, 1f);
					break;
				}
			}
		}

		private void AssignValuesToBar(PUI_InteractionPrompt bar, EnemyAgent agent, BossData data)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			ToggleBossbar(bar, value: true);
			bar.SetStyle((ePUIMessageStyle)0);
			bar.SetTimerFill(((Dam_SyncedDamageBase)agent.Damage).Health / ((Dam_SyncedDamageBase)agent.Damage).HealthMax);
			bar.SetMessage("<size=150%>" + data.BossName + "</size>\n" + data.BossSubName);
			bar.m_timer.color = data.BossbarColor;
			((Component)bar).gameObject.transform.localScale = new Vector3(1f, 1f, 1f);
		}

		public static List<BossData> ReadData()
		{
			List<BossData> list = BossbarJson.Deserialize<List<BossData>>(File.ReadAllText(Path.Combine(ConfigManager.CustomPath, "Brandon't-Bossbar", "BossbarConfig.json")));
			list.RemoveAll((BossData data) => !data.InternalEnabled);
			return list;
		}
	}
	[HarmonyPatch]
	internal class BossbarPatch
	{
		[HarmonyPatch(typeof(InteractionGuiLayer), "Setup")]
		[HarmonyPostfix]
		private static void AddNewLayer(InteractionGuiLayer __instance)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 3; i++)
			{
				BossbarMain.bossBars.Add(((Il2CppObjectBase)((GuiLayer)__instance).AddRectComp("Gui/Player/PUI_InteractionPrompt_CellUI", (GuiAnchor)3, new Vector2(0f, 200f), (Transform)null)).TryCast<PUI_InteractionPrompt>());
			}
		}
	}
	public class BossData
	{
		public string BossName { get; set; }

		public string BossSubName { get; set; }

		public uint BossId { get; set; }

		public Color BossbarColor { get; set; }

		public Vector3 SpawnCoords { get; set; }

		public Vector3 SpawnRot { get; set; }

		public uint LevelLayoutID { get; set; }

		public bool SpawnOnLevelGen { get; set; }

		public int SpawnLayer { get; set; }

		public int SpawnZone { get; set; }

		public int SpawnArea { get; set; }

		public int DimensionIndex { get; set; }

		public AgentMode SpawnMode { get; set; }

		public string DebugName { get; set; }

		public bool IgnoreLevelLayoutCheck { get; set; }

		public bool InternalEnabled { get; set; }

		public BossData()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0049: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			BossName = "";
			BossSubName = "";
			BossId = 0u;
			BossbarColor = default(Color);
			SpawnOnLevelGen = false;
			SpawnCoords = default(Vector3);
			SpawnRot = default(Vector3);
			SpawnLayer = 0;
			SpawnZone = 0;
			SpawnArea = 0;
			DimensionIndex = 0;
			LevelLayoutID = 0u;
			SpawnMode = (AgentMode)4;
			DebugName = "";
			IgnoreLevelLayoutCheck = false;
			InternalEnabled = false;
		}
	}
	[BepInPlugin("com.Brandonious.Bossbar", "Bossbar", "1.0.0")]
	public class Loader : BasePlugin
	{
		public const string MODNAME = "Bossbar";

		public const string AUTHOR = "Brandonious";

		public const string GUID = "com.Brandonious.Bossbar";

		public const string VERSION = "1.0.0";

		public static ManualLogSource Logger;

		public override void Load()
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			if (MTFOAPIWrapper.HasCustomContent)
			{
				ClassInjector.RegisterTypeInIl2Cpp<BossbarMain>();
				EventAPI.OnManagersSetup += delegate
				{
					BossbarMain @object = ((Component)Global.Current).gameObject.AddComponent<BossbarMain>();
					LevelAPI.OnEnterLevel += @object.LevelStarted;
					LevelAPI.OnLevelCleanup += @object.LevelCleanup;
				};
				Directory.CreateDirectory(Path.Combine(ConfigManager.CustomPath, "Brandon't-Bossbar"));
				if (!File.Exists(Path.Combine(ConfigManager.CustomPath, "Brandon't-Bossbar", "BossbarConfig.Json")))
				{
					File.WriteAllText(Path.Combine(ConfigManager.CustomPath, "Brandon't-Bossbar", "BossbarConfig.Json"), BossbarJson.Serialize(new List<BossData>
					{
						new BossData()
					}));
				}
				Logger = ((BasePlugin)this).Log;
				Harmony val = new Harmony("Bossbar");
				val.PatchAll();
				ManualLogSource log = ((BasePlugin)this).Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(18, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("Bossbars");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" Loaded! :)");
				}
				log.LogWarning(val2);
			}
		}
	}
	internal static class MTFOAPIWrapper
	{
		public const string PLUGIN_GUID = "com.dak.MTFO";

		public static string GameDataPath => MTFOPathAPI.RundownPath;

		public static string CustomPath => MTFOPathAPI.CustomPath;

		public static bool HasCustomContent => MTFOPathAPI.HasRundownPath;
	}
	public sealed class Vector3Converter : JsonConverter<Vector3>
	{
		public override bool HandleNull => false;

		public override Vector3 Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 vector = default(Vector3);
			switch (reader.TokenType)
			{
			case JsonTokenType.StartObject:
			{
				int currentDepth = reader.CurrentDepth;
				while (reader.Read())
				{
					if (reader.TokenType == JsonTokenType.EndObject && reader.CurrentDepth == currentDepth)
					{
						return vector;
					}
					if (reader.TokenType != JsonTokenType.PropertyName)
					{
						throw new JsonException("Expected PropertyName token");
					}
					string @string = reader.GetString();
					reader.Read();
					switch (@string.ToLowerInvariant())
					{
					case "x":
						vector.x = reader.GetSingle();
						break;
					case "y":
						vector.y = reader.GetSingle();
						break;
					case "z":
						vector.z = reader.GetSingle();
						break;
					}
				}
				throw new JsonException("Expected EndObject token");
			}
			case JsonTokenType.String:
			{
				string text = reader.GetString().Trim();
				if (TryParseVector3(text, out vector))
				{
					return vector;
				}
				throw new JsonException("Vector3 format is not right: " + text);
			}
			default:
				throw new JsonException($"Vector3Json type: {reader.TokenType} is not implemented!");
			}
		}

		private static bool TryParseVector3(string input, out Vector3 vector)
		{
			//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)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			float[] array = default(float[]);
			if (!RegexUtils.TryParseVectorString(input, ref array))
			{
				vector = Vector3.zero;
				return false;
			}
			if (array.Length < 3)
			{
				vector = Vector3.zero;
				return false;
			}
			vector = new Vector3(array[0], array[1], array[2]);
			return true;
		}

		public override void Write(Utf8JsonWriter writer, Vector3 value, JsonSerializerOptions options)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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)
			writer.WriteStartObject();
			writer.WriteNumber("x", value.x);
			writer.WriteNumber("y", value.y);
			writer.WriteNumber("z", value.z);
			writer.WriteEndObject();
		}
	}
}