Decompiled source of X explotion TheCompany v0.0.1

TheCompany.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using StaticNetcodeLib;
using TheCompany.AI;
using TheCompany.Enemy;
using TheCompany.Patches;
using TheCompany.Patches.Enemy;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TheCompany")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TheCompany")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cb833b0f-d0cd-4e40-bf49-09f5f36ff617")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TheCompany
{
	internal class ItemUtils
	{
		public static void GetItems(string name)
		{
			Dictionary<string, Item> all = new Dictionary<string, Item>();
			StartOfRound.Instance.allItemsList.itemsList.ForEach(delegate(Item item)
			{
				all.Add(((Object)item).name, item);
				TheCompanyMod.logger.LogInfo((object)((Object)item).name);
			});
		}
	}
	internal class ModMenu : MonoBehaviour
	{
		internal static ModMenu Instance;

		internal bool Visible = false;

		private const int MENUWIDTH = 600;

		private const int MENUHEIGHT = 800;

		private int MENUX;

		private int MENUY;

		private int ITEMWIDTH = 200;

		private int CENTERX;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			MENUX = Screen.width / 2;
			MENUY = Screen.height / 2;
			CENTERX = MENUX + (300 - ITEMWIDTH / 2);
		}

		private void Update()
		{
		}

		private void OnGUI()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (Visible)
			{
				GUI.Box(new Rect((float)MENUX, (float)MENUY, 600f, 800f), "The word of The Company");
			}
		}

		private Texture2D MakeTex(int width, int height, Color color)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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)
			//IL_002e: Expected O, but got Unknown
			Color[] array = (Color[])(object)new Color[width * height];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = color;
			}
			Texture2D val = new Texture2D(width, height);
			val.SetPixels(array);
			val.Apply();
			return val;
		}
	}
	[BepInPlugin("Xexplotion.TheCompany", "The Company", "0.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class TheCompanyMod : BaseUnityPlugin
	{
		private const string modGUID = "Xexplotion.TheCompany";

		private const string modName = "The Company";

		private const string modVersion = "0.0.1";

		private readonly Harmony harmony = new Harmony("Xexplotion.TheCompany");

		internal static TheCompanyMod Instance;

		internal static ManualLogSource logger;

		internal ModMenu modMenu;

		public static GameObject poofExplosion;

		public static AudioClip poofSFX;

		internal static AssetBundle EasterEggBundle;

		internal static TheCompanyConfig BoundConfig { get; private set; }

		private void Awake()
		{
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Expected O, but got Unknown
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			BoundConfig = new TheCompanyConfig(((BaseUnityPlugin)this).Config);
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("Xexplotion.TheCompany");
			logger.LogInfo((object)"All shall provail under my rain >:)");
			harmony.PatchAll(typeof(TheCompanyMod));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(ShovelPatch));
			harmony.PatchAll(typeof(GameNetworkManagerPatch));
			harmony.PatchAll(typeof(IHitablePatch));
			harmony.PatchAll(typeof(ShotGunPatch));
			harmony.PatchAll(typeof(ThumperPatch));
			harmony.PatchAll(typeof(BaboonHawkPatch));
			harmony.PatchAll(typeof(BunkerSpiderPatch));
			harmony.PatchAll(typeof(CoilheadPatch));
			harmony.PatchAll(typeof(CentipedePatch));
			harmony.PatchAll(typeof(PufferPatch));
			harmony.PatchAll(typeof(BlobPatch));
			harmony.PatchAll(typeof(CoilheadPatch));
			harmony.PatchAll(typeof(MaskedPatch));
			harmony.PatchAll(typeof(EyelessDogPatch));
			harmony.PatchAll(typeof(ForestGiantAI));
			GameObject val = new GameObject("ModMenu");
			Object.DontDestroyOnLoad((Object)(object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<ModMenu>();
			modMenu = (ModMenu)(object)val.GetComponent("ModMenu");
			string text = ((BaseUnityPlugin)Instance).Info.Location.TrimEnd("TheCompany.dll".ToCharArray()) + "Assets/easteregg.assetbundle";
			EasterEggBundle = AssetBundle.LoadFromFile(text);
			GameObject val2 = EasterEggBundle.LoadAsset<GameObject>("EasterEgg.prefab");
			GameObject val3 = Object.Instantiate<GameObject>(val2, default(Vector3), Quaternion.identity);
			StunGrenadeItem component = val3.GetComponent<StunGrenadeItem>();
			poofExplosion = component.stunGrenadeExplosion;
			poofSFX = component.explodeSFX;
			Object.Destroy((Object)(object)val2);
			Object.Destroy((Object)(object)val3);
		}
	}
	public static class ReflectionsExtensions
	{
		public static T GetFieldValue<T>(this object obj, string name)
		{
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
			FieldInfo field = obj.GetType().GetField(name, bindingAttr);
			if (field == null)
			{
				return default(T);
			}
			return (T)(field?.GetValue(obj));
		}
	}
	internal class TheCompanyConfig
	{
		public readonly ConfigEntry<bool> disableGod;

		public TheCompanyConfig(ConfigFile cfg)
		{
			cfg.SaveOnConfigSet = false;
			disableGod = cfg.Bind<bool>("General", "GodDisabled", true, "Enables or disables god.");
			ClearOrphanedEntries(cfg);
			cfg.Save();
			cfg.SaveOnConfigSet = true;
		}

		private static void ClearOrphanedEntries(ConfigFile cfg)
		{
			PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
			dictionary.Clear();
		}
	}
}
namespace TheCompany.Patches
{
	[HarmonyPatch(typeof(EnemyAI))]
	internal class EnemyAIPatch
	{
		[HarmonyPatch("OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void OnPlayerKilled(Collider other, EnemyAI __instance)
		{
			if ((Object)(object)__instance != (Object)null && (Object)(object)other != (Object)null)
			{
				PlayerControllerB val = __instance.MeetsStandardPlayerCollisionConditions(other, __instance.GetFieldValue<bool>("inKillAnimation"), false);
				DivineMessenger divineMessenger = default(DivineMessenger);
				if ((Object)(object)val != (Object)null && ((Component)__instance).TryGetComponent<DivineMessenger>(ref divineMessenger) && (Object)(object)divineMessenger.target != (Object)null && (Object)(object)val == (Object)(object)divineMessenger.target)
				{
					TheCompanyMod.logger.LogInfo((object)((Object)__instance).name);
				}
			}
		}

		private static IEnumerator Explode(GameObject entity, PlayerControllerB player)
		{
			if (!((Object)(object)TheCompanyMod.poofExplosion == (Object)null) && !((Object)(object)TheCompanyMod.poofSFX == (Object)null))
			{
				TheCompanyMod.logger.LogInfo((object)TheCompanyMod.poofExplosion);
				yield return (object)new WaitForSeconds(2f);
				Object.Instantiate<GameObject>(TheCompanyMod.poofExplosion, entity.transform.position, Quaternion.identity);
				Object.Destroy((Object)(object)entity.gameObject);
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class GameNetworkManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		public static void StartPatch()
		{
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class IHitablePatch
	{
		[HarmonyTargetMethod]
		public static MethodBase TargetMethod()
		{
			return AccessTools.Method(typeof(PlayerControllerB), "IHittable.Hit", new Type[5]
			{
				typeof(int),
				typeof(Vector3),
				typeof(PlayerControllerB),
				typeof(bool),
				typeof(int)
			}, (Type[])null);
		}

		[HarmonyPostfix]
		public static bool Prefix(int force, Vector3 hitDirection, PlayerControllerB playerWhoHit, bool playHitSFX, int hitID, PlayerControllerB __instance)
		{
			if (__instance.criticallyInjured && __instance.health - 20 <= 0)
			{
				GodClient.CastJudgementManual(GodClient.JudgementType.Action, __instance.actualClientId, playerWhoHit.actualClientId);
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	[StaticNetcode]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("KillPlayerClientRpc")]
		[HarmonyPostfix]
		public static void postKilledPlayer(int playerId, bool spawnBody, Vector3 bodyVelocity, int causeOfDeath, int deathAnimation, Vector3 positionOffset)
		{
			DivineMessenger[] array = Object.FindObjectsOfType<DivineMessenger>();
			foreach (DivineMessenger divineMessenger in array)
			{
				if ((Object)(object)StartOfRound.Instance.allPlayerScripts[playerId] == (Object)(object)divineMessenger.target && !divineMessenger.completed)
				{
					divineMessenger.Despawn();
				}
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void postUpdate(PlayerControllerB __instance)
		{
			__instance.sprintMeter = 1f;
			__instance.movementSpeed = 20f;
			__instance.takingFallDamage = false;
			if ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer)
			{
				return;
			}
			if (((ButtonControl)Keyboard.current.yKey).wasPressedThisFrame)
			{
			}
			if (((ButtonControl)Keyboard.current.xKey).wasPressedThisFrame)
			{
				TheCompanyMod.logger.LogInfo((object)"Exploding...");
				explode(__instance);
				if (((NetworkBehaviour)__instance).IsServer)
				{
					SyncExplosionClientRpc(__instance.actualClientId);
				}
			}
		}

		private static void explode(PlayerControllerB sendingPlayer)
		{
			//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_0048: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)TheCompanyMod.poofExplosion == (Object)null) && !((Object)(object)TheCompanyMod.poofSFX == (Object)null))
			{
				Object.Instantiate<GameObject>(TheCompanyMod.poofExplosion, ((Component)sendingPlayer).transform.position, Quaternion.identity);
				AudioSource.PlayClipAtPoint(TheCompanyMod.poofSFX, ((Component)sendingPlayer).transform.position);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public static void SyncExplosionServerRpc(ulong sendingClientId)
		{
			SyncExplosionClientRpc(sendingClientId);
		}

		[ClientRpc]
		public static void SyncExplosionClientRpc(ulong sendingClientId)
		{
			TheCompanyMod.logger.LogInfo((object)$"received rpc for {sendingClientId}");
			if (!((NetworkBehaviour)StartOfRound.Instance.allPlayerScripts[sendingClientId]).IsOwner)
			{
				PlayerControllerB sendingPlayer = StartOfRound.Instance.allPlayerScripts[sendingClientId];
				explode(sendingPlayer);
			}
		}
	}
	internal class QuickMenuManagerPatch
	{
		[HarmonyPatch("OpenQuickMenu")]
		[HarmonyPrefix]
		public static void OpenMenu()
		{
			TheCompanyMod.Instance.modMenu.Visible = true;
		}

		[HarmonyPatch("CloseQuickMenu")]
		[HarmonyPrefix]
		public static void CloseMenu()
		{
			TheCompanyMod.Instance.modMenu.Visible = false;
		}

		[HarmonyPatch("LeaveGameConfirm")]
		[HarmonyPrefix]
		public static void CloseMenuOnLeaveGame()
		{
			TheCompanyMod.Instance.modMenu.Visible = false;
		}
	}
	[HarmonyPatch(typeof(ShotgunItem))]
	[StaticNetcode]
	internal class ShotGunPatch
	{
		[HarmonyPatch("ShootGun")]
		[HarmonyPostfix]
		public static void PostShoot(Vector3 shotgunPosition, Vector3 shotgunForward, ShotgunItem __instance)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0078: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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)
			bool flag = false;
			if (((GrabbableObject)__instance).isHeld && (Object)(object)((GrabbableObject)__instance).playerHeldBy != (Object)null && (Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				flag = true;
			}
			if (((GrabbableObject)__instance).isHeldByEnemy)
			{
				return;
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null)
			{
				return;
			}
			Vector3 val = localPlayerController.playerCollider.ClosestPoint(shotgunPosition);
			if (!flag && !Physics.Linecast(shotgunPosition, val, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1) && Vector3.Angle(shotgunForward, val - shotgunPosition) < 30f)
			{
				float num = Vector3.Distance(((Component)localPlayerController).transform.position, ((Component)__instance.shotgunRayPoint).transform.position);
				int num2 = 0;
				TheCompanyMod.logger.LogInfo((object)((GrabbableObject)__instance).playerHeldBy.playerUsername);
				TheCompanyMod.logger.LogInfo((object)localPlayerController.playerUsername);
				TheCompanyMod.logger.LogInfo((object)"test2");
				TheCompanyMod.logger.LogInfo((object)localPlayerController.health);
				if (num < 5f)
				{
					num2 = 100;
				}
				if (num < 15f)
				{
					num2 = 100;
				}
				else if (num < 23f)
				{
					num2 = 40;
				}
				else if (num < 30f)
				{
					num2 = 20;
				}
				if (localPlayerController.health - num2 <= 0 || localPlayerController.health == 0)
				{
					IWasShotServerRpc(localPlayerController.actualClientId, ((GrabbableObject)__instance).playerHeldBy.actualClientId);
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public static void IWasShotServerRpc(ulong sendingClientId, ulong whoShotMeId)
		{
			GodClient.CastJudgementManual(GodClient.JudgementType.Action, sendingClientId, whoShotMeId);
		}
	}
	[HarmonyPatch(typeof(Shovel))]
	internal class ShovelPatch
	{
		[HarmonyPatch("HitShovel")]
		[HarmonyPostfix]
		public static void postUpdate(bool cancel, Shovel __instance)
		{
			TheCompanyMod.logger.LogInfo((object)"Shoveled");
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class SpawnScrapInLevelPatch
	{
		[HarmonyPatch("SpawnScrapInLevel")]
		[HarmonyPostfix]
		public static void postSpawnScrapInLevel(RoundManager __instance)
		{
			__instance.currentLevel.spawnableScrap.ForEach(delegate(SpawnableItemWithRarity scrap)
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: 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)
				if (((Object)scrap.spawnableItem).name.Equals("EasterEgg"))
				{
					GameObject spawnPrefab = scrap.spawnableItem.spawnPrefab;
					GameObject val = Object.Instantiate<GameObject>(spawnPrefab, default(Vector3), Quaternion.identity, __instance.spawnedScrapContainer);
					StunGrenadeItem component = val.GetComponent<StunGrenadeItem>();
					if ((Object)(object)component != (Object)null)
					{
						TheCompanyMod.poofExplosion = component.stunGrenadeExplosion;
						TheCompanyMod.logger.LogError((object)("BIG SAIDHASIUHDKASHDKHASKDHKASHDJHASKJDHAS " + (object)component.stunGrenadeExplosion));
						TheCompanyMod.logger.LogInfo((object)TheCompanyMod.poofExplosion);
						TheCompanyMod.poofSFX = component.explodeSFX;
					}
					Object.Destroy((Object)(object)val);
				}
			});
		}
	}
}
namespace TheCompany.Patches.Enemy
{
	[HarmonyPatch(typeof(BaboonBirdAI))]
	internal class BaboonHawkPatch
	{
		[HarmonyPatch("killPlayerAnimation")]
		[HarmonyPostfix]
		public static void OnKillPlayerAnimation(int playerObject, BaboonBirdAI __instance)
		{
			if ((Object)(object)((EnemyAI)__instance).targetPlayer == (Object)(object)((Component)__instance).GetComponent<DivineMessenger>()?.target)
			{
				((Component)__instance).GetComponent<DivineMessenger>()?.Complete();
			}
		}
	}
	[HarmonyPatch(typeof(BlobAI))]
	internal class BlobPatch
	{
		[HarmonyPatch("eatPlayerBody")]
		[HarmonyPostfix]
		public static void PostEatBody(BlobAI __instance)
		{
			if ((Object)(object)((EnemyAI)__instance).targetPlayer == (Object)(object)((Component)__instance).GetComponent<DivineMessenger>()?.target)
			{
				((Component)__instance).GetComponent<DivineMessenger>()?.Complete();
			}
		}
	}
	[HarmonyPatch(typeof(SandSpiderAI))]
	internal class BunkerSpiderPatch
	{
		[HarmonyPatch("turnBodyIntoWeb")]
		[HarmonyPostfix]
		public static void OnTurnBodyIntoWeb(SandSpiderAI __instance)
		{
			if ((Object)(object)((EnemyAI)__instance).targetPlayer == (Object)(object)((Component)__instance).GetComponent<DivineMessenger>()?.target)
			{
				((Component)__instance).GetComponent<DivineMessenger>()?.Complete();
			}
		}
	}
	[HarmonyPatch(typeof(CentipedeAI))]
	internal class CentipedePatch
	{
		[HarmonyPatch("UnclingFromPlayer")]
		[HarmonyPostfix]
		public static void OnUnclingFromPlayer(PlayerControllerB playerBeingKilled, bool playerDead, CentipedeAI __instance)
		{
			if (playerDead && (Object)(object)playerBeingKilled == (Object)(object)((Component)__instance).GetComponent<DivineMessenger>()?.target)
			{
				((Component)__instance).GetComponent<DivineMessenger>()?.Complete();
			}
		}
	}
	[HarmonyPatch(typeof(SpringManAI))]
	internal class CoilheadPatch
	{
		[HarmonyPatch("OnCollideWithPlayer")]
		[HarmonyPrefix]
		public static void OnOnCollideWithPlayer(Collider other, SpringManAI __instance)
		{
			PlayerControllerB val = ((EnemyAI)__instance).MeetsStandardPlayerCollisionConditions(other, false, false);
			if (val.health - 90 <= 0 && (Object)(object)val == (Object)(object)((Component)__instance).GetComponent<DivineMessenger>()?.target)
			{
				((Component)__instance).GetComponent<DivineMessenger>()?.Complete();
			}
		}
	}
	[HarmonyPatch(typeof(MouthDogAI))]
	internal class EyelessDogPatch
	{
		[HarmonyPatch("StopKillAnimation")]
		[HarmonyPostfix]
		public static void OnStopKillAnimation(MouthDogAI __instance)
		{
			if ((Object)(object)__instance.GetFieldValue<DeadBodyInfo>("carryingBody") != (Object)null && (Object)(object)__instance.GetFieldValue<DeadBodyInfo>("carryingBody").playerScript == (Object)(object)((Component)__instance).GetComponent<DivineMessenger>()?.target)
			{
				((Component)__instance).GetComponent<DivineMessenger>()?.Complete();
			}
		}
	}
	[HarmonyPatch(typeof(ForestGiantAI))]
	internal class ForestKeeperPatch
	{
		[HarmonyPatch("EatPlayerAnimation")]
		[HarmonyPostfix]
		private static IEnumerator OnEatPlayerAnimation(PlayerControllerB playerBeingEaten, Vector3 enemyPosition, int enemyYRot, ForestGiantAI __instance)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForSeconds(4.5f);
			if ((Object)(object)playerBeingEaten == (Object)(object)((Component)__instance).GetComponent<DivineMessenger>()?.target)
			{
				((Component)__instance).GetComponent<DivineMessenger>()?.Complete();
			}
		}
	}
	[HarmonyPatch(typeof(JesterAI))]
	internal class JesterPatch
	{
		[HarmonyPatch("killPlayerAnimation")]
		[HarmonyPostfix]
		private static IEnumerator OnKillPlayerAnimation(int playerId, JesterAI __instance)
		{
			yield return (object)new WaitForSeconds(4.5f);
			if ((Object)(object)StartOfRound.Instance.allPlayerScripts[playerId] == (Object)(object)((Component)__instance).GetComponent<DivineMessenger>()?.target)
			{
				((Component)__instance).GetComponent<DivineMessenger>()?.Complete();
			}
		}
	}
	[HarmonyPatch(typeof(MaskedPlayerEnemy))]
	internal class MaskedPatch
	{
		[HarmonyPatch("FinishKillAnimation")]
		[HarmonyPostfix]
		public static void OnFinishKillAnimation(bool killedPlayer, MaskedPlayerEnemy __instance)
		{
			if (killedPlayer && (Object)(object)((EnemyAI)__instance).targetPlayer == (Object)(object)((Component)__instance).GetComponent<DivineMessenger>()?.target)
			{
				((Component)__instance).GetComponent<DivineMessenger>()?.Complete();
			}
		}
	}
	[HarmonyPatch(typeof(PufferAI))]
	internal class PufferPatch
	{
		[HarmonyPatch("stompAnimation")]
		[HarmonyPostfix]
		public static void OnStompAnimation(PufferAI __instance)
		{
			if ((Object)(object)((EnemyAI)__instance).targetPlayer == (Object)(object)((Component)__instance).GetComponent<DivineMessenger>()?.target)
			{
				((Component)__instance).GetComponent<DivineMessenger>()?.Complete();
			}
		}
	}
	[HarmonyPatch(typeof(CrawlerAI))]
	internal class ThumperPatch
	{
		[HarmonyPatch("EatPlayerBodyAnimation")]
		[HarmonyPostfix]
		public static void OnEatBody(CrawlerAI __instance)
		{
			if ((Object)(object)((EnemyAI)__instance).targetPlayer == (Object)(object)((Component)__instance).GetComponent<DivineMessenger>()?.target)
			{
				((Component)__instance).GetComponent<DivineMessenger>()?.Complete();
			}
		}
	}
}
namespace TheCompany.Enemy
{
	[StaticNetcode]
	internal class DivineMessenger : NetworkBehaviour
	{
		public PlayerControllerB target;

		public bool completed;

		public void Complete()
		{
			completed = true;
			((MonoBehaviour)this).StartCoroutine(Explode(((Component)this).gameObject, target));
		}

		public void Despawn()
		{
			//IL_0007: 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)
			explode(((Component)this).transform.position);
			if (((NetworkBehaviour)this).IsServer)
			{
				SyncExplosionServerRpc(((Component)this).transform.position);
			}
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}

		private IEnumerator Explode(GameObject entity, PlayerControllerB player)
		{
			if (!((Object)(object)TheCompanyMod.poofExplosion == (Object)null) && !((Object)(object)TheCompanyMod.poofSFX == (Object)null))
			{
				if (((Object)((Component)this).gameObject).name.Contains("MouthDog"))
				{
					yield return (object)new WaitForSeconds(3.02f);
				}
				if (((Object)((Component)this).gameObject).name.Contains("ForestGiant"))
				{
					yield return (object)new WaitForSeconds(5f);
				}
				if (((Object)((Component)this).gameObject).name.Contains("Jester"))
				{
					yield return (object)new WaitForSeconds(2.5f);
				}
				if (((Object)((Component)this).gameObject).name.Contains("Masked"))
				{
					yield return (object)new WaitForSeconds(2.5f);
				}
				explode(((Component)this).transform.position);
				if (((NetworkBehaviour)this).IsServer)
				{
					SyncExplosionServerRpc(((Component)this).transform.position);
				}
				Object.Destroy((Object)(object)entity);
			}
		}

		[ServerRpc(RequireOwnership = true)]
		public static void SyncExplosionServerRpc(Vector3 pos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			SyncExplosionClientRpc(pos);
		}

		[ClientRpc]
		public static void SyncExplosionClientRpc(Vector3 pos)
		{
			//IL_000b: 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)
			TheCompanyMod.logger.LogInfo((object)$"received explode rpc at {pos}");
			explode(pos);
		}

		private static void explode(Vector3 pos)
		{
			//IL_0027: 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)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)TheCompanyMod.poofExplosion == (Object)null) && !((Object)(object)TheCompanyMod.poofSFX == (Object)null))
			{
				Object.Instantiate<GameObject>(TheCompanyMod.poofExplosion, pos, Quaternion.identity);
				AudioSource.PlayClipAtPoint(TheCompanyMod.poofSFX, pos);
			}
		}
	}
	internal class EnemyUtil
	{
		public static void spawn(string name, Vector3 pos, PlayerControllerB target)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(GeneralExtensions.GetValueSafe<string, EnemyType>(GetEnemies(), name).enemyPrefab, pos, Quaternion.identity);
			DivineMessenger divineMessenger = val.AddComponent(typeof(DivineMessenger)) as DivineMessenger;
			divineMessenger.target = target;
			divineMessenger.completed = false;
			val.GetComponentInChildren<NetworkObject>().Spawn(true);
		}

		public static Dictionary<string, EnemyType> GetEnemies()
		{
			Dictionary<string, EnemyType> dictionary = new Dictionary<string, EnemyType>();
			SelectableLevel[] levels = StartOfRound.Instance.levels;
			foreach (SelectableLevel val in levels)
			{
				if (!((Object)(object)val != (Object)null))
				{
					continue;
				}
				IEnumerable<SpawnableEnemyWithRarity> enumerable = val.OutsideEnemies.Concat(val.DaytimeEnemies);
				foreach (SpawnableEnemyWithRarity item in enumerable)
				{
					if ((Object)(object)item.enemyType != (Object)null && !dictionary.ContainsKey(item.enemyType.enemyName))
					{
						dictionary.Add(item.enemyType.enemyName, item.enemyType);
					}
				}
				foreach (SpawnableEnemyWithRarity enemy in val.Enemies)
				{
					if ((Object)(object)enemy.enemyType != (Object)null && !dictionary.ContainsKey(enemy.enemyType.enemyName))
					{
						dictionary.Add(enemy.enemyType.enemyName, enemy.enemyType);
					}
				}
			}
			return dictionary;
		}
	}
}
namespace TheCompany.AI
{
	[StaticNetcode]
	internal class GodClient
	{
		public enum JudgementType
		{
			SpokenWord,
			Action
		}

		private static readonly HttpClient client = new HttpClient();

		private const string apiKey = "ilFGp1LSL5m7gszUTeEXh2XD4DhCBLPxr4JUuXSK";

		private const string endpoint = "https://api.cohere.com/v1/chat";

		private static Random random = new Random();

		private static List<string> spokenWordPunishments = new List<string> { "[Commiter], for your blasphemy, you shall be punished with a [Punishment], a fitting end for one who dares defy a god's will.", "[Commiter], your blasphemy has brought forth the wrath of the divine. I condemn you to die by a [Punishment], a sentence befitting your arrogance.", "[Commiter], for your blasphemous words, I sentence you to a [Punishment]. Let this punishment remind all that the divine is not to be questioned.", "[Commiter], your blasphemy echoes through the realms. As a result, you shall endure a [Punishment], a fate designed to crush the pride you dared show.", "[Commiter], for your affront against divinity, you are cursed with a [Punishment]. May this punishment haunt you, as your words have desecrated the sacred." };

		private static List<string> actionPunishments = new List<string> { "[Commiter], for your transgression against [Victim], I deem you worthy of retribution. You have violated the natural order with your actions, and thus, you shall face a [Punishment]. Know that your cruelty cannot go unanswered.", "In your reckless pursuit of power, [Commiter], you have wronged [Victim]. Such a vile deed cannot go unpunished. I sentence you to deal with a [Punishment], as a reminder that no soul escapes judgment.", "Your actions, [Commiter], have brought harm to [Victim], disturbing the balance of this realm. For this crime, you shall suffer from a [Punishment], for balance must be restored, and your wrongdoing cannot be ignored.", "For the betrayal of [Victim], I, as ruler of this realm, decree that [Commiter] shall endure a [Punishment]. Let this serve as a lesson that those who harm others shall be repaid tenfold in suffering.", "[Commiter], you have crossed a line that should never have been breached. Your cruelty toward [Victim] brings you to my attention. As penance, you are condemned to die by a [Punishment]. Such malice will never go unpunished under my gaze." };

		private static Dictionary<string, string> outdoorEnemies = new Dictionary<string, string>
		{
			{ "Eyeless Dog", "MouthDog" },
			{ "Forest Giant", "ForestGiant" },
			{ "Earthworm", "Earth Leviatian" },
			{ "Baboon Hawk", "Baboon Hawk" },
			{ "Old Bird", "RadMech" }
		};

		private static Dictionary<string, string> indoorEnemies = new Dictionary<string, string>
		{
			{ "Bracken", "Flowerman" },
			{ "Jester", "Jester" },
			{ "Nutcracker", "Nutcracker" },
			{ "Coilhead", "Spring" },
			{ "Bunker Spider", "Bunker Spider" },
			{ "Thumper", "Crawler" },
			{ "Mimic", "Masked" },
			{ "Maneater", "Maneater" },
			{ "Butler", "Butler" },
			{ "Snare Flea", "Centipede" },
			{ "Spore Lizard", "Puffer" }
		};

		public static void CastJudgementManual(JudgementType type, ulong victimId, ulong commiterId)
		{
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsOwner && GameNetworkManager.Instance.localPlayerController.playerClientId == 0)
			{
				string text = "";
				switch (type)
				{
				case JudgementType.SpokenWord:
					text = spokenWordPunishments[random.Next(spokenWordPunishments.Count)];
					break;
				case JudgementType.Action:
					text = actionPunishments[random.Next(actionPunishments.Count)];
					break;
				}
				PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[commiterId];
				text = text.Replace("[Commiter]", val.playerUsername);
				text = text.Replace("[Victim]", StartOfRound.Instance.allPlayerScripts[victimId].playerUsername);
				string punishment = getPunishment(val.isInsideFactory);
				text = text.Replace("[Punishment]", punishment);
				if (val.isInsideFactory)
				{
					EnemyUtil.spawn(GeneralExtensions.GetValueSafe<string, string>(indoorEnemies, punishment), ((Component)val).transform.position, val);
				}
				else
				{
					EnemyUtil.spawn(GeneralExtensions.GetValueSafe<string, string>(outdoorEnemies, punishment), ((Component)val).transform.position, val);
				}
				SendTipServerRpc(text, ((Component)StartOfRound.Instance.allPlayerScripts[commiterId]).transform.position);
			}
		}

		private static string getPunishment(bool inside)
		{
			if (inside)
			{
				List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>(indoorEnemies);
				int index = random.Next(list.Count);
				return list[index].Key;
			}
			List<KeyValuePair<string, string>> list2 = new List<KeyValuePair<string, string>>(outdoorEnemies);
			int index2 = random.Next(list2.Count);
			return list2[index2].Key;
		}

		public static async void CastJudgement(string prompt, PlayerControllerB player)
		{
			if (((NetworkBehaviour)player).IsOwner && player.playerClientId == 0)
			{
				JObject response = JObject.Parse(await GetGodsWill(prompt, player));
				TheCompanyMod.logger.LogInfo((object)((object)response["text"]).ToString());
				string decision = ((object)response["text"]).ToString();
				if (decision.Contains("ForestGiant"))
				{
					EnemyUtil.spawn("ForestGiant", ((Component)player).transform.position, player);
				}
				if (decision.Contains("MouthDog"))
				{
					EnemyUtil.spawn("MouthDog", ((Component)player).transform.position, player);
				}
				if (decision.Contains("Earth"))
				{
					EnemyUtil.spawn("Earth Leviathan", ((Component)player).transform.position, player);
				}
				if (decision.Contains("Baboon"))
				{
					EnemyUtil.spawn("Baboon hawk", ((Component)player).transform.position, player);
				}
				if (decision.Contains("Flowerman"))
				{
					EnemyUtil.spawn("Flowerman", ((Component)player).transform.position, player);
				}
				if (decision.Contains("Jester"))
				{
					EnemyUtil.spawn("Jester", ((Component)player).transform.position, player);
				}
				if (decision.Contains("Nutcracker"))
				{
					EnemyUtil.spawn("Nutcracker", ((Component)player).transform.position, player);
				}
				if (decision.Contains("Spring"))
				{
					EnemyUtil.spawn("Spring", ((Component)player).transform.position, player);
				}
				if (decision.Contains("Bunker"))
				{
					EnemyUtil.spawn("Bunker Spider", ((Component)player).transform.position, player);
				}
				if (decision.Contains("Crawler"))
				{
					EnemyUtil.spawn("Crawler", ((Component)player).transform.position, player);
				}
				if (decision.Contains("Masked"))
				{
					EnemyUtil.spawn("Masked", ((Component)player).transform.position, player);
				}
				if (decision.Contains("Maneater"))
				{
					EnemyUtil.spawn("Maneater", ((Component)player).transform.position, player);
				}
				if (decision.Contains("Butler"))
				{
					EnemyUtil.spawn("Butler", ((Component)player).transform.position, player);
				}
				SendTipServerRpc(decision, ((Component)player).transform.position);
			}
		}

		public static async Task<string> GetGodsWill(string prompt, PlayerControllerB player)
		{
			string preamble = "You are a god, a ruler of a dimensional realm. You control all that happens and you decide the fates of everyones actions, punishing bad behavior and rewarding good behavior and give short responses to them. You will not give remarks on the victim, only the punishment and the reasoning. You can choose to do a variety of actions, you can kill the player, spawn a entity (either good or bad), or reward players with items. You can give players these items:\r\nA shovel, a useful tool.\r\n A stun, a way to survive danger\r\n. A pair of walkie talkies, to communicate.\r\n A very very powerful jetpack, only for special occasions.\r\n You can also reward players with loot, with a values between 1 - 200 with a skew to the lower side. You must withhold jetpacks to the highest standard though.\r\n You are able to summon these things on the player:\r\n";
			preamble = (player.isInsideFactory ? (preamble + "A Flowerman, a creature that snaps your neck when you aren't looking.\r\nA Jester, a winding up toy that when it finished with capture and destroy the player.\r\nA nutcracker with a shotgun who will watch you and if you move will blast you.\r\nA Spring, serving as a weeping angel.\r\nA Bunker Spider, who will stick players in webs, drag them away and use them as bait for others.\r\nA Crawler, who will chase they player forever.\r\nA Masked, a lookalike to the player but will kill them upon interaction.\r\nA Maneater, originally a small creature but if uncared for when crying will emerge into a monster to be reckoned with.\r\nA Butler, an innocent creature when watched by multiple players but alone will stab anyone.") : (preamble + "A ForestGiant, guard of the forest.\r\nA MouthDog, only able to hear players.\r\nA Baboon hawk, a tribe abiding animal with fear and aggression but dont spawn it much,\r\nAn Earth Leviathan, a worm that burrows underground and emerges to engulf players."));
			HttpRequestMessage val = new HttpRequestMessage
			{
				Method = HttpMethod.Post,
				RequestUri = new Uri("https://api.cohere.com/v1/chat")
			};
			((HttpHeaders)val.Headers).Add("Authorization", "Bearer ilFGp1LSL5m7gszUTeEXh2XD4DhCBLPxr4JUuXSK");
			val.Content = (HttpContent)new StringContent(JsonConvert.SerializeObject((object)new
			{
				stream = false,
				message = prompt,
				preamble = preamble,
				max_tokens = 100
			}), Encoding.UTF8, "application/json");
			HttpRequestMessage request = val;
			return await (await client.SendAsync(request)).Content.ReadAsStringAsync();
		}

		[ServerRpc(RequireOwnership = true)]
		public static void SendTipServerRpc(string tip, Vector3 pos)
		{
			//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_007f: Unknown result type (might be due to invalid IL or missing references)
			List<ulong> list = new List<ulong>();
			PlayerControllerB[] array = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
			foreach (PlayerControllerB val in array)
			{
				float num = Vector3.Distance(((Component)val).transform.position, pos);
				if (num <= 50f)
				{
					TheCompanyMod.logger.LogInfo((object)$"Found PlayerController {((Object)((Component)val).gameObject).name} within {num} units.");
					list.Add(val.actualClientId);
				}
			}
			SendTipClientRpc(tip, pos, list);
		}

		[ClientRpc]
		public static void SendTipClientRpc(string tip, Vector3 pos, List<ulong> clientIds)
		{
			if (clientIds.Contains(GameNetworkManager.Instance.localPlayerController.actualClientId))
			{
				HUDManager.Instance.DisplayTip("Divine Guidence", tip, true, false, "LC_Tip1");
			}
		}
	}
}