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 HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace DysonSphereJammerRange;
[BepInPlugin("w-gates.dysonsphereprogram.jammerrange", "DSP Jammer Range", "1.0.0")]
[BepInProcess("DSPGAME.exe")]
[BepInProcess("Dyson Sphere Program.exe")]
public class DysonSphereJammerRange : BaseUnityPlugin
{
public const string pluginGuid = "w-gates.dysonsphereprogram.jammerrange";
public const string pluginName = "DSP Jammer Range";
public const string pluginVersion = "1.0.0";
internal static ManualLogSource Logger;
internal static ConfigFile Config;
private Harmony harmony;
public static ConfigEntry<bool> configEnableDebug;
public static ConfigEntry<float> configBaseJammerRange;
public static ConfigEntry<bool> configIncreaseRangeWithUpgrade;
public void Awake()
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Config = ((BaseUnityPlugin)this).Config;
Logger.LogDebug((object)"Awake.");
try
{
InitialConfigSetup();
}
catch (Exception ex)
{
Logger.LogError((object)("Awake - Unable to set up config: " + ex.Message));
throw ex;
}
try
{
harmony = new Harmony("w-gates.dysonsphereprogram.jammerrange");
harmony.PatchAll(typeof(DysonSphereJammerRange));
}
catch (Exception ex2)
{
Logger.LogError((object)("Awake - Unable to patch: " + ex2.Message));
throw ex2;
}
Logger.LogInfo((object)"Awake - Initialization complete.");
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameMain), "Begin")]
public static void GameMain_Begin_Prefix()
{
if (configEnableDebug.Value)
{
Logger.LogDebug((object)"DSP Jammer Range: Calling - GameMain_Begin_Prefix.");
}
Config.Reload();
}
public void InitialConfigSetup()
{
try
{
configEnableDebug = Config.Bind<bool>("Config", "EnableDebug", false, "Enabling debug will add more feedback to the BepInEx console.");
configBaseJammerRange = Config.Bind<float>("Config", "BaseJammerRange", 40f, "The base Jammer Tower range. Default is 40m, the same as the base game.");
configIncreaseRangeWithUpgrade = Config.Bind<bool>("Config", "IncreaseWithUpgrade", true, "Increase Jammer Tower range by the same % amount granted by the EM Weapon Strengh upgrade. Max is +50% of base.");
}
catch (Exception ex)
{
Logger.LogError((object)("InitialConfigSetup - Bind Config: " + ex.Message));
throw ex;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(TurretComponent), "Shoot_Disturb")]
public static void TurretComponent_Shoot_Disturb_Prefix(ref PrefabDesc pdesc, ref CombatUpgradeData combatUpgradeData)
{
float num = configBaseJammerRange.Value;
if (configIncreaseRangeWithUpgrade.Value)
{
num *= (float)(int)((double)combatUpgradeData.magneticDamageScale * 1000.0 + 0.5) / 1000f;
}
pdesc.turretMaxAttackRange = num;
if (configEnableDebug.Value)
{
Logger.LogDebug((object)$"DSP Jammer Range: Jammer Tower Attack Range: {pdesc.turretMaxAttackRange}.");
}
}
}