Decompiled source of Arboretum V1 Testing v0.0.9

ArboretumV1.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading.Tasks;
using AIGraph;
using Agents;
using ArboretumV1.CustomEnemyBehavior;
using ArboretumV1.CustomLevelBehavior;
using ArboretumV1.Patches;
using ArboretumV1.StolenEEC;
using ArboretumV1.Utils;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using CConsole.Commands;
using CConsole.Interop;
using CellMenu;
using Enemies;
using ExtraObjectiveSetup.ExtendedWardenEvents;
using GTFO.API;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using LevelGeneration;
using MTFO.API;
using Microsoft.CodeAnalysis;
using ModifierAPI;
using Player;
using SNetwork;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ArboretumV1")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4ba6acfd0c34e4fe04383d6752e27bf0c0b78a60")]
[assembly: AssemblyProduct("ArboretumV1")]
[assembly: AssemblyTitle("ArboretumV1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
}
namespace ArboretumV1
{
	[BepInPlugin("RLC.ArboretumV1", "ArboretumV1", "1.0.0")]
	public class Plugin : BasePlugin
	{
		internal Harmony _harmony;

		public static Object s_CustomIntelImage1;

		public static GameObject s_customFogSphere;

		public static bool hasCConsole;

		public override void Load()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(21, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loading Arboretum V-1");
			}
			log.LogInfo(val);
			_harmony = new Harmony("RLC.ArboretumV1");
			GUI_Patches.Setup(_harmony);
			CustomGearPatches.Setup(_harmony);
			MiscPatches.Setup(_harmony);
			CustomEnemyPatches.Setup(_harmony);
			AssetAPI.OnAssetBundlesLoaded += RegisterTypes;
			AssetAPI.OnAssetBundlesLoaded += AssetAPI_OnAssetBundlesLoaded;
			UniversalLevelPatches.Setup();
			ManualLogSource log2 = ((BasePlugin)this).Log;
			val = new BepInExInfoLogInterpolatedStringHandler(19, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Arboretum V-1 Setup");
			}
			log2.LogInfo(val);
		}

		private static void RegisterTypes()
		{
			ClassInjector.RegisterTypeInIl2Cpp<CustomEnemyAbilityBase>();
			ClassInjector.RegisterTypeInIl2Cpp<CustomAbility_Phaser_Small>();
			ClassInjector.RegisterTypeInIl2Cpp<CustomAbility_Phaser_Big>();
			ClassInjector.RegisterTypeInIl2Cpp<CustomBlackoutHandler>();
			ClassInjector.RegisterTypeInIl2Cpp<A2Elevator>();
			ClassInjector.RegisterTypeInIl2Cpp<PUI_A3_DoorKnowledge>();
			ClassInjector.RegisterTypeInIl2Cpp<A4_DoubleSidedDoors>();
			ClassInjector.RegisterTypeInIl2Cpp<D1_Resurgence.D1_ReactorBehaviour>();
			CustomLevelBehavior_Manager.Setup();
			string key = "Inas.ExtraObjectiveSetup";
			if (((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey(key))
			{
				ArboretumEvents.Setup();
			}
			string key2 = "CConsole";
			if (((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey(key2))
			{
				hasCConsole = true;
			}
			ArboJsonHandler.Setup();
		}

		private static void AssetAPI_OnAssetBundlesLoaded()
		{
			s_CustomIntelImage1 = AssetAPI.GetLoadedAsset("Assets/Bundles/Arboretum/CustomIntel/CustomIntelImageObject1.prefab");
			s_customFogSphere = ((Il2CppObjectBase)AssetAPI.GetLoadedAsset("Assets/Bundles/Arboretum/A-2/CustomFogSphere.prefab")).TryCast<GameObject>();
		}
	}
}
namespace ArboretumV1.Utils
{
	public class ArboJsonHandler
	{
		private static string ArboCustomPath;

		private static readonly JsonSerializerOptions _setting = new JsonSerializerOptions
		{
			ReadCommentHandling = JsonCommentHandling.Skip,
			IncludeFields = true,
			PropertyNameCaseInsensitive = true,
			WriteIndented = true,
			IgnoreReadOnlyProperties = true,
			Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
		};

		public static void Setup()
		{
			ArboCustomPath = Path.Combine(MTFOPathAPI.CustomPath, "Arboretum");
			if (!Directory.Exists(ArboCustomPath))
			{
				Directory.CreateDirectory(ArboCustomPath);
			}
			MTFOHotReloadAPI.OnHotReload += OnHotreload;
		}

		public static void LoadJson(bool isHotreload = false)
		{
		}

		public static T DeserializeAndCreateIfNotReal<T>(string jsonPath, T data)
		{
			if (!File.Exists(jsonPath))
			{
				string contents = JsonSerializer.Serialize(data, _setting);
				File.WriteAllText(jsonPath, contents);
			}
			return JsonSerializer.Deserialize<T>(File.ReadAllText(jsonPath), _setting);
		}

		public static void OnHotreload()
		{
			Log.Info("Reloading json");
			LoadJson(isHotreload: true);
		}
	}
	internal class ArboretumEvents
	{
		public static void Setup()
		{
			EOSWardenEventManager.Current.AddEventDefinition("A1_Blackout", 2001u, (Action<WardenObjectiveEventData>)A1_Restart.BlackoutEvent);
			EOSWardenEventManager.Current.AddEventDefinition("A1_ChangeSecondaryObjectiveState", 2002u, (Action<WardenObjectiveEventData>)A1_Restart.ChangeSecondaryObjectiveState);
			EOSWardenEventManager.Current.AddEventDefinition("A2_MoveElevatorToFloor", 3002u, (Action<WardenObjectiveEventData>)A2_Balance.MoveElevatorToFloor);
		}
	}
	internal class CustomNetworkEvents
	{
		public static void RegisterEvents()
		{
		}
	}
	public class FuckingInterfaces
	{
		public interface iMineDeployerInstance_Detonation
		{
			event Action OnDetonationDone;

			void Setup(iMineDeployerInstanceCore core);

			void TriggerDetonate(float detectionRange);
		}
	}
	internal static class Log
	{
		private static readonly ManualLogSource _logger;

		static Log()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			_logger = new ManualLogSource("RLC.Arboretum");
			Logger.Sources.Add((ILogSource)(object)_logger);
		}

		private static string Format(object msg)
		{
			return msg.ToString();
		}

		public static void Info(object data)
		{
			_logger.LogMessage((object)Format(data));
		}

		public static void Verbose(object data)
		{
			_logger.LogDebug((object)Format(data));
		}

		public static void Debug(object data)
		{
			_logger.LogDebug((object)Format(data));
		}

		public static void Error(object data)
		{
			_logger.LogError((object)Format(data));
		}
	}
}
namespace ArboretumV1.StolenEEC
{
	public static class EnemyAgentExtension
	{
		public static void AddOnDeadOnce(this EnemyAgent agent, Action onDead)
		{
			bool called = false;
			agent.OnDeadCallback += Action.op_Implicit((Action)delegate
			{
				if (!called)
				{
					onDead?.Invoke();
					called = true;
				}
			});
		}

		public static T RegisterOrGetProperty<T>(this EnemyAgent agent) where T : class, new()
		{
			return EnemyProperty<T>.RegisterOrGet(agent);
		}

		public static bool TryGetProperty<T>(this EnemyAgent agent, out T property) where T : class, new()
		{
			return EnemyProperty<T>.TryGet(agent, out property);
		}

		public static bool TryGetSpawnData(this EnemyAgent agent, out pEnemySpawnData spawnData)
		{
			return EnemySpawnDataManager.TryGet(((Agent)agent).GlobalID, out spawnData);
		}

		public static bool TryGetEnemyGroup(this EnemyAgent agent, out EnemyGroup group)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (!agent.TryGetSpawnData(out var spawnData))
			{
				group = null;
				return false;
			}
			if (spawnData.groupReplicatorKey == 0)
			{
				group = null;
				return false;
			}
			IReplicator val = default(IReplicator);
			if (!SNet_Replication.TryGetReplicator(spawnData.groupReplicatorKey, ref val))
			{
				group = null;
				return false;
			}
			if (val.ReplicatorSupplier == null)
			{
				group = null;
				return false;
			}
			group = ((Il2CppObjectBase)val.ReplicatorSupplier).TryCast<EnemyGroup>();
			return (Object)(object)group != (Object)null;
		}

		public static AIG_CourseNode GetSpawnedNode(this EnemyAgent agent)
		{
			//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)
			pEnemySpawnData spawnData = ((SNet_DynamicReplicator<pEnemySpawnData>)(object)((Il2CppObjectBase)agent.Sync.Replicator).Cast<EnemyReplicator>()).GetSpawnData();
			AIG_CourseNode result = default(AIG_CourseNode);
			if (!((pCourseNode)(ref spawnData.courseNode)).TryGet(ref result))
			{
				return null;
			}
			return result;
		}
	}
	public delegate void EnemyTakeDamageHandler(EnemyAgent enemyAgent, Agent inflictor, float damage);
	public delegate void EnemyHealthUpdateHandler(EnemyAgent enemyAgent, float maxHealth, float health);
	public static class EnemyDamageEvents
	{
		public static event EnemyTakeDamageHandler Damage;

		[Obsolete("Disabled Due to Patching Error", true)]
		public static event EnemyTakeDamageHandler MeleeDamage;

		[Obsolete("Disabled Due to Patching Error", true)]
		public static event EnemyTakeDamageHandler BulletDamage;

		[Obsolete("Disabled Due to Patching Error", true)]
		public static event EnemyTakeDamageHandler ExplosionDamage;

		public static event EnemyHealthUpdateHandler HealthUpdated;

		internal static void OnDamage(EnemyAgent enemyAgent, Agent inflictor, float damage)
		{
			EnemyDamageEvents.Damage?.Invoke(enemyAgent, inflictor, damage);
		}

		internal static void OnMeleeDamage(EnemyAgent enemyAgent, Agent inflictor, float damage)
		{
			EnemyDamageEvents.MeleeDamage?.Invoke(enemyAgent, inflictor, damage);
		}

		internal static void OnBulletDamage(EnemyAgent enemyAgent, Agent inflictor, float damage)
		{
			EnemyDamageEvents.BulletDamage?.Invoke(enemyAgent, inflictor, damage);
		}

		internal static void OnExplosionDamage(EnemyAgent enemyAgent, Agent inflictor, float damage)
		{
			EnemyDamageEvents.ExplosionDamage?.Invoke(enemyAgent, inflictor, damage);
		}

		internal static void OnHealthUpdated(EnemyAgent enemyAgent, float maxHealth, float health)
		{
			EnemyDamageEvents.HealthUpdated?.Invoke(enemyAgent, maxHealth, health);
		}
	}
	public delegate void EnemyAgentHandlerWithSpawnData(EnemyAgent agent, pEnemySpawnData spawnData);
	public delegate void EnemyAgentHandler(EnemyAgent agent);
	public static class EnemyEvents
	{
		public static event EnemyAgentHandlerWithSpawnData Spawn;

		public static event EnemyAgentHandler Spawned;

		public static event EnemyAgentHandler Despawn;

		public static event EnemyAgentHandler Despawned;

		internal static void OnSpawn(EnemyAgent agent, pEnemySpawnData spawnData)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			EnemyEvents.Spawn?.Invoke(agent, spawnData);
		}

		internal static void OnSpawned(EnemyAgent agent)
		{
			EnemyEvents.Spawned?.Invoke(agent);
		}

		internal static void OnDespawn(EnemyAgent agent)
		{
			EnemyEvents.Despawn?.Invoke(agent);
		}

		internal static void OnDespawned(EnemyAgent agent)
		{
			EnemyEvents.Despawned?.Invoke(agent);
		}
	}
	public static class EnemyProperty<T> where T : class, new()
	{
		private static readonly Dictionary<ushort, T> _properties;

		public static IEnumerable<T> Properties => _properties.Values;

		static EnemyProperty()
		{
			_properties = new Dictionary<ushort, T>();
			EnemyEvents.Despawn += EnemyDespawn;
			UniversalLevelPatches.OnLevelCleanup += OnLevelCleanup;
		}

		private static void EnemyDespawn(EnemyAgent agent)
		{
			_properties.Remove(((Agent)agent).GlobalID);
		}

		private static void OnLevelCleanup()
		{
			_properties.Clear();
		}

		public static T RegisterOrGet(EnemyAgent agent)
		{
			T val = RegisterEnemy(agent);
			if (val != null)
			{
				return val;
			}
			return Get(agent);
		}

		public static T RegisterEnemy(EnemyAgent agent)
		{
			ushort globalID = ((Agent)agent).GlobalID;
			if (_properties.ContainsKey(globalID))
			{
				return null;
			}
			T val = new T();
			_properties.Add(globalID, val);
			return val;
		}

		public static T Get(EnemyAgent agent)
		{
			return Get(((Agent)agent).GlobalID);
		}

		public static T Get(ushort id)
		{
			if (_properties.ContainsKey(id))
			{
				return _properties[id];
			}
			return null;
		}

		public static bool TryGet(EnemyAgent agent, out T property)
		{
			return TryGet(((Agent)agent).GlobalID, out property);
		}

		public static bool TryGet(ushort id, out T property)
		{
			return _properties.TryGetValue(id, out property);
		}
	}
	public static class EnemySpawnDataManager
	{
		private static readonly Dictionary<ushort, pEnemySpawnData> _lookup;

		static EnemySpawnDataManager()
		{
			_lookup = new Dictionary<ushort, pEnemySpawnData>(500);
			EnemyEvents.Spawn += Spawn;
			EnemyEvents.Despawn += Despawn;
			UniversalLevelPatches.OnLevelCleanup += OnLevelCleanup;
		}

		private static void Spawn(EnemyAgent agent, pEnemySpawnData spawnData)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			_lookup[spawnData.replicationData.ReplicatorKey] = spawnData;
		}

		private static void Despawn(EnemyAgent agent)
		{
			_lookup.Remove(((Agent)agent).GlobalID);
		}

		private static void OnLevelCleanup()
		{
			_lookup.Clear();
		}

		public static bool TryGet(ushort id, out pEnemySpawnData data)
		{
			return _lookup.TryGetValue(id, out data);
		}
	}
	public struct LazyTimer
	{
		private float _lastTickTime;

		private float _durationInv;

		public float PassedTime { get; private set; }

		public float Duration { get; private set; }

		public bool Done => Progress >= 1f;

		public float Progress => Mathf.Clamp01(ProgressUnclamped);

		public float ProgressUnclamped
		{
			get
			{
				if (Duration != 0f)
				{
					return PassedTime * _durationInv;
				}
				return 1f;
			}
		}

		public LazyTimer(float duration)
		{
			PassedTime = 0f;
			Duration = duration;
			_durationInv = 1f / duration;
			_lastTickTime = GetTime();
		}

		public void Reset(float newDuration = -1f)
		{
			PassedTime = 0f;
			if (newDuration >= 0f)
			{
				Duration = newDuration;
				_durationInv = 1f / newDuration;
			}
			_lastTickTime = GetTime();
		}

		public void Tick()
		{
			float time = GetTime();
			float num = time - _lastTickTime;
			_lastTickTime = time;
			PassedTime += num;
		}

		public bool TickAndCheckDone()
		{
			Tick();
			return Done;
		}

		private static float GetTime()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)GameStateManager.CurrentStateName == 10)
			{
				return Clock.ExpeditionProgressionTime;
			}
			return Clock.Time;
		}
	}
	public struct Timer
	{
		private float _durationInv;

		public float PassedTime { get; private set; }

		public float Duration { get; private set; }

		public bool Done => Progress >= 1f;

		public float Progress => Mathf.Clamp01(ProgressUnclamped);

		public float ProgressUnclamped
		{
			get
			{
				if (Duration != 0f)
				{
					return PassedTime * _durationInv;
				}
				return 1f;
			}
		}

		public Timer(float duration)
		{
			PassedTime = 0f;
			Duration = duration;
			_durationInv = 1f / duration;
		}

		public void Reset(float newDuration = -1f)
		{
			PassedTime = 0f;
			if (newDuration >= 0f)
			{
				Duration = newDuration;
				_durationInv = 1f / newDuration;
			}
		}

		public void Tick()
		{
			PassedTime += Time.deltaTime;
		}

		public void Tick(float deltaTime)
		{
			PassedTime += deltaTime;
		}

		public bool TickAndCheckDone()
		{
			Tick();
			return Done;
		}

		public bool TickAndCheckDone(float deltaTime)
		{
			Tick(deltaTime);
			return Done;
		}
	}
	public struct DoubleTimer
	{
		private double _durationInv;

		public double PassedTime { get; private set; }

		public double Duration { get; private set; }

		public bool Done => Progress >= 1.0;

		public double Progress => Math.Clamp(0.0, 1.0, ProgressUnclamped);

		public double ProgressUnclamped
		{
			get
			{
				if (Duration != 0.0)
				{
					return PassedTime * _durationInv;
				}
				return 1.0;
			}
		}

		public DoubleTimer(double duration)
		{
			PassedTime = 0.0;
			Duration = duration;
			_durationInv = 1.0 / duration;
		}

		public void Reset(double newDuration = -1.0)
		{
			PassedTime = 0.0;
			if (newDuration >= 0.0)
			{
				Duration = newDuration;
				_durationInv = 1.0 / newDuration;
			}
		}

		public void Tick()
		{
			PassedTime += Time.deltaTime;
		}

		public bool TickAndCheckDone()
		{
			Tick();
			return Done;
		}
	}
}
namespace ArboretumV1.Patches
{
	public class CustomEnemyPatches
	{
		[HarmonyPatch(typeof(EnemyAgent), "Setup")]
		private class Patch_EnemyAgent_Setup
		{
			public static void Postfix(EnemyAgent __instance)
			{
				if (0 == 0)
				{
					((Component)__instance).gameObject.AddComponent<CustomEnemyAbilityBase>().Setup();
				}
			}
		}

		[HarmonyPatch(typeof(Dam_EnemyDamageBase), "ProcessReceivedDamage")]
		private class Patch_Dam_EnemyDamageBase_ProcessReceivedDamage
		{
			public static void Postfix(float damage, Agent damageSource, Dam_EnemyDamageBase __instance)
			{
				EnemyDamageEvents.OnDamage(__instance.Owner, damageSource, damage);
			}
		}

		public static void Setup(Harmony harmony)
		{
			harmony.PatchAll(typeof(Patch_EnemyAgent_Setup));
			harmony.PatchAll(typeof(Patch_Dam_EnemyDamageBase_ProcessReceivedDamage));
			Log.Info("Custom Enemy Patches Setup");
		}
	}
	internal class CustomGearPatches
	{
		[HarmonyPatch(typeof(MineDeployerFirstPerson), "OnWield")]
		private class Patch_MineDeployerFirstPerson_OnWield
		{
			public static void Postfix(MineDeployerFirstPerson __instance)
			{
				if (((Object)((Component)__instance).gameObject).name == "GearItem_Krieger C6")
				{
					__instance.m_mineIdToSpawn = 126u;
				}
				if (((Object)((Component)__instance).gameObject).name == "GearItem_Krieger G12")
				{
					__instance.m_mineIdToSpawn = 3027u;
				}
			}
		}

		[HarmonyPatch(typeof(ItemEquippable), "OnWield")]
		private class Patch_BulletWeapon_OnWeild
		{
			public static IStatModifier m_modifier = MoveSpeedAPI.AddModifier(1f, (StackLayer)4, "Default");

			public static void Postfix(BulletWeapon __instance)
			{
				if (((ItemEquippable)__instance).ArchetypeID == 1006)
				{
					m_modifier.Mod = 0.75f;
				}
				else
				{
					m_modifier.Mod = 1f;
				}
			}
		}

		[HarmonyPatch(typeof(PLOC_Run), "FixedUpdate")]
		private class Patch_PLOC_Run_FixedUpdate
		{
			public static void Prefix(PLOC_Run __instance)
			{
				ArchetypeDataBlock archetypeData = ((PLOC_Base)__instance).m_owner.Inventory.WieldedItem.ArchetypeData;
				float walkMoveSpeed = 3.5f;
				float runMoveSpeed = 6f;
				if (archetypeData != null)
				{
					if (((GameDataBlockBase<ArchetypeDataBlock>)(object)archetypeData).persistentID == 1006)
					{
						runMoveSpeed = 4.75f;
						walkMoveSpeed = 3f;
					}
					else
					{
						runMoveSpeed = 6f;
						walkMoveSpeed = 3.5f;
					}
				}
				((PLOC_Base)__instance).m_owner.PlayerData.walkMoveSpeed = walkMoveSpeed;
				((PLOC_Base)__instance).m_owner.PlayerData.runMoveSpeed = runMoveSpeed;
			}
		}

		[HarmonyPatch(typeof(PLOC_Stand), "FixedUpdate")]
		private class Patch_PLOC_Stand_FixedUpdate
		{
			public static void Prefix(PLOC_Stand __instance)
			{
				ArchetypeDataBlock archetypeData = ((PLOC_Base)__instance).m_owner.Inventory.WieldedItem.ArchetypeData;
				float walkMoveSpeed = 3.5f;
				float runMoveSpeed = 6f;
				if (archetypeData != null)
				{
					if (((GameDataBlockBase<ArchetypeDataBlock>)(object)archetypeData).persistentID == 1006)
					{
						runMoveSpeed = 4.75f;
						walkMoveSpeed = 3f;
					}
					else
					{
						runMoveSpeed = 6f;
						walkMoveSpeed = 3.5f;
					}
				}
				((PLOC_Base)__instance).m_owner.PlayerData.walkMoveSpeed = walkMoveSpeed;
				((PLOC_Base)__instance).m_owner.PlayerData.runMoveSpeed = runMoveSpeed;
			}
		}

		public static void Setup(Harmony harmony)
		{
			harmony.PatchAll(typeof(Patch_MineDeployerFirstPerson_OnWield));
			harmony.PatchAll(typeof(Patch_BulletWeapon_OnWeild));
			Log.Info("Custom Gear Patches Setup");
		}
	}
	internal class GUI_Patches
	{
		[HarmonyPatch(typeof(CM_ExpeditionWindow), "SetVisible")]
		private class Patch_CM_ExpeditionWindow_SetVisible
		{
			public static void Postfix(CM_ExpeditionWindow __instance)
			{
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				pProgressionData value = new pProgressionData();
				if (StoredProgressionData.TryGetValue(__instance.m_data.LevelLayoutData, out value))
				{
					if (value.SecondaryCompletionCount > 0)
					{
						__instance.m_sectorIconSecond.Setup((LG_LayerType)1, __instance.m_root, true, true, true, 1f, 1f);
					}
					else
					{
						__instance.m_sectorIconSecond.Setup((LG_LayerType)1, __instance.m_root, true, false, true, 1f, 1f);
					}
					((RectTransformComp)__instance.m_sectorIconSecond).SetPosition(new Vector2(410f, 0f));
					__instance.m_sectorIconSecond.BlinkIn(2.2f);
				}
			}
		}

		[HarmonyPatch(typeof(CM_PageRundown_New), "SetIconStatus")]
		private class Patch_CM_PageRundown_new_SetIconStatus
		{
			public static void Postfix(CM_ExpeditionIcon_New icon, string mainFinishCount, string secondFinishCount, string thirdFinishCount, string allFinishedCount)
			{
				pProgressionData value = new pProgressionData();
				if (mainFinishCount != "-")
				{
					value.MainCompletionCount = int.Parse(mainFinishCount);
				}
				if (secondFinishCount != "-")
				{
					value.SecondaryCompletionCount = int.Parse(secondFinishCount);
				}
				if (thirdFinishCount != "-")
				{
					value.ThirdCompletionCount = int.Parse(thirdFinishCount);
				}
				if (allFinishedCount != "-")
				{
					value.AllCompletionCount = int.Parse(allFinishedCount);
				}
				if (!StoredProgressionData.TryAdd(icon.DataBlock.LevelLayoutData, value))
				{
					StoredProgressionData.Remove(icon.DataBlock.LevelLayoutData);
					StoredProgressionData.TryAdd(icon.DataBlock.LevelLayoutData, value);
				}
			}
		}

		internal struct pProgressionData
		{
			public int MainCompletionCount;

			public int SecondaryCompletionCount;

			public int ThirdCompletionCount;

			public int AllCompletionCount;

			public pProgressionData()
			{
				MainCompletionCount = 0;
				SecondaryCompletionCount = 0;
				ThirdCompletionCount = 0;
				AllCompletionCount = 0;
			}
		}

		[HarmonyPatch(typeof(CM_PageExpeditionSuccess), "OnEnable")]
		private class Patch_CM_PageExpeditionSuccess_OnEnable
		{
			public static void Postfix(CM_PageExpeditionSuccess __instance)
			{
				pProgressionData value = new pProgressionData();
				StoredProgressionData.TryGetValue(1001u, out value);
				if (((TMP_Text)__instance.m_expeditionName).text.Contains("A-1:"))
				{
					if (value.SecondaryCompletionCount > 0)
					{
						__instance.m_sectorIconSecond.Setup((LG_LayerType)1, __instance.m_root, true, true, true, 1f, 1f);
					}
					else
					{
						__instance.m_sectorIconSecond.Setup((LG_LayerType)1, __instance.m_root, true, false, true, 1f, 1f);
					}
					__instance.m_sectorIconSecond.BlinkIn(6.2f);
				}
			}
		}

		[HarmonyPatch(typeof(CM_PageRundown_New), "SetRundownFullyRevealed")]
		private class Patch_CM_PageRundown_New_SetRundownFullyRevealed
		{
			public static void Postfix(CM_PageRundown_New __instance)
			{
				__instance.m_tierMarker1.SetVisible(true, 0f);
				__instance.m_tierMarker2.SetVisible(true, 0f);
				__instance.m_tierMarker3.SetVisible(true, 0f);
				__instance.m_tierMarker4.SetVisible(true, 0f);
				((Component)((Component)__instance).transform.GetChild(2).GetChild(4).GetChild(15)).gameObject.SetActive(false);
				((Component)((Component)__instance).transform.GetChild(2).GetChild(4).GetChild(17)).gameObject.SetActive(false);
			}
		}

		[HarmonyPatch(typeof(CM_PageRundown_New), "Setup")]
		private class Patch_CM_PageRundown_New_Setup
		{
			private static Coroutine? _Coroutine;

			public static void Postfix(CM_PageRundown_New __instance)
			{
				//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
				CM_Item buttonConnect = __instance.m_buttonConnect;
				buttonConnect.OnBtnPressCallback += Action<int>.op_Implicit((Action<int>)delegate
				{
					if (_Coroutine == null)
					{
						_Coroutine = CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(CustomRundownElements(__instance)), (Action)null);
					}
				});
				Transform child = ((Component)__instance).transform.GetChild(2).GetChild(4);
				m_customRundownName = Object.Instantiate<GameObject>(((Component)__instance.m_textRundownHeader).gameObject, child);
				m_customRundownName.SetActive(false);
				((TMP_Text)((Component)__instance.m_buttonVanityItemDrops).GetComponent<TextMeshPro>()).text = "";
				((Component)((Component)__instance.m_buttonVanityItemDrops).transform.GetChild(0)).gameObject.SetActive(false);
				((Component)__instance.m_vanityItemDropsNext).transform.localPosition = new Vector3(9999f, 0f, 0f);
			}

			private static IEnumerator CustomRundownElements(CM_PageRundown_New __instance)
			{
				Transform child = ((Component)__instance).transform.GetChild(2).GetChild(4);
				GameObject newTierMarker1 = Object.Instantiate<GameObject>(((Component)__instance.m_tierMarker1).gameObject, child);
				GameObject newTierMarker2 = Object.Instantiate<GameObject>(((Component)__instance.m_tierMarker2).gameObject, child);
				GameObject newTierMarker3 = Object.Instantiate<GameObject>(((Component)__instance.m_tierMarker3).gameObject, child);
				GameObject newTierMarker4 = Object.Instantiate<GameObject>(((Component)__instance.m_tierMarker4).gameObject, child);
				GameObject newTierMarker5 = Object.Instantiate<GameObject>(((Component)__instance.m_tierMarker5).gameObject, child);
				yield return (object)new WaitForSeconds(3.44f);
				newTierMarker1.SetActive(true);
				yield return (object)new WaitForSeconds(1f);
				newTierMarker2.SetActive(true);
				yield return (object)new WaitForSeconds(1f);
				newTierMarker3.SetActive(true);
				yield return (object)new WaitForSeconds(1f);
				newTierMarker4.SetActive(true);
				yield return (object)new WaitForSeconds(1f);
				newTierMarker5.SetActive(true);
				yield return (object)new WaitForSeconds(7f);
				yield return null;
			}
		}

		[HarmonyPatch(typeof(CM_PageRundown_New), "TryPlaceRundown")]
		private class Patch_CM_PageRundown_New_TryPlaceRundown
		{
			public static void Postfix(CM_PageRundown_New __instance)
			{
				CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(FixRundownName(__instance)), (Action)null);
			}

			private static IEnumerator FixRundownName(CM_PageRundown_New __instance)
			{
				((TMP_Text)m_customRundownName.GetComponent<TextMeshPro>()).text = ((TMP_Text)__instance.m_textRundownHeader).text;
				m_customRundownName.SetActive(false);
				yield return (object)new WaitForSeconds(5.6f);
				m_customRundownName.SetActive(true);
				yield return null;
			}
		}

		[HarmonyPatch(typeof(CM_RundownTierMarker), "Setup")]
		private class Patch_CM_RundownTierMarker_Setup
		{
			public static void Postfix(CM_RundownTierMarker __instance)
			{
				//IL_0020: 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)
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				((Component)((Component)__instance).transform.GetChild(0)).transform.localPosition = new Vector3(20f, 0f, 0f);
				((Component)((Component)__instance).transform.GetChild(0).GetChild(0)).transform.localPosition = new Vector3(0f, 0f, 0f);
				((Component)((Component)__instance).transform.GetChild(0).GetChild(0)).transform.localScale = new Vector3(0.9104f, 35.0818f, 0.9104f);
				((Component)((Component)__instance).transform.GetChild(0).GetChild(1)).transform.localPosition = new Vector3(850f, 0f, 0f);
			}
		}

		[HarmonyPatch(typeof(CM_BoosterImplantSlotHolder), "Setup")]
		private class Patch_CM_BoosterImplantSlotHolder_Setup
		{
			public static void Prefix(CM_BoosterImplantSlotHolder __instance)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				RectTransform component = ((Component)__instance).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.anchoredPosition = new Vector2(1f, 2000f);
					component.sizeDelta = new Vector2(1f, 2000f);
					((Transform)component).localScale = new Vector3(1f, 1f, 1f);
				}
			}
		}

		[HarmonyPatch(typeof(CM_GlobalPopup), "ShowMessage")]
		private class Patch_CM_GlobalPopup_ShowMessage
		{
			public static void Postfix(CM_GlobalPopup __instance)
			{
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_010c: Unknown result type (might be due to invalid IL or missing references)
				//IL_014b: Unknown result type (might be due to invalid IL or missing references)
				if (((Object)((Component)__instance).gameObject).name == "CM_GlobalPopup_RundownIntel(Clone)")
				{
					Transform transform = ((Component)((Component)__instance).gameObject.transform.GetChild(0).GetChild(4)).gameObject.transform;
					Object.Instantiate(Plugin.s_CustomIntelImage1, transform);
					GameObject gameObject = ((Component)((Component)__instance).gameObject.transform.GetChild(0).GetChild(4).GetChild(0)).gameObject;
					gameObject.transform.localScale = new Vector3(27f, 27f, 27f);
					((Renderer)gameObject.GetComponent<SpriteRenderer>()).sortingLayerID = 2124035475;
					((Component)((Component)__instance).gameObject.transform.GetChild(0).GetChild(4)).gameObject.GetComponent<SpriteRenderer>().color = new Color(0f, 0f, 0f, 0f);
					((Component)((Component)__instance).gameObject.transform.GetChild(0).GetChild(5)).gameObject.GetComponent<SpriteRenderer>().color = new Color(0f, 0f, 0f, 0f);
					((Component)((Component)__instance).gameObject.transform.GetChild(0).GetChild(6)).gameObject.GetComponent<SpriteRenderer>().color = new Color(0f, 0f, 0f, 0f);
					((Component)((Component)__instance).gameObject.transform.GetChild(0).GetChild(0).GetChild(1)).gameObject.SetActive(true);
					((TMP_Text)((Component)((Component)__instance).gameObject.transform.GetChild(0).GetChild(0).GetChild(1)).gameObject.GetComponent<TextMeshPro>()).SetText("RND_BRIEFING", true);
				}
			}
		}

		[HarmonyPatch(typeof(CM_ExpeditionIcon_New), "SetArtifactHeat")]
		private class Patch_CM_ExpeditionIcon_New_SetArtifactHeat
		{
			public static void Postfix(CM_ExpeditionIcon_New __instance)
			{
				((TMP_Text)__instance.m_artifactHeatText).SetText("", true);
			}
		}

		[HarmonyPatch(typeof(PUI_Watermark), "UpdateWatermark")]
		private class Patch_CustomWatermark
		{
			public static void Postfix(PUI_Watermark __instance)
			{
				((TMP_Text)__instance.m_watermarkText).SetText("Arboretum V-1<color=orange> 0.5.0</color>", true);
			}
		}

		internal static Dictionary<uint, pProgressionData> StoredProgressionData = new Dictionary<uint, pProgressionData>();

		private static GameObject m_customRundownName;

		public static void Setup(Harmony harmony)
		{
			harmony.PatchAll(typeof(Patch_CM_PageRundown_New_SetRundownFullyRevealed));
			harmony.PatchAll(typeof(Patch_CM_PageRundown_New_Setup));
			harmony.PatchAll(typeof(Patch_CM_PageRundown_New_TryPlaceRundown));
			harmony.PatchAll(typeof(Patch_CM_RundownTierMarker_Setup));
			harmony.PatchAll(typeof(Patch_CM_BoosterImplantSlotHolder_Setup));
			harmony.PatchAll(typeof(Patch_CM_GlobalPopup_ShowMessage));
			harmony.PatchAll(typeof(Patch_CM_ExpeditionIcon_New_SetArtifactHeat));
			FuckOffMTFO();
			Log.Info("GUI Patches Setup");
			async Task FuckOffMTFO()
			{
				await Task.Delay(5000);
				harmony.PatchAll(typeof(Patch_CustomWatermark));
			}
		}
	}
	internal class MiscPatches
	{
		[HarmonyPatch(typeof(FPSCamera), "OnPreCull")]
		private class Patch_FPSCamera_OnPreCull
		{
			public static void Postfix(FPSCamera __instance)
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)A2_Balance.ElevatorOne != (Object)null)
				{
					((Component)__instance.m_holder).transform.position = ((Component)__instance.m_holder).transform.localPosition;
				}
			}
		}

		[HarmonyPatch(typeof(RundownManager), "HasSecondaryLayer")]
		private class Patch_RundownManager_HasSecondaryLayer
		{
			public static bool Prefix(ExpeditionInTierData data)
			{
				if (data.LevelLayoutData == 1001)
				{
					Log.Info("Returning has secondary layer as true to do things in A-1");
					return true;
				}
				if (data != null && data.SecondaryLayerEnabled)
				{
					return data.SecondaryLayout != 0;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(PlayerAmmoStorage), "UpdateBulletsInPack")]
		private class Patch_PlayerAmmoStorage_UpdateBulletsInPack
		{
			private static float current;

			private static InventorySlotAmmo ammo;

			public static void Prefix(PlayerAmmoStorage __instance, ref AmmoType ammoType, ref int bulletCount)
			{
				ammo = ((Il2CppArrayBase<InventorySlotAmmo>)(object)__instance.m_ammoStorage)[(int)ammoType];
				current = ammo.AmmoInPack;
			}

			public static void Postfix(PlayerAmmoStorage __instance, ref AmmoType ammoType, ref int bulletCount)
			{
				ammo = ((Il2CppArrayBase<InventorySlotAmmo>)(object)__instance.m_ammoStorage)[(int)ammoType];
				float num = (float)bulletCount * ammo.CostOfBullet;
				float ammoInPack = current + num;
				ammo.AmmoInPack = ammoInPack;
				__instance.UpdateAllAmmoUI();
			}
		}

		public static void Setup(Harmony harmony)
		{
			harmony.PatchAll(typeof(Patch_PlayerAmmoStorage_UpdateBulletsInPack));
			harmony.PatchAll(typeof(Patch_FPSCamera_OnPreCull));
			Log.Info("miscellaneous patches setup");
		}
	}
	internal class UniversalLevelPatches
	{
		private class Patch_LG_Factory_OnFactoryBuildStart
		{
			public static void LinkEvent()
			{
				UniversalLevelPatches.OnBuildStart?.Invoke();
			}
		}

		[HarmonyPatch(typeof(LG_Factory), "FactoryDone")]
		private class Patch_LG_Factory_FactoryDone
		{
			public static void Postfix()
			{
				UniversalLevelPatches.OnBuildDone?.Invoke();
			}
		}

		[HarmonyPatch(typeof(WardenObjectiveManager), "OnLocalPlayerStartExpedition")]
		private class Patch_WardenObjectiveManager_OnLocalPlayerStartExpedition
		{
			public static void Postfix()
			{
				UniversalLevelPatches.OnStartExpedition?.Invoke();
			}
		}

		[HarmonyPatch(typeof(WardenObjectiveManager), "OnLocalPlayerSolvedObjectiveItem")]
		private class Patch_WardenObjectiveManager_OnLocalPlayerSolvedObjectiveItem
		{
			public static void Postfix()
			{
				UniversalLevelPatches.OnSolvedObjectiveItem?.Invoke();
			}
		}

		[HarmonyPatch(typeof(WardenObjectiveManager), "ActivateWinCondition")]
		private class Patch_WardenObjectiveManager_ActivateWinCondition
		{
			public static void Postfix()
			{
				UniversalLevelPatches.OnObjectiveComplete?.Invoke();
			}
		}

		[HarmonyPatch(typeof(GS_AfterLevel), "CleanupAfterExpedition")]
		private class Patch_GS_AfterLevel_CleanupAfterExpedition
		{
			public static void Postfix()
			{
				UniversalLevelPatches.OnLevelCleanup?.Invoke();
			}
		}

		public static event Action OnBuildStart;

		public static event Action OnBuildDone;

		public static event Action OnStartExpedition;

		public static event Action OnSolvedObjectiveItem;

		public static event Action OnObjectiveComplete;

		public static event Action OnLevelCleanup;

		public static void Setup()
		{
			LG_Factory.OnFactoryBuildStart += Action.op_Implicit((Action)Patch_LG_Factory_OnFactoryBuildStart.LinkEvent);
			Harmony.CreateAndPatchAll(typeof(Patch_LG_Factory_FactoryDone), (string)null);
			Harmony.CreateAndPatchAll(typeof(Patch_WardenObjectiveManager_OnLocalPlayerStartExpedition), (string)null);
			Harmony.CreateAndPatchAll(typeof(Patch_WardenObjectiveManager_OnLocalPlayerSolvedObjectiveItem), (string)null);
			Harmony.CreateAndPatchAll(typeof(Patch_WardenObjectiveManager_ActivateWinCondition), (string)null);
			Harmony.CreateAndPatchAll(typeof(Patch_GS_AfterLevel_CleanupAfterExpedition), (string)null);
			Log.Info("Universal Level Patches Setup");
		}
	}
}
namespace ArboretumV1.CustomLevelBehavior
{
	public class A1_Restart
	{
		private static List<CustomBlackoutHandler> blackoutHandlers = new List<CustomBlackoutHandler>();

		public void Setup()
		{
			UniversalLevelPatches.OnBuildDone += OnBuildDone;
			UniversalLevelPatches.OnLevelCleanup += OnLevelCleanup;
			Log.Error("A-1 Restart Setup");
			if (Plugin.hasCConsole)
			{
				RegisterCommands();
			}
		}

		internal static void RegisterCommands()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0077: Expected O, but got Unknown
			CustomCommands.Register(new CustomCommandSetting
			{
				Category = (CategoryType)13,
				Command = "SetBlackoutState",
				Description = "Sets the blackout state in the specified tile",
				HostOnly = true,
				MinArgumentCount = 0,
				Priority = 0,
				RequireInLevel = true,
				RequireLocalPlayer = true,
				RequireRayObject = false,
				Usage = "SetBlackoutState [TileIndex int] [Enabled bool] [SkipTerminals bool]"
			}, new OnCommandUsedDelegate(OnCommandUsed));
		}

		internal static void OnCommandUsed(in CustomCmdContext ctx, string[] args)
		{
			int index = 0;
			bool state = false;
			bool skipTerminals = false;
			try
			{
				index = int.Parse(args[0]);
				state = bool.Parse(args[1]);
				skipTerminals = bool.Parse(args[2]);
			}
			catch
			{
				Log.Error("Tried to parse an argument that wasn't an int or bool (or both)");
			}
			Log.Info("Setting new blackout state in zone: " + index + ", to: " + state);
			blackoutHandlers[index].SetState(state, skipTerminals);
		}

		private void OnBuildDone()
		{
			LG_Floor currentFloor = Builder.CurrentFloor;
			blackoutHandlers.Add(((Component)((Component)currentFloor).transform.GetChild(0).GetChild(0)).gameObject.AddComponent<CustomBlackoutHandler>());
			blackoutHandlers.Add(((Component)((Component)currentFloor).transform.GetChild(0).GetChild(1)).gameObject.AddComponent<CustomBlackoutHandler>());
			blackoutHandlers.Add(((Component)((Component)currentFloor).transform.GetChild(0).GetChild(2)).gameObject.AddComponent<CustomBlackoutHandler>());
			blackoutHandlers.Add(((Component)((Component)currentFloor).transform.GetChild(0).GetChild(3)).gameObject.AddComponent<CustomBlackoutHandler>());
			blackoutHandlers.Add(((Component)((Component)currentFloor).transform.GetChild(0).GetChild(4)).gameObject.AddComponent<CustomBlackoutHandler>());
			blackoutHandlers.Add(((Component)((Component)currentFloor).transform.GetChild(0).GetChild(5)).gameObject.AddComponent<CustomBlackoutHandler>());
			blackoutHandlers.Add(((Component)((Component)currentFloor).transform.GetChild(0).GetChild(6)).gameObject.AddComponent<CustomBlackoutHandler>());
			blackoutHandlers.Add(((Component)((Component)currentFloor).transform.GetChild(0).GetChild(7)).gameObject.AddComponent<CustomBlackoutHandler>());
		}

		public static void BlackoutEvent(WardenObjectiveEventData e)
		{
			switch (e.Count)
			{
			case 0:
				blackoutHandlers[0].SetState(!e.Enabled, e.ClearDimension);
				break;
			case 1:
				blackoutHandlers[1].SetState(!e.Enabled, e.ClearDimension);
				break;
			case 2:
				blackoutHandlers[2].SetState(!e.Enabled, e.ClearDimension);
				break;
			case 3:
				blackoutHandlers[3].SetState(!e.Enabled, e.ClearDimension);
				break;
			case 4:
				blackoutHandlers[4].SetState(!e.Enabled, e.ClearDimension);
				break;
			case 5:
				blackoutHandlers[5].SetState(!e.Enabled, e.ClearDimension);
				break;
			case 6:
				blackoutHandlers[6].SetState(!e.Enabled, e.ClearDimension);
				break;
			case 7:
				blackoutHandlers[7].SetState(!e.Enabled, e.ClearDimension);
				break;
			}
		}

		public static void ChangeSecondaryObjectiveState(WardenObjectiveEventData e)
		{
			if (e.Enabled)
			{
				WardenObjectiveManager.ForceCompleteObjective((LG_LayerType)1);
			}
		}

		private void OnLevelCleanup()
		{
			blackoutHandlers.Clear();
			UniversalLevelPatches.OnBuildDone -= OnBuildDone;
			UniversalLevelPatches.OnLevelCleanup -= OnLevelCleanup;
		}
	}
	public class CustomBlackoutHandler : MonoBehaviour
	{
		public LG_DoorButton[] doorButtons = Array.Empty<LG_DoorButton>();

		public LG_ComputerTerminal[] terminals = Array.Empty<LG_ComputerTerminal>();

		public LG_Light[] lights = Array.Empty<LG_Light>();

		public void Start()
		{
			doorButtons = Il2CppArrayBase<LG_DoorButton>.op_Implicit(((Component)this).GetComponentsInChildren<LG_DoorButton>());
			terminals = Il2CppArrayBase<LG_ComputerTerminal>.op_Implicit(((Component)this).GetComponentsInChildren<LG_ComputerTerminal>());
			lights = Il2CppArrayBase<LG_Light>.op_Implicit(((Component)this).GetComponentsInChildren<LG_Light>());
		}

		public void SetState(bool state, bool skipTerminals = false)
		{
			LG_DoorButton[] array = doorButtons;
			foreach (LG_DoorButton obj in array)
			{
				obj.m_enabled = state;
				((Component)((Component)obj).transform.GetChild(1)).gameObject.SetActive(state);
			}
			LG_Light[] array2 = lights;
			for (int i = 0; i < array2.Length; i++)
			{
				((Component)array2[i]).gameObject.SetActive(state);
			}
			LG_ComputerTerminal[] array3 = terminals;
			foreach (LG_ComputerTerminal val in array3)
			{
				if (skipTerminals)
				{
					break;
				}
				if (!((Object)(object)val.ConnectedReactor != (Object)null))
				{
					val.ExitFPSView();
					((Component)((Component)val).transform.GetChild(0)).gameObject.SetActive(state);
					((Component)((Component)val).transform.GetChild(1).GetChild(0)).gameObject.SetActive(state);
					((Component)((Component)val).transform.GetChild(1).GetChild(1).GetChild(1)).gameObject.SetActive(state);
				}
			}
		}
	}
	public class A2_Balance
	{
		[HarmonyPatch(typeof(PLOC_Base), "UpdateVerticalVelocityInAir")]
		private class Patch_PLOC_Base_UpdateVerticalVelocityInAir
		{
			public static void Postfix(PLOC_Base __instance)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				Vector3 verticalVelocity = __instance.m_owner.Locomotion.VerticalVelocity;
				__instance.m_owner.Locomotion.VerticalVelocity = new Vector3(verticalVelocity.x, verticalVelocity.y + ElevatorOne.velocity, verticalVelocity.z);
			}
		}

		private Harmony m_harmony = new Harmony("RLC.Arboretum.A2_Balance");

		public static A2Elevator ElevatorOne;

		private A2Elevator ElevatorTwo;

		public static GameObject LocalAgentParent;

		public static PlayerAgent epicDebugPlayerAgent;

		public void Setup()
		{
			LevelAPI.OnBuildStart += OnBuildStart;
			LevelAPI.OnBuildDone += OnBuildDone;
			LevelAPI.OnLevelCleanup += OnLevelCleanup;
			m_harmony.PatchAll(typeof(Patch_PLOC_Base_UpdateVerticalVelocityInAir));
			Log.Error("A-2 Balance Setup");
		}

		private void OnBuildStart()
		{
		}

		private void OnBuildDone()
		{
			SpawnElevators();
			CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(MakeElevatorsWork()), (Action)null);
		}

		private void SpawnElevators()
		{
			ElevatorOne = ((Component)((Component)Builder.CurrentFloor).transform.GetChild(0).GetChild(1).GetChild(1)
				.GetChild(0)).gameObject.AddComponent<A2Elevator>();
		}

		public void GenerateFogSphere()
		{
			//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)
			Log.Info("GeneratingFogSphere");
			FogSphereHandler component = Object.Instantiate<GameObject>(Plugin.s_customFogSphere, new Vector3(0f, 0f, 0f), Quaternion.identity).GetComponent<FogSphereHandler>();
			component.m_totalLength = 1E+13f;
			if (component.Play())
			{
				Log.Info("Played Fog Sphere");
			}
			else
			{
				Log.Error("Could not play fog sphere :(");
			}
		}

		private static IEnumerator MakeElevatorsWork()
		{
			if ((Object)(object)LocalAgentParent == (Object)null)
			{
				LocalAgentParent = new GameObject("FunctionalElevatorBullshit");
				Scene sceneByName = SceneManager.GetSceneByName("Complex_Shared_S20");
				SceneManager.MoveGameObjectToScene(LocalAgentParent, sceneByName);
			}
			yield return (object)new WaitForSeconds(5f);
			PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
			((Component)localPlayerAgent).transform.parent = LocalAgentParent.transform;
			((Component)localPlayerAgent.FPSCamera.m_orgParent.parent).transform.parent = LocalAgentParent.transform;
			epicDebugPlayerAgent = localPlayerAgent;
			yield return null;
		}

		internal static void MoveElevatorToFloor(WardenObjectiveEventData e)
		{
		}

		private void OnLevelCleanup()
		{
			UniversalLevelPatches.OnBuildDone -= OnBuildDone;
			UniversalLevelPatches.OnLevelCleanup -= OnLevelCleanup;
		}
	}
	public class A2Elevator : MonoBehaviour
	{
		private Transform ElevatorTransform;

		private GameObject linkedPlayerCollider;

		public List<Animator> doorAnimators;

		private float startTime;

		public float velocity;

		public float targetYPos;

		private float prevYPos;

		private void Start()
		{
			ElevatorTransform = ((Component)this).transform.GetChild(2);
			linkedPlayerCollider = ((Component)((Component)this).transform.GetChild(1)).gameObject;
			doorAnimators.Add(((Component)((Component)this).transform.GetChild(0).GetChild(0).GetChild(0)).GetComponentInChildren<Animator>());
			doorAnimators.Add(((Component)((Component)this).transform.GetChild(0).GetChild(0).GetChild(1)).GetComponentInChildren<Animator>());
			doorAnimators.Add(((Component)((Component)this).transform.GetChild(0).GetChild(0).GetChild(2)).GetComponentInChildren<Animator>());
			doorAnimators.Add(((Component)((Component)this).transform.GetChild(0).GetChild(0).GetChild(3)).GetComponentInChildren<Animator>());
		}

		private void Update()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)ElevatorTransform == (Object)null))
			{
				float y = ElevatorTransform.localPosition.y;
				float num = (Time.time - startTime) / 128f;
				Vector3 zero = Vector3.zero;
				zero.y = Mathf.SmoothStep(y, targetYPos, num);
				ElevatorTransform.localPosition = zero;
				velocity = (zero.y - y) / Time.time;
			}
		}

		internal void MoveToFloor(int floor)
		{
			startTime = Time.time;
			switch (floor)
			{
			case 0:
				prevYPos = targetYPos;
				targetYPos = 0f;
				break;
			case 1:
				prevYPos = targetYPos;
				targetYPos = -64f;
				break;
			case 2:
				prevYPos = targetYPos;
				targetYPos = -128f;
				break;
			}
		}

		internal void ChangeDoors(bool open = false)
		{
			foreach (Animator doorAnimator in doorAnimators)
			{
				if (open)
				{
					doorAnimator.Play("ElevatorDoorOpen");
				}
				else
				{
					doorAnimator.Play("ElevatorDoorClose");
				}
			}
		}

		public void TriggerElevatorMovement(int floor)
		{
		}
	}
	internal class A3_Betrayal
	{
		public GameObject m_customGUI;

		public void Setup()
		{
		}

		public void OnElevatorLand()
		{
		}

		private void CreateCustomGUI()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			m_customGUI = Object.Instantiate<GameObject>(new GameObject("PUI_A3_KnownDoors"), ((Component)GuiManager.PlayerLayer.WardenObjectives).transform.parent);
			m_customGUI.layer = 5;
			Transform transform = m_customGUI.transform;
			transform.localPosition = new Vector3(-880f, 200f, 0f);
			transform.localScale = new Vector3(5f, 5f, 5f);
			m_customGUI.AddComponent<PUI_A3_DoorKnowledge>();
			GameObject obj = Object.Instantiate<GameObject>(new GameObject("Header"), transform);
			obj.layer = 5;
			((TMP_Text)obj.AddComponent<TextMeshPro>()).text = "Intelligence";
		}
	}
	public class PUI_A3_DoorKnowledge : MonoBehaviour
	{
		public GameObject doorsHeader;
	}
	internal class A4_Control
	{
		public void Setup()
		{
		}
	}
	internal class A4_DoubleSidedDoors : MonoBehaviour
	{
		public Interact_RequireKeyItem backInteract_RequireKeyItem;

		public Interact_Hack backInteract_Hack;

		public Interact_MessageOnScreen backInteract_MessageOnScreen;

		public Interact_Timed backInteract_OpenOrActivate;
	}
	public class C2_Relay
	{
		private const string HarmonyID = "RLC.C2_Relay";

		public void Setup()
		{
			UniversalLevelPatches.OnStartExpedition += OnStartExpedition;
			UniversalLevelPatches.OnLevelCleanup += CleanupAfterExpedition;
			OnFactoryBuildStart();
			Log.Error("C2_Relay Setup with ID: RLC.C2_Relay");
		}

		public void OnFactoryBuildStart()
		{
		}

		public void OnStartExpedition()
		{
		}

		public void CleanupAfterExpedition()
		{
			Harmony.UnpatchID("RLC.C2_Relay");
			UniversalLevelPatches.OnStartExpedition -= OnStartExpedition;
			UniversalLevelPatches.OnLevelCleanup -= CleanupAfterExpedition;
			Log.Error("C2_Relay Cleaned up ID: RLC.C2_Relay");
		}
	}
	public class CustomFogTesting : MonoBehaviour
	{
		public static void Setup()
		{
			Log.Info("Setting up custom fog layer :)");
		}
	}
	internal class CustomLevelBehavior_Manager
	{
		public static A1_Restart A1;

		public static A2_Balance A2;

		public static A3_Betrayal A3;

		public static D1_Resurgence D1;

		public static C2_Relay C2;

		public static void Setup()
		{
			D1 = new D1_Resurgence();
			C2 = new C2_Relay();
			A1 = new A1_Restart();
			A2 = new A2_Balance();
			A3 = new A3_Betrayal();
			LG_Factory.OnFactoryBuildStart += Action.op_Implicit((Action)SetupCustomLevel);
		}

		public static void SetupCustomLevel()
		{
			switch (RundownManager.ActiveExpedition.LevelLayoutData)
			{
			case 1001u:
				A1.Setup();
				break;
			case 1002u:
				A2.Setup();
				break;
			case 1003u:
				A3.Setup();
				break;
			case 1u:
				D1.Setup();
				break;
			case 16u:
				C2.Setup();
				break;
			case 9999u:
				A2.Setup();
				break;
			}
		}
	}
	public class D1_Resurgence_ReactorRestart : MonoBehaviour
	{
		private void Start()
		{
		}

		private void Update()
		{
		}
	}
	internal class D1_Resurgence
	{
		public class D1_ReactorBehaviour : MonoBehaviour
		{
			private bool isSetup;

			public int ReactorTempMain;

			public int ReactorTempDecimal;

			public float ReactorTempActual;

			public void Setup()
			{
				isSetup = true;
			}

			public void Update()
			{
				_ = isSetup;
			}
		}

		private const string HarmonyID = "RLC.D1_Resurgence";

		public void Setup()
		{
			Log.Error("D-1 Resurgence Setup");
		}

		private static float IntToFloat(int mainPart, int decimalPart)
		{
			if (decimalPart < 0 || decimalPart >= 100)
			{
				Log.Error("Decimal part must be between 0 and 99.");
			}
			return (float)mainPart + (float)decimalPart / 100f;
		}

		private static void FloatToInt(float value, out int mainPart, out int decimalPart)
		{
			mainPart = (int)value;
			decimalPart = (int)Math.Round((value - (float)mainPart) * 100f);
		}
	}
}
namespace ArboretumV1.CustomEnemyBehavior
{
	public class CustomAbility_Phaser_Big : MonoBehaviour
	{
		private CustomEnemyAbilityBase m_customAbilityBase;

		private Timer _phaseRegenTimer;

		private bool _isTimerDone;

		public SkinnedMeshRenderer _meshRenderer;

		public bool EnableCloaking = true;

		private static float m_currentPhaseLevel = 0.5f;

		private static float m_minPhaseLevel = 0.05f;

		private static float m_maxPhaseLevel = 0.8f;

		private void Start()
		{
			m_customAbilityBase = ((Component)this).GetComponent<CustomEnemyAbilityBase>();
			SkinnedMeshRenderer component = ((Component)((Component)this).gameObject.transform.GetChild(3).GetChild(3)).GetComponent<SkinnedMeshRenderer>();
			_meshRenderer = component;
			EnemyDamageEvents.Damage += OnTakeDamage;
			m_customAbilityBase.m_enemyDamageBase.Owner.AddOnDeadOnce(delegate
			{
				EnemyDamageEvents.Damage -= OnTakeDamage;
			});
		}

		private void FixedUpdate()
		{
			//IL_0053: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			if (EnableCloaking && ((Agent)m_customAbilityBase.m_enemyAgent).Alive)
			{
				if (!_isTimerDone && _phaseRegenTimer.TickAndCheckDone())
				{
					_isTimerDone = true;
				}
				else if (_isTimerDone)
				{
					IncreasePhaseLevel();
				}
				Color color = ((Renderer)_meshRenderer).material.color;
				color.a = m_currentPhaseLevel;
				((Renderer)_meshRenderer).material.color = color;
			}
		}

		private void OnTakeDamage(EnemyAgent enemyAgent, Agent inflictor, float damage)
		{
			if (((Agent)enemyAgent).GlobalID == ((Agent)m_customAbilityBase.m_enemyAgent).GlobalID)
			{
				_phaseRegenTimer.Reset(6f);
				_isTimerDone = false;
				DecreasePhaseLevel(damage);
			}
		}

		private void DecreasePhaseLevel(float damage)
		{
			if (damage >= 100f)
			{
				m_currentPhaseLevel = Mathf.Lerp(m_currentPhaseLevel, m_minPhaseLevel, 0.15f);
				return;
			}
			float num = damage * 0.01f;
			m_currentPhaseLevel = Mathf.Clamp(Mathf.Lerp(m_currentPhaseLevel, m_currentPhaseLevel + num, 0.15f), m_minPhaseLevel, m_maxPhaseLevel);
		}

		private void IncreasePhaseLevel()
		{
			m_currentPhaseLevel = Mathf.Clamp(m_currentPhaseLevel - 0.01f, m_minPhaseLevel, m_maxPhaseLevel);
		}
	}
	public class CustomAbility_Phaser_Small : MonoBehaviour
	{
		private CustomEnemyAbilityBase m_customAbilityBase;

		private Timer _phaseRegenTimer;

		private bool _isTimerDone;

		public SkinnedMeshRenderer _meshRenderer;

		public bool EnableCloaking = true;

		private static float m_currentPhaseLevel = 0.5f;

		private static float m_minPhaseLevel = 0.05f;

		private static float m_maxPhaseLevel = 0.8f;

		private void Start()
		{
			m_customAbilityBase = ((Component)this).GetComponent<CustomEnemyAbilityBase>();
			SkinnedMeshRenderer component = ((Component)((Component)this).gameObject.transform.GetChild(3).GetChild(3)).GetComponent<SkinnedMeshRenderer>();
			_meshRenderer = component;
			EnemyDamageEvents.Damage += OnTakeDamage;
			m_customAbilityBase.m_enemyDamageBase.Owner.AddOnDeadOnce(delegate
			{
				EnemyDamageEvents.Damage -= OnTakeDamage;
			});
		}

		private void FixedUpdate()
		{
			//IL_0053: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			if (EnableCloaking && ((Agent)m_customAbilityBase.m_enemyAgent).Alive)
			{
				if (!_isTimerDone && _phaseRegenTimer.TickAndCheckDone())
				{
					_isTimerDone = true;
				}
				else if (_isTimerDone)
				{
					IncreasePhaseLevel();
				}
				Color color = ((Renderer)_meshRenderer).material.color;
				color.a = m_currentPhaseLevel;
				((Renderer)_meshRenderer).material.color = color;
			}
		}

		private void OnTakeDamage(EnemyAgent enemyAgent, Agent inflictor, float damage)
		{
			if (((Agent)enemyAgent).GlobalID == ((Agent)m_customAbilityBase.m_enemyAgent).GlobalID)
			{
				_phaseRegenTimer.Reset(3f);
				_isTimerDone = false;
				DecreasePhaseLevel(damage);
			}
		}

		private void DecreasePhaseLevel(float damage)
		{
			if (damage >= 100f)
			{
				m_currentPhaseLevel = Mathf.Lerp(m_currentPhaseLevel, m_minPhaseLevel, 0.15f);
				return;
			}
			float num = damage * 0.05f;
			m_currentPhaseLevel = Mathf.Clamp(Mathf.Lerp(m_currentPhaseLevel, m_currentPhaseLevel + num, 0.15f), m_minPhaseLevel, m_maxPhaseLevel);
		}

		private void IncreasePhaseLevel()
		{
			m_currentPhaseLevel = Mathf.Clamp(m_currentPhaseLevel - 0.015f, m_minPhaseLevel, m_maxPhaseLevel);
		}
	}
	public class CustomEnemyAbilityBase : MonoBehaviour
	{
		public EnemyAgent m_enemyAgent;

		public Dam_EnemyDamageBase m_enemyDamageBase;

		public void Setup()
		{
			m_enemyAgent = ((Component)this).GetComponent<EnemyAgent>();
			m_enemyDamageBase = ((Component)this).GetComponent<Dam_EnemyDamageBase>();
			if (((GameDataBlockBase<EnemyDataBlock>)(object)m_enemyAgent.EnemyData).persistentID == 503)
			{
				((Component)this).gameObject.AddComponent<CustomAbility_Phaser_Small>();
			}
			if (((GameDataBlockBase<EnemyDataBlock>)(object)m_enemyAgent.EnemyData).persistentID == 504)
			{
				((Component)this).gameObject.AddComponent<CustomAbility_Phaser_Big>();
			}
		}
	}
}