Decompiled source of FreeConveyors v1.4.0

FreeConveyors.dll

Decompiled 16 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GraveyardKeeper2LocalizationAPI.Api;
using HarmonyLib;
using LazyBearTechnology;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FreeConveyors")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FreeConveyors")]
[assembly: AssemblyTitle("FreeConveyors")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 FreeConveyors
{
	[BepInPlugin("enoc.gk2.freeconveyors", "Free Conveyors", "1.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "enoc.gk2.freeconveyors";

		private const string SectionBelts = "1. Belts";

		private const string SectionMachines = "2. Machines";

		private const string SectionDebug = "3. Debug";

		private static readonly string[] KnownMachines = new string[7] { "conveyor_assemblybench_t1", "conveyor_assemblybench_t2", "conveyor_furnace_t1", "conveyor_kitchen_t1", "conveyor_kitchen_t2", "conveyor_bioreactor", "conveyor_woodworkbench" };

		internal static ManualLogSource Log;

		internal static ConfigFile Cfg;

		internal static ModLocalizer L;

		internal static ConfigEntry<bool> DebugLog;

		private static readonly Dictionary<ConveyorElementType, ConfigEntry<bool>> Free = new Dictionary<ConveyorElementType, ConfigEntry<bool>>();

		private static readonly Dictionary<string, ConfigEntry<int>> Machine = new Dictionary<string, ConfigEntry<int>>();

		private void Awake()
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Cfg = ((BaseUnityPlugin)this).Config;
			L = LocalizationApi.For("enoc.gk2.freeconveyors");
			L.RegisterJson(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "FreeConveyors.Localization.json"));
			int num = 100;
			BindFree((ConveyorElementType)1, def: true, num--);
			BindFree((ConveyorElementType)7, def: true, num--);
			BindFree((ConveyorElementType)8, def: true, num--);
			BindFree((ConveyorElementType)6, def: true, num--);
			BindFree((ConveyorElementType)4, def: false, num--);
			BindFree((ConveyorElementType)9, def: false, num--);
			BindFree((ConveyorElementType)2, def: false, num--);
			string[] knownMachines = KnownMachines;
			for (int i = 0; i < knownMachines.Length; i++)
			{
				GetMachineEntry(knownMachines[i]);
			}
			DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Debug", "LogConsumption", false, L.Config("debug.log", 100, "3. Debug", "section.debug", 10, (AcceptableValueBase)null));
			new Harmony("enoc.gk2.freeconveyors").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Free Conveyors loaded.");
		}

		private unsafe void BindFree(ConveyorElementType type, bool def, int order)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Free[type] = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Belts", ((object)(*(ConveyorElementType*)(&type))/*cast due to .constrained prefix*/).ToString(), def, L.Config("belts." + ((object)(*(ConveyorElementType*)(&type))/*cast due to .constrained prefix*/).ToString().ToLowerInvariant(), order, "1. Belts", "section.belts", 100, (AcceptableValueBase)null));
		}

		private static ConfigEntry<int> GetMachineEntry(string id)
		{
			if (!Machine.TryGetValue(id, out var value))
			{
				int num = (id.EndsWith("_t1") ? 3 : 5);
				value = Cfg.Bind<int>("2. Machines", id, num, L.Config("machine." + id, 100 - Machine.Count, "2. Machines", "section.machines", 50, (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100)));
				Machine[id] = value;
			}
			return value;
		}

		internal static int MachineCost(string id)
		{
			return GetMachineEntry(id).Value;
		}

		internal static bool IsFree(ConveyorElementType type)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (Free.TryGetValue(type, out var value))
			{
				return value.Value;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(ConveyorWgoData), "GetQuality")]
	internal static class GetQualityPatch
	{
		private static readonly HashSet<string> Seen = new HashSet<string>();

		private static void Postfix(ConveyorWgoData __instance, ref float __result)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Invalid comparison between Unknown and I4
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			WGODef definition = ((ObjectLinkedToDefinition<WGODef>)(object)__instance).Definition;
			if (definition == null)
			{
				return;
			}
			if (Plugin.DebugLog.Value && Seen.Add(((BalanceBaseObject)definition).id + "|" + __result))
			{
				Plugin.Log.LogInfo((object)$"[CONSUMPTION] type={definition.conveyorType} id={((BalanceBaseObject)definition).id} original={__result}");
			}
			if ((int)definition.conveyorType == 3)
			{
				if (__result == 0f)
				{
					__result = -Plugin.MachineCost(((BalanceBaseObject)definition).id);
				}
			}
			else if (__result < 0f && Plugin.IsFree(definition.conveyorType))
			{
				__result = 0f;
			}
		}
	}
}