Decompiled source of SafeSoloScrap v1.0.0

SafeSoloScrap.dll

Decompiled 7 months 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[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: AssemblyCompany("SafeSoloScrap")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Lets you keep some scrap on the ship after dying in singleplayer, for a more casual solo-friendly experience.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SafeSoloScrap")]
[assembly: AssemblyTitle("SafeSoloScrap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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", "1.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 = "1.0.0";

		public static ConfigEntry<bool> configKeepTwoHanded;

		private void Awake()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			configKeepTwoHanded = ((BaseUnityPlugin)this).Config.Bind<bool>("Gameplay", "KeepTwoHanded", false, "Retain two-handed items?");
			Harmony val = new Harmony("butterystancakes.lethalcompany.safesoloscrap");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Safe Solo Scrap v1.0.0 loaded");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "SafeSoloScrap";

		public const string PLUGIN_NAME = "SafeSoloScrap";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace SafeSoloScrap.Patches
{
	[HarmonyPatch]
	internal class SafeSoloScrapPatches
	{
		[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
		[HarmonyPrefix]
		public static bool DespawnPropsAtEndOfRound(RoundManager __instance, bool despawnAllItems)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return false;
			}
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			for (int i = 0; i < array.Length; i++)
			{
				if (despawnAllItems || (!array[i].isHeld && !array[i].isInShipRoom) || array[i].deactivated || (StartOfRound.Instance.allPlayersDead && array[i].itemProperties.isScrap && (StartOfRound.Instance.connectedPlayersAmount > 0 || (array[i].itemProperties.twoHanded && !Plugin.configKeepTwoHanded.Value))))
				{
					if (array[i].isHeld && (Object)(object)array[i].playerHeldBy != (Object)null)
					{
						array[i].playerHeldBy.DropAllHeldItems(true, false);
					}
					((Component)array[i]).gameObject.GetComponent<NetworkObject>().Despawn(true);
				}
				else
				{
					array[i].scrapPersistedThroughRounds = true;
				}
				if (__instance.spawnedSyncedObjects.Contains(((Component)array[i]).gameObject))
				{
					__instance.spawnedSyncedObjects.Remove(((Component)array[i]).gameObject);
				}
			}
			GameObject[] array2 = GameObject.FindGameObjectsWithTag("TemporaryEffect");
			for (int j = 0; j < array2.Length; j++)
			{
				Object.Destroy((Object)(object)array2[j]);
			}
			return false;
		}
	}
}