using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TimerExtensions")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TimerExtensions")]
[assembly: AssemblyTitle("TimerExtensions")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.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;
}
}
[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;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class ExtensionMarkerAttribute : Attribute
{
public ExtensionMarkerAttribute(string name)
{
}
}
}
namespace TimerExtensions
{
public static class HarmonyHelpers
{
[SpecialName]
public sealed class <G>$6C7DE3593F499BD1D1FE1E0A0EDB9649
{
[SpecialName]
public static class <M>$DF98B1A0DF566D1B44D13273A7DDC79E
{
}
[ExtensionMarker("<M>$DF98B1A0DF566D1B44D13273A7DDC79E")]
public CodeMatcher RemoveInstructions(params CodeMatch[] matches)
{
throw null;
}
}
public static CodeMatcher RemoveInstructions(this CodeMatcher matcher, params CodeMatch[] matches)
{
matcher.MatchForward(false, matches).ThrowIfInvalid("Failed to find the match");
Plugin.Logger.LogInfo((object)$"inst: {matcher.Instruction}");
matcher.RemoveInstructions(matches.Length);
return matcher;
}
}
[HarmonyPatch(typeof(LevelStats))]
public static class LevelStatsPatcher
{
public static float offset;
[HarmonyTranspiler]
[HarmonyDebug]
[HarmonyPatch("CheckStats")]
private static IEnumerable<CodeInstruction> CheckStatsTranspiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Expected O, but got Unknown
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Expected O, but got Unknown
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Expected O, but got Unknown
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Expected O, but got Unknown
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Expected O, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Expected O, but got Unknown
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.RemoveInstructions(new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldflda, (object)AccessTools.Field(typeof(LevelStats), "minutes"), (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(float), "ToString", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Ldstr, (object)":", (string)null), new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldflda, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldstr, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null)).SearchForward((Func<CodeInstruction, bool>)((CodeInstruction ci) => ci.opcode == OpCodes.Callvirt && ci.operand is MethodInfo methodInfo && methodInfo.Name == "set_text")).ThrowIfInvalid("Could not find set_text property call")
.Insert((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)(Expression<Func<string>>)(() => GetTimeString())) });
return val.InstructionEnumeration();
}
private static string GetTimeString()
{
float seconds = MonoSingleton<StatsManager>.Instance.seconds;
float seconds2 = seconds - offset;
return "<color=#26e045>" + GetTimeString(seconds2) + "</color>\r\n" + GetTimeString(seconds);
}
private static string GetTimeString(float seconds)
{
return $"{seconds / 60f:N0}:{seconds % 60f:00.000}";
}
}
[BepInPlugin("com.10-days-till-xmas.timerextensions", "TimerExtensions", "1.0.0")]
public sealed class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger { get; private set; }
private void Awake()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin com.10-days-till-xmas.timerextensions is loaded!");
((Object)((Component)this).gameObject).hideFlags = (HideFlags)4;
Harmony val = new Harmony("com.10-days-till-xmas.timerextensions");
val.PatchAll(typeof(StatsManagerPatcher));
val.PatchAll(typeof(LevelStatsPatcher));
}
}
[HarmonyPatch(typeof(StatsManager))]
public static class StatsManagerPatcher
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
private static void StatsManagerAwakePostfix(StatsManager __instance)
{
StatsManager.checkpointRestart += OnCheckpointAction;
}
private static void OnCheckpointAction()
{
LevelStatsPatcher.offset = MonoSingleton<StatsManager>.Instance.seconds;
}
}
internal static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.10-days-till-xmas.timerextensions";
public const string PLUGIN_NAME = "TimerExtensions";
public const string PLUGIN_VERSION = "1.0.0";
}
}