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 NatureTalisman v1.0.0
NatureTalisman.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace BubNatureTalisman; [NetworkCompatibility(/*Could not decode attribute arguments.*/)] [SynchronizationMode(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("bub.naturetalisman", "Nature Talisman", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string Guid = "bub.naturetalisman"; public const string Version = "1.0.0"; internal const string PrefabName = "BubNatureTalisman"; private const string BasePrefab = "AmberPearl"; internal const string KData = "bub_nt_zdo"; internal const string KPrefab = "bub_nt_prefab"; internal const string KLabel = "bub_nt_label"; internal const string KTime = "bub_nt_time"; internal const string KHp = "bub_nt_hp"; internal const string KMaxHp = "bub_nt_maxhp"; internal const string KSaddle = "bub_nt_saddle"; internal const string KPregnant = "bub_nt_pregnant"; internal const string KBaby = "bub_nt_baby"; internal const string KOwner = "bub_nt_ownername"; internal static ManualLogSource Log; internal static ConfigEntry<string> recipe; internal static ConfigEntry<int> stationLevel; internal static ConfigEntry<bool> allowBosses; internal static ConfigEntry<float> cooldown; internal static ConfigEntry<float> channelSeconds; internal static ConfigEntry<float> throwRange; internal static ConfigEntry<float> tier1MaxHealth; internal static ConfigEntry<float> tier2MaxHealth; internal static ConfigEntry<string> tierOverrides; private static ItemDrop talismanDrop; private static Sprite iconFull; private static Sprite iconEmpty; private void Awake() { //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; recipe = Admin("Recipe", "Requirements", "Iron:2:0,Crystal:1:1,AncientSeed:1:0,Silver:0:2", "Forge recipe as Item:CraftAmount:AmountPerUpgradeLevel, comma separated (prefab names). The talisman has 3 levels."); stationLevel = Admin("Recipe", "Forge level", 1, "Forge level to craft. Upgrading to level N needs forge level + N - 1.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 7)); allowBosses = Admin("Rules", "Allow bosses", value: false, "Allow storing tamed creatures marked as bosses."); cooldown = Admin("Rules", "Cooldown (seconds)", 5f, "Minimum time between two uses (store or release), per player.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 600f)); channelSeconds = Admin("Rules", "Capture time (seconds)", 1.5f, "How long the capture takes; taking damage interrupts it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f)); throwRange = Admin("Rules", "Throw range (meters)", 25f, "How far you can throw the talisman to release a creature.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(3f, 40f)); tier1MaxHealth = Admin("Sizes", "Small max base health", 300f, "Creatures with base health up to this fit a level 1 talisman."); tier2MaxHealth = Admin("Sizes", "Medium max base health", 1500f, "Up to this they need level 2; above, level 3."); tierOverrides = Admin("Sizes", "Overrides", "Asksvin:3", "Force a size for specific creatures, as Prefab:Level, comma separated (e.g. Lox:2,Asksvin:3)."); LoadIcons(); AddTranslations(); PrefabManager.OnVanillaPrefabsAvailable += CreateItem; recipe.SettingChanged += delegate { ApplyRecipe(); }; stationLevel.SettingChanged += delegate { ApplyRecipe(); }; SynchronizationManager.OnConfigurationSynchronized += delegate { ApplyRecipe(); }; Harmony val = new Harmony("bub.naturetalisman"); val.Patch((MethodBase)AccessTools.Method(typeof(Humanoid), "UseItem", (Type[])null, (Type[])null), Hm(typeof(Talisman), "UseItemPrefix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.Method(typeof(Tameable), "RPC_Command", (Type[])null, (Type[])null), (HarmonyMethod)null, Hm(typeof(Talisman), "CommandPostfix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.Method(typeof(ItemDrop), "TimedDestruction", (Type[])null, (Type[])null), Hm(typeof(Plugin), "TimedDestructionPrefix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.Method(typeof(ItemData), "GetIcon", (Type[])null, (Type[])null), (HarmonyMethod)null, Hm(typeof(Plugin), "GetIconPostfix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(typeof(ItemData))) { ParameterInfo[] parameters = declaredMethod.GetParameters(); if (declaredMethod.Name == "GetTooltip" && declaredMethod.IsStatic && parameters.Length > 0 && parameters[0].ParameterType == typeof(ItemData)) { val.Patch((MethodBase)declaredMethod, (HarmonyMethod)null, Hm(typeof(Plugin), "TooltipPostfix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } } private void Update() { Talisman.Tick(); } private void OnGUI() { Talisman.DrawGui(); } private ConfigEntry<T> Admin<T>(string section, string key, T value, string description, AcceptableValueBase range = null) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown ConfigurationManagerAttributes val = new ConfigurationManagerAttributes(); val.IsAdminOnly = true; return ((BaseUnityPlugin)this).Config.Bind<T>(section, key, value, new ConfigDescription(description, range, new object[1] { val })); } private static HarmonyMethod Hm(Type type, string name) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Expected O, but got Unknown return new HarmonyMethod(type.GetMethod(name, BindingFlags.Static | BindingFlags.NonPublic)); } private static void LoadIcons() { iconFull = LoadSprite("BubNatureTalisman.icon_full.png"); iconEmpty = LoadSprite("BubNatureTalisman.icon_empty.png"); } private static Sprite LoadSprite(string resource) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_0070: 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) try { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource); if (stream == null) { Log.LogWarning((object)("Ícone não encontrado: " + resource)); return null; } byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); ImageConversion.LoadImage(val, array); return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } catch (Exception ex) { Log.LogWarning((object)("Ícone " + resource + ": " + ex.Message)); return null; } } private static void GetIconPostfix(ItemData __instance, ref Sprite __result) { if (Talisman.IsTalisman(__instance)) { Sprite val = (Talisman.IsFull(__instance) ? iconFull : iconEmpty); if ((Object)(object)val != (Object)null) { __result = val; } } } private static void AddTranslations() { CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); Dictionary<string, string> dictionary = new Dictionary<string, string>(); Dictionary<string, string> dictionary2 = new Dictionary<string, string>(); T(dictionary, dictionary2, "item_bub_naturetalisman", "Nature Talisman", "Talismã da Natureza"); T(dictionary, dictionary2, "item_bub_naturetalisman_desc", "Binds a tamed creature's spirit so it can travel with you. Use while aiming at your tame to bind it; use again to throw the talisman and release it where you aim.", "Prende o espírito de um animal domado para que ele viaje com você. Use mirando no seu domado para guardá-lo; use de novo para arremessar o talismã e soltá-lo onde mirar."); T(dictionary, dictionary2, "bub_nt_contains", "Holds", "Contém"); T(dictionary, dictionary2, "bub_nt_health", "Health", "Vida"); T(dictionary, dictionary2, "bub_nt_saddle", "saddled", "com sela"); T(dictionary, dictionary2, "bub_nt_pregnant", "pregnant", "prenha"); T(dictionary, dictionary2, "bub_nt_baby", "young", "filhote"); T(dictionary, dictionary2, "bub_nt_owner", "Owner", "Dono"); T(dictionary, dictionary2, "bub_nt_stored_for", "Stored for", "Guardado há"); T(dictionary, dictionary2, "bub_nt_days", "days", "dias"); T(dictionary, dictionary2, "bub_nt_hours", "hours", "horas"); T(dictionary, dictionary2, "bub_nt_empty", "Empty. Use while aiming at one of your tamed creatures.", "Vazio. Use mirando num animal domado seu."); T(dictionary, dictionary2, "bub_nt_fits", "Fits creatures up to size", "Guarda animais até o porte"); T(dictionary, dictionary2, "bub_nt_size1", "small", "pequeno"); T(dictionary, dictionary2, "bub_nt_size2", "medium", "médio"); T(dictionary, dictionary2, "bub_nt_size3", "large", "grande"); T(dictionary, dictionary2, "bub_nt_aim", "Aim at a tamed creature", "Mire num animal domado"); T(dictionary, dictionary2, "bub_nt_nottamed", "Only tamed creatures can be bound", "Só animais domados podem ser guardados"); T(dictionary, dictionary2, "bub_nt_rider", "Dismount first", "Desmonte primeiro"); T(dictionary, dictionary2, "bub_nt_boss", "This creature is too powerful to bind", "Essa criatura é poderosa demais para o talismã"); T(dictionary, dictionary2, "bub_nt_toobig", "Too big: needs a level {0} talisman", "Grande demais: precisa de talismã nível {0}"); T(dictionary, dictionary2, "bub_nt_notyours", "This creature belongs to {0}", "Esse animal pertence a {0}"); T(dictionary, dictionary2, "bub_nt_followsother", "This creature is following {0}", "Esse animal está seguindo {0}"); T(dictionary, dictionary2, "bub_nt_full", "The talisman already holds a creature", "O talismã já guarda uma criatura"); T(dictionary, dictionary2, "bub_nt_binding", "Binding", "Vinculando"); T(dictionary, dictionary2, "bub_nt_interrupted", "Binding interrupted", "Vínculo interrompido"); T(dictionary, dictionary2, "bub_nt_cancelled", "Binding cancelled", "Vínculo cancelado"); T(dictionary, dictionary2, "bub_nt_stored", "bound to the talisman", "guardado no talismã"); T(dictionary, dictionary2, "bub_nt_released", "released", "solto"); T(dictionary, dictionary2, "bub_nt_water", "Too deep to release here", "Água funda demais para soltar aqui"); T(dictionary, dictionary2, "bub_nt_space", "No room to release here", "Sem espaço para soltar aqui"); T(dictionary, dictionary2, "bub_nt_unknown", "This creature no longer exists in this world (mod removed?)", "Essa criatura não existe mais neste mundo (mod removido?)"); T(dictionary, dictionary2, "bub_nt_cooldown", "The talisman is recovering", "O talismã está se recuperando"); string text = "English"; string text2 = "Portuguese_Brazilian"; string text3 = "Portuguese_European"; localization.AddTranslation(ref text, dictionary); localization.AddTranslation(ref text2, dictionary2); localization.AddTranslation(ref text3, dictionary2); } private static void T(Dictionary<string, string> en, Dictionary<string, string> pt, string key, string english, string portuguese) { en[key] = english; pt[key] = portuguese; } private void CreateItem() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_0087: Unknown result type (might be due to invalid IL or missing references) PrefabManager.OnVanillaPrefabsAvailable -= CreateItem; ItemConfig val = new ItemConfig(); val.Name = "$item_bub_naturetalisman"; val.Description = "$item_bub_naturetalisman_desc"; val.CraftingStation = CraftingStations.Forge; val.MinStationLevel = stationLevel.Value; val.Requirements = ParseRecipe(recipe.Value).ToArray(); CustomItem val2 = new CustomItem("BubNatureTalisman", "AmberPearl", val); SharedData shared = val2.ItemDrop.m_itemData.m_shared; shared.m_itemType = (ItemType)16; shared.m_maxStackSize = 1; shared.m_maxQuality = 3; shared.m_teleportable = true; shared.m_weight = 1f; shared.m_value = 0; shared.m_questItem = false; if ((Object)(object)iconFull != (Object)null) { shared.m_icons = (Sprite[])(object)new Sprite[1] { iconFull }; } Tint(val2.ItemPrefab); ItemManager.Instance.AddItem(val2); talismanDrop = val2.ItemDrop; Talisman.Prefab = val2.ItemPrefab; } private static void Tint(GameObject prefab) { //IL_00c3: 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_004a: Expected O, but got Unknown //IL_005a: 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_007b: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); ((Color)(ref val))..ctor(0.35f, 0.85f, 0.45f); Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { Material[] sharedMaterials = val2.sharedMaterials; for (int j = 0; j < sharedMaterials.Length; j++) { if (!((Object)(object)sharedMaterials[j] == (Object)null)) { Material val3 = new Material(sharedMaterials[j]); if (val3.HasProperty("_Color")) { val3.color = val; } if (val3.HasProperty("_EmissionColor")) { val3.SetColor("_EmissionColor", val * 1.2f); } sharedMaterials[j] = val3; } } val2.sharedMaterials = sharedMaterials; } Light[] componentsInChildren2 = prefab.GetComponentsInChildren<Light>(true); foreach (Light val4 in componentsInChildren2) { val4.color = val; } } private static List<RequirementConfig> ParseRecipe(string text) { //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Expected O, but got Unknown List<RequirementConfig> list = new List<RequirementConfig>(); string[] array = text.Split(','); foreach (string text2 in array) { string[] array2 = text2.Trim().Split(':'); int result = 0; if (array2.Length < 2 || array2[0].Trim().Length == 0 || !int.TryParse(array2[1].Trim(), out var result2) || (array2.Length > 2 && !int.TryParse(array2[2].Trim(), out result)) || result2 < 0 || result < 0 || result2 + result == 0) { if (text2.Trim().Length > 0) { Log.LogWarning((object)("Receita: ignorando '" + text2 + "' (use Item:Quantidade:PorNível).")); } continue; } RequirementConfig val = new RequirementConfig(); val.Item = array2[0].Trim(); val.Amount = result2; val.AmountPerLevel = result; val.Recover = true; list.Add(val); } return list; } private static void ApplyRecipe() { //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Expected O, but got Unknown if ((Object)(object)ObjectDB.instance == (Object)null || (Object)(object)talismanDrop == (Object)null) { return; } foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if ((Object)(object)recipe == (Object)null || (Object)(object)recipe.m_item == (Object)null || ((Object)recipe.m_item).name != "BubNatureTalisman") { continue; } List<Requirement> list = new List<Requirement>(); foreach (RequirementConfig item in ParseRecipe(Plugin.recipe.Value)) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(item.Item); ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val == (Object)null) { Log.LogWarning((object)("Receita: item '" + item.Item + "' não existe.")); continue; } Requirement val2 = new Requirement(); val2.m_resItem = val; val2.m_amount = item.Amount; val2.m_amountPerLevel = item.AmountPerLevel; val2.m_recover = true; list.Add(val2); } recipe.m_resources = list.ToArray(); recipe.m_minStationLevel = stationLevel.Value; } } private static bool TimedDestructionPrefix(ItemDrop __instance) { if (Talisman.IsTalisman(__instance.m_itemData)) { return !Talisman.IsFull(__instance.m_itemData); } return true; } private static void TooltipPostfix(ItemData __0, ref string __result) { if (!Talisman.IsTalisman(__0)) { return; } string text = L("bub_nt_fits") + ": " + L("bub_nt_size" + Mathf.Clamp(__0.m_quality, 1, 3)); if (!Talisman.IsFull(__0)) { string text2 = __result; __result = text2 + "\n\n<color=#a0a0a0>" + L("bub_nt_empty") + "</color>\n" + text; return; } Dictionary<string, string> customData = __0.m_customData; string text3 = "\n\n<color=#8fe08f>" + L("bub_nt_contains") + ": " + Get(customData, "bub_nt_label") + "</color>"; string text4 = text3; text3 = text4 + "\n" + L("bub_nt_health") + ": " + Get(customData, "bub_nt_hp") + "/" + Get(customData, "bub_nt_maxhp"); List<string> list = new List<string>(); if (Get(customData, "bub_nt_saddle") == "1") { list.Add(L("bub_nt_saddle")); } if (Get(customData, "bub_nt_pregnant") == "1") { list.Add(L("bub_nt_pregnant")); } if (Get(customData, "bub_nt_baby") == "1") { list.Add(L("bub_nt_baby")); } if (list.Count > 0) { text3 = text3 + "\n" + string.Join(" · ", list.ToArray()); } if (Get(customData, "bub_nt_ownername").Length > 0) { string text5 = text3; text3 = text5 + "\n" + L("bub_nt_owner") + ": " + Get(customData, "bub_nt_ownername"); } string text6 = StoredFor(Get(customData, "bub_nt_time")); if (text6 != null) { string text7 = text3; text3 = text7 + "\n" + L("bub_nt_stored_for") + ": " + text6; } __result = __result + text3 + "\n" + text; } private static string StoredFor(string ticksText) { if ((Object)(object)ZNet.instance == (Object)null || (Object)(object)EnvMan.instance == (Object)null || !long.TryParse(ticksText, out var result)) { return null; } double num = (double)(ZNet.instance.GetTime().Ticks - result) / 10000000.0; if (num < 0.0) { return null; } double num2 = num / (double)EnvMan.instance.m_dayLengthSec; if (num2 >= 1.0) { return num2.ToString("0.#") + " " + L("bub_nt_days"); } return (num2 * 24.0).ToString("0") + " " + L("bub_nt_hours"); } private static string Get(Dictionary<string, string> d, string key) { if (d == null || !d.TryGetValue(key, out var value)) { return ""; } return value; } internal static string L(string token) { return Localization.instance.Localize("$" + token); } } internal static class Talisman { private class Channel { public ItemData Item; public Character Target; public float Start; public float Health; } private class Throw { public ItemData Item; public Vector3 From; public Vector3 To; public float Start; public float FlightStart; public float FlightTime; public GameObject Visual; } private const string OwnerKey = "bub_nt_owner"; private const string OwnerNameKey = "bub_nt_ownername"; private const float ThrowReleaseDelay = 0.35f; private const float MaxCaptureDistance = 8f; private const float ThrowSpeed = 22f; internal static GameObject Prefab; private static readonly FieldInfo ZanimField = AccessTools.Field(typeof(Character), "m_zanim"); private static readonly Func<Humanoid, GameObject> GetHoverObject = AccessTools.MethodDelegate<Func<Humanoid, GameObject>>(AccessTools.Method(typeof(Humanoid), "GetHoverObject", (Type[])null, (Type[])null), (object)null, true); private static float lastUse = -999f; private static Channel channel; private static Throw pending; private static Texture2D barBack; private static Texture2D barFill; private static readonly int SolidMask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "terrain", "vehicle" }); private static readonly int BlockMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "vehicle" }); internal static bool IsTalisman(ItemData item) { if (item != null && (Object)(object)item.m_dropPrefab != (Object)null) { return ((Object)item.m_dropPrefab).name == "BubNatureTalisman"; } return false; } internal static bool IsFull(ItemData item) { if (item != null && item.m_customData != null) { return item.m_customData.ContainsKey("bub_nt_zdo"); } return false; } private static string L(string token) { return Plugin.L(token); } private static void Msg(Player p, string text) { ((Character)p).Message((MessageType)2, text, 0, (Sprite)null, false); } private static bool UseItemPrefix(Humanoid __instance, ItemData __1) { if (!IsTalisman(__1)) { return true; } Player val = (Player)(object)((__instance is Player) ? __instance : null); if ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)Player.m_localPlayer) { return false; } if (channel != null) { channel = null; Msg(val, L("bub_nt_cancelled")); return false; } if (pending != null) { return false; } float num = Plugin.cooldown.Value - (Time.time - lastUse); if (num > 0f) { Msg(val, L("bub_nt_cooldown") + " (" + Mathf.CeilToInt(num) + " s)"); return false; } GameObject val2 = GetHoverObject(__instance); Tameable val3 = (((Object)(object)val2 != (Object)null) ? val2.GetComponentInParent<Tameable>() : null); if (IsFull(__1)) { if ((Object)(object)val3 != (Object)null) { Msg(val, L("bub_nt_full")); } else { StartThrow(val, __1); } } else if ((Object)(object)val3 == (Object)null) { Msg(val, L("bub_nt_aim")); } else { StartChannel(val, __1, val3); } return false; } private static void CommandPostfix(Tameable __instance, ZDOID __1) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || !component.IsValid() || !component.IsOwner() || (Object)(object)ZNetScene.instance == (Object)null) { return; } ZDO zDO = component.GetZDO(); if (zDO.GetLong("bub_nt_owner", 0L) == 0) { GameObject val = ZNetScene.instance.FindInstance(__1); Player val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Player>() : null); if (!((Object)(object)val2 == (Object)null)) { zDO.Set("bub_nt_owner", val2.GetPlayerID()); zDO.Set("bub_nt_ownername", val2.GetPlayerName()); } } } private static void StartChannel(Player player, ItemData item, Tameable tame) { Character component = ((Component)tame).GetComponent<Character>(); ZNetView component2 = ((Component)tame).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || component is Player || component.IsDead() || (Object)(object)component2 == (Object)null || !component2.IsValid()) { return; } string text = CaptureError(player, item, tame, component, component2.GetZDO()); if (text != null) { Msg(player, text); return; } channel = new Channel(); channel.Item = item; channel.Target = component; channel.Start = Time.time; channel.Health = ((Character)player).GetHealth(); if (Plugin.channelSeconds.Value <= 0f) { FinishChannel(player); } } private static string CaptureError(Player player, ItemData item, Tameable tame, Character c, ZDO zdo) { if (!tame.IsTamed()) { return L("bub_nt_nottamed"); } if (tame.HaveRider()) { return L("bub_nt_rider"); } if (c.IsBoss() && !Plugin.allowBosses.Value) { return L("bub_nt_boss"); } int num = RequiredSize(c); if (num > item.m_quality) { return string.Format(L("bub_nt_toobig"), num); } string text = zdo.GetString(ZDOVars.s_follow, ""); if (text.Length > 0 && text != player.GetPlayerName()) { return string.Format(L("bub_nt_followsother"), text); } if (text.Length == 0) { long num2 = zdo.GetLong("bub_nt_owner", 0L); if (num2 != 0 && num2 != player.GetPlayerID()) { return string.Format(L("bub_nt_notyours"), zdo.GetString("bub_nt_ownername", "?")); } } return null; } private static int RequiredSize(Character c) { string prefabName = Utils.GetPrefabName(((Component)c).gameObject); string[] array = Plugin.tierOverrides.Value.Split(','); foreach (string text in array) { string[] array2 = text.Trim().Split(':'); if (array2.Length == 2 && string.Equals(array2[0].Trim(), prefabName, StringComparison.OrdinalIgnoreCase) && int.TryParse(array2[1].Trim(), out var result)) { return Mathf.Clamp(result, 1, 3); } } GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(prefabName) : null); Character val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Character>() : null); float num = (((Object)(object)val2 != (Object)null) ? val2.m_health : c.m_health); if (num <= Plugin.tier1MaxHealth.Value) { return 1; } if (num <= Plugin.tier2MaxHealth.Value) { return 2; } return 3; } private static void FinishChannel(Player player) { //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Expected O, but got Unknown //IL_0251: Unknown result type (might be due to invalid IL or missing references) Channel channel = Talisman.channel; Talisman.channel = null; Character target = channel.Target; ZNetView val = (((Object)(object)target != (Object)null) ? ((Component)target).GetComponent<ZNetView>() : null); if ((Object)(object)target == (Object)null || target.IsDead() || (Object)(object)val == (Object)null || !val.IsValid()) { return; } Tameable component = ((Component)target).GetComponent<Tameable>(); string text = CaptureError(player, channel.Item, component, target, val.GetZDO()); if (text != null) { Msg(player, text); return; } if (!val.IsOwner()) { val.ClaimOwnership(); } ZDO zDO = val.GetZDO(); if (zDO.GetLong("bub_nt_owner", 0L) == 0) { zDO.Set("bub_nt_owner", player.GetPlayerID()); zDO.Set("bub_nt_ownername", player.GetPlayerName()); } ZPackage val2 = new ZPackage(); zDO.Serialize(val2); ItemData item = channel.Item; if (item.m_customData == null) { item.m_customData = new Dictionary<string, string>(); } Dictionary<string, string> customData = item.m_customData; string text2 = Label(target); customData["bub_nt_zdo"] = Convert.ToBase64String(val2.GetArray()); customData["bub_nt_prefab"] = zDO.GetPrefab().ToString(); customData["bub_nt_label"] = text2; customData["bub_nt_time"] = ZNet.instance.GetTime().Ticks.ToString(); customData["bub_nt_hp"] = Mathf.RoundToInt(target.GetHealth()).ToString(); customData["bub_nt_maxhp"] = Mathf.RoundToInt(target.GetMaxHealth()).ToString(); customData["bub_nt_saddle"] = (zDO.GetBool(ZDOVars.s_haveSaddleHash, false) ? "1" : "0"); customData["bub_nt_pregnant"] = ((zDO.GetLong(ZDOVars.s_pregnant, 0L) > 0) ? "1" : "0"); customData["bub_nt_baby"] = (((Object)(object)((Component)target).GetComponent<Growup>() != (Object)null) ? "1" : "0"); customData["bub_nt_ownername"] = zDO.GetString("bub_nt_ownername", player.GetPlayerName()); lastUse = Time.time; Effect("vfx_offering", ((Component)target).transform.position); ZNetScene.instance.Destroy(((Component)target).gameObject); Msg(player, text2 + " " + L("bub_nt_stored")); Plugin.Log.LogInfo((object)(player.GetPlayerName() + " guardou " + text2)); } private static string Label(Character c) { string text = Localization.instance.Localize(c.m_name); int num = c.GetLevel() - 1; string text2 = text + ((num > 0) ? (" " + new string('★', num)) : ""); string hoverName = c.GetHoverName(); if (!string.IsNullOrEmpty(hoverName) && hoverName != text) { text2 = hoverName + " (" + text2 + ")"; } return text2; } private static void StartThrow(Player player, ItemData item) { //IL_0044: 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) Vector3 point; string text = AimPoint(player, out point); if (text != null) { Msg(player, text); return; } object? value = ZanimField.GetValue(player); ZSyncAnimation val = (ZSyncAnimation)((value is ZSyncAnimation) ? value : null); if ((Object)(object)val != (Object)null) { val.SetTrigger("throw_bomb"); } Effect("sfx_bomb_throw", ((Component)player).transform.position); pending = new Throw(); pending.Item = item; pending.To = point; pending.Start = Time.time; } private static string AimPoint(Player player, out Vector3 point) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_003e: 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_0057: 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_0063: 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_0076: 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_007a: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: 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_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_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: 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_00c4: 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_010b: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011a: 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) //IL_0146: 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: Unknown result type (might be due to invalid IL or missing references) //IL_0157: 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_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) Vector3 position = ((Component)player).transform.position; Transform val = (((Object)(object)GameCamera.instance != (Object)null) ? ((Component)GameCamera.instance).transform : ((Component)player).transform); float value = Plugin.throwRange.Value; RaycastHit val3 = default(RaycastHit); Vector3 val2 = (Physics.Raycast(val.position, val.forward, ref val3, 60f, SolidMask) ? ((RaycastHit)(ref val3)).point : (val.position + val.forward * value)); Vector3 val4 = val2 - position; val4.y = 0f; if (((Vector3)(ref val4)).magnitude > value) { val2 = position + ((Vector3)(ref val4)).normalized * value + Vector3.up * (val2.y - position.y); } if (Physics.Raycast(val2 + Vector3.up * 4f, Vector3.down, ref val3, 30f, SolidMask)) { val2 = ((RaycastHit)(ref val3)).point; } else { val2.y = ZoneSystem.instance.GetGroundHeight(val2); } point = val2; if (Floating.GetLiquidLevel(val2, 1f, (LiquidType)0) > val2.y + 1.2f) { return L("bub_nt_water"); } if (Physics.CheckCapsule(val2 + Vector3.up * 0.7f, val2 + Vector3.up * 1.6f, 0.45f, BlockMask)) { return L("bub_nt_space"); } return null; } private static void Release(Player player, ItemData item, Vector3 pos) { //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_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Expected O, but got Unknown //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) Dictionary<string, string> customData = item.m_customData; int num; byte[] array; long result; try { num = int.Parse(customData["bub_nt_prefab"]); array = Convert.FromBase64String(customData["bub_nt_zdo"]); if (!long.TryParse(customData.ContainsKey("bub_nt_time") ? customData["bub_nt_time"] : "", out result)) { result = 0L; } } catch (Exception ex) { Plugin.Log.LogError((object)("Talismã com dados inválidos: " + ex.Message)); return; } if ((Object)(object)ZNetScene.instance.GetPrefab(num) == (Object)null) { Msg(player, L("bub_nt_unknown")); return; } pos += Vector3.up * 0.2f; ZDO val = ZDOMan.instance.CreateNewZDO(pos, num); val.Deserialize(new ZPackage(array)); val.SetPosition(pos); val.SetOwner(ZDOMan.GetSessionID()); long ticks = ZNet.instance.GetTime().Ticks; long num2 = ((result > 0) ? (ticks - result) : 0); if (num2 > 0) { int[] array2 = new int[3] { ZDOVars.s_spawnTime, ZDOVars.s_pregnant, ZDOVars.s_tameLastFeeding }; foreach (int num3 in array2) { long num4 = val.GetLong(num3, 0L); if (num4 > 0) { val.Set(num3, num4 + num2); } } } if (!customData.TryGetValue("bub_nt_label", out var value)) { value = "?"; } string[] array3 = new string[10] { "bub_nt_zdo", "bub_nt_prefab", "bub_nt_label", "bub_nt_time", "bub_nt_hp", "bub_nt_maxhp", "bub_nt_saddle", "bub_nt_pregnant", "bub_nt_baby", "bub_nt_ownername" }; foreach (string key in array3) { customData.Remove(key); } lastUse = Time.time; Effect("vfx_offering", pos); Msg(player, value + " " + L("bub_nt_released")); Plugin.Log.LogInfo((object)(player.GetPlayerName() + " soltou " + value)); } internal static void Tick() { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (Talisman.channel != null) { Channel channel = Talisman.channel; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead()) { Talisman.channel = null; } else if ((Object)(object)channel.Target == (Object)null || channel.Target.IsDead() || Vector3.Distance(((Component)channel.Target).transform.position, ((Component)localPlayer).transform.position) > 8f) { Talisman.channel = null; Msg(localPlayer, L("bub_nt_interrupted")); } else if (((Character)localPlayer).GetHealth() < channel.Health - 0.1f) { Talisman.channel = null; Msg(localPlayer, L("bub_nt_interrupted")); } else if (!((Humanoid)localPlayer).GetInventory().ContainsItem(channel.Item)) { Talisman.channel = null; } else if (Time.time - channel.Start >= Plugin.channelSeconds.Value) { FinishChannel(localPlayer); } } if (pending != null) { TickThrow(localPlayer); } } private static void TickThrow(Player p) { //IL_011d: 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_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0147: 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_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_0072: 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_0082: 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_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_00ab: 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_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) Throw obj = pending; if ((Object)(object)p == (Object)null || ((Character)p).IsDead()) { if ((Object)(object)obj.Visual != (Object)null) { Object.Destroy((Object)(object)obj.Visual); } pending = null; return; } if ((Object)(object)obj.Visual == (Object)null) { if (!(Time.time - obj.Start < 0.35f)) { obj.From = ((Component)p).transform.position + Vector3.up * 1.6f + ((Component)p).transform.forward * 0.4f + ((Component)p).transform.right * 0.3f; obj.FlightStart = Time.time; obj.FlightTime = Mathf.Clamp(Vector3.Distance(obj.From, obj.To) / 22f, 0.15f, 1.6f); obj.Visual = MakeVisual(obj.From); } return; } float num = Mathf.Clamp01((Time.time - obj.FlightStart) / obj.FlightTime); float num2 = 0.3f + Vector3.Distance(obj.From, obj.To) * 0.05f; obj.Visual.transform.position = Vector3.Lerp(obj.From, obj.To, num) + Vector3.up * (4f * num2 * num * (1f - num)); obj.Visual.transform.Rotate(540f * Time.deltaTime, 360f * Time.deltaTime, 0f, (Space)1); if (!(num < 1f)) { Object.Destroy((Object)(object)obj.Visual); pending = null; if (((Humanoid)p).GetInventory().ContainsItem(obj.Item) && IsFull(obj.Item)) { Release(p, obj.Item, obj.To); } } } private static GameObject MakeVisual(Vector3 pos) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown //IL_009b: 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_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("bub_nt_thrown"); val.transform.position = pos; GameObject prefab = Prefab; if ((Object)(object)prefab != (Object)null) { Transform transform = prefab.transform; MeshRenderer[] componentsInChildren = prefab.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val2 in componentsInChildren) { MeshFilter component = ((Component)val2).GetComponent<MeshFilter>(); if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null)) { GameObject val3 = new GameObject("part"); val3.transform.SetParent(val.transform, false); val3.transform.localPosition = transform.InverseTransformPoint(((Component)val2).transform.position); val3.transform.localRotation = Quaternion.Inverse(transform.rotation) * ((Component)val2).transform.rotation; val3.transform.localScale = ((Component)val2).transform.lossyScale; val3.AddComponent<MeshFilter>().sharedMesh = component.sharedMesh; ((Renderer)val3.AddComponent<MeshRenderer>()).sharedMaterials = ((Renderer)val2).sharedMaterials; } } } Light val4 = val.AddComponent<Light>(); val4.color = new Color(0.35f, 0.9f, 0.55f); val4.range = 3f; val4.intensity = 1.2f; return val; } private static void Effect(string name, Vector3 pos) { //IL_0026: 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) GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(name) : null); if ((Object)(object)val != (Object)null) { Object.Instantiate<GameObject>(val, pos, Quaternion.identity); } } internal static void DrawGui() { //IL_00bc: 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_011a: 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) if (channel != null && !(Plugin.channelSeconds.Value <= 0f)) { if ((Object)(object)barBack == (Object)null) { barBack = Solid(new Color(0f, 0f, 0f, 0.6f)); barFill = Solid(new Color(0.35f, 0.85f, 0.55f, 0.9f)); } float num = Mathf.Clamp01((Time.time - channel.Start) / Plugin.channelSeconds.Value); float num2 = 240f; float num3 = 14f; Rect val = default(Rect); ((Rect)(ref val))..ctor(((float)Screen.width - num2) * 0.5f, (float)Screen.height * 0.62f, num2, num3); GUI.DrawTexture(val, (Texture)(object)barBack); GUI.DrawTexture(new Rect(((Rect)(ref val)).x + 2f, ((Rect)(ref val)).y + 2f, (num2 - 4f) * num, num3 - 4f), (Texture)(object)barFill); GUI.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y - 20f, num2, 20f), L("bub_nt_binding") + "… " + Mathf.RoundToInt(num * 100f) + "%"); } } private static Texture2D Solid(Color c) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_000b: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(1, 1); val.SetPixel(0, 0, c); val.Apply(); return val; } }