using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Erenshor.FoodBuffDuration;
[BepInPlugin("et508.erenshor.foodbuffduration", "Food Buff Duration", "1.2.2")]
public class FoodBuffDurationPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(SpellDB), "Start")]
public class SpellDB_Start_Patch
{
public static void Postfix()
{
ApplyNourished();
ApplyHydrated();
ApplyVitheo();
ApplyFury();
ApplyProtection();
}
}
internal static ConfigEntry<string> ConfigVersion;
private const string CurrentConfigVersion = "1.2.0";
internal static ConfigEntry<float> NourishedMinutes;
internal static ConfigEntry<bool> NourishedPartyBuff;
internal static ConfigEntry<float> HydratedMinutes;
internal static ConfigEntry<bool> HydratedPartyBuff;
internal static ConfigEntry<float> VitheoMinutes;
internal static ConfigEntry<bool> VitheoPartyBuff;
internal static ConfigEntry<float> FuryMinutes;
internal static ConfigEntry<bool> FuryPartyBuff;
internal static ConfigEntry<float> ProtectionMinutes;
internal static ConfigEntry<bool> ProtectionPartyBuff;
internal static ManualLogSource Log;
private void Awake()
{
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Expected O, but got Unknown
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Expected O, but got Unknown
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Expected O, but got Unknown
//IL_0245: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Expected O, but got Unknown
//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Expected O, but got Unknown
//IL_047a: Unknown result type (might be due to invalid IL or missing references)
//IL_0480: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
ConfigVersion = ((BaseUnityPlugin)this).Config.Bind<string>("System", "ConfigVersion", "1.0.0", "DO NOT MODIFY: Used to detect config file changes.");
if (ConfigVersion.Value != "1.2.0")
{
Log.LogWarning((object)("[FBDI] Config version outdated (" + ConfigVersion.Value + "). Resetting config to 1.2.0."));
try
{
((BaseUnityPlugin)this).Config.Clear();
string configFilePath = ((BaseUnityPlugin)this).Config.ConfigFilePath;
if (File.Exists(configFilePath))
{
File.Delete(configFilePath);
}
ConfigVersion = ((BaseUnityPlugin)this).Config.Bind<string>("System", "ConfigVersion", "1.2.0", "DO NOT MODIFY: Used to detect config file changes.");
((BaseUnityPlugin)this).Config.Save();
Log.LogInfo((object)"[FBDI] Config successfully reset.");
}
catch (Exception ex)
{
Log.LogError((object)("[FBDI] Failed to reset config: " + ex.Message));
}
}
NourishedMinutes = ((BaseUnityPlugin)this).Config.Bind<float>("Nourished", "Duration", 10f, new ConfigDescription("Duration in minutes for Nourished (default 10 = 10 minutes = 100 ticks).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>()));
NourishedPartyBuff = ((BaseUnityPlugin)this).Config.Bind<bool>("Nourished", "NourishedGroupBuff", false, "If true, the Nourished buff from bread will be applied to the entire party.");
HydratedMinutes = ((BaseUnityPlugin)this).Config.Bind<float>("Hydrated", "Duration", 10f, new ConfigDescription("Duration in minutes for Hydrated (default 10 = 10 minutes = 100 ticks).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>()));
HydratedPartyBuff = ((BaseUnityPlugin)this).Config.Bind<bool>("Hydrated", "HydratedGroupBuff", false, "If true, the Hydrated buff will be applied the entire party.");
VitheoMinutes = ((BaseUnityPlugin)this).Config.Bind<float>("VitheosBlessing", "Duration", 0.2f, new ConfigDescription("Duration in minutes for Vitheos Blessing of the Sea (default 0.2 = 12 seconds = 2 ticks).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>()));
VitheoPartyBuff = ((BaseUnityPlugin)this).Config.Bind<bool>("VitheosBlessing", "VitheoGroupBuff", false, "If true, the Vitheos Blessing buff will be applied the entire party.");
FuryMinutes = ((BaseUnityPlugin)this).Config.Bind<float>("SpicedFury", "Duration", 2f, new ConfigDescription("Duration in minutes for Spiced Fury (default 2 = 2 minutes = 20 ticks).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>()));
FuryPartyBuff = ((BaseUnityPlugin)this).Config.Bind<bool>("SpicedFury", "SpicedGroupBuff", false, "If true, the Spiced Fury buff will be applied the entire party.");
ProtectionMinutes = ((BaseUnityPlugin)this).Config.Bind<float>("MinorProtection", "Duration", 25f, new ConfigDescription("Duration in minutes for Minor Protection (default 25 = 25 minutes = 250 ticks).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>()));
ProtectionPartyBuff = ((BaseUnityPlugin)this).Config.Bind<bool>("MinorProtection", "ProtectionGroupBuff", false, "If true, the Minor Protection buff will be applied the entire party.");
NourishedMinutes.SettingChanged += delegate
{
ApplyNourished();
};
NourishedPartyBuff.SettingChanged += delegate
{
ApplyNourished();
};
HydratedMinutes.SettingChanged += delegate
{
ApplyHydrated();
};
HydratedPartyBuff.SettingChanged += delegate
{
ApplyHydrated();
};
VitheoMinutes.SettingChanged += delegate
{
ApplyVitheo();
};
VitheoPartyBuff.SettingChanged += delegate
{
ApplyVitheo();
};
FuryMinutes.SettingChanged += delegate
{
ApplyFury();
};
FuryPartyBuff.SettingChanged += delegate
{
ApplyFury();
};
ProtectionMinutes.SettingChanged += delegate
{
ApplyProtection();
};
ProtectionPartyBuff.SettingChanged += delegate
{
ApplyProtection();
};
Harmony val = new Harmony("et508.erenshor.foodbuffduration");
val.PatchAll();
Log.LogInfo((object)"Food Buff Duration loaded.");
}
private static Spell GetSpellById(string id)
{
return GameData.SpellDatabase?.SpellDatabase?.FirstOrDefault((Func<Spell, bool>)((Spell s) => ((BaseScriptableObject)(s?)).Id == id));
}
private static void ApplyNourished()
{
Spell spellById = GetSpellById("1735287");
if (!((Object)(object)spellById == (Object)null))
{
int spellDurationInTicks = Mathf.RoundToInt(NourishedMinutes.Value * 10f);
spellById.SpellDurationInTicks = spellDurationInTicks;
spellById.GroupEffect = NourishedPartyBuff.Value;
}
}
private static void ApplyHydrated()
{
Spell spellById = GetSpellById("20309875");
if (!((Object)(object)spellById == (Object)null))
{
int spellDurationInTicks = Mathf.RoundToInt(HydratedMinutes.Value * 10f);
spellById.SpellDurationInTicks = spellDurationInTicks;
spellById.GroupEffect = HydratedPartyBuff.Value;
}
}
private static void ApplyVitheo()
{
Spell spellById = GetSpellById("68325939");
if (!((Object)(object)spellById == (Object)null))
{
int spellDurationInTicks = Mathf.RoundToInt(VitheoMinutes.Value * 10f);
spellById.SpellDurationInTicks = spellDurationInTicks;
spellById.GroupEffect = VitheoPartyBuff.Value;
}
}
private static void ApplyFury()
{
Spell spellById = GetSpellById("7328452");
if (!((Object)(object)spellById == (Object)null))
{
int spellDurationInTicks = Mathf.RoundToInt(FuryMinutes.Value * 10f);
spellById.SpellDurationInTicks = spellDurationInTicks;
spellById.GroupEffect = FuryPartyBuff.Value;
}
}
private static void ApplyProtection()
{
Spell spellById = GetSpellById("15855356");
if (!((Object)(object)spellById == (Object)null))
{
int spellDurationInTicks = Mathf.RoundToInt(ProtectionMinutes.Value * 10f);
spellById.SpellDurationInTicks = spellDurationInTicks;
spellById.GroupEffect = ProtectionPartyBuff.Value;
}
}
}