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 Photon.Pun; 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("NapberryEnhanced")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("NapberryEnhanced")] [assembly: AssemblyTitle("NapberryEnhanced")] [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 NapberryEnhanced { [BepInPlugin("jill920.napberryenhanced", "Napberry Enhanced", "1.0.0")] public class NapberryEnhancedPlugin : BaseUnityPlugin { public const string MOD_GUID = "jill920.napberryenhanced"; public const string MOD_NAME = "Napberry Enhanced"; public const string MOD_VERSION = "1.0.0"; public static NapberryEnhancedPlugin Instance; public static ManualLogSource Logger; public static bool IsDizzinessModInstalled; public static bool IsFatigueModInstalled; public static bool debugMode; private void Awake() { Instance = this; Logger = ((BaseUnityPlugin)this).Logger; debugMode = ((BaseUnityPlugin)this).Config.Bind("Debug", "EnableLogs", false, "Enable debug logging").Value; CheckForInstalledMods(); try { Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "jill920.napberryenhanced"); Logger.LogInfo((object)"[Napberry Enhanced 1.0.0] Loaded successfully!"); Logger.LogInfo((object)$" Dizziness Mod detected: {IsDizzinessModInstalled}"); Logger.LogInfo((object)$" Fatigue Mod detected: {IsFatigueModInstalled}"); } 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 { } } } } } namespace NapberryEnhanced.Patches { [HarmonyPatch(typeof(Item), "Consume")] internal static class Item_Consume_Patch { private const int NAPBERRY_ITEM_ID = 110; 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 (NapberryEnhancedPlugin.IsFatigueModInstalled) { _fatigueAvailable = true; return true; } try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (assembly.GetType("FatigueMod.FatigueTracker") != null) { _fatigueAvailable = true; NapberryEnhancedPlugin.IsFatigueModInstalled = true; NapberryEnhancedPlugin.Logger.LogInfo((object)"Napberry: Fatigue Mod detected at runtime!"); return true; } } } catch { } return false; } private static bool IsDizzinessModPresent() { if (_dizzinessCheckDone) { return _dizzinessAvailable; } _dizzinessCheckDone = true; if (NapberryEnhancedPlugin.IsDizzinessModInstalled) { _dizzinessAvailable = true; return true; } try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (assembly.GetType("DizzinessMod.DizzinessTracker") != null) { _dizzinessAvailable = true; NapberryEnhancedPlugin.IsDizzinessModInstalled = true; NapberryEnhancedPlugin.Logger.LogInfo((object)"Napberry: Dizziness Mod detected at runtime!"); return true; } } } catch { } return false; } [HarmonyPostfix] private static void Postfix(Item __instance, int consumerID) { if (__instance.itemID != 110) { return; } PhotonView photonView = PhotonNetwork.GetPhotonView(consumerID); if ((Object)(object)photonView == (Object)null) { return; } Character component = ((Component)photonView).GetComponent(); if ((Object)(object)component == (Object)null || !component.IsLocal) { return; } bool flag = IsDizzinessModPresent(); bool flag2 = IsFatigueModPresent(); if (flag || flag2) { if (flag) { ClearDizziness(component); } if (flag2) { ClearFatigue(component); } if (NapberryEnhancedPlugin.debugMode) { NapberryEnhancedPlugin.Logger.LogInfo((object)("Napberry: Cleared Dizziness/Fatigue for " + component.characterName)); } } } private static void ClearDizziness(Character character) { 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); field.SetValue(component, 0f); if (NapberryEnhancedPlugin.debugMode && num > 0.01f) { NapberryEnhancedPlugin.Logger.LogInfo((object)$"Napberry: Cleared Dizziness: {num:F3} → 0"); } } } catch (Exception ex) { NapberryEnhancedPlugin.Logger.LogWarning((object)("Failed to clear Dizziness: " + ex.Message)); } } private static void ClearFatigue(Character character) { 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); field.SetValue(component, 0f); if (field2 != null) { float num2 = (float)field2.GetValue(component); if (num2 > 0.01f) { field2.SetValue(component, 0f); if (NapberryEnhancedPlugin.debugMode) { NapberryEnhancedPlugin.Logger.LogInfo((object)$"Napberry: Cleared pending stamina: {num2:F3} → 0"); } } } if (NapberryEnhancedPlugin.debugMode && num > 0.01f) { NapberryEnhancedPlugin.Logger.LogInfo((object)$"Napberry: Cleared Fatigue: {num:F3} → 0"); } } catch (Exception ex) { NapberryEnhancedPlugin.Logger.LogWarning((object)("Failed to clear Fatigue: " + ex.Message)); } } } }