Decompiled source of robmodelpack v0.6.7

RobModelPack.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
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 BepInEx.Logging;
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("RobModelPack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RobModelPack")]
[assembly: AssemblyTitle("RobModelPack")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 RobModelPack
{
	public class MRTWILIGHT : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			return Assets.LoadModel("Twilight");
		}
	}
	public class MRTRIXIEMODEL : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			return Assets.LoadModel("TrixieModel");
		}
	}
	public class MRSKULLKID : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			return Assets.LoadModel("SkullKid");
		}
	}
	public class MRBURNTRAP : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			return Assets.LoadModel("SBBurntrap");
		}
	}
	public class MRMEJIROMCQUEEN : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			return Assets.LoadModel("MejiroMcQueen");
		}

		protected override void OnDeath()
		{
			((BodyReplacementBase)this).OnDeath();
			if (!((Object)(object)base.replacementDeadBody == (Object)null))
			{
				Transform transform = base.replacementDeadBody.transform;
				TriggerDeath(transform, "pfb_bdy1013_00/Position/Hip/UpBody_Ctrl/Waist/Spine/Chest/Neck/Head");
				TriggerDeath(transform, "pfb_bdy1013_00/Position/Hip");
			}
		}

		private static void TriggerDeath(Transform root, string path)
		{
			Transform val = root.Find(path);
			Animator val2 = default(Animator);
			if ((Object)(object)val != (Object)null && ((Component)val).TryGetComponent<Animator>(ref val2))
			{
				val2.SetTrigger("OnDeath");
			}
			else
			{
				Plugin.Log.LogWarning((object)("McQueen death animator not found at " + path));
			}
		}
	}
	[BepInPlugin("com.bloodytreats.robmodelpack", "robmodelpack", "0.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

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

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

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

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

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

		private void InitConfig()
		{
			twilightSuits = ((BaseUnityPlugin)this).Config.Bind<string>("Suits", "Twilight suits", "Twilight", "Comma separated suit names that turn into Twilight. Vanilla names: Default, Orange suit, Green suit, Hazard suit, Pajama suit");
			trixieSuits = ((BaseUnityPlugin)this).Config.Bind<string>("Suits", "Trixie suits", "Trixie", "Comma separated suit names that turn into Trixie.");
			mcqueenSuits = ((BaseUnityPlugin)this).Config.Bind<string>("Suits", "Mejiro McQueen suits", "Mejiro McQueen", "Comma separated suit names that turn into Mejiro McQueen.");
			burntrapSuits = ((BaseUnityPlugin)this).Config.Bind<string>("Suits", "Burntrap suits", "Burntrap", "Comma separated suit names that turn into Burntrap.");
			skullKidSuits = ((BaseUnityPlugin)this).Config.Bind<string>("Suits", "Skull Kid suits", "Skull Kid", "Comma separated suit names that turn into Skull Kid.");
		}

		private void Awake()
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			InitConfig();
			Assets.PopulateAssets();
			if (Assets.Bundles.Count == 0)
			{
				Log.LogError((object)"No asset bundles loaded; no models registered.");
				return;
			}
			Register(twilightSuits.Value, typeof(MRTWILIGHT));
			Register(trixieSuits.Value, typeof(MRTRIXIEMODEL));
			Register(mcqueenSuits.Value, typeof(MRMEJIROMCQUEEN));
			Register(burntrapSuits.Value, typeof(MRBURNTRAP));
			Register(skullKidSuits.Value, typeof(MRSKULLKID));
			new Harmony("com.bloodytreats.robmodelpack").PatchAll();
			Log.LogInfo((object)"robmodelpack loaded");
		}

		private static void Register(string suitList, Type replacement)
		{
			string[] array = suitList.Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length != 0)
				{
					ModelReplacementAPI.RegisterSuitModelReplacement(text, replacement);
					Log.LogInfo((object)(replacement.Name + " -> suit \"" + text + "\""));
				}
			}
		}
	}
	public static class Assets
	{
		public static readonly Dictionary<string, AssetBundle> Bundles = new Dictionary<string, AssetBundle>();

		private static string GetAssemblyName()
		{
			return Assembly.GetExecutingAssembly().GetName().Name.Replace(" ", "_");
		}

		public static void PopulateAssets()
		{
			if (Bundles.Count > 0)
			{
				return;
			}
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string text = GetAssemblyName() + ".";
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			foreach (string text2 in manifestResourceNames)
			{
				if (!text2.StartsWith(text) || !text2.EndsWith("bundle"))
				{
					continue;
				}
				byte[] array;
				using (Stream stream = executingAssembly.GetManifestResourceStream(text2))
				{
					using MemoryStream memoryStream = new MemoryStream();
					stream.CopyTo(memoryStream);
					array = memoryStream.ToArray();
				}
				AssetBundle val = AssetBundle.LoadFromMemory(array);
				if ((Object)(object)val == (Object)null)
				{
					Plugin.Log.LogError((object)("Failed to load embedded bundle " + text2 + ". Is another mod loading the same bundle?"));
					continue;
				}
				string text3 = text2.Substring(text.Length);
				Bundles[text3] = val;
				string[] allAssetNames = val.GetAllAssetNames();
				foreach (string text4 in allAssetNames)
				{
					Plugin.Log.LogInfo((object)(text3 + " contains: " + text4));
				}
			}
		}

		public static GameObject LoadModel(string prefabName)
		{
			foreach (AssetBundle value in Bundles.Values)
			{
				if (value.Contains(prefabName))
				{
					return value.LoadAsset<GameObject>(prefabName);
				}
			}
			Plugin.Log.LogError((object)("Prefab \"" + prefabName + "\" not found in any bundle. Check the \"contains:\" lines above."));
			return null;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}