Decompiled source of ViewbobFix v1.2.0

LCViewbob.dll

Decompiled a year ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LCViewbob")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCViewbob")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a607b541-19ef-4d5e-a9a0-4907a90c9f2e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCViewbob
{
	[BepInPlugin("snet0.lcviewbobfix", "Viewbob Fix", "1.1")]
	internal class LCViewbobFix : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		public const string pluginGuid = "snet0.lcviewbobfix";

		public const string pluginName = "Viewbob Fix";

		public const string pluginVersion = "1.1";

		private static Harmony _harmony = new Harmony("snet0.lcviewbobfix");

		public void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
		}
	}
}
namespace LCViewbob.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB), "SpawnPlayerAnimation")]
	internal class AnimPatch
	{
		private static AnimationClip walkClip;

		private static AnimationClip sprintClip;

		private static AnimationClip crouchWalkClip;

		private static AnimationClip walkSidewaysClip;

		private static AnimationClip walkTiredClip;

		private static AssetBundle animBundle;

		private static void Postfix()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			if ((Object)(object)animBundle == (Object)null)
			{
				animBundle = AssetBundle.LoadFromFile(Path.Combine(Paths.PluginPath, "ViewbobAnimationPatch"));
				if ((Object)(object)animBundle == (Object)null)
				{
					LCViewbobFix.Log.LogError((object)"Failed to load AssetBundle");
					return;
				}
				walkClip = (AnimationClip)animBundle.LoadAsset("WalkNoBob");
				sprintClip = (AnimationClip)animBundle.LoadAsset("SprintNoBob");
				crouchWalkClip = (AnimationClip)animBundle.LoadAsset("CrouchWalkNoBob");
				walkSidewaysClip = (AnimationClip)animBundle.LoadAsset("WalkSidewaysNoBob");
				walkTiredClip = (AnimationClip)animBundle.LoadAsset("WalkTiredNoBob");
				LCViewbobFix.Log.LogInfo((object)"Loaded animation clips");
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null)
			{
				LCViewbobFix.Log.LogError((object)"playerController is null");
				return;
			}
			Animator componentInChildren = ((Component)localPlayerController).GetComponentInChildren<Animator>();
			if ((Object)(object)componentInChildren == (Object)null || ((Object)componentInChildren).name != "metarig")
			{
				LCViewbobFix.Log.LogDebug((object)"animator is not metarig, skipping");
				return;
			}
			LCViewbobFix.Log.LogInfo((object)("Found animator: " + ((Object)componentInChildren).name + ". Patching animations"));
			AnimatorOverrideController val = new AnimatorOverrideController(componentInChildren.runtimeAnimatorController);
			val["Walk"] = walkClip;
			val["Sprint"] = sprintClip;
			val["CrouchWalk"] = crouchWalkClip;
			val["WalkSideways"] = walkSidewaysClip;
			val["WalkTired"] = walkTiredClip;
			componentInChildren.runtimeAnimatorController = (RuntimeAnimatorController)(object)val;
		}
	}
}