using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
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("MySecondBepInExMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MySecondBepInExMod")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("33e4b163-a712-4f97-8e38-4bf1b885afd3")]
[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 ControllableExplosiveEgg
{
[BepInPlugin("nexor.ControllableExplosiveEgg", "ControllableExplosiveEgg", "0.0.7")]
public class ControllableExplosiveEgg : BaseUnityPlugin
{
private const string modGUID = "nexor.ControllableExplosiveEgg";
private const string modName = "ControllableExplosiveEgg";
private const string modVersion = "0.0.7";
private readonly Harmony harmony = new Harmony("nexor.ControllableExplosiveEgg");
public ConfigEntry<float> my_explode_chance;
public ConfigEntry<bool> my_explode_prediction;
public ConfigEntry<bool> my_better_egg;
public static ControllableExplosiveEgg Instance;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
my_better_egg = ((BaseUnityPlugin)this).Config.Bind<bool>("Controllable Explosive Egg Config", "Whether to enable better egg mode", true, "是否启用更好的彩蛋模式,即G键丢下彩蛋不爆炸,左键丢出彩蛋必爆炸 (仅做server时对自己有效)\nWhether to enable a better Easter egg mode, that is, the G button will not explode when the Easter egg is dropped, and the left-click will explode when the Easter egg is thrown (only server & only works on yourself)");
my_explode_chance = ((BaseUnityPlugin)this).Config.Bind<float>("Controllable Explosive Egg Config", "Egg Explode Chance (%)", 16f, "你可以在这里修改全局的彩蛋爆炸的概率 (仅做server时有效)\nYou can modify the probability of everyone's egg's exploding here (only server)");
my_explode_prediction = ((BaseUnityPlugin)this).Config.Bind<bool>("Controllable Explosive Egg Config", "Explode Prediction", true, "当彩蛋出现在手上时游戏会计算该彩蛋是否会爆炸,是否将结果展示给你?(仅对自己有效,且如果自己不是server则可能会误报但不会漏报) 如果更好的彩蛋模式正常工作,则自动忽略本项\nWhen the Easter egg appears in hand, the game accountant calculates whether the egg will explode and displays the result to you? (only works on yourself, and if you are not a server, you may have false positives but no false negatives). If Better Easter Egg Mode is working fine, this item will be automatically ignored");
if (my_explode_chance.Value >= 99.99f)
{
my_explode_chance.Value = 99.99f;
}
harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"ControllableExplosiveEgg 0.0.7 loaded.");
}
}
}
namespace ControllableExplosiveEgg.Patches.Items
{
[HarmonyPatch(typeof(StunGrenadeItem))]
[HarmonyPatch("EquipItem")]
internal class StunGrenadeItem_EquipItem_Patch
{
[HarmonyPrefix]
private static void Prefix(StunGrenadeItem __instance)
{
NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
if (networkManager.IsServer && __instance.dontRequirePullingPin)
{
__instance.chanceToExplode = ControllableExplosiveEgg.Instance.my_explode_chance.Value;
}
}
}
[HarmonyPatch(typeof(StunGrenadeItem))]
[HarmonyPatch("SetExplodeOnThrowClientRpc")]
internal class StunGrenadeItem_SetExplodeOnThrowClientRpc_Patch
{
[HarmonyPostfix]
private static void Postfix(StunGrenadeItem __instance, bool explode)
{
NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
if ((!ControllableExplosiveEgg.Instance.my_better_egg.Value || !networkManager.IsServer) && explode && (Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)StartOfRound.Instance.localPlayerController)
{
if (networkManager.IsServer)
{
HUDManager.Instance.DisplayTip("Warning!", "will explode on next drop!!!", false, false, "LC_Tip1");
}
else
{
HUDManager.Instance.DisplayTip("Warning!", "might explode on next drop!!!", false, false, "LC_Tip1");
}
}
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
[HarmonyPatch("DiscardHeldObject")]
internal class PlayerControllerB_DiscardHeldObject_Patch
{
[HarmonyPrefix]
private static void Prefix(PlayerControllerB __instance, bool placeObject = false)
{
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
if (ControllableExplosiveEgg.Instance.my_better_egg.Value && networkManager.IsServer && (Object)(object)__instance == (Object)(object)StartOfRound.Instance.localPlayerController && __instance.currentlyHeldObjectServer is StunGrenadeItem && __instance.currentlyHeldObjectServer.itemProperties.itemName.Contains("egg"))
{
if (placeObject)
{
((StunGrenadeItem)__instance.currentlyHeldObjectServer).chanceToExplode = 99.99f;
}
else
{
((StunGrenadeItem)__instance.currentlyHeldObjectServer).chanceToExplode = 0f;
}
((StunGrenadeItem)__instance.currentlyHeldObjectServer).SetExplodeOnThrowServerRpc();
}
}
}
}