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 SpawnWard v1.7.0
SpawnWard_v1.7.0.dll
Decompiled 15 hours 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 HarmonyLib; using Jotunn.Entities; using Jotunn.Managers; 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("SpawnWard")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.7.0.0")] [assembly: AssemblyInformationalVersion("1.7.0")] [assembly: AssemblyProduct("SpawnWard")] [assembly: AssemblyTitle("SpawnWard")] [assembly: AssemblyVersion("1.7.0.0")] namespace SpawnWard; [BepInPlugin("DEEP_FROST.SpawnWard", "SpawnWard", "1.7.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class SpawnWardPlugin : BaseUnityPlugin { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__20_0; internal void <RegisterConsoleCommand>b__20_0(ConsoleEventArgs args) { //IL_0052: 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) if (args.Args.Length < 2 || !int.TryParse(args.Args[1], out var result)) { args.Context.AddString("использование: spawnward <метры>"); return; } GameCamera instance = GameCamera.instance; Player localPlayer = Player.m_localPlayer; if (!((Object)(object)instance == (Object)null) && !((Object)(object)localPlayer == (Object)null)) { RaycastHit val = default(RaycastHit); if (!Physics.Raycast(((Component)instance).transform.position, ((Component)instance).transform.forward, ref val, 50f, LayerMask.GetMask(new string[2] { "piece", "vehicle" })) || (Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<SpawnWardBehavior>() == (Object)null) { ((Character)localPlayer).Message((MessageType)2, "Смотрите на оберег покоя", 0, (Sprite)null, false); } else { ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<SpawnWardBehavior>().SetRadius(result, feedback: true); } } } } public const string PluginGuid = "DEEP_FROST.SpawnWard"; public const string PluginName = "SpawnWard"; public const string PluginVersion = "1.7.0"; public const string PiecePrefabName = "DEEP_FROST_piece_SpawnWard"; public const string RadiusZdoKey = "DEEP_FROST.SpawnWardRadius"; public const string NameToken = "$piece_spawnward"; public const string MistZoneName = "SpawnWard_MistZone"; internal static ConfigEntry<int> DefaultRadius; internal static ConfigEntry<int> MaxRadius; internal static ConfigEntry<float> RingSeconds; internal static ConfigEntry<bool> ClearFogInside; private static bool _built; public static SpawnWardPlugin Instance { get; private set; } private void Awake() { //IL_00d5: Unknown result type (might be due to invalid IL or missing references) Instance = this; DefaultRadius = ((BaseUnityPlugin)this).Config.Bind<int>("General", "DefaultRadius", 50, "Радиус блока спавнов у нового оберега, м / Default radius for a new ward, meters"); MaxRadius = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxRadius", 2000, "Максимальный радиус, м / Maximum radius, meters"); RingSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RingSeconds", 0f, "Сколько секунд показывать кольцо радиуса (0 = показывать всегда) / Seconds to show the radius ring (0 = always)"); ClearFogInside = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ClearFogInside", true, "Убирать серую дымку, пока игрок внутри радиуса (кроме Пепельных земель) / Remove grey haze while the player is inside the radius (Ashlands excluded)"); LocalizationManager.Instance.AddToken("$piece_spawnward", "Оберег покоя", false); LocalizationManager.Instance.AddToken("$piece_spawnward_desc", "Ничего не спавнится в радиусе оберега, туман не скапливается. E / Shift+E — сменить радиус. Точное значение: консоль, spawnward <метры>", false); PrefabManager.OnVanillaPrefabsAvailable += TryBuildPiece; RegisterConsoleCommand(); new Harmony("DEEP_FROST.SpawnWard").PatchAll(typeof(SpawnWardPlugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[SpawnWard] 1.7.0 загружен"); } internal void TryBuildPiece() { //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Expected O, but got Unknown try { if (_built) { return; } GameObject val = null; string text = null; if ((Object)(object)ZNetScene.instance != (Object)null) { foreach (GameObject prefab2 in ZNetScene.instance.m_prefabs) { if ((Object)(object)prefab2 != (Object)null && (Object)(object)prefab2.GetComponent<PrivateArea>() != (Object)null) { val = prefab2; text = "ZNetScene"; break; } } } if ((Object)(object)val == (Object)null && (Object)(object)ObjectDB.instance != (Object)null) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Hammer"); PieceTable val2 = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<PieceTable>() : null); if ((Object)(object)val2 != (Object)null && val2.m_pieces != null) { foreach (GameObject piece in val2.m_pieces) { if ((Object)(object)piece != (Object)null && (Object)(object)piece.GetComponent<PrivateArea>() != (Object)null) { val = piece; text = "HammerTable"; break; } } } } if ((Object)(object)val == (Object)null) { GameObject prefab = PrefabManager.Instance.GetPrefab("piece_guardstone"); if ((Object)(object)prefab != (Object)null && (Object)(object)prefab.GetComponent<PrivateArea>() != (Object)null) { val = prefab; text = "JotunnCache"; } } if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[SpawnWard] Оберег (PrivateArea) не найден в источниках: ZNetScene=" + ((Object)(object)ZNetScene.instance != (Object)null) + ", ObjectDB=" + ((Object)(object)ObjectDB.instance != (Object)null) + " — повторю на следующем событии")); return; } string name = ((Object)val).name; GameObject val3 = PrefabManager.Instance.CreateClonedPrefab("DEEP_FROST_piece_SpawnWard", val); if ((Object)(object)val3 == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)("[SpawnWard] Не удалось клонировать базу " + name)); return; } CircleProjector val4 = null; PrivateArea component = val3.GetComponent<PrivateArea>(); if ((Object)(object)component != (Object)null) { val4 = component.m_areaMarker; Object.DestroyImmediate((Object)(object)component); } if ((Object)(object)val4 != (Object)null) { Object.DestroyImmediate((Object)(object)((Component)val4).gameObject); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[SpawnWard] Убрана ванильная окружность зоны оберега"); } Piece component2 = val3.GetComponent<Piece>(); if ((Object)(object)component2 != (Object)null) { component2.m_craftingStation = null; } SetCheapCost(component2); AddMistZone(val3); val3.AddComponent<SpawnWardBehavior>(); CustomPiece val5 = new CustomPiece(val3, "Hammer", false); PieceManager.Instance.AddPiece(val5); if ((Object)(object)val5.Piece != (Object)null) { val5.Piece.m_name = "$piece_spawnward"; val5.Piece.m_description = "$piece_spawnward_desc"; } ((BaseUnityPlugin)this).Logger.LogInfo((object)("[SpawnWard] Деталь «Оберег покоя» создана на базе ванильного оберега '" + name + "' (источник: " + text + ")")); _built = true; PrefabManager.OnVanillaPrefabsAvailable -= TryBuildPiece; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("[SpawnWard] Ошибка создания детали: " + ex)); } } private void SetCheapCost(Piece piece) { //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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown try { ObjectDB instance = ObjectDB.instance; if ((Object)(object)piece == (Object)null || (Object)(object)instance == (Object)null) { return; } GameObject itemPrefab = instance.GetItemPrefab("Wood"); GameObject itemPrefab2 = instance.GetItemPrefab("GreyDwarfEye"); if (!((Object)(object)itemPrefab == (Object)null)) { List<Requirement> list = new List<Requirement>(); list.Add(new Requirement { m_resItem = itemPrefab.GetComponent<ItemDrop>(), m_amount = 10, m_recover = true }); if ((Object)(object)itemPrefab2 != (Object)null) { list.Add(new Requirement { m_resItem = itemPrefab2.GetComponent<ItemDrop>(), m_amount = 5, m_recover = true }); } piece.m_resources = list.ToArray(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[SpawnWard] Цена установки: дерево 10 + глаза грейдворфа 5"); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("[SpawnWard] Не удалось задать цену установки: " + ex.Message)); } } private static void AddMistZone(GameObject root) { //IL_0005: 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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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_0060: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("SpawnWard_MistZone") { layer = LayerMask.NameToLayer("character_trigger") }; val.transform.SetParent(root.transform, false); val.transform.localPosition = Vector3.zero; SphereCollider obj = val.AddComponent<SphereCollider>(); ((Collider)obj).isTrigger = true; obj.radius = DefaultRadius.Value; EffectArea obj2 = val.AddComponent<EffectArea>(); obj2.m_type = (Type)2; obj2.m_statusEffect = ""; obj2.m_playerOnly = false; } private void RegisterConsoleCommand() { //IL_0033: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown object obj = <>c.<>9__20_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { //IL_0052: 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) if (args.Args.Length < 2 || !int.TryParse(args.Args[1], out var result)) { args.Context.AddString("использование: spawnward <метры>"); } else { GameCamera instance = GameCamera.instance; Player localPlayer = Player.m_localPlayer; if (!((Object)(object)instance == (Object)null) && !((Object)(object)localPlayer == (Object)null)) { RaycastHit val2 = default(RaycastHit); if (!Physics.Raycast(((Component)instance).transform.position, ((Component)instance).transform.forward, ref val2, 50f, LayerMask.GetMask(new string[2] { "piece", "vehicle" })) || (Object)(object)((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<SpawnWardBehavior>() == (Object)null) { ((Character)localPlayer).Message((MessageType)2, "Смотрите на оберег покоя", 0, (Sprite)null, false); } else { ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<SpawnWardBehavior>().SetRadius(result, feedback: true); } } } }; <>c.<>9__20_0 = val; obj = (object)val; } new ConsoleCommand("spawnward", "радиус оберега, на который смотришь: spawnward <метры>", (ConsoleEvent)obj, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } } public class SpawnWardBehavior : MonoBehaviour, Interactable, Hoverable { private static readonly List<SpawnWardBehavior> Active = new List<SpawnWardBehavior>(); private static readonly int[] Presets = new int[8] { 10, 25, 50, 100, 200, 300, 500, 1000 }; private ZNetView _znv; private float _radius = -1f; private float _nextSync; private LineRenderer _ring; private float _ringUntil; private float _lastRingRadius = -1f; private SphereCollider _mistZone; private void Awake() { _znv = ((Component)this).GetComponent<ZNetView>(); if ((Object)(object)_znv == (Object)null) { _znv = ((Component)this).GetComponentInParent<ZNetView>(); } if ((Object)(object)_znv != (Object)null && _znv.IsValid()) { Active.Add(this); } Transform val = ((Component)this).transform.Find("SpawnWard_MistZone"); if ((Object)(object)val != (Object)null) { _mistZone = ((Component)val).GetComponent<SphereCollider>(); } EnsureRing(); _ringUntil = Time.time + 15f; } private void OnDestroy() { Active.Remove(this); if ((Object)(object)_ring != (Object)null) { Object.Destroy((Object)(object)((Component)_ring).gameObject); } } private void Update() { UpdateRing(); if (Time.time < _nextSync) { return; } _nextSync = Time.time + 0.5f; if (!((Object)(object)_znv == (Object)null) && _znv.IsValid() && _znv.GetZDO() != null) { int r = _znv.GetZDO().GetInt("DEEP_FROST.SpawnWardRadius", SpawnWardPlugin.DefaultRadius.Value); _radius = ClampRadius(r); if ((Object)(object)_mistZone != (Object)null && Math.Abs(_mistZone.radius - _radius) > 0.01f) { _mistZone.radius = _radius; } } } public static bool BlocksPoint(Vector3 point) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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) for (int i = 0; i < Active.Count; i++) { SpawnWardBehavior spawnWardBehavior = Active[i]; float radius = spawnWardBehavior._radius; if (!(radius <= 0f)) { float num = point.x - ((Component)spawnWardBehavior).transform.position.x; float num2 = point.z - ((Component)spawnWardBehavior).transform.position.z; if (num * num + num2 * num2 <= radius * radius) { return true; } } } return false; } public static bool SuppressEmitter(Vector3 emitterPos) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < Active.Count; i++) { SpawnWardBehavior spawnWardBehavior = Active[i]; float num = spawnWardBehavior._radius + 30f; if (!(num <= 0f)) { float num2 = emitterPos.x - ((Component)spawnWardBehavior).transform.position.x; float num3 = emitterPos.z - ((Component)spawnWardBehavior).transform.position.z; if (num2 * num2 + num3 * num3 <= num * num) { return true; } } } return false; } public static bool IsPlayerInsideAny(Vector3 playerPos) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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) for (int i = 0; i < Active.Count; i++) { SpawnWardBehavior spawnWardBehavior = Active[i]; float radius = spawnWardBehavior._radius; if (!(radius <= 0f)) { float num = playerPos.x - ((Component)spawnWardBehavior).transform.position.x; float num2 = playerPos.z - ((Component)spawnWardBehavior).transform.position.z; if (num * num + num2 * num2 <= radius * radius) { return true; } } } return false; } public bool Interact(Humanoid character, bool hold, bool alt) { if (hold) { return false; } CycleRadius((!alt) ? 1 : (-1)); return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } public float GetHoverOffset() { return 0f; } public string GetHoverText() { PulseRing(); return Localization.instance.Localize("$piece_spawnward") + " (" + Mathf.RoundToInt(GetRadius()) + " м)\n[<color=yellow><b>$KEY_Use</b></color>] радиус больше [<color=yellow><b>Shift+$KEY_Use</b></color>] радиус меньше"; } public string GetHoverName() { return Localization.instance.Localize("$piece_spawnward"); } public float GetRadius() { if (!(_radius < 0f)) { return _radius; } return SpawnWardPlugin.DefaultRadius.Value; } public void SetRadius(int radius, bool feedback) { _radius = ClampRadius(radius); if ((Object)(object)_znv != (Object)null && _znv.IsValid() && _znv.GetZDO() != null) { _znv.GetZDO().Set("DEEP_FROST.SpawnWardRadius", Mathf.RoundToInt(_radius)); } if (feedback) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { ((Character)localPlayer).Message((MessageType)2, Localization.instance.Localize("$piece_spawnward") + ": " + Mathf.RoundToInt(_radius) + " м", 0, (Sprite)null, false); } } PulseRing(); } private int ClampRadius(int r) { int value = SpawnWardPlugin.MaxRadius.Value; if (r < 1) { r = SpawnWardPlugin.DefaultRadius.Value; } if (r > value) { r = value; } return r; } private void CycleRadius(int dir) { int num = Mathf.RoundToInt(GetRadius()); if (dir > 0) { for (int i = 0; i < Presets.Length; i++) { if (Presets[i] > num) { SetRadius(Presets[i], feedback: true); return; } } SetRadius(Presets[0], feedback: true); return; } for (int num2 = Presets.Length - 1; num2 >= 0; num2--) { if (Presets[num2] < num) { SetRadius(Presets[num2], feedback: true); return; } } SetRadius(Presets[Presets.Length - 1], feedback: true); } public void PulseRing() { float value = SpawnWardPlugin.RingSeconds.Value; _ringUntil = ((value <= 0f) ? float.MaxValue : (Time.time + value)); EnsureRing(); } private void EnsureRing() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Expected O, but got Unknown if (!((Object)(object)_ring != (Object)null)) { GameObject val = new GameObject("SpawnWardRing"); val.transform.SetParent(((Component)this).transform, false); _ring = val.AddComponent<LineRenderer>(); _ring.useWorldSpace = true; _ring.loop = true; _ring.startWidth = 0.5f; _ring.endWidth = 0.5f; _ring.positionCount = 72; _ring.startColor = new Color(0.5f, 1f, 0.4f, 0.85f); _ring.endColor = new Color(0.5f, 1f, 0.4f, 0.85f); Shader val2 = Shader.Find("Sprites/Default"); if ((Object)(object)val2 == (Object)null) { val2 = Shader.Find("Particles/Standard Unlit"); } if ((Object)(object)val2 == (Object)null) { val2 = Shader.Find("Legacy Shaders/Transparent/Diffuse"); } if ((Object)(object)val2 != (Object)null) { ((Renderer)_ring).material = new Material(val2); } ((Renderer)_ring).enabled = false; } } private void UpdateRing() { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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) //IL_008b: 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) //IL_00b8: 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_00d5: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_ring == (Object)null) { if (Time.time >= _ringUntil) { return; } EnsureRing(); } bool flag = Time.time < _ringUntil; if (((Renderer)_ring).enabled != flag) { ((Renderer)_ring).enabled = flag; } if (!flag) { return; } float radius = GetRadius(); if (!(Mathf.Abs(radius - _lastRingRadius) < 0.01f)) { _lastRingRadius = radius; Vector3 val = ((Component)this).transform.position + Vector3.up * 0.35f; int positionCount = _ring.positionCount; for (int i = 0; i < positionCount; i++) { float num = MathF.PI * 2f * (float)i / (float)positionCount; _ring.SetPosition(i, val + new Vector3(Mathf.Sin(num) * radius, 0f, Mathf.Cos(num) * radius)); } } } } [HarmonyPatch(typeof(SpawnSystem), "IsSpawnPointGood")] internal static class SpawnSystem_IsSpawnPointGood_Patch { private static void Postfix(ref bool __result, ref Vector3 spawnPoint) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (__result && SpawnWardBehavior.BlocksPoint(spawnPoint)) { __result = false; } } } [HarmonyPatch(typeof(MistEmitter), "Update")] internal static class MistEmitter_Update_Patch { private static bool Prefix(MistEmitter __instance) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return !SpawnWardBehavior.SuppressEmitter(((Component)__instance).transform.position); } } [HarmonyPatch(typeof(EnvMan), "UpdateEnvironment")] internal static class EnvMan_UpdateEnvironment_Patch { private static void Postfix() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Invalid comparison between Unknown and I4 //IL_0034: Unknown result type (might be due to invalid IL or missing references) if (!SpawnWardPlugin.ClearFogInside.Value) { return; } Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { Vector3 position = ((Component)localPlayer).transform.position; if ((int)Heightmap.FindBiome(position) != 32 && SpawnWardBehavior.IsPlayerInsideAny(position)) { RenderSettings.fogDensity = Mathf.Min(RenderSettings.fogDensity, 0.003f); } } } } [HarmonyPatch(typeof(ZNetScene), "Awake")] internal static class ZNetScene_Awake_Patch { [HarmonyPostfix] private static void Postfix() { SpawnWardPlugin.Instance?.TryBuildPiece(); } } [HarmonyPatch(typeof(ObjectDB), "Awake")] internal static class ObjectDB_Awake_Patch { [HarmonyPostfix] private static void Postfix() { SpawnWardPlugin.Instance?.TryBuildPiece(); } }