using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Xml;
using Alpha;
using Alpha.Core.Command;
using Alpha.Core.Util;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Sweep.Core.Commands;
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("AndrewLin")]
[assembly: AssemblyConfiguration("Publish")]
[assembly: AssemblyDescription("Sweep: Periodically unloads unused Unity assets to reclaim memory.")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1+6b728ac84723d4f7964ec0bde26047dc2f58fe8d")]
[assembly: AssemblyProduct("AndrewLin.Sweep")]
[assembly: AssemblyTitle("AndrewLin.Sweep")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/andrewlimforfun/ot-mods")]
[assembly: AssemblyVersion("0.0.1.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace Sweep
{
public static class BuildInfo
{
public const string Version = "0.0.1";
}
[BepInPlugin("com.andrewlin.ontogether.sweep", "Sweep", "0.0.1")]
public class SweepPlugin : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <SweepLoop>d__14 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public SweepPlugin <>4__this;
private float <seconds>5__1;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <SweepLoop>d__14(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
break;
case 1:
<>1__state = -1;
Log.LogInfo((object)"Sweep: Unload unused assets...");
Resources.UnloadUnusedAssets();
break;
}
<seconds>5__1 = (float)GetInterval().TotalSeconds;
<>2__current = (object)new WaitForSecondsRealtime(<seconds>5__1);
<>1__state = 1;
return true;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public const string ModGUID = "com.andrewlin.ontogether.sweep";
public const string ModName = "Sweep";
public const string ModVersion = "0.0.1";
internal static ManualLogSource Log;
private Coroutine? _sweepCoroutine;
private static SweepPlugin? _instance;
public static ConfigEntry<string>? Interval { get; private set; }
internal static SweepPlugin? Instance => _instance;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Sweep v0.0.1 is loaded!");
InitConfig();
ChatCommandManager commandManager = AlphaPlugin.CommandManager;
if (commandManager != null)
{
commandManager.Register((IChatCommand)(object)new SweepIntervalCommand());
}
ChatCommandManager commandManager2 = AlphaPlugin.CommandManager;
if (commandManager2 != null)
{
commandManager2.Register((IChatCommand)(object)new SweepNowCommand());
}
RestartCoroutine();
}
private void InitConfig()
{
Interval = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Interval", "PT30M", "How often to unload unused assets. ISO 8601 duration. Examples: PT30M, PT1H, PT1H30M");
}
internal static TimeSpan GetInterval()
{
if (Interval == null)
{
return TimeSpan.FromMinutes(30.0);
}
TimeSpan result = default(TimeSpan);
if (TimeUtils.TryParseDuration(Interval.Value, ref result) && result.TotalSeconds > 0.0)
{
return result;
}
return TimeSpan.FromMinutes(30.0);
}
internal static string FormatInterval()
{
TimeSpan interval = GetInterval();
return XmlConvert.ToString(interval);
}
internal void RestartCoroutine()
{
if (_sweepCoroutine != null)
{
((MonoBehaviour)this).StopCoroutine(_sweepCoroutine);
}
_sweepCoroutine = ((MonoBehaviour)this).StartCoroutine(SweepLoop());
}
[IteratorStateMachine(typeof(<SweepLoop>d__14))]
private IEnumerator SweepLoop()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <SweepLoop>d__14(0)
{
<>4__this = this
};
}
private void OnEnable()
{
_instance = this;
}
private void OnDestroy()
{
_instance = null;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "AndrewLin.Sweep";
public const string PLUGIN_NAME = "AndrewLin.Sweep";
public const string PLUGIN_VERSION = "0.0.1";
}
}
namespace Sweep.Core.Commands
{
public class SweepIntervalCommand : IChatCommand, IComparable<IChatCommand>
{
public string Name => "sweepinterval";
public string ShortName => "si";
public string Description => "Get or set the sweep interval. Usage: /si [duration] (e.g. 30M, 1H, PT1H30M)";
public string Namespace => "sweep";
public void Execute(string[] args)
{
if (SweepPlugin.Interval == null)
{
return;
}
if (args.Length >= 1)
{
string text = args[0];
TimeSpan timeSpan = default(TimeSpan);
if (!TimeUtils.TryParseDuration(text, ref timeSpan) || timeSpan.TotalSeconds <= 0.0)
{
ChatUtils.AddGlobalNotification("Invalid duration. Examples: 30M, 1H, PT1H30M");
return;
}
SweepPlugin.Interval.Value = text.ToUpperInvariant();
SweepPlugin.Instance?.RestartCoroutine();
}
ChatUtils.AddGlobalNotification("Sweep interval = " + SweepPlugin.FormatInterval());
}
}
public class SweepNowCommand : IChatCommand, IComparable<IChatCommand>
{
public string Name => "sweepnow";
public string ShortName => "sn";
public string Description => "Unload unused Unity assets immediately.";
public string Namespace => "sweep";
public void Execute(string[] args)
{
SweepPlugin.Log.LogInfo((object)"Manual sweep triggered via /sweepnow.");
ChatUtils.AddGlobalNotification("Sweeping unused assets...");
Resources.UnloadUnusedAssets();
}
}
}