Decompiled source of TriTipDagger v0.2.1

plugins/MuckTriTip.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("MuckTriTip")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds Risk of Rain 2's Tri-Tip Dagger (bleed on hit) to Muck as a Blue powerup.")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+879fc7ac66fec639f2f84b4b7a65d5c61c9ed734")]
[assembly: AssemblyProduct("Tri-Tip Dagger")]
[assembly: AssemblyTitle("MuckTriTip")]
[assembly: InternalsVisibleTo("MuckTriTip.Tests")]
[assembly: AssemblyVersion("0.2.1.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
}
namespace MuckTriTip
{
	internal sealed class Bleed
	{
		private struct Proc
		{
			public double PerTick;

			public int TicksLeft;
		}

		private readonly List<Proc> _procs = new List<Proc>();

		private double _remainder;

		public int Stacks => _procs.Count;

		public bool IsActive => _procs.Count > 0;

		public void Apply(PlayerHit hit, DaggerRules rules)
		{
			_procs.Add(new Proc
			{
				PerTick = rules.PerTick(hit),
				TicksLeft = rules.TicksPerStack
			});
		}

		public int Tick()
		{
			if (_procs.Count == 0)
			{
				return 0;
			}
			double num = _remainder;
			for (int num2 = _procs.Count - 1; num2 >= 0; num2--)
			{
				Proc value = _procs[num2];
				num += value.PerTick;
				value.TicksLeft--;
				if (value.TicksLeft > 0)
				{
					_procs[num2] = value;
				}
				else
				{
					_procs.RemoveAt(num2);
				}
			}
			int num3;
			double num4;
			if (num >= 2147483647.0)
			{
				num3 = int.MaxValue;
				num4 = 0.0;
			}
			else if (num <= 0.0)
			{
				num3 = 0;
				num4 = 0.0;
			}
			else
			{
				num3 = (int)Math.Floor(num);
				num4 = num - (double)num3;
			}
			_remainder = ((_procs.Count > 0) ? num4 : 0.0);
			return num3;
		}

		public void Clear()
		{
			_procs.Clear();
			_remainder = 0.0;
		}
	}
	internal sealed class BleedTarget : MonoBehaviour
	{
		internal static bool InsideTickHit;

		private HitableMob _mob;

		private readonly Bleed _bleed = new Bleed();

		private Coroutine _loop;

		private readonly List<Collider> _colliders = new List<Collider>();

		public static BleedTarget On(HitableMob mob)
		{
			BleedTarget bleedTarget = ((Component)mob).GetComponent<BleedTarget>();
			if ((Object)(object)bleedTarget == (Object)null)
			{
				bleedTarget = ((Component)mob).gameObject.AddComponent<BleedTarget>();
			}
			return bleedTarget;
		}

		public void AddStack(PlayerHit hit, DaggerRules rules)
		{
			if (((Behaviour)this).isActiveAndEnabled)
			{
				_bleed.Apply(hit, rules);
				if (_loop == null)
				{
					_loop = ((MonoBehaviour)this).StartCoroutine(Run());
				}
				if (TriTipPlugin.Cfg.VerboseLogging.Value)
				{
					TriTipPlugin.Log.LogInfo((object)$"{_mob} bleeding x{_bleed.Stacks}. New bleed {rules.PerTick(hit):0.##} per tick for {rules.TicksPerStack} ticks (base {hit.WeaponBase} x strength {hit.Strength:0.##}, hit {hit.Damage})");
				}
			}
		}

		private void Awake()
		{
			_mob = ((Component)this).GetComponent<HitableMob>();
		}

		private void OnDisable()
		{
			if (_loop != null)
			{
				((MonoBehaviour)this).StopCoroutine(_loop);
				_loop = null;
			}
			_bleed.Clear();
		}

		private IEnumerator Run()
		{
			WaitForSeconds wait = new WaitForSeconds(0.25f);
			while (_bleed.IsActive)
			{
				yield return wait;
				if (!_bleed.IsActive)
				{
					break;
				}
				int num = _bleed.Tick();
				bool num2 = !_bleed.IsActive;
				if (num > 0 && (Object)(object)_mob != (Object)null && ((Hitable)_mob).hp > 0)
				{
					Strike(num);
				}
				if (num2)
				{
					break;
				}
			}
			_loop = null;
		}

		private void Strike(int damage)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			InsideTickHit = true;
			try
			{
				((Hitable)_mob).Hit(damage, 0f, 0, HitPoint(), -1);
			}
			catch (Exception arg)
			{
				TriTipPlugin.Log.LogError((object)$"Tri-Tip Dagger tick failed: {arg}");
			}
			finally
			{
				InsideTickHit = false;
			}
		}

		private Vector3 HitPoint()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			((Component)_mob).GetComponentsInChildren<Collider>(false, _colliders);
			foreach (Collider collider in _colliders)
			{
				if ((Object)(object)collider != (Object)null && collider.enabled && !collider.isTrigger)
				{
					Bounds bounds = collider.bounds;
					return ((Bounds)(ref bounds)).center;
				}
			}
			return ((Component)_mob).transform.position + Vector3.up;
		}
	}
	internal sealed class DaggerRules
	{
		public const int TicksPerSecond = 4;

		public const float TickInterval = 0.25f;

		private readonly float _chancePerDagger;

		public readonly float TickFraction;

		public readonly int TicksPerStack;

		private DaggerRules(float chancePerDagger, float tickFraction, int ticksPerStack)
		{
			_chancePerDagger = chancePerDagger;
			TickFraction = tickFraction;
			TicksPerStack = ticksPerStack;
		}

		public static DaggerRules Create(float chancePerDagger, float tickFraction, float bleedSeconds)
		{
			if (!(chancePerDagger > 0f))
			{
				chancePerDagger = 0f;
			}
			if (!(tickFraction > 0f))
			{
				tickFraction = 0f;
			}
			int num = ((!(bleedSeconds > 0f)) ? 1 : RoundToInt((double)bleedSeconds * 4.0));
			if (num < 1)
			{
				num = 1;
			}
			return new DaggerRules(chancePerDagger, tickFraction, num);
		}

		public float ChanceFor(int daggers)
		{
			if (daggers < 1)
			{
				return 0f;
			}
			float num = _chancePerDagger * (float)daggers;
			if (!(num < 1f))
			{
				return 1f;
			}
			return num;
		}

		public bool Procs(int daggers, float roll)
		{
			float num = ChanceFor(daggers);
			if (num >= 1f)
			{
				return true;
			}
			return roll < num;
		}

		public double PerTick(PlayerHit hit)
		{
			return (double)TickFraction * (double)hit.WeaponBase * (double)hit.Strength;
		}

		public string Description()
		{
			int num = RoundToInt((double)_chancePerDagger * 100.0);
			int num2 = RoundToInt((double)TickFraction * (double)TicksPerStack * 100.0);
			string text = ((double)TicksPerStack / 4.0).ToString("0.##", CultureInfo.InvariantCulture);
			return $"{num}% (+{num}% per stack) chance on hit to bleed an enemy for {num2}% of your weapon's base damage over {text}s. Each bleed runs out on its own.";
		}

		internal static int RoundToInt(double value)
		{
			return (int)Math.Round(value, MidpointRounding.ToEven);
		}
	}
	internal static class HitableMobHitPatch
	{
		private static bool _loggedStrength;

		internal static MethodInfo Target()
		{
			return AccessTools.DeclaredMethod(typeof(HitableMob), "Hit", new Type[5]
			{
				typeof(int),
				typeof(float),
				typeof(int),
				typeof(Vector3),
				typeof(int)
			}, (Type[])null);
		}

		internal static bool Apply(Harmony harmony)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			MethodInfo methodInfo = Target();
			if (methodInfo == null)
			{
				TriTipPlugin.Log.LogError((object)"HitableMob does not declare Hit. Tri-Tip Dagger will not proc.");
				return false;
			}
			try
			{
				MethodInfo methodInfo2 = AccessTools.Method(typeof(HitableMobHitPatch), "Postfix", (Type[])null, (Type[])null);
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				return true;
			}
			catch (Exception arg)
			{
				TriTipPlugin.Log.LogError((object)$"Tri-Tip Dagger failed to patch HitableMob.Hit: {arg}");
				return false;
			}
		}

		private static void Postfix(HitableMob __instance, int damage, int hitWeaponType)
		{
			try
			{
				if (!PlayerHit.Accepts(hitWeaponType, damage, ((Hitable)__instance).hp, BleedTarget.InsideTickHit))
				{
					return;
				}
				int num = TriTipPowerup.LocalStacks();
				if (num > 0)
				{
					DaggerRules daggerRules = TriTipPlugin.Cfg.Rules();
					if (daggerRules.Procs(num, Random.value) && PlayerHit.TryParse(hitWeaponType, damage, ((Hitable)__instance).hp, BleedTarget.InsideTickHit, ReadWeaponAttack(), ReadStrength(), out var hit))
					{
						BleedTarget.On(__instance).AddStack(hit, daggerRules);
					}
				}
			}
			catch (Exception arg)
			{
				TriTipPlugin.Log.LogError((object)$"Tri-Tip Dagger on-hit failed: {arg}");
			}
		}

		private static int ReadWeaponAttack()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Invalid comparison between Unknown and I4
			Hotbar instance = Hotbar.Instance;
			InventoryItem val = (((Object)(object)instance != (Object)null) ? instance.currentItem : null);
			if ((Object)(object)val == (Object)null)
			{
				return 0;
			}
			bool flag = (int)val.type == 9;
			int arrowAttack = 0;
			if (flag)
			{
				InventoryUI instance2 = InventoryUI.Instance;
				InventoryCell val2 = (((Object)(object)instance2 != (Object)null) ? instance2.arrows : null);
				InventoryItem val3 = (((Object)(object)val2 != (Object)null) ? val2.currentItem : null);
				arrowAttack = ((!((Object)(object)val3 != (Object)null)) ? 1 : val3.attackDamage);
			}
			return PlayerHit.WeaponAttack(val.attackDamage, flag, (int)val.tag == 8, arrowAttack);
		}

		private static float ReadStrength()
		{
			PowerupInventory instance = PowerupInventory.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return 1f;
			}
			try
			{
				return instance.GetStrengthMultiplier((int[])null);
			}
			catch (Exception e)
			{
				LogStrengthOnce(e);
				return 1f;
			}
		}

		private static void LogStrengthOnce(Exception e)
		{
			if (!_loggedStrength)
			{
				_loggedStrength = true;
				TriTipPlugin.Log.LogWarning((object)("Tri-Tip Dagger could not read the strength multiplier. Bleeds use 1. " + e.Message));
			}
		}
	}
	internal static class PickupArt
	{
		public const string ObjResource = "MuckTriTip.pickup.obj";

		public const string JsonResource = "MuckTriTip.pickup.json";

		public static void Apply(Powerup powerup, Powerup[] pool)
		{
			if ((Object)(object)powerup == (Object)null || (Object)(object)powerup.mesh != (Object)null)
			{
				return;
			}
			Powerup val = Donor(pool, powerup);
			try
			{
				PickupMesh data = PickupMesh.From(PickupModel.Parse(Read("MuckTriTip.pickup.obj"), Read("MuckTriTip.pickup.json")));
				Material val2 = (((Object)(object)val != (Object)null) ? val.material : null);
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = FallbackShader();
				}
				bool vertexColors = (Object)(object)val2 == (Object)null || !val2.HasProperty("_MainTex");
				powerup.mesh = ToMesh(data, powerup.name, vertexColors);
				powerup.material = ToMaterial(data, val2, powerup.name);
			}
			catch (Exception ex)
			{
				TriTipPlugin.Log.LogWarning((object)("Tri-Tip Dagger pickup model was not applied (" + ex.Message + ")."));
				if ((Object)(object)val != (Object)null && (Object)(object)val.mesh != (Object)null)
				{
					powerup.mesh = val.mesh;
					powerup.material = val.material;
				}
				else
				{
					TriTipPlugin.Log.LogWarning((object)"No Blue powerup to borrow a pickup model from; dropped Tri-Tip Daggers will be invisible.");
				}
			}
		}

		private static Powerup Donor(Powerup[] pool, Powerup self)
		{
			if (pool == null)
			{
				return null;
			}
			Powerup val = null;
			foreach (Powerup val2 in pool)
			{
				if (!((Object)(object)val2 == (Object)null) && val2 != self)
				{
					if ((Object)(object)val2.material != (Object)null)
					{
						return val2;
					}
					if ((Object)(object)val == (Object)null && (Object)(object)val2.mesh != (Object)null)
					{
						val = val2;
					}
				}
			}
			return val;
		}

		private static string Read(string name)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
			if (stream == null)
			{
				throw new FileNotFoundException(name);
			}
			using StreamReader streamReader = new StreamReader(stream);
			return streamReader.ReadToEnd();
		}

		private static Mesh ToMesh(PickupMesh data, string itemName, bool vertexColors)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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)
			Mesh val = new Mesh
			{
				name = itemName + " pickup",
				hideFlags = (HideFlags)32
			};
			List<Vector3> list = new List<Vector3>(data.Positions.Length);
			List<Vector3> list2 = new List<Vector3>(data.Normals.Length);
			List<Vector2> list3 = new List<Vector2>(data.U.Length);
			List<Color> list4 = new List<Color>(data.Positions.Length);
			for (int i = 0; i < data.Positions.Length; i++)
			{
				list.Add(new Vector3(data.Positions[i].X, data.Positions[i].Y, data.Positions[i].Z));
				list2.Add(new Vector3(data.Normals[i].X, data.Normals[i].Y, data.Normals[i].Z));
				list3.Add(new Vector2(data.U[i], 0.5f));
				list4.Add((Color)(vertexColors ? new Color(data.R[i], data.G[i], data.B[i], 1f) : Color.white));
			}
			val.SetVertices(list);
			val.SetNormals(list2);
			val.SetUVs(0, list3);
			val.SetColors(list4);
			val.SetTriangles(data.Triangles, 0);
			val.RecalculateBounds();
			return val;
		}

		private static Material FallbackShader()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			Shader val = Shader.Find("Standard");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Diffuse");
			}
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return new Material(val);
		}

		private static Material ToMaterial(PickupMesh data, Material source, string itemName)
		{
			//IL_0075: 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)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: 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)
			if ((Object)(object)source == (Object)null)
			{
				return null;
			}
			if (!source.HasProperty("_MainTex"))
			{
				MaterialSpec materialSpec = data.Palette[0];
				return new Material(source)
				{
					name = itemName + " pickup",
					color = new Color(materialSpec.R, materialSpec.G, materialSpec.B, 1f),
					hideFlags = (HideFlags)32
				};
			}
			Texture2D val = new Texture2D(data.Palette.Count, 1, (TextureFormat)4, false)
			{
				name = itemName + " palette",
				filterMode = (FilterMode)0,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)32
			};
			for (int i = 0; i < data.Palette.Count; i++)
			{
				MaterialSpec materialSpec2 = data.Palette[i];
				val.SetPixel(i, 0, new Color(materialSpec2.R, materialSpec2.G, materialSpec2.B, 1f));
			}
			val.Apply(false, true);
			Material val2 = new Material(source)
			{
				name = itemName + " pickup",
				hideFlags = (HideFlags)32
			};
			val2.mainTexture = (Texture)(object)val;
			val2.mainTextureScale = Vector2.one;
			val2.mainTextureOffset = Vector2.zero;
			if (val2.HasProperty("_Color"))
			{
				val2.color = Color.white;
			}
			return val2;
		}
	}
	internal readonly struct Vec3
	{
		public readonly float X;

		public readonly float Y;

		public readonly float Z;

		public Vec3(float x, float y, float z)
		{
			X = x;
			Y = y;
			Z = z;
		}

		public static Vec3 operator -(Vec3 a, Vec3 b)
		{
			return new Vec3(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
		}
	}
	internal readonly struct MaterialSpec
	{
		public readonly float R;

		public readonly float G;

		public readonly float B;

		public readonly float Emission;

		public MaterialSpec(float r, float g, float b, float emission)
		{
			R = r;
			G = g;
			B = b;
			Emission = emission;
		}
	}
	internal sealed class SubMesh
	{
		public readonly string Material;

		public readonly int[] Triangles;

		public SubMesh(string material, int[] triangles)
		{
			Material = material;
			Triangles = triangles;
		}
	}
	internal sealed class PickupModel
	{
		private sealed class ObjObject
		{
			public readonly List<Vec3> Positions = new List<Vec3>();

			public readonly List<Vec3> Normals = new List<Vec3>();

			public readonly List<string> MaterialOrder = new List<string>();

			public readonly Dictionary<string, List<int>> Triangles = new Dictionary<string, List<int>>();
		}

		public readonly string Name;

		public readonly Vec3[] Positions;

		public readonly Vec3[] Normals;

		public readonly IReadOnlyList<SubMesh> SubMeshes;

		public readonly IReadOnlyDictionary<string, MaterialSpec> Materials;

		public int TriangleCount => Positions.Length / 3;

		public PickupModel(string name, Vec3[] positions, Vec3[] normals, IReadOnlyList<SubMesh> subMeshes, IReadOnlyDictionary<string, MaterialSpec> materials)
		{
			Name = name;
			Positions = positions;
			Normals = normals;
			SubMeshes = subMeshes;
			Materials = materials;
		}

		public static PickupModel Parse(string objText, string json)
		{
			if (!(JsonReader.Parse(json) is Dictionary<string, object> obj))
			{
				throw new FormatException("pickup json: top level is not an object.");
			}
			string text = Str(obj, "name");
			Dictionary<string, MaterialSpec> dictionary = ReadMaterials(Obj(obj, "materials"));
			Dictionary<string, ObjObject> dictionary2 = ReadObj(objText, text);
			if (dictionary2.Count != 1)
			{
				throw new FormatException($"{text}: a pickup OBJ needs exactly one object, it has {dictionary2.Count}.");
			}
			ObjObject objObject = null;
			foreach (ObjObject value in dictionary2.Values)
			{
				objObject = value;
			}
			List<SubMesh> list = new List<SubMesh>();
			foreach (string item in objObject.MaterialOrder)
			{
				if (!dictionary.ContainsKey(item))
				{
					throw new FormatException(text + ": uses undefined material '" + item + "'.");
				}
				list.Add(new SubMesh(item, objObject.Triangles[item].ToArray()));
			}
			PickupModel pickupModel = new PickupModel(text, objObject.Positions.ToArray(), objObject.Normals.ToArray(), list, dictionary);
			int num = (int)Num(obj, "tris");
			if (pickupModel.TriangleCount != num)
			{
				throw new FormatException($"{text}: OBJ has {pickupModel.TriangleCount} triangles, the json says {num}.");
			}
			return pickupModel;
		}

		private static Dictionary<string, ObjObject> ReadObj(string text, string name)
		{
			if (text == null)
			{
				throw new FormatException(name + ": OBJ text is null.");
			}
			List<Vec3> list = new List<Vec3>();
			List<Vec3> list2 = new List<Vec3>();
			Dictionary<string, ObjObject> dictionary = new Dictionary<string, ObjObject>();
			ObjObject objObject = null;
			string text2 = null;
			string[] array = text.Split(new char[1] { '\n' });
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Trim().Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
				if (array2.Length == 0)
				{
					continue;
				}
				switch (array2[0])
				{
				case "v":
				{
					Vec3 vec2 = ReadVec(array2, name, i);
					list.Add(new Vec3(0f - vec2.X, vec2.Y, vec2.Z));
					break;
				}
				case "vn":
				{
					Vec3 vec = ReadVec(array2, name, i);
					list2.Add(new Vec3(0f - vec.X, vec.Y, vec.Z));
					break;
				}
				case "o":
				{
					string text3 = string.Join(" ", array2, 1, array2.Length - 1);
					if (dictionary.ContainsKey(text3))
					{
						throw new FormatException(name + ": OBJ object " + text3 + " appears twice.");
					}
					objObject = new ObjObject();
					dictionary.Add(text3, objObject);
					text2 = null;
					break;
				}
				case "usemtl":
					text2 = ((array2.Length > 1) ? array2[1] : null);
					break;
				case "f":
					if (objObject == null || text2 == null)
					{
						throw new FormatException($"{name}: OBJ line {i + 1} has a face outside an object or material.");
					}
					if (array2.Length != 4)
					{
						throw new FormatException($"{name}: OBJ line {i + 1} is not a triangle.");
					}
					AddTriangle(objObject, text2, list, list2, array2, name, i);
					break;
				}
			}
			return dictionary;
		}

		private static void AddTriangle(ObjObject obj, string material, List<Vec3> vertices, List<Vec3> normals, string[] tokens, string name, int line)
		{
			if (!obj.Triangles.TryGetValue(material, out var value))
			{
				value = new List<int>();
				obj.Triangles.Add(material, value);
				obj.MaterialOrder.Add(material);
			}
			int[] array = new int[3] { 1, 3, 2 };
			foreach (int num in array)
			{
				string[] array2 = tokens[num].Split(new char[1] { '/' });
				Vec3 item = vertices[Index(array2[0], vertices.Count, name, line)];
				if (array2.Length < 3 || array2[2].Length == 0)
				{
					throw new FormatException($"{name}: OBJ line {line + 1} has a corner without a normal.");
				}
				value.Add(obj.Positions.Count);
				obj.Positions.Add(item);
				obj.Normals.Add(normals[Index(array2[2], normals.Count, name, line)]);
			}
		}

		private static int Index(string raw, int count, string name, int line)
		{
			if (!int.TryParse(raw, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) || result == 0)
			{
				throw new FormatException($"{name}: OBJ line {line + 1} has a bad index '{raw}'.");
			}
			int num = ((result > 0) ? (result - 1) : (count + result));
			if (num < 0 || num >= count)
			{
				throw new FormatException($"{name}: OBJ line {line + 1} index {raw} is out of range.");
			}
			return num;
		}

		private static Vec3 ReadVec(string[] tokens, string name, int line)
		{
			if (tokens.Length < 4)
			{
				throw new FormatException($"{name}: OBJ line {line + 1} needs three numbers.");
			}
			return new Vec3(Float(tokens[1], name, line), Float(tokens[2], name, line), Float(tokens[3], name, line));
		}

		private static float Float(string raw, string name, int line)
		{
			if (!float.TryParse(raw, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
			{
				throw new FormatException($"{name}: OBJ line {line + 1} has a bad number '{raw}'.");
			}
			return result;
		}

		private static Dictionary<string, MaterialSpec> ReadMaterials(Dictionary<string, object> raw)
		{
			Dictionary<string, MaterialSpec> dictionary = new Dictionary<string, MaterialSpec>();
			foreach (KeyValuePair<string, object> item in raw)
			{
				if (!(item.Value is Dictionary<string, object> obj))
				{
					throw new FormatException("pickup json: material " + item.Key + " is not an object.");
				}
				Vec3 vec = ReadVec3(obj, "rgb");
				dictionary.Add(item.Key, new MaterialSpec(vec.X, vec.Y, vec.Z, (float)Num(obj, "emission")));
			}
			return dictionary;
		}

		private static Vec3 ReadVec3(Dictionary<string, object> obj, string key)
		{
			List<object> list = Arr(obj, key);
			if (list.Count != 3 || !(list[0] is double num) || !(list[1] is double num2) || !(list[2] is double num3))
			{
				throw new FormatException("pickup json: '" + key + "' is not three numbers.");
			}
			return new Vec3((float)num, (float)num2, (float)num3);
		}

		private static object Field(Dictionary<string, object> obj, string key)
		{
			if (!obj.TryGetValue(key, out var value))
			{
				throw new FormatException("pickup json: missing '" + key + "'.");
			}
			return value;
		}

		private static string Str(Dictionary<string, object> obj, string key)
		{
			return (Field(obj, key) as string) ?? throw new FormatException("pickup json: '" + key + "' is not a string.");
		}

		private static double Num(Dictionary<string, object> obj, string key)
		{
			object obj2 = Field(obj, key);
			if (obj2 is double)
			{
				return (double)obj2;
			}
			throw new FormatException("pickup json: '" + key + "' is not a number.");
		}

		private static List<object> Arr(Dictionary<string, object> obj, string key)
		{
			return (Field(obj, key) as List<object>) ?? throw new FormatException("pickup json: '" + key + "' is not an array.");
		}

		private static Dictionary<string, object> Obj(Dictionary<string, object> obj, string key)
		{
			return (Field(obj, key) as Dictionary<string, object>) ?? throw new FormatException("pickup json: '" + key + "' is not an object.");
		}
	}
	internal sealed class PickupMesh
	{
		public readonly Vec3[] Positions;

		public readonly Vec3[] Normals;

		public readonly float[] U;

		public readonly float[] R;

		public readonly float[] G;

		public readonly float[] B;

		public readonly int[] Triangles;

		public readonly IReadOnlyList<MaterialSpec> Palette;

		private PickupMesh(Vec3[] positions, Vec3[] normals, float[] u, float[] r, float[] g, float[] b, int[] triangles, IReadOnlyList<MaterialSpec> palette)
		{
			Positions = positions;
			Normals = normals;
			U = u;
			R = r;
			G = g;
			B = b;
			Triangles = triangles;
			Palette = palette;
		}

		public static PickupMesh From(PickupModel model)
		{
			Vec3 vec = new Vec3(float.MaxValue, float.MaxValue, float.MaxValue);
			Vec3 vec2 = new Vec3(float.MinValue, float.MinValue, float.MinValue);
			Vec3[] positions = model.Positions;
			for (int i = 0; i < positions.Length; i++)
			{
				Vec3 vec3 = positions[i];
				vec = new Vec3(Math.Min(vec.X, vec3.X), Math.Min(vec.Y, vec3.Y), Math.Min(vec.Z, vec3.Z));
				vec2 = new Vec3(Math.Max(vec2.X, vec3.X), Math.Max(vec2.Y, vec3.Y), Math.Max(vec2.Z, vec3.Z));
			}
			Vec3 vec4 = new Vec3((vec.X + vec2.X) / 2f, (vec.Y + vec2.Y) / 2f, (vec.Z + vec2.Z) / 2f);
			int count = model.SubMeshes.Count;
			List<Vec3> list = new List<Vec3>(model.Positions.Length);
			List<Vec3> list2 = new List<Vec3>(model.Positions.Length);
			List<float> list3 = new List<float>(model.Positions.Length);
			List<float> list4 = new List<float>(model.Positions.Length);
			List<float> list5 = new List<float>(model.Positions.Length);
			List<float> list6 = new List<float>(model.Positions.Length);
			List<MaterialSpec> list7 = new List<MaterialSpec>(count);
			for (int j = 0; j < count; j++)
			{
				SubMesh subMesh = model.SubMeshes[j];
				MaterialSpec item = model.Materials[subMesh.Material];
				list7.Add(item);
				float item2 = ((float)j + 0.5f) / (float)count;
				int[] triangles = subMesh.Triangles;
				foreach (int num in triangles)
				{
					list.Add(model.Positions[num] - vec4);
					list2.Add(model.Normals[num]);
					list3.Add(item2);
					list4.Add(item.R);
					list5.Add(item.G);
					list6.Add(item.B);
				}
			}
			int[] array = new int[list.Count];
			for (int k = 0; k < array.Length; k++)
			{
				array[k] = k;
			}
			return new PickupMesh(list.ToArray(), list2.ToArray(), list3.ToArray(), list4.ToArray(), list5.ToArray(), list6.ToArray(), array, list7);
		}
	}
	internal sealed class JsonReader
	{
		private readonly string text;

		private int pos;

		private JsonReader(string text)
		{
			this.text = text;
		}

		public static object Parse(string text)
		{
			if (text == null)
			{
				throw new FormatException("JSON text is null.");
			}
			JsonReader jsonReader = new JsonReader(text);
			object result = jsonReader.ReadValue();
			jsonReader.SkipWhitespace();
			if (jsonReader.pos != text.Length)
			{
				throw jsonReader.Error("trailing characters");
			}
			return result;
		}

		private object ReadValue()
		{
			SkipWhitespace();
			if (pos >= text.Length)
			{
				throw Error("unexpected end");
			}
			char c = text[pos];
			switch (c)
			{
			case '{':
				return ReadObject();
			case '[':
				return ReadArray();
			case '"':
				return ReadString();
			case 't':
				Expect("true");
				return true;
			case 'f':
				Expect("false");
				return false;
			case 'n':
				Expect("null");
				return null;
			default:
				switch (c)
				{
				case '-':
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9':
					return ReadNumber();
				default:
					throw Error($"unexpected '{c}'");
				}
			}
		}

		private Dictionary<string, object> ReadObject()
		{
			Dictionary<string, object> dictionary = new Dictionary<string, object>();
			pos++;
			SkipWhitespace();
			if (Peek() == '}')
			{
				pos++;
				return dictionary;
			}
			while (true)
			{
				SkipWhitespace();
				if (Peek() != '"')
				{
					throw Error("expected a key");
				}
				string key = ReadString();
				SkipWhitespace();
				if (Peek() != ':')
				{
					break;
				}
				pos++;
				dictionary[key] = ReadValue();
				SkipWhitespace();
				char c = Peek();
				pos++;
				switch (c)
				{
				case ',':
					break;
				case '}':
					return dictionary;
				default:
					throw Error("expected ',' or '}'");
				}
			}
			throw Error("expected ':'");
		}

		private List<object> ReadArray()
		{
			List<object> list = new List<object>();
			pos++;
			SkipWhitespace();
			if (Peek() == ']')
			{
				pos++;
				return list;
			}
			while (true)
			{
				list.Add(ReadValue());
				SkipWhitespace();
				char c = Peek();
				pos++;
				switch (c)
				{
				case ',':
					break;
				case ']':
					return list;
				default:
					throw Error("expected ',' or ']'");
				}
			}
		}

		private string ReadString()
		{
			pos++;
			StringBuilder stringBuilder = new StringBuilder();
			while (pos < text.Length)
			{
				char c = text[pos++];
				switch (c)
				{
				case '"':
					return stringBuilder.ToString();
				default:
					stringBuilder.Append(c);
					break;
				case '\\':
				{
					if (pos >= text.Length)
					{
						throw Error("unterminated escape");
					}
					char c2 = text[pos++];
					switch (c2)
					{
					case '"':
						stringBuilder.Append('"');
						break;
					case '\\':
						stringBuilder.Append('\\');
						break;
					case '/':
						stringBuilder.Append('/');
						break;
					case 'b':
						stringBuilder.Append('\b');
						break;
					case 'f':
						stringBuilder.Append('\f');
						break;
					case 'n':
						stringBuilder.Append('\n');
						break;
					case 'r':
						stringBuilder.Append('\r');
						break;
					case 't':
						stringBuilder.Append('\t');
						break;
					case 'u':
						if (pos + 4 > text.Length)
						{
							throw Error("short \\u escape");
						}
						stringBuilder.Append((char)int.Parse(text.Substring(pos, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture));
						pos += 4;
						break;
					default:
						throw Error($"bad escape '\\{c2}'");
					}
					break;
				}
				}
			}
			throw Error("unterminated string");
		}

		private double ReadNumber()
		{
			int num = pos;
			while (pos < this.text.Length && "+-0123456789.eE".IndexOf(this.text[pos]) >= 0)
			{
				pos++;
			}
			string text = this.text.Substring(num, pos - num);
			if (!double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
			{
				throw Error("bad number '" + text + "'");
			}
			return result;
		}

		private void Expect(string word)
		{
			if (string.CompareOrdinal(text, pos, word, 0, word.Length) != 0)
			{
				throw Error("expected '" + word + "'");
			}
			pos += word.Length;
		}

		private char Peek()
		{
			if (pos >= text.Length)
			{
				return '\0';
			}
			return text[pos];
		}

		private void SkipWhitespace()
		{
			while (pos < text.Length && char.IsWhiteSpace(text[pos]))
			{
				pos++;
			}
		}

		private FormatException Error(string what)
		{
			return new FormatException($"JSON: {what} at offset {pos}.");
		}
	}
	internal sealed class PlayerHit
	{
		public readonly int Damage;

		public readonly int WeaponBase;

		public readonly float Strength;

		private PlayerHit(int damage, int weaponBase, float strength)
		{
			Damage = damage;
			WeaponBase = weaponBase;
			Strength = strength;
		}

		public static bool Accepts(int weaponType, int damage, int hp, bool insideBleedTick)
		{
			if (weaponType >= 0 && damage > 0 && hp > 0)
			{
				return !insideBleedTick;
			}
			return false;
		}

		public static bool TryParse(int weaponType, int damage, int hp, bool insideBleedTick, int weaponBase, float strength, out PlayerHit hit)
		{
			if (Accepts(weaponType, damage, hp, insideBleedTick))
			{
				hit = new PlayerHit(damage, (weaponBase <= 1) ? 1 : weaponBase, (strength > 0f && strength < float.PositiveInfinity) ? strength : 1f);
				return true;
			}
			hit = null;
			return false;
		}

		public static int WeaponAttack(int heldAttack, bool heldIsBow, bool heldIsArrow, int arrowAttack)
		{
			if (heldIsBow)
			{
				return (int)Math.Min((long)heldAttack * (long)arrowAttack, 2147483647L);
			}
			if (heldIsArrow)
			{
				return 1;
			}
			return heldAttack;
		}
	}
	internal readonly struct PowerupClaim
	{
		public readonly bool Claimed;

		public readonly int Id;

		private PowerupClaim(bool claimed, int id)
		{
			Claimed = claimed;
			Id = id;
		}

		public static PowerupClaim Resolve(bool nameExists, bool existingIsOurs, int existingId, IEnumerable<int> existingIds)
		{
			if (nameExists && !existingIsOurs)
			{
				return new PowerupClaim(claimed: false, 0);
			}
			return new PowerupClaim(claimed: true, PowerupIds.Resolve(existingIds, nameExists, existingId));
		}
	}
	internal static class PowerupIds
	{
		public static int Resolve(IEnumerable<int> existingIds, bool nameExists, int existingId)
		{
			if (nameExists)
			{
				return existingId;
			}
			int num = 0;
			bool flag = false;
			foreach (int existingId2 in existingIds)
			{
				if (!flag || existingId2 > num)
				{
					num = existingId2;
					flag = true;
				}
			}
			if (!flag)
			{
				return 0;
			}
			return num + 1;
		}
	}
	internal sealed class TriTipConfig
	{
		public readonly ConfigEntry<float> ChancePerDagger;

		public readonly ConfigEntry<float> BaseDamageFractionPerTick;

		public readonly ConfigEntry<float> ProcBleedSeconds;

		public readonly ConfigEntry<KeyboardShortcut> GiveDaggerKey;

		public readonly ConfigEntry<bool> VerboseLogging;

		private DaggerRules _rules;

		public TriTipConfig(ConfigFile cfg)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			ChancePerDagger = cfg.Bind<float>("Tri-Tip Dagger", "ChancePerDagger", 0.1f, new ConfigDescription("Chance (0 to 1) per dagger that a melee swing or arrow hit applies one bleed. The total stops at 1. Default 0.1.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			BaseDamageFractionPerTick = cfg.Bind<float>("Tri-Tip Dagger", "BaseDamageFractionPerTick", 0.2f, new ConfigDescription("Damage each bleed deals per tick, as a fraction (0 to 10) of your base damage: the held weapon's attack (bow attack times arrow attack for a bow) times your strength multiplier. Crit, Sniper Scope, Crowbar and other hit multipliers do not count. Ticks run 4 times a second, so the default 0.2 over 3 seconds is 240% base damage per bleed. Default 0.2.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			ProcBleedSeconds = cfg.Bind<float>("Tri-Tip Dagger", "ProcBleedSeconds", 3f, new ConfigDescription("How long each bleed lasts, in seconds (0.25 to 30). Each proc has its own clock, rounded to whole ticks at 4 per second, at least 1 tick. A new proc does not extend older ones. Default 3.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 30f), Array.Empty<object>()));
			GiveDaggerKey = cfg.Bind<KeyboardShortcut>("Debug", "GiveDaggerKey", KeyboardShortcut.Empty, "Press in-game to give yourself one Tri-Tip Dagger stack (local test helper; e.g. F8). Empty = disabled.");
			VerboseLogging = cfg.Bind<bool>("Debug", "VerboseLogging", false, "Log every proc and tick.");
			cfg.SettingChanged += delegate
			{
				_rules = null;
				TriTipPowerup.RefreshDescription();
			};
		}

		public DaggerRules Rules()
		{
			if (_rules == null)
			{
				_rules = DaggerRules.Create(ChancePerDagger.Value, BaseDamageFractionPerTick.Value, ProcBleedSeconds.Value);
			}
			return _rules;
		}
	}
	[BepInPlugin("evan.muck.tritipdagger", "Tri-Tip Dagger", "0.2.1")]
	public class TriTipPlugin : BaseUnityPlugin
	{
		public const string Guid = "evan.muck.tritipdagger";

		public const string Name = "Tri-Tip Dagger";

		public const string Version = "0.2.1";

		internal static ManualLogSource Log;

		internal static TriTipConfig Cfg;

		private void Awake()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Cfg = new TriTipConfig(((BaseUnityPlugin)this).Config);
			Harmony val = new Harmony("evan.muck.tritipdagger");
			if (!HitableMobHitPatch.Apply(val))
			{
				Log.LogError((object)"Tri-Tip Dagger hit patch failed. The item will not be added to the drop pool.");
				return;
			}
			try
			{
				val.PatchAll(typeof(TriTipPlugin).Assembly);
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Tri-Tip Dagger registration patch failed. The item will not drop. {arg}");
				return;
			}
			TriTipPowerup.Create();
			Log.LogInfo((object)"Tri-Tip Dagger 0.2.1 loaded. Every player in a lobby needs this mod (same version).");
		}

		private void Update()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = Cfg.GiveDaggerKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				TriTipPowerup.GiveOneLocal();
			}
		}
	}
	internal static class TriTipPowerup
	{
		public const string PowerupName = "Tri-Tip Dagger";

		private static FieldRef<PowerupInventory, int[]> _powerupCounts;

		private static bool _countsLookupFailed;

		private static bool _loggedPastInventory;

		public static Powerup Definition { get; private set; }

		public static int Id { get; internal set; } = -1;

		public static void Create()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			Powerup obj = ScriptableObject.CreateInstance<Powerup>();
			obj.name = "Tri-Tip Dagger";
			((Object)obj).name = "Tri-Tip Dagger";
			obj.tier = (PowerTier)1;
			obj.sprite = LoadIcon();
			((Object)obj).hideFlags = (HideFlags)32;
			Definition = obj;
			RefreshDescription();
		}

		public static void RefreshDescription()
		{
			if (!((Object)(object)Definition == (Object)null) && TriTipPlugin.Cfg != null)
			{
				Definition.description = TriTipPlugin.Cfg.Rules().Description();
			}
		}

		public static int LocalStacks()
		{
			PowerupInventory instance = PowerupInventory.Instance;
			if ((Object)(object)instance == (Object)null || Id < 0)
			{
				return 0;
			}
			int[] array = Counts(instance);
			if (array == null)
			{
				return 0;
			}
			if (Id >= array.Length)
			{
				LogPastInventoryOnce(array.Length);
				return 0;
			}
			return array[Id];
		}

		private static int[] Counts(PowerupInventory inventory)
		{
			if (_countsLookupFailed || (Object)(object)inventory == (Object)null)
			{
				return null;
			}
			if (_powerupCounts == null)
			{
				try
				{
					_powerupCounts = AccessTools.FieldRefAccess<PowerupInventory, int[]>("powerups");
				}
				catch (Exception ex)
				{
					_countsLookupFailed = true;
					TriTipPlugin.Log.LogError((object)("Tri-Tip Dagger could not read PowerupInventory.powerups. Stack reads stay 0. " + ex.Message));
					return null;
				}
			}
			return _powerupCounts.Invoke(inventory);
		}

		private static void LogPastInventoryOnce(int length)
		{
			if (!_loggedPastInventory)
			{
				_loggedPastInventory = true;
				TriTipPlugin.Log.LogWarning((object)$"Tri-Tip Dagger id {Id} is past the inventory length {length}. A gap in the powerup ids can miss an array sized to the count. Stack reads stay 0.");
			}
		}

		public static void GiveOneLocal()
		{
			PowerupInventory instance = PowerupInventory.Instance;
			int[] array = (((Object)(object)instance != (Object)null) ? Counts(instance) : null);
			if (array == null || Id < 0 || Id >= array.Length)
			{
				if (array != null && Id >= array.Length)
				{
					LogPastInventoryOnce(array.Length);
				}
				TriTipPlugin.Log.LogWarning((object)"Can't give Tri-Tip Dagger: not in a game yet, or the powerup isn't registered.");
				return;
			}
			array[Id]++;
			PowerupUI instance2 = PowerupUI.Instance;
			if ((Object)(object)instance2 != (Object)null)
			{
				instance2.AddPowerup(Id);
			}
			PlayerStatus instance3 = PlayerStatus.Instance;
			if ((Object)(object)instance3 != (Object)null)
			{
				instance3.UpdateStats();
			}
			TriTipPlugin.Log.LogInfo((object)$"Debug: Tri-Tip Dagger stacks now {array[Id]} (local only; the host's copy of your powerups is not updated).");
		}

		private static Sprite LoadIcon()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				using Stream stream = typeof(TriTipPowerup).Assembly.GetManifestResourceStream("MuckTriTip.icon.png");
				if (stream == null)
				{
					throw new FileNotFoundException("embedded icon.png missing");
				}
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val, memoryStream.ToArray()))
				{
					throw new InvalidDataException("icon.png failed to decode");
				}
				((Object)val).name = "TriTipDaggerIcon";
				((Object)val).hideFlags = (HideFlags)32;
				Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
				((Object)obj).name = "TriTipDaggerIcon";
				((Object)obj).hideFlags = (HideFlags)32;
				return obj;
			}
			catch (Exception arg)
			{
				TriTipPlugin.Log.LogError((object)$"Failed to load Tri-Tip Dagger icon: {arg}");
				return null;
			}
		}
	}
	[HarmonyPatch(typeof(ItemManager), "InitAllPowerups")]
	internal static class RegisterTriTipPatch
	{
		[HarmonyPriority(600)]
		[HarmonyAfter(new string[] { "evan.muck.ukulele", "evan.muck.atgmissile", "evan.muck.crowbar", "evan.muck.stickybomb" })]
		private static void Postfix(ItemManager __instance)
		{
			Powerup definition = TriTipPowerup.Definition;
			if ((Object)(object)definition == (Object)null)
			{
				return;
			}
			Dictionary<int, Powerup> allPowerups = __instance.allPowerups;
			Dictionary<string, int> stringToPowerupId = __instance.stringToPowerupId;
			int value;
			bool flag = stringToPowerupId.TryGetValue("Tri-Tip Dagger", out value);
			Powerup value2;
			bool existingIsOurs = flag && allPowerups.TryGetValue(value, out value2) && (Object)(object)value2 == (Object)(object)definition;
			PowerupClaim powerupClaim = PowerupClaim.Resolve(flag, existingIsOurs, value, allPowerups.Keys);
			if (!powerupClaim.Claimed)
			{
				TriTipPlugin.Log.LogError((object)string.Format("The name {0} is already powerup id {1}. This mod will not add another pool entry.", "Tri-Tip Dagger", value));
				return;
			}
			PickupArt.Apply(definition, __instance.powerupsBlue);
			int id = powerupClaim.Id;
			if (!flag)
			{
				allPowerups.Add(id, definition);
				stringToPowerupId.Add("Tri-Tip Dagger", id);
			}
			definition.id = id;
			if (!__instance.powerupsBlue.Contains(definition))
			{
				__instance.powerupsBlue = CollectionExtensions.AddToArray<Powerup>(__instance.powerupsBlue, definition);
			}
			TriTipPowerup.Id = id;
			if (id >= allPowerups.Count)
			{
				TriTipPlugin.Log.LogWarning((object)$"Tri-Tip Dagger id {id} is past allPowerups.Count ({allPowerups.Count}). A gap in the ids can miss an inventory array sized to that count.");
			}
			TriTipPlugin.Log.LogInfo((object)$"Registered Tri-Tip Dagger as Blue powerup id {id} ({allPowerups.Count} powerups total, {__instance.powerupsBlue.Length} in the Blue pool).");
			if (TriTipPlugin.Cfg.VerboseLogging.Value)
			{
				TriTipPlugin.Log.LogInfo((object)("Powerup ids: " + string.Join(", ", from kv in allPowerups
					orderby kv.Key
					select $"{kv.Key}={kv.Value.name}")));
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MuckTriTip";

		public const string PLUGIN_NAME = "Tri-Tip Dagger";

		public const string PLUGIN_VERSION = "0.2.1";
	}
}