Decompiled source of PlanetwideShield v1.0.0

PlanetwideShield.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("un1eagle")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("全球护盾")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e0a4636012e407982a6ebb7ca91022353cadd8b0")]
[assembly: AssemblyProduct("PlanetwideShield")]
[assembly: AssemblyTitle("PlanetwideShield")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 PlanetwideShield
{
	[HarmonyPatch(typeof(PlanetATField), "UpdateGeneratorMatrix")]
	public static class Patch_PlanetATField_UpdateGeneratorMatrix
	{
		private const int MaxGeneratorCount = 80;

		private const int VirtualPointCount = 48;

		private const float AdjacentDistanceThreshold = 40f;

		[HarmonyPostfix]
		public static void Postfix(PlanetATField __instance)
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			if (__instance?.planet == null || __instance.defense.fieldGenerators.count < 2 || !AreTwoGeneratorsWithinThreshold(__instance))
			{
				return;
			}
			int generatorCount = __instance.generatorCount;
			if (generatorCount > 0)
			{
				float num = 0f;
				for (int i = 0; i < generatorCount; i++)
				{
					num = Math.Max(__instance.generatorMatrix[i].w, num);
				}
				Vector4[] array = BuildVirtualPoints(__instance.planet.realRadius, 48, num);
				int num2 = Mathf.Min(array.Length, 80);
				if (__instance.generatorMatrix == null || __instance.generatorMatrix.Length < num2)
				{
					__instance.generatorMatrix = (Vector4[])(object)new Vector4[80];
				}
				for (int j = 0; j < num2; j++)
				{
					__instance.generatorMatrix[j] = array[j];
				}
				for (int k = num2; k < 80; k++)
				{
					__instance.generatorMatrix[k] = default(Vector4);
				}
				__instance.generatorCount = num2;
				__instance.SetPhysicsChangeSensitivity(10000f);
			}
		}

		private static bool AreTwoGeneratorsWithinThreshold(PlanetATField field)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			DataPool<FieldGeneratorComponent> fieldGenerators = field.defense.fieldGenerators;
			FieldGeneratorComponent[] buffer = fieldGenerators.buffer;
			int cursor = fieldGenerators.cursor;
			float num = 1600f;
			Vector3 val = default(Vector3);
			Vector3 val2 = default(Vector3);
			for (int i = 1; i < cursor; i++)
			{
				if (buffer[i].id != i)
				{
					continue;
				}
				Vector4 holder = buffer[i].holder;
				((Vector3)(ref val))..ctor(holder.x, holder.y, holder.z);
				for (int j = i + 1; j < cursor; j++)
				{
					if (buffer[j].id == j)
					{
						Vector4 holder2 = buffer[j].holder;
						((Vector3)(ref val2))..ctor(holder2.x, holder2.y, holder2.z);
						Vector3 val3 = val - val2;
						if (((Vector3)(ref val3)).sqrMagnitude < num)
						{
							return true;
						}
					}
				}
			}
			return false;
		}

		private static Vector4[] BuildVirtualPoints(float planetRadius, int count, float w)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			Vector4[] array = (Vector4[])(object)new Vector4[count];
			for (int i = 0; i < count; i++)
			{
				float num = (float)(i + 1) / (float)(count + 1);
				float num2 = Mathf.Acos(1f - 2f * num);
				float num3 = (float)Math.PI * 2f * (1f + Mathf.Sqrt(5f)) / 2f * (float)i;
				float num4 = Mathf.Sin(num2) * Mathf.Cos(num3);
				float num5 = Mathf.Sin(num2) * Mathf.Sin(num3);
				float num6 = Mathf.Cos(num2);
				Vector3 val = new Vector3(num4, num5, num6) * planetRadius;
				array[i] = new Vector4(val.x, val.y, val.z, w);
			}
			return array;
		}
	}
	[BepInPlugin("un1eagle.planetwideshield", "全球护盾", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource? Log;

		public static ConfigEntry<bool> EnableDebugLog;

		public static bool DebugLog()
		{
			return EnableDebugLog?.Value ?? false;
		}

		private void Awake()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"[全球护盾] 正在加载... (GUID: un1eagle.planetwideshield)");
			EnableDebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableDebugLog", false, "为 true 时在日志中输出详细的调试信息,用于排查问题。正常使用时建议设置为 false。");
			new Harmony("un1eagle.planetwideshield").PatchAll(typeof(Plugin).Assembly);
			ManualLogSource? log = Log;
			if (log != null)
			{
				log.LogInfo((object)"[全球护盾] ✅ 加载完成!");
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "un1eagle.planetwideshield";

		public const string PLUGIN_NAME = "全球护盾";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}