Decompiled source of AssetUnloadGate v1.1.0

plugins/AssetUnloadGate/AssetUnloadGate.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("AssetUnloadGate")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("AssetUnloadGate")]
[assembly: AssemblyTitle("AssetUnloadGate")]
[assembly: AssemblyVersion("1.1.0.0")]
[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 AssetUnloadGate
{
	[BepInPlugin("homelab.assetunloadgate", "AssetUnloadGate", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "homelab.assetunloadgate";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<float> MaxHoursWithPlayers;

		internal static ConfigEntry<float> ClientMaxHours;

		internal static DateTime LastUnload = DateTime.Now;

		private void Awake()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Dedicated sunucuda oyuncu varken saatlik UnloadUnusedAssets'i atla.");
			MaxHoursWithPlayers = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxHoursWithPlayers", 6f, "Sunucu: oyuncu olsa bile en gec bu kadar saatte bir temizlik calissin (bellek siniri).");
			ClientMaxHours = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ClientMaxHours", 4f, "Istemci: oyundayken en gec bu kadar saatte bir temizlik calissin (bellek siniri).");
			new Harmony("homelab.assetunloadgate").PatchAll(typeof(Plugin).Assembly);
		}
	}
	[HarmonyPatch(typeof(Game), "CollectResourcesCheckPeriodic")]
	internal static class PeriodicPatch
	{
		private static bool Prefix()
		{
			ZNet instance = ZNet.instance;
			if (!Plugin.Enabled.Value || (Object)(object)instance == (Object)null)
			{
				return true;
			}
			double totalHours = (DateTime.Now - Plugin.LastUnload).TotalHours;
			if (instance.IsDedicated())
			{
				int peerConnections = instance.GetPeerConnections();
				if (peerConnections == 0)
				{
					return true;
				}
				if (totalHours >= (double)Plugin.MaxHoursWithPlayers.Value)
				{
					Plugin.Log.LogInfo((object)$"{peerConnections} oyuncu var ama son temizlikten bu yana {totalHours:F1} saat gecti; calistiriliyor.");
					return true;
				}
				Plugin.Log.LogInfo((object)$"Saatlik UnloadUnusedAssets atlandi: {peerConnections} oyuncu bagli, son temizlik {totalHours:F1} saat once.");
				return false;
			}
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return true;
			}
			if (totalHours >= (double)Plugin.ClientMaxHours.Value)
			{
				Plugin.Log.LogInfo((object)$"Oyundasin ama son temizlikten bu yana {totalHours:F1} saat gecti; calistiriliyor.");
				return true;
			}
			Plugin.Log.LogInfo((object)$"Saatlik UnloadUnusedAssets atlandi (istemci, oyunda), son temizlik {totalHours:F1} saat once.");
			return false;
		}
	}
	[HarmonyPatch(typeof(Game), "CollectResources")]
	internal static class CollectPatch
	{
		private static void Postfix()
		{
			Plugin.LastUnload = DateTime.Now;
		}
	}
}