using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using ProjectM.UI;
using Stunlock.Core;
using TrackCrafts.Core;
using TrackCrafts.Services;
using TrackCrafts.UI;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
using UnityEngine.EventSystems;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("TrackCrafts")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TrackCrafts")]
[assembly: AssemblyTitle("TrackCrafts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 TrackCrafts
{
[BepInPlugin("com.armanckeser.TrackCrafts", "TrackCrafts", "1.1.1")]
public class Plugin : BasePlugin
{
public static ManualLogSource Log;
public static Plugin Instance;
public static TrackCraftManager Manager;
public static Dictionary<int, string> PrefabNames = new Dictionary<int, string>();
private Harmony _harmony;
public static KeyCode ToggleHudKey = (KeyCode)283;
public static KeyCode ClearAllKey = (KeyCode)282;
public override void Load()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
Instance = this;
Log = ((BasePlugin)this).Log;
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(24, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("TrackCrafts v");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.1.1");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loading...");
}
log.LogInfo(val);
LoadPrefabNames();
Manager = new TrackCraftManager();
_harmony = new Harmony("com.armanckeser.TrackCrafts");
_harmony.PatchAll(typeof(Plugin).Assembly);
Log.LogInfo((object)"Registering IL2CPP types...");
ClassInjector.RegisterTypeInIl2Cpp<TrackCraftHUD>();
ClassInjector.RegisterTypeInIl2Cpp<InputHandler>();
Log.LogInfo((object)"IL2CPP types registered.");
((BasePlugin)this).AddComponent<TrackCraftHUD>();
((BasePlugin)this).AddComponent<InputHandler>();
Log.LogInfo((object)"TrackCrafts loaded successfully.");
}
public override bool Unload()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
return true;
}
private void LoadPrefabNames()
{
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Expected O, but got Unknown
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Expected O, but got Unknown
bool flag = default(bool);
try
{
string path = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location), "TrackCrafts_names.json");
if (!File.Exists(path))
{
Log.LogWarning((object)"TrackCrafts_names.json not found. Item names will use prefab names.");
return;
}
foreach (string item in SplitJsonPairs(File.ReadAllText(path).Trim().TrimStart('{')
.TrimEnd('}')))
{
string[] array = item.Split(new char[1] { ':' }, 2);
if (array.Length == 2)
{
string s = array[0].Trim().Trim('"');
string value = array[1].Trim().Trim('"');
if (int.TryParse(s, out var result))
{
PrefabNames[result] = value;
}
}
}
ManualLogSource log = Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loaded ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(PrefabNames.Count);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" prefab names.");
}
log.LogInfo(val);
}
catch (Exception ex)
{
ManualLogSource log2 = Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(29, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load prefab names: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
log2.LogWarning(val2);
}
}
private static List<string> SplitJsonPairs(string json)
{
List<string> list = new List<string>();
int num = 0;
int num2 = 0;
bool flag = false;
for (int i = 0; i < json.Length; i++)
{
char c = json[i];
if (c == '"' && (i == 0 || json[i - 1] != '\\'))
{
flag = !flag;
}
if (flag)
{
continue;
}
switch (c)
{
case '{':
num++;
break;
case '}':
num--;
break;
case ',':
if (num == 0)
{
list.Add(json.Substring(num2, i - num2));
num2 = i + 1;
}
break;
}
}
if (num2 < json.Length)
{
list.Add(json.Substring(num2));
}
return list;
}
public static bool TryPinRecipeFromEntry(GameObject entryObject)
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
try
{
if ((Object)(object)entryObject == (Object)null || Manager == null)
{
return false;
}
Manager.EnsureInitialized();
if (!TryResolveRecipeGuid(entryObject, out var recipeGuid, out var source))
{
LogInfo("[Mouse3] No recipe guid on clicked UI entry: " + ((Object)entryObject).name);
return false;
}
if (TryBuildRefinementModel(entryObject, recipeGuid, out var model))
{
Manager.AddOrReplace(model);
LogInfo("[Mouse3] Recipe tracked " + recipeGuid._Value + " from " + source + " (refinement-ui)");
return true;
}
if (!IconResolver.IsValidRecipeGuid(recipeGuid))
{
LogWarning("[Mouse3] Invalid recipe guid from " + source + ": " + recipeGuid._Value);
return false;
}
if (Manager.GetRecipe(recipeGuid) == null)
{
Manager.AddRecipe(recipeGuid);
}
ApplyUiIconFallback(entryObject, recipeGuid);
LogInfo("[Mouse3] Recipe tracked " + recipeGuid._Value + " from " + source);
return true;
}
catch (Exception ex)
{
LogError("[Mouse3] Pin from UI entry failed: " + ex.Message);
return false;
}
}
private static bool TryResolveRecipeGuid(GameObject entryObject, out PrefabGUID recipeGuid, out string source)
{
//IL_0001: 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)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
recipeGuid = default(PrefabGUID);
source = "unknown";
WorkstationRecipeGridSelectionEntry componentInParent = entryObject.GetComponentInParent<WorkstationRecipeGridSelectionEntry>();
if ((Object)(object)componentInParent != (Object)null && componentInParent.EntryId._Value != 0)
{
recipeGuid = componentInParent.EntryId;
source = "WorkstationRecipeGridSelectionEntry.EntryId";
return true;
}
RefinementstationRecipeEntry componentInParent2 = entryObject.GetComponentInParent<RefinementstationRecipeEntry>();
if ((Object)(object)componentInParent2 != (Object)null && componentInParent2.EntryId._Value != 0)
{
recipeGuid = componentInParent2.EntryId;
source = "RefinementstationRecipeEntry.EntryId";
return true;
}
RefinementstationRecipeItem componentInParent3 = entryObject.GetComponentInParent<RefinementstationRecipeItem>();
if ((Object)(object)componentInParent3 != (Object)null && componentInParent3.Guid._Value != 0)
{
recipeGuid = componentInParent3.Guid;
source = "RefinementstationRecipeItem.Guid";
return true;
}
return false;
}
private static bool TryBuildRefinementModel(GameObject entryObject, PrefabGUID recipeGuid, out TrackedRecipeModel model)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_0331: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_046b: Unknown result type (might be due to invalid IL or missing references)
//IL_0243: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0280: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
model = null;
try
{
RefinementstationRecipeEntry componentInParent = entryObject.GetComponentInParent<RefinementstationRecipeEntry>();
if ((Object)(object)componentInParent == (Object)null)
{
return false;
}
RefinementstationRecipeItem componentInParent2 = entryObject.GetComponentInParent<RefinementstationRecipeItem>();
PrefabGUID val = default(PrefabGUID);
Sprite val2 = null;
if ((Object)(object)componentInParent2 != (Object)null && componentInParent2.Guid._Value != 0 && (Object)(object)componentInParent.OutputParent != (Object)null && ((Component)componentInParent2).transform.IsChildOf(((Component)componentInParent.OutputParent).transform))
{
val = componentInParent2.Guid;
if ((Object)(object)componentInParent2.Icon != (Object)null)
{
val2 = componentInParent2.Icon.sprite;
}
}
model = new TrackedRecipeModel
{
RecipePrefabGuid = recipeGuid,
Quantity = 1
};
try
{
if ((Object)(object)componentInParent.RecipeName != (Object)null)
{
string text = componentInParent.RecipeName.GetText();
if (!string.IsNullOrWhiteSpace(text))
{
model.RecipeName = text.Trim();
}
}
}
catch
{
}
try
{
if (val._Value != 0)
{
model.RecipeName = IconResolver.GetCleanItemName(val);
if ((Object)(object)val2 != (Object)null)
{
model.RecipeIcon = IconResolver.SpriteToTexture2D(val2);
}
}
if ((Object)(object)componentInParent.OutputParent != (Object)null)
{
Il2CppArrayBase<RefinementstationRecipeItem> componentsInChildren = ((Component)componentInParent.OutputParent).GetComponentsInChildren<RefinementstationRecipeItem>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
RefinementstationRecipeItem val3 = componentsInChildren[i];
if ((Object)(object)val3 == (Object)null || val3.Guid._Value == 0)
{
continue;
}
bool flag = val._Value != 0 && val3.Guid._Value == val._Value;
if (flag || string.IsNullOrWhiteSpace(model.RecipeName) || model.RecipeName == "Unknown Recipe")
{
model.RecipeName = IconResolver.GetCleanItemName(val3.Guid);
if ((Object)(object)val3.Icon != (Object)null && (Object)(object)val3.Icon.sprite != (Object)null)
{
model.RecipeIcon = IconResolver.SpriteToTexture2D(val3.Icon.sprite);
}
if (flag)
{
break;
}
}
}
}
}
catch
{
}
if ((Object)(object)componentInParent.InputParent != (Object)null)
{
Il2CppArrayBase<RefinementstationRecipeItem> componentsInChildren2 = ((Component)componentInParent.InputParent).GetComponentsInChildren<RefinementstationRecipeItem>(true);
for (int j = 0; j < componentsInChildren2.Length; j++)
{
RefinementstationRecipeItem val4 = componentsInChildren2[j];
if ((Object)(object)val4 == (Object)null || val4.Guid._Value == 0)
{
continue;
}
int num = ParseCountFromRefinementItem(val4);
Texture2D icon = (((Object)(object)val4.Icon != (Object)null && (Object)(object)val4.Icon.sprite != (Object)null) ? IconResolver.SpriteToTexture2D(val4.Icon.sprite) : IconResolver.GetItemIconViaGameData(val4.Guid));
IngredientModel ingredientModel = FindIngredient(model, val4.Guid);
if (ingredientModel != null)
{
ingredientModel.AmountPerCraft += num;
if ((Object)(object)ingredientModel.Icon == (Object)null)
{
ingredientModel.Icon = icon;
}
}
else
{
model.Ingredients.Add(new IngredientModel
{
ItemPrefabGuid = val4.Guid,
ItemName = IconResolver.GetCleanItemName(val4.Guid),
Icon = icon,
AmountPerCraft = num
});
}
}
}
TrackedRecipeModel trackedRecipeModel = RecipeLookup.BuildTrackedRecipe(recipeGuid);
if (trackedRecipeModel != null)
{
if ((string.IsNullOrWhiteSpace(model.RecipeName) || model.RecipeName == "Unknown Recipe") && !string.IsNullOrWhiteSpace(trackedRecipeModel.RecipeName))
{
model.RecipeName = trackedRecipeModel.RecipeName;
}
if ((Object)(object)model.RecipeIcon == (Object)null)
{
model.RecipeIcon = trackedRecipeModel.RecipeIcon;
}
for (int k = 0; k < model.Ingredients.Count; k++)
{
IngredientModel ingredientModel2 = model.Ingredients[k];
for (int l = 0; l < trackedRecipeModel.Ingredients.Count; l++)
{
IngredientModel ingredientModel3 = trackedRecipeModel.Ingredients[l];
if (ingredientModel2.ItemPrefabGuid._Value == ingredientModel3.ItemPrefabGuid._Value)
{
if (ingredientModel2.AmountPerCraft < ingredientModel3.AmountPerCraft)
{
model.HasFloorBonus = true;
}
if ((Object)(object)ingredientModel2.Icon == (Object)null)
{
ingredientModel2.Icon = ingredientModel3.Icon;
}
break;
}
}
}
}
if (string.IsNullOrWhiteSpace(model.RecipeName) || model.RecipeName == "Unknown Recipe")
{
model.RecipeName = IconResolver.GetCleanItemName(recipeGuid);
}
if (model.Ingredients.Count == 0)
{
return false;
}
model.Recalculate(InventoryQuery.GetPlayerItemCounts());
return true;
}
catch (Exception ex)
{
LogWarning("[Mouse3] Refinement model build failed: " + ex.Message);
model = null;
return false;
}
}
private static IngredientModel FindIngredient(TrackedRecipeModel model, PrefabGUID guid)
{
//IL_0015: 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)
if (model == null)
{
return null;
}
for (int i = 0; i < model.Ingredients.Count; i++)
{
if (model.Ingredients[i].ItemPrefabGuid._Value == guid._Value)
{
return model.Ingredients[i];
}
}
return null;
}
private static int ParseCountFromRefinementItem(RefinementstationRecipeItem item)
{
try
{
if ((Object)(object)item != (Object)null && (Object)(object)item.Count != (Object)null)
{
string text = item.Count.GetText();
if (!string.IsNullOrEmpty(text))
{
StringBuilder stringBuilder = new StringBuilder(text.Length);
foreach (char c in text)
{
if (c >= '0' && c <= '9')
{
stringBuilder.Append(c);
}
}
if (stringBuilder.Length > 0 && int.TryParse(stringBuilder.ToString(), out var result) && result > 0)
{
return result;
}
}
}
}
catch
{
}
return 1;
}
private static void ApplyUiIconFallback(GameObject entryObject, PrefabGUID recipeGuid)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
try
{
if (Manager == null)
{
return;
}
TrackedRecipeModel recipe = Manager.GetRecipe(recipeGuid);
if (recipe == null)
{
return;
}
if ((Object)(object)recipe.RecipeIcon == (Object)null)
{
Sprite val = null;
WorkstationRecipeGridSelectionEntry componentInParent = entryObject.GetComponentInParent<WorkstationRecipeGridSelectionEntry>();
if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.ItemIcon != (Object)null)
{
val = componentInParent.ItemIcon.sprite;
}
if ((Object)(object)val == (Object)null)
{
RefinementstationRecipeItem componentInParent2 = entryObject.GetComponentInParent<RefinementstationRecipeItem>();
if ((Object)(object)componentInParent2 != (Object)null && (Object)(object)componentInParent2.Icon != (Object)null)
{
val = componentInParent2.Icon.sprite;
}
}
if ((Object)(object)val != (Object)null)
{
recipe.RecipeIcon = IconResolver.SpriteToTexture2D(val);
}
}
WorkstationRecipeGridSelectionEntry componentInParent3 = entryObject.GetComponentInParent<WorkstationRecipeGridSelectionEntry>();
if ((Object)(object)componentInParent3 != (Object)null)
{
TryApplyWorkstationRequirementIcons(componentInParent3, recipe);
}
TryApplyVisibleRequirementIcons(entryObject, recipe);
RefinementstationRecipeEntry componentInParent4 = entryObject.GetComponentInParent<RefinementstationRecipeEntry>();
if (!((Object)(object)componentInParent4 != (Object)null) || !((Object)(object)componentInParent4.InputParent != (Object)null))
{
return;
}
Il2CppArrayBase<RefinementstationRecipeItem> componentsInChildren = ((Component)componentInParent4.InputParent).GetComponentsInChildren<RefinementstationRecipeItem>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
RefinementstationRecipeItem val2 = componentsInChildren[i];
if ((Object)(object)val2 == (Object)null || val2.Guid._Value == 0 || (Object)(object)val2.Icon == (Object)null || (Object)(object)val2.Icon.sprite == (Object)null)
{
continue;
}
Texture2D val3 = IconResolver.SpriteToTexture2D(val2.Icon.sprite);
if ((Object)(object)val3 == (Object)null)
{
continue;
}
for (int j = 0; j < recipe.Ingredients.Count; j++)
{
if (recipe.Ingredients[j].ItemPrefabGuid._Value == val2.Guid._Value && (Object)(object)recipe.Ingredients[j].Icon == (Object)null)
{
recipe.Ingredients[j].Icon = val3;
break;
}
}
}
}
catch
{
}
}
private static void TryApplyWorkstationRequirementIcons(WorkstationRecipeGridSelectionEntry wsEntry, TrackedRecipeModel tracked)
{
try
{
if ((Object)(object)wsEntry == (Object)null || tracked == null || tracked.Ingredients.Count == 0 || wsEntry.Requirements == null)
{
return;
}
bool[] array = new bool[tracked.Ingredients.Count];
bool flag = false;
bool flag2 = false;
int count = wsEntry.Requirements.Count;
for (int i = 0; i < count; i++)
{
CostData val = wsEntry.Requirements[i];
if ((Object)(object)val.ItemSprite == (Object)null)
{
continue;
}
Texture2D val2 = IconResolver.SpriteToTexture2D(val.ItemSprite);
if ((Object)(object)val2 == (Object)null)
{
continue;
}
int num = -1;
for (int j = 0; j < tracked.Ingredients.Count; j++)
{
if (!array[j] && tracked.Ingredients[j].AmountPerCraft == val.Amount)
{
num = j;
break;
}
}
if (num < 0 && i < tracked.Ingredients.Count && !array[i])
{
num = i;
}
if (num < 0)
{
for (int k = 0; k < tracked.Ingredients.Count; k++)
{
if (!array[k] && (Object)(object)tracked.Ingredients[k].Icon == (Object)null)
{
num = k;
break;
}
}
}
if (num < 0)
{
continue;
}
IngredientModel ingredientModel = tracked.Ingredients[num];
ingredientModel.Icon = val2;
if (val.Amount > 0 && ingredientModel.AmountPerCraft > 0)
{
if (val.Amount < ingredientModel.AmountPerCraft)
{
flag2 = true;
}
if (val.Amount <= ingredientModel.AmountPerCraft && val.Amount != ingredientModel.AmountPerCraft)
{
ingredientModel.AmountPerCraft = val.Amount;
flag = true;
}
}
array[num] = true;
}
bool flag3 = tracked.HasFloorBonus != flag2;
tracked.HasFloorBonus = flag2;
if (flag || flag3)
{
tracked.Recalculate(InventoryQuery.GetPlayerItemCounts());
}
LogInfo("[Mouse3] Workstation UI costs applied: recipe=" + tracked.RecipeName + ", floorBonus=" + tracked.HasFloorBonus + ", amountsChanged=" + flag + ", requirements=" + count);
}
catch
{
}
}
private static void TryApplyVisibleRequirementIcons(GameObject entryObject, TrackedRecipeModel tracked)
{
try
{
if ((Object)(object)entryObject == (Object)null || tracked == null || tracked.Ingredients.Count == 0)
{
return;
}
Transform root = entryObject.transform.root;
if ((Object)(object)root == (Object)null)
{
return;
}
List<(string, Texture2D)> list = new List<(string, Texture2D)>();
Il2CppArrayBase<RequirementEntry> componentsInChildren = ((Component)root).GetComponentsInChildren<RequirementEntry>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
RequirementEntry val = componentsInChildren[i];
if ((Object)(object)val == (Object)null || (Object)(object)val.Icon == (Object)null || (Object)(object)val.Icon.sprite == (Object)null)
{
continue;
}
Texture2D val2 = IconResolver.SpriteToTexture2D(val.Icon.sprite);
if ((Object)(object)val2 == (Object)null)
{
continue;
}
string item = "";
try
{
if ((Object)(object)val.Name != (Object)null)
{
item = val.Name.GetText();
}
}
catch
{
}
list.Add((item, val2));
}
Il2CppArrayBase<WorkstationRequirementEntry> componentsInChildren2 = ((Component)root).GetComponentsInChildren<WorkstationRequirementEntry>(true);
for (int j = 0; j < componentsInChildren2.Length; j++)
{
WorkstationRequirementEntry val3 = componentsInChildren2[j];
if ((Object)(object)val3 == (Object)null || (Object)(object)val3.Icon == (Object)null || (Object)(object)val3.Icon.sprite == (Object)null)
{
continue;
}
Texture2D val4 = IconResolver.SpriteToTexture2D(val3.Icon.sprite);
if ((Object)(object)val4 == (Object)null)
{
continue;
}
string item2 = "";
try
{
if ((Object)(object)val3.Name != (Object)null)
{
item2 = val3.Name.GetText();
}
}
catch
{
}
list.Add((item2, val4));
}
Il2CppArrayBase<RecipeRequirementEntry> componentsInChildren3 = ((Component)root).GetComponentsInChildren<RecipeRequirementEntry>(true);
for (int k = 0; k < componentsInChildren3.Length; k++)
{
RecipeRequirementEntry val5 = componentsInChildren3[k];
if ((Object)(object)val5 == (Object)null || (Object)(object)val5.ItemIcon == (Object)null || (Object)(object)val5.ItemIcon.sprite == (Object)null)
{
continue;
}
Texture2D val6 = IconResolver.SpriteToTexture2D(val5.ItemIcon.sprite);
if ((Object)(object)val6 == (Object)null)
{
continue;
}
string item3 = "";
try
{
if ((Object)(object)val5.ItemNameText != (Object)null)
{
item3 = val5.ItemNameText.GetText();
}
}
catch
{
}
list.Add((item3, val6));
}
if (list.Count == 0)
{
return;
}
bool[] array = new bool[list.Count];
for (int l = 0; l < tracked.Ingredients.Count; l++)
{
if ((Object)(object)tracked.Ingredients[l].Icon != (Object)null)
{
continue;
}
string text = NormalizeItemName(tracked.Ingredients[l].ItemName);
if (string.IsNullOrEmpty(text))
{
continue;
}
for (int m = 0; m < list.Count; m++)
{
if (!array[m])
{
string text2 = NormalizeItemName(list[m].Item1);
if (!string.IsNullOrEmpty(text2) && (text == text2 || text.Contains(text2) || text2.Contains(text)))
{
tracked.Ingredients[l].Icon = list[m].Item2;
array[m] = true;
break;
}
}
}
}
}
catch
{
}
}
private static string NormalizeItemName(string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return string.Empty;
}
StringBuilder stringBuilder = new StringBuilder(value.Length);
foreach (char c in value)
{
if (char.IsLetterOrDigit(c))
{
stringBuilder.Append(char.ToLowerInvariant(c));
}
}
return stringBuilder.ToString();
}
public static void LogInfo(string msg)
{
ManualLogSource log = Log;
if (log != null)
{
log.LogInfo((object)msg);
}
}
public static void LogWarning(string msg)
{
ManualLogSource log = Log;
if (log != null)
{
log.LogWarning((object)msg);
}
}
public static void LogError(string msg)
{
ManualLogSource log = Log;
if (log != null)
{
log.LogError((object)msg);
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.armanckeser.TrackCrafts";
public const string PLUGIN_NAME = "TrackCrafts";
public const string PLUGIN_VERSION = "1.1.1";
}
public class InputHandler : MonoBehaviour
{
public static bool HudVisible = true;
public InputHandler(IntPtr ptr)
: base(ptr)
{
}
public void Update()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(Plugin.ToggleHudKey))
{
HudVisible = !HudVisible;
}
if (Input.GetKeyDown(Plugin.ClearAllKey))
{
Plugin.Manager?.ClearAll();
}
}
}
}
namespace TrackCrafts.UI
{
public class TrackCraftHUD : MonoBehaviour
{
private bool _collapsed;
private int _editingQuantityIndex = -1;
private string _quantityInput = "";
private float _refreshTimer;
private const float RefreshInterval = 2f;
private float _panelAlpha = 1f;
private float _posX = 15f;
private float _posY = 36f;
private bool IsVisible => InputHandler.HudVisible;
public TrackCraftHUD(IntPtr ptr)
: base(ptr)
{
}
public void Update()
{
TrackCraftManager manager = Plugin.Manager;
if (manager == null)
{
return;
}
_refreshTimer += Time.deltaTime;
if (!(_refreshTimer >= 2f))
{
return;
}
_refreshTimer = 0f;
try
{
manager.RefreshCounts();
}
catch (Exception ex)
{
Plugin.LogWarning("[HUD] RefreshCounts error: " + ex.Message);
}
}
public void OnGUI()
{
//IL_0088: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Expected O, but got Unknown
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
TrackCraftManager manager = Plugin.Manager;
if (!IsVisible || manager == null || manager.TrackedRecipes.Count == 0)
{
return;
}
bool flag = false;
try
{
VanillaStyle.ResetStyles();
float num = Mathf.Min(600f, (float)Screen.height - _posY - 8f);
if (num < 36f)
{
num = 36f;
}
int visibleRecipeCount = 0;
float num2 = (_collapsed ? 32f : CalculateVisiblePanelHeight(num, out visibleRecipeCount));
Rect val = default(Rect);
((Rect)(ref val))..ctor(_posX, _posY, 380f, num2);
Color color = GUI.color;
GUI.color = new Color(1f, 1f, 1f, _panelAlpha);
VanillaStyle.DrawPanel(val);
GUI.color = color;
GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 1f, ((Rect)(ref val)).y + 1f, ((Rect)(ref val)).width - 2f, ((Rect)(ref val)).height - 2f));
flag = true;
DrawTitleBar();
if (!_collapsed)
{
for (int i = 0; i < visibleRecipeCount; i++)
{
DrawRecipeEntry(i);
if (i < visibleRecipeCount - 1)
{
VanillaStyle.DrawSeparator(GUILayoutUtility.GetRect(360f, 1f));
}
}
int num3 = manager.TrackedRecipes.Count - visibleRecipeCount;
if (num3 > 0)
{
GUILayout.Space(2f);
GUIStyle val2 = new GUIStyle();
val2.fontSize = 11;
val2.normal.textColor = VanillaStyle.TextSecondary;
val2.alignment = (TextAnchor)4;
GUILayout.Label($"+{num3} hidden (screen limit)", val2, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(18f) });
}
}
HandleClickAway(val);
}
catch (Exception value)
{
Plugin.LogError($"[HUD] OnGUI error: {value}");
}
finally
{
if (flag)
{
try
{
GUILayout.EndArea();
}
catch
{
}
}
}
}
private void DrawTitleBar()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: 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_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Expected O, but got Unknown
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
Rect rect = GUILayoutUtility.GetRect(0f, 30f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
bool flag = ((Rect)(ref rect)).Contains(Event.current.mousePosition);
Texture2D val = (flag ? VanillaStyle.TitleHoverTex : (_collapsed ? VanillaStyle.TitleCollapsedTex : VanillaStyle.TitleExpandedTex));
GUI.DrawTexture(rect, (Texture)(object)val);
GUI.Label(new Rect(((Rect)(ref rect)).x + 8f, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width - 140f, ((Rect)(ref rect)).height), "Track Crafts", VanillaStyle.TitleStyle);
Rect val2 = new Rect(((Rect)(ref rect)).xMax - 112f, ((Rect)(ref rect)).y + 5f, 28f, ((Rect)(ref rect)).height - 10f);
Rect val3 = default(Rect);
((Rect)(ref val3))..ctor(((Rect)(ref rect)).xMax - 82f, ((Rect)(ref rect)).y + 5f, 28f, ((Rect)(ref rect)).height - 10f);
if (GUI.Button(val2, "A-", VanillaStyle.PresetBtnStyle))
{
_panelAlpha = Mathf.Clamp(_panelAlpha - 0.1f, 0.35f, 1f);
}
if (GUI.Button(val3, "A+", VanillaStyle.PresetBtnStyle))
{
_panelAlpha = Mathf.Clamp(_panelAlpha + 0.1f, 0.35f, 1f);
}
GUIStyle val4 = new GUIStyle();
val4.fontSize = 12;
val4.fontStyle = (FontStyle)1;
val4.normal.textColor = VanillaStyle.TextPrimary;
val4.alignment = (TextAnchor)5;
GUI.Label(new Rect(((Rect)(ref rect)).x + 8f, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width - 12f, ((Rect)(ref rect)).height), _collapsed ? "[+]" : "[-]", val4);
if ((int)Event.current.type == 0 && Event.current.button == 0 && flag)
{
_collapsed = !_collapsed;
Event.current.Use();
}
}
private void DrawRecipeEntry(int index)
{
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Expected O, but got Unknown
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
TrackCraftManager manager = Plugin.Manager;
if (index < 0 || index >= manager.TrackedRecipes.Count)
{
return;
}
TrackedRecipeModel trackedRecipeModel = manager.TrackedRecipes[index];
GUILayout.Space(4f);
GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
try
{
if ((Object)(object)trackedRecipeModel.RecipeIcon != (Object)null)
{
GUILayout.Label((Texture)(object)trackedRecipeModel.RecipeIcon, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(32f),
GUILayout.Height(32f)
});
}
else
{
GUILayout.Space(36f);
}
GUILayout.Label(trackedRecipeModel.RecipeName, VanillaStyle.TitleStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) });
GUILayout.FlexibleSpace();
if (trackedRecipeModel.HasFloorBonus)
{
GUIStyle val = new GUIStyle();
val.fontSize = 11;
val.fontStyle = (FontStyle)1;
val.normal.textColor = VanillaStyle.TextGreen;
val.alignment = (TextAnchor)2;
GUILayout.Label("-25%", val, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(48f),
GUILayout.Height(18f)
});
}
}
finally
{
GUILayout.EndHorizontal();
}
DrawQuantityRow(index);
GUILayout.Space(4f);
VanillaStyle.DrawSeparator(GUILayoutUtility.GetRect(360f, 1f));
GUILayout.Space(2f);
int quantity = trackedRecipeModel.Quantity;
for (int i = 0; i < trackedRecipeModel.Ingredients.Count; i++)
{
DrawIngredientRow(index, i, quantity);
}
GUILayout.Space(0f);
DrawBottomRemoveButton(index);
}
private bool DrawBottomRemoveButton(int index)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: 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_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
Rect rect = GUILayoutUtility.GetRect(364f, 24f);
bool flag = ((Rect)(ref rect)).Contains(Event.current.mousePosition);
GUI.DrawTexture(rect, (Texture)(object)(flag ? VanillaStyle.DangerHoverTex : VanillaStyle.DangerTex));
GUI.Label(rect, "Remove This Craft", VanillaStyle.DangerLabelStyle);
if ((int)Event.current.type == 0 && Event.current.button == 0 && flag)
{
Plugin.Manager?.RemoveRecipe(index);
Event.current.Use();
return true;
}
return false;
}
private void DrawQuantityRow(int index)
{
//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_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
//IL_0252: Unknown result type (might be due to invalid IL or missing references)
//IL_0261: Unknown result type (might be due to invalid IL or missing references)
//IL_0318: Unknown result type (might be due to invalid IL or missing references)
//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
//IL_034a: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
//IL_037d: Unknown result type (might be due to invalid IL or missing references)
//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
TrackCraftManager manager = Plugin.Manager;
if (index < 0 || index >= manager.TrackedRecipes.Count)
{
return;
}
TrackedRecipeModel trackedRecipeModel = manager.TrackedRecipes[index];
Rect rect = GUILayoutUtility.GetRect(364f, 24f);
float y = ((Rect)(ref rect)).y;
float num = 22f;
float num2 = 64f;
float num3 = 22f;
float num4 = 34f;
float num5 = 2f;
float num6 = ((Rect)(ref rect)).x + ((Rect)(ref rect)).width * 0.5f;
Rect val = default(Rect);
((Rect)(ref val))..ctor(num6 - num2 * 0.5f, y, num2, num);
Rect val2 = default(Rect);
((Rect)(ref val2))..ctor(((Rect)(ref val)).x - num5 - num3, y, num3, num);
Rect val3 = default(Rect);
((Rect)(ref val3))..ctor(((Rect)(ref val)).xMax + num5, y, num3, num);
Rect val4 = default(Rect);
((Rect)(ref val4))..ctor(((Rect)(ref val2)).x - num5 - num4, y, num4, num);
Rect val5 = default(Rect);
((Rect)(ref val5))..ctor(((Rect)(ref val4)).x - num5 - num4, y, num4, num);
Rect val6 = new Rect(((Rect)(ref val5)).x - num5 - num4, y, num4, num);
Rect val7 = default(Rect);
((Rect)(ref val7))..ctor(((Rect)(ref val3)).xMax + num5, y, num4, num);
Rect val8 = default(Rect);
((Rect)(ref val8))..ctor(((Rect)(ref val7)).xMax + num5, y, num4, num);
Rect val9 = default(Rect);
((Rect)(ref val9))..ctor(((Rect)(ref val8)).xMax + num5, y, num4, num);
if (GUI.Button(val6, "-100", VanillaStyle.PresetBtnStyle))
{
int quantity = Mathf.Max(1, trackedRecipeModel.Quantity - 100);
manager.SetQuantity(index, quantity);
CancelEdit();
}
if (GUI.Button(val5, "-50", VanillaStyle.PresetBtnStyle))
{
int quantity2 = Mathf.Max(1, trackedRecipeModel.Quantity - 50);
manager.SetQuantity(index, quantity2);
CancelEdit();
}
if (GUI.Button(val4, "-10", VanillaStyle.PresetBtnStyle))
{
int quantity3 = Mathf.Max(1, trackedRecipeModel.Quantity - 10);
manager.SetQuantity(index, quantity3);
CancelEdit();
}
if (GUI.Button(val2, "-", VanillaStyle.ButtonStyle))
{
int quantity4 = Mathf.Max(1, trackedRecipeModel.Quantity - 1);
manager.SetQuantity(index, quantity4);
CancelEdit();
}
if (_editingQuantityIndex == index)
{
GUI.DrawTexture(new Rect(((Rect)(ref val)).x - 1f, ((Rect)(ref val)).y - 1f, ((Rect)(ref val)).width + 2f, ((Rect)(ref val)).height + 2f), (Texture)(object)VanillaStyle.GoldBorderTex);
GUI.DrawTexture(val, (Texture)(object)VanillaStyle.FieldTex);
string text = (string.IsNullOrEmpty(_quantityInput) ? "_" : (_quantityInput + "_"));
GUI.Label(val, text, VanillaStyle.QuantityLabelStyle);
HandleQuantityKeyboardInput(index, val);
}
else
{
GUI.DrawTexture(val, (Texture)(object)VanillaStyle.FieldTex);
GUI.Label(val, trackedRecipeModel.Quantity.ToString(), VanillaStyle.QuantityLabelStyle);
if ((int)Event.current.type == 0 && ((Rect)(ref val)).Contains(Event.current.mousePosition))
{
_editingQuantityIndex = index;
_quantityInput = trackedRecipeModel.Quantity.ToString();
Event.current.Use();
}
}
if (GUI.Button(val3, "+", VanillaStyle.ButtonStyle))
{
int quantity5 = Mathf.Max(1, trackedRecipeModel.Quantity + 1);
manager.SetQuantity(index, quantity5);
CancelEdit();
}
if (GUI.Button(val7, "+10", VanillaStyle.PresetBtnStyle))
{
int quantity6 = Mathf.Max(1, trackedRecipeModel.Quantity + 10);
manager.SetQuantity(index, quantity6);
CancelEdit();
}
if (GUI.Button(val8, "+50", VanillaStyle.PresetBtnStyle))
{
int quantity7 = Mathf.Max(1, trackedRecipeModel.Quantity + 50);
manager.SetQuantity(index, quantity7);
CancelEdit();
}
if (GUI.Button(val9, "+100", VanillaStyle.PresetBtnStyle))
{
int quantity8 = Mathf.Max(1, trackedRecipeModel.Quantity + 100);
manager.SetQuantity(index, quantity8);
CancelEdit();
}
}
private void DrawIngredientRow(int recipeIndex, int ingredientIndex, int quantity)
{
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Expected O, but got Unknown
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
TrackCraftManager manager = Plugin.Manager;
if (recipeIndex < 0 || recipeIndex >= manager.TrackedRecipes.Count)
{
return;
}
TrackedRecipeModel trackedRecipeModel = manager.TrackedRecipes[recipeIndex];
if (ingredientIndex < 0 || ingredientIndex >= trackedRecipeModel.Ingredients.Count)
{
return;
}
IngredientModel ingredientModel = trackedRecipeModel.Ingredients[ingredientIndex];
GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
try
{
GUILayout.Space(8f);
if ((Object)(object)ingredientModel.Icon != (Object)null)
{
GUILayout.Label((Texture)(object)ingredientModel.Icon, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(24f),
GUILayout.Height(24f)
});
}
else
{
GUI.DrawTexture(GUILayoutUtility.GetRect(24f, 24f), (Texture)(object)VanillaStyle.FieldTex);
}
GUILayout.Space(6f);
GUILayout.Label(ingredientModel.ItemName, VanillaStyle.LabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(150f),
GUILayout.Height(28f)
});
GUILayout.FlexibleSpace();
int num = ingredientModel.AmountPerCraft * quantity;
int have = ingredientModel.Have;
bool flag = have >= num;
GUIStyle val = new GUIStyle();
val.fontSize = 12;
val.normal.textColor = (flag ? VanillaStyle.TextGreen : VanillaStyle.TextRed);
val.alignment = (TextAnchor)5;
val.fontStyle = (FontStyle)1;
GUILayout.Label($"{have} / {num}", val, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(90f),
GUILayout.Height(28f)
});
GUILayout.Space(8f);
}
finally
{
GUILayout.EndHorizontal();
}
}
private void HandleQuantityKeyboardInput(int index, Rect fieldRect)
{
//IL_000b: 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_0030: Invalid comparison between Unknown and I4
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Invalid comparison between Unknown and I4
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Invalid comparison between Unknown and I4
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Invalid comparison between Unknown and I4
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Invalid comparison between Unknown and I4
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Invalid comparison between Unknown and I4
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Invalid comparison between Unknown and I4
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Invalid comparison between Unknown and I4
Event current = Event.current;
if (current == null)
{
return;
}
if ((int)current.type == 0 && !((Rect)(ref fieldRect)).Contains(current.mousePosition))
{
ConfirmEdit(index);
}
else if (((int)current.type == 4 || (int)current.type == 5) && ((int)current.keyCode == 13 || (int)current.keyCode == 271))
{
current.Use();
}
else
{
if ((int)current.type != 4)
{
return;
}
if ((int)current.keyCode == 27)
{
CancelEdit();
current.Use();
return;
}
if ((int)current.keyCode == 8)
{
if (!string.IsNullOrEmpty(_quantityInput))
{
_quantityInput = _quantityInput.Substring(0, _quantityInput.Length - 1);
}
current.Use();
return;
}
if ((int)current.keyCode == 127)
{
_quantityInput = "";
current.Use();
return;
}
char character = current.character;
if (character < '0' || character > '9')
{
return;
}
if (_quantityInput.Length < 9)
{
_quantityInput += character;
_quantityInput = _quantityInput.TrimStart('0');
if (_quantityInput.Length == 0)
{
_quantityInput = "0";
}
}
current.Use();
}
}
private void ConfirmEdit(int index)
{
if (int.TryParse(_quantityInput, out var result) && result > 0)
{
Plugin.Manager?.SetQuantity(index, result);
}
CancelEdit();
}
private void CancelEdit()
{
_editingQuantityIndex = -1;
_quantityInput = "";
}
private void HandleClickAway(Rect panelRect)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
if (_editingQuantityIndex >= 0 && (int)Event.current.type == 0 && !((Rect)(ref panelRect)).Contains(Event.current.mousePosition))
{
ConfirmEdit(_editingQuantityIndex);
}
}
private float CalculateVisiblePanelHeight(float maxHeight, out int visibleRecipeCount)
{
TrackCraftManager manager = Plugin.Manager;
visibleRecipeCount = 0;
if (manager == null)
{
return 0f;
}
float num = 32f;
float num2 = num;
for (int i = 0; i < manager.TrackedRecipes.Count; i++)
{
float num3 = GetRecipeVisualHeight(manager.TrackedRecipes[i]);
if (i < manager.TrackedRecipes.Count - 1)
{
num3 += 5f;
}
if (num2 + num3 > maxHeight)
{
break;
}
num2 += num3;
visibleRecipeCount++;
}
if (visibleRecipeCount == 0 && manager.TrackedRecipes.Count > 0)
{
num2 = Mathf.Min(maxHeight, num + GetRecipeVisualHeight(manager.TrackedRecipes[0]));
visibleRecipeCount = 1;
}
return Mathf.Min(maxHeight, num2);
}
private static float GetRecipeVisualHeight(TrackedRecipeModel recipe)
{
return 4f + 32f + 24f + 7f + (float)recipe.Ingredients.Count * 28f + 24f;
}
}
public static class VanillaStyle
{
public static readonly Color PanelBg = new Color(0.06f, 0.06f, 0.08f, 0.88f);
public static readonly Color PanelBorder = new Color(0.16f, 0.16f, 0.2f, 1f);
public static readonly Color TitleBarBg = new Color(0.1f, 0.1f, 0.14f, 0.94f);
public static readonly Color TitleExpandedBg = new Color(0.1f, 0.1f, 0.16f, 0.96f);
public static readonly Color TitleCollapsedBg = new Color(0.08f, 0.12f, 0.24f, 0.96f);
public static readonly Color TitleHoverBlue = new Color(0.14f, 0.24f, 0.46f, 0.98f);
public static readonly Color TextPrimary = new Color(0.89f, 0.91f, 0.94f, 1f);
public static readonly Color TextSecondary = new Color(0.63f, 0.63f, 0.7f, 1f);
public static readonly Color TextGreen = new Color(0.29f, 0.87f, 0.5f, 1f);
public static readonly Color TextRed = new Color(0.97f, 0.45f, 0.44f, 1f);
public static readonly Color TextGold = new Color(0.83f, 0.65f, 0.2f, 1f);
public static readonly Color ButtonBg = new Color(0.14f, 0.14f, 0.18f, 1f);
public static readonly Color ButtonHover = new Color(0.22f, 0.22f, 0.28f, 1f);
public static readonly Color ButtonActive = new Color(0.3f, 0.3f, 0.38f, 1f);
public static readonly Color FieldBg = new Color(0.08f, 0.08f, 0.12f, 1f);
public static readonly Color FieldEditBorder = new Color(0.83f, 0.65f, 0.2f, 1f);
public static readonly Color SeparatorColor = new Color(0.2f, 0.2f, 0.25f, 0.8f);
public static readonly Color CloseRed = new Color(0.65f, 0.22f, 0.22f, 1f);
public static readonly Color DangerBg = new Color(0.3f, 0.09f, 0.11f, 0.95f);
public static readonly Color DangerHover = new Color(0.74f, 0.14f, 0.18f, 0.98f);
public const float PanelWidth = 380f;
public const float PanelPadding = 10f;
public const float RecipeIconSize = 32f;
public const float ItemIconSize = 24f;
public const float RowHeight = 28f;
public const float ButtonHeight = 22f;
public const float QuantityFieldWidth = 64f;
public const float PresetButtonWidth = 36f;
public const float CloseButtonSize = 20f;
public const float BorderWidth = 1f;
public const float MaxPanelHeight = 600f;
private static Texture2D _panelTex;
private static Texture2D _borderTex;
private static Texture2D _titleTex;
private static Texture2D _buttonTex;
private static Texture2D _buttonHoverTex;
private static Texture2D _buttonActiveTex;
private static Texture2D _fieldTex;
private static Texture2D _separatorTex;
private static Texture2D _goldBorderTex;
private static Texture2D _closeRedTex;
private static Texture2D _titleExpandedTex;
private static Texture2D _titleCollapsedTex;
private static Texture2D _titleHoverTex;
private static Texture2D _dangerTex;
private static Texture2D _dangerHoverTex;
private static GUIStyle _titleStyle;
private static GUIStyle _labelStyle;
private static GUIStyle _buttonStyle;
private static GUIStyle _presetBtnStyle;
private static GUIStyle _quantityFieldStyle;
private static GUIStyle _quantityLabelStyle;
private static GUIStyle _dangerLabelStyle;
public static Texture2D PanelTex => _panelTex ?? (_panelTex = MakeTex(PanelBg));
public static Texture2D BorderTex => _borderTex ?? (_borderTex = MakeTex(PanelBorder));
public static Texture2D TitleTex => _titleTex ?? (_titleTex = MakeTex(TitleBarBg));
public static Texture2D ButtonTex => _buttonTex ?? (_buttonTex = MakeTex(ButtonBg));
public static Texture2D ButtonHoverTex => _buttonHoverTex ?? (_buttonHoverTex = MakeTex(ButtonHover));
public static Texture2D ButtonActiveTex => _buttonActiveTex ?? (_buttonActiveTex = MakeTex(ButtonActive));
public static Texture2D FieldTex => _fieldTex ?? (_fieldTex = MakeTex(FieldBg));
public static Texture2D SeparatorTex => _separatorTex ?? (_separatorTex = MakeTex(SeparatorColor));
public static Texture2D GoldBorderTex => _goldBorderTex ?? (_goldBorderTex = MakeTex(FieldEditBorder));
public static Texture2D CloseRedTex => _closeRedTex ?? (_closeRedTex = MakeTex(CloseRed));
public static Texture2D TitleExpandedTex => _titleExpandedTex ?? (_titleExpandedTex = MakeTex(TitleExpandedBg));
public static Texture2D TitleCollapsedTex => _titleCollapsedTex ?? (_titleCollapsedTex = MakeTex(TitleCollapsedBg));
public static Texture2D TitleHoverTex => _titleHoverTex ?? (_titleHoverTex = MakeTex(TitleHoverBlue));
public static Texture2D DangerTex => _dangerTex ?? (_dangerTex = MakeTex(DangerBg));
public static Texture2D DangerHoverTex => _dangerHoverTex ?? (_dangerHoverTex = MakeTex(DangerHover));
public static GUIStyle TitleStyle
{
get
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
if (_titleStyle == null)
{
_titleStyle = new GUIStyle();
_titleStyle.fontSize = 13;
_titleStyle.fontStyle = (FontStyle)1;
_titleStyle.normal.textColor = TextPrimary;
_titleStyle.alignment = (TextAnchor)3;
_titleStyle.padding = MakeOffset(6, 6, 2, 2);
}
return _titleStyle;
}
}
public static GUIStyle LabelStyle
{
get
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
if (_labelStyle == null)
{
_labelStyle = new GUIStyle();
_labelStyle.fontSize = 12;
_labelStyle.normal.textColor = TextPrimary;
_labelStyle.alignment = (TextAnchor)3;
}
return _labelStyle;
}
}
public static GUIStyle ButtonStyle
{
get
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected O, but got Unknown
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
if (_buttonStyle == null)
{
_buttonStyle = new GUIStyle();
_buttonStyle.fontSize = 11;
_buttonStyle.normal.background = ButtonTex;
_buttonStyle.normal.textColor = TextPrimary;
_buttonStyle.hover.background = ButtonHoverTex;
_buttonStyle.hover.textColor = TextPrimary;
_buttonStyle.active.background = ButtonActiveTex;
_buttonStyle.active.textColor = TextPrimary;
_buttonStyle.border = MakeOffset(1, 1, 1, 1);
_buttonStyle.padding = MakeOffset(4, 4, 2, 2);
_buttonStyle.alignment = (TextAnchor)4;
}
return _buttonStyle;
}
}
public static GUIStyle PresetBtnStyle
{
get
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected O, but got Unknown
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
if (_presetBtnStyle == null)
{
_presetBtnStyle = new GUIStyle();
_presetBtnStyle.fontSize = 10;
_presetBtnStyle.normal.background = ButtonTex;
_presetBtnStyle.normal.textColor = TextPrimary;
_presetBtnStyle.hover.background = ButtonHoverTex;
_presetBtnStyle.hover.textColor = TextPrimary;
_presetBtnStyle.active.background = ButtonActiveTex;
_presetBtnStyle.active.textColor = TextPrimary;
_presetBtnStyle.border = MakeOffset(1, 1, 1, 1);
_presetBtnStyle.padding = MakeOffset(2, 2, 1, 1);
_presetBtnStyle.alignment = (TextAnchor)4;
}
return _presetBtnStyle;
}
}
public static GUIStyle QuantityFieldStyle
{
get
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected O, but got Unknown
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
if (_quantityFieldStyle == null)
{
_quantityFieldStyle = new GUIStyle();
_quantityFieldStyle.fontSize = 13;
_quantityFieldStyle.fontStyle = (FontStyle)1;
_quantityFieldStyle.normal.background = FieldTex;
_quantityFieldStyle.normal.textColor = TextPrimary;
_quantityFieldStyle.focused.background = FieldTex;
_quantityFieldStyle.focused.textColor = TextPrimary;
_quantityFieldStyle.alignment = (TextAnchor)4;
_quantityFieldStyle.border = MakeOffset(2, 2, 2, 2);
}
return _quantityFieldStyle;
}
}
public static GUIStyle QuantityLabelStyle
{
get
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
if (_quantityLabelStyle == null)
{
_quantityLabelStyle = new GUIStyle();
_quantityLabelStyle.fontSize = 13;
_quantityLabelStyle.fontStyle = (FontStyle)1;
_quantityLabelStyle.normal.textColor = TextPrimary;
_quantityLabelStyle.alignment = (TextAnchor)4;
}
return _quantityLabelStyle;
}
}
public static GUIStyle DangerLabelStyle
{
get
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
if (_dangerLabelStyle == null)
{
_dangerLabelStyle = new GUIStyle();
_dangerLabelStyle.fontSize = 11;
_dangerLabelStyle.fontStyle = (FontStyle)1;
_dangerLabelStyle.normal.textColor = TextPrimary;
_dangerLabelStyle.alignment = (TextAnchor)4;
}
return _dangerLabelStyle;
}
}
private static RectOffset MakeOffset(int left, int right, int top, int bottom)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: 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_0022: Expected O, but got Unknown
return new RectOffset
{
left = left,
right = right,
top = top,
bottom = bottom
};
}
public static Texture2D MakeTex(Color color)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: 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_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
val.SetPixel(0, 0, color);
val.Apply();
((Object)val).hideFlags = (HideFlags)61;
return val;
}
public static void DrawPanel(Rect rect)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
GUI.DrawTexture(rect, (Texture)(object)BorderTex);
GUI.DrawTexture(new Rect(((Rect)(ref rect)).x + 1f, ((Rect)(ref rect)).y + 1f, ((Rect)(ref rect)).width - 2f, ((Rect)(ref rect)).height - 2f), (Texture)(object)PanelTex);
}
public static void DrawSeparator(Rect rect)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
GUI.DrawTexture(new Rect(((Rect)(ref rect)).x + 8f, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width - 16f, 1f), (Texture)(object)SeparatorTex);
}
public static void ResetStyles()
{
_titleStyle = null;
_labelStyle = null;
_buttonStyle = null;
_presetBtnStyle = null;
_quantityFieldStyle = null;
_quantityLabelStyle = null;
_dangerLabelStyle = null;
}
}
}
namespace TrackCrafts.Services
{
public static class IconResolver
{
private static PrefabCollectionSystem _prefabCollection;
private static EntityManager _em;
private static World _world;
private static bool _initialized;
private static readonly Dictionary<int, Texture2D> _iconCache = new Dictionary<int, Texture2D>();
public static bool IsReady
{
get
{
if (_initialized)
{
return _prefabCollection != null;
}
return false;
}
}
public static void Initialize(World world)
{
_initialized = false;
_prefabCollection = null;
_world = null;
TryBindWorld(world);
if (_initialized)
{
return;
}
if (WorldLocator.TryGetClientWorld(out var world2))
{
TryBindWorld(world2);
if (_initialized)
{
return;
}
}
try
{
for (int i = 0; i < World.All.Count && !TryBindWorld(World.All[i]); i++)
{
}
}
catch
{
}
}
private static bool TryBindWorld(World world)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
if (world == null || !world.IsCreated)
{
return false;
}
try
{
PrefabCollectionSystem existingSystemManaged = world.GetExistingSystemManaged<PrefabCollectionSystem>();
if (existingSystemManaged == null)
{
return false;
}
_world = world;
_em = world.EntityManager;
_prefabCollection = existingSystemManaged;
_initialized = true;
return true;
}
catch
{
return false;
}
}
public static Entity GetPrefabEntity(PrefabGUID prefabGuid)
{
//IL_0000: 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)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
if (!TryGetPrefabEntity(prefabGuid, out var entity))
{
return Entity.Null;
}
return entity;
}
public static bool TryGetPrefabEntity(PrefabGUID prefabGuid, out Entity entity)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: 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_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
entity = Entity.Null;
if (!_initialized || _prefabCollection == null)
{
return false;
}
try
{
NativeParallelHashMap<PrefabGUID, Entity> prefabGuidToEntityMap = _prefabCollection._PrefabGuidToEntityMap;
if (prefabGuidToEntityMap.ContainsKey(prefabGuid))
{
entity = prefabGuidToEntityMap[prefabGuid];
return entity != Entity.Null;
}
}
catch
{
}
return false;
}
public static bool IsValidRecipeGuid(PrefabGUID recipeGuid)
{
//IL_0000: 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_001f: Unknown result type (might be due to invalid IL or missing references)
if (!TryGetPrefabEntity(recipeGuid, out var entity))
{
return false;
}
try
{
return ((EntityManager)(ref _em)).HasBuffer<RecipeRequirementBuffer>(entity) || ((EntityManager)(ref _em)).HasBuffer<RecipeOutputBuffer>(entity);
}
catch
{
return false;
}
}
public static Texture2D GetItemIcon(PrefabGUID itemPrefabGuid)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
return GetItemIconViaGameData(itemPrefabGuid);
}
public static Texture2D GetItemIconViaGameData(PrefabGUID itemPrefabGuid)
{
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
if (!_initialized)
{
return null;
}
if (_iconCache.TryGetValue(itemPrefabGuid._Value, out var value))
{
return value;
}
try
{
World world = World.DefaultGameObjectInjectionWorld;
if (_world != null && _world.IsCreated)
{
world = _world;
}
else if (!WorldLocator.TryGetClientWorld(out world) || world == null)
{
return null;
}
GameDataSystem existingSystemManaged = world.GetExistingSystemManaged<GameDataSystem>();
if (existingSystemManaged == null)
{
return null;
}
ManagedDataRegistry managedDataRegistry = existingSystemManaged.ManagedDataRegistry;
ItemDataComponent val = default(ItemDataComponent);
if (managedDataRegistry.TryGet<ItemDataComponent>(itemPrefabGuid, ref val) && (Object)(object)val != (Object)null && (Object)(object)val.Icon != (Object)null)
{
Texture2D val2 = SpriteToTexture2D(val.Icon);
_iconCache[itemPrefabGuid._Value] = val2;
return val2;
}
ItemData val3 = default(ItemData);
if (existingSystemManaged.ItemHashLookupMap.TryGetValue(itemPrefabGuid, ref val3))
{
ItemDataComponent val4 = default(ItemDataComponent);
if (val3.Entity != Entity.Null && managedDataRegistry.TryGet<ItemDataComponent>(val3.Entity, world.EntityManager, ref val4) && (Object)(object)val4 != (Object)null && (Object)(object)val4.Icon != (Object)null)
{
Texture2D val5 = SpriteToTexture2D(val4.Icon);
_iconCache[itemPrefabGuid._Value] = val5;
return val5;
}
_iconCache[itemPrefabGuid._Value] = null;
}
}
catch (Exception ex)
{
Plugin.LogWarning($"GameData icon resolve failed for {itemPrefabGuid._Value}: {ex.Message}");
}
return null;
}
public static Texture2D GetRecipeOutputIcon(PrefabGUID recipePrefabGuid)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: 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)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//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_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
if (!_initialized)
{
return null;
}
Entity prefabEntity = GetPrefabEntity(recipePrefabGuid);
if (prefabEntity == Entity.Null)
{
return null;
}
try
{
if (((EntityManager)(ref _em)).HasBuffer<RecipeOutputBuffer>(prefabEntity))
{
DynamicBuffer<RecipeOutputBuffer> buffer = ((EntityManager)(ref _em)).GetBuffer<RecipeOutputBuffer>(prefabEntity, false);
if (buffer.Length > 0)
{
return GetItemIconViaGameData(buffer[0].Guid);
}
}
}
catch
{
}
return null;
}
public static string GetPrefabName(PrefabGUID prefabGuid)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
if (Plugin.PrefabNames.TryGetValue(prefabGuid._Value, out var value))
{
return value;
}
if (_initialized && _prefabCollection != null)
{
try
{
PrefabLookupMap prefabLookupMap = ((PrefabCollectionSystem_Base)_prefabCollection).PrefabLookupMap;
string name = ((PrefabLookupMap)(ref prefabLookupMap)).GetName(prefabGuid);
if (!string.IsNullOrEmpty(name))
{
return name;
}
}
catch
{
}
}
if (_initialized && _prefabCollection != null)
{
try
{
Enumerator<string, PrefabGUID> enumerator = _prefabCollection.SpawnableNameToPrefabGuidDictionary.GetEnumerator();
while (enumerator.MoveNext())
{
KeyValuePair<string, PrefabGUID> current = enumerator.Current;
if (current.Value._Value == prefabGuid._Value)
{
return current.Key;
}
}
}
catch
{
}
}
return prefabGuid._Value.ToString();
}
public static string GetCleanItemName(PrefabGUID prefabGuid)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
if (Plugin.PrefabNames.TryGetValue(prefabGuid._Value, out var value))
{
return value;
}
string text = GetPrefabName(prefabGuid);
string[] array = new string[17]
{
"Recipe_Ingredient_Mineral_", "Recipe_Ingredient_", "Recipe_Output_", "Recipe_", "Item_Ingredient_Mineral_", "Item_Ingredient_", "Item_Building_", "Item_Consumable_", "Item_Weapon_", "Item_Armor_",
"Item_", "Ingredient_Mineral_", "Ingredient_", "Building_", "Consumable_", "Weapon_", "Armor_"
};
for (int i = 0; i < array.Length; i++)
{
if (text.StartsWith(array[i], StringComparison.OrdinalIgnoreCase))
{
text = text.Substring(array[i].Length);
break;
}
}
text = text.Replace("_T01", "").Replace("_T02", "").Replace("_T03", "")
.Replace("_T04", "");
return text.Replace("_", " ").Trim();
}
public static Texture2D SpriteToTexture2D(Sprite sprite)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: 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_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: 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_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Expected O, but got Unknown
if ((Object)(object)sprite == (Object)null || (Object)(object)sprite.texture == (Object)null)
{
return null;
}
try
{
Rect val = sprite.rect;
int num = (int)((Rect)(ref val)).width;
val = sprite.rect;
Texture2D val2 = new Texture2D(num, (int)((Rect)(ref val)).height);
Texture2D texture = sprite.texture;
val = sprite.textureRect;
int num2 = (int)((Rect)(ref val)).x;
val = sprite.textureRect;
int num3 = (int)((Rect)(ref val)).y;
val = sprite.textureRect;
int num4 = (int)((Rect)(ref val)).width;
val = sprite.textureRect;
Il2CppStructArray<Color> pixels = texture.GetPixels(num2, num3, num4, (int)((Rect)(ref val)).height);
val2.SetPixels(pixels);
val2.Apply();
return val2;
}
catch
{
return ExtractViaRenderTexture(sprite);
}
}
private static Texture2D ExtractViaRenderTexture(Sprite sprite)
{
//IL_0035: 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_0044: 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_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Expected O, but got Unknown
try
{
RenderTexture temporary = RenderTexture.GetTemporary(((Texture)sprite.texture).width, ((Texture)sprite.texture).height);
Graphics.Blit((Texture)(object)sprite.texture, temporary);
RenderTexture active = RenderTexture.active;
RenderTexture.active = temporary;
Rect textureRect = sprite.textureRect;
int num = (int)((Rect)(ref textureRect)).width;
textureRect = sprite.textureRect;
Texture2D val = new Texture2D(num, (int)((Rect)(ref textureRect)).height, (TextureFormat)4, false);
textureRect = sprite.textureRect;
float x = ((Rect)(ref textureRect)).x;
textureRect = sprite.textureRect;
float y = ((Rect)(ref textureRect)).y;
textureRect = sprite.textureRect;
float width = ((Rect)(ref textureRect)).width;
textureRect = sprite.textureRect;
val.ReadPixels(new Rect(x, y, width, ((Rect)(ref textureRect)).height), 0, 0);
val.Apply();
RenderTexture.active = active;
RenderTexture.ReleaseTemporary(temporary);
return val;
}
catch
{
return null;
}
}
public static void ClearCache()
{
_iconCache.Clear();
}
}
public static class InventoryQuery
{
private static readonly Dictionary<int, int> CachedCounts = new Dictionary<int, int>();
private static float _nextScanTime;
public static Dictionary<int, int> GetPlayerItemCounts()
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
if (Time.time < _nextScanTime && CachedCounts.Count > 0)
{
return new Dictionary<int, int>(CachedCounts);
}
_nextScanTime = Time.time + 1.5f;
CachedCounts.Clear();
try
{
if (!WorldLocator.TryGetClientWorld(out var world) || world == null)
{
return new Dictionary<int, int>(CachedCounts);
}
EntityManager entityManager = world.EntityManager;
Entity localPlayerEntity = GetLocalPlayerEntity(entityManager);
if (localPlayerEntity != Entity.Null && ((EntityManager)(ref entityManager)).HasBuffer<AttachedBuffer>(localPlayerEntity))
{
DynamicBuffer<AttachedBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<AttachedBuffer>(localPlayerEntity, false);
for (int i = 0; i < buffer.Length; i++)
{
CountInventoryItems(entityManager, buffer[i].Entity, CachedCounts);
}
}
if (CachedCounts.Count == 0)
{
ScanAllVisibleInventories(entityManager, CachedCounts);
}
}
catch (Exception ex)
{
Plugin.LogWarning("Inventory query failed: " + ex.Message);
}
return new Dictionary<int, int>(CachedCounts);
}
private static void ScanAllVisibleInventories(EntityManager em, Dictionary<int, int> counts)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
try
{
EntityQuery val = ((EntityManager)(ref em)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<InventoryBuffer>() });
NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
for (int i = 0; i < val2.Length; i++)
{
CountInventoryItems(em, val2[i], counts);
}
val2.Dispose();
}
catch
{
}
}
private static void CountInventoryItems(EntityManager em, Entity inventoryEntity, Dictionary<int, int> counts)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: 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)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!((EntityManager)(ref em)).HasBuffer<InventoryBuffer>(inventoryEntity))
{
return;
}
DynamicBuffer<InventoryBuffer> buffer = ((EntityManager)(ref em)).GetBuffer<InventoryBuffer>(inventoryEntity, false);
for (int i = 0; i < buffer.Length; i++)
{
InventoryBuffer val = buffer[i];
if (val.Amount <= 0)
{
continue;
}
int value = val.ItemType._Value;
if (value != 0)
{
if (counts.ContainsKey(value))
{
counts[value] += val.Amount;
}
else
{
counts[value] = val.Amount;
}
}
}
}
catch
{
}
}
public static Entity GetLocalPlayerEntity(EntityManager em)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: 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_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: 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_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: 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)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
try
{
EntityQuery val = ((EntityManager)(ref em)).CreateEntityQuery((ComponentType[])(object)new ComponentType[2]
{
ComponentType.ReadOnly<User>(),
ComponentType.ReadOnly<LocalUser>()
});
if (((EntityQuery)(ref val)).IsEmpty)
{
return Entity.Null;
}
NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
if (val2.Length == 0)
{
val2.Dispose();
return Entity.Null;
}
Entity val3 = val2[0];
val2.Dispose();
return ((EntityManager)(ref em)).GetComponentData<User>(val3).LocalCharacter._Entity;
}
catch
{
return Entity.Null;
}
}
}
public static class RecipeLookup
{
public static TrackedRecipeModel BuildTrackedRecipe(PrefabGUID recipePrefabGuid, int quantity = 1)
{
//IL_000f: 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)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: 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_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!IconResolver.IsReady)
{
return null;
}
Entity prefabEntity = IconResolver.GetPrefabEntity(recipePrefabGuid);
if (prefabEntity == Entity.Null)
{
return null;
}
if (!WorldLocator.TryGetClientWorld(out var world) || world == null)
{
return null;
}
EntityManager entityManager = world.EntityManager;
TrackedRecipeModel trackedRecipeModel = new TrackedRecipeModel
{
RecipePrefabGuid = recipePrefabGuid,
Quantity = quantity
};
if (((EntityManager)(ref entityManager)).HasBuffer<RecipeOutputBuffer>(prefabEntity))
{
DynamicBuffer<RecipeOutputBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<RecipeOutputBuffer>(prefabEntity, false);
if (buffer.Length > 0)
{
trackedRecipeModel.RecipeName = IconResolver.GetCleanItemName(buffer[0].Guid);
trackedRecipeModel.RecipeIcon = IconResolver.GetItemIconViaGameData(buffer[0].Guid);
}
}
if (string.IsNullOrEmpty(trackedRecipeModel.RecipeName) || trackedRecipeModel.RecipeName == "Unknown")
{
trackedRecipeModel.RecipeName = CleanRecipeName(IconResolver.GetPrefabName(recipePrefabGuid));
}
if ((Object)(object)trackedRecipeModel.RecipeIcon == (Object)null)
{
trackedRecipeModel.RecipeIcon = IconResolver.GetRecipeOutputIcon(recipePrefabGuid);
}
if (((EntityManager)(ref entityManager)).HasBuffer<RecipeRequirementBuffer>(prefabEntity))
{
DynamicBuffer<RecipeRequirementBuffer> buffer2 = ((EntityManager)(ref entityManager)).GetBuffer<RecipeRequirementBuffer>(prefabEntity, false);
for (int i = 0; i < buffer2.Length; i++)
{
RecipeRequirementBuffer val = buffer2[i];
IngredientModel item = new IngredientModel
{
ItemPrefabGuid = val.Guid,
ItemName = IconResolver.GetCleanItemName(val.Guid),
Icon = IconResolver.GetItemIconViaGameData(val.Guid),
AmountPerCraft = val.Amount
};
trackedRecipeModel.Ingredients.Add(item);
}
}
return trackedRecipeModel;
}
catch (Exception ex)
{
Plugin.LogWarning("Failed to build tracked recipe: " + ex.Message);
return null;
}
}
public static string CleanRecipeName(string rawName)
{
if (string.IsNullOrEmpty(rawName))
{
return "Unknown Recipe";
}
if (rawName.StartsWith("Recipe_"))
{
rawName = rawName.Substring(7);
}
return rawName.Replace("_", " ");
}
public static List<PrefabGUID> GetRecipeOutputs(PrefabGUID recipePrefabGuid)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: 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_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: 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)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
List<PrefabGUID> list = new List<PrefabGUID>();
try
{
Entity prefabEntity = IconResolver.GetPrefabEntity(recipePrefabGuid);
if (prefabEntity == Entity.Null)
{
return list;
}
if (!WorldLocator.TryGetClientWorld(out var world) || world == null)
{
return list;
}
EntityManager entityManager = world.EntityManager;
if (((EntityManager)(ref entityManager)).HasBuffer<RecipeOutputBuffer>(prefabEntity))
{
DynamicBuffer<RecipeOutputBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<RecipeOutputBuffer>(prefabEntity, false);
for (int i = 0; i < buffer.Length; i++)
{
list.Add(buffer[i].Guid);
}
}
}
catch
{
}
return list;
}
}
public static class WorldLocator
{
public static bool TryGetClientWorld(out World world)
{
world = null;
try
{
World defaultGameObjectInjectionWorld = World.DefaultGameObjectInjectionWorld;
if (defaultGameObjectInjectionWorld == null || !defaultGameObjectInjectionWorld.IsCreated)
{
return false;
}
try
{
ClientWorldManager existingSystemManaged = defaultGameObjectInjectionWorld.GetExistingSystemManaged<ClientWorldManager>();
if (existingSystemManaged != null)
{
World activeClientWorld = existingSystemManaged.ActiveClientWorld;
if (activeClientWorld != null && activeClientWorld.IsCreated)
{
world = activeClientWorld;
return true;
}
}
}
catch
{
}
world = defaultGameObjectInjectionWorld;
return true;
}
catch
{
return false;
}
}
}
}
namespace TrackCrafts.Patches
{
[HarmonyPatch]
public static class CraftingPatches
{
[HarmonyPatch(typeof(StartCraftingSystem), "OnUpdate")]
[HarmonyPostfix]
public static void OnStartCrafting_Postfix(StartCraftingSystem __instance)
{
}
[HarmonyPatch(typeof(UpdateCraftingSystem), "OnUpdate")]
[HarmonyPostfix]
public static void OnUpdateCrafting_Postfix(UpdateCraftingSystem __instance)
{
}
[HarmonyPatch(typeof(WorkstationRecipeGridSelectionEntry), "RefreshData")]
[HarmonyPostfix]
public static void WorkstationRecipeRefresh_Postfix(WorkstationRecipeGridSelectionEntry entry, Data data)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
try
{
if (data.isHovered)
{
PrefabGUID val = ((data.EntryId._Value != 0) ? data.EntryId : entry.EntryId);
if (val._Value != 0)
{
RecipeHoverState.SetHovered(val);
}
}
}
catch
{
}
}
[HarmonyPatch(typeof(RefinementstationRecipeEntry), "RefreshData")]
[HarmonyPostfix]
public static void RefinementRecipeRefresh_Postfix(RefinementstationRecipeEntry entry, Data data)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
try
{
if (data.Highlight)
{
PrefabGUID val = ((data.EntryId._Value != 0) ? data.EntryId : entry.EntryId);
if (val._Value != 0)
{
RecipeHoverState.SetHovered(val);
}
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(GridSelectionEntry), "OnPointerClick")]
public static class GridSelectionEntryPatch
{
[HarmonyPostfix]
public static void Postfix(GridSelectionEntry __instance, PointerEventData eventData)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Invalid comparison between Unknown and I4
try
{
if (eventData != null && (int)eventData.button == 2 && !((Object)(object)__instance == (Object)null))
{
Plugin.LogInfo("[Mouse3] OnPointerClick on " + ((Object)((Component)__instance).gameObject).name);
Plugin.TryPinRecipeFromEntry(((Component)__instance).gameObject);
}
}
catch
{
}
}
}
}
namespace TrackCrafts.Core
{
public class IngredientModel
{
public PrefabGUID ItemPrefabGuid { get; set; }
public string ItemName { get; set; } = "Unknown";
public Texture2D Icon { get; set; }
public int AmountPerCraft { get; set; }
public int TotalNeeded { get; set; }
public int Have { get; set; }
public int Missing { get; set; }
public bool IsSatisfied => Missing <= 0;
}
public static class RecipeHoverState
{
private static int _hoveredRecipeGuid;
private static float _hoveredAt;
public static void SetHovered(PrefabGUID recipeGuid)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
if (recipeGuid._Value != 0)
{
_hoveredRecipeGuid = recipeGuid._Value;
_hoveredAt = Time.realtimeSinceStartup;
}
}
public static bool TryGetHovered(out PrefabGUID recipeGuid, float maxAgeSeconds = 0.4f)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
recipeGuid = default(PrefabGUID);
if (_hoveredRecipeGuid == 0)
{
return false;
}
if (Time.realtimeSinceStartup - _hoveredAt > maxAgeSeconds)
{
return false;
}
recipeGuid._Value = _hoveredRecipeGuid;
return true;
}
}
public class TrackCraftManager
{
private bool _initialized;
public List<TrackedRecipeModel> TrackedRecipes { get; } = new List<TrackedRecipeModel>();
public void EnsureInitialized()
{
if ((!_initialized || !IconResolver.IsReady) && WorldLocator.TryGetClientWorld(out var world) && world != null)
{
IconResolver.Initialize(world);
_initialized = IconResolver.IsReady;
}
}
public bool AddRecipe(PrefabGUID recipePrefabGuid, int quantity = 1)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
EnsureInitialized();
if (!IconResolver.IsReady)
{
Plugin.LogWarning("[TrackCraftManager] IconResolver not ready; cannot add recipe.");
return false;
}
if (!IconResolver.IsValidRecipeGuid(recipePrefabGuid))
{
Plugin.LogWarning("[TrackCraftManager] Rejected invalid recipe guid: " + recipePrefabGuid._Value);
return false;
}
foreach (TrackedRecipeModel trackedRecipe in TrackedRecipes)
{
PrefabGUID recipePrefabGuid2 = trackedRecipe.RecipePrefabGuid;
if (((PrefabGUID)(ref recipePrefabGuid2)).Equals(recipePrefabGuid))
{
return false;
}
}
TrackedRecipeModel trackedRecipeModel = RecipeLookup.BuildTrackedRecipe(recipePrefabGuid, quantity);
if (trackedRecipeModel == null)
{
return false;
}
TrackedRecipes.Add(trackedRecipeModel);
RefreshCounts();
return true;
}
public void RemoveRecipe(int index)
{
if (index >= 0 && index < TrackedRecipes.Count)
{
TrackedRecipes.RemoveAt(index);
}
}
public TrackedRecipeModel GetRecipe(PrefabGUID recipePrefabGuid)
{
//IL_0010: 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)
for (int i = 0; i < TrackedRecipes.Count; i++)
{
if (TrackedRecipes[i].RecipePrefabGuid._Value == recipePrefabGuid._Value)
{
return TrackedRecipes[i];
}
}
return null;
}
public void AddOrReplace(TrackedRecipeModel model)
{
//IL_0014: 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)
if (model == null)
{
return;
}
for (int i = 0; i < TrackedRecipes.Count; i++)
{
if (TrackedRecipes[i].RecipePrefabGuid._Value == model.RecipePrefabGuid._Value