using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DisableFox.config;
using DisableFox.patches;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DisableFox")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DisableFox")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("091c8d72-c9b5-4ee1-81f7-a5ba0cb82774")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DisableFox
{
[BepInPlugin("Zesa.DisableFox", "DisableFox", "1.0.3.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class DisableFoxBase : BaseUnityPlugin
{
private const string modGUID = "Zesa.DisableFox";
private const string modName = "DisableFox";
private const string modVersion = "1.0.3.0";
private static DisableFoxBase Instance;
private readonly Harmony harmony = new Harmony("Zesa.DisableFox");
public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger;
internal static DisableFoxConfig DFC { get; private set; }
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
DFC = new DisableFoxConfig(((BaseUnityPlugin)this).Config);
DFC.disableItemDrop.SettingChanged += delegate
{
Log.LogInfo((object)"Repatching BushWolfEnemy::Update()..");
harmony.Unpatch((MethodBase)typeof(BushWolfEnemy).GetMethod("Update"), (HarmonyPatchType)3, (string)null);
};
harmony.PatchAll(typeof(RoundManagerPatch));
Log.LogInfo((object)"Patched RoundManager..");
harmony.PatchAll(typeof(BushWolfEnemyPatch));
Log.LogInfo((object)"Patched BushWolfEnemy..");
}
}
}
namespace DisableFox.patches
{
[HarmonyPatch(typeof(BushWolfEnemy))]
public class BushWolfEnemyPatch
{
private static int origIdx = -1;
private static List<CodeInstruction> origInstructions = new List<CodeInstruction>();
private static bool beenRemoved = false;
[HarmonyPatch("Start")]
[HarmonyPostfix]
public static void modifyFox(ref BushWolfEnemy __instance)
{
if (!DisableFoxBase.DFC.disableFox.Value && DisableFoxBase.DFC.foxHp.Value != 7)
{
DisableFoxBase.Log.LogInfo((object)$"Modified fox health | Old: {((EnemyAI)__instance).enemyHP} New: {DisableFoxBase.DFC.foxHp.Value}");
((EnemyAI)__instance).enemyHP = DisableFoxBase.DFC.foxHp.Value;
}
}
[HarmonyPatch("Update")]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> disableItemDropOnHit(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Callvirt && list[i].operand.ToString().Contains("DropAll"))
{
DisableFoxBase.Log.LogInfo((object)"Found call to DropAllHeldItemsAndSync");
origIdx = i - 2;
break;
}
}
if (origInstructions.Count == 0)
{
origInstructions.AddRange(list.GetRange(origIdx, 3));
}
if (DisableFoxBase.DFC.disableItemDrop.Value)
{
list.RemoveRange(origIdx, 3);
beenRemoved = true;
}
else if (!DisableFoxBase.DFC.disableItemDrop.Value && beenRemoved)
{
list.InsertRange(origIdx, origInstructions);
beenRemoved = false;
}
DisableFoxBase.Log.LogInfo((object)$"modified DropAllHeldItemsAndSync call | callable: {!DisableFoxBase.DFC.disableItemDrop.Value}");
return list.AsEnumerable();
}
}
[HarmonyPatch(typeof(RoundManager))]
public class RoundManagerPatch
{
[HarmonyPatch("LoadNewLevelWait")]
[HarmonyPrefix]
public static void noMold(ref RoundManager __instance)
{
if (DisableFoxBase.DFC.disableFox.Value && __instance.currentLevel.moldSpreadIterations > 0)
{
DisableFoxBase.Log.LogInfo((object)$"Prevented Vain Shrouds from spawning | Nodes prevented: {__instance.currentLevel.moldSpreadIterations}");
__instance.currentLevel.moldSpreadIterations = 0;
}
}
}
}
namespace DisableFox.config
{
internal class DisableFoxConfig
{
public readonly ConfigEntry<bool> disableFox;
public readonly ConfigEntry<int> foxHp;
public readonly ConfigEntry<bool> disableItemDrop;
public DisableFoxConfig(ConfigFile cfg)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Expected O, but got Unknown
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Expected O, but got Unknown
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Expected O, but got Unknown
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Expected O, but got Unknown
cfg.SaveOnConfigSet = false;
disableFox = cfg.Bind<bool>("General", "Disable Fox", true, "Prevents Vain Shrouds from spawning and therfore the fox cant spawn. Has to be applied before start of round. *Requires Host");
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(disableFox, false));
foxHp = cfg.Bind<int>("Modifications", "Fox Healthpoints", 7, "When the fox is not disabled, this value determines the foxes healthpoints. Has to be applied before start of round. *Requires Host");
ConfigEntry<int> obj = foxHp;
IntSliderOptions val = new IntSliderOptions();
((BaseRangeOptions<int>)val).Min = 1;
((BaseRangeOptions<int>)val).Max = 7;
((BaseOptions)val).RequiresRestart = false;
LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(obj, val));
disableItemDrop = cfg.Bind<bool>("Modifications", "Disable Item Drop", true, "Prevents Items from dropping when hit by fox tongue. Only applies to local player.");
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(disableItemDrop, false));
cfg.Save();
cfg.SaveOnConfigSet = true;
}
}
}