Decompiled source of Better SosigSpawner v1.1.3

BetterSosigSpawner.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("HLin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterSosigSpawner")]
[assembly: AssemblyTitle("BetterSosigSpawner")]
[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 BetterSosigSpawner
{
	[HarmonyPatch(typeof(SosigSpawner), "PageUpdate_SpawnSosig")]
	public static class Harmony_PageUpdate_SpawnSosig
	{
		[HarmonyPrefix]
		public static bool Prefix(SosigSpawner __instance)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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)
			_ = Vector3.zero;
			Physics.Raycast(__instance.Muzzle.position, __instance.Muzzle.forward, ref __instance.m_hit, __instance.Range_PlacementBeam, LayerMask.op_Implicit(__instance.LM_PlacementBeam), (QueryTriggerInteraction)1);
			((Component)__instance.PlacementBeam1).gameObject.SetActive(true);
			((Component)__instance.PlacementBeam2).gameObject.SetActive(false);
			__instance.PlacementBeam1.localScale = new Vector3(0.005f, 0.005f, ((RaycastHit)(ref __instance.m_hit)).distance);
			((Component)__instance.PlacementReticle).gameObject.SetActive(true);
			__instance.PlacementReticle_Valid.SetActive(true);
			__instance.PlacementReticle_Invalid.SetActive(false);
			__instance.m_canSpawn_Sosig = true;
			__instance.m_sosigSpawn_Point = ((RaycastHit)(ref __instance.m_hit)).point;
			__instance.PlacementReticle.position = ((RaycastHit)(ref __instance.m_hit)).point + Vector3.up * 0.01f;
			return false;
		}
	}
	[HarmonyPatch(typeof(SosigSpawner), "UpdateInteraction_SpawnSosig")]
	public static class Harmony_UpdateInteraction_SpawnSosig
	{
		[HarmonyPrefix]
		public static bool Prefix(SosigSpawner __instance, FVRViveHand hand)
		{
			//IL_0006: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			Physics.Raycast(__instance.Muzzle.position, __instance.Muzzle.forward, ref __instance.m_hit, 3000f, LayerMask.op_Implicit(__instance.LM_PlacementBeam), (QueryTriggerInteraction)1);
			((Component)__instance.PlacementReticle).gameObject.SetActive(true);
			__instance.PlacementReticle_Valid.SetActive(true);
			__instance.PlacementReticle_Invalid.SetActive(false);
			((Component)__instance.PlacementBeam1).gameObject.SetActive(true);
			((Component)__instance.PlacementBeam2).gameObject.SetActive(false);
			__instance.PlacementBeam1.localScale = new Vector3(0.005f, 0.005f, ((RaycastHit)(ref __instance.m_hit)).distance);
			__instance.m_canSpawn_Sosig = true;
			__instance.m_sosigSpawn_Point = ((RaycastHit)(ref __instance.m_hit)).point;
			__instance.PlacementReticle.position = ((RaycastHit)(ref __instance.m_hit)).point + Vector3.up * 0.01f;
			Vector3 position = ((Component)__instance).gameObject.transform.position;
			if (((FVRInteractiveObject)__instance).m_hasTriggeredUpSinceBegin && hand.Input.TriggerDown)
			{
				if (__instance.m_canSpawn_Sosig)
				{
					Vector3 val = __instance.m_sosigSpawn_Point - position;
					val.y = 0f;
					SM.PlayGenericSound(__instance.AudEvent_Spawn, position);
					if (__instance.SpawnerGroups[__instance.m_spawn_group].IsFurniture)
					{
						Object.Instantiate<GameObject>(__instance.SpawnerGroups[__instance.m_spawn_group].Furnitures[__instance.m_spawn_template], __instance.m_sosigSpawn_Point + Vector3.up * 0.5f, Quaternion.LookRotation(-val, Vector3.up));
						return false;
					}
					SosigEnemyTemplate val2 = __instance.SpawnerGroups[__instance.m_spawn_group].Templates[__instance.m_spawn_template];
					__instance.SpawnSosigWithTemplate(val2, __instance.m_sosigSpawn_Point, -val);
					return false;
				}
				SM.PlayGenericSound(__instance.AudEvent_Fail, position);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Sosig), "Speak_Pain")]
	public static class Harmony_Sosig_Speak_Pain
	{
		[HarmonyPrefix]
		public static bool Prefix(Sosig __instance, List<AudioClip> clips)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			//IL_0096: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			if (__instance.Speech.ForceDeathSpeech && (clips == __instance.Speech.OnDeath || clips == __instance.Speech.OnDeathAlt))
			{
				flag = true;
			}
			if ((int)__instance.BodyState == 3 && !flag)
			{
				return false;
			}
			if (clips.Count <= 0)
			{
				return false;
			}
			if (!__instance.CanSpeakPain() && !flag)
			{
				return false;
			}
			if (flag)
			{
				__instance.KillSpeech();
			}
			AudioClip val = clips[Random.Range(0, clips.Count)];
			__instance.m_tickDownToPainSpeechAvailability = val.length + Random.Range(1.1f, 1.2f);
			Vector3 position = ((Component)__instance).gameObject.transform.position;
			bool flag2 = true;
			if ((Object)(object)__instance.Links[0] != (Object)null)
			{
				position = ((Component)__instance.Links[0]).transform.position;
				flag2 = false;
			}
			float num = 1f;
			if (__instance.IsFrozen)
			{
				num = 0.8f;
			}
			if (__instance.IsSpeedUp)
			{
				num = 1.8f;
			}
			if ((Object)(object)GM.CurrentAIManager != (Object)null)
			{
				if (flag)
				{
					__instance.m_speakingSource = GM.CurrentAIManager.Speak(val, __instance.Speech.BaseVolume, __instance.Speech.BasePitch * num, position, (SpeakType)2);
				}
				else
				{
					__instance.m_speakingSource = GM.CurrentAIManager.Speak(val, __instance.Speech.BaseVolume, __instance.Speech.BasePitch * num, position, (SpeakType)1);
				}
			}
			if ((Object)(object)__instance.m_speakingSource != (Object)null && !flag2)
			{
				__instance.m_speakingSource.FollowThisTransform(((Component)__instance.Links[0]).transform);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Sosig), "Speak_State")]
	public static class Harmony_Sosig_Speak_State
	{
		[HarmonyPrefix]
		public static bool Prefix(Sosig __instance, List<AudioClip> clips)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			if ((int)__instance.BodyState == 3)
			{
				return false;
			}
			if (clips.Count <= 0)
			{
				return false;
			}
			AudioClip val = clips[Random.Range(0, clips.Count)];
			__instance.m_tickDownToNextStateSpeech = val.length + __instance.GetSpeakDelay();
			Vector3 position = ((Component)__instance).gameObject.transform.position;
			bool flag = true;
			if ((Object)(object)__instance.Links[0] != (Object)null)
			{
				position = ((Component)__instance.Links[0]).transform.position;
				flag = false;
			}
			float num = 1f;
			if (__instance.IsFrozen)
			{
				num = 0.8f;
			}
			if (__instance.IsSpeedUp)
			{
				num = 1.8f;
			}
			if ((Object)(object)GM.CurrentAIManager != (Object)null)
			{
				__instance.m_speakingSource = GM.CurrentAIManager.Speak(val, __instance.Speech.BaseVolume, __instance.Speech.BasePitch * num, position, (SpeakType)0);
			}
			if ((Object)(object)__instance.m_speakingSource != (Object)null && !flag)
			{
				__instance.m_speakingSource.FollowThisTransform(((Component)__instance.Links[0]).transform);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Sosig), "Init")]
	public static class Harmony_Sosig_Init
	{
		[HarmonyPrefix]
		public static bool Prefix(Sosig __instance)
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: 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)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < __instance.Links.Count; i++)
			{
				__instance.IgnoreRBs.Add(__instance.Links[i].R);
			}
			for (int j = 0; j < __instance.Links.Count; j++)
			{
				if ((Object)(object)__instance.Links[j].J != (Object)null)
				{
					__instance.m_joints.Add(__instance.Links[j].J);
				}
			}
			if ((Object)(object)__instance.E != (Object)null)
			{
				__instance.E.AIEventReceiveEvent += new AIEventReceive(__instance.EventReceive);
				__instance.E.AIReceiveSuppressionEvent += new AIReceiveSuppression(__instance.SuppresionEvent);
			}
			__instance.Agent.Warp(((Component)__instance).gameObject.transform.position);
			((Behaviour)__instance.Agent).enabled = true;
			__instance.m_cachedPath = new NavMeshPath();
			if (__instance.Priority != null && !__instance.m_hasConfiguredPriority)
			{
				__instance.m_hasPriority = true;
				__instance.Priority.Init(__instance.E, 5, 2f, 1.5f);
			}
			__instance.InitHands();
			__instance.Inventory.Init();
			if ((Object)(object)GM.CurrentAIManager != (Object)null && GM.CurrentAIManager.HasCPM)
			{
				__instance.CoverSearchRange = GM.CurrentAIManager.CPM.DefaultSearchRange;
			}
			__instance.m_targetPose = __instance.Pose_Standing;
			__instance.m_targetLocalPos = __instance.Pose_Standing.localPosition;
			__instance.m_targetLocalRot = __instance.Pose_Standing.localRotation;
			__instance.m_poseLocalEulers_Standing = __instance.Pose_Standing.localEulerAngles;
			__instance.m_poseLocalEulers_Crouching = __instance.Pose_Crouching.localEulerAngles;
			__instance.m_poseLocalEulers_Prone = __instance.Pose_Prone.localEulerAngles;
			__instance.UpdateJoints(1f);
			return false;
		}
	}
	[HarmonyPatch(typeof(Sosig), "SosigDies")]
	public static class Harmony_Sosig_SosigDies
	{
		[HarmonyPrefix]
		public static bool Prefix(Sosig __instance, DamageClass damClass, SosigDeathType deathType)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			if ((int)__instance.BodyState == 3)
			{
				return false;
			}
			__instance.RemoveSelfFromPathWiths();
			__instance.DeActivateAllBuffSystems();
			if ((int)damClass != 0)
			{
				__instance.m_diedFromClass = damClass;
			}
			__instance.m_diedFromType = deathType;
			if (!__instance.m_linksDestroyed[0])
			{
				__instance.Speak_Pain(__instance.Speech.OnDeath);
			}
			else
			{
				__instance.KillSpeech();
				if (__instance.Speech.UseAltDeathOnHeadExplode)
				{
					__instance.Speak_Pain(__instance.Speech.OnDeathAlt);
				}
			}
			__instance.SetBodyState((SosigBodyState)3);
			__instance.CurrentOrder = (SosigOrder)0;
			__instance.FallbackOrder = (SosigOrder)0;
			__instance.SetHandObjectUsage((SosigObjectUsageFocus)0);
			__instance.SetMovementState((SosigMovementState)0);
			if ((Object)(object)GM.CurrentAIManager != (Object)null && GM.CurrentAIManager.UsesSosigCorpsePerceptionSystem)
			{
				for (int i = 0; i < 4; i++)
				{
					if (!__instance.m_linksDestroyed[i] && (Object)(object)__instance.Links[i] != (Object)null)
					{
						GameObject obj = Object.Instantiate<GameObject>(__instance.CorpseEntityPrefab, ((Component)__instance.Links[i]).transform.position, ((Component)__instance.Links[i]).transform.rotation);
						obj.transform.SetParent(((Component)__instance.Links[i]).transform);
						obj.GetComponent<AIEntity>().IFFCode = __instance.E.IFFCode;
					}
				}
			}
			for (int j = 0; j < __instance.Hands.Count; j++)
			{
				__instance.Hands[j].DropHeldObject();
			}
			__instance.Inventory.DropAllObjects();
			for (int k = 0; k < __instance.Links.Count; k++)
			{
				if ((Object)(object)__instance.Links[k] != (Object)null && !__instance.m_jointsSevered[k])
				{
					__instance.Links[k].R.AddForce(Random.onUnitSphere * Random.Range(1f, 5f), (ForceMode)2);
					__instance.Links[k].O.DistantGrabbable = true;
				}
			}
			GM.CurrentSceneSettings.OnSosigKill(__instance);
			__instance.TickDownToClear(3f);
			__instance.E.IFFCode = -3;
			return false;
		}
	}
	[BepInProcess("h3vr.exe")]
	[BepInPlugin("HLin-Better-SosigSpawner", "BetterSosigSpawner", "1.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		private static readonly Harmony harmony = new Harmony("HLin-Better-SosigSpawner");

		public void Awake()
		{
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Better SosigSpawner Successfully!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BetterSosigSpawner";

		public const string PLUGIN_NAME = "BetterSosigSpawner";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}