Decompiled source of CyklopciaHead v1.0.0

plugins/CyklopciaHead/CyklopciaHead.dll

Decompiled 2 months 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.Logging;
using CyklopciaHead.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Autodesk.Fbx")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("FbxBuildTestAssets")]
[assembly: IgnoresAccessChecksTo("Klattersynth")]
[assembly: IgnoresAccessChecksTo("Photon3Unity3D")]
[assembly: IgnoresAccessChecksTo("PhotonChat")]
[assembly: IgnoresAccessChecksTo("PhotonRealtime")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking.Utilities")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.API")]
[assembly: IgnoresAccessChecksTo("PhotonVoice")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.PUN")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime.Public")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Utilities")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Formats.Fbx.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Postprocessing.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Antlr3.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Core")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Flow")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.State")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("websocket-sharp")]
[assembly: AssemblyCompany("CyklopciaHead")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Headman in cyklopcia style.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CyklopciaHead")]
[assembly: AssemblyTitle("CyklopciaHead")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
	[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 CyklopciaHead
{
	[BepInPlugin("CyklopciaHead", "CyklopciaHead", "1.0.0")]
	public class CyklopciaHead : BaseUnityPlugin
	{
		public static AssetBundle CyklopciaBundle;

		public static CyklopciaHead Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty;
			CyklopciaBundle = AssetBundle.LoadFromFile(Path.Combine(path, "cyklopcia_headman"));
			if ((Object)(object)CyklopciaBundle == (Object)null)
			{
				Logger.LogError((object)"Failed to load \"cyklopcia_headman\" asset bundle");
				return;
			}
			Patch();
			Logger.LogInfo((object)"CyklopciaHead v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("CyklopciaHead");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.CreateAndPatchAll(typeof(HeadModel), (string)null);
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CyklopciaHead";

		public const string PLUGIN_NAME = "CyklopciaHead";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace CyklopciaHead.Patches
{
	public class HeadModel
	{
		[HarmonyPatch(typeof(EnemyHeadController), "Awake")]
		[HarmonyPostfix]
		private static void ChangeModel(EnemyHeadController __instance)
		{
			CyklopciaHead.Logger.LogDebug((object)"Debug mode");
			CyklopciaHead.Logger.LogDebug((object)"Patching Head...");
			EnemyParent[] componentsInParent = ((Component)__instance).GetComponentsInParent<EnemyParent>();
			EnemyParent[] array = componentsInParent;
			foreach (EnemyParent val in array)
			{
				GameObject gameObject = ((Component)val).gameObject;
				Component[] componentsInChildren = gameObject.GetComponentsInChildren<Component>();
				Component[] array2 = componentsInChildren;
				foreach (Component val2 in array2)
				{
					MeshRenderer[] componentsInChildren2 = val2.GetComponentsInChildren<MeshRenderer>();
					MeshRenderer[] array3 = componentsInChildren2;
					foreach (MeshRenderer val3 in array3)
					{
						switch (((Object)val3).name)
						{
						case "Head Top":
						case "Head Bot":
						case "Ears":
							ChangeTexture((Renderer)(object)val3, "assets/cyklopciaheadman/new_uv.png");
							break;
						case "Eye Sockets":
							ChangeTexture((Renderer)(object)val3, "assets/cyklopciaheadman/new_headman eye sockets.png");
							break;
						}
					}
				}
			}
			CyklopciaHead.Logger.LogInfo((object)"Head got Cyklopcied!");
		}

		private static void ChangeTexture(Renderer renderer, string path)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			CyklopciaHead.Logger.LogDebug((object)"\t\t Changing texture...");
			CyklopciaHead.Logger.LogDebug((object)$"\t\t changing mesh -> name: {((Object)renderer).name} type: {((object)renderer).GetType()}");
			Texture2D val = CyklopciaHead.CyklopciaBundle.LoadAsset<Texture2D>(path);
			if ((Object)(object)val == (Object)null)
			{
				CyklopciaHead.Logger.LogError((object)"\t\t !!!!!!!!!!!!!!!!!!!!!Texture loading failed!!!!!!!!!!!!!!!!!!!!!!!");
				throw new NullReferenceException("Texture loading failed!");
			}
			Material val2 = new Material(renderer.sharedMaterial);
			val2.SetTexture("_AlbedoTexture", (Texture)(object)val);
			renderer.sharedMaterial = val2;
			CyklopciaHead.Logger.LogDebug((object)"\t\t Shader with new texture applied!!!");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}