Decompiled source of MuckArrows v1.2.0

MuckArrows.dll

Decompiled 4 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 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("MuckArrows")]
[assembly: AssemblyConfiguration("RELEASE")]
[assembly: AssemblyDescription("A plugin which adds various arrows, like Stone, Ruby, Chunkium, Obamium. Allows modifying arrow damage.")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+c83f9cd55aa6877169f18117cf58bacd7dbf7b9a")]
[assembly: AssemblyProduct("MuckArrows")]
[assembly: AssemblyTitle("MuckArrows")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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;
		}
	}
}
namespace BepInEx
{
	public static class Extensions
	{
		public static void LogItemCreated(this ManualLogSource log, InventoryItem item)
		{
			log.LogInfo((object)("Item \"" + item.name + "\" created, ID " + item.id));
		}

		public static ConfigEntry<int> BindMoreThanZero(this ConfigFile config, string section, string key, int defaultValue, string description)
		{
			ConfigEntry<int> val = config.Bind<int>(section, key, defaultValue, description);
			if (val.Value <= 0)
			{
				val.Value = defaultValue;
			}
			return val;
		}

		public static ConfigEntry<float> BindMoreThanZero(this ConfigFile config, string section, string key, float defaultValue, string description)
		{
			ConfigEntry<float> val = config.Bind<float>(section, key, defaultValue, description);
			if (val.Value <= 0f)
			{
				val.Value = defaultValue;
			}
			return val;
		}

		public static ConfigEntry<float> BindNonNegative(this ConfigFile config, string section, string key, float defaultValue, string description)
		{
			ConfigEntry<float> val = config.Bind<float>(section, key, defaultValue, description);
			if (val.Value < 0f)
			{
				val.Value = defaultValue;
			}
			return val;
		}

		public static ConfigEntry<int> BindNonNegative(this ConfigFile config, string section, string key, int defaultValue, string description)
		{
			ConfigEntry<int> val = config.Bind<int>(section, key, defaultValue, description);
			if ((float)val.Value < 0f)
			{
				val.Value = defaultValue;
			}
			return val;
		}

		public static InventoryItem Clone(this InventoryItem i)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			InventoryItem obj = ScriptableObject.CreateInstance<InventoryItem>();
			obj.amount = i.amount;
			obj.armor = i.armor;
			obj.armorComponent = i.armorComponent;
			obj.attackDamage = i.attackDamage;
			obj.attackRange = i.attackRange;
			obj.attackSpeed = i.attackSpeed;
			obj.attackTypes = i.attackTypes;
			obj.bowComponent = i.bowComponent;
			obj.buildRotation = i.buildRotation;
			obj.buildable = i.buildable;
			obj.craftAmount = i.craftAmount;
			obj.craftable = i.craftable;
			obj.description = i.description;
			obj.fuel = i.fuel;
			obj.grid = i.grid;
			obj.heal = i.heal;
			((Object)obj).hideFlags = ((Object)i).hideFlags;
			obj.hunger = i.hunger;
			obj.id = i.id;
			obj.important = i.important;
			obj.material = i.material;
			obj.max = i.max;
			obj.mesh = i.mesh;
			obj.name = i.name;
			obj.positionOffset = i.positionOffset;
			obj.prefab = i.prefab;
			obj.processTime = i.processTime;
			obj.processType = i.processType;
			obj.processable = i.processable;
			obj.processedItem = i.processedItem;
			obj.rarity = i.rarity;
			obj.requirements = i.requirements;
			obj.resourceDamage = i.resourceDamage;
			obj.rotationOffset = i.rotationOffset;
			obj.scale = i.scale;
			obj.sharpness = i.sharpness;
			obj.sprite = i.sprite;
			obj.stackable = i.stackable;
			obj.stamina = i.stamina;
			obj.stationRequirement = i.stationRequirement;
			obj.swingFx = i.swingFx;
			obj.tag = i.tag;
			obj.tier = i.tier;
			obj.type = i.type;
			obj.unlockWithFirstRequirementOnly = i.unlockWithFirstRequirementOnly;
			return obj;
		}
	}
}
namespace MuckArrows
{
	public class CreateRecipesPatch
	{
		public static InventoryItem[] ArrowRecipes = (InventoryItem[])(object)new InventoryItem[0];

		[HarmonyPatch(typeof(ItemManager), "InitAllItems")]
		[HarmonyPostfix]
		private static void ItemManager_InitAllItems()
		{
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Expected O, but got Unknown
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Expected O, but got Unknown
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Expected O, but got Unknown
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Expected O, but got Unknown
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Expected O, but got Unknown
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Expected O, but got Unknown
			InventoryItem item = ItemManager.Instance.allItems[67];
			InventoryItem item2 = ItemManager.Instance.allItems[71];
			InventoryItem item3 = ItemManager.Instance.allItems[89];
			InventoryItem item4 = ItemManager.Instance.allItems[90];
			InventoryItem item5 = ItemManager.Instance.allItems[92];
			InventoryItem item6 = ItemManager.Instance.allItems[94];
			InventoryItem item7 = ItemManager.Instance.allItems[95];
			InventoryItem obj = ItemManager.Instance.allItems[131];
			InventoryItem val = ItemManager.Instance.allItems[133];
			InventoryItem obj2 = ItemManager.Instance.allItems[135];
			InventoryItem obj3 = ItemManager.Instance.allItems[136];
			val.attackDamage = Plugin.FlintArrowDamage;
			obj3.attackDamage = Plugin.SteelArrowDamage;
			obj2.attackDamage = Plugin.MithrilArrowDamage;
			obj.attackDamage = Plugin.AdamantiteArrowDamage;
			List<InventoryItem> list = new List<InventoryItem>();
			list.Add(NewArrow(val, "Stone Arrow", "blunt arrows for a long distance slapp", Plugin.StoneArrowDamage, 4, val.sprite, val.sprite.texture, Plugin.CanCraftStoneArrows, new CraftRequirement
			{
				amount = 2,
				item = item6
			}, new CraftRequirement
			{
				amount = 1,
				item = item4
			}));
			list.Add(NewArrow(val, "Obamium Arrow", "the 44th arrow ever invented", Plugin.ObamiumArrowDamage, 4, Resources.ObamiumArrowSprite, Resources.ObamiumArrowTexture, Plugin.CanCraftObamiumArrows, new CraftRequirement
			{
				amount = 2,
				item = item5
			}, new CraftRequirement
			{
				amount = 1,
				item = item2
			}));
			list.Add(NewArrow(val, "Ruby Arrow", "shooting your arrows with style", Plugin.RubyArrowDamage, 4, Resources.RubyArrowSprite, Resources.RubyArrowTexture, Plugin.CanCraftRubyArrows, new CraftRequirement
			{
				amount = 2,
				item = item5
			}, new CraftRequirement
			{
				amount = 1,
				item = item3
			}));
			list.Add(NewArrow(val, "Chunkium Arrow", "how do these even fly?", Plugin.ChunkiumArrowDamage, 4, Resources.ChunkiumArrowSprite, Resources.ChunkiumArrowTexture, Plugin.CanCraftChunkiumArrows, new CraftRequirement
			{
				amount = 2,
				item = item7
			}, new CraftRequirement
			{
				amount = 1,
				item = item
			}));
			List<InventoryItem> list2 = list;
			int num = ItemManager.Instance.allItems.Keys.DefaultIfEmpty(0).Max() + 1;
			foreach (InventoryItem item8 in list2)
			{
				item8.id = num++;
				ItemManager.Instance.allItems.Add(item8.id, item8);
				Plugin.Log.LogItemCreated(item8);
			}
			ItemManager.Instance.allScriptableItems = ItemManager.Instance.allScriptableItems.Concat(list2).ToArray();
			ArrowRecipes = list2.ToArray();
		}

		private static InventoryItem NewArrow(InventoryItem baseArrow, string name, string description, int attackDamage, int amount, Sprite sprite, Texture2D texture, bool craftable, params CraftRequirement[] requirements)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: 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)
			InventoryItem obj = ScriptableObject.CreateInstance<InventoryItem>();
			obj.amount = amount;
			obj.armor = baseArrow.armor;
			obj.armorComponent = baseArrow.armorComponent;
			obj.attackDamage = attackDamage;
			obj.attackRange = baseArrow.attackRange;
			obj.attackSpeed = baseArrow.attackSpeed;
			obj.attackTypes = baseArrow.attackTypes;
			obj.bowComponent = baseArrow.bowComponent;
			obj.buildRotation = baseArrow.buildRotation;
			obj.buildable = baseArrow.buildable;
			obj.craftAmount = baseArrow.craftAmount;
			obj.craftable = baseArrow.craftable;
			obj.description = description;
			obj.fuel = baseArrow.fuel;
			obj.grid = baseArrow.grid;
			obj.heal = baseArrow.heal;
			((Object)obj).hideFlags = ((Object)baseArrow).hideFlags;
			obj.hunger = baseArrow.hunger;
			obj.id = baseArrow.id;
			obj.important = baseArrow.important;
			obj.material = baseArrow.material;
			obj.max = baseArrow.max;
			obj.mesh = baseArrow.mesh;
			obj.name = name;
			obj.positionOffset = baseArrow.positionOffset;
			obj.prefab = baseArrow.prefab;
			obj.processTime = baseArrow.processTime;
			obj.processType = baseArrow.processType;
			obj.processable = baseArrow.processable;
			obj.processedItem = baseArrow.processedItem;
			obj.rarity = baseArrow.rarity;
			obj.requirements = (CraftRequirement[])(craftable ? ((Array)requirements) : ((Array)Array.Empty<CraftRequirement>()));
			obj.resourceDamage = baseArrow.resourceDamage;
			obj.rotationOffset = baseArrow.rotationOffset;
			obj.scale = baseArrow.scale;
			obj.sharpness = baseArrow.sharpness;
			obj.material = new Material(baseArrow.material)
			{
				mainTexture = (Texture)(object)texture,
				color = new Color(1f, 1f, 1f, 1f)
			};
			obj.sprite = sprite;
			obj.stackable = baseArrow.stackable;
			obj.stamina = baseArrow.stamina;
			obj.stationRequirement = baseArrow.stationRequirement;
			obj.swingFx = baseArrow.swingFx;
			obj.tag = baseArrow.tag;
			obj.tier = baseArrow.tier;
			obj.type = baseArrow.type;
			obj.unlockWithFirstRequirementOnly = baseArrow.unlockWithFirstRequirementOnly;
			return obj;
		}

		[HarmonyPatch(typeof(CraftingUI), "Awake")]
		[HarmonyPostfix]
		private static void CraftingUI_Awake(CraftingUI __instance)
		{
			if (((Object)__instance).name == "FletchingNew")
			{
				InventoryItem[] items = __instance.tabs[1].items;
				InventoryItem[] array = (InventoryItem[])(object)new InventoryItem[items.Length + ArrowRecipes.Length];
				items.CopyTo(array, 0);
				ArrowRecipes.CopyTo(array, items.Length);
				Array.Sort(array, (InventoryItem x, InventoryItem y) => x.attackDamage - y.attackDamage);
				__instance.tabs[1].items = array;
			}
		}
	}
	[BepInPlugin("MuckArrows.MichMcb", "Muck Arrows", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Log = null;

		public static bool CanCraftStoneArrows = true;

		public static bool CanCraftObamiumArrows = true;

		public static bool CanCraftRubyArrows = true;

		public static bool CanCraftChunkiumArrows = true;

		public static int FlintArrowDamage = 20;

		public static int SteelArrowDamage = 30;

		public static int MithrilArrowDamage = 40;

		public static int AdamantiteArrowDamage = 50;

		public static int FireArrowDamage = 100;

		public static int LightningArrowDamage = 100;

		public static int WaterArrowDamage = 100;

		public static int StoneArrowDamage = 5;

		public static int ChunkiumArrowDamage = 55;

		public static int ObamiumArrowDamage = 60;

		public static int RubyArrowDamage = 75;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
			CanCraftStoneArrows = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "CanCraftStoneArrows", CanCraftStoneArrows, "If true, allows crafting (practically useless) stone arrows. Stone arrows can still exist in the game even if this setting is false, so toggling it will not cause any issues with saved games.").Value;
			CanCraftObamiumArrows = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "CanCraftObamiumArrows", CanCraftStoneArrows, "If true, allows crafting Obamium Arrows. As above, they always exist.").Value;
			CanCraftRubyArrows = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "CanCraftRubyArrows", CanCraftStoneArrows, "If true, allows crafting Ruby Arrows. As above, they always exist.").Value;
			CanCraftChunkiumArrows = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "CanCraftChunkiumArrows", CanCraftStoneArrows, "If true, allows crafting Chunkium Arrows. As above, they always exist.").Value;
			FlintArrowDamage = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Damage", "FlintArrowDamage", FlintArrowDamage, "The damage that Flint arrows deal. Vanilla: 20").Value;
			SteelArrowDamage = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Damage", "SteelArrowDamage", SteelArrowDamage, "The damage that Steel arrows deal. Vanilla: 30").Value;
			MithrilArrowDamage = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Damage", "MithrilArrowDamage", MithrilArrowDamage, "The damage that Mithril arrows deal. Vanilla: 40").Value;
			AdamantiteArrowDamage = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Damage", "AdamantiteArrowDamage", AdamantiteArrowDamage, "The damage that Adamantite arrows deal. Vanilla: 50").Value;
			FireArrowDamage = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Damage", "FireArrowDamage", FireArrowDamage, "The damage that Fire arrows deal. Vanilla: 100").Value;
			LightningArrowDamage = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Damage", "LightningArrowDamage", LightningArrowDamage, "The damage that Lightning arrows deal. Vanilla: 100").Value;
			WaterArrowDamage = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Damage", "WaterArrowDamage", WaterArrowDamage, "The damage that Water arrows deal. Vanilla: 100").Value;
			StoneArrowDamage = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Damage", "StoneArrowDamage", StoneArrowDamage, "The damage that Stone arrows deal. Vanilla: 5").Value;
			ChunkiumArrowDamage = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Damage", "ChunkiumArrowDamage", ChunkiumArrowDamage, "The damage that Chunkium arrows deal. Vanilla: 55").Value;
			ObamiumArrowDamage = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Damage", "ObamiumArrowDamage", ObamiumArrowDamage, "The damage that Obamium arrows deal. Vanilla: 60").Value;
			RubyArrowDamage = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Damage", "RubyArrowDamage", RubyArrowDamage, "The damage that Ruby arrows deal. Vanilla: 75").Value;
			((BaseUnityPlugin)this).Config.Save();
			Resources.Load();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"MuckArrows loaded!");
			Harmony.CreateAndPatchAll(typeof(CreateRecipesPatch), (string)null);
		}
	}
	public static class Resources
	{
		public static Texture2D ChunkiumArrowTexture;

		public static Sprite ChunkiumArrowSprite;

		public static Texture2D ObamiumArrowTexture;

		public static Sprite ObamiumArrowSprite;

		public static Texture2D RubyArrowTexture;

		public static Sprite RubyArrowSprite;

		public static void Load()
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MuckArrows.resources");
			AssetBundle obj = AssetBundle.LoadFromStream(stream);
			ChunkiumArrowTexture = obj.LoadAsset<Texture2D>("ChunkiumArrow.png");
			ChunkiumArrowSprite = obj.LoadAsset<Sprite>("ChunkiumArrow.png");
			ObamiumArrowTexture = obj.LoadAsset<Texture2D>("ObamiumArrow.png");
			ObamiumArrowSprite = obj.LoadAsset<Sprite>("ObamiumArrow.png");
			RubyArrowTexture = obj.LoadAsset<Texture2D>("RubyArrow.png");
			RubyArrowSprite = obj.LoadAsset<Sprite>("RubyArrow.png");
		}
	}
}