Decompiled source of SafeSoloScrap v2.1.1

SafeSoloScrap.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
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("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.1.1.0")]
[assembly: AssemblyInformationalVersion("2.1.1+6177976855f36ce53a291576b704f8ad5f58a628")]
[assembly: AssemblyProduct("SafeSoloScrap")]
[assembly: AssemblyTitle("SafeSoloScrap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.1.0")]
[module: UnverifiableCode]
[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 SafeSoloScrap
{
	internal static class LobbyCompatibility
	{
		internal static void Init()
		{
			PluginHelper.RegisterPlugin("butterystancakes.lethalcompany.safesoloscrap", Version.Parse("2.1.1"), (CompatibilityLevel)1, (VersionStrictness)0);
		}
	}
	[BepInPlugin("butterystancakes.lethalcompany.safesoloscrap", "Safe Solo Scrap", "2.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal const string PLUGIN_GUID = "butterystancakes.lethalcompany.safesoloscrap";

		internal const string PLUGIN_NAME = "Safe Solo Scrap";

		internal const string PLUGIN_VERSION = "2.1.1";

		public static ConfigEntry<int> configMaxPlayers;

		private const string GUID_LOBBY_COMPATIBILITY = "BMX.LobbyCompatibility";

		internal const string GUID_LATE_GAME_UPGRADES = "com.malco.lethalcompany.moreshipupgrades";

		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			if (Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility"))
			{
				Logger.LogInfo((object)"CROSS-COMPATIBILITY - Lobby Compatibility detected");
				LobbyCompatibility.Init();
			}
			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, 50), Array.Empty<object>()));
			((BaseUnityPlugin)this).Config.Bind<bool>("Gameplay", "KeepTwoHanded", false, "Legacy setting, doesn't work");
			((BaseUnityPlugin)this).Config.Remove(((BaseUnityPlugin)this).Config["Gameplay", "KeepTwoHanded"].Definition);
			((BaseUnityPlugin)this).Config.Save();
			new Harmony("butterystancakes.lethalcompany.safesoloscrap").PatchAll();
			Logger.LogInfo((object)"Safe Solo Scrap v2.1.1 loaded");
		}
	}
	public static class ScrapSafe
	{
		public static bool IsItemLost(bool isScrap, GrabbableObject grabObj)
		{
			if (isScrap)
			{
				if (StartOfRound.Instance.connectedPlayersAmount <= Plugin.configMaxPlayers.Value - 1)
				{
					return !grabObj.scrapPersistedThroughRounds;
				}
				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.1.1";
	}
}
namespace SafeSoloScrap.Patches
{
	[HarmonyPatch]
	internal class SafeSoloScrapPatches
	{
		[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
		[HarmonyTranspiler]
		[HarmonyPriority(300)]
		[HarmonyAfter(new string[] { "com.malco.lethalcompany.moreshipupgrades" })]
		public static IEnumerable<CodeInstruction> RoundManager_Trans_DespawnPropsAtEndOfRound(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Expected O, but got Unknown
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Expected O, but got Unknown
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			FieldInfo fieldInfo = AccessTools.Field(typeof(Item), "isScrap");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(StartOfRound), "allPlayersDead");
			for (int i = 6; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldfld && (FieldInfo)list[i].operand == fieldInfo && list[i - 2].opcode == OpCodes.Ldelem_Ref && list[i - 3].opcode == OpCodes.Ldloc_S && list[i - 4].opcode == OpCodes.Ldloc_0 && list[i - 6].opcode == OpCodes.Ldfld && (FieldInfo)list[i - 6].operand == fieldInfo2)
				{
					list.InsertRange(i + 1, new <>z__ReadOnlyArray<CodeInstruction>((CodeInstruction[])(object)new CodeInstruction[4]
					{
						new CodeInstruction(OpCodes.Ldloc_0, (object)null),
						new CodeInstruction(OpCodes.Ldloc_S, list[i - 3].operand),
						new CodeInstruction(OpCodes.Ldelem_Ref, (object)null),
						new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ScrapSafe), "IsItemLost", (Type[])null, (Type[])null))
					}));
					Plugin.Logger.LogDebug((object)"Transpiler (Penalty): Redirect scrap check to custom function");
					return list;
				}
			}
			Plugin.Logger.LogError((object)"Penalty transpiler failed");
			return instructions;
		}
	}
}
[CompilerGenerated]
internal sealed class <>z__ReadOnlyArray<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	int ICollection.Count => _items.Length;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => _items.Length;

	T IReadOnlyList<T>.this[int index] => _items[index];

	int ICollection<T>.Count => _items.Length;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlyArray(T[] items)
	{
		_items = items;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return ((IEnumerable)_items).GetEnumerator();
	}

	void ICollection.CopyTo(Array array, int index)
	{
		((ICollection)_items).CopyTo(array, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return ((IList)_items).Contains(value);
	}

	int IList.IndexOf(object value)
	{
		return ((IList)_items).IndexOf(value);
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return ((IEnumerable<T>)_items).GetEnumerator();
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return ((ICollection<T>)_items).Contains(item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		((ICollection<T>)_items).CopyTo(array, arrayIndex);
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		return ((IList<T>)_items).IndexOf(item);
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}