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 EmeraudeSanctuaire v1.1.0
plugins/EmeraudeSanctuaire.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; 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("EmeraudeSanctuaire")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.1.0.0")] [assembly: AssemblyInformationalVersion("1.1.0")] [assembly: AssemblyProduct("EmeraudeSanctuaire")] [assembly: AssemblyTitle("EmeraudeSanctuaire")] [assembly: AssemblyVersion("1.1.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 EmeraudeSanctuaire { [BepInPlugin("emeraude.sanctuaire", "Emeraude Sanctuaire", "1.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] [SynchronizationMode(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string Guid = "emeraude.sanctuaire"; public const string Name = "Emeraude Sanctuaire"; public const string Version = "1.1.0"; private static readonly Color Emerald = new Color(0.25f, 0.9f, 0.55f); internal static ConfigEntry<float> Radius; internal static ConfigEntry<bool> RepelMonsters; internal static ConfigEntry<bool> BlockRaids; internal static ConfigEntry<string> Recipe; private void Awake() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Expected O, but got Unknown //IL_00ff: Unknown result type (might be due to invalid IL or missing references) ConfigurationManagerAttributes val = new ConfigurationManagerAttributes { IsAdminOnly = true }; Radius = ((BaseUnityPlugin)this).Config.Bind<float>("Sanctuary", "Radius", 32f, new ConfigDescription("Radius of a new statue in meters: no monster spawns inside. Its builder then changes it with Shift + E (16, 24, 32, 48, 64 m). / Rayon d'une nouvelle statue en mètres : aucun monstre n'y apparaît. Son constructeur le change ensuite avec Maj + E (16, 24, 32, 48, 64 m).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(8f, 64f), new object[1] { val })); RepelMonsters = ((BaseUnityPlugin)this).Config.Bind<bool>("Sanctuary", "RepelMonsters", true, new ConfigDescription("Monsters flee from the statue's area, like around the trader, and stop chasing a player inside it. Tamed creatures are not affected. / Les monstres fuient la zone de la statue, comme autour du marchand, et cessent de poursuivre un joueur qui s'y trouve. Les créatures apprivoisées ne sont pas concernées.", (AcceptableValueBase)null, new object[1] { val })); BlockRaids = ((BaseUnityPlugin)this).Config.Bind<bool>("Sanctuary", "BlockRaids", true, new ConfigDescription("No raid starts on a player standing inside a statue's area. / Aucun raid ne démarre sur un joueur qui se trouve dans la zone d'une statue.", (AcceptableValueBase)null, new object[1] { val })); Recipe = ((BaseUnityPlugin)this).Config.Bind<string>("Sanctuary", "Recipe", "Stone:20,GreydwarfEye:10,SurtlingCore:2", new ConfigDescription("Cost of the statue (item:amount, comma separated), built with the hammer near a workbench. Requires a restart. / Coût de la statue (objet:quantité, séparés par des virgules), construite au marteau près d'un établi. Redémarrage requis.", (AcceptableValueBase)null, new object[1] { val })); AddTranslations(); PrefabManager.OnVanillaPrefabsAvailable += AddStatue; new Harmony("emeraude.sanctuaire").PatchAll(typeof(Plugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Emeraude Sanctuaire 1.1.0 loaded"); } private void AddTranslations() { CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); string text = "English"; localization.AddTranslation(ref text, new Dictionary<string, string> { ["emeraude_sanctuaire"] = "Emerald Statue", ["emeraude_sanctuaire_desc"] = "Monsters don't spawn around it and flee its area.", ["emeraude_sanctuaire_radius"] = "Radius: $1 m", ["emeraude_sanctuaire_change_radius"] = "Change the radius" }); text = "French"; localization.AddTranslation(ref text, new Dictionary<string, string> { ["emeraude_sanctuaire"] = "Statue d'Émeraude", ["emeraude_sanctuaire_desc"] = "Aucun monstre n'apparaît autour d'elle et ils fuient sa zone.", ["emeraude_sanctuaire_radius"] = "Rayon : $1 m", ["emeraude_sanctuaire_change_radius"] = "Changer le rayon" }); } private void AddStatue() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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_0037: 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_004e: Expected O, but got Unknown //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown PrefabManager.OnVanillaPrefabsAvailable -= AddStatue; PieceConfig val = new PieceConfig { Name = "$emeraude_sanctuaire", Description = "$emeraude_sanctuaire_desc", PieceTable = PieceTables.Hammer, CraftingStation = CraftingStations.Workbench, Category = PieceCategories.Misc }; string[] array = Recipe.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array) { string[] array2 = text.Split(':'); if (array2.Length == 2 && int.TryParse(array2[1].Trim(), out var result)) { val.AddRequirement(array2[0].Trim(), result, true); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Recipe : « " + text + " » ignoré, format attendu objet:quantité")); } } CustomPiece val2 = new CustomPiece("emeraude_sanctuaire", "guard_stone", val); GameObject piecePrefab = val2.PiecePrefab; PrivateArea component = piecePrefab.GetComponent<PrivateArea>(); Sanctuary sanctuary = piecePrefab.AddComponent<Sanctuary>(); sanctuary.m_areaMarker = component.m_areaMarker; sanctuary.m_model = component.m_model; sanctuary.m_hoverOffset = component.m_hoverOffset; if (Object.op_Implicit((Object)(object)component.m_enabledEffect)) { component.m_enabledEffect.SetActive(true); } if (Object.op_Implicit((Object)(object)component.m_inRangeEffect)) { component.m_inRangeEffect.SetActive(false); } Object.DestroyImmediate((Object)(object)component); Tint(piecePrefab); Material[] sharedMaterials = ((Renderer)sanctuary.m_model).sharedMaterials; foreach (Material val3 in sharedMaterials) { if (Object.op_Implicit((Object)(object)val3)) { val3.EnableKeyword("_EMISSION"); } } PieceManager.Instance.AddPiece(val2); } private static void Tint(GameObject prefab) { //IL_00d1: 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_0038: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { Material[] sharedMaterials = val.sharedMaterials; for (int j = 0; j < sharedMaterials.Length; j++) { if (Object.op_Implicit((Object)(object)sharedMaterials[j])) { Material val2 = new Material(sharedMaterials[j]); if (val2.HasProperty("_Color")) { val2.color *= Emerald; } if (val2.HasProperty("_EmissionColor")) { Color emerald = Emerald; Color color = val2.GetColor("_EmissionColor"); val2.SetColor("_EmissionColor", emerald * ((Color)(ref color)).maxColorComponent); } sharedMaterials[j] = val2; } } val.sharedMaterials = sharedMaterials; } Light[] componentsInChildren2 = prefab.GetComponentsInChildren<Light>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].color = Emerald; } } } [HarmonyPatch(typeof(RandEventSystem), "GetValidEventPoints")] internal static class Raids { private static readonly List<KeyValuePair<Vector3, float>> s_statues = new List<KeyValuePair<Vector3, float>>(); private static readonly List<ZDO> s_zdos = new List<ZDO>(); private static int s_frame = -1; private static void Postfix(List<Vector3> __result) { if (!Plugin.BlockRaids.Value || __result.Count == 0) { return; } List<KeyValuePair<Vector3, float>> statues = Statues(); __result.RemoveAll((Vector3 point) => statues.Exists((KeyValuePair<Vector3, float> statue) => Utils.DistanceXZ(point, statue.Key) < statue.Value)); } private static List<KeyValuePair<Vector3, float>> Statues() { //IL_0065: Unknown result type (might be due to invalid IL or missing references) if (s_frame == Time.frameCount) { return s_statues; } s_frame = Time.frameCount; s_statues.Clear(); s_zdos.Clear(); int num = 0; while (!ZDOMan.instance.GetAllZDOsWithPrefabIterative("emeraude_sanctuaire", s_zdos, ref num)) { } foreach (ZDO s_zdo in s_zdos) { s_statues.Add(new KeyValuePair<Vector3, float>(s_zdo.GetPosition(), Sanctuary.RadiusOf(s_zdo))); } return s_statues; } } public class Sanctuary : MonoBehaviour, Hoverable, Interactable { internal const string PrefabName = "emeraude_sanctuaire"; internal const string RadiusKey = "emeraude_sanctuaire_radius"; private static readonly float[] RadiusSteps = new float[5] { 16f, 24f, 32f, 48f, 64f }; public CircleProjector m_areaMarker; public MeshRenderer m_model; public float m_hoverOffset; private ZNetView m_nview; private Piece m_piece; private GameObject m_area; private float m_radius; internal static float RadiusOf(ZDO zdo) { return zdo.GetFloat("emeraude_sanctuaire_radius", Plugin.Radius.Value); } private void Awake() { m_nview = ((Component)this).GetComponent<ZNetView>(); m_piece = ((Component)this).GetComponent<Piece>(); if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid()) { SetMarkerRadius(Plugin.Radius.Value); return; } if (Object.op_Implicit((Object)(object)m_areaMarker)) { ((Component)m_areaMarker).gameObject.SetActive(false); } m_nview.Register<float>("EmeraudeSetRadius", (Action<long, float>)RPC_SetRadius); ApplyRadius(); ((MonoBehaviour)this).InvokeRepeating("ApplyRadius", 1f, 1f); } private void ApplyRadius() { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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) float num = RadiusOf(m_nview.GetZDO()); if (!Object.op_Implicit((Object)(object)m_area) || num != m_radius) { m_radius = num; SetMarkerRadius(num); if (Object.op_Implicit((Object)(object)m_area)) { Object.Destroy((Object)(object)m_area); } m_area = new GameObject("EmeraudeSanctuaireArea"); m_area.SetActive(false); m_area.layer = LayerMask.NameToLayer("character_trigger"); m_area.transform.SetParent(((Component)this).transform, false); m_area.AddComponent<SphereCollider>().radius = num; EffectArea val = m_area.AddComponent<EffectArea>(); val.m_type = (Type)4; if (Plugin.RepelMonsters.Value) { val.m_type = (Type)(val.m_type | 0x20); } m_area.SetActive(true); } } private void SetMarkerRadius(float radius) { if (Object.op_Implicit((Object)(object)m_areaMarker)) { m_areaMarker.m_radius = radius; } } private void ShowMarker() { if (Object.op_Implicit((Object)(object)m_areaMarker)) { ((Component)m_areaMarker).gameObject.SetActive(true); ((MonoBehaviour)this).CancelInvoke("HideMarker"); ((MonoBehaviour)this).Invoke("HideMarker", 0.5f); } } private void HideMarker() { ((Component)m_areaMarker).gameObject.SetActive(false); } private void RPC_SetRadius(long sender, float radius) { if (m_nview.IsOwner()) { m_nview.GetZDO().Set("emeraude_sanctuaire_radius", radius); } } public string GetHoverText() { if (!m_nview.IsValid() || !Object.op_Implicit((Object)(object)Player.m_localPlayer)) { return ""; } ShowMarker(); StringBuilder stringBuilder = new StringBuilder("$emeraude_sanctuaire"); stringBuilder.Append("\n$emeraude_sanctuaire_radius"); if (m_piece.IsCreator()) { stringBuilder.Append("\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] $emeraude_sanctuaire_change_radius"); } return Localization.instance.Localize(stringBuilder.ToString(), new string[1] { m_radius.ToString("0") }); } public string GetHoverName() { return "$emeraude_sanctuaire"; } public float GetHoverOffset() { return m_hoverOffset; } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold || !alt || !m_nview.IsValid() || !m_piece.IsCreator()) { return false; } int num = Array.FindIndex(RadiusSteps, (float step) => step > m_radius + 0.1f); float num2 = RadiusSteps[(num >= 0) ? num : 0]; m_nview.InvokeRPC("EmeraudeSetRadius", new object[1] { num2 }); SetMarkerRadius(num2); ShowMarker(); ((Character)user).Message((MessageType)2, Localization.instance.Localize("$emeraude_sanctuaire_radius", new string[1] { num2.ToString("0") }), 0, (Sprite)null, false); return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } } }