Decompiled source of TouhouCompany v73 v1.0.4

TouhouCompany.dll

Decompiled a month ago
using System;
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.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TouhouCompany.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("TouhouCompany")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ad4c3a017cbae46eab6cf841b0e4e397baafaad1")]
[assembly: AssemblyProduct("TouhouCompany")]
[assembly: AssemblyTitle("TouhouCompany")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 TouhouCompany
{
	public class KoumakanManager : NetworkBehaviour
	{
		public static Dictionary<string, GameObject> Objects;

		private void Awake()
		{
			TouhouCompanyPlugin.Instance.AddLog("Awaking KoumakanManager");
			Objects = new Dictionary<string, GameObject>();
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			TouhouCompanyPlugin.Instance.AddLog("KoumakanManager is awake");
		}

		public void Destroy()
		{
			Objects.Clear();
		}

		[ServerRpc]
		public void SpawnKoumakanServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Invalid comparison between Unknown and I4
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Invalid comparison between Unknown and I4
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				if (((NetworkBehaviour)this).OwnerClientId != networkManager.LocalClientId)
				{
					if ((int)networkManager.LogLevel <= 1)
					{
						Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
					}
					return;
				}
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1437523285u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1437523285u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				TouhouCompanyPlugin.Instance.AddLog("Running SpawnKoumakanServerRpc");
				EnableKoumakanClientRpc();
			}
		}

		[ClientRpc]
		public void EnableKoumakanClientRpc()
		{
			//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)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: 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)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2954063379u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2954063379u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			base.__rpc_exec_stage = (__RpcExecStage)0;
			TouhouCompanyPlugin.Instance.AddLog("Running RearrangeSceneClientRpc");
			Scene sceneByName = SceneManager.GetSceneByName("Level4March");
			GameObject[] rootGameObjects = ((Scene)(ref sceneByName)).GetRootGameObjects();
			try
			{
				GameObject[] array = rootGameObjects;
				foreach (GameObject val3 in array)
				{
					TouhouCompanyPlugin.Instance.AddLog("Processing " + ((Object)val3).name + " on Level4March.");
					if (((Object)val3).name == "Environment")
					{
						Transform val4 = val3.transform.Find("Map/RoofDome");
						((Renderer)((Component)val4).GetComponent<MeshRenderer>()).enabled = false;
						((Collider)((Component)val4).GetComponent<MeshCollider>()).enabled = false;
						GameObject obj = Object.Instantiate<GameObject>(TouhouCompanyPlugin.KoumakanPrefeb);
						obj.transform.SetParent(val4);
						obj.transform.localPosition = Vector3.zero;
						obj.transform.localRotation = Quaternion.identity;
						obj.transform.localScale = Vector3.one;
						TouhouCompanyPlugin.Instance.AddLog("Enable Koumakan.");
						Transform val5 = val3.transform.Find("HangingLight (13)");
						Transform obj2 = val3.transform.Find("HangingLight (14)");
						Object.Destroy((Object)(object)((Component)val5).gameObject);
						Object.Destroy((Object)(object)((Component)obj2).gameObject);
						TouhouCompanyPlugin.Instance.AddLog("Disable HangingLights.");
						Transform val6 = val3.transform.Find("SteelDoorFake");
						Transform val7 = val3.transform.Find("SteelDoorFake (1)");
						Transform obj3 = val3.transform.Find("DoorFrame (1)");
						Object.Destroy((Object)(object)((Component)val6).gameObject);
						Object.Destroy((Object)(object)((Component)val7).gameObject);
						Object.Destroy((Object)(object)((Component)obj3).gameObject);
						TouhouCompanyPlugin.Instance.AddLog("Disable SteelDoor.");
					}
				}
			}
			catch (Exception arg)
			{
				TouhouCompanyPlugin.Instance.AddLog($"An error occured when replacing Level4MarchBuilding: {arg}");
			}
		}

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

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(1437523285u, new RpcReceiveHandler(__rpc_handler_1437523285), "SpawnKoumakanServerRpc");
			((NetworkBehaviour)this).__registerRpc(2954063379u, new RpcReceiveHandler(__rpc_handler_2954063379), "EnableKoumakanClientRpc");
			((NetworkBehaviour)this).__initializeRpcs();
		}

		private static void __rpc_handler_1437523285(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if (rpcParams.Server.Receive.SenderClientId != target.OwnerClientId)
			{
				if ((int)networkManager.LogLevel <= 1)
				{
					Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
				}
			}
			else
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((KoumakanManager)(object)target).SpawnKoumakanServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2954063379(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;
				((KoumakanManager)(object)target).EnableKoumakanClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "KoumakanManager";
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.bean.TouhouCompany";

		public const string PLUGIN_NAME = "TouhouCompany";

		public const string PLUGIN_VERSION = "1.0.3";
	}
	internal class ShrineBuilding : NetworkBehaviour
	{
		private Fog fog;

		private float lowFogWeight = 500f;

		private float highFogWeight;

		private float targetFogWeight;

		private float fogFadeVelocity;

		private float fogFadeTime = 0.5f;

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			try
			{
				Scene sceneByName = SceneManager.GetSceneByName("CompanyBuilding");
				GameObject[] rootGameObjects = ((Scene)(ref sceneByName)).GetRootGameObjects();
				foreach (GameObject val in rootGameObjects)
				{
					if (!(((Object)val).name == "Environment"))
					{
						continue;
					}
					Transform val2 = val.transform.Find("Lighting/BrightDay/Sun/SunAnimContainer/Sky and Fog Global Volume");
					if (Object.op_Implicit((Object)(object)val2))
					{
						TouhouCompanyPlugin.Instance.AddLog("Found fog gameobject, getting volume component");
						fog = (Fog)((Component)val2).GetComponent<Volume>().profile.components.Find((VolumeComponent x) => ((object)x).GetType() == typeof(Fog));
						highFogWeight = ((VolumeParameter<float>)(object)fog.meanFreePath).value;
						targetFogWeight = highFogWeight;
					}
					else
					{
						TouhouCompanyPlugin.Instance.AddLog("Could not find fog gameobject");
					}
				}
			}
			catch
			{
				TouhouCompanyPlugin.Instance.AddLog("Wrong scene for fog.");
			}
		}

		private void Update()
		{
			((VolumeParameter<float>)(object)fog.meanFreePath).value = Mathf.SmoothDamp(((VolumeParameter<float>)(object)fog.meanFreePath).value, targetFogWeight, ref fogFadeVelocity, fogFadeTime);
		}

		private void OnTriggerEnter(Collider other)
		{
			PlayerControllerB val = default(PlayerControllerB);
			if (((Component)other).gameObject.TryGetComponent<PlayerControllerB>(ref val) && (Object)(object)val == (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				targetFogWeight = lowFogWeight;
			}
		}

		private void OnTriggerExit(Collider other)
		{
			PlayerControllerB val = default(PlayerControllerB);
			if (((Component)other).gameObject.TryGetComponent<PlayerControllerB>(ref val) && (Object)(object)val == (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				targetFogWeight = highFogWeight;
			}
		}

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

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

		protected internal override string __getTypeName()
		{
			return "ShrineBuilding";
		}
	}
	public class ShrineManager : NetworkBehaviour
	{
		public static Dictionary<string, GameObject> Objects;

		public static GameObject newspaper;

		public static GameObject note;

		public static Animator sukimaAnimator;

		private void Awake()
		{
			TouhouCompanyPlugin.Instance.AddLog("Awaking ShrineManager");
			Objects = new Dictionary<string, GameObject>();
			newspaper = null;
			note = null;
			sukimaAnimator = null;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			TouhouCompanyPlugin.Instance.AddLog("ShrineManager is awake");
		}

		public void Destroy()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				DespawnShrineServerRpc();
				GameObject obj = newspaper;
				if (obj != null)
				{
					obj.GetComponent<NetworkObject>().Despawn(true);
				}
				GameObject obj2 = note;
				if (obj2 != null)
				{
					obj2.GetComponent<NetworkObject>().Despawn(true);
				}
			}
		}

		[ServerRpc]
		public void SpawnShrineServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Invalid comparison between Unknown and I4
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Invalid comparison between Unknown and I4
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: 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)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				if (((NetworkBehaviour)this).OwnerClientId != networkManager.LocalClientId)
				{
					if ((int)networkManager.LogLevel <= 1)
					{
						Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
					}
					return;
				}
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2162103487u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2162103487u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				TouhouCompanyPlugin.Instance.AddLog("Running SpawnShrineServerRpc");
				Objects.Add("Shrine", Spawn(TouhouCompanyPlugin.HakureiShrinePrefeb, new Vector3(-28f, -1.9498372f, -96.44496f), Quaternion.Euler(270f, 90f, 0f), new Vector3(1.7513003f, 1.7513002f, 1.7513001f)));
				if ((Object)(object)newspaper == (Object)null)
				{
					newspaper = Spawn(TouhouCompanyPlugin.NewspaperPrefeb, new Vector3(-42.604f, -0.8589f, -34.657f), Quaternion.Euler(0f, 90f, 180f), new Vector3(0.36530885f, 0.3653086f, 0.36530864f));
				}
				if ((Object)(object)note == (Object)null)
				{
					note = Spawn(TouhouCompanyPlugin.NotePrefeb, new Vector3(-37.24687f, 0.43543386f, -36.885f), Quaternion.Euler(-3f, 270f, 0f), new Vector3(0.18259469f, 0.9129729f, 0.18259466f));
				}
				EnableShrineCompanyClientRpc(Objects["Shrine"].GetComponent<NetworkObject>().NetworkObjectId);
			}
		}

		public static GameObject Spawn(GameObject prefeb, Vector3 location, Quaternion rotation, Vector3 scale)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			TouhouCompanyPlugin.Instance.AddLog("Instantiating " + ((Object)prefeb).name + "...");
			GameObject val = Object.Instantiate<GameObject>(prefeb, location, rotation);
			val.transform.localScale = scale;
			NetworkObject component = val.GetComponent<NetworkObject>();
			if ((Object)(object)component != (Object)null)
			{
				component.Spawn(false);
				TouhouCompanyPlugin.Instance.AddLog(((Object)val).name + " NetworkObject spawned.");
			}
			else
			{
				TouhouCompanyPlugin.Instance.AddLog(((Object)val).name + "NetworkObject could not be spawned.");
			}
			return val;
		}

		[ClientRpc]
		public void EnableShrineCompanyClientRpc(ulong shrineId)
		{
			//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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_062a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0645: Unknown result type (might be due to invalid IL or missing references)
			//IL_0660: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Expected O, but got Unknown
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_051d: Expected O, but got Unknown
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2617659191u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, shrineId);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2617659191u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			base.__rpc_exec_stage = (__RpcExecStage)0;
			TouhouCompanyPlugin.Instance.AddLog("Running EnableShrineCompanyClientRpc");
			NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(shrineId, out var value);
			((Behaviour)((Component)((Component)value).transform).GetComponent<Animator>()).enabled = false;
			Scene sceneByName = SceneManager.GetSceneByName("CompanyBuilding");
			GameObject[] rootGameObjects = ((Scene)(ref sceneByName)).GetRootGameObjects();
			try
			{
				GameObject[] array = rootGameObjects;
				foreach (GameObject val3 in array)
				{
					TouhouCompanyPlugin.Instance.AddLog("Processing " + ((Object)val3).name + " on CompanyBuilding.");
					switch (((Object)val3).name)
					{
					case "Systems":
						if (TouhouCompanyPlugin.EnableSkyBoxReplace.Value && (Object)(object)TouhouCompanyPlugin.SkyBoxPrefeb != (Object)null)
						{
							Transform val6 = val3.transform.Find("Rendering");
							Object.Instantiate<GameObject>(TouhouCompanyPlugin.SkyBoxPrefeb, val6);
							TouhouCompanyPlugin.Instance.AddLog("Init SkyBox.");
						}
						break;
					case "CompanyMonstersAnims":
					{
						Transform val7 = val3.transform.Find("TentacleAnimContainer/GrossTentacle/BezierCurve");
						Transform obj = val3.transform.Find("TentacleAnimContainer/GrossTentacle2/BezierCurve");
						((Renderer)((Component)val7).GetComponent<SkinnedMeshRenderer>()).enabled = false;
						((Renderer)((Component)obj).GetComponent<SkinnedMeshRenderer>()).enabled = false;
						TouhouCompanyPlugin.Instance.AddLog("Disable Tentacles.");
						break;
					}
					case "Cube":
						Object.Destroy((Object)(object)val3);
						TouhouCompanyPlugin.Instance.AddLog("Destroy Cube.");
						break;
					case "DepositCounter":
					{
						Object.Destroy((Object)(object)((Component)val3.transform.Find("SpeakerBox")).gameObject);
						Object.Destroy((Object)(object)((Component)val3.transform.Find("TinyCamera (1)")).gameObject);
						Transform obj2 = val3.transform.Find("DoorAndHookAnim");
						((Collider)((Component)obj2).GetComponent<BoxCollider>()).isTrigger = true;
						((Renderer)((Component)obj2.Find("DepositCounterDoor (1)")).GetComponent<MeshRenderer>()).enabled = false;
						Transform obj3 = obj2.Find("InteractCube");
						obj3.localPosition = new Vector3(53.063f, -8.747f, 21.462f);
						obj3.localScale = new Vector3(0.93f, 1.4f, 0.75f);
						((Component)obj3).GetComponent<InteractTrigger>().hoverTip = "Donate item : [LMB]";
						sukimaAnimator = ((value != null) ? ((Component)((Component)value).transform.Find("HakureiShrine/Armature/Book殿_Parent")).GetComponent<Animator>() : null);
						((Component)val3.transform.Find("Audios/SpeakerAudio")).GetComponent<AudioSource>();
						TouhouCompanyPlugin.Instance.AddLog("Disable DepositCounter.");
						break;
					}
					case "Plane":
						Object.Destroy((Object)(object)val3);
						TouhouCompanyPlugin.Instance.AddLog("Destroy Plane.");
						break;
					case "Environment":
						foreach (Transform item in val3.transform.Find("Map/ShippingContainers"))
						{
							Transform val8 = item;
							bool flag;
							switch (((Object)val8).name)
							{
							case "ShippingContainer":
							case "ShippingContainer (1)":
							case "ShippingContainer (3)":
							case "ShippingContainer (4)":
								flag = true;
								break;
							default:
								flag = false;
								break;
							}
							if (flag)
							{
								Object.Destroy((Object)(object)((Component)val8).gameObject);
							}
						}
						TouhouCompanyPlugin.Instance.AddLog("Destroy ShippingContainers.");
						Object.Destroy((Object)(object)((Component)val3.transform.Find("Map/CompanyPlanet/Cube.003")).gameObject);
						TouhouCompanyPlugin.Instance.AddLog("Destroy Cube.003.");
						foreach (Transform item2 in val3.transform.Find("LightsContainer"))
						{
							Transform val9 = item2;
							bool flag;
							switch (((Object)val9).name)
							{
							case "LEDHangingLight (2)":
							case "LEDHangingLight (3)":
							case "LEDHangingLight (4)":
								flag = true;
								break;
							default:
								flag = false;
								break;
							}
							if (flag)
							{
								Object.Destroy((Object)(object)((Component)val9).gameObject);
							}
						}
						TouhouCompanyPlugin.Instance.AddLog("Destroy HangingLights.");
						break;
					case "BellDinger":
					{
						((Renderer)((Component)val3.transform.Find("BellDingerAnimContainer/BellTop")).GetComponent<MeshRenderer>()).enabled = false;
						((Renderer)((Component)val3.transform.Find("BellDingerAnimContainer/Stand")).GetComponent<MeshRenderer>()).enabled = false;
						Transform val4 = val3.transform.Find("Trigger");
						((Collider)((Component)val4).GetComponent<BoxCollider>()).isTrigger = true;
						Transform val5 = ((value != null) ? ((Component)value).transform.Find("HakureiShrine/铃/BellTrigger") : null);
						if ((Object)(object)val5 != (Object)null)
						{
							val4.localPosition = new Vector3(2.304908f, 1.9572053f, -1.7881355f);
							val4.localRotation = Quaternion.Euler(270f, 270f, 0f);
							val4.localScale = new Vector3(0.17513005f, 0.20139953f, 3.9404252f);
							AnimatedObjectTrigger component = ((Component)val4).GetComponent<AnimatedObjectTrigger>();
							AnimatedObjectTrigger component2 = ((Component)val5).GetComponent<AnimatedObjectTrigger>();
							component.triggerAnimator = component2.triggerAnimator;
							component.boolFalseAudios = component2.boolFalseAudios;
							TouhouCompanyPlugin.Instance.AddLog("BellTrigger changed.");
						}
						TouhouCompanyPlugin.Instance.AddLog("Disable Bell.");
						break;
					}
					}
				}
			}
			catch (Exception arg)
			{
				TouhouCompanyPlugin.Instance.AddLog($"An error occured when replacing the CompanyBuilding: {arg}");
			}
		}

		[ServerRpc]
		public void DespawnShrineServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Invalid comparison between Unknown and I4
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Invalid comparison between Unknown and I4
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				if (((NetworkBehaviour)this).OwnerClientId != networkManager.LocalClientId)
				{
					if ((int)networkManager.LogLevel <= 1)
					{
						Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
					}
					return;
				}
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(153946479u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 153946479u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
			{
				return;
			}
			base.__rpc_exec_stage = (__RpcExecStage)0;
			foreach (KeyValuePair<string, GameObject> @object in Objects)
			{
				GameObject value = @object.Value;
				if (value != null)
				{
					value.GetComponent<NetworkObject>().Despawn(true);
				}
			}
			Objects.Clear();
		}

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

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(2162103487u, new RpcReceiveHandler(__rpc_handler_2162103487), "SpawnShrineServerRpc");
			((NetworkBehaviour)this).__registerRpc(2617659191u, new RpcReceiveHandler(__rpc_handler_2617659191), "EnableShrineCompanyClientRpc");
			((NetworkBehaviour)this).__registerRpc(153946479u, new RpcReceiveHandler(__rpc_handler_153946479), "DespawnShrineServerRpc");
			((NetworkBehaviour)this).__initializeRpcs();
		}

		private static void __rpc_handler_2162103487(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if (rpcParams.Server.Receive.SenderClientId != target.OwnerClientId)
			{
				if ((int)networkManager.LogLevel <= 1)
				{
					Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
				}
			}
			else
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((ShrineManager)(object)target).SpawnShrineServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2617659191(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)
			{
				ulong shrineId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref shrineId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((ShrineManager)(object)target).EnableShrineCompanyClientRpc(shrineId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_153946479(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if (rpcParams.Server.Receive.SenderClientId != target.OwnerClientId)
			{
				if ((int)networkManager.LogLevel <= 1)
				{
					Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
				}
			}
			else
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((ShrineManager)(object)target).DespawnShrineServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "ShrineManager";
		}
	}
	[BepInPlugin("com.bean.TouhouCompany", "TouhouCompany", "1.0.3")]
	public class TouhouCompanyPlugin : BaseUnityPlugin
	{
		public static TouhouCompanyPlugin Instance;

		public static GameObject YukuriPrefeb;

		public static AudioClip YukuriAudio;

		internal static ConfigEntry<bool> EnableYukuriReplace;

		internal static ConfigEntry<bool> EnableYukuriAudio;

		internal static ConfigEntry<float> YukuriAudioVolume;

		public static GameObject ShanghaiPrefeb;

		internal static ConfigEntry<bool> EnableShanghaiReplace;

		public static GameObject MoriyaShrinePrefeb;

		public static AudioClip NitoriTheme;

		public static AudioClip NitoriThemeFar;

		internal static ConfigEntry<bool> EnableMoriyaReplace;

		internal static ConfigEntry<bool> EnableNitoriTheme;

		internal static ConfigEntry<float> NitoriThemeVolume;

		public static GameObject HakureiShrinePrefeb;

		public static GameObject NewspaperPrefeb;

		public static GameObject NotePrefeb;

		internal static ConfigEntry<bool> EnableHakureiReplace;

		public static GameObject SkyBoxPrefeb;

		internal static ConfigEntry<bool> EnableSkyBoxReplace;

		public static AudioMixer TuneMixer;

		public static GameObject KoumakanPrefeb;

		internal static ConfigEntry<bool> EnableKoumakanReplace;

		public static GameObject HangarShipPrefeb;

		internal static ConfigEntry<bool> EnableHangarShipReplace;

		private void Awake()
		{
			Instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"  ______ ____   __  __ __  __ ____   __  __");
			((BaseUnityPlugin)this).Logger.LogInfo((object)" /_  __// __ \\ / / / // / / // __ \\ / / / /");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"  / /  / / / // / / // /_/ // / / // / / / ");
			((BaseUnityPlugin)this).Logger.LogInfo((object)" / /  / /_/ // /_/ // __  // /_/ // /_/ /  ");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"/_/   \\____/ \\____//_/ /_/ \\____/ \\____/   ");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"");
			EnableYukuriReplace = ((BaseUnityPlugin)this).Config.Bind<bool>("1.Pumpkin", "EnableYukuriReplace", true, "Replace the model of Jack'o Lantern to YukuriReimu.");
			EnableYukuriAudio = ((BaseUnityPlugin)this).Config.Bind<bool>("1.Pumpkin", "EnableYukuriAudio", true, "Replace the audio to \"Yukuri\".");
			YukuriAudioVolume = ((BaseUnityPlugin)this).Config.Bind<float>("1.Pumpkin", "YukuriAudioVolume(0.0-1.0)", 0.3f, "Config the volume of \"Yukuri\".");
			EnableShanghaiReplace = ((BaseUnityPlugin)this).Config.Bind<bool>("2.PJMan", "EnableShanghaiReplace", true, "Replace the PJMan with 上海人形.");
			EnableMoriyaReplace = ((BaseUnityPlugin)this).Config.Bind<bool>("3.ItemShip", "EnableMoriyaReplace", true, "Replace the Item Ship with Moriya Shrine.");
			EnableNitoriTheme = ((BaseUnityPlugin)this).Config.Bind<bool>("3.ItemShip", "EnableNitoriTheme", true, "Replace the default music to Nitori's theme music.");
			NitoriThemeVolume = ((BaseUnityPlugin)this).Config.Bind<float>("3.ItemShip", "NitoriThemeVolume(0.0-1.0)", 1f, "Config the volume of Nitori's theme music.");
			EnableHakureiReplace = ((BaseUnityPlugin)this).Config.Bind<bool>("4.CompanyBuilding", "EnableHakureiReplace", true, "Replace the Company Building with Hakurei Shrine.");
			EnableSkyBoxReplace = ((BaseUnityPlugin)this).Config.Bind<bool>("4.CompanyBuilding", "EnableSkyBoxReplace", true, "Replace the SkyBox.");
			EnableKoumakanReplace = ((BaseUnityPlugin)this).Config.Bind<bool>("5.March", "EnableKoumakanReplace", true, "Replace the March Building with Koumakan.");
			EnableHangarShipReplace = ((BaseUnityPlugin)this).Config.Bind<bool>("6.HangarShip", "EnableHangarShipReplace", false, "Replace the HangarShip with 圣辇船. This is not finished. Not recommend.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Patching all functions.");
			NetcodeWeaver();
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"All systems ready, begin loading assets.");
			try
			{
				string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
				if (directoryName == null)
				{
					return;
				}
				AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(directoryName, "shipassets"));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading asset bundle.");
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				if (EnableYukuriReplace.Value)
				{
					YukuriPrefeb = val.LoadAsset<GameObject>("YukuriUnlockableContainer.prefab");
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"Load Yukuri: {(Object)(object)YukuriPrefeb != (Object)null}");
					if (EnableYukuriAudio.Value)
					{
						YukuriAudio = val.LoadAsset<AudioClip>("yukuri.ogg");
						((BaseUnityPlugin)this).Logger.LogInfo((object)$"Load YukuriAudio: {(Object)(object)YukuriAudio != (Object)null}");
					}
				}
				if (EnableShanghaiReplace.Value)
				{
					ShanghaiPrefeb = val.LoadAsset<GameObject>("上海人形Container.prefab");
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"Load Shanghai: {(Object)(object)ShanghaiPrefeb != (Object)null}");
				}
				if (EnableMoriyaReplace.Value)
				{
					MoriyaShrinePrefeb = val.LoadAsset<GameObject>("守矢.prefab");
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"Load Moriya: {(Object)(object)MoriyaShrinePrefeb != (Object)null}");
					if (EnableNitoriTheme.Value)
					{
						NitoriTheme = val.LoadAsset<AudioClip>("Nitori.mp3");
						NitoriThemeFar = val.LoadAsset<AudioClip>("NitoriFar.mp3");
						((BaseUnityPlugin)this).Logger.LogInfo((object)($"Load NitoriTheme: {(Object)(object)NitoriTheme != (Object)null}, " + $"NitoriThemeFar: {(Object)(object)NitoriThemeFar != (Object)null}"));
					}
				}
				if (EnableHakureiReplace.Value)
				{
					HakureiShrinePrefeb = val.LoadAsset<GameObject>("Shrine.prefab");
					HakureiShrinePrefeb.AddComponent<ShrineBuilding>();
					NewspaperPrefeb = val.LoadAsset<GameObject>("Newspaper.prefab");
					NotePrefeb = val.LoadAsset<GameObject>("Note.prefab");
					TuneMixer = val.LoadAsset<AudioMixer>("Tuner");
					((BaseUnityPlugin)this).Logger.LogInfo((object)($"Load Hakurei: {(Object)(object)HakureiShrinePrefeb != (Object)null}, " + $"Newspaper: {(Object)(object)NewspaperPrefeb != (Object)null}, " + $"Note: {(Object)(object)NotePrefeb != (Object)null}," + $"TuneMixer: {(Object)(object)TuneMixer != (Object)null}"));
					if (EnableSkyBoxReplace.Value)
					{
						SkyBoxPrefeb = val.LoadAsset<GameObject>("SkyBox.prefab");
						((BaseUnityPlugin)this).Logger.LogInfo((object)$"Load SkyBox: {(Object)(object)SkyBoxPrefeb != (Object)null}");
					}
				}
				if (EnableKoumakanReplace.Value)
				{
					KoumakanPrefeb = val.LoadAsset<GameObject>("Koumakan.prefab");
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"Load Koumakan: {(Object)(object)KoumakanPrefeb != (Object)null}");
				}
				if (EnableHangarShipReplace.Value)
				{
					HangarShipPrefeb = val.LoadAsset<GameObject>("圣辇船.prefab");
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"Load HangarShip: {(Object)(object)HangarShipPrefeb != (Object)null}");
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load assetbundle: " + ex.Message));
			}
		}

		private void Start()
		{
			try
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Start is good.");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Start not good." + ex.Message));
			}
		}

		public void AddLog(string info)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)info);
		}

		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);
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TouhouCompany";

		public const string PLUGIN_NAME = "TouhouCompany";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace TouhouCompany.Patches
{
	[HarmonyPatch(typeof(AutoParentToShip))]
	internal class AutoParentToShipPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void ReplaceUnlockable(AutoParentToShip __instance)
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			string name = ((Object)((Component)__instance).transform).name;
			if (name.Contains("PumpkinUnlockableContainer") && (Object)(object)TouhouCompanyPlugin.YukuriPrefeb != (Object)null && TouhouCompanyPlugin.EnableYukuriReplace.Value)
			{
				try
				{
					Transform obj = ((Component)__instance).transform.Find("PumpkinMesh");
					MeshRenderer val = ((obj != null) ? ((Component)obj).GetComponent<MeshRenderer>() : null);
					if (!((Object)(object)val == (Object)null))
					{
						((Renderer)val).enabled = false;
						PlaceableShipObject component = ((Component)((Component)__instance).transform.Find("PlacementCollider")).GetComponent<PlaceableShipObject>();
						AnimatedObjectTrigger component2 = ((Component)((Component)__instance).transform.Find("HitPumpkinTrigger")).GetComponent<AnimatedObjectTrigger>();
						Transform val2 = Object.Instantiate<GameObject>(TouhouCompanyPlugin.YukuriPrefeb).transform.Find("Yukuri");
						val2.SetParent(((Component)__instance).transform);
						((Component)val2).transform.localPosition = ((Component)val).transform.localPosition;
						((Component)val2).transform.localRotation = ((Component)val).transform.localRotation;
						((Component)val2).transform.localScale = Vector3.one;
						component.mainMesh = ((Component)val2).GetComponent<MeshFilter>();
						component2.boolFalseAudios[0] = TouhouCompanyPlugin.YukuriAudio;
						TouhouCompanyPlugin.Instance.AddLog("Replaced the Pumpkin.");
					}
					return;
				}
				catch
				{
					TouhouCompanyPlugin.Instance.AddLog("Failed to replace the Pumpkin.");
					return;
				}
			}
			if (!name.Contains("PlushiePJManContainer") || !((Object)(object)TouhouCompanyPlugin.ShanghaiPrefeb != (Object)null) || !TouhouCompanyPlugin.EnableShanghaiReplace.Value)
			{
				return;
			}
			try
			{
				Transform obj3 = ((Component)__instance).transform.Find("PJManPlush");
				MeshRenderer val3 = ((obj3 != null) ? ((Component)obj3).GetComponent<MeshRenderer>() : null);
				if (!((Object)(object)val3 == (Object)null))
				{
					((Renderer)val3).enabled = false;
					PlaceableShipObject component3 = ((Component)((Component)__instance).transform.Find("PlacementCollider")).GetComponent<PlaceableShipObject>();
					AnimatedObjectTrigger component4 = ((Component)((Component)__instance).transform.Find("TouchTrigger")).GetComponent<AnimatedObjectTrigger>();
					Transform val4 = Object.Instantiate<GameObject>(TouhouCompanyPlugin.ShanghaiPrefeb).transform.Find("PJManPlush");
					val4.SetParent(((Component)__instance).transform);
					((Component)val4).transform.localPosition = ((Component)val3).transform.localPosition;
					((Component)val4).transform.localRotation = ((Component)val3).transform.localRotation;
					((Component)val4).transform.localScale = ((Component)val3).transform.localScale;
					component3.mainMesh = ((Component)val4).GetComponent<MeshFilter>();
					component4.triggerAnimator = ((Component)val4).GetComponent<Animator>();
					TouhouCompanyPlugin.Instance.AddLog("Replaced the Plushie.");
				}
			}
			catch
			{
				TouhouCompanyPlugin.Instance.AddLog("Failed to replace the Plushie.");
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class GameNetworkManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StartPatch(GameNetworkManager __instance)
		{
			TouhouCompanyPlugin.Instance.AddLog("Adding network prefab");
			NetworkManager.Singleton.AddNetworkPrefab(TouhouCompanyPlugin.HakureiShrinePrefeb);
			NetworkManager.Singleton.AddNetworkPrefab(TouhouCompanyPlugin.NewspaperPrefeb);
			NetworkManager.Singleton.AddNetworkPrefab(TouhouCompanyPlugin.NotePrefeb);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
		public static void StartDisconnectPatch()
		{
			TouhouCompanyPlugin.Instance.AddLog("Player disconnected.");
		}
	}
	[HarmonyPatch]
	internal class InitializeGamePatches
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(InitializeGame), "Start")]
		public static void startInitializeGame(InitializeGame __instance)
		{
			if (TouhouCompanyPlugin.EnableHakureiReplace.Value && (Object)(object)TouhouCompanyPlugin.HakureiShrinePrefeb != (Object)null)
			{
				try
				{
					__instance.playColdOpenCinematic = true;
				}
				catch (Exception arg)
				{
					TouhouCompanyPlugin.Instance.AddLog($"An error occured when startInitializeGame: {arg}");
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ColdOpenCinematicCutscene), "Start")]
		public static void startColdOpenCinematic(ColdOpenCinematicCutscene __instance)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0518: Unknown result type (might be due to invalid IL or missing references)
			//IL_0537: Unknown result type (might be due to invalid IL or missing references)
			//IL_0555: Unknown result type (might be due to invalid IL or missing references)
			if (!TouhouCompanyPlugin.EnableHakureiReplace.Value || !((Object)(object)TouhouCompanyPlugin.HakureiShrinePrefeb != (Object)null))
			{
				return;
			}
			try
			{
				Scene sceneByName = SceneManager.GetSceneByName("ColdOpen1");
				GameObject[] rootGameObjects = ((Scene)(ref sceneByName)).GetRootGameObjects();
				foreach (GameObject val in rootGameObjects)
				{
					TouhouCompanyPlugin.Instance.AddLog("Processing " + ((Object)val).name + " on ColdOpen1.");
					switch (((Object)val).name)
					{
					case "ColdOpenMonitorRoom":
					case "DoorFrame":
					case "ComputerChairAndShelf":
						val.SetActive(false);
						TouhouCompanyPlugin.Instance.AddLog("Disable " + ((Object)val).name + ".");
						break;
					case "Systems":
						if (TouhouCompanyPlugin.EnableSkyBoxReplace.Value && (Object)(object)TouhouCompanyPlugin.SkyBoxPrefeb != (Object)null)
						{
							Transform val3 = val.transform.Find("Rendering");
							Object.Instantiate<GameObject>(TouhouCompanyPlugin.SkyBoxPrefeb, val3);
							TouhouCompanyPlugin.Instance.AddLog("Init SkyBox.");
						}
						break;
					case "Plane":
						val.transform.localPosition = new Vector3(-20.424732f, 10.964f, -2.058f);
						TouhouCompanyPlugin.Instance.AddLog("Set " + ((Object)val).name + ".");
						break;
					case "ColdOpen1AnimContainer":
					{
						Transform val2 = val.transform.Find("Cube.005");
						((Renderer)((Component)val2).GetComponent<MeshRenderer>()).enabled = false;
						TouhouCompanyPlugin.Instance.AddLog("Disable " + ((Object)val2).name + ".");
						val2 = val.transform.Find("MiscProps3/CurtainRod (2)");
						val2.localPosition = new Vector3(-15.71f, 7.64701f, -23.859324f);
						TouhouCompanyPlugin.Instance.AddLog("Set " + ((Object)val2).name + ".");
						val2 = val.transform.Find("MiscProps3/Cylinder.001 (1)");
						val2.localPosition = new Vector3(-13.64f, 2.527f, -8.006232f);
						TouhouCompanyPlugin.Instance.AddLog("Set " + ((Object)val2).name + ".");
						val2 = val.transform.Find("MiscProps3/FancyDesk");
						((Renderer)((Component)val2).GetComponent<MeshRenderer>()).enabled = false;
						TouhouCompanyPlugin.Instance.AddLog("Disable " + ((Object)val2).name + ".");
						val2 = val.transform.Find("MiscProps3/PottedPlant");
						((Renderer)((Component)val2).GetComponent<MeshRenderer>()).enabled = false;
						TouhouCompanyPlugin.Instance.AddLog("Disable " + ((Object)val2).name + ".");
						val2 = val.transform.Find("MiscProps3/Cube.002");
						((Component)val2).gameObject.SetActive(false);
						TouhouCompanyPlugin.Instance.AddLog("Disable " + ((Object)val2).name + ".");
						val2 = val.transform.Find("Door");
						((Component)val2).gameObject.SetActive(false);
						TouhouCompanyPlugin.Instance.AddLog("Disable " + ((Object)val2).name + ".");
						val2 = val.transform.Find("Lamp");
						((Component)val2).gameObject.SetActive(false);
						TouhouCompanyPlugin.Instance.AddLog("Disable " + ((Object)val2).name + ".");
						val2 = val.transform.Find("Remote");
						((Renderer)((Component)val2).GetComponent<MeshRenderer>()).enabled = false;
						TouhouCompanyPlugin.Instance.AddLog("Disable " + ((Object)val2).name + ".");
						val2 = val.transform.Find("ShipModels2b");
						((Component)val2).gameObject.SetActive(false);
						TouhouCompanyPlugin.Instance.AddLog("Disable " + ((Object)val2).name + ".");
						val2 = val.transform.Find("Desk");
						((Renderer)((Component)val2).GetComponent<MeshRenderer>()).enabled = false;
						TouhouCompanyPlugin.Instance.AddLog("Disable " + ((Object)val2).name + ".");
						val2 = val.transform.Find("DeskAddonComponent");
						((Renderer)((Component)val2).GetComponent<MeshRenderer>()).enabled = false;
						TouhouCompanyPlugin.Instance.AddLog("Disable " + ((Object)val2).name + ".");
						GameObject obj = Object.Instantiate<GameObject>(TouhouCompanyPlugin.HakureiShrinePrefeb);
						Object.Destroy((Object)(object)obj.GetComponent<NetworkObject>());
						Object.Destroy((Object)(object)obj.GetComponent<ShrineBuilding>());
						Object.Destroy((Object)(object)((Component)obj.transform.Find("HakureiShrine/Body/RecordPlayerContainer/Audio")).GetComponentInChildren<OccludeAudio>());
						Object.Destroy((Object)(object)((Component)obj.transform.Find("HakureiShrine/Body/TelevisionContainer/TVAudio")).GetComponentInChildren<OccludeAudio>());
						Object.Destroy((Object)(object)((Component)obj.transform.Find("HakureiShrine/Armature/土Interval_Parent/Toilet/Cube")).GetComponentInChildren<OccludeAudio>());
						obj.transform.position = new Vector3(4.1f, 7.198653f, -85.7f);
						obj.transform.rotation = Quaternion.Euler(270f, 90f, 0f);
						obj.transform.localScale = new Vector3(2.5f, 2.5f, 2.5f);
						TouhouCompanyPlugin.Instance.AddLog("Enable Shrine.");
						break;
					}
					}
				}
			}
			catch (Exception arg)
			{
				TouhouCompanyPlugin.Instance.AddLog($"An error occured when startColdOpenCinematic: {arg}");
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ColdOpenCinematicCutscene), "Update")]
		public static void updateColdOpenCinematic(ColdOpenCinematicCutscene __instance)
		{
			if (!TouhouCompanyPlugin.EnableHakureiReplace.Value || !((Object)(object)TouhouCompanyPlugin.HakureiShrinePrefeb != (Object)null))
			{
				return;
			}
			try
			{
				if (((ButtonControl)Keyboard.current.escapeKey).wasPressedThisFrame)
				{
					__instance.EndColdOpenCutscene();
				}
			}
			catch (Exception arg)
			{
				TouhouCompanyPlugin.Instance.AddLog($"An error occured when updateColdOpenCinematic: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(ItemDropship))]
	internal class ItemDropshipPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Start")]
		private static void ReplaceItemShip(ItemDropship __instance)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)TouhouCompanyPlugin.MoriyaShrinePrefeb != (Object)null) || !TouhouCompanyPlugin.EnableMoriyaReplace.Value)
			{
				return;
			}
			try
			{
				((Collider)((Component)((Component)__instance).transform).GetComponent<BoxCollider>()).enabled = false;
				Transform val = ((Component)__instance).transform.Find("ItemShip");
				((Renderer)((Component)val).GetComponent<MeshRenderer>()).enabled = false;
				for (int i = 0; i < val.childCount; i++)
				{
					Transform child = val.GetChild(i);
					if (((Object)child).name.Contains("Door"))
					{
						((Renderer)((Component)child).GetComponent<MeshRenderer>()).enabled = false;
					}
				}
				TouhouCompanyPlugin.Instance.AddLog("Hide ItemDropship model.");
				GameObject obj = Object.Instantiate<GameObject>(TouhouCompanyPlugin.MoriyaShrinePrefeb);
				obj.transform.SetParent(val);
				obj.transform.localPosition = Vector3.zero;
				obj.transform.localRotation = Quaternion.identity;
				obj.transform.localScale = new Vector3(0.77f, 0.77f, 0.77f);
				val.Find("Point Light").localPosition = new Vector3(0.037f, 0f, 1.75f);
				TouhouCompanyPlugin.Instance.AddLog("ItemDropship model replaced.");
				if (TouhouCompanyPlugin.EnableNitoriTheme.Value && (Object)(object)TouhouCompanyPlugin.NitoriTheme != (Object)null && (Object)(object)TouhouCompanyPlugin.NitoriThemeFar != (Object)null)
				{
					Transform obj2 = ((Component)__instance).transform.Find("Music");
					AudioSource component = ((Component)obj2).GetComponent<AudioSource>();
					component.clip = TouhouCompanyPlugin.NitoriTheme;
					component.volume = TouhouCompanyPlugin.NitoriThemeVolume.Value;
					AudioSource component2 = ((Component)obj2.Find("Music (1)")).GetComponent<AudioSource>();
					component2.clip = TouhouCompanyPlugin.NitoriThemeFar;
					component2.volume = TouhouCompanyPlugin.NitoriThemeVolume.Value;
					TouhouCompanyPlugin.Instance.AddLog("NitoriTheme replaced.");
				}
			}
			catch (Exception arg)
			{
				TouhouCompanyPlugin.Instance.AddLog($"An error occured when replacing the ItemDropship: {arg}");
			}
		}
	}
	[HarmonyPatch]
	internal class OtherPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(DepositItemsDesk), "OpenShutDoor")]
		public static void AngryMeshFix(DepositItemsDesk __instance, bool open)
		{
			if (!TouhouCompanyPlugin.EnableHakureiReplace.Value || !((Object)(object)TouhouCompanyPlugin.HakureiShrinePrefeb != (Object)null))
			{
				return;
			}
			try
			{
				Animator sukimaAnimator = ShrineManager.sukimaAnimator;
				if (sukimaAnimator != null)
				{
					sukimaAnimator.SetBool("doorOpen", open);
				}
			}
			catch (Exception arg)
			{
				TouhouCompanyPlugin.Instance.AddLog($"An error occured when enable Sukima: {arg}");
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(DepositItemsDesk), "Attack")]
		public static void AngryMeshFix(DepositItemsDesk __instance)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!TouhouCompanyPlugin.EnableHakureiReplace.Value || !((Object)(object)TouhouCompanyPlugin.HakureiShrinePrefeb != (Object)null))
			{
				return;
			}
			try
			{
				Scene sceneByName = SceneManager.GetSceneByName("CompanyBuilding");
				GameObject[] rootGameObjects = ((Scene)(ref sceneByName)).GetRootGameObjects();
				foreach (GameObject val in rootGameObjects)
				{
					TouhouCompanyPlugin.Instance.AddLog("Processing " + ((Object)val).name + ".");
					if (((Object)val).name == "CompanyMonstersAnims")
					{
						Transform val2 = val.transform.Find("TentacleAnimContainer/GrossTentacle/BezierCurve");
						Transform obj = val.transform.Find("TentacleAnimContainer/GrossTentacle2/BezierCurve");
						((Renderer)((Component)val2).GetComponent<SkinnedMeshRenderer>()).enabled = true;
						((Renderer)((Component)obj).GetComponent<SkinnedMeshRenderer>()).enabled = true;
						TouhouCompanyPlugin.Instance.AddLog("Enable Tentacles.");
					}
				}
			}
			catch (Exception arg)
			{
				TouhouCompanyPlugin.Instance.AddLog($"An error occured when enable CompanyMonster: {arg}");
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControllerB), "SetObjectAsNoLongerHeld")]
		public static bool TestNoLongerHeld(bool droppedInElevator, bool droppedInShipRoom, Vector3 targetFloorPosition, GrabbableObject dropObject, int floorYRot, PlayerControllerB __instance)
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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)
			TouhouCompanyPlugin.Instance.AddLog("TestNoLongerHeld: " + ((Object)dropObject).name + ".");
			if (((Object)dropObject).name != "Note(Clone)" && ((Object)dropObject).name != "Newspaper(Clone)")
			{
				TouhouCompanyPlugin.Instance.AddLog("Not processing.");
				return true;
			}
			for (int i = 0; i < __instance.ItemSlots.Length; i++)
			{
				if ((Object)(object)__instance.ItemSlots[i] == (Object)(object)dropObject)
				{
					__instance.ItemSlots[i] = null;
				}
			}
			dropObject.heldByPlayerOnServer = false;
			dropObject.parentObject = null;
			if (((NetworkBehaviour)__instance).IsServer)
			{
				if (droppedInElevator)
				{
					((Component)dropObject).transform.SetParent(__instance.playersManager.elevatorTransform, true);
				}
				else
				{
					((Component)dropObject).transform.SetParent(__instance.playersManager.propsContainer, true);
				}
			}
			__instance.SetItemInElevator(droppedInShipRoom, droppedInElevator, dropObject);
			dropObject.EnablePhysics(true);
			dropObject.EnableItemMeshes(true);
			((Component)dropObject).transform.localScale = dropObject.originalScale;
			dropObject.isHeld = false;
			dropObject.isPocketed = false;
			dropObject.fallTime = 0f;
			if ((Object)(object)((Component)dropObject).transform.parent != (Object)null)
			{
				dropObject.startFallingPosition = ((Component)dropObject).transform.parent.InverseTransformPoint(((Component)dropObject).transform.position);
			}
			dropObject.targetFloorPosition = targetFloorPosition;
			dropObject.floorYRot = floorYRot;
			__instance.twoHanded = false;
			__instance.twoHandedAnimation = false;
			__instance.carryWeight -= Mathf.Clamp(dropObject.itemProperties.weight - 1f, 0f, 10f);
			__instance.isHoldingObject = false;
			FieldInfo field = ((object)__instance).GetType().GetField("hasThrownObject", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(__instance, true);
			}
			TouhouCompanyPlugin.Instance.AddLog("Replaced method TestNoLongerHeld().");
			return false;
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch : NetworkBehaviour
	{
		public static ShrineManager ShrineManager;

		public static KoumakanManager KoumakanManager;

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void AwakePatch(RoundManager __instance)
		{
			TouhouCompanyPlugin.Instance.AddLog("RoundManagerPatch has awoken");
			ShrineManager = ((Component)__instance).gameObject.AddComponent<ShrineManager>();
			KoumakanManager = ((Component)__instance).gameObject.AddComponent<KoumakanManager>();
		}

		[HarmonyPatch("LoadNewLevelWait")]
		[HarmonyPrefix]
		public static void LoadNewLevelWaitPatch(RoundManager __instance)
		{
			TouhouCompanyPlugin.Instance.AddLog($"Loading level {__instance.currentLevel.levelID}...");
			if (__instance.currentLevel.levelID == 3 && TouhouCompanyPlugin.EnableHakureiReplace.Value && (Object)(object)TouhouCompanyPlugin.HakureiShrinePrefeb != (Object)null)
			{
				TouhouCompanyPlugin.Instance.AddLog("Spawning shrine objects");
				ShrineManager.SpawnShrineServerRpc();
			}
			if (__instance.currentLevel.levelID == 4 && TouhouCompanyPlugin.EnableKoumakanReplace.Value && (Object)(object)TouhouCompanyPlugin.KoumakanPrefeb != (Object)null)
			{
				TouhouCompanyPlugin.Instance.AddLog("Spawning Koumakan objects");
				KoumakanManager.SpawnKoumakanServerRpc();
			}
		}

		[HarmonyPatch("DespawnPropsAtEndOfRound")]
		[HarmonyPostfix]
		public static void DespawnPropsAtEndOfRoundPatch(RoundManager __instance)
		{
			TouhouCompanyPlugin.Instance.AddLog($"End level {__instance.currentLevel.levelID}...");
			if (__instance.currentLevel.levelID == 3 && TouhouCompanyPlugin.EnableHakureiReplace.Value && (Object)(object)TouhouCompanyPlugin.HakureiShrinePrefeb != (Object)null)
			{
				TouhouCompanyPlugin.Instance.AddLog("Despawning shrine objects");
				if (((NetworkBehaviour)ShrineManager).IsServer)
				{
					ShrineManager.DespawnShrineServerRpc();
				}
			}
		}

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

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

		protected internal override string __getTypeName()
		{
			return "RoundManagerPatch";
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		public static GameObject vanillaShip;

		public static GameObject newShip;

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void StartRoundPatch()
		{
			//IL_006c: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (TouhouCompanyPlugin.EnableHangarShipReplace.Value && !((Object)(object)TouhouCompanyPlugin.HangarShipPrefeb == (Object)null) && !((Object)(object)newShip != (Object)null))
				{
					vanillaShip = GameObject.Find("Environment/HangarShip");
					newShip = Object.Instantiate<GameObject>(TouhouCompanyPlugin.HangarShipPrefeb, vanillaShip.transform);
					newShip.transform.localPosition = new Vector3(11.1f, 32.6f, -7.22f);
					newShip.transform.localRotation = Quaternion.Euler(0f, 90f, 0f);
					newShip.transform.localScale = Vector3.one * 3f;
				}
			}
			catch (Exception arg)
			{
				TouhouCompanyPlugin.Instance.AddLog($"An error occured when replacing the HangarShip: {arg}");
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace TouhouCompany.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}