Decompiled source of Trinkets v0.1.35
SpellBrigadeTrinkets.dll
Decompiled 4 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; 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; using Il2CppSystem.Collections.Generic; using SpellBrigadeTrinkets.Core; using SpellBrigadeTrinkets.Game; using TMPro; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.Bindings; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Rendering; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("SpellBrigadeTrinkets")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.35.0")] [assembly: AssemblyInformationalVersion("0.1.35+9af619155fb0b7a9512cf71fec731e19cf2d3eda")] [assembly: AssemblyProduct("SpellBrigadeTrinkets")] [assembly: AssemblyTitle("SpellBrigadeTrinkets")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.35.0")] [module: UnverifiableCode] namespace SpellBrigadeTrinkets { internal static class ModConfig { public static ConfigEntry<bool> Enabled = null; public static ConfigEntry<float> EliteDropChance = null; public static ConfigEntry<float> MapSpawnSeconds = null; public static ConfigEntry<float> FirstMapSpawnSeconds = null; public static ConfigEntry<int> MaxOnGround = null; public static ConfigEntry<float> OrbLifetime = null; public static ConfigEntry<float> PickupRadius = null; public static ConfigEntry<float> MaxBuffSeconds = null; public static ConfigEntry<float> OrbSize = null; public static ConfigEntry<float> OrbHeight = null; public static ConfigEntry<bool> ShowHud = null; public static ConfigEntry<bool> UseModels = null; public static ConfigEntry<float> HudScale = null; public static ConfigEntry<float> HudBottom = null; public static ConfigEntry<string> HudSide = null; public static ConfigEntry<bool> ShowPickupText = null; public static ConfigEntry<bool> WizardGlow = null; public static ConfigEntry<bool> PickupFx = null; public static ConfigEntry<string> PickupFxDonor = null; public static ConfigEntry<bool> LogEffects = null; public static ConfigEntry<bool> TestHotkeys = null; private static readonly Dictionary<TrinketKind, (ConfigEntry<float> Strength, ConfigEntry<float> Seconds, ConfigEntry<float> Weight, ConfigEntry<string> Color)> Items = new Dictionary<TrinketKind, (ConfigEntry<float>, ConfigEntry<float>, ConfigEntry<float>, ConfigEntry<string>)>(); public static void Init(ConfigFile cfg) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Expected O, but got Unknown //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Expected O, but got Unknown //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Expected O, but got Unknown //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Expected O, but got Unknown //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Expected O, but got Unknown //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Expected O, but got Unknown //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Expected O, but got Unknown //IL_03a4: Unknown result type (might be due to invalid IL or missing references) //IL_03ae: Expected O, but got Unknown //IL_03dc: Unknown result type (might be due to invalid IL or missing references) //IL_03e6: Expected O, but got Unknown Enabled = cfg.Bind<bool>("General", "Enabled", true, "Trinkets drop from elites and appear on the map. Host setting in co-op."); EliteDropChance = cfg.Bind<float>("Spawning", "EliteDropChance", 0.3f, new ConfigDescription("Chance (0-1) that a killed elite drops a trinket.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); MapSpawnSeconds = cfg.Bind<float>("Spawning", "MapSpawnSeconds", 75f, new ConfigDescription("Seconds between trinkets appearing somewhere on the map. 0 = never.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 600f), Array.Empty<object>())); FirstMapSpawnSeconds = cfg.Bind<float>("Spawning", "FirstMapSpawnSeconds", 45f, new ConfigDescription("Seconds into a mission before the first map trinket.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 600f), Array.Empty<object>())); MaxOnGround = cfg.Bind<int>("Spawning", "MaxOnGround", 3, new ConfigDescription("At most this many trinkets lying around; no new map trinket while there are this many.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>())); OrbLifetime = cfg.Bind<float>("Spawning", "Lifetime", 90f, new ConfigDescription("Seconds a trinket stays on the ground before it fades away (it blinks for the last 5). 0 = forever.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 900f), Array.Empty<object>())); PickupRadius = cfg.Bind<float>("Spawning", "PickupRadius", 1.6f, new ConfigDescription("How close (world units) a wizard has to walk to pick a trinket up.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 6f), Array.Empty<object>())); MaxBuffSeconds = cfg.Bind<float>("Buffs", "MaxSeconds", 30f, new ConfigDescription("Picking up a buff you already have adds its time, up to this many seconds left.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 300f), Array.Empty<object>())); Item(cfg, TrinketKind.SwiftFeather, 50f, "Percent move speed.", 14f, 10f); Item(cfg, TrinketKind.HasteRune, 60f, "Percent cast speed.", 15f, 10f); Item(cfg, TrinketKind.GiantCap, 60f, "Percent spell size.", 18f, 10f); Item(cfg, TrinketKind.WardCharm, 0f, "Unused (the Ward makes you untouchable).", 6f, 8f); Item(cfg, TrinketKind.ManaSpring, 100f, "Percent extra mana (XP) for every wizard.", 25f, 8f); Item(cfg, TrinketKind.LuckyClover, 1f, "Extra rerolls, kept for the rest of the mission.", 0f, 5f); Item(cfg, TrinketKind.GoldPouch, 40f, "Gold for every wizard, added straight away.", 0f, 5f); Item(cfg, TrinketKind.JackpotCoin, 1f, "Extra pulls on Arcane Row's Gamble slot machine this mission. Only drops while the host has Gamble; a wizard without Gamble who picks one up gets 40 gold instead.", 0f, 4f); Migrate(cfg); OrbSize = cfg.Bind<float>("Look", "OrbSize", 1f, new ConfigDescription("Size of a trinket on the ground. 1 = as big as the game's own health potion and magnet (measured in the level).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.3f, 4f), Array.Empty<object>())); OrbHeight = cfg.Bind<float>("Look", "OrbHeight", 1f, new ConfigDescription("How high above the ground the orb floats.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 4f), Array.Empty<object>())); UseModels = cfg.Bind<bool>("Look", "UseModels", true, "Show trinkets that have a 3D model as that model (with a soft glow behind it). Off = glowing orbs with icons for all."); ShowHud = cfg.Bind<bool>("Look", "ShowHud", true, "Icons with a timer ring for your active trinket buffs, plus a short banner on pickup."); HudScale = cfg.Bind<float>("Look", "HudScale", 1f, new ConfigDescription("Size of the buff icons.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 3f), Array.Empty<object>())); ShowPickupText = cfg.Bind<bool>("Look", "ShowPickupText", false, "Show a line of text (like \"Gold Pouch Team: +25 gold\") when a trinket is picked up. Off by default: the buff icon says it."); HudSide = cfg.Bind<string>("Look", "HudSide", "Right", new ConfigDescription("Which side of the game's health/spell bar the buff icons sit on. They slide further out by themselves when other HUD art is in the way.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "Right", "Left" }), Array.Empty<object>())); HudBottom = cfg.Bind<float>("Look", "HudBottom", 60f, new ConfigDescription("Only used when the game's health bar can't be found: distance of the buff icons from the bottom of the screen (pixels at 1080p).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>())); WizardGlow = cfg.Bind<bool>("Look", "WizardGlow", true, "A soft glow in the buff's colour under every buffed wizard (yours and your teammates')."); PickupFx = cfg.Bind<bool>("Look", "PickupEffect", true, "On pickup, the wizard plays the game's own super-pickup buff effect, recoloured to the trinket with the trinket's symbol."); PickupFxDonor = cfg.Bind<string>("Look", "PickupEffectFrom", "MovementSpeed", "Which of the game's buff effects the pickup effect is made from: MovementSpeed, FireRate or CriticalChance."); LogEffects = cfg.Bind<bool>("Debug", "LogEffects", true, "Write a log line for every spawn, pickup and buff."); TestHotkeys = cfg.Bind<bool>("Debug", "TestHotkeys", false, "For testing, as host inside a mission: Ctrl+T drops the next trinket next to your wizard, Ctrl+Shift+T drops all seven."); } private static void Item(ConfigFile cfg, TrinketKind kind, float strength, string strengthText, float seconds, float weight) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Expected O, but got Unknown TrinketDef trinketDef = Trinkets.Of(kind); string text = trinketDef.Name.Replace(" ", ""); ConfigEntry<float> item = cfg.Bind<float>(text, "Strength", strength, strengthText); ConfigEntry<float> item2 = cfg.Bind<float>(text, "Seconds", seconds, new ConfigDescription(trinketDef.IsTimed ? "How long it lasts." : "Unused (this one lasts the whole mission).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 300f), Array.Empty<object>())); ConfigEntry<float> item3 = cfg.Bind<float>(text, "Weight", weight, new ConfigDescription("How often it drops compared to the others. 0 = never.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); ConfigEntry<string> item4 = cfg.Bind<string>(text, "Color", trinketDef.Color, "Orb colour, as #RRGGBB."); Items[kind] = (item, item2, item3, item4); } private static void Migrate(ConfigFile cfg) { ConfigEntry<int> val = cfg.Bind<int>("Debug", "BalanceVersion", 0, "Which balance pass this config has; the mod updates it itself."); if (val.Value >= 1) { return; } foreach (var value in Items.Values) { value.Strength.Value = (float)((ConfigEntryBase)value.Strength).DefaultValue; value.Seconds.Value = (float)((ConfigEntryBase)value.Seconds).DefaultValue; } EliteDropChance.Value = (float)((ConfigEntryBase)EliteDropChance).DefaultValue; val.Value = 1; ModLog.Info("Trinkets balance pass 1: buff strengths, durations and the elite drop chance set to the new defaults."); } public static TrinketTuning Tuning(TrinketKind kind) { (ConfigEntry<float>, ConfigEntry<float>, ConfigEntry<float>, ConfigEntry<string>) tuple = Items[kind]; return new TrinketTuning { Strength = tuple.Item1.Value, Seconds = tuple.Item2.Value, Weight = tuple.Item3.Value }; } public static string ColorText(TrinketKind kind) { return Items[kind].Color.Value; } } 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, "SpellBrigadeTrinkets.log"); public static string PreviousFilePath => Path.Combine(Paths.BepInExRootPath, "SpellBrigadeTrinkets.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($"SpellBrigadeTrinkets {"0.1.35"} 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 SpellBrigadeTrinkets.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.spellbrigadetrinkets", "SpellBrigadeTrinkets", "0.1.35")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BasePlugin { public const string Guid = "com.stefanws0.spellbrigadetrinkets"; public const string Name = "SpellBrigadeTrinkets"; public const string Version = "0.1.35"; public override void Load() { ModLog.Init(((BasePlugin)this).Log); ModLog.Step("Load: config"); ModConfig.Init(((BasePlugin)this).Config); Net.Received = (Action<TrinketMessage>)Delegate.Combine(Net.Received, new Action<TrinketMessage>(ClientView.Handle)); ModLog.Step("Load: registering TrinketsRunner"); ((BasePlugin)this).AddComponent<TrinketsRunner>(); KitSelfTest.Register(); ModLog.Step("Load: done"); string value = (ModConfig.Enabled.Value ? "" : " (General.Enabled is off: no trinkets spawn when you host)"); ModLog.Info($"{"SpellBrigadeTrinkets"} {"0.1.35"} loaded{value}."); } } public static class TrinketsApi { public const int Version = 1; public static int Pickups(List<int> ids, List<Vector3> positions, List<Color> colors, List<Sprite?> icons, List<string> names) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) ids.Clear(); positions.Clear(); colors.Clear(); icons.Clear(); names.Clear(); foreach (KeyValuePair<int, ShownOrb> orb in ClientView.Orbs) { OrbInfo info = orb.Value.Info; if (Trinkets.IsValid((int)info.Kind)) { TrinketDef trinketDef = Trinkets.Of(info.Kind); ids.Add(info.Id); positions.Add(new Vector3(info.X, info.Y, info.Z)); colors.Add(Art.ColorOf(info.Kind)); icons.Add(Art.Get("buff_" + trinketDef.Icon) ?? Art.Get(trinketDef.Icon)); names.Add(trinketDef.Name); } } return ids.Count; } } } namespace SpellBrigadeTrinkets.Game { internal static class Art { private static readonly Dictionary<string, Sprite?> Sprites = new Dictionary<string, Sprite>(); private static readonly Dictionary<TrinketKind, (string Text, Color Color)> Colors = new Dictionary<TrinketKind, (string, Color)>(); public static Sprite? Get(string name, float pixelsPerUnit = 128f) { //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Expected O, but got Unknown //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) string key = name + "@" + pixelsPerUnit; if (Sprites.TryGetValue(key, out Sprite value) && ((Object)(object)value == (Object)null || !((Il2CppObjectBase)value).WasCollected)) { return value; } Sprite val = null; try { using Stream stream = typeof(Art).Assembly.GetManifestResourceStream("SpellBrigadeTrinkets.Assets." + name + ".png"); if (stream == null) { ModLog.WarnOnce("art-" + name, "Embedded image " + name + ".png is missing."); } else { using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, true); if (ImageConversion.LoadImage(val2, Il2CppStructArray<byte>.op_Implicit(memoryStream.ToArray()))) { ((Object)val2).name = "SpellBrigadeTrinkets." + name; ((Texture)val2).wrapMode = (TextureWrapMode)1; ((Texture)val2).filterMode = (FilterMode)1; ((Object)val2).hideFlags = (HideFlags)61; val = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f), pixelsPerUnit); ((Object)val).name = ((Object)val2).name; ((Object)val).hideFlags = (HideFlags)61; } else { ModLog.Error("Embedded image " + name + ".png could not be decoded."); } } } catch (Exception ex) { ModLog.ErrorThrottled("art", ex, Time.unscaledTime, 60f); } Sprites[key] = val; return val; } public static Color ColorOf(TrinketKind kind) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) string text = ModConfig.ColorText(kind); if (Colors.TryGetValue(kind, out (string, Color) value) && value.Item1 == text) { return value.Item2; } Color val = default(Color); if (HexColor.TryParse(text, out var r, out var g, out var b, out var a)) { ((Color)(ref val))..ctor(r, g, b, a); } else { TrinketDef trinketDef = Trinkets.Of(kind); HexColor.TryParse(trinketDef.Color, out r, out g, out b, out a); ((Color)(ref val))..ctor(r, g, b, a); ModLog.Warn($"{trinketDef.Name}.Color: '{text}' is not a colour like #7FD8FF; using {trinketDef.Color}."); } Colors[kind] = (text, val); return val; } } internal static class BuffHud { private sealed class Slot { public GameObject Root; public Image Back; public Image Track; public Image Ring; public Image Icon; public Image Tens; public Image Ones; public TrinketKind Kind = (TrinketKind)(-1); public string Shown = ""; } private const int UiLayer = 5; private const int SortingOrder = 2000; private const float IconSize = 64f; private const float Gap = 14f; private const float BannerSeconds = 2.6f; private const float PunchSeconds = 0.25f; private const float WarnSeconds = 3f; private static readonly Dictionary<TrinketKind, float> Started = new Dictionary<TrinketKind, float>(); private static readonly Dictionary<TrinketKind, float> StartedEnd = new Dictionary<TrinketKind, float>(); private static readonly List<TrinketKind> Ended = new List<TrinketKind>(); private static GameObject? _root; private static RectTransform? _row; private static Canvas? _canvas; private static Vector2 _at; private static bool _placed; private static TextMeshProUGUI? _banner; private static readonly List<Slot> Slots = new List<Slot>(); private static readonly List<ShownBuff> Mine = new List<ShownBuff>(); private static float _bannerStart = -10f; private static Color _bannerColor = Color.white; private static Vector2 _bannerBase = new Vector2(0f, 80f); private static TMP_FontAsset? _font; private static float _nextFontTry; private static int _fontTries; private static int _rowKey; private const float DigitHeight = 20f; private static readonly Vector2 BadgeAt = new Vector2(23.04f, -21.76f); public static bool BannerShown { get { if ((Object)(object)_banner != (Object)null) { return ((Behaviour)_banner).enabled; } return false; } } public static List<(TrinketKind Kind, string Shown, float Left)> Counters() { List<(TrinketKind, string, float)> list = new List<(TrinketKind, string, float)>(); float time = Time.time; for (int i = 0; i < Math.Min(Mine.Count, Slots.Count); i++) { if (Slots[i].Root.activeSelf) { list.Add((Mine[i].Kind, Slots[i].Shown, Mine[i].End - time)); } } return list; } public static void Clear() { if ((Object)(object)_root != (Object)null) { _root.SetActive(false); } } public static void Render(float now) { //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_0306: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_0319: 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_0449: Unknown result type (might be due to invalid IL or missing references) //IL_0450: Unknown result type (might be due to invalid IL or missing references) //IL_045a: Unknown result type (might be due to invalid IL or missing references) //IL_045c: Unknown result type (might be due to invalid IL or missing references) //IL_0466: Unknown result type (might be due to invalid IL or missing references) //IL_046b: Unknown result type (might be due to invalid IL or missing references) //IL_047d: Unknown result type (might be due to invalid IL or missing references) PlayerInfo local = Players.Local; if (!ModConfig.ShowHud.Value || local == null) { if ((Object)(object)_root != (Object)null && _root.activeSelf) { _root.SetActive(false); } ClientView.Banners.Clear(); } else { if (!Ensure(now)) { return; } if (!_root.activeSelf) { _root.SetActive(true); } if ((Object)(object)_font == (Object)null && now >= _nextFontTry && _fontTries < 5) { _fontTries++; TryGameFont(now); } float value = ModConfig.HudScale.Value; ((Transform)_row).localScale = Vector3.one * value; Mine.Clear(); float time = Time.time; foreach (ShownBuff buff in ClientView.Buffs) { if (buff.Client == local.Client && buff.End > time) { Mine.Add(buff); } } Mine.Sort(delegate(ShownBuff shownBuff2, ShownBuff b) { int kind = (int)shownBuff2.Kind; return kind.CompareTo((int)b.Kind); }); float num = (float)Mine.Count * 64f + (float)Math.Max(0, Mine.Count - 1) * 14f; bool flag = now - _bannerStart <= 2.6f || ClientView.Banners.Count > 0; if (Mine.Count > 0 || flag) { Place(now, num, value); } for (int num2 = 0; num2 < Math.Max(Mine.Count, Slots.Count); num2++) { if (num2 >= Mine.Count) { if (Slots[num2].Root.activeSelf) { Slots[num2].Root.SetActive(false); } continue; } Slot slot = ((num2 < Slots.Count) ? Slots[num2] : NewSlot()); ShownBuff shownBuff = Mine[num2]; Color val = Art.ColorOf(shownBuff.Kind); if (slot.Kind != shownBuff.Kind) { slot.Kind = shownBuff.Kind; slot.Icon.sprite = Art.Get("buff_" + Trinkets.Of(shownBuff.Kind).Icon) ?? Art.Get(Trinkets.Of(shownBuff.Kind).Icon); } slot.Root.GetComponent<RectTransform>().anchoredPosition = new Vector2((0f - num) / 2f + 32f + (float)num2 * 78f, 0f); float num3 = shownBuff.End - time; slot.Ring.fillAmount = TrinketRules.Fraction(time, shownBuff.End, shownBuff.Full); ((Graphic)slot.Ring).color = val; Color color = val * 0.3f; color.a = 0.55f; ((Graphic)slot.Track).color = color; if (!Started.TryGetValue(shownBuff.Kind, out var value2) || StartedEnd[shownBuff.Kind] < shownBuff.End - 0.5f) { value2 = (Started[shownBuff.Kind] = now); StartedEnd[shownBuff.Kind] = shownBuff.End; } float num5 = now - value2; float num6 = ((num5 < 0.25f) ? (1f + 0.4f * Mathf.Pow(1f - num5 / 0.25f, 2f)) : 1f); float a = 1f; if (num3 < 3f) { float num7 = Mathf.Lerp(10f, 4f, num3 / 3f); float num8 = 0.5f + 0.5f * Mathf.Cos((3f - num3) * num7); num6 *= 1f + 0.1f * num8; a = 0.45f + 0.55f * num8; } slot.Root.transform.localScale = Vector3.one * num6; Color color2 = Color.Lerp(val, Color.white, 0.3f); color2.a = a; ((Graphic)slot.Icon).color = color2; string text = Mathf.Clamp(Mathf.CeilToInt(num3), 0, 99).ToString(CultureInfo.InvariantCulture); if (slot.Shown != text) { slot.Shown = text; ShowNumber(slot, text); } if (!slot.Root.activeSelf) { slot.Root.SetActive(true); } } Ended.Clear(); foreach (TrinketKind key in Started.Keys) { bool flag2 = false; foreach (ShownBuff item in Mine) { flag2 |= item.Kind == key; } if (!flag2) { Ended.Add(key); } } foreach (TrinketKind item2 in Ended) { Started.Remove(item2); StartedEnd.Remove(item2); } Banner(now); } } private static void Place(float now, float width, float scale) { //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) float num = (((Object)(object)_canvas != (Object)null && _canvas.scaleFactor > 0f) ? _canvas.scaleFactor : ((float)Screen.height / 1080f)); int num2 = Mine.Count; foreach (ShownBuff item in Mine) { num2 = (int)(num2 * 31 + item.Kind + 1); } if (num2 != _rowKey) { _rowKey = num2; HudPlacer.Rescan(); } HudPlacer.Scan(now, ((Il2CppObjectBase)_root.GetComponent<Canvas>()).Pointer); float num3 = num * scale; float rowW = Math.Max(width, 64f) * num3; float rowH = 64f * num3; Vector2 val = HudPlacer.Place(rowW, rowH, num3) / num; if (!_placed || Mine.Count == 0) { _placed = true; _at = val; } else { _at = Vector2.Lerp(_at, val, 1f - Mathf.Exp(-12f * Time.unscaledDeltaTime)); } _row.anchoredPosition = _at; Rect? bar = HudPlacer.Bar; float num4; if (!bar.HasValue) { num4 = 260f; } else { Rect value = bar.Value; num4 = ((Rect)(ref value)).yMax / num + 190f; } float num5 = num4; _bannerBase = new Vector2((float)Screen.width / 2f / num, num5) - _at; } private static void Banner(float now) { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0101: 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_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: 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) if (!ModConfig.ShowPickupText.Value) { ClientView.Banners.Clear(); if (((Behaviour)_banner).enabled) { ((Behaviour)_banner).enabled = false; } return; } if (ClientView.Banners.Count > 0 && now - _bannerStart > 0.8f) { var (kind, text) = ClientView.Banners.Dequeue(); ((TMP_Text)_banner).text = text; _bannerColor = Color.Lerp(Art.ColorOf(kind), Color.white, 0.35f); _bannerStart = now; } float num = now - _bannerStart; if (num > 2.6f) { if (((Behaviour)_banner).enabled) { ((Behaviour)_banner).enabled = false; } return; } if (!((Behaviour)_banner).enabled) { ((Behaviour)_banner).enabled = true; } float a = Mathf.Clamp01(num / 0.15f) * Mathf.Clamp01((2.6f - num) / 0.6f); Color bannerColor = _bannerColor; bannerColor.a = a; ((Graphic)_banner).color = bannerColor; float num2 = Math.Max(0.01f, ModConfig.HudScale.Value); ((TMP_Text)_banner).rectTransform.anchoredPosition = (_bannerBase + new Vector2(0f, 10f * Mathf.Clamp01(num / 0.3f))) / num2; } private static bool Ensure(float now) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: 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_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_root != (Object)null) { return true; } try { ModLog.Step("BuffHud: creating the canvas"); _root = new GameObject("SpellBrigadeTrinkets.Hud"); _root.layer = 5; Object.DontDestroyOnLoad((Object)(object)_root); Canvas? obj = (_canvas = _root.AddComponent<Canvas>()); obj.renderMode = (RenderMode)0; obj.sortingOrder = 2000; CanvasScaler obj2 = _root.AddComponent<CanvasScaler>(); obj2.uiScaleMode = (ScaleMode)1; obj2.referenceResolution = new Vector2(1920f, 1080f); obj2.matchWidthOrHeight = 1f; GameObject val = new GameObject("Row") { layer = 5 }; val.transform.SetParent(_root.transform, false); _row = val.AddComponent<RectTransform>(); RectTransform? row = _row; Vector2 anchorMin = (_row.anchorMax = Vector2.zero); row.anchorMin = anchorMin; _row.pivot = new Vector2(0.5f, 0.5f); _row.sizeDelta = new Vector2(10f, 64f); _banner = NewText(_row, "Banner", 30f); ((TMP_Text)_banner).rectTransform.sizeDelta = new Vector2(900f, 44f); ((Behaviour)_banner).enabled = false; TryGameFont(now); ModLog.Step("BuffHud: canvas created"); return true; } catch (Exception ex) { ModLog.ErrorThrottled("hud", ex, now, 60f); if ((Object)(object)_root != (Object)null) { Object.Destroy((Object)(object)_root); } _root = null; return false; } } private static Slot NewSlot() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_014b: 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) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("Buff" + Slots.Count); val.layer = 5; val.transform.SetParent((Transform)(object)_row, false); val.AddComponent<RectTransform>().sizeDelta = new Vector2(64f, 64f); Slot slot = new Slot { Root = val }; slot.Back = NewImage(val, "Back", "disc", 55.04f); ((Graphic)slot.Back).color = new Color(0.02f, 0.02f, 0.03f, 0.96f); slot.Track = NewImage(val, "Track", "slotring", 64f); slot.Ring = NewImage(val, "Ring", "slotring", 64f); slot.Ring.type = (Type)3; slot.Ring.fillMethod = (FillMethod)4; slot.Ring.fillOrigin = 2; slot.Ring.fillClockwise = false; slot.Icon = NewImage(val, "Icon", "disc", 53.76f); Image obj = NewImage(val, "Badge", "disc", 32f); ((Graphic)obj).color = new Color(0.05f, 0.05f, 0.07f, 0.92f); ((Graphic)obj).rectTransform.anchoredPosition = BadgeAt; slot.Tens = NewImage(val, "Tens", "digit0", 20f); slot.Ones = NewImage(val, "Ones", "digit0", 20f); RectTransform rectTransform = ((Graphic)slot.Tens).rectTransform; RectTransform rectTransform2 = ((Graphic)slot.Ones).rectTransform; Vector2 sizeDelta = default(Vector2); ((Vector2)(ref sizeDelta))..ctor(15f, 20f); rectTransform2.sizeDelta = sizeDelta; rectTransform.sizeDelta = sizeDelta; Slots.Add(slot); return slot; } private static Image NewImage(GameObject parent, string name, string sprite, float size) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name) { layer = 5 }; val.transform.SetParent(parent.transform, false); Image obj = val.AddComponent<Image>(); obj.sprite = Art.Get(sprite, 100f); ((Graphic)obj).raycastTarget = false; obj.preserveAspect = true; ((Graphic)obj).rectTransform.sizeDelta = new Vector2(size, size); return obj; } private static void ShowNumber(Slot slot, string text) { //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) float num = 11.599999f; if (text.Length >= 2) { slot.Tens.sprite = Art.Get("digit" + text[0], 100f); slot.Ones.sprite = Art.Get("digit" + text[1], 100f); ((Behaviour)slot.Tens).enabled = true; ((Graphic)slot.Tens).rectTransform.anchoredPosition = BadgeAt + new Vector2((0f - num) / 2f, 0f); ((Graphic)slot.Ones).rectTransform.anchoredPosition = BadgeAt + new Vector2(num / 2f, 0f); } else { slot.Ones.sprite = Art.Get("digit" + text[0], 100f); ((Behaviour)slot.Tens).enabled = false; ((Graphic)slot.Ones).rectTransform.anchoredPosition = BadgeAt; } } private static void SetFont(TextMeshProUGUI t, bool outline) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_font == (Object)null)) { ((TMP_Text)t).font = _font; if ((Object)(object)((TMP_Asset)_font).material != (Object)null) { ((TMP_Text)t).fontSharedMaterial = ((TMP_Asset)_font).material; } if (outline) { ((TMP_Text)t).outlineWidth = 0.2f; ((TMP_Text)t).outlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue); } } } private static TextMeshProUGUI NewText(RectTransform parent, string name, float size, bool outline = true) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: 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_0086: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name) { layer = 5 }; val.transform.SetParent((Transform)(object)parent, false); TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>(); ((TMP_Text)val2).fontSize = size; ((Graphic)val2).color = Color.white; ((TMP_Text)val2).alignment = (TextAlignmentOptions)514; ((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0; ((TMP_Text)val2).overflowMode = (TextOverflowModes)0; ((TMP_Text)val2).richText = false; ((Graphic)val2).raycastTarget = false; if ((Object)(object)_font != (Object)null) { SetFont(val2, outline); } else if (outline) { ((TMP_Text)val2).outlineWidth = 0.2f; ((TMP_Text)val2).outlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue); } return val2; } private static void TryGameFont(float now) { _nextFontTry = now + 2f; try { Il2CppArrayBase<TextMeshProUGUI> obj = Object.FindObjectsOfType<TextMeshProUGUI>(); Dictionary<IntPtr, (TMP_FontAsset, int)> dictionary = new Dictionary<IntPtr, (TMP_FontAsset, int)>(); foreach (TextMeshProUGUI item in obj) { if (!((Object)(object)item == (Object)null) && ((Behaviour)item).isActiveAndEnabled && !((Object)(object)item == (Object)(object)_banner)) { TMP_FontAsset font = ((TMP_Text)item).font; if (!((Object)(object)font == (Object)null)) { dictionary.TryGetValue(((Il2CppObjectBase)font).Pointer, out var value); dictionary[((Il2CppObjectBase)font).Pointer] = (font, value.Item2 + 1); } } } if (dictionary.Count != 0) { _font = dictionary.Values.OrderByDescending<(TMP_FontAsset, int), int>(((TMP_FontAsset font, int n) e) => e.n).First().Item1; if ((Object)(object)_banner != (Object)null) { SetFont(_banner, outline: true); } ModLog.Info("Trinket HUD uses the game's font '" + ((Object)_font).name + "'."); } } catch (Exception ex) { _nextFontTry = now + 30f; ModLog.ErrorThrottled("font", ex, now, 60f); } } } internal sealed class ShownOrb { public OrbInfo Info; public float Since; public float BornGameTime; } internal sealed class ShownBuff { public ulong Client; public TrinketKind Kind; public float End; public float Full; } internal static class ClientView { public static readonly Dictionary<int, ShownOrb> Orbs = new Dictionary<int, ShownOrb>(); public static readonly List<ShownBuff> Buffs = new List<ShownBuff>(); public static readonly Queue<(TrinketKind Kind, string Text)> Banners = new Queue<(TrinketKind, string)>(); private static readonly HashSet<int> Keep = new HashSet<int>(); private static readonly List<int> Drop = new List<int>(); public static void Clear() { Orbs.Clear(); Buffs.Clear(); Banners.Clear(); } public static void Handle(TrinketMessage m) { float unscaledTime = Time.unscaledTime; ulong num = Net.LocalClientId(Net.Manager); switch (m.Type) { case MessageType.Orbs: Keep.Clear(); foreach (OrbInfo orb in m.Orbs) { Keep.Add(orb.Id); if (Orbs.TryGetValue(orb.Id, out ShownOrb value)) { value.Info = orb; continue; } Orbs[orb.Id] = new ShownOrb { Info = orb, Since = unscaledTime, BornGameTime = Time.time }; } Drop.Clear(); foreach (int key in Orbs.Keys) { if (!Keep.Contains(key)) { Drop.Add(key); } } { foreach (int item in Drop) { Orbs.Remove(item); } break; } case MessageType.Taken: { Orbs.Remove(m.OrbId); long start = Timing.Begin(); if (!PickupFx.Play(m.Client, m.Kind, Time.time)) { OrbRenderer.Burst(m.OrbId, m.Kind); } Timing.End("view/pickup-fx", start, Time.unscaledTime); TrinketDef trinketDef = Trinkets.Of(m.Kind); if (m.Client == num || trinketDef.Target == TrinketTarget.Team) { Banners.Enqueue((m.Kind, trinketDef.Name + " " + TrinketRules.EffectLine(trinketDef, ModConfig.Tuning(m.Kind)))); } if (m.Client == num) { TestHotkeys.ShootSoon(unscaledTime, 0.5f, "pickup-" + m.Kind); } break; } case MessageType.Buff: { ShownBuff shownBuff = null; foreach (ShownBuff buff in Buffs) { if (buff.Client == m.Client && buff.Kind == m.Kind) { shownBuff = buff; } } if (shownBuff == null) { shownBuff = new ShownBuff { Client = m.Client, Kind = m.Kind }; Buffs.Add(shownBuff); } shownBuff.End = Time.time + m.SecondsLeft; shownBuff.Full = m.FullSeconds; break; } case MessageType.Permanent: if (m.AllClients || m.Client == num) { Effects.ApplyPermanentLocal(m.Kind, m.Amount, unscaledTime); } break; } } public static void Update() { float time = Time.time; for (int num = Buffs.Count - 1; num >= 0; num--) { if (Buffs[num].End <= time) { Buffs.RemoveAt(num); } } } } internal static class EffectBindings { private static float _next; private const float SettledSeconds = 2f; private static int _logs; private static readonly List<StatType> Needed = new List<StatType>(); public static void Now(float now) { _next = 0f; Update(now); } public static (int Players, int Covered) Coverage() { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) int num = 0; int num2 = 0; foreach (PlayerInfo item in Players.All) { PickupBuffEffectPlayer? obj = Players.EffectPlayer(item); List<StatEffectBinding> val = ((obj != null) ? obj.statEffects : null); if (val == null) { continue; } num++; HashSet<StatType> hashSet = new HashSet<StatType>(); for (int i = 0; i < val.Count; i++) { if ((Object)(object)val[i].Effect != (Object)null) { hashSet.Add(val[i].StatType); } } bool flag = Needed.Count > 0; foreach (StatType item2 in Needed) { flag &= hashSet.Contains(item2); } if (flag) { num2++; } } return (Players: num, Covered: num2); } private static ParticleSystem? QuietEffect(PickupBuffEffectPlayer p) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown try { Transform val = ((Component)p).transform.Find("TrinketsQuietEffect"); if ((Object)(object)val != (Object)null) { ParticleSystem component = ((Component)val).GetComponent<ParticleSystem>(); if ((Object)(object)component != (Object)null) { return component; } } GameObject val2 = new GameObject("TrinketsQuietEffect"); val2.transform.SetParent(((Component)p).transform, false); ParticleSystem obj = val2.AddComponent<ParticleSystem>(); obj.Stop(true, (ParticleSystemStopBehavior)0); MainModule main = obj.main; main.playOnAwake = false; main.maxParticles = 0; obj.emission.enabled = false; ParticleSystemRenderer component2 = val2.GetComponent<ParticleSystemRenderer>(); if ((Object)(object)component2 != (Object)null) { ((Renderer)component2).enabled = false; } return obj; } catch (Exception ex) { ModLog.WarnOnce("quiet-effect", "Could not make a silent buff effect; reusing the game's. " + ex.GetBaseException().Message); return null; } } public unsafe static void Update(float now) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: 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_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Invalid comparison between Unknown and I4 //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_0240: 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_0249: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_036d: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Expected I4, but got Unknown //IL_038e: Unknown result type (might be due to invalid IL or missing references) //IL_0393: Unknown result type (might be due to invalid IL or missing references) //IL_0433: Unknown result type (might be due to invalid IL or missing references) //IL_0438: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_04a2: Unknown result type (might be due to invalid IL or missing references) if (now < _next) { return; } _next = now + 2f; if (Needed.Count == 0) { TrinketDef[] all = Trinkets.All; foreach (TrinketDef trinketDef in all) { if (trinketDef.Effect == TrinketEffect.TimedStat && Enum.TryParse<StatType>(trinketDef.Stat, out StatType result) && !Needed.Contains(result)) { Needed.Add(result); } } } try { int num = 0; int num2 = 0; foreach (PlayerInfo item in Players.All) { PickupBuffEffectPlayer val = Players.EffectPlayer(item); if ((Object)(object)val == (Object)null) { continue; } List<StatEffectBinding> statEffects = val.statEffects; if (statEffects == null || statEffects.Count == 0) { continue; } num++; HashSet<StatType> hashSet = new HashSet<StatType>(); List<string> list = new List<string>(); List<int> list2 = new List<int>(); for (int j = 0; j < statEffects.Count; j++) { StatType statType = statEffects[j].StatType; list.Add(Enum.IsDefined(typeof(StatType), statType) ? ((object)(*(StatType*)(&statType))/*cast due to .constrained prefix*/).ToString() : "broken"); if (Enum.IsDefined(typeof(StatType), statType)) { hashSet.Add(statType); } else { list2.Add(j); } } StatEffectBinding val2 = null; for (int k = 0; k < statEffects.Count; k++) { if (Enum.IsDefined(typeof(StatType), statEffects[k].StatType) && (Object)(object)statEffects[k].Effect != (Object)null && (val2 == null || (int)statEffects[k].StatType == 2)) { val2 = statEffects[k]; } } if (val2 == null) { continue; } bool flag = false; foreach (StatType item2 in Needed) { flag |= !hashSet.Contains(item2); } if (!flag) { continue; } num2++; List<string> list3 = new List<string>(); foreach (StatType item3 in Needed) { if (!hashSet.Contains(item3)) { int index; if (list2.Count > 0) { index = list2[0]; list2.RemoveAt(0); } else { statEffects.Add(val2); index = statEffects.Count - 1; } ParticleSystem val3 = QuietEffect(val); if (!StructSlot.Write(((Il2CppObjectBase)statEffects).Pointer, index, (int)item3, ((Il2CppObjectBase)(val3 ?? val2.Effect)).Pointer, out string why)) { ModLog.Warn($"Could not add the {item3} buff effect: {why}."); _next = now + 1E+09f; return; } list3.Add(((object)(*(StatType*)(&item3))/*cast due to .constrained prefix*/).ToString()); } } List<string> list4 = new List<string>(); List<StatEffectBinding> statEffects2 = val.statEffects; for (int l = 0; l < statEffects2.Count; l++) { list4.Add((Enum.IsDefined(typeof(StatType), statEffects2[l].StatType) ? ((object)statEffects2[l].StatType/*cast due to .constrained prefix*/).ToString() : "broken") + (((Object)(object)statEffects2[l].Effect != (Object)null) ? "" : "(no effect)")); } if (_logs++ < 8) { DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(83, 6); defaultInterpolatedStringHandler.AppendLiteral("Buff effects on '"); defaultInterpolatedStringHandler.AppendFormatted(((Object)((Component)val).gameObject).name); defaultInterpolatedStringHandler.AppendLiteral("' ("); Scene scene = ((Component)val).gameObject.scene; defaultInterpolatedStringHandler.AppendFormatted(((Scene)(ref scene)).IsValid() ? "in the level" : "prefab"); defaultInterpolatedStringHandler.AppendLiteral("): had ["); defaultInterpolatedStringHandler.AppendFormatted(string.Join(", ", list)); defaultInterpolatedStringHandler.AppendLiteral("], added ["); defaultInterpolatedStringHandler.AppendFormatted(string.Join(", ", list3)); defaultInterpolatedStringHandler.AppendLiteral("] (silent effect, "); defaultInterpolatedStringHandler.AppendFormatted<StatType>(val2.StatType); defaultInterpolatedStringHandler.AppendLiteral(" as fallback); list now ["); defaultInterpolatedStringHandler.AppendFormatted(string.Join(", ", list4)); defaultInterpolatedStringHandler.AppendLiteral("]."); ModLog.Info(defaultInterpolatedStringHandler.ToStringAndClear()); } } if (num > 0 && num2 == 0) { _next = now + 2f; } } catch (Exception ex) { _next = now + 30f; ModLog.ErrorThrottled("bindings", ex, now, 60f); } } } internal static class StructSlot { public static bool Write(IntPtr list, int index, int stat, IntPtr effect, out string why) { why = ""; uint num = (uint)(IntPtr.Size * 2); IntPtr intPtr = IL2CPP.il2cpp_class_get_field_from_name(IL2CPP.il2cpp_object_get_class(list), "_items"); if (intPtr == IntPtr.Zero) { why = "no _items field"; return false; } IntPtr intPtr2 = Marshal.ReadIntPtr(list + (int)IL2CPP.il2cpp_field_get_offset(intPtr)); if (intPtr2 == IntPtr.Zero) { why = "no storage"; return false; } IntPtr nativeClassPtr = Il2CppClassPointerStore<StatEffectBinding>.NativeClassPtr; uint num2 = 0u; int num3 = IL2CPP.il2cpp_class_value_size(nativeClassPtr, ref num2); IntPtr intPtr3 = IL2CPP.il2cpp_class_get_field_from_name(nativeClassPtr, "<StatType>k__BackingField"); IntPtr intPtr4 = IL2CPP.il2cpp_class_get_field_from_name(nativeClassPtr, "<Effect>k__BackingField"); if (intPtr3 == IntPtr.Zero || intPtr4 == IntPtr.Zero) { why = "struct fields not found"; return false; } uint num4 = IL2CPP.il2cpp_field_get_offset(intPtr3); uint num5 = IL2CPP.il2cpp_field_get_offset(intPtr4); if (num4 >= num) { num4 -= num; } if (num5 >= num) { num5 -= num; } if (num3 <= 0 || num4 + 4 > num3 || num5 + IntPtr.Size > num3) { why = $"odd layout (size {num3}, stat {num4}, effect {num5})"; return false; } long num6 = Marshal.ReadInt64(intPtr2 + (int)num + IntPtr.Size); if (index < 0 || index >= num6) { why = $"slot {index} outside storage of {num6}"; return false; } IntPtr intPtr5 = intPtr2 + (int)num + IntPtr.Size * 2 + index * num3; for (int i = 0; i < num3; i++) { Marshal.WriteByte(intPtr5 + i, 0); } Marshal.WriteInt32(intPtr5 + (int)num4, stat); IL2CPP.il2cpp_gc_wbarrier_set_field(intPtr2, intPtr5 + (int)num5, effect); return true; } } internal static class Effects { private static BuffApplier? _applier; private static float _nextApplierLookup; private static int _applierTries; private static readonly List<StaticStatModifier> Permanent = new List<StaticStatModifier>(); private static PlayerStats? _permanentOwner; private static bool _loggedCheck; public static void Reset() { _applier = null; Permanent.Clear(); _permanentOwner = null; } private static BuffApplier? Applier(float now) { try { if ((Object)(object)_applier != (Object)null && !((Il2CppObjectBase)_applier).WasCollected) { return _applier; } } catch { _applier = null; } if (now < _nextApplierLookup) { return null; } _nextApplierLookup = now + Mathf.Min(4f, Mathf.Pow(2f, (float)_applierTries++)); ModLog.StepOnce("applier", "Effects: first BuffApplier lookup"); Object val = Object.FindObjectOfType(Il2CppType.Of<BuffApplier>()); _applier = ((val != (Object)null) ? ((Il2CppObjectBase)val).TryCast<BuffApplier>() : null); if ((Object)(object)_applier != (Object)null) { _applierTries = 0; } if ((Object)(object)_applier == (Object)null) { ModLog.WarnOnce("no-applier", "The game's BuffApplier was not found in this mission; timed trinkets do nothing."); } return _applier; } public static void ApplyTimed(ulong client, TrinketKind kind, float seconds, float now) { //IL_0074: Unknown result type (might be due to invalid IL or missing references) TrinketDef trinketDef = Trinkets.Of(kind); TrinketTuning trinketTuning = ModConfig.Tuning(kind); BuffApplier val = Applier(now); if ((Object)(object)val == (Object)null) { return; } try { float num = StatOf(client, trinketDef); StatType result; if (trinketDef.Effect == TrinketEffect.Invulnerable) { ModLog.StepOnce("invuln", "Effects: first ApplyInvincibilityBuff"); val.ApplyInvincibilityBuff(client, seconds); } else if (Enum.TryParse<StatType>(trinketDef.Stat, out result)) { EffectBindings.Now(Time.unscaledTime); ModLog.StepOnce("stat-buff", "Effects: first ApplyStatBuff"); val.ApplyStatBuff(client, result, trinketTuning.Strength, seconds); } if (ModConfig.LogEffects.Value) { ModLog.Info(FormattableString.Invariant($"{trinketDef.Name}: client {client}, {seconds:0.#} s piece (stat before {num:0.##}).")); } } catch (Exception ex) { ModLog.ErrorThrottled("apply-" + kind, ex, now); } } public static void CheckStat(ulong client, TrinketKind kind) { if (!_loggedCheck && ModConfig.LogEffects.Value) { TrinketDef trinketDef = Trinkets.Of(kind); if (trinketDef.Effect == TrinketEffect.TimedStat) { _loggedCheck = true; ModLog.Info(FormattableString.Invariant($"{trinketDef.Name}: client {client} {trinketDef.Stat} with the buff = {StatOf(client, trinketDef):0.##}.")); } } } private static float StatOf(ulong client, TrinketDef def) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) try { if (!Enum.TryParse<StatType>(def.Stat, out StatType result)) { return float.NaN; } GameplayPlayerManager instance = Singleton<GameplayPlayerManager>.Instance; return ((Object)(object)instance != (Object)null) ? instance.GetStatFor(client, result) : float.NaN; } catch { return float.NaN; } } public static void ApplyPermanentLocal(TrinketKind kind, float amount, float now) { //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Expected O, but got Unknown //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) TrinketDef trinketDef = Trinkets.Of(kind); try { switch (kind) { case TrinketKind.JackpotCoin: { int num = Math.Max(1, (int)Math.Round(amount)); int num2 = 0; for (int i = 0; i < num; i++) { if (GambleLink.AddPull(now)) { num2++; } } if (num2 > 0) { ModLog.Info($"Jackpot Coin: +{num2} Gamble pull(s)."); return; } LocalPlayer instance = SingletonPersistent<LocalPlayer>.Instance; if ((Object)(object)instance != (Object)null) { instance.AddGold(40); ModLog.Info("Jackpot Coin: no Gamble here, +40 gold instead."); } return; } case TrinketKind.GoldPouch: { LocalPlayer instance2 = SingletonPersistent<LocalPlayer>.Instance; if ((Object)(object)instance2 == (Object)null) { ModLog.WarnOnce("no-local-player", "LocalPlayer not found; the Gold Pouch gave nothing."); return; } int num3 = Math.Max(0, (int)Math.Round(amount)); ModLog.StepOnce("gold", "Effects: first LocalPlayer.AddGold"); instance2.AddGold(num3); ModLog.Info($"Gold Pouch: +{num3} gold (now {instance2.GetGold()})."); return; } } if (!Enum.TryParse<StatType>(trinketDef.Stat, out StatType result)) { return; } PlayerInfo? local = Players.Local; PlayerStats val = ((local != null) ? local.Identity.stats : null); if (!((Object)(object)val == (Object)null)) { if ((Object)(object)_permanentOwner == (Object)null || ((Il2CppObjectBase)val).Pointer != ((Il2CppObjectBase)_permanentOwner).Pointer) { Permanent.Clear(); _permanentOwner = val; } StaticStatModifier val2 = new StaticStatModifier(); val2.StatType = result; val2.Value = amount; ModLog.StepOnce("permanent", "Effects: first AddCharacterStatModifier"); val.AddCharacterStatModifier((StatModifier)(object)val2); Permanent.Add(val2); ModLog.Info(FormattableString.Invariant($"{trinketDef.Name}: +{amount:0.##} {result}, now {val.GetCharacterValue(result):0.##}.")); } } catch (Exception ex) { ModLog.ErrorThrottled("permanent-" + kind, ex, now); } } } internal static class EliteWatcher { private sealed class Seen { public Vector3 Position; public float HealthFraction = 1f; public bool Reported; public int Frame; public Enemy? Enemy; public EnemyHealthContainer? Health; } private const float SweepSeconds = 0.25f; private static float _nextSweep; private static readonly Dictionary<int, Seen> Tracked = new Dictionary<int, Seen>(); private static readonly List<int> Gone = new List<int>(); private static readonly HashSet<int> EliteTypes = new HashSet<int>(); private static IntPtr _runPtr; private static int _frame; public static Action<Vector3>? Killed; public static void Reset() { Tracked.Clear(); EliteTypes.Clear(); _runPtr = IntPtr.Zero; _nextSweep = 0f; } public static void Update(RunManager rm) { //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Expected I4, but got Unknown //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_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0399: Unknown result type (might be due to invalid IL or missing references) if (((Il2CppObjectBase)rm).Pointer != _runPtr) { Reset(); _runPtr = ((Il2CppObjectBase)rm).Pointer; AddElites(rm.Configuration); AddElites(rm.verdantMeadowsConfiguration); AddElites(rm.frozenAncientsConfiguration); AddElites(rm.pyrestormPitConfiguration); AddElites(rm.astralPlanesConfiguration); AddElites(rm.swampConfiguration); ModLog.Info($"Run started: {EliteTypes.Count} elite enemy types can drop trinkets."); } foreach (Seen value2 in Tracked.Values) { try { Enemy enemy = value2.Enemy; if (!((Object)(object)enemy == (Object)null) && ((Behaviour)enemy).isActiveAndEnabled) { value2.Position = ((Component)enemy).transform.position; EnemyHealthContainer health = value2.Health; if ((Object)(object)health != (Object)null && ((HealthContainer)health).MaxHealth > 0f) { value2.HealthFraction = ((HealthContainer)health).CurrentHealth / ((HealthContainer)health).MaxHealth; } if (value2.HealthFraction <= 0f && !value2.Reported) { value2.Reported = true; Killed?.Invoke(value2.Position); } } } catch (Exception ex) { ModLog.ErrorThrottled("elite", ex, Time.unscaledTime, 30f); } } float unscaledTime = Time.unscaledTime; if (unscaledTime < _nextSweep) { return; } _nextSweep = unscaledTime + 0.25f; List<Enemy> allEnemies = Enemy.AllEnemies; if (allEnemies == null) { return; } _frame++; for (int i = 0; i < allEnemies.Count; i++) { Enemy val = allEnemies[i]; if ((Object)(object)val == (Object)null) { continue; } try { if (!EliteTypes.Contains((int)val.EnemyType)) { continue; } int instanceID = ((Object)val).GetInstanceID(); if (!Tracked.TryGetValue(instanceID, out Seen value)) { value = new Seen { Enemy = val, Health = ((Component)val).GetComponent<EnemyHealthContainer>() }; Tracked[instanceID] = value; if (((Behaviour)val).isActiveAndEnabled) { value.Position = ((Component)val).transform.position; if ((Object)(object)value.Health != (Object)null && ((HealthContainer)value.Health).MaxHealth > 0f) { value.HealthFraction = ((HealthContainer)value.Health).CurrentHealth / ((HealthContainer)value.Health).MaxHealth; } } } value.Frame = _frame; } catch (Exception ex2) { ModLog.ErrorThrottled("elite", ex2, Time.unscaledTime, 30f); } } Gone.Clear(); foreach (KeyValuePair<int, Seen> item in Tracked) { if (item.Value.Frame != _frame) { Gone.Add(item.Key); } } foreach (int item2 in Gone) { Seen seen = Tracked[item2]; Tracked.Remove(item2); if (!seen.Reported && seen.HealthFraction <= 0.35f) { Killed?.Invoke(seen.Position); } } } private static void AddElites(RunConfiguration? cfg) { try { if ((Object)(object)cfg == (Object)null) { return; } List<EliteEnemyConfiguration> eliteEnemies = cfg.EliteEnemies; if (eliteEnemies == null) { return; } for (int i = 0; i < eliteEnemies.Count; i++) { EliteEnemyConfiguration val = eliteEnemies[i]; if (!((Object)(object)val == (Object)null)) { AddWeighted(val.weightedEnemies); AddWeighted(val.weightedEnemiesAfterFirstCycle); } } } catch (Exception ex) { ModLog.WarnOnce("elites", "Could not read the run's elite enemy types: " + ex.Message); } } private static void AddWeighted(List<WeightedEnemy>? weighted) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected I4, but got Unknown if (weighted == null) { return; } for (int i = 0; i < weighted.Count; i++) { WeightedEnemy val = weighted[i]; if (val != null) { EliteTypes.Add((int)val.Enemy); } } } } internal static class GambleLink { private static PropertyInfo? _canGamble; private static MethodInfo? _addPull; private static bool _looked; private static float _nextLook; private static readonly object[] Args = new object[1]; public static bool CanGamble(float now) { if (!Find(now)) { return false; } try { object value = _canGamble.GetValue(null); return value is bool && (bool)value; } catch (Exception ex) { Broken(ex); return false; } } public static bool AddPull(float now) { if (!Find(now)) { return false; } try { Args[0] = "Jackpot Coin"; object obj = _addPull.Invoke(null, Args); return obj is bool && (bool)obj; } catch (Exception ex) { Broken(ex); return false; } } private static void Broken(Exception ex) { _canGamble = null; _addPull = null; _nextLook = float.MaxValue; ModLog.Warn("Arcane Row's Gamble could not be reached; the Jackpot Coin is off. " + ex.GetBaseException().Message); } private static bool Find(float now) { if (_canGamble != null && _addPull != null) { return true; } if (_looked && now < _nextLook) { return false; } _looked = true; _nextLook = now + 10f; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (!(assembly.GetName().Name != "SpellBrigadeArcane")) { Type? type = assembly.GetType("SpellBrigadeArcane.GambleApi"); PropertyInfo propertyInfo = type?.GetProperty("CanGamble", BindingFlags.Static | BindingFlags.Public); MethodInfo methodInfo = type?.GetMethod("AddPull", new Type[1] { typeof(string) }); if (propertyInfo != null && methodInfo != null) { _canGamble = propertyInfo; _addPull = methodInfo; ModLog.Info("Arcane Row's Gamble found: the Jackpot Coin can drop for wizards with Gamble."); return true; } ModLog.InfoOnce("gamble-old", "Arcane Row is installed but has no GambleApi yet, so the Jackpot Coin does not drop."); return false; } } return false; } } internal static class HostDirector { private sealed class LyingOrb { public OrbInfo Info; public float Born; } private const float ResendSeconds = 2f; private static readonly Dictionary<int, LyingOrb> Orbs = new Dictionary<int, LyingOrb>(); private static readonly List<int> Expired = new List<int>(); private static readonly BuffLedger Ledger = new BuffLedger(); private static readonly Random Rng = new Random(); private static IntPtr _missionPtr; private static int _nextId = 1; private static float _nextMapSpawn; private static float _nextResend; private static bool _dirty; private static int _cycle; private static bool _hooked; private static float _checkAt = -1f; private static (ulong Client, TrinketKind Kind) _check; public static bool Active => _missionPtr != IntPtr.Zero; public static void Reset() { bool num = Orbs.Count > 0; Orbs.Clear(); Ledger.Clear(); _missionPtr = IntPtr.Zero; EliteWatcher.Reset(); if (num) { Net.SendToAll(Messages.Orbs(Array.Empty<OrbInfo>())); } } public static void Update(float now) { if (!_hooked) { _hooked = true; EliteWatcher.Killed = (Action<Vector3>)Delegate.Combine(EliteWatcher.Killed, new Action<Vector3>(OnEliteKilled)); } RunManager instance = NetworkSingleton<RunManager>.Instance; PlayerInfo local = Players.Local; if ((Object)(object)instance == (Object)null || local == null || !ModConfig.Enabled.Value) { if (Active) { Reset(); } return; } IntPtr pointer = ((Il2CppObjectBase)local.Identity).Pointer; if (pointer != _missionPtr) { Reset(); _missionPtr = pointer; _nextMapSpawn = now + ModConfig.FirstMapSpawnSeconds.Value; _dirty = true; ModLog.Info("Mission started: trinkets are on."); } float unscaledTime = Time.unscaledTime; long start = Timing.Begin(); EliteWatcher.Update(instance); Timing.End("host/elites", start, unscaledTime); start = Timing.Begin(); MapSpawn(now); Expire(now); Pickups(now); Timing.End("host/spawn-pickups", start, unscaledTime); foreach (BuffLedger.Piece item in Ledger.Tick(now)) { Effects.ApplyTimed(item.Client, item.Kind, item.Seconds, now); } if (_checkAt > 0f && now >= _checkAt) { _checkAt = -1f; Effects.CheckStat(_check.Client, _check.Kind); } if (!_dirty && !(now >= _nextResend)) { return; } _dirty = false; _nextResend = now + 2f; List<OrbInfo> list = new List<OrbInfo>(); foreach (LyingOrb value in Orbs.Values) { list.Add(value.Info); } start = Timing.Begin(); Net.SendToAll(Messages.Orbs(list)); Timing.End("host/send-orbs", start, unscaledTime); } private static void OnEliteKilled(Vector3 position) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (Active) { float value = ModConfig.EliteDropChance.Value; if (!(Rng.NextDouble() >= (double)value)) { Spawn(position, null, "an elite"); } } } private static void MapSpawn(float now) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) float value = ModConfig.MapSpawnSeconds.Value; if (value <= 0f || now < _nextMapSpawn) { return; } _nextMapSpawn = now + value; if (Orbs.Count < ModConfig.MaxOnGround.Value) { Vector3? val = MapPosition(); if (val.HasValue) { Spawn(val.Value, null, "the map"); } } } private static Vector3? MapPosition() { //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0150: 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_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) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) List<PlayerInfo> list = new List<PlayerInfo>(); foreach (PlayerInfo item in Players.All) { if (item.Alive && (Object)(object)item.Body != (Object)null) { list.Add(item); } } if (list.Count == 0) { return null; } Vector3 position = list[Rng.Next(list.Count)].Body.position; try { PickupSpawner instance = NetworkSingleton<PickupSpawner>.Instance; IMapPositionProvider val = (((Object)(object)instance != (Object)null) ? instance.mapPositionProvider : null); if (val != null && val.IsReady) { ModLog.StepOnce("map-pos", "HostDirector: first GetRandomPosition"); Vector3 randomPosition = val.GetRandomPosition(position, 10f, 24f); randomPosition.y = position.y; return randomPosition; } } catch (Exception ex) { ModLog.WarnOnce("map-pos", "The map's free spots could not be read (" + ex.Message + "); trinkets land near a wizard instead."); } float num = (float)(Rng.NextDouble() * Math.PI * 2.0); return position + new Vector3(Mathf.Cos(num), 0f, Mathf.Sin(num)) * 8f; } public static void Spawn(Vector3 position, TrinketKind? kind, string source) { //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) if (!Active) { return; } if (!kind.HasValue) { List<(TrinketKind, float)> list = new List<(TrinketKind, float)>(); bool flag = GambleLink.CanGamble(Time.time); TrinketDef[] all = Trinkets.All; foreach (TrinketDef trinketDef in all) { if (trinketDef.Kind != TrinketKind.JackpotCoin || flag) { list.Add((trinketDef.Kind, ModConfig.Tuning(trinketDef.Kind).Weight)); } } kind = TrinketRules.Pick(list, Rng.NextDouble()); if (!kind.HasValue) { return; } } OrbInfo info = new OrbInfo { Id = _nextId++, Kind = kind.Value, X = position.x, Y = position.y, Z = position.z }; Orbs[info.Id] = new LyingOrb { Info = info, Born = Time.time }; _dirty = true; if (ModConfig.LogEffects.Value) { ModLog.Info(FormattableString.Invariant($"Spawned {Trinkets.Of(kind.Value).Name} #{info.Id} from {source} at ({position.x:0.#}, {position.z:0.#}).")); } } public static void SpawnTest(bool all) { //IL_0028: 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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) PlayerInfo local = Players.Local; if (!Active || (Object)(object)local?.Body == (Object)null) { return; } Vector3 position = local.Body.position + local.Body.forward * 2.5f; if (all) { for (int i = 0; i < Trinkets.All.Length; i++) { float num = (float)i * (float)Math.PI * 2f / (float)Trinkets.All.Length; Spawn(local.Body.position + new Vector3(Mathf.Cos(num), 0f, Mathf.Sin(num)) * 3.5f, Trinkets.All[i].Kind, "Ctrl+Shift+T"); } } else { Spawn(position, Trinkets.All[_cycle++ % Trinkets.All.Length].Kind, "Ctrl+T"); } } public static bool TestTake(TrinketKind kind) { PlayerInfo local = Players.Local; if (!Active || local == null) { return false; } foreach (KeyValuePair<int, LyingOrb> orb in Orbs) { if (orb.Value.Info.Kind == kind) { Orbs.Remove(orb.Key); _dirty = true; Take(orb.Value.Info, local.Client, Time.time); return true; } } return false; } private static void Expire(float now) { float value = ModConfig.OrbLifetime.Value; if (value <= 0f) { return; } Expired.Clear(); foreach (KeyValuePair<int, LyingOrb> orb in Orbs) { if (now - orb.Value.Born >= value) { Expired.Add(orb.Key); } } foreach (int item in Expired) { Orbs.Remove(item); } if (Expired.Count > 0) { _dirty = true; } } private static void Pickups(float now) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) if (Orbs.Count == 0) { return; } float value = ModConfig.PickupRadius.Value; float num = value * value; Expired.Clear(); foreach (KeyValuePair<int, LyingOrb> orb in Orbs) { OrbInfo info = orb.Value.Info; foreach (PlayerInfo item in Players.All) { if (item.Alive && !((Object)(object)item.Body == (Object)null)) { Vector3 position = item.Body.position; float num2 = position.x - info.X; float num3 = position.z - info.Z; if (!(num2 * num2 + num3 * num3 > num)) { Expired.Add(orb.Key); Take(info, item.Client, now); break; } } } } foreach (int item2 in Expired) { Orbs.Remove(item2); } if (Expired.Count > 0) { _dirty = true; } } private static void Take(OrbInfo orb, ulong picker, float now) { TrinketDef trinketDef = Trinkets.Of(orb.Kind); TrinketTuning trinketTuning = ModConfig.Tuning(orb.Kind); if (ModConfig.LogEffects.Value) { ModLog.Info($"{trinketDef.Name} #{orb.Id} picked up by client {picker}."); } Net.SendToAll(Messages.Taken(orb.Id, picker, orb.Kind)); if (trinketDef.Effect == TrinketEffect.PermanentStat) { Net.SendToAll(Messages.Permanent((trinketDef.Target == TrinketTarget.Team) ? ((ulong?)null) : new ulong?(picker), orb.Kind, trinketTuning.Strength)); return; } List<ulong> list = new List<ulong>(); if (trinketDef.Target == TrinketTarget.Team) { foreach (PlayerInfo item in Players.All) { list.Add(item.Client); } } else { list.Add(picker); } foreach (ulong item2 in list) { float pieceNow; BuffLedger.Entry entry = Ledger.Grant(item2, orb.Kind, now, trinketTuning.Seconds, ModConfig.MaxBuffSeconds.Value, out pieceNow); if (pieceNow > 0f) { Effects.ApplyTimed(item2, orb.Kind, pieceNow, now); if (_checkAt < 0f) { _checkAt = now + 0.5f; _check = (Client: item2, Kind: orb.Kind); } } Net.SendToAll(Messages.Buff(item2, orb.Kind, entry.TotalEnd - now, entry.Full)); } } } internal static class HudPlacer { private struct Box { public Rect R; public string Name; } private const float ScanSeconds = 1f; private static readonly List<Box> Boxes = new List<Box>(); private static readonly List<Graphic> _graphics = new List<Graphic>(); private static readonly List<Graphic> _candidates = new List<Graphic>(); private static bool _rescan = true; private static int _scanW; private static int _scanH; private static Rect? _bar; private static string _barName = ""; private static float _nextScan; private static bool _loggedLayout; private static string _lastSpot = ""; private static PlayerHealthDisplay? _health; private static float _nextHealthLookup; private static int _healthTries; private static readonly Il2CppStructArray<Vector3> Corners = new Il2CppStructArray<Vector3>(4L); public static Rect? Bar => _bar; public static Rect? LastRow { get; private set; } public static float TipEdge { get; private set; } public static void Rescan() { _rescan = true; } public static (string Name, Rect Box)? Overlapping(Rect r) { //IL_0016: 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) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) foreach (Box box in Boxes) { Rect r2 = box.R; if (((Rect)(ref r2)).Overlaps(r)) { return (box.Name, box.R); } } return null; } private static Rect? HealthBar(float now) { try { if ((Object)(object)_health != (Object)null && ((Il2CppObjectBase)_health).WasCollected) { _health = null; } if ((Object)(object)_health != (Object)null && !((Behaviour)_health).isActiveAndEnabled) { return null; } if ((Object)(object)_health == (Object)null) { if (now < _nextHealthLookup) { return null; } _nextHealthLookup = now + Mathf.Min(30f, Mathf.Pow(2f, (float)_healthTries++)); foreach (Object item in (Il2CppArrayBase<Object>)(object)Object.FindObjectsOfType(Il2CppType.Of<PlayerHealthDisplay>())) { PlayerHealthDisplay val = ((item != null) ? ((Il2CppObjectBase)item).TryCast<PlayerHealthDisplay>() : null); if ((Object)(object)val != (Object)null && ((Behaviour)val).isActiveAndEnabled) { _health = val; break; } } if ((Object)(object)_health == (Object)null) { return null; } _healthTries = 0; } Rect? r = null; Add(ref r, ((Object)(object)_health.bar != (Object)null) ? ((Component)_health.bar).GetComponent<RectTransform>() : null); if ((Object)(object)_health.leftCorner != (Object)null && _health.leftCorner.activeInHierarchy) { Add(ref r, _health.leftCorner.GetComponent<RectTransform>()); } if ((Object)(object)_health.rightCorner != (Object)null && _health.rightCorner.activeInHierarchy) { Add(ref r, _health.rightCorner.GetComponent<RectTransform>()); } if (!r.HasValue) { Add(ref r, ((Component)_health).GetComponent<RectTransform>()); } return r; } catch (Exception ex) { _health = null; _nextHealthLookup = now + 10f; ModLog.WarnOnce("health-bar", "The game's health bar could not be measured (" + ex.Message + "); guessing its place instead."); return null; } } private static void Add(ref Rect? r, RectTransform? rt) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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_0059: 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_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: 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) if ((Object)(object)rt == (Object)null) { return; } Rect? val = ScreenBox(rt); if (val.HasValue) { Rect? val2; if (r.HasValue) { Rect value = r.Value; float xMin = ((Rect)(ref value)).xMin; value = val.Value; float num = Mathf.Min(xMin, ((Rect)(ref value)).xMin); value = r.Value; float yMin = ((Rect)(ref value)).yMin; value = val.Value; float num2 = Mathf.Min(yMin, ((Rect)(ref value)).yMin); value = r.Value; float xMax = ((Rect)(ref value)).xMax; value = val.Value; float num3 = Mathf.Max(xMax, ((Rect)(ref value)).xMax); value = r.Value; float yMax = ((Rect)(ref value)).yMax; value = val.Value; val2 = Rect.MinMaxRect(num, num2, num3, Mathf.Max(yMax, ((Rect)(ref value)).yMax)); } else { val2 = val; } r = val2; } } private static Rect? ScreenBox(RectTransform rt) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Invalid comparison between Unknown and I4 //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Invalid comparison between Unknown and I4 //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: 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_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) Canvas val = null; Transform val2 = ((Component)rt).transform; while ((Object)(object)val2 != (Object)null && (Object)(object)val == (Object)null) { val = ((Component)val2).GetComponent<Canvas>(); val2 = val2.parent; } if ((Object)(object)val == (Object)null) { return null; } Canvas rootCanvas = val.rootCanvas; if ((int)rootCanvas.renderMode == 2) { return null; } Camera cam = (((int)rootCanvas.renderMode == 1) ? rootCanvas.worldCamera : null); rt.GetWorldCorners(Corners); float num = float.MaxValue; float num2 = float.MaxValue; float num3 = float.MinValue; float num4 = float.MinValue; for (int i = 0; i < 4; i++) { Vector2 val3 = ToScreen(((Il2CppArrayBase<Vector3>)(object)Corners)[i], cam); num = Mathf.Min(num, val3.x); num3 = Mathf.Max(num3, val3.x); num2 = Mathf.Min(num2, val3.y); num4 = Mathf.Max(num4, val3.y); } if (!(num3 - num < 1f) && !(num4 - num2 < 1f)) { return Rect.MinMaxRect(num, num2, num3, num4); } return null; } private static bool Visible(Graphic g) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) if (g.color.a < 0.1f) { return false; } CanvasRenderer canvasRenderer = g.canvasRenderer; if ((Object)(object)canvasRenderer != (Object)null && canvasRenderer.cull) { return false; } float num = 1f; Transform val = ((Component)g).transform; while ((Object)(object)val != (Object)null) { CanvasGroup component = ((Component)val).GetComponent<CanvasGroup>(); if (!((Object)(object)component == (Object)null) && ((Behaviour)component).enabled) { num *= component.alpha; if (component.ignoreParentGroups || num < 0.1f) { break; } } val = val.parent; } return num >= 0.1f; } public static void Scan(float now, IntPtr ownCanvas) { //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Invalid comparison between Unknown and I4 //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) if (now < _nextScan) { return; } _nextScan = now + 1f; Boxes.Clear(); float num = Screen.width; float num2 = Screen.height; try { _bar = HealthBar(now); _barName = (_bar.HasValue ? "PlayerHealthDisplay" : ""); bool flag = _rescan || Screen.width != _scanW || Screen.height != _scanH; long start = Timing.Begin(); if (flag) { _rescan = false; _scanW = Screen.width; _scanH = Screen.height; _graphics.Clear(); foreach (Graphic item in Object.FindObjectsOfType<Graphic>()) { if ((Object)(object)item != (Object)null) { _graphics.Add(item); } } } List<Graphic> list = (flag ? _graphics : _candidates); if (flag) { _candidates.Clear(); } int num3 = 0; foreach (Graphic item2 in list) { try { if ((Object)(object)item2 == (Object)null || ((Il2CppObjectBase)item2).WasCollected || !((Behaviour)item2).isActiveAndEnabled) { continue; } Canvas canvas = item2.canvas; if ((Object)(object)canvas == (Object)null) { continue; } Canvas rootCanvas = canvas.rootCanvas; if ((Object)(object)rootCanvas == (Object)null || ((Il2CppObjectBase)rootCanvas).Pointer == ownCanvas || !((Behaviour)rootCanvas).isActiveAndEnabled || (int)rootCanvas.renderMode == 2) { continue; } Rect? val = ScreenBox(item2.rectTransform); if (!val.HasValue) { continue; } Rect value = val.Value; if (!(((Rect)(ref value)).width < 4f) && !(((Rect)(ref value)).height < 4f) && !(((Rect)(ref value)).xMax < 0f) && !(((Rect)(ref value)).yMax < 0f) && !(((Rect)(ref value)).xMin > num) && !(((Rect)(ref value)).yMin > num2) && !(((Rect)(ref value)).yMin > num2 * 0.5f) && !(((Rect)(ref value)).width > num * 0.4f) && !(((Rect)(ref value)).height > num2 * 0.4f)) { if (flag) { _candidates.Add(item2); } if (Visible(item2)) { Boxes.Add(new Box { R = value, Name = ((Object)((Component)item2).gameObject).name }); } } } catch (Exception ex) { if (num3++ == 0) { ModLog.WarnOnce("hud-scan-item", $"One HUD piece could not be measured ({ex.GetType().Name}: {ex.Message}); skipped."); } } } if (flag) { _graphics.Clear(); } Timing.End(flag ? "hud/full-scan" : "hud/re-measure", start, now); } catch (Exception ex2) { _nextScan = now + 10f; ModLog.ErrorThrottled("hud-scan", ex2, now, 60f); } } private static Vector2 ToScreen(Vector3 world, Camera? cam) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)cam == (Object)null)) { return RectTransformUtility.WorldToScreenPoint(cam, world); } return new Vector2(world.x, world.y); } public static Vector2 Place(float rowW, float rowH, float px) { //IL_0058: 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_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0118: 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_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: 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_0280: 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_028f: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: 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_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0202: 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_01ec: 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) float num = Screen.width; float num2 = Screen.height; float num3 = 18f * px; Rect val = (Rect)(((??)_bar) ?? new Rect(num / 2f - 550f * px, ModConfig.HudBottom.Value * px, 1100f * px, 30f * px)); bool flag = !string.Equals(ModConfig.HudSide.Value, "Left", StringComparison.OrdinalIgnoreCase); Rect value; if (flag) { float num4 = ((Rect)(ref val)).center.y - rowH / 2f; float num5 = Mathf.Max(((Rect)(ref val)).yMin - 4f * px, num4); float num6 = ((Rect)(ref val)).xMax + num3; float xMax = ((Rect)(ref val)).xMax; Rect val2 = default(Rect); for (int i = 0; i < 40; i++) { if (!(num6 + rowW <= num - 4f * px)) { break; } ((Rect)(ref val2))..ctor(num6, num5, rowW, rowH); Rect? val3 = FirstHit(val2); if (!val3.HasValue) { TipEdge = xMax; return Report(val2, (i == 0) ? "beside the bar's right tip" : "beside the bar's right tip, past other HUD art"); } value = val3.Value; xMax = ((Rect)(ref value)).xMax; value = val3.Value; num6 = ((Rect)(ref value)).xMax + num3; } } Rect val4 = default(Rect); for (int j = 0; j < 2; j++) { bool flag2 = ((j == 0) ? flag : (!flag)); float num7 = ((Rect)(ref val)).yMax + num3 * 0.5f; float num8 = (flag2 ? (((Rect)(ref val)).xMax - rowW) : ((Rect)(ref val)).xMin); for (int k = 0; k < 40; k++) { if (num8 < 4f * px) { break; } if (num8 + rowW > num - 4f * px) { break; } ((Rect)(ref val4))..ctor(num8, num7, rowW, rowH); Rect? val5 = FirstHit(val4); if (!val5.HasValue) { return Report(val4, flag2 ? "above the bar, right end" : "above the bar, left end"); } float num9; if (!flag2) { value = val5.Value; num9 = ((Rect)(ref value)).xMin - num3 - rowW; } else { value = val5.Value; num9 = ((Rect)(ref value)).xMax + num3; } num8 = num9; } } float num10 = (flag ? (((Rect)(ref val)).xMax - rowW) : ((Rect)(ref val)).xMin); float num11 = ((Rect)(ref val)).yMax + num3; Rect val6 = default(Rect); for (int l = 0; l < 40; l++) { ((Rect)(ref val6))..ctor(num10, num11, rowW, rowH); Rect? val7 = FirstHit(val6); if (!val7.HasValue || num11 + rowH > num2 * 0.6f) { return Report(val6, "above the bar"); } value = val7.Value; num11 = ((Rect)(ref value)).yMax + num3; } return Report(new Rect(num10, ((Rect)(ref val)).yMax + num3, rowW, rowH), "above the bar (crowded)"); } private static Rect? FirstHit(Rect want) { //IL_0021: 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_0029: 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_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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_0064: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing refe