Decompiled source of BingusModRevived v1.1.6

BingusMod.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using LookingGlass.ItemStatsNameSpace;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
using RiskyMod.Allies;
using RoR2;
using RoR2.CharacterAI;
using UnityEngine;
using UnityEngine.Networking;

[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: AssemblyCompany("BingusMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BingusMod")]
[assembly: AssemblyTitle("BingusMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BingusMod
{
	internal class Assets
	{
		internal class BingusBehavior : ItemBehavior
		{
			internal const float Cooldown = 20f;

			private bool wasHealthLow;

			private float cooldownTimer;

			private void FixedUpdate()
			{
				if (NetworkServer.active && Object.op_Implicit((Object)(object)base.body) && Object.op_Implicit((Object)(object)base.body.healthComponent))
				{
					if (cooldownTimer > 0f)
					{
						cooldownTimer -= Time.fixedDeltaTime;
					}
					bool flag = base.body.healthComponent.alive && base.body.healthComponent.isHealthLow;
					if (flag && !wasHealthLow && cooldownTimer <= 0f)
					{
						cooldownTimer = 20f;
						CharmEnemies(base.stack + 1);
					}
					wasHealthLow = flag;
				}
			}

			private static void CharmEnemies(int count)
			{
				List<CharacterMaster> list = new List<CharacterMaster>();
				foreach (TeamComponent teamMember in TeamComponent.GetTeamMembers((TeamIndex)2))
				{
					CharacterBody val = (Object.op_Implicit((Object)(object)teamMember) ? teamMember.body : null);
					if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.healthComponent) && val.healthComponent.alive)
					{
						CharacterMaster master = val.master;
						if (Object.op_Implicit((Object)(object)master) && !master.isBoss && Object.op_Implicit((Object)(object)((Component)master).GetComponent<BaseAI>()))
						{
							list.Add(master);
						}
					}
				}
				bool flag = Chainloader.PluginInfos.ContainsKey("com.RiskyLives.RiskyMod");
				for (int i = 0; i < count; i++)
				{
					if (list.Count <= 0)
					{
						break;
					}
					int index = Random.Range(0, list.Count);
					CharacterMaster val2 = list[index];
					list.RemoveAt(index);
					CharacterBody body = val2.GetBody();
					if (flag && Object.op_Implicit((Object)(object)body.inventory))
					{
						RiskyModCompat(body.inventory);
					}
					((Component)val2).gameObject.AddComponent<CharmedEnemy>().Charm(val2);
				}
			}
		}

		internal class CharmedEnemy : MonoBehaviour
		{
			internal const float Duration = 15f;

			private CharacterMaster master;

			private TeamIndex originalTeam;

			private float timer;

			internal void Charm(CharacterMaster master)
			{
				//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)
				this.master = master;
				originalTeam = master.teamIndex;
				timer = 15f;
				SetTeam((TeamIndex)1);
			}

			private void FixedUpdate()
			{
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				if (!NetworkServer.active)
				{
					return;
				}
				timer -= Time.fixedDeltaTime;
				if (!(timer > 0f))
				{
					SetTeam(originalTeam);
					Inventory val = (Object.op_Implicit((Object)(object)master) ? master.inventory : null);
					if (Object.op_Implicit((Object)(object)val) && Chainloader.PluginInfos.ContainsKey("com.RiskyLives.RiskyMod"))
					{
						RiskyModUncharm(val);
					}
					Object.Destroy((Object)(object)this);
				}
			}

			private void SetTeam(TeamIndex team)
			{
				//IL_001b: 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)
				if (Object.op_Implicit((Object)(object)master))
				{
					master.teamIndex = team;
					CharacterBody body = master.GetBody();
					if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.teamComponent))
					{
						body.teamComponent.teamIndex = team;
					}
					BaseAI component = ((Component)master).GetComponent<BaseAI>();
					if (Object.op_Implicit((Object)(object)component))
					{
						component.currentEnemy.Reset();
						component.ForceAcquireNearestEnemyIfNoCurrentEnemy();
					}
				}
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_OnInventoryChanged <>9__7_0;

			internal void <BingusAsRedTierItem>b__7_0(orig_OnInventoryChanged orig, CharacterBody self)
			{
				orig.Invoke(self);
				if (NetworkServer.active && self.isPlayerControlled)
				{
					self.AddItemBehavior<BingusBehavior>(self.inventory.GetItemCountEffective(BingusItemDef));
				}
			}
		}

		internal static GameObject BingusPrefab;

		internal static Sprite BingusIcon;

		internal static ItemDef BingusItemDef;

		private const string ModPrefix = "@BingusMod:";

		internal static void Init()
		{
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BingusMod.ror2bingus"))
			{
				AssetBundle val = AssetBundle.LoadFromStream(stream);
				BingusPrefab = val.LoadAsset<GameObject>("Assets/Import/bingus/bingus.prefab");
				BingusIcon = val.LoadAsset<Sprite>("Assets/Import/bingus_icon/bingus_icon.png");
			}
			BingusAsRedTierItem();
			AddLanguageTokens();
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void RiskyModCompat(Inventory inv)
		{
			inv.GiveItemPermanent(AllyItems.AllyMarkerItem, 1);
			inv.GiveItemPermanent(AllyItems.AllyScalingItem, 1);
			inv.GiveItemPermanent(AllyItems.AllyRegenItem, 40);
			inv.GiveItemPermanent(AllyItems.AllyAllowVoidDeathItem, 1);
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void RiskyModUncharm(Inventory inv)
		{
			inv.RemoveItemPermanent(AllyItems.AllyMarkerItem, 1);
			inv.RemoveItemPermanent(AllyItems.AllyScalingItem, 1);
			inv.RemoveItemPermanent(AllyItems.AllyRegenItem, 40);
			inv.RemoveItemPermanent(AllyItems.AllyAllowVoidDeathItem, 1);
		}

		private static void BingusAsRedTierItem()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_0112: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			BingusItemDef = ScriptableObject.CreateInstance<ItemDef>();
			ItemDef bingusItemDef = BingusItemDef;
			((Object)bingusItemDef).name = "BINGUS";
			bingusItemDef.deprecatedTier = (ItemTier)2;
			bingusItemDef.pickupModelPrefab = BingusPrefab;
			bingusItemDef.pickupIconSprite = BingusIcon;
			bingusItemDef.nameToken = "BINGUS_NAME";
			bingusItemDef.pickupToken = "BINGUS_PICKUP";
			bingusItemDef.descriptionToken = "BINGUS_DESC";
			bingusItemDef.loreToken = "BINGUS_LORE";
			ItemTag[] array = new ItemTag[4];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			bingusItemDef.tags = (ItemTag[])(object)array;
			ItemDisplayRule[] array2 = (ItemDisplayRule[])(object)new ItemDisplayRule[1];
			array2[0].followerPrefab = BingusPrefab;
			array2[0].childName = "Head";
			array2[0].localScale = new Vector3(1f, 1f, 1f);
			array2[0].localAngles = new Vector3(-90f, 0f, 0f);
			array2[0].localPos = new Vector3(0f, -0.25f, -0.34f);
			CustomItem val = new CustomItem(BingusItemDef, array2);
			ItemAPI.Add(val);
			object obj = <>c.<>9__7_0;
			if (obj == null)
			{
				hook_OnInventoryChanged val2 = delegate(orig_OnInventoryChanged orig, CharacterBody self)
				{
					orig.Invoke(self);
					if (NetworkServer.active && self.isPlayerControlled)
					{
						self.AddItemBehavior<BingusBehavior>(self.inventory.GetItemCountEffective(BingusItemDef));
					}
				};
				<>c.<>9__7_0 = val2;
				obj = (object)val2;
			}
			CharacterBody.OnInventoryChanged += (hook_OnInventoryChanged)obj;
		}

		private static void AddLanguageTokens()
		{
			LanguageAPI.Add("BINGUS_NAME", "Bingus");
			LanguageAPI.Add("BINGUS_PICKUP", "Entering <style=cDeath>low health state</style> charms enemies");
			LanguageAPI.Add("BINGUS_DESC", "Entering <style=cDeath>low health state</style> charms <style=cIsUtility>2</style> enemies <style=cStack>(+1 per stack)</style> for <style=cIsUtility>15</style> seconds. Recharges every <style=cIsUtility>20</style> seconds. Why? because they are stupid and think bingus squish is cute.");
			LanguageAPI.Add("BINGUS_LORE", "do not let its look fool you, it's a class-534 threat.");
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.phreel.bingusmodrevived", "Bingus Mod", "1.1.6")]
	public class CustomItem : BaseUnityPlugin
	{
		private const string ModVer = "1.1.6";

		private const string ModName = "Bingus Mod";

		public const string ModGuid = "com.phreel.bingusmodrevived";

		internal static ManualLogSource Logger;

		public void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Assets.Init();
			bool value = ((BaseUnityPlugin)this).Config.Bind<bool>("Mod Compatability: LookingGlass", "Enable Compatability Patches?", true, "Add item stats to LookingGlass (if installed)?").Value;
			if (LookingGlassCompat.IsLookingGlassInstalled && value)
			{
				LookingGlassCompat.Init();
			}
		}
	}
	internal static class LookingGlassCompat
	{
		public const string GUID = "droppod.lookingglass";

		public static bool IsLookingGlassInstalled => Chainloader.PluginInfos.ContainsKey("droppod.lookingglass");

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static void Init()
		{
			((ResourceAvailability)(ref ItemCatalog.availability)).CallWhenAvailable((Action)RegisterItemStats);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void RegisterItemStats()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected I4, but got Unknown
			try
			{
				ItemDef bingusItemDef = Assets.BingusItemDef;
				if (Object.op_Implicit((Object)(object)bingusItemDef) && (int)bingusItemDef.itemIndex != -1)
				{
					ItemStatsDef val = new ItemStatsDef();
					val.descriptions.Add("Enemies Charmed: ");
					val.valueTypes.Add((ValueType)2);
					val.measurementUnits.Add((MeasurementUnits)4);
					val.descriptions.Add("Charm Duration: ");
					val.valueTypes.Add((ValueType)2);
					val.measurementUnits.Add((MeasurementUnits)6);
					val.descriptions.Add("Cooldown: ");
					val.valueTypes.Add((ValueType)2);
					val.measurementUnits.Add((MeasurementUnits)6);
					val.calculateValuesFlat = (int count) => new List<float>
					{
						count + 1,
						15f,
						20f
					};
					ItemDefinitions.allItemDefinitions[(int)bingusItemDef.itemIndex] = val;
				}
			}
			catch (Exception ex)
			{
				CustomItem.Logger.LogError((object)("Failed to register LookingGlass item stats: " + ex));
			}
		}
	}
}