using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using REPO_Active.Debug;
using REPO_Active.Reflection;
using REPO_Active.Runtime;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("REPO_Active")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("4.0.2.0")]
[assembly: AssemblyInformationalVersion("4.0.2+ce2f605c02b6f6fb24ff765318ce60b729d328b9")]
[assembly: AssemblyProduct("REPO_Active")]
[assembly: AssemblyTitle("REPO_Active")]
[assembly: AssemblyVersion("4.0.2.0")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace REPO_Active
{
[BepInPlugin("angelcomilk.repo_active", "REPO_Active", "4.6.3")]
public sealed class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "angelcomilk.repo_active";
public const string PluginName = "REPO_Active";
public const string PluginVersion = "4.6.3";
private ConfigEntry<bool> _autoActivate;
private ConfigEntry<KeyCode> _keyActivateNearest;
private ConfigEntry<bool> _discoverAllPoints;
private ConfigEntry<bool> _enableDebugLog;
private ExtractionPointScanner _scanner;
private ExtractionPointInvoker _invoker;
private ModLogger? _dbg;
private float _autoTimer;
private float _discoverTimer;
private float _autoReadyTime = -1f;
private float _discoverReadyTime = -1f;
private bool _autoPrimed;
private bool _logReady;
private readonly HashSet<int> _deferredMarking = new HashSet<int>();
private readonly List<Component> _playerCache = new List<Component>();
private readonly List<Vector3> _playerLastPos = new List<Vector3>();
private int _playerCacheHash;
private int _playerListEmptyStreak;
private int _lastPlayerCount = -1;
private float _lastBaseInterval = 0.5f;
private bool _lastAnyMoved;
private int _lastHostPosCount = -1;
private string _lastDiscoverReason = "";
private int _lastDiscoverAll = -1;
private int _lastDiscoverCount = -1;
private int _lastAutoBufferBucket = int.MinValue;
private int _lastDiscoverBufferBucket = int.MinValue;
private string _lastBusyInfo = "";
private int _lastBusyCount = -1;
private float _lastBusyLogTime = -1f;
private const float RESCAN_COOLDOWN = 0.6f;
private const bool SKIP_ACTIVATED = true;
private const float AUTO_INTERVAL = 5f;
private const float DISCOVER_INTERVAL_BASE = 0.5f;
private const float DISCOVER_INTERVAL_4_6 = 1f;
private const float DISCOVER_INTERVAL_7_9 = 1.5f;
private const float DISCOVER_INTERVAL_10_12 = 2f;
private const float DISCOVER_INTERVAL_MAX = 3f;
private const float DISCOVER_RADIUS = 20f;
private const float AUTO_READY_BUFFER = 30f;
private const float PLAYER_MOVE_THRESHOLD = 1f;
private void Awake()
{
_autoActivate = ((BaseUnityPlugin)this).Config.Bind<bool>("Auto", "AutoActivate", false, "Auto activate when idle.");
_keyActivateNearest = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "ActivateNearest", (KeyCode)284, "Press to activate next extraction point (uses OnClick via reflection).");
_discoverAllPoints = ((BaseUnityPlugin)this).Config.Bind<bool>("Discovery", "DiscoverAllPoints", false, "If true, treat all extraction points as discovered.");
_enableDebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableDebugLog", false, "Enable detailed mod logs in BepInEx\\config\\REPO_Active\\logs.");
_invoker = new ExtractionPointInvoker(((BaseUnityPlugin)this).Logger);
_scanner = new ExtractionPointScanner(((BaseUnityPlugin)this).Logger, 0.6f);
_dbg = new ModLogger(((BaseUnityPlugin)this).Logger, _enableDebugLog.Value);
_scanner.DebugLog = _dbg.Log;
SceneManager.sceneLoaded += OnSceneLoaded;
((BaseUnityPlugin)this).Logger.LogInfo((object)"REPO_Active 4.6.3 loaded. (OnClick reflection activation)");
_dbg.Log(string.Format("[INIT] {0} {1} Auto={2} DiscoverAll={3}", "REPO_Active", "4.6.3", _autoActivate.Value, _discoverAllPoints.Value));
}
private void OnDestroy()
{
try
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
catch
{
}
}
private void Update()
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: 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)
if (_dbg != null)
{
_dbg.Enabled = _enableDebugLog.Value;
}
_scanner.LogReady = _logReady;
if (Input.GetKeyDown(_keyActivateNearest.Value))
{
_dbg?.Log("[INPUT] F3 pressed");
ActivateNearest();
}
_discoverTimer += Time.deltaTime;
float discoveryInterval = GetDiscoveryInterval();
if (_discoverTimer >= discoveryInterval)
{
_discoverTimer = 0f;
DiscoveryTick();
}
if (!_autoActivate.Value)
{
return;
}
if (_autoReadyTime < 0f)
{
if (_scanner.EnsureReady())
{
List<Component> list = _scanner.ScanAndGetAllPoints();
Vector3 referencePos = _scanner.GetReferencePos();
if (list.Count > 0 && referencePos != Vector3.zero)
{
_scanner.CaptureSpawnPosIfNeeded(referencePos);
_autoReadyTime = Time.realtimeSinceStartup;
_autoTimer = 0f;
_dbg?.Log($"[AUTO] primed count={list.Count} refPos={referencePos}");
}
}
return;
}
if (Time.realtimeSinceStartup - _autoReadyTime >= 30f)
{
_lastAutoBufferBucket = int.MinValue;
if (!_autoPrimed)
{
PrimeFirstPointIfAlreadyActivated();
_autoPrimed = true;
_dbg?.Log("[AUTO] primed-first");
}
_autoTimer += Time.deltaTime;
if (_autoTimer >= 5f)
{
_autoTimer = 0f;
_dbg?.Log("[AUTO] tick");
AutoActivateIfIdle();
}
return;
}
float num = 30f - (Time.realtimeSinceStartup - _autoReadyTime);
if (num > 0f)
{
int num2 = (int)(num / 5f);
if (num2 != _lastAutoBufferBucket)
{
_lastAutoBufferBucket = num2;
_dbg?.Log($"[AUTO] buffer wait {num:0.0}s");
}
}
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
_autoReadyTime = -1f;
_discoverReadyTime = Time.realtimeSinceStartup;
_autoPrimed = false;
_autoTimer = 0f;
_discoverTimer = 0f;
_scanner.ResetForNewRound();
_logReady = false;
_lastPlayerCount = -1;
_lastBaseInterval = 0.5f;
_dbg?.Log("[SCENE] new scene loaded, reset timers");
}
private void DiscoveryTick()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_0269: Unknown result type (might be due to invalid IL or missing references)
//IL_026e: Unknown result type (might be due to invalid IL or missing references)
//IL_0277: Unknown result type (might be due to invalid IL or missing references)
//IL_0279: Unknown result type (might be due to invalid IL or missing references)
//IL_0285: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
if (!_scanner.EnsureReady())
{
return;
}
List<Component> list = _scanner.ScanAndGetAllPoints();
Vector3 referencePos = _scanner.GetReferencePos();
_scanner.CaptureSpawnPosIfNeeded(referencePos);
if (!_logReady && list.Count > 0)
{
_logReady = true;
_scanner.LogReady = true;
_dbg?.Log("[LOG] ready: ExtractionPoint detected");
}
if (list.Count == 0)
{
if (_logReady)
{
LogDiscoverState("skip: no EP", 0, 0);
}
return;
}
if (_discoverAllPoints.Value)
{
_scanner.MarkAllDiscovered(list);
return;
}
if (_discoverReadyTime < 0f)
{
_discoverReadyTime = Time.realtimeSinceStartup;
}
if (Time.realtimeSinceStartup - _discoverReadyTime < 30f)
{
int num = (int)((30f - (Time.realtimeSinceStartup - _discoverReadyTime)) / 5f);
if (num != _lastDiscoverBufferBucket)
{
_lastDiscoverBufferBucket = num;
LogDiscoverState("buffer wait", list.Count, _scanner.DiscoveredCount);
}
return;
}
_lastDiscoverBufferBucket = int.MinValue;
if (_scanner.DiscoveredCount >= list.Count)
{
LogDiscoverState("skip: all discovered", list.Count, _scanner.DiscoveredCount);
return;
}
bool anyMoved;
List<Vector3> list2 = TryGetAllPlayerPositionsHost(out anyMoved);
_lastAnyMoved = anyMoved;
if (list2.Count == 0)
{
_playerListEmptyStreak++;
LogDiscoverState("skip: PlayerList not ready", list.Count, _scanner.DiscoveredCount);
return;
}
_playerListEmptyStreak = 0;
if (!anyMoved)
{
LogDiscoverState("skip: no movement", list.Count, _scanner.DiscoveredCount);
return;
}
Vector3 spawnPos = _scanner.GetSpawnPos();
for (int i = 0; i < list2.Count; i++)
{
List<Component> list3 = new List<Component>();
int num2 = _scanner.UpdateDiscoveredDetailed(list2[i], 20f, list3);
if (num2 <= 0 || _dbg == null)
{
continue;
}
_dbg.Log($"[DISCOVER] by player#{i} pos={list2[i]} +{num2}");
for (int j = 0; j < list3.Count; j++)
{
Component val = list3[j];
if (Object.op_Implicit((Object)(object)val))
{
Vector3 position = val.transform.position;
float num3 = Vector3.Distance(list2[i], position);
string text = ((spawnPos == Vector3.zero) ? "na" : Vector3.Distance(spawnPos, position).ToString("0.00"));
_dbg.Log($"[DISCOVER+] ep={((Object)val.gameObject).name} epPos={position} distToPlayer={num3:0.00} distToSpawn={text}");
}
}
}
if (list2.Count != _lastHostPosCount)
{
_lastHostPosCount = list2.Count;
_dbg?.Log($"[DISCOVER] hostPos count={list2.Count}");
}
LogDiscoverState("update: positions", list.Count, _scanner.DiscoveredCount);
}
private void AutoActivateIfIdle()
{
if (!_scanner.EnsureReady())
{
_dbg?.Log("[AUTO] EnsureReady=false");
}
else
{
ActivateNearest();
}
}
private void ActivateNearest()
{
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: 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_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_023d: Unknown result type (might be due to invalid IL or missing references)
//IL_0245: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0268: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0309: Unknown result type (might be due to invalid IL or missing references)
//IL_0311: Unknown result type (might be due to invalid IL or missing references)
if (!_scanner.EnsureReady())
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"ExtractionPoint type not found yet.");
_dbg?.Log("[F3] EnsureReady=false");
return;
}
List<Component> list = _scanner.ScanAndGetAllPoints();
_dbg?.Log($"[F3] allPoints={list.Count}");
if (_scanner.TryGetActivatingInfo(list, out string info, out int busyCount))
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"有提取点正在激活中,F3 忽略");
if (_dbg != null)
{
float realtimeSinceStartup = Time.realtimeSinceStartup;
if (info != _lastBusyInfo || busyCount != _lastBusyCount || realtimeSinceStartup - _lastBusyLogTime > 2f)
{
_lastBusyInfo = info;
_lastBusyCount = busyCount;
_lastBusyLogTime = realtimeSinceStartup;
_dbg.Log($"[F3] blocked: activating busy={busyCount} {info}");
}
}
return;
}
Vector3 referencePos = _scanner.GetReferencePos();
_scanner.CaptureSpawnPosIfNeeded(referencePos);
Vector3 spawnPos = _scanner.GetSpawnPos();
_dbg?.Log($"[F3] startPos={referencePos} spawnPos={spawnPos}");
if (_discoverAllPoints.Value)
{
_scanner.MarkAllDiscovered(list);
}
else
{
UpdateDiscoveredFromCachedPlayers(referencePos);
}
List<Component> list2 = (List<Component>)(_discoverAllPoints.Value ? ((IList)list) : ((IList)_scanner.FilterDiscovered(list)));
_dbg?.Log($"[F3] eligible={list2.Count} discoverAll={_discoverAllPoints.Value}");
List<Component> list3 = _scanner.BuildStage1PlannedList(list2, spawnPos, referencePos, skipActivated: true);
if (list3.Count == 0)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"没有可激活的提取点(可能都已激活或未发现)");
_dbg?.Log("[F3] plan empty");
return;
}
Component val = list3[0];
string text = _scanner.ReadStateName(val);
_dbg?.Log("[F3] next=" + ((Object)val.gameObject).name + " state=" + text);
float num = Vector3.Distance(referencePos, val.transform.position);
string text2 = ((spawnPos == Vector3.zero) ? "na" : Vector3.Distance(spawnPos, val.transform.position).ToString("0.00"));
_dbg?.Log($"[ACTIVATE] ep={((Object)val.gameObject).name} epPos={val.transform.position} distToPlayer={num:0.00} distToSpawn={text2} state={text}");
((BaseUnityPlugin)this).Logger.LogInfo((object)$"[F3] Activate planned EP: {((Object)val.gameObject).name} pos={val.transform.position} dist={Vector3.Distance(referencePos, val.transform.position):0.00}");
bool flag = _invoker.InvokeOnClick(val);
_dbg?.Log($"[F3] invoke={flag} next={((Object)val.gameObject).name}");
if (flag)
{
string text3 = _scanner.ReadStateName(val);
if (!string.IsNullOrEmpty(text3) && !ExtractionPointScanner.IsIdleLikeState(text3) && !ExtractionPointScanner.IsCompletedLikeState(text3))
{
_scanner.MarkActivated(val);
_dbg?.Log("[F3] marked activated: " + ((Object)val.gameObject).name + " state=" + text3);
}
else
{
_dbg?.Log("[F3] NOT marked (state not active): " + ((Object)val.gameObject).name + " state=" + text3);
TryDeferredMarkActivated(val);
}
}
}
private void TryDeferredMarkActivated(Component ep)
{
if (!((Object)(object)ep == (Object)null))
{
int instanceID = ((Object)ep).GetInstanceID();
if (!_deferredMarking.Add(instanceID))
{
_dbg?.Log("[F3] deferred already pending: " + ((Object)ep.gameObject).name);
}
else
{
((MonoBehaviour)this).StartCoroutine(DeferredMarkActivated(ep, instanceID));
}
}
}
private IEnumerator DeferredMarkActivated(Component ep, int id)
{
try
{
if ((Object)(object)ep == (Object)null)
{
yield break;
}
float[] waits = new float[5] { 0.15f, 0.25f, 0.35f, 0.35f, 0.4f };
string lastState = "";
for (int i = 0; i < waits.Length; i++)
{
if (waits[i] > 0f)
{
yield return (object)new WaitForSeconds(waits[i]);
}
if ((Object)(object)ep == (Object)null)
{
yield break;
}
string text = _scanner.ReadStateName(ep);
lastState = text;
if (!string.IsNullOrEmpty(text) && !ExtractionPointScanner.IsIdleLikeState(text) && !ExtractionPointScanner.IsCompletedLikeState(text))
{
_scanner.MarkActivated(ep);
_dbg?.Log("[F3] deferred marked activated: " + ((Object)ep.gameObject).name + " state=" + text);
yield break;
}
if (i == 0)
{
yield return null;
if ((Object)(object)ep == (Object)null)
{
yield break;
}
string text2 = _scanner.ReadStateName(ep);
lastState = (string.IsNullOrEmpty(text2) ? lastState : text2);
if (!string.IsNullOrEmpty(text2) && !ExtractionPointScanner.IsIdleLikeState(text2) && !ExtractionPointScanner.IsCompletedLikeState(text2))
{
_scanner.MarkActivated(ep);
_dbg?.Log("[F3] deferred marked activated: " + ((Object)ep.gameObject).name + " state=" + text2);
yield break;
}
}
}
_dbg?.Log("[F3] deferred NOT marked: " + ((Object)ep.gameObject).name + " state=" + lastState);
}
finally
{
_deferredMarking.Remove(id);
}
}
private void PrimeFirstPointIfAlreadyActivated()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
List<Component> list = _scanner.ScanAndGetAllPoints();
if (list.Count == 0)
{
return;
}
Vector3 referencePos = _scanner.GetReferencePos();
_scanner.CaptureSpawnPosIfNeeded(referencePos);
if (_discoverAllPoints.Value)
{
_scanner.MarkAllDiscovered(list);
}
else
{
_scanner.UpdateDiscovered(referencePos, 20f);
}
List<Component> allPoints = (List<Component>)(_discoverAllPoints.Value ? ((IList)list) : ((IList)_scanner.FilterDiscovered(list)));
List<Component> list2 = _scanner.BuildStage1PlannedList(allPoints, _scanner.GetSpawnPos(), referencePos, skipActivated: true);
if (list2.Count != 0)
{
Component ep = list2[0];
string text = _scanner.ReadStateName(ep);
if (!string.IsNullOrEmpty(text) && !ExtractionPointScanner.IsIdleLikeState(text))
{
_scanner.MarkActivated(ep);
}
}
}
private List<Vector3> TryGetAllPlayerPositionsHost(out bool anyMoved)
{
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_030e: Unknown result type (might be due to invalid IL or missing references)
//IL_0313: Unknown result type (might be due to invalid IL or missing references)
//IL_0316: Unknown result type (might be due to invalid IL or missing references)
//IL_0350: Unknown result type (might be due to invalid IL or missing references)
//IL_0329: Unknown result type (might be due to invalid IL or missing references)
//IL_032e: Unknown result type (might be due to invalid IL or missing references)
//IL_0330: Unknown result type (might be due to invalid IL or missing references)
//IL_0335: Unknown result type (might be due to invalid IL or missing references)
anyMoved = false;
List<Vector3> list = new List<Vector3>();
try
{
Type type = Type.GetType("Photon.Pun.PhotonNetwork, PhotonUnityNetworking");
if (type == null)
{
return list;
}
PropertyInfo property = type.GetProperty("InRoom");
PropertyInfo property2 = type.GetProperty("IsMasterClient");
bool flag = default(bool);
int num;
if (property != null)
{
object value = property.GetValue(null);
if (value is bool)
{
flag = (bool)value;
num = 1;
}
else
{
num = 0;
}
}
else
{
num = 0;
}
int num2 = num & (flag ? 1 : 0);
bool flag2 = default(bool);
int num3;
if (property2 != null)
{
object value = property2.GetValue(null);
if (value is bool)
{
flag2 = (bool)value;
num3 = 1;
}
else
{
num3 = 0;
}
}
else
{
num3 = 0;
}
bool flag3 = (byte)((uint)num3 & (flag2 ? 1u : 0u)) != 0;
if (num2 == 0 || !flag3)
{
return list;
}
Type type2 = Type.GetType("GameDirector, Assembly-CSharp");
if (type2 == null)
{
return list;
}
object obj = null;
PropertyInfo property3 = type2.GetProperty("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (property3 != null)
{
obj = property3.GetValue(null, null);
}
if (obj == null)
{
FieldInfo field = type2.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
obj = field.GetValue(null);
}
}
if (obj == null)
{
return list;
}
object obj2 = null;
PropertyInfo property4 = type2.GetProperty("PlayerList", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (property4 != null)
{
obj2 = property4.GetValue(obj, null);
}
if (obj2 == null)
{
FieldInfo field2 = type2.GetField("PlayerList", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field2 != null)
{
obj2 = field2.GetValue(obj);
}
}
if (obj2 == null)
{
return list;
}
if (!(obj2 is IEnumerable enumerable))
{
return list;
}
List<Component> list2 = new List<Component>();
int num4 = 17;
foreach (object item in enumerable)
{
if (item != null)
{
Component val = ExtractPlayerComponent(item);
if (!((Object)(object)val == (Object)null) && !((Object)(object)val.transform == (Object)null))
{
list2.Add(val);
num4 = num4 * 31 + ((Object)val).GetInstanceID();
}
}
}
if (list2.Count == 0)
{
return list;
}
if (num4 != _playerCacheHash || _playerCache.Count != list2.Count)
{
_playerCacheHash = num4;
_playerCache.Clear();
_playerCache.AddRange(list2);
_playerLastPos.Clear();
for (int i = 0; i < _playerCache.Count; i++)
{
_playerLastPos.Add(_playerCache[i].transform.position);
}
anyMoved = true;
}
for (int j = 0; j < _playerCache.Count; j++)
{
Component val2 = _playerCache[j];
if ((Object)(object)val2 == (Object)null || (Object)(object)val2.transform == (Object)null)
{
_playerCache.Clear();
_playerLastPos.Clear();
_playerCacheHash = 0;
return list;
}
Vector3 position = val2.transform.position;
list.Add(position);
if (!anyMoved)
{
Vector3 val3 = _playerLastPos[j] - position;
if (((Vector3)(ref val3)).sqrMagnitude >= 1f)
{
anyMoved = true;
}
}
_playerLastPos[j] = position;
}
return list;
}
catch
{
return list;
}
}
private Component? ExtractPlayerComponent(object p)
{
Component val = (Component)((p is Component) ? p : null);
if (val != null && (Object)(object)val.transform != (Object)null)
{
return val;
}
Type type = p.GetType();
object obj = null;
PropertyInfo property = type.GetProperty("PlayerAvatar", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (property != null)
{
obj = property.GetValue(p, null);
}
if (obj == null)
{
FieldInfo field = type.GetField("PlayerAvatar", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
obj = field.GetValue(p);
}
}
if (obj == null)
{
return null;
}
Component val2 = (Component)((obj is Component) ? obj : null);
if (val2 != null && (Object)(object)val2.transform != (Object)null)
{
return val2;
}
PropertyInfo property2 = obj.GetType().GetProperty("transform", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (!(property2 != null))
{
return null;
}
object? value = property2.GetValue(obj, null);
return (Component?)((value is Transform) ? value : null);
}
private int GetCachedPlayerCount()
{
if (_playerCache.Count > 0)
{
return _playerCache.Count;
}
return GetPlayerCountHost();
}
private void UpdateDiscoveredFromCachedPlayers(Vector3 fallbackPos)
{
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: 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_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_0242: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: 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_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
if (_playerCache.Count > 0 && _playerLastPos.Count == _playerCache.Count)
{
if (!_lastAnyMoved)
{
_dbg?.Log("[F3] skip discover: no movement");
return;
}
Vector3 spawnPos = _scanner.GetSpawnPos();
for (int i = 0; i < _playerLastPos.Count; i++)
{
List<Component> list = new List<Component>();
int num = _scanner.UpdateDiscoveredDetailed(_playerLastPos[i], 20f, list);
if (num <= 0 || _dbg == null)
{
continue;
}
_dbg.Log($"[DISCOVER] by player#{i} pos={_playerLastPos[i]} +{num}");
for (int j = 0; j < list.Count; j++)
{
Component val = list[j];
if (Object.op_Implicit((Object)(object)val))
{
Vector3 position = val.transform.position;
float num2 = Vector3.Distance(_playerLastPos[i], position);
string text = ((spawnPos == Vector3.zero) ? "na" : Vector3.Distance(spawnPos, position).ToString("0.00"));
_dbg.Log($"[DISCOVER+] ep={((Object)val.gameObject).name} epPos={position} distToPlayer={num2:0.00} distToSpawn={text}");
}
}
}
return;
}
List<Component> list2 = new List<Component>();
int num3 = _scanner.UpdateDiscoveredDetailed(fallbackPos, 20f, list2);
if (num3 <= 0 || _dbg == null)
{
return;
}
Vector3 spawnPos2 = _scanner.GetSpawnPos();
_dbg.Log($"[DISCOVER] by local pos={fallbackPos} +{num3}");
for (int k = 0; k < list2.Count; k++)
{
Component val2 = list2[k];
if (Object.op_Implicit((Object)(object)val2))
{
Vector3 position2 = val2.transform.position;
float num4 = Vector3.Distance(fallbackPos, position2);
string text2 = ((spawnPos2 == Vector3.zero) ? "na" : Vector3.Distance(spawnPos2, position2).ToString("0.00"));
_dbg.Log($"[DISCOVER+] ep={((Object)val2.gameObject).name} epPos={position2} distToPlayer={num4:0.00} distToSpawn={text2}");
}
}
}
private float GetDiscoveryInterval()
{
if (_discoverAllPoints.Value)
{
return 0.5f;
}
int cachedPlayerCount = GetCachedPlayerCount();
if (cachedPlayerCount != _lastPlayerCount)
{
_lastPlayerCount = cachedPlayerCount;
_lastBaseInterval = ComputeDiscoveryInterval(cachedPlayerCount);
_dbg?.Log($"[DISCOVER] interval base={_lastBaseInterval:0.0}s players={cachedPlayerCount}");
}
float lastBaseInterval = _lastBaseInterval;
if (_playerListEmptyStreak <= 0)
{
return lastBaseInterval;
}
float num = 1f + (float)Math.Min(_playerListEmptyStreak, 10) * 0.2f;
float num2 = lastBaseInterval * num;
if (!(num2 > 3f))
{
return num2;
}
return 3f;
}
private void LogDiscoverState(string reason, int allCount, int discoveredCount)
{
if (_dbg != null && (reason != _lastDiscoverReason || allCount != _lastDiscoverAll || discoveredCount != _lastDiscoverCount))
{
_lastDiscoverReason = reason;
_lastDiscoverAll = allCount;
_lastDiscoverCount = discoveredCount;
_dbg.Log($"[DISCOVER] {reason} all={allCount} discovered={discoveredCount}");
}
}
private float ComputeDiscoveryInterval(int players)
{
if (players <= 3)
{
return 0.5f;
}
if (players <= 6)
{
return 1f;
}
if (players <= 9)
{
return 1.5f;
}
return 2f;
}
private int GetPlayerCountHost()
{
try
{
Type type = Type.GetType("Photon.Pun.PhotonNetwork, PhotonUnityNetworking");
if (type == null)
{
return 1;
}
PropertyInfo property = type.GetProperty("InRoom");
PropertyInfo property2 = type.GetProperty("IsMasterClient");
PropertyInfo property3 = type.GetProperty("PlayerList");
bool flag = default(bool);
int num;
if (property != null)
{
object value = property.GetValue(null);
if (value is bool)
{
flag = (bool)value;
num = 1;
}
else
{
num = 0;
}
}
else
{
num = 0;
}
int num2 = num & (flag ? 1 : 0);
bool flag2 = default(bool);
int num3;
if (property2 != null)
{
object value = property2.GetValue(null);
if (value is bool)
{
flag2 = (bool)value;
num3 = 1;
}
else
{
num3 = 0;
}
}
else
{
num3 = 0;
}
bool flag3 = (byte)((uint)num3 & (flag2 ? 1u : 0u)) != 0;
if (num2 == 0 || !flag3)
{
return 1;
}
if (property3 != null && property3.GetValue(null) is Array array && array.Length > 0)
{
return array.Length;
}
}
catch
{
}
return 1;
}
}
}
namespace REPO_Active.Runtime
{
public sealed class ExtractionPointScanner
{
private readonly ManualLogSource _log;
private Type? _epType;
private readonly List<Component> _cached = new List<Component>();
private float _lastScanRealtime;
private int _lastScanCount = -1;
private Vector3? _spawnPos;
private readonly HashSet<int> _activatedIds = new HashSet<int>();
private readonly HashSet<int> _discovered = new HashSet<int>();
private static readonly Dictionary<string, bool> _idleCache = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
private static readonly Dictionary<string, bool> _completeCache = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
public float RescanCooldown { get; set; }
public Action<string>? DebugLog { get; set; }
public bool LogReady { get; set; }
public int CachedCount => _cached.Count;
public int DiscoveredCount => _discovered.Count;
public ExtractionPointScanner(ManualLogSource log, float rescanCooldown)
{
_log = log;
RescanCooldown = rescanCooldown;
}
public bool EnsureReady()
{
if (_epType != null)
{
return true;
}
_epType = AppDomain.CurrentDomain.GetAssemblies().SelectMany(delegate(Assembly a)
{
try
{
return a.GetTypes();
}
catch
{
return Array.Empty<Type>();
}
}).FirstOrDefault((Type t) => t != null && t.Name == "ExtractionPoint");
return _epType != null;
}
public void ScanIfNeeded(bool force)
{
try
{
float realtimeSinceStartup = Time.realtimeSinceStartup;
float num = realtimeSinceStartup;
if (!force && num - _lastScanRealtime < RescanCooldown)
{
return;
}
_lastScanRealtime = num;
if (!EnsureReady())
{
return;
}
Object[] source = Object.FindObjectsOfType(_epType);
_cached.Clear();
_cached.AddRange(from c in source.OfType<Component>()
where (Object)(object)c != (Object)null
select c);
float num2 = Time.realtimeSinceStartup - realtimeSinceStartup;
if (_lastScanCount != _cached.Count)
{
_lastScanCount = _cached.Count;
if (LogReady)
{
DebugLog?.Invoke($"[SCAN] count={_cached.Count} dt={num2:0.000}s");
}
}
}
catch (Exception ex)
{
_log.LogError((object)$"ScanIfNeeded failed: {ex}");
if (LogReady)
{
DebugLog?.Invoke("[SCAN][ERR] " + ex.GetType().Name + ": " + ex.Message);
}
}
}
public Vector3 GetReferencePos()
{
//IL_0017: 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_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
try
{
if ((Object)(object)Camera.main != (Object)null)
{
return ((Component)Camera.main).transform.position;
}
}
catch
{
}
try
{
GameObject val = GameObject.FindWithTag("Player");
if ((Object)(object)val != (Object)null)
{
return val.transform.position;
}
}
catch
{
}
return Vector3.zero;
}
public void MarkAllDiscovered(List<Component> allPoints)
{
int count = _discovered.Count;
for (int i = 0; i < allPoints.Count; i++)
{
Component val = allPoints[i];
if (Object.op_Implicit((Object)(object)val))
{
_discovered.Add(((Object)val).GetInstanceID());
}
}
int num = _discovered.Count - count;
if (num > 0 && LogReady)
{
DebugLog?.Invoke($"[DISCOVER] mark-all +{num} total={_discovered.Count}");
}
}
public void UpdateDiscovered(Vector3 refPos, float radius)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
UpdateDiscoveredDetailed(refPos, radius, null);
}
public int UpdateDiscoveredDetailed(Vector3 refPos, float radius, List<Component>? newly)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
if (_cached.Count == 0)
{
return 0;
}
int count = _discovered.Count;
for (int i = 0; i < _cached.Count; i++)
{
Component val = _cached[i];
if (!Object.op_Implicit((Object)(object)val))
{
continue;
}
int instanceID = ((Object)val).GetInstanceID();
if (!_discovered.Contains(instanceID))
{
Vector3 val2 = refPos - val.transform.position;
if (((Vector3)(ref val2)).sqrMagnitude <= radius * radius)
{
_discovered.Add(instanceID);
newly?.Add(val);
}
}
}
int num = _discovered.Count - count;
if (num > 0 && newly == null && LogReady)
{
DebugLog?.Invoke($"[DISCOVER] +{num} total={_discovered.Count} radius={radius:0.0}");
}
return num;
}
public List<Component> FilterDiscovered(List<Component> allPoints)
{
List<Component> list = new List<Component>();
for (int i = 0; i < allPoints.Count; i++)
{
Component val = allPoints[i];
if (Object.op_Implicit((Object)(object)val) && _discovered.Contains(((Object)val).GetInstanceID()))
{
list.Add(val);
}
}
return list;
}
public Vector3 GetSpawnPos()
{
//IL_0018: 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)
return (Vector3)(((??)_spawnPos) ?? Vector3.zero);
}
public void CaptureSpawnPosIfNeeded(Vector3 refPos)
{
//IL_000e: 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_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
if (!_spawnPos.HasValue && !(refPos == Vector3.zero))
{
_spawnPos = refPos;
if (LogReady)
{
DebugLog?.Invoke($"[SPAWN] pos={refPos}");
}
}
}
public List<Component> ScanAndGetAllPoints()
{
ScanIfNeeded(force: true);
return _cached.Where((Component c) => (Object)(object)c != (Object)null).ToList();
}
public void ResetForNewRound()
{
_cached.Clear();
_activatedIds.Clear();
_discovered.Clear();
_spawnPos = null;
_lastScanRealtime = 0f;
_lastScanCount = -1;
}
public void MarkActivated(Component ep)
{
if (!((Object)(object)ep == (Object)null))
{
_activatedIds.Add(((Object)ep).GetInstanceID());
}
}
private bool IsMarkedActivated(Component ep)
{
if ((Object)(object)ep == (Object)null)
{
return false;
}
return _activatedIds.Contains(((Object)ep).GetInstanceID());
}
public bool IsAnyExtractionPointActivating(List<Component> allPoints)
{
string info;
int busyCount;
return TryGetActivatingInfo(allPoints, out info, out busyCount);
}
public bool TryGetActivatingInfo(List<Component> allPoints, out string info, out int busyCount)
{
info = "";
busyCount = 0;
if (allPoints == null || allPoints.Count == 0)
{
return false;
}
for (int i = 0; i < allPoints.Count; i++)
{
Component val = allPoints[i];
if (!Object.op_Implicit((Object)(object)val))
{
continue;
}
try
{
Type type = ((object)val).GetType();
FieldInfo field = type.GetField("currentState", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
PropertyInfo property = type.GetProperty("currentState", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
object obj = null;
if (property != null)
{
obj = property.GetValue(val, null);
}
if (obj == null && field != null)
{
obj = field.GetValue(val);
}
if (obj == null)
{
continue;
}
string text = obj.ToString() ?? "";
if (text.Length != 0 && !IsIdleLikeState(text) && !IsCompletedLikeState(text))
{
busyCount++;
if (string.IsNullOrEmpty(info))
{
info = ((Object)val.gameObject).name + " state=" + text;
}
}
}
catch
{
if (busyCount == 0)
{
busyCount = 1;
}
if (string.IsNullOrEmpty(info))
{
info = "state read failed";
}
return true;
}
}
return busyCount > 0;
}
internal static bool IsIdleLikeState(string stateName)
{
if (string.IsNullOrEmpty(stateName))
{
return false;
}
if (_idleCache.TryGetValue(stateName, out var value))
{
return value;
}
bool flag = stateName.IndexOf("Idle", StringComparison.OrdinalIgnoreCase) >= 0;
_idleCache[stateName] = flag;
return flag;
}
internal static bool IsCompletedLikeState(string stateName)
{
if (string.IsNullOrEmpty(stateName))
{
return false;
}
if (_completeCache.TryGetValue(stateName, out var value))
{
return value;
}
string text = stateName.ToLowerInvariant();
bool flag = text.Contains("success") || text.Contains("complete") || text.Contains("submitted") || text.Contains("finish") || text.Contains("done");
_completeCache[stateName] = flag;
return flag;
}
public string ReadStateName(Component ep)
{
if (!Object.op_Implicit((Object)(object)ep))
{
return "";
}
try
{
Type type = ((object)ep).GetType();
FieldInfo field = type.GetField("currentState", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
PropertyInfo property = type.GetProperty("currentState", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
object obj = null;
if (property != null)
{
obj = property.GetValue(ep, null);
}
if (obj == null && field != null)
{
obj = field.GetValue(ep);
}
if (obj == null)
{
return "";
}
return obj.ToString() ?? "";
}
catch
{
return "";
}
}
public List<Component> BuildStage1PlannedList(List<Component> allPoints, Vector3 spawnPos, Vector3 startPos, bool skipActivated)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: 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_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_020f: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_025e: Unknown result type (might be due to invalid IL or missing references)
//IL_0263: Unknown result type (might be due to invalid IL or missing references)
//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
//IL_0356: Unknown result type (might be due to invalid IL or missing references)
//IL_0357: Unknown result type (might be due to invalid IL or missing references)
float realtimeSinceStartup = Time.realtimeSinceStartup;
List<Component> list = new List<Component>();
if (allPoints == null || allPoints.Count == 0)
{
return list;
}
if (spawnPos == Vector3.zero)
{
spawnPos = startPos;
}
if (startPos == Vector3.zero)
{
startPos = spawnPos;
}
List<Component> list2 = new List<Component>(allPoints.Count);
for (int i = 0; i < allPoints.Count; i++)
{
Component val = allPoints[i];
if (Object.op_Implicit((Object)(object)val))
{
string text = ReadStateName(val);
if (IsCompletedLikeState(text))
{
DebugLog?.Invoke("[PLAN][SKIP] completed name=" + ((Object)val.gameObject).name + " state=" + text);
}
else if (skipActivated && IsMarkedActivated(val))
{
DebugLog?.Invoke("[PLAN][SKIP] activated name=" + ((Object)val.gameObject).name);
}
else
{
list2.Add(val);
}
}
}
if (list2.Count == 0)
{
return list;
}
Component val2 = null;
float num = float.MaxValue;
Vector3 val3;
for (int j = 0; j < list2.Count; j++)
{
val3 = list2[j].transform.position - spawnPos;
float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
if (sqrMagnitude < num)
{
num = sqrMagnitude;
val2 = list2[j];
}
}
if ((Object)(object)val2 != (Object)null)
{
if (!skipActivated || !IsMarkedActivated(val2))
{
list.Add(val2);
}
list2.Remove(val2);
}
if (list2.Count == 0)
{
return list;
}
int index = -1;
float num2 = float.MaxValue;
for (int k = 0; k < list2.Count; k++)
{
val3 = list2[k].transform.position - spawnPos;
float sqrMagnitude2 = ((Vector3)(ref val3)).sqrMagnitude;
if (sqrMagnitude2 < num2)
{
num2 = sqrMagnitude2;
index = k;
}
}
Component val4 = list2[index];
list2.RemoveAt(index);
Vector3 val5 = startPos;
while (list2.Count > 0)
{
int index2 = 0;
float num3 = float.MaxValue;
for (int l = 0; l < list2.Count; l++)
{
val3 = val5 - list2[l].transform.position;
float sqrMagnitude3 = ((Vector3)(ref val3)).sqrMagnitude;
if (sqrMagnitude3 < num3)
{
num3 = sqrMagnitude3;
index2 = l;
}
}
Component val6 = list2[index2];
list2.RemoveAt(index2);
list.Add(val6);
val5 = val6.transform.position;
}
list.Add(val4);
float num4 = Time.realtimeSinceStartup - realtimeSinceStartup;
if (LogReady)
{
float num5 = (((Object)(object)val2 != (Object)null) ? Mathf.Sqrt(num) : (-1f));
val3 = val4.transform.position - spawnPos;
float magnitude = ((Vector3)(ref val3)).magnitude;
Action<string>? debugLog = DebugLog;
if (debugLog != null)
{
object[] obj = new object[7] { allPoints.Count, list.Count, null, null, null, null, null };
object obj2;
if (val2 == null)
{
obj2 = null;
}
else
{
GameObject gameObject = val2.gameObject;
obj2 = ((gameObject != null) ? ((Object)gameObject).name : null);
}
if (obj2 == null)
{
obj2 = "null";
}
obj[2] = obj2;
obj[3] = ((Object)val4.gameObject).name;
obj[4] = num5;
obj[5] = magnitude;
obj[6] = num4;
debugLog(string.Format("[PLAN] all={0} eligible={1} first={2} last={3} firstSpawnDist={4:0.00} lastSpawnDist={5:0.00} dt={6:0.000}s", obj));
}
DebugLogPlanList(list, startPos, spawnPos, val2, val4);
}
return list;
}
private void DebugLogPlanList(List<Component> plan, Vector3 startPos, Vector3 spawnPos, Component? first, Component last)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: 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_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
if (plan == null || plan.Count == 0)
{
return;
}
for (int i = 0; i < plan.Count; i++)
{
Component val = plan[i];
if (Object.op_Implicit((Object)(object)val))
{
Vector3 position = val.transform.position;
float num = Vector3.Distance(startPos, position);
float num2 = Vector3.Distance(spawnPos, position);
string text = ReadStateName(val);
bool flag = IsMarkedActivated(val);
bool flag2 = _discovered.Contains(((Object)val).GetInstanceID());
string text2 = (((Object)(object)val == (Object)(object)first) ? "FIRST" : (((Object)(object)val == (Object)(object)last) ? "LAST" : ""));
DebugLog?.Invoke($"[PLAN][{i}] name={((Object)val.gameObject).name} dist={num:0.00} spawnDist={num2:0.00} discovered={flag2} activated={flag} state={text} {text2}".Trim());
}
}
}
}
}
namespace REPO_Active.Reflection
{
public sealed class ExtractionPointInvoker
{
private readonly ManualLogSource _log;
public ExtractionPointInvoker(ManualLogSource log)
{
_log = log;
}
public bool InvokeOnClick(Component ep)
{
if ((Object)(object)ep == (Object)null)
{
return false;
}
try
{
Type type = ((object)ep).GetType();
MethodInfo method = type.GetMethod("OnClick", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method == null)
{
_log.LogWarning((object)("OnClick not found on " + type.FullName + ". (No activation performed)"));
return false;
}
object[] parameters = BuildDefaultArgs(method);
method.Invoke(ep, parameters);
return true;
}
catch (Exception arg)
{
_log.LogError((object)$"InvokeOnClick failed: {arg}");
return false;
}
}
private static object[]? BuildDefaultArgs(MethodInfo mi)
{
try
{
ParameterInfo[] parameters = mi.GetParameters();
if (parameters == null || parameters.Length == 0)
{
return null;
}
object[] array = new object[parameters.Length];
for (int i = 0; i < parameters.Length; i++)
{
ParameterInfo parameterInfo = parameters[i];
if (parameterInfo.HasDefaultValue)
{
array[i] = parameterInfo.DefaultValue;
continue;
}
Type type = parameterInfo.ParameterType;
if (type.IsByRef)
{
type = type.GetElementType() ?? type;
}
if (!type.IsValueType)
{
array[i] = null;
continue;
}
try
{
array[i] = Activator.CreateInstance(type);
}
catch
{
array[i] = null;
}
}
return array;
}
catch
{
return null;
}
}
}
}
namespace REPO_Active.Debug
{
public sealed class ModLogger
{
private readonly object _lock = new object();
private string _filePath = "";
public bool Enabled { get; set; }
public ModLogger(ManualLogSource log, bool enabled)
{
Enabled = enabled;
if (Enabled)
{
InitFile();
}
}
private void InitFile()
{
try
{
string text = Path.Combine(Paths.ConfigPath, "REPO_Active", "logs");
Directory.CreateDirectory(text);
string path = $"REPO_Active_{DateTime.Now:yyyyMMdd_HHmmss}.log";
_filePath = Path.Combine(text, path);
lock (_lock)
{
File.AppendAllText(_filePath, "[FileLog] " + _filePath + Environment.NewLine, Encoding.UTF8);
}
}
catch
{
}
}
public void Log(string message)
{
if (!Enabled)
{
return;
}
if (string.IsNullOrEmpty(_filePath))
{
InitFile();
if (string.IsNullOrEmpty(_filePath))
{
return;
}
}
try
{
lock (_lock)
{
File.AppendAllText(_filePath, message + Environment.NewLine, Encoding.UTF8);
}
}
catch
{
}
}
}
}