Decompiled source of DarkFogTuner v1.0.0

DarkFogTuner.dll

Decompiled 11 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.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[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 DarkFogTuner
{
	public enum Language
	{
		Auto,
		English,
		Chinese,
		Turkish
	}
	[BepInPlugin("bug.dsp.darkfogtuner", "DarkFogTuner", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private class Row
		{
			public string En;

			public string Zh;

			public string Tr;

			public float Min;

			public float Max;

			public bool Log;

			public bool ZeroAtLeft;

			public bool Whole;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static WindowFunction <0>__Draw;
		}

		private const int Aggression = 0;

		private const int Frequency = 1;

		private const int FleetSize = 2;

		private const int FleetGrowth = 3;

		private const int Spread = 4;

		private const int Growth = 5;

		private const int PowerThreat = 6;

		private const int BattleThreat = 7;

		private const int BattleExp = 8;

		private const int Capacity = 9;

		private const int Production = 10;

		private const int EnemyDamage = 11;

		private const int EnemyHealth = 12;

		private const int NewLevel = 13;

		private const int NewGrowth = 14;

		private const long NoGalaxy = -2L;

		private static readonly float[] AggressionValues = new float[6] { -1f, 0f, 0.5f, 1f, 2f, 3f };

		private static readonly string[][] AggressionNames = new string[6][]
		{
			new string[3] { "Dummy", "假人", "Kukla" },
			new string[3] { "Passive", "被动", "Pasif" },
			new string[3] { "Torpid", "迟钝", "Uyuşuk" },
			new string[3] { "Normal", "正常", "Normal" },
			new string[3] { "Sharp", "敏锐", "Keskin" },
			new string[3] { "Rampage", "狂暴", "Öfkeli" }
		};

		private static readonly Row[] Rows = new Row[15]
		{
			new Row
			{
				En = "Aggressiveness",
				Zh = "攻击性",
				Tr = "Agresiflik",
				Min = 0f,
				Max = 5f,
				Whole = true
			},
			new Row
			{
				En = "Attack frequency",
				Zh = "攻击频率",
				Tr = "Saldırı sıklığı",
				Min = 0.1f,
				Max = 100f,
				Log = true
			},
			new Row
			{
				En = "Fleet size",
				Zh = "舰队规模",
				Tr = "Filo büyüklüğü",
				Min = 0.1f,
				Max = 20f,
				Log = true
			},
			new Row
			{
				En = "Fleet growth per wave",
				Zh = "舰队增长速度",
				Tr = "Filo büyüme hızı",
				Min = 0.1f,
				Max = 10f,
				Log = true,
				ZeroAtLeft = true
			},
			new Row
			{
				En = "Spread to other stars",
				Zh = "星际扩散",
				Tr = "Yıldızlara yayılım",
				Min = 0.01f,
				Max = 20f,
				Log = true,
				ZeroAtLeft = true
			},
			new Row
			{
				En = "Build and replication speed",
				Zh = "建造与复制速度",
				Tr = "Üreme ve inşa hızı",
				Min = 0.1f,
				Max = 10f,
				Log = true
			},
			new Row
			{
				En = "Power threat (ground bases)",
				Zh = "能源威胁(地面基地)",
				Tr = "Enerji tehdidi (yer üsleri)",
				Min = 0.01f,
				Max = 100f,
				Log = true
			},
			new Row
			{
				En = "Threat from combat",
				Zh = "战斗威胁",
				Tr = "Savaş tehdidi",
				Min = 0.01f,
				Max = 100f,
				Log = true
			},
			new Row
			{
				En = "Experience from combat",
				Zh = "战斗经验",
				Tr = "Savaş deneyimi",
				Min = 0.01f,
				Max = 20f,
				Log = true
			},
			new Row
			{
				En = "Unit capacity",
				Zh = "单位容量",
				Tr = "Birim kapasitesi",
				Min = 1f,
				Max = 20f,
				Log = true
			},
			new Row
			{
				En = "Free unit production",
				Zh = "免费单位生产",
				Tr = "Bedava birim üretimi",
				Min = 1f,
				Max = 50f,
				Log = true
			},
			new Row
			{
				En = "Enemy damage",
				Zh = "敌方伤害",
				Tr = "Düşman hasarı",
				Min = 0.1f,
				Max = 100f,
				Log = true
			},
			new Row
			{
				En = "Enemy durability",
				Zh = "敌方耐久",
				Tr = "Düşman dayanıklılığı",
				Min = 0.1f,
				Max = 100f,
				Log = true
			},
			new Row
			{
				En = "New hive level",
				Zh = "新巢穴等级",
				Tr = "Yeni kovan seviyesi",
				Min = 0f,
				Max = 30f,
				Whole = true
			},
			new Row
			{
				En = "New hive head start",
				Zh = "新巢穴发展度",
				Tr = "Yeni kovan gelişimi",
				Min = 0f,
				Max = 4f
			}
		};

		private static readonly KeyValuePair<string[], float[]>[] Presets = new KeyValuePair<string[], float[]>[4]
		{
			Preset("Easy", "简单", "Kolay", 2f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.2f, 0.2f, 0.2f, 1f, 1f, 0.5f, 0.5f),
			Preset("Normal", "正常", "Normal", 3f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f),
			Preset("Hard", "困难", "Zor", 4f, 1.5f, 1.5f, 1.5f, 1.5f, 2f, 2f, 2f, 2f, 2f, 2f, 2f, 2f),
			Preset("Extreme", "极限", "Aşırı", 5f, 10f, 5f, 5f, 5f, 10f, 20f, 20f, 5f, 10f, 10f, 5f, 5f)
		};

		public static float AttackFrequency = 1f;

		public static float FleetSizeFactor = 1f;

		public static float FleetGrowthFactor = 1f;

		public static float SpreadFactor = 1f;

		public static float UnitCapacity = 1f;

		public static float ProductionFactor = 1f;

		public static float EnemyDamageFactor = 1f;

		public static float EnemyHealthFactor = 1f;

		private static ConfigEntry<KeyboardShortcut> hotkey;

		private static ConfigEntry<Language> language;

		private static ConfigFile config;

		private static long galaxy = -2L;

		private static bool open;

		private static bool dirty;

		private static readonly float[] draft = new float[Rows.Length];

		private static Rect window = new Rect(60f, 120f, 500f, 0f);

		public static bool MouseOverWindow;

		private static Texture2D panelTexture;

		private static GUIStyle panelStyle;

		private static GUIStyle labelStyle;

		private static bool InGame
		{
			get
			{
				if (GameMain.isRunning && !DSPGame.IsMenuDemo && GameMain.data != null)
				{
					return GameMain.data.gameDesc != null;
				}
				return false;
			}
		}

		private static float Scale => Math.Max(1f, (float)Screen.height / 1080f);

		private static KeyValuePair<string[], float[]> Preset(string en, string zh, string tr, params float[] v)
		{
			return new KeyValuePair<string[], float[]>(new string[3] { en, zh, tr }, v.Concat(new float[2]
			{
				float.NaN,
				float.NaN
			}).ToArray());
		}

		private void Awake()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			config = ((BaseUnityPlugin)this).Config;
			hotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "Hotkey", new KeyboardShortcut((KeyCode)107, (KeyCode[])(object)new KeyCode[2]
			{
				(KeyCode)306,
				(KeyCode)304
			}), "Opens and closes the panel.");
			language = ((BaseUnityPlugin)this).Config.Bind<Language>("General", "Language", Language.Auto, "Panel language. Auto follows the Windows language.");
			new Harmony("bug.dsp.darkfogtuner").PatchAll(typeof(Patches));
		}

		private void Update()
		{
			//IL_0042: 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_0093: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			long num = (InGame ? GameMain.data.GetClusterSeedKey() : (-2));
			if (num != galaxy)
			{
				galaxy = num;
				LoadGalaxy();
			}
			if (num == -2)
			{
				open = false;
				MouseOverWindow = false;
				return;
			}
			KeyboardShortcut value = hotkey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown() && !VFInput.inputing)
			{
				open = !open;
				if (open)
				{
					ReadDraft();
				}
			}
			if (open && dirty && !Input.GetMouseButton(0))
			{
				Apply();
			}
			int mouseOverWindow;
			if (open)
			{
				Rect val = WindowOnScreen();
				mouseOverWindow = (((Rect)(ref val)).Contains(new Vector2(Input.mousePosition.x, (float)Screen.height - Input.mousePosition.y)) ? 1 : 0);
			}
			else
			{
				mouseOverWindow = 0;
			}
			MouseOverWindow = (byte)mouseOverWindow != 0;
		}

		private static Rect WindowOnScreen()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			return new Rect(((Rect)(ref window)).x * Scale, ((Rect)(ref window)).y * Scale, ((Rect)(ref window)).width * Scale, ((Rect)(ref window)).height * Scale);
		}

		private static ConfigEntry<float> Stored(string name)
		{
			return config.Bind<float>("Galaxy " + galaxy, name, 1f, (ConfigDescription)null);
		}

		private static void LoadGalaxy()
		{
			dirty = false;
			bool num = galaxy == -2;
			AttackFrequency = (num ? 1f : Stored("AttackFrequency").Value);
			FleetSizeFactor = (num ? 1f : Stored("FleetSize").Value);
			FleetGrowthFactor = (num ? 1f : Stored("FleetGrowth").Value);
			SpreadFactor = (num ? 1f : Stored("Spread").Value);
			UnitCapacity = (num ? 1f : Stored("UnitCapacity").Value);
			ProductionFactor = (num ? 1f : Stored("Production").Value);
			EnemyDamageFactor = (num ? 1f : Stored("EnemyDamage").Value);
			EnemyHealthFactor = (num ? 1f : Stored("EnemyHealth").Value);
		}

		public static float MetadataMultiplier(GameHistoryData history)
		{
			return Traverse.Create((object)history).Property<float>("currentPropertyMultiplier", (object[])null).Value;
		}

		private static void ReadDraft()
		{
			ref CombatSettings combatSettings = ref GameMain.data.history.combatSettings;
			float aggressiveness = combatSettings.aggressiveness;
			draft[0] = Array.FindIndex(AggressionValues, (float v) => Math.Abs(v - aggressiveness) < 0.01f);
			draft[1] = AttackFrequency;
			draft[2] = FleetSizeFactor;
			draft[3] = FleetGrowthFactor;
			draft[4] = SpreadFactor;
			draft[5] = combatSettings.growthSpeedFactor;
			draft[6] = combatSettings.powerThreatFactor;
			draft[7] = combatSettings.battleThreatFactor;
			draft[8] = combatSettings.battleExpFactor;
			draft[9] = UnitCapacity;
			draft[10] = ProductionFactor;
			draft[11] = EnemyDamageFactor;
			draft[12] = EnemyHealthFactor;
			draft[13] = combatSettings.initialLevel;
			draft[14] = combatSettings.initialGrowth;
			dirty = false;
		}

		private static void Apply()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			dirty = false;
			GameHistoryData history = GameMain.data.history;
			ref CombatSettings combatSettings = ref history.combatSettings;
			EAggressiveLevel aggressiveLevel = ((CombatSettings)(ref combatSettings)).aggressiveLevel;
			float num = draft[2] / FleetSizeFactor;
			combatSettings.aggressiveness = AggressionValues[Math.Max(0, (int)draft[0])];
			combatSettings.growthSpeedFactor = draft[5];
			combatSettings.powerThreatFactor = draft[6];
			combatSettings.battleThreatFactor = draft[7];
			combatSettings.battleExpFactor = draft[8];
			combatSettings.initialLevel = draft[13];
			combatSettings.initialGrowth = draft[14];
			float attackFrequency = (Stored("AttackFrequency").Value = draft[1]);
			AttackFrequency = attackFrequency;
			attackFrequency = (Stored("FleetSize").Value = draft[2]);
			FleetSizeFactor = attackFrequency;
			attackFrequency = (Stored("FleetGrowth").Value = draft[3]);
			FleetGrowthFactor = attackFrequency;
			attackFrequency = (Stored("Spread").Value = draft[4]);
			SpreadFactor = attackFrequency;
			attackFrequency = (Stored("UnitCapacity").Value = draft[9]);
			UnitCapacity = attackFrequency;
			attackFrequency = (Stored("Production").Value = draft[10]);
			ProductionFactor = attackFrequency;
			attackFrequency = (Stored("EnemyDamage").Value = draft[11]);
			EnemyDamageFactor = attackFrequency;
			attackFrequency = (Stored("EnemyHealth").Value = draft[12]);
			EnemyHealthFactor = attackFrequency;
			GameMain.data.gameDesc.combatSettings.growthSpeedFactor = combatSettings.growthSpeedFactor;
			GameMain.data.gameDesc.combatSettings.battleThreatFactor = combatSettings.battleThreatFactor;
			history.minimalPropertyMultiplier = Math.Min(history.minimalPropertyMultiplier, MetadataMultiplier(history));
			history.minimalDifficulty = Math.Min(history.minimalDifficulty, ((CombatSettings)(ref combatSettings)).difficulty);
			SpaceSector spaceSector = GameMain.data.spaceSector;
			if (spaceSector?.dfHives != null)
			{
				EnemyDFHiveSystem[] dfHives = spaceSector.dfHives;
				for (int i = 0; i < dfHives.Length; i++)
				{
					for (EnemyDFHiveSystem val = dfHives[i]; val != null; val = val.nextSibling)
					{
						if (val.lancerAssaultCountBase >= 1f)
						{
							val.lancerAssaultCountBase = ClampAssault(val.lancerAssaultCountBase * num);
						}
						val.CalcFormsSupply();
					}
				}
			}
			PlanetFactory[] factories = GameMain.data.factories;
			foreach (PlanetFactory obj in factories)
			{
				if (obj != null)
				{
					EnemyDFGroundSystem enemySystem = obj.enemySystem;
					if (enemySystem != null)
					{
						enemySystem.CalcFormsSupply();
					}
				}
			}
			if (spaceSector != null)
			{
				spaceSector.OnDFAggressivenessChanged(aggressiveLevel, ((CombatSettings)(ref combatSettings)).aggressiveLevel);
			}
		}

		public static float FleetCap()
		{
			return Math.Min(1440f, 360f * UnitCapacity);
		}

		public static float ClampAssault(float count)
		{
			return Math.Max(2.5f, Math.Min(FleetCap(), count));
		}

		public static int ScaleSupply(int supply)
		{
			return (int)((double)supply * (double)UnitCapacity);
		}

		public static int ScaleDamage(int damage, ETargetType target, ETargetType caster)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			if (damage <= 0)
			{
				return damage;
			}
			if ((int)target == 4)
			{
				if (EnemyHealthFactor != 1f)
				{
					return Math.Max(1, (int)((double)damage / (double)EnemyHealthFactor));
				}
				return damage;
			}
			if ((int)caster != 4 || EnemyDamageFactor == 1f)
			{
				return damage;
			}
			return (int)Math.Min(2147483647.0, (double)damage * (double)EnemyDamageFactor);
		}

		public static int ScaleThreat(int threat)
		{
			if (threat < 1000000000)
			{
				return Math.Max(1, (int)((float)threat / AttackFrequency));
			}
			return threat;
		}

		public static int ScaleCount(int count)
		{
			if (count > 0)
			{
				return Math.Max(1, (int)((float)count * FleetSizeFactor + 0.5f));
			}
			return count;
		}

		public static double SpreadChance()
		{
			return 0.0625 * (double)SpreadFactor;
		}

		public static float Snap(float v)
		{
			if (v <= 0f)
			{
				return 0f;
			}
			int digits = Math.Max(0, Math.Min(15, 1 - (int)Math.Floor(Math.Log10(v))));
			return (float)Math.Round(v, digits);
		}

		public static float ToSlider(float min, float max, bool log, float v)
		{
			if (!log)
			{
				return (v - min) / (max - min);
			}
			if (v <= min)
			{
				return 0f;
			}
			return (float)(Math.Log(v / min) / Math.Log(max / min));
		}

		public static float FromSlider(float min, float max, bool log, bool zeroAtLeft, bool whole, float t)
		{
			if (zeroAtLeft && t < 0.01f)
			{
				return 0f;
			}
			if (whole)
			{
				return (float)Math.Round(min + (max - min) * t);
			}
			return Snap(log ? ((float)((double)min * Math.Pow(max / min, t))) : (min + (max - min) * t));
		}

		private static string T(string en, string zh, string tr)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			Language language = Plugin.language.Value;
			if (language == Language.Auto)
			{
				language = (((int)Application.systemLanguage == 37) ? Language.Turkish : (((int)Application.systemLanguage != 6 && (int)Application.systemLanguage != 40) ? Language.English : Language.Chinese));
			}
			return language switch
			{
				Language.Chinese => zh, 
				Language.Turkish => tr, 
				_ => en, 
			};
		}

		private static string T(string[] s)
		{
			return T(s[0], s[1], s[2]);
		}

		private void OnGUI()
		{
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Expected O, but got Unknown
			if (open && galaxy != -2)
			{
				if ((Object)(object)panelTexture == (Object)null)
				{
					panelTexture = new Texture2D(1, 1)
					{
						hideFlags = (HideFlags)61
					};
					panelTexture.SetPixel(0, 0, new Color(0.05f, 0.07f, 0.1f, 1f));
					panelTexture.Apply();
					panelStyle = new GUIStyle(GUI.skin.window);
					GUIStyleState normal = panelStyle.normal;
					Texture2D background = (panelStyle.onNormal.background = panelTexture);
					normal.background = background;
					GUIStyleState normal2 = panelStyle.normal;
					Color textColor = (panelStyle.onNormal.textColor = Color.white);
					normal2.textColor = textColor;
					labelStyle = new GUIStyle(GUI.skin.label);
					labelStyle.normal.textColor = Color.white;
				}
				GUI.matrix = Matrix4x4.Scale(new Vector3(Scale, Scale, 1f));
				Rect val2 = window;
				object obj = <>O.<0>__Draw;
				if (obj == null)
				{
					WindowFunction val3 = Draw;
					<>O.<0>__Draw = val3;
					obj = (object)val3;
				}
				window = GUILayout.Window(1145459797, val2, (WindowFunction)obj, T("Dark Fog settings", "黑雾设置", "Kara Sis ayarları"), panelStyle, Array.Empty<GUILayoutOption>());
			}
		}

		private static void Draw(int id)
		{
			if (!GameMain.data.gameDesc.isCombatMode)
			{
				GUILayout.Label(T("This save has no combat mode.", "此存档未开启战斗模式。", "Bu kayıtta savaş modu yok."), labelStyle, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				KeyValuePair<string[], float[]>[] presets = Presets;
				for (int i = 0; i < presets.Length; i++)
				{
					KeyValuePair<string[], float[]> keyValuePair = presets[i];
					if (!GUILayout.Button(T(keyValuePair.Key), Array.Empty<GUILayoutOption>()))
					{
						continue;
					}
					for (int j = 0; j < draft.Length; j++)
					{
						if (!float.IsNaN(keyValuePair.Value[j]))
						{
							draft[j] = keyValuePair.Value[j];
						}
					}
					dirty = true;
				}
				GUILayout.EndHorizontal();
				for (int k = 0; k < Rows.Length; k++)
				{
					Row row = Rows[k];
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					GUILayout.Label(T(row.En, row.Zh, row.Tr), labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(190f) });
					float num = ToSlider(row.Min, row.Max, row.Log, draft[k]);
					float num2 = GUILayout.HorizontalSlider(num, 0f, 1f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(190f) });
					if (num2 != num)
					{
						draft[k] = FromSlider(row.Min, row.Max, row.Log, row.ZeroAtLeft, row.Whole, num2);
						dirty = true;
					}
					GUILayout.Label((k == 0) ? ((draft[k] >= 0f) ? T(AggressionNames[(int)draft[k]]) : "?") : (row.Whole ? draft[k].ToString("0") : ("×" + draft[k].ToString("0.##"))), labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
					GUILayout.EndHorizontal();
				}
				GameHistoryData history = GameMain.data.history;
				GUILayout.Label(T("Difficulty ", "难度 ", "Zorluk ") + ((CombatSettings)(ref history.combatSettings)).difficulty.ToString("0.##") + T("    Metadata ×", "    元数据 ×", "    Meta veri ×") + MetadataMultiplier(history).ToString("0.##"), labelStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Label(T("Applies when you release the mouse. Hive count and starting hives are fixed at new game.", "松开鼠标时生效。巢穴数量和初始巢穴在新游戏时确定。", "Fareyi bırakınca uygulanır. Kovan sayısı ve başlangıç kovanları yeni oyunda belirlenir."), labelStyle, Array.Empty<GUILayoutOption>());
			}
			if (GUILayout.Button(T("Close", "关闭", "Kapat"), Array.Empty<GUILayoutOption>()))
			{
				open = false;
			}
			GUI.DragWindow();
		}
	}
	public static class Patches
	{
		[ThreadStatic]
		private static bool producing;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(EvolveData), "GetSpaceThreatMaxByWaves")]
		[HarmonyPatch(typeof(EvolveData), "GetGroundThreatMaxByWaves")]
		private static void ThreatMax(ref int __result)
		{
			__result = Plugin.ScaleThreat(__result);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(EvolveData), "GetGoundAssaultCountByWaves")]
		private static void GroundWave(ref int wave)
		{
			if (wave > 0)
			{
				wave = (int)((float)wave * Plugin.FleetGrowthFactor + 0.5f);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(EvolveData), "GetGoundAssaultCountByWaves")]
		private static void GroundCount(ref int cnt0, ref int cnt1, ref int ap0, ref int ap1)
		{
			cnt0 = Plugin.ScaleCount(cnt0);
			cnt1 = Plugin.ScaleCount(cnt1);
			ap0 = Plugin.ScaleCount(ap0);
			ap1 = Plugin.ScaleCount(ap1);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(EnemyDFHiveSystem), "GetLancerAssaultCountInitial")]
		private static void SpaceInitial(ref float __result)
		{
			if (__result > 0f)
			{
				__result = Plugin.ClampAssault(__result * Plugin.FleetSizeFactor);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(EnemyDFHiveSystem), "GetLancerAssaultCountIncrement")]
		private static void SpaceIncrement(ref float __result)
		{
			__result *= Plugin.FleetSizeFactor * Plugin.FleetGrowthFactor;
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(DFTinderComponent), "PrepareDispatchLogic")]
		private static IEnumerable<CodeInstruction> TinderChance(IEnumerable<CodeInstruction> instructions)
		{
			bool found = false;
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.opcode == OpCodes.Ldc_R8 && (double)instruction.operand == 0.0625)
				{
					found = true;
					yield return CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Plugin), "SpreadChance", (Type[])null, (Type[])null)), (IEnumerable<Label>)instruction.labels);
				}
				else
				{
					yield return instruction;
				}
			}
			if (!found)
			{
				throw new InvalidOperationException("DarkFogTuner: tinder launch chance not found; game code changed");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(DFSReplicatorComponent), "LogicTick")]
		private static void SpaceProduction(ref DFSReplicatorComponent __instance, EnemyDFHiveSystem hive, EnemyBuilderComponent[] builderPool, EAggressiveLevel agglv, float turboRatio, bool isLocal)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if (producing || Plugin.ProductionFactor <= 1f)
			{
				return;
			}
			producing = true;
			try
			{
				EnemyFormation val = hive.forms[__instance.productFormId];
				ref EnemyBuilderComponent reference = ref builderPool[__instance.builderId];
				for (int i = 1; (float)i < Plugin.ProductionFactor; i++)
				{
					if (reference.state < 3)
					{
						break;
					}
					if (val.vacancyCount <= 0)
					{
						break;
					}
					if (val.supplyBalance <= 0)
					{
						break;
					}
					reference.matter = Math.Max(reference.matter, __instance.productSpMatter);
					reference.energy = Math.Max(reference.energy, __instance.productSpEnergy);
					((DFSReplicatorComponent)(ref __instance)).LogicTick(hive, builderPool, agglv, turboRatio, isLocal);
				}
			}
			finally
			{
				producing = false;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(DFGReplicatorComponent), "LogicTick")]
		private static void GroundProduction(ref DFGReplicatorComponent __instance, DFGBaseComponent gbase, EnemyBuilderComponent[] builderPool, EAggressiveLevel agglv, float turboRatio, bool isLocal)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if (producing || Plugin.ProductionFactor <= 1f)
			{
				return;
			}
			producing = true;
			try
			{
				EnemyFormation val = gbase.forms[__instance.productFormId];
				ref EnemyBuilderComponent reference = ref builderPool[__instance.builderId];
				for (int i = 1; (float)i < Plugin.ProductionFactor; i++)
				{
					if (reference.state < 3)
					{
						break;
					}
					if (val.vacancyCount <= 0)
					{
						break;
					}
					if (val.supplyBalance <= 0)
					{
						break;
					}
					reference.matter = Math.Max(reference.matter, __instance.productSpMatter);
					reference.energy = Math.Max(reference.energy, __instance.productSpEnergy);
					((DFGReplicatorComponent)(ref __instance)).LogicTick(gbase, builderPool, agglv, turboRatio, isLocal);
				}
			}
			finally
			{
				producing = false;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(EnemyDFHiveSystem), "CalcFormsSupply")]
		private static void SpaceSupply(EnemyDFHiveSystem __instance)
		{
			if (__instance.realized)
			{
				EnemyFormation[] forms = __instance.forms;
				foreach (EnemyFormation obj in forms)
				{
					obj.supply = Plugin.ScaleSupply(obj.supply);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(EnemyDFGroundSystem), "CalcFormsSupply")]
		private static void GroundSupply(EnemyDFGroundSystem __instance)
		{
			DFGBaseComponent[] buffer = __instance.bases.buffer;
			for (int i = 1; i < __instance.bases.cursor; i++)
			{
				if (buffer[i] != null && buffer[i].id == i)
				{
					EnemyFormation[] forms = buffer[i].forms;
					foreach (EnemyFormation obj in forms)
					{
						obj.supply = Plugin.ScaleSupply(obj.supply);
					}
				}
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(EnemyDFHiveSystem), "AssaultingWavesDetermineAI")]
		private static IEnumerable<CodeInstruction> SpaceFleetCap(IEnumerable<CodeInstruction> instructions)
		{
			int found = 0;
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.opcode == OpCodes.Ldc_R4 && (float)instruction.operand == 360f)
				{
					found++;
					yield return CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Plugin), "FleetCap", (Type[])null, (Type[])null)), (IEnumerable<Label>)instruction.labels);
				}
				else
				{
					yield return instruction;
				}
			}
			if (found != 2)
			{
				throw new InvalidOperationException("DarkFogTuner: space fleet cap not found; game code changed");
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SkillSystem), "DamageObject")]
		private static void DamageSpace(ref int damage, ref SkillTarget target, ref SkillTarget caster)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			damage = Plugin.ScaleDamage(damage, target.type, caster.type);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SkillSystem), "DamageGroundObjectByLocalCaster")]
		private static void DamageGroundLocal(ref int damage, ref SkillTargetLocal target, ref SkillTargetLocal caster)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			damage = Plugin.ScaleDamage(damage, target.type, caster.type);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SkillSystem), "DamageGroundObjectByRemoteCaster")]
		private static void DamageGroundRemote(ref int damage, ref SkillTargetLocal target, ref SkillTarget caster)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			damage = Plugin.ScaleDamage(damage, target.type, caster.type);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SkillSystem), "CalculateDamageIncoming")]
		private static void DamageForecast(ref int __result, ref SkillTarget target)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)target.type == 4)
			{
				__result = Plugin.ScaleDamage(__result, (ETargetType)4, (ETargetType)0);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlanetATField), "TakeDamage")]
		private static void ShieldHit(ref int damage)
		{
			damage = Plugin.ScaleDamage(damage, (ETargetType)0, (ETargetType)4);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlanetATField), "TakeDamage")]
		private static void ShieldRemainder(ref int __result)
		{
			if (Plugin.EnemyDamageFactor != 1f)
			{
				__result = (int)((double)__result / (double)Plugin.EnemyDamageFactor);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(VFInput), "UpdateGameStates")]
		private static void BlockInput()
		{
			if (Plugin.MouseOverWindow)
			{
				VFInput.onGUI = true;
				VFInput.onGUIOperate = true;
			}
		}
	}
}