Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ChestRadar v1.3.0
ChestRadar.dll
Decompiled 3 weeks agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using Microsoft.CodeAnalysis; using RoR2; using RoR2.UI; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ChestRadar")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("ChestRadar")] [assembly: AssemblyTitle("ChestRadar")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ChestRadar { [BepInPlugin("ivan.ChestRadar", "ChestRadar", "1.3.0")] public class ChestRadarPlugin : BaseUnityPlugin { private enum Category { Chest, Shrine, Printer, Drone, Shop, Lunar, Teleporter, Portal, Other } private class Target { public GameObject gameObject; public PurchaseInteraction purchase; public BarrelInteraction barrel; public GenericInteraction generic; public Category category; public string label; public Renderer[] renderers; } public const string GUID = "ivan.ChestRadar"; public const string NAME = "ChestRadar"; public const string VERSION = "1.3.0"; private const float ScanInterval = 0.5f; private const string IndicatorPrefabPath = "Prefabs/PositionIndicators/PoiPositionIndicator"; private readonly Dictionary<GameObject, PositionIndicator> indicators = new Dictionary<GameObject, PositionIndicator>(); private GameObject indicatorPrefab; private bool prefabRequested; private float stageStartTime = -999f; private ConfigEntry<bool> markersOn; private ConfigEntry<KeyboardShortcut> toggleKey; private ConfigEntry<float> maxDistance; private ConfigEntry<bool> useGameIcons; private ConfigEntry<bool> showText; private ConfigEntry<bool> showNames; private ConfigEntry<bool> showDistance; private ConfigEntry<bool> showCost; private ConfigEntry<int> fontSize; private ConfigEntry<float> markerSize; private ConfigEntry<bool> outlineHighlight; private ConfigEntry<bool> showBarrels; private readonly Dictionary<Category, ConfigEntry<bool>> showCategory = new Dictionary<Category, ConfigEntry<bool>>(); private readonly Dictionary<Category, ConfigEntry<Color>> categoryColor = new Dictionary<Category, ConfigEntry<Color>>(); private readonly List<Target> targets = new List<Target>(); private float nextScan; private bool gameIconsBroken; private GUIStyle labelStyle; private GUIStyle shadowStyle; private void Awake() { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0229: 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_0269: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) markersOn = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Show markers. F7 (or ToggleKey) flips this in game."); toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleKey", new KeyboardShortcut((KeyCode)288, Array.Empty<KeyCode>()), "Key that shows/hides the markers."); maxDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxDistance", 0f, "Only mark things closer than this many meters. 0 = whole map."); useGameIcons = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "UseGameIcons", true, "Use the same icons as the Radar Scanner (seen through walls). If false, a colored square is drawn instead."); showText = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowText", true, "Show a text label under each icon."); showNames = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowNames", true, "Include the name in the label."); showDistance = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowDistance", true, "Include the distance in meters in the label."); showCost = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowCost", true, "Include the gold price in the label."); fontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Display", "FontSize", 13, "Text size of the labels."); markerSize = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "SquareSize", 10f, "Size of the square when UseGameIcons is false."); outlineHighlight = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "Outline", true, "Draw the game's outline (same as when you ping something) around each marked object, in its category color, through walls."); BindCategory(Category.Chest, "chests (normal, large, legendary, category, cloaked, lockboxes, equipment barrels)", new Color(1f, 0.85f, 0.2f)); BindCategory(Category.Shrine, "shrines", new Color(0.4f, 0.8f, 1f)); BindCategory(Category.Printer, "3D printers", new Color(1f, 0.55f, 0.1f)); BindCategory(Category.Drone, "broken drones and turrets", new Color(0.5f, 1f, 0.5f)); BindCategory(Category.Shop, "multishop terminals", Color.white); BindCategory(Category.Lunar, "lunar pods and Newt altars", new Color(0.55f, 0.6f, 1f)); BindCategory(Category.Teleporter, "the teleporter", new Color(1f, 0.3f, 0.3f)); BindCategory(Category.Portal, "portals (shop, gold, celestial, void...)", new Color(0.3f, 1f, 1f)); BindCategory(Category.Other, "other paid interactables", new Color(0.8f, 0.8f, 0.8f)); showBarrels = ((BaseUnityPlugin)this).Config.Bind<bool>("Categories", "MoneyBarrels", false, "Also mark money barrels (free, and there are many)."); Stage.onStageStartGlobal += delegate { targets.Clear(); ClearIndicators(); stageStartTime = Time.unscaledTime; nextScan = Time.unscaledTime + 1f; }; OutlineHighlight.onPreRenderOutlineHighlight = (Action<OutlineHighlight>)Delegate.Combine(OutlineHighlight.onPreRenderOutlineHighlight, new Action<OutlineHighlight>(OnPreRenderOutline)); } private void BindCategory(Category c, string description, Color color) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) showCategory[c] = ((BaseUnityPlugin)this).Config.Bind<bool>("Categories", c.ToString(), true, "Mark " + description + "."); categoryColor[c] = ((BaseUnityPlugin)this).Config.Bind<Color>("Colors", c.ToString(), color, "Label color for " + description + "."); } private void Update() { //IL_0006: 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) KeyboardShortcut value = toggleKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { markersOn.Value = !markersOn.Value; if (!markersOn.Value) { ClearIndicators(); } nextScan = 0f; } if (!markersOn.Value || (Object)(object)Run.instance == (Object)null) { if (targets.Count > 0 || indicators.Count > 0) { targets.Clear(); ClearIndicators(); } } else if (Time.unscaledTime >= nextScan) { nextScan = Time.unscaledTime + 0.5f; Scan(); Reveal(); } } private void OnDestroy() { OutlineHighlight.onPreRenderOutlineHighlight = (Action<OutlineHighlight>)Delegate.Remove(OutlineHighlight.onPreRenderOutlineHighlight, new Action<OutlineHighlight>(OnPreRenderOutline)); ClearIndicators(); } private void Scan() { //IL_0123: Unknown result type (might be due to invalid IL or missing references) targets.Clear(); PurchaseInteraction[] array = Object.FindObjectsOfType<PurchaseInteraction>(); foreach (PurchaseInteraction val in array) { if (Object.op_Implicit((Object)(object)val) && val.available) { Add(((Component)val).gameObject, Classify(((Object)((Component)val).gameObject).name), val.GetDisplayName(), val); } } if (showBarrels.Value) { BarrelInteraction[] array2 = Object.FindObjectsOfType<BarrelInteraction>(); foreach (BarrelInteraction val2 in array2) { if (Object.op_Implicit((Object)(object)val2) && !val2.Networkopened) { Add(((Component)val2).gameObject, Category.Other, Language.GetString(val2.displayNameToken), null, val2); } } } TeleporterInteraction instance = TeleporterInteraction.instance; if (Object.op_Implicit((Object)(object)instance) && !instance.isCharged) { Add(((Component)instance).gameObject, Category.Teleporter, NameOf(((Component)instance).gameObject, "Teleporter")); } SceneExitController[] array3 = Object.FindObjectsOfType<SceneExitController>(); foreach (SceneExitController val3 in array3) { if (Object.op_Implicit((Object)(object)val3) && !Object.op_Implicit((Object)(object)((Component)val3).GetComponent<TeleporterInteraction>())) { GenericInteraction component = ((Component)val3).GetComponent<GenericInteraction>(); if (!Object.op_Implicit((Object)(object)component) || (int)component.interactability != 0) { Add(((Component)val3).gameObject, Category.Portal, NameOf(((Component)val3).gameObject, "Portal"), null, null, component); } } } foreach (Target target in targets) { target.renderers = FindRenderers(target.gameObject); } } private void Add(GameObject go, Category cat, string label, PurchaseInteraction purchase = null, BarrelInteraction barrel = null, GenericInteraction generic = null) { if (showCategory[cat].Value) { targets.Add(new Target { gameObject = go, category = cat, label = label, purchase = purchase, barrel = barrel, generic = generic }); } } private static string NameOf(GameObject go, string fallback) { IDisplayNameProvider component = go.GetComponent<IDisplayNameProvider>(); string text = ((component != null) ? component.GetDisplayName() : null); if (!string.IsNullOrEmpty(text)) { return text; } return fallback; } private static Category Classify(string objectName) { string text = objectName.ToLowerInvariant(); if (text.Contains("lunarchest") || text.Contains("newtstatue")) { return Category.Lunar; } if (text.Contains("shrine")) { return Category.Shrine; } if (text.Contains("duplicator")) { return Category.Printer; } if (text.Contains("drone") || text.Contains("turret")) { return Category.Drone; } if (text.Contains("multishop") || text.Contains("shopterminal")) { return Category.Shop; } if (text.Contains("chest") || text.Contains("lockbox") || text.Contains("barrel")) { return Category.Chest; } return Category.Other; } private bool StillValid(Target t) { //IL_005a: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)t.gameObject)) { return false; } if (Object.op_Implicit((Object)(object)t.purchase) && !t.purchase.available) { return false; } if (Object.op_Implicit((Object)(object)t.barrel) && t.barrel.Networkopened) { return false; } if (Object.op_Implicit((Object)(object)t.generic) && (int)t.generic.interactability == 0) { return false; } return true; } private bool InRange(Camera cam, Vector3 pos, out float dist) { //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) dist = (Object.op_Implicit((Object)(object)cam) ? Vector3.Distance(((Component)cam).transform.position, pos) : 0f); if (!(maxDistance.Value <= 0f)) { return dist <= maxDistance.Value; } return true; } private void Reveal() { //IL_00b1: 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_0115: Unknown result type (might be due to invalid IL or missing references) if (!useGameIcons.Value || gameIconsBroken) { ClearIndicators(); } else if (!Object.op_Implicit((Object)(object)indicatorPrefab)) { if (!prefabRequested) { prefabRequested = true; LegacyResourcesAPI.LoadAsyncCallback<GameObject>("Prefabs/PositionIndicators/PoiPositionIndicator", (Action<GameObject>)delegate(GameObject p) { indicatorPrefab = p; }); } } else { if ((Object)(object)Stage.instance == (Object)null || Time.unscaledTime - stageStartTime < 1f) { return; } Camera camera = GetCamera(); HashSet<GameObject> hashSet = new HashSet<GameObject>(); try { foreach (Target target in targets) { if (!StillValid(target) || !InRange(camera, target.gameObject.transform.position, out var _)) { continue; } hashSet.Add(target.gameObject); if (!indicators.TryGetValue(target.gameObject, out var value) || !Object.op_Implicit((Object)(object)value)) { PositionIndicator component = Object.Instantiate<GameObject>(indicatorPrefab, target.gameObject.transform.position, target.gameObject.transform.rotation).GetComponent<PositionIndicator>(); component.targetTransform = target.gameObject.transform; SpriteRenderer val = (Object.op_Implicit((Object)(object)component.insideViewObject) ? component.insideViewObject.GetComponent<SpriteRenderer>() : null); if (Object.op_Implicit((Object)(object)val)) { val.sprite = PingIndicator.GetInteractableIcon(target.gameObject); } indicators[target.gameObject] = component; } } } catch (Exception ex) { gameIconsBroken = true; ((BaseUnityPlugin)this).Logger.LogWarning((object)("Game icons failed, falling back to squares: " + ex)); ClearIndicators(); return; } List<GameObject> list = new List<GameObject>(); foreach (KeyValuePair<GameObject, PositionIndicator> indicator in indicators) { if (!Object.op_Implicit((Object)(object)indicator.Key) || !hashSet.Contains(indicator.Key) || !Object.op_Implicit((Object)(object)indicator.Value)) { list.Add(indicator.Key); } } foreach (GameObject item in list) { if (indicators.TryGetValue(item, out var value2) && Object.op_Implicit((Object)(object)value2)) { Object.Destroy((Object)(object)((Component)value2).gameObject); } indicators.Remove(item); } } } private void ClearIndicators() { foreach (KeyValuePair<GameObject, PositionIndicator> indicator in indicators) { if (Object.op_Implicit((Object)(object)indicator.Value)) { Object.Destroy((Object)(object)((Component)indicator.Value).gameObject); } } indicators.Clear(); } private static Renderer[] FindRenderers(GameObject go) { Highlight component = go.GetComponent<Highlight>(); if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.targetRenderer)) { return (Renderer[])(object)new Renderer[1] { component.targetRenderer }; } List<Renderer> list = new List<Renderer>(); Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(); foreach (Renderer val in componentsInChildren) { if (val is MeshRenderer || val is SkinnedMeshRenderer) { list.Add(val); } } return list.ToArray(); } private void OnPreRenderOutline(OutlineHighlight outline) { //IL_0066: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) if (!outlineHighlight.Value || !markersOn.Value || targets.Count == 0) { return; } try { Camera camera = GetCamera(); foreach (Target target in targets) { if (target.renderers == null || !StillValid(target) || !InRange(camera, target.gameObject.transform.position, out var _)) { continue; } Color value = categoryColor[target.category].Value; Renderer[] renderers = target.renderers; foreach (Renderer val in renderers) { if (Object.op_Implicit((Object)(object)val) && ((Component)val).gameObject.activeInHierarchy) { outline.AddHighlight(val, value); } } } } catch (Exception ex) { outlineHighlight.Value = false; ((BaseUnityPlugin)this).Logger.LogWarning((object)("Outline failed, turning it off: " + ex)); } } private static Camera GetCamera() { foreach (CameraRigController readOnlyInstances in CameraRigController.readOnlyInstancesList) { if (Object.op_Implicit((Object)(object)readOnlyInstances) && readOnlyInstances.localUserViewer != null && Object.op_Implicit((Object)(object)readOnlyInstances.sceneCam)) { return readOnlyInstances.sceneCam; } } return Camera.main; } private void OnGUI() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Expected O, but got Unknown //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0137: 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) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0156: 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_015d: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) if (!markersOn.Value || targets.Count == 0 || (int)Event.current.type != 7) { return; } bool flag = !useGameIcons.Value || gameIconsBroken || !Object.op_Implicit((Object)(object)indicatorPrefab); if (!flag && !showText.Value) { return; } Camera camera = GetCamera(); if (!Object.op_Implicit((Object)(object)camera)) { return; } if (labelStyle == null || labelStyle.fontSize != fontSize.Value) { labelStyle = new GUIStyle(GUI.skin.label) { fontSize = fontSize.Value, alignment = (TextAnchor)1, fontStyle = (FontStyle)1 }; shadowStyle = new GUIStyle(labelStyle); shadowStyle.normal.textColor = Color.black; } float value = markerSize.Value; Rect val3 = default(Rect); foreach (Target target in targets) { if (!StillValid(target)) { continue; } Vector3 val = target.gameObject.transform.position + Vector3.up * 1.5f; if (!InRange(camera, val, out var dist)) { continue; } Vector3 val2 = camera.WorldToScreenPoint(val); if (val2.z <= 0f) { continue; } float x = val2.x; float num = (float)Screen.height - val2.y; Color value2 = categoryColor[target.category].Value; if (flag) { Color color = GUI.color; GUI.color = Color.black; GUI.DrawTexture(new Rect(x - value / 2f - 1f, num - value / 2f - 1f, value + 2f, value + 2f), (Texture)(object)Texture2D.whiteTexture); GUI.color = value2; GUI.DrawTexture(new Rect(x - value / 2f, num - value / 2f, value, value), (Texture)(object)Texture2D.whiteTexture); GUI.color = color; } if (showText.Value) { string text = BuildText(target, dist); if (!string.IsNullOrEmpty(text)) { float num2 = (flag ? (value / 2f + 2f) : 20f); ((Rect)(ref val3))..ctor(x - 150f, num + num2, 300f, (float)fontSize.Value * 3f); GUI.Label(new Rect(((Rect)(ref val3)).x + 1f, ((Rect)(ref val3)).y + 1f, ((Rect)(ref val3)).width, ((Rect)(ref val3)).height), text, shadowStyle); labelStyle.normal.textColor = value2; GUI.Label(val3, text, labelStyle); } } } } private string BuildText(Target t, float dist) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Invalid comparison between Unknown and I4 string text = (showNames.Value ? t.label : ""); if (showCost.Value && Object.op_Implicit((Object)(object)t.purchase) && t.purchase.cost > 0 && (int)t.purchase.costType == 1) { text = text + ((text.Length > 0) ? " " : "") + "$" + t.purchase.cost; } if (showDistance.Value) { text = text + ((text.Length > 0) ? " " : "") + Mathf.RoundToInt(dist) + "m"; } return text; } } }