using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using HarmonyLib.Tools;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("UltraTimerFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UltraTimerFix")]
[assembly: AssemblyCopyright("Licensed by MIT by beppinman12.")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("01f564ef-5371-465b-8ec5-9e143281b7be")]
[assembly: AssemblyFileVersion("1.0.4")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.4.0")]
namespace UltrakillTimerFix;
[BepInPlugin("UltrakillTimerFix", "Ultrakill Timer Fix", "1.0.4")]
public class TimerFix : BaseUnityPlugin
{
[HarmonyPatch(typeof(OnLevelStart), "StartLevel")]
public class ResetTimer
{
public static bool Prefix(bool startTimer = true, bool startMusic = true)
{
if (startTimer)
{
accumulator = 0f;
accumulatorTimestamp = 0f;
timestamp = Time.time;
timerNow = false;
}
return true;
}
}
[HarmonyPatch(typeof(StatsManager), "Update")]
public class PatchUpdateTimer
{
public static bool Prefix(StatsManager __instance, ref NewMovement ___nm)
{
if ((Input.GetKeyDown((KeyCode)114) || (!MonoSingleton<InputManager>.Instance.PerformingCheatMenuCombo() && MonoSingleton<InputManager>.Instance.InputSource.Fire1.WasPerformedThisFrame)) && ___nm.hp <= 0 && !___nm.endlessMode && !MonoSingleton<OptionsManager>.Instance.paused)
{
__instance.Restart();
}
if (__instance.timer)
{
if (accumulator > 0f && timerNow)
{
timestamp += accumulator;
}
accumulator = 0f;
accumulatorTimestamp = 0f;
__instance.seconds = Time.time - timestamp;
timerNow = true;
}
else if (accumulatorTimestamp == 0f)
{
accumulator = 0f;
accumulatorTimestamp = Time.time;
}
else
{
accumulator = Time.time - accumulatorTimestamp;
}
if (__instance.stylePoints < 0)
{
__instance.stylePoints = 0;
}
if (!__instance.endlessMode)
{
DiscordController.UpdateStyle(__instance.stylePoints);
}
return false;
}
}
[HarmonyPatch(typeof(CutsceneSkip), "LateUpdate")]
public class CutsceneFixer
{
public static bool Prefix(CutsceneSkip __instance, ref bool ___waitingForInput, ref float ___timeLeft, ref bool ___printLengthOfCutscene)
{
if (___waitingForInput && MonoSingleton<InputManager>.Instance.InputSource.Pause.WasPerformedThisFrame)
{
___waitingForInput = false;
___printLengthOfCutscene = false;
if (MonoSingleton<OptionsManager>.Instance.paused)
{
MonoSingleton<OptionsManager>.Instance.UnPause();
}
__instance.onSkip.Invoke("");
MonoSingleton<CutsceneSkipText>.Instance.Hide();
if (___timeLeft > 0f)
{
StatsManager instance = MonoSingleton<StatsManager>.Instance;
instance.seconds += ___timeLeft;
timestamp -= ___timeLeft;
MonoSingleton<WeaponCharges>.Instance.Charge(___timeLeft);
}
}
return false;
}
}
public static float timestamp;
public static float accumulator;
public static float accumulatorTimestamp;
public static bool timerNow;
private void Awake()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
HarmonyFileLog.Enabled = true;
new Harmony("UltrakillTimerFix").PatchAll();
}
}