Decompiled source of Custom NPCs v1.1.0

Mods/CustomNPCs.dll

Decompiled 3 weeks 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 CustomNPCs;
using HBMF.GameResources;
using HBMF.ModMenu;
using HarmonyLib;
using Il2Cpp;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.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: MelonInfo(typeof(Mod), "CustomNPCs", "1.1.0", "notnotnotswipez", null)]
[assembly: MelonGame("GexagonVR", "Hard Bullet")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CustomNPCs")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CustomNPCs")]
[assembly: AssemblyTitle("CustomNPCs")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomNPCs;

[HarmonyPatch]
public class Mod : MelonMod
{
	internal static MelonPreferences_Entry<bool> enabled;

	internal static MelonPreferences_Entry<int> npc;

	internal static readonly List<Il2CppAssetBundle> npcs = new List<Il2CppAssetBundle>();

	internal static readonly Dictionary<string, Quaternion> fixedBoneRotations = new Dictionary<string, Quaternion>
	{
		{
			"pelvis",
			Quaternion.Euler(0f, 90f, 0f)
		},
		{
			"thigh_l",
			Quaternion.Euler(1.6f, 90.1f, 175.9f)
		},
		{
			"calf_l",
			Quaternion.Euler(16f, 89f, 178.4f)
		},
		{
			"foot_l",
			Quaternion.Euler(295.9f, 90.1f, 166.8f)
		},
		{
			"thigh_r",
			Quaternion.Euler(8.1f, 89.5f, 188.5f)
		},
		{
			"calf_r",
			Quaternion.Euler(11.3f, 90f, 188.8f)
		},
		{
			"foot_r",
			Quaternion.Euler(309.7f, 86.4f, 202.3f)
		},
		{
			"spine_01",
			Quaternion.Euler(352.7f, 90f, 0f)
		},
		{
			"spine_02",
			Quaternion.Euler(352.7f, 90f, 0f)
		},
		{
			"spine_03",
			Quaternion.Euler(352.7f, 90f, 0f)
		},
		{
			"clavicle_l",
			Quaternion.Euler(73.4f, 149.8f, 151.3f)
		},
		{
			"upperarm_l",
			Quaternion.Euler(18.3f, 179.7f, 180f)
		},
		{
			"lowerarm_l",
			Quaternion.Euler(5.7f, 176.6f, 167.2f)
		},
		{
			"hand_l",
			Quaternion.Euler(1.2f, 200.1f, 174.9f)
		},
		{
			"neck_01",
			Quaternion.Euler(0f, 90f, 0f)
		},
		{
			"head",
			Quaternion.Euler(0f, 90f, 0f)
		},
		{
			"clavicle_r",
			Quaternion.Euler(71f, 24.8f, 204.5f)
		},
		{
			"upperarm_r",
			Quaternion.Euler(21f, 0.9f, 181.6f)
		},
		{
			"lowerarm_r",
			Quaternion.Euler(6.1f, 10.2f, 196.3f)
		},
		{
			"hand_r",
			Quaternion.Euler(6.6f, 5.9f, 191.9f)
		}
	};

	internal static readonly Dictionary<string, Quaternion> npcStartingBoneRotations = new Dictionary<string, Quaternion>
	{
		{
			"root",
			Quaternion.Euler(270f, 89.99962f, 0f)
		},
		{
			"pelvis",
			Quaternion.Euler(359.9358f, 184.4637f, 270.4815f)
		},
		{
			"thigh_l",
			Quaternion.Euler(8.15668f, 173.441f, 267.7521f)
		},
		{
			"thigh_twist_01_l",
			Quaternion.Euler(8.327586f, 178.9338f, 268.5964f)
		},
		{
			"calf_l",
			Quaternion.Euler(2.719432f, 183.0643f, 282.8113f)
		},
		{
			"calf_twist_01_l",
			Quaternion.Euler(3.008848f, 182.8015f, 283.6706f)
		},
		{
			"foot_l",
			Quaternion.Euler(359.7301f, 181.9635f, 270.6106f)
		},
		{
			"ball_l",
			Quaternion.Euler(359.7344f, 181.9548f, 2.492124f)
		},
		{
			"thigh_r",
			Quaternion.Euler(351.4557f, 192.2657f, 91.11668f)
		},
		{
			"thigh_twist_01_r",
			Quaternion.Euler(351.6059f, 186.7689f, 91.98359f)
		},
		{
			"calf_r",
			Quaternion.Euler(356.262f, 187.3356f, 102.3812f)
		},
		{
			"calf_twist_01_r",
			Quaternion.Euler(355.9748f, 187.6007f, 103.2356f)
		},
		{
			"foot_r",
			Quaternion.Euler(359.536f, 195.8096f, 92.75099f)
		},
		{
			"ball_r",
			Quaternion.Euler(359.5535f, 195.8265f, 184.1445f)
		},
		{
			"spine_01",
			Quaternion.Euler(358.8558f, 184.3812f, 277.4615f)
		},
		{
			"spine_02",
			Quaternion.Euler(359.4415f, 182.4554f, 264.3822f)
		},
		{
			"spine_03",
			Quaternion.Euler(359.4415f, 182.4554f, 261.6028f)
		},
		{
			"clavicle_l",
			Quaternion.Euler(278.2905f, 343.8468f, 86.11373f)
		},
		{
			"upperarm_l",
			Quaternion.Euler(347.6549f, 27.72342f, 77.48131f)
		},
		{
			"upperarm_twist_01_l",
			Quaternion.Euler(347.6551f, 27.72342f, 77.48112f)
		},
		{
			"lowerarm_l",
			Quaternion.Euler(346.4409f, 29.04144f, 110.6302f)
		},
		{
			"hand_l",
			Quaternion.Euler(7.182298f, 315.5613f, 103.6744f)
		},
		{
			"middle_01_l",
			Quaternion.Euler(10.31653f, 320.7238f, 65.56126f)
		},
		{
			"middle_02_l",
			Quaternion.Euler(16.27994f, 316.0125f, 29.20985f)
		},
		{
			"middle_03_l",
			Quaternion.Euler(20.54132f, 314.0967f, 10.07737f)
		},
		{
			"ring_01_l",
			Quaternion.Euler(358.6666f, 305.47f, 57.75902f)
		},
		{
			"ring_02_l",
			Quaternion.Euler(1.367205f, 308.5297f, 23.6674f)
		},
		{
			"ring_03_l",
			Quaternion.Euler(4.774271f, 306.1891f, 2.096951f)
		},
		{
			"index_01_l",
			Quaternion.Euler(13.63145f, 334.6859f, 76.20506f)
		},
		{
			"index_02_l",
			Quaternion.Euler(25.68698f, 332.3141f, 48.74823f)
		},
		{
			"index_03_l",
			Quaternion.Euler(36.61045f, 321.5544f, 29.22751f)
		},
		{
			"thumb_01_l",
			Quaternion.Euler(12.32823f, 47.89695f, 125.0221f)
		},
		{
			"thumb_02_l",
			Quaternion.Euler(15.40295f, 42.94625f, 106.9237f)
		},
		{
			"thumb_03_l",
			Quaternion.Euler(15.0866f, 38.85083f, 111.0976f)
		},
		{
			"pinky_01_l",
			Quaternion.Euler(352.5666f, 301.3074f, 61.48701f)
		},
		{
			"pinky_02_l",
			Quaternion.Euler(355.0344f, 307.4337f, 26.44539f)
		},
		{
			"pinky_03_l",
			Quaternion.Euler(359.3047f, 306.8917f, 351.2636f)
		},
		{
			"lowerarm_twist_01_l",
			Quaternion.Euler(346.441f, 29.04144f, 110.6302f)
		},
		{
			"clavicle_r",
			Quaternion.Euler(84.47646f, 24.3166f, 270.244f)
		},
		{
			"upperarm_r",
			Quaternion.Euler(16.52847f, 332.5979f, 263.9202f)
		},
		{
			"upperarm_twist_01_r",
			Quaternion.Euler(17.58203f, 353.449f, 270.0985f)
		},
		{
			"lowerarm_r",
			Quaternion.Euler(17.40118f, 334.7668f, 286.0838f)
		},
		{
			"hand_r",
			Quaternion.Euler(346.7275f, 48.77039f, 287.8882f)
		},
		{
			"AimingParent",
			Quaternion.Euler(75.27374f, 121.6568f, 60.88676f)
		},
		{
			"TargetAiming",
			Quaternion.Euler(75.27375f, 121.6568f, 60.8868f)
		},
		{
			"middle_01_r",
			Quaternion.Euler(347.1903f, 42.58516f, 259.5388f)
		},
		{
			"middle_02_r",
			Quaternion.Euler(341.7425f, 44.34082f, 233.1754f)
		},
		{
			"middle_03_r",
			Quaternion.Euler(338.5513f, 42.7038f, 224.6481f)
		},
		{
			"ring_01_r",
			Quaternion.Euler(354.8238f, 59.2237f, 247.6354f)
		},
		{
			"ring_02_r",
			Quaternion.Euler(352.6611f, 55.76963f, 220.7423f)
		},
		{
			"ring_03_r",
			Quaternion.Euler(348.3617f, 56.98845f, 205.9559f)
		},
		{
			"index_01_r",
			Quaternion.Euler(344.2755f, 28.68169f, 265.8052f)
		},
		{
			"index_02_r",
			Quaternion.Euler(333.7045f, 27.76102f, 243.1819f)
		},
		{
			"index_03_r",
			Quaternion.Euler(321.9613f, 32.84692f, 230.223f)
		},
		{
			"thumb_01_r",
			Quaternion.Euler(352.4722f, 316.5494f, 315.8899f)
		},
		{
			"thumb_02_r",
			Quaternion.Euler(348.7072f, 320.8224f, 295.3593f)
		},
		{
			"thumb_03_r",
			Quaternion.Euler(348.497f, 324.8737f, 297.1597f)
		},
		{
			"pinky_01_r",
			Quaternion.Euler(0.05095493f, 63.77827f, 250.8168f)
		},
		{
			"pinky_02_r",
			Quaternion.Euler(358.2986f, 57.77447f, 223.274f)
		},
		{
			"pinky_03_r",
			Quaternion.Euler(353.4954f, 57.44502f, 194.9016f)
		},
		{
			"lowerarm_twist_01_r",
			Quaternion.Euler(13.23932f, 348.0994f, 289.6236f)
		},
		{
			"CC_Base_NeckTwist01",
			Quaternion.Euler(19.22621f, 92.65044f, 0.590753f)
		},
		{
			"neck_01",
			Quaternion.Euler(0.6767672f, 182.5597f, 290.9768f)
		},
		{
			"head",
			Quaternion.Euler(359.9742f, 178.1008f, 276.9633f)
		},
		{
			"cap",
			Quaternion.Euler(359.9742f, 178.1008f, 276.9633f)
		},
		{
			"LeftEyeGougeTransform",
			Quaternion.Euler(353.4496f, 247.9669f, 272.3676f)
		},
		{
			"RightEyeGougeTransform",
			Quaternion.Euler(353.4674f, 288.2403f, 87.58361f)
		},
		{
			"LeftEye",
			Quaternion.Euler(3.159316f, 89.38143f, 359.9429f)
		},
		{
			"CC_Base_L_Eye",
			Quaternion.Euler(273.1599f, 90.41734f, 358.9657f)
		},
		{
			"RightEye",
			Quaternion.Euler(3.160189f, 88.72524f, 359.939f)
		},
		{
			"CC_Base_R_Eye",
			Quaternion.Euler(273.1608f, 89.83205f, 358.8949f)
		},
		{
			"PhysicalJawTarget",
			Quaternion.Euler(0.0363474f, 358.1045f, 174.1334f)
		},
		{
			"CC_Base_JawRoot",
			Quaternion.Euler(0.0363474f, 358.1045f, 174.1334f)
		},
		{
			"CC_Base_Teeth02",
			Quaternion.Euler(359.9739f, 178.0944f, 14.08693f)
		},
		{
			"CC_Base_Tongue01",
			Quaternion.Euler(0.03601579f, 358.1031f, 173.5262f)
		},
		{
			"CC_Base_Tongue02",
			Quaternion.Euler(0.03504266f, 358.1014f, 159.8548f)
		},
		{
			"CC_Base_Tongue03",
			Quaternion.Euler(0.03522929f, 358.1014f, 159.8549f)
		},
		{
			"JawModel",
			Quaternion.Euler(14.49283f, 88.10767f, 0.0261949f)
		},
		{
			"CC_Base_NeckTwist02",
			Quaternion.Euler(28.48101f, 88.11406f, 0.02947497f)
		},
		{
			"CC_Base_Head",
			Quaternion.Euler(5.869103f, 88.10693f, 0.02814491f)
		},
		{
			"CC_Base_FacialBone",
			Quaternion.Euler(0.02800858f, 358.1041f, 262.1033f)
		},
		{
			"CC_Base_UpperJaw",
			Quaternion.Euler(0.02755938f, 358.0992f, 172.1027f)
		},
		{
			"CC_Base_Teeth01",
			Quaternion.Euler(359.9706f, 178.103f, 7.896055f)
		},
		{
			"HeadForwardDirection",
			Quaternion.Euler(6.963346f, 88.10399f, 0.0260033f)
		},
		{
			"LookingRaycastPosition",
			Quaternion.Euler(6.963308f, 88.10394f, 0.02607598f)
		},
		{
			"SkullModel",
			Quaternion.Euler(7.652921f, 88.10434f, 0.02590025f)
		},
		{
			"HeadDeform",
			Quaternion.Euler(43.03727f, 268.0769f, 359.9647f)
		},
		{
			"MeshDeformationPoint",
			Quaternion.Euler(0.2374725f, 272.453f, 359.4415f)
		},
		{
			"StandartAimTransform",
			Quaternion.Euler(0f, 89.99962f, 0f)
		},
		{
			"ChestAimHelper",
			Quaternion.Euler(0f, 89.99962f, 0f)
		},
		{
			"ChestEntrails",
			Quaternion.Euler(0f, 89.99962f, -3.562222E-13f)
		},
		{
			"Entrails",
			Quaternion.Euler(-3.975693E-16f, 89.99962f, -8.060978E-09f)
		}
	};

	internal static readonly List<string> boneNames = new List<string> { "SkullModel", "PhysicalJawTarget", "Hipbone", "Thigh", "Leg", "UpperArm", "LowerArm", "ChestEntrails" };

	public override void OnInitializeMelon()
	{
		Directory.CreateDirectory(MelonEnvironment.UserDataDirectory + "/CustomNPCs");
		List<string> list = new List<string> { "RANDOM" };
		string[] files = Directory.GetFiles(MelonEnvironment.UserDataDirectory + "/CustomNPCs", "*.npc");
		foreach (string text in files)
		{
			npcs.Add(Il2CppAssetBundleManager.LoadFromFile(text));
			list.Add(Path.GetFileNameWithoutExtension(text).ToUpper());
		}
		MelonPreferences_Category val = MelonPreferences.CreateCategory("CustomNPCs");
		enabled = val.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		npc = val.CreateEntry<int>("NPC", 0, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		if (npc.Value >= list.Count)
		{
			npc.Value = 0;
		}
		Menu.CreateCategory("CUSTOM NPCS").CreateBool("ENABLED", enabled.Value, (Action<bool>)delegate(bool value)
		{
			enabled.Value = value;
		}).CreateEnum("NPC", npc.Value, list.ToArray(), (Action<int>)delegate(int value)
		{
			npc.Value = value;
		});
	}

	[HarmonyPatch(typeof(HealthContainer), "OnEnable")]
	[HarmonyPostfix]
	public static void CreateNPC(SkinsChanger __instance)
	{
		MelonCoroutines.Start(WaitToCreate(((Component)__instance).transform.parent.parent.parent));
	}

	private static IEnumerator WaitToCreate(Transform root)
	{
		yield return new WaitForPool();
		if ((Object)(object)root != (Object)null && (Object)(object)((Component)root).GetComponent<CustomNPC>() == (Object)null && (Object)(object)root.parent == (Object)(object)GameResources.Enemies)
		{
			((Component)root).gameObject.AddComponent<CustomNPC>();
		}
	}
}
[RegisterTypeInIl2Cpp]
public class WaitForPool : CustomYieldInstruction
{
	public override bool keepWaiting => (Object)(object)GameResources.Enemies == (Object)null;

	public WaitForPool(IntPtr ptr)
		: base(ptr)
	{
	}

	public WaitForPool()
		: base(ClassInjector.DerivedConstructorPointer<WaitForPool>())
	{
		ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this);
	}
}
[RegisterTypeInIl2Cpp]
public class CustomNPC : MonoBehaviour
{
	private readonly List<Transform> skinBones = new List<Transform>();

	private Transform mesh;

	private Transform[] bones;

	private GameObject skin;

	public CustomNPC(IntPtr ptr)
		: base(ptr)
	{
	}

	public void OnEnable()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
		if (!Mod.enabled.Value)
		{
			return;
		}
		Dictionary<Transform, Quaternion> dictionary = new Dictionary<Transform, Quaternion> { 
		{
			((Component)this).transform,
			((Component)this).transform.rotation
		} };
		bones = Il2CppArrayBase<Transform>.op_Implicit(((Component)((Component)this).transform.Find("[BODY]/AnimatorBones")).GetComponentsInChildren<Transform>());
		Transform[] array = bones;
		foreach (Transform val in array)
		{
			dictionary.Add(val, val.rotation);
		}
		((Component)this).transform.rotation = Quaternion.Euler(0f, 90f, 0f);
		Transform[] array2 = bones;
		foreach (Transform val2 in array2)
		{
			if (Mod.npcStartingBoneRotations.ContainsKey(((Object)val2).name))
			{
				val2.rotation = Mod.npcStartingBoneRotations[((Object)val2).name];
			}
		}
		int num = Mod.npc.Value - 1;
		if (num == -1)
		{
			num = Random.Range(0, Mod.npcs.Count);
		}
		GameObject val3 = Object.Instantiate<GameObject>(Mod.npcs[num].LoadAsset<GameObject>(((Il2CppArrayBase<string>)(object)Mod.npcs[num].GetAllAssetNames())[0]));
		val3.transform.position = ((Component)this).transform.position + new Vector3(0.1f, 0.04f, 0f);
		val3.transform.rotation = ((Component)this).transform.rotation;
		val3.transform.localScale = ((Component)this).transform.localScale;
		foreach (Transform componentsInChild in val3.GetComponentsInChildren<Transform>())
		{
			if (Mod.fixedBoneRotations.ContainsKey(((Object)componentsInChild).name))
			{
				componentsInChild.rotation = Mod.fixedBoneRotations[((Object)componentsInChild).name];
			}
		}
		foreach (Transform componentsInChild2 in ((Component)val3.transform.Find("actualNPC/NPC/bones")).GetComponentsInChildren<Transform>())
		{
			skinBones.Add(componentsInChild2);
		}
		mesh = val3.transform.Find("actualNPC/NPC/Mesh");
		mesh.parent = ((Component)this).transform;
		skin = ((Component)((Component)this).transform.Find("[DATA STORAGES]/MeshesStorage/Activated")).gameObject;
		skin.SetActive(false);
		Transform[] array3 = bones;
		foreach (Transform val4 in array3)
		{
			if (Mod.boneNames.Contains(((Object)val4).name))
			{
				((Component)val4).gameObject.SetActive(false);
			}
		}
		foreach (Transform skinBone in skinBones)
		{
			Transform[] array4 = bones;
			foreach (Transform val5 in array4)
			{
				if ((Object)(object)skinBone != (Object)null && ((Object)val5).name == ((Object)skinBone).name && !skinBones.Contains(val5))
				{
					skinBone.parent = val5;
				}
			}
		}
		foreach (KeyValuePair<Transform, Quaternion> item in dictionary)
		{
			item.Key.rotation = item.Value;
		}
		Object.Destroy((Object)(object)val3);
	}

	public void OnDisable()
	{
		if (!((Object)(object)mesh != (Object)null))
		{
			return;
		}
		skin.SetActive(true);
		Object.Destroy((Object)(object)((Component)mesh).gameObject);
		foreach (Transform skinBone in skinBones)
		{
			if ((Object)(object)skinBone != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)skinBone).gameObject);
			}
		}
		Transform[] array = bones;
		foreach (Transform val in array)
		{
			if (Mod.boneNames.Contains(((Object)val).name))
			{
				((Component)val).gameObject.SetActive(true);
			}
		}
	}
}