using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ChainExplosives")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ChainExplosives")]
[assembly: AssemblyTitle("ChainExplosives")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 ChainExplosives
{
[BepInPlugin("com.certifired.ChainExplosives", "ChainExplosives", "1.0.2")]
public class ChainExplosivesPlugin : BaseUnityPlugin
{
private const string MyGUID = "com.certifired.ChainExplosives";
private const string PluginName = "ChainExplosives";
private const string VersionString = "1.0.2";
private static readonly Harmony Harmony = new Harmony("com.certifired.ChainExplosives");
public static ManualLogSource Log;
public static HashSet<uint> trackedExplosiveIds = new HashSet<uint>();
public static List<ExplosiveInstance> explosives = new List<ExplosiveInstance>();
public static ConfigEntry<bool> debugMode;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
debugMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Debug Mode", false, "Enable debug logging for troubleshooting");
((BaseUnityPlugin)this).Logger.LogInfo((object)"ChainExplosives v1.0.2 is loading...");
Harmony.PatchAll(typeof(ExplosiveDefinitionPatch));
Harmony.PatchAll(typeof(ExplosiveInteractionPatch));
Harmony.PatchAll(typeof(ExplosiveInstancePatch));
((BaseUnityPlugin)this).Logger.LogInfo((object)"ChainExplosives v1.0.2 loaded - Interact with any explosive to detonate ALL placed explosives!");
}
public static void LogDebug(string message)
{
if (debugMode.Value)
{
Log.LogInfo((object)("[Debug] " + message));
}
}
}
[HarmonyPatch(typeof(ExplosiveDefinition))]
public static class ExplosiveDefinitionPatch
{
[HarmonyPatch("InitInstance")]
[HarmonyPostfix]
private static void TrackExplosive(ExplosiveDefinition __instance, ref ExplosiveInstance newInstance)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
if (newInstance.commonInfo.instanceId != 0)
{
uint instanceId = newInstance.commonInfo.instanceId;
if (!ChainExplosivesPlugin.trackedExplosiveIds.Contains(instanceId))
{
ChainExplosivesPlugin.trackedExplosiveIds.Add(instanceId);
ChainExplosivesPlugin.explosives.Add(newInstance);
ChainExplosivesPlugin.LogDebug($"Tracking explosive #{instanceId} (Total: {ChainExplosivesPlugin.explosives.Count})");
}
}
}
}
[HarmonyPatch(typeof(ExplosiveInteration))]
public static class ExplosiveInteractionPatch
{
[HarmonyPatch("Interact")]
[HarmonyPostfix]
private static void DetonateAllExplosives(ExplosiveInteration __instance)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: 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_0053: Unknown result type (might be due to invalid IL or missing references)
ChainExplosivesPlugin.Log.LogInfo((object)$"Chain detonation triggered! Detonating {ChainExplosivesPlugin.explosives.Count} explosives...");
List<ExplosiveInstance> list = new List<ExplosiveInstance>(ChainExplosivesPlugin.explosives);
int num = 0;
foreach (ExplosiveInstance item in list)
{
ExplosiveInstance current = item;
if (current.commonInfo.instanceId != 0)
{
try
{
ChainExplosivesPlugin.LogDebug($"Detonating explosive #{current.commonInfo.instanceId}");
((ExplosiveInstance)(ref current)).Detonate();
num++;
}
catch (Exception ex)
{
ChainExplosivesPlugin.Log.LogWarning((object)("Failed to detonate explosive: " + ex.Message));
}
}
}
ChainExplosivesPlugin.Log.LogInfo((object)$"Chain detonation complete! Detonated {num} explosives.");
ChainExplosivesPlugin.explosives.Clear();
ChainExplosivesPlugin.trackedExplosiveIds.Clear();
}
}
[HarmonyPatch(typeof(ExplosiveInstance))]
public static class ExplosiveInstancePatch
{
[HarmonyPatch("Detonate")]
[HarmonyPrefix]
private static void RemoveFromTracking(ExplosiveInstance __instance)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
if (__instance.commonInfo.instanceId == 0)
{
return;
}
uint instanceId = __instance.commonInfo.instanceId;
if (ChainExplosivesPlugin.trackedExplosiveIds.Contains(instanceId))
{
ChainExplosivesPlugin.trackedExplosiveIds.Remove(instanceId);
ChainExplosivesPlugin.explosives.RemoveAll((ExplosiveInstance e) => e.commonInfo.instanceId == instanceId);
ChainExplosivesPlugin.LogDebug($"Removed explosive #{instanceId} from tracking");
}
}
}
}