using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Agents;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using ChainedPuzzles;
using EOSExt.SecuritySensor.Component;
using EOSExt.SecuritySensor.Definition;
using ExtraObjectiveSetup;
using ExtraObjectiveSetup.BaseClasses;
using ExtraObjectiveSetup.ExtendedWardenEvents;
using ExtraObjectiveSetup.Utils;
using FloLib.Networks.Replications;
using GTFO.API;
using GTFO.API.Extensions;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using Localization;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using TMPro;
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.SecuritySensor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+191150f2201760d38178a442f9878a35e25f49c5")]
[assembly: AssemblyProduct("Inas07.EOSExt.SecuritySensor")]
[assembly: AssemblyTitle("Inas07.EOSExt.SecuritySensor")]
[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.SecuritySensor
{
internal static class Assets
{
public static GameObject CircleSensor { get; private set; }
public static GameObject MovableSensor { get; private set; }
public static void Init()
{
CircleSensor = AssetAPI.GetLoadedAsset<GameObject>("Assets/SecuritySensor/CircleSensor.prefab");
MovableSensor = AssetAPI.GetLoadedAsset<GameObject>("Assets/SecuritySensor/MovableSensor.prefab");
}
}
[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.SecuritySensor", "EOSExt.SecuritySensor", "1.1.7")]
public class EntryPoint : BasePlugin
{
public const string AUTHOR = "Inas";
public const string PLUGIN_NAME = "EOSExt.SecuritySensor";
public const string VERSION = "1.1.7";
private Harmony m_Harmony;
public override void Load()
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
SetupManagers();
AssetAPI.OnAssetBundlesLoaded += Assets.Init;
m_Harmony = new Harmony("EOSExt.SecuritySensor");
m_Harmony.PatchAll();
ClassInjector.RegisterTypeInIl2Cpp<SensorCollider>();
EOSLogger.Log("ExtraObjectiveSetup.SecuritySensor loaded.");
}
private void SetupManagers()
{
((GenericExpeditionDefinitionManager<SensorGroupSettings>)SecuritySensorManager.Current).Init();
}
}
public class MovableSensor
{
public GameObject movableGO { get; private set; }
public CP_BasicMovable movingComp { get; private set; }
private GameObject graphicsGO
{
get
{
GameObject obj = movableGO;
if (obj == null)
{
return null;
}
return ((Component)obj.transform.GetChild(0)).gameObject;
}
}
public static MovableSensor Instantiate(SensorSettings sensorSetting)
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: 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)
//IL_008c: 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_00d4: 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_00de: Unknown result type (might be due to invalid IL or missing references)
if (sensorSetting.MovingPosition.Count < 1)
{
EOSLogger.Error("SensorGroup.Instantiate: At least 1 moving position required to setup T-Sensor!");
return null;
}
if (EOSNetworking.AllotReplicatorID() == 0)
{
EOSLogger.Error("SensorGroup.Instantiate: replicator ID depleted, cannot create StateReplicator...");
return null;
}
MovableSensor movableSensor = new MovableSensor();
movableSensor.movableGO = Object.Instantiate<GameObject>(Assets.MovableSensor);
movableSensor.movingComp = movableSensor.movableGO.GetComponent<CP_BasicMovable>();
movableSensor.movingComp.Setup();
Vector3 element = sensorSetting.Position.ToVector3();
Vector3 val = sensorSetting.MovingPosition.First().ToVector3();
Vector3 val2 = sensorSetting.MovingPosition.Last().ToVector3();
IEnumerable<Vector3> source = sensorSetting.MovingPosition.ConvertAll((Vec3 e) => e.ToVector3()).AsEnumerable();
if (!((Vector3)(ref element)).Equals(val))
{
source = source.Prepend(element);
}
if (!((Vector3)(ref element)).Equals(val2))
{
source = source.Append(element);
}
movableSensor.movingComp.ScanPositions = ListExtensions.ToIl2Cpp<Vector3>(source.ToList());
movableSensor.movingComp.m_amountOfPositions = source.Count() - 1;
if (sensorSetting.MovingSpeedMulti > 0f)
{
CP_BasicMovable obj = movableSensor.movingComp;
obj.m_movementSpeed *= sensorSetting.MovingSpeedMulti;
}
return movableSensor;
}
public void StartMoving()
{
graphicsGO.SetActive(true);
movingComp.SyncUpdate();
movingComp.StartMoving();
}
public void ResumeMoving()
{
graphicsGO.SetActive(true);
movingComp.ResumeMovement();
}
public void StopMoving()
{
movingComp.StopMoving();
graphicsGO.SetActive(false);
}
public void PauseMoving()
{
movingComp.PauseMovement();
graphicsGO.SetActive(false);
}
public void Destroy()
{
Object.Destroy((Object)(object)movableGO);
movableGO = null;
movingComp = null;
}
private MovableSensor()
{
}
}
public enum SensorEventType
{
ToggleSensorGroupState = 400
}
public sealed class SecuritySensorManager : GenericExpeditionDefinitionManager<SensorGroupSettings>
{
private List<SensorGroup> sensorGroups = new List<SensorGroup>();
private Dictionary<IntPtr, int> sensorGroupIndex = new Dictionary<IntPtr, int>();
public static SecuritySensorManager Current { get; private set; }
protected override string DEFINITION_NAME => "SecuritySensor";
public void BuildSensorGroup(SensorGroupSettings sensorGroupSettings)
{
int count = sensorGroups.Count;
SensorGroup sensorGroup = SensorGroup.Instantiate(sensorGroupSettings, count);
sensorGroups.Add(sensorGroup);
foreach (GameObject basicSensor in sensorGroup.BasicSensors)
{
sensorGroupIndex[((Il2CppObjectBase)basicSensor).Pointer] = count;
}
foreach (MovableSensor movableSensor in sensorGroup.MovableSensors)
{
sensorGroupIndex[((Il2CppObjectBase)movableSensor.movableGO).Pointer] = count;
}
EOSLogger.Debug($"SensorGroup_{count} built");
}
internal void SensorTriggered(IntPtr pointer)
{
if (!sensorGroupIndex.ContainsKey(pointer))
{
EOSLogger.Error("Triggering a sensor but doesn't find its corresponding sensor group! This should not happen!");
return;
}
int num = sensorGroupIndex[pointer];
if (num < 0 || num >= sensorGroups.Count)
{
EOSLogger.Error($"TriggerSensor: invalid SensorGroup index {num}");
return;
}
sensorGroups[num].Settings.EventsOnTrigger.ForEach(delegate(WardenObjectiveEventData e)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
WardenObjectiveManager.CheckAndExecuteEventsOnTrigger(e, e.Trigger, true, 0f);
});
EOSLogger.Warning($"TriggerSensor: SensorGroup_{num} triggered");
}
private void BuildSecuritySensor()
{
if (base.definitions.ContainsKey(RundownManager.ActiveExpedition.LevelLayoutData))
{
base.definitions[RundownManager.ActiveExpedition.LevelLayoutData].Definitions.ForEach(BuildSensorGroup);
}
}
private void Clear()
{
sensorGroups.ForEach(delegate(SensorGroup sg)
{
sg.Destroy();
});
sensorGroups.Clear();
sensorGroupIndex.Clear();
}
private void ToggleSensorGroup(WardenObjectiveEventData e)
{
int count = e.Count;
bool enabled = e.Enabled;
if (count < 0 || count >= sensorGroups.Count)
{
EOSLogger.Error($"ToggleSensorGroup: invalid SensorGroup index {count}");
}
else
{
sensorGroups[count].ChangeToState(enabled ? ActiveState.ENABLED : ActiveState.DISABLED);
}
}
private SecuritySensorManager()
{
LevelAPI.OnBuildStart += delegate
{
Clear();
BuildSecuritySensor();
};
LevelAPI.OnLevelCleanup += Clear;
EventAPI.OnExpeditionStarted += delegate
{
sensorGroups.ForEach(delegate(SensorGroup sg)
{
sg.StartMovingMovables();
});
};
EOSWardenEventManager.Current.AddEventDefinition(SensorEventType.ToggleSensorGroupState.ToString(), 400u, (Action<WardenObjectiveEventData>)ToggleSensorGroup);
}
static SecuritySensorManager()
{
Current = new SecuritySensorManager();
}
}
public class SensorGroup
{
private List<GameObject> basicSensors = new List<GameObject>();
private List<MovableSensor> movableSensors = new List<MovableSensor>();
public int SensorGroupIndex { get; private set; }
public SensorGroupSettings Settings { get; private set; }
public StateReplicator<SensorGroupState> StateReplicator { get; private set; }
public IEnumerable<GameObject> BasicSensors => basicSensors;
public IEnumerable<MovableSensor> MovableSensors => movableSensors;
public ActiveState State => StateReplicator?.State.status ?? ActiveState.ENABLED;
public void ChangeToState(ActiveState status)
{
ChangeToStateUnsynced(new SensorGroupState
{
status = status
});
EOSLogger.Debug($"ChangeState: SecuritySensorGroup_{SensorGroupIndex} changed to state {status}");
if (SNet.IsMaster)
{
StateReplicator?.SetState(new SensorGroupState
{
status = status
});
}
}
private void OnStateChanged(SensorGroupState oldState, SensorGroupState newState, bool isRecall)
{
EOSLogger.Warning($"OnStateChanged: isRecall ? {isRecall}");
if (isRecall)
{
EOSLogger.Debug($"Recalling: SecuritySensorGroup_{SensorGroupIndex} changed to state {newState.status}");
ChangeToStateUnsynced(newState);
}
else if (oldState.status != newState.status)
{
ChangeToStateUnsynced(newState);
}
}
private void ChangeToStateUnsynced(SensorGroupState newState)
{
switch (newState.status)
{
case ActiveState.ENABLED:
basicSensors.ForEach(delegate(GameObject sensorGO)
{
sensorGO.SetActive(true);
});
ResumeMovingMovables();
break;
case ActiveState.DISABLED:
PauseMovingMovables();
basicSensors.ForEach(delegate(GameObject sensorGO)
{
sensorGO.SetActive(false);
});
break;
}
}
public static SensorGroup Instantiate(SensorGroupSettings sensorGroupSettings, int sensorGroupIndex)
{
//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_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: 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_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
SensorGroup sensorGroup = new SensorGroup();
sensorGroup.SensorGroupIndex = sensorGroupIndex;
sensorGroup.Settings = sensorGroupSettings;
foreach (SensorSettings item in sensorGroupSettings.SensorGroup)
{
Vector3 val = item.Position.ToVector3();
if (val == Vector3.zeroVector)
{
continue;
}
GameObject val2 = null;
switch (item.SensorType)
{
case SensorType.BASIC:
val2 = Object.Instantiate<GameObject>(Assets.CircleSensor);
sensorGroup.basicSensors.Add(val2);
break;
case SensorType.MOVABLE:
{
MovableSensor movableSensor = MovableSensor.Instantiate(item);
if (movableSensor == null)
{
EOSLogger.Error("ERROR: failed to build movable sensor");
continue;
}
val2 = movableSensor.movableGO;
sensorGroup.movableSensors.Add(movableSensor);
break;
}
default:
EOSLogger.Error($"Unsupported SensorType {item.SensorType}, skipped");
continue;
}
val2.transform.SetPositionAndRotation(val, Quaternion.identityQuaternion);
float num = 0.16216217f;
val2.transform.localScale = new Vector3(item.Radius, item.Radius, item.Radius);
Transform transform = val2.transform;
transform.localPosition += Vector3.up * num;
val2.AddComponent<SensorCollider>().Setup(item, sensorGroup);
((Component)val2.transform.GetChild(0).GetChild(1)).gameObject.GetComponentInChildren<Renderer>().material.SetColor("_ColorA", item.Color.ToUnityColor());
Transform child = val2.transform.GetChild(0).GetChild(2);
GameObject gameObject = ((Component)child.GetChild(0)).gameObject;
gameObject.transform.SetParent((Transform)null);
Object.Destroy((Object)(object)gameObject);
TextMeshPro component = VanillaTMPPros.Instantiate(((Component)child).gameObject).GetComponent<TextMeshPro>();
if ((Object)(object)component != (Object)null)
{
((TMP_Text)component).SetText(LocalizedText.op_Implicit(item.Text), true);
Color32 val4 = (((TMP_Text)component).m_fontColor32 = Color32.op_Implicit(item.TextColor.ToUnityColor()));
((TMP_Text)component).m_fontColor = Color32.op_Implicit(val4);
}
else
{
EOSLogger.Error("NO TEXT!");
}
val2.SetActive(true);
}
uint num2 = EOSNetworking.AllotReplicatorID();
if (num2 == 0)
{
EOSLogger.Error("SensorGroup.Instantiate: replicator ID depleted, cannot create StateReplicator...");
}
else
{
sensorGroup.StateReplicator = StateReplicator<SensorGroupState>.Create(num2, new SensorGroupState
{
status = ActiveState.ENABLED
}, (LifeTimeType)1, (IStateReplicatorHolder<SensorGroupState>)null);
sensorGroup.StateReplicator.OnStateChanged += sensorGroup.OnStateChanged;
}
return sensorGroup;
}
public void StartMovingMovables()
{
movableSensors.ForEach(delegate(MovableSensor movable)
{
movable.StartMoving();
});
}
public void PauseMovingMovables()
{
movableSensors.ForEach(delegate(MovableSensor movable)
{
movable.PauseMoving();
});
}
public void ResumeMovingMovables()
{
movableSensors.ForEach(delegate(MovableSensor movable)
{
movable.ResumeMoving();
});
}
public void Destroy()
{
basicSensors.ForEach((Action<GameObject>)Object.Destroy);
basicSensors.Clear();
movableSensors.ForEach(delegate(MovableSensor m)
{
m.Destroy();
});
movableSensors.Clear();
StateReplicator = null;
Settings = null;
}
private SensorGroup()
{
}
}
public enum ActiveState
{
DISABLED,
ENABLED
}
public struct SensorGroupState
{
public ActiveState status;
public SensorGroupState()
{
status = ActiveState.DISABLED;
}
public SensorGroupState(SensorGroupState o)
{
status = o.status;
}
public SensorGroupState(ActiveState status)
{
this.status = status;
}
}
public struct MovableSensorLerp
{
public float lerp;
public MovableSensorLerp()
{
lerp = 0f;
}
public MovableSensorLerp(MovableSensorLerp o)
{
lerp = o.lerp;
}
public MovableSensorLerp(float lerp)
{
this.lerp = lerp;
}
}
}
namespace EOSExt.SecuritySensor.Component
{
public class SensorCollider : MonoBehaviour
{
private float nextCheckTime = float.NaN;
private SensorSettings settings;
private int last_playersInSensor;
public static float CHECK_INTERVAL { get; } = 0.1f;
private Vector3 Position => ((Component)this).gameObject.transform.position;
public SensorGroup Parent { get; internal set; }
internal void Setup(SensorSettings sensorSettings, SensorGroup parent)
{
settings = sensorSettings;
Parent = parent;
}
private void Update()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
if ((int)GameStateManager.CurrentStateName != 10 || (!float.IsNaN(nextCheckTime) && Clock.Time < nextCheckTime))
{
return;
}
nextCheckTime = Clock.Time + CHECK_INTERVAL;
if (Parent.State != ActiveState.ENABLED)
{
return;
}
int num = 0;
Enumerator<PlayerAgent> enumerator = PlayerManager.PlayerAgentsInLevel.GetEnumerator();
while (enumerator.MoveNext())
{
PlayerAgent current = enumerator.Current;
if (!current.Owner.IsBot && ((Agent)current).Alive)
{
Vector3 val = Position - ((Agent)current).Position;
if (((Vector3)(ref val)).magnitude < settings.Radius)
{
num++;
}
}
}
if (num > last_playersInSensor)
{
SecuritySensorManager.Current.SensorTriggered(((Il2CppObjectBase)((Component)this).gameObject).Pointer);
}
last_playersInSensor = num;
}
private void OnDestroy()
{
Parent = null;
settings = null;
}
}
}
namespace EOSExt.SecuritySensor.Patches
{
[HarmonyPatch]
internal class Debug
{
[HarmonyPostfix]
[HarmonyPatch(typeof(LG_CollisionWorldEventTrigger), "Update")]
private static void Post(LG_CollisionWorldEventTrigger __instance)
{
}
static Debug()
{
}
}
}
namespace EOSExt.SecuritySensor.Definition
{
public class SensorGroupSettings
{
public List<SensorSettings> SensorGroup { get; set; } = new List<SensorSettings>
{
new SensorSettings()
};
public List<WardenObjectiveEventData> EventsOnTrigger { get; set; } = new List<WardenObjectiveEventData>();
}
public enum SensorType
{
BASIC,
MOVABLE
}
public class SensorSettings
{
public Vec3 Position { get; set; } = new Vec3();
public float Radius { get; set; } = 2.3f;
public EOSColor Color { get; set; } = new EOSColor
{
r = 99f / 106f,
g = 0.1055641f,
b = 0f,
a = 0.2627451f
};
public LocalizedText Text { get; set; } = new LocalizedText
{
Id = 0u,
UntranslatedText = "S:_EC/uR_ITY S:/Ca_N"
};
public EOSColor TextColor { get; set; } = new EOSColor
{
r = 0.8862745f,
g = 46f / 51f,
b = 0.8980392f,
a = 0.70980394f
};
public SensorType SensorType { get; set; }
public float MovingSpeedMulti { get; set; } = 1f;
public List<Vec3> MovingPosition { get; set; } = new List<Vec3>
{
new Vec3()
};
}
}