Decompiled source of BetterFPS v0.1.0

plugins/com.github.KinTheInfinite.BetterFPS.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.Playables;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.KinTheInfinite.BetterFPS")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("com.github.KinTheInfinite.BetterFPS")]
[assembly: AssemblyTitle("BetterFPS")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.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;
		}
	}
	[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 KinsDebugTools
{
	[BepInPlugin("com.github.KinTheInfinite.BetterFPS", "BetterFPS", "0.1.0")]
	public class BetterFPS : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(CenterOfMass), "FixedUpdate")]
		private class MassPatch
		{
			private static bool Prefix(CenterOfMass __instance)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				if (__instance.onlyOnGround && (int)__instance.item.itemState != 0)
				{
					return false;
				}
				Vector3 val = ((!Object.op_Implicit((Object)(object)__instance.centerOfMassTransform)) ? __instance.localCenterOfMass : __instance.centerOfMassTransform.localPosition);
				Vector3 centerOfMass = __instance.rb.centerOfMass;
				if (!((Vector3)(ref centerOfMass)).Equals(val))
				{
					__instance.rb.centerOfMass = val;
				}
				float angularDamping = __instance.angularDamping;
				if (__instance.rb.angularDamping != __instance.angularDamping)
				{
					__instance.rb.angularDamping = __instance.angularDamping;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(CharacterRagdoll), "FixedUpdate")]
		private class RagdollPatch
		{
			private static bool Prefix(CharacterRagdoll __instance)
			{
				//IL_0180: Unknown result type (might be due to invalid IL or missing references)
				//IL_0185: Unknown result type (might be due to invalid IL or missing references)
				if (__instance.character.IsLocal || __instance.character.isScoutmaster)
				{
					return true;
				}
				float value = instance.configCharacterUpdateSpeed.Value;
				float characterDistance = GetCharacterDistance(__instance.character);
				if (characterDistance > instance.configCharacterFarDistance.Value)
				{
					value = instance.configCharacterFarUpdateSpeed.Value;
				}
				else if (characterDistance > instance.configCharacterMediumDistance.Value)
				{
					value = instance.configCharacterMediumUpdateSpeed.Value;
				}
				if (value <= 0f)
				{
					return false;
				}
				float num = 1f / value;
				if (!update_time.ContainsKey(__instance))
				{
					update_time[__instance] = 0f;
				}
				update_time[__instance] += Time.fixedDeltaTime;
				if (update_time[__instance] >= num)
				{
					update_time[__instance] -= num;
					__instance.SetPhysicsMats();
					if (__instance.firstFrame)
					{
						__instance.firstFrame = false;
					}
					else
					{
						if (Object.op_Implicit((Object)(object)__instance.character.data.currentItem))
						{
							__instance.character.refs.animations.PrepIK();
						}
						__instance.RotateCharacter();
						__instance.character.refs.ikRigBuilder.SyncLayers();
						__instance.character.refs.ikRigBuilder.Evaluate(num);
						PlayableGraph playableGraph = __instance.character.refs.animator.playableGraph;
						((PlayableGraph)(ref playableGraph)).Evaluate(num);
						__instance.character.refs.animations.ConfigureIK();
						for (int i = 0; i < __instance.partList.Count; i++)
						{
							__instance.partList[i].SaveAnimationData();
							__instance.DrawLines(__instance.partList[i].jointParent, __instance.partList[i]);
						}
						__instance.SaveAdditionalTransformPositions();
						__instance.ResetRotation();
						for (int j = 0; j < __instance.partList.Count; j++)
						{
							__instance.partList[j].ResetTransform();
						}
					}
					return false;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(WindChillZone), "AddWindForceToCharacter")]
		private class WindCharacterPatch
		{
			private static bool Prefix(PhotonView __instance, Character character, float mult = 1f)
			{
				if (character.IsLocal)
				{
					return true;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(WindChillZone), "AddWindForceToItem")]
		private class WindItemPatch
		{
			private static bool Prefix(PhotonView __instance, Item item)
			{
				return false;
			}
		}

		public static BetterFPS instance;

		public static Harmony harmony;

		private ConfigEntry<float> configCharacterUpdateSpeed;

		private ConfigEntry<float> configCharacterMediumDistance;

		private ConfigEntry<float> configCharacterMediumUpdateSpeed;

		private ConfigEntry<float> configCharacterFarDistance;

		private ConfigEntry<float> configCharacterFarUpdateSpeed;

		public static Dictionary<CharacterRagdoll, float> update_time = new Dictionary<CharacterRagdoll, float>();

		public const string Id = "com.github.KinTheInfinite.BetterFPS";

		internal static ManualLogSource Log { get; private set; } = null;


		public static string Name => "BetterFPS";

		public static string Version => "0.1.0";

		private void Awake()
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			instance = this;
			configCharacterUpdateSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CharacterUpdateSpeed", 5f, "Amount of times per second the character model updates, 60 is base game.");
			configCharacterMediumDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MediumDistance", 30f, "Medium distance update range.");
			configCharacterMediumUpdateSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MediumUpdateSpeed", 2f, "Amount of times per second the character model updates, 60 is base game.");
			configCharacterFarDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FarDistance", 60f, "Far distance update range.");
			configCharacterFarUpdateSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FarUpdateSpeed", 1f, "Amount of times per second the character model updates, 60 is base game.");
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
			harmony = new Harmony("kintheinfinite.betterfps");
			harmony.PatchAll(typeof(MassPatch));
			harmony.PatchAll(typeof(RagdollPatch));
			harmony.PatchAll(typeof(WindCharacterPatch));
			harmony.PatchAll(typeof(WindItemPatch));
		}

		public static float GetCharacterDistance(Character character)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)Camera.main).transform.position - character.Center;
			return ((Vector3)(ref val)).magnitude;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}