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 TameTweaks v1.7.0
TameTweaks.dll
Decompiled an hour agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("TameTweaks")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("TameTweaks")] [assembly: AssemblyTitle("TameTweaks")] [assembly: AssemblyVersion("1.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 TameTweaks { [BepInPlugin("com.tametweaks", "TameTweaks", "1.7.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { internal sealed class CarryKind { public ConfigEntry<float> Base; public ConfigEntry<float> PerStar; } internal sealed class BreedingKind { public ConfigEntry<int> Limit; public ConfigEntry<int> Radius; } public const string PluginGUID = "com.tametweaks"; public const string PluginName = "TameTweaks"; public const string PluginVersion = "1.7.0"; internal static ManualLogSource Log; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> ShowStats; internal static ConfigEntry<bool> ShowSkillProgress; internal static ConfigEntry<int> Width; internal static ConfigEntry<int> Height; internal static ConfigEntry<float> DefaultWeight; internal static ConfigEntry<float> DefaultWeightPerStar; internal static ConfigEntry<bool> AllCanFollow; internal static readonly Dictionary<string, CarryKind> Carry = new Dictionary<string, CarryKind>(); internal static ConfigEntry<float> HealPercent; internal static ConfigEntry<float> FeedInterval; internal static ConfigEntry<bool> TeleportFollowers; internal static ConfigEntry<bool> FollowIntoDungeons; internal static ConfigEntry<bool> LockOwnership; internal static ConfigEntry<float> FollowerRange; internal static ConfigEntry<KeyboardShortcut> OpenKey; internal static ConfigEntry<bool> HandlingEnabled; internal static ConfigEntry<float> DamagePercent; internal static ConfigEntry<string> CustomDamage; internal static ConfigEntry<float> CarryPercent; internal static ConfigEntry<string> CustomCarry; internal static ConfigEntry<float> HealthPercent; internal static ConfigEntry<string> CustomHealth; internal static ConfigEntry<float> DamageXp; internal static ConfigEntry<float> TamingXp; internal static ConfigEntry<float> EatingXp; internal static ConfigEntry<float> CarryXp; internal static readonly Dictionary<string, BreedingKind> Breeding = new Dictionary<string, BreedingKind>(); private static readonly Dictionary<string, float> VanillaRadius = new Dictionary<string, float>(); private float _claimTimer; private void Awake() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Expected O, but got Unknown //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Expected O, but got Unknown //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Expected O, but got Unknown //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Expected O, but got Unknown //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Expected O, but got Unknown //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02bb: Expected O, but got Unknown //IL_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Expected O, but got Unknown //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_031b: Expected O, but got Unknown //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Expected O, but got Unknown //IL_0383: Unknown result type (might be due to invalid IL or missing references) //IL_038d: Expected O, but got Unknown //IL_03c5: Unknown result type (might be due to invalid IL or missing references) //IL_03cf: Expected O, but got Unknown //IL_03f9: Unknown result type (might be due to invalid IL or missing references) //IL_0403: Expected O, but got Unknown //IL_043b: Unknown result type (might be due to invalid IL or missing references) //IL_0445: Expected O, but got Unknown //IL_046f: Unknown result type (might be due to invalid IL or missing references) //IL_0479: Expected O, but got Unknown //IL_04b1: Unknown result type (might be due to invalid IL or missing references) //IL_04bb: Expected O, but got Unknown //IL_04e5: Unknown result type (might be due to invalid IL or missing references) //IL_04ef: Expected O, but got Unknown //IL_0527: Unknown result type (might be due to invalid IL or missing references) //IL_0531: Expected O, but got Unknown //IL_0569: Unknown result type (might be due to invalid IL or missing references) //IL_0573: Expected O, but got Unknown //IL_05ab: Unknown result type (might be due to invalid IL or missing references) //IL_05b5: Expected O, but got Unknown //IL_05ed: Unknown result type (might be due to invalid IL or missing references) //IL_05f7: Expected O, but got Unknown //IL_061a: Unknown result type (might be due to invalid IL or missing references) //IL_061f: Unknown result type (might be due to invalid IL or missing references) //IL_065b: Unknown result type (might be due to invalid IL or missing references) //IL_06e2: Unknown result type (might be due to invalid IL or missing references) //IL_06e8: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; ConfigurationManagerAttributes val = new ConfigurationManagerAttributes { IsAdminOnly = true }; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Food bag", "Enabled", true, new ConfigDescription("Tamed animals that eat get a bag.", (AcceptableValueBase)null, new object[1] { val })); ShowStats = ((BaseUnityPlugin)this).Config.Bind<bool>("Food bag", "ShowStats", true, "Show the animal's stats (health, damage, carry weight, Animal Handling bonus) in a window beside its bag."); Width = ((BaseUnityPlugin)this).Config.Bind<int>("Food bag", "BagWidth", 4, new ConfigDescription("Slots across in the bag. Animals pick up a new size when they next load.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 8), new object[1] { val })); Height = ((BaseUnityPlugin)this).Config.Bind<int>("Food bag", "BagHeight", 2, new ConfigDescription("Rows of slots in the bag.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 4), new object[1] { val })); DefaultWeight = ((BaseUnityPlugin)this).Config.Bind<float>("Carry weight", "DefaultCarryWeight", 100f, new ConfigDescription("Carry weight of a regular animal that has no entry of its own below (for example an animal from another mod).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5000f), new object[1] { val })); DefaultWeightPerStar = ((BaseUnityPlugin)this).Config.Bind<float>("Carry weight", "DefaultCarryWeightPerStar", 100f, new ConfigDescription("What each star adds for animals that have no entry of their own.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5000f), new object[1] { val })); AllCanFollow = ((BaseUnityPlugin)this).Config.Bind<bool>("Following", "AllTamedCanFollow", true, new ConfigDescription("Every tamed animal can be told to follow you or stay (the same as wolves): press the use key on it, like on a wolf. Off: only the animals the game lets you command.", (AcceptableValueBase)null, new object[1] { val })); AddCarry("Boar", 50f, 50f, val); AddCarry("Wolf", 100f, 100f, val); AddCarry("Lox", 600f, 150f, val); AddCarry("Asksvin", 250f, 100f, val); AddCarry("Moose", 400f, 100f, val); AddCarry("Hen", 10f, 10f, val); HealPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Food bag", "HealPercentPerFood", 20f, new ConfigDescription("How much health (percent of its maximum) an animal gets back from eating one food from the bag.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f), new object[1] { val })); FeedInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Food bag", "SecondsBetweenBites", 3f, new ConfigDescription("How long an animal waits between eating from the bag.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), new object[1] { val })); TeleportFollowers = ((BaseUnityPlugin)this).Config.Bind<bool>("Portals", "TeleportFollowers", true, new ConfigDescription("Tamed animals that are following you come through a portal with you.", (AcceptableValueBase)null, new object[1] { val })); FollowIntoDungeons = ((BaseUnityPlugin)this).Config.Bind<bool>("Portals", "FollowIntoDungeons", true, new ConfigDescription("Tamed animals that are following you come through dungeon entrances and exits (crypts, caves, ...) with you.", (AcceptableValueBase)null, new object[1] { val })); LockOwnership = ((BaseUnityPlugin)this).Config.Bind<bool>("Portals", "KeepFollowersOwnership", true, new ConfigDescription("A tamed animal that is following you stays owned by your game: it is not handed to other players who walk by (on your game, and on a server that has this mod), and your game takes it back if someone else gets it. Telling the animal to stay ends this.", (AcceptableValueBase)null, new object[1] { val })); FollowerRange = ((BaseUnityPlugin)this).Config.Bind<float>("Portals", "FollowerRange", 40f, new ConfigDescription("Only animals this close (meters) to you when you step into the portal or dungeon door come along.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 200f), new object[1] { val })); HandlingEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Animal Handling", "Enabled", true, new ConfigDescription("Adds the Animal Handling skill. Your following animals get stronger, carry more and have more health as it rises.", (AcceptableValueBase)null, new object[1] { val })); DamagePercent = ((BaseUnityPlugin)this).Config.Bind<float>("Animal Handling", "DamagePercentPerLevel", 2.5f, new ConfigDescription("How much each Animal Handling level adds to your followers' damage, in percent. Slider in steps of 0.5, up to 20; or type any value in the field below it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), new object[1] { val })); CustomDamage = ((BaseUnityPlugin)this).Config.Bind<string>("Animal Handling", "CustomDamagePercentPerLevel", "", new ConfigDescription("Type your own damage percent per level (for example 35 or 0.75). When this holds a number it is used instead of the slider. Leave empty to use the slider.", (AcceptableValueBase)null, new object[1] { val })); CarryPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Animal Handling", "CarryWeightPercentPerLevel", 2.5f, new ConfigDescription("How much each Animal Handling level adds to your followers' carry weight, in percent. Slider in steps of 0.5, up to 20; or type any value in the field below it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), new object[1] { val })); CustomCarry = ((BaseUnityPlugin)this).Config.Bind<string>("Animal Handling", "CustomCarryWeightPercentPerLevel", "", new ConfigDescription("Type your own carry weight percent per level. When this holds a number it is used instead of the slider. Leave empty to use the slider.", (AcceptableValueBase)null, new object[1] { val })); HealthPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Animal Handling", "HealthPercentPerLevel", 2.5f, new ConfigDescription("How much each Animal Handling level adds to your followers' health, in percent. Slider in steps of 0.5, up to 20; or type any value in the field below it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), new object[1] { val })); CustomHealth = ((BaseUnityPlugin)this).Config.Bind<string>("Animal Handling", "CustomHealthPercentPerLevel", "", new ConfigDescription("Type your own health percent per level. When this holds a number it is used instead of the slider. Leave empty to use the slider.", (AcceptableValueBase)null, new object[1] { val })); DamageXp = ((BaseUnityPlugin)this).Config.Bind<float>("Animal Handling", "XpPerDamage", 0.05f, new ConfigDescription("Skill progress for each point of damage your following animals do. At 0.05, a 20 damage bite counts like one of your own hits.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), new object[1] { val })); TamingXp = ((BaseUnityPlugin)this).Config.Bind<float>("Animal Handling", "XpPerTaming", 10f, new ConfigDescription("Skill progress when an animal is tamed near you.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), new object[1] { val })); EatingXp = ((BaseUnityPlugin)this).Config.Bind<float>("Animal Handling", "XpPerBagMeal", 1f, new ConfigDescription("Skill progress each time one of your following animals eats something out of its bag.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), new object[1] { val })); CarryXp = ((BaseUnityPlugin)this).Config.Bind<float>("Animal Handling", "XpPer50mHeavyLoad", 2.5f, new ConfigDescription("Skill progress for every 50 meters one of your following animals travels while carrying more than 75% of its carry weight.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), new object[1] { val })); Handling.Skill = SkillManager.Instance.AddSkill("com.tametweaks.animalhandling", "Animal Handling", "Your following animals hit harder, carry more and have more health. Raised by their damage, by taming animals nearby, by them eating from their bags and by heavy loads carried far.", 1f, Handling.MakeIcon()); ShowSkillProgress = ((BaseUnityPlugin)this).Config.Bind<bool>("Skills page", "ShowProgress", true, "On the skills page, show each skill's progress toward its next level next to the level, like 12 (3.4/16.3). Works for every skill, not only Animal Handling."); OpenKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "OpenKey", new KeyboardShortcut((KeyCode)114, Array.Empty<KeyCode>()), "Look at a tamed animal and press this to open its bag."); AddBreeding("Boar", 5, 10f, val); AddBreeding("Wolf", 4, 10f, val); AddBreeding("Lox", 4, 20f, val); AddBreeding("Hen", 10, 10f, val); AddBreeding("Asksvin", 10, 10f, val); AddBreeding("Moose", 5, 10f, val); Harmony val2 = new Harmony("com.tametweaks"); Type[] types = typeof(Plugin).Assembly.GetTypes(); foreach (Type type in types) { if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Length != 0) { try { val2.CreateClassProcessor(type).Patch(); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Could not apply patch " + type.Name + ": " + ex.Message)); } } } ((BaseUnityPlugin)this).Logger.LogInfo((object)"TameTweaks 1.7.0 loaded"); } private void AddCarry(string prefab, float baseWeight, float perStar, ConfigurationManagerAttributes admin) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Expected O, but got Unknown string text = "Carry weight - " + prefab; Carry[prefab] = new CarryKind { Base = ((BaseUnityPlugin)this).Config.Bind<float>(text, "CarryWeight", baseWeight, new ConfigDescription("How much a regular " + prefab + " can carry in its bag.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5000f), new object[1] { admin })), PerStar = ((BaseUnityPlugin)this).Config.Bind<float>(text, "ExtraPerStar", perStar, new ConfigDescription("How much each star adds for a " + prefab + ": one star is CarryWeight plus this, two stars is CarryWeight plus twice this.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5000f), new object[1] { admin })) }; } internal static float CarryWeightFor(string animalName, int level) { string text = (animalName.EndsWith("(Clone)") ? animalName.Substring(0, animalName.Length - "(Clone)".Length) : animalName); text = text.Replace("_spiritcaller", ""); int num = Mathf.Max(0, level - 1); if (Carry.TryGetValue(text, out var value)) { return value.Base.Value + (float)num * value.PerStar.Value; } return DefaultWeight.Value + (float)num * DefaultWeightPerStar.Value; } private void AddBreeding(string prefab, int vanillaLimit, float vanillaRadius, ConfigurationManagerAttributes admin) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Expected O, but got Unknown VanillaRadius[prefab] = vanillaRadius; string text = "Breeding - " + prefab; Breeding[prefab] = new BreedingKind { Limit = ((BaseUnityPlugin)this).Config.Bind<int>(text, "MaxAnimals", vanillaLimit, new ConfigDescription($"How many {prefab} (and their young) may be within the breeding radius before they stop breeding. The game's own value is {vanillaLimit}.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 500), new object[1] { admin })), Radius = ((BaseUnityPlugin)this).Config.Bind<int>(text, "BreedingRadius", 10, new ConfigDescription($"How far apart {prefab} are still counted together, from 1 to 10. 10 is the game's own distance ({vanillaRadius:0.#} m); " + $"each step down shrinks it by a tenth ({vanillaRadius / 10f:0.#} m per step). A smaller radius means fewer animals are counted, so a spread-out herd can grow bigger.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), new object[1] { admin })) }; } internal static float RadiusFor(string prefab, int slider) { return VanillaRadius[prefab] * (float)slider / 10f; } private void ReclaimFollowers() { //IL_0056: Unknown result type (might be due to invalid IL or missing references) _claimTimer += Time.deltaTime; if (_claimTimer < 0.5f) { return; } _claimTimer = 0f; Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return; } string playerName = localPlayer.GetPlayerName(); float num = (HandlingEnabled.Value ? ((Character)localPlayer).GetSkillLevel(Handling.Skill) : 0f); foreach (Character allCharacter in Character.GetAllCharacters()) { if ((Object)(object)allCharacter == (Object)null || allCharacter.IsPlayer() || !allCharacter.IsTamed()) { continue; } ZNetView component = ((Component)allCharacter).GetComponent<ZNetView>(); if (!((Object)(object)component == (Object)null) && component.IsValid()) { bool flag = component.GetZDO().GetString(ZDOVars.s_follow, "") == playerName; if (LockOwnership.Value && flag && !component.IsOwner()) { component.ClaimOwnership(); } if (component.IsOwner()) { Handling.Apply(allCharacter, component, flag ? num : 0f); } } } } private void Update() { //IL_0017: 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) ReclaimFollowers(); if (!Enabled.Value) { return; } KeyboardShortcut value = OpenKey.Value; if (!((KeyboardShortcut)(ref value)).IsDown()) { return; } Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && !((Character)localPlayer).IsDead() && !Console.IsVisible() && !Menu.IsVisible() && !TextInput.IsVisible() && GUIUtility.keyboardControl == 0 && !InventoryGui.IsVisible() && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus())) { GameObject hoverObject = ((Humanoid)localPlayer).GetHoverObject(); Tameable val = (((Object)(object)hoverObject != (Object)null) ? hoverObject.GetComponentInParent<Tameable>() : null); if (!((Object)(object)val == (Object)null) && val.IsTamed()) { ((Component)val).GetComponentInChildren<FoodBag>(true)?.Open(localPlayer); } } } } internal class FoodBag : MonoBehaviour { private static readonly MethodInfo OnConsumed = AccessTools.Method(typeof(Tameable), "OnConsumedItem", (Type[])null, (Type[])null); internal static readonly Dictionary<Inventory, FoodBag> ByInventory = new Dictionary<Inventory, FoodBag>(); private Tameable _tameable; private MonsterAI _ai; private Character _character; private ZNetView _nview; private Container _container; private float _timer; private Vector3 _lastPosition; private bool _havePosition; private float _heavyMeters; private static readonly FieldRef<BaseAI, float> LastFlee = AccessTools.FieldRefAccess<BaseAI, float>("m_lastFlee"); internal Character Character => _character; internal Inventory Inventory { get { if (!((Object)(object)_container != (Object)null)) { return null; } return _container.GetInventory(); } } internal float Capacity { get { if (!((Object)(object)_character != (Object)null)) { return Plugin.DefaultWeight.Value; } return Plugin.CarryWeightFor(((Object)_character).name, _character.GetLevel()) * Handling.MultOf(_character, Handling.Stat.Carry); } } internal static void Attach(Tameable tameable) { //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_0064: 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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.Enabled.Value) { return; } MonsterAI component = ((Component)tameable).GetComponent<MonsterAI>(); ZNetView component2 = ((Component)tameable).GetComponent<ZNetView>(); if (!((Object)(object)component == (Object)null) && !((Object)(object)component2 == (Object)null) && component.m_consumeItems != null && component.m_consumeItems.Count != 0 && !((Object)(object)((Component)tameable).GetComponentInChildren<FoodBag>(true) != (Object)null)) { GameObject val = new GameObject("FoodBag"); val.SetActive(false); val.transform.SetParent(((Component)tameable).transform, false); Container val2 = val.AddComponent<Container>(); val2.m_name = "Pack bag"; val2.m_width = Plugin.Width.Value; val2.m_height = Plugin.Height.Value; val2.m_privacy = (PrivacySetting)2; val2.m_rootObjectOverride = component2; FoodBag foodBag = val.AddComponent<FoodBag>(); foodBag._tameable = tameable; foodBag._ai = component; foodBag._character = ((Component)tameable).GetComponent<Character>(); foodBag._nview = component2; foodBag._container = val2; val.SetActive(true); Inventory inventory = val2.GetInventory(); if (inventory != null) { ByInventory[inventory] = foodBag; } Plugin.Log.LogInfo((object)$"Bag created for {((Object)tameable).name} (animal {component2.GetZDO()?.m_uid}, bag #{((Object)val2).GetInstanceID()}, owner here: {component2.IsOwner()})"); } } private void OnDestroy() { if ((Object)(object)_container != (Object)null && _container.GetInventory() != null) { ByInventory.Remove(_container.GetInventory()); } } internal void Open(Player player) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_container == (Object)null)) { Plugin.Log.LogInfo((object)$"Opening bag #{((Object)_container).GetInstanceID()} of animal {_nview.GetZDO()?.m_uid}: the animal has {((Component)((Component)this).GetComponentInParent<Tameable>()).GetComponentsInChildren<Container>(true).Length} bag(s), owner here: {_nview.IsOwner()}, holds {Describe(_container.GetInventory())}"); _container.Interact((Humanoid)(object)player, false, false); } } internal static string Describe(Inventory inventory) { if (inventory == null) { return "nothing (no inventory)"; } int num = 0; foreach (ItemData allItem in inventory.GetAllItems()) { num += allItem.m_stack; } return $"{num} items in {inventory.GetAllItems().Count} stacks, weight {inventory.GetTotalWeight():0.#}"; } private void Update() { TrackHeavyLoad(); _timer += Time.deltaTime; if (!(_timer < Plugin.FeedInterval.Value)) { _timer = 0f; TryFeed(); } } private void TrackHeavyLoad() { //IL_0050: 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_013d: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_0092: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.HandlingEnabled.Value || (Object)(object)_nview == (Object)null || !_nview.IsValid() || !_nview.IsOwner() || (Object)(object)_container == (Object)null) { _havePosition = false; return; } Vector3 position = ((Component)this).transform.position; if (_havePosition) { float num = Vector3.Distance(new Vector3(position.x, 0f, position.z), new Vector3(_lastPosition.x, 0f, _lastPosition.z)); if (num < 10f) { Inventory inventory = _container.GetInventory(); if (inventory != null && inventory.GetTotalWeight() > Capacity * 0.75f) { _heavyMeters += num; if (_heavyMeters >= 50f) { int num2 = Mathf.FloorToInt(_heavyMeters / 50f); _heavyMeters -= (float)num2 * 50f; Handling.Award(_nview.GetZDO().GetString(ZDOVars.s_follow, ""), Plugin.CarryXp.Value * (float)num2); } } } } _lastPosition = position; _havePosition = true; } private bool IsFrightened() { if ((Object)(object)_ai != (Object)null) { return Time.time - LastFlee.Invoke((BaseAI)(object)_ai) < ((BaseAI)_ai).m_fleeInterval + 1f; } return false; } private bool Eats(ItemData item) { foreach (ItemDrop consumeItem in _ai.m_consumeItems) { if ((Object)(object)consumeItem != (Object)null && consumeItem.m_itemData.m_shared.m_name == item.m_shared.m_name) { return true; } } return false; } private void TryFeed() { //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0115: 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_0129: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.Enabled.Value || (Object)(object)_nview == (Object)null || !_nview.IsValid() || !_nview.IsOwner() || (Object)(object)_container == (Object)null || (Object)(object)_character == (Object)null || _character.IsDead() || !_tameable.IsTamed() || _character.GetHealth() >= _character.GetMaxHealth() - 0.01f || IsFrightened()) { return; } Inventory inventory = _container.GetInventory(); if (inventory == null) { return; } foreach (ItemData allItem in inventory.GetAllItems()) { if (Eats(allItem)) { inventory.RemoveOneItem(allItem); _character.Heal(_character.GetMaxHealth() * Plugin.HealPercent.Value / 100f, true); Humanoid componentInParent = ((Component)this).GetComponentInParent<Humanoid>(); if (componentInParent != null) { componentInParent.m_consumeItemEffects.Create(((Component)this).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID)); } ZSyncAnimation componentInParent2 = ((Component)this).GetComponentInParent<ZSyncAnimation>(); if (componentInParent2 != null) { componentInParent2.SetTrigger("consume"); } OnConsumed?.Invoke(_tameable, new object[1]); Handling.Award(_nview.GetZDO().GetString(ZDOVars.s_follow, ""), Plugin.EatingXp.Value); break; } } } internal void DropAll() { //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_0076: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009b: 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) if ((Object)(object)_container == (Object)null || (Object)(object)_nview == (Object)null || !_nview.IsValid() || !_nview.IsOwner()) { return; } Inventory inventory = _container.GetInventory(); if (inventory == null) { return; } foreach (ItemData item in new List<ItemData>(inventory.GetAllItems())) { Vector3 val = ((Component)this).transform.position + Vector3.up * 0.5f + Random.insideUnitSphere * 0.5f; ItemDrop.DropItem(item, item.m_stack, val, Quaternion.identity); } inventory.RemoveAll(); } } [HarmonyPatch(typeof(Tameable), "Awake")] internal static class Tameable_Awake_Patch { private static void Postfix(Tameable __instance) { if (Plugin.AllCanFollow.Value && !__instance.m_commandable && (Object)(object)((Component)__instance).GetComponent<MonsterAI>() != (Object)null) { __instance.m_commandable = true; } FoodBag.Attach(__instance); } } [HarmonyPatch(typeof(Tameable), "GetHoverText")] internal static class Tameable_GetHoverText_Patch { private static void Postfix(Tameable __instance, ref string __result) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) if (Plugin.Enabled.Value && __instance.IsTamed() && !((Object)(object)((Component)__instance).GetComponentInChildren<FoodBag>(true) == (Object)null)) { string obj = __result; KeyboardShortcut value = Plugin.OpenKey.Value; __result = obj + $"\n[<color=yellow><b>{((KeyboardShortcut)(ref value)).MainKey}</b></color>] Bag"; } } } [HarmonyPatch(typeof(Character), "OnDeath")] internal static class Character_OnDeath_Patch { private static void Prefix(Character __instance) { ((Component)__instance).GetComponentInChildren<FoodBag>(true)?.DropAll(); } } internal static class BagLimit { internal static bool Loading; internal static void Refused(FoodBag bag, Inventory inventory, ItemData item, int wanted, int allowed) { string name = item.m_shared.m_name; Plugin.Log.LogInfo((object)$"Bag weight limit: {name} x{wanted} -> x{allowed} (the bag holds {inventory.GetTotalWeight():0.#} of {bag.Capacity:0.#}, one {name} weighs {item.m_shared.m_weight:0.##})"); if ((Object)(object)Player.m_localPlayer != (Object)null) { ((Character)Player.m_localPlayer).Message((MessageType)1, $"The bag is carrying {inventory.GetTotalWeight():0.#} of {bag.Capacity:0.#}", 0, (Sprite)null, false); } } } [HarmonyPatch(typeof(Inventory), "Load", new Type[] { typeof(ZPackage) })] internal static class Inventory_Load_Patch { private static void Prefix() { BagLimit.Loading = true; } private static void Finalizer() { BagLimit.Loading = false; } } [HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData), typeof(int), typeof(int), typeof(int), typeof(bool) })] internal static class Inventory_AddItemAt_Patch { private static bool Prefix(Inventory __instance, ItemData item, ref int amount, ref bool __result) { if (BagLimit.Loading || !FoodBag.ByInventory.TryGetValue(__instance, out var value)) { return true; } if (__instance.ContainsItem(item)) { return true; } float weight = item.m_shared.m_weight; if (weight <= 0f) { return true; } int num = Mathf.Min(amount, item.m_stack); int num2 = Mathf.FloorToInt((value.Capacity - __instance.GetTotalWeight()) / weight + 0.0001f); if (num2 >= num) { return true; } BagLimit.Refused(value, __instance, item, num, Mathf.Max(0, num2)); amount = Mathf.Max(0, num2); if (amount <= 0) { __result = false; return false; } return true; } } [HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })] internal static class Inventory_AddItem_Patch { private static bool Prefix(Inventory __instance, ItemData item, ref bool __result) { if (BagLimit.Loading || !FoodBag.ByInventory.TryGetValue(__instance, out var value)) { return true; } if (__instance.ContainsItem(item)) { return true; } if (__instance.GetTotalWeight() + item.GetWeight(-1) > value.Capacity) { BagLimit.Refused(value, __instance, item, item.m_stack, 0); __result = false; return false; } return true; } } [HarmonyPatch(typeof(InventoryGui), "UpdateContainerWeight")] internal static class InventoryGui_UpdateContainerWeight_Patch { private static readonly FieldRef<InventoryGui, Container> Current = AccessTools.FieldRefAccess<InventoryGui, Container>("m_currentContainer"); private static void Postfix(InventoryGui __instance) { Container val = Current.Invoke(__instance); if (!((Object)(object)val == (Object)null) && !((Object)(object)__instance.m_containerWeight == (Object)null)) { Inventory inventory = val.GetInventory(); if (inventory != null && FoodBag.ByInventory.TryGetValue(inventory, out var value)) { __instance.m_containerWeight.text = Mathf.CeilToInt(inventory.GetTotalWeight()) + "/" + Mathf.RoundToInt(value.Capacity); } } } } internal enum Entry { None, Portal, Dungeon } internal static class Portal { internal static Entry Active; } [HarmonyPatch(typeof(TeleportWorld), "Teleport")] internal static class TeleportWorld_Teleport_Patch { private static void Prefix() { Portal.Active = Entry.Portal; } private static void Finalizer() { Portal.Active = Entry.None; } } [HarmonyPatch(typeof(Teleport), "Interact")] internal static class Teleport_Interact_Patch { private static void Prefix() { Portal.Active = Entry.Dungeon; } private static void Finalizer() { Portal.Active = Entry.None; } } [HarmonyPatch(typeof(Player), "TeleportTo")] internal static class Player_TeleportTo_Patch { private static void Postfix(Player __instance, Vector3 pos, bool __result) { //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Unknown result type (might be due to invalid IL or missing references) Entry active = Portal.Active; if (active == Entry.None || (Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return; } if (!__result) { Plugin.Log.LogInfo((object)$"{active} teleport did not go ahead, so no animals were moved."); return; } if ((active == Entry.Portal) ? (!Plugin.TeleportFollowers.Value) : (!Plugin.FollowIntoDungeons.Value)) { Plugin.Log.LogInfo((object)$"{active} teleport: following through it is switched off in the settings."); return; } float num = ((active == Entry.Dungeon) ? 0.8f : 1.5f); float num2 = ((active == Entry.Dungeon) ? 1.6f : 3f); int num3 = 0; foreach (Character item in new List<Character>(Character.GetAllCharacters())) { if ((Object)(object)item == (Object)null || item.IsPlayer() || !item.IsTamed()) { continue; } string name = ((Object)item).name; ZNetView component = ((Component)item).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || !component.IsValid() || (Object)(object)((Component)item).GetComponent<Tameable>() == (Object)null) { continue; } string text = component.GetZDO().GetString(ZDOVars.s_follow, ""); MonsterAI component2 = ((Component)item).GetComponent<MonsterAI>(); if (!(text == __instance.GetPlayerName()) && (!((Object)(object)component2 != (Object)null) || !((Object)(object)component2.GetFollowTarget() == (Object)(object)((Component)__instance).gameObject))) { Plugin.Log.LogInfo((object)(" " + name + ": not following you (follows '" + text + "'), left behind")); continue; } float num4 = Vector3.Distance(((Component)item).transform.position, ((Component)__instance).transform.position); if (num4 > Plugin.FollowerRange.Value) { Plugin.Log.LogInfo((object)$" {name}: {num4:0} m away, farther than FollowerRange, left behind"); continue; } component.ClaimOwnership(); Vector2 insideUnitCircle = Random.insideUnitCircle; Vector2 val = ((Vector2)(ref insideUnitCircle)).normalized * Random.Range(num, num2); Vector3 position = pos + new Vector3(val.x, 0.5f, val.y); component.GetZDO().SetPosition(position); ((Component)item).transform.position = position; Rigidbody component3 = ((Component)item).GetComponent<Rigidbody>(); if ((Object)(object)component3 != (Object)null) { component3.position = position; component3.velocity = Vector3.zero; } num3++; Plugin.Log.LogInfo((object)(" " + name + ": moved to the other side")); } Plugin.Log.LogInfo((object)$"{active} teleport: moved {num3} animal(s)."); } } [HarmonyPatch(typeof(ZDO), "SetOwner")] internal static class ZDO_SetOwner_Patch { private static bool Prefix(ZDO __instance, long uid) { if (!Plugin.LockOwnership.Value || !__instance.GetBool(ZDOVars.s_tamed, false)) { return true; } string text = __instance.GetString(ZDOVars.s_follow, ""); if (string.IsNullOrEmpty(text)) { return true; } long num = PlayerSession(text); if (num != 0L) { return num == uid; } return true; } private static long PlayerSession(string name) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_005e: 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) if ((Object)(object)Player.m_localPlayer != (Object)null && Player.m_localPlayer.GetPlayerName() == name) { return ZDOMan.GetSessionID(); } if ((Object)(object)ZNet.instance == (Object)null) { return 0L; } foreach (PlayerInfo player in ZNet.instance.GetPlayerList()) { if (player.m_name == name) { ZDOID characterID = player.m_characterID; return ((ZDOID)(ref characterID)).UserID; } } return 0L; } } internal static class Handling { internal enum Stat { Damage, Carry, Health } internal static SkillType Skill; private static readonly int[] Keys = new int[3] { StringExtensionMethods.GetStableHashCode("TT_HandlingDamage"), StringExtensionMethods.GetStableHashCode("TT_HandlingCarry"), StringExtensionMethods.GetStableHashCode("TT_HandlingHealth") }; internal static float Percent(Stat stat) { string value; float value2; switch (stat) { case Stat.Damage: value = Plugin.CustomDamage.Value; value2 = Plugin.DamagePercent.Value; break; case Stat.Carry: value = Plugin.CustomCarry.Value; value2 = Plugin.CarryPercent.Value; break; default: value = Plugin.CustomHealth.Value; value2 = Plugin.HealthPercent.Value; break; } if (!string.IsNullOrWhiteSpace(value) && float.TryParse(value.Trim().TrimEnd(new char[1] { '%' }), NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { return Mathf.Max(0f, result); } return Mathf.Round(value2 * 2f) / 2f; } internal static float MultiplierFor(Stat stat, float level) { return 1f + level * Percent(stat) / 100f; } internal static float MultOf(Character character, Stat stat) { ZNetView component = ((Component)character).GetComponent<ZNetView>(); if (!((Object)(object)component != (Object)null) || !component.IsValid()) { return 1f; } return component.GetZDO().GetFloat(Keys[(int)stat], 1f); } internal static void Apply(Character character, ZNetView nview, float level) { Stat[] array = new Stat[3] { Stat.Damage, Stat.Carry, Stat.Health }; foreach (Stat stat in array) { float num = MultiplierFor(stat, level); if (Mathf.Abs(nview.GetZDO().GetFloat(Keys[(int)stat], 1f) - num) > 0.001f) { nview.GetZDO().Set(Keys[(int)stat], num); } } float num2 = character.GetMaxHealthBase() * MultiplierFor(Stat.Health, level); float maxHealth = character.GetMaxHealth(); if (Mathf.Abs(maxHealth - num2) > 0.5f) { float num3 = ((maxHealth > 0f) ? Mathf.Clamp01(character.GetHealth() / maxHealth) : 1f); character.SetMaxHealth(num2); character.SetHealth(num3 * num2); } } internal static void Raise(float xp) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) if (Plugin.HandlingEnabled.Value && xp > 0f && (Object)(object)Player.m_localPlayer != (Object)null) { ((Character)Player.m_localPlayer).RaiseSkill(Skill, xp); } } internal static void Award(string playerName, float xp) { //IL_006c: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.HandlingEnabled.Value || xp <= 0f || string.IsNullOrEmpty(playerName)) { return; } if ((Object)(object)Player.m_localPlayer != (Object)null && Player.m_localPlayer.GetPlayerName() == playerName) { Raise(xp); } else { if ((Object)(object)ZNet.instance == (Object)null || ZRoutedRpc.instance == null) { return; } foreach (PlayerInfo player in ZNet.instance.GetPlayerList()) { if (player.m_name == playerName) { ZRoutedRpc instance = ZRoutedRpc.instance; ZDOID characterID = player.m_characterID; instance.InvokeRoutedRPC(((ZDOID)(ref characterID)).UserID, "TT_Raise", new object[1] { xp }); break; } } } } internal static Sprite MakeIcon() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0096: 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_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_0110: 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_00fc: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false); Color val2 = default(Color); ((Color)(ref val2))..ctor(0f, 0f, 0f, 0f); Color val3 = default(Color); ((Color)(ref val3))..ctor(0.93f, 0.85f, 0.65f, 1f); Vector2[] array = (Vector2[])(object)new Vector2[5] { new Vector2(32f, 22f), new Vector2(15f, 36f), new Vector2(26f, 46f), new Vector2(38f, 46f), new Vector2(49f, 36f) }; float[] array2 = new float[5] { 13f, 6f, 6f, 6f, 6f }; for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { Color val4 = val2; for (int k = 0; k < array.Length; k++) { if (Vector2.Distance(new Vector2((float)j, (float)i), array[k]) <= array2[k]) { val4 = val3; } } val.SetPixel(j, i, val4); } } val.Apply(); return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f)); } } [HarmonyPatch(typeof(Character), "Damage")] internal static class Character_Damage_Patch { private static void Prefix(Character __instance, HitData hit) { if (!Plugin.HandlingEnabled.Value || (Object)(object)Player.m_localPlayer == (Object)null || hit == null) { return; } Character attacker = hit.GetAttacker(); if ((Object)(object)attacker == (Object)null || attacker.IsPlayer() || !attacker.IsTamed() || __instance.IsPlayer() || __instance.IsTamed()) { return; } ZNetView component = ((Component)attacker).GetComponent<ZNetView>(); if (!((Object)(object)component == (Object)null) && component.IsValid() && !(component.GetZDO().GetString(ZDOVars.s_follow, "") != Player.m_localPlayer.GetPlayerName())) { Handling.Raise(hit.GetTotalDamage() * Plugin.DamageXp.Value); float num = Handling.MultOf(attacker, Handling.Stat.Damage); if (num > 1.0001f) { ((DamageTypes)(ref hit.m_damage)).Modify(num); } } } } [HarmonyPatch(typeof(Tameable), "Tame")] internal static class Tameable_Tame_Patch { private static void Prefix(Tameable __instance) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.HandlingEnabled.Value) { return; } ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || !component.IsValid() || !component.IsOwner() || __instance.IsTamed() || (Object)(object)((Component)__instance).GetComponent<MonsterAI>() == (Object)null || (Object)(object)((Component)__instance).GetComponent<Character>() == (Object)null) { return; } List<Player> list = new List<Player>(); Player.GetPlayersInRange(((Component)__instance).transform.position, 30f, list); foreach (Player item in list) { if ((Object)(object)item == (Object)(object)Player.m_localPlayer) { Handling.Raise(Plugin.TamingXp.Value); } else if (ZRoutedRpc.instance != null) { ZRoutedRpc instance = ZRoutedRpc.instance; ZDOID zDOID = ((Character)item).GetZDOID(); instance.InvokeRoutedRPC(((ZDOID)(ref zDOID)).UserID, "TT_Raise", new object[1] { Plugin.TamingXp.Value }); } } } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] internal static class ZNet_OnNewConnection_Patch { private static ZRoutedRpc _registered; private static void Postfix() { if (ZRoutedRpc.instance != null && ZRoutedRpc.instance != _registered) { _registered = ZRoutedRpc.instance; ZRoutedRpc.instance.Register<float>("TT_Raise", (Action<long, float>)delegate(long sender, float xp) { Handling.Raise(xp); }); } } } [HarmonyPatch(typeof(Container), "Save")] internal static class Container_Save_LogPatch { private static void Postfix(Container __instance) { Inventory inventory = __instance.GetInventory(); if (inventory != null && FoodBag.ByInventory.ContainsKey(inventory)) { Plugin.Log.LogInfo((object)$"Bag #{((Object)__instance).GetInstanceID()} SAVED: {FoodBag.Describe(inventory)}"); } } } [HarmonyPatch(typeof(Container), "Load")] internal static class Container_Load_LogPatch { private static void Postfix(Container __instance, bool __result) { Inventory inventory = __instance.GetInventory(); if (__result && inventory != null && FoodBag.ByInventory.ContainsKey(inventory)) { Plugin.Log.LogInfo((object)$"Bag #{((Object)__instance).GetInstanceID()} LOADED from saved data: {FoodBag.Describe(inventory)}"); } } } [HarmonyPatch(typeof(SkillsDialog), "Setup")] internal static class SkillsDialog_Setup_Patch { private static readonly FieldRef<SkillsDialog, List<GameObject>> Elements = AccessTools.FieldRefAccess<SkillsDialog, List<GameObject>>("m_elements"); private static void Postfix(SkillsDialog __instance, Player player) { if (!Plugin.ShowSkillProgress.Value || (Object)(object)player == (Object)null) { return; } List<Skill> skillList = ((Character)player).GetSkills().GetSkillList(); List<GameObject> list = Elements.Invoke(__instance); for (int i = 0; i < skillList.Count && i < list.Count; i++) { Skill val = skillList[i]; if (!(val.m_level >= 100f)) { Transform val2 = Utils.FindChild(list[i].transform, "leveltext", (IterativeSearchType)0); TMP_Text val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<TMP_Text>() : null); if (!((Object)(object)val3 == (Object)null)) { float num = Mathf.Pow(Mathf.Floor(val.m_level + 1f), 1.5f) * 0.5f + 0.5f; val3.enableWordWrapping = false; val3.overflowMode = (TextOverflowModes)0; val3.text = (int)val.m_level + " <size=70%>(" + val.m_accumulator.ToString("0.#") + "/" + num.ToString("0.#") + ")</size>"; } } } } } internal static class StatsPanel { private static GameObject _panel; private static TextMeshProUGUI _text; private static float _nextUpdate; private static readonly FieldRef<InventoryGui, Container> Current = AccessTools.FieldRefAccess<InventoryGui, Container>("m_currentContainer"); private static void Create(InventoryGui gui) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_004f: 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_005f: 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_009c: 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_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: 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_010b: 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_017e: Unknown result type (might be due to invalid IL or missing references) _panel = new GameObject("TameTweaks_Stats", new Type[2] { typeof(RectTransform), typeof(Image) }); _panel.transform.SetParent(((Component)gui).transform, false); RectTransform val = (RectTransform)_panel.transform; val.pivot = new Vector2(0f, 1f); val.sizeDelta = new Vector2(280f, 230f); Image component = _panel.GetComponent<Image>(); ((Graphic)component).color = new Color(0f, 0f, 0f, 0.65f); ((Graphic)component).raycastTarget = false; GameObject val2 = new GameObject("Text", new Type[1] { typeof(RectTransform) }); val2.transform.SetParent(_panel.transform, false); RectTransform val3 = (RectTransform)val2.transform; val3.anchorMin = Vector2.zero; val3.anchorMax = Vector2.one; val3.offsetMin = new Vector2(10f, 8f); val3.offsetMax = new Vector2(-10f, -8f); _text = val2.AddComponent<TextMeshProUGUI>(); if ((Object)(object)gui.m_containerName != (Object)null) { ((TMP_Text)_text).font = gui.m_containerName.font; } ((TMP_Text)_text).fontSize = 17f; ((Graphic)_text).color = new Color(1f, 0.95f, 0.85f, 1f); ((TMP_Text)_text).alignment = (TextAlignmentOptions)257; ((TMP_Text)_text).richText = true; ((TMP_Text)_text).enableWordWrapping = true; ((Graphic)_text).raycastTarget = false; } internal static void Tick(InventoryGui gui) { //IL_00b2: 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_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) FoodBag value = null; Container val = Current.Invoke(gui); if (Plugin.Enabled.Value && Plugin.ShowStats.Value && (Object)(object)val != (Object)null && val.GetInventory() != null) { FoodBag.ByInventory.TryGetValue(val.GetInventory(), out value); } if ((Object)(object)value == (Object)null || (Object)(object)gui.m_container == (Object)null) { if ((Object)(object)_panel != (Object)null) { _panel.SetActive(false); } return; } if ((Object)(object)_panel == (Object)null) { Create(gui); } _panel.SetActive(true); Vector3[] array = (Vector3[])(object)new Vector3[4]; gui.m_container.GetWorldCorners(array); float x = ((Component)gui).transform.lossyScale.x; _panel.transform.position = array[2] + new Vector3(8f * x, 0f, 0f); if (Time.time >= _nextUpdate) { _nextUpdate = Time.time + 0.25f; ((TMP_Text)_text).text = Describe(value); } } private static string Damage(DamageTypes damage, float savedFactor, out string kind) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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_003f: 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_0051: Unknown result type (might be due to invalid IL or missing references) float[] array = new float[9] { damage.m_damage, damage.m_blunt, damage.m_slash, damage.m_pierce, damage.m_fire, damage.m_frost, damage.m_lightning, damage.m_poison, damage.m_spirit }; string[] array2 = new string[9] { "", "blunt", "slash", "pierce", "fire", "frost", "lightning", "poison", "spirit" }; int num = 0; for (int i = 1; i < array.Length; i++) { if (array[i] > array[num]) { num = i; } } kind = array2[num]; float num2 = ((DamageTypes)(ref damage)).GetTotalDamage() * savedFactor; int num3 = Mathf.RoundToInt(num2 * Mathf.Sqrt(0.75f)); int num4 = Mathf.RoundToInt(num2); if (num3 != num4) { return num3 + "-" + num4; } return num4.ToString(); } private static string Describe(FoodBag bag) { //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) Character character = bag.Character; if ((Object)(object)character == (Object)null) { return ""; } StringBuilder stringBuilder = new StringBuilder(); Tameable component = ((Component)character).GetComponent<Tameable>(); string text = (((Object)(object)component != (Object)null) ? component.GetHoverName() : character.m_name); int num = Mathf.Max(1, character.GetLevel()); stringBuilder.Append("<b>").Append(Localization.instance.Localize(text)).Append("</b>\n"); stringBuilder.Append("Level ").Append(num); if (num > 1) { stringBuilder.Append(" (").Append(num - 1).Append((num == 2) ? " star)" : " stars)"); } stringBuilder.Append("\n\n"); stringBuilder.Append("Health: ").Append(Mathf.CeilToInt(character.GetHealth())).Append(" / ") .Append(Mathf.CeilToInt(character.GetMaxHealth())) .Append('\n'); Humanoid component2 = ((Component)character).GetComponent<Humanoid>(); ItemData val = (((Object)(object)component2 != (Object)null) ? component2.GetCurrentWeapon() : null); if (val != null) { DamageTypes damage = val.GetDamage(); float num2 = 1f + (float)Mathf.Max(0, num - 1) * 0.5f; float num3 = Handling.MultOf(character, Handling.Stat.Damage); ((DamageTypes)(ref damage)).Modify(num2 * num3); ZNetView component3 = ((Component)character).GetComponent<ZNetView>(); float? obj; if (component3 == null) { obj = null; } else { ZDO zDO = component3.GetZDO(); obj = ((zDO != null) ? new float?(zDO.GetFloat(ZDOVars.s_randomSkillFactor, 1f)) : ((float?)null)); } float savedFactor = obj ?? 1f; string kind; string value = Damage(damage, savedFactor, out kind); stringBuilder.Append("Damage per hit: ").Append(value); if (kind.Length > 0) { stringBuilder.Append(" (").Append(kind).Append(')'); } stringBuilder.Append('\n'); } Inventory inventory = bag.Inventory; if (inventory != null) { stringBuilder.Append("Carrying: ").Append(Mathf.CeilToInt(inventory.GetTotalWeight())).Append(" / ") .Append(Mathf.RoundToInt(bag.Capacity)) .Append('\n'); } if (Plugin.HandlingEnabled.Value) { stringBuilder.Append("Animal Handling: +").Append(Mathf.RoundToInt((Handling.MultOf(character, Handling.Stat.Damage) - 1f) * 100f)).Append("% damage, +") .Append(Mathf.RoundToInt((Handling.MultOf(character, Handling.Stat.Carry) - 1f) * 100f)) .Append("% carry, +") .Append(Mathf.RoundToInt((Handling.MultOf(character, Handling.Stat.Health) - 1f) * 100f)) .Append("% health\n"); } ZNetView component4 = ((Component)character).GetComponent<ZNetView>(); object obj2; if (component4 == null) { obj2 = null; } else { ZDO zDO2 = component4.GetZDO(); obj2 = ((zDO2 != null) ? zDO2.GetString(ZDOVars.s_follow, "") : null); } string text2 = (string)obj2; stringBuilder.Append(string.IsNullOrEmpty(text2) ? "Staying put" : ("Following " + text2)); return stringBuilder.ToString(); } } [HarmonyPatch(typeof(InventoryGui), "Update")] internal static class InventoryGui_Update_StatsPatch { private static void Postfix(InventoryGui __instance) { StatsPanel.Tick(__instance); } } }