Decompiled source of CodyHeadCosmetic v1.2.0

CodyHead.dll

Decompiled 7 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 CodyHead.Cosmetics;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MoreCompany.Cosmetics;
using MoreCompany.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("EliteMasterEric")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("New interesting cosmetics for Lethal Company")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("WackyCosmetics")]
[assembly: AssemblyTitle("WackyCosmetics")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CodyHead
{
	public static class PluginInfo
	{
		public const string PLUGIN_ID = "CodyHead";

		public const string PLUGIN_NAME = "A Cosmetic that is just my head lmao";

		public const string PLUGIN_VERSION = "1.0.0";

		public const string PLUGIN_GUID = "com.decodinator.codyhead";
	}
	[BepInPlugin("com.decodinator.codyhead", "A Cosmetic that is just my head lmao", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public ManualLogSource PluginLogger;

		public PluginConfig PluginConfig;

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			Instance = this;
			PluginLogger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("com.decodinator.codyhead");
			val.PatchAll();
			PluginLogger.LogInfo((object)"Plugin A Cosmetic that is just my head lmao (com.decodinator.codyhead) is loaded!");
			LoadConfig();
			LoadCosmetics();
		}

		private void LoadConfig()
		{
			PluginConfig = new PluginConfig();
			PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
		}

		private void LoadCosmetics()
		{
			CodyHeadCosmeticGeneric.LoadCosmeticsFromThisAssembly();
		}
	}
	internal class PluginAssets
	{
		public static AssetBundle LoadBundleFromThisAssembly(string filename)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			if (executingAssembly == null)
			{
				Plugin.Instance.PluginLogger.LogError((object)("Failed to get assembly reference while loading bundle: " + filename));
				return null;
			}
			return BundleUtilities.LoadBundleFromInternalAssembly(filename, executingAssembly);
		}

		public static string[] ListEmbeddedResourcesInThisAssembly()
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			if (executingAssembly == null)
			{
				Plugin.Instance.PluginLogger.LogError((object)"Failed to get assembly reference while listing embedded resources.");
				return null;
			}
			return executingAssembly.GetManifestResourceNames();
		}
	}
	public class PluginConfig
	{
		public Dictionary<string, ConfigEntry<bool>> CosmeticConfigEntries;

		public PluginConfig()
		{
			CosmeticConfigEntries = new Dictionary<string, ConfigEntry<bool>>();
		}

		public void BindConfig(ConfigFile config)
		{
			CodyHeadCosmeticGeneric.GenerateCosmeticConfigEntries(config);
		}

		internal void GenerateCosmeticConfigEntry(ConfigFile config, CodyHeadCosmeticGeneric cosmetic)
		{
			ConfigEntry<bool> value = config.Bind<bool>("Cosmetics", "EnableCosmetic_" + ((CosmeticGeneric)cosmetic).cosmeticId, true, "Enable the " + cosmetic.cosmeticName + " cosmetic.");
			CosmeticConfigEntries.Add(((CosmeticGeneric)cosmetic).cosmeticId, value);
		}

		public bool IsCosmeticEnabled(CodyHeadCosmeticGeneric cosmetic)
		{
			return CosmeticConfigEntries[((CosmeticGeneric)cosmetic).cosmeticId].Value;
		}
	}
}
namespace CodyHead.Cosmetics
{
	public class CodyHeadCosmeticGeneric : CosmeticGeneric
	{
		public virtual string cosmeticName { get; }

		public virtual string assetBundlePath { get; }

		public AssetBundle assetBundle { get; private set; }

		public void LoadFromAssetBundle()
		{
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Instance.PluginConfig.IsCosmeticEnabled(this))
			{
				Plugin.Instance.PluginLogger.LogInfo((object)("Skipped the cody head cosmetic: " + ((CosmeticGeneric)this).cosmeticId + ":("));
				return;
			}
			assetBundle = PluginAssets.LoadBundleFromThisAssembly(assetBundlePath);
			if ((Object)(object)assetBundle == (Object)null)
			{
				Plugin.Instance.PluginLogger.LogError((object)("Failed to load cosmetic asset bundle: " + assetBundlePath));
				return;
			}
			GameObject val = AssetBundleExtension.LoadPersistentAsset<GameObject>(assetBundle, ((CosmeticGeneric)this).gameObjectPath);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Instance.PluginLogger.LogError((object)("Failed to load cosmetic prefab: " + ((CosmeticGeneric)this).gameObjectPath));
				return;
			}
			Texture2D val2 = AssetBundleExtension.LoadPersistentAsset<Texture2D>(assetBundle, ((CosmeticGeneric)this).textureIconPath);
			if ((Object)(object)val2 == (Object)null)
			{
				Plugin.Instance.PluginLogger.LogError((object)("Failed to load cosmetic icon: " + ((CosmeticGeneric)this).textureIconPath));
				return;
			}
			CosmeticInstance val3 = val.AddComponent<CosmeticInstance>();
			val3.cosmeticId = ((CosmeticGeneric)this).cosmeticId;
			val3.icon = val2;
			val3.cosmeticType = ((CosmeticGeneric)this).cosmeticType;
			CosmeticRegistry.cosmeticInstances.Add(((CosmeticGeneric)this).cosmeticId, val3);
			Plugin.Instance.PluginLogger.LogInfo((object)("Loaded the cody head cosmetic: " + ((CosmeticGeneric)this).cosmeticId + ":)"));
		}

		public static void GenerateCosmeticConfigEntries(ConfigFile config)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			if (executingAssembly == null)
			{
				Plugin.Instance.PluginLogger.LogError((object)"Failed to get assembly reference while generating config entries.");
				return;
			}
			Plugin.Instance.PluginLogger.LogInfo((object)"Generating config entries for cody head cosmetic (this is unneeded but i don't feel like removing it right now lmfao");
			Type[] types = executingAssembly.GetTypes();
			foreach (Type type in types)
			{
				if (!(type == null) && type.IsSubclassOf(typeof(CodyHeadCosmeticGeneric)))
				{
					CodyHeadCosmeticGeneric cosmetic = (CodyHeadCosmeticGeneric)Activator.CreateInstance(type);
					Plugin.Instance.PluginConfig.GenerateCosmeticConfigEntry(config, cosmetic);
				}
			}
		}

		public static void LoadCosmeticsFromThisAssembly()
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			if (executingAssembly == null)
			{
				Plugin.Instance.PluginLogger.LogError((object)"Failed to get assembly reference while loading cosmetics.");
				return;
			}
			Plugin.Instance.PluginLogger.LogInfo((object)"Loading the cody head cosmetic.");
			Type[] types = executingAssembly.GetTypes();
			foreach (Type type in types)
			{
				if (!(type == null) && type.IsSubclassOf(typeof(CodyHeadCosmeticGeneric)))
				{
					CodyHeadCosmeticGeneric codyHeadCosmeticGeneric = (CodyHeadCosmeticGeneric)Activator.CreateInstance(type);
					codyHeadCosmeticGeneric.LoadFromAssetBundle();
				}
			}
		}
	}
}
namespace WackyCosmetics.Cosmetics
{
	public class CODY : CodyHeadCosmeticGeneric
	{
		public override string gameObjectPath => "assets/decodinator/cody_head/CODY.prefab";

		public override string cosmeticId => "decodinator.cody";

		public override string textureIconPath => "assets/decodinator/cody_head/Cody_Icon.png";

		public override string cosmeticName => "Cody Head";

		public override string assetBundlePath => "cosmetic_codyhead";

		public override CosmeticType cosmeticType => (CosmeticType)0;
	}
	public class CODY2 : CodyHeadCosmeticGeneric
	{
		public override string gameObjectPath => "assets/decodinator/cody_head/CODY_2.prefab";

		public override string cosmeticId => "decodinator.cody2";

		public override string textureIconPath => "assets/decodinator/cody_head/Cody_Icon_2.png";

		public override string cosmeticName => "Cody Head Alt";

		public override string assetBundlePath => "cosmetic_codyhead_2";

		public override CosmeticType cosmeticType => (CosmeticType)0;
	}
}