Decompiled source of Framerate compensator v1.0.0

framerate_compensator.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("your_name")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Sample BepInEx plugin template for H3VR!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("framerate_compensator")]
[assembly: AssemblyTitle("BepInEx Plugin Title")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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;
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace plugin
{
	[BepInPlugin("Aiyke.Framerate_compensator", "Framerate compensator", "1.0.0")]
	[BepInProcess("h3vr.exe")]
	public class framerate_compensator : BaseUnityPlugin
	{
		private static float framerate = 90f;

		private static float framerate_prev = 90f;

		private static float factor = 1f;

		private static float print_timer = 0f;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogMessage((object)"framerate_compensator is active");
			Logger.LogDebug((object)"framerate_compensator is active");
			Harmony.CreateAndPatchAll(typeof(framerate_compensator), (string)null);
		}

		private void Update()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			framerate = (framerate_prev + 1f / Time.unscaledDeltaTime) / 2f;
			factor = Mathf.Pow((90f - framerate) / 90f, 4f) * 8f;
			if (factor > 1.5f)
			{
				factor = 1.5f;
			}
			if (factor < 1f)
			{
				factor = 1f;
			}
			print_timer += Time.deltaTime;
			if (print_timer >= 1f)
			{
				Logger.LogDebug((object)("framerate = " + framerate));
				Logger.LogDebug((object)("compensation factor = " + factor));
				print_timer = 0f;
			}
			framerate_prev = framerate;
		}

		[HarmonyPatch(typeof(HandgunSlide), "UpdateSlide")]
		[HarmonyPrefix]
		private static void UpdateSlide_prefix(HandgunSlide __instance)
		{
			__instance.SpringStiffness *= factor;
		}

		[HarmonyPatch(typeof(HandgunSlide), "UpdateSlide")]
		[HarmonyPostfix]
		private static void UpdateSlide_postfix(HandgunSlide __instance)
		{
			__instance.SpringStiffness /= factor;
		}

		[HarmonyPatch(typeof(ClosedBolt), "UpdateBolt")]
		[HarmonyPrefix]
		private static void UpdateClosedBolt_prefix(ClosedBolt __instance)
		{
			__instance.SpringStiffness *= factor;
		}

		[HarmonyPatch(typeof(ClosedBolt), "UpdateBolt")]
		[HarmonyPostfix]
		private static void UpdateClosedBolt_postfix(ClosedBolt __instance)
		{
			__instance.SpringStiffness /= factor;
		}

		[HarmonyPatch(typeof(OpenBoltReceiverBolt), "UpdateBolt")]
		[HarmonyPrefix]
		private static void UpdateSlide_prefix(OpenBoltReceiverBolt __instance)
		{
			__instance.BoltSpringStiffness *= factor;
		}

		[HarmonyPatch(typeof(OpenBoltReceiverBolt), "UpdateBolt")]
		[HarmonyPostfix]
		private static void UpdateSlide_postfix(OpenBoltReceiverBolt __instance)
		{
			__instance.BoltSpringStiffness /= factor;
		}
	}
}