Decompiled source of RailSafeLoot v1.0.4

SafeLoot2.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("SafeLoot2")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SafeLoot2")]
[assembly: AssemblyTitle("SafeLoot2")]
[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;
		}
	}
}
[BepInPlugin("com.michalis.safelootfull", "SafeLootFull", "1.0.5")]
public class SafeLootFull : BaseUnityPlugin
{
	public static ManualLogSource Log;

	public static List<GrabbableObject> persistentItems = new List<GrabbableObject>();

	public static string lastMoon;

	private void Awake()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogInfo((object)"SafeLootFull 1.0.5 loaded! Items will persist no matter what, even on death or across moons/seeds.");
		new Harmony("com.michalis.safelootfull").PatchAll();
	}

	public static void SaveAllItems()
	{
		GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
		persistentItems.RemoveAll((GrabbableObject i) => (Object)(object)i == (Object)null);
		GrabbableObject[] array2 = array;
		foreach (GrabbableObject val in array2)
		{
			if ((Object)(object)val != (Object)null && !persistentItems.Contains(val))
			{
				persistentItems.Add(val);
				Log.LogInfo((object)("[SafeLootFull] Saved item: " + ((Object)((Component)val).gameObject).name));
			}
		}
	}
}
[HarmonyPatch(typeof(StartOfRound), "StartGame")]
public static class StartOfRoundPatch
{
	private static void Postfix(StartOfRound __instance)
	{
		if (!((NetworkBehaviour)__instance).IsServer)
		{
			return;
		}
		int num = 0;
		foreach (GrabbableObject persistentItem in SafeLootFull.persistentItems)
		{
			if ((Object)(object)persistentItem != (Object)null && !((Component)persistentItem).gameObject.activeInHierarchy)
			{
				((Component)persistentItem).gameObject.SetActive(true);
				num++;
			}
		}
		SafeLootFull.Log.LogInfo((object)$"[SafeLootFull] Restored {num} items (cross-moon/seed persistence).");
		SafeLootFull.lastMoon = __instance.currentLevel.PlanetName;
	}
}
[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
public static class RoundManagerPatch
{
	private static bool Prefix(RoundManager __instance, bool despawnAllItems = false)
	{
		if (!((NetworkBehaviour)__instance).IsServer)
		{
			return true;
		}
		SafeLootFull.SaveAllItems();
		GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
		foreach (GrabbableObject val in array)
		{
			if ((Object)(object)val != (Object)null)
			{
				val.scrapPersistedThroughRounds = true;
				if (!SafeLootFull.persistentItems.Contains(val))
				{
					SafeLootFull.persistentItems.Add(val);
				}
				if (__instance.spawnedSyncedObjects.Contains(((Component)val).gameObject))
				{
					__instance.spawnedSyncedObjects.Remove(((Component)val).gameObject);
				}
				SafeLootFull.Log.LogInfo((object)("[SafeLootFull] Persisting item: " + ((Object)((Component)val).gameObject).name));
			}
		}
		GameObject[] array2 = GameObject.FindGameObjectsWithTag("TemporaryEffect");
		for (int i = 0; i < array2.Length; i++)
		{
			Object.Destroy((Object)(object)array2[i]);
		}
		return false;
	}
}