using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DSP_AssemblerUI.AssemblerSpeedUI.Patchers;
using DSP_AssemblerUI.AssemblerSpeedUI.Util;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DSP_AssemblerUI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DSP_AssemblerUI")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7ede0ba0-773b-43c0-8f28-a448a54dca31")]
[assembly: AssemblyFileVersion("2.3.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("2.3.0.0")]
namespace DSP_AssemblerUI.AssemblerSpeedUI
{
[BepInPlugin("dsp.assemblerUI.speedMod", "Assembler UI Speed Info Mod", "2.3.0.0")]
public class AssemblerSpeedUIMod : BaseUnityPlugin
{
internal Harmony harmony;
internal static ModLogger ModLogger;
public static ConfigEntry<bool> configEnableOutputSpeeds;
public static ConfigEntry<bool> configEnableInputSpeeds;
public static ConfigEntry<bool> configInputSpeedsPerSecond;
public static ConfigEntry<bool> configOutputSpeedsPerSecond;
public static ConfigEntry<bool> configShowLiveSpeed;
public static ConfigEntry<uint> configShownDecimalPlaces;
public static ConfigEntry<bool> configShowMinerSpeed;
public static ConfigEntry<bool> configShowMinerLiveSpeed;
public static ConfigEntry<bool> configMinerSpeedsPerSecond;
internal void Awake()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Expected O, but got Unknown
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Expected O, but got Unknown
ManualLogSource val = new ManualLogSource("AssemblerSpeedUIMod");
Logger.Sources.Add((ILogSource)(object)val);
ModLogger = new ModLogger(val);
configEnableOutputSpeeds = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableOutputSpeedInfo", true, "Enables the speed information below the output area in the Assembler Window.");
configEnableInputSpeeds = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableInputSpeedInfo", true, "Enables the speed information above the input area in the Assembler Window.");
configOutputSpeedsPerSecond = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableOutputSpeedInfoPerSecond", false, "Sets the output speeds shown in Assemblers to items/s (default: items/min).");
configInputSpeedsPerSecond = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableInputSpeedInfoPerSecond", false, "Sets the input speeds shown in Assemblers to items/s (default: items/min).");
configShowLiveSpeed = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowLiveSpeedInfo", false, "True: shows current speed of production building. False: shows regular recipe speed of production building.");
configShownDecimalPlaces = ((BaseUnityPlugin)this).Config.Bind<uint>("General", "NumberOfDecimalsShown", 1u, new ConfigDescription($"Sets the number of decimal places shown for speed values. Value must be in range [{0u},{3u}].", (AcceptableValueBase)(object)new AcceptableValueRange<uint>(0u, 3u), Array.Empty<object>()));
configShowMinerSpeed = ((BaseUnityPlugin)this).Config.Bind<bool>("Miner", "EnableMinerSpeedInfo", true, "Enables the speed information below the output area in the Miner Window.");
configShowMinerLiveSpeed = ((BaseUnityPlugin)this).Config.Bind<bool>("Miner", "ShowMinerLiveSpeedInfo", false, "True: shows current speed of production building. False: shows regular recipe speed of production building.");
configMinerSpeedsPerSecond = ((BaseUnityPlugin)this).Config.Bind<bool>("Miner", "EnableMinerOutputSpeedInfoPerSecond", false, "Sets the output speeds shown in Miners to items/s (default: items/min).");
UiAssemblerWindowPatch.additionalSpeedLabels = new AdditionalSpeedLabels(ModLogger, configEnableOutputSpeeds.Value, configEnableInputSpeeds.Value, Constants.AssemblerWindowSpeedTextPath);
UiMinerWindowPatch.additionalSpeedLabels = new AdditionalSpeedLabels(ModLogger, configShowMinerSpeed.Value, setupInputLabels: false, Constants.MinerWindowSpeedTextPath);
harmony = new Harmony("dsp.assemblerUI.speedMod");
try
{
harmony.PatchAll(typeof(UiAssemblerWindowPatch));
harmony.PatchAll(typeof(UiMinerWindowPatch));
}
catch (Exception ex)
{
ModLogger.ErrorLog(ex.Message);
ModLogger.ErrorLog(ex.StackTrace);
}
}
internal void OnDestroy()
{
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
UiAssemblerWindowPatch.additionalSpeedLabels.Destroy();
UiMinerWindowPatch.additionalSpeedLabels.Destroy();
}
}
internal static class Constants
{
public static readonly string BaseWindowsPath = "UI Root/Overlay Canvas/In Game/Windows";
public static readonly string AssemblerWindowPath = BaseWindowsPath + "/Assembler Window";
public static readonly string AssemblerWindowSpeedTextPath = AssemblerWindowPath + "/produce/speed/speed-text";
public static readonly string MinerWindowPath = BaseWindowsPath + "/Miner Window";
public static readonly string MinerWindowSpeedTextPath = MinerWindowPath + "/produce/speed/speed-text";
public const uint MIN_DECIMAL_PLACES = 0u;
public const uint MAX_DECIMAL_PLACES = 3u;
public const float INPUT_YPOS = 25f;
public const float OUTPUT_YPOS = -50f;
public const float INPUT_FIRST_X_OFFSET = 130f;
public const float OUTPUT_FIRST_X_OFFSET = 1f;
public const float INPUT_X_ITEMSIZE = 50f;
public const float OUTPUT_X_ITEMSIZE = 64f;
public const float INPUT_MAXWIDTH = 48f;
public const float OUTPUT_MAXWIDTH = 62f;
public const int MAX_FONTSIZE = 12;
}
public static class ModInfo
{
public const string ModID = "dsp.assemblerUI.speedMod";
public const string ModName = "Assembler UI Speed Info Mod";
public const string majorVersion = "2";
public const string minorVersion = "3";
public const string hotfixVersion = "0";
public const string buildVersion = "0";
public const string VersionString = "2.3.0.0";
}
public class ModLogger
{
private readonly ManualLogSource _logSource;
public ModLogger(ManualLogSource logSource)
{
_logSource = logSource;
}
[Conditional("DEBUG")]
public void DebugLog(string logMessage)
{
_logSource.LogDebug((object)logMessage);
}
public void ErrorLog(string logMessage)
{
_logSource.LogError((object)logMessage);
}
}
}
namespace DSP_AssemblerUI.AssemblerSpeedUI.Patchers
{
public static class UiAssemblerWindowPatch
{
internal static AdditionalSpeedLabels additionalSpeedLabels;
public static void UpdateSpeedLabels(float baseSpeed, int[] productCounts, int[] requireCounts)
{
additionalSpeedLabels.UpdateSpeedLabels(baseSpeed, productCounts, requireCounts);
}
private static void SetupLabels(UIAssemblerWindow window)
{
int? productCount = window.factorySystem?.assemblerPool[window.assemblerId].products?.Length;
int? inputCount = window.factorySystem?.assemblerPool[window.assemblerId].requires?.Length;
additionalSpeedLabels.SetupLabels(productCount, inputCount);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIAssemblerWindow), "OnAssemblerIdChange")]
public static void OnAssemblerIdChangePostfix(UIAssemblerWindow __instance)
{
SetupLabels(__instance);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(AssemblerComponent), "SetRecipe")]
public static void SetRecipePostfix(AssemblerComponent __instance)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
if (((ManualBehaviour)UIRoot.instance.uiGame.assemblerWindow).active && UIRoot.instance.uiGame.assemblerWindow.assemblerId == __instance.id)
{
SetupLabels(UIRoot.instance.uiGame.assemblerWindow);
}
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(UIAssemblerWindow), "_OnUpdate")]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator codeGen)
{
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Expected O, but got Unknown
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Expected O, but got Unknown
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Expected O, but got Unknown
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Expected O, but got Unknown
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Expected O, but got Unknown
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Expected O, but got Unknown
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Expected O, but got Unknown
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Expected O, but got Unknown
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Expected O, but got Unknown
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Expected O, but got Unknown
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Expected O, but got Unknown
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Expected O, but got Unknown
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Expected O, but got Unknown
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Expected O, but got Unknown
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01cd: Expected O, but got Unknown
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f5: Expected O, but got Unknown
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_021d: Expected O, but got Unknown
//IL_0232: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Expected O, but got Unknown
//IL_026a: Unknown result type (might be due to invalid IL or missing references)
//IL_0270: Expected O, but got Unknown
//IL_0290: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Expected O, but got Unknown
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
//IL_02a9: Expected O, but got Unknown
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
//IL_02c2: Expected O, but got Unknown
//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
//IL_02d0: Expected O, but got Unknown
//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
//IL_02e3: Expected O, but got Unknown
//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0304: Expected O, but got Unknown
//IL_030c: Unknown result type (might be due to invalid IL or missing references)
//IL_0312: Expected O, but got Unknown
//IL_032e: Unknown result type (might be due to invalid IL or missing references)
//IL_0334: Expected O, but got Unknown
//IL_037d: Unknown result type (might be due to invalid IL or missing references)
//IL_0383: Expected O, but got Unknown
LocalBuilder localBuilder = codeGen.DeclareLocal(typeof(float));
localBuilder.SetLocalSymInfo("baseSpeedValue");
Label label = codeGen.DefineLabel();
(int, int)? tuple = FieldIndexFinder.FindRelevantFieldIndicesUIAssemblerWindow(instructions);
if (tuple.HasValue)
{
(int, int) value = tuple.Value;
int divisor60 = value.Item1;
int speedvalue = value.Item2;
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldc_R4 && CodeInstructionExtensions.OperandIs(i, (object)60f)), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder localBuilder4 && localBuilder4.LocalIndex == divisor60), (string)null),
new CodeMatch((OpCode?)OpCodes.Div, (object)null, (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stloc_S && i.operand is LocalBuilder localBuilder3 && localBuilder3.LocalIndex == speedvalue), (string)null)
});
val.Advance(1);
val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[8]
{
new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)speedvalue),
new CodeInstruction(OpCodes.Ldloc_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)typeof(AssemblerComponent).GetField("speedOverride")),
new CodeInstruction(OpCodes.Conv_R4, (object)null),
new CodeInstruction(OpCodes.Ldc_R4, (object)0.0001f),
new CodeInstruction(OpCodes.Mul, (object)null),
new CodeInstruction(OpCodes.Mul, (object)null),
new CodeInstruction(OpCodes.Stloc_S, (object)localBuilder)
});
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((OpCode?)OpCodes.Mul, (object)null, (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stloc_S && i.operand is LocalBuilder localBuilder2 && localBuilder2.LocalIndex == speedvalue), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldarg_0), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldfld && i.operand is FieldInfo fieldInfo && fieldInfo.Name == typeof(UIAssemblerWindow).GetField("speedText").Name), (string)null)
});
val.Advance(2);
CodeInstruction val2 = new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder);
val2.labels.Add(label);
val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[11]
{
new CodeInstruction(OpCodes.Ldsfld, (object)typeof(AssemblerSpeedUIMod).GetField("configShowLiveSpeed")),
new CodeInstruction(OpCodes.Callvirt, (object)typeof(ConfigEntry<bool>).GetProperty("Value").GetGetMethod()),
new CodeInstruction(OpCodes.Brfalse, (object)label),
new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)speedvalue),
new CodeInstruction(OpCodes.Stloc_S, (object)localBuilder),
val2,
new CodeInstruction(OpCodes.Ldloc_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)typeof(AssemblerComponent).GetField("productCounts")),
new CodeInstruction(OpCodes.Ldloc_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)typeof(AssemblerComponent).GetField("requireCounts")),
new CodeInstruction(OpCodes.Call, (object)typeof(UiAssemblerWindowPatch).GetMethod("UpdateSpeedLabels", new Type[3]
{
typeof(float),
typeof(int[]),
typeof(int[])
}))
});
return val.InstructionEnumeration();
}
AssemblerSpeedUIMod.ModLogger.ErrorLog("[UIAssemblerWindow] Could not find the desired fields for patching the update logic.");
return instructions;
}
}
public static class UiMinerWindowPatch
{
internal static AdditionalSpeedLabels additionalSpeedLabels;
[HarmonyPostfix]
[HarmonyPatch(typeof(UIMinerWindow), "OnMinerIdChange")]
public static void OnMinerIdChangePostfix()
{
additionalSpeedLabels.SetupLabels(1, null);
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(UIMinerWindow), "_OnUpdate")]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator codeGen)
{
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Expected O, but got Unknown
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Expected O, but got Unknown
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Expected O, but got Unknown
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Expected O, but got Unknown
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Expected O, but got Unknown
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Expected O, but got Unknown
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Expected O, but got Unknown
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Expected O, but got Unknown
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Expected O, but got Unknown
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Expected O, but got Unknown
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Expected O, but got Unknown
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Expected O, but got Unknown
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: Expected O, but got Unknown
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Expected O, but got Unknown
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Expected O, but got Unknown
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_021f: Expected O, but got Unknown
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Expected O, but got Unknown
//IL_0240: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Expected O, but got Unknown
//IL_0277: Unknown result type (might be due to invalid IL or missing references)
//IL_027d: Expected O, but got Unknown
//IL_029f: Unknown result type (might be due to invalid IL or missing references)
//IL_02a5: Expected O, but got Unknown
//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
//IL_02ca: Expected O, but got Unknown
//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
//IL_02d8: Expected O, but got Unknown
//IL_0309: Unknown result type (might be due to invalid IL or missing references)
//IL_030f: Expected O, but got Unknown
//IL_0331: Unknown result type (might be due to invalid IL or missing references)
//IL_0337: Expected O, but got Unknown
//IL_0359: Unknown result type (might be due to invalid IL or missing references)
//IL_035f: Expected O, but got Unknown
//IL_0381: Unknown result type (might be due to invalid IL or missing references)
//IL_0387: Expected O, but got Unknown
//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
//IL_03ac: Expected O, but got Unknown
//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
//IL_03ba: Expected O, but got Unknown
//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
//IL_03de: Expected O, but got Unknown
//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
//IL_03f3: Expected O, but got Unknown
//IL_0401: Unknown result type (might be due to invalid IL or missing references)
//IL_0407: Expected O, but got Unknown
//IL_0416: Unknown result type (might be due to invalid IL or missing references)
//IL_041c: Expected O, but got Unknown
//IL_0428: Unknown result type (might be due to invalid IL or missing references)
//IL_042f: Expected O, but got Unknown
//IL_0442: Unknown result type (might be due to invalid IL or missing references)
//IL_0449: Expected O, but got Unknown
//IL_047b: Unknown result type (might be due to invalid IL or missing references)
//IL_0481: Expected O, but got Unknown
//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
//IL_04a7: Expected O, but got Unknown
//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
//IL_04ba: Expected O, but got Unknown
//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
//IL_04d3: Expected O, but got Unknown
//IL_04db: Unknown result type (might be due to invalid IL or missing references)
//IL_04e1: Expected O, but got Unknown
//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
//IL_04f5: Expected O, but got Unknown
//IL_0502: Unknown result type (might be due to invalid IL or missing references)
//IL_0508: Expected O, but got Unknown
//IL_0510: Unknown result type (might be due to invalid IL or missing references)
//IL_0516: Expected O, but got Unknown
//IL_051f: Unknown result type (might be due to invalid IL or missing references)
//IL_0525: Expected O, but got Unknown
//IL_055a: Unknown result type (might be due to invalid IL or missing references)
//IL_0560: Expected O, but got Unknown
LocalBuilder localBuilder = codeGen.DeclareLocal(typeof(float));
localBuilder.SetLocalSymInfo("baseSpeedValue");
LocalBuilder localBuilder2 = codeGen.DeclareLocal(typeof(float));
localBuilder.SetLocalSymInfo("miningSpeedFactor");
Label label = codeGen.DefineLabel();
Label label2 = codeGen.DefineLabel();
(int, int, int)? tuple = FieldIndexFinder.FindRelevantFieldIndicesUIMinerWindow(instructions);
if (tuple.HasValue)
{
(int, int, int) value = tuple.Value;
int divisor60 = value.Item1;
int speedvalue = value.Item2;
int outputstringFactor = value.Item3;
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldc_R4 && CodeInstructionExtensions.OperandIs(i, (object)60f)), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder localBuilder7 && localBuilder7.LocalIndex == divisor60), (string)null),
new CodeMatch((OpCode?)OpCodes.Div, (object)null, (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stloc_S && i.operand is LocalBuilder localBuilder6 && localBuilder6.LocalIndex == speedvalue), (string)null)
});
val.Advance(1);
val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[13]
{
new CodeInstruction(OpCodes.Ldc_R4, (object)0.0001f),
new CodeInstruction(OpCodes.Ldloc_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)typeof(MinerComponent).GetField("speed")),
new CodeInstruction(OpCodes.Conv_R4, (object)null),
new CodeInstruction(OpCodes.Mul, (object)null),
new CodeInstruction(OpCodes.Call, (object)typeof(GameMain).GetProperty("history").GetGetMethod()),
new CodeInstruction(OpCodes.Ldfld, (object)typeof(GameHistoryData).GetField("miningSpeedScale")),
new CodeInstruction(OpCodes.Mul, (object)null),
new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)speedvalue),
new CodeInstruction(OpCodes.Mul, (object)null),
new CodeInstruction(OpCodes.Stloc_S, (object)localBuilder),
new CodeInstruction(OpCodes.Ldc_R4, (object)1f),
new CodeInstruction(OpCodes.Stloc_S, (object)localBuilder2)
});
val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[2]
{
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldfld && i.operand is FieldInfo fieldInfo2 && fieldInfo2.Name == "veinCount" && fieldInfo2.FieldType == typeof(int)), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Conv_R4), (string)null)
});
val.Advance(1);
val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Stloc_S, (object)localBuilder2),
new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder2)
});
val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldsfld && i.operand is FieldInfo fieldInfo && fieldInfo.Name == "oilSpeedMultiplier" && fieldInfo.FieldType == typeof(float)), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Conv_R8), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Mul), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Conv_R4), (string)null)
});
val.Advance(1);
val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Stloc_S, (object)localBuilder2),
new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder2)
});
val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder localBuilder5 && localBuilder5.LocalIndex == speedvalue), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder localBuilder4 && localBuilder4.LocalIndex == outputstringFactor), (string)null),
new CodeMatch((OpCode?)OpCodes.Mul, (object)null, (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stloc_S && i.operand is LocalBuilder localBuilder3 && localBuilder3.LocalIndex == speedvalue), (string)null)
});
CodeInstruction val2 = new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder);
val2.labels.Add(label);
CodeInstruction val3 = new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder);
val3.labels.Add(label2);
val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[12]
{
new CodeInstruction(OpCodes.Ldsfld, (object)typeof(AssemblerSpeedUIMod).GetField("configShowMinerLiveSpeed")),
new CodeInstruction(OpCodes.Callvirt, (object)typeof(ConfigEntry<bool>).GetProperty("Value").GetGetMethod()),
new CodeInstruction(OpCodes.Brfalse, (object)label),
new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)speedvalue),
new CodeInstruction(OpCodes.Stloc_S, (object)localBuilder),
new CodeInstruction(OpCodes.Br, (object)label2),
val2,
new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder2),
new CodeInstruction(OpCodes.Mul, (object)null),
new CodeInstruction(OpCodes.Stloc_S, (object)localBuilder),
val3,
new CodeInstruction(OpCodes.Call, (object)typeof(UiMinerWindowPatch).GetMethod("UpdateSpeedLabel", new Type[1] { typeof(float) }))
});
return val.Instructions();
}
AssemblerSpeedUIMod.ModLogger.ErrorLog("[UIMinerWindow] Could not find the desired fields for patching the update logic.");
return instructions;
}
public static void UpdateSpeedLabel(float baseSpeed)
{
additionalSpeedLabels.UpdateSpeedLabel("assembler-speed-out-item0", baseSpeed, AssemblerSpeedUIMod.configMinerSpeedsPerSecond.Value);
}
}
}
namespace DSP_AssemblerUI.AssemblerSpeedUI.Util
{
public class AdditionalSpeedLabels
{
private readonly string speedTextPath;
private const string OutputKeyBase = "assembler-speed-out-item";
private const string InputKeyBase = "assembler-speed-in-item";
private const int safetyIndexLimit = 5;
private Dictionary<string, ItemSpeedInfoLabel> speedInfos = new Dictionary<string, ItemSpeedInfoLabel>();
private int speedInfosOutCount;
private int speedInfosInCount;
private Vector3? vanillaSpeedPos;
private int currentOutputs = 1;
private int currentInputs = 1;
private ModLogger modLogger;
private bool setupOutputLabels;
private bool setupInputLabels;
private string DecimalFormatString => "F" + AssemblerSpeedUIMod.configShownDecimalPlaces.Value;
public AdditionalSpeedLabels(ModLogger modLogger, bool setupOutputLabels, bool setupInputLabels, string speedTextPath)
{
this.modLogger = modLogger;
this.setupOutputLabels = setupOutputLabels;
this.setupInputLabels = setupInputLabels;
this.speedTextPath = speedTextPath;
currentInputs = (setupInputLabels ? 1 : 0);
}
private string MakeFormattedPaddedLabelString(float f)
{
return " " + f.ToString(DecimalFormatString);
}
private static string ItemInputKey(int index)
{
return "assembler-speed-in-item" + index;
}
private static string ItemOutputKey(int index)
{
return "assembler-speed-out-item" + index;
}
public void SetupLabels(int? productCount, int? inputCount)
{
if (setupOutputLabels && productCount.HasValue)
{
SetupSidedLabels(productCount.Value, isInput: false);
}
if (setupInputLabels && inputCount.HasValue)
{
SetupSidedLabels(inputCount.Value, isInput: true);
}
}
public void SetupSidedLabels(int itemCount, bool isInput)
{
Func<int, string> func = (isInput ? new Func<int, string>(ItemInputKey) : new Func<int, string>(ItemOutputKey));
int num = Math.Min(itemCount, 5);
if (isInput)
{
currentInputs = num;
}
else
{
currentOutputs = num;
}
for (int i = 0; i < num; i++)
{
if (!speedInfos.ContainsKey(func(i)))
{
AddSpeedLabel(func(i), i, num, isInput);
if (isInput)
{
speedInfosInCount++;
}
else
{
speedInfosOutCount++;
}
}
}
string text = Localization.Translate("每分钟");
int num2 = (isInput ? speedInfosInCount : speedInfosOutCount);
for (int j = 0; j < num2; j++)
{
if (j < itemCount)
{
speedInfos[func(j)].Value.text = MakeFormattedPaddedLabelString(0f) + text;
speedInfos[func(j)].GameObject.SetActive(true);
TryStartPositioningOnLabel(speedInfos[func(j)], num);
}
else
{
speedInfos[func(j)].GameObject.SetActive(false);
}
}
}
public void AddSpeedLabel(string id, int num, int ofNum, bool input)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: 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_00d4: 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)
GameObject val = GameObject.Find(speedTextPath);
if ((Object)(object)val == (Object)null)
{
throw new InvalidOperationException("Assembler speed base entry is not present");
}
GameObject val2 = null;
val.GetComponent<Text>();
val2 = Object.Instantiate<GameObject>(val, val.transform.position, Quaternion.identity);
Object.Destroy((Object)(object)val2.GetComponentInChildren<Localizer>());
ContentSizeFitter val3 = val2.AddComponent<ContentSizeFitter>();
val3.horizontalFit = (FitMode)2;
val3.verticalFit = (FitMode)2;
((Object)val2).name = id;
val2.transform.SetParent(val.transform.parent);
Text value = val2.GetComponentsInChildren<Text>()[0];
if (!vanillaSpeedPos.HasValue)
{
vanillaSpeedPos = val.transform.localPosition;
}
val2.transform.localScale = new Vector3(1f, 1f, 1f);
val2.transform.right = val.transform.right;
ItemSpeedInfoLabel itemSpeedInfoLabel = new ItemSpeedInfoLabel
{
GameObject = val2,
Value = value,
Index = num,
IsInput = input,
Fitter = val3
};
speedInfos.Add(id, itemSpeedInfoLabel);
TryStartPositioningOnLabel(itemSpeedInfoLabel, ofNum);
}
private IEnumerator PositionSpeedLabel(ItemSpeedInfoLabel labelData, int ofNum)
{
RectTransform targetTransform = (RectTransform)((Component)labelData.Fitter).transform;
float sizeLimit = (labelData.IsInput ? 48f : 62f);
yield return null;
Rect rect;
while (true)
{
rect = targetTransform.rect;
if (((Rect)(ref rect)).width < sizeLimit - 5f && labelData.Value.fontSize < 12)
{
labelData.Value.fontSize = Math.Min(12, labelData.Value.fontSize + 4);
yield return null;
continue;
}
break;
}
while (true)
{
rect = targetTransform.rect;
if (!(((Rect)(ref rect)).width > sizeLimit))
{
break;
}
Text value = labelData.Value;
value.fontSize -= 1;
yield return null;
}
int index = labelData.Index;
bool isInput = labelData.IsInput;
float z = vanillaSpeedPos.Value.z;
rect = targetTransform.rect;
Vector3 pos = GetPos(index, ofNum, isInput, z, ((Rect)(ref rect)).width);
((Transform)targetTransform).localPosition = pos;
}
private void TryStartPositioningOnLabel(ItemSpeedInfoLabel labelData, int ofNum)
{
if (labelData.GameObject.activeInHierarchy)
{
((MonoBehaviour)labelData.Fitter).StartCoroutine(PositionSpeedLabel(labelData, ofNum));
}
}
private static Vector3 GetPos(int num, int ofNum, bool input, float z, float width)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
float num2 = (input ? 25f : (-50f));
return new Vector3(GetXShift(num, ofNum, input, width), num2, z);
}
private static float GetXShift(int num, int ofNum, bool input, float width)
{
if (input)
{
float num2 = 50f;
return 130f - width / 2f + (float)num * num2;
}
float num3 = -64f;
return 1f - width / 2f + (float)(ofNum - 1 - num) * num3;
}
public void UpdateSpeedLabel(string id, float value, bool perSecond)
{
string text = Localization.Translate("每分钟");
string text2 = "/s";
string text3 = ((!perSecond) ? (MakeFormattedPaddedLabelString(value) + text) : (MakeFormattedPaddedLabelString(value / 60f) + text2));
if (text3 != speedInfos[id].Value.text)
{
speedInfos[id].Value.text = text3;
TryStartPositioningOnLabel(speedInfos[id], speedInfos[id].IsInput ? currentInputs : currentOutputs);
}
}
public void UpdateSpeedLabels(float baseSpeed, int[] productCounts, int[] requireCounts)
{
if (setupOutputLabels)
{
for (int i = 0; i < Math.Min(productCounts.Length, 5); i++)
{
UpdateSpeedLabel(ItemOutputKey(i), (float)productCounts[i] * baseSpeed, AssemblerSpeedUIMod.configOutputSpeedsPerSecond.Value);
}
}
if (setupInputLabels)
{
for (int j = 0; j < Math.Min(requireCounts.Length, 5); j++)
{
UpdateSpeedLabel(ItemInputKey(j), (float)requireCounts[j] * baseSpeed, AssemblerSpeedUIMod.configInputSpeedsPerSecond.Value);
}
}
}
public void Destroy()
{
foreach (KeyValuePair<string, ItemSpeedInfoLabel> speedInfo in speedInfos)
{
Object.Destroy((Object)(object)speedInfo.Value.GameObject);
}
}
}
internal class ItemSpeedInfoLabel
{
public GameObject GameObject { get; set; }
public Text Value { get; set; }
public int Index { get; set; }
public bool IsInput { get; set; }
public ContentSizeFitter Fitter { get; set; }
}
public class FieldIndexFinder
{
public static (int a, int b, int c)? FindRelevantFieldIndicesUIMinerWindow(IEnumerable<CodeInstruction> instructions)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Expected O, but got Unknown
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Expected O, but got Unknown
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Expected O, but got Unknown
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Expected O, but got Unknown
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Expected O, but got Unknown
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Expected O, but got Unknown
int num = -1;
int second = -1;
int num2 = -1;
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldc_R4 && CodeInstructionExtensions.OperandIs(i, (object)60f)), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder), (string)null),
new CodeMatch((OpCode?)OpCodes.Div, (object)null, (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stloc_S && i.operand is LocalBuilder), (string)null)
});
if (val.IsValid)
{
val.Advance(1);
num = ((LocalBuilder)val.Instruction.operand).LocalIndex;
val.Advance(2);
second = ((LocalBuilder)val.Instruction.operand).LocalIndex;
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder localBuilder2 && localBuilder2.LocalIndex == second), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder), (string)null),
new CodeMatch((OpCode?)OpCodes.Mul, (object)null, (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stloc_S && i.operand is LocalBuilder localBuilder && localBuilder.LocalIndex == second), (string)null)
});
if (val.IsValid)
{
val.Advance(1);
num2 = ((LocalBuilder)val.Instruction.operand).LocalIndex;
return (num, second, num2);
}
return null;
}
return null;
}
public static (int a, int b)? FindRelevantFieldIndicesUIAssemblerWindow(IEnumerable<CodeInstruction> instructions)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Expected O, but got Unknown
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Expected O, but got Unknown
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Expected O, but got Unknown
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Expected O, but got Unknown
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Expected O, but got Unknown
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Expected O, but got Unknown
int num = -1;
int second = -1;
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldc_R4 && CodeInstructionExtensions.OperandIs(i, (object)60f)), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder), (string)null),
new CodeMatch((OpCode?)OpCodes.Div, (object)null, (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stloc_S && i.operand is LocalBuilder), (string)null)
});
if (val.IsValid)
{
val.Advance(1);
num = ((LocalBuilder)val.Instruction.operand).LocalIndex;
val.Advance(2);
second = ((LocalBuilder)val.Instruction.operand).LocalIndex;
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((OpCode?)OpCodes.Mul, (object)null, (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stloc_S && i.operand is LocalBuilder localBuilder && localBuilder.LocalIndex == second), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldarg_0), (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldfld && i.operand is FieldInfo fieldInfo && fieldInfo.Name == typeof(UIAssemblerWindow).GetField("speedText").Name), (string)null)
});
if (val.IsValid)
{
return (num, second);
}
return null;
}
return null;
}
}
}