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 FishNet.Object;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HowToFish.TNTChaos")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("HowToFish.TNTChaos")]
[assembly: AssemblyTitle("HowToFish.TNTChaos")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 HowToFish.TNTChaos
{
[BepInPlugin("community.howtofish.tntchaos", "TNT Chaos", "0.2.0")]
[BepInProcess("How to Fish.exe")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(Item), "get_Cost")]
private class PatchCost
{
private static bool Prefix(Item __instance, ref int __result)
{
if (IsTNT(__instance))
{
__result = TNTPrice.Value;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Item), "get_DefaultWorth")]
private class PatchDefaultWorth
{
private static bool Prefix(Item __instance, ref int __result)
{
if (IsTNT(__instance))
{
__result = TNTPrice.Value;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Item), "get_TotalWorth")]
private class PatchTotalWorth
{
private static bool Prefix(Item __instance, ref int __result)
{
if (IsTNT(__instance))
{
__result = TNTPrice.Value;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Explosive), "RpcLogic___ObserverActivate___1538889672")]
private class PatchActivate
{
private static void Postfix(Explosive __instance)
{
if (Enabled.Value && ((NetworkBehaviour)__instance).IsServerInitialized && !(_timeUntilExplosionField == null))
{
float num = InstantChance.Value;
float num2 = DudChance.Value;
if (num + num2 > 1f)
{
float num3 = 1f / (num + num2);
num *= num3;
num2 *= num3;
}
float value = Random.value;
if (value < num)
{
_timeUntilExplosionField.SetValue(__instance, 0.001f);
DudSet.Remove(__instance);
}
else if (value < num + num2)
{
DudSet.Add(__instance);
}
}
}
}
[HarmonyPatch(typeof(Explosive), "ServerExplode")]
private class PatchServerExplode
{
private static bool Prefix(Explosive __instance)
{
if (!Enabled.Value)
{
return true;
}
if (DudSet.Contains(__instance))
{
DudSet.Remove(__instance);
if (_hasExplodedField != null)
{
_hasExplodedField.SetValue(__instance, true);
}
return false;
}
DudSet.Remove(__instance);
return true;
}
}
private static Plugin Instance;
private static Harmony Harmony;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<float> InstantChance;
internal static ConfigEntry<float> DudChance;
internal static ConfigEntry<int> TNTPrice;
private static FieldInfo _timeUntilExplosionField;
private static FieldInfo _hasExplodedField;
private static readonly HashSet<Explosive> DudSet = new HashSet<Explosive>();
private void Awake()
{
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Expected O, but got Unknown
Instance = this;
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable random TNT outcomes");
InstantChance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "InstantChance", 0.12f, "Chance to explode instantly (0-1)");
DudChance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DudChance", 0.12f, "Chance to be a dud (no explosion, 0-1)");
TNTPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Price", "TNTPrice", 1, "TNT buy & sell price override (1 = costs/sells for $1). Set to the original value to disable.");
Type typeFromHandle = typeof(Explosive);
_timeUntilExplosionField = typeFromHandle.GetField("_timeUntilExplosion", BindingFlags.Instance | BindingFlags.NonPublic);
_hasExplodedField = typeFromHandle.GetField("_hasExploded", BindingFlags.Instance | BindingFlags.NonPublic);
Harmony = new Harmony("community.howtofish.tntchaos");
Harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"TNT Chaos 0.2.0 loaded");
}
private static bool IsTNT(Item item)
{
if (item == null)
{
return false;
}
return (Object)(object)((Component)item).GetComponent<Explosive>() != (Object)null;
}
}
}