Decompiled source of InfinityTechnologies v1.0.2

com.Valoneu.InfinityTechnologies.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using CommonAPI;
using CommonAPI.Systems;
using CommonAPI.Systems.ModLocalization;
using DysonSphereMods.Shared;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Valoneu")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+28cd33c1b9dcbc30f7c776c691eeca2686efbc35")]
[assembly: AssemblyProduct("DysonSphereMods")]
[assembly: AssemblyTitle("com.Valoneu.InfinityTechnologies")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 DysonSphereMods.Shared
{
	public static class Log
	{
		private static ManualLogSource _logger;

		public static void Init(ManualLogSource logger)
		{
			_logger = logger;
		}

		public static void Debug(object data)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogDebug(data);
			}
		}

		public static void Info(object data)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogInfo(data);
			}
		}

		public static void Warning(object data)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogWarning(data);
			}
		}

		public static void Error(object data)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogError(data);
			}
		}

		public static void Fatal(object data)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogFatal(data);
			}
		}

		public static void Message(object data)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogMessage(data);
			}
		}

		public static void LogOnce(string msg, ref bool flag, params object[] args)
		{
			if (flag)
			{
				return;
			}
			flag = true;
			try
			{
				string[] array = ((args == null) ? Array.Empty<string>() : args.Select((object arg) => (arg != null) ? ((!(arg is int) && !(arg is string) && !arg.GetType().IsPrimitive) ? JsonUtility.ToJson(arg) : arg.ToString()) : "null").ToArray());
				object[] args2 = array;
				Info(string.Format(msg, args2));
			}
			catch (Exception arg2)
			{
				Warning($"LogOnce failed to format message: {msg}. Exception: {arg2}");
			}
		}
	}
	public static class MultiplierService
	{
		private static readonly Dictionary<string, float> _multipliers = new Dictionary<string, float>();

		private static bool _isDirty;

		public static event Action OnMultipliersChanged;

		public static void SetMultiplier(string key, float value)
		{
			if (!_multipliers.TryGetValue(key, out var value2) || Math.Abs(value2 - value) > 0.0001f)
			{
				_multipliers[key] = value;
				_isDirty = true;
			}
		}

		public static float GetMultiplier(string key, float defaultValue = 1f)
		{
			if (!_multipliers.TryGetValue(key, out var value))
			{
				return defaultValue;
			}
			return value;
		}

		public static void CommitChanges()
		{
			if (_isDirty)
			{
				_isDirty = false;
				MultiplierService.OnMultipliersChanged?.Invoke();
			}
		}
	}
	public static class TickManager
	{
		private static long _lastSlowTick = -1L;

		private static long _lastLazyTick = -1L;

		private static bool _patched = false;

		public static event Action OnSlowTick;

		public static event Action OnLazyTick;

		public static void Patch(Harmony harmony)
		{
			if (!_patched)
			{
				_patched = true;
				harmony.PatchAll(typeof(TickManager));
			}
		}

		[HarmonyPatch(typeof(GameMain), "Begin")]
		[HarmonyPostfix]
		public static void Init()
		{
			_lastSlowTick = -1L;
			_lastLazyTick = -1L;
		}

		[HarmonyPatch(typeof(GameLogic), "LogicFrame")]
		[HarmonyPostfix]
		public static void GameTick()
		{
			long gameTick = GameMain.gameTick;
			if (gameTick / 60 > _lastSlowTick)
			{
				_lastSlowTick = gameTick / 60;
				TickManager.OnSlowTick?.Invoke();
			}
			if (gameTick / 600 > _lastLazyTick)
			{
				_lastLazyTick = gameTick / 600;
				TickManager.OnLazyTick?.Invoke();
			}
		}
	}
	public abstract class WindowBase
	{
		public Rect WindowRect;

		protected Vector2 ScrollPos;

		private bool _isResizing;

		private Rect _resizeRect = new Rect(0f, 0f, 15f, 15f);

		public Vector2 MinSize = new Vector2(300f, 200f);

		public int WindowId { get; protected set; }

		public string Title { get; set; }

		public bool IsVisible { get; set; }

		protected WindowBase(int windowId, string title, Rect defaultRect)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			WindowId = windowId;
			Title = title;
			WindowRect = defaultRect;
		}

		public virtual void OnGUI()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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)
			if (IsVisible)
			{
				GUI.backgroundColor = new Color(0.08f, 0.12f, 0.22f, 0.95f);
				WindowRect = GUILayout.Window(WindowId, WindowRect, new WindowFunction(DrawWindowInternal), Title, Array.Empty<GUILayoutOption>());
				GUI.backgroundColor = Color.white;
				((Rect)(ref WindowRect)).x = Mathf.Clamp(((Rect)(ref WindowRect)).x, 0f - ((Rect)(ref WindowRect)).width + 50f, (float)(Screen.width - 50));
				((Rect)(ref WindowRect)).y = Mathf.Clamp(((Rect)(ref WindowRect)).y, -20f, (float)(Screen.height - 50));
			}
		}

		private void DrawWindowInternal(int id)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_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)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00dd: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Invalid comparison between Unknown and I4
			//IL_00f4: 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: Invalid comparison between Unknown and I4
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			DrawWindowHeader();
			ScrollPos = GUILayout.BeginScrollView(ScrollPos, Array.Empty<GUILayoutOption>());
			DrawWindowContent();
			GUILayout.EndScrollView();
			DrawWindowFooter();
			((Rect)(ref _resizeRect)).x = ((Rect)(ref WindowRect)).width - 20f;
			((Rect)(ref _resizeRect)).y = ((Rect)(ref WindowRect)).height - 20f;
			((Rect)(ref _resizeRect)).width = 20f;
			((Rect)(ref _resizeRect)).height = 20f;
			GUI.Label(_resizeRect, "↘", new GUIStyle(GUI.skin.label)
			{
				alignment = (TextAnchor)4,
				fontSize = 20,
				normal = new GUIStyleState
				{
					textColor = new Color(0.6f, 0.6f, 0.6f, 0.8f)
				}
			});
			Event current = Event.current;
			bool flag = false;
			if ((int)current.type == 0 && ((Rect)(ref _resizeRect)).Contains(current.mousePosition))
			{
				_isResizing = true;
				flag = true;
				current.Use();
			}
			else if ((int)current.type == 1)
			{
				_isResizing = false;
			}
			else if ((int)current.type == 3 && _isResizing)
			{
				ref Rect windowRect = ref WindowRect;
				((Rect)(ref windowRect)).width = ((Rect)(ref windowRect)).width + current.delta.x;
				ref Rect windowRect2 = ref WindowRect;
				((Rect)(ref windowRect2)).height = ((Rect)(ref windowRect2)).height + current.delta.y;
				((Rect)(ref WindowRect)).width = Mathf.Max(MinSize.x, ((Rect)(ref WindowRect)).width);
				((Rect)(ref WindowRect)).height = Mathf.Max(MinSize.y, ((Rect)(ref WindowRect)).height);
				current.Use();
			}
			if ((int)current.type == 0 && !flag)
			{
				GUIUtility.keyboardControl = 0;
			}
			GUI.DragWindow();
		}

		protected virtual void DrawWindowHeader()
		{
		}

		protected abstract void DrawWindowContent();

		protected virtual void DrawWindowFooter()
		{
		}

		public virtual void Toggle()
		{
			IsVisible = !IsVisible;
		}
	}
}
namespace InfinityTechnologies
{
	[BepInPlugin("com.Valoneu.InfinityTechnologies", "InfinityTechnologies", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[CommonAPISubmoduleDependency(new string[] { "ProtoRegistry", "LocalizationModule" })]
	public class InfinityTechnologiesPlugin : BaseUnityPlugin
	{
		public static ModifierManager Modifiers;

		private void Awake()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Log.Init(((BaseUnityPlugin)this).Logger);
			Modifiers = new ModifierManager();
			Harmony val = new Harmony("com.Valoneu.InfinityTechnologies");
			val.PatchAll(typeof(InfinityTechnologiesPlugin));
			val.PatchAll(typeof(Patches));
			TechDefinitions.Register();
			Log.Info("InfinityTechnologies v1.0.2 loaded!");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameHistoryData), "UnlockTechFunction")]
		public static void OnTechUnlocked()
		{
			Modifiers.Recalculate();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameMain), "Begin")]
		public static void OnGameBegin()
		{
			Modifiers.Recalculate();
		}
	}
	public class ModifierManager
	{
		public float SpherePowerMultiplier = 1f;

		public float ProliferatorMultiplier = 1f;

		public float CombatSpeedMultiplier = 1f;

		public float WirelessPowerMultiplier = 1f;

		public float ResearchProductivityMultiplier = 1f;

		public void Recalculate()
		{
			GameHistoryData history = GameMain.history;
			if (history != null && !((Object)(object)LDB.techs == (Object)null))
			{
				SpherePowerMultiplier = 1f;
				ProliferatorMultiplier = 1f;
				CombatSpeedMultiplier = 1f;
				WirelessPowerMultiplier = 1f;
				ResearchProductivityMultiplier = 1f;
				WirelessPowerMultiplier = GetLevelBonus(9002, 0.2f);
				SpherePowerMultiplier = GetLogBonus(9051, 3f, 10f);
				ProliferatorMultiplier = GetLevelBonus(9052, 0.0025f);
				CombatSpeedMultiplier = GetLevelBonus(9054, 0.05f);
				ResearchProductivityMultiplier = GetLogBonus(9055, 16.33f, 10f);
				Log.Debug($"Recalculated Modifiers: Combat={CombatSpeedMultiplier:F2}, Prolif={ProliferatorMultiplier:F3}, Wireless={WirelessPowerMultiplier:F2}");
				ApplyGlobalChanges();
			}
			float GetLevelBonus(int techId, float perLevel)
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				if (history.techStates.TryGetValue(techId, out var value2))
				{
					TechProto val2 = ((ProtoSet<TechProto>)(object)LDB.techs).Select(techId);
					if (val2 != null)
					{
						return 1f + (float)Math.Max(0, value2.curLevel - val2.Level) * perLevel;
					}
				}
				return 1f;
			}
			float GetLogBonus(int techId, float logFactor, float slowness = 1f)
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				if (history.techStates.TryGetValue(techId, out var value))
				{
					TechProto val = ((ProtoSet<TechProto>)(object)LDB.techs).Select(techId);
					if (val != null)
					{
						int num = Math.Max(0, value.curLevel - val.Level);
						if (num > 0)
						{
							return 1f + logFactor * (float)Math.Log10(1.0 + (double)num / (double)slowness);
						}
					}
				}
				return 1f;
			}
		}

		private void ApplyGlobalChanges()
		{
			if (GameMain.data?.dysonSpheres != null)
			{
				DysonSphere[] dysonSpheres = GameMain.data.dysonSpheres;
				foreach (DysonSphere val in dysonSpheres)
				{
					if (val != null)
					{
						Patches.UpdateDysonSpherePower(val);
					}
				}
			}
			if (!(ProliferatorMultiplier > 1.0001f))
			{
				return;
			}
			float num = ProliferatorMultiplier - 1f;
			for (int j = 1; j <= 10; j++)
			{
				if (j == 1 || j == 2 || j == 4)
				{
					Cargo.incTableMilli[j] = Math.Min(0.5, j switch
					{
						2 => 0.2, 
						1 => 0.125, 
						_ => 0.25, 
					} + (double)num);
					Cargo.accTableMilli[j] = Math.Min(2.5, (double)Cargo.accTable[j] / 1000.0 + (double)num);
				}
			}
		}
	}
	public static class Patches
	{
		private static FieldRef<DysonSphere, bool> _needRecalculatePowerRef = AccessTools.FieldRefAccess<DysonSphere, bool>("needRecalculatePower");

		private static ModifierManager M => InfinityTechnologiesPlugin.Modifiers;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
		public static void VFPreload_Postfix()
		{
			Log.Info("Syncing Mod Technology Metadata...");
			CopyTechIcon(9001, 2301);
			CopyTechIcon(9002, 1101);
			CopyTechIcon(9051, 1501);
			CopyTechIcon(9052, 1153);
			CopyTechIcon(9054, 1817);
			CopyItemIcon(9055, 6006);
			TechProto val = ((ProtoSet<TechProto>)(object)LDB.techs).Select(9001);
			if (val != null)
			{
				string desc = (val.description = Localization.Translate("TechDesc_9001"));
				val.Desc = desc;
			}
			TechProto val2 = ((ProtoSet<TechProto>)(object)LDB.techs).Select(9052);
			if (val2 != null)
			{
				string desc = (val2.description = Localization.Translate("TechDesc_9052"));
				val2.Desc = desc;
			}
			Log.Info("Metadata sync complete.");
			static void CopyItemIcon(int targetTechId, int sourceItemId)
			{
				TechProto val3 = ((ProtoSet<TechProto>)(object)LDB.techs).Select(targetTechId);
				ItemProto val4 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(sourceItemId);
				if (val3 != null && val4 != null)
				{
					val3.IconPath = val4.IconPath;
					Traverse.Create((object)val3).Field("_iconSprite").SetValue((object)val4.iconSprite);
					Log.Debug($"Applied icon from item {sourceItemId} to tech {targetTechId}");
				}
			}
			static void CopyTechIcon(int targetId, int sourceTechId)
			{
				TechProto val5 = ((ProtoSet<TechProto>)(object)LDB.techs).Select(targetId);
				TechProto val6 = ((ProtoSet<TechProto>)(object)LDB.techs).Select(sourceTechId);
				if (val5 != null && val6 != null)
				{
					val5.IconPath = val6.IconPath;
					Traverse.Create((object)val5).Field("_iconSprite").SetValue((object)val6.iconSprite);
					Log.Debug($"Applied icon from tech {sourceTechId} to {targetId}");
				}
				else if (val5 == null)
				{
					Log.Warning($"Target tech {targetId} not found for icon sync.");
				}
				else
				{
					Log.Warning($"Source tech {sourceTechId} not found for icon sync.");
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TechProto), "UnlockFunctionText")]
		public static void TechProto_UnlockFunctionText_Postfix(TechProto __instance, ref string __result)
		{
			if (((Proto)__instance).ID < 9000)
			{
				return;
			}
			List<string> list = new List<string>();
			bool flag = __instance.UnlockFunctions.Any((int f) => f < 100);
			for (int i = 0; i < __instance.UnlockFunctions.Length; i++)
			{
				int num = __instance.UnlockFunctions[i];
				if (num >= 100)
				{
					string text = $"TechFunction_{num}";
					string text2 = Localization.Translate(text);
					if (text2 != text)
					{
						list.Add(string.Format(text2, __instance.UnlockValues[i]));
					}
				}
			}
			if (list.Count > 0)
			{
				string text3 = string.Join("\n", list);
				if (string.IsNullOrEmpty(__result) || !flag)
				{
					__result = text3;
				}
				else
				{
					__result = __result + "\n" + text3;
				}
			}
		}

		public static void UpdateDysonSpherePower(DysonSphere ds)
		{
			if (ds?.starData != null && !(M.SpherePowerMultiplier <= 1.0001f))
			{
				float dysonLumino = ds.starData.dysonLumino;
				ds.energyGenPerSail = (long)((float)Configs.freeMode.solarSailEnergyPerTick * dysonLumino * M.SpherePowerMultiplier);
				ds.energyGenPerNode = (long)((float)Configs.freeMode.dysonNodeEnergyPerTick * dysonLumino * M.SpherePowerMultiplier);
				ds.energyGenPerFrame = (long)((float)Configs.freeMode.dysonFrameEnergyPerTick * dysonLumino * M.SpherePowerMultiplier);
				ds.energyGenPerShell = (long)((float)Configs.freeMode.dysonShellEnergyPerTick * dysonLumino * M.SpherePowerMultiplier);
				_needRecalculatePowerRef.Invoke(ds) = true;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(DysonSphere), "Init")]
		public static void DysonSphere_Init_Postfix(DysonSphere __instance)
		{
			UpdateDysonSpherePower(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UITechTree), "RefreshDataValueText")]
		public static void UITechTree_RefreshDataValueText_Postfix(UITechTree __instance)
		{
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.upgradePage != 1)
			{
				return;
			}
			string text = __instance.dataValue1_8.text;
			if (!string.IsNullOrEmpty(text) && !text.Contains("TechName_90"))
			{
				StringBuilder stringBuilder = new StringBuilder(text);
				int num = 0;
				if (M.SpherePowerMultiplier > 1.0001f)
				{
					stringBuilder.Append(string.Format("\n{0} +{1:P1}", Localization.Translate("TechName_9051"), M.SpherePowerMultiplier - 1f));
					num++;
				}
				if (M.ResearchProductivityMultiplier > 1.0001f)
				{
					stringBuilder.Append(string.Format("\n{0} +{1:P0}", Localization.Translate("TechName_9055"), M.ResearchProductivityMultiplier - 1f));
					num++;
				}
				if (M.ProliferatorMultiplier > 1.0001f)
				{
					stringBuilder.Append(string.Format("\n{0} +{1:P1}", Localization.Translate("TechName_9052"), M.ProliferatorMultiplier - 1f));
					num++;
				}
				if (M.WirelessPowerMultiplier > 1.0001f)
				{
					stringBuilder.Append(string.Format("\n{0} +{1:P0}", Localization.Translate("TechName_9002"), M.WirelessPowerMultiplier - 1f));
					num++;
				}
				if (M.CombatSpeedMultiplier > 1.0001f)
				{
					stringBuilder.Append(string.Format("\n{0} +{1:P0}", Localization.Translate("TechName_9054"), M.CombatSpeedMultiplier - 1f));
					num++;
				}
				__instance.dataValue1_8.text = stringBuilder.ToString();
				if (num > 0)
				{
					float num2 = ((GameMain.history.inserterStackCountObsolete > 1) ? 168f : 150f) + (float)num * 18f;
					__instance.rect1_8.sizeDelta = new Vector2(__instance.rect1_8.sizeDelta.x, num2);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(LabComponent), "InternalUpdateResearch")]
		public static void LabComponent_Research_Prefix(ref TechState ts, out long __state)
		{
			__state = ts.hashUploaded;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(LabComponent), "InternalUpdateResearch")]
		public static void LabComponent_Research_Postfix(ref TechState ts, ref long hashRegister, ref long uMatrixPoint, ref int techHashedThisFrame, long __state)
		{
			if (!(M.ResearchProductivityMultiplier <= 1.001f))
			{
				long num = ts.hashUploaded - __state;
				if (num > 0)
				{
					long num2 = (long)((float)num * (M.ResearchProductivityMultiplier - 1f));
					ts.hashUploaded = Math.Min(ts.hashNeeded, ts.hashUploaded + num2);
					hashRegister += num2;
					uMatrixPoint += num2 * ts.uPointPerHash;
					techHashedThisFrame += (int)num2;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UILabWindow), "_OnUpdate")]
		public static void UILabWindow_OnUpdate_Postfix(UILabWindow __instance)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (M.ResearchProductivityMultiplier <= 1.001f || __instance.labId == 0 || __instance.factory == null)
			{
				return;
			}
			LabComponent val = __instance.factorySystem.labPool[__instance.labId];
			if (val.id == __instance.labId && val.researchMode)
			{
				string text = Localization.Translate("哈希每秒");
				string text2 = __instance.speedText.text;
				if (text2.EndsWith(text) && float.TryParse(text2.Substring(0, text2.Length - text.Length), NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
				{
					result *= M.ResearchProductivityMultiplier;
					__instance.speedText.text = result.ToString("0.0") + text;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ItemProto), "GetPropValue")]
		public static void ItemProto_GetPropValue_Postfix(ItemProto __instance, int index, StringBuilder sb, int incLevel, ref string __result)
		{
			if (M.CombatSpeedMultiplier > 1.001f && index >= 0 && index < __instance.DescFields.Length)
			{
				int num = __instance.DescFields[index];
				if (num == 49 || num == 63 || num == 66)
				{
					float num2 = M.CombatSpeedMultiplier - 1f;
					string text = Localization.Translate("发每秒");
					float num3 = 0f;
					if (__instance.prefabDesc.isTurret && num == 49)
					{
						num3 = ((__instance.prefabDesc.turretMuzzleCount <= 1) ? ((float)__instance.prefabDesc.turretROF * 60f / (float)__instance.prefabDesc.turretRoundInterval) : ((float)__instance.prefabDesc.turretROF * 60f * (float)(int)__instance.prefabDesc.turretMuzzleCount / (float)(__instance.prefabDesc.turretRoundInterval + __instance.prefabDesc.turretMuzzleInterval * (__instance.prefabDesc.turretMuzzleCount - 1))));
					}
					else if (__instance.prefabDesc.isCraftUnit)
					{
						num3 = ((num != 63) ? ((__instance.prefabDesc.craftUnitMuzzleCount0 > 1) ? ((float)__instance.prefabDesc.craftUnitROF0 * 60f * (float)__instance.prefabDesc.craftUnitMuzzleCount0 / (float)(__instance.prefabDesc.craftUnitRoundInterval0 + __instance.prefabDesc.craftUnitMuzzleInterval0 * (__instance.prefabDesc.craftUnitMuzzleCount0 - 1))) : ((float)__instance.prefabDesc.craftUnitROF0 * 60f / (float)__instance.prefabDesc.craftUnitRoundInterval0)) : ((__instance.prefabDesc.craftUnitMuzzleCount1 > 1) ? ((float)__instance.prefabDesc.craftUnitROF1 * 60f * (float)__instance.prefabDesc.craftUnitMuzzleCount1 / (float)(__instance.prefabDesc.craftUnitRoundInterval1 + __instance.prefabDesc.craftUnitMuzzleInterval1 * (__instance.prefabDesc.craftUnitMuzzleCount1 - 1))) : ((float)__instance.prefabDesc.craftUnitROF1 * 60f / (float)__instance.prefabDesc.craftUnitRoundInterval1)));
					}
					if (num3 > 0.001f)
					{
						float num4 = num3 * num2;
						string text2 = (__result.EndsWith(text) ? __result.Substring(0, __result.Length - text.Length) : __result);
						if (text2.Contains("<color="))
						{
							int num5 = text2.LastIndexOf("</color>");
							if (num5 > 0)
							{
								string text3 = text2.Substring(0, num5);
								string text4 = text2.Substring(num5);
								__result = text3 + " + " + num4.ToString("0.##") + text4 + text;
							}
						}
						else
						{
							__result = text2 + "<color=#61D8FFB8> + " + num4.ToString("0.##") + "</color>" + text;
						}
					}
				}
			}
			if (M.WirelessPowerMultiplier > 1.001f && index >= 0 && index < __instance.DescFields.Length && __instance.DescFields[index] == 11 && __instance.prefabDesc.isPowerNode && !__instance.prefabDesc.isAccumulator)
			{
				float num6 = M.WirelessPowerMultiplier - 1f;
				string text5 = "W";
				long num7 = __instance.prefabDesc.workEnergyPerTick * 60;
				if (num7 > 0)
				{
					long num8 = (long)((float)num7 * num6);
					string text6 = "";
					text6 = ((num8 >= 1000000) ? (((double)num8 / 1000000.0).ToString("0.##") + " M") : ((num8 < 1000) ? num8.ToString() : (((double)num8 / 1000.0).ToString("0.##") + " k")));
					string text7 = (__result.EndsWith(text5) ? __result.Substring(0, __result.Length - text5.Length) : __result);
					__result = text7 + "<color=#61D8FFB8> + " + text6 + "</color>" + text5;
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UITechTree), "RefreshDataValueText")]
		public static void UITechTree_RefreshDataValueText_Prefix(UITechTree __instance, out float __state)
		{
			__state = 0f;
			if (__instance.upgradePage == 3 && M.CombatSpeedMultiplier > 1.001f)
			{
				__state = M.CombatSpeedMultiplier - 1f;
				GameHistoryData history = GameMain.history;
				history.combatDroneROFRatio += __state;
				GameHistoryData history2 = GameMain.history;
				history2.combatShipROFRatio += __state;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UITechTree), "RefreshDataValueText")]
		public static void UITechTree_RefreshDataValueText_Restore_Postfix(UITechTree __instance, float __state)
		{
			if (__state > 0f && __instance.upgradePage == 3)
			{
				GameHistoryData history = GameMain.history;
				history.combatDroneROFRatio -= __state;
				GameHistoryData history2 = GameMain.history;
				history2.combatShipROFRatio -= __state;
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(PowerSystem), "GameTick")]
		public static IEnumerable<CodeInstruction> PowerSystem_GameTick_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			FieldInfo fieldInfo = AccessTools.Field(typeof(PowerNodeComponent), "workEnergyPerTick");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(InfinityTechnologiesPlugin), "Modifiers");
			FieldInfo fieldInfo3 = AccessTools.Field(typeof(ModifierManager), "WirelessPowerMultiplier");
			if (fieldInfo == null || fieldInfo2 == null || fieldInfo3 == null)
			{
				Log.Error("Failed to find fields for PowerSystem transpiler.");
				return instructions;
			}
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldfld && (FieldInfo)list[i].operand == fieldInfo)
				{
					int num = 1;
					if (i + 1 < list.Count && list[i + 1].opcode == OpCodes.Conv_R8)
					{
						num = 2;
					}
					list.Insert(i + num, new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo2));
					list.Insert(i + num + 1, new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo3));
					list.Insert(i + num + 2, new CodeInstruction(OpCodes.Conv_R8, (object)null));
					list.Insert(i + num + 3, new CodeInstruction(OpCodes.Mul, (object)null));
					break;
				}
			}
			return list;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameHistoryData), "GetCombatUpgradeData")]
		public static void GameHistoryData_GetCombatUpgradeData_Postfix(ref CombatUpgradeData combatUpgradeData)
		{
			if (M.CombatSpeedMultiplier > 1.001f)
			{
				float num = M.CombatSpeedMultiplier - 1f;
				combatUpgradeData.combatDroneROFRatio += num;
				combatUpgradeData.combatShipROFRatio += num;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TurretComponent), "Shoot")]
		public static void TurretComponent_Shoot_Prefix(ref float power)
		{
			if (M.CombatSpeedMultiplier > 1.001f)
			{
				power *= M.CombatSpeedMultiplier;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UITurretWindow), "_OnUpdate")]
		public static void UITurretWindow_OnUpdate_Postfix(UITurretWindow __instance)
		{
			if (!(M.CombatSpeedMultiplier <= 1.001f) && __instance.turretId != 0 && __instance.factory != null)
			{
				string text = " /s";
				string text2 = __instance.bpmText.text;
				if (text2.EndsWith(text) && float.TryParse(text2.Substring(0, text2.Length - text.Length), NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
				{
					result *= M.CombatSpeedMultiplier;
					__instance.bpmText.text = result.ToString("0.##") + text;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIDEOverview), "_OnInit")]
		public static void UIDEOverview_OnInit_Postfix(UIDEOverview __instance, bool __result)
		{
			if (__result && !((Object)(object)__instance.starLuminText == (Object)null))
			{
				DysonSphere value = Traverse.Create((object)__instance).Field("dysonSphere").GetValue<DysonSphere>();
				if (value != null && !(M.SpherePowerMultiplier <= 1.001f))
				{
					string text = value.starData.dysonLumino.ToString("0.000");
					float num = value.starData.dysonLumino * (M.SpherePowerMultiplier - 1f);
					__instance.starLuminText.text = "x " + text + " + " + num.ToString("0.000");
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIStarDetail), "OnStarDataSet")]
		public static void UIStarDetail_OnStarDataSet_Postfix(UIStarDetail __instance)
		{
			if (__instance.star != null && !((Object)(object)__instance.luminoValueText == (Object)null) && !(M.SpherePowerMultiplier <= 1.001f))
			{
				string text = __instance.star.dysonLumino.ToString("0.000");
				float num = __instance.star.dysonLumino * (M.SpherePowerMultiplier - 1f);
				__instance.luminoValueText.text = text + " + " + num.ToString("0.000") + " L    ";
			}
		}
	}
	public static class TechDefinitions
	{
		public static void Register()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			RegisterStrings();
			TechProto val = RegisterTech(9001, "TechName_9001", "TechDesc_9001", "Inventory capacity expanded.", "Icons/Tech/2301", new int[1] { 6006 }, 50000, 50000, new Vector2(42f, 8f));
			val.MaxLevel = 3;
			val.UnlockFunctions = new int[2] { 5, 38 };
			val.UnlockValues = new double[2] { 1.0, 1.0 };
			RegisterInfinite(9002, "TechName_9002", "TechDesc_9002", "Icons/Tech/1101", 102, 0.2, 50000, 50000, new Vector2(42f, 4f));
			RegisterInfinite(9051, "TechName_9051", "TechDesc_9051_Log", "Icons/Tech/1501", 106, 3.0, 10000000, 10000000, new Vector2(50f, 8f));
			RegisterInfinite(9052, "TechName_9052", "TechDesc_9052", "Icons/Tech/1153", 107, 0.0025, 10000000, 10000000, new Vector2(50f, 4f)).MaxLevel = 100;
			RegisterInfinite(9054, "TechName_9054", "TechDesc_9054", "Icons/Tech/1817", 109, 0.05, 300000, 300000, new Vector2(50f, 0f));
			RegisterInfinite(9055, "TechName_9055", "TechDesc_9055_Log", "Icons/ItemRecipe/6006", 110, 16.33, 5000000, 5000000, new Vector2(50f, -4f));
		}

		private static TechProto RegisterInfinite(int id, string name, string desc, string icon, int func, double val, int cost, int costCoef, Vector2 pos)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			TechProto val2 = RegisterTech(id, name, desc, Localization.Translate(name), icon, new int[1] { 6006 }, cost, costCoef, pos);
			val2.MaxLevel = 100000;
			val2.UnlockFunctions = new int[1] { func };
			val2.UnlockValues = new double[1] { val };
			val2.RefreshTranslation();
			return val2;
		}

		private static TechProto RegisterTech(int id, string name, string desc, string concl, string icon, int[] items, int itemCount, int costCoef, Vector2 pos)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			int[] array = Enumerable.Repeat(36, items.Length).ToArray();
			long num = (long)itemCount * 100L;
			TechProto obj = ProtoRegistry.RegisterTech(id, name, desc, concl, icon, new int[0], items, array, num, new int[0], pos);
			obj.LevelCoef1 = (int)((long)costCoef * 100L);
			obj.LevelCoef2 = 0;
			return obj;
		}

		private static void RegisterStrings()
		{
			Reg("TechName_9001", "Infinite Inventory");
			Reg("TechDesc_9001", "Increases the player's inventory capacity further (adds 1 row and 1 column per level). Limited to 3 levels.");
			Reg("TechName_9002", "Wireless Power Boost");
			Reg("TechDesc_9002", "Increases the speed at which the mecha charges from wireless power towers.");
			Reg("TechName_9051", "Dyson Sphere Efficiency");
			Reg("TechDesc_9051_Log", "Increases the total power output generated by the Dyson Sphere. (Logarithmic Scaling)");
			Reg("TechName_9052", "Proliferator Enhancement");
			Reg("TechDesc_9052", "Increases the extra output/speed bonus from Proliferated items. Limited to 100 levels.");
			Reg("TechName_9054", "Logistics Combat Optimization");
			Reg("TechDesc_9054", "Increases shooting speed of turrets, drones and vessels.");
			Reg("TechName_9055", "Research Productivity");
			Reg("TechDesc_9055_Log", "Increases the amount of research hashes produced per matrix consumed. (Logarithmic Scaling)");
			Reg("TechFunction_102", "Wireless charging power +{0:P0}");
			Reg("TechFunction_106", "Sphere energy extraction (Log scaling factor: {0:F2})");
			Reg("TechFunction_107", "Proliferation effects +{0:P1}");
			Reg("TechFunction_109", "Combat fire rate +{0:P0}");
			Reg("TechFunction_110", "Research hashes (Log scaling factor: {0:F1})");
			static void Reg(string key, string en)
			{
				LocalizationModule.RegisterTranslation(key, en);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.Valoneu.InfinityTechnologies";

		public const string PLUGIN_NAME = "InfinityTechnologies";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}