using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; 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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("FaerieLanternEnhanced")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+b0ca20efa02412f153573223d64426edebafe134")] [assembly: AssemblyProduct("FaerieLanternEnhanced")] [assembly: AssemblyTitle("FaerieLanternEnhanced")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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 FaerieLanternEnhanced { [BepInPlugin("jill920.faerielanternenhanced", "Faerie Lantern Enhanced", "1.0.1")] public class FaerieLanternEnhancedPlugin : BaseUnityPlugin { public const string MOD_GUID = "jill920.faerielanternenhanced"; public const string MOD_NAME = "Faerie Lantern Enhanced"; public const string MOD_VERSION = "1.0.1"; public static FaerieLanternEnhancedPlugin Instance; public static ManualLogSource Logger; public static bool IsDizzinessModInstalled = false; public static bool IsFatigueModInstalled = false; public static bool debugMode = false; public static float dizzinessHealRate = 0.025f; public static float fatigueHealRate = 0.025f; public static float effectRadius = 7.2f; private void Awake() { Instance = this; Logger = ((BaseUnityPlugin)this).Logger; debugMode = ((BaseUnityPlugin)this).Config.Bind("Debug", "EnableLogs", false, "Enable debug logging").Value; dizzinessHealRate = ((BaseUnityPlugin)this).Config.Bind("Healing", "DizzinessHealRate", 0.025f, "Dizziness reduction per second while near lit Faerie Lantern").Value; fatigueHealRate = ((BaseUnityPlugin)this).Config.Bind("Healing", "FatigueHealRate", 0.025f, "Fatigue reduction per second while near lit Faerie Lantern").Value; effectRadius = ((BaseUnityPlugin)this).Config.Bind("Healing", "EffectRadius", 7.2f, "Radius in meters for lantern healing effects").Value; CheckForInstalledMods(); try { Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "jill920.faerielanternenhanced"); Logger.LogInfo((object)"[Faerie Lantern Enhanced 1.0.1] Loaded successfully!"); Logger.LogInfo((object)$" Dizziness Mod detected: {IsDizzinessModInstalled}"); Logger.LogInfo((object)$" Fatigue Mod detected: {IsFatigueModInstalled}"); Logger.LogInfo((object)$" Dizziness heal rate: {dizzinessHealRate}/s"); Logger.LogInfo((object)$" Fatigue heal rate: {fatigueHealRate}/s"); Logger.LogInfo((object)$" Effect radius: {effectRadius}m"); } catch (Exception ex) { Logger.LogError((object)("Failed to load: " + ex.Message)); } } private void CheckForInstalledMods() { IsDizzinessModInstalled = false; IsFatigueModInstalled = false; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { try { if (assembly.GetType("DizzinessMod.DizzinessTracker") != null) { IsDizzinessModInstalled = true; } if (assembly.GetType("FatigueMod.FatigueTracker") != null) { IsFatigueModInstalled = true; } } catch { } } if (!IsFatigueModInstalled) { try { IsFatigueModInstalled = Type.GetType("FatigueMod.FatigueTracker, Assembly-CSharp") != null; } catch { } } if (!IsDizzinessModInstalled) { try { IsDizzinessModInstalled = Type.GetType("DizzinessMod.DizzinessTracker, Assembly-CSharp") != null; } catch { } } } } } namespace FaerieLanternEnhanced.Patches { [HarmonyPatch(typeof(ItemCooking), "RPC_CookingExplode")] internal static class ItemCooking_Explode_Patch { private const int FAERIE_LANTERN_ID = 43; private const float EXPLOSION_RADIUS = 4.8f; private static bool _fatigueCheckDone; private static bool _fatigueAvailable; private static bool _dizzinessCheckDone; private static bool _dizzinessAvailable; private static bool IsFatigueModPresent() { if (_fatigueCheckDone) { return _fatigueAvailable; } _fatigueCheckDone = true; if (FaerieLanternEnhancedPlugin.IsFatigueModInstalled) { _fatigueAvailable = true; return true; } try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (assembly.GetType("FatigueMod.FatigueTracker") != null) { _fatigueAvailable = true; FaerieLanternEnhancedPlugin.IsFatigueModInstalled = true; FaerieLanternEnhancedPlugin.Logger.LogInfo((object)"Faerie Lantern Explosion: Fatigue Mod detected at runtime!"); return true; } } } catch { } return false; } private static bool IsDizzinessModPresent() { if (_dizzinessCheckDone) { return _dizzinessAvailable; } _dizzinessCheckDone = true; if (FaerieLanternEnhancedPlugin.IsDizzinessModInstalled) { _dizzinessAvailable = true; return true; } try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (assembly.GetType("DizzinessMod.DizzinessTracker") != null) { _dizzinessAvailable = true; FaerieLanternEnhancedPlugin.IsDizzinessModInstalled = true; FaerieLanternEnhancedPlugin.Logger.LogInfo((object)"Faerie Lantern Explosion: Dizziness Mod detected at runtime!"); return true; } } } catch { } return false; } [HarmonyPrefix] private static void Prefix(ItemCooking __instance) { //IL_0032: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) Item item = ((ItemComponent)__instance).item; if ((Object)(object)item == (Object)null || item.itemID != 43) { return; } Vector3 position = ((Component)__instance).transform.position; bool flag = IsDizzinessModPresent(); bool flag2 = IsFatigueModPresent(); foreach (Character allCharacter in Character.AllCharacters) { if ((Object)(object)allCharacter == (Object)null) { continue; } float num = Vector3.Distance(position, allCharacter.Center); if (!(num > 4.8f)) { float num2 = 1f - num / 4.8f; float amount = -0.25f * num2; if (flag) { AddDizziness(allCharacter, amount); } if (flag2) { AddFatigue(allCharacter, amount); } } } FaerieLanternEnhancedPlugin.Logger.LogInfo((object)$"Faerie Lantern explosion: Applied status restoration within {4.8f}m"); } private static void AddDizziness(Character character, float amount) { try { Component component = ((Component)character).GetComponent("DizzinessMod.DizzinessTracker"); if ((Object)(object)component == (Object)null) { return; } FieldInfo field = ((object)component).GetType().GetField("dizzinessValue", BindingFlags.Instance | BindingFlags.Public); if (!(field == null)) { float num = (float)field.GetValue(component); float num2 = Mathf.Clamp01(num + amount); field.SetValue(component, num2); if (FaerieLanternEnhancedPlugin.debugMode) { FaerieLanternEnhancedPlugin.Logger.LogInfo((object)$"Explosion changed Dizziness: {num:F3} → {num2:F3} ({amount:F3})"); } } } catch (Exception ex) { FaerieLanternEnhancedPlugin.Logger.LogWarning((object)("Failed to modify Dizziness: " + ex.Message)); } } private static void AddFatigue(Character character, float amount) { try { Component component = ((Component)character).GetComponent("FatigueMod.FatigueTracker"); if ((Object)(object)component == (Object)null) { return; } FieldInfo field = ((object)component).GetType().GetField("fatigueValue", BindingFlags.Instance | BindingFlags.Public); if (field == null) { return; } float num = (float)field.GetValue(component); float num2 = Mathf.Clamp01(num + amount); field.SetValue(component, num2); if (amount < 0f && num2 < num) { FieldInfo field2 = ((object)component).GetType().GetField("pendingStaminaFromActions", BindingFlags.Instance | BindingFlags.NonPublic); if (field2 != null) { field2.SetValue(component, 0f); } } if (FaerieLanternEnhancedPlugin.debugMode) { FaerieLanternEnhancedPlugin.Logger.LogInfo((object)$"Explosion changed Fatigue: {num:F3} → {num2:F3} ({amount:F3})"); } } catch (Exception ex) { FaerieLanternEnhancedPlugin.Logger.LogWarning((object)("Failed to modify Fatigue: " + ex.Message)); } } } [HarmonyPatch(typeof(Lantern), "Update")] internal static class Lantern_Update_Patch { private const int FAERIE_LANTERN_ID = 43; private static FieldInfo _litField; private static bool _fatigueCheckDone; private static bool _fatigueAvailable; private static bool IsLit(Lantern lantern) { if (_litField == null) { _litField = typeof(Lantern).GetField("lit", BindingFlags.Instance | BindingFlags.NonPublic); } return _litField != null && (bool)_litField.GetValue(lantern); } private static bool IsFatigueModPresent() { if (_fatigueCheckDone) { return _fatigueAvailable; } _fatigueCheckDone = true; try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (assembly.GetType("FatigueMod.FatigueTracker") != null) { _fatigueAvailable = true; FaerieLanternEnhancedPlugin.IsFatigueModInstalled = true; FaerieLanternEnhancedPlugin.Logger.LogInfo((object)"Fatigue Mod detected at runtime!"); return true; } } } catch { } return false; } private static bool IsDizzinessModPresent() { if (FaerieLanternEnhancedPlugin.IsDizzinessModInstalled) { return true; } try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (assembly.GetType("DizzinessMod.DizzinessTracker") != null) { FaerieLanternEnhancedPlugin.IsDizzinessModInstalled = true; return true; } } } catch { } return false; } [HarmonyPostfix] private static void Postfix(Lantern __instance) { //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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)((ItemComponent)__instance).item == (Object)null || ((ItemComponent)__instance).item.itemID != 43 || !IsLit(__instance)) { return; } Vector3 position = ((Component)__instance).transform.position; float effectRadius = FaerieLanternEnhancedPlugin.effectRadius; float deltaTime = Time.deltaTime; bool flag = IsDizzinessModPresent(); bool flag2 = IsFatigueModPresent(); if (!flag && !flag2) { return; } foreach (Character allCharacter in Character.AllCharacters) { if ((Object)(object)allCharacter == (Object)null) { continue; } float num = Vector3.Distance(position, allCharacter.Center); if (!(num > effectRadius)) { if (flag) { ReduceDizziness(allCharacter, FaerieLanternEnhancedPlugin.dizzinessHealRate * deltaTime); } if (flag2) { ReduceFatigue(allCharacter, FaerieLanternEnhancedPlugin.fatigueHealRate * deltaTime); } if (FaerieLanternEnhancedPlugin.debugMode) { FaerieLanternEnhancedPlugin.Logger.LogInfo((object)$"Faerie Lantern healing {allCharacter.characterName} (dist={num:F2}m)"); } } } } private static void ReduceDizziness(Character character, float amount) { try { Component component = ((Component)character).GetComponent("DizzinessMod.DizzinessTracker"); if ((Object)(object)component == (Object)null) { return; } FieldInfo field = ((object)component).GetType().GetField("dizzinessValue", BindingFlags.Instance | BindingFlags.Public); if (!(field == null)) { float num = (float)field.GetValue(component); float num2 = Mathf.Max(0f, num - amount); field.SetValue(component, num2); if (FaerieLanternEnhancedPlugin.debugMode && amount > 0.001f) { FaerieLanternEnhancedPlugin.Logger.LogInfo((object)$"Reduced Dizziness: {num:F3} → {num2:F3} (-{amount:F3})"); } } } catch (Exception ex) { FaerieLanternEnhancedPlugin.Logger.LogWarning((object)("Failed to reduce Dizziness: " + ex.Message)); } } private static void ReduceFatigue(Character character, float amount) { try { Component component = ((Component)character).GetComponent("FatigueMod.FatigueTracker"); if ((Object)(object)component == (Object)null) { return; } FieldInfo field = ((object)component).GetType().GetField("fatigueValue", BindingFlags.Instance | BindingFlags.Public); if (field == null) { return; } FieldInfo field2 = ((object)component).GetType().GetField("pendingStaminaFromActions", BindingFlags.Instance | BindingFlags.NonPublic); float num = (float)field.GetValue(component); float num2 = Mathf.Max(0f, num - amount); field.SetValue(component, num2); if (field2 != null && amount > 0.001f && num > 0.001f) { float num3 = (float)field2.GetValue(component); if (num3 > 0f) { float num4 = num3 * (amount / num); field2.SetValue(component, Mathf.Max(0f, num3 - num4)); } } if (FaerieLanternEnhancedPlugin.debugMode && amount > 0.001f) { FaerieLanternEnhancedPlugin.Logger.LogInfo((object)$"Reduced Fatigue: {num:F3} → {num2:F3} (-{amount:F3})"); } } catch (Exception ex) { FaerieLanternEnhancedPlugin.Logger.LogWarning((object)("Failed to reduce Fatigue: " + ex.Message)); } } } }