Decompiled source of BetterFabber v1.0.2

BetterFabber.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
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 CG.Game;
using CG.Objects;
using CG.Ship.Hull;
using CG.Space;
using Gameplay.Carryables;
using Gameplay.Factory;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UI.Fabricator;
using UnityEngine;
using VoidManager;
using VoidManager.CustomGUI;
using VoidManager.MPModChecks;
using VoidManager.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BetterFabber")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Auto-recycles alloy, increases fabricator recycle and print speed. Host side")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+424c8d9205e4905f629e6056c81eec296a6863b9")]
[assembly: AssemblyProduct("BetterFabber")]
[assembly: AssemblyTitle("Auto-recycles alloy, increases fabricator recycle and print speed. Host side")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 BetterFabber
{
	[HarmonyPatch(typeof(FabricatorData))]
	internal class AutoRecyclePatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static void Constructor(FabricatorData __instance, CarryableFactoryLogic logic)
		{
			logic.PrintSocket.OnAcquireCarryable += delegate(ICarrier printSocket, AbstractCarryableObject carryableObject, ICarrier previousCarrier)
			{
				OnInsert(__instance, printSocket, carryableObject, previousCarrier);
			};
		}

		private static void OnInsert(FabricatorData instance, ICarrier printSocket, AbstractCarryableObject carryableObject, ICarrier previousCarrier)
		{
			if (PhotonNetwork.IsMasterClient && ((BepinPlugin.Bindings.AutoRecycleAlloy.Value && ((Object)carryableObject).name.Contains("Item_Alloy")) || (BepinPlugin.Bindings.AutoRecycleEverything.Value && previousCarrier != printSocket && !((Object)carryableObject).name.Contains("Item_BlankBuildBox"))))
			{
				instance.RecycleNow(instance.SocketItem);
			}
		}
	}
	[HarmonyPatch(typeof(CarryablesSocket))]
	internal class CarryablesSocketPatch
	{
		private static readonly FieldInfo carrierField = AccessTools.Field(typeof(AbstractCarryableObject), "carrier");

		[HarmonyPrefix]
		[HarmonyPatch("TryInsertCarryable")]
		private static void TryInsertCarryable(CarryablesSocket __instance, AbstractCarryableObject carryable)
		{
			ClientGame current = ClientGame.Current;
			object obj;
			if (current == null)
			{
				obj = null;
			}
			else
			{
				AbstractPlayerControlledShip playerShip = current.PlayerShip;
				if (playerShip == null)
				{
					obj = null;
				}
				else
				{
					GameObject gameObject = ((Component)playerShip).gameObject;
					if (gameObject == null)
					{
						obj = null;
					}
					else
					{
						CarryableFactoryLogic componentInChildren = gameObject.GetComponentInChildren<CarryableFactoryLogic>();
						obj = ((componentInChildren != null) ? componentInChildren.PrintSocket : null);
					}
				}
			}
			if (!((Object)(object)__instance != (Object)obj) && carryable.Carrier == null)
			{
				carrierField.SetValue(carryable, __instance);
			}
		}
	}
	[BepInPlugin("Dragon.BetterFabber", "Better Fabber", "1.0.2")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal class Bindings
		{
			internal static ConfigEntry<float> FabRecycleSpeedMultiplier;

			internal static ConfigEntry<float> FabPrintSpeedMultiplier;

			internal static ConfigEntry<bool> AutoRecycleAlloy;

			internal static ConfigEntry<bool> AutoRecycleEverything;
		}

		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Bindings.FabRecycleSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FabRecycleSpeedMultiplier", 10f, (ConfigDescription)null);
			Bindings.FabPrintSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FabPrintSpeedMultiplier", 10f, (ConfigDescription)null);
			Bindings.AutoRecycleAlloy = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AutoRecycleAlloy", true, (ConfigDescription)null);
			Bindings.AutoRecycleEverything = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AutoRecycleEverything", false, (ConfigDescription)null);
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Dragon.BetterFabber");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Dragon.BetterFabber is loaded!");
		}
	}
	internal class BFGUI : ModSettingsMenu
	{
		private string FabRecycleSpeed;

		private string FabPrintSpeed;

		private string errorMessage;

		public override void Draw()
		{
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.Label("Better Fabber menu", Array.Empty<GUILayoutOption>());
			GUILayout.Label("Fabricator Recycle Speed", Array.Empty<GUILayoutOption>());
			FabRecycleSpeed = GUILayout.TextField(FabRecycleSpeed, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Fabricator Print Speed", Array.Empty<GUILayoutOption>());
			FabPrintSpeed = GUILayout.TextField(FabPrintSpeed, Array.Empty<GUILayoutOption>());
			GUITools.DrawCheckbox("Auto Recycle Alloy", ref BepinPlugin.Bindings.AutoRecycleAlloy);
			GUITools.DrawCheckbox("Auto Recycle Everything (except blank crates)", ref BepinPlugin.Bindings.AutoRecycleEverything);
			if (float.TryParse(FabRecycleSpeed, out var result))
			{
				if (result < 0.25f)
				{
					errorMessage = "Recycle Speed cannot go below 0.25x";
				}
				else if (BepinPlugin.Bindings.FabRecycleSpeedMultiplier.Value != result)
				{
					BepinPlugin.Log.LogInfo((object)("Updating Fab Recycle Speed to " + result));
					BepinPlugin.Bindings.FabRecycleSpeedMultiplier.Value = result;
				}
			}
			if (float.TryParse(FabPrintSpeed, out result))
			{
				if (result < 0.25f)
				{
					errorMessage = "Print Speed cannot go below 0.25x";
				}
				else if (BepinPlugin.Bindings.FabPrintSpeedMultiplier.Value != result)
				{
					BepinPlugin.Log.LogInfo((object)("Updating Fab Print Speed to " + result));
					BepinPlugin.Bindings.FabPrintSpeedMultiplier.Value = result;
				}
			}
			if (errorMessage != null)
			{
				GUI.color = Color.red;
				GUILayout.Label(errorMessage, Array.Empty<GUILayoutOption>());
				errorMessage = null;
				GUI.color = Color.white;
			}
		}

		public override string Name()
		{
			return "Better Fabber";
		}

		public override void OnOpen()
		{
			if (FabRecycleSpeed == null)
			{
				FabRecycleSpeed = BepinPlugin.Bindings.FabRecycleSpeedMultiplier.Value.ToString();
			}
			if (FabPrintSpeed == null)
			{
				FabPrintSpeed = BepinPlugin.Bindings.FabPrintSpeedMultiplier.Value.ToString();
			}
		}
	}
	public class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Dragon.BetterFabber";

		public const string PLUGIN_NAME = "BetterFabber";

		public const string USERS_PLUGIN_NAME = "Better Fabber";

		public const string PLUGIN_VERSION = "1.0.2";

		public const string PLUGIN_DESCRIPTION = "Auto-recycles alloy, increases fabricator recycle and print speed. Host side";

		public const string PLUGIN_ORIGINAL_AUTHOR = "Dragon";

		public const string PLUGIN_AUTHORS = "Dragon, 18107";

		public const string PLUGIN_THUNDERSTORE_ID = "VoidCrewModdingTeam/BetterFabber";
	}
	[HarmonyPatch(typeof(CarryableFactoryUtils), "GetRecycleAnimationDuration")]
	internal class FabricatorRecycleSpeedPatch
	{
		[HarmonyPostfix]
		private static void Patch(ref float __result)
		{
			__result /= BepinPlugin.Bindings.FabRecycleSpeedMultiplier.Value;
		}
	}
	[HarmonyPatch(typeof(CarryableFactoryUtils), "GetCopierAnimationDuration")]
	internal class FabricatorPrintSpeedPatch
	{
		[HarmonyPostfix]
		private static void Patch(ref float __result)
		{
			__result /= BepinPlugin.Bindings.FabPrintSpeedMultiplier.Value;
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)20;

		public override string Author => "Dragon, 18107";

		public override string Description => "Auto-recycles alloy, increases fabricator recycle and print speed. Host side";

		public override string ThunderstoreID => "VoidCrewModdingTeam/BetterFabber";
	}
}