Decompiled source of Custom Sosig Loader v1.0.2

Sosig_Squad.CustomSosigLoader.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using CustomSosigLoader;
using FistVR;
using H3MP;
using H3MP.Networking;
using H3MP.Scripts;
using H3MP.Tracking;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using OtherLoader;
using Sodalite.Api;
using TNHFramework;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("Packer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A Custom Sosig Loader for H3VR")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1845cfc158ceac82ffb3fe05a0c1e184d09d0718")]
[assembly: AssemblyProduct("Sosig_Squad.CustomSosigLoader")]
[assembly: AssemblyTitle("Custom Sosig Loader")]
[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;
		}
	}
}
public class WavUtility
{
	private const int BlockSize_16Bit = 2;

	public static AudioClip ToAudioClip(string filePath)
	{
		byte[] fileBytes = File.ReadAllBytes(filePath);
		return ToAudioClip(fileBytes);
	}

	public static AudioClip ToAudioClip(byte[] fileBytes, int offsetSamples = 0, string name = "wav")
	{
		int num = BitConverter.ToInt32(fileBytes, 16);
		ushort code = BitConverter.ToUInt16(fileBytes, 20);
		string text = FormatCode(code);
		ushort num2 = BitConverter.ToUInt16(fileBytes, 22);
		int num3 = BitConverter.ToInt32(fileBytes, 24);
		ushort num4 = BitConverter.ToUInt16(fileBytes, 34);
		int num5 = 20 + num + 4;
		int dataSize = BitConverter.ToInt32(fileBytes, num5);
		float[] array = num4 switch
		{
			8 => Convert8BitByteArrayToAudioClipData(fileBytes, num5, dataSize), 
			16 => Convert16BitByteArrayToAudioClipData(fileBytes, num5, dataSize), 
			24 => Convert24BitByteArrayToAudioClipData(fileBytes, num5, dataSize), 
			32 => Convert32BitByteArrayToAudioClipData(fileBytes, num5, dataSize), 
			_ => throw new Exception(num4 + " bit depth is not supported."), 
		};
		AudioClip val = AudioClip.Create(name, array.Length, (int)num2, num3, false);
		val.SetData(array, 0);
		return val;
	}

	private static float[] Convert8BitByteArrayToAudioClipData(byte[] source, int headerOffset, int dataSize)
	{
		int num = BitConverter.ToInt32(source, headerOffset);
		headerOffset += 4;
		float[] array = new float[num];
		sbyte b = sbyte.MaxValue;
		for (int i = 0; i < num; i++)
		{
			array[i] = (float)(int)source[i] / (float)b;
		}
		return array;
	}

	private static float[] Convert16BitByteArrayToAudioClipData(byte[] source, int headerOffset, int dataSize)
	{
		int num = BitConverter.ToInt32(source, headerOffset);
		headerOffset += 4;
		int num2 = 2;
		int num3 = num / num2;
		float[] array = new float[num3];
		short num4 = short.MaxValue;
		int num5 = 0;
		for (int i = 0; i < num3; i++)
		{
			num5 = i * num2 + headerOffset;
			array[i] = (float)BitConverter.ToInt16(source, num5) / (float)num4;
		}
		return array;
	}

	private static float[] Convert24BitByteArrayToAudioClipData(byte[] source, int headerOffset, int dataSize)
	{
		int num = BitConverter.ToInt32(source, headerOffset);
		headerOffset += 4;
		int num2 = 3;
		int num3 = num / num2;
		int num4 = int.MaxValue;
		float[] array = new float[num3];
		byte[] array2 = new byte[4];
		int num5 = 0;
		for (int i = 0; i < num3; i++)
		{
			num5 = i * num2 + headerOffset;
			Buffer.BlockCopy(source, num5, array2, 1, num2);
			array[i] = (float)BitConverter.ToInt32(array2, 0) / (float)num4;
		}
		return array;
	}

	private static float[] Convert32BitByteArrayToAudioClipData(byte[] source, int headerOffset, int dataSize)
	{
		int num = BitConverter.ToInt32(source, headerOffset);
		headerOffset += 4;
		int num2 = 4;
		int num3 = num / num2;
		int num4 = int.MaxValue;
		float[] array = new float[num3];
		int num5 = 0;
		for (int i = 0; i < num3; i++)
		{
			num5 = i * num2 + headerOffset;
			array[i] = (float)BitConverter.ToInt32(source, num5) / (float)num4;
		}
		return array;
	}

	public static byte[] FromAudioClip(AudioClip audioClip)
	{
		string filepath;
		return FromAudioClip(audioClip, out filepath, saveAsFile: false);
	}

	public static byte[] FromAudioClip(AudioClip audioClip, out string filepath, bool saveAsFile = true, string dirname = "recordings")
	{
		MemoryStream stream = new MemoryStream();
		ushort bitDepth = 16;
		int fileSize = audioClip.samples * 2 + 44;
		WriteFileHeader(ref stream, fileSize);
		WriteFileFormat(ref stream, audioClip.channels, audioClip.frequency, bitDepth);
		WriteFileData(ref stream, audioClip, bitDepth);
		byte[] array = stream.ToArray();
		if (saveAsFile)
		{
			filepath = string.Format("{0}/{1}/{2}.{3}", Application.persistentDataPath, dirname, DateTime.UtcNow.ToString("yyMMdd-HHmmss-fff"), "wav");
			Directory.CreateDirectory(Path.GetDirectoryName(filepath));
			File.WriteAllBytes(filepath, array);
		}
		else
		{
			filepath = null;
		}
		stream.Dispose();
		return array;
	}

	private static int WriteFileHeader(ref MemoryStream stream, int fileSize)
	{
		int num = 0;
		int num2 = 12;
		byte[] bytes = Encoding.ASCII.GetBytes("RIFF");
		num += WriteBytesToMemoryStream(ref stream, bytes, "ID");
		int value = fileSize - 8;
		num += WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value), "CHUNK_SIZE");
		byte[] bytes2 = Encoding.ASCII.GetBytes("WAVE");
		return num + WriteBytesToMemoryStream(ref stream, bytes2, "FORMAT");
	}

	private static int WriteFileFormat(ref MemoryStream stream, int channels, int sampleRate, ushort bitDepth)
	{
		int num = 0;
		int num2 = 24;
		byte[] bytes = Encoding.ASCII.GetBytes("fmt ");
		num += WriteBytesToMemoryStream(ref stream, bytes, "FMT_ID");
		int value = 16;
		num += WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value), "SUBCHUNK_SIZE");
		ushort value2 = 1;
		num += WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value2), "AUDIO_FORMAT");
		ushort value3 = Convert.ToUInt16(channels);
		num += WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value3), "CHANNELS");
		num += WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(sampleRate), "SAMPLE_RATE");
		int value4 = sampleRate * channels * BytesPerSample(bitDepth);
		num += WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value4), "BYTE_RATE");
		ushort value5 = Convert.ToUInt16(channels * BytesPerSample(bitDepth));
		num += WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value5), "BLOCK_ALIGN");
		return num + WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(bitDepth), "BITS_PER_SAMPLE");
	}

	private static int WriteFileData(ref MemoryStream stream, AudioClip audioClip, ushort bitDepth)
	{
		int num = 0;
		int num2 = 8;
		float[] array = new float[audioClip.samples * audioClip.channels];
		audioClip.GetData(array, 0);
		byte[] bytes = ConvertAudioClipDataToInt16ByteArray(array);
		byte[] bytes2 = Encoding.ASCII.GetBytes("data");
		num += WriteBytesToMemoryStream(ref stream, bytes2, "DATA_ID");
		int value = Convert.ToInt32(audioClip.samples * 2);
		num += WriteBytesToMemoryStream(ref stream, BitConverter.GetBytes(value), "SAMPLES");
		return num + WriteBytesToMemoryStream(ref stream, bytes, "DATA");
	}

	private static byte[] ConvertAudioClipDataToInt16ByteArray(float[] data)
	{
		MemoryStream memoryStream = new MemoryStream();
		int count = 2;
		short num = short.MaxValue;
		for (int i = 0; i < data.Length; i++)
		{
			memoryStream.Write(BitConverter.GetBytes(Convert.ToInt16(data[i] * (float)num)), 0, count);
		}
		byte[] result = memoryStream.ToArray();
		memoryStream.Dispose();
		return result;
	}

	private static int WriteBytesToMemoryStream(ref MemoryStream stream, byte[] bytes, string tag = "")
	{
		int num = bytes.Length;
		stream.Write(bytes, 0, num);
		return num;
	}

	public static ushort BitDepth(AudioClip audioClip)
	{
		return Convert.ToUInt16((float)(audioClip.samples * audioClip.channels) * audioClip.length / (float)audioClip.frequency);
	}

	private static int BytesPerSample(ushort bitDepth)
	{
		return bitDepth / 8;
	}

	private static int BlockSize(ushort bitDepth)
	{
		return bitDepth switch
		{
			32 => 4, 
			16 => 2, 
			8 => 1, 
			_ => throw new Exception(bitDepth + " bit depth is not supported."), 
		};
	}

	private static string FormatCode(ushort code)
	{
		switch (code)
		{
		case 1:
			return "PCM";
		case 2:
			return "ADPCM";
		case 3:
			return "IEEE";
		case 7:
			return "μ-law";
		case 65534:
			return "WaveFormatExtensable";
		default:
			Debug.LogWarning((object)("Unknown wav code format:" + code));
			return "";
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace H3MP.Networking
{
	public class Networking
	{
		public static bool ServerRunning()
		{
			if (CustomSosigLoaderPlugin.h3mpEnabled)
			{
				return isServerRunning();
			}
			return false;
		}

		private static bool isServerRunning()
		{
			if ((Object)(object)Mod.managerObject == (Object)null)
			{
				return false;
			}
			return true;
		}

		public static bool IsClient()
		{
			if (CustomSosigLoaderPlugin.h3mpEnabled)
			{
				return isClient();
			}
			return false;
		}

		private static bool isClient()
		{
			if ((Object)(object)Mod.managerObject == (Object)null)
			{
				return false;
			}
			if (!ThreadManager.host)
			{
				return true;
			}
			return false;
		}

		public static bool IsHost()
		{
			if (CustomSosigLoaderPlugin.h3mpEnabled)
			{
				return isHosting();
			}
			return false;
		}

		private static bool isHosting()
		{
			if ((Object)(object)Mod.managerObject == (Object)null)
			{
				return false;
			}
			if (ThreadManager.host)
			{
				return true;
			}
			return false;
		}

		public static int GetPlayerCount()
		{
			if (CustomSosigLoaderPlugin.h3mpEnabled)
			{
				return GetNetworkPlayerCount();
			}
			return 1;
		}

		private static int GetNetworkPlayerCount()
		{
			return GameManager.players.Count;
		}

		public static int[] GetPlayerIDs()
		{
			int[] array = new int[GameManager.players.Count];
			int num = 0;
			foreach (KeyValuePair<int, PlayerManager> player in GameManager.players)
			{
				array[num] = player.Key;
				num++;
			}
			return array;
		}

		public static int GetLocalID()
		{
			return GameManager.ID;
		}

		public static int RegisterHostCustomPacket(string identifier)
		{
			if (Mod.registeredCustomPacketIDs.ContainsKey(identifier))
			{
				return Mod.registeredCustomPacketIDs[identifier];
			}
			return Server.RegisterCustomPacketType(identifier, 0);
		}

		public static PlayerData GetPlayer(int i)
		{
			return PlayerData.GetPlayer(i);
		}
	}
	public class PlayerData
	{
		public Transform head;

		public string username;

		public Transform handLeft;

		public Transform handRight;

		public int ID;

		public float health;

		public int iff;

		public static PlayerData GetPlayer(int i)
		{
			return new PlayerData
			{
				head = GameManager.players[i].head,
				username = GameManager.players[i].username,
				handLeft = GameManager.players[i].leftHand,
				handRight = GameManager.players[i].rightHand
			};
		}
	}
}
namespace CustomSosigLoader
{
	internal class Custom_SosigData
	{
		public static MeshRenderer GetSosigMeshRenderer(string title, Transform geoParent)
		{
			for (int i = 0; i < geoParent.childCount; i++)
			{
				if (((Object)geoParent.GetChild(i)).name == title)
				{
					return ((Component)geoParent.GetChild(i)).GetComponent<MeshRenderer>();
				}
			}
			return null;
		}

		public static void UpdateSosigLink(SosigLink link, Vector3 bodyScale, Vector3 linkScale, Material sosigMaterial, bool stopSever, MeshRenderer geo)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)link == (Object)null)
			{
				return;
			}
			CapsuleCollider val = (CapsuleCollider)link.C;
			val.height *= linkScale.y;
			val.radius *= ((linkScale.x > linkScale.z) ? linkScale.x : linkScale.z);
			CharacterJoint val2 = (((Object)(object)link.J != (Object)null) ? link.J : ((Component)link).GetComponent<CharacterJoint>());
			if (Object.op_Implicit((Object)(object)val2))
			{
				((Joint)val2).autoConfigureConnectedAnchor = false;
				((Joint)val2).anchor = new Vector3(0f, ((Joint)val2).anchor.y * bodyScale.y, 0f);
				((Joint)val2).connectedAnchor = new Vector3(0f, ((Joint)val2).connectedAnchor.y * bodyScale.y, 0f);
			}
			((Renderer)geo).sharedMaterial = sosigMaterial;
			((Component)geo).transform.localScale = linkScale;
			if (stopSever)
			{
				link.m_isJointSevered = true;
			}
			if (link.m_wearables.Count <= 0)
			{
				return;
			}
			foreach (SosigWearable wearable in link.m_wearables)
			{
				((Component)wearable).gameObject.transform.localScale = ((Component)geo).transform.localScale;
			}
		}
	}
	[Serializable]
	public class Custom_OutfitConfig
	{
		public string name;

		public string[] Headwear;

		public float Chance_Headwear = 0f;

		public bool HeadUsesTorsoIndex = false;

		public bool ForceWearAllHead = false;

		public string[] Eyewear;

		public float Chance_Eyewear = 0f;

		public bool ForceWearAllEye = false;

		public string[] Torsowear;

		public float Chance_Torsowear = 0f;

		public bool ForceWearAllTorso = false;

		public string[] Pantswear;

		public float Chance_Pantswear = 0f;

		public bool PantsUsesTorsoIndex = false;

		public bool ForceWearAllPants = false;

		public string[] Pantswear_Lower;

		public float Chance_Pantswear_Lower = 0f;

		public bool PantsLowerUsesPantsIndex = false;

		public bool ForceWearAllPantsLower = false;

		public string[] Backpacks;

		public float Chance_Backpacks = 0f;

		public bool ForceWearAllBackpacks = false;

		public string[] TorsoDecoration;

		public float Chance_TorsoDecoration = 0f;

		public bool ForceWearAllTorsoDecoration = false;

		public string[] Belt;

		public float Chance_Belt = 0f;

		public bool ForceWearAllBelt = false;

		public string[] Facewear;

		public float Chance_Facewear = 0f;

		public bool ForceWearAllFace = false;

		public SosigOutfitConfig Initialize()
		{
			SosigOutfitConfig val = ScriptableObject.CreateInstance<SosigOutfitConfig>();
			val.HeadUsesTorsoIndex = HeadUsesTorsoIndex;
			val.PantsUsesTorsoIndex = PantsUsesTorsoIndex;
			val.PantsLowerUsesPantsIndex = PantsLowerUsesPantsIndex;
			val.Headwear = new List<FVRObject>();
			Global.ItemIDToList(Headwear, val.Headwear);
			val.Eyewear = new List<FVRObject>();
			Global.ItemIDToList(Eyewear, val.Eyewear);
			val.Torsowear = new List<FVRObject>();
			Global.ItemIDToList(Torsowear, val.Torsowear);
			val.Pantswear = new List<FVRObject>();
			Global.ItemIDToList(Pantswear, val.Pantswear);
			val.Pantswear_Lower = new List<FVRObject>();
			Global.ItemIDToList(Pantswear_Lower, val.Pantswear_Lower);
			val.Backpacks = new List<FVRObject>();
			Global.ItemIDToList(Backpacks, val.Backpacks);
			val.TorosDecoration = new List<FVRObject>();
			Global.ItemIDToList(TorsoDecoration, val.TorosDecoration);
			val.Belt = new List<FVRObject>();
			Global.ItemIDToList(Belt, val.Belt);
			val.Facewear = new List<FVRObject>();
			Global.ItemIDToList(Facewear, val.Facewear);
			val.Chance_Headwear = Chance_Headwear;
			val.Chance_Eyewear = Chance_Eyewear;
			val.Chance_Torsowear = Chance_Torsowear;
			val.Chance_Pantswear = Chance_Pantswear;
			val.Chance_Pantswear_Lower = Chance_Pantswear_Lower;
			val.Chance_Backpacks = Chance_Backpacks;
			val.Chance_TorosDecoration = Chance_TorsoDecoration;
			val.Chance_Belt = Chance_Belt;
			val.Chance_Facewear = Chance_Facewear;
			return val;
		}
	}
	[Serializable]
	public class Custom_Sosig
	{
		public string name;

		public SosigEnemyID baseSosigID = (SosigEnemyID)0;

		public string voiceSet = "";

		public float voicePitch = 1.15f;

		public float voiceVolume = 0.4f;

		public Vector3 scaleBody = Vector3.one;

		public Vector3 scaleHead = Vector3.one;

		public Vector3 scaleTorso = Vector3.one;

		public Vector3 scaleLegsUpper = Vector3.one;

		public Vector3 scaleLegsLower = Vector3.one;

		public bool hideHeadMesh = false;

		public bool hideTorsoMesh = false;

		public bool hideLegsUpperMesh = false;

		public bool hideLegsLowerMesh = false;

		public string customSkin = "";

		public Color color;

		public float metallic = 0f;

		public float specularity = 0.3f;

		public float specularTint = 0f;

		public float roughness = 1f;

		public float normalStrength = 1f;

		public bool specularHighlights = true;

		public bool glossyReflections = true;

		public string directory;

		public Texture2D albedo;

		public Texture2D normalmap;

		public Texture2D masr;
	}
	[Serializable]
	public class Custom_SosigConfigTemplate
	{
		public string name;

		[Header("AIEntityParams")]
		public float ViewDistance = 250f;

		public Vector3 StateSightRangeMults = new Vector3(0.1f, 0.35f, 1f);

		public float HearingDistance = 300f;

		public Vector3 StateHearingRangeMults = new Vector3(0.6f, 1f, 1f);

		public float MaxFOV = 105f;

		public Vector3 StateFOVMults = new Vector3(0.5f, 0.6f, 1f);

		[Header("Core Identity Params")]
		public bool HasABrain = true;

		public bool RegistersPassiveThreats = false;

		public bool DoesAggroOnFriendlyFire = false;

		public float SearchExtentsModifier = 1f;

		public bool DoesDropWeaponsOnBallistic = true;

		public bool CanPickup_Ranged = true;

		public bool CanPickup_Melee = true;

		public bool CanPickup_Other = true;

		[Header("TargetPrioritySystemParams")]
		public int TargetCapacity = 5;

		public float TargetTrackingTime = 2f;

		public float NoFreshTargetTime = 1.5f;

		public float AssaultPointOverridesSkirmishPointWhenFurtherThan = 200f;

		public float TimeInSkirmishToAlert = 1f;

		[Header("Movement Params")]
		public float RunSpeed = 3.5f;

		public float WalkSpeed = 1.4f;

		public float SneakSpeed = 0.6f;

		public float CrawlSpeed = 0.3f;

		public float TurnSpeed = 2f;

		public float MaxJointLimit = 6f;

		public float MovementRotMagnitude = 10f;

		[Header("Damage Params")]
		public bool AppliesDamageResistToIntegrityLoss = false;

		public float TotalMustard = 100f;

		public float BleedDamageMult = 0.5f;

		public float BleedRateMultiplier = 1f;

		public float BleedVFXIntensity = 0.2f;

		public float DamMult_Projectile = 1f;

		public float DamMult_Explosive = 1f;

		public float DamMult_Melee = 1f;

		public float DamMult_Piercing = 1f;

		public float DamMult_Blunt = 1f;

		public float DamMult_Cutting = 1f;

		public float DamMult_Thermal = 1f;

		public float DamMult_Chilling = 1f;

		public float DamMult_EMP = 1f;

		public List<float> LinkDamageMultipliers;

		public List<float> LinkStaggerMultipliers;

		public List<Vector2> StartingLinkIntegrity;

		public List<float> StartingChanceBrokenJoint;

		[Header("Shudder Params")]
		public float ShudderThreshold = 2f;

		[Header("Confusion Params")]
		public float ConfusionThreshold = 0.3f;

		public float ConfusionMultiplier = 6f;

		public float ConfusionTimeMax = 4f;

		[Header("Stun Params")]
		public float StunThreshold = 1.4f;

		public float StunMultiplier = 2f;

		public float StunTimeMax = 4f;

		[Header("Unconsciousness Params")]
		public bool CanBeKnockedOut = true;

		public float MaxUnconsciousTime = 90f;

		[Header("Resistances")]
		public bool CanBeGrabbed = true;

		public bool CanBeSevered = true;

		public bool CanBeStabbed = true;

		[Header("Suppression")]
		public bool CanBeSurpressed = true;

		public float SuppressionMult = 1f;

		[Header("Death Flags")]
		public bool DoesJointBreakKill_Head = true;

		public bool DoesJointBreakKill_Upper = false;

		public bool DoesJointBreakKill_Lower = false;

		public bool DoesSeverKill_Head = true;

		public bool DoesSeverKill_Upper = true;

		public bool DoesSeverKill_Lower = true;

		public bool DoesExplodeKill_Head = true;

		public bool DoesExplodeKill_Upper = true;

		public bool DoesExplodeKill_Lower = true;

		[Header("SpawnOnLinkDestroy")]
		public bool UsesLinkSpawns = false;

		public List<string> LinkSpawns;

		public List<float> LinkSpawnChance;

		public SosigConfigTemplate Initialize()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			SosigConfigTemplate val = ScriptableObject.CreateInstance<SosigConfigTemplate>();
			val.ViewDistance = ViewDistance;
			val.StateSightRangeMults = StateSightRangeMults;
			val.HearingDistance = HearingDistance;
			val.StateHearingRangeMults = StateHearingRangeMults;
			val.MaxFOV = MaxFOV;
			val.StateFOVMults = StateFOVMults;
			val.HasABrain = HasABrain;
			val.RegistersPassiveThreats = RegistersPassiveThreats;
			val.DoesAggroOnFriendlyFire = DoesAggroOnFriendlyFire;
			val.SearchExtentsModifier = SearchExtentsModifier;
			val.DoesDropWeaponsOnBallistic = DoesDropWeaponsOnBallistic;
			val.CanPickup_Ranged = CanPickup_Ranged;
			val.CanPickup_Melee = CanPickup_Melee;
			val.CanPickup_Other = CanPickup_Other;
			val.TargetCapacity = TargetCapacity;
			val.TargetTrackingTime = TargetTrackingTime;
			val.NoFreshTargetTime = NoFreshTargetTime;
			val.AssaultPointOverridesSkirmishPointWhenFurtherThan = AssaultPointOverridesSkirmishPointWhenFurtherThan;
			val.RunSpeed = RunSpeed;
			val.WalkSpeed = WalkSpeed;
			val.SneakSpeed = SneakSpeed;
			val.CrawlSpeed = CrawlSpeed;
			val.TurnSpeed = TurnSpeed;
			val.MaxJointLimit = MaxJointLimit;
			val.MovementRotMagnitude = MovementRotMagnitude;
			val.AppliesDamageResistToIntegrityLoss = AppliesDamageResistToIntegrityLoss;
			val.TotalMustard = TotalMustard;
			val.BleedDamageMult = BleedDamageMult;
			val.BleedRateMultiplier = BleedRateMultiplier;
			val.BleedVFXIntensity = BleedVFXIntensity;
			val.DamMult_Projectile = DamMult_Projectile;
			val.DamMult_Explosive = DamMult_Explosive;
			val.DamMult_Melee = DamMult_Melee;
			val.DamMult_Piercing = DamMult_Piercing;
			val.DamMult_Blunt = DamMult_Blunt;
			val.DamMult_Cutting = DamMult_Cutting;
			val.DamMult_Thermal = DamMult_Thermal;
			val.DamMult_Chilling = DamMult_Chilling;
			val.DamMult_EMP = DamMult_EMP;
			val.LinkDamageMultipliers = LinkDamageMultipliers;
			val.LinkStaggerMultipliers = LinkStaggerMultipliers;
			val.StartingLinkIntegrity = StartingLinkIntegrity;
			val.StartingChanceBrokenJoint = StartingChanceBrokenJoint;
			val.ShudderThreshold = ShudderThreshold;
			val.ConfusionThreshold = ConfusionThreshold;
			val.ConfusionMultiplier = ConfusionMultiplier;
			val.ConfusionTimeMax = ConfusionTimeMax;
			val.StunThreshold = StunThreshold;
			val.StunMultiplier = StunMultiplier;
			val.StunTimeMax = StunTimeMax;
			val.CanBeKnockedOut = CanBeKnockedOut;
			val.MaxUnconsciousTime = MaxUnconsciousTime;
			val.CanBeGrabbed = CanBeGrabbed;
			val.CanBeSevered = CanBeSevered;
			val.CanBeStabbed = CanBeStabbed;
			val.CanBeSurpressed = CanBeSurpressed;
			val.SuppressionMult = SuppressionMult;
			val.DoesJointBreakKill_Head = DoesJointBreakKill_Head;
			val.DoesJointBreakKill_Upper = DoesJointBreakKill_Upper;
			val.DoesJointBreakKill_Lower = DoesJointBreakKill_Lower;
			val.DoesSeverKill_Head = DoesSeverKill_Head;
			val.DoesSeverKill_Upper = DoesSeverKill_Upper;
			val.DoesSeverKill_Lower = DoesSeverKill_Lower;
			val.DoesExplodeKill_Head = DoesExplodeKill_Head;
			val.DoesExplodeKill_Upper = DoesExplodeKill_Upper;
			val.DoesExplodeKill_Lower = DoesExplodeKill_Lower;
			val.UsesLinkSpawns = UsesLinkSpawns;
			Global.ItemIDToList(LinkSpawns.ToArray(), val.LinkSpawns);
			val.LinkSpawnChance = LinkSpawnChance;
			return val;
		}
	}
	[Serializable]
	public class Custom_SosigEnemyTemplate
	{
		public string DisplayName = "New Sosig";

		public int SosigEnemyCategory = 0;

		public int SosigEnemyID = -1;

		public Custom_Sosig[] CustomSosigs;

		public Custom_OutfitConfig[] OutfitConfigs;

		public Custom_SosigConfigTemplate[] Configs;

		public Custom_SosigConfigTemplate[] ConfigsEasy;

		public string[] WeaponOptions;

		public string[] WeaponOptionsSecondary;

		public string[] WeaponOptionsTertiary;

		public float SecondaryChance = 0f;

		public float TertiaryChance = 0f;

		public SosigEnemyTemplate Initialize()
		{
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			SosigEnemyTemplate val = ScriptableObject.CreateInstance<SosigEnemyTemplate>();
			val.OutfitConfig = new List<SosigOutfitConfig>();
			for (int i = 0; i < OutfitConfigs.Length; i++)
			{
				val.OutfitConfig.Add(OutfitConfigs[i].Initialize());
			}
			val.ConfigTemplates = new List<SosigConfigTemplate>();
			for (int j = 0; j < Configs.Length; j++)
			{
				val.ConfigTemplates.Add(Configs[j].Initialize());
			}
			val.ConfigTemplates_Easy = new List<SosigConfigTemplate>();
			if (ConfigsEasy.Length != 0)
			{
				for (int k = 0; k < ConfigsEasy.Length; k++)
				{
					val.ConfigTemplates.Add(ConfigsEasy[k].Initialize());
				}
			}
			else
			{
				val.ConfigTemplates_Easy.AddRange(val.ConfigTemplates);
			}
			val.SosigPrefabs = new List<FVRObject>();
			for (int l = 0; l < CustomSosigs.Length; l++)
			{
				SosigEnemyTemplate val2 = ManagerSingleton<IM>.Instance.odicSosigObjsByID[CustomSosigs[l].baseSosigID];
				FVRObject item = val2.SosigPrefabs[Random.Range(0, val2.SosigPrefabs.Count)];
				val.SosigPrefabs.Add(item);
			}
			val.WeaponOptions = new List<FVRObject>();
			Global.ItemIDToList(WeaponOptions, val.WeaponOptions);
			val.WeaponOptions_Secondary = new List<FVRObject>();
			Global.ItemIDToList(WeaponOptionsSecondary, val.WeaponOptions_Secondary);
			val.WeaponOptions_Tertiary = new List<FVRObject>();
			Global.ItemIDToList(WeaponOptionsTertiary, val.WeaponOptions_Tertiary);
			val.SecondaryChance = SecondaryChance;
			val.TertiaryChance = TertiaryChance;
			return val;
		}

		public void ExportJson()
		{
			using StreamWriter streamWriter = new StreamWriter(Paths.PluginPath + "\\Sosig_Squad-SupplyRaid\\" + DisplayName + ".json");
			string value = JsonUtility.ToJson((object)this, true);
			streamWriter.Write(value);
		}
	}
	internal class Global
	{
		public class SosigMaterial
		{
			public string name;

			public Texture2D albedo;

			public Texture2D normal;

			public Texture masr;
		}

		public static Texture2D whiteSosig;

		public static List<SosigMaterial> sosigMaterials;

		public static List<string> GetCustomSosigDirectories()
		{
			return Directory.GetFiles(Paths.PluginPath, "*.csosig", SearchOption.AllDirectories).ToList();
		}

		public static void LoadCustomSosigs()
		{
			List<string> customSosigDirectories = GetCustomSosigDirectories();
			if (customSosigDirectories.Count == 0)
			{
				CustomSosigLoaderPlugin.Logger.LogInfo((object)"No Custom Sosigs were found!");
				return;
			}
			for (int i = 0; i < customSosigDirectories.Count; i++)
			{
				using StreamReader streamReader = new StreamReader(customSosigDirectories[i]);
				string text = streamReader.ReadToEnd();
				Custom_SosigEnemyTemplate custom_SosigEnemyTemplate;
				try
				{
					custom_SosigEnemyTemplate = JsonUtility.FromJson<Custom_SosigEnemyTemplate>(text);
				}
				catch (Exception ex)
				{
					CustomSosigLoaderPlugin.Logger.LogInfo((object)ex.Message);
					break;
				}
				for (int j = 0; j < custom_SosigEnemyTemplate.CustomSosigs.Length; j++)
				{
					custom_SosigEnemyTemplate.CustomSosigs[j].directory = customSosigDirectories[i];
				}
				CustomSosigLoaderPlugin.customSosigs.Add(custom_SosigEnemyTemplate.SosigEnemyID, custom_SosigEnemyTemplate);
				CustomSosigLoaderPlugin.Logger.LogInfo((object)("Custom Sosig Loader - Loaded " + custom_SosigEnemyTemplate.SosigEnemyID + " - " + custom_SosigEnemyTemplate.DisplayName));
			}
		}

		public static void LoadSosigMaterial(Custom_Sosig customSosig)
		{
			if (!(customSosig.customSkin == "CustomSosig_Base"))
			{
				string text = Path.GetDirectoryName(customSosig.directory) + customSosig.customSkin;
				customSosig.albedo = LoadTexture(text + ".png");
				customSosig.normalmap = LoadTexture(text + "_Normal.png");
				customSosig.masr = LoadTexture(text + "_MARS.png");
			}
		}

		public static void ItemIDToList(string[] itemIDs, List<FVRObject> input)
		{
			if (itemIDs == null)
			{
				CustomSosigLoaderPlugin.Logger.LogInfo((object)"Item IDs missing");
				return;
			}
			for (int i = 0; i < itemIDs.Length; i++)
			{
				if (IM.OD.ContainsKey(itemIDs[i]) && IM.OD.TryGetValue(itemIDs[i], out var value))
				{
					input.Add(value);
				}
				else
				{
					CustomSosigLoaderPlugin.Logger.LogInfo((object)("Custom Sosig Loader - Could not find |" + itemIDs[i] + "|"));
				}
			}
		}

		public static Texture2D LoadTexture(string path)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			Texture2D val = null;
			if (File.Exists(path) && (Object)(object)val == (Object)null)
			{
				byte[] array = File.ReadAllBytes(path);
				val = new Texture2D(2, 2);
				val.LoadImage(array);
			}
			if ((Object)(object)val == (Object)null)
			{
				CustomSosigLoaderPlugin.Logger.LogError((object)("Custom Sosig Loader - Texture Not Found: " + path));
				return null;
			}
			return val;
		}

		public static void LoadWhiteSosigTexture(string textureName)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			string text = Paths.PluginPath + "\\Sosig_Squad-Custom_Sosig_Loader\\" + textureName;
			Texture2D val = null;
			if (File.Exists(text) && (Object)(object)val == (Object)null)
			{
				byte[] array = File.ReadAllBytes(text);
				val = new Texture2D(2, 2);
				val.LoadImage(array);
			}
			if ((Object)(object)val == (Object)null)
			{
				CustomSosigLoaderPlugin.Logger.LogError((object)("Custom Sosig Loader - Texture Not Found: " + text));
				whiteSosig = null;
			}
			((Object)val).name = textureName;
			whiteSosig = val;
		}

		public static void LoadCustomVoiceLines()
		{
			CustomSosigLoaderPlugin.Logger.LogInfo((object)"Loading Custom Voice Lines");
			try
			{
				string[] directories = Directory.GetDirectories(Paths.PluginPath, "*", SearchOption.AllDirectories);
				List<string> list = new List<string>();
				string[] array = directories;
				foreach (string text in array)
				{
					string text2 = Path.Combine(text, "voicelines");
					if (!Directory.Exists(text2))
					{
						continue;
					}
					string[] files = Directory.GetFiles(text, "*.yaml", SearchOption.TopDirectoryOnly);
					if (files.Length == 0)
					{
						continue;
					}
					string[] array2 = files;
					foreach (string yamlFilePath in array2)
					{
						VoiceSet voicelines = GetVoicelines(yamlFilePath);
						string name = voicelines.name;
						float pitch = voicelines.pitch;
						float volume = voicelines.volume;
						if (!string.IsNullOrEmpty(name) && !list.Contains(name))
						{
							SosigSpeechSet val = ScriptableObject.CreateInstance<SosigSpeechSet>();
							((Object)val).name = name;
							val.BasePitch = pitch;
							val.BaseVolume = volume;
							val.OnAssault = new List<AudioClip>();
							val.OnBackBreak = new List<AudioClip>();
							val.OnBeingAimedAt = new List<AudioClip>();
							val.OnCall_Assistance = new List<AudioClip>();
							val.OnCall_Skirmish = new List<AudioClip>();
							val.OnConfusion = new List<AudioClip>();
							val.OnDeath = new List<AudioClip>();
							val.OnDeathAlt = new List<AudioClip>();
							val.OnInvestigate = new List<AudioClip>();
							val.OnJointBreak = new List<AudioClip>();
							val.OnJointSever = new List<AudioClip>();
							val.OnJointSlice = new List<AudioClip>();
							val.OnMedic = new List<AudioClip>();
							val.OnNeckBreak = new List<AudioClip>();
							val.OnPain = new List<AudioClip>();
							val.OnReloading = new List<AudioClip>();
							val.OnRespond_Assistance = new List<AudioClip>();
							val.OnRespond_Skirmish = new List<AudioClip>();
							val.OnSearchingForGuns = new List<AudioClip>();
							val.OnSkirmish = new List<AudioClip>();
							val.OnTakingCover = new List<AudioClip>();
							val.OnWander = new List<AudioClip>();
							val.Test = new List<AudioClip>();
							list.Add(name);
							AddAllAudioFromDirectory(Path.Combine(text2, "state_wander"), val.OnWander);
							AddAllAudioFromDirectory(Path.Combine(text2, "state_skirmish"), val.OnSkirmish);
							AddAllAudioFromDirectory(Path.Combine(text2, "state_reload"), val.OnReloading);
							AddAllAudioFromDirectory(Path.Combine(text2, "state_investigate"), val.OnInvestigate);
							AddAllAudioFromDirectory(Path.Combine(text2, "pain_joint_slice"), val.OnJointSlice);
							AddAllAudioFromDirectory(Path.Combine(text2, "pain_joint_sever"), val.OnJointSever);
							AddAllAudioFromDirectory(Path.Combine(text2, "pain_joint_break"), val.OnJointBreak);
							AddAllAudioFromDirectory(Path.Combine(text2, "pain_default"), val.OnPain);
							AddAllAudioFromDirectory(Path.Combine(text2, "pain_break_neck"), val.OnNeckBreak);
							AddAllAudioFromDirectory(Path.Combine(text2, "pain_break_back"), val.OnBackBreak);
							CustomSosigLoaderPlugin.customVoicelines.Add(name, val);
							CustomSosigLoaderPlugin.Logger.LogInfo((object)("Custom Sosig Loader: Loaded voicelines - " + name));
							break;
						}
					}
				}
			}
			catch (Exception ex)
			{
				Console.WriteLine("An error occurred: " + ex.Message);
			}
		}

		public static void AddAllAudioFromDirectory(string path, List<AudioClip> list)
		{
			string[] files = Directory.GetFiles(path, "*.wav", SearchOption.TopDirectoryOnly);
			string[] array = files;
			foreach (string filePath in array)
			{
				AudioClip val = LoadWav(filePath);
				if ((Object)(object)val != (Object)null)
				{
					list.Add(val);
				}
			}
		}

		public static AudioClip LoadWav(string filePath)
		{
			try
			{
				return WavUtility.ToAudioClip(filePath);
			}
			catch (Exception ex)
			{
				CustomSosigLoaderPlugin.Logger.LogError((object)("An error occurred while loading the .wav file: " + ex.Message));
				return null;
			}
		}

		private static VoiceSet GetVoicelines(string yamlFilePath)
		{
			try
			{
				VoiceSet voiceSet = new VoiceSet();
				string[] array = File.ReadAllLines(yamlFilePath);
				string[] array2 = array;
				foreach (string text in array2)
				{
					if (text.Trim().StartsWith("name:"))
					{
						voiceSet.name = text.Substring(text.IndexOf("name: ") + "name:".Length).Trim();
					}
					if (text.Trim().StartsWith("base_pitch:"))
					{
						voiceSet.pitch = float.Parse(text.Substring(text.IndexOf("base_pitch: ") + "base_pitch:".Length).Trim());
					}
					if (text.Trim().StartsWith("base_volume:"))
					{
						voiceSet.volume = float.Parse(text.Substring(text.IndexOf("base_volume: ") + "base_volume:".Length).Trim());
					}
				}
				return voiceSet;
			}
			catch (Exception ex)
			{
				Console.WriteLine("Custom Sosig Loader: An error occurred while reading the file: " + ex.Message);
			}
			return null;
		}
	}
	public class VoiceSet
	{
		public string name = "";

		public float pitch = 1.15f;

		public float volume = 0.4f;
	}
	public class SosigMP : MonoBehaviour
	{
		public static SosigMP instance;

		private int sosigUpdate_ID = -1;

		private void Awake()
		{
			instance = this;
		}

		public void Start()
		{
			if (CustomSosigLoaderPlugin.h3mpEnabled)
			{
				StartNetworking();
			}
		}

		private void StartNetworking()
		{
			if (Networking.ServerRunning() && (Networking.IsHost() || Client.isFullyConnected))
			{
				SetupPacketTypes();
			}
		}

		private void SetupPacketTypes()
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			if (Networking.IsHost())
			{
				if (Mod.registeredCustomPacketIDs.ContainsKey("CSL_Update"))
				{
					sosigUpdate_ID = Mod.registeredCustomPacketIDs["CSL_Update"];
				}
				else
				{
					sosigUpdate_ID = Server.RegisterCustomPacketType("CSL_Update", 0);
				}
				Mod.customPacketHandlers[sosigUpdate_ID] = new CustomPacketHandler(CustomSosig_Handler);
			}
			else if (Mod.registeredCustomPacketIDs.ContainsKey("CSL_Update"))
			{
				sosigUpdate_ID = Mod.registeredCustomPacketIDs["CSL_Update"];
				Mod.customPacketHandlers[sosigUpdate_ID] = new CustomPacketHandler(CustomSosig_Handler);
			}
			else
			{
				ClientSend.RegisterCustomPacketType("CSL_Update");
				Mod.CustomPacketHandlerReceived += new CustomPacketHandlerReceivedDelegate(CustomSosig_Received);
			}
		}

		public void CustomSosig_Send(Sosig sosig, int sosigID, int customIndex)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			TrackedSosig component = ((Component)sosig).gameObject.GetComponent<TrackedSosig>();
			if (Networking.ServerRunning() && !Networking.IsClient() && !Object.op_Implicit((Object)(object)component))
			{
				Packet val = new Packet(sosigUpdate_ID);
				val.Write(((TrackedObjectData)component.sosigData).trackedID);
				val.Write(sosigID);
				val.Write(customIndex);
				ServerSend.SendTCPDataToAll(val, true);
				Debug.Log((object)("Server - Sending Custom sosig data to " + ((TrackedObject)component).data.trackedID + " ID: " + sosigID));
			}
		}

		private void CustomSosig_Handler(int clientID, Packet packet)
		{
			int num = packet.ReadInt(true);
			int num2 = packet.ReadInt(true);
			int customIndex = packet.ReadInt(true);
			Debug.Log((object)("Client - Sosig data: " + num + " ID " + num2));
			if (Client.objects.Length > num && Client.objects[num] != null)
			{
				Sosig component = ((Component)Client.objects[num].physical).gameObject.GetComponent<Sosig>();
				CustomSosigLoaderPlugin.customSosigIDs.TryGetValue((SosigEnemyID)num2, out var value);
				Hooks.SetupCustomSosig(component, value, customIndex);
			}
		}

		private void CustomSosig_Received(string identifier, int index)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			if (identifier == "CSL_Update")
			{
				sosigUpdate_ID = index;
				Mod.customPacketHandlers[index] = new CustomPacketHandler(CustomSosig_Handler);
				Mod.CustomPacketHandlerReceived -= new CustomPacketHandlerReceivedDelegate(CustomSosig_Received);
			}
		}
	}
	[HarmonyPatch]
	internal static class Hooks
	{
		[HarmonyPatch(typeof(Sosig))]
		[HarmonyPatch("Configure")]
		[HarmonyPrefix]
		public static void Configure_Prefix(Sosig __instance, SosigConfigTemplate t)
		{
			SetupCustomSosig(__instance, t);
		}

		public static void SetupCustomSosig(Sosig sosig, SosigConfigTemplate t, int customIndex = -1)
		{
			//IL_001e: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected I4, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected I4, but got Unknown
			if (!CustomSosigLoaderPlugin.customSosigConfigs.ContainsKey(t))
			{
				return;
			}
			SosigEnemyID valueOrDefault = CustomSosigLoaderPlugin.customSosigConfigs.GetValueOrDefault(t);
			if ((int)valueOrDefault <= 0)
			{
				return;
			}
			int key = (int)valueOrDefault;
			if (!CustomSosigLoaderPlugin.customSosigs.ContainsKey(key))
			{
				return;
			}
			Custom_SosigEnemyTemplate valueOrDefault2 = CustomSosigLoaderPlugin.customSosigs.GetValueOrDefault(key);
			if (valueOrDefault2 != null)
			{
				if (customIndex == -1)
				{
					customIndex = Random.Range(0, valueOrDefault2.CustomSosigs.Length);
				}
				ModifySosig(sosig, valueOrDefault2, customIndex);
				if (CustomSosigLoaderPlugin.h3mpEnabled && Networking.IsHost())
				{
					SosigMP.instance.CustomSosig_Send(sosig, (int)valueOrDefault, customIndex);
				}
			}
		}

		public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
		{
			dictionary.TryGetValue(key, out var value);
			return value;
		}

		public static void ModifySosig(Sosig sosig, Custom_SosigEnemyTemplate template, int customIndex)
		{
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Expected O, but got Unknown
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Expected O, but got Unknown
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c5: Expected O, but got Unknown
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Expected O, but got Unknown
			if (template == null)
			{
				CustomSosigLoaderPlugin.Logger.LogInfo((object)"Missing Template");
			}
			Custom_Sosig custom_Sosig = template.CustomSosigs[customIndex];
			Custom_SosigConfigTemplate custom_SosigConfigTemplate = template.Configs[Random.Range(0, template.Configs.Length)];
			bool flag = custom_SosigConfigTemplate.CanBeSevered;
			if (!flag && (custom_Sosig.scaleHead.y * custom_Sosig.scaleBody.y > 1f || custom_Sosig.scaleTorso.y * custom_Sosig.scaleBody.y > 1f || custom_Sosig.scaleLegsUpper.y * custom_Sosig.scaleBody.y > 1f || custom_Sosig.scaleLegsLower.y * custom_Sosig.scaleBody.y > 1f))
			{
				flag = true;
			}
			MeshRenderer sosigMeshRenderer = Custom_SosigData.GetSosigMeshRenderer("Geo_Head", ((Component)sosig.Links[0]).transform);
			MeshRenderer sosigMeshRenderer2 = Custom_SosigData.GetSosigMeshRenderer("Geo_Torso", ((Component)sosig.Links[1]).transform);
			MeshRenderer sosigMeshRenderer3 = Custom_SosigData.GetSosigMeshRenderer("Geo_UpperLink", ((Component)sosig.Links[2]).transform);
			MeshRenderer sosigMeshRenderer4 = Custom_SosigData.GetSosigMeshRenderer("Geo_LowerLink", ((Component)sosig.Links[3]).transform);
			((Renderer)sosigMeshRenderer).enabled = !custom_Sosig.hideHeadMesh;
			((Renderer)sosigMeshRenderer2).enabled = !custom_Sosig.hideTorsoMesh;
			((Renderer)sosigMeshRenderer3).enabled = !custom_Sosig.hideLegsUpperMesh;
			((Renderer)sosigMeshRenderer4).enabled = !custom_Sosig.hideLegsLowerMesh;
			Material material = ((Renderer)sosigMeshRenderer).material;
			if (custom_Sosig.customSkin.Contains("CustomSosig_Base"))
			{
				material.SetTexture("_MainTex", (Texture)(object)CustomSosigLoaderPlugin.customSosigTexture);
			}
			else if (custom_Sosig.customSkin != "")
			{
				if (Object.op_Implicit((Object)(object)custom_Sosig.albedo))
				{
					material.SetTexture("_MainTex", (Texture)(object)custom_Sosig.albedo);
				}
				if (Object.op_Implicit((Object)(object)custom_Sosig.normalmap))
				{
					material.SetTexture("_BumpMap", (Texture)(object)custom_Sosig.normalmap);
				}
				if (Object.op_Implicit((Object)(object)custom_Sosig.masr))
				{
					material.SetTexture("_SpecTex", (Texture)(object)custom_Sosig.masr);
				}
			}
			material.SetColor("_Color", custom_Sosig.color);
			material.SetFloat("_Metallic", custom_Sosig.metallic);
			material.SetFloat("_Specularity", custom_Sosig.specularity);
			material.SetFloat("_SpecularTint", custom_Sosig.specularTint);
			material.SetFloat("_Roughness", custom_Sosig.roughness);
			material.SetFloat("_BumpScale", custom_Sosig.normalStrength);
			material.SetInt("_SpecularHighlights", custom_Sosig.specularHighlights ? 1 : 0);
			material.SetInt("_GlossyReflections", custom_Sosig.glossyReflections ? 1 : 0);
			((Renderer)sosigMeshRenderer).sharedMaterial = material;
			sosig.GibMaterial = material;
			if (sosig.Links.Count >= 1)
			{
				Custom_SosigData.UpdateSosigLink(sosig.Links[0], custom_Sosig.scaleBody, custom_Sosig.scaleHead, material, flag, (MeshRenderer)sosig.Renderers[0]);
			}
			if (sosig.Links.Count >= 2)
			{
				Custom_SosigData.UpdateSosigLink(sosig.Links[1], custom_Sosig.scaleBody, custom_Sosig.scaleTorso, material, flag, (MeshRenderer)sosig.Renderers[1]);
			}
			if (sosig.Links.Count >= 3)
			{
				Custom_SosigData.UpdateSosigLink(sosig.Links[2], custom_Sosig.scaleBody, custom_Sosig.scaleLegsUpper, material, flag, (MeshRenderer)sosig.Renderers[2]);
			}
			if (sosig.Links.Count >= 4)
			{
				Custom_SosigData.UpdateSosigLink(sosig.Links[3], custom_Sosig.scaleBody, custom_Sosig.scaleLegsUpper, material, flag, (MeshRenderer)sosig.Renderers[3]);
			}
			((Component)sosig).transform.localScale = custom_Sosig.scaleBody;
			float num = ((custom_Sosig.scaleBody.x > custom_Sosig.scaleBody.z) ? custom_Sosig.scaleBody.x : custom_Sosig.scaleBody.z);
			if (num > sosig.Agent.radius)
			{
				sosig.Agent.radius = sosig.Agent.radius * ((custom_Sosig.scaleBody.x > custom_Sosig.scaleBody.z) ? custom_Sosig.scaleBody.x : custom_Sosig.scaleBody.z);
			}
			NavMeshAgent agent = sosig.Agent;
			agent.height *= custom_Sosig.scaleBody.y;
			if (custom_Sosig.voiceSet != "")
			{
				CustomSosigLoaderPlugin.customVoicelines.TryGetValue(custom_Sosig.voiceSet, out var value);
				if ((Object)(object)value != (Object)null)
				{
					sosig.Speech = value;
				}
			}
			else if (custom_Sosig.voicePitch != 1.15f || custom_Sosig.voiceVolume != 0.4f)
			{
				SosigSpeechSet val = ScriptableObject.CreateInstance<SosigSpeechSet>();
				val.OnAssault = sosig.Speech.OnAssault;
				val.OnBackBreak = sosig.Speech.OnBackBreak;
				val.OnBeingAimedAt = sosig.Speech.OnBeingAimedAt;
				val.OnCall_Assistance = sosig.Speech.OnCall_Assistance;
				val.OnCall_Skirmish = sosig.Speech.OnCall_Skirmish;
				val.OnConfusion = sosig.Speech.OnConfusion;
				val.OnDeath = sosig.Speech.OnDeath;
				val.OnDeathAlt = sosig.Speech.OnDeathAlt;
				val.OnInvestigate = sosig.Speech.OnInvestigate;
				val.OnJointBreak = sosig.Speech.OnJointBreak;
				val.OnJointSever = sosig.Speech.OnJointSever;
				val.OnJointSlice = sosig.Speech.OnJointSlice;
				val.OnMedic = sosig.Speech.OnMedic;
				val.OnNeckBreak = sosig.Speech.OnNeckBreak;
				val.OnPain = sosig.Speech.OnPain;
				val.OnReloading = sosig.Speech.OnReloading;
				val.OnRespond_Assistance = sosig.Speech.OnRespond_Assistance;
				val.OnRespond_Skirmish = sosig.Speech.OnRespond_Skirmish;
				val.OnSearchingForGuns = sosig.Speech.OnSearchingForGuns;
				val.OnSkirmish = sosig.Speech.OnSkirmish;
				val.OnTakingCover = sosig.Speech.OnTakingCover;
				val.OnWander = sosig.Speech.OnWander;
				val.Test = sosig.Speech.Test;
				val.LessTalkativeSkirmish = sosig.Speech.LessTalkativeSkirmish;
				val.UseAltDeathOnHeadExplode = sosig.Speech.UseAltDeathOnHeadExplode;
				val.ForceDeathSpeech = sosig.Speech.ForceDeathSpeech;
				val.BasePitch = custom_Sosig.voicePitch;
				val.BaseVolume = custom_Sosig.voiceVolume;
				sosig.Speech = val;
			}
		}
	}
	[BepInPlugin("Sosig_Squad.CustomSosigLoader", "Custom Sosig Loader", "1.0.2")]
	[BepInProcess("h3vr.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class CustomSosigLoaderPlugin : BaseUnityPlugin
	{
		public delegate void SosigsLoadedComplete();

		public static bool h3mpEnabled = false;

		public static bool supplyRaidEnabled = false;

		public static bool otherLoaderEnabled = false;

		public static bool tnhFramework = false;

		public static bool CustomSosigsLoaded = false;

		public static SosigMP sosigMP;

		public static Dictionary<int, Custom_SosigEnemyTemplate> customSosigs = new Dictionary<int, Custom_SosigEnemyTemplate>();

		public static Dictionary<SosigConfigTemplate, SosigEnemyID> customSosigConfigs = new Dictionary<SosigConfigTemplate, SosigEnemyID>();

		public static Dictionary<SosigEnemyID, SosigConfigTemplate> customSosigIDs = new Dictionary<SosigEnemyID, SosigConfigTemplate>();

		public static Texture2D customSosigTexture;

		public static Dictionary<string, SosigSpeechSet> customVoicelines = new Dictionary<string, SosigSpeechSet>();

		public static bool screenshotSosigs = false;

		public static bool screenshotSosigGear = false;

		internal static ManualLogSource Logger { get; private set; }

		public static event SosigsLoadedComplete SosigsLoadedCompleted;

		private void Awake()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			h3mpEnabled = Chainloader.PluginInfos.ContainsKey("VIP.TommySoucy.H3MP");
			supplyRaidEnabled = Chainloader.PluginInfos.ContainsKey("com.Packer.SupplyRaid");
			otherLoaderEnabled = Chainloader.PluginInfos.ContainsKey("h3vr.otherloader");
			tnhFramework = Chainloader.PluginInfos.ContainsKey("h3vr.tnhframework");
			LoaderStatus.ProgressUpdated += new StatusUpdate(LoadCustomSosigCheck);
		}

		private void Start()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (h3mpEnabled)
			{
				sosigMP = new GameObject().AddComponent<SosigMP>();
				Object.DontDestroyOnLoad((Object)(object)((Component)sosigMP).gameObject);
			}
		}

		private void OnDestroy()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			LoaderStatus.ProgressUpdated -= new StatusUpdate(LoadCustomSosigCheck);
		}

		private void LoadCustomSosigs()
		{
			Logger.LogInfo((object)"Custom Sosig Loader: Loading Sosigs");
			Logger.LogInfo((object)"Custom Sosig Loader: Start Sosig Capture - Right Shift + O");
			Logger.LogInfo((object)"Custom Sosig Loader: Stop Sosig Capture - Right Shift + P");
			Logger.LogInfo((object)"Custom Sosig Loader: Start Gear Capture - Right Shift + U");
			Logger.LogInfo((object)"Custom Sosig Loader: Stop Gear Capture - Right Shift + I");
			Global.LoadCustomVoiceLines();
			Global.LoadWhiteSosigTexture("CustomSosig_Base.png");
			Global.LoadCustomSosigs();
			((MonoBehaviour)this).StartCoroutine(SetupSosigTemplates());
			Harmony.CreateAndPatchAll(typeof(Hooks), (string)null);
		}

		private void LoadCustomSosigCheck(float progress)
		{
			if (!CustomSosigsLoaded && !(progress < 1f))
			{
				LoadCustomSosigs();
				CustomSosigsLoaded = true;
			}
		}

		private void Update()
		{
			if (Input.GetKey((KeyCode)303) && Input.GetKeyUp((KeyCode)116))
			{
				Logger.LogInfo((object)"Printing all Sosig Clothing");
				PrintAllFVRObjects();
			}
			if (Input.GetKey((KeyCode)303) && Input.GetKeyUp((KeyCode)111))
			{
				Logger.LogInfo((object)"Right Shift + O Pressed - Start Sosig Capture");
				if (!screenshotSosigs)
				{
					screenshotSosigs = true;
					((MonoBehaviour)this).StartCoroutine(SosigScreenshots.RunSosigCapture());
				}
			}
			if (Input.GetKey((KeyCode)303) && Input.GetKeyUp((KeyCode)112))
			{
				Logger.LogInfo((object)"Right Shift + P Pressed - Stop Sosig Capture");
				screenshotSosigs = false;
			}
			if (Input.GetKey((KeyCode)303) && Input.GetKeyUp((KeyCode)117))
			{
				Logger.LogInfo((object)"Right Shift + U Pressed - Start Gear Capture");
				if (!screenshotSosigGear)
				{
					screenshotSosigGear = true;
					((MonoBehaviour)this).StartCoroutine(SosigScreenshots.RunSosigGearCapture());
				}
			}
			if (Input.GetKey((KeyCode)303) && Input.GetKeyUp((KeyCode)105))
			{
				Logger.LogInfo((object)"Right Shift + I Pressed - Stop Gear Capture");
				screenshotSosigGear = false;
			}
		}

		public IEnumerator SetupSosigTemplates()
		{
			Logger.LogInfo((object)("Custom Sosigs count: " + customSosigs.Count));
			Logger.LogInfo((object)("Sosigs count: " + ManagerSingleton<IM>.Instance.odicSosigObjsByID.Count));
			foreach (KeyValuePair<int, Custom_SosigEnemyTemplate> customTemplate in customSosigs)
			{
				SosigEnemyTemplate template = customTemplate.Value.Initialize();
				template.DisplayName = customTemplate.Value.DisplayName;
				template.SosigEnemyID = (SosigEnemyID)customTemplate.Value.SosigEnemyID;
				template.SosigEnemyCategory = (SosigEnemyCategory)customTemplate.Value.SosigEnemyCategory;
				template.SosigPrefabs = new List<FVRObject>();
				new List<string>();
				for (int i = 0; i < customTemplate.Value.CustomSosigs.Length; i++)
				{
					SosigEnemyID id = customTemplate.Value.CustomSosigs[i].baseSosigID;
					template.SosigPrefabs = ManagerSingleton<IM>.Instance.odicSosigObjsByID[id].SosigPrefabs;
					if (customTemplate.Value.CustomSosigs[i].customSkin != "")
					{
						Global.LoadSosigMaterial(customTemplate.Value.CustomSosigs[i]);
					}
				}
				for (int j = 0; j < template.ConfigTemplates.Count; j++)
				{
					if (!customSosigConfigs.ContainsKey(template.ConfigTemplates[j]))
					{
						customSosigConfigs.Add(template.ConfigTemplates[j], template.SosigEnemyID);
					}
					if (!customSosigIDs.ContainsKey(template.SosigEnemyID))
					{
						customSosigIDs.Add(template.SosigEnemyID, template.ConfigTemplates[j]);
					}
				}
				if (!ManagerSingleton<IM>.Instance.olistSosigCats.Contains(template.SosigEnemyCategory))
				{
					ManagerSingleton<IM>.Instance.olistSosigCats.Add(template.SosigEnemyCategory);
				}
				if (!ManagerSingleton<IM>.Instance.odicSosigIDsByCategory.ContainsKey(template.SosigEnemyCategory))
				{
					List<SosigEnemyID> sosigIDs = new List<SosigEnemyID>();
					ManagerSingleton<IM>.Instance.odicSosigIDsByCategory.Add(template.SosigEnemyCategory, sosigIDs);
					List<SosigEnemyTemplate> enemyTemplates = new List<SosigEnemyTemplate>();
					ManagerSingleton<IM>.Instance.odicSosigObjsByCategory.Add(template.SosigEnemyCategory, enemyTemplates);
				}
				if ((int)template.SosigEnemyID != -1)
				{
					ManagerSingleton<IM>.Instance.odicSosigIDsByCategory[template.SosigEnemyCategory].Add(template.SosigEnemyID);
					ManagerSingleton<IM>.Instance.odicSosigObjsByCategory[template.SosigEnemyCategory].Add(template);
					if (!ManagerSingleton<IM>.Instance.odicSosigObjsByID.ContainsKey(template.SosigEnemyID))
					{
						ManagerSingleton<IM>.Instance.odicSosigObjsByID.Add(template.SosigEnemyID, template);
					}
				}
				yield return null;
			}
			Logger.LogInfo((object)("Sosigs Total count: " + ManagerSingleton<IM>.Instance.odicSosigObjsByID.Count));
		}

		public void PrintAllFVRObjects()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			foreach (string key in IM.OD.Keys)
			{
				if (IM.OD.TryGetValue(key, out var value) && Object.op_Implicit((Object)(object)value) && (int)value.Category == 60)
				{
					Logger.LogInfo((object)value.DisplayName);
				}
			}
		}
	}
	public class SosigScreenshots
	{
		public static Camera captureCamera;

		public static Transform spawnPoint;

		public static Sosig currentSosig;

		public static GameObject currentGear;

		public static readonly SpawnOptions _spawnOptions = new SpawnOptions
		{
			SpawnState = (SosigOrder)0,
			SpawnActivated = true,
			EquipmentMode = (EquipmentSlots)7,
			SpawnWithFullAmmo = true,
			IFF = 0
		};

		public static void CreateScreenshotSetup()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Expected O, but got Unknown
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)captureCamera != (Object)null))
			{
				GameObject val = new GameObject();
				val.transform.position = Vector3.up * 150f;
				captureCamera = val.AddComponent<Camera>();
				captureCamera.fov = 15f;
				captureCamera.fieldOfView = 15f;
				captureCamera.targetTexture = new RenderTexture(1024, 1024, 1, (RenderTextureFormat)0, (RenderTextureReadWrite)2);
				captureCamera.Render();
				spawnPoint = new GameObject().transform;
				spawnPoint.parent = val.transform;
				spawnPoint.localPosition = new Vector3(0f, -1f, 10f);
				spawnPoint.rotation = Quaternion.Euler(0f, 180f, 0f);
				Material val2 = new Material(Shader.Find("Unlit/Color"));
				val2.SetColor("_Color", Color.green);
				GameObject val3 = GameObject.CreatePrimitive((PrimitiveType)3);
				((Renderer)val3.GetComponent<MeshRenderer>()).material = val2;
				val3.transform.parent = ((Component)spawnPoint).transform;
				val3.transform.localPosition = new Vector3(0f, 0f, -2f);
				val3.transform.localScale = new Vector3(10f, 10f, 1f);
				GameObject val4 = GameObject.CreatePrimitive((PrimitiveType)3);
				((Renderer)val4.GetComponent<MeshRenderer>()).material = val2;
				val4.transform.parent = spawnPoint;
				val4.transform.localPosition = new Vector3(0f, -0.51f, 0f);
				val4.transform.localScale = new Vector3(10f, 1f, 10f);
				val4.AddComponent<NavMeshSurface>().BuildNavMesh();
				GameObject val5 = new GameObject();
				Light val6 = val5.AddComponent<Light>();
				val6.intensity = 4f;
				val6.type = (LightType)2;
				val6.range = 30f;
				val5.transform.parent = spawnPoint;
				val5.transform.localPosition = new Vector3(1.5f, 3f, 3f);
			}
		}

		public static List<FVRObject> GearSosigClothing()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Invalid comparison between Unknown and I4
			List<FVRObject> list = new List<FVRObject>();
			foreach (string key in IM.OD.Keys)
			{
				if (IM.OD.TryGetValue(key, out var value) && Object.op_Implicit((Object)(object)value) && (int)value.Category == 60)
				{
					list.Add(value);
				}
			}
			return list;
		}

		public static IEnumerator RunSosigGearCapture()
		{
			CreateScreenshotSetup();
			List<FVRObject> gearList = GearSosigClothing();
			yield return null;
			captureCamera.fov = 7.5f;
			captureCamera.fieldOfView = 7.5f;
			CustomSosigLoaderPlugin.screenshotSosigGear = true;
			CustomSosigLoaderPlugin.Logger.LogInfo((object)("Sosig Gear Started at " + DateTime.Now));
			foreach (FVRObject gear in gearList)
			{
				if (!CustomSosigLoaderPlugin.screenshotSosigGear)
				{
					CustomSosigLoaderPlugin.Logger.LogInfo((object)("Sosig Gear force stopped at " + DateTime.Now));
					if (Object.op_Implicit((Object)(object)currentGear))
					{
						Object.Destroy((Object)(object)currentGear);
					}
					yield break;
				}
				GameObject spawnObject = ((AnvilAsset)gear).GetGameObject();
				if (Object.op_Implicit((Object)(object)spawnObject))
				{
					currentGear = Object.Instantiate<GameObject>(spawnObject).gameObject;
				}
				if (!((Object)(object)spawnObject == (Object)null) && !((Object)(object)currentGear == (Object)null))
				{
					currentGear.transform.position = spawnPoint.position + Vector3.up;
					currentGear.transform.rotation = Quaternion.Euler(0f, 180f, 0f);
					yield return null;
					yield return null;
					yield return null;
					TakeScreenshot(gear.ItemID, "/Gear/");
					yield return null;
					if (Object.op_Implicit((Object)(object)currentGear))
					{
						Object.Destroy((Object)(object)currentGear);
					}
					yield return null;
				}
			}
			if (Object.op_Implicit((Object)(object)currentGear))
			{
				Object.Destroy((Object)(object)currentGear);
			}
			CustomSosigLoaderPlugin.Logger.LogInfo((object)("Sosig Gear Complete at " + DateTime.Now));
		}

		public static IEnumerator RunSosigCapture()
		{
			CreateScreenshotSetup();
			yield return null;
			captureCamera.fov = 15f;
			captureCamera.fieldOfView = 15f;
			CustomSosigLoaderPlugin.screenshotSosigs = true;
			CustomSosigLoaderPlugin.Logger.LogInfo((object)("Screen Capture Started at " + DateTime.Now));
			foreach (SosigEnemyID value in Enum.GetValues(typeof(SosigEnemyID)))
			{
				SosigEnemyID pieceType = value;
				if (!CustomSosigLoaderPlugin.screenshotSosigs)
				{
					CustomSosigLoaderPlugin.Logger.LogInfo((object)("Screen Capture force stopped at " + DateTime.Now));
					if (Object.op_Implicit((Object)(object)currentSosig))
					{
						currentSosig.DeSpawnSosig();
					}
					yield break;
				}
				string enumName = Enum.GetName(typeof(SosigEnemyID), pieceType);
				CustomSosigLoaderPlugin.Logger.LogInfo((object)(((object)(SosigEnemyID)(ref pieceType)).ToString() + " - " + enumName));
				ManagerSingleton<IM>.Instance.odicSosigObjsByID.TryGetValue(pieceType, out var newSosig);
				if (!((Object)(object)newSosig == (Object)null))
				{
					currentSosig = SosigAPI.Spawn(newSosig, _spawnOptions, spawnPoint.position, spawnPoint.rotation);
					if (!((Object)(object)currentSosig == (Object)null))
					{
						yield return null;
						yield return null;
						yield return null;
						TakeScreenshot((int)pieceType + "_" + enumName, "/Sosigs/");
						yield return null;
						yield return null;
						currentSosig.DeSpawnSosig();
						yield return null;
						yield return null;
						newSosig = null;
					}
				}
			}
			if (Object.op_Implicit((Object)(object)captureCamera))
			{
				Object.Destroy((Object)(object)((Component)captureCamera).gameObject);
			}
			CustomSosigLoaderPlugin.Logger.LogInfo((object)("Screen Capture Complete at " + DateTime.Now));
		}

		public static void TakeScreenshot(string nameID, string directory)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			RenderTexture active = RenderTexture.active;
			RenderTexture.active = captureCamera.targetTexture;
			captureCamera.Render();
			Texture2D val = new Texture2D(((Texture)captureCamera.targetTexture).width, ((Texture)captureCamera.targetTexture).height, (TextureFormat)4, false, true);
			val.ReadPixels(new Rect(0f, 0f, (float)((Texture)captureCamera.targetTexture).width, (float)((Texture)captureCamera.targetTexture).height), 0, 0);
			val.Apply();
			RenderTexture.active = active;
			byte[] array = val.EncodeToPNG();
			string text = nameID + ".png";
			string text2 = Application.persistentDataPath + directory;
			try
			{
				if (!Directory.Exists(text2))
				{
					Directory.CreateDirectory(text2);
				}
			}
			catch (Exception ex)
			{
				CustomSosigLoaderPlugin.Logger.LogInfo((object)ex.Message);
				return;
			}
			text2 += text;
			using FileStream fileStream = new FileStream(text2, FileMode.OpenOrCreate);
			CustomSosigLoaderPlugin.Logger.LogInfo((object)("Write to file: " + text2));
			fileStream.Write(array, 0, array.Length);
		}
	}
	public class TnHFrameworkLoader
	{
		public class FrameworkSosig
		{
			public string DisplayName;

			public string SosigEnemyCategory;

			public string SosigEnemyID;

			public string[] SosigPrefabs;

			public Custom_SosigConfigTemplate[] Configs;

			public Custom_SosigConfigTemplate[] ConfigsEasy;
		}

		public static void AddSosigEnemyTemplateToTnHFramework(SosigEnemyTemplate template)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected I4, but got Unknown
			LoadedTemplateManager.SosigIDDict.Add(template.DisplayName, (int)template.SosigEnemyID);
		}

		public static void LoadFrameworkSosigs()
		{
			CustomSosigLoaderPlugin.Logger.LogInfo((object)"Loading TnH Framework Sosigs");
			try
			{
				string[] directories = Directory.GetDirectories(Paths.PluginPath, "*", SearchOption.AllDirectories);
				List<string> list = new List<string>();
				string[] array = directories;
				foreach (string text in array)
				{
					string path = Path.Combine(text, "Sosigs");
					if (!Directory.Exists(path))
					{
						continue;
					}
					string[] files = Directory.GetFiles(text, "*.json", SearchOption.TopDirectoryOnly);
					if (files.Length != 0)
					{
						string[] array2 = files;
						foreach (string text2 in array2)
						{
						}
					}
				}
			}
			catch (Exception ex)
			{
				Console.WriteLine("An error occurred: " + ex.Message);
			}
		}
	}
}