using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Movement;
using Sparroh.UI;
using TMPro;
using Unity.Netcode;
using UnityEngine;
[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("Sparroh")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("IncursionTracker")]
[assembly: AssemblyTitle("IncursionTracker")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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;
}
}
}
public static class ConfigManager
{
private const float DebounceSeconds = 0.25f;
private static ConfigFile config;
private static ManualLogSource logger;
private static FileSystemWatcher configWatcher;
private static volatile bool pendingRefresh;
private static volatile bool reloadPending;
private static float lastReloadTime;
public static ConfigEntry<bool> EnableHud { get; private set; }
public static ConfigEntry<bool> StopAtFloor30 { get; private set; }
public static HudAnchors Anchors { get; private set; }
public static ConfigColor ValueColor { get; private set; }
public static ConfigColor FrozenColor { get; private set; }
public static void Initialize(ConfigFile configFile, ManualLogSource log)
{
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
config = configFile;
logger = log;
EnableHud = config.Bind<bool>("General", "Enable Incursion HUD", true, "Enables the Incursion tracker HUD display.");
StopAtFloor30 = config.Bind<bool>("General", "Stop Tracking At 30", false, "When enabled, freezes all trackers once the player reaches floor 30.");
Anchors = HudAnchors.Bind(config, "Tracker", 0.6512445f, 0.93617f, "HUD Positioning");
ValueColor = ConfigColor.Bind(config, "Colors", "Tracker Color", UIColors.Amber, "Rich-text value color while tracking (hex RRGGBB or #RRGGBB).");
FrozenColor = ConfigColor.Bind(config, "Colors", "Frozen Color", UIColors.TextMuted, "Rich-text value color when trackers are frozen (hex RRGGBB or #RRGGBB).");
EnableHud.SettingChanged += OnSettingChanged;
StopAtFloor30.SettingChanged += OnSettingChanged;
try
{
SetupFileWatcher();
}
catch (Exception ex)
{
logger.LogError((object)("Error setting up config file watcher: " + ex.Message));
}
}
public static void Tick()
{
if (!reloadPending || Time.unscaledTime - lastReloadTime < 0.25f)
{
return;
}
reloadPending = false;
lastReloadTime = Time.unscaledTime;
try
{
config.Reload();
pendingRefresh = true;
logger.LogInfo((object)"Config reloaded from disk.");
}
catch (Exception ex)
{
logger.LogError((object)("Error reloading config: " + ex.Message));
}
}
public static bool ConsumePendingRefresh()
{
if (!pendingRefresh)
{
return false;
}
pendingRefresh = false;
return true;
}
public static void Dispose()
{
if (EnableHud != null)
{
EnableHud.SettingChanged -= OnSettingChanged;
}
if (StopAtFloor30 != null)
{
StopAtFloor30.SettingChanged -= OnSettingChanged;
}
if (configWatcher != null)
{
configWatcher.EnableRaisingEvents = false;
configWatcher.Changed -= OnConfigFileChanged;
configWatcher.Created -= OnConfigFileChanged;
configWatcher.Renamed -= OnConfigFileChanged;
configWatcher.Dispose();
configWatcher = null;
}
}
private static void SetupFileWatcher()
{
configWatcher = new FileSystemWatcher(Paths.ConfigPath, "sparroh.incursiontracker.cfg");
configWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite;
configWatcher.Changed += OnConfigFileChanged;
configWatcher.Created += OnConfigFileChanged;
configWatcher.Renamed += OnConfigFileChanged;
configWatcher.EnableRaisingEvents = true;
}
private static void OnConfigFileChanged(object sender, FileSystemEventArgs e)
{
reloadPending = true;
}
private static void OnSettingChanged(object sender, EventArgs e)
{
pendingRefresh = true;
}
}
public class IncursionTrackerHUD
{
private const float RemainingTimerPauseGraceSeconds = 1.5f;
private int abominationsKilled;
private float accumulatedMissionTime;
private int codesInput;
private int floor;
private float frozenMissionTime;
private float frozenRemainingTime;
private HudHandle hud;
private bool isMissionTimerPaused;
private float lastRemainingTimerTickTime;
private int leversPulled;
private float missionSegmentStartTime;
private float remainingTime;
public static IncursionTrackerHUD Instance { get; private set; }
private bool IsHudAlive
{
get
{
if (HudHandle.IsValid(hud) && hud.Lines != null)
{
return hud.Lines.Length >= 6;
}
return false;
}
}
public bool IsTracking { get; private set; }
public bool IsFrozen { get; private set; }
public bool IsActive
{
get
{
if (IsHudAlive)
{
return hud.IsActive;
}
return false;
}
}
public IncursionTrackerHUD()
{
Instance = this;
}
public void OnConfigChanged()
{
if (!ConfigManager.EnableHud.Value && HudHandle.IsValid(hud))
{
DestroyHud();
}
UpdateHudVisibility();
}
public void UpdateHudVisibility()
{
if (!IsHudAlive)
{
ClearDestroyedHud();
return;
}
bool active = ConfigManager.EnableHud.Value && IsTracking;
hud.SetActive(active);
}
private void ClearDestroyedHud()
{
if (hud != null)
{
hud = null;
}
}
public void StartTracking()
{
IsTracking = true;
IsFrozen = false;
isMissionTimerPaused = false;
accumulatedMissionTime = 0f;
missionSegmentStartTime = Time.realtimeSinceStartup;
frozenMissionTime = 0f;
remainingTime = 0f;
frozenRemainingTime = 0f;
lastRemainingTimerTickTime = Time.realtimeSinceStartup;
floor = 0;
abominationsKilled = 0;
leversPulled = 0;
codesInput = 0;
if ((Object)(object)IncursionObjective.Instance != (Object)null)
{
floor = IncursionObjective.Instance.CurrentFloor;
}
SparrohPlugin.Logger.LogInfo((object)"Incursion tracker started");
UpdateHudVisibility();
}
public void StopTracking()
{
IsTracking = false;
IsFrozen = false;
isMissionTimerPaused = false;
SparrohPlugin.Logger.LogInfo((object)"Incursion tracker stopped");
UpdateHudVisibility();
}
public void SetFloor(int newFloor)
{
if (IsTracking && !IsFrozen)
{
floor = newFloor;
TryFreezeAtFloor30();
}
}
public void SetRemainingTime(float time)
{
if (IsTracking && !IsFrozen)
{
remainingTime = Mathf.Max(0f, time);
lastRemainingTimerTickTime = Time.realtimeSinceStartup;
ResumeMissionTimer();
}
}
public void OnAbominationKilled()
{
if (IsTracking && !IsFrozen)
{
abominationsKilled++;
SparrohPlugin.Logger.LogInfo((object)$"Abomination killed. Total: {abominationsKilled}");
}
}
public void OnLeverPulled()
{
if (IsTracking && !IsFrozen)
{
leversPulled++;
SparrohPlugin.Logger.LogInfo((object)$"Lever pulled. Total: {leversPulled}");
}
}
public void OnCodeInput()
{
if (IsTracking && !IsFrozen)
{
codesInput++;
SparrohPlugin.Logger.LogInfo((object)$"Door code input. Total: {codesInput}");
}
}
private void TryFreezeAtFloor30()
{
if (ConfigManager.StopAtFloor30.Value && !IsFrozen && floor >= 30)
{
IsFrozen = true;
PauseMissionTimer();
frozenMissionTime = GetCurrentMissionTime();
frozenRemainingTime = remainingTime;
SparrohPlugin.Logger.LogInfo((object)$"Incursion trackers frozen at floor {floor}");
}
}
private float GetCurrentMissionTime()
{
if (isMissionTimerPaused)
{
return accumulatedMissionTime;
}
return accumulatedMissionTime + (Time.realtimeSinceStartup - missionSegmentStartTime);
}
private void PauseMissionTimer()
{
if (!isMissionTimerPaused)
{
accumulatedMissionTime += Time.realtimeSinceStartup - missionSegmentStartTime;
isMissionTimerPaused = true;
}
}
private void ResumeMissionTimer()
{
if (isMissionTimerPaused)
{
missionSegmentStartTime = Time.realtimeSinceStartup;
isMissionTimerPaused = false;
}
}
private void UpdateMissionTimerPauseState()
{
if (!IsFrozen)
{
if (Time.realtimeSinceStartup - lastRemainingTimerTickTime > 1.5f)
{
PauseMissionTimer();
}
else
{
ResumeMissionTimer();
}
}
}
private void CreateTrackerHUD()
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
if (!IsHudAlive)
{
ClearDestroyedHud();
hud = HudBuilder.Create("IncursionTrackerHUD").ParentToReticle(true).Anchor(ConfigManager.Anchors.XValue, ConfigManager.Anchors.YValue)
.Pivot(new Vector2(0f, 1f))
.Size(280f, 140f, true)
.AddLines(6, 16f, (TextAlignmentOptions)257)
.Build();
if (IsHudAlive)
{
hud.EnableReposition("sparroh.incursiontracker", "Incursion Tracker", ConfigManager.Anchors);
UpdateHudVisibility();
}
}
}
private void DestroyHud()
{
if (hud != null)
{
if (hud.IsAlive)
{
hud.Destroy();
}
hud = null;
}
}
public void Update()
{
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: 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_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: 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_01e0: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!IsTracking || ConfigManager.EnableHud == null || !ConfigManager.EnableHud.Value)
{
if (IsHudAlive && hud.IsActive)
{
hud.SetActive(false);
}
return;
}
if (hud != null && !IsHudAlive)
{
ClearDestroyedHud();
}
if (!IsFrozen && (Object)(object)IncursionObjective.Instance != (Object)null)
{
int currentFloor = IncursionObjective.Instance.CurrentFloor;
if (currentFloor != floor)
{
SetFloor(currentFloor);
}
}
UpdateMissionTimerPauseState();
if (!((Object)(object)Player.LocalPlayer == (Object)null) && !((Object)(object)Player.LocalPlayer.PlayerLook == (Object)null) && !((Object)(object)Player.LocalPlayer.PlayerLook.Reticle == (Object)null))
{
if (!IsHudAlive)
{
CreateTrackerHUD();
return;
}
float timeInSeconds = (IsFrozen ? frozenMissionTime : GetCurrentMissionTime());
float timeInSeconds2 = (IsFrozen ? frozenRemainingTime : remainingTime);
Color val = (IsFrozen ? ConfigManager.FrozenColor.Value : ConfigManager.ValueColor.Value);
hud.Lines[0].SetRich("Mission", FormatTime(timeInSeconds), val, (string)null);
hud.Lines[1].SetRich("Remaining", FormatRemaining(timeInSeconds2), val, (string)null);
hud.Lines[2].SetRich("Floor", floor, val, (string)null);
hud.Lines[3].SetRich("Aboms", abominationsKilled, val, (string)null);
hud.Lines[4].SetRich("Levers", leversPulled, val, (string)null);
hud.Lines[5].SetRich("Codes", codesInput, val, (string)null);
}
}
catch (Exception ex)
{
SparrohPlugin.Logger.LogError((object)("Error in IncursionTrackerHUD.Update(): " + ex.Message));
}
}
private static string FormatTime(float timeInSeconds)
{
if (timeInSeconds < 0f)
{
timeInSeconds = 0f;
}
int num = (int)(timeInSeconds / 60f);
int num2 = (int)(timeInSeconds % 60f);
int num3 = (int)(timeInSeconds % 1f * 1000f);
return $"{num:D2}:{num2:D2}.{num3:D3}";
}
private static string FormatRemaining(float timeInSeconds)
{
if (timeInSeconds < 0f)
{
timeInSeconds = 0f;
}
int num = Mathf.FloorToInt(timeInSeconds / 60f);
int num2 = Mathf.FloorToInt(timeInSeconds % 60f);
return $"{num}:{num2:D2}";
}
public void OnDestroy()
{
try
{
DestroyHud();
}
catch (Exception ex)
{
SparrohPlugin.Logger.LogError((object)("Error in IncursionTrackerHUD.OnDestroy(): " + ex.Message));
}
}
}
[HarmonyPatch]
public static class IncursionTrackerPatches
{
private const float CodeInputDebounceSeconds = 0.5f;
private static Action<EnemyBrain> abominationSpawnedHandler;
private static Action<EnemyBrain> abominationKilledHandler;
private static Action<RepairableObject> leverRepairedHandler;
private static RepairableObject subscribedLever;
private static float lastCodeInputRealtime = -999f;
private static void EnsureHandlers()
{
if (abominationSpawnedHandler == null)
{
abominationSpawnedHandler = OnAbominationSpawned;
}
if (abominationKilledHandler == null)
{
abominationKilledHandler = OnAbominationKilled;
}
if (leverRepairedHandler == null)
{
leverRepairedHandler = OnLeverRepaired;
}
}
private static bool CanTrack()
{
if (IncursionTrackerHUD.Instance != null && IncursionTrackerHUD.Instance.IsTracking && !IncursionTrackerHUD.Instance.IsFrozen)
{
return (Object)(object)IncursionObjective.Instance != (Object)null;
}
return false;
}
private static void SubscribeAbominationTracking()
{
EnsureHandlers();
EnemyBrain.OnAbominationSpawned -= abominationSpawnedHandler;
EnemyBrain.OnAbominationSpawned += abominationSpawnedHandler;
}
private static void UnsubscribeAbominationTracking()
{
if (abominationSpawnedHandler != null)
{
EnemyBrain.OnAbominationSpawned -= abominationSpawnedHandler;
}
UnsubscribeLever();
}
private static void OnAbominationSpawned(EnemyBrain brain)
{
if (CanTrack() && !((Object)(object)brain == (Object)null))
{
brain.OnKilled -= abominationKilledHandler;
brain.OnKilled += abominationKilledHandler;
}
}
private static void OnAbominationKilled(EnemyBrain brain)
{
if ((Object)(object)brain != (Object)null)
{
brain.OnKilled -= abominationKilledHandler;
}
if (CanTrack())
{
IncursionTrackerHUD.Instance.OnAbominationKilled();
}
}
private static void SubscribeLever(RepairableObject lever)
{
EnsureHandlers();
UnsubscribeLever();
if (!((Object)(object)lever == (Object)null))
{
subscribedLever = lever;
subscribedLever.OnRepaired += leverRepairedHandler;
}
}
private static void UnsubscribeLever()
{
if ((Object)(object)subscribedLever != (Object)null && leverRepairedHandler != null)
{
subscribedLever.OnRepaired -= leverRepairedHandler;
}
subscribedLever = null;
}
private static void OnLeverRepaired(RepairableObject lever)
{
if (CanTrack())
{
IncursionTrackerHUD.Instance.OnLeverPulled();
}
}
[HarmonyPatch(typeof(IncursionObjective), "Setup")]
[HarmonyPostfix]
private static void Setup_Postfix(IncursionObjective __instance)
{
if (IncursionTrackerHUD.Instance == null)
{
return;
}
EnsureHandlers();
IncursionTrackerHUD.Instance.StartTracking();
SubscribeAbominationTracking();
try
{
FieldInfo fieldInfo = AccessTools.Field(typeof(IncursionObjective), "addTimeLever");
if (fieldInfo != null)
{
object? value = fieldInfo.GetValue(__instance);
RepairableObject val = (RepairableObject)((value is RepairableObject) ? value : null);
if ((Object)(object)val != (Object)null)
{
SubscribeLever(val);
}
}
}
catch (Exception ex)
{
SparrohPlugin.Logger.LogWarning((object)("Could not subscribe to existing lever: " + ex.Message));
}
}
[HarmonyPatch(typeof(IncursionObjective), "OnDestroy")]
[HarmonyPostfix]
private static void OnDestroy_Postfix()
{
UnsubscribeAbominationTracking();
if (IncursionTrackerHUD.Instance != null)
{
IncursionTrackerHUD.Instance.StopTracking();
}
}
[HarmonyPatch(typeof(IncursionObjective), "SpawnRooms_ClientRpc")]
[HarmonyPostfix]
private static void SpawnRooms_ClientRpc_Postfix(IncursionObjective __instance, int currentFloor, int floorsReached)
{
if (IncursionTrackerHUD.Instance != null && IncursionTrackerHUD.Instance.IsTracking)
{
IncursionTrackerHUD.Instance.SetFloor(currentFloor);
}
}
[HarmonyPatch(typeof(IncursionObjective), "OnCodeInputSuccess_ClientRpc")]
[HarmonyPostfix]
private static void OnCodeInputSuccess_ClientRpc_Postfix()
{
if (CanTrack())
{
float realtimeSinceStartup = Time.realtimeSinceStartup;
if (!(realtimeSinceStartup - lastCodeInputRealtime < 0.5f))
{
lastCodeInputRealtime = realtimeSinceStartup;
IncursionTrackerHUD.Instance.OnCodeInput();
}
}
}
[HarmonyPatch(typeof(IncursionObjective), "OnAddTimeLeverSpawned_ClientRpc")]
[HarmonyPostfix]
private static void OnAddTimeLeverSpawned_ClientRpc_Postfix(NetworkBehaviourReference leverRef)
{
RepairableObject lever = default(RepairableObject);
if (IncursionTrackerHUD.Instance != null && ((NetworkBehaviourReference)(ref leverRef)).TryGet<RepairableObject>(ref lever, (NetworkManager)null))
{
SubscribeLever(lever);
}
}
[HarmonyPatch(typeof(IncursionHUD), "UpdateTimer")]
[HarmonyPostfix]
private static void UpdateTimer_Postfix(float time)
{
if (IncursionTrackerHUD.Instance != null && IncursionTrackerHUD.Instance.IsTracking)
{
IncursionTrackerHUD.Instance.SetRemainingTime(time);
}
}
[HarmonyPatch(typeof(IncursionHUD), "SetFloor")]
[HarmonyPostfix]
private static void SetFloor_Postfix(int floor)
{
if (IncursionTrackerHUD.Instance != null && IncursionTrackerHUD.Instance.IsTracking)
{
IncursionTrackerHUD.Instance.SetFloor(floor);
}
}
}
[BepInPlugin("sparroh.incursiontracker", "IncursionTracker", "1.0.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class SparrohPlugin : BaseUnityPlugin
{
public const string PluginGUID = "sparroh.incursiontracker";
public const string PluginName = "IncursionTracker";
public const string PluginVersion = "1.0.3";
internal static ManualLogSource Logger;
private Harmony harmony;
private IncursionTrackerHUD tracker;
private void Awake()
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
try
{
ConfigManager.Initialize(((BaseUnityPlugin)this).Config, Logger);
}
catch (Exception ex)
{
Logger.LogError((object)("Failed to initialize config: " + ex.Message));
return;
}
try
{
harmony = new Harmony("sparroh.incursiontracker");
}
catch (Exception ex2)
{
Logger.LogError((object)("Failed to create Harmony instance: " + ex2.Message));
return;
}
try
{
tracker = new IncursionTrackerHUD();
}
catch (Exception ex3)
{
Logger.LogError((object)("Failed to initialize IncursionTracker: " + ex3.Message));
}
try
{
harmony.PatchAll();
}
catch (Exception ex4)
{
Logger.LogError((object)("Failed to apply Harmony patches: " + ex4.Message));
}
Logger.LogInfo((object)"IncursionTracker loaded successfully.");
}
private void Update()
{
try
{
ConfigManager.Tick();
if (ConfigManager.ConsumePendingRefresh() && tracker != null)
{
tracker.OnConfigChanged();
}
if (tracker != null)
{
tracker.UpdateHudVisibility();
tracker.Update();
}
}
catch (Exception ex)
{
Logger.LogError((object)("Error in IncursionTracker.Update(): " + ex.Message));
}
}
private void OnDestroy()
{
try
{
if (tracker != null)
{
tracker.OnDestroy();
}
}
catch (Exception ex)
{
Logger.LogError((object)("Error in IncursionTracker.OnDestroy(): " + ex.Message));
}
try
{
ConfigManager.Dispose();
}
catch (Exception ex2)
{
Logger.LogError((object)("Error disposing config: " + ex2.Message));
}
try
{
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
catch (Exception ex3)
{
Logger.LogError((object)("Error unpatching Harmony: " + ex3.Message));
}
}
}
namespace IncursionTracker
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "IncursionTracker";
public const string PLUGIN_NAME = "IncursionTracker";
public const string PLUGIN_VERSION = "1.0.3";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}