Decompiled source of BetterSprint v2.0.0

BetterSprint.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Linq;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Autodesk.Fbx")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("FbxBuildTestAssets")]
[assembly: IgnoresAccessChecksTo("Klattersynth")]
[assembly: IgnoresAccessChecksTo("Photon3Unity3D")]
[assembly: IgnoresAccessChecksTo("PhotonChat")]
[assembly: IgnoresAccessChecksTo("PhotonRealtime")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking.Utilities")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.API")]
[assembly: IgnoresAccessChecksTo("PhotonVoice")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.PUN")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime.Public")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Utilities")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Formats.Fbx.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Postprocessing.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Antlr3.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Core")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Flow")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.State")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("websocket-sharp")]
[assembly: AssemblyCompany("BetterSprint")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Better Sprint Plugin")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0")]
[assembly: AssemblyProduct("BetterSprint")]
[assembly: AssemblyTitle("BetterSprint")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.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;
		}
	}
}
public class BetterSprintManager : MonoBehaviour
{
	private ManualLogSource logger = null;

	private string currentLevelName = "";

	private string lastUpgradeLevel = "Not Set";

	private string[] blacklistedLevelNames = new string[4] { "", "Main Menu", "Level - Lobby Menu", "Lobby Menu" };

	public void Awake()
	{
		logger = Plugin.logger;
		logger.LogInfo((object)"BetterSprintManager Awake() called.");
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		logger.LogInfo((object)"Starting initialization sequence");
	}

	private void Update()
	{
		try
		{
			CheckLevel();
			if (IsValidLevel() && lastUpgradeLevel != currentLevelName)
			{
				ApplyPlayerUpgrades();
			}
		}
		catch (Exception arg)
		{
			logger.LogError((object)$"Error checking level: {arg}");
		}
	}

	private bool IsValidLevel()
	{
		return !blacklistedLevelNames.Contains<string>(currentLevelName, StringComparer.OrdinalIgnoreCase);
	}

	private void CheckLevel()
	{
		LevelGenerator instance = LevelGenerator.Instance;
		if (!((Object)(object)instance == (Object)null) && instance.Generated)
		{
			string value = instance.Level?.NarrativeName ?? "";
			if (blacklistedLevelNames.Contains<string>(value, StringComparer.OrdinalIgnoreCase))
			{
				currentLevelName = "";
				lastUpgradeLevel = "Not Set";
			}
			else
			{
				currentLevelName = value;
			}
		}
	}

	private void ApplyPlayerUpgrades()
	{
		try
		{
			if ((Object)(object)PlayerController.instance != (Object)null)
			{
				PlayerController instance = PlayerController.instance;
				AccessTools.Field(typeof(PlayerController), "sprintRechargeTime").SetValue(instance, Plugin.SprintRechargeTime.Value);
				AccessTools.Field(typeof(PlayerController), "sprintRechargeAmount").SetValue(instance, Plugin.SprintRechargeAmount.Value);
				logger.LogInfo((object)"Applied sprint enhancements");
				lastUpgradeLevel = currentLevelName;
			}
		}
		catch (Exception arg)
		{
			logger.LogError((object)$"Failed to apply player upgrades: {arg}");
		}
	}
}
[BepInPlugin("com.example.bettersprint", "BetterSprint", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static ManualLogSource logger;

	public static ConfigEntry<float> SprintRechargeTime;

	public static ConfigEntry<float> SprintRechargeAmount;

	private void Awake()
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Expected O, but got Unknown
		logger = ((BaseUnityPlugin)this).Logger;
		logger.LogInfo((object)"[Plugin] Awake");
		SprintRechargeTime = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SprintRechargeTime", 0.1f, "Time it takes for sprint to begin recharging.");
		SprintRechargeAmount = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SprintRechargeAmount", 6f, "Amount of sprint restored per tick.");
		GameObject val = new GameObject("BetterSprint");
		((Object)val).hideFlags = (HideFlags)61;
		BetterSprintManager betterSprintManager = val.AddComponent<BetterSprintManager>();
		if ((Object)(object)betterSprintManager == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"[Plugin] Failed to add BetterSprintManager component");
			return;
		}
		val.SetActive(true);
		Object.DontDestroyOnLoad((Object)(object)val);
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"Plugin Better Sprint is loaded with recharge time {SprintRechargeTime.Value} and amount {SprintRechargeAmount.Value}");
	}
}
namespace BetterSprint
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BetterSprint";

		public const string PLUGIN_NAME = "BetterSprint";

		public const string PLUGIN_VERSION = "2.0.0";
	}
}