Decompiled source of EOSExt DimensionWarp v1.0.1

plugins/Inas07.EOSExt.DimensionWarp.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AIGraph;
using Agents;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using EOSExt.DimensionWarp.Definition;
using ExtraObjectiveSetup.BaseClasses;
using ExtraObjectiveSetup.ExtendedWardenEvents;
using ExtraObjectiveSetup.Utils;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Inas07.EOSExt.DimensionWarp")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Inas07.EOSExt.DimensionWarp")]
[assembly: AssemblyTitle("Inas07.EOSExt.DimensionWarp")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EOSExt.DimensionWarp
{
	public class DimensionWarpManager : GenericExpeditionDefinitionManager<DimensionWarpDefinition>
	{
		public enum WardenEvents_Warp
		{
			WarpTeam = 160,
			WarpRange,
			WarpItemsInZone
		}

		private readonly ImmutableList<Vector3> lookDirs = new List<Vector3>
		{
			Vector3.forward,
			Vector3.back,
			Vector3.left,
			Vector3.right
		}.ToImmutableList();

		public static DimensionWarpManager Current { get; private set; }

		protected override string DEFINITION_NAME => "DimensionWarp";

		public AIG_NodeCluster GetNodeFromDimensionPosition(eDimensionIndex dimensionIndex, Vector3 position)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			AIG_GeomorphNodeVolume val = default(AIG_GeomorphNodeVolume);
			AIG_VoxelNodePillar val2 = default(AIG_VoxelNodePillar);
			AIG_INode val3 = default(AIG_INode);
			AIG_NodeCluster result = default(AIG_NodeCluster);
			if (!AIG_GeomorphNodeVolume.TryGetGeomorphVolume(0, dimensionIndex, position, ref val) || !((AIG_NodeVolume)val).m_voxelNodeVolume.TryGetPillar(position, ref val2) || !val2.TryGetVoxelNode(position.y, ref val3) || !AIG_NodeCluster.TryGetNodeCluster(val3.ClusterID, ref result))
			{
				EOSLogger.Error("GetNodeFromDimensionPosition: Position is not valid, try again inside an area.");
				return null;
			}
			return result;
		}

		public DimensionWarpDefinition GetWarpDefinition(string worldEventObjectFilter)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			if ((int)GameStateManager.CurrentStateName != 10 || !base.definitions.ContainsKey(RundownManager.ActiveExpedition.LevelLayoutData))
			{
				EOSLogger.Error($"GetWarpPositions: Didn't find config with MainLevelLayout {RundownManager.ActiveExpedition.LevelLayoutData}");
				return null;
			}
			DimensionWarpDefinition dimensionWarpDefinition = base.definitions[RundownManager.ActiveExpedition.LevelLayoutData].Definitions.Find((DimensionWarpDefinition def) => def.WorldEventObjectFilter == worldEventObjectFilter);
			if (dimensionWarpDefinition == null)
			{
				EOSLogger.Error($"GetWarpPositions: Didn't find config for {worldEventObjectFilter} with MainLevelLayout {RundownManager.ActiveExpedition.LevelLayoutData}");
				return new DimensionWarpDefinition();
			}
			return dimensionWarpDefinition;
		}

		public void WarpItem(ItemInLevel item, eDimensionIndex warpToDim, Vector3 warpToPosition)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_001b: 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_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_0039: 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)
			if (SNet.IsMaster && (int)GameStateManager.CurrentStateName == 10 && (Object)(object)item != (Object)null)
			{
				AIG_NodeCluster nodeFromDimensionPosition = GetNodeFromDimensionPosition(warpToDim, warpToPosition);
				if (nodeFromDimensionPosition != null)
				{
					item.GetSyncComponent().AttemptPickupInteraction((ePickupItemInteractionType)1, (SNet_Player)null, ((Item)item).pItemData.custom, warpToPosition, Quaternion.identity, nodeFromDimensionPosition.CourseNode, true, true);
				}
				else
				{
					EOSLogger.Error("WarpTeam: cannot find course node for item to warp");
				}
			}
		}

		public void WarpItemsInZone(eDimensionIndex dimensionIndex, LG_LayerType layer, eLocalZoneIndex localIndex, string worldEventObjectFilter)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			if (!SNet.IsMaster || (int)GameStateManager.CurrentStateName != 10)
			{
				return;
			}
			if ((Object)(object)PlayerManager.GetLocalPlayerAgent() == (Object)null)
			{
				EOSLogger.Error("WarpItemsInZone: master - LocalPlayerAgent is null???");
				return;
			}
			DimensionWarpDefinition warpDefinition = GetWarpDefinition(worldEventObjectFilter);
			if (warpDefinition == null)
			{
				EOSLogger.Error("WarpItemsInZone: worldEventObjectFilter '" + worldEventObjectFilter + "' is not defined");
				return;
			}
			List<PositionAndLookDir> locations = warpDefinition.Locations;
			if (locations.Count < 1)
			{
				EOSLogger.Error("WarpItemsInZone: no warp position found");
				return;
			}
			int num = 0;
			Enumerator<IWarpableObject> enumerator = Dimension.WarpableObjects.GetEnumerator();
			while (enumerator.MoveNext())
			{
				ItemInLevel val = ((Il2CppObjectBase)enumerator.Current).TryCast<ItemInLevel>();
				if ((Object)(object)val != (Object)null)
				{
					AIG_CourseNode courseNode = val.CourseNode;
					if (val.internalSync.GetCurrentState().placement.droppedOnFloor && courseNode.m_dimension.DimensionIndex == dimensionIndex && courseNode.LayerType == layer && courseNode.m_zone.LocalIndex == localIndex && (!warpDefinition.OnWarp.WarpItemsInZone_OnlyWarpWarpable || val.CanWarp))
					{
						Vector3 warpToPosition = locations[num].Position.ToVector3();
						WarpItem(val, dimensionIndex, warpToPosition);
					}
					num = (num + 1) % locations.Count;
				}
			}
		}

		internal void WarpItemsInZone(WardenObjectiveEventData e)
		{
			//IL_0001: 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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			eDimensionIndex dimensionIndex = e.DimensionIndex;
			LG_LayerType layer = e.Layer;
			eLocalZoneIndex localIndex = e.LocalIndex;
			string worldEventObjectFilter = e.WorldEventObjectFilter;
			WarpItemsInZone(dimensionIndex, layer, localIndex, worldEventObjectFilter);
		}

		public void WarpRange(Vector3 rangeOrigin, float range, string worldEventObjectFilter)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			if ((int)GameStateManager.CurrentStateName != 10)
			{
				return;
			}
			PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
			if ((Object)(object)localPlayerAgent == (Object)null)
			{
				EOSLogger.Error("WarpTeam: LocalPlayerAgent is null");
				return;
			}
			DimensionWarpDefinition warpDefinition = GetWarpDefinition(worldEventObjectFilter);
			if (warpDefinition == null)
			{
				EOSLogger.Error("WarpItemsInZone: worldEventObjectFilter '" + worldEventObjectFilter + "' is not defined");
				return;
			}
			List<PositionAndLookDir> locations = warpDefinition.Locations;
			if (locations.Count < 1)
			{
				EOSLogger.Error("WarpAlivePlayersInRange: no warp locations found");
				return;
			}
			int index = localPlayerAgent.PlayerSlotIndex % locations.Count;
			Vector3 val = locations[index].Position.ToVector3();
			int index2 = locations[index].LookDir % lookDirs.Count;
			Vector3 val2 = lookDirs[index2];
			int num = 0;
			List<SentryGunInstance> list = new List<SentryGunInstance>();
			Enumerator<IWarpableObject> enumerator = Dimension.WarpableObjects.GetEnumerator();
			Vector3 val4;
			while (enumerator.MoveNext())
			{
				IWarpableObject current = enumerator.Current;
				SentryGunInstance val3 = ((Il2CppObjectBase)current).TryCast<SentryGunInstance>();
				if ((Object)(object)val3 != (Object)null)
				{
					if (!((ItemEquippable)val3).LocallyPlaced || !((Agent)((Item)val3).Owner).Alive)
					{
						continue;
					}
					val4 = rangeOrigin - ((Agent)((Item)val3).Owner).Position;
					if (((Vector3)(ref val4)).magnitude < range)
					{
						val4 = rangeOrigin - ((Component)val3).transform.position;
						if (((Vector3)(ref val4)).magnitude < range || warpDefinition.OnWarp.WarpRange_WarpDeployedSentryOutsideRange)
						{
							list.Add(val3);
						}
					}
				}
				else
				{
					if (!SNet.IsMaster)
					{
						continue;
					}
					ItemInLevel val5 = ((Il2CppObjectBase)current).TryCast<ItemInLevel>();
					if ((Object)(object)val5 != (Object)null)
					{
						val4 = ((Component)val5).transform.position - rangeOrigin;
						if (((Vector3)(ref val4)).magnitude < range)
						{
							Vector3 warpToPosition = locations[num].Position.ToVector3();
							WarpItem(val5, warpDefinition.DimensionIndex, warpToPosition);
							num = (num + 1) % locations.Count;
						}
					}
				}
			}
			list.ForEach(delegate(SentryGunInstance sentryGun)
			{
				sentryGun.m_sync.WantItemAction(((Item)sentryGun).Owner, (SyncedItemAction_New)0);
			});
			if (((Agent)localPlayerAgent).Alive)
			{
				val4 = rangeOrigin - ((Agent)localPlayerAgent).Position;
				if (((Vector3)(ref val4)).magnitude < range && !localPlayerAgent.TryWarpTo(warpDefinition.DimensionIndex, val, val2, true))
				{
					EOSLogger.Error($"WarpAlivePlayersInRange: TryWarpTo failed, Position: {val}");
				}
			}
		}

		internal void WarpRange(WardenObjectiveEventData e)
		{
			//IL_0001: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = e.Position;
			float fogTransitionDuration = e.FogTransitionDuration;
			string worldEventObjectFilter = e.WorldEventObjectFilter;
			WarpRange(position, fogTransitionDuration, worldEventObjectFilter);
		}

		public void WarpTeam(string worldEventObjectFilter)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			if ((int)GameStateManager.CurrentStateName != 10)
			{
				return;
			}
			PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
			if ((Object)(object)localPlayerAgent == (Object)null)
			{
				EOSLogger.Error("WarpTeam: LocalPlayerAgent is null");
				return;
			}
			DimensionWarpDefinition warpDefinition = GetWarpDefinition(worldEventObjectFilter);
			if (warpDefinition == null)
			{
				EOSLogger.Error("WarpTeam: worldEventObjectFilter '" + worldEventObjectFilter + "' is not defined");
				return;
			}
			List<PositionAndLookDir> locations = warpDefinition.Locations;
			if (locations.Count < 1)
			{
				EOSLogger.Error("WarpTeam: no warp locations found");
				return;
			}
			int num = localPlayerAgent.PlayerSlotIndex % locations.Count;
			Vector3 val = locations[num].Position.ToVector3();
			int index = locations[num].LookDir % lookDirs.Count;
			Vector3 val2 = lookDirs[index];
			int num2 = 0;
			List<SentryGunInstance> list = new List<SentryGunInstance>();
			Enumerator<IWarpableObject> enumerator = Dimension.WarpableObjects.GetEnumerator();
			while (enumerator.MoveNext())
			{
				IWarpableObject current = enumerator.Current;
				SentryGunInstance val3 = ((Il2CppObjectBase)current).TryCast<SentryGunInstance>();
				if ((Object)(object)val3 != (Object)null)
				{
					if (((ItemEquippable)val3).LocallyPlaced)
					{
						list.Add(val3);
					}
				}
				else if (SNet.IsMaster && warpDefinition.OnWarp.WarpTeam_WarpAllWarpableBigPickupItems)
				{
					ItemInLevel val4 = ((Il2CppObjectBase)current).TryCast<ItemInLevel>();
					if ((Object)(object)val4 != (Object)null && val4.CanWarp && val4.internalSync.GetCurrentState().placement.droppedOnFloor)
					{
						Vector3 warpToPosition = locations[num2].Position.ToVector3();
						WarpItem(val4, warpDefinition.DimensionIndex, warpToPosition);
						EOSLogger.Warning(((Item)val4).PublicName ?? "");
						num2 = (num2 + 1) % locations.Count;
					}
				}
			}
			list.ForEach(delegate(SentryGunInstance sentryGun)
			{
				sentryGun.m_sync.WantItemAction(((Item)sentryGun).Owner, (SyncedItemAction_New)0);
			});
			if (!localPlayerAgent.TryWarpTo(warpDefinition.DimensionIndex, val, val2, true))
			{
				EOSLogger.Error($"WarpTeam: TryWarpTo failed. Position: {val}, playerSlotIndex: {localPlayerAgent.PlayerSlotIndex}, warpLocationIndex: {num}");
			}
		}

		internal void WarpTeam(WardenObjectiveEventData e)
		{
			WarpTeam(e.WorldEventObjectFilter);
		}

		private DimensionWarpManager()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			EOSWardenEventManager.Current.AddEventDefinition(WardenEvents_Warp.WarpTeam.ToString(), 160u, (Action<WardenObjectiveEventData>)WarpTeam);
			EOSWardenEventManager.Current.AddEventDefinition(WardenEvents_Warp.WarpRange.ToString(), 161u, (Action<WardenObjectiveEventData>)WarpRange);
			EOSWardenEventManager.Current.AddEventDefinition(WardenEvents_Warp.WarpItemsInZone.ToString(), 162u, (Action<WardenObjectiveEventData>)WarpItemsInZone);
		}

		static DimensionWarpManager()
		{
			Current = new DimensionWarpManager();
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Inas.EOSExt.DimensionWarp", "EOSExt.DimensionWarp", "1.0.1")]
	public class EntryPoint : BasePlugin
	{
		public const string AUTHOR = "Inas";

		public const string PLUGIN_NAME = "EOSExt.DimensionWarp";

		public const string VERSION = "1.0.1";

		private Harmony m_Harmony;

		public override void Load()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			SetupManagers();
			m_Harmony = new Harmony("EOSExt.DimensionWarp");
			m_Harmony.PatchAll();
			EOSLogger.Log("ExtraObjectiveSetup.DimensionWarp loaded.");
		}

		private void SetupManagers()
		{
			((GenericExpeditionDefinitionManager<DimensionWarpDefinition>)DimensionWarpManager.Current).Init();
		}
	}
}
namespace EOSExt.DimensionWarp.Definition
{
	public class PositionAndLookDir
	{
		public Vec3 Position { get; set; } = new Vec3();


		public int LookDir { get; set; }
	}
	public class OnWarp
	{
		public bool WarpTeam_WarpAllWarpableBigPickupItems { get; set; } = true;


		public bool WarpRange_WarpDeployedSentryOutsideRange { get; set; } = true;


		public bool WarpItemsInZone_OnlyWarpWarpable { get; set; } = true;

	}
	public class DimensionWarpDefinition
	{
		public string WorldEventObjectFilter { get; set; } = string.Empty;


		public eDimensionIndex DimensionIndex { get; set; }

		public OnWarp OnWarp { get; set; } = new OnWarp();


		public List<PositionAndLookDir> Locations { get; set; } = new List<PositionAndLookDir>();

	}
}