Decompiled source of BarberVisibilityTweaks v1.1.1

BarberVisibilityTweaks.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
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 CSync.Extensions;
using CSync.Lib;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using qwcanBarber.patch;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("qwcan")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3-alpha.0.12+9218f93048915b54c74739ef5d7ac1436cce2493")]
[assembly: AssemblyProduct("BarberPatch")]
[assembly: AssemblyTitle("BarberVisibilityTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace qwcanBarber
{
	public class BarberConfig : SyncedConfig2<BarberConfig>
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static CanModifyDelegate <0>__IsHostCallback;
		}

		[SyncedEntryField]
		public SyncedEntry<float> minFadingDistance;

		[SyncedEntryField]
		public SyncedEntry<float> maxFadingDistance;

		public ConfigEntry<float> localMinFadingDistance;

		public ConfigEntry<float> localMaxFadingDistance;

		private static CanModifyResult IsHostCallback()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			if (!Object.op_Implicit((Object)(object)instance) || ((NetworkBehaviour)instance).IsHost)
			{
				return CanModifyResult.True();
			}
			return CanModifyResult.op_Implicit((false, "This setting can only be modified by the host."));
		}

		public BarberConfig(ConfigFile configFile)
			: base("BarberVisibilityTweaks")
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			minFadingDistance = SyncedBindingExtensions.BindSyncedEntry<float>(configFile, "Fading", "Minimum Fading Distance", 5f, "Distance at which the barber will be fully opaque");
			maxFadingDistance = SyncedBindingExtensions.BindSyncedEntry<float>(configFile, "Fading", "Maximum Fading Distance", 7f, "Distance at which the barber will start fading in");
			ConfigEntry<float> entry = minFadingDistance.Entry;
			FloatStepSliderOptions val = new FloatStepSliderOptions();
			((BaseRangeOptions<float>)(object)val).Min = 0f;
			((BaseRangeOptions<float>)(object)val).Max = 100f;
			val.Step = 0.5f;
			((BaseOptions)val).RequiresRestart = false;
			FloatStepSliderOptions obj = val;
			object obj2 = <>O.<0>__IsHostCallback;
			if (obj2 == null)
			{
				CanModifyDelegate val2 = IsHostCallback;
				<>O.<0>__IsHostCallback = val2;
				obj2 = (object)val2;
			}
			((BaseOptions)obj).CanModifyCallback = (CanModifyDelegate)obj2;
			FloatStepSliderConfigItem val3 = new FloatStepSliderConfigItem(entry, val);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val3);
			ConfigEntry<float> entry2 = maxFadingDistance.Entry;
			val = new FloatStepSliderOptions();
			((BaseRangeOptions<float>)(object)val).Min = 0f;
			((BaseRangeOptions<float>)(object)val).Max = 100f;
			val.Step = 0.5f;
			((BaseOptions)val).RequiresRestart = false;
			FloatStepSliderOptions obj3 = val;
			object obj4 = <>O.<0>__IsHostCallback;
			if (obj4 == null)
			{
				CanModifyDelegate val4 = IsHostCallback;
				<>O.<0>__IsHostCallback = val4;
				obj4 = (object)val4;
			}
			((BaseOptions)obj3).CanModifyCallback = (CanModifyDelegate)obj4;
			FloatStepSliderConfigItem val5 = new FloatStepSliderConfigItem(entry2, val);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val5);
			minFadingDistance.Changed += delegate(object sender, SyncedSettingChangedEventArgs<float> args)
			{
				Plugin.Log.LogInfo((object)$"minFadingDistance changed from {args.OldValue} to {args.NewValue}");
			};
			maxFadingDistance.Changed += delegate(object sender, SyncedSettingChangedEventArgs<float> args)
			{
				Plugin.Log.LogInfo((object)$"maxFadingDistance changed from {args.OldValue} to {args.NewValue}");
			};
			ConfigManager.Register<BarberConfig>((SyncedConfig2<BarberConfig>)this);
		}
	}
	[BepInPlugin("BarberVisibilityTweaks", "BarberVisibilityTweaks", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency("com.sigurd.csync", "5.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("BarberVisibilityTweaks");

		internal static BarberConfig Config;

		public static Plugin Instance { get; set; }

		public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger;

		public Plugin()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			Instance = this;
		}

		private void Awake()
		{
			Config = new BarberConfig(((BaseUnityPlugin)this).Config);
			Log.LogInfo((object)"Applying patches...");
			ApplyPluginPatch();
			Log.LogInfo((object)"Patches applied");
		}

		private void ApplyPluginPatch()
		{
			_harmony.PatchAll(typeof(BarberPatch));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BarberVisibilityTweaks";

		public const string PLUGIN_NAME = "BarberPatch";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace qwcanBarber.patch
{
	[HarmonyPatch(typeof(ClaySurgeonAI))]
	public class BarberPatch
	{
		[HarmonyPatch(typeof(NetworkManager))]
		internal static class NetworkPrefabPatch2
		{
			private static readonly string MOD_GUID = "BarberVisibilityTweaks";

			[HarmonyPostfix]
			[HarmonyPatch("SetSingleton")]
			private static void RegisterPrefab()
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Expected O, but got Unknown
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = new GameObject(MOD_GUID + " Prefab");
				((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
				Object.DontDestroyOnLoad((Object)(object)val);
				NetworkObject obj = val.AddComponent<NetworkObject>();
				FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
				field.SetValue(obj, GetHash(MOD_GUID));
				NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
				static uint GetHash(string value)
				{
					return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
				}
			}
		}

		[HarmonyPatch(typeof(ClaySurgeonAI), "SetVisibility")]
		[HarmonyPrefix]
		private static void SetVisibility(ref ClaySurgeonAI __instance)
		{
			__instance.minDistance = Plugin.Config.minFadingDistance.Value;
			__instance.maxDistance = Plugin.Config.maxFadingDistance.Value;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}