Decompiled source of CadaverBloomForMRAPI v1.0.0

CadaverBloomForMRAPI.dll

Decompiled 8 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ModelReplacement;
using ModelReplacement.AvatarBodyUpdater;
using UnityEngine;
using UnityEngine.Rendering;

[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: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("DunGen")]
[assembly: IgnoresAccessChecksTo("DunGen.Integration.ASPP")]
[assembly: IgnoresAccessChecksTo("DunGen.Integration.UnityNav")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.XR.CoreUtils")]
[assembly: IgnoresAccessChecksTo("Unity.XR.Management")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.ConformanceAutomation")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MetaQuestSupport")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MockRuntime")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.OculusQuestSupport")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.RuntimeDebugger")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.SpatialTracking")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("UnityEngine.XR.LegacyInputHelpers")]
[assembly: AssemblyCompany("CadaverBloomForMRAPI")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CadaverBloomForMRAPI")]
[assembly: AssemblyTitle("CadaverBloomForMRAPI")]
[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.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]
	[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]
	[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 CadaverBloomForMRAPI
{
	internal class CadaverBloomAIReplacementBase : MonoBehaviour
	{
		public CadaverBloomAI enemyAI = null;

		public GameObject replacementModel;

		public bool IsActive = false;

		public CadaverBloomAvatarUpdater avatar { get; private set; }

		protected virtual void Awake()
		{
			enemyAI = ((Component)this).GetComponent<CadaverBloomAI>();
			ModelReplacementAPI.Instance.Logger.LogInfo((object)$"Awake CadaverBloom mimicking {enemyAI.burstPlayer?.playerUsername} {this}");
			if (!ModelReplacementAPI.MRAPI_NetworkingPresent)
			{
				PlayerControllerB val = enemyAI.burstPlayer;
				if ((Object)(object)val == (Object)null)
				{
					Console.WriteLine("CadaverBloom not mimicking anyone, choose at random: ");
					Random random = new Random();
					val = StartOfRound.Instance.allPlayerScripts[random.Next(StartOfRound.Instance.ClientPlayerList.Count)];
				}
				if ((Object)(object)val != (Object)null)
				{
					SetReplacement(val);
				}
			}
		}

		protected void SetReplacement(PlayerControllerB mimicking)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			BodyReplacementBase val = default(BodyReplacementBase);
			if (ModelReplacementAPI.GetPlayerModelReplacement(mimicking, ref val))
			{
				IsActive = true;
				replacementModel = Object.Instantiate<GameObject>(val.replacementModel);
				GameObject obj = replacementModel;
				((Object)obj).name = ((Object)obj).name + "(CadaverBloom)";
				replacementModel.transform.localPosition = new Vector3(0f, 0f, 0f);
				replacementModel.SetActive(true);
				Renderer[] componentsInChildren = replacementModel.GetComponentsInChildren<Renderer>();
				foreach (Renderer val2 in componentsInChildren)
				{
					val2.shadowCastingMode = (ShadowCastingMode)1;
					((Component)val2).gameObject.layer = val.viewState.VisibleLayer;
					val2.enabled = ((Behaviour)this).enabled;
				}
				avatar = new CadaverBloomAvatarUpdater();
				avatar.AssignModelReplacement(((Component)enemyAI).gameObject, replacementModel);
				SkinnedMeshRenderer thisSkinnedRenderer = enemyAI.thisSkinnedRenderer;
				Material[] materials = ((Renderer)thisSkinnedRenderer).materials;
				materials[1] = Plugin.material;
				((Renderer)thisSkinnedRenderer).materials = materials;
			}
		}

		protected virtual void Start()
		{
		}

		public virtual void LateUpdate()
		{
			if (IsActive)
			{
				avatar.Update();
			}
		}

		protected virtual void OnDestroy()
		{
			if ((Object)(object)replacementModel != (Object)null)
			{
				ModelReplacementAPI.Instance.Logger.LogInfo((object)("Destroy CadaverBloom body component " + ((Object)replacementModel).name));
				Object.Destroy((Object)(object)replacementModel);
			}
		}
	}
	internal class CadaverBloomAvatarUpdater
	{
		protected SkinnedMeshRenderer enemyModelRenderer = null;

		protected Animator replacementAnimator = null;

		protected GameObject enemy = null;

		protected GameObject replacement = null;

		protected bool hasUpperChest = false;

		protected Vector3 rootPositionOffset = Vector3.zero;

		protected static Dictionary<string, HumanBodyBones> modelToAvatarBone = new Dictionary<string, HumanBodyBones>
		{
			{
				"spine",
				(HumanBodyBones)0
			},
			{
				"spine2",
				(HumanBodyBones)7
			},
			{
				"shoulder.L",
				(HumanBodyBones)11
			},
			{
				"arm.L_upper",
				(HumanBodyBones)13
			},
			{
				"arm.L_lower",
				(HumanBodyBones)15
			},
			{
				"hand.L",
				(HumanBodyBones)17
			},
			{
				"finger5.L",
				(HumanBodyBones)36
			},
			{
				"finger5.L.001",
				(HumanBodyBones)37
			},
			{
				"finger4.L",
				(HumanBodyBones)33
			},
			{
				"finger4.L.001",
				(HumanBodyBones)34
			},
			{
				"finger3.L",
				(HumanBodyBones)30
			},
			{
				"finger3.L.001",
				(HumanBodyBones)31
			},
			{
				"finger2.L",
				(HumanBodyBones)27
			},
			{
				"finger2.L.001",
				(HumanBodyBones)28
			},
			{
				"finger1.L",
				(HumanBodyBones)24
			},
			{
				"finger1.L.001",
				(HumanBodyBones)26
			},
			{
				"shoulder.R",
				(HumanBodyBones)12
			},
			{
				"arm.R_upper",
				(HumanBodyBones)14
			},
			{
				"arm.R_lower",
				(HumanBodyBones)16
			},
			{
				"hand.R",
				(HumanBodyBones)18
			},
			{
				"finger5.R",
				(HumanBodyBones)51
			},
			{
				"finger5.R.001",
				(HumanBodyBones)52
			},
			{
				"finger4.R",
				(HumanBodyBones)48
			},
			{
				"finger4.R.001",
				(HumanBodyBones)49
			},
			{
				"finger3.R",
				(HumanBodyBones)45
			},
			{
				"finger3.R.001",
				(HumanBodyBones)46
			},
			{
				"finger2.R",
				(HumanBodyBones)42
			},
			{
				"finger2.R.001",
				(HumanBodyBones)43
			},
			{
				"finger1.R",
				(HumanBodyBones)39
			},
			{
				"finger1.R.001",
				(HumanBodyBones)41
			},
			{
				"PlayerHead",
				(HumanBodyBones)10
			},
			{
				"thigh.L",
				(HumanBodyBones)1
			},
			{
				"shin.L",
				(HumanBodyBones)3
			},
			{
				"foot.L",
				(HumanBodyBones)5
			},
			{
				"toe.L",
				(HumanBodyBones)19
			},
			{
				"thigh.R",
				(HumanBodyBones)2
			},
			{
				"shin.R",
				(HumanBodyBones)4
			},
			{
				"foot.R",
				(HumanBodyBones)6
			},
			{
				"toe.R",
				(HumanBodyBones)20
			}
		};

		public Vector3 ItemHolderPositionOffset { get; private set; } = Vector3.zero;

		public Quaternion ItemHolderRotationOffset { get; private set; } = Quaternion.identity;

		public Transform ItemHolder { get; private set; } = null;

		public virtual void AssignModelReplacement(GameObject enemy, GameObject replacement)
		{
			//IL_0041: 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)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			CadaverBloomAI component = enemy.GetComponent<CadaverBloomAI>();
			enemyModelRenderer = component.thisSkinnedRenderer;
			this.enemy = enemy;
			replacementAnimator = replacement.GetComponentInChildren<Animator>();
			this.replacement = replacement;
			OffsetBuilder component2 = ((Component)replacementAnimator).gameObject.GetComponent<OffsetBuilder>();
			ItemHolderPositionOffset = component2.itemPositonOffset;
			ItemHolderRotationOffset = component2.itemRotationOffset;
			ItemHolder = component2.itemHolder.transform;
			rootPositionOffset = component2.rootPositionOffset;
			Transform boneTransform = replacementAnimator.GetBoneTransform((HumanBodyBones)54);
			hasUpperChest = (Object)(object)boneTransform != (Object)null;
		}

		protected virtual void UpdateModel()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			Transform[] bones = enemyModelRenderer.bones;
			foreach (Transform val in bones)
			{
				Transform avatarTransformFromBoneName = GetAvatarTransformFromBoneName(((Object)val).name);
				if (!((Object)(object)avatarTransformFromBoneName == (Object)null))
				{
					avatarTransformFromBoneName.rotation = val.rotation;
					RotationOffset component = ((Component)avatarTransformFromBoneName).GetComponent<RotationOffset>();
					if (Object.op_Implicit((Object)(object)component))
					{
						avatarTransformFromBoneName.rotation *= component.offset;
					}
				}
			}
			Transform avatarTransformFromBoneName2 = GetAvatarTransformFromBoneName("spine");
			Transform playerTransformFromBoneName = GetPlayerTransformFromBoneName("spine");
			avatarTransformFromBoneName2.position = playerTransformFromBoneName.position + playerTransformFromBoneName.TransformVector(rootPositionOffset);
		}

		public void Update()
		{
			if (!((Object)(object)enemyModelRenderer == (Object)null) && !((Object)(object)replacementAnimator == (Object)null))
			{
				UpdateModel();
			}
		}

		public Transform GetAvatarTransformFromBoneName(string boneName)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (boneName == "spine.002")
			{
				return hasUpperChest ? replacementAnimator.GetBoneTransform((HumanBodyBones)8) : null;
			}
			if (boneName == "spine.003")
			{
				return hasUpperChest ? replacementAnimator.GetBoneTransform((HumanBodyBones)54) : replacementAnimator.GetBoneTransform((HumanBodyBones)8);
			}
			HumanBodyBones value;
			return modelToAvatarBone.TryGetValue(boneName, out value) ? replacementAnimator.GetBoneTransform(value) : null;
		}

		public Transform GetPlayerTransformFromBoneName(string boneName)
		{
			IEnumerable<Transform> source = enemyModelRenderer.bones.Where((Transform x) => ((Object)x).name == boneName);
			if (source.Any())
			{
				return source.First();
			}
			return null;
		}
	}
	[BepInPlugin("hlb.CadaverBloomForMRAPI", "CadaverBloomForMRAPI", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(CadaverBloomAI))]
		public class CadaverBloomEnemyPatch
		{
			[HarmonyPatch("Start")]
			[HarmonyPostfix]
			public static void ManageRegistryBodyReplacements(ref EnemyAI __instance)
			{
				try
				{
					((Component)__instance).gameObject.AddComponent<CadaverBloomAIReplacementBase>();
				}
				catch (Exception arg)
				{
					ModelReplacementAPI.Instance.Logger.LogError((object)$"Exception in CadaverBloomAI ManageRegistryBodyReplacements: {arg}");
				}
			}

			[HarmonyPatch("SetSuit")]
			[HarmonyPrefix]
			public static bool ManageRegistryBodyReplacements2(CadaverBloomAI __instance)
			{
				if ((Object)(object)__instance.burstPlayer != (Object)null)
				{
					BodyReplacementBase val = default(BodyReplacementBase);
					ModelReplacementAPI.GetPlayerModelReplacement(__instance.burstPlayer, ref val);
					if ((Object)(object)val != (Object)null)
					{
						return false;
					}
				}
				return true;
			}
		}

		public ManualLogSource Logger;

		private static AssetBundle bundle;

		public static Material material;

		private static string GetAssemblyName()
		{
			return Assembly.GetExecutingAssembly().GetName().Name;
		}

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			Logger = Logger.CreateLogSource("CadaverBloomForMRAPI");
			Harmony val = new Harmony("hlb.CadaverBloomForMRAPI");
			val.PatchAll();
			Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + ".cadaversss");
			bundle = AssetBundle.LoadFromStream(manifestResourceStream);
			material = bundle.LoadAsset<Material>("Assets/0CadaverBloomAI/mats.mat");
			Logger.LogInfo((object)"CadaverBloomForMRAPI loaded!");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}