Decompiled source of ScrapMerger v1.0.1

BepInEx/plugins/ScrapMerger/ScrapMerger.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using ScrapMerger.InputUtils;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: AssemblyCompany("ScrapMerger")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0")]
[assembly: AssemblyProduct("ScrapMerger")]
[assembly: AssemblyTitle("ScrapMerger")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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.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;
		}
	}
	[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 ScrapMerger
{
	internal static class MergeScrap
	{
		private static List<string> IgnoreItemNameList = new List<string>();

		public static void Merge()
		{
			GameObject val = GameObject.Find("/Environment/HangarShip");
			GrabbableObject[] componentsInChildren = val.GetComponentsInChildren<GrabbableObject>();
			Dictionary<string, GrabbableObject> dictionary = new Dictionary<string, GrabbableObject>();
			string text = "Homemade flashbang,Gift,Stop sign,Yield sign,Shotgun,Cat";
			IgnoreItemNameList = text.Split(new char[1] { ',' }).ToList();
			foreach (string ignoreItemName in IgnoreItemNameList)
			{
			}
			GrabbableObject[] array = componentsInChildren;
			foreach (GrabbableObject val2 in array)
			{
				if (Check(val2))
				{
					if (dictionary.ContainsKey(val2.itemProperties.itemName))
					{
						GrabbableObject val3 = dictionary[val2.itemProperties.itemName];
						val3.SetScrapValue(val3.scrapValue + val2.scrapValue);
						((NetworkBehaviour)val2).NetworkObject.Despawn(true);
					}
					else
					{
						dictionary[val2.itemProperties.itemName] = val2;
					}
				}
			}
			StartOfRound.Instance.SyncShipUnlockablesServerRpc();
			ScrapMerger.Log("Scrap Merged");
		}

		private static bool Check(GrabbableObject obj)
		{
			if (!obj.itemProperties.isScrap)
			{
				return false;
			}
			if (obj.isHeld)
			{
				return false;
			}
			if (obj.heldByPlayerOnServer)
			{
				return false;
			}
			if (IgnoreItemNameList.Contains(obj.itemProperties.itemName))
			{
				return false;
			}
			return true;
		}
	}
	[BepInPlugin("ScrapMerger", "ScrapMerger", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class ScrapMerger : BaseUnityPlugin
	{
		public static ScrapMerger instance;

		internal static InputUtilsKeybinds InputActionsInstance = new InputUtilsKeybinds();

		private const string GUID = "ScrapMerger";

		private const string NAME = "ScrapMerger";

		private const string VERSION = "1.0.0";

		public static void Log(string message)
		{
			((BaseUnityPlugin)instance).Logger.LogInfo((object)message);
		}

		public static void LogError(string message)
		{
			((BaseUnityPlugin)instance).Logger.LogError((object)message);
		}

		private void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ScrapMerger is loaded!");
			Harmony val = new Harmony("ScrapMerger");
			val.PatchAll(Assembly.GetExecutingAssembly());
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ScrapMerger";

		public const string PLUGIN_NAME = "ScrapMerger";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ScrapMerger.InputUtils
{
	internal class InputUtilsKeybinds : LcInputActions
	{
		[InputAction("<Keyboard>/m", Name = "Merge Scrap")]
		public InputAction MergeScrapKey { get; set; }
	}
}
namespace ScrapMerger.Configuration
{
	[HarmonyPatch]
	internal static class Keybinds
	{
		public static PlayerControllerB localPlayerController;

		[HarmonyPatch(typeof(PlayerControllerB), "OnDisable")]
		[HarmonyPostfix]
		public static void OnDisable(PlayerControllerB __instance)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0022: Expected O, but got Unknown
			if (ScrapMerger.InputActionsInstance.MergeScrapKey != null && !((Object)__instance != (Object)localPlayerController))
			{
				ScrapMerger.InputActionsInstance.MergeScrapKey.performed -= OnScrapMergerShipCleanupCalled;
				ScrapMerger.InputActionsInstance.MergeScrapKey.Disable();
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "OnEnable")]
		[HarmonyPostfix]
		public static void OnEnable(PlayerControllerB __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0016: Expected O, but got Unknown
			if ((Object)__instance == (Object)localPlayerController)
			{
				SubscribeToEvents();
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		public static void OnLocalPlayerConnect(PlayerControllerB __instance)
		{
			localPlayerController = __instance;
			if (((Component)localPlayerController).gameObject.activeSelf)
			{
				SubscribeToEvents();
			}
			ScrapMerger.Log("Local Player Connect");
			ScrapMerger.Log("Registering Manager");
		}

		private static void OnScrapMergerShipCleanupCalled(CallbackContext context)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			if (!((Object)localPlayerController == (Object)null) && localPlayerController.isPlayerControlled && !localPlayerController.isTypingChat && !localPlayerController.inTerminalMenu && (!((NetworkBehaviour)localPlayerController).IsServer || localPlayerController.isHostPlayerObject) && StartOfRound.Instance.inShipPhase && !StartOfRound.Instance.shipHasLanded)
			{
				ScrapMerger.Log("Ship Has Not Landed and In Ship Phase, merge scrap");
				MergeScrap.Merge();
			}
		}

		private static void SubscribeToEvents()
		{
			if (ScrapMerger.InputActionsInstance.MergeScrapKey != null)
			{
				ScrapMerger.InputActionsInstance.MergeScrapKey.Enable();
				ScrapMerger.InputActionsInstance.MergeScrapKey.performed += OnScrapMergerShipCleanupCalled;
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}