using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HBMF.ModMenu;
using HarmonyLib;
using Il2Cpp;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;
using VariableSlowMotion;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Mod), "VariableSlowMotion", "1.1.0", "korbykob", null)]
[assembly: MelonGame("GexagonVR", "Hard Bullet")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("VariableSlowMotion")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("VariableSlowMotion")]
[assembly: AssemblyTitle("VariableSlowMotion")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace VariableSlowMotion;
[HarmonyPatch]
public class Mod : MelonMod
{
private static SlowMotion slowMotion;
private static TimeManager timeManager;
private static float defaultScale;
private static FMODEventWithParameterPlayer sound;
private static MelonPreferences_Entry<bool> enabled;
private static bool disabling;
public override void OnInitializeMelon()
{
enabled = MelonPreferences.CreateCategory("VariableSlowMotion").CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
Menu.CreateCategory("VARIABLE SLOW MOTION").CreateBool("ENABLE", enabled.Value, (Action<bool>)delegate(bool value)
{
enabled.Value = value;
});
}
[HarmonyPatch(typeof(TimeManager), "SwitchSlowMotionState")]
[HarmonyPrefix]
public static bool Patch()
{
if (enabled.Value)
{
if (!TimeManager._slowMoStatus)
{
if (!timeManager._isSlowMoInTransition)
{
timeManager._slowedTimeScale = 0.5f;
timeManager.EnableSlowMotion();
}
else if (!disabling && timeManager._slowedTimeScale != 0.125f)
{
TimeManager obj = timeManager;
obj._slowedTimeScale /= 2f;
timeManager._transitionTweener.ChangeEndValue(Object.op_Implicit(timeManager._slowedTimeScale), -1f, false);
sound.Play(0);
}
}
else if (!timeManager._isSlowMoInTransition)
{
timeManager.DisableSlowMotion();
disabling = true;
MelonCoroutines.Start(Done());
}
return false;
}
timeManager._slowedTimeScale = defaultScale;
return true;
}
private static IEnumerator Done()
{
yield return new WaitForDisabled();
disabling = false;
}
[HarmonyPatch(typeof(SlowMotion), "Awake")]
[HarmonyPostfix]
public static void GetScripts(SlowMotion __instance)
{
slowMotion = __instance;
timeManager = ((Component)__instance).GetComponent<TimeManager>();
defaultScale = timeManager._slowedTimeScale;
sound = ((Component)__instance).GetComponent<FMODEventWithParameterPlayer>();
}
}
[RegisterTypeInIl2Cpp]
public class WaitForDisabled : CustomYieldInstruction
{
public override bool keepWaiting => TimeManager._slowMoStatus;
public WaitForDisabled(IntPtr ptr)
: base(ptr)
{
}
public WaitForDisabled()
: base(ClassInjector.DerivedConstructorPointer<WaitForDisabled>())
{
ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this);
}
}