Decompiled source of BuildRadiusCustomizer v1.2.0

Build Radius Customizer.dll

Decompiled 20 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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("Build_Radius_Customizer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Build_Radius_Customizer")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("677cd222-4e2c-430c-9157-c1c39ec1c4de")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BuildRadiusCustomizer
{
	[BepInPlugin("Viking.buildradiuscustomizer", "BuildRadiusCustomizer", "1.2.0")]
	public class BuildRadiusCustomizerPlugin : BaseUnityPlugin
	{
		private const string PluginGUID = "Viking.buildradiuscustomizer";

		private const string PluginName = "BuildRadiusCustomizer";

		private const string PluginVersion = "1.2.0";

		private readonly Harmony harmony = new Harmony("Viking.buildradiuscustomizer");

		public static ConfigEntry<bool> IsConfigLocked;

		public static ConfigEntry<bool> ModEnabled;

		private static ConfigEntry<float> _workbenchRadius;

		private static ConfigEntry<float> _stonecutterRadius;

		private static ConfigEntry<float> _forgeRadius;

		private static ConfigEntry<float> _blackForgeRadius;

		private static ConfigEntry<float> _galdrTableRadius;

		public static float WorkbenchRadius => ModEnabled.Value ? _workbenchRadius.Value : 20f;

		public static float StonecutterRadius => ModEnabled.Value ? _stonecutterRadius.Value : 20f;

		public static float ForgeRadius => ModEnabled.Value ? _forgeRadius.Value : 20f;

		public static float BlackForgeRadius => ModEnabled.Value ? _blackForgeRadius.Value : 20f;

		public static float GaldrTableRadius => ModEnabled.Value ? _galdrTableRadius.Value : 20f;

		private void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			IsConfigLocked = ((BaseUnityPlugin)this).Config.Bind<bool>("0 - General", "Lock Configuration", true, new ConfigDescription("If true, configuration settings will be locked to server-side values via ConditionalConfigSync for non-admin players.", (AcceptableValueBase)null, new object[1]
			{
				new
				{
					order = 210
				}
			}));
			ModEnabled = BindConfig("0 - General", "Mod Enabled", value: true, "If false, all custom build radius adjustments are ignored and game default values are used. [Synced with Server]", 200);
			_workbenchRadius = BindConfig("1 - Radius Settings", "Workbench Radius", 20f, "Maximum building radius for the Workbench. (Vanilla default: 20) [Synced with Server]", 100);
			_stonecutterRadius = BindConfig("1 - Radius Settings", "Stonecutter Radius", 20f, "Maximum building radius for the Stonecutter. (Vanilla default: 20) [Synced with Server]", 99);
			_forgeRadius = BindConfig("1 - Radius Settings", "Forge Radius", 20f, "Maximum building radius for the Forge. (Vanilla default: 20) [Synced with Server]", 98);
			_blackForgeRadius = BindConfig("1 - Radius Settings", "Black Forge Radius", 20f, "Maximum building radius for the Black Forge. (Vanilla default: 20) [Synced with Server]", 97);
			_galdrTableRadius = BindConfig("1 - Radius Settings", "Galdr Table Radius", 20f, "Maximum building radius for the Galdr Table. (Vanilla default: 20) [Synced with Server]", 96);
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"BuildRadiusCustomizer version 1.2.0 loaded successfully.");
		}

		private ConfigEntry<T> BindConfig<T>(string group, string name, T value, string description, int order)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			ConfigEntry<T> val = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
			{
				new { order }
			}));
			val.SettingChanged += OnSettingChanged;
			return val;
		}

		private void OnSettingChanged(object sender, EventArgs e)
		{
			UpdateActiveStationRanges();
		}

		public static void UpdateActiveStationRanges()
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			CraftingStation[] array = Object.FindObjectsByType<CraftingStation>((FindObjectsSortMode)0);
			CraftingStation[] array2 = array;
			foreach (CraftingStation val in array2)
			{
				ZNetView component = ((Component)val).GetComponent<ZNetView>();
				if (Object.op_Implicit((Object)(object)component) && component.IsValid())
				{
					float targetRadius = GetTargetRadius(val.m_name);
					if (targetRadius > 0f)
					{
						val.m_rangeBuild = targetRadius;
					}
				}
			}
		}

		public static float GetTargetRadius(string stationName)
		{
			return stationName switch
			{
				"$piece_workbench" => WorkbenchRadius, 
				"$piece_stonecutter" => StonecutterRadius, 
				"$piece_forge" => ForgeRadius, 
				"$piece_blackforge" => BlackForgeRadius, 
				"$piece_magictable" => GaldrTableRadius, 
				_ => -1f, 
			};
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
		}
	}
	[HarmonyPatch(typeof(CraftingStation), "Awake")]
	public static class CraftingStation_Awake_Patch
	{
		public static void Postfix(CraftingStation __instance)
		{
			float targetRadius = BuildRadiusCustomizerPlugin.GetTargetRadius(__instance.m_name);
			if (targetRadius > 0f)
			{
				__instance.m_rangeBuild = targetRadius;
			}
		}
	}
}
namespace Build_Radius_Customizer.MonoBehaviours
{
	internal class Build_Radius_CustomizerComponent : MonoBehaviour
	{
		public void Awake()
		{
		}

		public void Start()
		{
		}

		public void Update()
		{
		}

		public void LateUpdate()
		{
		}
	}
}