Decompiled source of DoorSpeedModifier v1.0.0

DoorSpeedModifier.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.IO;
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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DoorSpeedModifier")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("blacks7ar")]
[assembly: AssemblyProduct("DoorSpeedModifier")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("FD72F97F-FACE-4F90-A8B1-53D5C768F4F6")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DoorSpeedModifier
{
	[BepInPlugin("blacks7ar.DoorSpeedModifier", "DoorSpeedModifier", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private static class Logging
		{
			public static void LogDebug(string debug)
			{
				DSLogger.LogDebug((object)debug);
			}

			public static void LogInfo(string info)
			{
				DSLogger.LogInfo((object)info);
			}

			public static void LogWarning(string warning)
			{
				DSLogger.LogWarning((object)warning);
			}

			public static void LogError(string error)
			{
				DSLogger.LogError((object)error);
			}
		}

		[HarmonyPatch(typeof(Door), "Interact")]
		private class Patches
		{
			private static void Postfix(Door __instance)
			{
				if (!((Object)(object)__instance == (Object)null) && __instance.CanInteract() && __instance.m_nview.IsValid() && __instance.m_nview.IsOwner() && !((Object)(object)__instance.m_animator == (Object)null))
				{
					__instance.m_animator.speed = _speed.Value;
				}
			}
		}

		private const string modGUID = "blacks7ar.DoorSpeedModifier";

		public const string modName = "DoorSpeedModifier";

		public const string modAuthor = "blacks7ar";

		public const string modVersion = "1.0.0";

		public const string modLink = "";

		private static string configFileName = "blacks7ar.DoorSpeedModifier.cfg";

		private static string configFileFullPath;

		public static readonly ManualLogSource DSLogger;

		private static readonly Harmony _harmony;

		private static ConfigEntry<float> _speed;

		private void ConfigWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, configFileName);
			fileSystemWatcher.Changed += OnConfigChanged;
			fileSystemWatcher.Created += OnConfigChanged;
			fileSystemWatcher.Renamed += OnConfigChanged;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void OnConfigChanged(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(configFileFullPath))
			{
				return;
			}
			try
			{
				Logging.LogDebug("OnConfigChanged called..");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				Logging.LogError("There was an issue loading your " + configFileName);
				Logging.LogError("Please check your config entries for spelling and format!");
			}
		}

		public void Awake()
		{
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			_speed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Speed", 0.5f, "Door open close animation speed.");
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
			ConfigWatcher();
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		static Plugin()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			configFileFullPath = configPath + directorySeparatorChar + configFileName;
			DSLogger = Logger.CreateLogSource("DoorSpeedModifier");
			_harmony = new Harmony("blacks7ar.DoorSpeedModifier");
		}
	}
}