Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of CraftFavorites v1.6.0
CraftFavorites_v1.6.0.dll
Decompiled 5 days agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("CraftFavorites")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.6.0.0")] [assembly: AssemblyInformationalVersion("1.6.0")] [assembly: AssemblyProduct("CraftFavorites")] [assembly: AssemblyTitle("CraftFavorites")] [assembly: AssemblyVersion("1.6.0.0")] namespace CraftFavorites; [HarmonyPatch(typeof(InventoryGui), "AddRecipeToList")] internal static class AddRecipeToList_Patch { private static readonly FieldInfo RecipesField = AccessTools.Field(typeof(InventoryGui), "m_availableRecipes"); private static bool _starErrorLogged; private static void Postfix(InventoryGui __instance, Recipe recipe, ItemData item) { try { if (item == null && RecipesField.GetValue(__instance) is IList { Count: >0 } list) { object obj = list[list.Count - 1]; object? obj2 = AccessTools.Property(obj.GetType(), "InterfaceElement")?.GetValue(obj); GameObject val = (GameObject)((obj2 is GameObject) ? obj2 : null); if ((Object)(object)val != (Object)null) { FavoritesHud.CreateStar(val, recipe); } } } catch (Exception arg) { if (!_starErrorLogged) { _starErrorLogged = true; Debug.LogWarning((object)$"[CraftFavorites] ошибка звезды (дальше не повторяется): {arg}"); } } } } [BepInPlugin("DEEP_FROST.CraftFavorites", "CraftFavorites", "1.6.0")] public class CraftFavoritesPlugin : BaseUnityPlugin { public const string PluginGuid = "DEEP_FROST.CraftFavorites"; public const string PluginName = "CraftFavorites"; public const string PluginVersion = "1.6.0"; internal static CraftFavoritesPlugin Instance; internal static ManualLogSource Log; internal static ConfigEntry<int> CfgLimit; internal static ConfigEntry<bool> CfgShowHud; internal static ConfigEntry<KeyboardShortcut> CfgClearKey; internal static ConfigEntry<float> CfgHudScale; internal static ConfigEntry<float> CfgHudX; internal static ConfigEntry<float> CfgTopOffset; private GameObject _hud; private void Awake() { //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) Instance = this; Log = ((BaseUnityPlugin)this).Logger; CfgLimit = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Limit", 3, "Максимум избранных рецептов / Max favorited recipes"); CfgShowHud = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Show", true, "Показывать панель избранного слева сверху / Show the favorites panel top-left"); CfgHudScale = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "HudScale", 2f, "Масштаб панели избранного (иконки и текст) / HUD panel scale (icons and text)"); CfgHudX = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "HudX", 18f, "Отступ блоков слева, пиксели / Blocks offset from left edge, pixels"); CfgTopOffset = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "TopOffset", 250f, "Отступ блоков от ВЕРХНЕГО края ВНИЗ, пиксели. Только положительное число / Blocks offset DOWN from the top edge, pixels. Positive only"); CfgClearKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "ClearAll", new KeyboardShortcut((KeyCode)291, Array.Empty<KeyCode>()), "Очистить все избранные рецепты / Clear all favorites"); new Harmony("DEEP_FROST.CraftFavorites").PatchAll(typeof(CraftFavoritesPlugin).Assembly); Log.LogInfo((object)"[CraftFavorites] 1.6.0 загружен"); } private void Update() { //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown //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) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: 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_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { if ((Object)(object)_hud != (Object)null) { Object.Destroy((Object)(object)_hud); _hud = null; } return; } if ((Object)(object)_hud == (Object)null) { _hud = new GameObject("CraftFavoritesHUD", new Type[3] { typeof(RectTransform), typeof(Canvas), typeof(GraphicRaycaster) }); Object.DontDestroyOnLoad((Object)(object)_hud); RectTransform val = (RectTransform)_hud.transform; val.anchorMin = Vector2.zero; val.anchorMax = Vector2.one; val.offsetMin = Vector2.zero; val.offsetMax = Vector2.zero; Canvas component = _hud.GetComponent<Canvas>(); component.renderMode = (RenderMode)0; component.sortingOrder = 40; _hud.AddComponent<FavoritesHud>(); } KeyboardShortcut value = CfgClearKey.Value; if (((KeyboardShortcut)(ref value)).IsDown() && Favorites.All().Count > 0) { Favorites.Clear(); ((Character)localPlayer).Message((MessageType)2, "Избранные рецепты очищены", 0, (Sprite)null, false); Log.LogInfo((object)"[CraftFavorites] Избранные очищены хоткеем"); } } } internal static class Favorites { public const string ZdoKey = "CraftFavorites"; private static readonly List<string> _items = new List<string>(); private static float _nextSync; private static bool _dirty; private static void Sync() { if (Time.unscaledTime < _nextSync && !_dirty) { return; } _nextSync = Time.unscaledTime + 1f; ZNetView znv = GetZnv(); if ((Object)(object)znv == (Object)null) { return; } string text = znv.GetZDO().GetString("CraftFavorites", ""); List<string> list = new List<string>(); string[] array = text.Split('|'); foreach (string text2 in array) { if (text2.Length > 0) { list.Add(text2); } } if (!_dirty) { _items.Clear(); _items.AddRange(list); } } private static ZNetView GetZnv() { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return null; } ZNetView component = ((Component)localPlayer).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || !component.IsValid() || component.GetZDO() == null) { return null; } return component; } public static List<string> All() { Sync(); return _items; } public static bool IsFav(string key) { return All().Contains(key); } public static bool Toggle(string key, int limit) { Sync(); if (_items.Contains(key)) { _items.Remove(key); _dirty = true; Save(); return false; } if (_items.Count >= limit) { return false; } _items.Add(key); _dirty = true; Save(); return true; } public static void Clear() { _items.Clear(); _dirty = true; Save(); } private static void Save() { ZNetView znv = GetZnv(); if ((Object)(object)znv != (Object)null) { znv.GetZDO().Set("CraftFavorites", string.Join("|", _items)); _dirty = false; } } } public class FavoritesHud : MonoBehaviour { private class RowRef { public TMP_Text Label; public string ResName; public string ResLocal; public int Need; } private class BlockRef { public GameObject Go; public string Key; public Recipe Recipe; public TMP_Text CounterLabel; public List<RowRef> Rows = new List<RowRef>(); } private static readonly Color CounterColor = new Color(1f, 0.85f, 0.2f, 1f); private static readonly Color CounterZeroColor = new Color(0.6f, 0.6f, 0.6f, 1f); private static readonly Color OkColor = new Color(0.55f, 1f, 0.5f); private static readonly Color LackColor = new Color(1f, 0.55f, 0.4f); private readonly List<BlockRef> _blocks = new List<BlockRef>(); private float _nextPoll; private string _lastFavs; private TMP_FontAsset _font; private static Sprite _starSprite; private float Scale => CraftFavoritesPlugin.CfgHudScale.Value; private void Update() { bool value = CraftFavoritesPlugin.CfgShowHud.Value; if (((Behaviour)((Component)this).GetComponent<Canvas>()).enabled != value) { ((Behaviour)((Component)this).GetComponent<Canvas>()).enabled = value; } if (value && !(Time.unscaledTime < _nextPoll)) { _nextPoll = Time.unscaledTime + 0.5f; List<string> list = Favorites.All(); string text = string.Join("|", list); if (text != _lastFavs) { _lastFavs = text; RebuildBlocks(list); } UpdateCounts(); } } private TMP_FontAsset Font() { if ((Object)(object)_font == (Object)null && (Object)(object)InventoryGui.instance != (Object)null) { _font = InventoryGui.instance.m_playerName.font; } return _font; } private TMP_Text MakeText(GameObject parent, string text, float fontSize, Color color) { //IL_0025: 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_0068: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("text", new Type[2] { typeof(RectTransform), typeof(TextMeshProUGUI) }); val.transform.SetParent(parent.transform, false); TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>(); TMP_FontAsset val2 = Font(); if ((Object)(object)val2 != (Object)null) { ((TMP_Text)component).font = val2; } ((TMP_Text)component).text = text; ((TMP_Text)component).fontSize = fontSize; ((Graphic)component).color = color; ((TMP_Text)component).fontStyle = (FontStyles)1; ((TMP_Text)component).enableWordWrapping = false; ((Graphic)component).raycastTarget = false; return (TMP_Text)(object)component; } private Image MakeIcon(GameObject parent, Sprite sprite, float size) { //IL_0025: 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_003c: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("icon", new Type[2] { typeof(RectTransform), typeof(Image) }); val.transform.SetParent(parent.transform, false); LayoutElement obj = val.AddComponent<LayoutElement>(); obj.minWidth = size; obj.minHeight = size; obj.preferredWidth = size; obj.preferredHeight = size; Image component = val.GetComponent<Image>(); if ((Object)(object)sprite != (Object)null) { component.sprite = sprite; } component.preserveAspect = true; return component; } private GameObject MakeBlock(string key) { //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_0061: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_007b: 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_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Expected O, but got Unknown //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Expected O, but got Unknown GameObject val = new GameObject("FavBlock_" + key, new Type[4] { typeof(RectTransform), typeof(Image), typeof(VerticalLayoutGroup), typeof(ContentSizeFitter) }); val.transform.SetParent((Transform)(RectTransform)((Component)this).transform, false); ((Graphic)val.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.6f); VerticalLayoutGroup component = val.GetComponent<VerticalLayoutGroup>(); ((LayoutGroup)component).childAlignment = (TextAnchor)0; ((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight = false; ((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = false; float scale = Scale; ((LayoutGroup)component).padding = new RectOffset(Mathf.RoundToInt(10f * scale), Mathf.RoundToInt(10f * scale), Mathf.RoundToInt(8f * scale), Mathf.RoundToInt(8f * scale)); ((HorizontalOrVerticalLayoutGroup)component).spacing = 4f * scale; ContentSizeFitter component2 = val.GetComponent<ContentSizeFitter>(); component2.verticalFit = (FitMode)2; component2.horizontalFit = (FitMode)2; return val; } private void RebuildBlocks(List<string> favs) { //IL_042d: Unknown result type (might be due to invalid IL or missing references) //IL_0434: Expected O, but got Unknown //IL_0440: Unknown result type (might be due to invalid IL or missing references) //IL_0456: Unknown result type (might be due to invalid IL or missing references) //IL_046c: Unknown result type (might be due to invalid IL or missing references) //IL_047a: Unknown result type (might be due to invalid IL or missing references) //IL_0487: Unknown result type (might be due to invalid IL or missing references) //IL_048c: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Expected O, but got Unknown //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_03b9: Unknown result type (might be due to invalid IL or missing references) //IL_03c3: Expected O, but got Unknown //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Expected O, but got Unknown //IL_035f: Unknown result type (might be due to invalid IL or missing references) foreach (BlockRef block in _blocks) { Object.Destroy((Object)(object)block.Go); } _blocks.Clear(); ObjectDB instance = ObjectDB.instance; if ((Object)(object)instance == (Object)null) { return; } float scale = Scale; foreach (string fav in favs) { Recipe val = null; foreach (Recipe recipe in instance.m_recipes) { if ((Object)(object)recipe != (Object)null && (Object)(object)recipe.m_item != (Object)null && ((Object)((Component)recipe.m_item).gameObject).name == fav) { val = recipe; break; } } GameObject val2 = MakeBlock(fav); BlockRef blockRef = new BlockRef { Key = fav, Go = val2, Recipe = val }; _blocks.Add(blockRef); if ((Object)(object)val == (Object)null || (Object)(object)val.m_item == (Object)null) { MakeText(val2, "Избранный рецепт не найден", 14f * scale, new Color(1f, 0.8f, 0.4f)); continue; } GameObject val3 = new GameObject("title", new Type[2] { typeof(RectTransform), typeof(HorizontalLayoutGroup) }); val3.transform.SetParent(val2.transform, false); HorizontalLayoutGroup component = val3.GetComponent<HorizontalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight = false; ((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)component).spacing = 8f * scale; MakeIcon(val3, val.m_item.m_itemData.GetIcon(), 32f * scale); MakeText(val3, Localize(val.m_item.m_itemData.m_shared.m_name), 18f * scale, new Color(1f, 0.95f, 0.75f)); blockRef.CounterLabel = MakeText(val3, "", 18f * scale, CounterColor); blockRef.Rows.Clear(); Requirement[] resources = val.m_resources; foreach (Requirement val4 in resources) { if (val4 != null && (Object)(object)val4.m_resItem != (Object)null && val4.m_amount > 0) { string name = val4.m_resItem.m_itemData.m_shared.m_name; string text = Localize(name); GameObject val5 = new GameObject("req", new Type[2] { typeof(RectTransform), typeof(HorizontalLayoutGroup) }); val5.transform.SetParent(val2.transform, false); HorizontalLayoutGroup component2 = val5.GetComponent<HorizontalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)component2).childForceExpandHeight = false; ((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)component2).spacing = 8f * scale; MakeIcon(val5, val4.m_resItem.m_itemData.GetIcon(), 26f * scale); TMP_Text label = MakeText(val5, "0/" + val4.m_amount + " " + text, 16f * scale, new Color(0.9f, 0.9f, 0.9f)); blockRef.Rows.Add(new RowRef { Label = label, ResName = name, ResLocal = text, Need = val4.m_amount }); } } LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)val2.transform); } float num = Mathf.Max(0f, CraftFavoritesPlugin.CfgTopOffset.Value); float num2 = Mathf.Max(0f, CraftFavoritesPlugin.CfgHudX.Value); float num3 = 0f - num; foreach (BlockRef block2 in _blocks) { RectTransform val6 = (RectTransform)block2.Go.transform; val6.anchorMin = new Vector2(0f, 1f); val6.anchorMax = new Vector2(0f, 1f); val6.pivot = new Vector2(0f, 1f); val6.anchoredPosition = new Vector2(num2, num3); float num4 = num3; Rect rect = val6.rect; num3 = num4 - (((Rect)(ref rect)).height + 8f * Scale); } } private void UpdateCounts() { //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); if (inventory == null) { return; } foreach (BlockRef block in _blocks) { int num = int.MaxValue; foreach (RowRef row in block.Rows) { int num2 = inventory.CountItems(row.ResName, -1, true); row.Label.text = num2 + "/" + row.Need + " " + row.ResLocal; ((Graphic)row.Label).color = ((num2 >= row.Need) ? OkColor : LackColor); if (row.Need > 0) { num = Math.Min(num, num2 / row.Need); } } if (!((Object)(object)block.CounterLabel == (Object)null)) { int num3 = ((num != int.MaxValue) ? num : 0); int num4 = ((!((Object)(object)block.Recipe != (Object)null)) ? 1 : Math.Max(1, block.Recipe.m_amount)); int num5 = num3 * num4; block.CounterLabel.text = "×" + num5; ((Graphic)block.CounterLabel).color = ((num5 > 0) ? CounterColor : CounterZeroColor); } } } private static string Localize(string token) { if (token == null || !token.StartsWith("$")) { return token; } return Localization.instance.Localize(token); } public static void CreateStar(GameObject row, Recipe recipe) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown //IL_007f: 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) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Expected O, but got Unknown if ((Object)(object)row.transform.Find("FavStar") != (Object)null) { return; } string key = ((Object)((Component)recipe.m_item).gameObject).name; bool flag = Favorites.IsFav(key); GameObject val = new GameObject("FavStar", new Type[3] { typeof(RectTransform), typeof(Image), typeof(Button) }); RectTransform val2 = (RectTransform)val.transform; ((Transform)val2).SetParent(row.transform, false); val2.anchorMin = new Vector2(1f, 0.5f); val2.anchorMax = new Vector2(1f, 0.5f); val2.pivot = new Vector2(0.5f, 0.5f); val2.anchoredPosition = new Vector2(-7f, 0f); val2.sizeDelta = new Vector2(20f, 20f); Image img = val.GetComponent<Image>(); img.sprite = StarSprite(); ((Graphic)img).color = (flag ? new Color(1f, 0.85f, 0.2f, 1f) : new Color(1f, 1f, 1f, 0.25f)); Button component = val.GetComponent<Button>(); ((Selectable)component).transition = (Transition)1; ((UnityEvent)component.onClick).AddListener((UnityAction)delegate { //IL_0050: 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) int value = CraftFavoritesPlugin.CfgLimit.Value; bool flag2 = Favorites.Toggle(key, value); ((Graphic)img).color = (flag2 ? new Color(1f, 0.85f, 0.2f, 1f) : new Color(1f, 1f, 1f, 0.25f)); Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { if (flag2) { ((Character)localPlayer).Message((MessageType)2, "Добавлено в избранное (HUD слева сверху)", 0, (Sprite)null, false); } else { ((Character)localPlayer).Message((MessageType)2, "Убрано из избранного", 0, (Sprite)null, false); } } }); val.transform.SetAsLastSibling(); } private static Sprite StarSprite() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0123: 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) if ((Object)(object)_starSprite != (Object)null) { return _starSprite; } Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false); float num = 15.5f; float num2 = 15.5f; float num3 = 14.5f; float num4 = num3 * 0.42f; for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { float num5 = (float)j - num; float num6 = (float)i - num2; float num7 = Mathf.Sqrt(num5 * num5 + num6 * num6); float num8 = (Mathf.Atan2(num6, num5) + MathF.PI) / (MathF.PI * 2f) * 10f; float num9 = Mathf.Abs(num8 - Mathf.Floor(num8) - 0.5f) * 2f; float num10 = Mathf.Lerp(num3, num4, num9); float num11 = ((num7 <= num10) ? 1f : 0f); val.SetPixel(j, i, new Color(1f, 1f, 1f, num11)); } } val.Apply(); _starSprite = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 100f); return _starSprite; } }