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 PerfectWisp v0.1.9
plugins/PerfectWisp.dll
Decompiled 5 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; 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("PerfectWisp")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.9.0")] [assembly: AssemblyInformationalVersion("0.1.9")] [assembly: AssemblyProduct("PerfectWisp")] [assembly: AssemblyTitle("PerfectWisp")] [assembly: AssemblyVersion("0.1.9.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 PerfectWisp { [BepInPlugin("com.perfectmods.perfectwisp", "PerfectWisp", "0.1.9")] [BepInDependency("com.jotunn.jotunn", "2.30.2")] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public sealed class PerfectWispPlugin : BaseUnityPlugin { public const string PluginGuid = "com.perfectmods.perfectwisp"; public const string PluginVersion = "0.1.9"; private static readonly int[] Ranges = new int[4] { 15, 20, 25, 30 }; private Harmony _harmony; private void Awake() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown _harmony = new Harmony("com.perfectmods.perfectwisp"); try { _harmony.PatchAll(Assembly.GetExecutingAssembly()); } catch { _harmony.UnpatchSelf(); throw; } ((BaseUnityPlugin)this).Logger.LogInfo((object)("PerfectWisp 0.1.9 loaded. Ranges: " + string.Join(" / ", Ranges) + " m.")); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } internal static bool IsWisplight(ItemData item) { return item?.m_shared?.m_name == "$item_demister"; } internal static int GetRange(int quality) { return Ranges[Mathf.Clamp(quality, 1, Ranges.Length) - 1]; } } [HarmonyPatch(typeof(ObjectDB), "UpdateRegisters")] internal static class WisplightRecipePatch { private enum Ingredient { Vanilla, Silver, Eitr, SoftTissue } private sealed class RequirementRule { internal readonly Ingredient Ingredient; internal RequirementRule(Ingredient ingredient) { Ingredient = ingredient; } internal int GetAmount(int quality) { switch (quality) { case 2: if (Ingredient != Ingredient.Silver) { return 0; } return 2; case 3: case 4: if (Ingredient != Ingredient.Eitr && Ingredient != Ingredient.SoftTissue) { return 0; } return quality - 1; default: return 0; } } } [HarmonyPatch(typeof(Requirement), "GetAmount")] private static class RequirementAmountPatch { private static bool Prefix(Requirement __instance, int __0, ref int __result) { if (!Rules.TryGetValue(__instance, out var value) || (value.Ingredient == Ingredient.Vanilla && __0 <= 1)) { return true; } __result = value.GetAmount(__0); return false; } } private static readonly ConditionalWeakTable<Requirement, RequirementRule> Rules = new ConditionalWeakTable<Requirement, RequirementRule>(); public static void Postfix(ObjectDB __instance) { GameObject itemPrefab = __instance.GetItemPrefab("Demister"); ItemDrop wisplight = (Object.op_Implicit((Object)(object)itemPrefab) ? itemPrefab.GetComponent<ItemDrop>() : null); if (!Object.op_Implicit((Object)(object)wisplight) || wisplight.m_itemData?.m_shared == null || __instance.m_recipes == null) { return; } Recipe val = __instance.m_recipes.Find((Recipe candidate) => Object.op_Implicit((Object)(object)candidate) && (Object)(object)candidate.m_item == (Object)(object)wisplight); if (!Object.op_Implicit((Object)(object)val) || val.m_resources == null) { return; } ItemDrop material = GetMaterial(__instance, "Silver"); ItemDrop material2 = GetMaterial(__instance, "Eitr"); ItemDrop material3 = GetMaterial(__instance, "Softtissue"); if (!Object.op_Implicit((Object)(object)material) || !Object.op_Implicit((Object)(object)material2) || !Object.op_Implicit((Object)(object)material3)) { return; } List<Requirement> list = new List<Requirement>(val.m_resources); Requirement[] resources = val.m_resources; foreach (Requirement val2 in resources) { if (val2 != null) { Rules.GetValue(val2, (Requirement _) => new RequirementRule(Ingredient.Vanilla)); } } AddUpgradeIngredient(list, material, Ingredient.Silver); AddUpgradeIngredient(list, material2, Ingredient.Eitr); AddUpgradeIngredient(list, material3, Ingredient.SoftTissue); if (list.Count != val.m_resources.Length) { val.m_resources = list.ToArray(); } wisplight.m_itemData.m_shared.m_maxQuality = 4; } private static ItemDrop GetMaterial(ObjectDB database, string prefabName) { GameObject itemPrefab = database.GetItemPrefab(prefabName); if (!Object.op_Implicit((Object)(object)itemPrefab)) { return null; } return itemPrefab.GetComponent<ItemDrop>(); } private static void AddUpgradeIngredient(List<Requirement> requirements, ItemDrop material, Ingredient ingredient) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_0044: Expected O, but got Unknown if (!requirements.Exists((Requirement requirement) => requirement != null && Rules.TryGetValue(requirement, out var value) && value.Ingredient == ingredient)) { Requirement val = new Requirement { m_resItem = material, m_amount = 0, m_amountPerLevel = 0, m_recover = false }; Rules.Add(val, new RequirementRule(ingredient)); requirements.Add(val); } } } [HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(ItemData), typeof(int), typeof(bool), typeof(float), typeof(int), typeof(bool) })] internal static class WisplightTooltipPatch { private const string RangeLabel = "Дальность работы"; private static void Postfix(ItemData item, int qualityLevel, bool appending, ref string __result) { if (!appending && PerfectWispPlugin.IsWisplight(item) && !string.IsNullOrEmpty(__result)) { int range = PerfectWispPlugin.GetRange((qualityLevel > 0) ? qualityLevel : item.m_quality); __result += string.Format("\n\n<color=#E6A23C>{0}:</color> <color=orange>{1} м</color>", "Дальность работы", range); } } } [HarmonyPatch(typeof(SE_Demister), "UpdateStatusEffect", new Type[] { typeof(float) })] internal static class WisplightRangePatch { private sealed class RangeState { internal GameObject Ball; internal ParticleSystemForceField[] Fields; internal int Range; } private static readonly FieldRef<Humanoid, ItemData> UtilityItem = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_utilityItem"); private static readonly ConditionalWeakTable<SE_Demister, RangeState> States = new ConditionalWeakTable<SE_Demister, RangeState>(); private static void Postfix(SE_Demister __instance, Character ___m_character, GameObject ___m_ballInstance) { if (!Object.op_Implicit((Object)(object)___m_ballInstance)) { return; } Humanoid val = (Humanoid)(object)((___m_character is Humanoid) ? ___m_character : null); if (val == null || (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsDedicated())) { return; } ItemData val2 = UtilityItem.Invoke(val); if (!PerfectWispPlugin.IsWisplight(val2)) { return; } int range = PerfectWispPlugin.GetRange(val2.m_quality); RangeState orCreateValue = States.GetOrCreateValue(__instance); if ((Object)(object)orCreateValue.Ball != (Object)(object)___m_ballInstance) { orCreateValue.Ball = ___m_ballInstance; orCreateValue.Fields = orCreateValue.Ball.GetComponentsInChildren<ParticleSystemForceField>(true); orCreateValue.Range = 0; } if (orCreateValue.Range == range) { return; } ParticleSystemForceField[] fields = orCreateValue.Fields; foreach (ParticleSystemForceField val3 in fields) { if (Object.op_Implicit((Object)(object)val3)) { val3.endRange = range; } } orCreateValue.Range = range; } } }