Decompiled source of Creative Provider v1.0.7

CreativeStuff.dll

Decompiled a month 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 CreativeStuff.Data;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("CreativeStuff")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A mod to create an infite amount of stuff")]
[assembly: AssemblyFileVersion("1.0.7.0")]
[assembly: AssemblyInformationalVersion("1.0.7+b439f5a5d2fd466a46f608f3b3b0448dd4c0fc70")]
[assembly: AssemblyProduct("CreativeStuff")]
[assembly: AssemblyTitle("CreativeStuff")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.7.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 CreativeStuff
{
	[BepInPlugin("nl.jessestam.creativeStuff", "creativeStuff", "1.0.7.0")]
	[BepInProcess("DSPGAME.exe")]
	public class CreativeStuff : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "nl.jessestam.creativeStuff";

		public const string PLUGIN_NAME = "creativeStuff";

		public const string PLUGIN_VERSION = "1.0.7.0";

		public static SplitterConfig SplitterConfig;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			SplitterConfig = new SplitterConfig(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Config.Save();
			harmony = new Harmony("nl.jessestam.creativeStuff");
			harmony.PatchAll(typeof(SplitterPatch));
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
		}
	}
	public static class SplitterPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(CargoTraffic), "UpdateSplitter")]
		[HarmonyPatch(typeof(CargoTraffic), "UpdateSplitterAsync")]
		public static void CargoTraffic_UpdateSplitter_Prefix(CargoTraffic __instance, ref SplitterComponent sp)
		{
			if (sp.outFilter != 0 && AllInputIsNone(ref sp))
			{
				int outFilter = sp.outFilter;
				TryDoOutputForOutput(outFilter, sp.output0);
				TryDoOutputForOutput(outFilter, sp.output1);
				TryDoOutputForOutput(outFilter, sp.output2);
				TryDoOutputForOutput(outFilter, sp.output3);
			}
			static bool AllInputIsNone(ref SplitterComponent sp)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				SplitterComponent val = sp;
				if (val.input0 == 0 && val.input1 == 0 && val.input2 == 0)
				{
					return val.input3 == 0;
				}
				return false;
			}
			void TryDoOutputForOutput(int filter, int output)
			{
				if (output > 0)
				{
					CargoPath cargoPath = __instance.GetCargoPath(__instance.beltPool[output].segPathId);
					if (cargoPath != null && cargoPath.TestBlankAtHead() == 0)
					{
						cargoPath.TryInsertItemAtHeadAndFillBlank(filter, CreativeStuff.SplitterConfig.OutputStackSize.Value, CreativeStuff.SplitterConfig.SprayLevel.Value);
					}
				}
			}
		}
	}
}
namespace CreativeStuff.Data
{
	public class SplitterConfig
	{
		public ConfigEntry<byte> OutputStackSize;

		public ConfigEntry<byte> SprayLevel;

		public SplitterConfig(ConfigFile config)
		{
			OutputStackSize = config.Bind<byte>("General", "Stacksize", (byte)4, "The output stack size (Range 1-8) above that has not been tested");
			SprayLevel = config.Bind<byte>("General", "SprayLevel", (byte)16, "How much spray has been applied to the output? (Range 0-255) the values seems to scale in some odd way");
			OutputStackSize.Value = (byte)Mathf.Clamp((int)OutputStackSize.Value, 1, 8);
			SprayLevel.Value = (byte)Mathf.Clamp((int)SprayLevel.Value, 0, 255);
		}
	}
}