using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AddAmountOfRecipePer1min")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AddAmountOfRecipePer1min")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0e1d6dd0-6e33-462d-9342-fa66119d3c45")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.1.0")]
[module: UnverifiableCode]
namespace AddAmountOfRecipePer1min;
[HarmonyPatch(typeof(UIItemTip))]
[HarmonyPatch("SetTip")]
internal static class Patch_UIItemTip_SetTip
{
private const int DEFAULT_RECIPE_ENTRY_ARR_SIZE = 32;
private static void Prefix(UIItemTip __instance, int __0, int __1, Vector2 __2, Transform __3)
{
ref UIRecipeEntry[] reference = ref AccessTools.FieldRefAccess<UIItemTip, UIRecipeEntry[]>(__instance, "recipeEntryArr");
if (reference == null)
{
return;
}
for (int i = 0; i < reference.Length; i++)
{
if ((Object)(object)reference[i] != (Object)null)
{
((Component)reference[i]).gameObject.SetActive(false);
}
}
}
private static void Postfix(UIItemTip __instance, int __0, int __1, Vector2 __2, Transform __3)
{
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Invalid comparison between Unknown and I4
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Invalid comparison between Unknown and I4
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_022e: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_028d: Unknown result type (might be due to invalid IL or missing references)
//IL_029d: Unknown result type (might be due to invalid IL or missing references)
//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_0371: Unknown result type (might be due to invalid IL or missing references)
//IL_0376: Unknown result type (might be due to invalid IL or missing references)
//IL_0378: Unknown result type (might be due to invalid IL or missing references)
//IL_0388: Unknown result type (might be due to invalid IL or missing references)
//IL_0397: Unknown result type (might be due to invalid IL or missing references)
//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
int num;
int num2;
if (__0 > 0)
{
num = __0;
num2 = 0;
}
else if (__0 < 0)
{
num = 0;
num2 = -__0;
}
else
{
num = 0;
num2 = 0;
}
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(num);
RecipeProto val2 = ((ProtoSet<RecipeProto>)(object)LDB.recipes).Select(num2);
List<RecipeProto> list = new List<RecipeProto>();
if (val2 != null)
{
list.Add(null);
list[0] = val2;
}
List<RecipeProto> list2 = ((val != null) ? val.recipes : ((val2 != null) ? list : null));
ref UIRecipeEntry reference = ref AccessTools.FieldRefAccess<UIItemTip, UIRecipeEntry>(__instance, "recipeEntry");
ref UIRecipeEntry[] reference2 = ref AccessTools.FieldRefAccess<UIItemTip, UIRecipeEntry[]>(__instance, "recipeEntryArr");
if (reference2 != null && reference2.Length == 32)
{
Array.Resize(ref reference2, 64);
}
if (list2 != null && list2.Count > 0)
{
float num3 = 0f;
for (int i = 0; i < list2.Count; i++)
{
if ((int)list2[i].Type != 8)
{
float num4 = (list2[i].Results.Length + list2[i].Items.Length) * 40 + 40 + 20;
if (num4 > num3)
{
num3 = num4;
}
}
}
for (int j = 0; j < list2.Count; j++)
{
if ((Object)(object)reference2[j + 32] == (Object)null)
{
reference2[j + 32] = Object.Instantiate<UIRecipeEntry>(reference, ((Component)__instance).transform);
}
if ((int)list2[j].Type == 8)
{
((Component)reference2[j + 32]).gameObject.SetActive(false);
continue;
}
SetRecipe1Min(reference2[j + 32], list2[j]);
reference2[j + 32].rectTrans.anchoredPosition = new Vector2(reference2[j].rectTrans.anchoredPosition.x + num3, reference2[j].rectTrans.anchoredPosition.y);
((Component)reference2[j + 32]).gameObject.SetActive(true);
}
ref RectTransform reference3 = ref AccessTools.FieldRefAccess<UIItemTip, RectTransform>(__instance, "trans");
if (reference3.sizeDelta.x < num3 * 2f)
{
reference3.sizeDelta = new Vector2(num3 * 2f, reference3.sizeDelta.y);
((Transform)reference3).SetParent((Transform)(object)UIRoot.instance.itemTipTransform, true);
Rect rect = UIRoot.instance.itemTipTransform.rect;
float num5 = Mathf.RoundToInt(((Rect)(ref rect)).width);
float num6 = Mathf.RoundToInt(((Rect)(ref rect)).height);
float num7 = reference3.anchorMin.x * num5 + reference3.anchoredPosition.x;
float num8 = reference3.anchorMin.y * num6 + reference3.anchoredPosition.y;
Rect rect2 = reference3.rect;
((Rect)(ref rect2)).x = ((Rect)(ref rect2)).x + num7;
((Rect)(ref rect2)).y = ((Rect)(ref rect2)).y + num8;
Vector2 zero = Vector2.zero;
if (((Rect)(ref rect2)).xMin < 0f)
{
zero.x -= ((Rect)(ref rect2)).xMin;
}
if (((Rect)(ref rect2)).yMin < 0f)
{
zero.y -= ((Rect)(ref rect2)).yMin;
}
if (((Rect)(ref rect2)).xMax > num5)
{
zero.x -= ((Rect)(ref rect2)).xMax - num5;
}
if (((Rect)(ref rect2)).yMax > num6)
{
zero.y -= ((Rect)(ref rect2)).yMax - num6;
}
reference3.anchoredPosition += zero;
reference3.anchoredPosition = new Vector2((float)(int)reference3.anchoredPosition.x, (float)(int)reference3.anchoredPosition.y);
((Transform)reference3).localScale = new Vector3(1f, 1f, 1f);
}
}
if (val != null && val.prefabDesc.isBelt)
{
StringBuilder stringBuilder = new StringBuilder(" ", 12);
string propValue = val.GetPropValue(0, stringBuilder, 0);
string text = ((double)val.prefabDesc.beltSpeed * 60.0 / 10.0 * 60.0).ToString("0.##") + "/min";
ref Text reference4 = ref AccessTools.FieldRefAccess<UIItemTip, Text>(__instance, "valuesText");
reference4.text = reference4.text.Replace(propValue, propValue + "(" + text + ")");
}
}
private static void SetRecipe1Min(UIRecipeEntry uiRecipeEntry, RecipeProto recipeProto)
{
//IL_001b: 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)
//IL_0072: Invalid comparison between Unknown and I4
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
//IL_02ae: Invalid comparison between Unknown and I4
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
//IL_02de: Unknown result type (might be due to invalid IL or missing references)
//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
//IL_0503: Unknown result type (might be due to invalid IL or missing references)
//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
int num = 0;
int num2 = 0;
int i = 0;
double num3 = 1.0;
if (((Graphic)uiRecipeEntry.timeText).rectTransform.sizeDelta.y > 37f)
{
((Graphic)uiRecipeEntry.timeText).rectTransform.sizeDelta = new Vector2(((Graphic)uiRecipeEntry.timeText).rectTransform.sizeDelta.x, 37f);
}
uiRecipeEntry.timeText.text = "1min";
if ((int)recipeProto.Type == 4)
{
((Graphic)uiRecipeEntry.timeText).rectTransform.sizeDelta = new Vector2(((Graphic)uiRecipeEntry.timeText).rectTransform.sizeDelta.x, ((Graphic)uiRecipeEntry.timeText).rectTransform.sizeDelta.y + 25f);
if (MainPlugin.LimitDefaultAssemblerSpeedToLatestUnlocked.Value)
{
string text = MainPlugin.DefaultAssemblerSpeed.Value;
string text2 = (GameMain.data.history.TechUnlocked(1203) ? MainPlugin.MK3 : (GameMain.data.history.TechUnlocked(1202) ? MainPlugin.MK2 : MainPlugin.MK1));
if (text == MainPlugin.MK3 && text2 != MainPlugin.MK3)
{
text = MainPlugin.MK2;
}
if (text == MainPlugin.MK2 && text2 != MainPlugin.MK2 && text2 != MainPlugin.MK3)
{
text = MainPlugin.MK1;
}
num3 = MainPlugin.ValidSpeedsForAssembler[text];
uiRecipeEntry.timeText.text = "1min\r\n(" + text + ")";
}
else
{
num3 = MainPlugin.ValidSpeedsForAssembler[MainPlugin.DefaultAssemblerSpeed.Value];
uiRecipeEntry.timeText.text = "1min\r\n(" + MainPlugin.DefaultAssemblerSpeed.Value + ")";
}
if (Input.GetKey((KeyCode)306))
{
num3 = MainPlugin.ValidSpeedsForAssembler[MainPlugin.SpeedToShowOnLeftCtrl.Value];
uiRecipeEntry.timeText.text = "1min\r\n(" + MainPlugin.SpeedToShowOnLeftCtrl.Value + ")";
}
if (Input.GetKey((KeyCode)304))
{
num3 = MainPlugin.ValidSpeedsForAssembler[MainPlugin.SpeedToShowOnLeftShift.Value];
uiRecipeEntry.timeText.text = "1min\r\n(" + MainPlugin.SpeedToShowOnLeftShift.Value + ")";
}
if (Input.GetKey((KeyCode)308))
{
num3 = MainPlugin.ValidSpeedsForAssembler[MainPlugin.SpeedToShowOnLeftAlt.Value];
uiRecipeEntry.timeText.text = "1min\r\n(" + MainPlugin.SpeedToShowOnLeftAlt.Value + ")";
}
}
else if ((int)recipeProto.Type == 1)
{
((Graphic)uiRecipeEntry.timeText).rectTransform.sizeDelta = new Vector2(((Graphic)uiRecipeEntry.timeText).rectTransform.sizeDelta.x, ((Graphic)uiRecipeEntry.timeText).rectTransform.sizeDelta.y + 25f);
if (MainPlugin.LimitDefaultSmelterSpeedToLatestUnlocked.Value)
{
string text3 = MainPlugin.DefaultSmelterSpeed.Value;
string text4 = (GameMain.data.history.TechUnlocked(1417) ? MainPlugin.MK2 : MainPlugin.MK1);
if (text3 == MainPlugin.MK2 && text4 != MainPlugin.MK2)
{
text3 = MainPlugin.MK1;
}
num3 = MainPlugin.ValidSpeedsForSmelter[text3];
uiRecipeEntry.timeText.text = "1min\r\n(" + text3 + ")";
}
else
{
num3 = MainPlugin.ValidSpeedsForSmelter[MainPlugin.DefaultSmelterSpeed.Value];
uiRecipeEntry.timeText.text = "1min\r\n(" + MainPlugin.DefaultSmelterSpeed.Value + ")";
}
string text5 = ((MainPlugin.DefaultSmelterSpeed.Value == MainPlugin.MK1) ? MainPlugin.MK2 : MainPlugin.MK1);
if (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)308))
{
num3 = MainPlugin.ValidSpeedsForSmelter[text5];
uiRecipeEntry.timeText.text = "1min\r\n(" + text5 + ")";
}
}
for (; i < recipeProto.Results.Length; i++)
{
if (num >= 7)
{
break;
}
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(recipeProto.Results[i]);
if (val != null)
{
uiRecipeEntry.icons[num].sprite = val.iconSprite;
}
else
{
uiRecipeEntry.icons[num].sprite = null;
}
uiRecipeEntry.countTexts[num].text = ((double)(60f / (float)recipeProto.TimeSpend * 60f * (float)recipeProto.ResultCounts[i]) * num3).ToString();
((Graphic)uiRecipeEntry.icons[num]).rectTransform.anchoredPosition = new Vector2((float)num2, 0f);
((Component)uiRecipeEntry.icons[num]).gameObject.SetActive(true);
num++;
num2 += 40;
}
uiRecipeEntry.arrow.anchoredPosition = new Vector2((float)num2, -27f);
num2 += 40;
for (int j = 0; j < recipeProto.Items.Length; j++)
{
if (num >= 7)
{
break;
}
ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(recipeProto.Items[j]);
if (val2 != null)
{
uiRecipeEntry.icons[num].sprite = val2.iconSprite;
}
else
{
uiRecipeEntry.icons[num].sprite = null;
}
uiRecipeEntry.countTexts[num].text = ((double)(60f / (float)recipeProto.TimeSpend * 60f * (float)recipeProto.ItemCounts[j]) * num3).ToString();
((Graphic)uiRecipeEntry.icons[num]).rectTransform.anchoredPosition = new Vector2((float)num2, 0f);
((Component)uiRecipeEntry.icons[num]).gameObject.SetActive(true);
num++;
num2 += 40;
}
for (int k = num; k < 7; k++)
{
((Component)uiRecipeEntry.icons[k]).gameObject.SetActive(false);
}
}
}
[HarmonyPatch(typeof(UIItemTip))]
[HarmonyPatch("OnDisable")]
internal static class Patch_UIItemTip_OnDisable
{
private static void Postfix(UIItemTip __instance)
{
ref UIRecipeEntry[] reference = ref AccessTools.FieldRefAccess<UIItemTip, UIRecipeEntry[]>(__instance, "recipeEntryArr");
if (reference == null)
{
return;
}
for (int i = 0; i < reference.Length; i++)
{
if ((Object)(object)reference[i] != (Object)null)
{
((Component)reference[i]).gameObject.SetActive(false);
}
}
}
}
[BepInPlugin("com.enriquein.plugins.addamountofrecipeper1min_continued", "AddAmountOfRecipePer1min", "1.3.1")]
[BepInProcess("DSPGAME.exe")]
public class MainPlugin : BaseUnityPlugin
{
public const string ModGuid = "com.enriquein.plugins.addamountofrecipeper1min_continued";
public const string ModName = "AddAmountOfRecipePer1min";
public const string ModVersion = "1.3.1";
public static string MK1 = "mk1";
public static string MK2 = "mk2";
public static string MK3 = "mk3";
public static Dictionary<string, double> ValidSpeedsForAssembler = new Dictionary<string, double>
{
{ MK1, 0.75 },
{ MK2, 1.0 },
{ MK3, 1.5 }
};
public static Dictionary<string, double> ValidSpeedsForSmelter = new Dictionary<string, double>
{
{ MK1, 1.0 },
{ MK2, 2.0 }
};
public static ConfigEntry<bool> LimitDefaultAssemblerSpeedToLatestUnlocked { get; set; }
public static ConfigEntry<string> DefaultAssemblerSpeed { get; set; }
public static ConfigEntry<bool> LimitDefaultSmelterSpeedToLatestUnlocked { get; set; }
public static ConfigEntry<string> DefaultSmelterSpeed { get; set; }
public static ConfigEntry<string> SpeedToShowOnLeftCtrl { get; set; }
public static ConfigEntry<string> SpeedToShowOnLeftShift { get; set; }
public static ConfigEntry<string> SpeedToShowOnLeftAlt { get; set; }
public void Awake()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
LoadConfig();
Harmony val = new Harmony("com.enriquein.plugins.addamountofrecipeper1min_continued.patch");
val.PatchAll(typeof(Patch_UIItemTip_SetTip));
val.PatchAll(typeof(Patch_UIItemTip_OnDisable));
}
private void LoadConfig()
{
DefaultAssemblerSpeed = ((BaseUnityPlugin)this).Config.Bind<string>("Default Speeds", "Default_Assembler_Speed", MK2, "Default speed to use for Assembler recipe tooltips.");
DefaultAssemblerSpeed.Value = GetDefaultIfInvalid(ValidSpeedsForAssembler.Keys, DefaultAssemblerSpeed.Value, MK2);
DefaultSmelterSpeed = ((BaseUnityPlugin)this).Config.Bind<string>("Default Speeds", "Default_Smelter_Speed", MK1, "Default speed to use for Smelter recipe tooltips.");
DefaultSmelterSpeed.Value = GetDefaultIfInvalid(ValidSpeedsForSmelter.Keys, DefaultSmelterSpeed.Value, MK1);
LimitDefaultAssemblerSpeedToLatestUnlocked = ((BaseUnityPlugin)this).Config.Bind<bool>("Default Speeds", "Limit_Default_Assembler_Speed_To_Latest_Unlocked", true, "When `true` it will limit the default speed to the maximum assembler speed unlocked. Useful if you want to display a specific speed, but only if you have unlocked it. If `false` it will always use the default speed regardless of your unlocks.");
LimitDefaultSmelterSpeedToLatestUnlocked = ((BaseUnityPlugin)this).Config.Bind<bool>("Default Speeds", "Limit_Default_Smelter_Speed_To_Latest_Unlocked", true, "When `true` it will limit the default speed to the maximum smelter speed unlocked. Useful if you want to display a specific speed, but only if you have unlocked it. If `false` it will always use the default speed regardless of your unlocks.");
SpeedToShowOnLeftCtrl = ((BaseUnityPlugin)this).Config.Bind<string>("Hover key bindings", "Speed_To_Show_On_Left_Ctrl", MK1, "Speed to show when pressing the left Ctrl key while hovering over an item. Valid values are " + MK1 + ", " + MK2 + ", and " + MK3 + ". Only applies to Assemblers, since Smelters will use the non-default speed on hover.");
SpeedToShowOnLeftCtrl.Value = GetDefaultIfInvalid(ValidSpeedsForAssembler.Keys, SpeedToShowOnLeftCtrl.Value, MK1);
SpeedToShowOnLeftShift = ((BaseUnityPlugin)this).Config.Bind<string>("Hover key bindings", "Speed_To_Show_On_Left_Shift", MK2, "Speed to show when pressing the left Shift key while hovering over an item. Valid values are " + MK1 + ", " + MK2 + ", and " + MK3 + ". Only applies to Assemblers, since Smelters will use the non-default speed on hover.");
SpeedToShowOnLeftShift.Value = GetDefaultIfInvalid(ValidSpeedsForAssembler.Keys, SpeedToShowOnLeftShift.Value, MK2);
SpeedToShowOnLeftAlt = ((BaseUnityPlugin)this).Config.Bind<string>("Hover key bindings", "Speed_To_Show_On_Left_Alt", MK3, "Speed to show when pressing the left Alt key while hovering over an item. Valid values are " + MK1 + ", " + MK2 + ", and " + MK3 + ". Only applies to Assemblers, since Smelters will use the non-default speed on hover.");
SpeedToShowOnLeftAlt.Value = GetDefaultIfInvalid(ValidSpeedsForAssembler.Keys, SpeedToShowOnLeftAlt.Value, MK3);
}
private string GetDefaultIfInvalid(IEnumerable<string> validValues, string value, string defaultValue)
{
if (validValues.Count((string x) => x.ToLowerInvariant() == value.ToLowerInvariant()) <= 0)
{
return defaultValue;
}
return value.ToLowerInvariant();
}
}