Decompiled source of Grimoire Weiss v1.1.0

BepInEx/plugins/GrimoireWeiss/GrimoireWeiss.dll

Decompiled 10 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using GrimoireWeiss.NetcodePatcher;
using GrimoireWeissScrap.Behaviours;
using JetBrains.Annotations;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[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("CMM")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds your favorite cookbook to the game.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+fb0a5905462a3b97850844ae31013b478cd5cc59")]
[assembly: AssemblyProduct("GrimoireWeiss")]
[assembly: AssemblyTitle("GrimoireWeiss")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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 GrimoireWeissScrap
{
	[BepInPlugin("CMM.GrimoireWeiss", "GrimoireWeiss", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "CMM.GrimoireWeiss";

		public const string PluginAuthor = "CMM";

		public const string PluginName = "GrimoireWeiss";

		public const string PluginVersion = "1.1.0";

		private static Plugin s_instance;

		internal static ManualLogSource Log;

		public static AssetBundle WeissBundle;

		public GameObject NetManagerPrefab;

		private void Awake()
		{
			try
			{
				NetcodeWeaver();
				if ((Object)(object)s_instance == (Object)null)
				{
					s_instance = this;
				}
				Log = Logger.CreateLogSource("CMM.GrimoireWeiss");
				LoadAssetBundles();
				DoNetworkThingy();
				LoadAndRegisterItems();
				Log.LogInfo((object)"Weiss! You dumbass!");
			}
			catch (Exception)
			{
				Log.LogError((object)"Plugin CMM.GrimoireWeiss failed to load.");
			}
		}

		private static void NetcodeWeaver()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			for (int i = 0; i < types.Length; i++)
			{
				MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}

		private void DoNetworkThingy()
		{
			NetManagerPrefab = WeissBundle.LoadAsset<GameObject>("Assets/Dumbass/WeissNetworkManager.prefab");
			NetManagerPrefab.AddComponent<WeissNetworkManager>();
		}

		private static void LoadAssetBundles()
		{
			WeissBundle = LoadAssetBundle("grimoireweiss", "weissBundle");
		}

		private static AssetBundle LoadAssetBundle(string bundleName, string bundleDisplayName)
		{
			AssetBundle obj = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? throw new InvalidOperationException(), bundleName));
			if ((Object)(object)obj == (Object)null)
			{
				Log.LogError((object)("Failed to load " + bundleDisplayName + "."));
			}
			return obj;
		}

		private static void LoadAndRegisterItems()
		{
			Scrap[] array = new Scrap[7]
			{
				new Scrap("Grimoire Weiss", Plugin.LoadItemFromBundle<Item>(WeissBundle, "Assets/Dumbass/GrimoireWeissItem.asset")),
				new Scrap("Tome Blood & Sacrifice", Plugin.LoadItemFromBundle<Item>(WeissBundle, "Assets/Dumbass/TomeBlood&SacrificeItem.asset")),
				new Scrap("Tome Belief & Heart", Plugin.LoadItemFromBundle<Item>(WeissBundle, "Assets/Dumbass/TomeBelief&HeartItem.asset")),
				new Scrap("Tome Heaven & Earth", Plugin.LoadItemFromBundle<Item>(WeissBundle, "Assets/Dumbass/TomeHeaven&EarthItem.asset")),
				new Scrap("Tome Cause & Malice", Plugin.LoadItemFromBundle<Item>(WeissBundle, "Assets/Dumbass/TomeCause&MaliceItem.asset")),
				new Scrap("Tome Sea & Chasm", Plugin.LoadItemFromBundle<Item>(WeissBundle, "Assets/Dumbass/TomeSea&ChasmItem.asset")),
				new Scrap("Tome Star & Song", Plugin.LoadItemFromBundle<Item>(WeissBundle, "Assets/Dumbass/TomeStar&SongItem.asset"))
			};
			Scrap[] array2 = array;
			foreach (Scrap obj in array2)
			{
				string name = obj.Name;
				Item item = obj.Item;
				if ((Object)(object)item == (Object)null)
				{
					Log.LogError((object)("Failed to load item: " + name));
					continue;
				}
				if (!(name == "Grimoire Weiss"))
				{
					if (name == "Tome Blood & Sacrifice")
					{
						TomeBlood tomeBlood = item.spawnPrefab.AddComponent<TomeBlood>();
						((GrabbableObject)tomeBlood).grabbable = true;
						((GrabbableObject)tomeBlood).grabbableToEnemies = true;
						((GrabbableObject)tomeBlood).itemProperties = item;
					}
				}
				else
				{
					Weiss weiss = item.spawnPrefab.AddComponent<Weiss>();
					((GrabbableObject)weiss).grabbable = true;
					((GrabbableObject)weiss).scrapPersistedThroughRounds = true;
					((GrabbableObject)weiss).grabbableToEnemies = true;
					((GrabbableObject)weiss).itemProperties = item;
				}
				NetworkPrefabs.RegisterNetworkPrefab(item.spawnPrefab);
				Utilities.FixMixerGroups(item.spawnPrefab);
			}
			array2 = array;
			foreach (Scrap scrap in array2)
			{
				switch (scrap.Name)
				{
				case "Grimoire Weiss":
					Items.RegisterScrap(scrap.Item, new Dictionary<LevelTypes, int>
					{
						{
							(LevelTypes)64,
							15
						},
						{
							(LevelTypes)4,
							5
						},
						{
							(LevelTypes)8,
							5
						},
						{
							(LevelTypes)16,
							10
						}
					}, (Dictionary<string, int>)null);
					break;
				case "Tome Blood & Sacrifice":
					Items.RegisterScrap(scrap.Item, new Dictionary<LevelTypes, int>
					{
						{
							(LevelTypes)64,
							15
						},
						{
							(LevelTypes)512,
							10
						}
					}, (Dictionary<string, int>)null);
					break;
				case "Tome Heaven & Earth":
					Items.RegisterScrap(scrap.Item, new Dictionary<LevelTypes, int>
					{
						{
							(LevelTypes)128,
							15
						},
						{
							(LevelTypes)256,
							10
						}
					}, (Dictionary<string, int>)null);
					break;
				case "Tome Belief & Heart":
					Items.RegisterScrap(scrap.Item, new Dictionary<LevelTypes, int>
					{
						{
							(LevelTypes)256,
							15
						},
						{
							(LevelTypes)128,
							10
						}
					}, (Dictionary<string, int>)null);
					break;
				default:
					Items.RegisterScrap(scrap.Item, new Dictionary<LevelTypes, int>
					{
						{
							(LevelTypes)4,
							10
						},
						{
							(LevelTypes)8,
							10
						},
						{
							(LevelTypes)16,
							15
						},
						{
							(LevelTypes)256,
							10
						},
						{
							(LevelTypes)128,
							10
						},
						{
							(LevelTypes)64,
							7
						},
						{
							(LevelTypes)512,
							5
						}
					}, (Dictionary<string, int>)null);
					break;
				}
			}
		}

		public static T LoadItemFromBundle<T>(AssetBundle bundle, string path) where T : Object
		{
			T val = bundle.LoadAsset<T>(path);
			if ((Object)(object)val == (Object)null)
			{
				Log.LogError((object)("Failed to load asset at path " + path + " from bundle " + ((Object)bundle).name));
			}
			return val;
		}
	}
	public class Scrap
	{
		public string Name { get; }

		public Item Item { get; }

		public Scrap(string name, Item item)
		{
			Name = name;
			Item = item;
			base..ctor();
		}
	}
}
namespace GrimoireWeissScrap.Behaviours
{
	public class WeissNetworkManager : NetworkBehaviour
	{
		public static WeissNetworkManager Instance;

		public override void OnNetworkSpawn()
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				WeissNetworkManager instance = Instance;
				if (instance != null)
				{
					((Component)instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
				}
			}
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "WeissNetworkManager";
		}
	}
	internal class TomeBelief : PhysicsProp
	{
		private const int BMaxHealth = 100;

		private bool _bIsEquipped;

		public override void GrabItem()
		{
			((GrabbableObject)this).GrabItem();
			_ = (Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null;
		}

		public override void EquipItem()
		{
			((PhysicsProp)this).EquipItem();
			if (!((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null))
			{
				_bIsEquipped = true;
				if (((GrabbableObject)this).scrapValue >= 2 && ((GrabbableObject)this).playerHeldBy.health < 100)
				{
					((MonoBehaviour)this).StartCoroutine(RegenerateCoroutine());
				}
			}
		}

		public override void PocketItem()
		{
			((GrabbableObject)this).PocketItem();
			if (_bIsEquipped)
			{
				_bIsEquipped = false;
			}
		}

		private IEnumerator RegenerateCoroutine()
		{
			int healthMissing = 100 - ((GrabbableObject)this).playerHeldBy.health;
			while (_bIsEquipped && ((GrabbableObject)this).scrapValue > 0 && healthMissing != 0)
			{
				int num = Mathf.Min(2 * healthMissing, ((GrabbableObject)this).scrapValue);
				int healthRegenerated = Mathf.FloorToInt((float)(num / 2));
				RegeneratePlayer(num, healthRegenerated);
				healthMissing = 100 - ((GrabbableObject)this).playerHeldBy.health;
				yield return (object)new WaitForSeconds(3f);
			}
		}

		private void RegeneratePlayer(int scrapCost, int healthRegenerated)
		{
			PlayerControllerB playerHeldBy = ((GrabbableObject)this).playerHeldBy;
			playerHeldBy.health += Mathf.FloorToInt((float)healthRegenerated);
			((GrabbableObject)this).playerHeldBy.DamagePlayerClientRpc(-healthRegenerated, ((GrabbableObject)this).playerHeldBy.health);
			HUDManager.Instance.UpdateHealthUI(((GrabbableObject)this).playerHeldBy.health, false);
			if (((GrabbableObject)this).playerHeldBy.health >= 10 && ((GrabbableObject)this).playerHeldBy.criticallyInjured)
			{
				((GrabbableObject)this).playerHeldBy.MakeCriticallyInjured(false);
			}
			UpdateScrapValueServerRpc(((GrabbableObject)this).scrapValue - scrapCost);
		}

		[ServerRpc(RequireOwnership = false)]
		public void UpdateScrapValueServerRpc(int value)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2231642400u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, value);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2231642400u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					UpdateScrapValueClientRpc(value);
				}
			}
		}

		[ClientRpc]
		public void UpdateScrapValueClientRpc(int value)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2444448827u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, value);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2444448827u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					((GrabbableObject)this).SetScrapValue(value);
				}
			}
		}

		protected override void __initializeVariables()
		{
			((PhysicsProp)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_TomeBelief()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(2231642400u, new RpcReceiveHandler(__rpc_handler_2231642400));
			NetworkManager.__rpc_func_table.Add(2444448827u, new RpcReceiveHandler(__rpc_handler_2444448827));
		}

		private static void __rpc_handler_2231642400(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int value = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref value);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((TomeBelief)(object)target).UpdateScrapValueServerRpc(value);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2444448827(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int value = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref value);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((TomeBelief)(object)target).UpdateScrapValueClientRpc(value);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "TomeBelief";
		}
	}
	internal class TomeBlood : PhysicsProp
	{
		private const int BMinDamage = 25;

		private const int BMaxDamage = 75;

		private int _bUsesLeft;

		private int _bSacrifices;

		private bool _bIsFirstUse = true;

		private bool _bCanFlickerLights = true;

		private PlayerControllerB _wasGrabbedBy;

		private RoundManager _roundManager;

		private bool _bCanScarePlayer;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			_bUsesLeft = 10;
			_roundManager = Object.FindFirstObjectByType<RoundManager>();
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (!buttonDown || (Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null)
			{
				return;
			}
			if ((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && _bUsesLeft > 0)
			{
				_bUsesLeft--;
				if (_bSacrifices >= 3)
				{
					if (_bIsFirstUse)
					{
						HandleUseFirst();
					}
					else
					{
						HandleUse();
					}
					if (Random.value <= 0.05f)
					{
						SacrificeScrapServerRpc();
					}
				}
				else
				{
					((GrabbableObject)this).playerHeldBy.DamagePlayer(100, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				}
			}
			else if (_bUsesLeft <= 0)
			{
				((GrabbableObject)this).playerHeldBy.MakeCriticallyInjured(true);
			}
		}

		public override void GrabItem()
		{
			((GrabbableObject)this).GrabItem();
			if (!((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null))
			{
				if (!Object.op_Implicit((Object)(object)_wasGrabbedBy) && _bCanFlickerLights)
				{
					_roundManager.FlickerLights(false, true);
				}
				_wasGrabbedBy = ((GrabbableObject)this).playerHeldBy;
			}
		}

		public override void EquipItem()
		{
			((PhysicsProp)this).EquipItem();
			if (!((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null) && _bCanScarePlayer)
			{
				((GrabbableObject)this).playerHeldBy.JumpToFearLevel(0.5f, true);
				HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
				_bCanScarePlayer = false;
			}
		}

		public override void PocketItem()
		{
			((GrabbableObject)this).PocketItem();
			if (!((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null) && _bCanFlickerLights && Random.value <= 0.5f)
			{
				_roundManager.FlickerLights(true, false);
			}
		}

		public override void DiscardItem()
		{
			((GrabbableObject)this).DiscardItem();
			if (!((Object)(object)_wasGrabbedBy == (Object)null) && _wasGrabbedBy.isPlayerDead)
			{
				SacrificeScrapServerRpc();
			}
		}

		private void HandleUseFirst()
		{
			//IL_0035: 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)
			_bIsFirstUse = false;
			int num = ((GrabbableObject)this).playerHeldBy.health - 1;
			int num2 = Random.Range(25, Mathf.Min(76, num + 1));
			((GrabbableObject)this).playerHeldBy.DamagePlayer(num2, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
			((GrabbableObject)this).playerHeldBy.JumpToFearLevel(0.5f, true);
			HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
			_roundManager.FlickerLights(false, false);
		}

		private void HandleUse()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			int num = Random.Range(25, 76);
			((GrabbableObject)this).playerHeldBy.DamagePlayer(num, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
			((GrabbableObject)this).playerHeldBy.JumpToFearLevel(0.5f, true);
			HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
			_roundManager.FlickerLights(false, false);
		}

		[ServerRpc(RequireOwnership = false)]
		public void SacrificeScrapServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(915431107u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 915431107u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					int num = ((GrabbableObject)this).scrapValue / 3;
					int newPrice = Random.Range(5, num);
					SacrificeScrapClientRpc(newPrice);
					_roundManager.SpawnEnemiesOutside();
					string[] array = new string[4]
					{
						"In shadows deep, " + _wasGrabbedBy.playerUsername + " surrenders willingly, to the Tome's insatiable hunger.",
						"The air thickens with the scent of sacrifice.",
						"The forbidden rites reach their dark conclusion.",
						"The Tome's hunger grows, consuming their very essence."
					};
					string text = array[Random.Range(0, array.Length)];
					HUDManager.Instance.AddTextToChatOnServer(text, -1);
					_bSacrifices++;
				}
			}
		}

		[ClientRpc]
		private void SacrificeScrapClientRpc(int newPrice)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2585402183u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, newPrice);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2585402183u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			((GrabbableObject)this).SetScrapValue(((GrabbableObject)this).scrapValue + newPrice);
			_bCanFlickerLights = false;
			_roundManager.FlickerLights(false, true);
			foreach (Light allPoweredLight in _roundManager.allPoweredLights)
			{
				((MonoBehaviour)this).StartCoroutine(ChangeLightColorCoroutine(5f, allPoweredLight, Color.red));
			}
			((MonoBehaviour)this).StartCoroutine(SacrificeTurnOffLights(10f, 3f, _roundManager.allPoweredLightsAnimators));
		}

		private IEnumerator SacrificeTurnOffLights(float graceDelay, float turnOffDelay, List<Animator> animators)
		{
			yield return (object)new WaitForSeconds(graceDelay);
			foreach (Animator animator in animators)
			{
				yield return (object)new WaitForSeconds(turnOffDelay);
				animator.SetBool("on", false);
				if (Random.value <= 0.05f)
				{
					_roundManager.FlickerLights(false, false);
				}
			}
		}

		private static IEnumerator ChangeLightColorCoroutine(float delay, Light light, Color color)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForSeconds(delay);
			light.color = color;
		}

		protected override void __initializeVariables()
		{
			((PhysicsProp)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_TomeBlood()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(915431107u, new RpcReceiveHandler(__rpc_handler_915431107));
			NetworkManager.__rpc_func_table.Add(2585402183u, new RpcReceiveHandler(__rpc_handler_2585402183));
		}

		private static void __rpc_handler_915431107(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((TomeBlood)(object)target).SacrificeScrapServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2585402183(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int newPrice = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref newPrice);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((TomeBlood)(object)target).SacrificeScrapClientRpc(newPrice);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "TomeBlood";
		}
	}
	internal class TomeHeaven : PhysicsProp
	{
		protected override void __initializeVariables()
		{
			((PhysicsProp)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "TomeHeaven";
		}
	}
	internal class Weiss : PhysicsProp
	{
		private bool _wIsInDungeon;

		private bool _wCanTalkEnterDungeon = true;

		private bool _wCanTalkLeftDungeon = true;

		private bool _wCanTalkDiscardDungeon = true;

		private bool _wCanTalkDiscardShip = true;

		private bool _wCanTalkSwitchedOff = true;

		private bool _wCanTalkAloneInDungeon = true;

		private bool _wCanTalkClimbing = true;

		private bool _wCanTalkQuicksand = true;

		private bool _wCanTalkSand = true;

		private bool _wCanTalkWater = true;

		private int _wTimesEnteredDungeon;

		private int _wTimesLeftDungeon;

		private int _wTimesDiscardDungeon;

		private int _wTimesDiscardShip;

		private int _wTimesGrabbed;

		private int _wTimesSwitchedOff;

		private AudioSource _audioSource;

		private readonly Dictionary<string, AudioClip> _audioClips = new Dictionary<string, AudioClip>();

		private PlayerControllerB _wasGrabbedBy;

		private RoundManager _roundManager;

		[UsedImplicitly]
		private void Awake()
		{
			_audioSource = ((Component)this).GetComponent<AudioSource>();
		}

		public override void Start()
		{
			((GrabbableObject)this).Start();
			_roundManager = Object.FindFirstObjectByType<RoundManager>();
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (Time.frameCount % 60 != 0 || (Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null)
			{
				return;
			}
			string name = ((Object)_roundManager.currentLevel).name;
			bool flag = ((name == "RendLevel" || name == "DineLevel") ? true : false);
			bool flag2 = flag;
			flag = ((name == "OffenseLevel" || name == "AssuranceLevel") ? true : false);
			bool flag3 = flag;
			if (((GrabbableObject)this).isInFactory)
			{
				if (!_wIsInDungeon)
				{
					_wIsInDungeon = true;
					_wCanTalkDiscardShip = true;
					if (_wCanTalkEnterDungeon)
					{
						if (flag2)
						{
							((MonoBehaviour)this).StartCoroutine(PlayFollowUpLine("PlayerIsEnteringDungeonMansion" + Random.Range(1, 5), 3f, _wIsInDungeon, followUpConditionExpected: true));
						}
						else
						{
							switch (_wTimesEnteredDungeon)
							{
							case 0:
								((MonoBehaviour)this).StartCoroutine(PlayFollowUpLine("PlayerIsEnteringDungeon1", 3f, _wIsInDungeon, followUpConditionExpected: true));
								((MonoBehaviour)this).StartCoroutine(PlayFollowUpLine("PlayerIsEnteringDungeon1FollowUp", 60f, _wIsInDungeon, followUpConditionExpected: true));
								break;
							case 1:
							case 2:
								((MonoBehaviour)this).StartCoroutine(PlayFollowUpLine("PlayerIsEnteringDungeon2", 3f, _wIsInDungeon, followUpConditionExpected: true));
								((MonoBehaviour)this).StartCoroutine(PlayFollowUpLine("PlayerIsEnteringDungeon2FollowUp", 30f, _wIsInDungeon, followUpConditionExpected: true));
								break;
							case 3:
							case 4:
								((MonoBehaviour)this).StartCoroutine(PlayFollowUpLine("PlayerIsEnteringDungeon" + Random.Range(3, 6), 3f, _wIsInDungeon, followUpConditionExpected: true));
								break;
							}
							_wTimesEnteredDungeon++;
							_wCanTalkEnterDungeon = false;
						}
					}
					if (_wCanTalkAloneInDungeon && ((GrabbableObject)this).playerHeldBy.isPlayerAlone && Random.value <= 0.25f)
					{
						((MonoBehaviour)this).StartCoroutine(PlayFollowUpLine("PlayerIsAlone" + Random.Range(1, 3), 120f, ((GrabbableObject)this).playerHeldBy.isPlayerAlone, _wIsInDungeon));
						_wCanTalkAloneInDungeon = false;
					}
					return;
				}
			}
			else
			{
				if (_wIsInDungeon)
				{
					_wIsInDungeon = false;
					if (_wCanTalkLeftDungeon)
					{
						switch (_wTimesLeftDungeon)
						{
						case 0:
							((MonoBehaviour)this).StartCoroutine(PlayFollowUpLine("PlayerIsLeavingDungeon1", 7f, _wIsInDungeon, followUpConditionExpected: false));
							break;
						case 1:
						case 2:
						case 3:
							((MonoBehaviour)this).StartCoroutine(PlayFollowUpLine("PlayerIsLeavingDungeon" + Random.Range(2, 4), 7f, _wIsInDungeon, followUpConditionExpected: false));
							break;
						}
						_wTimesLeftDungeon++;
						_wCanTalkLeftDungeon = false;
					}
					return;
				}
				if (!((GrabbableObject)this).isInElevator)
				{
					if (_wCanTalkClimbing && ((GrabbableObject)this).playerHeldBy.isClimbingLadder && Random.value <= 0.25f)
					{
						_wCanTalkClimbing = false;
					}
					if (_wCanTalkQuicksand && ((GrabbableObject)this).playerHeldBy.isSinking && !((GrabbableObject)this).playerHeldBy.isUnderwater && Random.value <= 0.5f)
					{
						_wCanTalkQuicksand = false;
						PlayAudioClip("Quicksand" + Random.Range(1, 6));
					}
					if (_wCanTalkWater && ((GrabbableObject)this).playerHeldBy.isSinking && ((GrabbableObject)this).playerHeldBy.isUnderwater && Random.value <= 0.5f)
					{
						_wCanTalkWater = false;
						PlayAudioClip("Water" + Random.Range(1, 4));
					}
					if (_wCanTalkSand && flag3 && Random.value <= 0.5f)
					{
						((MonoBehaviour)this).StartCoroutine(PlayFollowUpLine("MapHasSand" + Random.Range(1, 5), 35f, _wIsInDungeon, followUpConditionExpected: false));
						_wCanTalkSand = false;
					}
					return;
				}
			}
			if (((GrabbableObject)this).isInElevator)
			{
				_wCanTalkEnterDungeon = true;
				_wCanTalkLeftDungeon = true;
				_wCanTalkDiscardDungeon = true;
			}
		}

		public override void GrabItem()
		{
			((GrabbableObject)this).GrabItem();
			if ((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null)
			{
				return;
			}
			_wasGrabbedBy = ((GrabbableObject)this).playerHeldBy;
			if (_wTimesGrabbed == 0)
			{
				PlayAudioClip("PlayerPickedWeissIntro" + Random.Range(1, 7));
				_wTimesGrabbed++;
			}
			else if (Random.value <= 0.5f)
			{
				switch (_wTimesGrabbed)
				{
				case 2:
				case 3:
					PlayAudioClip("PlayerPickedWeiss" + Random.Range(1, 5));
					break;
				case 9:
				case 10:
				case 11:
				case 12:
				case 13:
					PlayAudioClip("PlayerPickedWeissIsAnnoyed" + Random.Range(1, 8));
					break;
				}
				_wTimesGrabbed++;
			}
		}

		public override void PocketItem()
		{
			((GrabbableObject)this).PocketItem();
			if ((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null || !_wCanTalkSwitchedOff)
			{
				return;
			}
			_wCanTalkSwitchedOff = false;
			if (_wTimesSwitchedOff == 0)
			{
				PlayAudioClip("PlayerAddedWeissToInv1");
				_wTimesSwitchedOff++;
			}
			else if (Random.value <= 0.5f)
			{
				int wTimesSwitchedOff = _wTimesSwitchedOff;
				if (wTimesSwitchedOff >= 1 && wTimesSwitchedOff <= 7)
				{
					PlayAudioClip("PlayerAddedWeissToInv" + Random.Range(2, 7));
				}
				_wTimesSwitchedOff++;
			}
		}

		public override void DiscardItem()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected I4, but got Unknown
			((GrabbableObject)this).DiscardItem();
			if ((Object)(object)_wasGrabbedBy == (Object)null)
			{
				return;
			}
			if (_wasGrabbedBy.isPlayerDead)
			{
				CauseOfDeath causeOfDeath = _wasGrabbedBy.causeOfDeath;
				switch ((int)causeOfDeath)
				{
				case 7:
					PlayAudioClip("PlayerIsDeadMine1");
					break;
				case 3:
					PlayAudioClip("PlayerIsDeadMine1");
					break;
				case 0:
				case 1:
					PlayAudioClip("PlayerIsDeadBludg1");
					break;
				case 2:
				case 4:
					PlayAudioClip("PlayerIsDeadStra1");
					break;
				case 5:
				case 6:
				case 8:
				case 9:
				case 10:
				case 11:
					PlayAudioClip("PlayerIsDeadElc1");
					break;
				default:
					PlayAudioClip("PlayerIsDead" + Random.Range(1, 7));
					break;
				}
			}
			else
			{
				if (((GrabbableObject)this).isInElevator && _wCanTalkDiscardShip)
				{
					switch (_wTimesDiscardShip)
					{
					case 0:
						PlayAudioClip("PlayerDroppedWeissInsideShip1");
						break;
					case 5:
						PlayAudioClip("PlayerDroppedWeissInsideShip2");
						_wCanTalkDiscardShip = false;
						break;
					}
					_wTimesDiscardShip++;
				}
				if (((GrabbableObject)this).isInFactory && _wCanTalkDiscardDungeon)
				{
					switch (_wTimesDiscardDungeon)
					{
					case 0:
						PlayAudioClip("PlayerDroppedWeissInsideDungeon1");
						break;
					case 5:
						PlayAudioClip("PlayerDroppedWeissInsideDungeon2");
						_wCanTalkDiscardDungeon = false;
						break;
					}
					_wTimesDiscardDungeon++;
				}
			}
			_wCanTalkSwitchedOff = true;
		}

		private void LoadAudioClip(string clip, string clipFile)
		{
			AudioClip val = Plugin.LoadItemFromBundle<AudioClip>(Plugin.WeissBundle, "Assets/Dumbass/Resources/Sounds/Weiss/" + clip + ".wav");
			if ((Object)(object)val != (Object)null)
			{
				_audioClips[clip] = val;
			}
		}

		public void PlayAudioClip(string clip)
		{
			if (!_audioSource.isPlaying)
			{
				if (!_audioClips.ContainsKey(clip))
				{
					LoadAudioClip(clip, clip + ".wav");
				}
				if (_audioClips.ContainsKey(clip))
				{
					_audioSource.PlayOneShot(_audioClips[clip]);
				}
			}
		}

		private IEnumerator PlayFollowUpLine(string clip, float delayInSeconds, bool followUpCondition, bool followUpConditionExpected)
		{
			yield return (object)new WaitForSeconds(delayInSeconds);
			if (followUpCondition == followUpConditionExpected)
			{
				PlayAudioClip(clip);
			}
		}

		protected override void __initializeVariables()
		{
			((PhysicsProp)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "Weiss";
		}
	}
}
namespace GrimoireWeiss.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}