Decompiled source of SafeSoloScrap v2.0.0

SafeSoloScrap.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SafeSoloScrap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Lets you keep some scrap on the ship after dying in singleplayer, for a more casual solo-friendly experience.")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0+c27adf28c60862ff1762a9d8e589adae0ca8abbc")]
[assembly: AssemblyProduct("SafeSoloScrap")]
[assembly: AssemblyTitle("SafeSoloScrap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SafeSoloScrap
{
	[BepInPlugin("butterystancakes.lethalcompany.safesoloscrap", "Safe Solo Scrap", "2.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "butterystancakes.lethalcompany.safesoloscrap";

		private const string PLUGIN_NAME = "Safe Solo Scrap";

		private const string PLUGIN_VERSION = "2.0.0";

		public static ConfigEntry<int> configMaxPlayers;

		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			configMaxPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("Gameplay", "MaxPlayers", 1, new ConfigDescription("How many players are allowed in the lobby before vanilla death penalty takes over?", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 3), Array.Empty<object>()));
			((BaseUnityPlugin)this).Config.Bind<bool>("Gameplay", "KeepTwoHanded", false, "Legacy setting");
			((BaseUnityPlugin)this).Config.Remove(((BaseUnityPlugin)this).Config["Gameplay", "KeepTwoHanded"].Definition);
			Logger = ((BaseUnityPlugin)this).Logger;
			new Harmony("butterystancakes.lethalcompany.safesoloscrap").PatchAll();
			Logger.LogInfo((object)"Safe Solo Scrap v2.0.0 loaded");
		}
	}
	public static class ScrapSafe
	{
		private static readonly string[] drillPieces = new string[1] { "LungApparatus" };

		public static bool IsItemLost(GrabbableObject grabObj)
		{
			if (grabObj.itemProperties.isScrap)
			{
				if (StartOfRound.Instance.connectedPlayersAmount <= Plugin.configMaxPlayers.Value - 1 && grabObj.scrapPersistedThroughRounds)
				{
					return Array.Exists(drillPieces, (string drillPiece) => drillPiece == ((Object)grabObj.itemProperties).name);
				}
				return true;
			}
			return false;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "SafeSoloScrap";

		public const string PLUGIN_NAME = "SafeSoloScrap";

		public const string PLUGIN_VERSION = "2.0.0";
	}
}
namespace SafeSoloScrap.Patches
{
	[HarmonyPatch]
	internal class SafeSoloScrapPatches
	{
		[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> TransDespawnPropsAtEndOfRound(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			FieldInfo fieldInfo = AccessTools.Field(typeof(Item), "isScrap");
			for (int i = 2; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Brfalse && list[i - 1].opcode == OpCodes.Ldfld && (FieldInfo)list[i - 1].operand == fieldInfo)
				{
					list[i - 1].opcode = OpCodes.Call;
					list[i - 1].operand = AccessTools.Method(typeof(ScrapSafe), "IsItemLost", (Type[])null, (Type[])null);
					list.RemoveAt(i - 2);
					Plugin.Logger.LogDebug((object)"Transpiler (Penalty): Redirect scrap check to custom function");
					return list;
				}
			}
			Plugin.Logger.LogError((object)"Penalty transpiler failed");
			return list;
		}
	}
}