Decompiled source of Munster Energy Items v1.0.0

ItemPack.dll

Decompiled 4 days ago
using System;
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.Logging;
using ItemPack.Items;
using Microsoft.CodeAnalysis;
using R2API;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;

[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("ItemPack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3f724776dc2720966f0b2915f7417dc4a895aefd")]
[assembly: AssemblyProduct("ItemPack")]
[assembly: AssemblyTitle("ItemPack")]
[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 ItemPack
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.JohnGroton.ItemPack", "Munster Energy Items", "1.0.0")]
	public class ItemPackPlugin : BaseUnityPlugin
	{
		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			new MunsterEnergy().Init();
			new WhiteMunster().Init();
			Log.Info("ItemPack loaded");
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}
namespace ItemPack.Items
{
	public static class CanAssets
	{
		private const string energyDrinkPickupPath = "RoR2/Base/SprintBonus/PickupSoda.prefab";

		private static GameObject prefabHolder;

		public static GameObject CreateCanModel(string modelName, string textureResource)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			GameObject val = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/SprintBonus/PickupSoda.prefab").WaitForCompletion();
			if (!Object.op_Implicit((Object)(object)val))
			{
				Log.Error("Couldn't load Energy Drink model at 'RoR2/Base/SprintBonus/PickupSoda.prefab', using placeholder.");
				return null;
			}
			Texture2D val2 = LoadEmbeddedTexture(textureResource);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				return null;
			}
			GameObject val3 = Object.Instantiate<GameObject>(val, GetPrefabHolder().transform);
			((Object)val3).name = modelName;
			Renderer[] componentsInChildren = val3.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val4 in componentsInChildren)
			{
				Material[] sharedMaterials = val4.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (Object.op_Implicit((Object)(object)sharedMaterials[j]))
					{
						sharedMaterials[j] = new Material(sharedMaterials[j])
						{
							mainTexture = (Texture)(object)val2
						};
					}
				}
				val4.sharedMaterials = sharedMaterials;
			}
			return val3;
		}

		public static Sprite CreateIconSprite(string textureResource)
		{
			//IL_0031: 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)
			Texture2D val = LoadEmbeddedTexture(textureResource);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			((Texture)val).filterMode = (FilterMode)1;
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}

		private static Texture2D LoadEmbeddedTexture(string resourceName)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
			if (stream == null)
			{
				Log.Error("Embedded texture '" + resourceName + "' not found. Is it marked as EmbeddedResource in the csproj?");
				return null;
			}
			byte[] array = new byte[stream.Length];
			for (int i = 0; i < array.Length; i += stream.Read(array, i, array.Length - i))
			{
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, array);
			((Texture)val).filterMode = (FilterMode)0;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Object)val).name = Path.GetFileNameWithoutExtension(resourceName);
			return val;
		}

		private static GameObject GetPrefabHolder()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)prefabHolder))
			{
				prefabHolder = new GameObject("ItemPackPrefabs");
				prefabHolder.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)prefabHolder);
			}
			return prefabHolder;
		}
	}
	public class MunsterEnergy
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static StatHookEventHandler <0>__OnGetStatCoefficients;
		}

		public static ItemDef itemDef;

		public const float damagePerStack = 0.05f;

		public const float speedPerStack = 0.1f;

		private const string canTextureResource = "ItemPack.Assets.texMunsterCan.png";

		private const string iconTextureResource = "ItemPack.Assets.mpreviewfinal.png";

		public void Init()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00f7: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			itemDef = ScriptableObject.CreateInstance<ItemDef>();
			((Object)itemDef).name = "MUNSTERENERGY";
			itemDef.nameToken = "ITEMPACK_MUNSTERENERGY_NAME";
			itemDef.pickupToken = "ITEMPACK_MUNSTERENERGY_DESC";
			itemDef.descriptionToken = "ITEMPACK_MUNSTERENERGY_DESC";
			itemDef.loreToken = "ITEMPACK_MUNSTERENERGY_LORE";
			itemDef.deprecatedTier = (ItemTier)0;
			itemDef.tags = (ItemTag[])(object)new ItemTag[2]
			{
				(ItemTag)1,
				(ItemTag)3
			};
			itemDef.canRemove = true;
			itemDef.hidden = false;
			itemDef.pickupIconSprite = CanAssets.CreateIconSprite("ItemPack.Assets.mpreviewfinal.png") ?? Addressables.LoadAssetAsync<Sprite>((object)"RoR2/Base/Common/MiscIcons/texMysteryIcon.png").WaitForCompletion();
			itemDef.pickupModelPrefab = CanAssets.CreateCanModel("PickupMunsterEnergy", "ItemPack.Assets.texMunsterCan.png") ?? Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Mystery/PickupMystery.prefab").WaitForCompletion();
			ItemAPI.Add(new CustomItem(itemDef, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
			LanguageAPI.Add("ITEMPACK_MUNSTERENERGY_NAME", "Munster Energy");
			LanguageAPI.Add("ITEMPACK_MUNSTERENERGY_DESC", $"Increase <style=cIsDamage>damage</style> by <style=cIsDamage>{5f:0.##}%</style> <style=cStack>(+{5f:0.##}% per stack)</style>. " + $"Increase <style=cIsUtility>movement speed</style> by <style=cIsUtility>{10f:0.##}%</style> <style=cStack>(+{10f:0.##}% per stack)</style>.");
			LanguageAPI.Add("ITEMPACK_MUNSTERENERGY_LORE", "Contains 160mg of caffeine and an unspecified amount of cheese. Do not ask about the cheese.");
			object obj = <>O.<0>__OnGetStatCoefficients;
			if (obj == null)
			{
				StatHookEventHandler val = OnGetStatCoefficients;
				<>O.<0>__OnGetStatCoefficients = val;
				obj = (object)val;
			}
			RecalculateStatsAPI.GetStatCoefficients += (StatHookEventHandler)obj;
		}

		private static void OnGetStatCoefficients(CharacterBody body, StatHookEventArgs args)
		{
			if (Object.op_Implicit((Object)(object)body.inventory))
			{
				int itemCount = body.inventory.GetItemCount(itemDef);
				if (itemCount > 0)
				{
					args.damageMultAdd += 0.05f * (float)itemCount;
					args.moveSpeedMultAdd += 0.1f * (float)itemCount;
				}
			}
		}
	}
	public class WhiteMunster
	{
		private class ShieldWatcher : ItemBehavior
		{
			private bool hadShield;

			private void FixedUpdate()
			{
				bool flag = HasShield(base.body);
				if (flag != hadShield)
				{
					hadShield = flag;
					base.body.MarkAllStatsDirty();
				}
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static StatHookEventHandler <0>__OnGetStatCoefficients;

			public static Action<CharacterBody> <1>__OnBodyInventoryChanged;
		}

		public static ItemDef itemDef;

		public const float bonusPerStack = 0.2f;

		public const float penaltyPerStack = 0.2f;

		private const string canTextureResource = "ItemPack.Assets.WhitemonsterTexReal_512.png";

		private const string iconTextureResource = "ItemPack.Assets.whiteMonsterFinalPreview.png";

		public void Init()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00f7: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			itemDef = ScriptableObject.CreateInstance<ItemDef>();
			((Object)itemDef).name = "WHITEMUNSTER";
			itemDef.nameToken = "ITEMPACK_WHITEMUNSTER_NAME";
			itemDef.pickupToken = "ITEMPACK_WHITEMUNSTER_DESC";
			itemDef.descriptionToken = "ITEMPACK_WHITEMUNSTER_DESC";
			itemDef.loreToken = "ITEMPACK_WHITEMUNSTER_LORE";
			itemDef.deprecatedTier = (ItemTier)3;
			itemDef.tags = (ItemTag[])(object)new ItemTag[2]
			{
				(ItemTag)1,
				(ItemTag)3
			};
			itemDef.canRemove = true;
			itemDef.hidden = false;
			itemDef.pickupIconSprite = CanAssets.CreateIconSprite("ItemPack.Assets.whiteMonsterFinalPreview.png") ?? Addressables.LoadAssetAsync<Sprite>((object)"RoR2/Base/Common/MiscIcons/texMysteryIcon.png").WaitForCompletion();
			itemDef.pickupModelPrefab = CanAssets.CreateCanModel("PickupWhiteMunster", "ItemPack.Assets.WhitemonsterTexReal_512.png") ?? Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Mystery/PickupMystery.prefab").WaitForCompletion();
			ItemAPI.Add(new CustomItem(itemDef, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
			LanguageAPI.Add("ITEMPACK_WHITEMUNSTER_NAME", "White Munster");
			LanguageAPI.Add("ITEMPACK_WHITEMUNSTER_DESC", $"While you have <style=cIsHealing>shield</style>, increase <style=cIsDamage>damage</style> and <style=cIsUtility>movement speed</style> by <style=cIsDamage>{20f:0.##}%</style> <style=cStack>(+{20f:0.##}% per stack)</style>. " + $"Without <style=cIsHealing>shield</style>, reduce them by <style=cIsHealth>{20f:0.##}%</style> <style=cStack>(-{20f:0.##}% per stack, compounding)</style>.");
			LanguageAPI.Add("ITEMPACK_WHITEMUNSTER_LORE", "Zero sugar. Zero cheese. The can is cold to the touch, and it stays that way.");
			object obj = <>O.<0>__OnGetStatCoefficients;
			if (obj == null)
			{
				StatHookEventHandler val = OnGetStatCoefficients;
				<>O.<0>__OnGetStatCoefficients = val;
				obj = (object)val;
			}
			RecalculateStatsAPI.GetStatCoefficients += (StatHookEventHandler)obj;
			CharacterBody.onBodyInventoryChangedGlobal += OnBodyInventoryChanged;
		}

		private static bool HasShield(CharacterBody body)
		{
			if (Object.op_Implicit((Object)(object)body.healthComponent))
			{
				return body.healthComponent.shield > 0f;
			}
			return false;
		}

		private static void OnGetStatCoefficients(CharacterBody body, StatHookEventArgs args)
		{
			if (Object.op_Implicit((Object)(object)body.inventory))
			{
				int itemCount = body.inventory.GetItemCount(itemDef);
				if (itemCount > 0)
				{
					float num = (HasShield(body) ? (0.2f * (float)itemCount) : (Mathf.Pow(0.8f, (float)itemCount) - 1f));
					args.damageMultAdd += num;
					args.moveSpeedMultAdd += num;
				}
			}
		}

		private static void OnBodyInventoryChanged(CharacterBody body)
		{
			body.AddItemBehavior<ShieldWatcher>(body.inventory.GetItemCount(itemDef));
		}
	}
}