Decompiled source of ChebsAmplifiedStations v1.1.1

plugins/ChebsAmplifiedStations.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using ChebsAmplifiedStations.CraftingStations;
using HarmonyLib;
using Jotunn;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ChebsAmplifiedStations")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ChebsAmplifiedStations")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ChebsAmplifiedStations
{
	[BepInPlugin("com.chebgonaz.chebsamplifiedstations", "ChebsAmplifiedStations", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class ChebsAmplifiedStations : BaseUnityPlugin
	{
		public const string PluginGuid = "com.chebgonaz.chebsamplifiedstations";

		public const string PluginName = "ChebsAmplifiedStations";

		public const string PluginVersion = "1.1.1";

		public static ConfigEntry<bool> DaisyChainEnabled;

		private readonly Harmony _harmony = new Harmony("com.chebgonaz.chebsamplifiedstations");

		private ArtisanTable _artisanTable = new ArtisanTable();

		private BlackForge _blackForge = new BlackForge();

		private Cauldron _cauldron = new Cauldron();

		private Forge _forge = new Forge();

		private Workbench _workbench = new Workbench();

		private Stonecutter _stonecutter = new Stonecutter();

		private void Awake()
		{
			CreateConfigValues();
			_harmony.PatchAll();
			PrefabManager.OnVanillaPrefabsAvailable += DoOnVanillaPrefabsAvailable;
		}

		private void DoOnVanillaPrefabsAvailable()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= DoOnVanillaPrefabsAvailable;
			foreach (string item in new List<string> { _artisanTable.PrefabName, _blackForge.PrefabName, _cauldron.PrefabName, _forge.PrefabName, _workbench.PrefabName, _stonecutter.PrefabName })
			{
				CraftingStation.SetRange(item);
			}
		}

		private void CreateConfigValues()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			DaisyChainEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("DaisyChain", "DaisyChainEnabled", true, new ConfigDescription("Whether or not daisy-chaining is enabled (connect the effects of the workstations that are within range of each other).", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			_artisanTable.CreateConfigs((BaseUnityPlugin)(object)this);
			_blackForge.CreateConfigs((BaseUnityPlugin)(object)this);
			_cauldron.CreateConfigs((BaseUnityPlugin)(object)this);
			_forge.CreateConfigs((BaseUnityPlugin)(object)this);
			_workbench.CreateConfigs((BaseUnityPlugin)(object)this);
			_stonecutter.CreateConfigs((BaseUnityPlugin)(object)this);
		}
	}
}
namespace ChebsAmplifiedStations.Patches
{
	[HarmonyPatch(typeof(CraftingStation))]
	public class CraftingStationPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("HaveBuildStationInRange")]
		private static void HaveBuildStationInRangePostfix(string name, Vector3 point, CraftingStation __instance, ref CraftingStation __result)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (!ChebsAmplifiedStations.DaisyChainEnabled.Value)
			{
				return;
			}
			foreach (CraftingStation allStation in CraftingStation.m_allStations)
			{
				if (!(Vector3.Distance(((Component)allStation).transform.position, point) < allStation.GetStationBuildRange()))
				{
					continue;
				}
				List<CraftingStation> networkStations = new List<CraftingStation>();
				RecursiveAddNearbyStations(allStation, ref networkStations, CraftingStation.m_allStations);
				foreach (CraftingStation item in networkStations)
				{
					if (item.m_name == name)
					{
						__result = item;
						allStation.ShowAreaMarker();
					}
				}
			}
		}

		private static void RecursiveAddNearbyStations(CraftingStation from, ref List<CraftingStation> networkStations, List<CraftingStation> allStations)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if (networkStations.Contains(from))
			{
				return;
			}
			networkStations.Add(from);
			foreach (CraftingStation allStation in allStations)
			{
				if (Vector3.Distance(((Component)allStation).transform.position, ((Component)from).transform.position) < Mathf.Max(allStation.GetStationBuildRange(), from.GetStationBuildRange()))
				{
					RecursiveAddNearbyStations(allStation, ref networkStations, allStations);
				}
			}
		}
	}
}
namespace ChebsAmplifiedStations.CraftingStations
{
	public class ArtisanTable : CraftingStation
	{
		public override string PrefabName => "piece_artisanstation";
	}
	public class BlackForge : CraftingStation
	{
		public override string PrefabName => "blackforge";
	}
	public class Cauldron : CraftingStation
	{
		public override string PrefabName => "piece_cauldron";
	}
	public class CraftingStation
	{
		public static ConfigEntry<float> LevelRangeIncrease;

		public static ConfigEntry<float> BaseRange;

		public virtual string PrefabName => "";

		public virtual void CreateConfigs(BaseUnityPlugin plugin)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			string text = GetType().Name + " (Server Synced)";
			LevelRangeIncrease = plugin.Config.Bind<float>(text, "LevelRangeIncrease", 10f, new ConfigDescription("How much the range will increase per level of the crafting station.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			BaseRange = plugin.Config.Bind<float>(text, "BaseRange", 20f, new ConfigDescription("How much the range will increase per level of the crafting station.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
		}

		public static void SetRange(string prefabName)
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab(prefabName);
			if ((Object)(object)prefab == (Object)null)
			{
				Logger.LogError((object)("Failed to get " + prefabName + " prefab."));
				return;
			}
			CraftingStation val = default(CraftingStation);
			if (!prefab.TryGetComponent<CraftingStation>(ref val))
			{
				Logger.LogError((object)"Failed to get CraftingStation script.");
				return;
			}
			val.m_rangeBuild = BaseRange.Value;
			val.m_extraRangePerLevel = LevelRangeIncrease.Value;
		}
	}
	public class Forge : CraftingStation
	{
		public override string PrefabName => "forge";
	}
	public class Stonecutter : CraftingStation
	{
		public override string PrefabName => "piece_stonecutter";
	}
	public class Workbench : CraftingStation
	{
		public override string PrefabName => "piece_workbench";
	}
}