Decompiled source of Healthbars v1.3.0

plugins/Healthbars/Healthbars.dll

Decompiled 8 months 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 HarmonyLib;
using Healthbars;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Fields;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[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("Healthbars")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Healthbars")]
[assembly: AssemblyTitle("Healthbars")]
[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;
		}
	}
}
public class BarSegment : MonoBehaviour
{
	public Image bar;

	public Image DPSBar;

	public LayoutElement layoutElement;

	public float SegmentHealth
	{
		get
		{
			return layoutElement.flexibleWidth;
		}
		set
		{
			layoutElement.flexibleWidth = value;
		}
	}
}
public enum DisplayMode
{
	Normalized,
	Accurate
}
public enum SegmentMode
{
	Disabled,
	Per5Health
}
public class Healthbar : MonoBehaviour
{
	public const float HEALTHBAR_LENGTH_EXPONENT = 0.55f;

	protected static Dictionary<EnemyIdentifier, Healthbar> activeHealthbars;

	public TextMeshProUGUI label;

	public HorizontalLayoutGroup barLayout;

	public BarSegment bar;

	public CanvasGroup canvasGroup;

	public TextMeshProUGUI damageLabel;

	public Image staminaBar;

	[HideInInspector]
	public bool setupStamina;

	public float[] segmentValues;

	public BarSegment[] barSegments;

	public EnemyType enemyType;

	public MonoBehaviour enemyAI;

	public RectTransform rectTransform;

	public EnemyIdentifier enemy;

	public Transform head;

	private const int BUFFER = 6;

	private float timeSinceDamaged = 99.9f;

	private float lastHealth = 0f;

	private float maxHealth = 0f;

	private float damage = 0f;

	private float healthMultiplier = 1f;

	private float dpsFill = 1f;

	public void Start()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Invalid comparison between Unknown and I4
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Expected O, but got Unknown
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		ref RectTransform reference = ref rectTransform;
		Transform transform = ((Component)this).transform;
		reference = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		enemyType = enemy.enemyType;
		if ((int)enemyType == 1 && (Object)(object)((Component)enemy).GetComponent<Mandalore>() != (Object)null)
		{
			enemyType = (EnemyType)25;
		}
		lastHealth = enemy.health;
		maxHealth = enemy.health;
		healthMultiplier = enemy.totalHealthModifier;
		int privateField = enemy.GetPrivateField<int>("difficulty");
		if (enemy.isBoss)
		{
			switch (privateField)
			{
			case 4:
				healthMultiplier *= 1.5f;
				break;
			case 5:
				healthMultiplier *= 2f;
				break;
			}
		}
		Plugin.useTotalHealth.onValueChange += new BoolValueChangeEventDelegate(UpdateHealthbarLength);
		int num = 0;
		int num2 = -3 + Plugin.height.value;
		setupStamina = false;
		staminaBar.fillAmount = 0f;
		num = -3;
		float[] segments = GetSegments();
		barSegments = new BarSegment[segments.Length];
		bar.SegmentHealth = segments[0];
		barSegments[0] = bar;
		for (int i = 1; i < segments.Length; i++)
		{
			barSegments[i] = Object.Instantiate<GameObject>(((Component)bar).gameObject, ((Component)bar).transform.parent).GetComponent<BarSegment>();
			Debug.Log((object)(i + ": " + segments[i]));
			barSegments[i].SegmentHealth = segments[i];
		}
		float num3 = 25f * Plugin.width.value;
		int num4 = num + num2;
		if (Plugin.useTotalHealth.value)
		{
			rectTransform.sizeDelta = new Vector2((float)Mathf.CeilToInt(Mathf.Pow(maxHealth * healthMultiplier, 0.55f) * num3), rectTransform.sizeDelta.y + (float)num4);
		}
		else
		{
			rectTransform.sizeDelta = new Vector2((float)Mathf.CeilToInt(Mathf.Pow(maxHealth, 0.55f) * num3), rectTransform.sizeDelta.y + (float)num4);
		}
		Transform transform2 = ((Component)barLayout).transform;
		? val = ((transform2 is RectTransform) ? transform2 : null);
		Transform transform3 = ((Component)barLayout).transform;
		((RectTransform)val).sizeDelta = new Vector2(-6f, ((RectTransform)((transform3 is RectTransform) ? transform3 : null)).sizeDelta.y + (float)num2);
		Debug.Log((object)("enemyAI: " + (object)enemyAI));
		Transform transform4 = ((Component)barLayout).transform;
		LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)(object)((transform4 is RectTransform) ? transform4 : null));
		SeasonalHats componentInChildren = ((Component)enemy).GetComponentInChildren<SeasonalHats>(true);
		head = ((componentInChildren != null) ? ((Component)componentInChildren).transform : null);
		if ((Object)(object)head == (Object)null)
		{
			head = ((Component)enemy).transform;
		}
	}

	private void Update()
	{
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: 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_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0541: Unknown result type (might be due to invalid IL or missing references)
		//IL_057d: Unknown result type (might be due to invalid IL or missing references)
		timeSinceDamaged += Time.deltaTime;
		canvasGroup.alpha = Mathf.InverseLerp(4f, 3.5f, timeSinceDamaged);
		if ((Object)(object)enemy == (Object)null || (enemy.health <= 0f && canvasGroup.alpha <= 0f))
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		if ((Object)(object)head == (Object)null)
		{
			head = ((Component)enemy).transform;
		}
		Vector3 val = MonoSingleton<CameraController>.Instance.cam.WorldToScreenPoint(head.position + head.localScale.y * Vector3.up * 0.5f);
		if (val.z < 0f)
		{
			canvasGroup.alpha = 0f;
		}
		((Transform)rectTransform).position = val + new Vector3(0f, 12f, 0f);
		float totalHealthModifier = enemy.totalHealthModifier;
		if (totalHealthModifier != healthMultiplier)
		{
			healthMultiplier = totalHealthModifier;
			if (Plugin.useTotalHealth.value)
			{
				rectTransform.sizeDelta = new Vector2((float)Mathf.CeilToInt(Mathf.Sqrt(maxHealth * healthMultiplier) * 25f), rectTransform.sizeDelta.y);
				Transform transform = ((Component)barLayout).transform;
				? val2 = ((transform is RectTransform) ? transform : null);
				Transform transform2 = ((Component)barLayout).transform;
				((RectTransform)val2).sizeDelta = new Vector2(-6f, ((RectTransform)((transform2 is RectTransform) ? transform2 : null)).sizeDelta.y);
			}
		}
		if (lastHealth != enemy.health && (lastHealth > 0f || enemy.health > 0f))
		{
			float num = Mathf.Max(lastHealth, 0f);
			if (timeSinceDamaged <= 4f)
			{
				damage += Mathf.Min(lastHealth - enemy.health, num) * healthMultiplier;
			}
			else
			{
				damage = Mathf.Min(lastHealth - enemy.health, num) * healthMultiplier;
			}
			lastHealth = enemy.health;
			timeSinceDamaged = 0f;
		}
		float num2 = 0f;
		float num3 = 0f;
		dpsFill = Mathf.Max(enemy.health, Mathf.MoveTowards(dpsFill, enemy.health, Time.deltaTime * Mathf.Lerp(1f, 10f, dpsFill - enemy.health)));
		BarSegment[] array = barSegments;
		foreach (BarSegment barSegment in array)
		{
			barSegment.bar.fillAmount = Mathf.InverseLerp(num2, num2 + barSegment.SegmentHealth, enemy.health);
			barSegment.DPSBar.fillAmount = Mathf.InverseLerp(num2, num2 + barSegment.SegmentHealth, dpsFill);
			num2 += barSegment.SegmentHealth;
			num3 += barSegment.SegmentHealth;
		}
		switch (Plugin.displayMode.value)
		{
		case DisplayMode.Normalized:
			((TMP_Text)label).text = $"{Mathf.CeilToInt(Mathf.Max(enemy.health * 100f * healthMultiplier, 0f))}<space=0.25em><size=75%><color=#FFFA>{Mathf.CeilToInt(maxHealth * healthMultiplier * 100f)}";
			break;
		case DisplayMode.Accurate:
		{
			string text = ((float)Mathf.CeilToInt(maxHealth * 100f * healthMultiplier) / 100f).ToString();
			string text2 = ((float)Mathf.CeilToInt(Mathf.Max(enemy.health * 100f * healthMultiplier, 0f)) / 100f).ToString("0.00");
			((TMP_Text)label).text = text2 + "<space=0.25em><size=75%><color=#FFFA>" + text;
			break;
		}
		}
		UpdateDamageLabel();
		bool flag = true;
		bool flag2 = true;
		if (enemy.blessed)
		{
			BarSegment[] array2 = barSegments;
			foreach (BarSegment barSegment2 in array2)
			{
				((Graphic)barSegment2.bar).color = Plugin.blessedColor.value;
			}
		}
		else if (enemy.isBoss)
		{
			BarSegment[] array3 = barSegments;
			foreach (BarSegment barSegment3 in array3)
			{
				((Graphic)barSegment3.bar).color = Plugin.bossColor.value;
			}
		}
		else
		{
			BarSegment[] array4 = barSegments;
			foreach (BarSegment barSegment4 in array4)
			{
				((Graphic)barSegment4.bar).color = Plugin.normalColor.value;
			}
		}
	}

	private void UpdateDamageLabel()
	{
		switch (Plugin.displayMode.value)
		{
		case DisplayMode.Normalized:
		{
			float num3 = Mathf.Sign(damage);
			float num4 = num3;
			if (num4 != 1f)
			{
				if (num4 != 0f)
				{
					if (num4 == -1f)
					{
						((TMP_Text)damageLabel).text = $"<color=#0F0>+{Mathf.FloorToInt(damage * -100f)}";
					}
				}
				else
				{
					((TMP_Text)damageLabel).text = "-0";
				}
			}
			else
			{
				((TMP_Text)damageLabel).text = $"-{Mathf.FloorToInt(damage * 100f)}";
			}
			break;
		}
		case DisplayMode.Accurate:
		{
			float num = Mathf.Sign(damage);
			float num2 = num;
			if (num2 != 1f)
			{
				if (num2 != 0f)
				{
					if (num2 == -1f)
					{
						((TMP_Text)damageLabel).text = $"<color=#0F0>+{(float)Mathf.FloorToInt(damage * -100f) / 100f}";
					}
				}
				else
				{
					((TMP_Text)damageLabel).text = "-0";
				}
			}
			else
			{
				((TMP_Text)damageLabel).text = $"-{(float)Mathf.FloorToInt(damage * 100f) / 100f}";
			}
			break;
		}
		}
	}

	private void UpdateHealthbarLength(BoolValueChangeEvent data)
	{
		//IL_0072: 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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		if (data.value)
		{
			rectTransform.sizeDelta = new Vector2((float)Mathf.CeilToInt(Mathf.Sqrt(maxHealth * healthMultiplier) * 25f), rectTransform.sizeDelta.y);
		}
		else
		{
			rectTransform.sizeDelta = new Vector2((float)Mathf.CeilToInt(Mathf.Sqrt(maxHealth) * 25f), rectTransform.sizeDelta.y);
		}
		Transform transform = ((Component)barLayout).transform;
		? val = ((transform is RectTransform) ? transform : null);
		Transform transform2 = ((Component)barLayout).transform;
		((RectTransform)val).sizeDelta = new Vector2(-6f, ((RectTransform)((transform2 is RectTransform) ? transform2 : null)).sizeDelta.y);
	}

	private void OnDestroy()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		Plugin.useTotalHealth.onValueChange -= new BoolValueChangeEventDelegate(UpdateHealthbarLength);
	}

	private float[] GetSegments()
	{
		SegmentMode value = Plugin.segmentedBars.value;
		SegmentMode segmentMode = value;
		if (segmentMode != 0 && segmentMode == SegmentMode.Per5Health)
		{
			if (maxHealth > 250f)
			{
				return new float[1] { maxHealth };
			}
			float[] array = new float[Mathf.CeilToInt(maxHealth / 5f)];
			for (int i = 0; i < array.Length - 1; i++)
			{
				array[i] = 5f;
			}
			array[^1] = ((maxHealth % 5f <= 0f) ? 5f : (maxHealth % 5f));
			return array;
		}
		return new float[1] { maxHealth };
	}
}
namespace Healthbars
{
	[BepInPlugin("Healthbars", "Healthbars", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const bool ENABLE_STAMINA_BAR = false;

		public const bool PER_PHASE_SEGMENTING = false;

		public static Plugin instance;

		public static GameObject ob;

		public static GameObject healthbar;

		public static Canvas canvas;

		internal static PluginConfigurator config;

		internal static EnumField<DisplayMode> displayMode;

		public static ColorField bossColor;

		public static ColorField normalColor;

		public static ColorField blessedColor;

		public static FloatField width;

		public static IntField height;

		public static FloatField minMaxHealth;

		public static BoolField useTotalHealth;

		public static EnumField<SegmentMode> segmentedBars;

		private void Awake()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Expected O, but got Unknown
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Expected O, but got Unknown
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Expected O, but got Unknown
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Expected O, but got Unknown
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Expected O, but got Unknown
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Expected O, but got Unknown
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Harmony val = new Harmony("me.eladnlg.healthbars");
			val.PatchAll();
			ob = ((Component)this).gameObject;
			instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Healthbars is loaded!");
			AssetBundle val2 = AssetUtils.LoadAssetBundleFromResources("healthbars", Assembly.GetExecutingAssembly());
			healthbar = val2.LoadAsset<GameObject>("Healthbar");
			if ((Object)(object)healthbar == (Object)null)
			{
				throw new NullReferenceException("Healthbar asset is null!");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Healthbars is loade2d!");
			canvas = Object.Instantiate<GameObject>(val2.LoadAsset<GameObject>("HealthbarCanvas")).GetComponent<Canvas>();
			Object.DontDestroyOnLoad((Object)(object)((Component)canvas).gameObject);
			((Object)((Component)canvas).gameObject).hideFlags = (HideFlags)61;
			config = PluginConfigurator.Create("Healthbars", "me.eladnlg.healthbars");
			config.SetIconWithURL("https://raw.githubusercontent.com/EladNLG/UltrakillHealthbars/main/assets/icon.png");
			displayMode = new EnumField<DisplayMode>(config.rootPanel, "Display Mode", "displayMode", DisplayMode.Accurate);
			displayMode.SetEnumDisplayName(DisplayMode.Accurate, "Accurate/Vanilla");
			width = new FloatField(config.rootPanel, "Width Multiplier", "width", 1f);
			width.maximumValue = 2f;
			width.minimumValue = 0.333f;
			height = new IntField(config.rootPanel, "Height", "height", 3);
			height.minimumValue = 1;
			height.maximumValue = 8;
			ConfigPanel val3 = new ConfigPanel(config.rootPanel, "Colors", "colors");
			bossColor = new ColorField(val3, "Boss Healthbar Color", "bossColor", new Color(1f, 0.28f, 0.28f));
			normalColor = new ColorField(val3, "Regular Healthbar Color", "normalColor", new Color(1f, 0.82f, 0.28f));
			blessedColor = new ColorField(val3, "Blessed Healthbar Color", "blessedColor", new Color(0.28f, 0.82f, 1f));
			new ConfigHeader(config.rootPanel, "The minimum BASE health (inclusive) of an enemy to display a healthbar.\r\nPersonal Recommendations:\r\n5 - Schisms and above display healthbar\r\n4.5 - Streetcleaners and above display healthbar\r\n0 - All enemies display healthbar", 16);
			minMaxHealth = new FloatField(config.rootPanel, "Min Health", "minHealth", 0f);
			segmentedBars = new EnumField<SegmentMode>(config.rootPanel, "Segmented Bars", "segmentedBars", SegmentMode.Disabled);
			useTotalHealth = new BoolField(config.rootPanel, "Increase healthbar length with radiance tiers", "useTotalHealth", true);
		}
	}
	internal static class ReflectionUtils
	{
		public static T GetPrivateField<T>(this object obj, string field)
		{
			Type type = obj.GetType();
			if (type.GetField(field, BindingFlags.Instance | BindingFlags.NonPublic) == null)
			{
				throw new ArgumentException("The field " + field + " does not exist in target class " + type.Name + "!");
			}
			return (T)type.GetField(field, BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Healthbars";

		public const string PLUGIN_NAME = "Healthbars";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Healthbars.Patches
{
	[HarmonyPatch(typeof(EnemyIdentifier))]
	public class EnemyPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void EnemySpawned(EnemyIdentifier __instance)
		{
			if (!(__instance.health < Plugin.minMaxHealth.value))
			{
				Debug.Log((object)$"healthbar asset: {Plugin.healthbar}\nCanvas: {Plugin.canvas}");
				GameObject val = Object.Instantiate<GameObject>(Plugin.healthbar, ((Component)Plugin.canvas).transform);
				val.GetComponent<Healthbar>().enemy = __instance;
			}
		}
	}
}
namespace Jotunn.Utils
{
	public static class AssetUtils
	{
		public const char AssetBundlePathSeparator = '$';

		public static Texture2D LoadTexture(string texturePath, bool relativePath = true)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			string text = texturePath;
			if (relativePath)
			{
				text = Path.Combine(Paths.PluginPath, texturePath);
			}
			if (!File.Exists(text))
			{
				return null;
			}
			if (!text.EndsWith(".png") && !text.EndsWith(".jpg"))
			{
				throw new Exception("LoadTexture can only load png or jpg textures");
			}
			byte[] array = File.ReadAllBytes(text);
			Texture2D val = new Texture2D(2, 2);
			val.LoadRawTextureData(array);
			return val;
		}

		public static Sprite LoadSpriteFromFile(string spritePath)
		{
			//IL_002e: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = LoadTexture(spritePath);
			if ((Object)(object)val != (Object)null)
			{
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), default(Vector2), 100f);
			}
			return null;
		}

		public static AssetBundle LoadAssetBundle(string bundlePath)
		{
			string text = Path.Combine(Paths.PluginPath, bundlePath);
			if (!File.Exists(text))
			{
				return null;
			}
			return AssetBundle.LoadFromFile(text);
		}

		public static AssetBundle LoadAssetBundleFromResources(string bundleName, Assembly resourceAssembly)
		{
			if (resourceAssembly == null)
			{
				throw new ArgumentNullException("Parameter resourceAssembly can not be null.");
			}
			string text = null;
			try
			{
				text = resourceAssembly.GetManifestResourceNames().Single((string str) => str.EndsWith(bundleName));
			}
			catch (Exception)
			{
			}
			if (text == null)
			{
				Debug.LogError((object)("AssetBundle " + bundleName + " not found in assembly manifest"));
				return null;
			}
			AssetBundle result;
			using (Stream stream = resourceAssembly.GetManifestResourceStream(text))
			{
				result = AssetBundle.LoadFromStream(stream);
			}
			return result;
		}

		public static string LoadText(string path)
		{
			string text = Path.Combine(Paths.PluginPath, path);
			if (!File.Exists(text))
			{
				Debug.LogError((object)("Error, failed to load contents from non-existant path: $" + text));
				return null;
			}
			return File.ReadAllText(text);
		}

		public static Sprite LoadSprite(string assetPath)
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(Paths.PluginPath, assetPath);
			if (!File.Exists(text))
			{
				return null;
			}
			if (text.Contains('$'.ToString()))
			{
				string[] array = text.Split(new char[1] { '$' });
				string text2 = array[0];
				string text3 = array[1];
				AssetBundle val = AssetBundle.LoadFromFile(text2);
				Sprite result = val.LoadAsset<Sprite>(text3);
				val.Unload(false);
				return result;
			}
			Texture2D val2 = LoadTexture(text, relativePath: false);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				return null;
			}
			return Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), Vector2.zero);
		}
	}
}