using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Peak;
using UnityEngine;
using UnityEngine.Rendering;
[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("BellBeacon")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+96529ebfe56eabbe962a3212f237319f36170064")]
[assembly: AssemblyProduct("BellBeacon")]
[assembly: AssemblyTitle("BellBeacon")]
[assembly: AssemblyVersion("1.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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;
}
}
}
namespace BellBeacon
{
internal sealed class BellBeaconController : IDisposable
{
private const float ReconcileInterval = 0.5f;
private readonly ModConfig _config;
private readonly ManualLogSource _logger;
private readonly Dictionary<int, BellMarker> _markers = new Dictionary<int, BellMarker>();
private readonly HashSet<int> _seenIds = new HashSet<int>();
private readonly List<int> _staleIds = new List<int>();
private Material? _material;
private float _nextReconcileAt;
private bool _materialFailureLogged;
public BellBeaconController(ModConfig config, ManualLogSource logger)
{
_config = config;
_logger = logger;
}
public void Tick()
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: 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)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
if (!_config.Enabled.Value)
{
ClearMarkers();
return;
}
if (Time.unscaledTime >= _nextReconcileAt)
{
ReconcileMarkers();
_nextReconcileAt = Time.unscaledTime + 0.5f;
}
Color safeUnlitColor = _config.SafeUnlitColor;
Color safeLitColor = _config.SafeLitColor;
float safeHeight = _config.SafeHeight;
float safeWidth = _config.SafeWidth;
foreach (BellMarker value in _markers.Values)
{
value.Tick(safeUnlitColor, safeLitColor, safeHeight, safeWidth);
}
}
public void Dispose()
{
ClearMarkers();
if ((Object)(object)_material != (Object)null)
{
Object.Destroy((Object)(object)_material);
}
_material = null;
}
private void ReconcileMarkers()
{
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
Material orCreateMaterial = GetOrCreateMaterial();
if ((Object)(object)orCreateMaterial == (Object)null)
{
return;
}
_seenIds.Clear();
List<GloomSafeZone> aLL_GLOOM_SAFE_ZONES = GloomSafeZone.ALL_GLOOM_SAFE_ZONES;
for (int i = 0; i < aLL_GLOOM_SAFE_ZONES.Count; i++)
{
GloomSafeZone obj = aLL_GLOOM_SAFE_ZONES[i];
GhostFire val = (GhostFire)(object)((obj is GhostFire) ? obj : null);
if (val != null && !((Object)(object)val == (Object)null) && ((Behaviour)val).isActiveAndEnabled)
{
int instanceID = ((Object)val).GetInstanceID();
_seenIds.Add(instanceID);
if (!_markers.ContainsKey(instanceID))
{
_markers.Add(instanceID, new BellMarker(val, orCreateMaterial));
_logger.LogDebug((object)$"Created Belltower beacon at {((Component)val).transform.position}.");
}
}
}
_staleIds.Clear();
foreach (int key2 in _markers.Keys)
{
if (!_seenIds.Contains(key2))
{
_staleIds.Add(key2);
}
}
for (int j = 0; j < _staleIds.Count; j++)
{
int key = _staleIds[j];
_markers[key].Dispose();
_markers.Remove(key);
}
}
private Material? GetOrCreateMaterial()
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: 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)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Expected O, but got Unknown
if ((Object)(object)_material != (Object)null)
{
return _material;
}
Shader val = Shader.Find("Sprites/Default");
if ((Object)(object)val == (Object)null)
{
if (!_materialFailureLogged)
{
_materialFailureLogged = true;
_logger.LogError((object)"Could not find the Sprites/Default shader; Belltower beacons are disabled.");
}
return null;
}
_material = new Material(val)
{
name = "BellBeacon.SharedMaterial",
hideFlags = (HideFlags)61,
renderQueue = 4000
};
return _material;
}
private void ClearMarkers()
{
if (_markers.Count == 0)
{
return;
}
foreach (BellMarker value in _markers.Values)
{
value.Dispose();
}
_markers.Clear();
_seenIds.Clear();
_staleIds.Clear();
}
}
internal sealed class BellMarker : IDisposable
{
private const float BaseOffset = 1f;
private readonly GhostFire _tower;
private readonly GameObject _gameObject;
private readonly LineRenderer _line;
private Vector3 _lastTowerPosition;
private float _lastHeight;
private float _lastWidth;
private bool _hasGeometry;
private Color _lastColor;
private bool _hasLastState;
private bool _lastLit;
public BellMarker(GhostFire tower, Material material)
{
//IL_0023: 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)
//IL_0035: Expected O, but got Unknown
_tower = tower;
_gameObject = new GameObject($"BellBeacon.Beam.{((Object)tower).GetInstanceID()}")
{
hideFlags = (HideFlags)61
};
_line = _gameObject.AddComponent<LineRenderer>();
((Renderer)_line).sharedMaterial = material;
_line.useWorldSpace = true;
_line.alignment = (LineAlignment)0;
_line.positionCount = 2;
_line.numCapVertices = 4;
((Renderer)_line).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)_line).receiveShadows = false;
((Renderer)_line).lightProbeUsage = (LightProbeUsage)0;
((Renderer)_line).reflectionProbeUsage = (ReflectionProbeUsage)0;
((Renderer)_line).sortingOrder = 32767;
}
public void Tick(Color unlitColor, Color litColor, float height, float width)
{
//IL_002a: 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_002b: 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_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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)
if (!((Object)(object)_tower == (Object)null))
{
UpdateGeometry(height, width);
bool isLit = ((GloomSafeZone)_tower).isLit;
Color val = (isLit ? litColor : unlitColor);
if (!_hasLastState || isLit != _lastLit || !(val == _lastColor))
{
_line.startColor = val;
_line.endColor = val;
_lastLit = isLit;
_lastColor = val;
_hasLastState = true;
}
}
}
public void Dispose()
{
if ((Object)(object)_gameObject != (Object)null)
{
Object.Destroy((Object)(object)_gameObject);
}
}
private void UpdateGeometry(float height, float width)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: 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_003b: 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)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: 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_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
Vector3 position = ((Component)_tower).transform.position;
if (!_hasGeometry || position != _lastTowerPosition || height != _lastHeight)
{
Vector3 val = position + Vector3.up * 1f;
_line.SetPosition(0, val);
_line.SetPosition(1, val + Vector3.up * height);
_lastTowerPosition = position;
_lastHeight = height;
}
if (!_hasGeometry || width != _lastWidth)
{
_line.startWidth = width;
_line.endWidth = width;
_lastWidth = width;
}
_hasGeometry = true;
}
}
internal sealed class ModConfig
{
private const float DefaultHeight = 500f;
private const float DefaultWidth = 0.8f;
private const float MinHeight = 10f;
private const float MaxHeight = 5000f;
private const float MinWidth = 0.05f;
private const float MaxWidth = 20f;
private const string DefaultUnlitColor = "#FFFFFF";
private const string DefaultLitColor = "#D57AE6";
private const string LegacyUnlitColor = "#8C929B";
private const string PreviousUnlitColor = "#FF3B6B";
private const string LegacyLitColor = "#FFB347";
private const string LegacyAutoLitColor = "GameFlame";
private const string PreviousLitColor = "#006FFF";
private readonly ManualLogSource _logger;
private string? _lastUnlitText;
private string? _lastLitText;
private Color _unlitColor;
private Color _litColor;
public ConfigEntry<bool> Enabled { get; }
public ConfigEntry<float> Height { get; }
public ConfigEntry<float> Width { get; }
public ConfigEntry<string> UnlitColor { get; }
public ConfigEntry<string> LitColor { get; }
public float SafeHeight => SafeRange(Height.Value, 10f, 5000f, 500f);
public float SafeWidth => SafeRange(Width.Value, 0.05f, 20f, 0.8f);
public Color SafeUnlitColor
{
get
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
RefreshColors();
return _unlitColor;
}
}
public Color SafeLitColor
{
get
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
RefreshColors();
return _litColor;
}
}
public ModConfig(ConfigFile config, ManualLogSource logger)
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Expected O, but got Unknown
_logger = logger;
Enabled = config.Bind<bool>("General", "Enabled", true, "Show beacon lines above Belltowers in the GLOOM.");
Height = config.Bind<float>("Visual", "Height", 500f, new ConfigDescription("Beacon height in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 5000f), Array.Empty<object>()));
Width = config.Bind<float>("Visual", "Width", 0.8f, new ConfigDescription("Beacon width in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 20f), Array.Empty<object>()));
UnlitColor = config.Bind<string>("Colors", "Unlit", "#FFFFFF", "Beacon color for an unlit Belltower, as an HTML hex color.");
LitColor = config.Bind<string>("Colors", "Lit", "#D57AE6", "Beacon color for a lit Belltower, as an HTML hex color.");
if (string.Equals(UnlitColor.Value, "#8C929B", StringComparison.OrdinalIgnoreCase) || string.Equals(UnlitColor.Value, "#FF3B6B", StringComparison.OrdinalIgnoreCase))
{
UnlitColor.Value = "#FFFFFF";
}
if (string.Equals(LitColor.Value, "#FFB347", StringComparison.OrdinalIgnoreCase) || string.Equals(LitColor.Value, "GameFlame", StringComparison.OrdinalIgnoreCase) || string.Equals(LitColor.Value, "#006FFF", StringComparison.OrdinalIgnoreCase))
{
LitColor.Value = "#D57AE6";
}
RefreshColors();
}
private void RefreshColors()
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: 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_0076: Unknown result type (might be due to invalid IL or missing references)
string text = UnlitColor.Value ?? string.Empty;
if (text != _lastUnlitText)
{
_unlitColor = ParseColor(text, "#FFFFFF", "Colors.Unlit");
_lastUnlitText = text;
}
string text2 = LitColor.Value ?? string.Empty;
if (text2 != _lastLitText)
{
_litColor = ParseColor(text2, "#D57AE6", "Colors.Lit");
_lastLitText = text2;
}
}
private Color ParseColor(string value, string fallback, string settingName)
{
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
Color result = default(Color);
if (ColorUtility.TryParseHtmlString(value, ref result))
{
return result;
}
ColorUtility.TryParseHtmlString(fallback, ref result);
_logger.LogWarning((object)("Invalid " + settingName + " color '" + value + "'. Using " + fallback + "."));
return result;
}
private static float SafeRange(float value, float min, float max, float fallback)
{
if (float.IsNaN(value) || float.IsInfinity(value))
{
return fallback;
}
return Mathf.Clamp(value, min, max);
}
}
[BepInPlugin("com.github.lllei.BellBeacon", "BellBeacon", "1.1.0")]
public sealed class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "com.github.lllei.BellBeacon";
public const string PluginName = "BellBeacon";
private BellBeaconController? _controller;
private void Awake()
{
ModConfig config = new ModConfig(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
_controller = new BellBeaconController(config, ((BaseUnityPlugin)this).Logger);
((BaseUnityPlugin)this).Logger.LogInfo((object)"BellBeacon 1.1.0 loaded for PEAK 2.0.a baseline.");
}
private void Update()
{
_controller?.Tick();
}
private void OnDestroy()
{
_controller?.Dispose();
_controller = null;
}
}
internal static class BuildInfo
{
internal const string Version = "1.1.0";
}
}