Decompiled source of AzuWorkbench Inventory Repair v1.0.1

AzuWorkbenchInventoryRepair.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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("AzuWorkbenchInventoryRepair")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Azumatt")]
[assembly: AssemblyProduct("AzuWorkbenchInventoryRepair")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("E4703CF7-8132-4C44-89E0-A885D44D9FD7")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
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.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace AzuWorkbenchInventoryRepair
{
	[HarmonyPatch(typeof(InventoryGui), "RepairOneItem")]
	public static class InventoryGuiRepairOneItemTranspiler
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			if (AzuWorkbenchInventoryRepairPlugin.AutoRepair.Value == AzuWorkbenchInventoryRepairPlugin.Toggle.On)
			{
				list.RemoveRange(52, 11);
			}
			return list.AsEnumerable();
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateRepair")]
	public static class InventoryGuiUpdateRepairPatch
	{
		[HarmonyPrefix]
		public static void Prefix(InventoryGui __instance)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (AzuWorkbenchInventoryRepairPlugin.AutoRepair.Value == AzuWorkbenchInventoryRepairPlugin.Toggle.Off)
			{
				return;
			}
			CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation();
			if (!((Object)(object)currentCraftingStation == (Object)null))
			{
				int num = 0;
				while (__instance.HaveRepairableItems())
				{
					__instance.RepairOneItem();
					num++;
				}
				if (num > 0)
				{
					currentCraftingStation.m_repairItemDoneEffects.Create(((Component)currentCraftingStation).transform.position, Quaternion.identity, (Transform)null, 1f, -1);
				}
			}
		}
	}
	[BepInPlugin("Azumatt.AzuWorkbenchInventoryRepair", "AzuWorkbenchInventoryRepair", "1.0.1")]
	public class AzuWorkbenchInventoryRepairPlugin : BaseUnityPlugin
	{
		public enum Toggle
		{
			Off,
			On
		}

		internal const string ModName = "AzuWorkbenchInventoryRepair";

		internal const string ModVersion = "1.0.1";

		internal const string Author = "Azumatt";

		private const string ModGUID = "Azumatt.AzuWorkbenchInventoryRepair";

		private static string ConfigFileName = "Azumatt.AzuWorkbenchInventoryRepair.cfg";

		private static string ConfigFileFullPath;

		internal static string ConnectionError;

		private readonly Harmony _harmony = new Harmony("Azumatt.AzuWorkbenchInventoryRepair");

		public static readonly ManualLogSource AzuWorkbenchInventoryRepairLogger;

		internal static ConfigEntry<Toggle> AutoRepair;

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			AutoRepair = config("1 - General", "Auto repair", Toggle.On, new ConfigDescription("Auto repair your things when interacting with a build station", (AcceptableValueBase)null, Array.Empty<object>()));
			_harmony.PatchAll();
			SetupWatcher();
		}

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

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

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

		private ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description)
		{
			return ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, description);
		}

		private ConfigEntry<T> config<T>(string group, string name, T value, string description)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()));
		}

		static AzuWorkbenchInventoryRepairPlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			ConnectionError = "";
			AzuWorkbenchInventoryRepairLogger = Logger.CreateLogSource("AzuWorkbenchInventoryRepair");
			AutoRepair = null;
		}
	}
}