Decompiled source of CraftingStationTweakz v0.0.1

plugins/CraftingStationTweakz.dll

Decompiled a week 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.Permissions;
using BepInEx;
using BepInEx.Configuration;
using CraftingStationTweakz.Configs;
using Jotunn;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CraftingStationTweakz")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CraftingStationTweakz")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace CraftingStationTweakz
{
	[BepInPlugin("DeathWizsh.CraftingStationTweakz", "CraftingStationTweakz", "0.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class CraftingStationTweakz : BaseUnityPlugin
	{
		public const string PluginGUID = "DeathWizsh.CraftingStationTweakz";

		public const string PluginName = "CraftingStationTweakz";

		public const string PluginVersion = "0.0.1";

		public static CraftingStationTweakz Instance;

		private void Awake()
		{
			Instance = this;
			PluginConfig.Init();
			PrefabManager.OnPrefabsRegistered += PatchPieces;
		}

		private void PatchPieces()
		{
			UpdateExtensionPieces();
			UpdateCraftingStation();
			PrefabManager.OnPrefabsRegistered -= PatchPieces;
		}

		public void UpdateExtensionPieces()
		{
			List<GameObject> list = ZNetScene.instance.m_prefabs.FindAll((GameObject item) => ((Object)item).name.Contains("_ext"));
			foreach (GameObject item in list)
			{
				StationExtension component = item.GetComponent<StationExtension>();
				Piece component2 = item.GetComponent<Piece>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component2 == (Object)null))
				{
					component.m_maxStationDistance = PluginConfig.extensionRange.Value;
					component2.m_spaceRequirement = PluginConfig.extensionSpaceRange.Value;
				}
			}
		}

		public void UpdateCraftingStation()
		{
			List<GameObject> list = ZNetScene.instance.m_prefabs.FindAll((GameObject item) => Object.op_Implicit((Object)(object)item.GetComponent<CraftingStation>()));
			foreach (GameObject item in list)
			{
				CraftingStation component = item.GetComponent<CraftingStation>();
				Piece component2 = item.GetComponent<Piece>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component2 == (Object)null))
				{
					component.m_rangeBuild = PluginConfig.stationBuildRange.Value;
					component.m_extraRangePerLevel = PluginConfig.stationBuildRangePerUpgrade.Value;
				}
			}
		}
	}
}
namespace CraftingStationTweakz.Configs
{
	internal static class PluginConfig
	{
		public static string sectionGeneral = "General";

		public static ConfigEntry<float> stationBuildRange;

		public static ConfigEntry<float> stationBuildRangePerUpgrade;

		public static ConfigEntry<float> stationPlayerBaseRange;

		public static ConfigEntry<float> extensionRange;

		public static ConfigEntry<float> extensionSpaceRange;

		private static int entryCount = 1000;

		public static void Init()
		{
			InitGeneralConfig();
		}

		public static void InitGeneralConfig()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0064: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00eb: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_00f5: Expected O, but got Unknown
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Expected O, but got Unknown
			//IL_0186: Expected O, but got Unknown
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Expected O, but got Unknown
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Expected O, but got Unknown
			//IL_0217: Expected O, but got Unknown
			try
			{
				stationBuildRange = ((BaseUnityPlugin)CraftingStationTweakz.Instance).Config.Bind<float>(new ConfigDefinition(sectionGeneral, "Build range"), 20f, new ConfigDescription("The base build range of the crafting station. (only updates on restart for already existing crafting stations)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 50f), new object[1] { (object)new ConfigurationManagerAttributes
				{
					IsAdminOnly = false,
					Order = HandleOrder()
				} }));
				stationBuildRange.SettingChanged += delegate
				{
					CraftingStationTweakz.Instance.UpdateCraftingStation();
				};
				stationBuildRangePerUpgrade = ((BaseUnityPlugin)CraftingStationTweakz.Instance).Config.Bind<float>(new ConfigDefinition(sectionGeneral, "Build range increase per upgrade"), 4f, new ConfigDescription("Each upgrade increases the crafting station's build range. (only updates on restart for already existing crafting stations)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(4f, 50f), new object[1] { (object)new ConfigurationManagerAttributes
				{
					IsAdminOnly = false,
					Order = HandleOrder()
				} }));
				stationBuildRangePerUpgrade.SettingChanged += delegate
				{
					CraftingStationTweakz.Instance.UpdateCraftingStation();
				};
				extensionRange = ((BaseUnityPlugin)CraftingStationTweakz.Instance).Config.Bind<float>(new ConfigDefinition(sectionGeneral, "Upgrade range"), 10f, new ConfigDescription("The maximum distance at which upgrades still connect to the crafting station. (only updates on restart for already existing crafting stations)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 50f), new object[1] { (object)new ConfigurationManagerAttributes
				{
					IsAdminOnly = false,
					Order = HandleOrder()
				} }));
				extensionRange.SettingChanged += delegate
				{
					CraftingStationTweakz.Instance.UpdateExtensionPieces();
				};
				extensionSpaceRange = ((BaseUnityPlugin)CraftingStationTweakz.Instance).Config.Bind<float>(new ConfigDefinition(sectionGeneral, "Space requirement between upgrades"), 0f, new ConfigDescription("The minimum required spacing between upgrades in order to place them (game default is 2). (only updates on restart for already existing crafting stations)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), new object[1] { (object)new ConfigurationManagerAttributes
				{
					IsAdminOnly = false,
					Order = HandleOrder()
				} }));
				extensionSpaceRange.SettingChanged += delegate
				{
					CraftingStationTweakz.Instance.UpdateExtensionPieces();
				};
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Could not initialise general config: " + ex));
			}
		}

		private static int HandleOrder()
		{
			entryCount--;
			return (entryCount >= 0) ? entryCount : 0;
		}
	}
}