Decompiled source of Warfare Vanilla Arrows v1.0.0

WarfareVanillaArrows.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
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(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[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 WarfareVanillaArrows
{
	public enum StationMode
	{
		Vanilla,
		Workbench
	}
	[BepInPlugin("local.WarfareVanillaArrows", "Warfare Vanilla Arrows", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "local.WarfareVanillaArrows";

		public const string PluginName = "Warfare Vanilla Arrows";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<StationMode> Station;

		private void Awake()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Station = ((BaseUnityPlugin)this).Config.Bind<StationMode>("General", "Station", StationMode.Vanilla, "Where the vanilla bows, arrows and bolts that Warfare moves to its Fletcher Table are crafted instead.\nVanilla = their original vanilla station (e.g. Bronzehead arrows at the Forge).\nWorkbench = all of them at the Workbench (the required station level stays the same).\n[restart the game after changing]");
			Type type = AccessTools.TypeByName("Warfare.BowsPatch");
			MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "ChangeStation", new Type[1] { typeof(string) }, (Type[])null) : null);
			if (methodInfo == null)
			{
				Log.LogError((object)"Warfare.BowsPatch.ChangeStation not found - Warfare probably changed in an update. Nothing was patched.");
				return;
			}
			new Harmony("local.WarfareVanillaArrows").Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Plugin).GetMethod("ChangeStationPrefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Log.LogInfo((object)("Vanilla bows, arrows and bolts are no longer moved to Warfare's Fletcher Table (Station = " + Station.Value.ToString() + ")."));
		}

		private static bool ChangeStationPrefix(string name)
		{
			try
			{
				if (Station.Value == StationMode.Workbench)
				{
					MoveToWorkbench(name);
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Could not handle " + name + ": " + ex));
			}
			return false;
		}

		private static void MoveToWorkbench(string name)
		{
			if ((Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return;
			}
			GameObject prefab = ZNetScene.instance.GetPrefab(name);
			ItemDrop val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null);
			if (!((Object)(object)val == (Object)null))
			{
				Recipe recipe = ObjectDB.instance.GetRecipe(val.m_itemData);
				GameObject prefab2 = ZNetScene.instance.GetPrefab("piece_workbench");
				CraftingStation val2 = (((Object)(object)prefab2 != (Object)null) ? prefab2.GetComponent<CraftingStation>() : null);
				if ((Object)(object)recipe != (Object)null && (Object)(object)val2 != (Object)null)
				{
					recipe.m_craftingStation = val2;
				}
			}
		}
	}
}