using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Threading.Tasks;
using AnsiConsolePlugin.Util;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: AssemblyCompany("TimeElapsingConsolePlugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A mod that allows for Time Elapsing for Windows 10+ in BepInEx.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+6dca09feca38e2d33302377114a2299bc853778f")]
[assembly: AssemblyProduct("TimeElapsingConsolePlugin")]
[assembly: AssemblyTitle("TimeElapsingConsolePlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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;
}
}
}
namespace TimeElapsingConsolePlugin
{
[BepInPlugin("creator.BepInEx.TimeElapsingMod", "Time Elapsing Mod", "1.1.0")]
public class TimeElapsingMod : BaseUnityPlugin
{
public const string PluginGuid = "creator.BepInEx.TimeElapsingMod";
public const string PluginName = "Time Elapsing Mod";
public const string PluginVersion = "1.1.0";
public static ManualLogSource Log = new ManualLogSource("Time Elapsing Mod");
public void Awake()
{
((BaseUnityPlugin)this).Logger.LogMessage((object)"Setting Sail! Too lazy to readd the old tests plus they weren't needed so have this instead as proof its loaded.");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "TimeElapsingConsolePlugin";
public const string PLUGIN_NAME = "TimeElapsingConsolePlugin";
public const string PLUGIN_VERSION = "1.1.0";
}
}
namespace TimeElapsingConsolePlugin.Util
{
public class HandleTimeUnits
{
public static string SwitchUnits(string Type)
{
return Type.ToLower() switch
{
"milliseconds" => "ms",
"seconds" => "s",
"minutes" => "m",
"hours" => "h",
"days" => "d",
"ticks" => "t",
_ => Type,
};
}
}
public class Information
{
public readonly Stopwatch watch;
public CancellationTokenSource Run { get; set; }
public string WhatDoWeAwait { get; set; }
public string Type { get; set; }
public string ModName { get; set; }
public Information(string whatDoWeAwait, string type, string modName)
{
Run = new CancellationTokenSource();
WhatDoWeAwait = whatDoWeAwait;
Type = HandleTimeUnits.SwitchUnits(type);
ModName = modName;
watch = new Stopwatch();
Stopwatches.HandleStopwatch("Start", watch);
}
}
public class Logging
{
public static Information StartWaitTime(string WhatDoWeAwait, string Type, string ModName)
{
Information Info = new Information(WhatDoWeAwait, Type, ModName);
Info.Run?.Cancel();
Info.Run = new CancellationTokenSource();
Stopwatches.HandleStopwatch("Reset", Info.watch);
Stopwatches.HandleStopwatch("Start", Info.watch);
Task.Run(async delegate
{
while (!Info.Run.IsCancellationRequested)
{
LogMessage(Stopwatches.GetTimeFromType(Info.Type, Stopwatches.HandleStopwatch("Elapsed", Info.watch)), Info);
await Task.Delay(100, Info.Run.Token);
}
});
return Info;
}
public static void StopWaitTime(Information Info)
{
if (Info.Run != null)
{
Info.Run.Cancel();
Stopwatches.HandleStopwatch("Stop", Info.watch);
int timeFromType = Stopwatches.GetTimeFromType(Info.Type, Stopwatches.HandleStopwatch("Elapsed", Info.watch));
Console.WriteLine("[Time Elapsing Console Library - " + Info.ModName + "]: \u001b[0m" + GetColorFromTypeFunctions.GetColorFromString("Yellow", "HighIntensityBold") + "Finished loading \u001b[0m" + GetColorFromTypeFunctions.GetColorFromString("Yellow", "HighIntensityUnderlined") + Info.WhatDoWeAwait.ToLower() + "\u001b[0m" + GetColorFromTypeFunctions.GetColorFromString("Yellow", "HighIntensityBold") + " time taken to load: \u001b[0m" + GetColorFromTypeFunctions.GetColorFromString("Yellow", "HighIntensityUnderlined") + timeFromType + Info.Type + "\u001b[0m ");
}
}
public static void LogMessage(int Time, Information Info)
{
int cursorTop = Console.CursorTop;
int cursorLeft = Console.CursorLeft;
Console.Write("[Time Elapsing Console Library - " + Info.ModName + "]: \u001b[0m" + GetColorFromTypeFunctions.GetColorFromString("Yellow", "HighIntensityBold") + "Awaiting time for \u001b[0m" + GetColorFromTypeFunctions.GetColorFromString("Yellow", "HighIntensityUnderlined") + Info.WhatDoWeAwait.ToLower() + "\u001b[0m" + GetColorFromTypeFunctions.GetColorFromString("Yellow", "HighIntensityBold") + " time spent waiting: \u001b[0m" + GetColorFromTypeFunctions.GetColorFromString("Yellow", "HighIntensityUnderlined") + Time + Info.Type + "\u001b[0m");
Console.SetCursorPosition(cursorLeft, cursorTop);
}
}
public class Stopwatches
{
public static TimeSpan HandleStopwatch(string Action, Stopwatch timer)
{
TimeSpan result = default(TimeSpan);
switch (Action)
{
case "Stop":
timer.Stop();
break;
case "Start":
timer.Start();
break;
case "Reset":
timer.Reset();
break;
case "Restart":
timer.Restart();
break;
case "Elapsed":
return timer.Elapsed;
}
return result;
}
public static int GetTimeFromType(string Type, TimeSpan span)
{
Type = HandleTimeUnits.SwitchUnits(Type);
return Type switch
{
"ms" => (int)span.TotalMilliseconds,
"s" => (int)span.TotalSeconds,
"m" => (int)span.TotalMinutes,
"h" => (int)span.TotalHours,
"d" => (int)span.TotalDays,
"t" => (int)span.Ticks,
_ => 0,
};
}
}
[Obsolete]
public class Waiting
{
[Obsolete]
public static async Task WaitType(int X, string Type)
{
Type = HandleTimeUnits.SwitchUnits(Type);
switch (Type)
{
case "ms":
await WaitMilliseconds(X);
break;
case "s":
await WaitSeconds(X);
break;
case "m":
await WaitMinutes(X);
break;
case "h":
await WaitHours(X);
break;
case "d":
await WaitDays(X);
break;
case "t":
await WaitTicks(X);
break;
}
}
[Obsolete]
public static void WaitTypeSync(int X, string Type)
{
Type = HandleTimeUnits.SwitchUnits(Type);
switch (Type)
{
case "ms":
Thread.Sleep(X);
break;
case "s":
Thread.Sleep(X * 1000);
break;
case "m":
Thread.Sleep(X * 60 * 1000);
break;
case "h":
Thread.Sleep(X * 60 * 60 * 1000);
break;
case "d":
Thread.Sleep(X * 24 * 60 * 60 * 1000);
break;
case "t":
Thread.Sleep((int)((long)X / 10000L));
break;
}
}
[Obsolete]
public static async Task WaitMilliseconds(int waitingTime)
{
await Task.Delay(TimeSpan.FromMilliseconds(waitingTime));
}
[Obsolete]
public static async Task WaitSeconds(int waitingTime)
{
await Task.Delay(TimeSpan.FromSeconds(waitingTime));
}
[Obsolete]
public static async Task WaitMinutes(int waitingTime)
{
await Task.Delay(TimeSpan.FromMinutes(waitingTime));
}
[Obsolete]
public static async Task WaitHours(int waitingTime)
{
await Task.Delay(TimeSpan.FromHours(waitingTime));
}
[Obsolete]
public static async Task WaitDays(int waitingTime)
{
await Task.Delay(TimeSpan.FromDays(waitingTime));
}
[Obsolete]
public static async Task WaitTicks(int waitingTime)
{
await Task.Delay(TimeSpan.FromTicks(waitingTime));
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}