Decompiled source of Broadcast Perch v1.1.0

Broadcast_Perch.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using BroadcastPerch.Content;
using EnemiesReturns.Configuration;
using EnemiesReturns.Enemies.MechanicalSpider.Enemy;
using EnemiesReturns.Enemies.Spitter;
using FRCSharp;
using HG;
using HG.Reflection;
using LOP;
using R2API;
using RoR2;
using RoR2.ContentManagement;
using RoR2.Navigation;
using RoR2BepInExPack.GameAssetPathsBetter;
using SS2;
using ShaderSwapper;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
public class ReplaceShaders : MonoBehaviour
{
}
namespace BroadcastPerch
{
	[BepInPlugin("wormsworms.Broadcast_Perch", "Broadcast_Perch", "1.1.0")]
	public class BroadcastPerch : BaseUnityPlugin
	{
		public const string Author = "wormsworms";

		public const string Name = "Broadcast_Perch";

		public const string Version = "1.1.0";

		public const string GUID = "wormsworms.Broadcast_Perch";

		public static BroadcastPerch instance;

		public static ConfigEntry<bool> enableRegular;

		public static ConfigEntry<bool> enableSimulacrum;

		public static ConfigEntry<bool> stage1Simulacrum;

		public static ConfigEntry<bool> toggleSpider;

		public static ConfigEntry<bool> toggleSpitter;

		public static ConfigEntry<bool> toggleWayfarer;

		public static ConfigEntry<bool> toggleBrassMonolith;

		public const string mapName = "broadcastperch_wormsworms";

		public const string simuName = "itbroadcastperch_wormsworms";

		private static GameObject fanPrefab;

		private void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			ConfigSetup();
			ContentManager.collectContentPackProviders += new CollectContentPackProvidersDelegate(GiveToRoR2OurContentPackProviders);
			Language.collectLanguageRootFolders += CollectLanguageRootFolders;
			SceneManager.sceneLoaded += SceneSetup;
			RoR2Application.onLoadFinished = (Action)Delegate.Combine(RoR2Application.onLoadFinished, new Action(AddModdedEnemies));
		}

		public static void AddModdedEnemies()
		{
			if (IsEnemiesReturns.enabled)
			{
				EnemiesReturnsCompat.AddEnemies();
			}
			if (IsStarstorm2.enabled)
			{
				Starstorm2Compat.AddEnemies();
			}
			if (IsForgottenRelics.enabled)
			{
				ForgottenRelicsCompat.AddEnemies();
			}
		}

		private void Destroy()
		{
			Language.collectLanguageRootFolders -= CollectLanguageRootFolders;
		}

		private static void GiveToRoR2OurContentPackProviders(AddContentPackProviderDelegate addContentPackProvider)
		{
			addContentPackProvider.Invoke((IContentPackProvider)(object)new ContentProvider());
		}

		public void CollectLanguageRootFolders(List<string> folders)
		{
			folders.Add(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Language"));
			folders.Add(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Plugins/Language"));
		}

		private void SceneSetup(Scene newScene, LoadSceneMode loadSceneMode)
		{
			if (((Scene)(ref newScene)).name == "broadcastperch_wormsworms")
			{
				Transform transform = GameObject.Find("HOLDER: Skybox/Rings").transform;
				for (int i = 0; i < transform.childCount; i++)
				{
					GameObject gameObject = ((Component)transform.GetChild(i).GetChild(0)).gameObject;
					((Collider)gameObject.GetComponent<MeshCollider>()).enabled = false;
					gameObject.layer = 0;
				}
			}
			if (!(((Scene)(ref newScene)).name == "broadcastperch_wormsworms") && !(((Scene)(ref newScene)).name == "itbroadcastperch_wormsworms"))
			{
				return;
			}
			Log.Debug("looking for objects");
			Transform transform2 = GameObject.Find("Human Props/Generators").transform;
			for (int j = 0; j < transform2.childCount; j++)
			{
				((Renderer)((Component)transform2.GetChild(j).GetChild(0)).gameObject.GetComponent<MeshRenderer>()).sharedMaterial = BroadcastPerchContent.treetopBlueMetal;
			}
			Transform transform3 = GameObject.Find("Human Props/Cell Towers").transform;
			for (int k = 0; k < transform3.childCount; k++)
			{
				((Renderer)((Component)transform3.GetChild(k).GetChild(0).GetChild(0)).gameObject.GetComponent<MeshRenderer>()).sharedMaterial = BroadcastPerchContent.treetopMetal;
			}
			Transform transform4 = GameObject.Find("Human Props/Containers").transform;
			for (int l = 0; l < transform4.childCount; l++)
			{
				((Renderer)((Component)transform4.GetChild(l).GetChild(0)).gameObject.GetComponent<MeshRenderer>()).sharedMaterial = BroadcastPerchContent.treetopBlueMetal;
			}
			Transform transform5 = GameObject.Find("RANDOM: Tall Center Log/Props/Ship Piece").transform;
			if ((Object)(object)transform5.GetChild(0).GetChild(0).GetChild(0) != (Object)null)
			{
				((Renderer)((Component)transform5.GetChild(0).GetChild(0).GetChild(0)).gameObject.GetComponent<MeshRenderer>()).sharedMaterial = BroadcastPerchContent.treetopMetal;
				((Component)transform5.GetChild(0).GetChild(0).GetChild(0)).gameObject.layer = 11;
			}
			Transform transform6 = GameObject.Find("RANDOM: Short Center Log/Props/Debris (3)").transform;
			if ((Object)(object)transform6.GetChild(0) != (Object)null)
			{
				((Renderer)((Component)transform6.GetChild(0)).gameObject.GetComponent<MeshRenderer>()).sharedMaterial = BroadcastPerchContent.treetopMetal;
			}
			GameObject[] array = (GameObject[])(object)new GameObject[6]
			{
				GameObject.Find("RANDOM: Short Center Log/Props/Generator"),
				GameObject.Find("RANDOM: Short Center Log/Props/Generator (2)"),
				GameObject.Find("RANDOM: Short Center Log/Props/Generator (4)"),
				GameObject.Find("RANDOM: Tall Center Log/Props/Generator"),
				GameObject.Find("RANDOM: Tall Center Log/Props/Generator (2)"),
				GameObject.Find("RANDOM: Tall Center Log/Props/Generator (4)")
			};
			foreach (GameObject val in array)
			{
				if ((Object)(object)val.transform.GetChild(0) != (Object)null)
				{
					((Renderer)((Component)val.transform.GetChild(0)).GetComponent<MeshRenderer>()).sharedMaterial = BroadcastPerchContent.treetopBlueMetal;
				}
			}
			Object.Destroy((Object)(object)GameObject.Find("Dish Light/FW_Light2On(Clone)/LightPostLight"));
		}

		public static void CreateFanPrefab(ContentPack contentPack)
		{
			//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_008a: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			fanPrefab = PrefabAPI.InstantiateClone(Addressables.LoadAssetAsync<GameObject>((object)RoR2_Base_frozenwall.FW_HumanFan_prefab).WaitForCompletion(), "TreetopFan", true);
			PurchaseInteraction val = default(PurchaseInteraction);
			fanPrefab.TryGetComponent<PurchaseInteraction>(ref val);
			val.automaticallyScaleCostWithDifficulty = true;
			val.cost = 5;
			((Renderer)((Component)fanPrefab.transform.GetChild(0).GetChild(2)).GetComponent<SkinnedMeshRenderer>()).sharedMaterial = BroadcastPerchContent.treetopBlueMetal;
			MainModule main = ((Component)fanPrefab.transform.GetChild(0).GetChild(0).GetChild(0)
				.GetChild(0)).GetComponent<ParticleSystem>().main;
			MainModule main2 = ((Component)fanPrefab.transform.GetChild(0).GetChild(0).GetChild(0)
				.GetChild(1)).GetComponent<ParticleSystem>().main;
			MainModule main3 = ((Component)fanPrefab.transform.GetChild(0).GetChild(0).GetChild(1)
				.GetChild(0)).GetComponent<ParticleSystem>().main;
			MainModule main4 = ((Component)fanPrefab.transform.GetChild(0).GetChild(0).GetChild(1)
				.GetChild(1)).GetComponent<ParticleSystem>().main;
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Color.gray);
			((MainModule)(ref main2)).startColor = MinMaxGradient.op_Implicit(Color.gray);
			((MainModule)(ref main3)).startColor = MinMaxGradient.op_Implicit(Color.gray);
			((MainModule)(ref main4)).startColor = MinMaxGradient.op_Implicit(Color.gray);
			fanPrefab = PrefabAPI.InstantiateClone(fanPrefab, "TreetopFan", true);
			contentPack.networkedObjectPrefabs.Add((GameObject[])(object)new GameObject[1] { fanPrefab });
		}

		private void ConfigSetup()
		{
			enableRegular = ((BaseUnityPlugin)this).Config.Bind<bool>("00 - Stages", "Enable Broadcast Perch", true, "If true, Broadcast Perch can appear in regular runs.");
			enableSimulacrum = ((BaseUnityPlugin)this).Config.Bind<bool>("00 - Stages", "Enable Simulacrum Variant", true, "If true, Broadcast Perch can appear in the Simulacrum.");
			stage1Simulacrum = ((BaseUnityPlugin)this).Config.Bind<bool>("00 - Stages", "Enable Simulacrum Variant on Stage 1", false, "If false, Broadcast Perch will only appear after clearing at least one stage in the Simulacrum, like Commencement.");
			toggleSpider = ((BaseUnityPlugin)this).Config.Bind<bool>("01 - Monsters: EnemiesReturns", "Enable Mechanical Spider", true, "If true, Mechanical Spiders will appear in Broadcast Perch.");
			toggleSpitter = ((BaseUnityPlugin)this).Config.Bind<bool>("01 - Monsters: EnemiesReturns", "Enable Spitter", true, "If true, Spitters will appear in Broadcast Perch.");
			toggleBrassMonolith = ((BaseUnityPlugin)this).Config.Bind<bool>("02 - Monsters: Forgotten Relics", "Enable Brass Monolith", true, "If true, Brass Monoliths will appear in Broadcast Perch (after clearing 5 stages).");
			toggleWayfarer = ((BaseUnityPlugin)this).Config.Bind<bool>("03 - Monsters: Starstorm 2", "Enable Wayfarer", true, "If true, Wayfarers will appear in Broadcast Perch.");
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	public class IsStarstorm2
	{
		private static bool? _enabled;

		public static bool enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("com.TeamMoonstorm.MSU") && Chainloader.PluginInfos.ContainsKey("com.TeamMoonstorm");
				}
				return _enabled.Value;
			}
		}
	}
	public class IsEnemiesReturns
	{
		private static bool? _enabled;

		public static bool enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("com.Viliger.EnemiesReturns");
				}
				return _enabled.Value;
			}
		}
	}
	public class IsSandswept
	{
		private static bool? _enabled;

		public static bool enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("com.TeamSandswept.Sandswept");
				}
				return _enabled.Value;
			}
		}
	}
	public class IsForgottenRelics
	{
		private static bool? _enabled;

		public static bool enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("PlasmaCore.ForgottenRelics");
				}
				return _enabled.Value;
			}
		}
	}
	public class EnemiesReturnsCompat
	{
		public static void AddEnemies()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_0126: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			if (BroadcastPerch.toggleSpitter.Value && General.EnableSpitter.Value)
			{
				DirectorCard card = new DirectorCard
				{
					spawnCard = (SpawnCard)SpawnCards.cscSpitterDefault,
					spawnDistance = (MonsterSpawnDistance)0,
					selectionWeight = Spitter.SelectionWeight.Value,
					minimumStageCompletions = Spitter.MinimumStageCompletion.Value
				};
				DirectorCardHolder val = new DirectorCardHolder
				{
					Card = card,
					MonsterCategory = (MonsterCategory)3
				};
				if (!Spitter.DefaultStageList.Value.Contains("broadcastperch_wormsworms"))
				{
					Helpers.AddNewMonsterToStage(val, false, (Stage)1, "broadcastperch_wormsworms");
					Log.Info("Spitter added to Broadcast Perch's spawn pool.");
				}
				if (!Spitter.DefaultStageList.Value.Contains("itbroadcastperch_wormsworms"))
				{
					Helpers.AddNewMonsterToStage(val, false, (Stage)1, "itbroadcastperch_wormsworms");
					Log.Info("Spitter added to Broadcast Perch's simulacrum spawn pool.");
				}
			}
			if (BroadcastPerch.toggleSpider.Value && General.EnableMechanicalSpider.Value)
			{
				DirectorCard card2 = new DirectorCard
				{
					spawnCard = (SpawnCard)SpawnCards.cscMechanicalSpiderGrassy,
					spawnDistance = (MonsterSpawnDistance)0,
					selectionWeight = MechanicalSpider.SelectionWeight.Value,
					minimumStageCompletions = MechanicalSpider.MinimumStageCompletion.Value
				};
				DirectorCardHolder val2 = new DirectorCardHolder
				{
					Card = card2,
					MonsterCategory = (MonsterCategory)2
				};
				if (!MechanicalSpider.DefaultStageList.Value.Contains("broadcastperch_wormsworms"))
				{
					Helpers.AddNewMonsterToStage(val2, false, (Stage)1, "broadcastperch_wormsworms");
					Log.Info("Mechanical Spider added to Broadcast Perch's spawn pool.");
				}
				if (!MechanicalSpider.DefaultStageList.Value.Contains("itbroadcastperch_wormsworms"))
				{
					Helpers.AddNewMonsterToStage(val2, false, (Stage)1, "itbroadcastperch_wormsworms");
					Log.Info("Mechanical Spider added to Broadcast Perch's simulacrum spawn pool.");
				}
			}
		}
	}
	public class ForgottenRelicsCompat
	{
		public static void AddEnemies()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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)
			//IL_0023: 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_0033: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_0068: Expected O, but got Unknown
			if (BroadcastPerch.toggleBrassMonolith.Value && !VF2ConfigManager.disableBrassMonolith.Value)
			{
				DirectorCardHolder val = new DirectorCardHolder
				{
					Card = new DirectorCard
					{
						spawnCard = (SpawnCard)VF2ContentPackProvider.cscBrassMonolith,
						selectionWeight = 1,
						minimumStageCompletions = 5
					},
					MonsterCategory = (MonsterCategory)4
				};
				Helpers.AddNewMonsterToStage(val, false, (Stage)1, "broadcastperch_wormsworms");
				Helpers.AddNewMonsterToStage(val, false, (Stage)1, "itbroadcastperch_wormsworms");
				Log.Debug("Brass Monolith added to Broadcast Perch spawn pool.");
			}
		}
	}
	public class Starstorm2Compat
	{
		public static string FindEnemyConfig(string monsterName)
		{
			string text = "00 - Enemy Disabling.Disable Enemy: " + monsterName;
			ConfigEntryBase[] configEntries = SS2Config.ConfigMonster.GetConfigEntries();
			foreach (ConfigEntryBase val in configEntries)
			{
				if (((object)val.Definition).ToString() == text)
				{
					return val.GetSerializedValue();
				}
			}
			return "false";
		}

		public static void AddEnemies()
		{
			//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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0078: Expected O, but got Unknown
			string text = FindEnemyConfig("Lamp Boss");
			if (BroadcastPerch.toggleWayfarer.Value && text == "false")
			{
				DirectorCard card = new DirectorCard
				{
					spawnCard = SS2Assets.LoadAsset<SpawnCard>("scLampBoss", (SS2Bundle)17),
					spawnDistance = (MonsterSpawnDistance)0,
					selectionWeight = 1
				};
				DirectorCardHolder val = new DirectorCardHolder
				{
					Card = card,
					MonsterCategory = (MonsterCategory)4
				};
				Helpers.AddNewMonsterToStage(val, false, (Stage)1, "broadcastperch_wormsworms");
				Helpers.AddNewMonsterToStage(val, false, (Stage)1, "itbroadcastperch_wormsworms");
				Log.Info("Wayfarer added to Broadcast Perch's spawn pool.");
			}
		}
	}
	public class ReplaceFan : MonoBehaviour
	{
		private GameObject fanInstance;

		private GameObject fan;

		private GameObject oldFan;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkServer.active)
			{
				fan = Addressables.LoadAssetAsync<GameObject>((object)RoR2_Base_frozenwall.FW_HumanFan_prefab).WaitForCompletion();
				oldFan = ((Component)((Component)this).gameObject.transform.GetChild(0)).gameObject;
				((Renderer)((Component)fan.transform.GetChild(0).GetChild(2)).GetComponent<SkinnedMeshRenderer>()).sharedMaterial = BroadcastPerchContent.treetopBlueMetal;
				JumpVolume component = ((Component)this).gameObject.GetComponent<JumpVolume>();
				JumpVolume component2 = ((Component)fan.transform.GetChild(0).GetChild(0)).GetComponent<JumpVolume>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					Log.Debug("new fan's jump volume found");
				}
				component2.jumpSoundString = component.jumpSoundString;
				component2.jumpVelocity = component.jumpVelocity;
				component2.time = component.time;
				component2.targetElevationTransform = component.targetElevationTransform;
				InstantiateGeyserPrefab component3 = ((Component)this).gameObject.GetComponent<InstantiateGeyserPrefab>();
				GateStateSetter obj = ((Component)fan.transform.GetChild(0).GetChild(0)).gameObject.AddComponent<GateStateSetter>();
				obj.gateToDisableWhenEnabled = component3.gateToDisableWhenPurchased;
				obj.gateToEnableWhenEnabled = component3.gateToEnableWhenPurchased;
				fanInstance = Object.Instantiate<GameObject>(fan, oldFan.transform.position, oldFan.transform.rotation, ((Component)this).gameObject.transform);
				NetworkServer.Spawn(fanInstance);
				Object.Destroy((Object)(object)oldFan);
				Object.Destroy((Object)(object)oldFan);
			}
		}
	}
}
namespace BroadcastPerch.Content
{
	public static class BroadcastPerchContent
	{
		internal const string ScenesAssetBundleFileName = "BroadcastPerchScenes";

		internal const string AssetsAssetBundleFileName = "BroadcastPerchAssets";

		private static AssetBundle _scenesAssetBundle;

		private static AssetBundle _assetsAssetBundle;

		internal static UnlockableDef[] UnlockableDefs;

		internal static SceneDef[] SceneDefs;

		internal static SceneDef treetopSceneDef;

		internal static Sprite treetopSceneDefPreviewSprite;

		internal static Material treetopBazaarSeer;

		internal static Material treetopMetal;

		internal static Material treetopBlueMetal;

		internal static SceneDef simuSceneDef;

		internal static Sprite simuSceneDefPreviewSprite;

		internal static Material simuBazaarSeer;

		public static List<Material> SwappedMaterials = new List<Material>();

		internal static IEnumerator LoadAssetBundlesAsync(AssetBundle scenesAssetBundle, AssetBundle assetsAssetBundle, IProgress<float> progress, ContentPack contentPack)
		{
			_scenesAssetBundle = scenesAssetBundle;
			_assetsAssetBundle = assetsAssetBundle;
			IEnumerator upgradeStubbedShaders = ShaderSwapper.UpgradeStubbedShadersAsync(_assetsAssetBundle);
			while (upgradeStubbedShaders.MoveNext())
			{
				yield return upgradeStubbedShaders.Current;
			}
			yield return LoadAllAssetsAsync<UnlockableDef>(assetsAssetBundle, progress, (Action<UnlockableDef[]>)delegate(UnlockableDef[] assets)
			{
				contentPack.unlockableDefs.Add(assets);
			});
			yield return LoadAllAssetsAsync<Sprite>(_assetsAssetBundle, progress, (Action<Sprite[]>)delegate(Sprite[] assets)
			{
				treetopSceneDefPreviewSprite = assets.First((Sprite a) => ((Object)a).name == "texBPScenePreview");
				simuSceneDefPreviewSprite = assets.First((Sprite a) => ((Object)a).name == "texBPScenePreview");
			});
			yield return LoadAllAssetsAsync<Material>(_assetsAssetBundle, progress, (Action<Material[]>)delegate(Material[] assets)
			{
				treetopMetal = assets.First((Material a) => ((Object)a).name == "matPTMetal");
				treetopBlueMetal = assets.First((Material a) => ((Object)a).name == "matPTBlueMetal");
			});
			yield return LoadAllAssetsAsync<SceneDef>(_assetsAssetBundle, progress, (Action<SceneDef[]>)delegate(SceneDef[] assets)
			{
				SceneDefs = assets;
				treetopSceneDef = SceneDefs.First((SceneDef sd) => sd.baseSceneNameOverride == "broadcastperch_wormsworms");
				simuSceneDef = SceneDefs.First((SceneDef sd) => sd.baseSceneNameOverride == "itbroadcastperch_wormsworms");
				Log.Debug(treetopSceneDef.nameToken);
				contentPack.sceneDefs.Add(assets);
			});
			treetopSceneDef.portalMaterial = StageRegistration.MakeBazaarSeerMaterial((Texture2D)treetopSceneDef.previewTexture);
			AsyncOperationHandle<MusicTrackDef> mainTrackDefRequest = Addressables.LoadAssetAsync<MusicTrackDef>((object)"RoR2/Base/Common/MusicTrackDefs/muSong13.asset");
			while (!mainTrackDefRequest.IsDone)
			{
				yield return null;
			}
			AsyncOperationHandle<MusicTrackDef> bossTrackDefRequest = Addressables.LoadAssetAsync<MusicTrackDef>((object)"RoR2/Base/Common/MusicTrackDefs/muSong05.asset");
			while (!bossTrackDefRequest.IsDone)
			{
				yield return null;
			}
			treetopSceneDef.mainTrack = mainTrackDefRequest.Result;
			treetopSceneDef.bossTrack = bossTrackDefRequest.Result;
			simuSceneDef.mainTrack = treetopSceneDef.mainTrack;
			simuSceneDef.bossTrack = treetopSceneDef.bossTrack;
			if (BroadcastPerch.enableRegular.Value)
			{
				StageRegistration.RegisterSceneDefToNormalProgression(treetopSceneDef, 1f, true, true);
			}
			if (BroadcastPerch.enableSimulacrum.Value && BroadcastPerch.stage1Simulacrum.Value)
			{
				Simulacrum.RegisterSceneToSimulacrum(simuSceneDef);
			}
			else if (BroadcastPerch.enableSimulacrum.Value && !BroadcastPerch.stage1Simulacrum.Value)
			{
				Simulacrum.RegisterSceneToSimulacrum(simuSceneDef, canBeStage1: false);
			}
		}

		internal static void Unload()
		{
			_assetsAssetBundle.Unload(true);
			_scenesAssetBundle.Unload(true);
		}

		private static IEnumerator LoadAllAssetsAsync<T>(AssetBundle assetBundle, IProgress<float> progress, Action<T[]> onAssetsLoaded) where T : Object
		{
			AssetBundleRequest sceneDefsRequest = assetBundle.LoadAllAssetsAsync<T>();
			while (!((AsyncOperation)sceneDefsRequest).isDone)
			{
				progress.Report(((AsyncOperation)sceneDefsRequest).progress);
				yield return null;
			}
			onAssetsLoaded(sceneDefsRequest.allAssets.Cast<T>().ToArray());
		}
	}
	public class ContentProvider : IContentPackProvider
	{
		private readonly ContentPack _contentPack = new ContentPack();

		public static string assetDirectory;

		public string identifier => "wormsworms.Broadcast_Perch.ContentProvider";

		public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
		{
			_contentPack.identifier = identifier;
			string assetsFolderFullPath = (assetDirectory = Path.GetDirectoryName(typeof(ContentProvider).Assembly.Location));
			BroadcastPerch.CreateFanPrefab(_contentPack);
			AssetBundle scenesAssetBundle = null;
			yield return LoadAssetBundle(Path.Combine(assetsFolderFullPath, "BroadcastPerchScenes"), args.progressReceiver, delegate(AssetBundle assetBundle)
			{
				scenesAssetBundle = assetBundle;
			});
			AssetBundle assetsAssetBundle = null;
			yield return LoadAssetBundle(Path.Combine(assetsFolderFullPath, "BroadcastPerchAssets"), args.progressReceiver, delegate(AssetBundle assetBundle)
			{
				assetsAssetBundle = assetBundle;
			});
			yield return BroadcastPerchContent.LoadAssetBundlesAsync(scenesAssetBundle, assetsAssetBundle, args.progressReceiver, _contentPack);
		}

		private IEnumerator LoadAssetBundle(string assetBundleFullPath, IProgress<float> progress, Action<AssetBundle> onAssetBundleLoaded)
		{
			AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(assetBundleFullPath);
			while (!((AsyncOperation)assetBundleCreateRequest).isDone)
			{
				progress.Report(((AsyncOperation)assetBundleCreateRequest).progress);
				yield return null;
			}
			onAssetBundleLoaded(assetBundleCreateRequest.assetBundle);
		}

		public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
		{
			ContentPack.Copy(_contentPack, args.output);
			args.ReportProgress(1f);
			yield break;
		}

		public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
		{
			args.ReportProgress(1f);
			yield break;
		}
	}
	public static class Simulacrum
	{
		public static void RegisterSceneToSimulacrum(SceneDef sceneDef, bool canBeStage1 = true, float weight = 1f)
		{
			//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_0019: 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)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			SceneCollection val = Addressables.LoadAssetAsync<SceneCollection>((object)"RoR2/DLC1/GameModes/InfiniteTowerRun/SceneGroups/sgInfiniteTowerStageX.asset").WaitForCompletion();
			SceneCollection val2 = Addressables.LoadAssetAsync<SceneCollection>((object)"RoR2/DLC1/GameModes/InfiniteTowerRun/SceneGroups/sgInfiniteTowerStage1.asset").WaitForCompletion();
			List<SceneCollection> list = new List<SceneCollection>();
			Enumerator<SceneEntry> enumerator = val.sceneEntries.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					SceneEntry current = enumerator.Current;
					if ((Object)(object)current.sceneDef == (Object)(object)sceneDef)
					{
						Log.Error("SceneDef " + sceneDef.cachedName + " is already registered into the Simulacrum");
						return;
					}
					if (current.sceneDef.hasAnyDestinations)
					{
						list.Add(current.sceneDef.destinationsGroup);
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			SceneCollection val3 = ScriptableObject.CreateInstance<SceneCollection>();
			((Object)val3).name = "sgInfiniteTowerStageX" + sceneDef.cachedName;
			val3._sceneEntries = val._sceneEntries;
			sceneDef.destinationsGroup = val3;
			SceneEntry val4 = default(SceneEntry);
			val4.sceneDef = sceneDef;
			val4.weightMinusOne = weight - 1f;
			SceneEntry val5 = val4;
			ArrayUtils.ArrayAppend<SceneEntry>(ref val._sceneEntries, ref val5);
			if (canBeStage1)
			{
				ArrayUtils.ArrayAppend<SceneEntry>(ref val2._sceneEntries, ref val5);
			}
			foreach (SceneCollection item in list)
			{
				ArrayUtils.ArrayAppend<SceneEntry>(ref item._sceneEntries, ref val5);
			}
		}
	}
}