using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BlackoutHazards")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BlackoutHazards")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("de0ddf87-f738-4090-8db2-ad18c90d4883")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BlackoutHazards;
[BepInPlugin("Toshizuno.BlackoutHazards", "Blackout Hazards", "1.0.1")]
public class BlackoutHazardPlugin : BaseUnityPlugin
{
private static BlackoutHazardPlugin Instance;
private readonly Harmony Patcher = new Harmony("Toshizuno.BlackoutHazards");
private readonly MethodInfo LandmineUpdate = typeof(Landmine).GetMethod("Update", BindingFlags.Instance | BindingFlags.NonPublic);
private readonly MethodInfo SpikeRoofTrapUpdate = typeof(SpikeRoofTrap).GetMethod("Update");
private readonly MethodInfo TurretUpdate = typeof(Turret).GetMethod("Update", BindingFlags.Instance | BindingFlags.NonPublic);
private ConfigEntry<bool> Landmines;
private ConfigEntry<bool> SpikeRoofTraps;
private ConfigEntry<bool> Turrets;
private static void LandmineUpdatePatch(Landmine __instance)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
if (((NetworkBehaviour)RoundManager.Instance).IsHost)
{
BreakerBox val = (BreakerBox)Object.FindObjectOfType(typeof(BreakerBox));
bool flag = (bool)Traverse.Create((object)__instance).Field("mineActivated").GetValue();
if (flag != val.isPowerOn)
{
__instance.ToggleMine(val.isPowerOn);
}
}
}
private static void SpikeRoofTrapUpdatePatch(SpikeRoofTrap __instance)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
if (((NetworkBehaviour)RoundManager.Instance).IsHost)
{
BreakerBox val = (BreakerBox)Object.FindObjectOfType(typeof(BreakerBox));
if (__instance.trapActive != val.isPowerOn)
{
__instance.ToggleSpikesEnabled(val.isPowerOn);
}
}
}
private static void TurretUpdatePatch(Turret __instance)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Invalid comparison between Unknown and I4
if (((NetworkBehaviour)RoundManager.Instance).IsHost)
{
BreakerBox val = (BreakerBox)Object.FindObjectOfType(typeof(BreakerBox));
TurretMode val2 = (TurretMode)Traverse.Create((object)__instance).Field("turretModeLastFrame").GetValue();
if (__instance.turretActive != val.isPowerOn && ((int)val2 == 0 || (int)val2 == 1))
{
__instance.ToggleTurretEnabled(val.isPowerOn);
}
}
}
private void Awake()
{
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Expected O, but got Unknown
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Expected O, but got Unknown
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Expected O, but got Unknown
Instance = Instance ?? this;
Landmines = ((BaseUnityPlugin)this).Config.Bind<bool>("Hazards", "Landmines", true, "Landmines are disabled when the breaker is turned off.");
SpikeRoofTraps = ((BaseUnityPlugin)this).Config.Bind<bool>("Hazards", "SpikeRoofTraps", true, "Spike Roof Traps are disabled when the breaker is turned off.");
Turrets = ((BaseUnityPlugin)this).Config.Bind<bool>("Hazards", "Turrets", true, "Turrets are disabled when the breaker is turned off.");
if (Instance.Landmines.Value)
{
Patcher.Patch((MethodBase)LandmineUpdate, (HarmonyMethod)null, new HarmonyMethod(typeof(BlackoutHazardPlugin).GetMethod("LandmineUpdatePatch", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
if (Instance.SpikeRoofTraps.Value)
{
Patcher.Patch((MethodBase)SpikeRoofTrapUpdate, (HarmonyMethod)null, new HarmonyMethod(typeof(BlackoutHazardPlugin).GetMethod("SpikeRoofTrapUpdatePatch", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
if (Instance.Turrets.Value)
{
Patcher.Patch((MethodBase)TurretUpdate, (HarmonyMethod)null, new HarmonyMethod(typeof(BlackoutHazardPlugin).GetMethod("TurretUpdatePatch", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
}