Decompiled source of DerangedCompany v0.3.0

DerangedCompany.dll

Decompiled 10 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using DerangedCompany.MonoBehaviours;
using GameNetcodeStuff;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using On;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DerangedCompany")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds a bunch of random (deranged) things to the game")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0")]
[assembly: AssemblyProduct("DerangedCompany")]
[assembly: AssemblyTitle("DerangedCompany")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.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 DerangedCompany
{
	[BepInPlugin("DerangedCompany", "DerangedCompany", "0.3.0")]
	public class Plugin : BaseUnityPlugin
	{
		private AssetBundle _assets;

		private static Dictionary<string, GameObject> _prefabs;

		private void Awake()
		{
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading plugin...");
			_assets = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("DerangedCompany.derangedassets"));
			if ((Object)(object)_assets == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogFatal((object)"Asset bundle could not be found.");
				return;
			}
			_prefabs = new Dictionary<string, GameObject>();
			GameObject val = _assets.LoadAsset<GameObject>("Assets/DerangedCompany/Scrap/AmongPlushie/VentDrop.prefab");
			AudioClip value = _assets.LoadAsset<AudioClip>("Assets/DerangedCompany/Audio/impostor-kill.mp3");
			NetworkPrefabs.RegisterNetworkPrefab(val);
			LoadScrap("Deez", 20, (LevelTypes)(-1));
			LoadScrap("AmongPlushie", 10, (LevelTypes)(-1), typeof(ItemUseDeath), new Dictionary<string, object>
			{
				{ "incrementChance", 0.4f },
				{ "frustrateChance", 0.1f },
				{
					"frustrateBounds",
					(object)new Vector2(8f, 14f)
				},
				{ "deathObject", val },
				{ "deathSound", value },
				{ "frustrationDeathReduction", 3f }
			});
			LoadScrap("Policia", 1, (LevelTypes)(-1), typeof(Policia));
			LoadScrap("AmongChip", 1, (LevelTypes)992, typeof(HealItem));
			LoadEnemy("Finger", 40, (LevelTypes)(-1), typeof(FingerAI));
			LoadEnemy("YourMother", 20, (LevelTypes)992, typeof(YourMotherAI));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin loaded!!");
		}

		private void LoadScrap(string assetName, int rarity = 20, LevelTypes levelTypes = -1, Type customScript = null, Dictionary<string, object> newFields = null)
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_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_00e3: Unknown result type (might be due to invalid IL or missing references)
			Item val = _assets.LoadAsset<Item>("Assets/DerangedCompany/Scrap/" + assetName + "/" + assetName + ".asset");
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not load scrap " + assetName + "."));
			}
			if (customScript != null)
			{
				val.spawnPrefab = SwapScripts(val.spawnPrefab, typeof(GrabbableObject), customScript, newFields);
			}
			GameObject spawnPrefab = val.spawnPrefab;
			if (assetName != "Deez")
			{
				spawnPrefab.AddComponent<AudioMixerFixer>();
			}
			_prefabs.Add(assetName, spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(spawnPrefab);
			Items.RegisterScrap(val, rarity, (LevelTypes)(levelTypes & 0x1C));
			Items.RegisterScrap(val, (int)Math.Round((double)rarity * 1.5), (LevelTypes)(levelTypes & 0x60));
			Items.RegisterScrap(val, rarity * 2, (LevelTypes)(levelTypes & 0x380));
		}

		private void LoadEnemy(string assetName, int rarity = 40, LevelTypes levelTypes = -1, Type customScript = null, Dictionary<string, object> newFields = null)
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			EnemyType val = _assets.LoadAsset<EnemyType>("Assets/DerangedCompany/Enemies/" + assetName + "/" + assetName + ".asset");
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not load enemy " + assetName + "."));
			}
			if (customScript != null)
			{
				val.enemyPrefab = SwapScripts(val.enemyPrefab, typeof(EnemyAI), customScript, newFields);
			}
			GameObject enemyPrefab = val.enemyPrefab;
			enemyPrefab.AddComponent<AudioMixerFixer>();
			TerminalNode val2 = _assets.LoadAsset<TerminalNode>("Assets/DerangedCompany/Enemies/" + assetName + "/TerminalNode.asset");
			TerminalKeyword val3 = _assets.LoadAsset<TerminalKeyword>("Assets/DerangedCompany/Enemies/" + assetName + "/TerminalKeyword.asset");
			if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not load terminal configs for " + assetName + "."));
			}
			_prefabs.Add(assetName, enemyPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(enemyPrefab);
			Enemies.RegisterEnemy(val, rarity, levelTypes, (SpawnType)0, val2, val3);
		}

		private GameObject SwapScripts(GameObject obj, Type original, Type replacement, Dictionary<string, object> newFields = null)
		{
			Component component = obj.GetComponent(original);
			Component obj2 = obj.AddComponent(replacement);
			FieldInfo[] fields = ((object)component).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
			foreach (FieldInfo fieldInfo in fields)
			{
				FieldInfo field = replacement.GetField(fieldInfo.Name);
				if (field != null)
				{
					field.SetValue(obj2, fieldInfo.GetValue(component));
				}
			}
			Object.Destroy((Object)(object)component);
			if (newFields != null)
			{
				foreach (string key in newFields.Keys)
				{
					FieldInfo field2 = replacement.GetField(key);
					object obj3 = newFields[key];
					if (field2 != null && field2.FieldType == obj3.GetType())
					{
						field2.SetValue(obj2, obj3);
					}
				}
			}
			return obj;
		}

		private static void SpawnPrefab(StartOfRound self, string name)
		{
			//IL_0040: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			float num = (((Object)(object)_prefabs[name].GetComponent<EnemyAI>() == (Object)null) ? 0f : 2f);
			Object.Instantiate<GameObject>(_prefabs[name], ((Component)self.localPlayerController.gameplayCamera).transform.position + Vector3.forward * num, Quaternion.identity).GetComponent<NetworkObject>().Spawn(false);
			UnityLogWriter.WriteStringToUnityLog("Spawned " + name + "!");
		}

		private static void StartOfRound_Update(orig_Update super, StartOfRound self)
		{
			if (((ButtonControl)Keyboard.current[(Key)94]).wasPressedThisFrame)
			{
				SpawnPrefab(self, "Deez");
			}
			if (((ButtonControl)Keyboard.current[(Key)95]).wasPressedThisFrame)
			{
				SpawnPrefab(self, "AmongPlushie");
			}
			if (((ButtonControl)Keyboard.current[(Key)96]).wasPressedThisFrame)
			{
				SpawnPrefab(self, "Vent");
			}
			if (((ButtonControl)Keyboard.current[(Key)97]).wasPressedThisFrame)
			{
				SpawnPrefab(self, "Policia");
			}
			if (((ButtonControl)Keyboard.current[(Key)98]).wasPressedThisFrame)
			{
				SpawnPrefab(self, "AmongChip");
			}
			if (((ButtonControl)Keyboard.current[(Key)103]).wasPressedThisFrame)
			{
				SpawnPrefab(self, "Finger");
			}
			if (((ButtonControl)Keyboard.current[(Key)102]).wasPressedThisFrame)
			{
				SpawnPrefab(self, "YourMother");
			}
			super.Invoke(self);
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public struct LevelTypeUtil
	{
		public const LevelTypes Easy = 28;

		public const LevelTypes Middle = 96;

		public const LevelTypes Expert = 896;
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DerangedCompany";

		public const string PLUGIN_NAME = "DerangedCompany";

		public const string PLUGIN_VERSION = "0.3.0";
	}
}
namespace DerangedCompany.MonoBehaviours
{
	public class AudioMixerFixer : MonoBehaviour
	{
		private static AudioMixerGroup _masterDiageticMixer;

		public static AudioMixerGroup MasterDiageticMixer
		{
			get
			{
				if ((Object)(object)_masterDiageticMixer == (Object)null)
				{
					AudioSource? obj = (from p in ((Component)GameNetworkManager.Instance).GetComponent<NetworkManager>().NetworkConfig.Prefabs.Prefabs
						select p.Prefab.GetComponentInChildren<NoisemakerProp>() into p
						where (Object)(object)p != (Object)null
						select ((Component)p).GetComponentInChildren<AudioSource>() into p
						where (Object)(object)p != (Object)null
						select p).FirstOrDefault();
					if ((Object)(object)obj == (Object)null)
					{
						throw new Exception("Failed to locate a suitable AudioSource output mixer to reference! Could you be calling this method before the GameNetworkManager is initialized?");
					}
					_masterDiageticMixer = obj.outputAudioMixerGroup;
				}
				return _masterDiageticMixer;
			}
		}

		private void Start()
		{
			foreach (AudioSource item in ((Component)this).GetComponents<AudioSource>().Concat(((Component)this).GetComponentsInChildren<AudioSource>()))
			{
				item.outputAudioMixerGroup = MasterDiageticMixer;
			}
		}
	}
	public class FingerAI : EnemyAI
	{
		public int fingerDamage = 35;

		public float deathCrunch = 0.3f;

		private float _timeSinceHittingLocalPlayer;

		public override void Start()
		{
			((Component)this).GetComponentInChildren<EnemyAICollisionDetect>().mainScript = (EnemyAI)(object)this;
			((EnemyAI)this).Start();
			_timeSinceHittingLocalPlayer = 0f;
		}

		public override void Update()
		{
			//IL_0022: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Update();
			if (base.isEnemyDead)
			{
				((Behaviour)base.creatureAnimator).enabled = false;
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(((Component)this).transform.localScale.x, deathCrunch, ((Component)this).transform.localScale.z);
				((Component)this).transform.localScale = Vector3.Lerp(((Component)this).transform.localScale, val, 0.1f);
			}
			if (base.ventAnimationFinished && !base.isEnemyDead && !StartOfRound.Instance.allPlayersDead)
			{
				_timeSinceHittingLocalPlayer += Time.deltaTime;
			}
		}

		public override void DoAIInterval()
		{
			((EnemyAI)this).DoAIInterval();
			if (!base.isEnemyDead && !StartOfRound.Instance.allPlayersDead)
			{
				base.targetPlayer = ((EnemyAI)this).GetClosestPlayer(false, true, true);
				base.movingTowardsTargetPlayer = base.targetPlayer.isInsideFactory;
			}
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).OnCollideWithPlayer(other);
			if (!((double)_timeSinceHittingLocalPlayer < 0.25))
			{
				PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
				if (!((Object)(object)val == (Object)null))
				{
					_timeSinceHittingLocalPlayer = 0f;
					val.DamagePlayer(fingerDamage, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
					val.bleedingHeavily = true;
				}
			}
		}

		public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false)
		{
			if (!base.isEnemyDead)
			{
				base.enemyHP -= force;
				if (((NetworkBehaviour)this).IsOwner && base.enemyHP <= 0)
				{
					((EnemyAI)this).HitEnemy(force, playerWhoHit, false);
					((EnemyAI)this).KillEnemyOnOwnerClient(false);
				}
				else
				{
					((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX);
				}
			}
		}
	}
	public class HealItem : NoisemakerProp
	{
		[Range(0f, 1f)]
		public float useChance = 1f;

		public int itemUses = 1;

		[Range(0f, 1f)]
		public float healAmount = 1f;

		private Random _random;

		private float _uses;

		public override void Start()
		{
			((NoisemakerProp)this).Start();
			_uses = 0f;
			_random = new Random(StartOfRound.Instance.randomMapSeed);
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if (!((Object)(object)localPlayerController == (Object)null) && !((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null))
			{
				((NoisemakerProp)this).ItemActivate(used, buttonDown);
				bool flag = ((Object)localPlayerController).name == ((Object)((GrabbableObject)this).playerHeldBy).name && localPlayerController.actualClientId == ((GrabbableObject)this).playerHeldBy.actualClientId;
				if (flag)
				{
					localPlayerController.health = Mathf.Min(100, localPlayerController.health + (int)(100f * healAmount));
					HUDManager.Instance.UpdateHealthUI(localPlayerController.health, false);
				}
				if (_random.NextDouble() <= (double)useChance)
				{
					_uses += 1f;
				}
				if (_uses >= (float)itemUses && flag)
				{
					((GrabbableObject)this).DestroyObjectInHand(localPlayerController);
				}
			}
		}
	}
	public class ItemUseDeath : NoisemakerProp
	{
		[Range(0f, 1f)]
		public float incrementChance = 0.5f;

		public float frustrateIncrement = 1f;

		[Range(0f, 1f)]
		public float frustrateChance = 0.5f;

		public Vector2 frustrateBounds = new Vector2(4f, 10f);

		public GameObject deathObject;

		public AudioClip deathSound;

		public float frustrationDeathReduction = 2f;

		private AudioSource _audioSource;

		private Random _random;

		private float _frustration;

		public override void Start()
		{
			((NoisemakerProp)this).Start();
			_audioSource = ((Component)this).GetComponent<AudioSource>();
			_random = new Random(StartOfRound.Instance.randomMapSeed);
			_frustration = 0f;
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null || (Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null)
			{
				return;
			}
			if (_random.NextDouble() >= (double)incrementChance)
			{
				_frustration += frustrateIncrement;
			}
			bool num = (_frustration >= frustrateBounds.x && _random.NextDouble() >= (double)frustrateChance) || _frustration >= frustrateBounds.y;
			bool flag = ((Object)localPlayerController).name == ((Object)((GrabbableObject)this).playerHeldBy).name && localPlayerController.actualClientId == ((GrabbableObject)this).playerHeldBy.actualClientId;
			if (num && !StartOfRound.Instance.inShipPhase)
			{
				if (flag)
				{
					localPlayerController.bleedingHeavily = true;
					localPlayerController.DropBlood(Vector3.up, true, false);
					localPlayerController.DropBlood(Vector3.down, true, false);
					localPlayerController.AddBloodToBody();
					localPlayerController.KillPlayer(Vector3.down, true, (CauseOfDeath)6, 0);
					localPlayerController.AddBloodToBody();
				}
				Object.Instantiate<GameObject>(deathObject, ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.position, Quaternion.identity).GetComponent<NetworkObject>().Spawn(true);
				_frustration /= frustrationDeathReduction;
				_audioSource.PlayOneShot(deathSound);
			}
			else
			{
				((NoisemakerProp)this).ItemActivate(used, buttonDown);
			}
		}
	}
	public class Policia : GrabbableObject
	{
		private Transform _siren;

		private Transform _player;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			_siren = ((Component)((Component)this).GetComponentInChildren<SpriteRenderer>()).transform;
			_player = ((Component)GameNetworkManager.Instance.localPlayerController.gameplayCamera).transform;
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (!((Object)(object)_siren == (Object)null) && !((Object)(object)_player == (Object)null))
			{
				_siren.LookAt(_player);
			}
		}
	}
	public class YourMotherAI : EnemyAI
	{
		public int hitDamage = 35;

		private int _maxHp;

		private float _timeSinceHittingLocalPlayer;

		private Vector3 _originalSize;

		public override void Start()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).GetComponentInChildren<EnemyAICollisionDetect>().mainScript = (EnemyAI)(object)this;
			((EnemyAI)this).Start();
			_maxHp = base.enemyHP;
			_timeSinceHittingLocalPlayer = 0f;
			_originalSize = ((Component)this).transform.localScale;
		}

		public override void Update()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Update();
			float num = Mathf.Max((float)base.enemyHP / (float)_maxHp, 0f);
			((Component)this).transform.localScale = Vector3.Lerp(((Component)this).transform.localScale, new Vector3(num * _originalSize.x, _originalSize.y, num * _originalSize.z), 0.1f);
			if (base.ventAnimationFinished && !base.isEnemyDead && !StartOfRound.Instance.allPlayersDead)
			{
				_timeSinceHittingLocalPlayer += Time.deltaTime;
			}
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).OnCollideWithPlayer(other);
			if (!((double)_timeSinceHittingLocalPlayer < 0.25))
			{
				PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
				if (!((Object)(object)val == (Object)null))
				{
					_timeSinceHittingLocalPlayer = 0f;
					val.DamagePlayer(hitDamage, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
					val.DropBlood(default(Vector3), true, false);
				}
			}
		}

		public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!base.isEnemyDead)
			{
				base.enemyHP -= force;
				if (Object.op_Implicit((Object)(object)playerWhoHit))
				{
					playerWhoHit.DropBlood(default(Vector3), true, false);
				}
				if (((NetworkBehaviour)this).IsOwner && base.enemyHP <= 0)
				{
					((EnemyAI)this).HitEnemy(force, playerWhoHit, false);
					((EnemyAI)this).KillEnemyOnOwnerClient(false);
				}
				else
				{
					((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX);
				}
			}
		}
	}
}