Decompiled source of ConfigurableWipe v0.1.0

Exund.ConfigurableWipe.dll

Decompiled 10 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 BepInEx.Logging;
using HarmonyLib;
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 = "")]
[assembly: AssemblyCompany("Exund")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("ConfigurableWipe")]
[assembly: AssemblyTitle("Exund.ConfigurableWipe")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
namespace ConfigurableWipe
{
	[BepInPlugin("Exund.ConfigurableWipe", "ConfigurableWipe", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public class PluginConfig
		{
			public ConfigEntry<bool> keepScrap;

			public ConfigEntry<float> scrapKeepChance;

			public ConfigEntry<bool> keepGear;

			public ConfigEntry<float> gearKeepChance;

			public PluginConfig(ConfigFile cfg)
			{
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Expected O, but got Unknown
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: Expected O, but got Unknown
				keepScrap = cfg.Bind<bool>("General", "KeepScrap", false, "Keep scrap when all players die");
				scrapKeepChance = cfg.Bind<float>("General", "ScrapKeepChance", 1f, new ConfigDescription("Chance to keep scrap in the ship", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
				keepGear = cfg.Bind<bool>("General", "KeepGear", true, "Keep purchased gear when all players die");
				gearKeepChance = cfg.Bind<float>("General", "GearKeepChance", 1f, new ConfigDescription("Chance to keep purchased gear", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			}
		}

		public static PluginConfig config;

		public static ManualLogSource Log;

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			config = new PluginConfig(((BaseUnityPlugin)this).Config);
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"Exund.ConfigurableWipe is loaded!");
			new Harmony("Exund.ConfigurableWipe").PatchAll(Assembly.GetExecutingAssembly());
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Exund.ConfigurableWipe";

		public const string PLUGIN_NAME = "ConfigurableWipe";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace ConfigurableWipe.Patches
{
	[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
	internal class RoundManagerPatcher
	{
		[HarmonyPrefix]
		public static bool DespawnPropsAtEndOfRound(RoundManager __instance, bool despawnAllItems)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return false;
			}
			Plugin.Log.LogInfo((object)"DespawnPropsAtEndOfRound");
			Plugin.Log.LogInfo((object)$"keepScrap: {Plugin.config.keepScrap.Value}");
			Plugin.Log.LogInfo((object)$"scrapKeepChance: {Plugin.config.scrapKeepChance.Value}");
			Plugin.Log.LogInfo((object)$"keepGear: {Plugin.config.keepGear.Value}");
			Plugin.Log.LogInfo((object)$"gearKeepChance: {Plugin.config.gearKeepChance.Value}");
			if (StartOfRound.Instance.allPlayersDead)
			{
				Plugin.Log.LogInfo((object)"Team wipe");
			}
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			foreach (GrabbableObject val in array)
			{
				bool flag = despawnAllItems || (!val.isHeld && !val.isInShipRoom) || val.deactivated;
				if (!flag && StartOfRound.Instance.allPlayersDead)
				{
					if (val.itemProperties.isScrap)
					{
						if (!Plugin.config.keepScrap.Value)
						{
							flag = Random.value > Plugin.config.scrapKeepChance.Value;
						}
					}
					else if (!Plugin.config.keepGear.Value)
					{
						flag = Random.value > Plugin.config.gearKeepChance.Value;
					}
					if (flag)
					{
						Plugin.Log.LogInfo((object)("Removing item " + ((Object)val).name));
					}
				}
				if (flag)
				{
					if (val.isHeld && (Object)(object)val.playerHeldBy != (Object)null)
					{
						val.playerHeldBy.DropAllHeldItemsAndSync();
					}
					NetworkObject component = ((Component)val).gameObject.GetComponent<NetworkObject>();
					if (Object.op_Implicit((Object)(object)component) && component.IsSpawned)
					{
						component.Despawn(true);
					}
					else
					{
						Debug.Log((object)("Error/warning: prop '" + ((Object)((Component)val).gameObject).name + "' was not spawned or did not have a NetworkObject component! Skipped despawning and destroyed it instead."));
						Object.Destroy((Object)(object)((Component)val).gameObject);
					}
				}
				else
				{
					val.scrapPersistedThroughRounds = true;
				}
				__instance.spawnedSyncedObjects.Remove(((Component)val).gameObject);
			}
			GameObject[] array2 = GameObject.FindGameObjectsWithTag("TemporaryEffect");
			foreach (GameObject val2 in array2)
			{
				Object.Destroy((Object)(object)val2);
			}
			return false;
		}
	}
}