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.Logging;
using HarmonyLib;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace PlanetShieldEnhanced;
[BepInPlugin("boris.dsp.PlanetShieldEnhanced", "PlanetShieldEnhanced", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "boris.dsp.PlanetShieldEnhanced";
public const string PluginName = "PlanetShieldEnhanced";
public const string PluginVersion = "1.0.0";
public static ManualLogSource Log;
public void Awake()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
try
{
Harmony harmony = new Harmony("boris.dsp.PlanetShieldEnhanced");
PlanetWideShieldPatch.RegisterPatch(harmony);
GroundShieldPatch.RegisterPatches(harmony);
}
catch (Exception arg)
{
Log.LogError((object)$"[PlanetShield] Init failed: {arg}");
}
Log.LogInfo((object)"PlanetShieldEnhanced v1.0.0 loaded.");
}
}
public static class GroundShieldPatch
{
private static long GetEnergyPerDamage()
{
return GameMain.history.planetaryATFieldEnergyRate;
}
public static void RegisterPatches(Harmony harmony)
{
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Expected O, but got Unknown
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Expected O, but got Unknown
MethodInfo methodInfo = AccessTools.Method(typeof(SkillSystem), "DamageGroundObjectByLocalCaster", (Type[])null, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(SkillSystem), "DamageGroundObjectByRemoteCaster", (Type[])null, (Type[])null);
MethodInfo methodInfo3 = AccessTools.Method(typeof(GroundShieldPatch), "DamageGroundLocal", (Type[])null, (Type[])null);
MethodInfo methodInfo4 = AccessTools.Method(typeof(GroundShieldPatch), "DamageGroundRemote", (Type[])null, (Type[])null);
if (methodInfo != null)
{
harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo3), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
else
{
Plugin.Log.LogError((object)"[PlanetShield] Could not find DamageGroundObjectByLocalCaster");
}
if (methodInfo2 != null)
{
harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(methodInfo4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
else
{
Plugin.Log.LogError((object)"[PlanetShield] Could not find DamageGroundObjectByRemoteCaster");
}
}
public static void DamageGroundLocal(PlanetFactory factory, ref int damage, ref int slice, ref SkillTargetLocal target, ref SkillTargetLocal caster)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
TryAbsorbDamage(factory, ref damage, target.type);
}
public static void DamageGroundRemote(PlanetFactory factory, ref int damage, ref int slice, ref SkillTargetLocal target, ref SkillTarget caster)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
TryAbsorbDamage(factory, ref damage, target.type);
}
private static void TryAbsorbDamage(PlanetFactory factory, ref int damage, ETargetType targetType)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Invalid comparison between Unknown and I4
if (damage <= 0 || (int)targetType == 4)
{
return;
}
PlanetATField val = factory?.planetATField;
if (val == null || val.generatorCount <= 0 || val.energy <= 0)
{
return;
}
long num = GetEnergyPerDamage();
if (num <= 0)
{
num = 1L;
}
long num2 = damage * num;
if (val.energy >= num2)
{
val.energy -= num2;
damage = 0;
return;
}
int num3 = (int)(val.energy / num);
val.energy = 0L;
damage -= num3;
if (damage < 0)
{
damage = 0;
}
}
}
public static class PlanetWideShieldPatch
{
public static void RegisterPatch(Harmony harmony)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
MethodInfo methodInfo = AccessTools.Method(typeof(PlanetATField), "UpdateGeneratorMatrix", (Type[])null, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(PlanetWideShieldPatch), "Postfix", (Type[])null, (Type[])null);
if (methodInfo != null)
{
harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.Log.LogInfo((object)"[PlanetShield] Patched: PlanetATField.UpdateGeneratorMatrix");
}
else
{
Plugin.Log.LogError((object)"[PlanetShield] Could not find PlanetATField.UpdateGeneratorMatrix");
}
}
public static void Postfix(PlanetATField __instance)
{
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
int generatorCount = __instance.generatorCount;
if (generatorCount <= 0)
{
return;
}
float num = 0f;
for (int i = 0; i < generatorCount; i++)
{
num = Math.Max(__instance.generatorMatrix[i].w, num);
}
__instance.generatorCount = 0;
Array.Clear(__instance.generatorMatrix, 0, 80);
double num2 = 80.0;
double num3 = __instance.planet.realRadius;
int num4 = (int)Math.Ceiling(Math.PI * num3 / (2.0 * num2));
Vector4 val = default(Vector4);
val.x = 0f;
val.y = (float)num3;
val.z = 0f;
val.w = num;
Vector4[] generatorMatrix = __instance.generatorMatrix;
int generatorCount2 = __instance.generatorCount;
__instance.generatorCount = generatorCount2 + 1;
generatorMatrix[generatorCount2] = val;
for (int j = 1; j <= num4; j++)
{
double num5 = (double)j * Math.PI / (double)num4;
val.x = 0f;
val.y = (float)(num3 * Math.Cos(num5));
val.z = (float)(num3 * Math.Sin(num5));
val.w = num;
Vector4[] generatorMatrix2 = __instance.generatorMatrix;
generatorCount2 = __instance.generatorCount;
__instance.generatorCount = generatorCount2 + 1;
generatorMatrix2[generatorCount2] = val;
double num6 = num3 * Math.Sin(num5);
int num7 = (int)Math.Ceiling(Math.PI * num6 * 2.0 / (2.0 * num2));
for (int k = 1; k < num7; k++)
{
double num8 = (double)k * 2.0 * Math.PI / (double)num7;
val.x = (float)(num6 * Math.Sin(num8));
val.z = (float)(num6 * Math.Cos(num8));
Vector4[] generatorMatrix3 = __instance.generatorMatrix;
generatorCount2 = __instance.generatorCount;
__instance.generatorCount = generatorCount2 + 1;
generatorMatrix3[generatorCount2] = val;
}
}
}
}