using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ButFaster.objects;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using REPOLib.Modules;
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("NBFBs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0")]
[assembly: AssemblyProduct("ButFaster")]
[assembly: AssemblyTitle("ButFaster")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
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 ButFaster
{
internal static class ConfigManager
{
public enum Mode
{
OnNextLevel,
WithTime,
Both
}
private static ConfigFile config;
public static ConfigEntry<Mode> mode;
public static ConfigEntry<float> initSpeed;
public static ConfigEntry<float> speedPerMinute;
public static ConfigEntry<float> speedPerLevel;
public static void Init(ConfigFile _config)
{
config = _config;
BindConfigs();
}
private static void BindConfigs()
{
mode = config.Bind<Mode>("General", "Mode", Mode.Both, "How the game is sped up\nWithTime speeds the game up by 1x (default) every 5 minutes.\nOnNextLevel will add 0.5 (default) to the speed multiplier when the next level is loaded (after you shop).\nBoth does... both.");
initSpeed = config.Bind<float>("General", "InitialSpeed", 1f, "How fast the game runs at the very start");
speedPerMinute = config.Bind<float>("General", "SpeedPerMinute", 0.2f, "How much to increase the speed every minute (if Mode = WithTime or Both)");
speedPerLevel = config.Bind<float>("General", "SpeedPerLevel", 1f, "How much to increase the speed every level (if Mode = OnNextLevel or Both)");
}
}
[BepInPlugin("NBFBs.ButFaster", "ButFaster", "0.2.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
internal static Plugin Instance { get; private set; }
internal static ManualLogSource Logger => Instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; set; }
private void Awake()
{
Instance = this;
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
Patch();
Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
ConfigManager.Init(((BaseUnityPlugin)this).Config);
}
private void Start()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
SpeedManager speedManager = new GameObject().AddComponent<SpeedManager>();
}
internal void Patch()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
//IL_0025: Expected O, but got Unknown
if (Harmony == null)
{
Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
Harmony val2 = val;
Harmony = val;
}
Harmony.PatchAll();
}
internal void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
}
namespace ButFaster.patches
{
[HarmonyPatch]
internal static class GameDetection
{
[HarmonyPrefix]
[HarmonyPatch(typeof(RunManager), "ChangeLevel")]
private static void ChangeLevel_Prefix(RunManager __instance, bool _completedLevel, bool _levelFailed, ChangeLevelType _changeLevelType)
{
if (SemiFunc.IsMasterClientOrSingleplayer() && !__instance.restarting && (_levelFailed || _completedLevel))
{
SpeedManager.Instance.EndRound();
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(RunManager), "SetRunLevel")]
private static void SetRunLevel_Postfix()
{
if (SemiFunc.IsMasterClientOrSingleplayer())
{
SpeedManager.Instance.StartRound();
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(RunManager), "LeaveToMainMenu")]
private static IEnumerator LeaveToMainMenu_Prefix(IEnumerator __result)
{
SpeedManager.Instance.EndGame();
while (__result.MoveNext())
{
yield return __result.Current;
}
}
}
}
namespace ButFaster.objects
{
public class SpeedManager : MonoBehaviour
{
private bool roundIsOn;
private static NetworkedEvent speedEvent;
private Coroutine speedUpCoroutine;
public static SpeedManager Instance { get; private set; }
private void Awake()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
Instance = this;
speedEvent = new NetworkedEvent("Speed Event", (Action<EventData>)HandleSpeedEvent);
}
public void StartRound()
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
if (SemiFunc.IsMasterClientOrSingleplayer() && !roundIsOn)
{
roundIsOn = true;
Plugin.Logger.LogDebug((object)"Round started!");
if (RunManager.instance.levelsCompleted == 0)
{
speedEvent.RaiseEvent((object)ConfigManager.initSpeed.Value, NetworkingEvents.RaiseAll, SendOptions.SendReliable);
}
if (ConfigManager.mode.Value != ConfigManager.Mode.WithTime)
{
SpeedUpOnLevel();
}
if (ConfigManager.mode.Value != 0)
{
speedUpCoroutine = ((MonoBehaviour)this).StartCoroutine(SpeedUpOverTime());
}
}
}
public void EndRound()
{
if (SemiFunc.IsMasterClientOrSingleplayer() && roundIsOn)
{
roundIsOn = false;
Plugin.Logger.LogDebug((object)"Round ended!");
if (speedUpCoroutine != null)
{
((MonoBehaviour)this).StopCoroutine(speedUpCoroutine);
}
}
}
public void EndGame()
{
if (SemiFunc.IsMasterClientOrSingleplayer())
{
Plugin.Logger.LogDebug((object)"Round ended!");
roundIsOn = false;
}
}
private static void HandleSpeedEvent(EventData eventData)
{
float num2 = (Time.timeScale = (float)eventData.CustomData);
Plugin.Logger.LogDebug((object)$"Set speed: {num2}");
}
private void SpeedUpOnLevel()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
float num = ConfigManager.initSpeed.Value + ConfigManager.speedPerLevel.Value * (float)RunManager.instance.levelsCompleted;
speedEvent.RaiseEvent((object)num, NetworkingEvents.RaiseAll, SendOptions.SendReliable);
}
private IEnumerator SpeedUpOverTime()
{
while (true)
{
yield return (object)new WaitForSecondsRealtime(12f);
float num = Time.timeScale + ConfigManager.speedPerMinute.Value / 5f;
speedEvent.RaiseEvent((object)num, NetworkingEvents.RaiseAll, SendOptions.SendReliable);
}
}
}
}