Decompiled source of FpsProtector CleanupStation v1.0.3

FpsProtector_CleanupStation.dll

Decompiled an hour ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ValheimCleanupStation")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ValheimCleanupStation")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("28b5dede-c42b-40e7-9ab1-f2f6fb3a6835")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ValheimCleanupStation;

[BepInPlugin("com.shaya.cleanupstation", "Cleanup Station", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class CleanupPlugin : BaseUnityPlugin
{
	private void Awake()
	{
		PrefabManager.OnVanillaPrefabsAvailable += CreateCleanupStation;
	}

	private void CreateCleanupStation()
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Expected O, but got Unknown
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected O, but got Unknown
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Expected O, but got Unknown
		PrefabManager.OnVanillaPrefabsAvailable -= CreateCleanupStation;
		GameObject val = PrefabManager.Instance.CreateClonedPrefab("CleanupStation", "piece_workbench");
		Object.DestroyImmediate((Object)(object)val.GetComponent<CraftingStation>());
		val.AddComponent<CleanupInteraction>();
		PieceConfig val2 = new PieceConfig();
		val2.Name = "Cleanup Station";
		val2.Description = "Removes ground items to save server lag.";
		val2.PieceTable = PieceTables.Hammer;
		val2.Category = "Misc";
		val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
		{
			new RequirementConfig
			{
				Item = "Wood",
				Amount = 10,
				Recover = true
			},
			new RequirementConfig
			{
				Item = "Stone",
				Amount = 5,
				Recover = true
			}
		};
		PieceConfig val3 = val2;
		CustomPiece val4 = new CustomPiece(val, val3);
		PieceManager.Instance.AddPiece(val4);
	}
}
public class CleanupInteraction : MonoBehaviour, Interactable, Hoverable
{
	public string GetHoverText()
	{
		return "Cleanup Station\n[<color=yellow><b>E</b></color>] Open Menu";
	}

	public string GetHoverName()
	{
		return "Cleanup Station";
	}

	public float GetHoverOffset()
	{
		return 0f;
	}

	public bool Interact(Humanoid user, bool hold, bool alt)
	{
		if (hold)
		{
			return false;
		}
		CleanupUI.ToggleUI();
		return true;
	}

	public bool UseItem(Humanoid user, ItemData item)
	{
		return false;
	}
}
public static class CleanupUI
{
	private static GameObject uiPanel;

	public static void ToggleUI()
	{
		if ((Object)(object)uiPanel == (Object)null)
		{
			CreateUI();
		}
		bool flag = !uiPanel.activeSelf;
		uiPanel.SetActive(flag);
		GUIManager.BlockInput(flag);
	}

	private static void CreateUI()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Expected O, but got Unknown
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Expected O, but got Unknown
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Expected O, but got Unknown
		if (!((Object)(object)GUIManager.CustomGUIFront == (Object)null))
		{
			uiPanel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 0f), 400f, 250f);
			((UnityEvent)GUIManager.Instance.CreateButton("Cleanup ground items", uiPanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 60f), 250f, 40f).GetComponent<Button>().onClick).AddListener(new UnityAction(ExecuteCleanup));
			((UnityEvent)GUIManager.Instance.CreateButton("4-step Cleanup items & Optimize Fps", uiPanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 0f), 250f, 40f).GetComponent<Button>().onClick).AddListener(new UnityAction(ExecuteOptimize));
			((UnityEvent)GUIManager.Instance.CreateButton("Close Cleanup menu", uiPanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, -60f), 250f, 40f).GetComponent<Button>().onClick).AddListener(new UnityAction(ToggleUI));
			uiPanel.SetActive(false);
		}
	}

	private static void ExecuteCleanup()
	{
		int num = 0;
		ItemDrop[] array = Object.FindObjectsOfType<ItemDrop>();
		for (int i = 0; i < array.Length; i++)
		{
			ZNetView component = ((Component)array[i]).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid())
			{
				component.ClaimOwnership();
				component.Destroy();
				num++;
			}
		}
		((Character)Player.m_localPlayer).Message((MessageType)2, $"Cleaned up {num} items.", 0, (Sprite)null, false);
		ToggleUI();
	}

	private static void ExecuteOptimize()
	{
		int num = 0;
		int num2 = 0;
		int num3 = 0;
		ItemDrop[] array = Object.FindObjectsOfType<ItemDrop>();
		for (int i = 0; i < array.Length; i++)
		{
			ZNetView component = ((Component)array[i]).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid())
			{
				component.ClaimOwnership();
				component.Destroy();
				num++;
			}
		}
		Smoke[] array2 = Object.FindObjectsOfType<Smoke>();
		for (int i = 0; i < array2.Length; i++)
		{
			Object.Destroy((Object)(object)((Component)array2[i]).gameObject);
			num2++;
		}
		Ragdoll[] array3 = Object.FindObjectsOfType<Ragdoll>();
		for (int i = 0; i < array3.Length; i++)
		{
			Object.Destroy((Object)(object)((Component)array3[i]).gameObject);
			num3++;
		}
		long totalMemory = GC.GetTotalMemory(forceFullCollection: false);
		GC.Collect();
		long totalMemory2 = GC.GetTotalMemory(forceFullCollection: false);
		long num4 = (totalMemory - totalMemory2) / 1048576;
		if (num4 < 0)
		{
			num4 = 0L;
		}
		((Character)Player.m_localPlayer).Message((MessageType)2, $"Optimized! Cleared {num} items, {num2} smoke, {num3} corpses. Freed {num4} MB of RAM.", 0, (Sprite)null, false);
		ToggleUI();
	}
}