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.Configuration;
using BepInEx.Logging;
using ExplodingPresents.Patches;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("ExplodingPresents")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Santa packed a boom in these presents!")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1")]
[assembly: AssemblyProduct("ExplodingPresents")]
[assembly: AssemblyTitle("ExplodingPresents")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
namespace ExplodingPresents
{
[BepInPlugin("ExplodingPresents", "ExplodingPresents", "1.1.1")]
public class Plugin : BaseUnityPlugin
{
private bool _patched;
public static ConfigEntry<int> ChanceConfig;
public static int Chance;
public static ManualLogSource Logger { get; set; }
private void Awake()
{
if (_patched)
{
Logger.LogWarning((object)"Already Patched");
return;
}
ChanceConfig = ((BaseUnityPlugin)this).Config.Bind<int>("General", "SpawnChance", 20, "The chance a present has to blow up");
Chance = ChanceConfig.Value;
Logger = ((BaseUnityPlugin)this).Logger;
Harmony.CreateAndPatchAll(typeof(PresentsPatch), "ExplodingPresents");
Logger.LogInfo((object)string.Format("Plugin {0} is loaded, with a chance value of {1}", "ExplodingPresents", Chance));
_patched = true;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "ExplodingPresents";
public const string PLUGIN_NAME = "ExplodingPresents";
public const string PLUGIN_VERSION = "1.1.1";
}
}
namespace ExplodingPresents.Patches
{
internal class PresentsPatch
{
[HarmonyPatch(typeof(GiftBoxItem), "OpenGiftBoxServerRpc")]
[HarmonyPostfix]
private static void GiftBoxPatch(GiftBoxItem __instance)
{
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
if (NetworkManager.Singleton.IsServer)
{
Random random = new Random();
int num2;
try
{
double num = 1.0 / (double)Plugin.Chance;
double value = num * 100.0;
int maxValue = (int)Math.Round(value, 0);
num2 = random.Next(0, maxValue);
}
catch (Exception ex)
{
Plugin.Logger.LogError((object)"Chance not set to 0-100!");
Plugin.Logger.LogError((object)ex);
return;
}
if (num2 == 0)
{
Landmine val = Resources.FindObjectsOfTypeAll<Landmine>()[0];
AudioSource component = ((Component)__instance).gameObject.GetComponent<AudioSource>();
component.PlayOneShot(val.mineTrigger, 1f);
new WaitForSecondsRealtime(0.3f);
component.PlayOneShot(val.mineDetonate, 1f);
Landmine.SpawnExplosion(((Component)__instance).transform.position, true, 10f, 10f);
}
}
}
}
}