Decompiled source of BoykisserModelReplacement v1.0.1

BepInEx/plugins/LC_BoykisserModelReplacement.dll

Decompiled 7 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ModelReplacement;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LC_BoykisserModelReplacement")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LC_BoykisserModelReplacement")]
[assembly: AssemblyTitle("LC_BoykisserModelReplacement")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
}
namespace BoykisserModelReplacement
{
	[BepInPlugin("boykisser.modelreplacement", "Boykisser Model", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigFile config;

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

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

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

		private static void InitConfig()
		{
			enableModelForAllSuits = config.Bind<bool>("Suits to Replace Settings", "Enable Model for all Suits", false, "Enable to replace every suit with the Boykisser model.");
			enableModelAsDefault = config.Bind<bool>("Suits to Replace Settings", "Enable Model as default", true, "Enable to replace every suit that hasn't been otherwise registered.");
			suitNamesToEnableModel = config.Bind<string>("Suits to Replace Settings", "Suits to enable Model for", "Boykisser", "Enter a comma separated list of suit names. (e.g. Boykisser, Default)");
		}

		private void Awake()
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			config = ((BaseUnityPlugin)this).Config;
			InitConfig();
			Assets.PopulateAssets();
			if (enableModelForAllSuits.Value)
			{
				ModelReplacementAPI.RegisterModelReplacementOverride(typeof(BodyReplacementBoykisser));
			}
			if (enableModelAsDefault.Value)
			{
				ModelReplacementAPI.RegisterModelReplacementDefault(typeof(BodyReplacementBoykisser));
			}
			string[] array = suitNamesToEnableModel.Value.Split(',');
			foreach (string text in array)
			{
				if (!string.IsNullOrWhiteSpace(text))
				{
					ModelReplacementAPI.RegisterSuitModelReplacement(text.Trim(), typeof(BodyReplacementBoykisser));
				}
			}
			new Harmony("boykisser.modelreplacement").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Boykisser Model plugin v1.0.1 is loaded!");
		}
	}
	public static class Assets
	{
		public static AssetBundle MainAssetBundle;

		public static void PopulateAssets()
		{
			if (!((Object)(object)MainAssetBundle == (Object)null))
			{
				return;
			}
			string[] array = new string[3] { "boykisserbundle", "LC_BoykisserModelReplacement.boykisserbundle", "BoykisserModelReplacement.boykisserbundle" };
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			Debug.Log((object)"Available resources:");
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			foreach (string text in manifestResourceNames)
			{
				Debug.Log((object)("  - " + text));
			}
			manifestResourceNames = array;
			foreach (string text2 in manifestResourceNames)
			{
				try
				{
					using Stream stream = executingAssembly.GetManifestResourceStream(text2);
					if (stream != null)
					{
						MainAssetBundle = AssetBundle.LoadFromStream(stream);
						if ((Object)(object)MainAssetBundle != (Object)null)
						{
							Debug.Log((object)("AssetBundle loaded successfully from: " + text2));
							return;
						}
					}
				}
				catch (Exception ex)
				{
					Debug.LogWarning((object)("Failed to load from " + text2 + ": " + ex.Message));
				}
			}
			Debug.LogError((object)"Failed to load AssetBundle from any known resource name!");
		}
	}
	public class BodyReplacementBoykisser : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "Boykisser";
			GameObject val = Assets.MainAssetBundle.LoadAsset<GameObject>(text);
			if ((Object)(object)val == (Object)null)
			{
				ModelReplacementAPI.Instance.Logger.LogError((object)"Boykisser model not found in asset bundle!");
				return null;
			}
			return val;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}