using System;
using System.Collections;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using TurretWhacker.Config;
using TurretWhacker.Patches;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("magico13.TurretWhacker")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b5a1f909292187ad3e67b88fe1db0c3e8c0c5857")]
[assembly: AssemblyProduct("TurretWhacker")]
[assembly: AssemblyTitle("magico13.TurretWhacker")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 TurretWhacker
{
[BepInPlugin("magico13.TurretWhacker", "TurretWhacker", "1.0.0")]
public class TurretWhacker : BaseUnityPlugin
{
public static TurretWhacker Instance { get; private set; }
internal static PluginConfig PluginConfig { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static Harmony? Harmony { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
PluginConfig = new PluginConfig(((BaseUnityPlugin)this).Config);
Patch();
Logger.LogDebug((object)"magico13.TurretWhacker v1.0.0 has loaded!");
}
internal static void Patch()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("magico13.TurretWhacker");
}
Logger.LogDebug((object)"Patching...");
Harmony.CreateAndPatchAll(typeof(TurretPatch), (string)null);
Logger.LogDebug((object)"Finished patching!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "magico13.TurretWhacker";
public const string PLUGIN_NAME = "TurretWhacker";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace TurretWhacker.Patches
{
public class TurretPatch
{
[HarmonyPatch(typeof(Turret), "IHittable.Hit")]
[HarmonyPrefix]
public static bool Hit(Turret __instance, ref bool __result)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
if ((int)__instance.turretMode == 3 || !__instance.turretActive)
{
return true;
}
float num = Random.Range(0f, 1f);
float value = TurretWhacker.PluginConfig.NoEffectChance.Value;
float value2 = TurretWhacker.PluginConfig.SuccessChance.Value;
float value3 = TurretWhacker.PluginConfig.CriticalSuccessChance.Value;
TerminalAccessibleObject component = ((Component)__instance).GetComponent<TerminalAccessibleObject>();
string objectCode = component.objectCode;
float num2 = 0f;
if (num < (num2 += value))
{
TurretWhacker.Logger.LogDebug((object)$"Turret {objectCode} has been hit! Random value: {num}. No effect.");
}
else if (num < (num2 += value2))
{
TurretWhacker.Logger.LogDebug((object)$"Turret {objectCode} has been hit! Random value: {num}. Turret is being disabled.");
((MonoBehaviour)__instance).StartCoroutine(DisableTurretFromTerminal(__instance, component));
}
else
{
if (!(num < (num2 += value3)))
{
TurretWhacker.Logger.LogDebug((object)$"Turret {objectCode} has been hit! Random value: {num}. Turret is beserk.");
return true;
}
TurretWhacker.Logger.LogDebug((object)$"Turret {objectCode} has been hit! Random value: {num}. Turret is being permanently disabled.");
((MonoBehaviour)__instance).StartCoroutine(DisableTurretPermanently(__instance));
}
__result = true;
return false;
}
public static IEnumerator DisableTurretFromTerminal(Turret turret, TerminalAccessibleObject terminalObject)
{
turret.SwitchTurretMode(0);
turret.SetToModeClientRpc(0);
yield return 0;
terminalObject.CallFunctionFromTerminal();
}
public static IEnumerator DisableTurretPermanently(Turret turret)
{
turret.SwitchTurretMode(0);
turret.SetToModeClientRpc(0);
yield return 0;
turret.ToggleTurretEnabled(false);
}
}
}
namespace TurretWhacker.Config
{
public class PluginConfig
{
public ConfigEntry<float> NoEffectChance { get; }
public ConfigEntry<float> SuccessChance { get; }
public ConfigEntry<float> CriticalSuccessChance { get; }
public PluginConfig(ConfigFile config)
{
config.SaveOnConfigSet = false;
NoEffectChance = config.Bind<float>("General", "NoEffectChance", 0.1f, "The chance that nothing at all happens when a turret it hit.");
SuccessChance = config.Bind<float>("General", "SuccessChance", 0.8f, "The chance that the turret is disabled when hit.");
CriticalSuccessChance = config.Bind<float>("General", "CriticalSuccessChance", 0.01f, "The chance that the turret is permanently disabled when hit.");
config.Save();
config.SaveOnConfigSet = true;
}
}
}