Decompiled source of Genesis Fix V0 10 35 v0.0.1

GenesisVeinHeightFix.dll

Decompiled 9 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[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: AssemblyVersion("0.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
}
namespace DSPGenesisVeinHeightFix
{
	[BepInPlugin("DSP.Kawaayi.GenesisVeinHeightFix", "Genesis Fix V0.10.35", "0.0.1")]
	[BepInProcess("DSPGAME.exe")]
	public sealed class GenesisVeinHeightFixPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "DSP.Kawaayi.GenesisVeinHeightFix";

		public const string PluginName = "Genesis Fix V0.10.35";

		public const string PluginVersion = "0.0.1";

		private Harmony? _harmony;

		private bool _hooked;

		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("DSP.Kawaayi.GenesisVeinHeightFix");
			AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;
			BirthStarCreatePlanetFix.TryHook(_harmony, ((BaseUnityPlugin)this).Logger);
			TryHook();
			int num = PatchGenerateVeinsDirect();
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} {1} loaded. genesisHooks={2} directVeinPatches={3}", "Genesis Fix V0.10.35", "0.0.1", GenesisBrokenPatchFix.HookCount, num));
		}

		private void OnDestroy()
		{
			AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoad;
			Harmony? harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args)
		{
			try
			{
				string name = args.LoadedAssembly.GetName().Name;
				if (name == "ProjectGenesis" || name == "GenesisBook")
				{
					TryHook();
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("OnAssemblyLoad: " + ex.Message));
			}
		}

		private void TryHook()
		{
			if (_hooked || _harmony == null)
			{
				return;
			}
			try
			{
				GenesisBrokenPatchFix.TryHook(_harmony, ((BaseUnityPlugin)this).Logger);
				BirthStarCreatePlanetFix.TryHook(_harmony, ((BaseUnityPlugin)this).Logger);
				if (GenesisBrokenPatchFix.HookCount > 0)
				{
					_hooked = true;
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("TryHook failed: " + ex));
			}
		}

		private int PatchGenerateVeinsDirect()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			int num = 0;
			string[] array = new string[4] { "PlanetAlgorithm", "PlanetAlgorithm11", "PlanetAlgorithm12", "PlanetAlgorithm13" };
			foreach (string text in array)
			{
				try
				{
					MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName(text), "GenerateVeins", (Type[])null, (Type[])null);
					if (!(methodInfo == null))
					{
						_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(VeinHeightTranspiler), "Transpile", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
					}
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Patch " + text + ".GenerateVeins failed: " + ex.Message));
				}
			}
			return num;
		}
	}
	internal static class VeinHeightTranspiler
	{
		private static readonly FieldInfo RadiusField = AccessTools.Field(typeof(PlanetData), "radius");

		private static readonly FieldInfo WaterItemIdField = AccessTools.Field(typeof(PlanetData), "waterItemId");

		public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			bool flag = false;
			bool flag2 = false;
			for (int i = 0; i < list.Count - 1; i++)
			{
				if (!flag && list[i].opcode == OpCodes.Ldfld && object.Equals(list[i].operand, RadiusField) && IsHeightCompareBranch(list[i + 1].opcode))
				{
					FixRadiusHeightBranch(list, i + 1);
					flag = true;
				}
				else if (!flag2 && list[i].opcode == OpCodes.Ldfld && object.Equals(list[i].operand, WaterItemIdField) && (list[i + 1].opcode == OpCodes.Brfalse || list[i + 1].opcode == OpCodes.Brfalse_S))
				{
					CodeInstruction val = list[i + 1];
					object operand = val.operand;
					if (operand != null)
					{
						List<Label> labels = val.labels;
						list[i + 1] = new CodeInstruction(OpCodes.Pop, (object)null)
						{
							labels = labels
						};
						list.Insert(i + 2, new CodeInstruction(OpCodes.Br, operand));
						flag2 = true;
					}
				}
			}
			return list;
		}

		private static void FixRadiusHeightBranch(List<CodeInstruction> codes, int branchIndex)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			CodeInstruction obj = codes[branchIndex];
			object operand = obj.operand;
			List<Label> labels = obj.labels;
			bool num = IsBgeFamily(obj.opcode);
			codes[branchIndex] = new CodeInstruction(OpCodes.Pop, (object)null)
			{
				labels = labels
			};
			codes.Insert(branchIndex + 1, new CodeInstruction(OpCodes.Pop, (object)null));
			if (num && operand != null)
			{
				codes.Insert(branchIndex + 2, new CodeInstruction(OpCodes.Br, operand));
			}
		}

		private static bool IsHeightCompareBranch(OpCode op)
		{
			if (!IsBgeFamily(op))
			{
				return IsBltFamily(op);
			}
			return true;
		}

		private static bool IsBgeFamily(OpCode op)
		{
			if (!(op == OpCodes.Bge) && !(op == OpCodes.Bge_S) && !(op == OpCodes.Bge_Un))
			{
				return op == OpCodes.Bge_Un_S;
			}
			return true;
		}

		private static bool IsBltFamily(OpCode op)
		{
			if (!(op == OpCodes.Blt) && !(op == OpCodes.Blt_S) && !(op == OpCodes.Blt_Un))
			{
				return op == OpCodes.Blt_Un_S;
			}
			return true;
		}
	}
	internal static class GammaCatalystTranspiler
	{
		private static readonly FieldInfo CatalystPointField = AccessTools.Field(typeof(PowerGeneratorComponent), "catalystPoint");

		public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			int num = 0;
			for (int i = 0; i < list.Count - 2; i++)
			{
				if (list[i].opcode == OpCodes.Ldfld && object.Equals(list[i].operand, CatalystPointField) && list[i + 1].opcode == OpCodes.Ldc_I4_1 && list[i + 2].opcode == OpCodes.Sub)
				{
					list[i + 1].opcode = OpCodes.Ldc_I4_S;
					list[i + 1].operand = (sbyte)10;
					num++;
				}
			}
			return list;
		}

		public static IEnumerable<CodeInstruction> TranspileUi(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			foreach (CodeInstruction item in list)
			{
				if (item.opcode == OpCodes.Ldstr && item.operand is string text && text == "0.100 / min")
				{
					item.operand = "1 / min";
				}
			}
			return list;
		}
	}
	internal static class GenesisBrokenPatchFix
	{
		private static ManualLogSource? _log;

		private static readonly HashSet<MethodBase> Hooked = new HashSet<MethodBase>();

		public static int HookCount { get; private set; }

		public static void NoteHook()
		{
			HookCount++;
		}

		public static void TryHook(Harmony harmony, ManualLogSource log)
		{
			_log = log;
			HookReplace(harmony, "ProjectGenesis.Patches.AddVeinPatches", "PlanetAlgorithm_GenerateVeins_RemoveHeightLimit_Transpiler", "VeinHeightPrefix");
			HookReplace(harmony, "ProjectGenesis.Patches.GammaGeneratorPatches", "PowerGeneratorComponent_GameTick_Gamma_Transpiler", "GammaPrefix");
			HookReplace(harmony, "ProjectGenesis.Patches.GammaGeneratorPatches", "UIPowerGeneratorWindow_OnUpdate_Transpiler", "GammaUiPrefix");
			HookNoop(harmony, "ProjectGenesis.Patches.UILootFilterPatches", "RefreshIcons_Transpiler");
			HookNoop(harmony, "ProjectGenesis.Patches.UILootFilterPatches", "UILootFilter_RefreshIcons_currentTypeField_Transpiler");
			HookNoop(harmony, "ProjectGenesis.Patches.UILootFilterPatches", "TestMouseIndex_Transpiler");
			HookNoop(harmony, "ProjectGenesis.Patches.UILootFilterPatches", "Transpiler");
			HookNoop(harmony, "ProjectGenesis.Patches.UILootFilterPatches", "UILootFilter_OnBoxMouseDown_currentTypeField_Transpiler");
			HookNoop(harmony, "ProjectGenesis.Patches.UILootFilterPatches", "UILootFilter_SetMaterialProps_currentTypeField_Transpiler");
			HookNoop(harmony, "ProjectGenesis.Patches.UILootFilterPatches", "UILootFilter_RefreshWindow_Transpiler");
			HookNoop(harmony, "ProjectGenesis.Patches.UILootFilterPatches", "UILootFilter_SetMaterialProps_Transpiler");
		}

		private static void HookReplace(Harmony harmony, string typeName, string methodName, string prefixName)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			MethodInfo methodInfo = Find(typeName, methodName);
			if (methodInfo == null || !Hooked.Add(methodInfo))
			{
				return;
			}
			try
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(GenesisBrokenPatchFix), prefixName, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				HookCount++;
				ManualLogSource? log = _log;
				if (log != null)
				{
					log.LogInfo((object)("Replace: " + typeName + "." + methodName));
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? log2 = _log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Replace failed " + methodName + ": " + ex.Message));
				}
			}
		}

		private static void HookNoop(Harmony harmony, string typeName, string methodName)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			MethodInfo methodInfo = Find(typeName, methodName);
			if (methodInfo == null || !Hooked.Add(methodInfo))
			{
				return;
			}
			try
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(GenesisBrokenPatchFix), "NoopPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				HookCount++;
				ManualLogSource? log = _log;
				if (log != null)
				{
					log.LogInfo((object)("Noop: " + typeName + "." + methodName));
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? log2 = _log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Noop failed " + methodName + ": " + ex.Message));
				}
			}
		}

		private static MethodInfo? Find(string typeName, string methodName)
		{
			Type type = AccessTools.TypeByName(typeName);
			if (!(type == null))
			{
				return AccessTools.Method(type, methodName, (Type[])null, (Type[])null);
			}
			return null;
		}

		public static bool VeinHeightPrefix(ref IEnumerable<CodeInstruction> __result, IEnumerable<CodeInstruction> instructions)
		{
			__result = VeinHeightTranspiler.Transpile(instructions);
			return false;
		}

		public static bool GammaPrefix(ref IEnumerable<CodeInstruction> __result, IEnumerable<CodeInstruction> instructions)
		{
			__result = GammaCatalystTranspiler.Transpile(instructions);
			return false;
		}

		public static bool GammaUiPrefix(ref IEnumerable<CodeInstruction> __result, IEnumerable<CodeInstruction> instructions)
		{
			__result = GammaCatalystTranspiler.TranspileUi(instructions);
			return false;
		}

		public static bool NoopPrefix(ref IEnumerable<CodeInstruction> __result, IEnumerable<CodeInstruction> instructions)
		{
			__result = instructions;
			return false;
		}
	}
	internal static class BirthStarCreatePlanetFix
	{
		private static ManualLogSource? _log;

		private static bool _genesisNooped;

		private static bool _starGenPatched;

		public static void TryHook(Harmony harmony, ManualLogSource log)
		{
			_log = log;
			NoopGenesisTranspiler(harmony);
			PatchCreateStarPlanets(harmony);
		}

		private static void NoopGenesisTranspiler(Harmony harmony)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			if (_genesisNooped)
			{
				return;
			}
			MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName("ProjectGenesis.Patches.BirthStarPatches"), "StarGen_CreateStarPlanets_Transpiler", (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				return;
			}
			try
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(BirthStarCreatePlanetFix), "NoopPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_genesisNooped = true;
				GenesisBrokenPatchFix.NoteHook();
				ManualLogSource? log = _log;
				if (log != null)
				{
					log.LogInfo((object)"Noop: ProjectGenesis.Patches.BirthStarPatches.StarGen_CreateStarPlanets_Transpiler");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? log2 = _log;
				if (log2 != null)
				{
					log2.LogWarning((object)("BirthStar genesis noop failed: " + ex.Message));
				}
			}
		}

		private static void PatchCreateStarPlanets(Harmony harmony)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			if (_starGenPatched)
			{
				return;
			}
			MethodInfo methodInfo = AccessTools.Method(typeof(StarGen), "CreateStarPlanets", (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				return;
			}
			try
			{
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(BirthStarCreatePlanetFix), "Transpile", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
				_starGenPatched = true;
				ManualLogSource? log = _log;
				if (log != null)
				{
					log.LogInfo((object)"Patch: StarGen.CreateStarPlanets birth-star ModifyBirthStar");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? log2 = _log;
				if (log2 != null)
				{
					log2.LogWarning((object)("CreateStarPlanets patch failed: " + ex.Message));
				}
			}
		}

		public static bool NoopPrefix(ref IEnumerable<CodeInstruction> __result, IEnumerable<CodeInstruction> instructions)
		{
			__result = instructions;
			return false;
		}

		public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Expected O, but got Unknown
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Expected O, but got Unknown
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Expected O, but got Unknown
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Expected O, but got Unknown
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			FieldInfo objB = AccessTools.Field(typeof(StarData), "index");
			FieldInfo planetCountField = AccessTools.Field(typeof(StarData), "planetCount");
			MethodInfo methodInfo = AccessTools.Method(typeof(BirthStarCreatePlanetFix), "ModifyBirthStar", (Type[])null, (Type[])null);
			int num = -1;
			for (int i = 0; i < list.Count - 1; i++)
			{
				if (list[i].opcode == OpCodes.Ldfld && object.Equals(list[i].operand, objB) && (list[i + 1].opcode == OpCodes.Brtrue || list[i + 1].opcode == OpCodes.Brtrue_S))
				{
					num = i;
					break;
				}
			}
			if (num < 0)
			{
				ManualLogSource? log = _log;
				if (log != null)
				{
					log.LogWarning((object)"BirthStar transpile: index/brtrue not found");
				}
				return list;
			}
			int num2 = FindOperandTarget(list, list[num + 1].operand);
			if (num2 < 0)
			{
				ManualLogSource? log2 = _log;
				if (log2 != null)
				{
					log2.LogWarning((object)"BirthStar transpile: birth skip target not found");
				}
				return list;
			}
			int num3 = -1;
			for (int j = num + 2; j < num2; j++)
			{
				if (list[j].opcode == OpCodes.Br || list[j].opcode == OpCodes.Br_S)
				{
					num3 = j;
					break;
				}
			}
			if (num3 < 0)
			{
				ManualLogSource? log3 = _log;
				if (log3 != null)
				{
					log3.LogWarning((object)"BirthStar transpile: birth exit br not found");
				}
				return list;
			}
			int num4 = FindOperandTarget(list, list[num3].operand);
			if (num4 < 0 || !IsPlanetArrayInit(list, num4, planetCountField))
			{
				ManualLogSource? log4 = _log;
				if (log4 != null)
				{
					log4.LogWarning((object)"BirthStar transpile: planet array init pattern mismatch");
				}
				return list;
			}
			int num5 = FindAfterPlanetLoop(list, num4, planetCountField);
			if (num5 < 0)
			{
				ManualLogSource? log5 = _log;
				if (log5 != null)
				{
					log5.LogWarning((object)"BirthStar transpile: after-planet-loop not found");
				}
				return list;
			}
			Label label;
			if (list[num5].labels.Count > 0)
			{
				label = list[num5].labels[0];
			}
			else
			{
				label = default(Label);
				list[num5].labels.Add(label);
			}
			list[num3].operand = label;
			list.InsertRange(num3, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[5]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_1, (object)null),
				new CodeInstruction(OpCodes.Ldarg_2, (object)null),
				new CodeInstruction(OpCodes.Ldloc_0, (object)null),
				new CodeInstruction(OpCodes.Call, (object)methodInfo)
			});
			ManualLogSource? log6 = _log;
			if (log6 != null)
			{
				log6.LogInfo((object)$"BirthStar transpile ok: insert@{num3}, skip planets [{num4}..{num5})");
			}
			return list;
		}

		private static bool IsPlanetArrayInit(List<CodeInstruction> codes, int i, FieldInfo planetCountField)
		{
			if (i + 3 < codes.Count && codes[i].opcode == OpCodes.Ldarg_1 && codes[i + 1].opcode == OpCodes.Ldarg_1 && codes[i + 2].opcode == OpCodes.Ldfld && object.Equals(codes[i + 2].operand, planetCountField))
			{
				return codes[i + 3].opcode == OpCodes.Newarr;
			}
			return false;
		}

		private static int FindAfterPlanetLoop(List<CodeInstruction> codes, int planetStart, FieldInfo planetCountField)
		{
			for (int i = planetStart + 4; i < codes.Count - 3; i++)
			{
				if (IsLdloc(codes[i]) && !(codes[i + 1].opcode != OpCodes.Ldarg_1) && !(codes[i + 2].opcode != OpCodes.Ldfld) && object.Equals(codes[i + 2].operand, planetCountField) && (!(codes[i + 3].opcode != OpCodes.Blt) || !(codes[i + 3].opcode != OpCodes.Blt_S)))
				{
					int num = FindOperandTarget(codes, codes[i + 3].operand);
					if (num >= planetStart && num < i)
					{
						return i + 4;
					}
				}
			}
			return -1;
		}

		private static bool IsLdloc(CodeInstruction ci)
		{
			if (!(ci.opcode == OpCodes.Ldloc) && !(ci.opcode == OpCodes.Ldloc_S) && !(ci.opcode == OpCodes.Ldloc_0) && !(ci.opcode == OpCodes.Ldloc_1) && !(ci.opcode == OpCodes.Ldloc_2))
			{
				return ci.opcode == OpCodes.Ldloc_3;
			}
			return true;
		}

		private static int FindOperandTarget(List<CodeInstruction> codes, object? operand)
		{
			if (operand == null)
			{
				return -1;
			}
			if (operand is Label item)
			{
				for (int i = 0; i < codes.Count; i++)
				{
					if (codes[i].labels.Contains(item))
					{
						return i;
					}
				}
			}
			for (int j = 0; j < codes.Count; j++)
			{
				if (codes[j] == operand)
				{
					return j;
				}
				foreach (Label label in codes[j].labels)
				{
					if (operand.Equals(label))
					{
						return j;
					}
				}
			}
			return -1;
		}

		public static void ModifyBirthStar(GalaxyData galaxy, StarData star, GameDesc gameDesc, DotNet35Random rng)
		{
			star.planetCount = 5;
			star.planets = (PlanetData[])(object)new PlanetData[5];
			int num = rng.Next();
			int num2 = rng.Next();
			star.planets[0] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, new int[1] { 9 }, 0, 0, 1, 1, false, num, num2);
			num = rng.Next();
			num2 = rng.Next();
			star.planets[1] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, new int[1] { 21 }, 1, 0, 2, 2, true, num, num2);
			num = rng.Next();
			num2 = rng.Next();
			star.planets[2] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, new int[1] { 1 }, 2, 2, 1, 1, false, num, num2);
			num = rng.Next();
			num2 = rng.Next();
			star.planets[3] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, new int[1] { 7 }, 3, 2, 2, 2, false, num, num2);
			num = rng.Next();
			num2 = rng.Next();
			star.planets[4] = PlanetGen.CreatePlanet(galaxy, star, gameDesc, new int[1] { 20 }, 4, 0, 3, 3, false, num, num2);
		}
	}
}