Decompiled source of HatsuneMachine v1.0.0

doomahreal.ultrakill.HatsuneMachine/HatsuneMachine.dll

Decompiled 7 months ago
using System;
using System.Collections;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("HatsuneMachine")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HatsuneMachine")]
[assembly: AssemblyTitle("HatsuneMachine")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HatsuneMachine
{
	public static class Loader
	{
		public static AssetBundle LoadMiku()
		{
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				string name = "HatsuneMachine.miku.bundle";
				using Stream stream = executingAssembly.GetManifestResourceStream(name);
				if (stream == null)
				{
					Debug.LogError((object)"Resource 'miku.bundle' not found in embedded resources.");
					return null;
				}
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				return AssetBundle.LoadFromMemory(array);
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Error loading objector: " + ex.Message));
				return null;
			}
		}
	}
	[BepInPlugin("doomahreal.ultrakill.HatsuneMachine", "HatsuneMachine", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private AssetBundle MikuBundle;

		public static AudioClip smallhurt;

		public static GameObject bighurt;

		public static GameObject hair;

		public static GameObject leek;

		public static Texture2D body;

		public static Texture2D Angrybody;

		public static Texture2D Angryhair;

		public static Texture2D Calmhair;

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			Instance = this;
			MikuBundle = Loader.LoadMiku();
			bighurt = MikuBundle.LoadAsset<GameObject>("assets/scenes/miku/actual miku/bigpainaudio.prefab");
			body = MikuBundle.LoadAsset<Texture2D>("assets/scenes/miku/actual miku/t_swordsmachine_noglowtexture.png");
			smallhurt = MikuBundle.LoadAsset<AudioClip>("assets/scenes/miku/actual miku/smallmiku.mp3");
			leek = MikuBundle.LoadAsset<GameObject>("assets/scenes/miku/actual miku/leekprefab.prefab");
			hair = MikuBundle.LoadAsset<GameObject>("assets/scenes/miku/actual miku/hairprefab.prefab");
			Calmhair = MikuBundle.LoadAsset<Texture2D>("assets/scenes/miku/actual miku/hair.png");
			Angryhair = MikuBundle.LoadAsset<Texture2D>("assets/scenes/miku/actual miku/angryhair.png");
			Angrybody = MikuBundle.LoadAsset<Texture2D>("assets/scenes/miku/actual miku/angrymiku.png");
			Harmony val = new Harmony("doomahreal.ultrakill.HatsuneMachine");
			val.PatchAll();
			Debug.Log((object)"Miku says AAAAAA-");
		}
	}
	[HarmonyPatch(typeof(ThrownSword))]
	[HarmonyPatch("Start")]
	public static class ThrownSword_Awake_Patch
	{
		private static void Postfix(ThrownSword __instance)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)__instance).transform.Find("SwordMachineSword");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
			if (!((Object)(object)component == (Object)null))
			{
				component.mesh = null;
				GameObject val2 = Object.Instantiate<GameObject>(Plugin.leek, val.position, val.rotation, val);
				Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>();
				List<Material> list = new List<Material>();
				Renderer[] array = componentsInChildren;
				foreach (Renderer val3 in array)
				{
					list.AddRange(val3.materials);
				}
				Material[] materials = list.ToArray();
				SwordsMachine_Awake_Patch.LoadShaderAndApply(materials);
			}
		}
	}
	[HarmonyPatch(typeof(SwordsMachine))]
	[HarmonyPatch("Update")]
	public static class SwordsMachine_UnEnrage_Patch
	{
		private static bool prevEnragedState;

		private static void Postfix(SwordsMachine __instance)
		{
			if (__instance.enraged == prevEnragedState)
			{
				return;
			}
			prevEnragedState = __instance.enraged;
			Transform val = ((Component)__instance).transform.Find("Swordsmachine_New/Armature/Control/Waist/Chest/Head/Head_end/hairprefab(Clone)");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)"Hair object not found.");
				return;
			}
			Renderer component = ((Component)val).GetComponent<Renderer>();
			if ((Object)(object)component == (Object)null)
			{
				Debug.LogError((object)"Renderer not found on hair object.");
				return;
			}
			Material material = component.material;
			if ((Object)(object)material == (Object)null)
			{
				Debug.LogError((object)"Material not found on hair object.");
			}
			else
			{
				material.mainTexture = (Texture)(object)(__instance.enraged ? Plugin.Angryhair : Plugin.Calmhair);
			}
		}
	}
	[HarmonyPatch(typeof(SwordsMachine))]
	[HarmonyPatch("Awake")]
	public static class SwordsMachine_Awake_Patch
	{
		private static void Postfix(SwordsMachine __instance)
		{
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			__instance.bigPainSound = Plugin.bighurt;
			((MonoBehaviour)Plugin.Instance).StartCoroutine(WaitForMaterial(__instance));
			Machine component = ((Component)__instance).GetComponent<Machine>();
			component.hurtSounds = (AudioClip[])(object)new AudioClip[1];
			component.hurtSounds[0] = Plugin.smallhurt;
			SkinnedMeshRenderer swordMR = __instance.swordMR;
			swordMR.sharedMesh = null;
			GameObject val = Object.Instantiate<GameObject>(Plugin.hair, ((Component)__instance).transform);
			GameObject val2 = Object.Instantiate<GameObject>(Plugin.leek, ((Component)__instance).transform);
			Transform val3 = ((Component)__instance).transform.Find("Swordsmachine_New/Armature/Control/Waist/Chest/Head/Head_end");
			if ((Object)(object)val3 != (Object)null)
			{
				val.transform.parent = val3;
			}
			Transform parent = ((Component)__instance).transform.Find("Swordsmachine_New/Armature/Control/Waist/Chest/UArm_L/LArm_L/Hand_L/Sword_0");
			if ((Object)(object)val3 != (Object)null)
			{
				val2.transform.parent = parent;
			}
			val.transform.localPosition = new Vector3(0f, -0.6f, 0f);
			val.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
			val.transform.localScale = new Vector3(3f, 3f, 3f);
			val2.transform.localPosition = new Vector3(0f, 0f, 0f);
			val2.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
			val2.transform.localScale = new Vector3(3f, 3f, 3f);
			Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>();
			Renderer[] componentsInChildren2 = val2.GetComponentsInChildren<Renderer>();
			List<Material> list = new List<Material>();
			List<Material> list2 = new List<Material>();
			Renderer[] array = componentsInChildren;
			foreach (Renderer val4 in array)
			{
				list.AddRange(val4.materials);
			}
			Renderer[] array2 = componentsInChildren2;
			foreach (Renderer val5 in array2)
			{
				list2.AddRange(val5.materials);
			}
			Material[] materials = list.ToArray();
			LoadShaderAndApply(materials);
			Material[] materials2 = list2.ToArray();
			LoadShaderAndApply(materials2);
		}

		private static IEnumerator WaitForMaterial(SwordsMachine instance)
		{
			Material originalMaterial = null;
			Material originalMaterial2 = null;
			while ((Object)(object)originalMaterial == (Object)null || (Object)(object)originalMaterial2 == (Object)null)
			{
				originalMaterial = instance.ensim.originalMaterial;
				originalMaterial2 = instance.ensim.enragedMaterial;
				yield return null;
			}
			originalMaterial.mainTexture = (Texture)(object)Plugin.body;
			originalMaterial2.mainTexture = (Texture)(object)Plugin.Angrybody;
		}

		public static void LoadShaderAndApply(Material[] materials)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			AsyncOperationHandle<Shader> val = Addressables.LoadAssetAsync<Shader>((object)"Assets/Shaders/Main/ULTRAKILL-unlit-emissive-nocull.shader");
			val.WaitForCompletion();
			if ((int)val.Status == 1)
			{
				Shader result = val.Result;
				foreach (Material val2 in materials)
				{
					val2.shader = result;
				}
			}
			else
			{
				AsyncOperationStatus status = val.Status;
				Debug.LogError((object)("Failed to load shader: " + ((object)(AsyncOperationStatus)(ref status)).ToString()));
			}
			Addressables.Release<Shader>(val);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "HatsuneMachine";

		public const string PLUGIN_NAME = "HatsuneMachine";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}