Decompiled source of TheCompany v0.1.2

TheCompany.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using StaticNetcodeLib;
using TheCompany.AI;
using TheCompany.Components;
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;

		public 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));
		}
	}
	public class TheCompanyConfig
	{
		public readonly ConfigEntry<bool> enableGod;

		public readonly ConfigEntry<bool> disableNonServerExplosions;

		public TheCompanyConfig(ConfigFile cfg)
		{
			cfg.SaveOnConfigSet = false;
			enableGod = cfg.Bind<bool>("General", "GodEnabled", false, "Enables or disables god.");
			disableNonServerExplosions = cfg.Bind<bool>("General", "NoExplosionClients", false, "Disabled explosions from non server hosts.");
			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))
			{
				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(GrabbableObject))]
	internal class GrabbableObjectPatch
	{
		[HarmonyPatch("OnHitGround")]
		[HarmonyPostfix]
		public static void postOnHitGround(GrabbableObject __instance)
		{
			if (__instance.scrapValue != 0 && __instance.isInShipRoom && !StartOfRound.Instance.inShipPhase && Object.op_Implicit((Object)(object)__instance.playerHeldBy))
			{
			}
		}
	}
	[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("Awake")]
		[HarmonyPostfix]
		public static void postAwake(PlayerControllerB __instance)
		{
			((Component)__instance).gameObject.AddComponent<GodsOpinion>();
		}

		[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)
		{
			if ((!TheCompanyMod.BoundConfig.disableNonServerExplosions.Value || ((NetworkBehaviour)__instance).IsHost) && ((__instance.isPlayerControlled && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject)) || __instance.isTestingPlayer) && ((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;
				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.hasBegunSpectating)
				{
					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.Components
{
	internal class GodsOpinion : NetworkBehaviour
	{
		private float bias;

		public void Awake()
		{
			bias = 0f;
		}

		public float GetBias()
		{
			return bias;
		}

		public void ChangeBias(float amount)
		{
			bias += amount;
		}
	}
}
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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			FlowermanAI val2 = default(FlowermanAI);
			PufferAI val3 = default(PufferAI);
			for (int i = 0; (float)i < ((Component)target).GetComponent<GodsOpinion>().GetBias() * -1f; i++)
			{
				TheCompanyMod.logger.LogInfo((object)("spawned: " + (i + 1)));
				GameObject val = Object.Instantiate<GameObject>(GeneralExtensions.GetValueSafe<string, EnemyType>(GetEnemies(), name).enemyPrefab, pos, Quaternion.identity);
				if (val.TryGetComponent<FlowermanAI>(ref val2))
				{
					val2.AvoidClosestPlayer();
				}
				if (val.TryGetComponent<PufferAI>(ref val3))
				{
					val3.ShakeTailServerRpc();
				}
				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 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			if (TheCompanyMod.BoundConfig.enableGod.Value && ((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];
				if (type == JudgementType.Action)
				{
					((Component)val).gameObject.GetComponent<GodsOpinion>().ChangeBias(-1.5f);
				}
				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;
		}

		[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");
			}
		}
	}
}