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 Requisite v0.1.1
plugins/Requisite.dll
Decompiled 14 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.TextCore; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 Requisite { public static class Hint { private const float Refresh = 0.25f; internal static int Version; private static object lastHover; private static float nextHover; private static int hoverVersion = -1; private static string suffix; private static string lastIn; private static string lastOut; private static GameObject lastBare; private static float nextBare; private static int bareVersion = -1; private static string bareText = ""; private static readonly List<Ask> asks = new List<Ask>(); private static readonly List<MonoBehaviour> behaviours = new List<MonoBehaviour>(); private static readonly HashSet<object> owners = new HashSet<object>(); private static readonly List<ItemStand> stands = new List<ItemStand>(); private static readonly List<bool> filled = new List<bool>(); private static readonly Dictionary<Type, bool> modTypes = new Dictionary<Type, bool>(); private static readonly HashSet<Type> logged = new HashSet<Type>(); private static readonly Assembly game = typeof(Player).Assembly; private static readonly Rules.Look look = new Rules.Look(); private static int errors; public static string Extend(Hoverable hoverable, string text) { if (string.IsNullOrEmpty(text) || !Plugin.Enabled.Value) { return text; } try { float unscaledTime = Time.unscaledTime; if (hoverable != lastHover || unscaledTime >= nextHover || hoverVersion != Version) { lastHover = hoverable; nextHover = unscaledTime + 0.25f; hoverVersion = Version; string text2 = Lines((Component)(object)((hoverable is Component) ? hoverable : null)); if (text2 != suffix) { suffix = text2; lastIn = null; } } if (string.IsNullOrEmpty(suffix)) { return text; } if (lastIn == null || !string.Equals(text, lastIn, StringComparison.Ordinal)) { lastIn = text; lastOut = text + "\n" + suffix; } return lastOut; } catch (Exception e) { Failed(e); suffix = null; return text; } } public static string Bare(Player player) { if (!Plugin.Enabled.Value || Plugin.Tools.Value == ToolHint.Off) { return ""; } try { if ((Object)(object)TextViewer.instance != (Object)null && TextViewer.instance.IsVisible()) { return ""; } GameObject val = (((Object)(object)player != (Object)null) ? ((Humanoid)player).GetHoverObject() : null); if ((Object)(object)val == (Object)null) { lastBare = null; return ""; } Words.Ensure(); float unscaledTime = Time.unscaledTime; if ((Object)(object)val != (Object)(object)lastBare || unscaledTime >= nextBare || bareVersion != Version) { lastBare = val; nextBare = unscaledTime + 0.25f; bareVersion = Version; asks.Clear(); BareTool(val, player); bareText = ((asks.Count > 0) ? (Rules.Format(asks, Look(player)) ?? "") : ""); } return bareText; } catch (Exception e) { Failed(e); return ""; } } private static void Failed(Exception e) { if (errors++ < 5) { Plugin.Warn("hover lines: " + e); } } private static string Lines(Component c) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)c == (Object)null || (Object)(object)localPlayer == (Object)null) { return null; } Words.Ensure(); asks.Clear(); Collect(c, localPlayer); if (Plugin.OtherMods.Value) { ModComponents(c); } if (asks.Count <= 0) { return null; } return Rules.Format(asks, Look(localPlayer)); } private static void Add(Ask ask) { if (ask != null) { asks.Add(ask); } } private static void Collect(Component c, Player player) { //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) OfferingBowl val = (OfferingBowl)(object)((c is OfferingBowl) ? c : null); if (val == null) { ItemStand val2 = (ItemStand)(object)((c is ItemStand) ? c : null); if (val2 == null) { Door val3 = (Door)(object)((c is Door) ? c : null); if (val3 == null) { Turret val4 = (Turret)(object)((c is Turret) ? c : null); if (val4 == null) { Switch val5 = (Switch)(object)((c is Switch) ? c : null); if (val5 == null) { Character val6 = (Character)(object)((c is Character) ? c : null); if (val6 == null) { MineRock val7 = (MineRock)(object)((c is MineRock) ? c : null); if (val7 == null) { MineRock5 val8 = (MineRock5)(object)((c is MineRock5) ? c : null); if (val8 != null) { Tool(val8.m_minToolTier, val8.m_damageModifiers, player); } } else { Tool(val7.m_minToolTier, val7.m_damageModifiers, player); } } else if (Plugin.Saddles.Value) { Tameable component = ((Component)val6).GetComponent<Tameable>(); if ((Object)(object)component != (Object)null) { Add(Rules.Saddle(component, component.IsTamed(), component.HaveSaddle())); } } } else { Owners(val5); } } else if (Plugin.FuelAndAmmo.Value) { int ammo = val4.GetAmmo(); Add(Rules.Ammo(val4, ammo, (ammo > 0) ? SharedName(val4.GetAmmoType()) : null)); } } else if (Plugin.Doors.Value) { Add(Rules.Key(val3, Closed(val3))); } } else if (Plugin.Stands.Value) { Add(Rules.Stand(val2, val2.HaveAttachment())); } } else if (Plugin.Altars.Value) { if (val.m_useItemStands) { Stands.Near(val, stands, filled); Add(Rules.OfferingStands(val, stands, filled)); } else { Add(Rules.Offering(val)); } } } private static bool Closed(Door door) { if ((Object)(object)door.m_nview != (Object)null && door.m_nview.IsValid()) { return door.m_nview.GetZDO().GetInt(ZDOVars.s_state, 0) == 0; } return false; } private static string SharedName(string prefab) { if (string.IsNullOrEmpty(prefab) || (Object)(object)ObjectDB.instance == (Object)null) { return null; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefab); return Rules.NameOf(((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null); } private static void Owners(Switch button) { owners.Clear(); Visit((Delegate)(object)button.m_onHover); Visit((Delegate)(object)button.m_onUse); } private static void Visit(Delegate callback) { if ((object)callback == null) { return; } Delegate[] invocationList = callback.GetInvocationList(); for (int i = 0; i < invocationList.Length; i++) { object? target = invocationList[i].Target; Component val = (Component)((target is Component) ? target : null); if (val == null || (Object)(object)val == (Object)null || !owners.Add(val)) { continue; } ShieldGenerator val2 = (ShieldGenerator)(object)((val is ShieldGenerator) ? val : null); if (val2 != null) { if (Plugin.FuelAndAmmo.Value) { Add(Rules.Fuel(val2, val2.GetFuel())); } } else if (Plugin.OtherMods.Value && IsModType(((object)val).GetType())) { AddMod(val); } } } private static void ModComponents(Component c) { if (IsModType(((object)c).GetType())) { AddMod(c); } c.GetComponents<MonoBehaviour>(behaviours); foreach (MonoBehaviour behaviour in behaviours) { if ((Object)(object)behaviour != (Object)null && (object)behaviour != c && (behaviour is Hoverable || behaviour is Interactable) && IsModType(((object)behaviour).GetType())) { AddMod(behaviour); } } behaviours.Clear(); } private static void AddMod(object component) { Type type = component.GetType(); if (Plugin.DebugLog.Value && logged.Add(type)) { Plugin.Log("mod object " + type.FullName + " (" + type.Assembly.GetName().Name + "): " + string.Join(", ", Rules.PlanText(type))); } foreach (Ask item in Rules.ModFields(component)) { asks.Add(item); } } private static bool IsModType(Type type) { if (modTypes.TryGetValue(type, out var value)) { return value; } value = true; Type type2 = type; while (type2 != null) { Assembly assembly = type2.Assembly; if (assembly == game) { value = false; break; } string text = assembly.GetName().Name ?? ""; if (type2 == type && (text.StartsWith("assembly_", StringComparison.Ordinal) || text.StartsWith("Unity", StringComparison.Ordinal) || text == "mscorlib" || text.StartsWith("System", StringComparison.Ordinal))) { value = false; break; } type2 = type2.BaseType; } if (value && type.Assembly == typeof(Hint).Assembly) { value = false; } modTypes[type] = value; return value; } private static void BareTool(GameObject go, Player player) { //IL_0017: 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_005d: 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) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) TreeBase componentInParent = go.GetComponentInParent<TreeBase>(); if ((Object)(object)componentInParent != (Object)null) { Tool(componentInParent.m_minToolTier, componentInParent.m_damageModifiers, player); return; } TreeLog componentInParent2 = go.GetComponentInParent<TreeLog>(); if ((Object)(object)componentInParent2 != (Object)null) { Tool(componentInParent2.m_minToolTier, componentInParent2.m_damages, player); return; } MineRock componentInParent3 = go.GetComponentInParent<MineRock>(); if ((Object)(object)componentInParent3 != (Object)null) { Tool(componentInParent3.m_minToolTier, componentInParent3.m_damageModifiers, player); return; } MineRock5 componentInParent4 = go.GetComponentInParent<MineRock5>(); if ((Object)(object)componentInParent4 != (Object)null) { Tool(componentInParent4.m_minToolTier, componentInParent4.m_damageModifiers, player); return; } Destructible componentInParent5 = go.GetComponentInParent<Destructible>(); if ((Object)(object)componentInParent5 != (Object)null) { Tool(componentInParent5.m_minToolTier, componentInParent5.m_damages, player); } } private static void Tool(int minTier, DamageModifiers mods, Player player) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) if (Plugin.Tools.Value != ToolHint.Off && minTier > 0) { bool usedUp; ItemDrop val = Catalog.Weakest(mods, minTier, out usedUp); if (!((Object)(object)val == (Object)null)) { bool lockedTools = (Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGlobalKey((GlobalKeys)29); bool works; ItemData best = Rules.BestTool(((Humanoid)player).GetInventory(), mods, minTier, Catalog.HitsOf, lockedTools, Game.m_worldLevel, out works); Add(Rules.Tool(minTier, val, usedUp, best, works, Plugin.Tools.Value == ToolHint.Always)); } } } private static Rules.Look Look(Player player) { Inventory inventory = ((Humanoid)player).GetInventory(); look.Word = (string key, string[] words) => (words != null && words.Length != 0) ? Localization.instance.Localize("$" + key, words) : Localization.instance.Localize("$" + key); look.Item = (string name) => Localization.instance.Localize(name); look.Icon = Icons.Tag; look.Have = ((Plugin.ShowHave.Value && inventory != null) ? ((Func<string, int>)((string name) => inventory.CountItems(name, -1, true))) : null); look.MaxItems = Plugin.MaxItems.Value; return look; } } internal static class Stands { private static readonly List<ItemStand> all = new List<ItemStand>(); internal static void Add(ItemStand stand) { if ((Object)(object)stand != (Object)null) { all.Add(stand); } } internal static void Near(OfferingBowl bowl, List<ItemStand> stands, List<bool> filled) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) stands.Clear(); filled.Clear(); Vector3 position = ((Component)bowl).transform.position; float itemstandMaxRange = bowl.m_itemstandMaxRange; string text = bowl.m_itemStandPrefix ?? ""; for (int num = all.Count - 1; num >= 0; num--) { ItemStand val = all[num]; if ((Object)(object)val == (Object)null) { all[num] = all[all.Count - 1]; all.RemoveAt(all.Count - 1); } else if (((Component)val).gameObject.activeInHierarchy && !(Vector3.Distance(position, ((Component)val).transform.position) > itemstandMaxRange) && Utils.CustomStartsWith(((Object)((Component)val).gameObject).name, text)) { stands.Add(val); filled.Add(val.HaveAttachment()); } } } } internal static class Catalog { private static ObjectDB db; private static int loadedItems = -1; private static readonly Dictionary<string, (ItemDrop item, bool usedUp)> weakest = new Dictionary<string, (ItemDrop, bool)>(); private static readonly List<ItemDrop> items = new List<ItemDrop>(); private static readonly HashSet<string> obtainable = new HashSet<string>(); private static readonly Dictionary<GameObject, Aoe[]> blasts = new Dictionary<GameObject, Aoe[]>(); private static readonly List<Aoe> found = new List<Aoe>(); private static readonly HashSet<GameObject> seen = new HashSet<GameObject>(); internal static ItemDrop Weakest(DamageModifiers mods, int tier, out bool usedUp) { //IL_0039: 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) usedUp = false; ObjectDB instance = ObjectDB.instance; if ((Object)(object)instance == (Object)null) { return null; } if ((Object)(object)instance != (Object)(object)db || instance.m_items.Count != loadedItems) { Load(instance); } string text = Key(mods, tier); if (!weakest.TryGetValue(text, out (ItemDrop, bool) value)) { bool usedUp2; ItemDrop val = Rules.Weakest(items, mods, tier, (ItemDrop d) => HitsOf(d.m_itemData), (ItemDrop d) => obtainable.Contains(Rules.NameOf(d)), out usedUp2); value = (val, usedUp2); weakest[text] = value; Plugin.Debug(string.Format("tool for tier {0} ({1}): {2}", tier, text, ((Object)(object)val != (Object)null) ? (val.m_itemData.m_shared.m_name + (usedUp2 ? ", used up" : "")) : "nothing the player can get")); } usedUp = value.Item2; return value.Item1; } private static string Key(DamageModifiers m, int tier) { //IL_0017: 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_0022: Expected I4, but got Unknown //IL_0025: 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_0030: Expected I4, but got Unknown //IL_0033: 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_003e: Expected I4, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected I4, but got Unknown //IL_004f: 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_005a: Expected I4, but got Unknown //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected I4, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected I4, but got Unknown //IL_0079: 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: Expected I4, but got Unknown //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected I4, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected I4, but got Unknown return $"{tier}:{(int)m.m_blunt},{(int)m.m_slash},{(int)m.m_pierce},{(int)m.m_chop},{(int)m.m_pickaxe},{(int)m.m_fire},{(int)m.m_frost},{(int)m.m_lightning},{(int)m.m_poison},{(int)m.m_spirit}"; } internal static List<Hit> HitsOf(ItemData item) { List<Hit> list = new List<Hit>(); SharedData val = item?.m_shared; if (val == null) { return list; } GameObject val2 = ((val.m_attack != null) ? val.m_attack.m_attackProjectile : null); GameObject val3 = ((val.m_secondaryAttack != null) ? val.m_secondaryAttack.m_attackProjectile : null); Rules.OwnHit(val, (Object)(object)val2 != (Object)null || (Object)(object)val3 != (Object)null, list); Aoe[] array = BlastsOf(val2); for (int i = 0; i < array.Length; i++) { Rules.AoeHit(array[i], val, list); } array = BlastsOf(val3); for (int i = 0; i < array.Length; i++) { Rules.AoeHit(array[i], val, list); } return list; } private static Aoe[] BlastsOf(GameObject projectile) { if ((Object)(object)projectile == (Object)null) { return Array.Empty<Aoe>(); } if (blasts.TryGetValue(projectile, out var value)) { return value; } found.Clear(); seen.Clear(); Walk(projectile, 0); value = found.ToArray(); blasts[projectile] = value; return value; } private static void Walk(GameObject go, int depth) { if ((Object)(object)go == (Object)null || depth > 3 || !seen.Add(go)) { return; } Aoe[] componentsInChildren = go.GetComponentsInChildren<Aoe>(true); foreach (Aoe val in componentsInChildren) { if ((Object)(object)val != (Object)null && !found.Contains(val)) { found.Add(val); } } Projectile[] componentsInChildren2 = go.GetComponentsInChildren<Projectile>(true); foreach (Projectile val2 in componentsInChildren2) { if ((Object)(object)val2 == (Object)null) { continue; } Walk(val2.m_spawnOnHit, depth + 1); if (val2.m_randomSpawnOnHit == null) { continue; } foreach (GameObject item in val2.m_randomSpawnOnHit) { Walk(item, depth + 1); } } } private static void Load(ObjectDB current) { db = current; loadedItems = current.m_items.Count; weakest.Clear(); items.Clear(); obtainable.Clear(); foreach (GameObject item in current.m_items) { ItemDrop val = (((Object)(object)item != (Object)null) ? item.GetComponent<ItemDrop>() : null); if ((Object)(object)val != (Object)null) { items.Add(val); } } foreach (Recipe recipe in current.m_recipes) { string text = (((Object)(object)recipe != (Object)null && recipe.m_enabled) ? Rules.NameOf(recipe.m_item) : null); if (text != null) { obtainable.Add(text); } } ZNetScene instance = ZNetScene.instance; if (!((Object)(object)instance != (Object)null)) { return; } foreach (GameObject prefab in instance.m_prefabs) { Trader val2 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Trader>() : null); if ((Object)(object)val2 == (Object)null || val2.m_items == null) { continue; } foreach (TradeItem item2 in val2.m_items) { string text2 = ((item2 != null) ? Rules.NameOf(item2.m_prefab) : null); if (text2 != null) { obtainable.Add(text2); } } } } } internal static class Hooks { [HarmonyPatch(typeof(Hud), "UpdateCrosshair")] private static class Crosshair { private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Expected O, but got Unknown //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Expected O, but got Unknown MethodInfo methodInfo = AccessTools.Method(typeof(Hoverable), "GetHoverText", (Type[])null, (Type[])null); MethodInfo methodInfo2 = AccessTools.PropertySetter(typeof(TMP_Text), "text"); MethodInfo methodInfo3 = AccessTools.Method(typeof(Hint), "Extend", (Type[])null, (Type[])null); MethodInfo methodInfo4 = AccessTools.Method(typeof(Hint), "Bare", (Type[])null, (Type[])null); List<CodeInstruction> list = new List<CodeInstruction>(instructions); int num = 0; int num2 = 0; for (int i = 0; i < list.Count; i++) { if (num == 0 && CodeInstructionExtensions.Calls(list[i], methodInfo)) { CodeInstruction val = new CodeInstruction(OpCodes.Dup, (object)null); CodeInstructionExtensions.MoveLabelsFrom(val, list[i]); CodeInstructionExtensions.MoveBlocksFrom(val, list[i]); list.Insert(i, val); list.Insert(i + 2, new CodeInstruction(OpCodes.Call, (object)methodInfo3)); i += 2; num++; } else if (num2 == 0 && list[i].opcode == OpCodes.Ldstr && list[i].operand as string == "" && i + 1 < list.Count && CodeInstructionExtensions.Calls(list[i + 1], methodInfo2)) { CodeInstruction val2 = new CodeInstruction(OpCodes.Ldarg_1, (object)null); CodeInstructionExtensions.MoveLabelsFrom(val2, list[i]); CodeInstructionExtensions.MoveBlocksFrom(val2, list[i]); list[i] = val2; list.Insert(i + 1, new CodeInstruction(OpCodes.Call, (object)methodInfo4)); i++; num2++; } } HoverHooked = num == 1; BareHooked = num2 == 1; if (!HoverHooked) { Plugin.Warn("Hud.UpdateCrosshair: the hover text call was not found, the mod shows nothing"); } if (!BareHooked) { Plugin.Warn("Hud.UpdateCrosshair: the empty hover text was not found, no tool lines for trees and stumps"); } return list; } } [HarmonyPatch(typeof(ItemStand), "Awake")] private static class StandAwake { private static void Postfix(ItemStand __instance) { Stands.Add(__instance); } } [HarmonyPatch(typeof(Localization), "SetupLanguage")] private static class Language { private static void Postfix(Localization __instance, string language) { Words.Add(__instance, language); } } internal static bool HoverHooked; internal static bool BareHooked; } internal static class Icons { private static readonly Dictionary<Sprite, string> tags = new Dictionary<Sprite, string>(); private static readonly List<TMP_SpriteAsset> made = new List<TMP_SpriteAsset>(); private static readonly FieldInfo version = typeof(TMP_Asset).GetField("m_Version", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static Material baseMaterial; private static bool noMaterial; private static int serial; private static float madeScale; internal static string Tag(ItemDrop item) { if (!Plugin.ShowIcons.Value || !Rules.Live((Object)(object)item)) { return ""; } Sprite[] array = item.m_itemData?.m_shared?.m_icons; if (array == null || array.Length == 0 || (Object)(object)array[0] == (Object)null) { return ""; } float value = Plugin.IconSize.Value; if (Math.Abs(value - madeScale) > 0.001f) { Reset(value); } Sprite val = array[0]; if (tags.TryGetValue(val, out var value2)) { return value2; } try { value2 = Make(val, value); } catch (Exception ex) { value2 = ""; Plugin.Warn("icon of " + item.m_itemData.m_shared.m_name + " not made: " + ex.Message); } tags[val] = value2; return value2; } private static void Reset(float scale) { tags.Clear(); foreach (TMP_SpriteAsset item in made) { if ((Object)(object)item != (Object)null) { if ((Object)(object)((TMP_Asset)item).material != (Object)null) { Object.Destroy((Object)(object)((TMP_Asset)item).material); } Object.Destroy((Object)(object)item); } } made.Clear(); madeScale = scale; } private static string Make(Sprite sprite, float scale) { //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_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Expected O, but got Unknown //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Expected O, but got Unknown //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Expected O, but got Unknown Texture2D texture = sprite.texture; Material val = Material(); if ((Object)(object)texture == (Object)null || (Object)(object)val == (Object)null) { return ""; } Rect val2 = Area(sprite, (Texture)(object)texture); if (((Rect)(ref val2)).width < 1f || ((Rect)(ref val2)).height < 1f) { return ""; } TMP_SpriteAsset val3 = ScriptableObject.CreateInstance<TMP_SpriteAsset>(); ((Object)val3).name = "requisite_icon_" + ++serial; ((Object)val3).hideFlags = (HideFlags)61; version?.SetValue(val3, "1.1.0"); val3.spriteSheet = (Texture)(object)texture; GlyphMetrics val4 = default(GlyphMetrics); ((GlyphMetrics)(ref val4))..ctor(((Rect)(ref val2)).width, ((Rect)(ref val2)).height, 0f, ((Rect)(ref val2)).height * 0.8f, ((Rect)(ref val2)).width); TMP_SpriteGlyph val5 = new TMP_SpriteGlyph(0u, val4, new GlyphRect((int)((Rect)(ref val2)).x, (int)((Rect)(ref val2)).y, (int)((Rect)(ref val2)).width, (int)((Rect)(ref val2)).height), scale, 0) { sprite = sprite }; val3.spriteGlyphTable.Add(val5); val3.spriteCharacterTable.Add(new TMP_SpriteCharacter(65534u, val3, val5) { name = "icon" }); Material val6 = new Material(val) { name = ((Object)val3).name, hideFlags = (HideFlags)61 }; val6.SetTexture("_MainTex", (Texture)(object)texture); ((TMP_Asset)val3).material = val6; val3.UpdateLookupTables(); MaterialReferenceManager.AddSpriteAsset(val3); made.Add(val3); return "<sprite=\"" + ((Object)val3).name + "\" index=0> "; } private static Rect Area(Sprite sprite, Texture texture) { //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_00b8: 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) //IL_0021: 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_002e: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_0054: 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) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_009b: 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_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) try { return sprite.textureRect; } catch { Vector2[] uv = sprite.uv; if (uv == null || uv.Length == 0) { return sprite.rect; } Vector2 val = uv[0]; Vector2 val2 = uv[0]; Vector2[] array = uv; foreach (Vector2 val3 in array) { val = Vector2.Min(val, val3); val2 = Vector2.Max(val2, val3); } return new Rect(val.x * (float)texture.width, val.y * (float)texture.height, (val2.x - val.x) * (float)texture.width, (val2.y - val.y) * (float)texture.height); } } private static Material Material() { //IL_0119: 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_012b: Expected O, but got Unknown if ((Object)(object)baseMaterial != (Object)null || noMaterial) { return baseMaterial; } try { baseMaterial = (((Object)(object)TMP_Settings.defaultSpriteAsset != (Object)null) ? ((TMP_Asset)TMP_Settings.defaultSpriteAsset).material : null); } catch { baseMaterial = null; } if ((Object)(object)baseMaterial == (Object)null && (Object)(object)Hud.instance != (Object)null && (Object)(object)Hud.instance.m_hoverName != (Object)null && (Object)(object)((TMP_Text)Hud.instance.m_hoverName).spriteAsset != (Object)null) { baseMaterial = ((TMP_Asset)((TMP_Text)Hud.instance.m_hoverName).spriteAsset).material; } if ((Object)(object)baseMaterial == (Object)null) { TMP_SpriteAsset[] array = Resources.FindObjectsOfTypeAll<TMP_SpriteAsset>(); foreach (TMP_SpriteAsset val in array) { if ((Object)(object)val != (Object)null && (Object)(object)((TMP_Asset)val).material != (Object)null && !made.Contains(val)) { baseMaterial = ((TMP_Asset)val).material; break; } } } if ((Object)(object)baseMaterial == (Object)null) { Shader val2 = Shader.Find("TextMeshPro/Sprite"); if ((Object)(object)val2 != (Object)null) { baseMaterial = new Material(val2) { hideFlags = (HideFlags)61 }; } } if ((Object)(object)baseMaterial == (Object)null) { noMaterial = true; Plugin.Warn("no TextMeshPro sprite material: item icons are off"); } else { string[] obj2 = new string[5] { "icon material: ", ((Object)baseMaterial).name, " (", null, null }; Shader shader = baseMaterial.shader; obj2[3] = ((shader != null) ? ((Object)shader).name : null); obj2[4] = ")"; Plugin.Debug(string.Concat(obj2)); } return baseMaterial; } } internal enum ToolHint { Off, WhenTooWeak, Always } [BepInPlugin("chistix.requisite", "Requisite", "0.1.1")] public sealed class Plugin : BaseUnityPlugin { public const string Guid = "chistix.requisite"; public const string Version = "0.1.1"; private static ManualLogSource log; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> ShowHave; internal static ConfigEntry<bool> ShowIcons; internal static ConfigEntry<bool> Altars; internal static ConfigEntry<bool> Stands; internal static ConfigEntry<bool> Doors; internal static ConfigEntry<bool> FuelAndAmmo; internal static ConfigEntry<bool> Saddles; internal static ConfigEntry<bool> OtherMods; internal static ConfigEntry<bool> DebugLog; internal static ConfigEntry<float> IconSize; internal static ConfigEntry<int> MaxItems; internal static ConfigEntry<ToolHint> Tools; private static GUIStyle centred; private void Awake() { //IL_02b6: Unknown result type (might be due to invalid IL or missing references) log = ((BaseUnityPlugin)this).Logger; ConfigurationManagerAttributes tags = new ConfigurationManagerAttributes { CustomDrawer = Stepper }; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, D("Show the items objects take under the hover text.", "Показывать под подсказкой наведения, какой предмет нужен объекту.")); ShowHave = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowHave", true, D("Add how many the player has: (you have 1).", "Дописывать, сколько есть у игрока: (у вас 1).")); ShowIcons = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowIcons", true, D("The item's icon before its name.", "Иконка предмета перед названием.")); IconSize = ((BaseUnityPlugin)this).Config.Bind<float>("General", "IconSize", 1.25f, D("Icon height, in the height of the text's capital letters.", "Высота иконки в высотах заглавных букв текста.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.8f, 1.6f))); MaxItems = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxItems", 4, D("When an object takes one of several items (ballista ammo, shield generator fuel): how many lines at most; the ones the player has come first.", "Когда объекту подходит любой из нескольких предметов (снаряды баллисты, топливо щита): сколько строк самое большее; сначала те, что есть у игрока.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10))); Altars = ((BaseUnityPlugin)this).Config.Bind<bool>("Objects", "Altars", true, D("Summoning altars: the boss item and how many (Eikthyr: deer trophies), and altars with stands (what is still missing, stands filled).", "Алтари призыва: предмет и сколько (Эйктюр: трофеи оленя), и алтари с подставками (чего не хватает, сколько подставок заполнено).")); Stands = ((BaseUnityPlugin)this).Config.Bind<bool>("Objects", "ItemStands", true, D("Empty stands that take only certain items: sacrificial stones (boss trophies), altar stands.", "Пустые подставки, которые принимают только определённые предметы: жертвенные камни (трофеи боссов), подставки алтарей.")); Doors = ((BaseUnityPlugin)this).Config.Bind<bool>("Objects", "Doors", true, D("Locked doors: the key (crypt key, sealbreaker...).", "Запертые двери: ключ (ключ от склепа, печать...).")); FuelAndAmmo = ((BaseUnityPlugin)this).Config.Bind<bool>("Objects", "FuelAndAmmo", true, D("Shield generator fuel, ballista and turret ammo (with ammo in: only that kind).", "Топливо щитового генератора, снаряды баллисты и турелей (если заряжено - только этот вид).")); Saddles = ((BaseUnityPlugin)this).Config.Bind<bool>("Objects", "Saddles", true, D("Tamed animals that can be ridden and have no saddle on: the saddle.", "Приручённые звери, на которых можно ездить, без седла: седло.")); OtherMods = ((BaseUnityPlugin)this).Config.Bind<bool>("Objects", "OtherMods", true, D("Other mods' objects (custom bosses' altars, locked gates...): the item fields of their components.", "Объекты других модов (алтари кастомных боссов, запертые ворота...): поля предметов их компонентов.")); Tools = ((BaseUnityPlugin)this).Config.Bind<ToolHint>("Objects", "ToolTier", ToolHint.WhenTooWeak, D("Rocks, ores, trees, stumps: the tool tier they need. WhenTooWeak: only when your best tool cannot break it. Always: always. Off: never.", "Камни, руда, деревья, пни: какой уровень инструмента нужен. WhenTooWeak: только когда лучший ваш инструмент его не берёт. Always: всегда. Off: никогда.", null, tags)); DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DebugLog", false, D("More details in the log (which fields of other mods' objects are read).", "Подробности в журнал (какие поля объектов других модов читаются).")); ((BaseUnityPlugin)this).Config.SettingChanged += delegate { Hint.Version++; }; new Harmony("chistix.requisite").PatchAll(typeof(Plugin).Assembly); Log("Requisite 0.1.1" + (Hooks.HoverHooked ? "" : " - hover text not hooked")); } private static ConfigDescription D(string en, string ru, AcceptableValueBase values = null, object tags = null) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown return new ConfigDescription(en + "\n" + ru, values, (tags == null) ? Array.Empty<object>() : new object[1] { tags }); } internal static void Stepper(ConfigEntryBase entry) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown Array values = Enum.GetValues(entry.SettingType); if (values.Length == 0) { GUILayout.Label(entry.BoxedValue?.ToString() ?? "", Array.Empty<GUILayoutOption>()); return; } int num = Array.IndexOf(values, entry.BoxedValue); if (centred == null) { centred = new GUIStyle(GUI.skin.label) { alignment = (TextAnchor)4 }; } if (GUILayout.Button("‹", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(28f) })) { entry.BoxedValue = values.GetValue((Math.Max(num, 0) - 1 + values.Length) % values.Length); } GUILayout.Label(entry.BoxedValue?.ToString() ?? "", centred, (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.MinWidth(120f), GUILayout.ExpandWidth(true) }); if (GUILayout.Button("›", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(28f) })) { entry.BoxedValue = values.GetValue((num + 1) % values.Length); } } internal static void Log(string text) { ManualLogSource obj = log; if (obj != null) { obj.LogInfo((object)text); } } internal static void Warn(string text) { ManualLogSource obj = log; if (obj != null) { obj.LogWarning((object)text); } } internal static void Debug(string text) { if (DebugLog != null && DebugLog.Value) { ManualLogSource obj = log; if (obj != null) { obj.LogInfo((object)text); } } } } internal sealed class ConfigurationManagerAttributes { public Action<ConfigEntryBase> CustomDrawer; } internal enum Kind { Offering, Stand, Key, Fuel, Ammo, Saddle, Tool, Mod } internal struct Hit { public int Tier; public DamageTypes Damage; public bool UsedUp; } internal sealed class Need { public ItemDrop Item; public string Name; public int Amount; } internal sealed class Ask { public Kind Kind; public readonly List<Need> Items = new List<Need>(); public int Placed = -1; public int Total = -1; public int Tier = -1; public bool UsedUp; public bool HasTool; public string Best; public string Source; } internal static class Rules { private sealed class Plan { public FieldInfo Field; public bool List; public FieldInfo Amount; public string Source; } internal sealed class Look { public Func<string, string[], string> Word; public Func<string, string> Item; public Func<ItemDrop, string> Icon; public Func<string, int> Have; public int MaxItems = 4; } internal static Func<Object, bool> Alive = (Object o) => Object.op_Implicit(o); private static readonly string[] Given = new string[41] { "drop", "result", "reward", "output", "product", "spawn", "loot", "return", "give", "gift", "prize", "yield", "craft", "create", "produce", "made", "make", "visual", "display", "show", "icon", "current", "last", "prev", "attached", "placed", "stored", "held", "hold", "equip", "loaded", "inside", "contain", "unarmed", "default", "fallback", "debug", "test", "fake", "ghost", "preview" }; private static readonly string[] TakenWords = new string[35] { "key", "fuel", "ammo", "boss", "summon", "offer", "sacrific", "tribute", "require", "need", "cost", "pay", "price", "fee", "toll", "bait", "feed", "food", "consum", "input", "ingredient", "accept", "allow", "support", "insert", "socket", "charge", "activat", "use", "trophy", "lock", "unlock", "open", "token", "ticket" }; private static readonly string[] Objects = new string[19] { "altar", "offer", "summon", "shrine", "sacrific", "tribute", "lock", "door", "gate", "portal", "pedestal", "bowl", "brazier", "turret", "generator", "totem", "ritual", "obelisk", "seal" }; private static readonly string[] Amounts = new string[12] { "count", "amount", "num", "number", "quantity", "cost", "required", "needed", "need", "stack", "items", "price" }; private static readonly string[] NotAmounts = new string[34] { "max", "min", "level", "tier", "time", "delay", "range", "radius", "health", "damage", "index", "current", "placed", "have", "left", "stage", "state", "cooldown", "chance", "percent", "distance", "offset", "id", "hash", "version", "layer", "mask", "quality", "variant", "seed", "spawn", "drop", "reward", "result" }; private const int MaxAsksPerObject = 3; private static readonly Dictionary<Type, Plan[]> plans = new Dictionary<Type, Plan[]>(); internal static bool Live(Object o) { if (o != null) { return Alive(o); } return false; } internal static string NameOf(ItemDrop item) { if (!Live((Object)(object)item)) { return null; } string text = item.m_itemData?.m_shared?.m_name; if (!string.IsNullOrEmpty(text)) { return text; } return null; } private static Ask One(Kind kind, ItemDrop item, int amount) { string text = NameOf(item); if (text == null || amount <= 0) { return null; } return new Ask { Kind = kind, Items = { new Need { Item = item, Name = text, Amount = amount } } }; } private static Ask AnyOf(Kind kind, IEnumerable items, int amount, IEnumerable except = null) { if (items == null || amount <= 0) { return null; } HashSet<string> hashSet = null; if (except != null) { foreach (object item2 in except) { string text = NameOf((ItemDrop)((item2 is ItemDrop) ? item2 : null)); if (text != null) { (hashSet ?? (hashSet = new HashSet<string>())).Add(text); } } } Ask ask = new Ask { Kind = kind }; HashSet<string> hashSet2 = new HashSet<string>(); foreach (object item3 in items) { ItemDrop item = (ItemDrop)((item3 is ItemDrop) ? item3 : null); string text2 = NameOf(item); if (text2 != null && (hashSet == null || !hashSet.Contains(text2)) && hashSet2.Add(text2)) { ask.Items.Add(new Need { Item = item, Name = text2, Amount = amount }); } } if (ask.Items.Count <= 0) { return null; } return ask; } internal static Ask Offering(OfferingBowl bowl) { if (bowl == null || bowl.m_useItemStands) { return null; } return One(Kind.Offering, bowl.m_bossItem, Math.Max(1, bowl.m_bossItems)); } internal static Ask OfferingStands(OfferingBowl bowl, IList<ItemStand> stands, IList<bool> filled) { if (bowl == null || !bowl.m_useItemStands || stands == null || stands.Count == 0) { return null; } Ask ask = new Ask { Kind = Kind.Offering, Total = stands.Count, Placed = 0 }; Dictionary<string, Need> dictionary = new Dictionary<string, Need>(); for (int i = 0; i < stands.Count; i++) { if (filled != null && i < filled.Count && filled[i]) { ask.Placed++; continue; } ItemDrop item = FirstNamed(stands[i]?.m_supportedItems); string text = NameOf(item); if (text != null) { if (dictionary.TryGetValue(text, out var value)) { value.Amount++; continue; } value = new Need { Item = item, Name = text, Amount = 1 }; dictionary.Add(text, value); ask.Items.Add(value); } } if (ask.Placed >= ask.Total) { return null; } return ask; } private static ItemDrop FirstNamed(List<ItemDrop> items) { if (items == null) { return null; } foreach (ItemDrop item in items) { if (NameOf(item) != null) { return item; } } return null; } internal static Ask Stand(ItemStand stand, bool filled) { if (stand == null || filled || stand.m_supportedItems == null || stand.m_supportedItems.Count == 0) { return null; } return AnyOf(Kind.Stand, stand.m_supportedItems, 1, stand.m_unsupportedItems); } internal static Ask Key(Door door, bool closed) { if (door != null && closed) { return One(Kind.Key, door.m_keyItem, 1); } return null; } internal static Ask Fuel(ShieldGenerator generator, float fuel) { if (generator == null || fuel > (float)(generator.m_maxFuel - 1)) { return null; } return AnyOf(Kind.Fuel, generator.m_fuelItems, 1); } internal static Ask Ammo(Turret turret, int ammo, string loadedName) { //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_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) if (turret == null || !turret.m_targetEnemies || ammo >= turret.m_maxAmmo || turret.m_allowedAmmo == null) { return null; } List<ItemDrop> list = new List<ItemDrop>(); foreach (AmmoType item in turret.m_allowedAmmo) { if (ammo <= 0 || loadedName == null || !(NameOf(item.m_ammo) != loadedName)) { list.Add(item.m_ammo); } } return AnyOf(Kind.Ammo, list, 1); } internal static Ask Saddle(Tameable tameable, bool tamed, bool haveSaddle) { if (tameable == null || !tamed || haveSaddle || !Live((Object)(object)tameable.m_saddle)) { return null; } return One(Kind.Saddle, tameable.m_saddleItem, 1); } internal static float Taken(DamageModifiers mods, DamageTypes d) { //IL_0005: 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_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_0022: 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) //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_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_004d: 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_005e: 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_006a: 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_0071: 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_0082: 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_008e: 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_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: 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_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) return Math.Max(0f, d.m_damage) + T(d.m_blunt, mods.m_blunt) + T(d.m_slash, mods.m_slash) + T(d.m_pierce, mods.m_pierce) + T(d.m_chop, mods.m_chop) + T(d.m_pickaxe, mods.m_pickaxe) + T(d.m_fire, mods.m_fire) + T(d.m_frost, mods.m_frost) + T(d.m_lightning, mods.m_lightning) + T(d.m_poison, mods.m_poison) + T(d.m_spirit, mods.m_spirit); } private static float T(float damage, DamageModifier m) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Invalid comparison between Unknown and I4 //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 if (!(damage > 0f) || (int)m == 3 || (int)m == 4) { return 0f; } return damage; } private static bool IsHeld(ItemType type) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Invalid comparison between Unknown and I4 //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 if ((int)type != 3 && (int)type != 14 && (int)type != 22 && (int)type != 19) { return (int)type == 15; } return true; } private static bool UsedUp(SharedData s) { if (s?.m_attack != null) { return s.m_attack.m_consumeItem; } return false; } internal static void OwnHit(SharedData s, bool fires, List<Hit> hits) { //IL_0005: 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) if (s != null && (IsHeld(s.m_itemType) || fires || UsedUp(s))) { hits.Add(new Hit { Tier = s.m_toolTier, Damage = s.m_damages, UsedUp = UsedUp(s) }); } } internal static void AoeHit(Aoe aoe, SharedData s, List<Hit> hits) { //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_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) if (aoe != null && aoe.m_hitProps && s != null) { if (aoe.m_useAttackSettings) { hits.Add(new Hit { Tier = s.m_toolTier, Damage = s.m_damages, UsedUp = UsedUp(s) }); } else { hits.Add(new Hit { Tier = aoe.m_toolTier, Damage = aoe.m_damage, UsedUp = UsedUp(s) }); } } } internal static bool Breaks(IList<Hit> hits, DamageModifiers mods, int minTier) { //IL_001e: 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) if (hits == null) { return false; } foreach (Hit hit in hits) { if (hit.Tier >= minTier && Taken(mods, hit.Damage) > 0f) { return true; } } return false; } private static int TierOn(IList<Hit> hits, DamageModifiers mods) { //IL_0015: 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) int num = -1; if (hits != null) { foreach (Hit hit in hits) { if (Taken(mods, hit.Damage) > 0f && hit.Tier > num) { num = hit.Tier; } } } return num; } internal static ItemData BestTool(Inventory inventory, DamageModifiers mods, int minTier, Func<ItemData, List<Hit>> hitsOf, bool lockedTools, int worldLevel, out bool works) { //IL_004d: 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) works = false; if (inventory == null || hitsOf == null) { return null; } ItemData result = null; int num = -1; foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem?.m_shared != null && (!lockedTools || allItem.m_worldLevel >= worldLevel)) { List<Hit> hits = hitsOf(allItem); if (Breaks(hits, mods, minTier)) { works = true; return allItem; } int num2 = TierOn(hits, mods); if (num2 > num) { result = allItem; num = num2; } } } return result; } internal static ItemDrop Weakest(IEnumerable<ItemDrop> items, DamageModifiers mods, int minTier, Func<ItemDrop, List<Hit>> hitsOf, Func<ItemDrop, bool> obtainable, out bool usedUp) { //IL_0089: 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_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: 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) usedUp = false; if (items == null || hitsOf == null) { return null; } ItemDrop val = null; bool flag = false; int num = 0; float num2 = 0f; foreach (ItemDrop item in items) { string text = NameOf(item); if (text == null || (obtainable != null && !obtainable(item))) { continue; } List<Hit> list = hitsOf(item); if (list == null) { continue; } int num3 = int.MaxValue; float num4 = 0f; bool flag2 = false; foreach (Hit item2 in list) { float num5 = Taken(mods, item2.Damage); if (item2.Tier < minTier || num5 <= 0f) { continue; } DamageTypes damage; if (item2.Tier >= num3) { if (item2.Tier != num3) { continue; } damage = item2.Damage; if (!(num5 / Math.Max(1f, ((DamageTypes)(ref damage)).GetTotalDamage()) > num4)) { continue; } } num3 = item2.Tier; damage = item2.Damage; num4 = num5 / Math.Max(1f, ((DamageTypes)(ref damage)).GetTotalDamage()); flag2 = item2.UsedUp; } if (num3 != int.MaxValue && (val == null || (!flag2 && flag) || (flag2 == flag && (num3 < num || (num3 == num && (num4 > num2 + 0.0001f || (Math.Abs(num4 - num2) <= 0.0001f && string.CompareOrdinal(text, NameOf(val)) < 0))))))) { val = item; flag = flag2; num = num3; num2 = num4; } } usedUp = flag; return val; } internal static Ask Tool(int minTier, ItemDrop sample, bool usedUp, ItemData best, bool bestWorks, bool always) { string text = NameOf(sample); if (minTier <= 0 || text == null) { return null; } if (bestWorks && !always) { return null; } return new Ask { Kind = Kind.Tool, Tier = minTier, UsedUp = usedUp, HasTool = (best != null), Best = best?.m_shared?.m_name, Items = { new Need { Item = sample, Name = text, Amount = 1 } } }; } internal static List<Ask> ModFields(object component) { List<Ask> list = new List<Ask>(); if (component == null) { return list; } Plan[] array = PlanOf(component.GetType()); foreach (Plan plan in array) { if (list.Count >= 3) { break; } object value; try { value = plan.Field.GetValue(component); } catch { continue; } int amount = 1; if (plan.Amount != null) { try { amount = Math.Max(1, Convert.ToInt32(plan.Amount.GetValue(component))); } catch { amount = 1; } } Ask ask = (plan.List ? AnyOf(Kind.Mod, value as IEnumerable, amount) : One(Kind.Mod, (ItemDrop)((value is ItemDrop) ? value : null), amount)); if (ask != null) { ask.Source = plan.Source; list.Add(ask); } } return list; } internal static IReadOnlyList<string> PlanText(Type type) { List<string> list = new List<string>(); Plan[] array = PlanOf(type); foreach (Plan plan in array) { list.Add(plan.Field.Name + (plan.List ? "[]" : "") + ((plan.Amount != null) ? (" x " + plan.Amount.Name) : "")); } return list; } private static Plan[] PlanOf(Type type) { if (plans.TryGetValue(type, out var value)) { return value; } List<FieldInfo> list = new List<FieldInfo>(); List<FieldInfo> list2 = new List<FieldInfo>(); Type type2 = type; while (type2 != null && type2 != typeof(object) && !IsEngine(type2)) { FieldInfo[] fields = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (ItemField(fieldInfo.FieldType, out var _)) { list.Add(fieldInfo); } else if (IsInteger(fieldInfo.FieldType)) { list2.Add(fieldInfo); } } type2 = type2.BaseType; } bool flag = HasAny(Words(type.Name), Objects); List<Plan> list4 = new List<Plan>(); foreach (FieldInfo item in list) { List<string> words = Words(FieldName(item)); if (!HasAny(words, Given) && (HasAny(words, TakenWords) || flag)) { ItemField(item.FieldType, out var list5); list4.Add(new Plan { Field = item, List = list5, Source = type.Name + "." + item.Name }); } } foreach (Plan item2 in list4) { item2.Amount = AmountFor(item2.Field, list2, list4.Count == 1); } value = list4.ToArray(); plans[type] = value; return value; } private static FieldInfo AmountFor(FieldInfo item, List<FieldInfo> numbers, bool single) { List<string> list = Words(FieldName(item)); List<string> list2 = new List<string>(); foreach (string item2 in list) { if (item2 != "item" && item2 != "items" && item2 != "prefab" && item2 != "prefabs" && item2 != "drop") { list2.Add(item2); } } FieldInfo fieldInfo = null; FieldInfo result = null; int num = 0; foreach (FieldInfo number in numbers) { List<string> words = Words(FieldName(number)); if (HasAny(words, NotAmounts) || !HasAny(words, Amounts)) { continue; } if (list2.Count > 0 && StartsWithAll(words, list2)) { if (fieldInfo == null) { fieldInfo = number; } } else { result = number; num++; } } if (fieldInfo != null) { return fieldInfo; } if (!single || num != 1) { return null; } return result; } private static bool StartsWithAll(List<string> words, List<string> stem) { if (words.Count < stem.Count) { return false; } for (int i = 0; i < stem.Count; i++) { if (words[i] != stem[i]) { return false; } } return true; } private static bool ItemField(Type type, out bool list) { list = false; if (typeof(ItemDrop).IsAssignableFrom(type)) { return true; } if (type.IsArray && typeof(ItemDrop).IsAssignableFrom(type.GetElementType())) { list = true; return true; } if (type.IsGenericType && typeof(IEnumerable).IsAssignableFrom(type)) { Type[] genericArguments = type.GetGenericArguments(); if (genericArguments.Length == 1 && typeof(ItemDrop).IsAssignableFrom(genericArguments[0])) { list = true; return true; } } return false; } private static bool IsInteger(Type t) { if (!(t == typeof(int)) && !(t == typeof(short)) && !(t == typeof(byte)) && !(t == typeof(long)) && !(t == typeof(uint))) { return t == typeof(ushort); } return true; } private static bool IsEngine(Type t) { string text = t.Assembly.GetName().Name ?? ""; if (!(t == typeof(MonoBehaviour)) && !(t == typeof(Behaviour)) && !(t == typeof(Component)) && !text.StartsWith("UnityEngine", StringComparison.Ordinal) && !(text == "mscorlib")) { return text == "netstandard"; } return true; } private static string FieldName(FieldInfo f) { string text = f.Name; if (text.Length > 2 && text[0] == '<') { int num = text.IndexOf('>'); if (num > 1) { text = text.Substring(1, num - 1); } } return text; } internal static List<string> Words(string name) { List<string> words = new List<string>(); if (string.IsNullOrEmpty(name)) { return words; } if (name.StartsWith("m_", StringComparison.Ordinal) || name.StartsWith("s_", StringComparison.Ordinal)) { name = name.Substring(2); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < name.Length; i++) { char c = name[i]; if (!char.IsLetter(c)) { Flush(); continue; } if (char.IsUpper(c) && sb.Length > 0 && (!char.IsUpper(name[i - 1]) || (i + 1 < name.Length && char.IsLower(name[i + 1])))) { Flush(); } sb.Append(c); } Flush(); return words; void Flush() { if (sb.Length > 0) { words.Add(sb.ToString().ToLowerInvariant()); sb.Length = 0; } } } private static bool HasAny(List<string> words, string[] stems) { foreach (string word in words) { int num = 0; while (num < stems.Length) { string text = stems[num]; bool num2; if (text.Length > 3) { num2 = word.StartsWith(text, StringComparison.Ordinal); } else { if (word == text) { goto IL_0052; } num2 = word == text + "s"; } if (!num2) { num++; continue; } goto IL_0052; IL_0052: return true; } } return false; } internal static string Format(IList<Ask> asks, Look look) { if (asks == null || asks.Count == 0 || look == null) { return null; } StringBuilder stringBuilder = new StringBuilder(); foreach (Ask ask in asks) { if (ask == null) { continue; } if (stringBuilder.Length > 0) { stringBuilder.Append('\n'); } if (ask.Kind == Kind.Tool) { ToolLine(stringBuilder, ask, look); continue; } string text = ((ask.Kind == Kind.Saddle) ? "requisite_ride" : "requisite_need"); if (ask.Items.Count == 1) { stringBuilder.Append(look.Word(text, null)).Append(' '); ItemText(stringBuilder, ask.Items[0], look); } else if (ask.Items.Count > 1) { stringBuilder.Append(look.Word(text + "_any", null)); List<Need> list = new List<Need>(ask.Items); if (look.Have != null) { List<Need> list2 = new List<Need>(); List<Need> list3 = new List<Need>(); foreach (Need item in list) { ((look.Have(item.Name) > 0) ? list2 : list3).Add(item); } list = list2; list.AddRange(list3); } int num = Math.Min(list.Count, Math.Max(1, look.MaxItems)); for (int i = 0; i < num; i++) { stringBuilder.Append('\n'); ItemText(stringBuilder, list[i], look); } if (list.Count > num) { stringBuilder.Append('\n').Append(look.Word("requisite_more", new string[1] { (list.Count - num).ToString() })); } } if (ask.Total > 0) { if (ask.Items.Count > 0) { stringBuilder.Append('\n'); } stringBuilder.Append(look.Word("requisite_stands", new string[2] { ask.Placed.ToString(), ask.Total.ToString() })); } } if (stringBuilder.Length <= 0) { return null; } return stringBuilder.ToString(); } private static void ItemText(StringBuilder sb, Need need, Look look) { sb.Append((look.Icon != null) ? look.Icon(need.Item) : "").Append(look.Item(need.Name)).Append(" ×") .Append(need.Amount); if (look.Have != null) { sb.Append(" (").Append(look.Word("requisite_have", new string[1] { look.Have(need.Name).ToString() })).Append(')'); } } private static void ToolLine(StringBuilder sb, Ask ask, Look look) { if (ask.Items.Count == 0) { return; } Need need = ask.Items[0]; string value = ((look.Icon != null) ? look.Icon(need.Item) : ""); if (ask.UsedUp) { sb.Append(look.Word("requisite_mined", null)).Append(' ').Append(value) .Append(look.Item(need.Name)); if (look.Have != null) { sb.Append(" (").Append(look.Word("requisite_have", new string[1] { look.Have(need.Name).ToString() })).Append(')'); } } else { sb.Append(look.Word("requisite_tool", null)).Append(' ').Append(value) .Append(look.Item(need.Name)) .Append(' ') .Append(look.Word("requisite_or_better", null)); sb.Append(" ("); sb.Append((ask.HasTool && ask.Best != null) ? look.Word("requisite_yours", new string[1] { look.Item(ask.Best) }) : look.Word("requisite_none", null)); sb.Append(')'); } } } internal static class Words { private static Action<Localization, string, string> addWord; internal static readonly (string key, string en, string ru)[] Texts = new(string, string, string)[12] { ("requisite_need", "Requires:", "Нужно:"), ("requisite_need_any", "Requires one of:", "Нужно одно из:"), ("requisite_ride", "To ride:", "Для езды:"), ("requisite_ride_any", "To ride, one of:", "Для езды одно из:"), ("requisite_have", "you have $1", "у вас $1"), ("requisite_more", "... and $1 more", "... и ещё $1"), ("requisite_stands", "On the stands: $1/$2", "На подставках: $1/$2"), ("requisite_tool", "Requires a tool:", "Нужен инструмент:"), ("requisite_or_better", "or better", "или лучше"), ("requisite_mined", "Mined with:", "Добывается:"), ("requisite_yours", "yours: $1", "у вас: $1"), ("requisite_none", "you have none", "у вас нет") }; private static string added; private static Action<Localization, string, string> AddWord => addWord ?? (addWord = AccessTools.MethodDelegate<Action<Localization, string, string>>(AccessTools.Method(typeof(Localization), "AddWord", (Type[])null, (Type[])null), (object)null, true)); internal static void Ensure() { Localization instance = Localization.instance; if (instance != null) { string selectedLanguage = instance.GetSelectedLanguage(); if (selectedLanguage != added) { Add(instance, selectedLanguage); } } } internal static void Add(Localization localization, string language) { if (localization != null && AddWord != null) { added = language; bool flag = string.Equals(language, "Russian", StringComparison.OrdinalIgnoreCase); (string, string, string)[] texts = Texts; for (int i = 0; i < texts.Length; i++) { var (arg, text, text2) = texts[i]; AddWord(localization, arg, flag ? text2 : text); } } } } }