Decompiled source of WorldWidePower v1.0.0

World.Wide.Power.v.1.0.0.dll

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

[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("Loki Moon Labs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("World Wide Power")]
[assembly: AssemblyTitle("WorldWidePower")]
[assembly: AssemblyVersion("1.0.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 WorldWidePower
{
	internal static class ModInfo
	{
		internal const string Guid = "com.lokimoonlabs.worldwidepower";

		internal const string Name = "World Wide Power";

		internal const string Version = "1.0.0";

		internal const string HarmonyId = "com.lokimoonlabs.worldwidepower.patches";
	}
	[HarmonyPatch]
	internal static class Patches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
		private static void AfterPreload()
		{
			WorldWidePowerLogic.ApplyPrefabRanges();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PowerSystem), "NewNodeComponent")]
		private static void BeforeNewNode(ref float __1, ref float __2)
		{
			WorldWidePowerLogic.ApplyNodeRange(ref __1, ref __2);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PowerSystem), "Import")]
		private static void AfterPowerSystemImport(PowerSystem __instance)
		{
			WorldWidePowerLogic.ApplyExistingPowerSystem(__instance);
		}
	}
	[BepInPlugin("com.lokimoonlabs.worldwidepower", "World Wide Power", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private Harmony harmony;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			harmony = new Harmony("com.lokimoonlabs.worldwidepower.patches");
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"World Wide Power v1.0.0 loaded.");
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
	internal static class WorldWidePowerLogic
	{
		internal const float PlanetWideRange = 1000f;

		private const float PlanetWideRangeSquared = 1000000f;

		internal static void ApplyNodeRange(ref float connectDistance, ref float coverRadius)
		{
			connectDistance = 1000f;
			coverRadius = 1000f;
		}

		internal static void ApplyPrefabRanges()
		{
			ItemProto[] array = ((ProtoSet<ItemProto>)(object)LDB.items)?.dataArray;
			if (array == null)
			{
				return;
			}
			for (int i = 0; i < array.Length; i++)
			{
				PrefabDesc val = array[i]?.prefabDesc;
				if (val != null && (val.isPowerNode || val.isPowerGen))
				{
					val.powerConnectDistance = 1000f;
					val.powerCoverRadius = 1000f;
				}
			}
		}

		internal static void ApplyExistingPowerSystem(PowerSystem powerSystem)
		{
			if (powerSystem == null || powerSystem.nodePool == null)
			{
				return;
			}
			int num = 0;
			for (int i = 1; i < powerSystem.nodeCursor; i++)
			{
				ref PowerNodeComponent reference = ref powerSystem.nodePool[i];
				if (reference.id == i && reference.entityId > 0)
				{
					reference.connectDistance = 1000f;
					reference.coverRadius = 1000f;
					if (num == 0 && reference.networkId > 0)
					{
						num = i;
					}
				}
			}
			UpdateCachedNetworkRanges(powerSystem);
			if (num != 0)
			{
				powerSystem.OnNodeRemoving(num);
				ref PowerNodeComponent reference2 = ref powerSystem.nodePool[num];
				reference2.connectDistance = 1000f;
				reference2.coverRadius = 1000f;
				powerSystem.OnNodeAdded(num);
				UpdateCachedNetworkRanges(powerSystem);
			}
		}

		private static void UpdateCachedNetworkRanges(PowerSystem powerSystem)
		{
			if (powerSystem.netPool == null)
			{
				return;
			}
			for (int i = 1; i < powerSystem.netCursor; i++)
			{
				PowerNetwork val = powerSystem.netPool[i];
				if (val == null || val.id != i || val.nodes == null)
				{
					continue;
				}
				for (int j = 0; j < val.nodes.Count; j++)
				{
					Node val2 = val.nodes[j];
					if (val2 != null)
					{
						val2.connDistance2 = 1000000f;
						val2.coverRadius2 = 1000000f;
					}
				}
			}
		}
	}
}