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 PhantomVikingsPresence v1.0.0
PhantomViking.dll
Decompiled 2 weeks agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Inspect { [BepInPlugin("com.inspect", "Inspect", "1.0")] public class InspectPlugin : BaseUnityPlugin { private void Awake() { } } } namespace phantomviking { public static class ConfigData { public static ConfigEntry<float> LureRadius; public static ConfigEntry<bool> RequireCosts; public static ConfigEntry<bool> RequireFuel; public static ConfigEntry<string> FuelItemPrefab; public static ConfigEntry<float> FuelConsumePerMinute; public static ConfigEntry<float> MaxFuel; public static void Initialize(ConfigFile config) { LureRadius = config.Bind<float>("General", "LureRadius", 5f, "The radius in meters where the stone simulates player presence."); RequireCosts = config.Bind<bool>("General", "RequireCosts", true, "If false, the stone costs nothing to build (good for testing)."); RequireFuel = config.Bind<bool>("Fuel", "RequireFuel", true, "If false, the stone works infinitely without fuel."); FuelItemPrefab = config.Bind<string>("Fuel", "FuelItemPrefab", "Resin", "The prefab name of the item used as fuel."); FuelConsumePerMinute = config.Bind<float>("Fuel", "FuelConsumePerMinute", 0.0166f, "How much fuel is consumed per minute (0.0166 = 1 per hour)."); MaxFuel = config.Bind<float>("Fuel", "MaxFuel", 100f, "Maximum amount of fuel the stone can hold."); config.SettingChanged += delegate { UpdatePieceCosts(); }; } private static void UpdatePieceCosts() { //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: 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_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: 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_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Expected O, but got Unknown //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Expected O, but got Unknown if ((Object)(object)Plugin.piecePrefab == (Object)null) { return; } Piece component = Plugin.piecePrefab.GetComponent<Piece>(); if ((Object)(object)component == (Object)null || (Object)(object)ObjectDB.instance == (Object)null) { return; } if (RequireCosts.Value) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Stone"); ItemDrop val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null); GameObject itemPrefab2 = ObjectDB.instance.GetItemPrefab("GreydwarfEye"); ItemDrop val2 = ((itemPrefab2 != null) ? itemPrefab2.GetComponent<ItemDrop>() : null); GameObject itemPrefab3 = ObjectDB.instance.GetItemPrefab("SurtlingCore"); ItemDrop val3 = ((itemPrefab3 != null) ? itemPrefab3.GetComponent<ItemDrop>() : null); if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null && (Object)(object)val3 != (Object)null) { component.m_resources = (Requirement[])(object)new Requirement[3] { new Requirement { m_resItem = val, m_amount = 20, m_recover = true }, new Requirement { m_resItem = val2, m_amount = 10, m_recover = true }, new Requirement { m_resItem = val3, m_amount = 5, m_recover = true } }; } } else { component.m_resources = (Requirement[])(object)new Requirement[0]; } } } public static class Consts { public const string ModGuid = "com.yourname.phantomviking"; public const string ModName = "Phantom Viking's Presence"; public const string ModVersion = "1.0.0"; public const string PrefabName = "PhantomViking_stone"; } public class PhantomVikingMono : MonoBehaviour, Interactable, Hoverable { public static readonly List<PhantomVikingMono> Instances = new List<PhantomVikingMono>(); private ZNetView _nview; private GameObject _enabledEffect; private Renderer _modelRenderer; private GameObject _areaMarker; private static readonly int EmissionColorProperty = Shader.PropertyToID("_EmissionColor"); private bool? _lastVisualState; private void Awake() { //IL_0150: 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_0195: Unknown result type (might be due to invalid IL or missing references) _nview = ((Component)this).GetComponent<ZNetView>(); if ((Object)(object)_nview == (Object)null || _nview.GetZDO() == null) { return; } Instances.Add(this); _nview.Register("RPC_AddFuel", (Action<long>)RPC_AddFuel); _nview.Register("RPC_ToggleActive", (Action<long>)RPC_ToggleActive); ((MonoBehaviour)this).InvokeRepeating("UpdateFuel", 2f, 2f); Transform obj = Utils.FindChild(((Component)this).transform, "PhantomViking_EnabledEffect", (IterativeSearchType)0); _enabledEffect = ((obj != null) ? ((Component)obj).gameObject : null); Transform obj2 = Utils.FindChild(((Component)this).transform, "PhantomViking_Model", (IterativeSearchType)0); _modelRenderer = ((obj2 != null) ? ((Component)obj2).GetComponent<Renderer>() : null); Transform obj3 = Utils.FindChild(((Component)this).transform, "PhantomViking_AreaMarker", (IterativeSearchType)0); _areaMarker = ((obj3 != null) ? ((Component)obj3).gameObject : null); if ((Object)(object)_enabledEffect != (Object)null) { Renderer[] componentsInChildren = _enabledEffect.GetComponentsInChildren<Renderer>(true); Renderer[] array = componentsInChildren; foreach (Renderer val in array) { if (val.material.HasProperty(EmissionColorProperty)) { val.material.SetColor(EmissionColorProperty, Color.cyan * 1.5f); } } Light[] componentsInChildren2 = _enabledEffect.GetComponentsInChildren<Light>(true); Light[] array2 = componentsInChildren2; foreach (Light val2 in array2) { val2.color = Color.cyan; } } UpdateVisuals(); } private void OnDestroy() { Instances.Remove(this); } private void UpdateFuel() { if (!_nview.IsOwner() || !ConfigData.RequireFuel.Value) { return; } float num = _nview.GetZDO().GetFloat("fuel", 0f); if (!(num <= 0f)) { float num2 = ConfigData.FuelConsumePerMinute.Value / 60f; long ticks = _nview.GetZDO().GetLong("lastTime", ZNet.instance.GetTime().Ticks); double num3 = (ZNet.instance.GetTime() - new DateTime(ticks)).TotalSeconds; if (num3 < 0.0) { num3 = 0.0; } float num4 = (float)(num3 * (double)num2); float num5 = num - num4; if (num5 < 0f) { num5 = 0f; } _nview.GetZDO().Set("fuel", num5); _nview.GetZDO().Set("lastTime", ZNet.instance.GetTime().Ticks); UpdateVisuals(); } } public bool IsActive() { if ((Object)(object)_nview == (Object)null || !_nview.IsValid()) { return false; } if (!_nview.GetZDO().GetBool("enabled", false)) { return false; } if (!ConfigData.RequireFuel.Value) { return true; } return _nview.GetZDO().GetFloat("fuel", 0f) > 0f; } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold || alt) { return false; } bool flag = false; GameObject val = (ConfigData.RequireFuel.Value ? ObjectDB.instance.GetItemPrefab(ConfigData.FuelItemPrefab.Value) : null); if ((Object)(object)val != (Object)null) { ItemDrop component = val.GetComponent<ItemDrop>(); if ((Object)(object)component != (Object)null && user.GetInventory().CountItems(component.m_itemData.m_shared.m_name, -1, true) > 0) { flag = true; } } if (!flag) { _nview.InvokeRPC("RPC_ToggleActive", Array.Empty<object>()); return true; } if (!ConfigData.RequireFuel.Value) { return false; } float num = _nview.GetZDO().GetFloat("fuel", 0f); if (num >= ConfigData.MaxFuel.Value) { ((Character)user).Message((MessageType)2, "Lure Stone is full", 0, (Sprite)null, false); return false; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(ConfigData.FuelItemPrefab.Value); if ((Object)(object)itemPrefab == (Object)null) { return false; } ItemDrop component2 = itemPrefab.GetComponent<ItemDrop>(); if ((Object)(object)component2 == (Object)null) { return false; } string name = component2.m_itemData.m_shared.m_name; if (user.GetInventory().CountItems(component2.m_itemData.m_shared.m_name, -1, true) > 0) { user.GetInventory().RemoveItem(component2.m_itemData.m_shared.m_name, 1, -1, true); ((Character)user).Message((MessageType)2, "Added 1 " + Localization.instance.Localize(name), 0, (Sprite)null, false); _nview.InvokeRPC("RPC_AddFuel", Array.Empty<object>()); return true; } ((Character)user).Message((MessageType)2, "You don't have any " + Localization.instance.Localize(name), 0, (Sprite)null, false); return false; } private void RPC_AddFuel(long sender) { if (_nview.IsOwner()) { float num = _nview.GetZDO().GetFloat("fuel", 0f); _nview.GetZDO().Set("fuel", num + 1f); _nview.GetZDO().Set("lastTime", ZNet.instance.GetTime().Ticks); UpdateVisuals(); } } public bool UseItem(Humanoid user, ItemData item) { return false; } private void RPC_ToggleActive(long sender) { if (_nview.IsOwner()) { bool flag = _nview.GetZDO().GetBool("enabled", false); _nview.GetZDO().Set("enabled", !flag); UpdateVisuals(); } } private void UpdateVisuals() { //IL_00b1: 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) bool flag = IsActive(); if (_lastVisualState == flag) { return; } if ((Object)(object)_enabledEffect != (Object)null) { _enabledEffect.SetActive(flag); } if ((Object)(object)_modelRenderer != (Object)null && _modelRenderer.material.HasProperty(EmissionColorProperty)) { if (flag) { _modelRenderer.material.SetColor(EmissionColorProperty, Color.white); } else { _modelRenderer.material.SetColor(EmissionColorProperty, Color.black); } } _lastVisualState = flag; } private void FixedUpdate() { if ((Object)(object)_areaMarker != (Object)null) { bool flag = (Object)(object)Player.m_localPlayer != (Object)null && ((Character)Player.m_localPlayer).InPlaceMode(); if (_areaMarker.activeSelf != flag) { _areaMarker.SetActive(flag); } } } public string GetHoverText() { bool flag = (Object)(object)_nview != (Object)null && _nview.IsValid() && _nview.GetZDO().GetBool("enabled", false); string text = (flag ? "Deactivate" : "Activate"); if (!ConfigData.RequireFuel.Value) { return Localization.instance.Localize("Phantom Viking's Presence (" + (flag ? "Active" : "Inactive") + ")\n[<color=yellow><b>$KEY_Use</b></color>] " + text); } float num = (((Object)(object)_nview != (Object)null && _nview.IsValid()) ? _nview.GetZDO().GetFloat("fuel", 0f) : 0f); string text2 = ((!flag) ? "Inactive" : ((num > 0f) ? "Active" : "Active (Needs Fuel)")); GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(ConfigData.FuelItemPrefab.Value); string text3 = (((Object)(object)itemPrefab != (Object)null) ? Localization.instance.Localize(itemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_name) : ConfigData.FuelItemPrefab.Value); return Localization.instance.Localize($"Phantom Viking's Presence: {text2}\nFuel: {Mathf.RoundToInt(num)}/{ConfigData.MaxFuel.Value}\n[<color=yellow><b>$KEY_Use</b></color>] Add {text3} or {text}"); } public string GetHoverName() { return "Phantom Viking's Presence"; } public float GetHoverOffset() { return 0.5f; } } [BepInPlugin("com.zeecamelsnake.phantomviking", "Phantom Viking's Presence", "1.0.0")] public class Plugin : BaseUnityPlugin { public static GameObject? piecePrefab; private void Awake() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown ConfigData.Initialize(((BaseUnityPlugin)this).Config); Harmony val = new Harmony("com.yourname.phantomviking"); val.PatchAll(); } } [HarmonyPatch(typeof(ZNetScene), "Awake")] public static class ZNetSceneAwakePatch { public static void Postfix(ZNetScene __instance) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown if ((Object)(object)Plugin.piecePrefab == (Object)null) { GameObject prefab = __instance.GetPrefab("guard_stone"); if ((Object)(object)prefab == (Object)null) { return; } GameObject val = new GameObject("PhantomVikingRoot"); val.SetActive(false); Object.DontDestroyOnLoad((Object)(object)val); Plugin.piecePrefab = Object.Instantiate<GameObject>(prefab, val.transform); ((Object)Plugin.piecePrefab).name = "PhantomViking_stone"; ZNetView component = Plugin.piecePrefab.GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null) { } PrivateArea componentInChildren = Plugin.piecePrefab.GetComponentInChildren<PrivateArea>(true); if ((Object)(object)componentInChildren != (Object)null) { if ((Object)(object)componentInChildren.m_enabledEffect != (Object)null) { ((Object)componentInChildren.m_enabledEffect).name = "PhantomViking_EnabledEffect"; } if ((Object)(object)componentInChildren.m_model != (Object)null) { ((Object)componentInChildren.m_model).name = "PhantomViking_Model"; } if ((Object)(object)componentInChildren.m_areaMarker != (Object)null) { ((Object)componentInChildren.m_areaMarker).name = "PhantomViking_AreaMarker"; } Object.DestroyImmediate((Object)(object)componentInChildren); } EffectArea componentInChildren2 = Plugin.piecePrefab.GetComponentInChildren<EffectArea>(true); if ((Object)(object)componentInChildren2 != (Object)null) { Object.DestroyImmediate((Object)(object)componentInChildren2); } GuidePoint componentInChildren3 = Plugin.piecePrefab.GetComponentInChildren<GuidePoint>(true); if ((Object)(object)componentInChildren3 != (Object)null) { RavenText text = componentInChildren3.m_text; text.m_topic = "Phantom Viking's Presence"; text.m_text = "This mystical stone tricks enemies into thinking you are nearby. But remember: Spawners only work when the area is loaded!\n\nBe sure to place a Chunk Loader nearby so the spawner doesn't fall asleep while you are away."; componentInChildren3.m_text = text; } Plugin.piecePrefab.AddComponent<PhantomVikingMono>(); } if (__instance.m_prefabs == null || __instance.m_prefabs.Contains(Plugin.piecePrefab)) { return; } __instance.m_prefabs.Add(Plugin.piecePrefab); if (((object)__instance).GetType().GetField("m_namedPrefabs", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance) is Dictionary<int, GameObject> dictionary) { int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)Plugin.piecePrefab).name); if (!dictionary.ContainsKey(stableHashCode)) { dictionary.Add(stableHashCode, Plugin.piecePrefab); } } } } [HarmonyPatch(typeof(ObjectDB), "Awake")] public static class ObjectDBAwakePatch { public static void Postfix(ObjectDB __instance) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Expected O, but got Unknown //IL_00f9: 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_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Expected O, but got Unknown //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_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Expected O, but got Unknown if ((Object)(object)Plugin.piecePrefab == (Object)null) { return; } Piece component = Plugin.piecePrefab.GetComponent<Piece>(); if ((Object)(object)component != (Object)null) { component.m_name = "Phantom Viking's Presence"; component.m_description = "Simulates a player's presence in a small radius to keep spawners active. Needs fuel."; component.m_category = (PieceCategory)0; if (ConfigData.RequireCosts.Value) { GameObject itemPrefab = __instance.GetItemPrefab("Stone"); ItemDrop val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null); GameObject itemPrefab2 = __instance.GetItemPrefab("GreydwarfEye"); ItemDrop val2 = ((itemPrefab2 != null) ? itemPrefab2.GetComponent<ItemDrop>() : null); GameObject itemPrefab3 = __instance.GetItemPrefab("SurtlingCore"); ItemDrop val3 = ((itemPrefab3 != null) ? itemPrefab3.GetComponent<ItemDrop>() : null); if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null && (Object)(object)val3 != (Object)null) { component.m_resources = (Requirement[])(object)new Requirement[3] { new Requirement { m_resItem = val, m_amount = 20, m_recover = true }, new Requirement { m_resItem = val2, m_amount = 10, m_recover = true }, new Requirement { m_resItem = val3, m_amount = 5, m_recover = true } }; } } else { component.m_resources = (Requirement[])(object)new Requirement[0]; } } GameObject itemPrefab4 = __instance.GetItemPrefab("Hammer"); if ((Object)(object)itemPrefab4 != (Object)null) { PieceTable buildPieces = itemPrefab4.GetComponent<ItemDrop>().m_itemData.m_shared.m_buildPieces; if ((Object)(object)buildPieces != (Object)null && !buildPieces.m_pieces.Contains(Plugin.piecePrefab)) { buildPieces.m_pieces.Add(Plugin.piecePrefab); } } } } } namespace phantomviking.Patch { [HarmonyPatch(typeof(Player), "IsPlayerInRange", new Type[] { typeof(Vector3), typeof(float) })] public static class Player_IsPlayerInRange_Patch { public static void Postfix(Vector3 point, float range, ref bool __result) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) if (__result) { return; } float value = ConfigData.LureRadius.Value; foreach (PhantomVikingMono instance in PhantomVikingMono.Instances) { if (!((Object)(object)instance == (Object)null) && instance.IsActive()) { float num = Vector3.Distance(point, ((Component)instance).transform.position); if (num <= value) { __result = true; break; } } } } } [HarmonyPatch(typeof(CreatureSpawner), "UpdateSpawner")] public static class CreatureSpawner_Update_Patch { public static void Prefix(CreatureSpawner __instance) { if (PhantomVikingMono.Instances.Count <= 0) { } } } }