Decompiled source of DarkFogGasGiants v1.0.2

DarkFogGasGiants.dll

Decompiled 3 weeks ago
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 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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DarkFogGasGiants
{
	public static class GasGiantPatch
	{
		private const int DFMatrix = 5201;

		private const int SiliconNeuron = 5202;

		private const int MatterRecombinator = 5203;

		private const int NegentropySingularity = 5204;

		private const int CoreElement = 5205;

		private const int EnergyShard = 5206;

		private static readonly int[] GroupA = new int[3] { 5201, 5202, 5203 };

		private static readonly int[] GroupB = new int[3] { 5204, 5205, 5206 };

		private static readonly float[] GroupASpeeds = new float[3] { 0.5f, 0.3f, 0.2f };

		private static readonly float[] GroupBSpeeds = new float[3] { 0.2f, 0.3f, 0.5f };

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlanetGen), "SetPlanetTheme")]
		public static void SetPlanetThemePostfix(PlanetData planet, int theme_seed)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			if (!Plugin.GalacticScaleLoaded && (int)planet.type == 5)
			{
				Random random = new Random(planet.seed);
				bool num = random.Next(2) == 0;
				int[] array = (num ? GroupA : GroupB);
				float[] array2 = (num ? GroupASpeeds : GroupBSpeeds);
				int[] gasItems = planet.gasItems;
				int num2 = ((gasItems != null) ? gasItems.Length : 0);
				int num3 = num2 + 3;
				int[] array3 = new int[num3];
				float[] array4 = new float[num3];
				float[] array5 = new float[num3];
				for (int i = 0; i < num2; i++)
				{
					array3[i] = planet.gasItems[i];
					array4[i] = planet.gasSpeeds[i];
					array5[i] = planet.gasHeatValues[i];
				}
				double num4 = planet.gasTotalHeat;
				for (int j = 0; j < 3; j++)
				{
					int num5 = (array3[num2 + j] = array[j]);
					float num6 = array2[j];
					num6 *= (float)random.NextDouble() * 0.19090915f + 0.9090909f;
					num6 = (array4[num2 + j] = num6 * Mathf.Pow(planet.star.resourceCoef, 0.3f));
					num4 += (double)((array5[num2 + j] = ((float?)((ProtoSet<ItemProto>)(object)LDB.items).Select(num5)?.HeatValue) ?? 0f) * num6);
				}
				planet.gasItems = array3;
				planet.gasSpeeds = array4;
				planet.gasHeatValues = array5;
				planet.gasTotalHeat = num4;
			}
		}

		public static void AddDarkFogItems(PlanetData planet)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)planet.type != 5)
			{
				return;
			}
			if (planet.gasItems != null)
			{
				for (int i = 0; i < planet.gasItems.Length; i++)
				{
					if (planet.gasItems[i] >= 5201 && planet.gasItems[i] <= 5206)
					{
						return;
					}
				}
			}
			Random random = new Random(planet.seed);
			bool num = random.Next(2) == 0;
			int[] array = (num ? GroupA : GroupB);
			float[] array2 = (num ? GroupASpeeds : GroupBSpeeds);
			int[] gasItems = planet.gasItems;
			int num2 = ((gasItems != null) ? gasItems.Length : 0);
			int num3 = num2 + 3;
			int[] array3 = new int[num3];
			float[] array4 = new float[num3];
			float[] array5 = new float[num3];
			for (int j = 0; j < num2; j++)
			{
				array3[j] = planet.gasItems[j];
				array4[j] = planet.gasSpeeds[j];
				array5[j] = planet.gasHeatValues[j];
			}
			double num4 = planet.gasTotalHeat;
			for (int k = 0; k < 3; k++)
			{
				int num5 = (array3[num2 + k] = array[k]);
				float num6 = array2[k];
				num6 *= (float)random.NextDouble() * 0.19090915f + 0.9090909f;
				num6 = (array4[num2 + k] = num6 * Mathf.Pow(planet.star.resourceCoef, 0.3f));
				num4 += (double)((array5[num2 + k] = ((float?)((ProtoSet<ItemProto>)(object)LDB.items).Select(num5)?.HeatValue) ?? 0f) * num6);
			}
			planet.gasItems = array3;
			planet.gasSpeeds = array4;
			planet.gasHeatValues = array5;
			planet.gasTotalHeat = num4;
		}
	}
	[BepInPlugin("com.leo.dsp.DarkFogGasGiants", "DarkFogGasGiants", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.leo.dsp.DarkFogGasGiants";

		public const string PluginName = "DarkFogGasGiants";

		public const string PluginVersion = "1.0.1";

		public static bool GalacticScaleLoaded;

		public static ManualLogSource Log;

		private Harmony _harmony;

		public void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("com.leo.dsp.DarkFogGasGiants");
			_harmony.PatchAll(typeof(GasGiantPatch));
			TryPatchGalacticScale();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"DarkFogGasGiants 1.0.1 loaded.");
		}

		private void TryPatchGalacticScale()
		{
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			try
			{
				Assembly assembly = null;
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly2 in assemblies)
				{
					((BaseUnityPlugin)this).Logger.LogDebug((object)("Checking assembly: " + assembly2.GetName().Name));
					if (assembly2.GetName().Name == "GalacticScale")
					{
						assembly = assembly2;
						break;
					}
				}
				if (assembly == null)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Galactic Scale not detected");
					return;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Galactic Scale assembly found");
				GalacticScaleLoaded = true;
				Type type = assembly.GetType("GalacticScale.GS2");
				if (type == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"GS2 type not found");
					return;
				}
				MethodInfo method = type.GetMethod("SetPlanetTheme", BindingFlags.Static | BindingFlags.Public);
				if (method == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"GS2.SetPlanetTheme not found");
					return;
				}
				MethodInfo method2 = typeof(GasGiantPatch).GetMethod("AddDarkFogItems", BindingFlags.Static | BindingFlags.Public);
				_harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Galactic Scale compatibility enabled - patched GS2.SetPlanetTheme");
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Failed to patch Galactic Scale: {arg}");
			}
		}

		public void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}