Decompiled source of Leaf BS v1.0.1

LeafModel.dll

Decompiled 11 hours ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ModelReplacement;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("LeafModel")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LeafModel")]
[assembly: AssemblyTitle("LeafModel")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LeafModel;

[BepInPlugin("kami_nii.LeafModel", "LeafModel", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	public static ConfigEntry<string> SuitNames { get; private set; }

	public static ConfigEntry<bool> EnableForAllSuits { get; private set; }

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		SuitNames = ((BaseUnityPlugin)this).Config.Bind<string>("Suits", "Suit names", "Leaf", "Comma separated list of suit names that use the Leaf model. The bundled More Suits suit is named Leaf.");
		EnableForAllSuits = ((BaseUnityPlugin)this).Config.Bind<bool>("Suits", "Replace every suit", false, "If true, every suit uses the Leaf model (ignores the suit name list).");
		Assets.Load();
		if (EnableForAllSuits.Value)
		{
			ModelReplacementAPI.RegisterModelReplacementOverride(typeof(MRLeaf));
		}
		else
		{
			string[] array = SuitNames.Value.Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length != 0)
				{
					ModelReplacementAPI.RegisterSuitModelReplacement(text, typeof(MRLeaf));
					Log.LogInfo((object)("Registered Leaf model for suit '" + text + "'"));
				}
			}
		}
		Log.LogInfo((object)"LeafModel 1.0.1 loaded");
	}
}
public static class PluginInfo
{
	public const string GUID = "kami_nii.LeafModel";

	public const string NAME = "LeafModel";

	public const string DEFAULT_SUIT = "Leaf";

	public const string VERSION = "1.0.1";
}
public static class Assets
{
	public const string BundleName = "leafbundle";

	public static AssetBundle MainAssetBundle;

	public static void Load()
	{
		if ((Object)(object)MainAssetBundle != (Object)null)
		{
			return;
		}
		string text = "LeafModel.leafbundle";
		using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(text))
		{
			if (stream == null)
			{
				Plugin.Log.LogError((object)("Embedded asset bundle '" + text + "' not found"));
				return;
			}
			MainAssetBundle = AssetBundle.LoadFromStream(stream);
		}
		if ((Object)(object)MainAssetBundle == (Object)null)
		{
			Plugin.Log.LogError((object)"Failed to load the Leaf asset bundle");
		}
	}
}
public class MRLeaf : BodyReplacementBase
{
	private static readonly int SpeedParam = Animator.StringToHash("speed");

	private static readonly int WalkingParam = Animator.StringToHash("Walking");

	private static readonly int SprintingParam = Animator.StringToHash("Sprinting");

	private static readonly int JumpingParam = Animator.StringToHash("Jumping");

	private static readonly int FallParam = Animator.StringToHash("FallNoJump");

	private Animator wingAnimator;

	private Animator shadowWingAnimator;

	protected override GameObject LoadAssetsAndReturnModel()
	{
		return Assets.MainAssetBundle.LoadAsset<GameObject>("Leaf");
	}

	public override void LateUpdate()
	{
		((BodyReplacementBase)this).LateUpdate();
		float num = 0f;
		Animator val = (((Object)(object)((BodyReplacementBase)this).controller != (Object)null) ? ((BodyReplacementBase)this).controller.playerBodyAnimator : null);
		if ((Object)(object)val != (Object)null)
		{
			if (((BodyReplacementBase)this).controller.isSprinting || val.GetBool(SprintingParam) || val.GetBool(JumpingParam) || val.GetBool(FallParam))
			{
				num = 1.25f;
			}
			else if (val.GetBool(WalkingParam))
			{
				num = 0.45f;
			}
		}
		if ((Object)(object)wingAnimator == (Object)null && (Object)(object)base.replacementModel != (Object)null)
		{
			wingAnimator = base.replacementModel.GetComponentInChildren<Animator>();
		}
		if ((Object)(object)shadowWingAnimator == (Object)null && (Object)(object)base.replacementModelShadow != (Object)null)
		{
			shadowWingAnimator = base.replacementModelShadow.GetComponentInChildren<Animator>();
		}
		if ((Object)(object)wingAnimator != (Object)null && (Object)(object)wingAnimator.runtimeAnimatorController != (Object)null)
		{
			wingAnimator.SetFloat(SpeedParam, num);
		}
		if ((Object)(object)shadowWingAnimator != (Object)null && (Object)(object)shadowWingAnimator.runtimeAnimatorController != (Object)null)
		{
			shadowWingAnimator.SetFloat(SpeedParam, num);
		}
	}
}