using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using SpellBrigadeLootBeams.Core;
using SpellBrigadeLootBeams.Game;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SpellBrigadeLootBeams")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+c15876f7b3875c3c4f77f070200221d1c77176f7")]
[assembly: AssemblyProduct("SpellBrigadeLootBeams")]
[assembly: AssemblyTitle("SpellBrigadeLootBeams")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
namespace SpellBrigadeLootBeams
{
internal static class ModConfig
{
public static ConfigEntry<bool> Enabled;
public static ConfigEntry<bool> ShowHealth;
public static ConfigEntry<bool> ShowMagnet;
public static ConfigEntry<bool> ShowArtifact;
public static ConfigEntry<string> HealthColor;
public static ConfigEntry<string> MagnetColor;
public static ConfigEntry<string> ArtifactColor;
public static ConfigEntry<float> Height;
public static ConfigEntry<float> Width;
public static ConfigEntry<float> Opacity;
public static ConfigEntry<float> FadeDistance;
public static ConfigEntry<float> PulseSpeed;
public static ConfigEntry<float> PulseAmount;
public static ConfigEntry<float> BurstSeconds;
public static ConfigEntry<float> BurstScale;
public static ConfigEntry<float> CoreWidth;
public static ConfigEntry<float> ScanInterval;
public static ConfigEntry<bool> LogPickups;
public static ConfigEntry<bool> TestHotkeys;
public static void Init(ConfigFile cfg)
{
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Expected O, but got Unknown
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Expected O, but got Unknown
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Expected O, but got Unknown
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Expected O, but got Unknown
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Expected O, but got Unknown
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Expected O, but got Unknown
//IL_0242: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Expected O, but got Unknown
//IL_027a: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Expected O, but got Unknown
//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Expected O, but got Unknown
//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
//IL_02f4: Expected O, but got Unknown
Enabled = cfg.Bind<bool>("General", "Enabled", true, "Show a beam of light above potions and power-ups lying on the ground. Can be switched off while playing.");
ShowHealth = cfg.Bind<bool>("Pickups", "Health", true, "Beam above Health Potions.");
ShowMagnet = cfg.Bind<bool>("Pickups", "Magnet", true, "Beam above Magnets.");
ShowArtifact = cfg.Bind<bool>("Pickups", "Artifact", true, "Beam above Artifacts.");
HealthColor = cfg.Bind<string>("Colors", "Health", "#FF3B4E", "Beam colour for Health Potions, as #RRGGBB or #RRGGBBAA.");
MagnetColor = cfg.Bind<string>("Colors", "Magnet", "#3FA9FF", "Beam colour for Magnets, as #RRGGBB or #RRGGBBAA.");
ArtifactColor = cfg.Bind<string>("Colors", "Artifact", "#FFC93C", "Beam colour for Artifacts, as #RRGGBB or #RRGGBBAA.");
Height = cfg.Bind<float>("Beam", "Height", 8f, new ConfigDescription("How tall the beam is, in world units.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
Width = cfg.Bind<float>("Beam", "Width", 1.4f, new ConfigDescription("How wide the beam's glow is, in world units.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 5f), Array.Empty<object>()));
Opacity = cfg.Bind<float>("Beam", "Opacity", 1f, new ConfigDescription("How solid the beam is at its brightest (0 = invisible, 1 = fully solid).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 1f), Array.Empty<object>()));
FadeDistance = cfg.Bind<float>("Beam", "FadeDistance", 3f, new ConfigDescription("The beam starts fading when your wizard comes this close (world units) and is gone just before you reach the item. 0 = never fade.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), Array.Empty<object>()));
PulseSpeed = cfg.Bind<float>("Beam", "PulseSpeed", 0.6f, new ConfigDescription("Pulses per second. 0 = no pulse.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
PulseAmount = cfg.Bind<float>("Beam", "PulseAmount", 0.2f, new ConfigDescription("How much the beam dims during a pulse (0 = steady, 1 = fades out completely).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
CoreWidth = cfg.Bind<float>("Beam", "CoreWidth", 0.35f, new ConfigDescription("Width of the bright, near-white core as a share of the beam's width. 0 = no core.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
BurstSeconds = cfg.Bind<float>("Burst", "Seconds", 1.5f, new ConfigDescription("When an item drops, its beam starts bigger and brighter and settles to the normal look over this many seconds. 0 = no burst.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
BurstScale = cfg.Bind<float>("Burst", "Scale", 1.8f, new ConfigDescription("How much bigger the beam is the moment the item drops (1 = same size).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
ScanInterval = cfg.Bind<float>("General", "ScanInterval", 0.25f, new ConfigDescription("Seconds between looking for new pickups.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 2f), Array.Empty<object>()));
LogPickups = cfg.Bind<bool>("Debug", "LogPickups", false, "Write one line per pickup the first time it is seen: its kind, object name and position.");
TestHotkeys = cfg.Bind<bool>("Debug", "TestHotkeys", false, "For testing, as host inside a run: Ctrl+L drops a Health Potion next to your wizard.");
}
}
internal static class ModLog
{
private static ManualLogSource? _log;
private static StreamWriter? _file;
private static readonly HashSet<string> Once = new HashSet<string>();
private static readonly Dictionary<string, float> Throttle = new Dictionary<string, float>();
public const string CleanExit = "clean exit";
public static string FilePath => Path.Combine(Paths.BepInExRootPath, "SpellBrigadeLootBeams.log");
public static string PreviousFilePath => Path.Combine(Paths.BepInExRootPath, "SpellBrigadeLootBeams.prev.log");
public static string? PreviousCrashStep { get; private set; }
public static void Init(ManualLogSource log)
{
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Expected O, but got Unknown
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Expected O, but got Unknown
_log = log;
bool flag = default(bool);
try
{
if (File.Exists(FilePath))
{
File.Copy(FilePath, PreviousFilePath, overwrite: true);
string text = null;
string[] array = File.ReadAllLines(FilePath);
foreach (string text2 in array)
{
int num = text2.IndexOf(" STEP ", StringComparison.Ordinal);
if (num >= 0)
{
string text3 = text2;
int num2 = num + 7;
text = text3.Substring(num2, text3.Length - num2).Trim();
}
}
if (text != null && text != "clean exit")
{
PreviousCrashStep = text;
}
}
}
catch (Exception ex)
{
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(30, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not read the previous ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(FilePath);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val);
}
try
{
_file = new StreamWriter(new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
AutoFlush = true
};
_file.WriteLine($"SpellBrigadeLootBeams {"0.2.0"} log, started {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
if (PreviousCrashStep != null)
{
_file.WriteLine("Previous session did not exit cleanly; its last step was: " + PreviousCrashStep + " (log kept as SpellBrigadeLootBeams.prev.log)");
}
}
catch (Exception ex2)
{
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(17, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not open ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(FilePath);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
}
log.LogWarning(val);
}
}
public static void Info(string msg)
{
ManualLogSource? log = _log;
if (log != null)
{
log.LogInfo((object)msg);
}
ToFile("INFO ", msg);
}
public static void Warn(string msg)
{
ManualLogSource? log = _log;
if (log != null)
{
log.LogWarning((object)msg);
}
ToFile("WARN ", msg);
}
public static void Error(string msg)
{
ManualLogSource? log = _log;
if (log != null)
{
log.LogError((object)msg);
}
ToFile("ERROR", msg);
}
public static void Debug(string msg)
{
ManualLogSource? log = _log;
if (log != null)
{
log.LogDebug((object)msg);
}
ToFile("DEBUG", msg);
}
public static void Step(string msg)
{
ToFile("STEP ", msg);
}
public static void StepOnce(string key, string msg)
{
if (Once.Add("step:" + key))
{
Step(msg);
}
}
public static void InfoOnce(string key, string msg)
{
if (Once.Add(key))
{
Info(msg);
}
}
public static void WarnOnce(string key, string msg)
{
if (Once.Add(key))
{
Warn(msg);
}
}
public static void ErrorThrottled(string key, Exception ex, float now, float seconds = 10f)
{
if (!Throttle.TryGetValue(key, out var value) || !(now - value < seconds))
{
Throttle[key] = now;
Error($"[{key}] {ex.GetType().Name}: {ex.Message}\n{ex.StackTrace}");
}
}
private static void ToFile(string level, string msg)
{
if (_file == null)
{
return;
}
try
{
lock (_file)
{
_file.WriteLine($"{DateTime.Now:HH:mm:ss.fff} {level} {msg}");
}
}
catch
{
}
}
}
[BepInPlugin("com.stefanws0.spellbrigadelootbeams", "SpellBrigadeLootBeams", "0.2.0")]
public class Plugin : BasePlugin
{
public const string Guid = "com.stefanws0.spellbrigadelootbeams";
public const string Name = "SpellBrigadeLootBeams";
public const string Version = "0.2.0";
public override void Load()
{
ModLog.Init(((BasePlugin)this).Log);
ModLog.Step("Load: config");
ModConfig.Init(((BasePlugin)this).Config);
ModLog.Step("Load: registering LootBeamsRunner");
((BasePlugin)this).AddComponent<LootBeamsRunner>();
ModLog.Step("Load: done");
string value = (ModConfig.Enabled.Value ? "" : " (General.Enabled is off: no beams are drawn)");
ModLog.Info($"{"SpellBrigadeLootBeams"} {"0.2.0"} loaded{value}.");
}
}
}
namespace SpellBrigadeLootBeams.Game
{
internal static class BeamRenderer
{
private sealed class Beam
{
public GameObject Root;
public SpriteRenderer Renderer;
public SpriteRenderer Core;
public bool Active;
}
private const int TexWidth = 64;
private const int TexHeight = 256;
private const float SpriteHeight = 4f;
private static readonly List<Beam> Pool = new List<Beam>();
private static readonly Dictionary<PickupKind, (string Text, Color Color)> ColorCache = new Dictionary<PickupKind, (string, Color)>();
private static GameObject? _root;
private static Sprite? _sprite;
public static void Render(List<TrackedPickup> tracked, float now)
{
//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_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: 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_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_0226: Unknown result type (might be due to invalid IL or missing references)
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_028d: Unknown result type (might be due to invalid IL or missing references)
//IL_028f: Unknown result type (might be due to invalid IL or missing references)
//IL_029b: Unknown result type (might be due to invalid IL or missing references)
//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
int num = 0;
Camera val = ((tracked.Count > 0) ? Camera.main : null);
if ((Object)(object)val != (Object)null && EnsureReady())
{
Vector3 position = ((Component)val).transform.position;
Vector3? playerPosition = PickupWatcher.PlayerPosition;
float value = ModConfig.Height.Value;
float value2 = ModConfig.Width.Value;
float value3 = ModConfig.Opacity.Value;
float value4 = ModConfig.FadeDistance.Value;
float value5 = ModConfig.PulseSpeed.Value;
float value6 = ModConfig.PulseAmount.Value;
float value7 = ModConfig.BurstSeconds.Value;
float value8 = ModConfig.BurstScale.Value;
float value9 = ModConfig.CoreWidth.Value;
for (int i = 0; i < tracked.Count; i++)
{
TrackedPickup trackedPickup = tracked[i];
try
{
if ((Object)(object)trackedPickup.Target == (Object)null || !((Component)trackedPickup.Target).gameObject.activeInHierarchy)
{
continue;
}
Vector3 position2 = trackedPickup.Target.position;
float distance = float.PositiveInfinity;
if (playerPosition.HasValue)
{
Vector3 val2 = position2 - playerPosition.Value;
val2.y = 0f;
distance = ((Vector3)(ref val2)).magnitude;
}
Color val3 = ColorOf(trackedPickup.Kind);
float age = now - trackedPickup.Since;
float burst = BeamRules.Burst(age, value7);
float num2 = (position2.x * 0.37f + position2.z * 0.61f) % 10f;
val3.a *= BeamRules.Alpha(value3, distance, value4, now + num2, value5, value6, age, burst);
if (!(val3.a <= 0.003f))
{
Beam beam = BeamAt(num++);
Transform transform = beam.Root.transform;
transform.position = position2;
float num3 = BeamRules.BurstScale(burst, value8);
transform.localScale = new Vector3(value2 * num3, value * num3 / 4f, 1f);
Vector3 val4 = position - position2;
val4.y = 0f;
if (((Vector3)(ref val4)).sqrMagnitude > 0.0001f)
{
transform.rotation = Quaternion.LookRotation(-((Vector3)(ref val4)).normalized, Vector3.up);
}
beam.Renderer.color = val3;
bool flag = value9 > 0f;
if (((Renderer)beam.Core).enabled != flag)
{
((Renderer)beam.Core).enabled = flag;
}
if (flag)
{
((Component)beam.Core).transform.localScale = new Vector3(value9, 1f, 1f);
Color color = Color.Lerp(val3, Color.white, BeamRules.CoreWhite(burst));
color.a = val3.a;
beam.Core.color = color;
}
if (!beam.Active)
{
beam.Root.SetActive(true);
beam.Active = true;
}
}
}
catch (Exception ex)
{
ModLog.ErrorThrottled("beam", ex, now);
}
}
}
for (int j = num; j < Pool.Count; j++)
{
Beam beam2 = Pool[j];
if (beam2.Active)
{
beam2.Active = false;
if ((Object)(object)beam2.Root != (Object)null)
{
beam2.Root.SetActive(false);
}
}
}
}
private static bool EnsureReady()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
if ((Object)(object)_root == (Object)null)
{
ModLog.Step("BeamRenderer: creating the beam root");
Pool.Clear();
_root = new GameObject("SpellBrigadeLootBeams");
Object.DontDestroyOnLoad((Object)(object)_root);
}
if ((Object)(object)_sprite == (Object)null)
{
ModLog.Step("BeamRenderer: building the beam sprite");
_sprite = BuildSprite();
ModLog.Step("BeamRenderer: beam sprite built");
}
return (Object)(object)_sprite != (Object)null;
}
private static Sprite BuildSprite()
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Expected O, but got Unknown
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = new Texture2D(64, 256, (TextureFormat)4, false);
((Object)val).name = "SpellBrigadeLootBeams.Beam";
((Texture)val).wrapMode = (TextureWrapMode)1;
((Texture)val).filterMode = (FilterMode)1;
for (int i = 0; i < 256; i++)
{
for (int j = 0; j < 64; j++)
{
val.SetPixel(j, i, new Color(1f, 1f, 1f, BeamTexture.AlphaAt(j, i, 64, 256)));
}
}
val.Apply(false, true);
((Object)val).hideFlags = (HideFlags)32;
Sprite obj = Sprite.Create(val, new Rect(0f, 0f, 64f, 256f), new Vector2(0.5f, 0f), 64f);
((Object)obj).name = ((Object)val).name;
((Object)obj).hideFlags = (HideFlags)32;
return obj;
}
private static Beam BeamAt(int index)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//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_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
while (Pool.Count <= index)
{
GameObject val = new GameObject("Beam");
val.transform.SetParent(_root.transform, false);
SpriteRenderer val2 = val.AddComponent<SpriteRenderer>();
val2.sprite = _sprite;
((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)val2).receiveShadows = false;
((Renderer)val2).sortingOrder = 0;
GameObject val3 = new GameObject("Core");
val3.transform.SetParent(val.transform, false);
SpriteRenderer val4 = val3.AddComponent<SpriteRenderer>();
val4.sprite = _sprite;
((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)val4).receiveShadows = false;
((Renderer)val4).sortingOrder = 1;
val3.transform.localPosition = new Vector3(0f, 0f, -0.01f);
if (Pool.Count == 0)
{
Material sharedMaterial = ((Renderer)val2).sharedMaterial;
ModLog.Info("Beams use material '" + (((Object)(object)sharedMaterial == (Object)null) ? "none" : ((Object)sharedMaterial).name) + "'.");
}
val.SetActive(false);
Pool.Add(new Beam
{
Root = val,
Renderer = val2,
Core = val4
});
}
return Pool[index];
}
private static Color ColorOf(PickupKind kind)
{
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
string text = kind switch
{
PickupKind.Magnet => ModConfig.MagnetColor.Value,
PickupKind.Artifact => ModConfig.ArtifactColor.Value,
_ => ModConfig.HealthColor.Value,
};
if (ColorCache.TryGetValue(kind, out (string, Color) value) && value.Item1 == text)
{
return value.Item2;
}
Color white = default(Color);
if (HexColor.TryParse(text, out var r, out var g, out var b, out var a))
{
((Color)(ref white))..ctor(r, g, b, a);
}
else
{
white = Color.white;
ModLog.Warn($"Colors.{kind}: '{text}' is not a colour like #FF3B4E; using white.");
}
ColorCache[kind] = (text, white);
return white;
}
}
public class LootBeamsRunner : MonoBehaviour
{
public LootBeamsRunner(IntPtr ptr)
: base(ptr)
{
}
public void Update()
{
float unscaledTime = Time.unscaledTime;
try
{
PickupWatcher.Update(unscaledTime);
}
catch (Exception ex)
{
ModLog.ErrorThrottled("watcher", ex, unscaledTime);
}
try
{
BeamRenderer.Render(PickupWatcher.Tracked, unscaledTime);
}
catch (Exception ex2)
{
ModLog.ErrorThrottled("beams", ex2, unscaledTime);
}
try
{
TestHotkeys.Update();
}
catch (Exception ex3)
{
ModLog.ErrorThrottled("hotkeys", ex3, unscaledTime);
}
}
public void OnApplicationQuit()
{
ModLog.Step("clean exit");
}
}
internal sealed class TrackedPickup
{
public Transform Target;
public PickupKind Kind;
public float Since;
}
internal static class PickupWatcher
{
private const float PlayerLookupSeconds = 1f;
private static readonly Dictionary<IntPtr, TrackedPickup> ByPtr = new Dictionary<IntPtr, TrackedPickup>();
private static readonly HashSet<IntPtr> Seen = new HashSet<IntPtr>();
private static readonly List<IntPtr> Gone = new List<IntPtr>();
private static float _nextScan;
private static float _nextPlayerLookup;
private static GameplayPlayerIdentity? _local;
public static readonly List<TrackedPickup> Tracked = new List<TrackedPickup>();
public static Vector3? PlayerPosition { get; private set; }
public static void Update(float now)
{
if (!ModConfig.Enabled.Value)
{
Clear();
return;
}
UpdatePlayer(now);
if (!(now < _nextScan))
{
_nextScan = now + ModConfig.ScanInterval.Value;
Scan(now);
}
}
private static void Clear()
{
if (ByPtr.Count != 0 || Tracked.Count != 0)
{
ByPtr.Clear();
Tracked.Clear();
}
}
private static void UpdatePlayer(float now)
{
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
try
{
if (((Object)(object)_local == (Object)null || !((NetworkBehaviour)_local).IsOwner) && now >= _nextPlayerLookup)
{
_nextPlayerLookup = now + 1f;
_local = LocalIdentity();
}
NetworkObject val = (((Object)(object)_local != (Object)null) ? _local.currentGameplayPlayer : null);
PlayerPosition = (((Object)(object)val != (Object)null) ? new Vector3?(((Component)val).transform.position) : ((Vector3?)null));
}
catch (Exception ex)
{
_local = null;
PlayerPosition = null;
ModLog.WarnOnce("player", "Could not find your wizard; beams will not fade up close. " + ex.Message);
}
}
private static GameplayPlayerIdentity? LocalIdentity()
{
ModLog.StepOnce("identity", "PickupWatcher: first GameplayPlayerIdentity lookup");
Il2CppReferenceArray<Object> val = Object.FindObjectsOfType(Il2CppType.Of<GameplayPlayerIdentity>());
if (val == null)
{
return null;
}
foreach (Object item in (Il2CppArrayBase<Object>)(object)val)
{
GameplayPlayerIdentity val2 = ((item != null) ? ((Il2CppObjectBase)item).TryCast<GameplayPlayerIdentity>() : null);
if ((Object)(object)val2 != (Object)null && ((NetworkBehaviour)val2).IsOwner)
{
return val2;
}
}
return null;
}
private static void Scan(float now)
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
ModLog.StepOnce("pointers", "PickupWatcher: first ScreenPointerManager read");
ScreenPointerManager instance = Singleton<ScreenPointerManager>.Instance;
Dictionary<Transform, ScreenPointer> val = (((Object)(object)instance != (Object)null) ? instance.activePointers : null);
if (val == null)
{
Clear();
return;
}
Seen.Clear();
Enumerator<Transform, ScreenPointer> enumerator = val.GetEnumerator();
while (enumerator.MoveNext())
{
KeyValuePair<Transform, ScreenPointer> current = enumerator.Current;
Transform key = current.Key;
ScreenPointer value = current.Value;
if ((Object)(object)key == (Object)null || (Object)(object)value == (Object)null || !TryKind(value.pointerType, out var kind) || !Wanted(kind) || !((Component)key).gameObject.activeInHierarchy)
{
continue;
}
IntPtr pointer = ((Il2CppObjectBase)key).Pointer;
Seen.Add(pointer);
if (!ByPtr.ContainsKey(pointer))
{
ByPtr[pointer] = new TrackedPickup
{
Target = key,
Kind = kind,
Since = now
};
if (ModConfig.LogPickups.Value)
{
Vector3 position = key.position;
ModLog.Info($"Pickup {kind}: '{((Object)key).name}' at ({position.x:0.#}, {position.y:0.#}, {position.z:0.#}).");
}
}
}
Gone.Clear();
foreach (IntPtr key2 in ByPtr.Keys)
{
if (!Seen.Contains(key2))
{
Gone.Add(key2);
}
}
for (int i = 0; i < Gone.Count; i++)
{
ByPtr.Remove(Gone[i]);
}
Tracked.Clear();
foreach (TrackedPickup value2 in ByPtr.Values)
{
Tracked.Add(value2);
}
}
private static bool TryKind(PointerType type, out PickupKind kind)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected I4, but got Unknown
switch (type - 4)
{
case 2:
kind = PickupKind.Health;
return true;
case 1:
kind = PickupKind.Magnet;
return true;
case 0:
kind = PickupKind.Artifact;
return true;
default:
kind = PickupKind.Health;
return false;
}
}
private static bool Wanted(PickupKind kind)
{
return kind switch
{
PickupKind.Health => ModConfig.ShowHealth.Value,
PickupKind.Magnet => ModConfig.ShowMagnet.Value,
PickupKind.Artifact => ModConfig.ShowArtifact.Value,
_ => false,
};
}
}
internal static class TestHotkeys
{
private static bool _keyboardRead;
public static void Update()
{
if (ModConfig.TestHotkeys.Value)
{
bool num = !_keyboardRead;
_keyboardRead = true;
if (num)
{
ModLog.Step("first Keyboard.current read");
}
Keyboard current = Keyboard.current;
if (num)
{
ModLog.Step("first Keyboard.current read done");
}
if (current != null && (((ButtonControl)current.leftCtrlKey).isPressed || ((ButtonControl)current.rightCtrlKey).isPressed) && ((ButtonControl)current.lKey).wasPressedThisFrame)
{
SpawnPotion();
}
}
}
private static void SpawnPotion()
{
//IL_003e: 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)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
Vector3? playerPosition = PickupWatcher.PlayerPosition;
if (!playerPosition.HasValue)
{
ModLog.Info("Ctrl+L: only works in a mission, while your wizard is up.");
return;
}
PickupSpawner instance = NetworkSingleton<PickupSpawner>.Instance;
if ((Object)(object)instance == (Object)null || !((NetworkBehaviour)instance).IsServer)
{
ModLog.Info("Ctrl+L: only works when you host (or play solo).");
return;
}
Vector3 val = playerPosition.Value + new Vector3(3f, 0f, 0f);
ModLog.Step("Ctrl+L: PickupSpawner.SpawnPickup");
instance.SpawnPickup(val, Quaternion.identity, instance.HealthPickupPrefab);
ModLog.Info("Ctrl+L: dropped a Health Potion next to you.");
}
}
}
namespace SpellBrigadeLootBeams.Core
{
public static class BeamRules
{
public const float FadeInSeconds = 0.08f;
public const float CoreWhiteness = 0.55f;
public static float DistanceFade(float distance, float fadeDistance)
{
if (!(fadeDistance > 0f))
{
return 1f;
}
if (float.IsNaN(distance))
{
return 1f;
}
float num = fadeDistance * 0.25f;
if (distance >= fadeDistance)
{
return 1f;
}
if (distance <= num)
{
return 0f;
}
return SmoothStep((distance - num) / (fadeDistance - num));
}
public static float Pulse(float time, float speed, float amount)
{
amount = Clamp01(amount);
if (!(speed > 0f) || amount == 0f)
{
return 1f;
}
float num = 0.5f + 0.5f * MathF.Sin(time * speed * 2f * (float)Math.PI);
return 1f - amount * (1f - num);
}
public static float FadeIn(float age)
{
return SmoothStep(age / 0.08f);
}
public static float Burst(float age, float seconds)
{
if (!(seconds > 0f) || float.IsNaN(age) || age >= seconds)
{
return 0f;
}
if (age <= 0f)
{
return 1f;
}
float num = 1f - age / seconds;
return num * num;
}
public static float BurstScale(float burst, float burstScale)
{
return 1f + (Math.Max(1f, burstScale) - 1f) * Clamp01(burst);
}
public static float Alpha(float opacity, float distance, float fadeDistance, float time, float pulseSpeed, float pulseAmount, float age, float burst = 0f)
{
burst = Clamp01(burst);
float num = Clamp01(opacity) * Pulse(time, pulseSpeed, pulseAmount);
return Clamp01((num + (1f - num) * burst) * DistanceFade(distance, fadeDistance) * FadeIn(age));
}
public static float CoreWhite(float burst)
{
return 0.55f + 0.34999996f * Clamp01(burst);
}
private static float SmoothStep(float t)
{
t = Clamp01(t);
return t * t * (3f - 2f * t);
}
private static float Clamp01(float v)
{
if (!float.IsNaN(v))
{
if (!(v < 0f))
{
if (!(v > 1f))
{
return v;
}
return 1f;
}
return 0f;
}
return 0f;
}
}
public static class BeamTexture
{
public static float AlphaAt(int x, int y, int width, int height)
{
if (width <= 0 || height <= 0)
{
return 0f;
}
float value = ((float)x + 0.5f) / (float)width * 2f - 1f;
float num = ((float)y + 0.5f) / (float)height;
float num2 = Math.Abs(value);
float num3 = MathF.Exp((0f - num2) * num2 * 30f);
float num4 = MathF.Pow(Math.Max(0f, 1f - num2), 1.6f) * 0.7f;
float num5 = Math.Min(1f, num3 + num4);
float num6 = Math.Min(1f, num / 0.06f);
float num7 = MathF.Pow(1f - num, 0.8f);
return num5 * num6 * num7;
}
}
public static class HexColor
{
public static bool TryParse(string? text, out float r, out float g, out float b, out float a)
{
r = (g = (b = 0f));
a = 1f;
if (text == null)
{
return false;
}
string text2 = text.Trim();
if (text2.StartsWith("#"))
{
text2 = text2.Substring(1);
}
if (text2.Length != 6 && text2.Length != 8)
{
return false;
}
if (!uint.TryParse(text2, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result))
{
return false;
}
if (text2.Length == 6)
{
result = (result << 8) | 0xFF;
}
r = (float)((result >> 24) & 0xFF) / 255f;
g = (float)((result >> 16) & 0xFF) / 255f;
b = (float)((result >> 8) & 0xFF) / 255f;
a = (float)(result & 0xFF) / 255f;
return true;
}
}
public enum PickupKind
{
Health,
Magnet,
Artifact
}
}
namespace System.Runtime.CompilerServices
{
[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 flag)
{
NullableFlags = new byte[1] { flag };
}
public NullableAttribute(byte[] flags)
{
NullableFlags = flags;
}
}
[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 flag)
{
Flag = flag;
}
}
}